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 serviceProfilePicture ($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. $sImageUrl = '';
  135. if (isset($aContentInfo[BxPersonsConfig::$FIELD_PICTURE]) && $aContentInfo[BxPersonsConfig::$FIELD_PICTURE]) {
  136. bx_import('BxDolImageTranscoder');
  137. $oImagesTranscoder = BxDolImageTranscoder::getObjectInstance(BxPersonsConfig::$OBJECT_IMAGES_TRANSCODER_PREVIEW);
  138. if (!$oImagesTranscoder)
  139. return false;
  140. $sImageUrl = $oImagesTranscoder->getImageUrl($aContentInfo[BxPersonsConfig::$FIELD_PICTURE]);
  141. }
  142. if (!$sImageUrl)
  143. $sImageUrl = $this->_oTemplate->getImageUrl('no-picture-preview.png');
  144. $aVars = array ('url' => $sImageUrl);
  145. return $this->_oTemplate->parseHtmlByName('block_picture.html', $aVars);
  146. }
  147. // ====== ACTION METHODS
  148. function actionBrowse ($sMode = '') {
  149. $sMode = bx_process_input($sMode);
  150. /*
  151. if ('user' == $sMode || 'my' == $sMode) {
  152. $aProfile = getProfileInfo ($this->_iProfileId);
  153. if (0 == strcasecmp($sValue, $aProfile['NickName']) || 'my' == $sMode) {
  154. $this->_browseMy ($aProfile);
  155. return;
  156. }
  157. }
  158. if ('tag' == $sMode || 'category' == $sMode)
  159. $sValue = uri2title($sValue);
  160. */
  161. if (CHECK_ACTION_RESULT_ALLOWED !== $this->isAllowedBrowse()) {
  162. $this->_oTemplate->displayAccessDenied ();
  163. return;
  164. }
  165. bx_import ('SearchResult', $this->_aModule);
  166. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  167. $o = new $sClass($sMode);
  168. if ($o->isError) {
  169. $this->_oTemplate->displayPageNotFound ();
  170. return;
  171. }
  172. if (bx_get('rss')) {
  173. echo $o->rss();
  174. exit;
  175. }
  176. if (!($s = $o->processing())) {
  177. $this->_oTemplate->displayNoData ();
  178. return;
  179. }
  180. // TODO: remale to use "pages"
  181. $this->_oTemplate->addCss ('main.css');
  182. $oTemplate = BxDolTemplate::getInstance();
  183. $oTemplate->setPageHeader ($o->aCurrent['title']);
  184. $oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
  185. $oTemplate->setPageContent ('page_main_code', $s);
  186. $oTemplate->getPageCode();
  187. }
  188. function actionDiscardGhost ($iFileId, $iContentId = 0) {
  189. $this->_actionWithGhost('discardGhost', $iFileId, $iContentId);
  190. }
  191. function actionDeleteGhost ($iFileId, $iContentId = 0) {
  192. $this->_actionWithGhost('deleteGhost', $iFileId, $iContentId);
  193. }
  194. function _actionWithGhost ($sAction, $iFileId, $iContentId = 0) {
  195. $iFileId = (int)$iFileId;
  196. $iContentId = (int)$iContentId;
  197. if (!$iFileId) {
  198. header('Content-type: text/html; charset=utf-8');
  199. echo _t('_sys_txt_error_occured');
  200. exit;
  201. }
  202. bx_import('BxDolForm');
  203. $oForm = BxDolForm::getObjectInstance('bx_person', 'bx_person_add');
  204. header('Content-type: text/html; charset=utf-8');
  205. echo $oForm->$sAction($iFileId, $iContentId);
  206. exit;
  207. }
  208. // ====== PERMISSION METHODS
  209. function _checkModeratorAccess ($isPerformAction = false) {
  210. // check moderator ACL
  211. $aCheck = checkActionModule($this->_iProfileId, 'edit any person profile', $this->getName(), $isPerformAction);
  212. return $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED;
  213. }
  214. /**
  215. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  216. */
  217. function isAllowedView ($aDataEntry, $isPerformAction = false) {
  218. // moderator and owner always have access
  219. if ($aDataEntry[BxPersonsConfig::$FIELD_AUTHOR] == $this->_iProfileId || $this->_checkModeratorAccess($isPerformAction))
  220. return CHECK_ACTION_RESULT_ALLOWED;
  221. // check ACL
  222. $aCheck = checkActionModule($this->_iProfileId, 'view person profile', $this->getName(), $isPerformAction);
  223. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  224. return $aCheck[CHECK_ACTION_MESSAGE];
  225. // TODO: check privacy
  226. return CHECK_ACTION_RESULT_ALLOWED;
  227. }
  228. /**
  229. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  230. */
  231. function isAllowedBrowse () {
  232. return CHECK_ACTION_RESULT_ALLOWED;
  233. }
  234. /**
  235. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  236. */
  237. function isAllowedAdd ($isPerformAction = false) {
  238. // check ACL
  239. $aCheck = checkActionModule($this->_iProfileId, 'create person profile', $this->getName(), $isPerformAction);
  240. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  241. return $aCheck[CHECK_ACTION_MESSAGE];
  242. return CHECK_ACTION_RESULT_ALLOWED;
  243. }
  244. /**
  245. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  246. */
  247. function isAllowedEdit ($aDataEntry, $isPerformAction = false) {
  248. // moderator always has access
  249. if ($this->_checkModeratorAccess($isPerformAction))
  250. return CHECK_ACTION_RESULT_ALLOWED;
  251. // owner (checked by account! not as profile as ususal) always have access
  252. bx_import('BxDolProfile');
  253. $oProfileAurhor = BxDolProfile::getInstance($aDataEntry[BxPersonsConfig::$FIELD_AUTHOR]);
  254. if ($oProfileAurhor->getAccountId() == $this->_iAccountId)
  255. return CHECK_ACTION_RESULT_ALLOWED;
  256. return _t('_sys_txt_access_denied');
  257. }
  258. /**
  259. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  260. */
  261. function isAllowedDelete (&$aDataEntry, $isPerformAction = false) {
  262. // moderator always has access
  263. if ($this->_checkModeratorAccess($isPerformAction))
  264. return CHECK_ACTION_RESULT_ALLOWED;
  265. // check ACL and owner (checked by account! not as profile as ususal)
  266. bx_import('BxDolProfile');
  267. $oProfileAurhor = BxDolProfile::getInstance($aDataEntry[BxPersonsConfig::$FIELD_AUTHOR]);
  268. $aCheck = checkActionModule($this->_iProfileId, 'delete person profile', $this->getName(), $isPerformAction);
  269. if ($oProfileAurhor->getAccountId() == $this->_iAccountId && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  270. return CHECK_ACTION_RESULT_ALLOWED;
  271. return _t('_sys_txt_access_denied');
  272. }
  273. }
  274. /** @} */