1
0

BxBaseServices.php 6.0 KB

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