BxBaseModProfileTemplate.php 29 KB

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