BxBaseModProfileTemplate.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup BaseProfile Base classes for profile modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /*
  12. * Profile based modules representation.
  13. */
  14. class BxBaseModProfileTemplate extends BxBaseModGeneralTemplate
  15. {
  16. protected $_sUnitDefault;
  17. protected $_sUnitSizeDefault;
  18. protected $_sUnitClass;
  19. protected $_sUnitClassWithCover;
  20. protected $_sUnitClassWoInfo;
  21. protected $_sUnitClassWoInfoShowCase;
  22. protected $_sUnitClassShowCase;
  23. /*
  24. * Enable/Disable Letter based thumbnail in "Unit with Cover" only.
  25. */
  26. protected $_bLetterAvatar;
  27. function __construct(&$oConfig, &$oDb)
  28. {
  29. parent::__construct($oConfig, $oDb);
  30. $this->_sUnitDefault = 'unit.html';
  31. $this->_sUnitSizeDefault = 'thumb';
  32. $this->_sUnitClass = 'bx-base-pofile-unit';
  33. $this->_sUnitClassWithCover = 'bx-base-pofile-unit-with-cover';
  34. $this->_sUnitClassWoInfo = 'bx-base-pofile-unit-wo-info';
  35. $this->_sUnitClassWoInfoShowCase = 'bx-base-pofile-unit-wo-info bx-base-unit-showcase bx-base-pofile-unit-wo-info-showcase';
  36. $this->_sUnitClassShowCase = 'bx-base-pofile-unit-with-cover bx-base-unit-showcase bx-base-pofile-unit-showcase';
  37. $this->_bLetterAvatar = true;
  38. }
  39. public function addLocationBase()
  40. {
  41. parent::addLocationBase();
  42. $this->addLocation('mod_profile', BX_DIRECTORY_PATH_MODULES . 'base' . DIRECTORY_SEPARATOR . 'profile' . DIRECTORY_SEPARATOR, BX_DOL_URL_MODULES . 'base/profile/');
  43. }
  44. /**
  45. * Get profile unit
  46. */
  47. function unit ($aData, $isCheckPrivateContent = true, $mixedTemplate = false, $aParams = [])
  48. {
  49. list($sTemplate) = is_array($mixedTemplate) ? $mixedTemplate : array($mixedTemplate);
  50. if(!empty($aParams['template_name']))
  51. $sTemplate = $aParams['template_name'];
  52. if(empty($sTemplate))
  53. $sTemplate = $this->_sUnitDefault;
  54. /**
  55. * Allow use separate template for private profiles.
  56. * These templates will be used if privacy field "Visible to" don't allow to view content.
  57. * To use them you need to create a template with a postfix "_private" and put it in specified module
  58. * Example: "unit_private.html" for "unit.html" or "unit_wo_links_private.html" for "unit_wo_links.html"
  59. */
  60. $oModule = $this->getModule();
  61. if ($oModule->serviceCheckAllowedViewForProfile($aData) !== 0){
  62. $sTemplatePrivate = str_replace('.html', '_private.html' , $sTemplate);
  63. if($this->parseHtmlByName($sTemplatePrivate, array())){
  64. $sTemplate = $sTemplatePrivate;
  65. }
  66. }
  67. $aVars = $this->unitVars($aData, $isCheckPrivateContent, $mixedTemplate, $aParams);
  68. $aExtras = [
  69. 'module' => $oModule->getName(),
  70. 'data' => $aData,
  71. 'check_private_content' => $isCheckPrivateContent,
  72. 'template' => $mixedTemplate,
  73. 'params' => $aParams,
  74. 'tmpl_name' => &$sTemplate,
  75. 'tmpl_vars' => &$aVars
  76. ];
  77. /**
  78. * @hooks
  79. * @hookdef hook-profile-unit 'profile', 'unit' - hook to override profile browsing unit
  80. * - $unit_name - equals `profile`
  81. * - $action - equals `unit`
  82. * - $object_id - not used
  83. * - $sender_id - not used
  84. * - $extra_params - array of additional params with the following array keys:
  85. * - `module` - [string] module name
  86. * - `data` - [array] profile info array as key&value pairs
  87. * - `check_private_content` - [boolean] check if it's a provate profile
  88. * - `template` - [string] or [array] with template for profile unit
  89. * - `params` - [array] additional params array as key&value pairs
  90. * - `tmpl_name` - [string] by ref, template name, can be overridden in hook processing
  91. * - `tmpl_vars` - [array] by ref, template parsable variables as key&value pairs, can be overridden in hook processing
  92. * @hook @ref hook-profile-unit
  93. */
  94. bx_alert('profile', 'unit', 0, 0, $aExtras);
  95. /**
  96. * @hooks
  97. * @hookdef hook-bx_base_profile-unit '{module_name}', 'unit' - hook to override profile browsing unit
  98. * It's equivalent to @ref hook-profile-unit
  99. * @hook @ref hook-bx_base_profile-unit
  100. */
  101. bx_alert($aExtras['module'], 'unit', 0, 0, $aExtras);
  102. return $this->parseHtmlByName($sTemplate, $aVars);
  103. }
  104. public function unitAPI($aData, $aParams = [])
  105. {
  106. return $this->getModule()->getDataAPI($aData, $aParams);
  107. }
  108. function unitVars ($aData, $isCheckPrivateContent = true, $mixedTemplate = false, $aParams = [])
  109. {
  110. $CNF = &$this->_oConfig->CNF;
  111. list($sTemplate, $sTemplateSize, $aTemplateVars) = is_array($mixedTemplate) ? $mixedTemplate : array($mixedTemplate, false, array());
  112. if(!empty($aParams['template_name']))
  113. $sTemplate = $aParams['template_name'];
  114. if(empty($sTemplate))
  115. $sTemplate = $this->_sUnitDefault;
  116. if(!empty($aParams['template_size']))
  117. $sTemplateSize = $aParams['template_size'];
  118. if(empty($sTemplateSize))
  119. $sTemplateSize = $this->_getUnitSize($aData, $sTemplate);
  120. if(!empty($aParams['template_vars']) && is_array($aParams['template_vars']))
  121. $aTemplateVars = $aParams['template_vars'];
  122. if(empty($aTemplateVars) || !is_array($aTemplateVars))
  123. $aTemplateVars = array();
  124. $oModule = $this->getModule();
  125. $iContentId = (int)$aData[$CNF['FIELD_ID']];
  126. $bPublic = $isCheckPrivateContent && !empty($CNF['OBJECT_PRIVACY_VIEW']) ? $this->isProfilePublic($aData) : true;
  127. $bPublicThumb = true;
  128. if($isCheckPrivateContent && $oModule->checkAllowedViewProfileImage($aData) !== CHECK_ACTION_RESULT_ALLOWED)
  129. $bPublicThumb = false;
  130. $bPublicCover = true;
  131. if($isCheckPrivateContent && $oModule->checkAllowedViewCoverImage($aData) !== CHECK_ACTION_RESULT_ALLOWED)
  132. $bPublicCover = false;
  133. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->MODULE);
  134. $iProfile = $oProfile->id();
  135. // get profile's url
  136. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId));
  137. // get profile's title
  138. $sTitle = $oModule->serviceProfileName($iContentId);
  139. $sText = $sSummary = '';
  140. if(!empty($CNF['FIELD_TEXT']) && !empty($aData[$CNF['FIELD_TEXT']])) {
  141. $sText = $this->getText($aData);
  142. $sSummary = $this->getSummary($aData, $sTitle, $sText, $sUrl);
  143. }
  144. $sCoverUrl = $bPublicCover ? $this->urlCoverUnit($aData, false) : '';
  145. $bCoverUrl = !empty($sCoverUrl);
  146. if(empty($sCoverUrl) && ($iCoverId = (int)getParam('sys_unit_cover_profile')) != 0)
  147. $sCoverUrl = BxDolTranscoder::getObjectInstance(BX_DOL_TRANSCODER_OBJ_COVER_UNIT_PROFILE)->getFileUrlById($iCoverId);
  148. if(empty($sCoverUrl))
  149. $sCoverUrl = $this->getImageUrl('cover.svg');
  150. $sThumbUrl = $bPublicThumb ? $this->_getUnitThumbUrl($sTemplateSize, $aData, false) : '';
  151. $bThumbUrl = !empty($sThumbUrl);
  152. if(substr($sTemplate, 0, 13) == 'unit_wo_cover' && !$bThumbUrl && $bCoverUrl) {
  153. $bThumbUrl = true;
  154. $sThumbUrl = $sCoverUrl;
  155. }
  156. $aTmplVarsThumbnail = array(
  157. 'class_size' => '',
  158. 'bx_if:show_thumb_image' => array(
  159. 'condition' => $bThumbUrl,
  160. 'content' => array(
  161. 'class_size' => '',
  162. 'size' => $sTemplateSize,
  163. 'thumb_url' => $sThumbUrl
  164. )
  165. ),
  166. 'bx_if:show_thumb_letter' => array(
  167. 'condition' => !$bThumbUrl,
  168. 'content' => array(
  169. 'class_size' => '',
  170. 'size' => $sTemplateSize,
  171. 'color' => implode(', ', BxDolTemplate::getColorCode($iProfile, 1.0)),
  172. 'letter' => mb_strtoupper(mb_substr($sTitle, 0, 1))
  173. )
  174. ),
  175. 'bx_if:show_online' => array(
  176. 'condition' => $oProfile->isOnline(),
  177. 'content' => array()
  178. ),
  179. 'size' => $sTemplateSize,
  180. 'badges' => $oModule->serviceGetBadges($iContentId, false, true),
  181. 'thumb_url' => $bThumbUrl ? $sThumbUrl : $this->getImageUrl('no-picture-thumb.png'),
  182. );
  183. $aTmplVarsMeta = array();
  184. if(substr($sTemplate, 0, 8) != 'unit_wo_')
  185. $aTmplVarsMeta = $this->getSnippetMenuVars ($iProfile, $bPublic, $aParams);
  186. $sCoverData = isset($aData['cover_data']) ? $aData['cover_data'] : '';
  187. return array_merge(array (
  188. 'class' => $this->_getUnitClass($aData, $sTemplate) . (!$bCoverUrl ? ' bx-cover-empty' : ''),
  189. 'id' => $iContentId,
  190. 'public' => $bPublic,
  191. 'bx_if:show_thumbnail' => array(
  192. 'condition' => $bThumbUrl || $this->_bLetterAvatar,
  193. 'content' => $aTmplVarsThumbnail
  194. ),
  195. 'cover_url' => $sCoverUrl,
  196. 'cover_settings' => $this->_getImageSettings($sCoverData),
  197. 'bx_if:show_cover' => array(
  198. 'condition' => $bCoverUrl,
  199. 'content' => array(
  200. 'cover_url' => $sCoverUrl,
  201. 'cover_settins' => $this->_getImageSettings($sCoverData),
  202. 'title' => $sTitle,
  203. )
  204. ),
  205. 'content_url' => $bPublic ? $sUrl : 'javascript:void(0);',
  206. 'content_click' => !$bPublic ? 'javascript:bx_alert(' . bx_js_string('"' . _t('_sys_access_denied_to_private_content') . '"') . ');' : '',
  207. 'title' => $sTitle,
  208. 'title_attr' => bx_html_attribute($sTitle),
  209. 'addon' => !empty($aData['addon']) ? $aData['addon'] : '',
  210. 'module_name' => _t($CNF['T']['txt_sample_single']),
  211. 'ts' => $aData[$CNF['FIELD_ADDED']],
  212. 'bx_if:meta' => array(
  213. 'condition' => !empty($aTmplVarsMeta),
  214. 'content' => $aTmplVarsMeta
  215. ),
  216. 'text' => $sText,
  217. 'summary' => $sSummary,
  218. ), $aTmplVarsThumbnail, $aTemplateVars);
  219. }
  220. function isProfilePublic($aData)
  221. {
  222. $CNF = &$this->_oConfig->CNF;
  223. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  224. if ($oPrivacy && !$oPrivacy->check($aData[$CNF['FIELD_ID']]) && !$oPrivacy->isPartiallyVisible($aData[$CNF['FIELD_ALLOW_VIEW_TO']]))
  225. return false;
  226. return true;
  227. }
  228. function getSnippetMenuVars ($iProfileId, $bPublic = null, $aParams = [])
  229. {
  230. $CNF = &$this->_oConfig->CNF;
  231. $oProfile = false;
  232. if(empty($CNF['OBJECT_MENU_SNIPPET_META']) || !($oProfile = BxDolProfile::getInstance($iProfileId)))
  233. return [];
  234. $oMetaMenu = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SNIPPET_META'], $this);
  235. if(!$oMetaMenu)
  236. return [];
  237. if ($bPublic === null) {
  238. $aData = $this->getModule()->serviceGetContentInfoById($oProfile->getContentId());
  239. $bPublic = $this->isProfilePublic($aData);
  240. }
  241. $oMetaMenu->setContentId($oProfile->getContentId());
  242. $oMetaMenu->setContentPublic($bPublic);
  243. if(isset($aParams['context']))
  244. $oMetaMenu->setContext($aParams['context']);
  245. return [
  246. 'meta' => $oMetaMenu->getCode()
  247. ];
  248. }
  249. function getBlockCover($aData, $aParams = [])
  250. {
  251. $CNF = &$this->_oConfig->CNF;
  252. $oProfile = BxDolProfile::getInstanceByContentAndType($aData[$CNF['FIELD_ID']], $this->MODULE);
  253. if(!$oProfile)
  254. return '';
  255. $aTmplVars = $this->prepareCover($aData, array_merge($aParams, [
  256. 'use_as_block' => true
  257. ]));
  258. $this->addCss(array('cover.css'));
  259. return $this->parseHtmlByName('cover_block.html', $aTmplVars);
  260. }
  261. function prepareCover($aData, $aParams = [])
  262. {
  263. $CNF = &$this->_oConfig->CNF;
  264. $oModule = $this->getModule();
  265. $sClass = isset($aParams['class']) ? $aParams['class'] : '';
  266. $sShowData = isset($aParams['show_data']) ? $aParams['show_data'] : '';
  267. $bShowCover = !isset($aParams['show_cover']) || $aParams['show_cover'] === true;
  268. $bShowAvatar = !isset($aParams['show_avatar']) || $aParams['show_avatar'] === true;
  269. $sAddCode = "";
  270. $bUseAsAuthor = isset($aParams['use_as_author']) && $aParams['use_as_author'] === true;
  271. $bUseAsBlock = $bUseAsAuthor || (isset($aParams['use_as_block']) && $aParams['use_as_block'] === true);
  272. if($bUseAsAuthor)
  273. $sClass .= ' bx-base-author';
  274. else
  275. BxDolTemplate::getInstance()->addInjection('injection_main_class', 'text', 'bx-base-profile-view');
  276. $bProfileViewAllowed = $oModule->checkAllowedView($aData) === CHECK_ACTION_RESULT_ALLOWED;
  277. if($oModule->checkAllowedViewProfileImage($aData) !== CHECK_ACTION_RESULT_ALLOWED)
  278. $aData[$CNF['FIELD_PICTURE']] = 0;
  279. if($oModule->checkAllowedViewCoverImage($aData) !== CHECK_ACTION_RESULT_ALLOWED)
  280. $aData[$CNF['FIELD_COVER']] = 0;
  281. $oProfile = BxDolProfile::getInstanceByContentAndType($aData[$CNF['FIELD_ID']], $this->MODULE);
  282. $iProfile = $oProfile->id();
  283. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aData[$CNF['FIELD_ID']]));
  284. $sTitle = bx_process_output($oProfile->getDisplayName());
  285. //--- Process Cover
  286. $bTmplVarsShowCover = $bShowCover;
  287. $aTmplVarsShowCover = [];
  288. if($bTmplVarsShowCover) {
  289. $sCoverPopupId = $this->MODULE . '-popup-cover';
  290. $bIsAllowEditCover = $oModule->checkAllowedChangeCover($aData) === CHECK_ACTION_RESULT_ALLOWED;
  291. $oPage = false;
  292. if(isset($aParams['page']) && is_a($aParams['page'], 'BxDolPage'))
  293. $oPage = $aParams['page'];
  294. $bUrlCover = false;
  295. $sUrlCover = $this->urlCover($aData, false);
  296. if(!$sUrlCover && $oPage !== false && $oPage->isPageCover()) {
  297. $aCover = $oPage->getPageCoverImage();
  298. if(!empty($aCover))
  299. $sUrlCover = BxDolCover::getCoverImageUrl($aCover);
  300. }
  301. if(!empty($sUrlCover)) {
  302. if(!$bUseAsAuthor)
  303. BxDolTemplate::getInstance()->addPageMetaImage($sUrlCover);
  304. $bUrlCover = true;
  305. }
  306. else
  307. $sUrlCover = $this->getImageUrl('cover.svg');
  308. $sAddClassCover = "";
  309. if(isset($CNF['FIELD_COVER']) && isset($CNF['OBJECT_UPLOADERS_COVER']) && isset($CNF['OBJECT_STORAGE_COVER']) && isset($CNF['OBJECT_IMAGES_TRANSCODER_COVER'])){
  310. /**
  311. * @hooks
  312. * @hookdef hook-system-image_editor 'system', 'image_editor' - hook to override profile cover editor
  313. * - $unit_name - equals `system`
  314. * - $action - equals `image_editor`
  315. * - $object_id - not used
  316. * - $sender_id - not used
  317. * - $extra_params - array of additional params with the following array keys:
  318. * - `module` - [string] module name
  319. * - `content_id` - [int] profile content id
  320. * - `is_allow_edit` - [boolean] if edit action is allowed to current user
  321. * - `image_type` - [string] image type equals to `cover`
  322. * - `image_url` - [string] image URL
  323. * - `uploader` - [string] uploader name
  324. * - `storage` - [string] storage name
  325. * - `transcoder` - [string] transcoder name
  326. * - `field` - [string] field name
  327. * - `is_background` - [boolean] if image is used as background, always `true`
  328. * - `add_class` - [string] by ref, class to add, can be overridden in hook processing
  329. * - `add_code` - [array] by ref, code to add, can be overridden in hook processing
  330. * @hook @ref hook-system-image_editor
  331. */
  332. bx_alert('system', 'image_editor', 0, 0, [
  333. 'module' => $oModule->getName(),
  334. 'content_id' => $aData[$CNF['FIELD_ID']],
  335. 'is_allow_edit' => $bIsAllowEditCover,
  336. 'image_type' => 'cover',
  337. 'image_url' => $aData[$CNF['FIELD_COVER']] ? $sUrlCover : '',
  338. 'uploader' => $CNF['OBJECT_UPLOADERS_COVER'][0],
  339. 'storage' => $CNF['OBJECT_STORAGE_COVER'],
  340. 'transcoder' => $CNF['OBJECT_IMAGES_TRANSCODER_COVER'],
  341. 'field' => $CNF['FIELD_COVER'],
  342. 'is_background' => true,
  343. 'add_class' => &$sAddClassCover,
  344. 'add_code' => &$sAddCode
  345. ]);
  346. }
  347. $sCoverTweak = '';
  348. $sUniqIdCover = genRndPwd (8, false);
  349. if ($bIsAllowEditCover && empty($sAddCode)){
  350. $sCoverTweak = $this->_prepareImage($aData, $sUniqIdCover, $CNF['OBJECT_UPLOADERS_COVER'], $CNF['OBJECT_STORAGE_COVER'], $CNF['FIELD_COVER'], true);
  351. }
  352. $aTmplVarsShowCover = [
  353. 'cover_popup_id' => $sCoverPopupId,
  354. 'cover_url' => $sUrlCover,
  355. 'unique_id' => $sUniqIdCover,
  356. 'cover_settins' => isset($CNF['FIELD_COVER_POSITION']) ? $this->_getImageSettings($aData[$CNF['FIELD_COVER_POSITION']]) : '',
  357. 'add_class' => $sAddClassCover,
  358. 'img_class' => $sAddClassCover != '' ? 'bx-media-editable-src' : '',
  359. ];
  360. }
  361. else
  362. $sClass .= ' bx-no-cover';
  363. //--- Process Avatar
  364. $sUrlAvatar = $this->urlAvatarBig($aData, false);
  365. $bUrlAvatar = !empty($sUrlAvatar);
  366. $bTmplVarsShowAvatar = $bShowAvatar && ($bUrlAvatar || $this->_bLetterAvatar);
  367. $aTmplVarsShowAvatar = [];
  368. $sPicturePopup = '';
  369. if($bTmplVarsShowAvatar) {
  370. $sPicturePopupId = $this->MODULE . '-popup-picture';
  371. $bIsAllowEditPicture = $oModule->checkAllowedEdit($aData) === CHECK_ACTION_RESULT_ALLOWED;
  372. $sUrlPicture = $this->urlPicture ($aData);
  373. $sUrlPictureChange = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_EDIT_ENTRY'] . '&id=' . $aData[$CNF['FIELD_ID']]));
  374. $sAddClassPicture = "";
  375. if(isset($CNF['FIELD_PICTURE']) && isset($CNF['OBJECT_UPLOADERS_PICTURE']) && isset($CNF['OBJECT_STORAGE']) && isset($CNF['OBJECT_IMAGES_TRANSCODER_THUMB'])){
  376. /**
  377. * @hooks
  378. * @hookdef hook-system-image_editor 'system', 'image_editor' - hook to override profile avatar editor
  379. * - $unit_name - equals `system`
  380. * - $action - equals `image_editor`
  381. * - $object_id - not used
  382. * - $sender_id - not used
  383. * - $extra_params - array of additional params with the following array keys:
  384. * - `module` - [string] module name
  385. * - `content_id` - [int] profile content id
  386. * - `is_allow_edit` - [boolean] if edit action is allowed to current user
  387. * - `image_type` - [string] image type equals to `avatar`
  388. * - `image_url` - [string] image URL
  389. * - `uploader` - [string] uploader name
  390. * - `storage` - [string] storage name
  391. * - `transcoder` - [string] transcoder name
  392. * - `field` - [string] field name
  393. * - `is_background` - [boolean] if image used is as background, always `false`
  394. * - `add_class` - [string] by ref, class to add, can be overridden in hook processing
  395. * - `add_code` - [array] by ref, code to add, can be overridden in hook processing
  396. * @hook @ref hook-system-image_editor
  397. */
  398. bx_alert('system', 'image_editor', 0, 0, [
  399. 'module' => $oModule->getName(),
  400. 'content_id' => $aData[$CNF['FIELD_ID']],
  401. 'is_allow_edit' => $bIsAllowEditPicture,
  402. 'image_type' => 'avatar',
  403. 'image_url' => $aData[$CNF['FIELD_PICTURE']] ? $sUrlPicture : '',
  404. 'uploader' => $CNF['OBJECT_UPLOADERS_PICTURE'][0],
  405. 'storage' => $CNF['OBJECT_STORAGE'],
  406. 'transcoder' => $CNF['OBJECT_IMAGES_TRANSCODER_AVATAR_BIG'],
  407. 'field' => $CNF['FIELD_PICTURE'],
  408. 'is_background' => false,
  409. 'add_class' => &$sAddClassPicture,
  410. 'add_code' => &$sAddCode
  411. ]);
  412. }
  413. $sPictureTweak = '';
  414. $sUniqIdPicture = genRndPwd (8, false);
  415. if ($bIsAllowEditPicture && empty($sAddCode)){
  416. $sPictureTweak = $this->_prepareImage($aData, $sUniqIdPicture, $CNF['OBJECT_UPLOADERS_PICTURE'], $CNF['OBJECT_STORAGE'], $CNF['FIELD_PICTURE'], false);
  417. }
  418. $aTmplVarsShowAvatar = array(
  419. 'add_class' => $sAddClassPicture,
  420. 'letter' => mb_strtoupper(mb_substr($sTitle, 0, 1)),
  421. 'img_class' => $sAddClassPicture != '' ? 'bx-media-editable-src' : '',
  422. 'ava_url' => $sUrlAvatar,
  423. 'color' => implode(', ', BxDolTemplate::getColorCode($iProfile, 1.0)),
  424. 'bx_if:show_ava_image' => array(
  425. 'condition' => $bUrlAvatar,
  426. 'content' => [true]
  427. ),
  428. 'bx_if:show_ava_letter' => array(
  429. 'condition' => !$bUrlAvatar,
  430. 'content' => [true]
  431. ),
  432. 'bx_if:show_online' => array(
  433. 'condition' => $oProfile->isOnline(),
  434. 'content' => [true]
  435. ),
  436. 'bx_if:is_avatar' => array(
  437. 'condition' => $bUrlAvatar,
  438. 'content' => [
  439. 'picture_popup_id' => $sPicturePopupId,
  440. 'picture_url' => $sUrlPicture,
  441. ]
  442. ),
  443. 'picture_avatar_url' => $bUrlAvatar ? $sUrlAvatar : $this->getImageUrl('no-picture-preview.png'),
  444. 'unique_id' => $sUniqIdPicture,
  445. 'picture_tweak' => $sPictureTweak,
  446. 'cover_settins' => isset($CNF['FIELD_PICTURE_POSITION']) ? $this->_getImageSettings($aData[$CNF['FIELD_PICTURE_POSITION']]) : '',
  447. 'picture_href' => !$aData[$CNF['FIELD_PICTURE']] && CHECK_ACTION_RESULT_ALLOWED === $oModule->checkAllowedEdit($aData) ? $sUrlPictureChange : 'javascript:void(0);',
  448. );
  449. if($bProfileViewAllowed && $aData[$CNF['FIELD_PICTURE']]) {
  450. $sPicturePopup = BxTemplFunctions::getInstance()->transBox($sPicturePopupId, $this->parseHtmlByName('image_popup.html', array (
  451. 'image_url' => $sUrlPicture,
  452. 'bx_if:owner' => array (
  453. 'condition' => false,
  454. 'content' => array (
  455. 'change_image_url' => $sUrlPictureChange,
  456. ),
  457. ),
  458. )), true, true);
  459. }
  460. }
  461. //--- Process Actions menu
  462. $sActionsMenu = '';
  463. if(!isset($aParams['show_menu_actions']) || $aParams['show_menu_actions'] === true) {
  464. $sActionsMenu = $oModule->serviceEntityAllActions([$aData[$CNF['FIELD_ID']], $aData]);
  465. if(!$sActionsMenu && ($oMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY'], $this)) !== false)
  466. $sActionsMenu = $oMenu->getCode();
  467. }
  468. //--- Process Meta menu
  469. $sMetaMenu = '';
  470. if((!isset($aParams['show_menu_meta']) || $aParams['show_menu_meta'] === true) && !empty($CNF['OBJECT_MENU_VIEW_ENTRY_META'])) {
  471. $oMetaMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_VIEW_ENTRY_META']);
  472. if($oMetaMenu !== false) {
  473. $oMetaMenu->setContentId($aData[$CNF['FIELD_ID']]);
  474. $oMetaMenu->setContentPublic($this->isProfilePublic($aData));
  475. $sMetaMenu = $oMetaMenu->getCode();
  476. }
  477. }
  478. $aTmplVars = [
  479. 'module' => $this->_oConfig->getName(),
  480. 'class' => trim($sClass),
  481. 'id' => $aData[$CNF['FIELD_ID']],
  482. 'content_url' => $sUrl,
  483. 'title' => $sTitle,
  484. 'bx_if:show_title_as_tag' => [
  485. 'condition' => !$bUseAsAuthor,
  486. 'content' => [
  487. 'title' => $sTitle
  488. ]
  489. ],
  490. 'bx_if:show_title_as_text' => [
  491. 'condition' => $bUseAsAuthor,
  492. 'content' => [
  493. 'title' => $sTitle
  494. ]
  495. ],
  496. 'bx_if:show_avatar' => [
  497. 'condition' => $bTmplVarsShowAvatar,
  498. 'content' => $aTmplVarsShowAvatar
  499. ],
  500. 'bx_if:show_avatar_placeholder' => [
  501. 'condition' => !$bTmplVarsShowAvatar,
  502. 'content' => [true]
  503. ],
  504. 'badges' => $oModule->serviceGetBadges($aData[$CNF['FIELD_ID']]),
  505. 'action_menu' => $sActionsMenu,
  506. 'meta' => $sMetaMenu,
  507. 'show_data' => $sShowData,
  508. 'picture_popup' => $sPicturePopup,
  509. 'additional_code' => $sAddCode,
  510. 'cover_tweak' => $sCoverTweak,
  511. ];
  512. $bShowClickable = !isset($aParams['show_clickable']) || $aParams['show_clickable'] === true; //--- Is available for UseAsBlock appearance only.
  513. if($bUseAsBlock && $bShowClickable)
  514. $sClass .= ' bx-clickable';
  515. if($bUseAsBlock)
  516. $aTmplVars = array_merge($aTmplVars, [
  517. 'bx_if:show_clickable' => [
  518. 'condition' => $bShowClickable,
  519. 'content' => [
  520. 'content_url' => $sUrl
  521. ]
  522. ],
  523. 'bx_if:show_cover' => [
  524. 'condition' => $bTmplVarsShowCover,
  525. 'content' => $aTmplVarsShowCover
  526. ],
  527. 'bx_if:show_text' => [
  528. 'condition' => !isset($aParams['show_text']) || $aParams['show_text'] === true,
  529. 'content' => [
  530. 'text' => isset($CNF['FIELD_TEXT']) ? strmaxtextlen(strip_tags($aData[$CNF['FIELD_TEXT']]), 150) : ''
  531. ]
  532. ]
  533. ]);
  534. else
  535. $aTmplVars = array_merge($aTmplVars, $aTmplVarsShowCover, [
  536. 'bx_if:show_cover' => [
  537. 'condition' => $bUrlCover,
  538. 'content' => [true]
  539. ],
  540. 'bx_if:show_cover_placeholder' => [
  541. 'condition' => !$bUrlCover,
  542. 'content' => [true]
  543. ],
  544. ]);
  545. return $aTmplVars;
  546. }
  547. /**
  548. * Get profile cover
  549. */
  550. function setCover ($oPage, $aData, $sTemplateName = 'cover.html')
  551. {
  552. BxDolCover::getInstance($this)->set($this->prepareCover($aData, ['page' => $oPage]), $sTemplateName);
  553. }
  554. /**
  555. * Get profile picture thumb url
  556. * @deprecated since 11.0.0 use BxBaseModProfileTemplate::urlAvatar instead.
  557. */
  558. function avatar ($aData, $bSubstituteNoImage = true)
  559. {
  560. return $this->urlAvatar($aData, $bSubstituteNoImage);
  561. }
  562. /**
  563. * Get profile picture thumb url
  564. * @deprecated since 11.0.0 use BxBaseModProfileTemplate::urlThumb instead.
  565. */
  566. function thumb ($aData, $bSubstituteNoImage = true)
  567. {
  568. return $this->urlThumb($aData, $bSubstituteNoImage);
  569. }
  570. /**
  571. * Get profile picture thumb url
  572. * @deprecated since 11.0.0 use BxBaseModProfileTemplate::urlIcon instead.
  573. */
  574. function icon ($aData, $bSubstituteNoImage = true)
  575. {
  576. return $this->urlIcon($aData, $bSubstituteNoImage);
  577. }
  578. /**
  579. * Get profile picture icon url
  580. */
  581. function urlIcon ($aData, $bSubstituteNoImage = true)
  582. {
  583. $CNF = &$this->_oConfig->CNF;
  584. return $this->_image ($CNF['FIELD_PICTURE'], $CNF['OBJECT_IMAGES_TRANSCODER_ICON'], 'no-picture-icon.png', $aData, $bSubstituteNoImage);
  585. }
  586. /**
  587. * Get profile thumb url
  588. */
  589. function urlThumb ($aData, $bSubstituteNoImage = true)
  590. {
  591. $CNF = &$this->_oConfig->CNF;
  592. return $this->_image ($CNF['FIELD_PICTURE'], $CNF['OBJECT_IMAGES_TRANSCODER_THUMB'], 'no-picture-thumb.png', $aData, $bSubstituteNoImage);
  593. }
  594. /**
  595. * Get profile avatar url
  596. */
  597. function urlAvatar ($aData, $bSubstituteNoImage = true)
  598. {
  599. $CNF = &$this->_oConfig->CNF;
  600. $sDefault = bx_is_api() ? '' : 'no-picture-preview.png';
  601. return $this->_image ($CNF['FIELD_PICTURE'], $CNF['OBJECT_IMAGES_TRANSCODER_AVATAR'], $sDefault, $aData, $bSubstituteNoImage);
  602. }
  603. /**
  604. * Get profile avatar big url
  605. */
  606. function urlAvatarBig ($aData, $bSubstituteNoImage = true)
  607. {
  608. $CNF = &$this->_oConfig->CNF;
  609. return $this->_image ($CNF['FIELD_PICTURE'], $CNF['OBJECT_IMAGES_TRANSCODER_AVATAR_BIG'], 'no-picture-preview.png', $aData, $bSubstituteNoImage);
  610. }
  611. /**
  612. * Get profile picture url
  613. */
  614. function urlPicture ($aData, $bSubstituteNoImage = true)
  615. {
  616. $CNF = &$this->_oConfig->CNF;
  617. return $this->_image ($CNF['FIELD_PICTURE'], $CNF['OBJECT_IMAGES_TRANSCODER_PICTURE'], 'no-picture-preview.png', $aData, $bSubstituteNoImage);
  618. }
  619. /**
  620. * Get profile cover image url
  621. */
  622. function urlCover ($aData, $bSubstituteNoImage = false)
  623. {
  624. $CNF = &$this->_oConfig->CNF;
  625. $sImageUrl = $this->_image($CNF['FIELD_COVER'], $CNF['OBJECT_IMAGES_TRANSCODER_COVER'], '', $aData, $bSubstituteNoImage);
  626. return $sImageUrl;
  627. }
  628. /**
  629. * Get profile cover image url for browse unit
  630. */
  631. function urlCoverUnit ($aData, $bSubstituteNoImage = true)
  632. {
  633. $CNF = &$this->_oConfig->CNF;
  634. $sImageUrl = $this->_image ($CNF['FIELD_COVER'], $CNF['OBJECT_IMAGES_TRANSCODER_GALLERY'], '', $aData, false);
  635. if(!$bSubstituteNoImage || $sImageUrl)
  636. return $sImageUrl;
  637. $iImageId = (int)getParam('sys_unit_cover_profile');
  638. $oImageTranscoder = BxDolTranscoderImage::getObjectInstance(BX_DOL_TRANSCODER_OBJ_COVER_UNIT_PROFILE);
  639. if($oImageTranscoder && $iImageId != 0)
  640. $sImageUrl = $oImageTranscoder->getFileUrl($iImageId);
  641. if(!$sImageUrl)
  642. $sImageUrl = $this->getImageUrl('cover.svg');
  643. return $sImageUrl;
  644. }
  645. /**
  646. * Get profile picture icon url
  647. */
  648. function _image ($sField, $sTranscodeObject, $sNoImage, $aData, $bSubstituteNoImage = true)
  649. {
  650. $sImageUrl = false;
  651. if ($aData[$sField]) {
  652. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscodeObject);
  653. if ($oImagesTranscoder)
  654. $sImageUrl = $oImagesTranscoder->getFileUrl($aData[$sField]);
  655. }
  656. if(!$bSubstituteNoImage || $sImageUrl)
  657. return $sImageUrl;
  658. $sImageUrl = $this->getImageUrl($sNoImage);
  659. if(!$sImageUrl)
  660. $sImageUrl = bx_is_api() ? '' : $this->getImageUrl(substr($sNoImage, 0, strrpos($sNoImage, '-')) . '.svg');
  661. return $sImageUrl;
  662. }
  663. protected function _getUnitClass($aData, $sTemplateName = 'unit.html')
  664. {
  665. $sResult = '';
  666. switch($sTemplateName) {
  667. default:
  668. case 'unit.html':
  669. $sResult = $this->_sUnitClass;
  670. break;
  671. case 'unit_with_cover.html':
  672. $sResult = $this->_sUnitClassWithCover;
  673. break;
  674. case 'unit_wo_info.html':
  675. case 'unit_wo_info_links.html':
  676. $sResult = $this->_sUnitClassWoInfo;
  677. break;
  678. case 'unit_with_cover_showcase.html':
  679. $sResult = $this->_sUnitClassShowCase;
  680. break;
  681. case 'unit_wo_info_showcase.html':
  682. $sResult = $this->_sUnitClassWoInfoShowCase;
  683. break;
  684. }
  685. return $sResult;
  686. }
  687. protected function _getUnitSize($aData, $sTemplateName = 'unit.html')
  688. {
  689. $sResult = '';
  690. switch($sTemplateName) {
  691. case 'unit_with_cover.html':
  692. case 'unit_with_cover_showcase.html':
  693. $sResult = 'ava';
  694. break;
  695. default:
  696. $sResult = $this->_sUnitSizeDefault;
  697. break;
  698. }
  699. return $sResult;
  700. }
  701. protected function _getUnitThumbUrl($sSize, $aData, $bSubstituteNoImage = true)
  702. {
  703. $sMethod = 'url' . bx_gen_method_name(str_replace('ava', 'avatar', $sSize), array('_', '-'));
  704. if(method_exists($this, $sMethod))
  705. return $this->$sMethod($aData, $bSubstituteNoImage);
  706. else
  707. return $this->_getUnitThumbUrl($this->_sUnitSizeDefault, $aData, $bSubstituteNoImage);
  708. }
  709. }
  710. /** @} */