BxNotesModule.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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(BX_DOL_URL_ROOT . $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 $this->_oTemplate->entryAuthor ($aContentInfo, $oProfile);
  139. }
  140. public function serviceGetTimelineData()
  141. {
  142. return array(
  143. 'handlers' => array(
  144. array('type' => 'insert', 'alert_unit' => $this->_aModule['name'], 'alert_action' => 'added', 'module_name' => $this->_aModule['name'], 'module_method' => 'get_timeline_post', 'module_params' => '', 'module_class' => 'Module', 'groupable' => 0, 'group_by' => ''),
  145. array('type' => 'update', 'alert_unit' => $this->_aModule['name'], 'alert_action' => 'edited'),
  146. array('type' => 'delete', 'alert_unit' => $this->_aModule['name'], 'alert_action' => 'deleted')
  147. ),
  148. 'alerts' => array(
  149. array('unit' => $this->_aModule['name'], 'action' => 'added'),
  150. array('unit' => $this->_aModule['name'], 'action' => 'edited'),
  151. array('unit' => $this->_aModule['name'], 'action' => 'deleted'),
  152. )
  153. );
  154. }
  155. public function serviceGetTimelinePost()
  156. {
  157. }
  158. // ====== ACTION METHODS
  159. function actionBrowse ($sMode = '') {
  160. $sMode = bx_process_input($sMode);
  161. /*
  162. if ('user' == $sMode || 'my' == $sMode) {
  163. $aProfile = getProfileInfo ($this->_iProfileId);
  164. if (0 == strcasecmp($sValue, $aProfile['NickName']) || 'my' == $sMode) {
  165. $this->_browseMy ($aProfile);
  166. return;
  167. }
  168. }
  169. if ('tag' == $sMode || 'category' == $sMode)
  170. $sValue = uri2title($sValue);
  171. */
  172. if (CHECK_ACTION_RESULT_ALLOWED !== $this->isAllowedBrowse()) {
  173. $this->_oTemplate->displayAccessDenied ();
  174. return;
  175. }
  176. bx_import ('SearchResult', $this->_aModule);
  177. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  178. $o = new $sClass($sMode);
  179. if ($o->isError) {
  180. $this->_oTemplate->displayPageNotFound ();
  181. return;
  182. }
  183. if (bx_get('rss')) {
  184. echo $o->rss();
  185. exit;
  186. }
  187. if (!($s = $o->processing())) {
  188. $this->_oTemplate->displayNoData ();
  189. return;
  190. }
  191. // TODO: remake to use "pages"
  192. $this->_oTemplate->addCss ('main.css');
  193. $oTemplate = BxDolTemplate::getInstance();
  194. $oTemplate->setPageHeader ($o->aCurrent['title']);
  195. $oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
  196. $oTemplate->setPageContent ('page_main_code', $s);
  197. $oTemplate->getPageCode();
  198. }
  199. // ====== PERMISSION METHODS
  200. function _checkModeratorAccess ($isPerformAction = false) {
  201. // check moderator ACnoteL
  202. $aCheck = checkActionModule($this->_iProfileId, 'edit any note', $this->getName(), $isPerformAction);
  203. return $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED;
  204. }
  205. /**
  206. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  207. */
  208. function isAllowedView ($aDataEntry, $isPerformAction = false) {
  209. // moderator and owner always have access
  210. if ($aDataEntry[BxNotesConfig::$FIELD_AUTHOR] == $this->_iProfileId || $this->_checkModeratorAccess($isPerformAction))
  211. return CHECK_ACTION_RESULT_ALLOWED;
  212. // check ACL
  213. $aCheck = checkActionModule($this->_iProfileId, 'view note', $this->getName(), $isPerformAction);
  214. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  215. return $aCheck[CHECK_ACTION_MESSAGE];
  216. // TODO: check privacy
  217. return CHECK_ACTION_RESULT_ALLOWED;
  218. }
  219. /**
  220. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  221. */
  222. function isAllowedBrowse () {
  223. return CHECK_ACTION_RESULT_ALLOWED;
  224. }
  225. /**
  226. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  227. */
  228. function isAllowedAdd ($isPerformAction = false) {
  229. // check ACL
  230. $aCheck = checkActionModule($this->_iProfileId, 'create note', $this->getName(), $isPerformAction);
  231. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  232. return $aCheck[CHECK_ACTION_MESSAGE];
  233. return CHECK_ACTION_RESULT_ALLOWED;
  234. }
  235. /**
  236. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  237. */
  238. function isAllowedEdit ($aDataEntry, $isPerformAction = false) {
  239. // moderator and owner always have access
  240. if ($aDataEntry[BxNotesConfig::$FIELD_AUTHOR] == $this->_iProfileId || $this->_checkModeratorAccess($isPerformAction))
  241. return CHECK_ACTION_RESULT_ALLOWED;
  242. return _t('_sys_txt_access_denied');
  243. }
  244. /**
  245. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  246. */
  247. function isAllowedDelete (&$aDataEntry, $isPerformAction = false) {
  248. // moderator always has access
  249. if ($this->_checkModeratorAccess($isPerformAction))
  250. return CHECK_ACTION_RESULT_ALLOWED;
  251. // check ACL
  252. $aCheck = checkActionModule($this->_iProfileId, 'delete note', $this->getName(), $isPerformAction);
  253. if ($aDataEntry[BxNotesConfig::$FIELD_AUTHOR] == $this->_iProfileId && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  254. return CHECK_ACTION_RESULT_ALLOWED;
  255. return _t('_sys_txt_access_denied');
  256. }
  257. /**
  258. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  259. */
  260. function isAllowedSetThumb () {
  261. // check ACL
  262. $aCheck = checkActionModule($this->_iProfileId, 'set thumb', $this->getName(), false);
  263. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  264. return $aCheck[CHECK_ACTION_MESSAGE];
  265. return CHECK_ACTION_RESULT_ALLOWED;
  266. }
  267. }
  268. /** @} */