BxPersonsModule.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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 Persons Persons
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import ('BxDolModule');
  12. bx_import ('BxDolAcl');
  13. /**
  14. * Persons module
  15. *
  16. * Basic person profiles.
  17. */
  18. class BxPersonsModule extends BxDolModule implements iBxDolProfileService {
  19. protected $_iProfileId;
  20. protected $_iAccountId;
  21. function __construct(&$aModule) {
  22. parent::__construct($aModule);
  23. $this->_iProfileId = bx_get_logged_profile_id();
  24. $this->_iAccountId = getLoggedId();
  25. }
  26. // ====== SERVICE METHODS
  27. public function serviceProfileUnit ($iContentId) {
  28. if (!$iContentId)
  29. return false;
  30. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  31. if (!$aContentInfo)
  32. return false;
  33. return $this->_oTemplate->unit($aContentInfo);
  34. }
  35. public function serviceProfileThumb ($iContentId) {
  36. if (!$iContentId)
  37. return false;
  38. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  39. if (!$aContentInfo)
  40. return false;
  41. return $this->_oTemplate->thumb($aContentInfo);
  42. }
  43. public function serviceProfileIcon ($iContentId) {
  44. if (!$iContentId)
  45. return false;
  46. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  47. if (!$aContentInfo)
  48. return false;
  49. return $this->_oTemplate->icon($aContentInfo);
  50. }
  51. public function serviceProfileName ($iContentId) {
  52. if (!$iContentId)
  53. return false;
  54. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  55. if (!$aContentInfo)
  56. return false;
  57. return $aContentInfo[BxPersonsConfig::$FIELD_NAME];
  58. }
  59. public function serviceProfileUrl ($iContentId) {
  60. if (!$iContentId)
  61. return false;
  62. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  63. if (!$aContentInfo)
  64. return false;
  65. bx_import('BxDolPermalinks');
  66. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=view-persons-profile&id=' . $aContentInfo['id']);
  67. }
  68. public function serviceBrowseRecentPersons () {
  69. return $this->_serviceBrowse ('recent');
  70. }
  71. public function serviceBrowseConnections ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iDesignBox = BX_DB_PADDING_DEF) {
  72. return $this->_serviceBrowse (
  73. 'connections',
  74. array(
  75. 'object' => $sObjectConnections,
  76. 'type' => $sConnectionsType,
  77. 'mutual' => $iMutual,
  78. 'profile' => (int)$iProfileId),
  79. $iDesignBox
  80. );
  81. }
  82. public function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF) {
  83. bx_import('SearchResult', $this->_aModule);
  84. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  85. $o = new $sClass($sMode, $aParams);
  86. $o->setDesignBoxTemplateId($iDesignBox);
  87. if ($o->isError)
  88. return false;
  89. if ($s = $o->processing())
  90. return $s;
  91. else
  92. return false;
  93. }
  94. public function serviceCreateProfile () {
  95. bx_import('ProfileForms', $this->_aModule);
  96. $oProfileForms = new BxPersonsProfileForms($this);
  97. return $oProfileForms->addDataForm();
  98. }
  99. public function serviceEditProfile ($iContentId = 0) {
  100. if (!$iContentId)
  101. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  102. if (!$iContentId)
  103. return false;
  104. bx_import('ProfileForms', $this->_aModule);
  105. $oProfileForms = new BxPersonsProfileForms($this);
  106. return $oProfileForms->editDataForm((int)$iContentId);
  107. }
  108. public function serviceDeleteProfile ($iContentId = 0) {
  109. if (!$iContentId)
  110. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  111. if (!$iContentId)
  112. return false;
  113. bx_import('ProfileForms', $this->_aModule);
  114. $oProfileForms = new BxPersonsProfileForms($this);
  115. return $oProfileForms->deleteDataForm((int)$iContentId);
  116. }
  117. public function serviceProfileInfo ($iContentId = 0) {
  118. if (!$iContentId)
  119. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  120. if (!$iContentId)
  121. return false;
  122. bx_import('ProfileForms', $this->_aModule);
  123. $oProfileForms = new BxPersonsProfileForms($this);
  124. return $oProfileForms->viewDataForm((int)$iContentId);
  125. }
  126. public function serviceProfileCover ($iContentId = 0) {
  127. if (!$iContentId)
  128. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  129. if (!$iContentId)
  130. return false;
  131. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  132. if (!$aContentInfo)
  133. return false;
  134. return $this->_oTemplate->cover($aContentInfo);
  135. }
  136. public function serviceProfileFriends ($iContentId = 0) {
  137. if (!$iContentId)
  138. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  139. if (!$iContentId)
  140. return false;
  141. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  142. if (!$aContentInfo)
  143. return false;
  144. return 'TODO: friends here';
  145. }
  146. // ====== ACTION METHODS
  147. function actionBrowse ($sMode = '') {
  148. $sMode = bx_process_input($sMode);
  149. /*
  150. if ('user' == $sMode || 'my' == $sMode) {
  151. $aProfile = getProfileInfo ($this->_iProfileId);
  152. if (0 == strcasecmp($sValue, $aProfile['NickName']) || 'my' == $sMode) {
  153. $this->_browseMy ($aProfile);
  154. return;
  155. }
  156. }
  157. if ('tag' == $sMode || 'category' == $sMode)
  158. $sValue = uri2title($sValue);
  159. */
  160. if (CHECK_ACTION_RESULT_ALLOWED !== $this->isAllowedBrowse()) {
  161. $this->_oTemplate->displayAccessDenied ();
  162. return;
  163. }
  164. bx_import ('SearchResult', $this->_aModule);
  165. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  166. $o = new $sClass($sMode);
  167. if ($o->isError) {
  168. $this->_oTemplate->displayPageNotFound ();
  169. return;
  170. }
  171. if (bx_get('rss')) {
  172. echo $o->rss();
  173. exit;
  174. }
  175. if (!($s = $o->processing())) {
  176. $this->_oTemplate->displayNoData ();
  177. return;
  178. }
  179. // TODO: remale to use "pages"
  180. $this->_oTemplate->addCss ('main.css');
  181. $oTemplate = BxDolTemplate::getInstance();
  182. $oTemplate->setPageHeader ($o->aCurrent['title']);
  183. $oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
  184. $oTemplate->setPageContent ('page_main_code', $s);
  185. $oTemplate->getPageCode();
  186. }
  187. function actionDiscardGhost ($iFileId, $iContentId = 0, $sFieldName = '') {
  188. $this->_actionWithGhost('discardGhost', $iFileId, $iContentId, $sFieldName);
  189. }
  190. function actionDeleteGhost ($iFileId, $iContentId = 0, $sFieldName = '') {
  191. $this->_actionWithGhost('deleteGhost', $iFileId, $iContentId, $sFieldName);
  192. }
  193. function _actionWithGhost ($sAction, $iFileId, $iContentId = 0, $sFieldName = '') {
  194. $iFileId = (int)$iFileId;
  195. $iContentId = (int)$iContentId;
  196. if (!$iFileId) {
  197. header('Content-type: text/html; charset=utf-8');
  198. echo _t('_sys_txt_error_occured');
  199. exit;
  200. }
  201. bx_import('BxDolForm');
  202. $oForm = BxDolForm::getObjectInstance('bx_person', 'bx_person_add');
  203. header('Content-type: text/html; charset=utf-8');
  204. echo $oForm->$sAction($iFileId, $iContentId, true, $sFieldName);
  205. exit;
  206. }
  207. // ====== PERMISSION METHODS
  208. function _checkModeratorAccess ($isPerformAction = false) {
  209. // check moderator ACL
  210. $aCheck = checkActionModule($this->_iProfileId, 'edit any person profile', $this->getName(), $isPerformAction);
  211. return $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED;
  212. }
  213. /**
  214. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  215. */
  216. function isAllowedView ($aDataEntry, $isPerformAction = false) {
  217. // moderator and owner always have access
  218. if ($aDataEntry[BxPersonsConfig::$FIELD_AUTHOR] == $this->_iProfileId || $this->_checkModeratorAccess($isPerformAction))
  219. return CHECK_ACTION_RESULT_ALLOWED;
  220. // check ACL
  221. $aCheck = checkActionModule($this->_iProfileId, 'view person profile', $this->getName(), $isPerformAction);
  222. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  223. return $aCheck[CHECK_ACTION_MESSAGE];
  224. // TODO: check privacy
  225. return CHECK_ACTION_RESULT_ALLOWED;
  226. }
  227. /**
  228. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  229. */
  230. function isAllowedBrowse () {
  231. return CHECK_ACTION_RESULT_ALLOWED;
  232. }
  233. /**
  234. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  235. */
  236. function isAllowedAdd ($isPerformAction = false) {
  237. // check ACL
  238. $aCheck = checkActionModule($this->_iProfileId, 'create person profile', $this->getName(), $isPerformAction);
  239. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  240. return $aCheck[CHECK_ACTION_MESSAGE];
  241. return CHECK_ACTION_RESULT_ALLOWED;
  242. }
  243. /**
  244. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  245. */
  246. function isAllowedEdit ($aDataEntry, $isPerformAction = false) {
  247. // moderator always has access
  248. if ($this->_checkModeratorAccess($isPerformAction))
  249. return CHECK_ACTION_RESULT_ALLOWED;
  250. // owner (checked by account! not as profile as ususal) always have access
  251. bx_import('BxDolProfile');
  252. $oProfileAurhor = BxDolProfile::getInstance($aDataEntry[BxPersonsConfig::$FIELD_AUTHOR]);
  253. if ($oProfileAurhor->getAccountId() == $this->_iAccountId)
  254. return CHECK_ACTION_RESULT_ALLOWED;
  255. return _t('_sys_txt_access_denied');
  256. }
  257. /**
  258. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  259. */
  260. function isAllowedDelete (&$aDataEntry, $isPerformAction = false) {
  261. // moderator always has access
  262. if ($this->_checkModeratorAccess($isPerformAction))
  263. return CHECK_ACTION_RESULT_ALLOWED;
  264. // check ACL and owner (checked by account! not as profile as ususal)
  265. bx_import('BxDolProfile');
  266. $oProfileAurhor = BxDolProfile::getInstance($aDataEntry[BxPersonsConfig::$FIELD_AUTHOR]);
  267. $aCheck = checkActionModule($this->_iProfileId, 'delete person profile', $this->getName(), $isPerformAction);
  268. if ($oProfileAurhor->getAccountId() == $this->_iAccountId && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  269. return CHECK_ACTION_RESULT_ALLOWED;
  270. return _t('_sys_txt_access_denied');
  271. }
  272. }
  273. /** @} */