BxBaseModProfileTemplate.php 10 KB

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