BxBaseModProfileTemplate.php 9.7 KB

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