BxBaseModTextModule.php 5.8 KB

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