BxNotesModule.php 13 KB

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