1
0

BxNotesModule.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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 Notes Notes
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import ('BxDolModule');
  12. bx_import ('BxDolAcl');
  13. /**
  14. * Notes module
  15. */
  16. class BxNotesModule extends BxDolModule {
  17. protected $_iProfileId;
  18. function __construct(&$aModule) {
  19. parent::__construct($aModule);
  20. $this->_iProfileId = bx_get_logged_profile_id();
  21. }
  22. // ====== SERVICE METHODS
  23. public function serviceBrowseRecent () {
  24. return $this->_serviceBrowse ('recent');
  25. }
  26. public function serviceBrowseFeatured () {
  27. return $this->_serviceBrowse ('recent');
  28. }
  29. public function _serviceBrowse ($sMode, $aParams = false) {
  30. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  31. bx_import('SearchResult', $this->_aModule);
  32. $o = new $sClass($sMode, $aParams);
  33. if ($o->isError)
  34. return false;
  35. if ($s = $o->processing())
  36. return $s;
  37. else
  38. return false;
  39. }
  40. public function serviceEntityCreate () {
  41. bx_import('NoteForms', $this->_aModule);
  42. $oProfileForms = new BxNotesNoteForms($this);
  43. return $oProfileForms->addDataForm();
  44. }
  45. /**
  46. * @return edit note form string
  47. */
  48. public function serviceEntityEdit ($iContentId = 0) {
  49. if (!$iContentId)
  50. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  51. if (!$iContentId)
  52. return false;
  53. bx_import('NoteForms', $this->_aModule);
  54. $oProfileForms = new BxNotesNoteForms($this);
  55. return $oProfileForms->editDataForm((int)$iContentId);
  56. }
  57. /**
  58. * @return delete note form string
  59. */
  60. public function serviceEntityDelete ($iContentId = 0) {
  61. if (!$iContentId)
  62. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  63. if (!$iContentId)
  64. return false;
  65. bx_import('NoteForms', $this->_aModule);
  66. $oProfileForms = new BxNotesNoteForms($this);
  67. return $oProfileForms->deleteDataForm((int)$iContentId);
  68. }
  69. /**
  70. * A note's text with some additional controls, like menu
  71. */
  72. public function serviceEntityTextBlock ($iContentId = 0) {
  73. if (!$iContentId)
  74. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  75. if (!$iContentId)
  76. return false;
  77. bx_import('NoteForms', $this->_aModule);
  78. $oProfileForms = new BxNotesNoteForms($this);
  79. return $oProfileForms->viewDataEntry((int)$iContentId);
  80. }
  81. public function serviceEntityInfo ($iContentId = 0) {
  82. if (!$iContentId)
  83. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  84. if (!$iContentId)
  85. return false;
  86. bx_import('NoteForms', $this->_aModule);
  87. $oProfileForms = new BxNotesNoteForms($this);
  88. return $oProfileForms->viewDataForm((int)$iContentId);
  89. }
  90. public function serviceEntitySocialSharing ($iContentId = 0) {
  91. if (!$iContentId)
  92. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  93. if (!$iContentId)
  94. return false;
  95. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  96. if (!$aContentInfo)
  97. return false;
  98. bx_import('BxDolPermalinks');
  99. $sUrl = BxDolPermalinks::getInstance()->permalink('page.php?i=view-note&id=' . $aContentInfo['id']);
  100. $aCustomParams = false;
  101. if ($aContentInfo[BxNotesConfig::$FIELD_THUMB]) {
  102. bx_import('BxDolStorage');
  103. $oStorage = BxDolStorage::getObjectInstance(BxNotesConfig::$OBJECT_STORAGE);
  104. if ($oStorage && ($sImgUrl = $oStorage->getFileUrlById($aContentInfo[BxNotesConfig::$FIELD_THUMB]))) {
  105. $aCustomParams = array (
  106. 'img_url' => $sImgUrl,
  107. 'img_url_encoded' => rawurlencode($sImgUrl),
  108. );
  109. }
  110. }
  111. bx_import('BxTemplSocialSharing');
  112. return BxTemplSocialSharing::getInstance()->getCode($sUrl, $aContentInfo['title'], $aCustomParams);
  113. }
  114. public function serviceEntityComments ($iContentId = 0) {
  115. if (!$iContentId)
  116. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  117. if (!$iContentId)
  118. return false;
  119. bx_import('BxTemplCmtsView');
  120. $oCmts = new BxTemplCmtsView(BxNotesConfig::$OBJECT_COMMENTS, $iContentId);
  121. if(!$oCmts->isEnabled())
  122. return false;
  123. return $oCmts->getCommentsBlock();
  124. }
  125. public function serviceEntityAuthor ($iContentId = 0) {
  126. if (!$iContentId)
  127. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  128. if (!$iContentId)
  129. return false;
  130. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  131. if (!$aContentInfo)
  132. return false;
  133. $oProfile = BxDolProfile::getInstance($aContentInfo[BxNotesConfig::$FIELD_AUTHOR]);
  134. if (!$oProfile) {
  135. bx_import('BxDolProfileUndefined');
  136. $oProfile = BxDolProfileUndefined::getInstance();
  137. }
  138. return $oProfile->getUnit();
  139. }
  140. // ====== ACTION METHODS
  141. function actionBrowse ($sMode = '') {
  142. $sMode = bx_process_input($sMode);
  143. /*
  144. if ('user' == $sMode || 'my' == $sMode) {
  145. $aProfile = getProfileInfo ($this->_iProfileId);
  146. if (0 == strcasecmp($sValue, $aProfile['NickName']) || 'my' == $sMode) {
  147. $this->_browseMy ($aProfile);
  148. return;
  149. }
  150. }
  151. if ('tag' == $sMode || 'category' == $sMode)
  152. $sValue = uri2title($sValue);
  153. */
  154. if (CHECK_ACTION_RESULT_ALLOWED != $this->isAllowedBrowse()) {
  155. $this->_oTemplate->displayAccessDenied ();
  156. return;
  157. }
  158. bx_import ('SearchResult', $this->_aModule);
  159. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  160. $o = new $sClass($sMode);
  161. if ($o->isError) {
  162. $this->_oTemplate->displayPageNotFound ();
  163. return;
  164. }
  165. if (bx_get('rss')) {
  166. echo $o->rss();
  167. exit;
  168. }
  169. if (!($s = $o->processing())) {
  170. $this->_oTemplate->displayNoData ();
  171. return;
  172. }
  173. // TODO: remake to use "pages"
  174. $this->_oTemplate->addCss ('main.css');
  175. $oTemplate = BxDolTemplate::getInstance();
  176. $oTemplate->setPageHeader ($o->aCurrent['title']);
  177. $oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
  178. $oTemplate->setPageContent ('page_main_code', $s);
  179. $oTemplate->getPageCode();
  180. }
  181. // ====== PERMISSION METHODS
  182. function _checkModeratorAccess ($isPerformAction = false) {
  183. // check moderator ACnoteL
  184. $aCheck = checkActionModule($this->_iProfileId, 'edit any note', $this->getName(), $isPerformAction);
  185. return $aCheck[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED;
  186. }
  187. /**
  188. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  189. */
  190. function isAllowedView ($aDataEntry, $isPerformAction = false) {
  191. // moderator and owner always have access
  192. if ($aDataEntry[BxNotesConfig::$FIELD_AUTHOR] == $this->_iProfileId || $this->_checkModeratorAccess($isPerformAction))
  193. return CHECK_ACTION_RESULT_ALLOWED;
  194. // check ACL
  195. $aCheck = checkActionModule($this->_iProfileId, 'view note', $this->getName(), $isPerformAction);
  196. if ($aCheck[CHECK_ACTION_RESULT] != CHECK_ACTION_RESULT_ALLOWED)
  197. return $aCheck[CHECK_ACTION_MESSAGE];
  198. // TODO: check privacy
  199. return CHECK_ACTION_RESULT_ALLOWED;
  200. }
  201. /**
  202. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  203. */
  204. function isAllowedBrowse () {
  205. return CHECK_ACTION_RESULT_ALLOWED;
  206. }
  207. /**
  208. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  209. */
  210. function isAllowedAdd ($isPerformAction = false) {
  211. // check ACL
  212. $aCheck = checkActionModule($this->_iProfileId, 'create note', $this->getName(), $isPerformAction);
  213. if ($aCheck[CHECK_ACTION_RESULT] != CHECK_ACTION_RESULT_ALLOWED)
  214. return $aCheck[CHECK_ACTION_MESSAGE];
  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.
  219. */
  220. function isAllowedEdit ($aDataEntry, $isPerformAction = false) {
  221. // moderator and owner always have access
  222. if ($aDataEntry[BxNotesConfig::$FIELD_AUTHOR] == $this->_iProfileId || $this->_checkModeratorAccess($isPerformAction))
  223. return CHECK_ACTION_RESULT_ALLOWED;
  224. return _t('_sys_txt_access_denied');
  225. }
  226. /**
  227. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  228. */
  229. function isAllowedDelete (&$aDataEntry, $isPerformAction = false) {
  230. // moderator always has access
  231. if ($this->_checkModeratorAccess($isPerformAction))
  232. return CHECK_ACTION_RESULT_ALLOWED;
  233. // check ACL
  234. $aCheck = checkActionModule($this->_iProfileId, 'delete note', $this->getName(), $isPerformAction);
  235. if ($aCheck[CHECK_ACTION_RESULT] != CHECK_ACTION_RESULT_ALLOWED)
  236. return $aCheck[CHECK_ACTION_MESSAGE];
  237. return CHECK_ACTION_RESULT_ALLOWED;
  238. }
  239. /**
  240. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  241. */
  242. function isAllowedSetThumb () {
  243. // check ACL
  244. $aCheck = checkActionModule($this->_iProfileId, 'set thumb', $this->getName(), false);
  245. if ($aCheck[CHECK_ACTION_RESULT] != CHECK_ACTION_RESULT_ALLOWED)
  246. return $aCheck[CHECK_ACTION_MESSAGE];
  247. return CHECK_ACTION_RESULT_ALLOWED;
  248. }
  249. }
  250. /** @} */