BxNotesModule.php 13 KB

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