BxBaseModTextModule.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. /**
  24. * Display pablic entries
  25. * @return HTML string
  26. */
  27. public function serviceBrowsePublic ()
  28. {
  29. return $this->_serviceBrowse ('public', false, BX_DB_PADDING_DEF, true);
  30. }
  31. /**
  32. * Display featured entries
  33. * @return HTML string
  34. */
  35. public function serviceBrowseFeatured ()
  36. {
  37. return $this->_serviceBrowse ('public', false, BX_DB_PADDING_DEF, true);
  38. }
  39. /**
  40. * Display entries of the author
  41. * @return HTML string
  42. */
  43. public function serviceBrowseAuthor ($iProfileId = 0)
  44. {
  45. if (!$iProfileId)
  46. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  47. if (!$iProfileId)
  48. return '';
  49. return $this->_serviceBrowse ('author', array('author' => $iProfileId), BX_DB_PADDING_DEF, true);
  50. }
  51. /**
  52. * Entry social sharing block
  53. */
  54. public function serviceEntitySocialSharing ($iContentId = 0)
  55. {
  56. if (!$iContentId)
  57. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  58. if (!$iContentId)
  59. return false;
  60. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  61. if (!$aContentInfo)
  62. return false;
  63. $CNF = &$this->_oConfig->CNF;
  64. bx_import('BxDolPermalinks');
  65. $sUrl = BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  66. $aCustomParams = false;
  67. if ($aContentInfo[$CNF['FIELD_THUMB']]) {
  68. bx_import('BxDolStorage');
  69. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  70. if ($oStorage && ($sImgUrl = $oStorage->getFileUrlById($aContentInfo[$CNF['FIELD_THUMB']]))) {
  71. $aCustomParams = array (
  72. 'img_url' => $sImgUrl,
  73. 'img_url_encoded' => rawurlencode($sImgUrl),
  74. );
  75. }
  76. }
  77. //TODO: Rebuild using menus engine when it will be ready for such elements like Vote, Share, etc.
  78. $sVotes = '';
  79. bx_import('BxDolVote');
  80. $oVotes = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aContentInfo[$CNF['FIELD_ID']]);
  81. if ($oVotes)
  82. $sVotes = $oVotes->getElementBlock(array('show_do_vote_as_button' => true));
  83. $sShare = '';
  84. if (BxDolRequest::serviceExists('bx_timeline', 'get_share_element_block'))
  85. $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)));
  86. bx_import('BxTemplSocialSharing');
  87. $sSocial = BxTemplSocialSharing::getInstance()->getCode($iContentId, $this->_aModule['name'], BX_DOL_URL_ROOT . $sUrl, $aContentInfo[$CNF['FIELD_TITLE']], $aCustomParams);
  88. return $this->_oTemplate->parseHtmlByName('entry-share.html', array(
  89. 'vote' => $sVotes,
  90. 'share' => $sShare,
  91. 'social' => $sSocial,
  92. ));
  93. //TODO: Rebuild using menus engine when it will be ready for such elements like Vote, Share, etc.
  94. }
  95. /**
  96. * Entry text with some additional controls
  97. */
  98. public function serviceEntityTextBlock ($iContentId = 0)
  99. {
  100. return $this->_serviceEntityForm ('viewDataEntry', $iContentId);
  101. }
  102. /**
  103. * Entry comments
  104. */
  105. public function serviceEntityComments ($iContentId = 0)
  106. {
  107. if (!$iContentId)
  108. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  109. if (!$iContentId)
  110. return false;
  111. bx_import('BxDolCmts');
  112. $oCmts = BxDolCmts::getObjectInstance($this->_oConfig->CNF['OBJECT_COMMENTS'], $iContentId);
  113. if (!$oCmts || !$oCmts->isEnabled())
  114. return false;
  115. return $oCmts->getCommentsBlock(0, 0, false);
  116. }
  117. /**
  118. * Entry author block
  119. */
  120. public function serviceEntityAuthor ($iContentId = 0)
  121. {
  122. return $this->_serviceTemplateFunc ('entryAuthor', $iContentId);
  123. }
  124. /**
  125. * Entry attachments block
  126. */
  127. public function serviceEntityAttachments ($iContentId = 0)
  128. {
  129. return $this->_serviceTemplateFunc ('entryAttachments', $iContentId);
  130. }
  131. /**
  132. * My entries actions block
  133. */
  134. public function serviceMyEntriesActions ($iProfileId = 0)
  135. {
  136. if (!$iProfileId)
  137. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  138. if (!$iProfileId || $iProfileId != $this->_iProfileId)
  139. return false;
  140. bx_import('BxTemplMenu');
  141. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']);
  142. return $oMenu ? $oMenu->getCode() : false;
  143. }
  144. /**
  145. * Data for Timeline
  146. */
  147. public function serviceGetTimelineData()
  148. {
  149. return array(
  150. 'handlers' => array(
  151. 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' => ''),
  152. array('type' => 'update', 'alert_unit' => $this->_aModule['name'], 'alert_action' => 'edited'),
  153. array('type' => 'delete', 'alert_unit' => $this->_aModule['name'], 'alert_action' => 'deleted')
  154. ),
  155. 'alerts' => array(
  156. array('unit' => $this->_aModule['name'], 'action' => 'added'),
  157. array('unit' => $this->_aModule['name'], 'action' => 'edited'),
  158. array('unit' => $this->_aModule['name'], 'action' => 'deleted'),
  159. )
  160. );
  161. }
  162. /**
  163. * Entry post for Timeline
  164. */
  165. public function serviceGetTimelinePost($aEvent)
  166. {
  167. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  168. if(empty($aContentInfo) || !is_array($aContentInfo))
  169. return '';
  170. $CNF = &$this->_oConfig->CNF;
  171. bx_import('BxDolPermalinks');
  172. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  173. //--- Image(s)
  174. $sImage = '';
  175. if (isset($aContentInfo[$CNF['FIELD_THUMB']]) && $aContentInfo[$CNF['FIELD_THUMB']]) {
  176. bx_import('BxDolStorage');
  177. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  178. if($oStorage)
  179. $sImage = $oStorage->getFileUrlById($aContentInfo[$CNF['FIELD_THUMB']]);
  180. }
  181. //--- Votes
  182. bx_import('BxDolVote');
  183. $oVotes = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aEvent['object_id']);
  184. $aVotes = array();
  185. if ($oVotes && $oVotes->isEnabled())
  186. $aVotes = array(
  187. 'system' => $CNF['OBJECT_VOTES'],
  188. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  189. 'count' => $aContentInfo['votes']
  190. );
  191. //--- Comments
  192. bx_import('BxDolCmts');
  193. $oCmts = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $aEvent['object_id']);
  194. $aComments = array();
  195. if($oCmts && $oCmts->isEnabled())
  196. $aComments = array(
  197. 'system' => $CNF['OBJECT_COMMENTS'],
  198. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  199. 'count' => $aContentInfo['comments']
  200. );
  201. return array(
  202. 'owner_id' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  203. 'content' => array(
  204. 'sample' => _t($CNF['T']['txt_sample_single']),
  205. 'url' => $sUrl,
  206. 'title' => isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...'),
  207. 'text' => $aContentInfo[$CNF['FIELD_TEXT']],
  208. 'images' => array(
  209. array(
  210. 'url' => $sUrl,
  211. 'src' => $sImage
  212. )
  213. )
  214. ), //a string to display or array to parse default template before displaying.
  215. 'votes' => $aVotes,
  216. 'comments' => $aComments,
  217. 'title' => '', //may be empty.
  218. 'description' => '' //may be empty.
  219. );
  220. }
  221. // ====== PERMISSION METHODS
  222. /**
  223. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  224. */
  225. public function checkAllowedSetThumb ()
  226. {
  227. // check ACL
  228. $aCheck = checkActionModule($this->_iProfileId, 'set thumb', $this->getName(), false);
  229. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  230. return $aCheck[CHECK_ACTION_MESSAGE];
  231. return CHECK_ACTION_RESULT_ALLOWED;
  232. }
  233. // ====== PROTECTED METHODS
  234. protected function _buildRssParams($sMode, $aArgs)
  235. {
  236. $aParams = array ();
  237. $sMode = bx_process_input($sMode);
  238. switch ($sMode) {
  239. case 'author':
  240. $aParams = array('author' => isset($aArgs[0]) ? (int)$aArgs[0] : '');
  241. break;
  242. }
  243. return $aParams;
  244. }
  245. }
  246. /** @} */