1
0

BxNotesModule.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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($iContentId, 'bx_notes', 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(0, 0, false);
  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 serviceEntityActions ($iContentId = 0) {
  149. if (!$iContentId)
  150. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  151. if (!$iContentId)
  152. return false;
  153. bx_import('BxTemplMenu');
  154. $oMenu = BxTemplMenu::getObjectInstance('bx_notes_view');
  155. return $oMenu ? $oMenu->getCode() : false;
  156. }
  157. public function serviceMyEntriesActions ($iProfileId = 0) {
  158. if (!$iProfileId)
  159. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  160. if (!$iProfileId || $iProfileId != $this->_iProfileId)
  161. return false;
  162. bx_import('BxTemplMenu');
  163. $oMenu = BxTemplMenu::getObjectInstance('bx_notes_my');
  164. return $oMenu ? $oMenu->getCode() : false;
  165. }
  166. public function serviceGetTimelineData()
  167. {
  168. return array(
  169. 'handlers' => array(
  170. 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' => ''),
  171. array('type' => 'update', 'alert_unit' => $this->_aModule['name'], 'alert_action' => 'edited'),
  172. array('type' => 'delete', 'alert_unit' => $this->_aModule['name'], 'alert_action' => 'deleted')
  173. ),
  174. 'alerts' => array(
  175. array('unit' => $this->_aModule['name'], 'action' => 'added'),
  176. array('unit' => $this->_aModule['name'], 'action' => 'edited'),
  177. array('unit' => $this->_aModule['name'], 'action' => 'deleted'),
  178. )
  179. );
  180. }
  181. public function serviceGetTimelinePost($aEvent)
  182. {
  183. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  184. if(empty($aContentInfo) || !is_array($aContentInfo))
  185. return '';
  186. bx_import('BxDolPermalinks');
  187. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=view-note&id=' . $aContentInfo[BxNotesConfig::$FIELD_ID]);
  188. //--- Image(s)
  189. $sImage = '';
  190. if($aContentInfo[BxNotesConfig::$FIELD_THUMB]) {
  191. bx_import('BxDolStorage');
  192. $oStorage = BxDolStorage::getObjectInstance(BxNotesConfig::$OBJECT_STORAGE);
  193. if($oStorage)
  194. $sImage = $oStorage->getFileUrlById($aContentInfo[BxNotesConfig::$FIELD_THUMB]);
  195. }
  196. //--- Votes
  197. bx_import('BxDolVote');
  198. $oVotes = BxDolVote::getObjectInstance(BxNotesConfig::$OBJECT_VOTES, $aEvent['object_id']);
  199. $aVotes = array();
  200. if($oVotes->isEnabled())
  201. $aVotes = array(
  202. 'system' => BxNotesConfig::$OBJECT_VOTES,
  203. 'object_id' => $aContentInfo[BxNotesConfig::$FIELD_ID],
  204. 'count' => $aContentInfo['votes']
  205. );
  206. //--- Comments
  207. bx_import('BxDolCmts');
  208. $oCmts = BxDolCmts::getObjectInstance(BxNotesConfig::$OBJECT_COMMENTS, $aEvent['object_id']);
  209. $aComments = array();
  210. if($oCmts->isEnabled())
  211. $aComments = array(
  212. 'system' => BxNotesConfig::$OBJECT_COMMENTS,
  213. 'object_id' => $aContentInfo[BxNotesConfig::$FIELD_ID],
  214. 'count' => $aContentInfo['comments']
  215. );
  216. return array(
  217. 'owner_id' => $aContentInfo[BxNotesConfig::$FIELD_AUTHOR],
  218. 'content_type' => !empty($sImage) ? 'photo' : 'text', //how to parse content, 'text' by default.
  219. 'content' => array(
  220. 'sample' => _t('_bx_notes_txt_sample_single'),
  221. 'url' => $sUrl,
  222. 'title' => $aContentInfo[BxNotesConfig::$FIELD_TITLE],
  223. 'text' => $aContentInfo[BxNotesConfig::$FIELD_TEXT],
  224. 'images' => array(
  225. array(
  226. 'url' => $sUrl,
  227. 'src' => $sImage
  228. )
  229. )
  230. ), //a string to display or array to parse default template before displaying.
  231. 'votes' => $aVotes,
  232. 'comments' => $aComments,
  233. 'title' => '', //may be empty.
  234. 'description' => '' //may be empty.
  235. );
  236. }
  237. // ====== ACTION METHODS
  238. function actionBrowse ($sMode = '') {
  239. $sMode = bx_process_input($sMode);
  240. /*
  241. if ('user' == $sMode || 'my' == $sMode) {
  242. $aProfile = getProfileInfo ($this->_iProfileId);
  243. if (0 == strcasecmp($sValue, $aProfile['NickName']) || 'my' == $sMode) {
  244. $this->_browseMy ($aProfile);
  245. return;
  246. }
  247. }
  248. if ('tag' == $sMode || 'category' == $sMode)
  249. $sValue = uri2title($sValue);
  250. */
  251. if (CHECK_ACTION_RESULT_ALLOWED !== $this->isAllowedBrowse()) {
  252. $this->_oTemplate->displayAccessDenied ();
  253. return;
  254. }
  255. bx_import ('SearchResult', $this->_aModule);
  256. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  257. $o = new $sClass($sMode);
  258. if ($o->isError) {
  259. $this->_oTemplate->displayPageNotFound ();
  260. return;
  261. }
  262. if (bx_get('rss')) {
  263. echo $o->rss();
  264. exit;
  265. }
  266. if (!($s = $o->processing())) {
  267. $this->_oTemplate->displayNoData ();
  268. return;
  269. }
  270. // TODO: remake to use "pages"
  271. $this->_oTemplate->addCss ('main.css');
  272. $oTemplate = BxDolTemplate::getInstance();
  273. $oTemplate->setPageHeader ($o->aCurrent['title']);
  274. $oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
  275. $oTemplate->setPageContent ('page_main_code', $s);
  276. $oTemplate->getPageCode();
  277. }
  278. // ====== PERMISSION METHODS
  279. function _checkModeratorAccess ($isPerformAction = false) {
  280. // check moderator ACnoteL
  281. $aCheck = checkActionModule($this->_iProfileId, 'edit any note', $this->getName(), $isPerformAction);
  282. return $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED;
  283. }
  284. /**
  285. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  286. */
  287. function isAllowedView ($aDataEntry, $isPerformAction = false) {
  288. // moderator and owner always have access
  289. if ($aDataEntry[BxNotesConfig::$FIELD_AUTHOR] == $this->_iProfileId || $this->_checkModeratorAccess($isPerformAction))
  290. return CHECK_ACTION_RESULT_ALLOWED;
  291. // check ACL
  292. $aCheck = checkActionModule($this->_iProfileId, 'view note', $this->getName(), $isPerformAction);
  293. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  294. return $aCheck[CHECK_ACTION_MESSAGE];
  295. // check privacy
  296. bx_import('BxDolPrivacy');
  297. $oPrivacy = BxDolPrivacy::getObjectInstance(BxNotesConfig::$OBJECT_PRIVACY_VIEW);
  298. if ($oPrivacy && !$oPrivacy->check($aDataEntry[BxNotesConfig::$FIELD_ID]))
  299. return _t('_sys_access_denied_to_private_content');
  300. return CHECK_ACTION_RESULT_ALLOWED;
  301. }
  302. /**
  303. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  304. */
  305. function isAllowedBrowse () {
  306. return CHECK_ACTION_RESULT_ALLOWED;
  307. }
  308. /**
  309. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  310. */
  311. function isAllowedAdd ($isPerformAction = false) {
  312. // check ACL
  313. $aCheck = checkActionModule($this->_iProfileId, 'create note', $this->getName(), $isPerformAction);
  314. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  315. return $aCheck[CHECK_ACTION_MESSAGE];
  316. return CHECK_ACTION_RESULT_ALLOWED;
  317. }
  318. /**
  319. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  320. */
  321. function isAllowedEdit ($aDataEntry, $isPerformAction = false) {
  322. // moderator and owner always have access
  323. if ($aDataEntry[BxNotesConfig::$FIELD_AUTHOR] == $this->_iProfileId || $this->_checkModeratorAccess($isPerformAction))
  324. return CHECK_ACTION_RESULT_ALLOWED;
  325. return _t('_sys_txt_access_denied');
  326. }
  327. /**
  328. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  329. */
  330. function isAllowedDelete (&$aDataEntry, $isPerformAction = false) {
  331. // moderator always has access
  332. if ($this->_checkModeratorAccess($isPerformAction))
  333. return CHECK_ACTION_RESULT_ALLOWED;
  334. // check ACL
  335. $aCheck = checkActionModule($this->_iProfileId, 'delete note', $this->getName(), $isPerformAction);
  336. if ($aDataEntry[BxNotesConfig::$FIELD_AUTHOR] == $this->_iProfileId && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  337. return CHECK_ACTION_RESULT_ALLOWED;
  338. return _t('_sys_txt_access_denied');
  339. }
  340. /**
  341. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  342. */
  343. function isAllowedSetThumb () {
  344. // check ACL
  345. $aCheck = checkActionModule($this->_iProfileId, 'set thumb', $this->getName(), false);
  346. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  347. return $aCheck[CHECK_ACTION_MESSAGE];
  348. return CHECK_ACTION_RESULT_ALLOWED;
  349. }
  350. }
  351. /** @} */