BxBaseModProfileTemplate.php 37 KB

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