BxBaseModTextModule.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. return $this->_serviceBrowseWithParam ('author', 'profile_id', $iProfileId, $aParams);
  82. }
  83. /**
  84. * Display entries posted into particular context
  85. * @return HTML string
  86. */
  87. public function serviceBrowseContext ($iProfileId = 0, $aParams = array())
  88. {
  89. return $this->_serviceBrowseWithParam ('context', 'profile_id', $iProfileId, $aParams);
  90. }
  91. public function _serviceBrowseWithParam ($sParamName, $sParamGet, $sParamVal, $aParams = array())
  92. {
  93. if (!$sParamVal)
  94. $sParamVal = bx_process_input(bx_get($sParamGet), BX_DATA_INT);
  95. if (!$sParamVal)
  96. return '';
  97. $bEmptyMessage = true;
  98. if(isset($aParams['empty_message'])) {
  99. $bEmptyMessage = (bool)$aParams['empty_message'];
  100. unset($aParams['empty_message']);
  101. }
  102. return $this->_serviceBrowse ($sParamName, array_merge(array($sParamName => $sParamVal), $aParams), BX_DB_PADDING_DEF, $bEmptyMessage);
  103. }
  104. /**
  105. * Entry author block
  106. */
  107. public function serviceEntityAuthor ($iContentId = 0)
  108. {
  109. return $this->_serviceTemplateFunc ('entryAuthor', $iContentId);
  110. }
  111. /**
  112. * Entry context block
  113. */
  114. public function serviceEntityContext ($iContentId = 0)
  115. {
  116. return $this->_serviceTemplateFunc ('entryContext', $iContentId);
  117. }
  118. public function serviceEntityBreadcrumb ($iContentId = 0)
  119. {
  120. if (!$iContentId)
  121. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  122. if (!$iContentId)
  123. return false;
  124. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  125. if (!$aContentInfo)
  126. return false;
  127. return $this->_oTemplate->entryBreadcrumb($aContentInfo);
  128. }
  129. /**
  130. * Delete all content by profile
  131. * @param $iProfileId profile id
  132. * @return number of deleted items
  133. */
  134. public function serviceDeleteEntitiesByAuthor ($iProfileId)
  135. {
  136. $a = $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  137. if (!$a)
  138. return 0;
  139. $iCount = 0;
  140. foreach ($a as $aContentInfo)
  141. $iCount += ('' == $this->serviceDeleteEntity($aContentInfo[$this->_oConfig->CNF['FIELD_ID']]) ? 1 : 0);
  142. return $iCount;
  143. }
  144. // ====== PERMISSION METHODS
  145. /**
  146. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  147. */
  148. public function checkAllowedSetThumb ($iContentId = 0)
  149. {
  150. // check ACL
  151. $aCheck = checkActionModule($this->_iProfileId, 'set thumb', $this->getName(), false);
  152. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  153. return $aCheck[CHECK_ACTION_MESSAGE];
  154. return CHECK_ACTION_RESULT_ALLOWED;
  155. }
  156. // ====== PROTECTED METHODS
  157. protected function _buildRssParams($sMode, $aArgs)
  158. {
  159. $aParams = array ();
  160. $sMode = bx_process_input($sMode);
  161. switch ($sMode) {
  162. case 'author':
  163. $aParams = array('author' => isset($aArgs[0]) ? (int)$aArgs[0] : '');
  164. break;
  165. }
  166. return $aParams;
  167. }
  168. }
  169. /** @} */