BxBaseModTextModule.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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 serviceBrowsePopular ()
  47. {
  48. return $this->_serviceBrowse ('popular', 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 location info
  115. */
  116. public function serviceEntityLocation ($iContentId = 0)
  117. {
  118. if (!$iContentId)
  119. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  120. if (!$iContentId)
  121. return false;
  122. return $this->_oTemplate->entryLocation ($iContentId);
  123. }
  124. /**
  125. * Entry comments
  126. */
  127. public function serviceEntityComments ($iContentId = 0)
  128. {
  129. if (!$iContentId)
  130. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  131. if (!$iContentId)
  132. return false;
  133. bx_import('BxDolCmts');
  134. $oCmts = BxDolCmts::getObjectInstance($this->_oConfig->CNF['OBJECT_COMMENTS'], $iContentId);
  135. if (!$oCmts || !$oCmts->isEnabled())
  136. return false;
  137. return $oCmts->getCommentsBlock(0, 0, false);
  138. }
  139. /**
  140. * Entry author block
  141. */
  142. public function serviceEntityAuthor ($iContentId = 0)
  143. {
  144. return $this->_serviceTemplateFunc ('entryAuthor', $iContentId);
  145. }
  146. /**
  147. * Entry attachments block
  148. */
  149. public function serviceEntityAttachments ($iContentId = 0)
  150. {
  151. return $this->_serviceTemplateFunc ('entryAttachments', $iContentId);
  152. }
  153. /**
  154. * My entries actions block
  155. */
  156. public function serviceMyEntriesActions ($iProfileId = 0)
  157. {
  158. if (!$iProfileId)
  159. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  160. if (!$iProfileId || $iProfileId != $this->_iProfileId)
  161. return false;
  162. bx_import('BxTemplMenu');
  163. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']);
  164. return $oMenu ? $oMenu->getCode() : false;
  165. }
  166. /**
  167. * Data for Notification
  168. */
  169. public function serviceGetNotificationsData()
  170. {
  171. return array(
  172. 'handlers' => array(
  173. array('type' => 'insert', 'alert_unit' => $this->_aModule['name'], 'alert_action' => 'added', 'module_name' => $this->_aModule['name'], 'module_method' => 'get_notifications_post', 'module_class' => 'Module'),
  174. array('type' => 'update', 'alert_unit' => $this->_aModule['name'], 'alert_action' => 'edited'),
  175. array('type' => 'delete', 'alert_unit' => $this->_aModule['name'], 'alert_action' => 'deleted')
  176. ),
  177. 'alerts' => array(
  178. array('unit' => $this->_aModule['name'], 'action' => 'added'),
  179. array('unit' => $this->_aModule['name'], 'action' => 'edited'),
  180. array('unit' => $this->_aModule['name'], 'action' => 'deleted'),
  181. )
  182. );
  183. }
  184. /**
  185. * Entry post for Timeline
  186. */
  187. public function serviceGetNotificationsPost($aEvent)
  188. {
  189. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  190. if(empty($aContentInfo) || !is_array($aContentInfo))
  191. return array();
  192. $CNF = &$this->_oConfig->CNF;
  193. bx_import('BxDolPermalinks');
  194. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  195. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  196. return array(
  197. 'entry_sample' => _t($CNF['T']['txt_sample_single']),
  198. 'entry_url' => $sEntryUrl,
  199. 'entry_caption' => $sEntryCaption,
  200. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  201. );
  202. }
  203. /**
  204. * Data for Timeline
  205. */
  206. public function serviceGetTimelineData()
  207. {
  208. return array(
  209. 'handlers' => array(
  210. 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' => ''),
  211. array('type' => 'update', 'alert_unit' => $this->_aModule['name'], 'alert_action' => 'edited'),
  212. array('type' => 'delete', 'alert_unit' => $this->_aModule['name'], 'alert_action' => 'deleted')
  213. ),
  214. 'alerts' => array(
  215. array('unit' => $this->_aModule['name'], 'action' => 'added'),
  216. array('unit' => $this->_aModule['name'], 'action' => 'edited'),
  217. array('unit' => $this->_aModule['name'], 'action' => 'deleted'),
  218. )
  219. );
  220. }
  221. /**
  222. * Entry post for Timeline
  223. */
  224. public function serviceGetTimelinePost($aEvent)
  225. {
  226. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  227. if(empty($aContentInfo) || !is_array($aContentInfo))
  228. return '';
  229. $CNF = &$this->_oConfig->CNF;
  230. bx_import('BxDolPermalinks');
  231. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  232. //--- Image(s)
  233. $sImage = '';
  234. if (isset($aContentInfo[$CNF['FIELD_THUMB']]) && $aContentInfo[$CNF['FIELD_THUMB']]) {
  235. bx_import('BxDolStorage');
  236. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  237. if($oStorage)
  238. $sImage = $oStorage->getFileUrlById($aContentInfo[$CNF['FIELD_THUMB']]);
  239. }
  240. $aImages = array();
  241. if(!empty($sImage))
  242. $aImages = array(
  243. array('url' => $sUrl, 'src' => $sImage)
  244. );
  245. //--- Votes
  246. bx_import('BxDolVote');
  247. $oVotes = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aEvent['object_id']);
  248. $aVotes = array();
  249. if ($oVotes && $oVotes->isEnabled())
  250. $aVotes = array(
  251. 'system' => $CNF['OBJECT_VOTES'],
  252. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  253. 'count' => $aContentInfo['votes']
  254. );
  255. //--- Comments
  256. bx_import('BxDolCmts');
  257. $oCmts = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $aEvent['object_id']);
  258. $aComments = array();
  259. if($oCmts && $oCmts->isEnabled())
  260. $aComments = array(
  261. 'system' => $CNF['OBJECT_COMMENTS'],
  262. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  263. 'count' => $aContentInfo['comments']
  264. );
  265. return array(
  266. 'owner_id' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  267. 'content' => array(
  268. 'sample' => _t($CNF['T']['txt_sample_single']),
  269. 'url' => $sUrl,
  270. 'title' => isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...'),
  271. 'text' => $aContentInfo[$CNF['FIELD_TEXT']],
  272. 'images' => $aImages,
  273. ), //a string to display or array to parse default template before displaying.
  274. 'votes' => $aVotes,
  275. 'comments' => $aComments,
  276. 'title' => '', //may be empty.
  277. 'description' => '' //may be empty.
  278. );
  279. }
  280. // ====== PERMISSION METHODS
  281. /**
  282. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  283. */
  284. public function checkAllowedSetThumb ()
  285. {
  286. // check ACL
  287. $aCheck = checkActionModule($this->_iProfileId, 'set thumb', $this->getName(), false);
  288. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  289. return $aCheck[CHECK_ACTION_MESSAGE];
  290. return CHECK_ACTION_RESULT_ALLOWED;
  291. }
  292. // ====== PROTECTED METHODS
  293. protected function _buildRssParams($sMode, $aArgs)
  294. {
  295. $aParams = array ();
  296. $sMode = bx_process_input($sMode);
  297. switch ($sMode) {
  298. case 'author':
  299. $aParams = array('author' => isset($aArgs[0]) ? (int)$aArgs[0] : '');
  300. break;
  301. }
  302. return $aParams;
  303. }
  304. }
  305. /** @} */