BxBaseServices.php 7.5 KB

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