BxBaseModTextModule.php 6.4 KB

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