BxBaseModProfileTemplate.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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. $oProfile = BxDolProfile::getInstanceByContentAndType($aData[$CNF['FIELD_ID']], $this->MODULE);
  110. $iProfile = $oProfile->id();
  111. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aData[$CNF['FIELD_ID']]);
  112. $sTitle = bx_process_output($aData[$CNF['FIELD_NAME']]);
  113. $sUrlPicture = $this->urlPicture ($aData);
  114. $sUrlPictureChange = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_EDIT_ENTRY'] . '&id=' . $aData[$CNF['FIELD_ID']]);
  115. $sUrlAvatar = $this->urlAvatar($aData, false);
  116. $bUrlAvatar = !empty($sUrlAvatar);
  117. $sUrlCover = $this->urlCover ($aData, false);
  118. if(!$sUrlCover && $oPage !== false && $oPage->isPageCover()) {
  119. $aCover = $oPage->getPageCoverImage();
  120. if(!empty($aCover))
  121. $sUrlCover = BxDolCover::getCoverImageUrl($aCover);
  122. }
  123. if(!$sUrlCover)
  124. $sUrlCover = $this->getImageUrl('cover.jpg');
  125. $sUrlCoverChange = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_EDIT_COVER'] . '&id=' . $aData[$CNF['FIELD_ID']]);
  126. $sCoverPopup = '';
  127. $sCoverPopupId = $this->MODULE . '-popup-cover';
  128. if ($aData[$CNF['FIELD_COVER']]) {
  129. $sCoverPopup = BxTemplFunctions::getInstance()->transBox($sCoverPopupId, $this->parseHtmlByName('image_popup.html', array (
  130. 'image_url' => $sUrlCover,
  131. 'bx_if:owner' => array (
  132. 'condition' => CHECK_ACTION_RESULT_ALLOWED === $this->getModule()->checkAllowedChangeCover($aData),
  133. 'content' => array (
  134. 'change_image_url' => $sUrlCoverChange,
  135. ),
  136. ),
  137. )), true, true);
  138. }
  139. $sPicturePopup = '';
  140. $sPicturePopupId = $this->MODULE . '-popup-picture';
  141. if ($aData[$CNF['FIELD_PICTURE']]) {
  142. $sPicturePopup = BxTemplFunctions::getInstance()->transBox($sPicturePopupId, $this->parseHtmlByName('image_popup.html', array (
  143. 'image_url' => $sUrlPicture,
  144. 'bx_if:owner' => array (
  145. 'condition' => CHECK_ACTION_RESULT_ALLOWED === $this->getModule()->checkAllowedEdit($aData),
  146. 'content' => array (
  147. 'change_image_url' => $sUrlPictureChange,
  148. ),
  149. ),
  150. )), true, true);
  151. }
  152. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  153. // generate html
  154. $aVars = array (
  155. 'id' => $aData[$CNF['FIELD_ID']],
  156. 'content_url' => $sUrl,
  157. 'title' => $sTitle,
  158. //'menu' => BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY_COVER'])->getCode(), // TODO: check if menu is used somewhere
  159. 'action_menu' => $oMenu ? $oMenu->getCode() : '',
  160. 'bx_if:show_ava_image' => array(
  161. 'condition' => $bUrlAvatar,
  162. 'content' => array(
  163. 'ava_url' => $sUrlAvatar
  164. )
  165. ),
  166. 'bx_if:show_ava_letter' => array(
  167. 'condition' => !$bUrlAvatar,
  168. 'content' => array(
  169. 'color' => implode(', ', BxDolTemplate::getColorCode($iProfile, 0.5)),
  170. 'letter' => mb_substr($sTitle, 0, 1)
  171. )
  172. ),
  173. 'picture_avatar_url' => $bUrlAvatar ? $sUrlAvatar : $this->getImageUrl('no-picture-preview.png'),
  174. 'picture_popup' => $sPicturePopup,
  175. 'picture_popup_id' => $sPicturePopupId,
  176. 'picture_url' => $sUrlPicture,
  177. 'picture_href' => !$aData[$CNF['FIELD_PICTURE']] && CHECK_ACTION_RESULT_ALLOWED === $this->getModule()->checkAllowedEdit($aData) ? $sUrlPictureChange : 'javascript:void(0);',
  178. 'cover_popup' => $sCoverPopup,
  179. 'cover_popup_id' => $sCoverPopupId,
  180. 'cover_url' => $sUrlCover,
  181. 'cover_href' => !$aData[$CNF['FIELD_COVER']] && CHECK_ACTION_RESULT_ALLOWED === $this->getModule()->checkAllowedChangeCover($aData) ? $sUrlCoverChange : 'javascript:void(0);',
  182. );
  183. BxDolCover::getInstance($this)->set($aVars, $sTemplateName);
  184. }
  185. /**
  186. * Get profile picture thumb url
  187. */
  188. function thumb ($aData, $bSubstituteNoImage = true)
  189. {
  190. $CNF = &$this->_oConfig->CNF;
  191. return $this->_image ($CNF['FIELD_PICTURE'], $CNF['OBJECT_IMAGES_TRANSCODER_THUMB'], 'no-picture-thumb.png', $aData, $bSubstituteNoImage);
  192. }
  193. /**
  194. * Get profile picture icon url
  195. */
  196. function icon ($aData, $bSubstituteNoImage = true)
  197. {
  198. $CNF = &$this->_oConfig->CNF;
  199. return $this->_image ($CNF['FIELD_PICTURE'], $CNF['OBJECT_IMAGES_TRANSCODER_ICON'], 'no-picture-icon.png', $aData, $bSubstituteNoImage);
  200. }
  201. /**
  202. * Get profile avatar url
  203. */
  204. function urlAvatar ($aData, $bSubstituteNoImage = true)
  205. {
  206. $CNF = &$this->_oConfig->CNF;
  207. return $this->_image ($CNF['FIELD_PICTURE'], $CNF['OBJECT_IMAGES_TRANSCODER_AVATAR'], 'no-picture-preview.png', $aData, $bSubstituteNoImage);
  208. }
  209. /**
  210. * Get profile picture url
  211. */
  212. function urlPicture ($aData, $bSubstituteNoImage = true)
  213. {
  214. $CNF = &$this->_oConfig->CNF;
  215. return $this->_image ($CNF['FIELD_PICTURE'], $CNF['OBJECT_IMAGES_TRANSCODER_PICTURE'], 'no-picture-preview.png', $aData, $bSubstituteNoImage);
  216. }
  217. /**
  218. * Get profile cover image url
  219. */
  220. function urlCover ($aData, $bSubstituteNoImage = true)
  221. {
  222. $CNF = &$this->_oConfig->CNF;
  223. return $this->_image ($CNF['FIELD_COVER'], $CNF['OBJECT_IMAGES_TRANSCODER_COVER'], 'cover.jpg', $aData, $bSubstituteNoImage);
  224. }
  225. /**
  226. * Get profile cover image url for browse unit
  227. */
  228. function urlCoverUnit ($aData, $bSubstituteNoImage = true)
  229. {
  230. $CNF = &$this->_oConfig->CNF;
  231. return $this->_image ($CNF['FIELD_COVER'], $CNF['OBJECT_IMAGES_TRANSCODER_GALLERY'], 'cover.jpg', $aData, $bSubstituteNoImage);
  232. }
  233. /**
  234. * Get profile picture icon url
  235. */
  236. function _image ($sField, $sTranscodeObject, $sNoImage, $aData, $bSubstituteNoImage = true)
  237. {
  238. $sImageUrl = false;
  239. if ($aData[$sField]) {
  240. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscodeObject);
  241. if ($oImagesTranscoder)
  242. $sImageUrl = $oImagesTranscoder->getFileUrl($aData[$sField]);
  243. }
  244. return $bSubstituteNoImage && !$sImageUrl ? $this->getImageUrl($sNoImage) : $sImageUrl;
  245. }
  246. protected function _getUnitClass($aData, $sTemplateName = 'unit.html')
  247. {
  248. $sResult = '';
  249. switch($sTemplateName) {
  250. case 'unit.html':
  251. $sResult = 'bx-base-pofile-unit';
  252. break;
  253. case 'unit_with_cover.html':
  254. $sResult = 'bx-base-pofile-unit-with-cover';
  255. break;
  256. case 'unit_wo_info.html':
  257. case 'unit_wo_info_links.html':
  258. $sResult = 'bx-base-pofile-unit-wo-info';
  259. break;
  260. }
  261. return $sResult;
  262. }
  263. }
  264. /** @} */