BxBaseModProfileTemplate.php 31 KB

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