BxBaseModProfileTemplate.php 27 KB

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