BxBaseServices.php 10 KB

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