BxNotesModule.php 11 KB

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