1
0

BxBaseModTextModule.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. * Display entries favored by a member
  81. * @return HTML string
  82. */
  83. public function serviceBrowseFavorite ($iProfileId = 0, $aParams = array())
  84. {
  85. $oProfile = null;
  86. if((int)$iProfileId)
  87. $oProfile = BxDolProfile::getInstance($iProfileId);
  88. if(!$oProfile && bx_get('profile_id') !== false)
  89. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  90. if(!$oProfile)
  91. $oProfile = BxDolProfile::getInstance();
  92. if(!$oProfile)
  93. return '';
  94. return $this->_serviceBrowse ('favorite', array_merge(array('user' => $oProfile->id()), $aParams), BX_DB_PADDING_DEF, true);
  95. }
  96. /**
  97. * Entry social sharing block
  98. */
  99. public function serviceEntityAllActions ($iContentId = 0)
  100. {
  101. return $this->_oTemplate->entryAllActions('', $this->serviceEntitySocialSharing($iContentId));
  102. }
  103. /**
  104. * Entry comments
  105. */
  106. public function serviceEntityComments ($iContentId = 0)
  107. {
  108. return $this->_entityComments($this->_oConfig->CNF['OBJECT_COMMENTS'], $iContentId);
  109. }
  110. /**
  111. * Entry author block
  112. */
  113. public function serviceEntityAuthor ($iContentId = 0)
  114. {
  115. return $this->_serviceTemplateFunc ('entryAuthor', $iContentId);
  116. }
  117. /**
  118. * Entry attachments block
  119. */
  120. public function serviceEntityAttachments ($iContentId = 0)
  121. {
  122. return $this->_serviceTemplateFunc ('entryAttachments', $iContentId);
  123. }
  124. public function serviceEntityBreadcrumb ($iContentId = 0)
  125. {
  126. if (!$iContentId)
  127. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  128. if (!$iContentId)
  129. return false;
  130. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  131. if (!$aContentInfo)
  132. return false;
  133. return $this->_oTemplate->entryBreadcrumb($aContentInfo);
  134. }
  135. /**
  136. * My entries actions block
  137. */
  138. public function serviceMyEntriesActions ($iProfileId = 0)
  139. {
  140. if (!$iProfileId)
  141. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  142. if (!$iProfileId || $iProfileId != $this->_iProfileId)
  143. return false;
  144. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']);
  145. return $oMenu ? $oMenu->getCode() : false;
  146. }
  147. /**
  148. * Delete all content by profile
  149. * @param $iProfileId profile id
  150. * @return number of deleted items
  151. */
  152. public function serviceDeleteEntitiesByAuthor ($iProfileId)
  153. {
  154. $a = $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  155. if (!$a)
  156. return 0;
  157. $iCount = 0;
  158. foreach ($a as $aContentInfo)
  159. $iCount += ('' == $this->serviceDeleteEntity($aContentInfo[$this->_oConfig->CNF['FIELD_ID']]) ? 1 : 0);
  160. return $iCount;
  161. }
  162. // ====== PERMISSION METHODS
  163. /**
  164. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  165. */
  166. public function checkAllowedSetThumb ()
  167. {
  168. // check ACL
  169. $aCheck = checkActionModule($this->_iProfileId, 'set thumb', $this->getName(), false);
  170. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  171. return $aCheck[CHECK_ACTION_MESSAGE];
  172. return CHECK_ACTION_RESULT_ALLOWED;
  173. }
  174. // ====== AUXILIARY METHODS
  175. public function getObjectFavorite($sSystem = '', $iId = 0)
  176. {
  177. $CNF = &$this->_oConfig->CNF;
  178. if(empty($sSystem) && !empty($CNF['OBJECT_FAVORITES']))
  179. $sSystem = $CNF['OBJECT_FAVORITES'];
  180. if(empty($sSystem))
  181. return false;
  182. $oFavorite = BxDolFavorite::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  183. if(!$oFavorite->isEnabled())
  184. return false;
  185. return $oFavorite;
  186. }
  187. // ====== PROTECTED METHODS
  188. protected function _buildRssParams($sMode, $aArgs)
  189. {
  190. $aParams = array ();
  191. $sMode = bx_process_input($sMode);
  192. switch ($sMode) {
  193. case 'author':
  194. $aParams = array('author' => isset($aArgs[0]) ? (int)$aArgs[0] : '');
  195. break;
  196. }
  197. return $aParams;
  198. }
  199. protected function _entityComments ($sObject, $iId = 0)
  200. {
  201. if (!$iId)
  202. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  203. if (!$iId)
  204. return false;
  205. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  206. if (!$oCmts || !$oCmts->isEnabled())
  207. return false;
  208. return $oCmts->getCommentsBlock(0, 0, false);
  209. }
  210. }
  211. /** @} */