BxBaseModProfileTemplate.php 12 KB

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