1
0

BxBaseModTextModule.php 6.3 KB

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