BxNotesModule.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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(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. //--- Comments
  197. bx_import('BxDolCmts');
  198. $oCmts = BxDolCmts::getObjectInstance(BxNotesConfig::$OBJECT_COMMENTS, $aEvent['object_id']);
  199. $aComments = array();
  200. if($oCmts->isEnabled())
  201. $aComments = array(
  202. 'system' => BxNotesConfig::$OBJECT_COMMENTS,
  203. 'object_id' => $aContentInfo[BxNotesConfig::$FIELD_ID],
  204. 'count' => $aContentInfo['comments']
  205. );
  206. return array(
  207. 'owner_id' => $aContentInfo[BxNotesConfig::$FIELD_AUTHOR],
  208. 'content_type' => !empty($sImage) ? 'photo' : 'text', //how to parse content, 'text' by default.
  209. 'content' => array(
  210. 'url' => $sUrl,
  211. 'title' => $aContentInfo[BxNotesConfig::$FIELD_TITLE],
  212. 'text' => $aContentInfo[BxNotesConfig::$FIELD_TEXT],
  213. 'images' => array(
  214. array(
  215. 'url' => $sUrl,
  216. 'src' => $sImage
  217. )
  218. )
  219. ), //a string to display or array to parse default template before displaying.
  220. 'comments' => $aComments,
  221. 'title' => '', //may be empty.
  222. 'description' => '' //may be empty.
  223. );
  224. }
  225. // ====== ACTION METHODS
  226. function actionBrowse ($sMode = '') {
  227. $sMode = bx_process_input($sMode);
  228. /*
  229. if ('user' == $sMode || 'my' == $sMode) {
  230. $aProfile = getProfileInfo ($this->_iProfileId);
  231. if (0 == strcasecmp($sValue, $aProfile['NickName']) || 'my' == $sMode) {
  232. $this->_browseMy ($aProfile);
  233. return;
  234. }
  235. }
  236. if ('tag' == $sMode || 'category' == $sMode)
  237. $sValue = uri2title($sValue);
  238. */
  239. if (CHECK_ACTION_RESULT_ALLOWED !== $this->isAllowedBrowse()) {
  240. $this->_oTemplate->displayAccessDenied ();
  241. return;
  242. }
  243. bx_import ('SearchResult', $this->_aModule);
  244. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  245. $o = new $sClass($sMode);
  246. if ($o->isError) {
  247. $this->_oTemplate->displayPageNotFound ();
  248. return;
  249. }
  250. if (bx_get('rss')) {
  251. echo $o->rss();
  252. exit;
  253. }
  254. if (!($s = $o->processing())) {
  255. $this->_oTemplate->displayNoData ();
  256. return;
  257. }
  258. // TODO: remake to use "pages"
  259. $this->_oTemplate->addCss ('main.css');
  260. $oTemplate = BxDolTemplate::getInstance();
  261. $oTemplate->setPageHeader ($o->aCurrent['title']);
  262. $oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
  263. $oTemplate->setPageContent ('page_main_code', $s);
  264. $oTemplate->getPageCode();
  265. }
  266. // ====== PERMISSION METHODS
  267. function _checkModeratorAccess ($isPerformAction = false) {
  268. // check moderator ACnoteL
  269. $aCheck = checkActionModule($this->_iProfileId, 'edit any note', $this->getName(), $isPerformAction);
  270. return $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED;
  271. }
  272. /**
  273. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  274. */
  275. function isAllowedView ($aDataEntry, $isPerformAction = false) {
  276. // moderator and owner always have access
  277. if ($aDataEntry[BxNotesConfig::$FIELD_AUTHOR] == $this->_iProfileId || $this->_checkModeratorAccess($isPerformAction))
  278. return CHECK_ACTION_RESULT_ALLOWED;
  279. // check ACL
  280. $aCheck = checkActionModule($this->_iProfileId, 'view note', $this->getName(), $isPerformAction);
  281. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  282. return $aCheck[CHECK_ACTION_MESSAGE];
  283. // check privacy
  284. bx_import('BxDolPrivacy');
  285. $oPrivacy = BxDolPrivacy::getObjectInstance(BxNotesConfig::$OBJECT_PRIVACY_VIEW);
  286. if ($oPrivacy && !$oPrivacy->check($aDataEntry[BxNotesConfig::$FIELD_ID]))
  287. return _t('_sys_access_denied_to_private_content');
  288. return CHECK_ACTION_RESULT_ALLOWED;
  289. }
  290. /**
  291. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  292. */
  293. function isAllowedBrowse () {
  294. return CHECK_ACTION_RESULT_ALLOWED;
  295. }
  296. /**
  297. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  298. */
  299. function isAllowedAdd ($isPerformAction = false) {
  300. // check ACL
  301. $aCheck = checkActionModule($this->_iProfileId, 'create note', $this->getName(), $isPerformAction);
  302. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  303. return $aCheck[CHECK_ACTION_MESSAGE];
  304. return CHECK_ACTION_RESULT_ALLOWED;
  305. }
  306. /**
  307. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  308. */
  309. function isAllowedEdit ($aDataEntry, $isPerformAction = false) {
  310. // moderator and owner always have access
  311. if ($aDataEntry[BxNotesConfig::$FIELD_AUTHOR] == $this->_iProfileId || $this->_checkModeratorAccess($isPerformAction))
  312. return CHECK_ACTION_RESULT_ALLOWED;
  313. return _t('_sys_txt_access_denied');
  314. }
  315. /**
  316. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  317. */
  318. function isAllowedDelete (&$aDataEntry, $isPerformAction = false) {
  319. // moderator always has access
  320. if ($this->_checkModeratorAccess($isPerformAction))
  321. return CHECK_ACTION_RESULT_ALLOWED;
  322. // check ACL
  323. $aCheck = checkActionModule($this->_iProfileId, 'delete note', $this->getName(), $isPerformAction);
  324. if ($aDataEntry[BxNotesConfig::$FIELD_AUTHOR] == $this->_iProfileId && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  325. return CHECK_ACTION_RESULT_ALLOWED;
  326. return _t('_sys_txt_access_denied');
  327. }
  328. /**
  329. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  330. */
  331. function isAllowedSetThumb () {
  332. // check ACL
  333. $aCheck = checkActionModule($this->_iProfileId, 'set thumb', $this->getName(), false);
  334. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  335. return $aCheck[CHECK_ACTION_MESSAGE];
  336. return CHECK_ACTION_RESULT_ALLOWED;
  337. }
  338. }
  339. /** @} */