BxBaseModProfileTemplate.php 11 KB

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