BxBaseServices.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. public function serviceGetCreatePostForm($sDefault = 'bx_posts')
  87. {
  88. if(!isLogged())
  89. return '';
  90. $oMenu = BxDolMenu::getObjectInstance('sys_create_post');
  91. $aMenuItems = $oMenu->getMenuItems();
  92. if(empty($aMenuItems) || !is_array($aMenuItems))
  93. return '';
  94. if(empty($sDefault)) {
  95. $aDefault = array_shift($aMenuItems);
  96. $sDefault = $aDefault['module'];
  97. }
  98. $oMenu->setSelected($sDefault, $sDefault);
  99. $oTemplate = BxDolTemplate::getInstance();
  100. $oTemplate->addJs(array('BxDolCreatePost.js'));
  101. $sJsObject = 'oBxDolCreatePost';
  102. $sJsContent = $oTemplate->_wrapInTagJsCode("var " . $sJsObject . " = new BxDolCreatePost(" . json_encode(array(
  103. 'sObjName' => $sJsObject,
  104. 'sRootUrl' => BX_DOL_URL_ROOT,
  105. 'sDefault' => $sDefault
  106. )) . ");");
  107. return array('content' => BxDolTemplate::getInstance()->parseHtmlByName('create_post_form.html', array(
  108. 'default' => $sDefault,
  109. 'user_thumb' => BxDolProfile::getInstance()->getUnit(0, array('template' => 'unit_wo_info')),
  110. 'menu' => $oMenu->getCode(),
  111. 'form' => BxDolService::call($sDefault, 'get_create_post_form', array(array('ajax_mode' => true, 'absolute_action_url' => true))),
  112. 'js_object' => $sJsObject,
  113. 'js_content' => $sJsContent
  114. )));
  115. }
  116. /**
  117. * @see iBxDolProfileService::serviceCheckSpacePrivacy
  118. */
  119. public function serviceCheckSpacePrivacy($iContentId)
  120. {
  121. return _t('_Access denied');
  122. }
  123. public function serviceFormsHelper ()
  124. {
  125. return new BxTemplAccountForms();
  126. }
  127. public function serviceActAsProfile ()
  128. {
  129. return false;
  130. }
  131. public function servicePrepareFields ($aFieldsProfile)
  132. {
  133. return $aFieldsProfile;
  134. }
  135. public function serviceProfilesSearch ($sTerm, $iLimit)
  136. {
  137. $oDb = BxDolAccountQuery::getInstance();
  138. $aRet = array();
  139. $a = $oDb->searchByTerm($sTerm, $iLimit);
  140. foreach ($a as $r)
  141. $aRet[] = array ('label' => $this->serviceProfileName($r['content_id']), 'value' => $r['profile_id']);
  142. return $aRet;
  143. }
  144. public function serviceKeywordSearch ($sSection, $aCondition, $sTemplate = '', $iStart = 0, $iPerPage = 0, $bLiveSearch = 0)
  145. {
  146. if (!$sSection || !isset($aCondition['keyword']))
  147. return '';
  148. $sClass = 'BxTemplSearch';
  149. $sElsName = 'bx_elasticsearch';
  150. $sElsMethod = 'is_configured';
  151. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod)) {
  152. $oModule = BxDolModule::getInstance($sElsName);
  153. bx_import('Search', $oModule->_aModule);
  154. $sClass = 'BxElsSearch';
  155. }
  156. $oSearch = new $sClass(array($sSection));
  157. $oSearch->setLiveSearch($bLiveSearch);
  158. $oSearch->setMetaType(isset($aCondition['meta_type']) ? $aCondition['meta_type'] : '');
  159. $oSearch->setCategoryObject(isset($aCondition['cat']) ? $aCondition['cat'] : '');
  160. $oSearch->setCustomSearchCondition($aCondition);
  161. $oSearch->setRawProcessing(true);
  162. $oSearch->setCustomCurrentCondition(array(
  163. 'paginate' => array (
  164. 'start' => $iStart,
  165. 'perPage' => $iPerPage ? $iPerPage : BX_DOL_SEARCH_RESULTS_PER_PAGE_DEFAULT,
  166. )));
  167. if ($sTemplate)
  168. $oSearch->setUnitTemplate($sTemplate);
  169. return $oSearch->response();
  170. }
  171. public function _serviceProfileFunc ($sFunc, $iContentId)
  172. {
  173. if (!$iContentId)
  174. return false;
  175. if (!($oAccount = BxDolAccount::getInstance($iContentId)))
  176. return false;
  177. return $oAccount->$sFunc();
  178. }
  179. public function serviceAlertResponseProcessInstalled()
  180. {
  181. BxDolTranscoderImage::registerHandlersSystem();
  182. }
  183. public function serviceAlertResponseProcessStorageChange ($oAlert)
  184. {
  185. if ('sys_storage_default' != $oAlert->aExtras['option'])
  186. return;
  187. $aStorages = BxDolStorageQuery::getStorageObjects();
  188. foreach ($aStorages as $r) {
  189. if (0 == $r['current_size'] && 0 == $r['current_number'] && ($oStorage = BxDolStorage::getObjectInstance($r['object'])))
  190. $oStorage->changeStorageEngine($oAlert->aExtras['value']);
  191. }
  192. }
  193. /**
  194. * This service adds notification for users which open your site on mobile devices
  195. * and suggest to add your site to their mobile homepage.
  196. */
  197. public function serviceAddToMobileHomepage ()
  198. {
  199. BxDolTemplate::getInstance()->addJs('cubiq-add-to-homescreen/addtohomescreen.min.js');
  200. BxDolTemplate::getInstance()->addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'cubiq-add-to-homescreen/style/|addtohomescreen.css');
  201. return "<script>addToHomescreen();</script>";
  202. }
  203. }
  204. /** @} */