BxNotesModule.php 13 KB

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