1
0

BxBaseModTextModule.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. /**
  12. * Base module class for text based modules
  13. */
  14. class BxBaseModTextModule extends BxBaseModGeneralModule
  15. {
  16. function __construct(&$aModule)
  17. {
  18. parent::__construct($aModule);
  19. }
  20. // ====== SERVICE METHODS
  21. public function serviceGetMenuAddonManageTools()
  22. {
  23. bx_import('SearchResult', $this->_aModule);
  24. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  25. $o = new $sClass();
  26. $o->fillFilters(array(
  27. 'status' => 'hidden'
  28. ));
  29. $o->unsetPaginate();
  30. return $o->getNum();
  31. }
  32. public function serviceGetMenuAddonManageToolsProfileStats()
  33. {
  34. bx_import('SearchResult', $this->_aModule);
  35. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  36. $o = new $sClass();
  37. $o->fillFilters(array(
  38. 'author' => bx_get_logged_profile_id()
  39. ));
  40. $o->unsetPaginate();
  41. return $o->getNum();
  42. }
  43. /**
  44. * Display public entries
  45. * @return HTML string
  46. */
  47. public function serviceBrowsePublic ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  48. {
  49. return $this->_serviceBrowse ('public', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  50. }
  51. /**
  52. * Display popular entries
  53. * @return HTML string
  54. */
  55. public function serviceBrowsePopular ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  56. {
  57. return $this->_serviceBrowse ('popular', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  58. }
  59. /**
  60. * Display recently updated entries
  61. * @return HTML string
  62. */
  63. public function serviceBrowseUpdated ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  64. {
  65. return $this->_serviceBrowse ('updated', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  66. }
  67. /**
  68. * Display entries of the author
  69. * @return HTML string
  70. */
  71. public function serviceBrowseAuthor ($iProfileId = 0, $aParams = array())
  72. {
  73. if (!$iProfileId)
  74. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  75. if (!$iProfileId)
  76. return '';
  77. return $this->_serviceBrowse ('author', array_merge(array('author' => $iProfileId), $aParams), BX_DB_PADDING_DEF, true);
  78. }
  79. /**
  80. * Entry social sharing block
  81. */
  82. public function serviceEntitySocialSharing ($iContentId = 0)
  83. {
  84. if (!$iContentId)
  85. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  86. if (!$iContentId)
  87. return false;
  88. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  89. if (!$aContentInfo)
  90. return false;
  91. $CNF = &$this->_oConfig->CNF;
  92. return $this->_entitySocialSharing ($iContentId, array(
  93. 'id_timeline' => $iContentId,
  94. 'id_thumb' => $aContentInfo[$CNF['FIELD_THUMB']],
  95. 'title' => $aContentInfo[$CNF['FIELD_TITLE']],
  96. 'object_storage' => $CNF['OBJECT_STORAGE'],
  97. 'object_transcoder' => false,
  98. 'object_vote' => $CNF['OBJECT_VOTES'],
  99. 'object_report' => $CNF['OBJECT_REPORTS'],
  100. 'uri_view_entry' => $CNF['URI_VIEW_ENTRY']
  101. ));
  102. }
  103. public function serviceEntityAllActions ($iContentId = 0)
  104. {
  105. return $this->_oTemplate->entryAllActions('', $this->serviceEntitySocialSharing($iContentId));
  106. }
  107. /**
  108. * Entry comments
  109. */
  110. public function serviceEntityComments ($iContentId = 0)
  111. {
  112. return $this->_entityComments($this->_oConfig->CNF['OBJECT_COMMENTS'], $iContentId);
  113. }
  114. /**
  115. * Entry author block
  116. */
  117. public function serviceEntityAuthor ($iContentId = 0)
  118. {
  119. return $this->_serviceTemplateFunc ('entryAuthor', $iContentId);
  120. }
  121. /**
  122. * Entry attachments block
  123. */
  124. public function serviceEntityAttachments ($iContentId = 0)
  125. {
  126. return $this->_serviceTemplateFunc ('entryAttachments', $iContentId);
  127. }
  128. public function serviceEntityBreadcrumb ($iContentId = 0)
  129. {
  130. if (!$iContentId)
  131. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  132. if (!$iContentId)
  133. return false;
  134. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  135. if (!$aContentInfo)
  136. return false;
  137. return $this->_oTemplate->entryBreadcrumb($aContentInfo);
  138. }
  139. /**
  140. * My entries actions block
  141. */
  142. public function serviceMyEntriesActions ($iProfileId = 0)
  143. {
  144. if (!$iProfileId)
  145. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  146. if (!$iProfileId || $iProfileId != $this->_iProfileId)
  147. return false;
  148. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']);
  149. return $oMenu ? $oMenu->getCode() : false;
  150. }
  151. /**
  152. * Delete all content by profile
  153. * @param $iProfileId profile id
  154. * @return number of deleted items
  155. */
  156. public function serviceDeleteEntitiesByAuthor ($iProfileId)
  157. {
  158. $a = $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  159. if (!$a)
  160. return 0;
  161. $iCount = 0;
  162. foreach ($a as $aContentInfo)
  163. $iCount += ('' == $this->serviceDeleteEntity($aContentInfo[$this->_oConfig->CNF['FIELD_ID']]) ? 1 : 0);
  164. return $iCount;
  165. }
  166. // ====== PERMISSION METHODS
  167. /**
  168. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  169. */
  170. public function checkAllowedSetThumb ()
  171. {
  172. // check ACL
  173. $aCheck = checkActionModule($this->_iProfileId, 'set thumb', $this->getName(), false);
  174. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  175. return $aCheck[CHECK_ACTION_MESSAGE];
  176. return CHECK_ACTION_RESULT_ALLOWED;
  177. }
  178. // ====== PROTECTED METHODS
  179. protected function _buildRssParams($sMode, $aArgs)
  180. {
  181. $aParams = array ();
  182. $sMode = bx_process_input($sMode);
  183. switch ($sMode) {
  184. case 'author':
  185. $aParams = array('author' => isset($aArgs[0]) ? (int)$aArgs[0] : '');
  186. break;
  187. }
  188. return $aParams;
  189. }
  190. protected function _entityComments ($sObject, $iId = 0)
  191. {
  192. if (!$iId)
  193. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  194. if (!$iId)
  195. return false;
  196. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  197. if (!$oCmts || !$oCmts->isEnabled())
  198. return false;
  199. return $oCmts->getCommentsBlock(0, 0, false);
  200. }
  201. }
  202. /** @} */