BxBaseModProfileTemplate.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  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),
  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)
  213. {
  214. $CNF = &$this->_oConfig->CNF;
  215. $oProfile = BxDolProfile::getInstanceByContentAndType($aData[$CNF['FIELD_ID']], $this->MODULE);
  216. if(!$oProfile)
  217. return '';
  218. $aVars = $this->prepareCover($aData, false);
  219. $oConnectionFriends = BxDolConnection::getObjectInstance('sys_profiles_friends');
  220. $oConnectionFollowing = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  221. $aVars2 = [
  222. 'bx_if:show_following' => array (
  223. 'condition' => $oConnectionFollowing && $this->_oModule->serviceActAsProfile(),
  224. 'content' => array (
  225. 'count' => $oConnectionFollowing->getConnectedContentCount($oProfile->id(), false),
  226. ),
  227. ),
  228. 'bx_if:show_followers' => array (
  229. 'condition' => $oConnectionFollowing,
  230. 'content' => array (
  231. 'count' => $oConnectionFollowing->getConnectedInitiatorsCount($oProfile->id(), false),
  232. ),
  233. ),
  234. 'bx_if:show_friends' => array (
  235. 'condition' => $oConnectionFriends && $this->_oModule->serviceActAsProfile(),
  236. 'content' => array (
  237. 'count' => $oConnectionFriends->getConnectedContentCount($oProfile->id(), true),
  238. ),
  239. ),
  240. 'info' => isset($CNF['FIELD_TEXT']) ? $aData[$CNF['FIELD_TEXT']] : ''
  241. ];
  242. return $this->parseHtmlByName('cover_block.html', array_merge($aVars, $aVars2));
  243. }
  244. function prepareCover($aData, $oPage)
  245. {
  246. $CNF = &$this->_oConfig->CNF;
  247. $oModule = $this->getModule();
  248. BxDolTemplate::getInstance()->addInjection('injection_main_class', 'text', 'bx-base-profile-view');
  249. $bProfileViewAllowed = CHECK_ACTION_RESULT_ALLOWED === $oModule->checkAllowedView($aData);
  250. if (CHECK_ACTION_RESULT_ALLOWED !== $oModule->checkAllowedViewProfileImage($aData))
  251. $aData[$CNF['FIELD_PICTURE']] = 0;
  252. if (CHECK_ACTION_RESULT_ALLOWED !== $oModule->checkAllowedViewCoverImage($aData))
  253. $aData[$CNF['FIELD_COVER']] = 0;
  254. $oProfile = BxDolProfile::getInstanceByContentAndType($aData[$CNF['FIELD_ID']], $this->MODULE);
  255. $iProfile = $oProfile->id();
  256. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aData[$CNF['FIELD_ID']]);
  257. $sTitle = bx_process_output($oProfile->getDisplayName());
  258. $sUrlAvatar = $this->urlAvatarBig($aData, false);
  259. $bUrlAvatar = !empty($sUrlAvatar);
  260. $sUrlPicture = $this->urlPicture ($aData);
  261. $sUrlPictureChange = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_EDIT_ENTRY'] . '&id=' . $aData[$CNF['FIELD_ID']]);
  262. $sUrlCover = $this->urlCover ($aData, false);
  263. if(!$sUrlCover && $oPage !== false && $oPage->isPageCover()) {
  264. $aCover = $oPage->getPageCoverImage();
  265. if(!empty($aCover))
  266. $sUrlCover = BxDolCover::getCoverImageUrl($aCover);
  267. }
  268. if(!$sUrlCover)
  269. $sUrlCover = $this->getImageUrl('cover.svg');
  270. else
  271. BxDolTemplate::getInstance()->addPageMetaImage($sUrlCover);
  272. $sUrlCoverChange = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_EDIT_COVER'] . '&id=' . $aData[$CNF['FIELD_ID']]);
  273. $bIsAllowEditCover = CHECK_ACTION_RESULT_ALLOWED === $oModule->checkAllowedChangeCover($aData);
  274. $bIsAllowEditPicture = CHECK_ACTION_RESULT_ALLOWED === $oModule->checkAllowedEdit($aData);
  275. $sAddClassCover = "";
  276. $sAddClassPicture = "";
  277. $sAddCode = "";
  278. if(isset($CNF['FIELD_COVER']) && isset($CNF['OBJECT_UPLOADERS_COVER']) && isset($CNF['OBJECT_STORAGE_COVER']) && isset($CNF['OBJECT_IMAGES_TRANSCODER_COVER'])){
  279. bx_alert('system', 'image_editor', 0, 0, array(
  280. 'module' => $oModule->getName(),
  281. 'image_type' => 'cover',
  282. 'is_allow_edit' => $bIsAllowEditCover,
  283. 'image_url' => $aData[$CNF['FIELD_COVER']] ? $sUrlCover : '',
  284. 'content_id' => $aData[$CNF['FIELD_ID']],
  285. 'uploader' => $CNF['OBJECT_UPLOADERS_COVER'][0],
  286. 'storage' => $CNF['OBJECT_STORAGE_COVER'],
  287. 'transcoder' => $CNF['OBJECT_IMAGES_TRANSCODER_COVER'],
  288. 'field' => $CNF['FIELD_COVER'],
  289. 'is_background' => true,
  290. 'add_class' => &$sAddClassCover,
  291. 'add_code' => &$sAddCode
  292. ));
  293. }
  294. if(isset($CNF['FIELD_PICTURE']) && isset($CNF['OBJECT_UPLOADERS_PICTURE']) && isset($CNF['OBJECT_STORAGE']) && isset($CNF['OBJECT_IMAGES_TRANSCODER_THUMB'])){
  295. bx_alert('system', 'image_editor', 0, 0, array(
  296. 'module' => $oModule->getName(),
  297. 'image_type' => 'avatar',
  298. 'is_allow_edit' => $bIsAllowEditPicture,
  299. 'image_url' => $aData[$CNF['FIELD_PICTURE']] ? $sUrlPicture : '',
  300. 'content_id' => $aData[$CNF['FIELD_ID']],
  301. 'uploader' => $CNF['OBJECT_UPLOADERS_PICTURE'][0],
  302. 'storage' => $CNF['OBJECT_STORAGE'],
  303. 'transcoder' => $CNF['OBJECT_IMAGES_TRANSCODER_THUMB'],
  304. 'field' => $CNF['FIELD_PICTURE'],
  305. 'is_background' => false,
  306. 'add_class' => &$sAddClassPicture,
  307. 'add_code' => &$sAddCode
  308. ));
  309. }
  310. $sCoverPopup = '';
  311. $sCoverPopupId = $this->MODULE . '-popup-cover';
  312. if($bProfileViewAllowed && $aData[$CNF['FIELD_COVER']]) {
  313. $sCoverPopup = BxTemplFunctions::getInstance()->transBox($sCoverPopupId, $this->parseHtmlByName('image_popup.html', array (
  314. 'image_url' => $sUrlCover,
  315. 'bx_if:owner' => array (
  316. 'condition' => $bIsAllowEditCover && empty($sAddClassCover),
  317. 'content' => array (
  318. 'change_image_url' => $sUrlCoverChange,
  319. ),
  320. ),
  321. )), true, true);
  322. }
  323. $bShowAvatar = $bUrlAvatar || $this->_bLetterAvatar;
  324. $aShowAvatar = array();
  325. $sPicturePopup = '';
  326. if($bShowAvatar) {
  327. $sPicturePopupId = $this->MODULE . '-popup-picture';
  328. $aShowAvatar = array(
  329. 'add_class' => $sAddClassPicture,
  330. 'bx_if:show_ava_image' => array(
  331. 'condition' => $bUrlAvatar,
  332. 'content' => array(
  333. 'ava_url' => $sUrlAvatar,
  334. 'img_class' => $sAddClassPicture != '' ? 'bx-media-editable-src' : '',
  335. )
  336. ),
  337. 'bx_if:show_ava_letter' => array(
  338. 'condition' => !$bUrlAvatar,
  339. 'content' => array(
  340. 'color' => implode(', ', BxDolTemplate::getColorCode($iProfile, 1.0)),
  341. 'letter' => mb_substr($sTitle, 0, 1)
  342. )
  343. ),
  344. 'bx_if:show_online' => array(
  345. 'condition' => $oProfile->isOnline(),
  346. 'content' => array()
  347. ),
  348. 'picture_avatar_url' => $bUrlAvatar ? $sUrlAvatar : $this->getImageUrl('no-picture-preview.png'),
  349. 'picture_popup_id' => $sPicturePopupId,
  350. 'picture_url' => $sUrlPicture,
  351. 'picture_href' => !$aData[$CNF['FIELD_PICTURE']] && CHECK_ACTION_RESULT_ALLOWED === $oModule->checkAllowedEdit($aData) ? $sUrlPictureChange : 'javascript:void(0);',
  352. );
  353. if($bProfileViewAllowed && $aData[$CNF['FIELD_PICTURE']]) {
  354. $sPicturePopup = BxTemplFunctions::getInstance()->transBox($sPicturePopupId, $this->parseHtmlByName('image_popup.html', array (
  355. 'image_url' => $sUrlPicture,
  356. 'bx_if:owner' => array (
  357. 'condition' => $bIsAllowEditPicture && empty($sAddClassPicture),
  358. 'content' => array (
  359. 'change_image_url' => $sUrlPictureChange,
  360. ),
  361. ),
  362. )), true, true);
  363. }
  364. }
  365. $sActionsMenu = $oModule->serviceEntityAllActions();
  366. if(!$sActionsMenu && ($oMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY'], $this)) !== false)
  367. $sActionsMenu = $oMenu->getCode();
  368. $sMetaMenu = '';
  369. if(!empty($CNF['OBJECT_MENU_VIEW_ENTRY_META']) && ($oMetaMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_VIEW_ENTRY_META'])) !== false) {
  370. $oMetaMenu->setContentId($aData[$CNF['FIELD_ID']]);
  371. $oMetaMenu->setContentPublic($this->isProfilePublic($aData));
  372. $sMetaMenu = $oMetaMenu->getCode();
  373. }
  374. // generate html
  375. $aVars = array (
  376. 'module' => $this->_oConfig->getName(),
  377. 'id' => $aData[$CNF['FIELD_ID']],
  378. 'content_url' => $sUrl,
  379. 'title' => $sTitle,
  380. 'action_menu' => $sActionsMenu,
  381. 'bx_if:show_avatar' => array(
  382. 'condition' => $bShowAvatar,
  383. 'content' => $aShowAvatar
  384. ),
  385. 'bx_if:show_avatar_placeholder' => array(
  386. 'condition' => !$bShowAvatar,
  387. 'content' => array()
  388. ),
  389. 'picture_popup' => $sPicturePopup,
  390. 'cover_popup' => $sCoverPopup,
  391. 'cover_popup_id' => $sCoverPopupId,
  392. 'cover_url' => $sUrlCover,
  393. 'add_class' => $sAddClassCover,
  394. 'img_class' => $sAddClassCover != '' ? 'bx-media-editable-src' : '',
  395. 'additional_code' => $sAddCode,
  396. 'cover_href' => !$aData[$CNF['FIELD_COVER']] && $bIsAllowEditCover ? $sUrlCoverChange : 'javascript:void(0);',
  397. 'badges' => $oModule->serviceGetBadges($aData[$CNF['FIELD_ID']]),
  398. 'meta' => $sMetaMenu,
  399. );
  400. return $aVars;
  401. }
  402. /**
  403. * Get profile cover
  404. */
  405. function setCover ($oPage, $aData, $sTemplateName = 'cover.html')
  406. {
  407. BxDolCover::getInstance($this)->set($this->prepareCover($aData, $oPage), $sTemplateName);
  408. }
  409. /**
  410. * Get profile picture thumb url
  411. * @deprecated since 11.0.0 use BxBaseModProfileTemplate::urlAvatar instead.
  412. */
  413. function avatar ($aData, $bSubstituteNoImage = true)
  414. {
  415. return $this->urlAvatar($aData, $bSubstituteNoImage);
  416. }
  417. /**
  418. * Get profile picture thumb url
  419. * @deprecated since 11.0.0 use BxBaseModProfileTemplate::urlThumb instead.
  420. */
  421. function thumb ($aData, $bSubstituteNoImage = true)
  422. {
  423. return $this->urlThumb($aData, $bSubstituteNoImage);
  424. }
  425. /**
  426. * Get profile picture thumb url
  427. * @deprecated since 11.0.0 use BxBaseModProfileTemplate::urlIcon instead.
  428. */
  429. function icon ($aData, $bSubstituteNoImage = true)
  430. {
  431. return $this->urlIcon($aData, $bSubstituteNoImage);
  432. }
  433. /**
  434. * Get profile picture icon url
  435. */
  436. function urlIcon ($aData, $bSubstituteNoImage = true)
  437. {
  438. $CNF = &$this->_oConfig->CNF;
  439. return $this->_image ($CNF['FIELD_PICTURE'], $CNF['OBJECT_IMAGES_TRANSCODER_ICON'], 'no-picture-icon.png', $aData, $bSubstituteNoImage);
  440. }
  441. /**
  442. * Get profile thumb url
  443. */
  444. function urlThumb ($aData, $bSubstituteNoImage = true)
  445. {
  446. $CNF = &$this->_oConfig->CNF;
  447. return $this->_image ($CNF['FIELD_PICTURE'], $CNF['OBJECT_IMAGES_TRANSCODER_THUMB'], 'no-picture-thumb.png', $aData, $bSubstituteNoImage);
  448. }
  449. /**
  450. * Get profile avatar url
  451. */
  452. function urlAvatar ($aData, $bSubstituteNoImage = true)
  453. {
  454. $CNF = &$this->_oConfig->CNF;
  455. return $this->_image ($CNF['FIELD_PICTURE'], $CNF['OBJECT_IMAGES_TRANSCODER_AVATAR'], 'no-picture-preview.png', $aData, $bSubstituteNoImage);
  456. }
  457. /**
  458. * Get profile avatar big url
  459. */
  460. function urlAvatarBig ($aData, $bSubstituteNoImage = true)
  461. {
  462. $CNF = &$this->_oConfig->CNF;
  463. return $this->_image ($CNF['FIELD_PICTURE'], $CNF['OBJECT_IMAGES_TRANSCODER_AVATAR_BIG'], 'no-picture-preview.png', $aData, $bSubstituteNoImage);
  464. }
  465. /**
  466. * Get profile picture url
  467. */
  468. function urlPicture ($aData, $bSubstituteNoImage = true)
  469. {
  470. $CNF = &$this->_oConfig->CNF;
  471. return $this->_image ($CNF['FIELD_PICTURE'], $CNF['OBJECT_IMAGES_TRANSCODER_PICTURE'], 'no-picture-preview.png', $aData, $bSubstituteNoImage);
  472. }
  473. /**
  474. * Get profile cover image url
  475. */
  476. function urlCover ($aData, $bSubstituteNoImage = false)
  477. {
  478. $CNF = &$this->_oConfig->CNF;
  479. $sImageUrl = $this->_image($CNF['FIELD_COVER'], $CNF['OBJECT_IMAGES_TRANSCODER_COVER'], '', $aData, $bSubstituteNoImage);
  480. return $sImageUrl;
  481. }
  482. /**
  483. * Get profile cover image url for browse unit
  484. */
  485. function urlCoverUnit ($aData, $bSubstituteNoImage = true)
  486. {
  487. $CNF = &$this->_oConfig->CNF;
  488. $sImageUrl = $this->_image ($CNF['FIELD_COVER'], $CNF['OBJECT_IMAGES_TRANSCODER_GALLERY'], '', $aData, false);
  489. if($sImageUrl === false) {
  490. $iImageId = (int)getParam('sys_unit_cover_profile');
  491. $oImageTranscoder = BxDolTranscoderImage::getObjectInstance(BX_DOL_TRANSCODER_OBJ_COVER_UNIT_PROFILE);
  492. if($oImageTranscoder && $iImageId != 0)
  493. $sImageUrl = $oImageTranscoder->getFileUrl($iImageId);
  494. }
  495. if($bSubstituteNoImage && !$sImageUrl)
  496. $sImageUrl = $this->getImageUrl('cover.svg');
  497. return $sImageUrl;
  498. }
  499. /**
  500. * Get profile picture icon url
  501. */
  502. function _image ($sField, $sTranscodeObject, $sNoImage, $aData, $bSubstituteNoImage = true)
  503. {
  504. $sImageUrl = false;
  505. if ($aData[$sField]) {
  506. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscodeObject);
  507. if ($oImagesTranscoder)
  508. $sImageUrl = $oImagesTranscoder->getFileUrl($aData[$sField]);
  509. }
  510. return $bSubstituteNoImage && !$sImageUrl ? $this->getImageUrl($sNoImage) : $sImageUrl;
  511. }
  512. protected function _getUnitClass($aData, $sTemplateName = 'unit.html')
  513. {
  514. $sResult = '';
  515. switch($sTemplateName) {
  516. default:
  517. case 'unit.html':
  518. $sResult = $this->_sUnitClass;
  519. break;
  520. case 'unit_with_cover.html':
  521. $sResult = $this->_sUnitClassWithCover;
  522. break;
  523. case 'unit_wo_info.html':
  524. case 'unit_wo_info_links.html':
  525. $sResult = $this->_sUnitClassWoInfo;
  526. break;
  527. case 'unit_with_cover_showcase.html':
  528. $sResult = $this->_sUnitClassShowCase;
  529. break;
  530. case 'unit_wo_info_showcase.html':
  531. $sResult = $this->_sUnitClassWoInfoShowCase;
  532. break;
  533. }
  534. return $sResult;
  535. }
  536. protected function _getUnitSize($aData, $sTemplateName = 'unit.html')
  537. {
  538. $sResult = '';
  539. switch($sTemplateName) {
  540. case 'unit_with_cover.html':
  541. $sResult = 'ava';
  542. break;
  543. default:
  544. $sResult = $this->_sUnitSizeDefault;
  545. break;
  546. }
  547. return $sResult;
  548. }
  549. protected function _getUnitThumbUrl($sSize, $aData, $bSubstituteNoImage = true)
  550. {
  551. $sMethod = 'url' . bx_gen_method_name(str_replace('ava', 'avatar', $sSize), array('_', '-'));
  552. if(method_exists($this, $sMethod))
  553. return $this->$sMethod($aData, $bSubstituteNoImage);
  554. else
  555. return $this->_getUnitThumbUrl($this->_sUnitSizeDefault, $aData, $bSubstituteNoImage);
  556. }
  557. }
  558. /** @} */