BxBaseModTextModule.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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, $iContentId, $aContentInfo[$CNF['FIELD_THUMB']], $aContentInfo[$CNF['FIELD_TITLE']], $CNF['OBJECT_STORAGE'], false, $CNF['OBJECT_VOTES'], $CNF['OBJECT_REPORTS'], $CNF['URI_VIEW_ENTRY']);
  93. }
  94. public function serviceEntityAllActions ($iContentId = 0)
  95. {
  96. return $this->_oTemplate->entryAllActions('', $this->serviceEntitySocialSharing($iContentId));
  97. }
  98. /**
  99. * Entry location info
  100. */
  101. public function serviceEntityLocation ($iContentId = 0)
  102. {
  103. if (!$iContentId)
  104. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  105. if (!$iContentId)
  106. return false;
  107. return $this->_oTemplate->entryLocation ($iContentId);
  108. }
  109. /**
  110. * Entry comments
  111. */
  112. public function serviceEntityComments ($iContentId = 0)
  113. {
  114. return $this->_entityComments($this->_oConfig->CNF['OBJECT_COMMENTS'], $iContentId);
  115. }
  116. /**
  117. * Entry author block
  118. */
  119. public function serviceEntityAuthor ($iContentId = 0)
  120. {
  121. return $this->_serviceTemplateFunc ('entryAuthor', $iContentId);
  122. }
  123. /**
  124. * Entry attachments block
  125. */
  126. public function serviceEntityAttachments ($iContentId = 0)
  127. {
  128. return $this->_serviceTemplateFunc ('entryAttachments', $iContentId);
  129. }
  130. /**
  131. * My entries actions block
  132. */
  133. public function serviceMyEntriesActions ($iProfileId = 0)
  134. {
  135. if (!$iProfileId)
  136. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  137. if (!$iProfileId || $iProfileId != $this->_iProfileId)
  138. return false;
  139. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']);
  140. return $oMenu ? $oMenu->getCode() : false;
  141. }
  142. /**
  143. * Delete all content by profile
  144. * @param $iProfileId profile id
  145. * @return number of deleted items
  146. */
  147. public function serviceDeleteEntitiesByAuthor ($iProfileId)
  148. {
  149. $a = $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  150. if (!$a)
  151. return 0;
  152. $iCount = 0;
  153. foreach ($a as $aContentInfo)
  154. $iCount += ('' == $this->serviceDeleteEntity($aContentInfo[$this->_oConfig->CNF['FIELD_ID']]) ? 1 : 0);
  155. return $iCount;
  156. }
  157. // ====== PERMISSION METHODS
  158. /**
  159. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  160. */
  161. public function checkAllowedSetThumb ()
  162. {
  163. // check ACL
  164. $aCheck = checkActionModule($this->_iProfileId, 'set thumb', $this->getName(), false);
  165. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  166. return $aCheck[CHECK_ACTION_MESSAGE];
  167. return CHECK_ACTION_RESULT_ALLOWED;
  168. }
  169. // ====== PROTECTED METHODS
  170. protected function _buildRssParams($sMode, $aArgs)
  171. {
  172. $aParams = array ();
  173. $sMode = bx_process_input($sMode);
  174. switch ($sMode) {
  175. case 'author':
  176. $aParams = array('author' => isset($aArgs[0]) ? (int)$aArgs[0] : '');
  177. break;
  178. }
  179. return $aParams;
  180. }
  181. protected function _entityComments ($sObject, $iId = 0)
  182. {
  183. if (!$iId)
  184. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  185. if (!$iId)
  186. return false;
  187. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  188. if (!$oCmts || !$oCmts->isEnabled())
  189. return false;
  190. return $oCmts->getCommentsBlock(0, 0, false);
  191. }
  192. }
  193. /** @} */