1
0

BxBaseModTextModule.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 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 ($sUnitView = false)
  50. {
  51. return $this->_serviceBrowse ('public', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, true);
  52. }
  53. /**
  54. * Display featured entries
  55. * @return HTML string
  56. */
  57. public function serviceBrowsePopular ($sUnitView = false)
  58. {
  59. return $this->_serviceBrowse ('popular', $sUnitView ? array('unit_view' => $sUnitView) : 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, $sUnitView = false)
  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, 'unit_view' => $sUnitView ? $sUnitView : ''), 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. * Delete all content by profile
  179. * @param $iProfileId profile id
  180. * @return number of deleted items
  181. */
  182. public function serviceDeleteEntitiesByAuthor ($iProfileId)
  183. {
  184. $a = $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  185. if (!$a)
  186. return 0;
  187. $iCount = 0;
  188. foreach ($a as $aContentInfo)
  189. $iCount += ('' == $this->serviceDeleteEntity($aContentInfo[$this->_oConfig->CNF['FIELD_ID']]) ? 1 : 0);
  190. return $iCount;
  191. }
  192. /**
  193. * Data for Notification
  194. */
  195. public function serviceGetNotificationsData()
  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_notifications_post', 'module_class' => 'Module'),
  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 serviceGetNotificationsPost($aEvent)
  214. {
  215. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  216. if(empty($aContentInfo) || !is_array($aContentInfo))
  217. return array();
  218. $CNF = &$this->_oConfig->CNF;
  219. bx_import('BxDolPermalinks');
  220. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  221. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  222. return array(
  223. 'entry_sample' => _t($CNF['T']['txt_sample_single']),
  224. 'entry_url' => $sEntryUrl,
  225. 'entry_caption' => $sEntryCaption,
  226. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  227. );
  228. }
  229. /**
  230. * Data for Timeline
  231. */
  232. public function serviceGetTimelineData()
  233. {
  234. return array(
  235. 'handlers' => array(
  236. 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' => ''),
  237. array('type' => 'update', 'alert_unit' => $this->_aModule['name'], 'alert_action' => 'edited'),
  238. array('type' => 'delete', 'alert_unit' => $this->_aModule['name'], 'alert_action' => 'deleted')
  239. ),
  240. 'alerts' => array(
  241. array('unit' => $this->_aModule['name'], 'action' => 'added'),
  242. array('unit' => $this->_aModule['name'], 'action' => 'edited'),
  243. array('unit' => $this->_aModule['name'], 'action' => 'deleted'),
  244. )
  245. );
  246. }
  247. /**
  248. * Entry post for Timeline
  249. */
  250. public function serviceGetTimelinePost($aEvent)
  251. {
  252. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  253. if(empty($aContentInfo) || !is_array($aContentInfo))
  254. return '';
  255. $CNF = &$this->_oConfig->CNF;
  256. bx_import('BxDolPermalinks');
  257. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  258. //--- Image(s)
  259. $sImage = '';
  260. if (isset($aContentInfo[$CNF['FIELD_THUMB']]) && $aContentInfo[$CNF['FIELD_THUMB']]) {
  261. bx_import('BxDolStorage');
  262. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  263. if($oStorage)
  264. $sImage = $oStorage->getFileUrlById($aContentInfo[$CNF['FIELD_THUMB']]);
  265. }
  266. $aImages = array();
  267. if(!empty($sImage))
  268. $aImages = array(
  269. array('url' => $sUrl, 'src' => $sImage)
  270. );
  271. //--- Votes
  272. bx_import('BxDolVote');
  273. $oVotes = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aEvent['object_id']);
  274. $aVotes = array();
  275. if ($oVotes && $oVotes->isEnabled())
  276. $aVotes = array(
  277. 'system' => $CNF['OBJECT_VOTES'],
  278. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  279. 'count' => $aContentInfo['votes']
  280. );
  281. //--- Comments
  282. bx_import('BxDolCmts');
  283. $oCmts = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $aEvent['object_id']);
  284. $aComments = array();
  285. if($oCmts && $oCmts->isEnabled())
  286. $aComments = array(
  287. 'system' => $CNF['OBJECT_COMMENTS'],
  288. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  289. 'count' => $aContentInfo['comments']
  290. );
  291. return array(
  292. 'owner_id' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  293. 'content' => array(
  294. 'sample' => _t($CNF['T']['txt_sample_single']),
  295. 'url' => $sUrl,
  296. 'title' => isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...'),
  297. 'text' => $aContentInfo[$CNF['FIELD_TEXT']],
  298. 'images' => $aImages,
  299. ), //a string to display or array to parse default template before displaying.
  300. 'votes' => $aVotes,
  301. 'comments' => $aComments,
  302. 'title' => '', //may be empty.
  303. 'description' => '' //may be empty.
  304. );
  305. }
  306. // ====== PERMISSION METHODS
  307. /**
  308. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  309. */
  310. public function checkAllowedSetThumb ()
  311. {
  312. // check ACL
  313. $aCheck = checkActionModule($this->_iProfileId, 'set thumb', $this->getName(), false);
  314. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  315. return $aCheck[CHECK_ACTION_MESSAGE];
  316. return CHECK_ACTION_RESULT_ALLOWED;
  317. }
  318. // ====== PROTECTED METHODS
  319. protected function _buildRssParams($sMode, $aArgs)
  320. {
  321. $aParams = array ();
  322. $sMode = bx_process_input($sMode);
  323. switch ($sMode) {
  324. case 'author':
  325. $aParams = array('author' => isset($aArgs[0]) ? (int)$aArgs[0] : '');
  326. break;
  327. }
  328. return $aParams;
  329. }
  330. }
  331. /** @} */