BxBaseModProfileTemplate.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  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 = $this->_isUnitThumb($aData, $sTemplate) && $bPublicThumb ? $this->_getUnitThumbUrl($sTemplateSize, $aData, false) : '';
  151. $bThumbUrl = !empty($sThumbUrl);
  152. $aTmplVarsThumbnail = array(
  153. 'class_size' => '',
  154. 'bx_if:show_thumb_image' => array(
  155. 'condition' => $bThumbUrl,
  156. 'content' => array(
  157. 'class_size' => '',
  158. 'size' => $sTemplateSize,
  159. 'thumb_url' => $sThumbUrl
  160. )
  161. ),
  162. 'bx_if:show_thumb_letter' => array(
  163. 'condition' => !$bThumbUrl,
  164. 'content' => array(
  165. 'class_size' => '',
  166. 'size' => $sTemplateSize,
  167. 'color' => implode(', ', BxDolTemplate::getColorCode($iProfile, 1.0)),
  168. 'letter' => mb_strtoupper(mb_substr($sTitle, 0, 1))
  169. )
  170. ),
  171. 'bx_if:show_online' => array(
  172. 'condition' => $oProfile->isOnline(),
  173. 'content' => array()
  174. ),
  175. 'size' => $sTemplateSize,
  176. 'badges' => $oModule->serviceGetBadges($iContentId, false, true),
  177. 'thumb_url' => $bThumbUrl ? $sThumbUrl : $this->getImageUrl('no-picture-thumb.png'),
  178. );
  179. $aTmplVarsMeta = array();
  180. if(substr($sTemplate, 0, 8) != 'unit_wo_')
  181. $aTmplVarsMeta = $this->getSnippetMenuVars ($iProfile, $bPublic, $aParams);
  182. $sCoverData = isset($aData['cover_data']) ? $aData['cover_data'] : '';
  183. return array_merge(array (
  184. 'class' => $this->_getUnitClass($aData, $sTemplate) . (!$bCoverUrl ? ' bx-cover-empty' : ''),
  185. 'id' => $iContentId,
  186. 'public' => $bPublic,
  187. 'bx_if:show_thumbnail' => array(
  188. 'condition' => $bThumbUrl || $this->_bLetterAvatar,
  189. 'content' => $aTmplVarsThumbnail
  190. ),
  191. 'cover_url' => $sCoverUrl,
  192. 'cover_settings' => $this->_getImageSettings($sCoverData),
  193. 'bx_if:show_cover' => array(
  194. 'condition' => $bCoverUrl,
  195. 'content' => array(
  196. 'cover_url' => $sCoverUrl,
  197. 'cover_settins' => $this->_getImageSettings($sCoverData),
  198. 'title' => $sTitle,
  199. )
  200. ),
  201. 'content_url' => $bPublic ? $sUrl : 'javascript:void(0);',
  202. 'content_click' => !$bPublic ? 'javascript:bx_alert(' . bx_js_string('"' . _t('_sys_access_denied_to_private_content') . '"') . ');' : '',
  203. 'content_target' => !empty($aParams['link_target']) ? $aParams['link_target'] : '_self',
  204. 'title' => $sTitle,
  205. 'title_attr' => bx_html_attribute($sTitle),
  206. 'addon' => !empty($aData['addon']) ? $aData['addon'] : '',
  207. 'module_name' => _t($CNF['T']['txt_sample_single']),
  208. 'ts' => $aData[$CNF['FIELD_ADDED']],
  209. 'bx_if:meta' => array(
  210. 'condition' => !empty($aTmplVarsMeta),
  211. 'content' => $aTmplVarsMeta
  212. ),
  213. 'text' => $sText,
  214. 'summary' => $sSummary,
  215. ), $aTmplVarsThumbnail, $aTemplateVars);
  216. }
  217. function isProfilePublic($aData)
  218. {
  219. $CNF = &$this->_oConfig->CNF;
  220. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  221. if ($oPrivacy && !$oPrivacy->check($aData[$CNF['FIELD_ID']]) && !$oPrivacy->isPartiallyVisible($aData[$CNF['FIELD_ALLOW_VIEW_TO']]))
  222. return false;
  223. return true;
  224. }
  225. function getSnippetMenuVars ($iProfileId, $bPublic = null, $aParams = [])
  226. {
  227. $CNF = &$this->_oConfig->CNF;
  228. $oProfile = false;
  229. if(empty($CNF['OBJECT_MENU_SNIPPET_META']) || !($oProfile = BxDolProfile::getInstance($iProfileId)))
  230. return [];
  231. $oMetaMenu = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SNIPPET_META'], $this);
  232. if(!$oMetaMenu)
  233. return [];
  234. if ($bPublic === null) {
  235. $aData = $this->getModule()->serviceGetContentInfoById($oProfile->getContentId());
  236. $bPublic = $this->isProfilePublic($aData);
  237. }
  238. $oMetaMenu->setContentId($oProfile->getContentId());
  239. $oMetaMenu->setContentPublic($bPublic);
  240. if(isset($aParams['context']))
  241. $oMetaMenu->setContext($aParams['context']);
  242. return [
  243. 'meta' => $oMetaMenu->getCode()
  244. ];
  245. }
  246. function getBlockCover($aData, $aParams = [])
  247. {
  248. $CNF = &$this->_oConfig->CNF;
  249. $oProfile = BxDolProfile::getInstanceByContentAndType($aData[$CNF['FIELD_ID']], $this->MODULE);
  250. if(!$oProfile)
  251. return '';
  252. $aTmplVars = $this->prepareCover($aData, array_merge($aParams, [
  253. 'use_as_block' => true
  254. ]));
  255. $this->addCss(array('cover.css'));
  256. return $this->parseHtmlByName('cover_block.html', $aTmplVars);
  257. }
  258. function prepareCover($aData, $aParams = [])
  259. {
  260. $CNF = &$this->_oConfig->CNF;
  261. $oModule = $this->getModule();
  262. $sClass = isset($aParams['class']) ? $aParams['class'] : '';
  263. $sShowData = isset($aParams['show_data']) ? $aParams['show_data'] : '';
  264. $bShowCover = !isset($aParams['show_cover']) || $aParams['show_cover'] === true;
  265. $bShowAvatar = !isset($aParams['show_avatar']) || $aParams['show_avatar'] === true;
  266. $sAddCode = "";
  267. $bUseAsAuthor = isset($aParams['use_as_author']) && $aParams['use_as_author'] === true;
  268. $bUseAsBlock = $bUseAsAuthor || (isset($aParams['use_as_block']) && $aParams['use_as_block'] === true);
  269. if($bUseAsAuthor)
  270. $sClass .= ' bx-base-author';
  271. else
  272. BxDolTemplate::getInstance()->addInjection('injection_main_class', 'text', 'bx-base-profile-view');
  273. $bProfileViewAllowed = $oModule->checkAllowedView($aData) === CHECK_ACTION_RESULT_ALLOWED;
  274. if($oModule->checkAllowedViewProfileImage($aData) !== CHECK_ACTION_RESULT_ALLOWED)
  275. $aData[$CNF['FIELD_PICTURE']] = 0;
  276. if($oModule->checkAllowedViewCoverImage($aData) !== CHECK_ACTION_RESULT_ALLOWED)
  277. $aData[$CNF['FIELD_COVER']] = 0;
  278. $oProfile = BxDolProfile::getInstanceByContentAndType($aData[$CNF['FIELD_ID']], $this->MODULE);
  279. $iProfile = $oProfile->id();
  280. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aData[$CNF['FIELD_ID']]));
  281. $sTitle = bx_process_output($oProfile->getDisplayName());
  282. //--- Process Cover
  283. $bTmplVarsShowCover = $bShowCover;
  284. $aTmplVarsShowCover = [];
  285. if($bTmplVarsShowCover) {
  286. $sCoverPopupId = $this->MODULE . '-popup-cover';
  287. $bIsAllowEditCover = $oModule->checkAllowedChangeCover($aData) === CHECK_ACTION_RESULT_ALLOWED;
  288. $oPage = false;
  289. if(isset($aParams['page']) && is_a($aParams['page'], 'BxDolPage'))
  290. $oPage = $aParams['page'];
  291. $bUrlCover = false;
  292. $sUrlCover = $this->urlCover($aData, false);
  293. if(!$sUrlCover && $oPage !== false && $oPage->isPageCover()) {
  294. $aCover = $oPage->getPageCoverImage();
  295. if(!empty($aCover))
  296. $sUrlCover = BxDolCover::getCoverImageUrl($aCover);
  297. }
  298. if(!empty($sUrlCover)) {
  299. if(!$bUseAsAuthor)
  300. BxDolTemplate::getInstance()->addPageMetaImage($sUrlCover);
  301. $bUrlCover = true;
  302. }
  303. else
  304. $sUrlCover = $this->getImageUrl('cover.svg');
  305. $sAddClassCover = "";
  306. if(isset($CNF['FIELD_COVER']) && isset($CNF['OBJECT_UPLOADERS_COVER']) && isset($CNF['OBJECT_STORAGE_COVER']) && isset($CNF['OBJECT_IMAGES_TRANSCODER_COVER'])){
  307. /**
  308. * @hooks
  309. * @hookdef hook-system-image_editor 'system', 'image_editor' - hook to override profile cover editor
  310. * - $unit_name - equals `system`
  311. * - $action - equals `image_editor`
  312. * - $object_id - not used
  313. * - $sender_id - not used
  314. * - $extra_params - array of additional params with the following array keys:
  315. * - `module` - [string] module name
  316. * - `content_id` - [int] profile content id
  317. * - `is_allow_edit` - [boolean] if edit action is allowed to current user
  318. * - `image_type` - [string] image type equals to `cover`
  319. * - `image_url` - [string] image URL
  320. * - `uploader` - [string] uploader name
  321. * - `storage` - [string] storage name
  322. * - `transcoder` - [string] transcoder name
  323. * - `field` - [string] field name
  324. * - `is_background` - [boolean] if image is used as background, always `true`
  325. * - `add_class` - [string] by ref, class to add, can be overridden in hook processing
  326. * - `add_code` - [array] by ref, code to add, can be overridden in hook processing
  327. * @hook @ref hook-system-image_editor
  328. */
  329. bx_alert('system', 'image_editor', 0, 0, [
  330. 'module' => $oModule->getName(),
  331. 'content_id' => $aData[$CNF['FIELD_ID']],
  332. 'is_allow_edit' => $bIsAllowEditCover,
  333. 'image_type' => 'cover',
  334. 'image_url' => $CNF['FIELD_COVER'] && $aData[$CNF['FIELD_COVER']] ? $sUrlCover : '',
  335. 'uploader' => $CNF['OBJECT_UPLOADERS_COVER'][0],
  336. 'storage' => $CNF['OBJECT_STORAGE_COVER'],
  337. 'transcoder' => $CNF['OBJECT_IMAGES_TRANSCODER_COVER'],
  338. 'field' => $CNF['FIELD_COVER'],
  339. 'is_background' => true,
  340. 'add_class' => &$sAddClassCover,
  341. 'add_code' => &$sAddCode
  342. ]);
  343. }
  344. $sCoverTweak = '';
  345. $sUniqIdCover = genRndPwd (8, false);
  346. if ($bIsAllowEditCover && empty($sAddCode)){
  347. $sCoverTweak = $this->_prepareImage($aData, $sUniqIdCover, $CNF['OBJECT_UPLOADERS_COVER'], $CNF['OBJECT_STORAGE_COVER'], $CNF['FIELD_COVER'], true);
  348. }
  349. $aTmplVarsShowCover = [
  350. 'cover_popup_id' => $sCoverPopupId,
  351. 'cover_url' => $sUrlCover,
  352. 'unique_id' => $sUniqIdCover,
  353. 'cover_settins' => isset($CNF['FIELD_COVER_POSITION']) ? $this->_getImageSettings($aData[$CNF['FIELD_COVER_POSITION']]) : '',
  354. 'add_class' => $sAddClassCover,
  355. 'img_class' => $sAddClassCover != '' ? 'bx-media-editable-src' : '',
  356. ];
  357. }
  358. else
  359. $sClass .= ' bx-no-cover';
  360. //--- Process Avatar
  361. $sUrlAvatar = $this->urlAvatarBig($aData, false);
  362. $bUrlAvatar = !empty($sUrlAvatar);
  363. $bTmplVarsShowAvatar = $bShowAvatar && ($bUrlAvatar || $this->_bLetterAvatar);
  364. $aTmplVarsShowAvatar = [];
  365. $sPicturePopup = '';
  366. if($bTmplVarsShowAvatar) {
  367. $sPicturePopupId = $this->MODULE . '-popup-picture';
  368. $bIsAllowEditPicture = $oModule->checkAllowedEdit($aData) === CHECK_ACTION_RESULT_ALLOWED;
  369. $sUrlPicture = $this->urlPicture ($aData);
  370. $sUrlPictureChange = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_EDIT_ENTRY'] . '&id=' . $aData[$CNF['FIELD_ID']]));
  371. $sAddClassPicture = "";
  372. if(isset($CNF['FIELD_PICTURE']) && isset($CNF['OBJECT_UPLOADERS_PICTURE']) && isset($CNF['OBJECT_STORAGE']) && isset($CNF['OBJECT_IMAGES_TRANSCODER_THUMB'])){
  373. /**
  374. * @hooks
  375. * @hookdef hook-system-image_editor 'system', 'image_editor' - hook to override profile avatar editor
  376. * - $unit_name - equals `system`
  377. * - $action - equals `image_editor`
  378. * - $object_id - not used
  379. * - $sender_id - not used
  380. * - $extra_params - array of additional params with the following array keys:
  381. * - `module` - [string] module name
  382. * - `content_id` - [int] profile content id
  383. * - `is_allow_edit` - [boolean] if edit action is allowed to current user
  384. * - `image_type` - [string] image type equals to `avatar`
  385. * - `image_url` - [string] image URL
  386. * - `uploader` - [string] uploader name
  387. * - `storage` - [string] storage name
  388. * - `transcoder` - [string] transcoder name
  389. * - `field` - [string] field name
  390. * - `is_background` - [boolean] if image used is as background, always `false`
  391. * - `add_class` - [string] by ref, class to add, can be overridden in hook processing
  392. * - `add_code` - [array] by ref, code to add, can be overridden in hook processing
  393. * @hook @ref hook-system-image_editor
  394. */
  395. bx_alert('system', 'image_editor', 0, 0, [
  396. 'module' => $oModule->getName(),
  397. 'content_id' => $aData[$CNF['FIELD_ID']],
  398. 'is_allow_edit' => $bIsAllowEditPicture,
  399. 'image_type' => 'avatar',
  400. 'image_url' => $CNF['FIELD_PICTURE'] && $aData[$CNF['FIELD_PICTURE']] ? $sUrlPicture : '',
  401. 'uploader' => $CNF['OBJECT_UPLOADERS_PICTURE'][0],
  402. 'storage' => $CNF['OBJECT_STORAGE'],
  403. 'transcoder' => $CNF['OBJECT_IMAGES_TRANSCODER_AVATAR_BIG'],
  404. 'field' => $CNF['FIELD_PICTURE'],
  405. 'is_background' => false,
  406. 'add_class' => &$sAddClassPicture,
  407. 'add_code' => &$sAddCode
  408. ]);
  409. }
  410. $sPictureTweak = '';
  411. $sUniqIdPicture = genRndPwd (8, false);
  412. if ($bIsAllowEditPicture && empty($sAddCode)){
  413. $sPictureTweak = $this->_prepareImage($aData, $sUniqIdPicture, $CNF['OBJECT_UPLOADERS_PICTURE'], $CNF['OBJECT_STORAGE'], $CNF['FIELD_PICTURE'], false);
  414. }
  415. $aTmplVarsShowAvatar = array(
  416. 'add_class' => $sAddClassPicture,
  417. 'letter' => mb_strtoupper(mb_substr($sTitle, 0, 1)),
  418. 'img_class' => $sAddClassPicture != '' ? 'bx-media-editable-src' : '',
  419. 'ava_url' => $sUrlAvatar,
  420. 'color' => implode(', ', BxDolTemplate::getColorCode($iProfile, 1.0)),
  421. 'bx_if:show_ava_image' => array(
  422. 'condition' => $bUrlAvatar,
  423. 'content' => [true]
  424. ),
  425. 'bx_if:show_ava_letter' => array(
  426. 'condition' => !$bUrlAvatar,
  427. 'content' => [true]
  428. ),
  429. 'bx_if:show_online' => array(
  430. 'condition' => $oProfile->isOnline(),
  431. 'content' => [true]
  432. ),
  433. 'bx_if:is_avatar' => array(
  434. 'condition' => $bUrlAvatar,
  435. 'content' => [
  436. 'picture_popup_id' => $sPicturePopupId,
  437. 'picture_url' => $sUrlPicture,
  438. ]
  439. ),
  440. 'picture_avatar_url' => $bUrlAvatar ? $sUrlAvatar : $this->getImageUrl('no-picture-preview.png'),
  441. 'unique_id' => $sUniqIdPicture,
  442. 'picture_tweak' => $sPictureTweak,
  443. 'cover_settins' => isset($CNF['FIELD_PICTURE_POSITION']) ? $this->_getImageSettings($aData[$CNF['FIELD_PICTURE_POSITION']]) : '',
  444. 'picture_href' => (!$CNF['FIELD_PICTURE'] || !$aData[$CNF['FIELD_PICTURE']]) && CHECK_ACTION_RESULT_ALLOWED === $oModule->checkAllowedEdit($aData) ? $sUrlPictureChange : 'javascript:void(0);',
  445. );
  446. if($bProfileViewAllowed && $CNF['FIELD_PICTURE'] && $aData[$CNF['FIELD_PICTURE']]) {
  447. $sPicturePopup = BxTemplFunctions::getInstance()->transBox($sPicturePopupId, $this->parseHtmlByName('image_popup.html', [
  448. 'image_url' => $sUrlPicture,
  449. ]), true, true);
  450. }
  451. }
  452. //--- Process Actions menu
  453. $sActionsMenu = '';
  454. if(!isset($aParams['show_menu_actions']) || $aParams['show_menu_actions'] === true) {
  455. $sActionsMenu = $oModule->serviceEntityAllActions([$aData[$CNF['FIELD_ID']], $aData]);
  456. if(!$sActionsMenu && ($oMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY'], $this)) !== false)
  457. $sActionsMenu = $oMenu->getCode();
  458. }
  459. //--- Process Meta menu
  460. $sMetaMenu = '';
  461. if((!isset($aParams['show_menu_meta']) || $aParams['show_menu_meta'] === true) && !empty($CNF['OBJECT_MENU_VIEW_ENTRY_META'])) {
  462. $oMetaMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_VIEW_ENTRY_META']);
  463. if($oMetaMenu !== false) {
  464. $oMetaMenu->setContentId($aData[$CNF['FIELD_ID']]);
  465. $oMetaMenu->setContentPublic($this->isProfilePublic($aData));
  466. $sMetaMenu = $oMetaMenu->getCode();
  467. }
  468. }
  469. $aTmplVars = [
  470. 'module' => $this->_oConfig->getName(),
  471. 'class' => trim($sClass),
  472. 'id' => $aData[$CNF['FIELD_ID']],
  473. 'content_url' => $sUrl,
  474. 'title' => $sTitle,
  475. 'bx_if:show_title_as_tag' => [
  476. 'condition' => !$bUseAsAuthor,
  477. 'content' => [
  478. 'title' => $sTitle
  479. ]
  480. ],
  481. 'bx_if:show_title_as_text' => [
  482. 'condition' => $bUseAsAuthor,
  483. 'content' => [
  484. 'title' => $sTitle
  485. ]
  486. ],
  487. 'bx_if:show_avatar' => [
  488. 'condition' => $bTmplVarsShowAvatar,
  489. 'content' => $aTmplVarsShowAvatar
  490. ],
  491. 'bx_if:show_avatar_placeholder' => [
  492. 'condition' => !$bTmplVarsShowAvatar,
  493. 'content' => [true]
  494. ],
  495. 'badges' => $oModule->serviceGetBadges($aData[$CNF['FIELD_ID']]),
  496. 'action_menu' => $sActionsMenu,
  497. 'meta' => $sMetaMenu,
  498. 'show_data' => $sShowData,
  499. 'picture_popup' => $sPicturePopup,
  500. 'additional_code' => $sAddCode,
  501. 'cover_tweak' => $sCoverTweak,
  502. ];
  503. $bShowClickable = !isset($aParams['show_clickable']) || $aParams['show_clickable'] === true; //--- Is available for UseAsBlock appearance only.
  504. if($bUseAsBlock && $bShowClickable)
  505. $sClass .= ' bx-clickable';
  506. if($bUseAsBlock)
  507. $aTmplVars = array_merge($aTmplVars, [
  508. 'bx_if:show_clickable' => [
  509. 'condition' => $bShowClickable,
  510. 'content' => [
  511. 'content_url' => $sUrl
  512. ]
  513. ],
  514. 'bx_if:show_cover' => [
  515. 'condition' => $bTmplVarsShowCover,
  516. 'content' => $aTmplVarsShowCover
  517. ],
  518. 'bx_if:show_text' => [
  519. 'condition' => !isset($aParams['show_text']) || $aParams['show_text'] === true,
  520. 'content' => [
  521. 'text' => isset($CNF['FIELD_TEXT']) ? strmaxtextlen(strip_tags($aData[$CNF['FIELD_TEXT']]), 150) : ''
  522. ]
  523. ]
  524. ]);
  525. else
  526. $aTmplVars = array_merge($aTmplVars, $aTmplVarsShowCover, [
  527. 'bx_if:show_cover' => [
  528. 'condition' => $bUrlCover,
  529. 'content' => [true]
  530. ],
  531. 'bx_if:show_cover_placeholder' => [
  532. 'condition' => !$bUrlCover,
  533. 'content' => [true]
  534. ],
  535. ]);
  536. return $aTmplVars;
  537. }
  538. /**
  539. * Get profile cover
  540. */
  541. function setCover ($oPage, $aData, $sTemplateName = 'cover.html')
  542. {
  543. BxDolCover::getInstance($this)->set($this->prepareCover($aData, ['page' => $oPage]), $sTemplateName);
  544. }
  545. /**
  546. * Get profile picture thumb url
  547. * @deprecated since 11.0.0 use BxBaseModProfileTemplate::urlAvatar instead.
  548. */
  549. function avatar ($aData, $bSubstituteNoImage = true)
  550. {
  551. return $this->urlAvatar($aData, $bSubstituteNoImage);
  552. }
  553. /**
  554. * Get profile picture thumb url
  555. * @deprecated since 11.0.0 use BxBaseModProfileTemplate::urlThumb instead.
  556. */
  557. function thumb ($aData, $bSubstituteNoImage = true)
  558. {
  559. return $this->urlThumb($aData, $bSubstituteNoImage);
  560. }
  561. /**
  562. * Get profile picture thumb url
  563. * @deprecated since 11.0.0 use BxBaseModProfileTemplate::urlIcon instead.
  564. */
  565. function icon ($aData, $bSubstituteNoImage = true)
  566. {
  567. return $this->urlIcon($aData, $bSubstituteNoImage);
  568. }
  569. /**
  570. * Get profile picture icon url
  571. */
  572. function urlIcon ($aData, $bSubstituteNoImage = true)
  573. {
  574. $CNF = &$this->_oConfig->CNF;
  575. return $this->_image ($CNF['FIELD_PICTURE'], $CNF['OBJECT_IMAGES_TRANSCODER_ICON'], 'no-picture-icon.png', $aData, $bSubstituteNoImage);
  576. }
  577. /**
  578. * Get profile thumb url
  579. */
  580. function urlThumb ($aData, $bSubstituteNoImage = true)
  581. {
  582. $CNF = &$this->_oConfig->CNF;
  583. return $this->_image ($CNF['FIELD_PICTURE'], $CNF['OBJECT_IMAGES_TRANSCODER_THUMB'], 'no-picture-thumb.png', $aData, $bSubstituteNoImage);
  584. }
  585. /**
  586. * Get profile avatar url
  587. */
  588. function urlAvatar ($aData, $bSubstituteNoImage = true)
  589. {
  590. $CNF = &$this->_oConfig->CNF;
  591. $sDefault = bx_is_api() ? '' : 'no-picture-preview.png';
  592. return $this->_image ($CNF['FIELD_PICTURE'], $CNF['OBJECT_IMAGES_TRANSCODER_AVATAR'], $sDefault, $aData, $bSubstituteNoImage);
  593. }
  594. /**
  595. * Get profile avatar big url
  596. */
  597. function urlAvatarBig ($aData, $bSubstituteNoImage = true)
  598. {
  599. $CNF = &$this->_oConfig->CNF;
  600. return $this->_image ($CNF['FIELD_PICTURE'], $CNF['OBJECT_IMAGES_TRANSCODER_AVATAR_BIG'], 'no-picture-preview.png', $aData, $bSubstituteNoImage);
  601. }
  602. /**
  603. * Get profile picture url
  604. */
  605. function urlPicture ($aData, $bSubstituteNoImage = true)
  606. {
  607. $CNF = &$this->_oConfig->CNF;
  608. return $this->_image ($CNF['FIELD_PICTURE'], $CNF['OBJECT_IMAGES_TRANSCODER_PICTURE'], 'no-picture-preview.png', $aData, $bSubstituteNoImage);
  609. }
  610. /**
  611. * Get profile cover image url
  612. */
  613. function urlCover ($aData, $bSubstituteNoImage = false)
  614. {
  615. $CNF = &$this->_oConfig->CNF;
  616. $sImageUrl = $this->_image($CNF['FIELD_COVER'], $CNF['OBJECT_IMAGES_TRANSCODER_COVER'], '', $aData, $bSubstituteNoImage);
  617. return $sImageUrl;
  618. }
  619. /**
  620. * Get profile cover image url for browse unit
  621. */
  622. function urlCoverUnit ($aData, $bSubstituteNoImage = true)
  623. {
  624. $CNF = &$this->_oConfig->CNF;
  625. $sImageUrl = $this->_image ($CNF['FIELD_COVER'], $CNF['OBJECT_IMAGES_TRANSCODER_GALLERY'], '', $aData, false);
  626. if(!$bSubstituteNoImage || $sImageUrl)
  627. return $sImageUrl;
  628. $iImageId = (int)getParam('sys_unit_cover_profile');
  629. $oImageTranscoder = BxDolTranscoderImage::getObjectInstance(BX_DOL_TRANSCODER_OBJ_COVER_UNIT_PROFILE);
  630. if($oImageTranscoder && $iImageId != 0)
  631. $sImageUrl = $oImageTranscoder->getFileUrl($iImageId);
  632. if(!$sImageUrl)
  633. $sImageUrl = $this->getImageUrl('cover.svg');
  634. return $sImageUrl;
  635. }
  636. /**
  637. * Get profile picture icon url
  638. */
  639. function _image ($sField, $sTranscodeObject, $sNoImage, $aData, $bSubstituteNoImage = true)
  640. {
  641. $sImageUrl = false;
  642. if (isset($aData[$sField]) && $aData[$sField]) {
  643. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscodeObject);
  644. if ($oImagesTranscoder)
  645. $sImageUrl = $oImagesTranscoder->getFileUrl($aData[$sField]);
  646. }
  647. if(!$bSubstituteNoImage || $sImageUrl)
  648. return $sImageUrl;
  649. $sImageUrl = $this->getImageUrl($sNoImage);
  650. if(!$sImageUrl)
  651. $sImageUrl = bx_is_api() ? '' : $this->getImageUrl(substr($sNoImage, 0, strrpos($sNoImage, '-')) . '.svg');
  652. return $sImageUrl;
  653. }
  654. protected function _getUnitClass($aData, $sTemplateName = 'unit.html')
  655. {
  656. $sResult = '';
  657. switch($sTemplateName) {
  658. default:
  659. case 'unit.html':
  660. $sResult = $this->_sUnitClass;
  661. break;
  662. case 'unit_with_cover.html':
  663. $sResult = $this->_sUnitClassWithCover;
  664. break;
  665. case 'unit_wo_info.html':
  666. case 'unit_wo_info_links.html':
  667. $sResult = $this->_sUnitClassWoInfo;
  668. break;
  669. case 'unit_with_cover_showcase.html':
  670. $sResult = $this->_sUnitClassShowCase;
  671. break;
  672. case 'unit_wo_info_showcase.html':
  673. $sResult = $this->_sUnitClassWoInfoShowCase;
  674. break;
  675. }
  676. return $sResult;
  677. }
  678. protected function _getUnitSize($aData, $sTemplateName = 'unit.html')
  679. {
  680. $sResult = '';
  681. switch($sTemplateName) {
  682. case 'unit_with_cover.html':
  683. case 'unit_with_cover_showcase.html':
  684. $sResult = 'ava';
  685. break;
  686. default:
  687. $sResult = $this->_sUnitSizeDefault;
  688. break;
  689. }
  690. return $sResult;
  691. }
  692. protected function _isUnitThumb($aData, $sTemplateName = 'unit.html')
  693. {
  694. return true;
  695. }
  696. protected function _getUnitThumbUrl($sSize, $aData, $bSubstituteNoImage = true)
  697. {
  698. $sMethod = 'url' . bx_gen_method_name(str_replace('ava', 'avatar', $sSize), array('_', '-'));
  699. if(method_exists($this, $sMethod))
  700. return $this->$sMethod($aData, $bSubstituteNoImage);
  701. else
  702. return $this->_getUnitThumbUrl($this->_sUnitSizeDefault, $aData, $bSubstituteNoImage);
  703. }
  704. }
  705. /** @} */