BxBaseModProfileTemplate.php 31 KB

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