BxNotesModule.php 10 KB

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