BxBaseModProfileTemplate.php 11 KB

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