BxBaseModTextModule.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup BaseText Base classes for text modules
  7. * @ingroup UnaModules
  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 comments
  81. */
  82. public function serviceEntityComments ($iContentId = 0)
  83. {
  84. return $this->_entityComments($this->_oConfig->CNF['OBJECT_COMMENTS'], $iContentId);
  85. }
  86. /**
  87. * Entry author block
  88. */
  89. public function serviceEntityAuthor ($iContentId = 0)
  90. {
  91. return $this->_serviceTemplateFunc ('entryAuthor', $iContentId);
  92. }
  93. /**
  94. * Entry attachments block
  95. */
  96. public function serviceEntityAttachments ($iContentId = 0)
  97. {
  98. return $this->_serviceTemplateFunc ('entryAttachments', $iContentId);
  99. }
  100. public function serviceEntityBreadcrumb ($iContentId = 0)
  101. {
  102. if (!$iContentId)
  103. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  104. if (!$iContentId)
  105. return false;
  106. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  107. if (!$aContentInfo)
  108. return false;
  109. return $this->_oTemplate->entryBreadcrumb($aContentInfo);
  110. }
  111. /**
  112. * My entries actions block
  113. */
  114. public function serviceMyEntriesActions ($iProfileId = 0)
  115. {
  116. if (!$iProfileId)
  117. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  118. if (!$iProfileId || $iProfileId != $this->_iProfileId)
  119. return false;
  120. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']);
  121. return $oMenu ? $oMenu->getCode() : false;
  122. }
  123. /**
  124. * Delete all content by profile
  125. * @param $iProfileId profile id
  126. * @return number of deleted items
  127. */
  128. public function serviceDeleteEntitiesByAuthor ($iProfileId)
  129. {
  130. $a = $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  131. if (!$a)
  132. return 0;
  133. $iCount = 0;
  134. foreach ($a as $aContentInfo)
  135. $iCount += ('' == $this->serviceDeleteEntity($aContentInfo[$this->_oConfig->CNF['FIELD_ID']]) ? 1 : 0);
  136. return $iCount;
  137. }
  138. // ====== PERMISSION METHODS
  139. /**
  140. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  141. */
  142. public function checkAllowedSetThumb ()
  143. {
  144. // check ACL
  145. $aCheck = checkActionModule($this->_iProfileId, 'set thumb', $this->getName(), false);
  146. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  147. return $aCheck[CHECK_ACTION_MESSAGE];
  148. return CHECK_ACTION_RESULT_ALLOWED;
  149. }
  150. // ====== PROTECTED METHODS
  151. protected function _buildRssParams($sMode, $aArgs)
  152. {
  153. $aParams = array ();
  154. $sMode = bx_process_input($sMode);
  155. switch ($sMode) {
  156. case 'author':
  157. $aParams = array('author' => isset($aArgs[0]) ? (int)$aArgs[0] : '');
  158. break;
  159. }
  160. return $aParams;
  161. }
  162. protected function _entityComments ($sObject, $iId = 0)
  163. {
  164. if (!$iId)
  165. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  166. if (!$iId)
  167. return false;
  168. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  169. if (!$oCmts || !$oCmts->isEnabled())
  170. return false;
  171. return $oCmts->getCommentsBlock(0, 0, false);
  172. }
  173. }
  174. /** @} */