BxBaseModProfileTemplate.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  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 = array())
  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 = array(
  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. bx_alert('profile', 'unit', 0, 0, $aExtras);
  78. bx_alert($aExtras['module'], 'unit', 0, 0, $aExtras);
  79. return $this->parseHtmlByName($sTemplate, $aVars);
  80. }
  81. function unitVars ($aData, $isCheckPrivateContent = true, $mixedTemplate = false, $aParams = array())
  82. {
  83. $CNF = &$this->_oConfig->CNF;
  84. list($sTemplate, $sTemplateSize, $aTemplateVars) = is_array($mixedTemplate) ? $mixedTemplate : array($mixedTemplate, false, array());
  85. if(!empty($aParams['template_name']))
  86. $sTemplate = $aParams['template_name'];
  87. if(empty($sTemplate))
  88. $sTemplate = $this->_sUnitDefault;
  89. if(!empty($aParams['template_size']))
  90. $sTemplateSize = $aParams['template_size'];
  91. if(empty($sTemplateSize))
  92. $sTemplateSize = $this->_getUnitSize($aData, $sTemplate);
  93. if(!empty($aParams['template_vars']) && is_array($aParams['template_vars']))
  94. $aTemplateVars = $aParams['template_vars'];
  95. if(empty($aTemplateVars) || !is_array($aTemplateVars))
  96. $aTemplateVars = array();
  97. $oModule = $this->getModule();
  98. $iContentId = (int)$aData[$CNF['FIELD_ID']];
  99. $bPublic = $isCheckPrivateContent && !empty($CNF['OBJECT_PRIVACY_VIEW']) ? $this->isProfilePublic($aData) : true;
  100. $bPublicThumb = true;
  101. if($isCheckPrivateContent && $oModule->checkAllowedViewProfileImage($aData) !== CHECK_ACTION_RESULT_ALLOWED)
  102. $bPublicThumb = false;
  103. $bPublicCover = true;
  104. if($isCheckPrivateContent && $oModule->checkAllowedViewCoverImage($aData) !== CHECK_ACTION_RESULT_ALLOWED)
  105. $bPublicCover = false;
  106. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->MODULE);
  107. $iProfile = $oProfile->id();
  108. // get profile's url
  109. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId);
  110. // get profile's title
  111. $sTitle = $oModule->getProfileName($aData);
  112. $sText = $sSummary = '';
  113. if(!empty($CNF['FIELD_TEXT']) && !empty($aData[$CNF['FIELD_TEXT']])) {
  114. $sText = $this->getText($aData);
  115. $sSummary = $this->getSummary($aData, $sTitle, $sText, $sUrl);
  116. }
  117. $sCoverUrl = $bPublicCover ? $this->urlCoverUnit($aData, false) : '';
  118. $bCoverUrl = !empty($sCoverUrl);
  119. $bCoverImage = false;
  120. if(empty($sCoverUrl) && ($iCoverId = (int)getParam('sys_unit_cover_profile')) != 0)
  121. $sCoverUrl = BxDolTranscoder::getObjectInstance(BX_DOL_TRANSCODER_OBJ_COVER_UNIT_PROFILE)->getFileUrlById($iCoverId);
  122. if(empty($sCoverUrl))
  123. $sCoverUrl = $this->getImageUrl('cover.svg');
  124. else
  125. $bCoverImage = true;
  126. $sThumbUrl = $bPublicThumb ? $this->_getUnitThumbUrl($sTemplateSize, $aData, false) : '';
  127. $bThumbUrl = !empty($sThumbUrl);
  128. if(substr($sTemplate, 0, 13) == 'unit_wo_cover' && $bCoverImage && !$bThumbUrl){
  129. $bThumbUrl = true;
  130. $sThumbUrl = BxDolTranscoder::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_COVER_THUMB'])->getFileUrlById($aData[$CNF['FIELD_COVER']]);
  131. }
  132. $aTmplVarsThumbnail = array(
  133. 'bx_if:show_thumb_image' => array(
  134. 'condition' => $bThumbUrl,
  135. 'content' => array(
  136. 'size' => $sTemplateSize,
  137. 'thumb_url' => $sThumbUrl
  138. )
  139. ),
  140. 'bx_if:show_thumb_letter' => array(
  141. 'condition' => !$bThumbUrl,
  142. 'content' => array(
  143. 'size' => $sTemplateSize,
  144. 'color' => implode(', ', BxDolTemplate::getColorCode($iProfile, 1.0)),
  145. 'letter' => mb_strtoupper(mb_substr($sTitle, 0, 1))
  146. )
  147. ),
  148. 'bx_if:show_online' => array(
  149. 'condition' => $oProfile->isOnline(),
  150. 'content' => array()
  151. ),
  152. 'size' => $sTemplateSize,
  153. 'badges' => $oModule->serviceGetBadges($iContentId, false, true),
  154. 'thumb_url' => $bThumbUrl ? $sThumbUrl : $this->getImageUrl('no-picture-thumb.png'),
  155. );
  156. $aTmplVarsMeta = array();
  157. if(substr($sTemplate, 0, 8) != 'unit_wo_')
  158. $aTmplVarsMeta = $this->getSnippetMenuVars ($iProfile, $bPublic);
  159. return array_merge(array (
  160. 'class' => $this->_getUnitClass($aData, $sTemplate) . (!$bCoverUrl ? ' bx-cover-empty' : ''),
  161. 'id' => $iContentId,
  162. 'public' => $bPublic,
  163. 'bx_if:show_thumbnail' => array(
  164. 'condition' => $bThumbUrl || $this->_bLetterAvatar,
  165. 'content' => $aTmplVarsThumbnail
  166. ),
  167. 'cover_url' => $sCoverUrl,
  168. 'bx_if:show_cover' => array(
  169. 'condition' => $bCoverUrl,
  170. 'content' => array(
  171. 'cover_url' => $sCoverUrl,
  172. )
  173. ),
  174. 'content_url' => $bPublic ? $sUrl : 'javascript:void(0);',
  175. 'content_click' => !$bPublic ? 'javascript:bx_alert(' . bx_js_string('"' . _t('_sys_access_denied_to_private_content') . '"') . ');' : '',
  176. 'title' => $sTitle,
  177. 'title_attr' => bx_html_attribute($sTitle),
  178. 'addon' => !empty($aData['addon']) ? $aData['addon'] : '',
  179. 'module_name' => _t($CNF['T']['txt_sample_single']),
  180. 'ts' => $aData[$CNF['FIELD_ADDED']],
  181. 'bx_if:meta' => array(
  182. 'condition' => !empty($aTmplVarsMeta),
  183. 'content' => $aTmplVarsMeta
  184. ),
  185. 'text' => $sText,
  186. 'summary' => $sSummary,
  187. ), $aTmplVarsThumbnail, $aTemplateVars);
  188. }
  189. function isProfilePublic($aData)
  190. {
  191. $CNF = &$this->_oConfig->CNF;
  192. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  193. if ($oPrivacy && !$oPrivacy->check($aData[$CNF['FIELD_ID']]) && !$oPrivacy->isPartiallyVisible($aData[$CNF['FIELD_ALLOW_VIEW_TO']]))
  194. return false;
  195. return true;
  196. }
  197. function getSnippetMenuVars ($iProfileId, $bPublic = null)
  198. {
  199. if (!($oProfile = BxDolProfile::getInstance($iProfileId)))
  200. return array();
  201. $CNF = &$this->_oConfig->CNF;
  202. if (null === $bPublic) {
  203. $aData = $this->getModule()->serviceGetContentInfoById($oProfile->getContentId());
  204. $bPublic = $this->isProfilePublic($aData);
  205. }
  206. $aTmplVarsMeta = array();
  207. if (!empty($CNF['OBJECT_MENU_SNIPPET_META'])) {
  208. $oMenuMeta = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SNIPPET_META'], $this);
  209. if($oMenuMeta) {
  210. $oMenuMeta->setContentId($oProfile->getContentId());
  211. $oMenuMeta->setContentPublic($bPublic);
  212. $aTmplVarsMeta = array(
  213. 'meta' => $oMenuMeta->getCode()
  214. );
  215. }
  216. }
  217. return $aTmplVarsMeta;
  218. }
  219. function getBlockCover($aData, $aParams = [])
  220. {
  221. $CNF = &$this->_oConfig->CNF;
  222. $oProfile = BxDolProfile::getInstanceByContentAndType($aData[$CNF['FIELD_ID']], $this->MODULE);
  223. if(!$oProfile)
  224. return '';
  225. $aTmplVars = $this->prepareCover($aData, array_merge($aParams, [
  226. 'use_as_block' => true
  227. ]));
  228. return $this->parseHtmlByName('cover_block.html', $aTmplVars);
  229. }
  230. function prepareCover($aData, $aParams = [])
  231. {
  232. $CNF = &$this->_oConfig->CNF;
  233. $oModule = $this->getModule();
  234. $sClass = isset($aParams['class']) ? $aParams['class'] : '';
  235. $sShowData = isset($aParams['show_data']) ? $aParams['show_data'] : '';
  236. $bShowCover = !isset($aParams['show_cover']) || $aParams['show_cover'] === true;
  237. $bShowAvatar = !isset($aParams['show_avatar']) || $aParams['show_avatar'] === true;
  238. $sAddCode = "";
  239. $bUseAsAuthor = isset($aParams['use_as_author']) && $aParams['use_as_author'] === true;
  240. $bUseAsBlock = $bUseAsAuthor || (isset($aParams['use_as_block']) && $aParams['use_as_block'] === true);
  241. if(!$bUseAsAuthor)
  242. BxDolTemplate::getInstance()->addInjection('injection_main_class', 'text', 'bx-base-profile-view');
  243. $bProfileViewAllowed = $oModule->checkAllowedView($aData) === CHECK_ACTION_RESULT_ALLOWED;
  244. if($oModule->checkAllowedViewProfileImage($aData) !== CHECK_ACTION_RESULT_ALLOWED)
  245. $aData[$CNF['FIELD_PICTURE']] = 0;
  246. if($oModule->checkAllowedViewCoverImage($aData) !== CHECK_ACTION_RESULT_ALLOWED)
  247. $aData[$CNF['FIELD_COVER']] = 0;
  248. $oProfile = BxDolProfile::getInstanceByContentAndType($aData[$CNF['FIELD_ID']], $this->MODULE);
  249. $iProfile = $oProfile->id();
  250. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aData[$CNF['FIELD_ID']]);
  251. $sTitle = bx_process_output($oProfile->getDisplayName());
  252. //--- Process Cover
  253. $bTmplVarsShowCover = $bShowCover;
  254. $aTmplVarsShowCover = [];
  255. $sCoverPopup = '';
  256. if($bTmplVarsShowCover) {
  257. $sCoverPopupId = $this->MODULE . '-popup-cover';
  258. $bIsAllowEditCover = $oModule->checkAllowedChangeCover($aData) === CHECK_ACTION_RESULT_ALLOWED;
  259. $oPage = false;
  260. if(isset($aParams['page']) && is_a($aParams['page'], 'BxDolPage'))
  261. $oPage = $aParams['page'];
  262. $bUrlCover = false;
  263. $sUrlCover = $this->urlCover($aData, false);
  264. if(!$sUrlCover && $oPage !== false && $oPage->isPageCover()) {
  265. $aCover = $oPage->getPageCoverImage();
  266. if(!empty($aCover))
  267. $sUrlCover = BxDolCover::getCoverImageUrl($aCover);
  268. }
  269. if(!empty($sUrlCover)) {
  270. if(!$bUseAsAuthor)
  271. BxDolTemplate::getInstance()->addPageMetaImage($sUrlCover);
  272. $bUrlCover = true;
  273. }
  274. else
  275. $sUrlCover = $this->getImageUrl('cover.svg');
  276. $sUrlCoverChange = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_EDIT_COVER'] . '&id=' . $aData[$CNF['FIELD_ID']]);
  277. $sAddClassCover = "";
  278. if(isset($CNF['FIELD_COVER']) && isset($CNF['OBJECT_UPLOADERS_COVER']) && isset($CNF['OBJECT_STORAGE_COVER']) && isset($CNF['OBJECT_IMAGES_TRANSCODER_COVER'])){
  279. bx_alert('system', 'image_editor', 0, 0, array(
  280. 'module' => $oModule->getName(),
  281. 'image_type' => 'cover',
  282. 'is_allow_edit' => $bIsAllowEditCover,
  283. 'image_url' => $aData[$CNF['FIELD_COVER']] ? $sUrlCover : '',
  284. 'content_id' => $aData[$CNF['FIELD_ID']],
  285. 'uploader' => $CNF['OBJECT_UPLOADERS_COVER'][0],
  286. 'storage' => $CNF['OBJECT_STORAGE_COVER'],
  287. 'transcoder' => $CNF['OBJECT_IMAGES_TRANSCODER_COVER'],
  288. 'field' => $CNF['FIELD_COVER'],
  289. 'is_background' => true,
  290. 'add_class' => &$sAddClassCover,
  291. 'add_code' => &$sAddCode
  292. ));
  293. }
  294. $aTmplVarsShowCover = [
  295. 'cover_popup_id' => $sCoverPopupId,
  296. 'cover_url' => $sUrlCover,
  297. 'cover_href' => !$aData[$CNF['FIELD_COVER']] && $bIsAllowEditCover ? $sUrlCoverChange : 'javascript:void(0);',
  298. 'add_class' => $sAddClassCover,
  299. 'img_class' => $sAddClassCover != '' ? 'bx-media-editable-src' : '',
  300. ];
  301. if($bProfileViewAllowed && $aData[$CNF['FIELD_COVER']]) {
  302. $sCoverPopup = BxTemplFunctions::getInstance()->transBox($sCoverPopupId, $this->parseHtmlByName('image_popup.html', array (
  303. 'image_url' => $sUrlCover,
  304. 'bx_if:owner' => array (
  305. 'condition' => $bIsAllowEditCover && empty($sAddClassCover),
  306. 'content' => array (
  307. 'change_image_url' => $sUrlCoverChange,
  308. ),
  309. ),
  310. )), true, true);
  311. }
  312. }
  313. else
  314. $sClass .= ' bx-no-cover';
  315. //--- Process Avatar
  316. $sUrlAvatar = $this->urlAvatarBig($aData, false);
  317. $bUrlAvatar = !empty($sUrlAvatar);
  318. $bTmplVarsShowAvatar = $bShowAvatar && ($bUrlAvatar || $this->_bLetterAvatar);
  319. $aTmplVarsShowAvatar = [];
  320. $sPicturePopup = '';
  321. if($bTmplVarsShowAvatar) {
  322. $sPicturePopupId = $this->MODULE . '-popup-picture';
  323. $bIsAllowEditPicture = $oModule->checkAllowedEdit($aData) === CHECK_ACTION_RESULT_ALLOWED;
  324. $sUrlPicture = $this->urlPicture ($aData);
  325. $sUrlPictureChange = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_EDIT_ENTRY'] . '&id=' . $aData[$CNF['FIELD_ID']]);
  326. $sAddClassPicture = "";
  327. if(isset($CNF['FIELD_PICTURE']) && isset($CNF['OBJECT_UPLOADERS_PICTURE']) && isset($CNF['OBJECT_STORAGE']) && isset($CNF['OBJECT_IMAGES_TRANSCODER_THUMB'])){
  328. bx_alert('system', 'image_editor', 0, 0, array(
  329. 'module' => $oModule->getName(),
  330. 'image_type' => 'avatar',
  331. 'is_allow_edit' => $bIsAllowEditPicture,
  332. 'image_url' => $aData[$CNF['FIELD_PICTURE']] ? $sUrlPicture : '',
  333. 'content_id' => $aData[$CNF['FIELD_ID']],
  334. 'uploader' => $CNF['OBJECT_UPLOADERS_PICTURE'][0],
  335. 'storage' => $CNF['OBJECT_STORAGE'],
  336. 'transcoder' => $CNF['OBJECT_IMAGES_TRANSCODER_AVATAR_BIG'],
  337. 'field' => $CNF['FIELD_PICTURE'],
  338. 'is_background' => false,
  339. 'add_class' => &$sAddClassPicture,
  340. 'add_code' => &$sAddCode
  341. ));
  342. }
  343. $aTmplVarsShowAvatar = array(
  344. 'add_class' => $sAddClassPicture,
  345. 'letter' => mb_substr($sTitle, 0, 1),
  346. 'img_class' => $sAddClassPicture != '' ? 'bx-media-editable-src' : '',
  347. 'ava_url' => $sUrlAvatar,
  348. 'color' => implode(', ', BxDolTemplate::getColorCode($iProfile, 1.0)),
  349. 'bx_if:show_ava_image' => array(
  350. 'condition' => $bUrlAvatar,
  351. 'content' => array()
  352. ),
  353. 'bx_if:show_ava_letter' => array(
  354. 'condition' => !$bUrlAvatar,
  355. 'content' => array()
  356. ),
  357. 'bx_if:show_online' => array(
  358. 'condition' => $oProfile->isOnline(),
  359. 'content' => array()
  360. ),
  361. 'picture_avatar_url' => $bUrlAvatar ? $sUrlAvatar : $this->getImageUrl('no-picture-preview.png'),
  362. 'picture_popup_id' => $sPicturePopupId,
  363. 'picture_url' => $sUrlPicture,
  364. 'picture_href' => !$aData[$CNF['FIELD_PICTURE']] && CHECK_ACTION_RESULT_ALLOWED === $oModule->checkAllowedEdit($aData) ? $sUrlPictureChange : 'javascript:void(0);',
  365. );
  366. if($bProfileViewAllowed && $aData[$CNF['FIELD_PICTURE']]) {
  367. $sPicturePopup = BxTemplFunctions::getInstance()->transBox($sPicturePopupId, $this->parseHtmlByName('image_popup.html', array (
  368. 'image_url' => $sUrlPicture,
  369. 'bx_if:owner' => array (
  370. 'condition' => $bIsAllowEditPicture && empty($sAddClassPicture),
  371. 'content' => array (
  372. 'change_image_url' => $sUrlPictureChange,
  373. ),
  374. ),
  375. )), true, true);
  376. }
  377. }
  378. //--- Process Actions menu
  379. $sActionsMenu = '';
  380. if(!isset($aParams['show_menu_actions']) || $aParams['show_menu_actions'] === true) {
  381. $sActionsMenu = $oModule->serviceEntityAllActions([$aData[$CNF['FIELD_ID']], $aData]);
  382. if(!$sActionsMenu && ($oMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY'], $this)) !== false)
  383. $sActionsMenu = $oMenu->getCode();
  384. }
  385. //--- Process Meta menu
  386. $sMetaMenu = '';
  387. if((!isset($aParams['show_menu_meta']) || $aParams['show_menu_meta'] === true) && !empty($CNF['OBJECT_MENU_VIEW_ENTRY_META'])) {
  388. $oMetaMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_VIEW_ENTRY_META']);
  389. if($oMetaMenu !== false) {
  390. $oMetaMenu->setContentId($aData[$CNF['FIELD_ID']]);
  391. $oMetaMenu->setContentPublic($this->isProfilePublic($aData));
  392. $sMetaMenu = $oMetaMenu->getCode();
  393. }
  394. }
  395. $aTmplVars = [
  396. 'module' => $this->_oConfig->getName(),
  397. 'class' => $sClass,
  398. 'id' => $aData[$CNF['FIELD_ID']],
  399. 'content_url' => $sUrl,
  400. 'title' => $sTitle,
  401. 'bx_if:show_avatar' => [
  402. 'condition' => $bTmplVarsShowAvatar,
  403. 'content' => $aTmplVarsShowAvatar
  404. ],
  405. 'bx_if:show_avatar_placeholder' => [
  406. 'condition' => !$bTmplVarsShowAvatar,
  407. 'content' => []
  408. ],
  409. 'badges' => $oModule->serviceGetBadges($aData[$CNF['FIELD_ID']]),
  410. 'action_menu' => $sActionsMenu,
  411. 'meta' => $sMetaMenu,
  412. 'show_data' => $sShowData,
  413. 'picture_popup' => $sPicturePopup,
  414. 'cover_popup' => $sCoverPopup,
  415. 'additional_code' => $sAddCode,
  416. ];
  417. if($bUseAsBlock)
  418. $aTmplVars = array_merge($aTmplVars, [
  419. 'bx_if:show_cover' => [
  420. 'condition' => $bTmplVarsShowCover,
  421. 'content' => $aTmplVarsShowCover
  422. ],
  423. 'bx_if:show_text' => [
  424. 'condition' => !isset($aParams['show_text']) || $aParams['show_text'] === true,
  425. 'content' => [
  426. 'text' => isset($CNF['FIELD_TEXT']) ? strmaxtextlen(strip_tags($aData[$CNF['FIELD_TEXT']]), 150) : ''
  427. ]
  428. ]
  429. ]);
  430. else
  431. $aTmplVars = array_merge($aTmplVars, $aTmplVarsShowCover, [
  432. 'bx_if:show_cover' => [
  433. 'condition' => $bUrlCover,
  434. 'content' => []
  435. ],
  436. 'bx_if:show_cover_placeholder' => [
  437. 'condition' => !$bUrlCover,
  438. 'content' => []
  439. ],
  440. ]);
  441. return $aTmplVars;
  442. }
  443. /**
  444. * Get profile cover
  445. */
  446. function setCover ($oPage, $aData, $sTemplateName = 'cover.html')
  447. {
  448. BxDolCover::getInstance($this)->set($this->prepareCover($aData, ['page' => $oPage]), $sTemplateName);
  449. }
  450. /**
  451. * Get profile picture thumb url
  452. * @deprecated since 11.0.0 use BxBaseModProfileTemplate::urlAvatar instead.
  453. */
  454. function avatar ($aData, $bSubstituteNoImage = true)
  455. {
  456. return $this->urlAvatar($aData, $bSubstituteNoImage);
  457. }
  458. /**
  459. * Get profile picture thumb url
  460. * @deprecated since 11.0.0 use BxBaseModProfileTemplate::urlThumb instead.
  461. */
  462. function thumb ($aData, $bSubstituteNoImage = true)
  463. {
  464. return $this->urlThumb($aData, $bSubstituteNoImage);
  465. }
  466. /**
  467. * Get profile picture thumb url
  468. * @deprecated since 11.0.0 use BxBaseModProfileTemplate::urlIcon instead.
  469. */
  470. function icon ($aData, $bSubstituteNoImage = true)
  471. {
  472. return $this->urlIcon($aData, $bSubstituteNoImage);
  473. }
  474. /**
  475. * Get profile picture icon url
  476. */
  477. function urlIcon ($aData, $bSubstituteNoImage = true)
  478. {
  479. $CNF = &$this->_oConfig->CNF;
  480. return $this->_image ($CNF['FIELD_PICTURE'], $CNF['OBJECT_IMAGES_TRANSCODER_ICON'], 'no-picture-icon.png', $aData, $bSubstituteNoImage);
  481. }
  482. /**
  483. * Get profile thumb url
  484. */
  485. function urlThumb ($aData, $bSubstituteNoImage = true)
  486. {
  487. $CNF = &$this->_oConfig->CNF;
  488. return $this->_image ($CNF['FIELD_PICTURE'], $CNF['OBJECT_IMAGES_TRANSCODER_THUMB'], 'no-picture-thumb.png', $aData, $bSubstituteNoImage);
  489. }
  490. /**
  491. * Get profile avatar url
  492. */
  493. function urlAvatar ($aData, $bSubstituteNoImage = true)
  494. {
  495. $CNF = &$this->_oConfig->CNF;
  496. return $this->_image ($CNF['FIELD_PICTURE'], $CNF['OBJECT_IMAGES_TRANSCODER_AVATAR'], 'no-picture-preview.png', $aData, $bSubstituteNoImage);
  497. }
  498. /**
  499. * Get profile avatar big url
  500. */
  501. function urlAvatarBig ($aData, $bSubstituteNoImage = true)
  502. {
  503. $CNF = &$this->_oConfig->CNF;
  504. return $this->_image ($CNF['FIELD_PICTURE'], $CNF['OBJECT_IMAGES_TRANSCODER_AVATAR_BIG'], 'no-picture-preview.png', $aData, $bSubstituteNoImage);
  505. }
  506. /**
  507. * Get profile picture url
  508. */
  509. function urlPicture ($aData, $bSubstituteNoImage = true)
  510. {
  511. $CNF = &$this->_oConfig->CNF;
  512. return $this->_image ($CNF['FIELD_PICTURE'], $CNF['OBJECT_IMAGES_TRANSCODER_PICTURE'], 'no-picture-preview.png', $aData, $bSubstituteNoImage);
  513. }
  514. /**
  515. * Get profile cover image url
  516. */
  517. function urlCover ($aData, $bSubstituteNoImage = false)
  518. {
  519. $CNF = &$this->_oConfig->CNF;
  520. $sImageUrl = $this->_image($CNF['FIELD_COVER'], $CNF['OBJECT_IMAGES_TRANSCODER_COVER'], '', $aData, $bSubstituteNoImage);
  521. return $sImageUrl;
  522. }
  523. /**
  524. * Get profile cover image url for browse unit
  525. */
  526. function urlCoverUnit ($aData, $bSubstituteNoImage = true)
  527. {
  528. $CNF = &$this->_oConfig->CNF;
  529. $sImageUrl = $this->_image ($CNF['FIELD_COVER'], $CNF['OBJECT_IMAGES_TRANSCODER_GALLERY'], '', $aData, false);
  530. if($sImageUrl === false) {
  531. $iImageId = (int)getParam('sys_unit_cover_profile');
  532. $oImageTranscoder = BxDolTranscoderImage::getObjectInstance(BX_DOL_TRANSCODER_OBJ_COVER_UNIT_PROFILE);
  533. if($oImageTranscoder && $iImageId != 0)
  534. $sImageUrl = $oImageTranscoder->getFileUrl($iImageId);
  535. }
  536. if($bSubstituteNoImage && !$sImageUrl)
  537. $sImageUrl = $this->getImageUrl('cover.svg');
  538. return $sImageUrl;
  539. }
  540. /**
  541. * Get profile picture icon url
  542. */
  543. function _image ($sField, $sTranscodeObject, $sNoImage, $aData, $bSubstituteNoImage = true)
  544. {
  545. $sImageUrl = false;
  546. if ($aData[$sField]) {
  547. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscodeObject);
  548. if ($oImagesTranscoder)
  549. $sImageUrl = $oImagesTranscoder->getFileUrl($aData[$sField]);
  550. }
  551. return $bSubstituteNoImage && !$sImageUrl ? $this->getImageUrl($sNoImage) : $sImageUrl;
  552. }
  553. protected function _getUnitClass($aData, $sTemplateName = 'unit.html')
  554. {
  555. $sResult = '';
  556. switch($sTemplateName) {
  557. default:
  558. case 'unit.html':
  559. $sResult = $this->_sUnitClass;
  560. break;
  561. case 'unit_with_cover.html':
  562. $sResult = $this->_sUnitClassWithCover;
  563. break;
  564. case 'unit_wo_info.html':
  565. case 'unit_wo_info_links.html':
  566. $sResult = $this->_sUnitClassWoInfo;
  567. break;
  568. case 'unit_with_cover_showcase.html':
  569. $sResult = $this->_sUnitClassShowCase;
  570. break;
  571. case 'unit_wo_info_showcase.html':
  572. $sResult = $this->_sUnitClassWoInfoShowCase;
  573. break;
  574. }
  575. return $sResult;
  576. }
  577. protected function _getUnitSize($aData, $sTemplateName = 'unit.html')
  578. {
  579. $sResult = '';
  580. switch($sTemplateName) {
  581. case 'unit_with_cover.html':
  582. case 'unit_with_cover_showcase.html':
  583. $sResult = 'ava';
  584. break;
  585. default:
  586. $sResult = $this->_sUnitSizeDefault;
  587. break;
  588. }
  589. return $sResult;
  590. }
  591. protected function _getUnitThumbUrl($sSize, $aData, $bSubstituteNoImage = true)
  592. {
  593. $sMethod = 'url' . bx_gen_method_name(str_replace('ava', 'avatar', $sSize), array('_', '-'));
  594. if(method_exists($this, $sMethod))
  595. return $this->$sMethod($aData, $bSubstituteNoImage);
  596. else
  597. return $this->_getUnitThumbUrl($this->_sUnitSizeDefault, $aData, $bSubstituteNoImage);
  598. }
  599. }
  600. /** @} */