BxBaseServices.php 15 KB

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