BxBaseModProfileTemplate.php 34 KB

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