1
0

BxBaseModTextModule.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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 BaseText Base classes for text modules
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import ('BxBaseModGeneralModule');
  12. bx_import ('BxDolAcl');
  13. /**
  14. * Base module class for text based modules
  15. */
  16. class BxBaseModTextModule extends BxBaseModGeneralModule
  17. {
  18. function __construct(&$aModule)
  19. {
  20. parent::__construct($aModule);
  21. }
  22. // ====== SERVICE METHODS
  23. public function serviceGetMenuAddonManageTools()
  24. {
  25. bx_import('SearchResult', $this->_aModule);
  26. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  27. $o = new $sClass();
  28. $o->fillFilters(array(
  29. 'status' => 'hidden'
  30. ));
  31. $o->unsetPaginate();
  32. return $o->getNum();
  33. }
  34. /**
  35. * Display pablic entries
  36. * @return HTML string
  37. */
  38. public function serviceBrowsePublic ()
  39. {
  40. return $this->_serviceBrowse ('public', false, BX_DB_PADDING_DEF, true);
  41. }
  42. /**
  43. * Display featured entries
  44. * @return HTML string
  45. */
  46. public function serviceBrowseFeatured ()
  47. {
  48. return $this->_serviceBrowse ('public', false, BX_DB_PADDING_DEF, true);
  49. }
  50. /**
  51. * Display entries of the author
  52. * @return HTML string
  53. */
  54. public function serviceBrowseAuthor ($iProfileId = 0)
  55. {
  56. if (!$iProfileId)
  57. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  58. if (!$iProfileId)
  59. return '';
  60. return $this->_serviceBrowse ('author', array('author' => $iProfileId), BX_DB_PADDING_DEF, true);
  61. }
  62. /**
  63. * Entry social sharing block
  64. */
  65. public function serviceEntitySocialSharing ($iContentId = 0)
  66. {
  67. if (!$iContentId)
  68. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  69. if (!$iContentId)
  70. return false;
  71. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  72. if (!$aContentInfo)
  73. return false;
  74. $CNF = &$this->_oConfig->CNF;
  75. bx_import('BxDolPermalinks');
  76. $sUrl = BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  77. $aCustomParams = false;
  78. if ($aContentInfo[$CNF['FIELD_THUMB']]) {
  79. bx_import('BxDolStorage');
  80. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  81. if ($oStorage && ($sImgUrl = $oStorage->getFileUrlById($aContentInfo[$CNF['FIELD_THUMB']]))) {
  82. $aCustomParams = array (
  83. 'img_url' => $sImgUrl,
  84. 'img_url_encoded' => rawurlencode($sImgUrl),
  85. );
  86. }
  87. }
  88. //TODO: Rebuild using menus engine when it will be ready for such elements like Vote, Share, etc.
  89. $sVotes = '';
  90. bx_import('BxDolVote');
  91. $oVotes = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aContentInfo[$CNF['FIELD_ID']]);
  92. if ($oVotes)
  93. $sVotes = $oVotes->getElementBlock(array('show_do_vote_as_button' => true));
  94. $sShare = '';
  95. if (BxDolRequest::serviceExists('bx_timeline', 'get_share_element_block'))
  96. $sShare = BxDolService::call('bx_timeline', 'get_share_element_block', array(bx_get_logged_profile_id(), $this->_aModule['name'], 'added', $aContentInfo[$CNF['FIELD_ID']], array('show_do_share_as_button' => true)));
  97. bx_import('BxTemplSocialSharing');
  98. $sSocial = BxTemplSocialSharing::getInstance()->getCode($iContentId, $this->_aModule['name'], BX_DOL_URL_ROOT . $sUrl, $aContentInfo[$CNF['FIELD_TITLE']], $aCustomParams);
  99. return $this->_oTemplate->parseHtmlByName('entry-share.html', array(
  100. 'vote' => $sVotes,
  101. 'share' => $sShare,
  102. 'social' => $sSocial,
  103. ));
  104. //TODO: Rebuild using menus engine when it will be ready for such elements like Vote, Share, etc.
  105. }
  106. /**
  107. * Entry text with some additional controls
  108. */
  109. public function serviceEntityTextBlock ($iContentId = 0)
  110. {
  111. return $this->_serviceEntityForm ('viewDataEntry', $iContentId);
  112. }
  113. /**
  114. * Entry comments
  115. */
  116. public function serviceEntityComments ($iContentId = 0)
  117. {
  118. if (!$iContentId)
  119. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  120. if (!$iContentId)
  121. return false;
  122. bx_import('BxDolCmts');
  123. $oCmts = BxDolCmts::getObjectInstance($this->_oConfig->CNF['OBJECT_COMMENTS'], $iContentId);
  124. if (!$oCmts || !$oCmts->isEnabled())
  125. return false;
  126. //add transient live update
  127. $sName = $this->_oConfig->getName();
  128. $sServiceCall = BxDolService::getSerializedService('system', 'get_live_updates_comments', array($this->_oConfig->CNF['OBJECT_COMMENTS'], $iContentId, $this->_iProfileId), 'TemplCmtsServices');
  129. bx_import('BxDolLiveUpdates');
  130. BxDolLiveUpdates::getInstance()->add($sName . '_live_updates_cmts', 1, $sServiceCall);
  131. //add transient live update
  132. return $oCmts->getCommentsBlock(0, 0, false);
  133. }
  134. /**
  135. * Entry author block
  136. */
  137. public function serviceEntityAuthor ($iContentId = 0)
  138. {
  139. return $this->_serviceTemplateFunc ('entryAuthor', $iContentId);
  140. }
  141. /**
  142. * Entry attachments block
  143. */
  144. public function serviceEntityAttachments ($iContentId = 0)
  145. {
  146. return $this->_serviceTemplateFunc ('entryAttachments', $iContentId);
  147. }
  148. /**
  149. * My entries actions block
  150. */
  151. public function serviceMyEntriesActions ($iProfileId = 0)
  152. {
  153. if (!$iProfileId)
  154. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  155. if (!$iProfileId || $iProfileId != $this->_iProfileId)
  156. return false;
  157. bx_import('BxTemplMenu');
  158. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']);
  159. return $oMenu ? $oMenu->getCode() : false;
  160. }
  161. /**
  162. * Data for Notification
  163. */
  164. public function serviceGetNotificationsData()
  165. {
  166. return array(
  167. 'handlers' => array(
  168. array('type' => 'insert', 'alert_unit' => $this->_aModule['name'], 'alert_action' => 'added', 'module_name' => $this->_aModule['name'], 'module_method' => 'get_notifications_post', 'module_class' => 'Module'),
  169. array('type' => 'update', 'alert_unit' => $this->_aModule['name'], 'alert_action' => 'edited'),
  170. array('type' => 'delete', 'alert_unit' => $this->_aModule['name'], 'alert_action' => 'deleted')
  171. ),
  172. 'alerts' => array(
  173. array('unit' => $this->_aModule['name'], 'action' => 'added'),
  174. array('unit' => $this->_aModule['name'], 'action' => 'edited'),
  175. array('unit' => $this->_aModule['name'], 'action' => 'deleted'),
  176. )
  177. );
  178. }
  179. /**
  180. * Entry post for Timeline
  181. */
  182. public function serviceGetNotificationsPost($aEvent)
  183. {
  184. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  185. if(empty($aContentInfo) || !is_array($aContentInfo))
  186. return array();
  187. $CNF = &$this->_oConfig->CNF;
  188. bx_import('BxDolPermalinks');
  189. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  190. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  191. return array(
  192. 'entry_sample' => _t($CNF['T']['txt_sample_single']),
  193. 'entry_url' => $sEntryUrl,
  194. 'entry_caption' => $sEntryCaption,
  195. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  196. );
  197. }
  198. /**
  199. * Data for Timeline
  200. */
  201. public function serviceGetTimelineData()
  202. {
  203. return array(
  204. 'handlers' => array(
  205. 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' => ''),
  206. array('type' => 'update', 'alert_unit' => $this->_aModule['name'], 'alert_action' => 'edited'),
  207. array('type' => 'delete', 'alert_unit' => $this->_aModule['name'], 'alert_action' => 'deleted')
  208. ),
  209. 'alerts' => array(
  210. array('unit' => $this->_aModule['name'], 'action' => 'added'),
  211. array('unit' => $this->_aModule['name'], 'action' => 'edited'),
  212. array('unit' => $this->_aModule['name'], 'action' => 'deleted'),
  213. )
  214. );
  215. }
  216. /**
  217. * Entry post for Timeline
  218. */
  219. public function serviceGetTimelinePost($aEvent)
  220. {
  221. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  222. if(empty($aContentInfo) || !is_array($aContentInfo))
  223. return '';
  224. $CNF = &$this->_oConfig->CNF;
  225. bx_import('BxDolPermalinks');
  226. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  227. //--- Image(s)
  228. $sImage = '';
  229. if (isset($aContentInfo[$CNF['FIELD_THUMB']]) && $aContentInfo[$CNF['FIELD_THUMB']]) {
  230. bx_import('BxDolStorage');
  231. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  232. if($oStorage)
  233. $sImage = $oStorage->getFileUrlById($aContentInfo[$CNF['FIELD_THUMB']]);
  234. }
  235. $aImages = array();
  236. if(!empty($sImage))
  237. $aImages = array(
  238. array('url' => $sUrl, 'src' => $sImage)
  239. );
  240. //--- Votes
  241. bx_import('BxDolVote');
  242. $oVotes = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aEvent['object_id']);
  243. $aVotes = array();
  244. if ($oVotes && $oVotes->isEnabled())
  245. $aVotes = array(
  246. 'system' => $CNF['OBJECT_VOTES'],
  247. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  248. 'count' => $aContentInfo['votes']
  249. );
  250. //--- Comments
  251. bx_import('BxDolCmts');
  252. $oCmts = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $aEvent['object_id']);
  253. $aComments = array();
  254. if($oCmts && $oCmts->isEnabled())
  255. $aComments = array(
  256. 'system' => $CNF['OBJECT_COMMENTS'],
  257. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  258. 'count' => $aContentInfo['comments']
  259. );
  260. return array(
  261. 'owner_id' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  262. 'content' => array(
  263. 'sample' => _t($CNF['T']['txt_sample_single']),
  264. 'url' => $sUrl,
  265. 'title' => isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...'),
  266. 'text' => $aContentInfo[$CNF['FIELD_TEXT']],
  267. 'images' => $aImages,
  268. ), //a string to display or array to parse default template before displaying.
  269. 'votes' => $aVotes,
  270. 'comments' => $aComments,
  271. 'title' => '', //may be empty.
  272. 'description' => '' //may be empty.
  273. );
  274. }
  275. // ====== PERMISSION METHODS
  276. /**
  277. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  278. */
  279. public function checkAllowedSetThumb ()
  280. {
  281. // check ACL
  282. $aCheck = checkActionModule($this->_iProfileId, 'set thumb', $this->getName(), false);
  283. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  284. return $aCheck[CHECK_ACTION_MESSAGE];
  285. return CHECK_ACTION_RESULT_ALLOWED;
  286. }
  287. // ====== PROTECTED METHODS
  288. protected function _buildRssParams($sMode, $aArgs)
  289. {
  290. $aParams = array ();
  291. $sMode = bx_process_input($sMode);
  292. switch ($sMode) {
  293. case 'author':
  294. $aParams = array('author' => isset($aArgs[0]) ? (int)$aArgs[0] : '');
  295. break;
  296. }
  297. return $aParams;
  298. }
  299. }
  300. /** @} */