BxBaseModTextModule.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup BaseText Base classes for text modules
  7. * @ingroup TridentModules
  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. * Display entries favored by a member
  81. * @return HTML string
  82. */
  83. public function serviceBrowseFavorite ($iProfileId = 0, $aParams = array())
  84. {
  85. $oProfile = null;
  86. if((int)$iProfileId)
  87. $oProfile = BxDolProfile::getInstance($iProfileId);
  88. if(!$oProfile && bx_get('profile_id') !== false)
  89. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  90. if(!$oProfile)
  91. $oProfile = BxDolProfile::getInstance();
  92. if(!$oProfile)
  93. return '';
  94. return $this->_serviceBrowse ('favorite', array_merge(array('user' => $oProfile->id()), $aParams), BX_DB_PADDING_DEF, true);
  95. }
  96. /**
  97. * Entry social sharing block
  98. */
  99. public function serviceEntitySocialSharing ($iContentId = 0)
  100. {
  101. if (!$iContentId)
  102. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  103. if (!$iContentId)
  104. return false;
  105. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  106. if (!$aContentInfo)
  107. return false;
  108. $CNF = &$this->_oConfig->CNF;
  109. return $this->_entitySocialSharing ($iContentId, array(
  110. 'id_timeline' => $iContentId,
  111. 'id_thumb' => $aContentInfo[$CNF['FIELD_THUMB']],
  112. 'title' => $aContentInfo[$CNF['FIELD_TITLE']],
  113. 'object_storage' => $CNF['OBJECT_STORAGE'],
  114. 'object_transcoder' => false,
  115. 'object_vote' => $CNF['OBJECT_VOTES'],
  116. 'object_report' => $CNF['OBJECT_REPORTS'],
  117. 'uri_view_entry' => $CNF['URI_VIEW_ENTRY']
  118. ));
  119. }
  120. public function serviceEntityAllActions ($iContentId = 0)
  121. {
  122. return $this->_oTemplate->entryAllActions('', $this->serviceEntitySocialSharing($iContentId));
  123. }
  124. /**
  125. * Entry comments
  126. */
  127. public function serviceEntityComments ($iContentId = 0)
  128. {
  129. return $this->_entityComments($this->_oConfig->CNF['OBJECT_COMMENTS'], $iContentId);
  130. }
  131. /**
  132. * Entry author block
  133. */
  134. public function serviceEntityAuthor ($iContentId = 0)
  135. {
  136. return $this->_serviceTemplateFunc ('entryAuthor', $iContentId);
  137. }
  138. /**
  139. * Entry attachments block
  140. */
  141. public function serviceEntityAttachments ($iContentId = 0)
  142. {
  143. return $this->_serviceTemplateFunc ('entryAttachments', $iContentId);
  144. }
  145. public function serviceEntityBreadcrumb ($iContentId = 0)
  146. {
  147. if (!$iContentId)
  148. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  149. if (!$iContentId)
  150. return false;
  151. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  152. if (!$aContentInfo)
  153. return false;
  154. return $this->_oTemplate->entryBreadcrumb($aContentInfo);
  155. }
  156. /**
  157. * My entries actions block
  158. */
  159. public function serviceMyEntriesActions ($iProfileId = 0)
  160. {
  161. if (!$iProfileId)
  162. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  163. if (!$iProfileId || $iProfileId != $this->_iProfileId)
  164. return false;
  165. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']);
  166. return $oMenu ? $oMenu->getCode() : false;
  167. }
  168. /**
  169. * Delete all content by profile
  170. * @param $iProfileId profile id
  171. * @return number of deleted items
  172. */
  173. public function serviceDeleteEntitiesByAuthor ($iProfileId)
  174. {
  175. $a = $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  176. if (!$a)
  177. return 0;
  178. $iCount = 0;
  179. foreach ($a as $aContentInfo)
  180. $iCount += ('' == $this->serviceDeleteEntity($aContentInfo[$this->_oConfig->CNF['FIELD_ID']]) ? 1 : 0);
  181. return $iCount;
  182. }
  183. // ====== PERMISSION METHODS
  184. /**
  185. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  186. */
  187. public function checkAllowedSetThumb ()
  188. {
  189. // check ACL
  190. $aCheck = checkActionModule($this->_iProfileId, 'set thumb', $this->getName(), false);
  191. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  192. return $aCheck[CHECK_ACTION_MESSAGE];
  193. return CHECK_ACTION_RESULT_ALLOWED;
  194. }
  195. // ====== AUXILIARY METHODS
  196. public function getObjectFavorite($sSystem = '', $iId = 0)
  197. {
  198. $CNF = &$this->_oConfig->CNF;
  199. if(empty($sSystem) && !empty($CNF['OBJECT_FAVORITES']))
  200. $sSystem = $CNF['OBJECT_FAVORITES'];
  201. if(empty($sSystem))
  202. return false;
  203. $oFavorite = BxDolFavorite::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  204. if(!$oFavorite->isEnabled())
  205. return false;
  206. return $oFavorite;
  207. }
  208. // ====== PROTECTED METHODS
  209. protected function _buildRssParams($sMode, $aArgs)
  210. {
  211. $aParams = array ();
  212. $sMode = bx_process_input($sMode);
  213. switch ($sMode) {
  214. case 'author':
  215. $aParams = array('author' => isset($aArgs[0]) ? (int)$aArgs[0] : '');
  216. break;
  217. }
  218. return $aParams;
  219. }
  220. protected function _entityComments ($sObject, $iId = 0)
  221. {
  222. if (!$iId)
  223. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  224. if (!$iId)
  225. return false;
  226. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  227. if (!$oCmts || !$oCmts->isEnabled())
  228. return false;
  229. return $oCmts->getCommentsBlock(0, 0, false);
  230. }
  231. }
  232. /** @} */