1
0

BxBaseModProfileModule.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup BaseProfile Base classes for profile modules
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import ('BxBaseModGeneralModule');
  12. bx_import ('BxDolAcl');
  13. /**
  14. * Base class for profile modules.
  15. */
  16. class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolProfileService
  17. {
  18. protected $_iAccountId;
  19. function __construct(&$aModule)
  20. {
  21. parent::__construct($aModule);
  22. $this->_iAccountId = getLoggedId();
  23. }
  24. // ====== SERVICE METHODS
  25. public function serviceProfilesSearch ($sTerm, $iLimit)
  26. {
  27. $aRet = array();
  28. $a = $this->_oDb->searchByTerm($sTerm, $iLimit);
  29. foreach ($a as $r)
  30. $aRet[] = array ('label' => $this->serviceProfileName($r['content_id']), 'value' => $r['profile_id']);
  31. return $aRet;
  32. }
  33. public function serviceProfileUnit ($iContentId)
  34. {
  35. return $this->_serviceTemplateFunc('unit', $iContentId);
  36. }
  37. public function serviceProfileAvatar ($iContentId)
  38. {
  39. return $this->_serviceTemplateFunc('urlAvatar', $iContentId);
  40. }
  41. public function serviceProfileEditUrl ($iContentId)
  42. {
  43. bx_import('BxDolPermalinks');
  44. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $this->_oConfig->CNF['URI_EDIT_ENTRY'] . '&id=' . $iContentId);
  45. }
  46. public function serviceProfileThumb ($iContentId)
  47. {
  48. return $this->_serviceTemplateFunc('thumb', $iContentId);
  49. }
  50. public function serviceProfileIcon ($iContentId)
  51. {
  52. return $this->_serviceTemplateFunc('icon', $iContentId);
  53. }
  54. public function serviceProfileName ($iContentId)
  55. {
  56. if (!$iContentId)
  57. return false;
  58. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  59. if (!$aContentInfo)
  60. return false;
  61. return $aContentInfo[$this->_oConfig->CNF['FIELD_NAME']];
  62. }
  63. public function serviceProfileUrl ($iContentId)
  64. {
  65. if (!$iContentId)
  66. return false;
  67. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  68. if (!$aContentInfo)
  69. return false;
  70. $CNF = $this->_oConfig->CNF;
  71. bx_import('BxDolPermalinks');
  72. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  73. }
  74. public function serviceBrowseRecentProfiles ()
  75. {
  76. return $this->_serviceBrowse ('recent');
  77. }
  78. public function serviceBrowseConnections ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iDesignBox = BX_DB_PADDING_DEF, $iProfileId2 = 0)
  79. {
  80. return $this->_serviceBrowse (
  81. 'connections',
  82. array(
  83. 'object' => $sObjectConnections,
  84. 'type' => $sConnectionsType,
  85. 'mutual' => $iMutual,
  86. 'profile' => (int)$iProfileId,
  87. 'profile2' => (int)$iProfileId2),
  88. $iDesignBox
  89. );
  90. }
  91. public function serviceEntityEditCover ($iContentId = 0)
  92. {
  93. return $this->_serviceEntityForm ('editDataForm', $iContentId, $this->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT_COVER']);
  94. }
  95. public function serviceProfileCover ($iContentId = 0)
  96. {
  97. if (!$iContentId)
  98. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  99. if (!$iContentId)
  100. return false;
  101. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  102. if (!$aContentInfo)
  103. return false;
  104. return $this->_oTemplate->cover($aContentInfo);
  105. }
  106. public function serviceProfileFriends ($iContentId = 0)
  107. {
  108. if (!$iContentId)
  109. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  110. if (!$iContentId)
  111. return false;
  112. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  113. if (!$aContentInfo)
  114. return false;
  115. return 'TODO: friends here';
  116. }
  117. // ====== PERMISSION METHODS
  118. /**
  119. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  120. */
  121. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  122. {
  123. // moderator always has access
  124. if ($this->_isModerator($isPerformAction))
  125. return CHECK_ACTION_RESULT_ALLOWED;
  126. // owner (checked by account! not as profile as ususal) always have access
  127. bx_import('BxDolProfile');
  128. $oProfileAurhor = BxDolProfile::getInstance($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']]);
  129. if ($oProfileAurhor->getAccountId() == $this->_iAccountId)
  130. return CHECK_ACTION_RESULT_ALLOWED;
  131. return _t('_sys_txt_access_denied');
  132. }
  133. /**
  134. * Check if user can change cover image
  135. */
  136. public function checkAllowedChangeCover ($aDataEntry, $isPerformAction = false)
  137. {
  138. // moderator always has access
  139. if ($this->_isModerator($isPerformAction))
  140. return CHECK_ACTION_RESULT_ALLOWED;
  141. // owner (checked by account! not as profile as ususal) always have access
  142. bx_import('BxDolProfile');
  143. $oProfileAurhor = BxDolProfile::getInstance($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']]);
  144. if ($oProfileAurhor->getAccountId() == $this->_iAccountId)
  145. return CHECK_ACTION_RESULT_ALLOWED;
  146. return _t('_sys_txt_access_denied');
  147. }
  148. /**
  149. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  150. */
  151. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  152. {
  153. // moderator always has access
  154. if ($this->_isModerator($isPerformAction))
  155. return CHECK_ACTION_RESULT_ALLOWED;
  156. // check ACL and owner (checked by account! not as profile as ususal)
  157. bx_import('BxDolProfile');
  158. $oProfileAurhor = BxDolProfile::getInstance($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']]);
  159. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  160. if ($oProfileAurhor->getAccountId() == $this->_iAccountId && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  161. return CHECK_ACTION_RESULT_ALLOWED;
  162. return _t('_sys_txt_access_denied');
  163. }
  164. /**
  165. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  166. */
  167. public function checkAllowedViewMoreMenu (&$aDataEntry, $isPerformAction = false)
  168. {
  169. bx_import('BxTemplMenu');
  170. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']);
  171. if (!$oMenu || !$oMenu->getCode())
  172. return _t('_sys_txt_access_denied');
  173. return CHECK_ACTION_RESULT_ALLOWED;
  174. }
  175. /**
  176. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  177. */
  178. public function checkAllowedFriendAdd (&$aDataEntry, $isPerformAction = false)
  179. {
  180. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', true, false);
  181. }
  182. /**
  183. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  184. */
  185. public function checkAllowedFriendRemove (&$aDataEntry, $isPerformAction = false)
  186. {
  187. if (CHECK_ACTION_RESULT_ALLOWED === $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', false, true, true))
  188. return CHECK_ACTION_RESULT_ALLOWED;
  189. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', false, true, false);
  190. }
  191. /**
  192. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  193. */
  194. public function checkAllowedSubscribeAdd (&$aDataEntry, $isPerformAction = false)
  195. {
  196. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, false);
  197. }
  198. /**
  199. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  200. */
  201. public function checkAllowedSubscribeRemove (&$aDataEntry, $isPerformAction = false)
  202. {
  203. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, true);
  204. }
  205. // ====== PROTECTED METHODS
  206. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap = false)
  207. {
  208. if (!$this->_iProfileId)
  209. return _t('_sys_txt_access_denied');
  210. $CNF = &$this->_oConfig->CNF;
  211. $oProfileAuthor = BxDolProfile::getInstance($aDataEntry[$CNF['FIELD_AUTHOR']]);
  212. $oProfile = $oProfileAuthor ? BxDolProfile::getInstanceByContentTypeAccount($aDataEntry[$CNF['FIELD_ID']], $this->_aModule['name'], $oProfileAuthor->getAccountId()) : false;
  213. if (!$oProfile || $oProfile->id() == $this->_iProfileId)
  214. return _t('_sys_txt_access_denied');
  215. bx_import('BxDolConnection');
  216. $oConn = BxDolConnection::getObjectInstance($sObjConnection);
  217. if ($isSwap)
  218. $isConnected = $oConn->isConnected($oProfile->id(), $this->_iProfileId, $isMutual);
  219. else
  220. $isConnected = $oConn->isConnected($this->_iProfileId, $oProfile->id(), $isMutual);
  221. if ($isInvertResult)
  222. $isConnected = !$isConnected;
  223. return $isConnected ? _t('_sys_txt_access_denied') : CHECK_ACTION_RESULT_ALLOWED;
  224. }
  225. protected function _buildRssParams($sMode, $aArgs)
  226. {
  227. $aParams = array ();
  228. $sMode = bx_process_input($sMode);
  229. switch ($sMode) {
  230. case 'connections':
  231. $aParams = array(
  232. 'object' => isset($aArgs[0]) ? $aArgs[0] : '',
  233. 'type' => isset($aArgs[1]) ? $aArgs[1] : '',
  234. 'profile' => isset($aArgs[2]) ? (int)$aArgs[2] : 0,
  235. 'mutual' => isset($aArgs[3]) ? (int)$aArgs[3] : 0,
  236. 'profile2' => isset($aArgs[4]) ? (int)$aArgs[4] : 0,
  237. );
  238. break;
  239. }
  240. return $aParams;
  241. }
  242. }
  243. /** @} */