BxBaseModProfileTemplate.php 36 KB

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