1
0

BxBaseModProfileTemplate.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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 $_sUnitClass;
  17. protected $_sUnitClassWithCover;
  18. protected $_sUnitClassWoInfo;
  19. function __construct(&$oConfig, &$oDb)
  20. {
  21. parent::__construct($oConfig, $oDb);
  22. $this->_sUnitClass = 'bx-base-pofile-unit';
  23. $this->_sUnitClassWithCover = 'bx-base-pofile-unit-with-cover';
  24. $this->_sUnitClassWoInfo = 'bx-base-pofile-unit-wo-info';
  25. }
  26. /**
  27. * Get profile unit
  28. */
  29. function unit ($aData, $isCheckPrivateContent = true, $sTemplateName = 'unit.html')
  30. {
  31. $aVars = $this->unitVars ($aData, $isCheckPrivateContent, $sTemplateName);
  32. return $this->parseHtmlByName($sTemplateName, $aVars);
  33. }
  34. function unitVars ($aData, $isCheckPrivateContent = true, $sTemplateName = 'unit.html')
  35. {
  36. $CNF = &$this->_oConfig->CNF;
  37. $oModule = $this->getModule();
  38. $bPublic = true;
  39. if($isCheckPrivateContent && !empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  40. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  41. if ($oPrivacy && !$oPrivacy->check($aData[$CNF['FIELD_ID']]) && !$oPrivacy->isPartiallyVisible($aData[$CNF['FIELD_ALLOW_VIEW_TO']]))
  42. $bPublic = false;
  43. }
  44. $bPublicThumb = true;
  45. if($isCheckPrivateContent && $oModule->checkAllowedViewProfileImage($aData) !== CHECK_ACTION_RESULT_ALLOWED)
  46. $bPublicThumb = false;
  47. $bPublicCover = true;
  48. if($isCheckPrivateContent && $oModule->checkAllowedViewCoverImage($aData) !== CHECK_ACTION_RESULT_ALLOWED)
  49. $bPublicCover = false;
  50. //$aVars = parent::unitVars ($aData, $isCheckPrivateContent, $sTemplateName);
  51. $oProfile = BxDolProfile::getInstanceByContentAndType($aData[$CNF['FIELD_ID']], $this->MODULE);
  52. $iProfile = $oProfile->id();
  53. // get profile's title
  54. $sTitle = bx_process_output($aData[$CNF['FIELD_NAME']]);
  55. // get profile's url
  56. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aData[$CNF['FIELD_ID']]);
  57. // connections object
  58. $sConnectionsObject = isset($CNF['OBJECT_CONNECTIONS']) ? $CNF['OBJECT_CONNECTIONS'] : 'sys_profiles_friends';
  59. $oConn = BxDolConnection::getObjectInstance($sConnectionsObject);
  60. $aConnectionTitles = $oModule->serviceGetConnectionButtonsTitles($iProfile, $sConnectionsObject);
  61. $sThumbUrl = $bPublicThumb ? $this->thumb($aData, false) : '';
  62. $bThumbUrl = !empty($sThumbUrl);
  63. $sCoverUrl = $bPublicCover ? $this->urlCoverUnit($aData, false) : '';
  64. if(empty($sCoverUrl) && ($iCoverId = (int)getParam('sys_unit_cover_profile')) != 0)
  65. $sCoverUrl = BxDolTranscoder::getObjectInstance(BX_DOL_TRANSCODER_OBJ_COVER_UNIT_PROFILE)->getFileUrlById($iCoverId);
  66. if(empty($sCoverUrl))
  67. $sCoverUrl = $this->getImageUrl('cover.jpg');
  68. // generate html
  69. $aVars = array (
  70. 'class' => $this->_getUnitClass($aData, $sTemplateName),
  71. 'id' => $aData[$CNF['FIELD_ID']],
  72. 'bx_if:show_thumb_image' => array(
  73. 'condition' => $bThumbUrl,
  74. 'content' => array(
  75. 'thumb_url' => $sThumbUrl
  76. )
  77. ),
  78. 'bx_if:show_thumb_letter' => array(
  79. 'condition' => !$bThumbUrl,
  80. 'content' => array(
  81. 'color' => implode(', ', BxDolTemplate::getColorCode($iProfile, 0.5)),
  82. 'letter' => mb_strtoupper(mb_substr($sTitle, 0, 1))
  83. )
  84. ),
  85. 'thumb_url' => $bThumbUrl ? $sThumbUrl : $this->getImageUrl('no-picture-thumb.png'),
  86. 'cover_url' => $sCoverUrl,
  87. 'content_url' => $bPublic ? $sUrl : 'javascript:void(0);',
  88. 'content_click' => !$bPublic ? 'javascript:bx_alert(' . bx_js_string('"' . _t('_sys_access_denied_to_private_content') . '"') . ');' : '',
  89. 'title' => $sTitle,
  90. 'module_name' => _t($CNF['T']['txt_sample_single']),
  91. 'ts' => $aData[$CNF['FIELD_ADDED']],
  92. 'bx_if:info' => array(
  93. 'condition' => true,
  94. 'content' => array (
  95. 'members' => $bPublic ? _t($CNF['T']['txt_N_fans'], $oConn ? $oConn->getConnectedInitiatorsCount($iProfile, true) : 0) : '&nbsp;',
  96. 'bx_if:btn' => array (
  97. 'condition' => isLogged() && !empty($aConnectionTitles['add']) && CHECK_ACTION_RESULT_ALLOWED === $this->getModule()->checkAllowedFriendAdd($aData),
  98. 'content' => array (
  99. 'id' => $iProfile,
  100. 'title' => isset($aConnectionTitles['add']) ? $aConnectionTitles['add'] : '',
  101. 'object' => $sConnectionsObject,
  102. ),
  103. ),
  104. ),
  105. ),
  106. );
  107. return $aVars;
  108. }
  109. /**
  110. * Get profile cover
  111. */
  112. function setCover ($oPage, $aData, $sTemplateName = 'cover.html')
  113. {
  114. $CNF = &$this->_oConfig->CNF;
  115. if (CHECK_ACTION_RESULT_ALLOWED !== $this->getModule()->checkAllowedViewProfileImage($aData)) {
  116. $CNF = &$this->_oConfig->CNF;
  117. $aData[$CNF['FIELD_PICTURE']] = 0;
  118. }
  119. if (CHECK_ACTION_RESULT_ALLOWED !== $this->getModule()->checkAllowedViewCoverImage($aData)) {
  120. $CNF = &$this->_oConfig->CNF;
  121. $aData[$CNF['FIELD_COVER']] = 0;
  122. }
  123. $oProfile = BxDolProfile::getInstanceByContentAndType($aData[$CNF['FIELD_ID']], $this->MODULE);
  124. $iProfile = $oProfile->id();
  125. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aData[$CNF['FIELD_ID']]);
  126. $sTitle = bx_process_output($aData[$CNF['FIELD_NAME']]);
  127. $sUrlPicture = $this->urlPicture ($aData);
  128. $sUrlPictureChange = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_EDIT_ENTRY'] . '&id=' . $aData[$CNF['FIELD_ID']]);
  129. $sUrlAvatar = $this->urlAvatar($aData, false);
  130. $bUrlAvatar = !empty($sUrlAvatar);
  131. $sUrlCover = $this->urlCover ($aData, false);
  132. if(!$sUrlCover && $oPage !== false && $oPage->isPageCover()) {
  133. $aCover = $oPage->getPageCoverImage();
  134. if(!empty($aCover))
  135. $sUrlCover = BxDolCover::getCoverImageUrl($aCover);
  136. }
  137. if(!$sUrlCover)
  138. $sUrlCover = $this->getImageUrl('cover.jpg');
  139. $sUrlCoverChange = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_EDIT_COVER'] . '&id=' . $aData[$CNF['FIELD_ID']]);
  140. $sCoverPopup = '';
  141. $sCoverPopupId = $this->MODULE . '-popup-cover';
  142. if ($aData[$CNF['FIELD_COVER']]) {
  143. $sCoverPopup = BxTemplFunctions::getInstance()->transBox($sCoverPopupId, $this->parseHtmlByName('image_popup.html', array (
  144. 'image_url' => $sUrlCover,
  145. 'bx_if:owner' => array (
  146. 'condition' => CHECK_ACTION_RESULT_ALLOWED === $this->getModule()->checkAllowedChangeCover($aData),
  147. 'content' => array (
  148. 'change_image_url' => $sUrlCoverChange,
  149. ),
  150. ),
  151. )), true, true);
  152. }
  153. $sPicturePopup = '';
  154. $sPicturePopupId = $this->MODULE . '-popup-picture';
  155. if ($aData[$CNF['FIELD_PICTURE']]) {
  156. $sPicturePopup = BxTemplFunctions::getInstance()->transBox($sPicturePopupId, $this->parseHtmlByName('image_popup.html', array (
  157. 'image_url' => $sUrlPicture,
  158. 'bx_if:owner' => array (
  159. 'condition' => CHECK_ACTION_RESULT_ALLOWED === $this->getModule()->checkAllowedEdit($aData),
  160. 'content' => array (
  161. 'change_image_url' => $sUrlPictureChange,
  162. ),
  163. ),
  164. )), true, true);
  165. }
  166. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  167. // generate html
  168. $aVars = array (
  169. 'id' => $aData[$CNF['FIELD_ID']],
  170. 'content_url' => $sUrl,
  171. 'title' => $sTitle,
  172. //'menu' => BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY_COVER'])->getCode(), // TODO: check if menu is used somewhere
  173. 'action_menu' => $oMenu ? $oMenu->getCode() : '',
  174. 'bx_if:show_ava_image' => array(
  175. 'condition' => $bUrlAvatar,
  176. 'content' => array(
  177. 'ava_url' => $sUrlAvatar
  178. )
  179. ),
  180. 'bx_if:show_ava_letter' => array(
  181. 'condition' => !$bUrlAvatar,
  182. 'content' => array(
  183. 'color' => implode(', ', BxDolTemplate::getColorCode($iProfile, 0.5)),
  184. 'letter' => mb_substr($sTitle, 0, 1)
  185. )
  186. ),
  187. 'picture_avatar_url' => $bUrlAvatar ? $sUrlAvatar : $this->getImageUrl('no-picture-preview.png'),
  188. 'picture_popup' => $sPicturePopup,
  189. 'picture_popup_id' => $sPicturePopupId,
  190. 'picture_url' => $sUrlPicture,
  191. 'picture_href' => !$aData[$CNF['FIELD_PICTURE']] && CHECK_ACTION_RESULT_ALLOWED === $this->getModule()->checkAllowedEdit($aData) ? $sUrlPictureChange : 'javascript:void(0);',
  192. 'cover_popup' => $sCoverPopup,
  193. 'cover_popup_id' => $sCoverPopupId,
  194. 'cover_url' => $sUrlCover,
  195. 'cover_href' => !$aData[$CNF['FIELD_COVER']] && CHECK_ACTION_RESULT_ALLOWED === $this->getModule()->checkAllowedChangeCover($aData) ? $sUrlCoverChange : 'javascript:void(0);',
  196. );
  197. BxDolCover::getInstance($this)->set($aVars, $sTemplateName);
  198. }
  199. /**
  200. * Get profile picture thumb url
  201. */
  202. function thumb ($aData, $bSubstituteNoImage = true)
  203. {
  204. $CNF = &$this->_oConfig->CNF;
  205. return $this->_image ($CNF['FIELD_PICTURE'], $CNF['OBJECT_IMAGES_TRANSCODER_THUMB'], 'no-picture-thumb.png', $aData, $bSubstituteNoImage);
  206. }
  207. /**
  208. * Get profile picture icon url
  209. */
  210. function icon ($aData, $bSubstituteNoImage = true)
  211. {
  212. $CNF = &$this->_oConfig->CNF;
  213. return $this->_image ($CNF['FIELD_PICTURE'], $CNF['OBJECT_IMAGES_TRANSCODER_ICON'], 'no-picture-icon.png', $aData, $bSubstituteNoImage);
  214. }
  215. /**
  216. * Get profile avatar url
  217. */
  218. function urlAvatar ($aData, $bSubstituteNoImage = true)
  219. {
  220. $CNF = &$this->_oConfig->CNF;
  221. return $this->_image ($CNF['FIELD_PICTURE'], $CNF['OBJECT_IMAGES_TRANSCODER_AVATAR'], 'no-picture-preview.png', $aData, $bSubstituteNoImage);
  222. }
  223. /**
  224. * Get profile picture url
  225. */
  226. function urlPicture ($aData, $bSubstituteNoImage = true)
  227. {
  228. $CNF = &$this->_oConfig->CNF;
  229. return $this->_image ($CNF['FIELD_PICTURE'], $CNF['OBJECT_IMAGES_TRANSCODER_PICTURE'], 'no-picture-preview.png', $aData, $bSubstituteNoImage);
  230. }
  231. /**
  232. * Get profile cover image url
  233. */
  234. function urlCover ($aData, $bSubstituteNoImage = true)
  235. {
  236. $CNF = &$this->_oConfig->CNF;
  237. return $this->_image ($CNF['FIELD_COVER'], $CNF['OBJECT_IMAGES_TRANSCODER_COVER'], 'cover.jpg', $aData, $bSubstituteNoImage);
  238. }
  239. /**
  240. * Get profile cover image url for browse unit
  241. */
  242. function urlCoverUnit ($aData, $bSubstituteNoImage = true)
  243. {
  244. $CNF = &$this->_oConfig->CNF;
  245. return $this->_image ($CNF['FIELD_COVER'], $CNF['OBJECT_IMAGES_TRANSCODER_GALLERY'], 'cover.jpg', $aData, $bSubstituteNoImage);
  246. }
  247. /**
  248. * Get profile picture icon url
  249. */
  250. function _image ($sField, $sTranscodeObject, $sNoImage, $aData, $bSubstituteNoImage = true)
  251. {
  252. $sImageUrl = false;
  253. if ($aData[$sField]) {
  254. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscodeObject);
  255. if ($oImagesTranscoder)
  256. $sImageUrl = $oImagesTranscoder->getFileUrl($aData[$sField]);
  257. }
  258. return $bSubstituteNoImage && !$sImageUrl ? $this->getImageUrl($sNoImage) : $sImageUrl;
  259. }
  260. protected function _getUnitClass($aData, $sTemplateName = 'unit.html')
  261. {
  262. $sResult = '';
  263. switch($sTemplateName) {
  264. case 'unit.html':
  265. $sResult = $this->_sUnitClass;
  266. break;
  267. case 'unit_with_cover.html':
  268. $sResult = $this->_sUnitClassWithCover;
  269. break;
  270. case 'unit_wo_info.html':
  271. case 'unit_wo_info_links.html':
  272. $sResult = $this->_sUnitClassWoInfo;
  273. break;
  274. }
  275. return $sResult;
  276. }
  277. }
  278. /** @} */