BxBaseModProfileTemplate.php 32 KB

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