1
0

BxBaseModTextModule.php 12 KB

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