1
0

BxBaseServices.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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 serviceIsSafeService($s)
  19. {
  20. $sService = bx_gen_method_name($s);
  21. $aSafeServices = $this->serviceGetSafeServices();
  22. return isset($aSafeServices[$sService]);
  23. }
  24. public function serviceGetSafeServices()
  25. {
  26. return array(
  27. 'GetCreatePostForm' => 'BxBaseServices',
  28. 'KeywordSearch' => 'BxBaseServices',
  29. 'CreateAccountForm' => 'BxBaseServiceAccount',
  30. 'ForgotPassword' => 'BxBaseServiceAccount',
  31. 'CategoriesList' => 'BxBaseServiceCategory',
  32. );
  33. }
  34. public function serviceProfileUnit ($iContentId, $aParams = array())
  35. {
  36. return $this->_serviceProfileFunc('getUnit', $iContentId, $aParams);
  37. }
  38. public function serviceHasImage ($iContentId)
  39. {
  40. return false;
  41. }
  42. public function serviceProfilePicture ($iContentId)
  43. {
  44. return $this->_serviceProfileFunc('getPicture', $iContentId);
  45. }
  46. public function serviceProfileAvatar ($iContentId)
  47. {
  48. return $this->_serviceProfileFunc('getAvatar', $iContentId);
  49. }
  50. public function serviceProfileCover ($iContentId)
  51. {
  52. return $this->_serviceTemplateFunc('urlCover', $iContentId);
  53. }
  54. public function serviceProfileEditUrl ($iContentId)
  55. {
  56. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=account-settings-info');
  57. }
  58. public function serviceProfileThumb ($iContentId)
  59. {
  60. return $this->_serviceProfileFunc('getThumb', $iContentId);
  61. }
  62. public function serviceProfileIcon ($iContentId)
  63. {
  64. return $this->_serviceProfileFunc('getIcon', $iContentId);
  65. }
  66. public function serviceProfileName ($iContentId)
  67. {
  68. return $this->_serviceProfileFunc('getDisplayName', $iContentId);
  69. }
  70. public function serviceProfileUrl ($iContentId)
  71. {
  72. return $this->_serviceProfileFunc('getUrl', $iContentId);
  73. }
  74. /**
  75. * @see iBxDolProfileService::serviceCheckAllowedProfileView
  76. */
  77. public function serviceCheckAllowedProfileView($iContentId)
  78. {
  79. return _t('_Access denied');
  80. }
  81. /**
  82. * @see iBxDolProfileService::serviceCheckAllowedProfileContact
  83. */
  84. public function serviceCheckAllowedProfileContact($iContentId)
  85. {
  86. return _t('_Access denied');
  87. }
  88. /**
  89. * @see iBxDolProfileService::serviceCheckAllowedPostInProfile
  90. */
  91. public function serviceCheckAllowedPostInProfile($iContentId)
  92. {
  93. return _t('_Access denied');
  94. }
  95. /**
  96. * @see iBxDolProfileService::serviceGetSpaceTitle
  97. */
  98. public function serviceGetSpaceTitle()
  99. {
  100. return '';
  101. }
  102. /**
  103. * @see iBxDolProfileService::serviceGetParticipatingProfiles
  104. */
  105. public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObject = false)
  106. {
  107. return array();
  108. }
  109. /**
  110. * @page service Service Calls
  111. * @section bx_system_general System Services
  112. * @subsection bx_system_general-general General
  113. * @subsubsection bx_system_general-get_create_post_form get_create_post_form
  114. *
  115. * @code bx_srv('system', 'get_create_post_form', [false, "bx_posts"], 'TemplServices'); @endcode
  116. * @code {{~system:get_create_post_form:TemplServices[false,"bx_posts"]~}} @endcode
  117. *
  118. * Get United Create Post form.
  119. * @param $mixedContextId - context which the post will be created in:
  120. * - false = 'Public' post form;
  121. * - 0 = 'Profile' post form, which allows to post in your own profile and connections;
  122. * - n = 'Context' post form, which allows to post in context (3d party profile, group, event, etc).
  123. * @param $sDefault - tab selected by default.
  124. * @param $aCustom - an array with custom paramaters.
  125. * @return string with form content
  126. *
  127. * @see BxBaseServices::serviceGetCreatePostForm
  128. */
  129. /**
  130. * @ref bx_system_general-get_create_post_form "get_create_post_form"
  131. */
  132. public function serviceGetCreatePostForm($mixedContextId = false, $sDefault = '', $aCustom = array())
  133. {
  134. if(!isLogged() || ($mixedContextId !== false && !is_numeric($mixedContextId)))
  135. return '';
  136. if($mixedContextId !== false)
  137. $mixedContextId = (int)(!empty($mixedContextId) ? -$mixedContextId : bx_get_logged_profile_id());
  138. $bContext = $mixedContextId !== false;
  139. if($bContext && ($oContextProfile = BxDolProfile::getInstance(abs($mixedContextId))) !== false)
  140. if($oContextProfile->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  141. return '';
  142. $sTitle = _t('_sys_page_block_title_create_post' . (!$bContext ? '_public' : ($mixedContextId < 0 ? '_context' : '')));
  143. $sPlaceholder = _t('_sys_txt_create_post_placeholder', BxDolProfile::getInstance()->getDisplayName());
  144. $oMenu = BxDolMenu::getObjectInstance('sys_create_post');
  145. $aMenuItems = $oMenu->getMenuItems();
  146. if(empty($aMenuItems) || !is_array($aMenuItems))
  147. return '';
  148. if(empty($sDefault)) {
  149. $aDefault = array_shift($aMenuItems);
  150. $sDefault = $aDefault['module'];
  151. }
  152. $oMenu->setSelected($sDefault, $sDefault);
  153. $oTemplate = BxDolTemplate::getInstance();
  154. $oTemplate->addJs(array('BxDolCreatePost.js'));
  155. $sJsObject = 'oBxDolCreatePost';
  156. $sJsContent = $oTemplate->_wrapInTagJsCode("var " . $sJsObject . " = new BxDolCreatePost(" . json_encode(array(
  157. 'sObjName' => $sJsObject,
  158. 'sRootUrl' => BX_DOL_URL_ROOT,
  159. 'sDefault' => $sDefault,
  160. 'iContextId' => $bContext ? $mixedContextId : 0,
  161. 'oCustom' => $aCustom
  162. )) . ");");
  163. return array('content' => BxDolTemplate::getInstance()->parseHtmlByName('create_post_form.html', array(
  164. 'default' => $sDefault,
  165. 'title' => $sTitle,
  166. 'placeholder' => $sPlaceholder,
  167. 'user_thumb' => BxDolProfile::getInstance()->getUnit(0, array('template' => 'unit_wo_info')),
  168. 'menu' => $oMenu->getCode(),
  169. 'form' => BxDolService::call($sDefault, 'get_create_post_form', array(array('context_id' => $mixedContextId, 'ajax_mode' => true, 'absolute_action_url' => true, 'custom' => $aCustom))),
  170. 'js_object' => $sJsObject,
  171. 'js_content' => $sJsContent
  172. )));
  173. }
  174. /**
  175. * @see iBxDolProfileService::serviceCheckSpacePrivacy
  176. */
  177. public function serviceCheckSpacePrivacy($iContentId)
  178. {
  179. return _t('_Access denied');
  180. }
  181. public function serviceFormsHelper ()
  182. {
  183. return new BxTemplAccountForms();
  184. }
  185. public function serviceActAsProfile ()
  186. {
  187. return false;
  188. }
  189. public function servicePrepareFields ($aFieldsProfile)
  190. {
  191. return $aFieldsProfile;
  192. }
  193. public function serviceProfilesSearch ($sTerm, $iLimit)
  194. {
  195. $oDb = BxDolAccountQuery::getInstance();
  196. $aRet = array();
  197. $a = $oDb->searchByTerm($sTerm, $iLimit);
  198. foreach ($a as $r)
  199. $aRet[] = array ('label' => $this->serviceProfileName($r['content_id']), 'value' => $r['profile_id']);
  200. return $aRet;
  201. }
  202. /**
  203. * @page service Service Calls
  204. * @section bx_system_general System Services
  205. * @subsection bx_system_general-general General
  206. * @subsubsection bx_system_general-keyword_search keyword_search
  207. *
  208. * @code bx_srv('system', 'keyword_search', ["bx_posts", ["keyword" => "test"}], 'TemplServices'); @endcode
  209. *
  210. * @code {{~system:keyword_search:TemplServices["bx_posts", {"keyword":"test"}]~}} @endcode
  211. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country", "keyword": "AU"}, "unit.html"]~}} @endcode
  212. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_state", "state":"NSW", "keyword": "AU"}, "unit.html"]~}} @endcode
  213. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"}, "unit.html"]~}} @endcode
  214. * @code {{~system:keyword_search:TemplServices["bx_posts", {"meta_type": "mention", "keyword": 2}, "unit_gallery.html"]~}} @endcode
  215. * @code {{~system:keyword_search:TemplServices["bx_posts", {"cat": "bx_posts_cats", "keyword": 3}, "unit_gallery.html"]~}} @endcode
  216. *
  217. * Search by keyword
  218. * @param $sSection - search object to search in, usually module name, for example: bx_posts
  219. * @param $aCondition - condition for search, supported conditions:
  220. * - search by keyword: ["keyword" => "test"]
  221. * - search by country: ["meta_type" => "location_country", "keyword" => "AU"]
  222. * - search by country and state: ["meta_type": "location_country_state", "state":"NSW", "keyword": "AU"]
  223. * - search by country, state and city: ["meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"]
  224. * - search for mentions: ["meta_type" => "mention", "keyword" => 2]
  225. * - search in category: ["cat": "bx_posts_cats", "keyword": 3]
  226. * @param $sTemplate - template for displaying search results, for example: unit.html
  227. * @param $iStart - paginate, display records starting from this number
  228. * @param $iPerPage - paginate, display this number of records per page
  229. * @param $bLiveSearch - search results like in live search
  230. *
  231. * @see BxBaseServices::serviceKeywordSearch
  232. */
  233. /**
  234. * @ref bx_system_general-keyword_search "keyword_search"
  235. */
  236. public function serviceKeywordSearch ($sSection, $aCondition, $sTemplate = '', $iStart = 0, $iPerPage = 0, $bLiveSearch = 0)
  237. {
  238. if (!$sSection || !isset($aCondition['keyword']))
  239. return '';
  240. $sClass = 'BxTemplSearch';
  241. $sElsName = 'bx_elasticsearch';
  242. $sElsMethod = 'is_configured';
  243. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod)) {
  244. $oModule = BxDolModule::getInstance($sElsName);
  245. bx_import('Search', $oModule->_aModule);
  246. $sClass = 'BxElsSearch';
  247. }
  248. $oSearch = new $sClass(array($sSection));
  249. $oSearch->setLiveSearch($bLiveSearch);
  250. $oSearch->setMetaType(isset($aCondition['meta_type']) ? $aCondition['meta_type'] : '');
  251. $oSearch->setCategoryObject(isset($aCondition['cat']) ? $aCondition['cat'] : '');
  252. $oSearch->setCustomSearchCondition($aCondition);
  253. $oSearch->setRawProcessing(true);
  254. $oSearch->setCustomCurrentCondition(array(
  255. 'paginate' => array (
  256. 'start' => $iStart,
  257. 'perPage' => $iPerPage ? $iPerPage : BX_DOL_SEARCH_RESULTS_PER_PAGE_DEFAULT,
  258. )));
  259. if ($sTemplate)
  260. $oSearch->setUnitTemplate($sTemplate);
  261. return $oSearch->response();
  262. }
  263. public function _serviceProfileFunc ($sFunc, $iContentId, $aParams = array())
  264. {
  265. if (!$iContentId)
  266. return false;
  267. if (!($oAccount = BxDolAccount::getInstance($iContentId)))
  268. return false;
  269. return $oAccount->$sFunc(false, $aParams);
  270. }
  271. public function serviceAlertResponseProcessInstalled()
  272. {
  273. BxDolTranscoderImage::registerHandlersSystem();
  274. }
  275. public function serviceAlertResponseProcessStorageChange ($oAlert)
  276. {
  277. if ('sys_storage_default' != $oAlert->aExtras['option'])
  278. return;
  279. $aStorages = BxDolStorageQuery::getStorageObjects();
  280. foreach ($aStorages as $r) {
  281. if (0 == $r['current_size'] && 0 == $r['current_number'] && ($oStorage = BxDolStorage::getObjectInstance($r['object'])))
  282. $oStorage->changeStorageEngine($oAlert->aExtras['value']);
  283. }
  284. }
  285. /**
  286. * This service adds notification for users which open your site on mobile devices
  287. * and suggest to add your site to their mobile homepage.
  288. */
  289. public function serviceAddToMobileHomepage ()
  290. {
  291. BxDolTemplate::getInstance()->addJs('cubiq-add-to-homescreen/addtohomescreen.min.js');
  292. BxDolTemplate::getInstance()->addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'cubiq-add-to-homescreen/style/|addtohomescreen.css');
  293. return "<script>addToHomescreen();</script>";
  294. }
  295. public function serviceGetOptionsProfileBot()
  296. {
  297. $aResult = array(
  298. array('key' => '', 'value' => _t('_Select_one'))
  299. );
  300. $aAccountsIds = BxDolAccountQuery::getInstance()->getOperators();
  301. foreach($aAccountsIds as $iAccountId) {
  302. $aProfilesIds = BxDolAccount::getInstance($iAccountId)->getProfilesIds();
  303. foreach($aProfilesIds as $iProfileId)
  304. $aResult[] = array(
  305. 'key' => $iProfileId,
  306. 'value' => BxDolProfile::getInstance($iProfileId)->getDisplayName()
  307. );
  308. }
  309. return $aResult;
  310. }
  311. public function serviceGetOptionsEmbedDefault()
  312. {
  313. $aResults = array(
  314. '' => _t('_None')
  315. );
  316. $aObjects = BxDolEmbedQuery::getObjects();
  317. foreach($aObjects as $aObject)
  318. $aResults[$aObject['object']] = $aObject['title'];
  319. return $aResults;
  320. }
  321. public function serviceGetOptionsRelations()
  322. {
  323. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
  324. $aProfiles = array();
  325. foreach($aModules as $aModule) {
  326. $sMethod = 'act_as_profile';
  327. if(!BxDolRequest::serviceExists($aModule['name'], $sMethod) || !BxDolService::call($aModule['name'], $sMethod))
  328. continue;
  329. $aProfiles[$aModule['name']] = _t('_' . $aModule['name']);
  330. }
  331. $aResults = array();
  332. foreach($aProfiles as $sName1 => $sTitle1)
  333. foreach($aProfiles as $sName2 => $sTitle2)
  334. $aResults[$sName1 . '_' . $sName2] = $sTitle1 . ' - ' . $sTitle2;
  335. return $aResults;
  336. }
  337. }
  338. /** @} */