BxPersonsModule.php 11 KB

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