BxBaseServices.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * System services.
  11. */
  12. class BxBaseServices extends BxDol implements iBxDolProfileService
  13. {
  14. public function __construct()
  15. {
  16. parent::__construct();
  17. }
  18. public function serviceProfileUnit ($iContentId, $aParams = array())
  19. {
  20. return $this->_serviceProfileFunc('getUnit', $iContentId);
  21. }
  22. public function serviceHasImage ($iContentId)
  23. {
  24. return false;
  25. }
  26. public function serviceProfilePicture ($iContentId)
  27. {
  28. return $this->_serviceProfileFunc('getPicture', $iContentId);
  29. }
  30. public function serviceProfileAvatar ($iContentId)
  31. {
  32. return $this->_serviceProfileFunc('getAvatar', $iContentId);
  33. }
  34. public function serviceProfileEditUrl ($iContentId)
  35. {
  36. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=account-settings-info');
  37. }
  38. public function serviceProfileThumb ($iContentId)
  39. {
  40. return $this->_serviceProfileFunc('getThumb', $iContentId);
  41. }
  42. public function serviceProfileIcon ($iContentId)
  43. {
  44. return $this->_serviceProfileFunc('getIcon', $iContentId);
  45. }
  46. public function serviceProfileName ($iContentId)
  47. {
  48. return $this->_serviceProfileFunc('getDisplayName', $iContentId);
  49. }
  50. public function serviceProfileUrl ($iContentId)
  51. {
  52. return $this->_serviceProfileFunc('getUrl', $iContentId);
  53. }
  54. /**
  55. * @see iBxDolProfileService::serviceCheckAllowedProfileView
  56. */
  57. public function serviceCheckAllowedProfileView($iContentId)
  58. {
  59. return _t('_Access denied');
  60. }
  61. /**
  62. * @see iBxDolProfileService::serviceCheckAllowedPostInProfile
  63. */
  64. public function serviceCheckAllowedPostInProfile($iContentId)
  65. {
  66. return _t('_Access denied');
  67. }
  68. /**
  69. * @see iBxDolProfileService::serviceGetSpaceTitle
  70. */
  71. public function serviceGetSpaceTitle()
  72. {
  73. return '';
  74. }
  75. /**
  76. * @see iBxDolProfileService::serviceGetParticipatingProfiles
  77. */
  78. public function serviceGetParticipatingProfiles($iProfileId)
  79. {
  80. return array();
  81. }
  82. /**
  83. * @see iBxDolProfileService::serviceCheckSpacePrivacy
  84. */
  85. public function serviceCheckSpacePrivacy($iContentId)
  86. {
  87. return _t('_Access denied');
  88. }
  89. public function serviceFormsHelper ()
  90. {
  91. return new BxTemplAccountForms();
  92. }
  93. public function serviceActAsProfile ()
  94. {
  95. return false;
  96. }
  97. public function servicePrepareFields ($aFieldsProfile)
  98. {
  99. return $aFieldsProfile;
  100. }
  101. public function serviceProfilesSearch ($sTerm, $iLimit)
  102. {
  103. $oDb = BxDolAccountQuery::getInstance();
  104. $aRet = array();
  105. $a = $oDb->searchByTerm($sTerm, $iLimit);
  106. foreach ($a as $r)
  107. $aRet[] = array ('label' => $this->serviceProfileName($r['content_id']), 'value' => $r['profile_id']);
  108. return $aRet;
  109. }
  110. public function serviceKeywordSearch ($sSection, $aCondition, $sTemplate = '', $iStart = 0, $iPerPage = 0, $bLiveSearch = 0)
  111. {
  112. if (!$sSection || !isset($aCondition['keyword']))
  113. return '';
  114. $sClass = 'BxTemplSearch';
  115. $sElsName = 'bx_elasticsearch';
  116. $sElsMethod = 'is_configured';
  117. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod)) {
  118. $oModule = BxDolModule::getInstance($sElsName);
  119. bx_import('Search', $oModule->_aModule);
  120. $sClass = 'BxElsSearch';
  121. }
  122. $oSearch = new $sClass(array($sSection));
  123. $oSearch->setLiveSearch($bLiveSearch);
  124. $oSearch->setMetaType(isset($aCondition['meta_type']) ? $aCondition['meta_type'] : '');
  125. $oSearch->setCategoryObject(isset($aCondition['cat']) ? $aCondition['cat'] : '');
  126. $oSearch->setCustomSearchCondition($aCondition);
  127. $oSearch->setRawProcessing(true);
  128. $oSearch->setCustomCurrentCondition(array(
  129. 'paginate' => array (
  130. 'start' => $iStart,
  131. 'perPage' => $iPerPage ? $iPerPage : BX_DOL_SEARCH_RESULTS_PER_PAGE_DEFAULT,
  132. )));
  133. if ($sTemplate)
  134. $oSearch->setUnitTemplate($sTemplate);
  135. return $oSearch->response();
  136. }
  137. public function _serviceProfileFunc ($sFunc, $iContentId)
  138. {
  139. if (!$iContentId)
  140. return false;
  141. if (!($oAccount = BxDolAccount::getInstance($iContentId)))
  142. return false;
  143. return $oAccount->$sFunc();
  144. }
  145. public function serviceAlertResponseProcessInstalled()
  146. {
  147. BxDolTranscoderImage::registerHandlersSystem();
  148. }
  149. public function serviceAlertResponseProcessStorageChange ($oAlert)
  150. {
  151. if ('sys_storage_default' != $oAlert->aExtras['option'])
  152. return;
  153. $aStorages = BxDolStorageQuery::getStorageObjects();
  154. foreach ($aStorages as $r) {
  155. if (0 == $r['current_size'] && 0 == $r['current_number'] && ($oStorage = BxDolStorage::getObjectInstance($r['object'])))
  156. $oStorage->changeStorageEngine($oAlert->aExtras['value']);
  157. }
  158. }
  159. /**
  160. * This service adds notification for users which open your site on mobile devices
  161. * and suggest to add your site to their mobile homepage.
  162. */
  163. public function serviceAddToMobileHomepage ()
  164. {
  165. BxDolTemplate::getInstance()->addJs('cubiq-add-to-homescreen/addtohomescreen.min.js');
  166. BxDolTemplate::getInstance()->addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'cubiq-add-to-homescreen/style/|addtohomescreen.css');
  167. return "<script>addToHomescreen();</script>";
  168. }
  169. }
  170. /** @} */