1
0

BxBaseModTextModule.php 12 KB

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