BxBaseModProfileTemplate.php 12 KB

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