BxBaseServices.php 8.9 KB

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