BxNotesModule.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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 serviceBrowsePublic () {
  24. return $this->_serviceBrowse ('public');
  25. }
  26. public function serviceBrowseFeatured () {
  27. return $this->_serviceBrowse ('public');
  28. }
  29. public function serviceBrowseAuthor ($iProfileId = 0) {
  30. if (!$iProfileId)
  31. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  32. if (!$iProfileId)
  33. return '';
  34. return $this->_serviceBrowse ('author', array('author' => $iProfileId));
  35. }
  36. public function _serviceBrowse ($sMode, $aParams = false) {
  37. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  38. bx_import('SearchResult', $this->_aModule);
  39. $o = new $sClass($sMode, $aParams);
  40. $o->setDisplayEmptyMsg(true);
  41. if ($o->isError)
  42. return false;
  43. if ($s = $o->processing())
  44. return $s;
  45. else
  46. return false;
  47. }
  48. public function serviceEntityCreate () {
  49. bx_import('NoteForms', $this->_aModule);
  50. $oProfileForms = new BxNotesNoteForms($this);
  51. return $oProfileForms->addDataForm();
  52. }
  53. /**
  54. * @return edit note form string
  55. */
  56. public function serviceEntityEdit ($iContentId = 0) {
  57. if (!$iContentId)
  58. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  59. if (!$iContentId)
  60. return false;
  61. bx_import('NoteForms', $this->_aModule);
  62. $oProfileForms = new BxNotesNoteForms($this);
  63. return $oProfileForms->editDataForm((int)$iContentId);
  64. }
  65. /**
  66. * @return delete note form string
  67. */
  68. public function serviceEntityDelete ($iContentId = 0) {
  69. if (!$iContentId)
  70. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  71. if (!$iContentId)
  72. return false;
  73. bx_import('NoteForms', $this->_aModule);
  74. $oProfileForms = new BxNotesNoteForms($this);
  75. return $oProfileForms->deleteDataForm((int)$iContentId);
  76. }
  77. /**
  78. * A note's text with some additional controls, like menu
  79. */
  80. public function serviceEntityTextBlock ($iContentId = 0) {
  81. if (!$iContentId)
  82. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  83. if (!$iContentId)
  84. return false;
  85. bx_import('NoteForms', $this->_aModule);
  86. $oProfileForms = new BxNotesNoteForms($this);
  87. return $oProfileForms->viewDataEntry((int)$iContentId);
  88. }
  89. public function serviceEntityInfo ($iContentId = 0) {
  90. if (!$iContentId)
  91. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  92. if (!$iContentId)
  93. return false;
  94. bx_import('NoteForms', $this->_aModule);
  95. $oProfileForms = new BxNotesNoteForms($this);
  96. return $oProfileForms->viewDataForm((int)$iContentId);
  97. }
  98. public function serviceEntitySocialSharing ($iContentId = 0) {
  99. if (!$iContentId)
  100. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  101. if (!$iContentId)
  102. return false;
  103. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  104. if (!$aContentInfo)
  105. return false;
  106. bx_import('BxDolPermalinks');
  107. $sUrl = BxDolPermalinks::getInstance()->permalink('page.php?i=view-note&id=' . $aContentInfo['id']);
  108. $aCustomParams = false;
  109. if ($aContentInfo[BxNotesConfig::$FIELD_THUMB]) {
  110. bx_import('BxDolStorage');
  111. $oStorage = BxDolStorage::getObjectInstance(BxNotesConfig::$OBJECT_STORAGE);
  112. if ($oStorage && ($sImgUrl = $oStorage->getFileUrlById($aContentInfo[BxNotesConfig::$FIELD_THUMB]))) {
  113. $aCustomParams = array (
  114. 'img_url' => $sImgUrl,
  115. 'img_url_encoded' => rawurlencode($sImgUrl),
  116. );
  117. }
  118. }
  119. bx_import('BxTemplSocialSharing');
  120. return BxTemplSocialSharing::getInstance()->getCode(BX_DOL_URL_ROOT . $sUrl, $aContentInfo['title'], $aCustomParams);
  121. }
  122. public function serviceEntityComments ($iContentId = 0) {
  123. if (!$iContentId)
  124. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  125. if (!$iContentId)
  126. return false;
  127. bx_import('BxTemplCmtsView');
  128. $oCmts = new BxTemplCmtsView(BxNotesConfig::$OBJECT_COMMENTS, $iContentId);
  129. if(!$oCmts->isEnabled())
  130. return false;
  131. return $oCmts->getCommentsBlock();
  132. }
  133. public function serviceEntityAuthor ($iContentId = 0) {
  134. if (!$iContentId)
  135. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  136. if (!$iContentId)
  137. return false;
  138. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  139. if (!$aContentInfo)
  140. return false;
  141. $oProfile = BxDolProfile::getInstance($aContentInfo[BxNotesConfig::$FIELD_AUTHOR]);
  142. if (!$oProfile) {
  143. bx_import('BxDolProfileUndefined');
  144. $oProfile = BxDolProfileUndefined::getInstance();
  145. }
  146. return $this->_oTemplate->entryAuthor ($aContentInfo, $oProfile);
  147. }
  148. public function serviceGetTimelineData()
  149. {
  150. return array(
  151. 'handlers' => array(
  152. array('type' => 'insert', 'alert_unit' => $this->_aModule['name'], 'alert_action' => 'added', 'module_name' => $this->_aModule['name'], 'module_method' => 'get_timeline_post', 'module_class' => 'Module', 'groupable' => 0, 'group_by' => ''),
  153. array('type' => 'update', 'alert_unit' => $this->_aModule['name'], 'alert_action' => 'edited'),
  154. array('type' => 'delete', 'alert_unit' => $this->_aModule['name'], 'alert_action' => 'deleted')
  155. ),
  156. 'alerts' => array(
  157. array('unit' => $this->_aModule['name'], 'action' => 'added'),
  158. array('unit' => $this->_aModule['name'], 'action' => 'edited'),
  159. array('unit' => $this->_aModule['name'], 'action' => 'deleted'),
  160. )
  161. );
  162. }
  163. public function serviceGetTimelinePost($aEvent)
  164. {
  165. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  166. if(empty($aContentInfo) || !is_array($aContentInfo))
  167. return '';
  168. bx_import('BxDolPermalinks');
  169. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=view-note&id=' . $aContentInfo['id']);
  170. $sImage = '';
  171. if($aContentInfo[BxNotesConfig::$FIELD_THUMB]) {
  172. bx_import('BxDolStorage');
  173. $oStorage = BxDolStorage::getObjectInstance(BxNotesConfig::$OBJECT_STORAGE);
  174. if($oStorage)
  175. $sImage = $oStorage->getFileUrlById($aContentInfo[BxNotesConfig::$FIELD_THUMB]);
  176. }
  177. $aComments = array();
  178. bx_import('BxDolCmts');
  179. $oCmts = BxDolCmts::getObjectInstance(BxNotesConfig::$OBJECT_COMMENTS, $aEvent['object_id']);
  180. if($oCmts->isEnabled())
  181. $aComments = array(
  182. 'count' => $aContentInfo['comments'],
  183. 'url' => $oCmts->getListUrl()
  184. );
  185. return array(
  186. 'owner_id' => $aContentInfo[BxNotesConfig::$FIELD_AUTHOR],
  187. 'content_type' => !empty($sImage) ? 'image' : 'text', //how to parse content, 'text' by default.
  188. 'content' => array(
  189. 'url' => $sUrl,
  190. 'title' => $aContentInfo[BxNotesConfig::$FIELD_TITLE],
  191. 'text' => $aContentInfo[BxNotesConfig::$FIELD_TEXT],
  192. 'image' => $sImage
  193. ), //a string to display or array to parse default template before displaying.
  194. 'comments'=> $aComments,
  195. 'title' => '', //may be empty.
  196. 'description' => '' //may be empty.
  197. );
  198. }
  199. // ====== ACTION METHODS
  200. function actionBrowse ($sMode = '') {
  201. $sMode = bx_process_input($sMode);
  202. /*
  203. if ('user' == $sMode || 'my' == $sMode) {
  204. $aProfile = getProfileInfo ($this->_iProfileId);
  205. if (0 == strcasecmp($sValue, $aProfile['NickName']) || 'my' == $sMode) {
  206. $this->_browseMy ($aProfile);
  207. return;
  208. }
  209. }
  210. if ('tag' == $sMode || 'category' == $sMode)
  211. $sValue = uri2title($sValue);
  212. */
  213. if (CHECK_ACTION_RESULT_ALLOWED !== $this->isAllowedBrowse()) {
  214. $this->_oTemplate->displayAccessDenied ();
  215. return;
  216. }
  217. bx_import ('SearchResult', $this->_aModule);
  218. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  219. $o = new $sClass($sMode);
  220. if ($o->isError) {
  221. $this->_oTemplate->displayPageNotFound ();
  222. return;
  223. }
  224. if (bx_get('rss')) {
  225. echo $o->rss();
  226. exit;
  227. }
  228. if (!($s = $o->processing())) {
  229. $this->_oTemplate->displayNoData ();
  230. return;
  231. }
  232. // TODO: remake to use "pages"
  233. $this->_oTemplate->addCss ('main.css');
  234. $oTemplate = BxDolTemplate::getInstance();
  235. $oTemplate->setPageHeader ($o->aCurrent['title']);
  236. $oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
  237. $oTemplate->setPageContent ('page_main_code', $s);
  238. $oTemplate->getPageCode();
  239. }
  240. // ====== PERMISSION METHODS
  241. function _checkModeratorAccess ($isPerformAction = false) {
  242. // check moderator ACnoteL
  243. $aCheck = checkActionModule($this->_iProfileId, 'edit any note', $this->getName(), $isPerformAction);
  244. return $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED;
  245. }
  246. /**
  247. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  248. */
  249. function isAllowedView ($aDataEntry, $isPerformAction = false) {
  250. // moderator and owner always have access
  251. if ($aDataEntry[BxNotesConfig::$FIELD_AUTHOR] == $this->_iProfileId || $this->_checkModeratorAccess($isPerformAction))
  252. return CHECK_ACTION_RESULT_ALLOWED;
  253. // check ACL
  254. $aCheck = checkActionModule($this->_iProfileId, 'view note', $this->getName(), $isPerformAction);
  255. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  256. return $aCheck[CHECK_ACTION_MESSAGE];
  257. // check privacy
  258. bx_import('BxDolPrivacy');
  259. $oPrivacy = BxDolPrivacy::getObjectInstance(BxNotesConfig::$OBJECT_PRIVACY_VIEW);
  260. if ($oPrivacy && !$oPrivacy->check($aDataEntry[BxNotesConfig::$FIELD_ID]))
  261. return _t('_sys_access_denied_to_private_content');
  262. return CHECK_ACTION_RESULT_ALLOWED;
  263. }
  264. /**
  265. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  266. */
  267. function isAllowedBrowse () {
  268. return CHECK_ACTION_RESULT_ALLOWED;
  269. }
  270. /**
  271. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  272. */
  273. function isAllowedAdd ($isPerformAction = false) {
  274. // check ACL
  275. $aCheck = checkActionModule($this->_iProfileId, 'create note', $this->getName(), $isPerformAction);
  276. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  277. return $aCheck[CHECK_ACTION_MESSAGE];
  278. return CHECK_ACTION_RESULT_ALLOWED;
  279. }
  280. /**
  281. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  282. */
  283. function isAllowedEdit ($aDataEntry, $isPerformAction = false) {
  284. // moderator and owner always have access
  285. if ($aDataEntry[BxNotesConfig::$FIELD_AUTHOR] == $this->_iProfileId || $this->_checkModeratorAccess($isPerformAction))
  286. return CHECK_ACTION_RESULT_ALLOWED;
  287. return _t('_sys_txt_access_denied');
  288. }
  289. /**
  290. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  291. */
  292. function isAllowedDelete (&$aDataEntry, $isPerformAction = false) {
  293. // moderator always has access
  294. if ($this->_checkModeratorAccess($isPerformAction))
  295. return CHECK_ACTION_RESULT_ALLOWED;
  296. // check ACL
  297. $aCheck = checkActionModule($this->_iProfileId, 'delete note', $this->getName(), $isPerformAction);
  298. if ($aDataEntry[BxNotesConfig::$FIELD_AUTHOR] == $this->_iProfileId && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  299. return CHECK_ACTION_RESULT_ALLOWED;
  300. return _t('_sys_txt_access_denied');
  301. }
  302. /**
  303. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  304. */
  305. function isAllowedSetThumb () {
  306. // check ACL
  307. $aCheck = checkActionModule($this->_iProfileId, 'set thumb', $this->getName(), false);
  308. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  309. return $aCheck[CHECK_ACTION_MESSAGE];
  310. return CHECK_ACTION_RESULT_ALLOWED;
  311. }
  312. }
  313. /** @} */