BxBaseServices.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  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. 'Cmts' => 'BxBaseServices',
  30. 'CreateAccountForm' => 'BxBaseServiceAccount',
  31. 'ForgotPassword' => 'BxBaseServiceAccount',
  32. 'SwitchProfile' => 'BxBaseServiceAccount',
  33. 'CategoriesList' => 'BxBaseServiceCategory',
  34. 'Test' => 'BxBaseServiceLogin',
  35. 'MemberAuthCode' => 'BxBaseServiceLogin',
  36. 'LoginForm' => 'BxBaseServiceLogin',
  37. 'KeywordsCloud' => 'BxBaseServiceMetatags',
  38. 'ProfileMembership' => 'BxBaseServiceProfiles',
  39. 'ProfileNotifications' => 'BxBaseServiceProfiles',
  40. 'GetCountOnlineProfiles' => 'BxBaseServiceProfiles',
  41. 'GetChartGrowth' => 'BxBaseChartServices',
  42. 'GetChartStats' => 'BxBaseChartServices',
  43. 'GetCartItemsCount' => 'BxBasePaymentsServices',
  44. 'GetOrdersCount' => 'BxBasePaymentsServices',
  45. );
  46. }
  47. public function serviceProfileUnit ($iContentId, $aParams = array())
  48. {
  49. return $this->_serviceProfileFunc('getUnit', $iContentId, $aParams);
  50. }
  51. public function serviceHasImage ($iContentId)
  52. {
  53. return false;
  54. }
  55. public function serviceProfilePicture ($iContentId)
  56. {
  57. return BxDolTemplate::getInstance()->getImageUrl('account-picture.png');
  58. }
  59. public function serviceProfileAvatar ($iContentId)
  60. {
  61. return BxDolTemplate::getInstance()->getImageUrl('account-avatar.png');
  62. }
  63. public function serviceProfileCover ($iContentId)
  64. {
  65. return '';
  66. }
  67. public function serviceProfileEditUrl ($iContentId)
  68. {
  69. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=account-settings-info');
  70. }
  71. public function serviceProfileThumb ($iContentId)
  72. {
  73. return $this->_serviceProfileFunc('getThumb', $iContentId);
  74. }
  75. public function serviceProfileIcon ($iContentId)
  76. {
  77. return $this->_serviceProfileFunc('getIcon', $iContentId);
  78. }
  79. public function serviceProfileName ($iContentId)
  80. {
  81. return $this->_serviceProfileFunc('getDisplayName', $iContentId);
  82. }
  83. public function serviceProfileUrl ($iContentId)
  84. {
  85. return $this->_serviceProfileFunc('getUrl', $iContentId);
  86. }
  87. /**
  88. * @see iBxDolProfileService::serviceCheckAllowedProfileView
  89. */
  90. public function serviceCheckAllowedProfileView($iContentId)
  91. {
  92. return _t('_Access denied');
  93. }
  94. /**
  95. * @see iBxDolProfileService::serviceCheckAllowedProfileContact
  96. */
  97. public function serviceCheckAllowedProfileContact($iContentId)
  98. {
  99. return _t('_Access denied');
  100. }
  101. /**
  102. * @see iBxDolProfileService::serviceCheckAllowedPostInProfile
  103. */
  104. public function serviceCheckAllowedPostInProfile($iContentId)
  105. {
  106. return _t('_Access denied');
  107. }
  108. /**
  109. * @see iBxDolProfileService::serviceGetSpaceTitle
  110. */
  111. public function serviceGetSpaceTitle()
  112. {
  113. return '';
  114. }
  115. /**
  116. * @see iBxDolProfileService::serviceGetParticipatingProfiles
  117. */
  118. public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObject = false)
  119. {
  120. return array();
  121. }
  122. /**
  123. * @page service Service Calls
  124. * @section bx_system_general System Services
  125. * @subsection bx_system_general-general General
  126. * @subsubsection bx_system_general-get_create_post_form get_create_post_form
  127. *
  128. * @code bx_srv('system', 'get_create_post_form', [false, "bx_posts"], 'TemplServices'); @endcode
  129. * @code {{~system:get_create_post_form:TemplServices[false,"bx_posts"]~}} @endcode
  130. *
  131. * Get United Create Post form.
  132. * @param $mixedContextId - context which the post will be created in:
  133. * - false = 'Public' post form;
  134. * - 0 = 'Profile' post form, which allows to post in your own profile and connections;
  135. * - n = 'Context' post form, which allows to post in context (3d party profile, group, event, etc).
  136. * @param $sDefault - tab selected by default.
  137. * @param $aCustom - an array with custom paramaters.
  138. * @return string with form content
  139. *
  140. * @see BxBaseServices::serviceGetCreatePostForm
  141. */
  142. /**
  143. * @ref bx_system_general-get_create_post_form "get_create_post_form"
  144. */
  145. public function serviceGetCreatePostForm($mixedContextId = false, $sDefault = '', $aCustom = array())
  146. {
  147. if(!isLogged() || ($mixedContextId !== false && !is_numeric($mixedContextId)))
  148. return '';
  149. $oProfile = BxDolProfile::getInstance();
  150. if(!$oProfile)
  151. return '';
  152. if($mixedContextId !== false)
  153. $mixedContextId = (int)(!empty($mixedContextId) ? -$mixedContextId : $oProfile->id());
  154. $bContext = $mixedContextId !== false;
  155. if($bContext && ($oContextProfile = BxDolProfile::getInstance(abs($mixedContextId))) !== false)
  156. if($oContextProfile->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  157. return '';
  158. $sTitle = _t('_sys_page_block_title_create_post' . (!$bContext ? '_public' : ($mixedContextId < 0 ? '_context' : '')));
  159. $sPlaceholder = _t('_sys_txt_create_post_placeholder', $oProfile->getDisplayName());
  160. $oMenu = BxDolMenu::getObjectInstance('sys_create_post');
  161. if(!$oMenu)
  162. return '';
  163. $aMenuItems = $oMenu->getMenuItems();
  164. if(empty($aMenuItems) || !is_array($aMenuItems))
  165. return '';
  166. if(empty($sDefault)) {
  167. $aDefault = array_shift($aMenuItems);
  168. $sDefault = !empty($aDefault['module']) ? $aDefault['module'] : $aDefault['name'];
  169. }
  170. $oMenu->setSelected($sDefault, $sDefault);
  171. $oTemplate = BxDolTemplate::getInstance();
  172. $oTemplate->addJs(array('BxDolCreatePost.js'));
  173. $sJsObject = 'oBxDolCreatePost';
  174. $sJsContent = $oTemplate->_wrapInTagJsCode("var " . $sJsObject . " = new BxDolCreatePost(" . json_encode(array(
  175. 'sObjName' => $sJsObject,
  176. 'sRootUrl' => BX_DOL_URL_ROOT,
  177. 'sDefault' => $sDefault,
  178. 'iContextId' => $bContext ? $mixedContextId : 0,
  179. 'oCustom' => $aCustom
  180. )) . ");");
  181. return array(
  182. 'title' => $sTitle,
  183. 'content' => BxDolTemplate::getInstance()->parseHtmlByName('create_post_form.html', array(
  184. 'default' => $sDefault,
  185. 'placeholder' => $sPlaceholder,
  186. 'user_thumb' => $oProfile->getUnit(0, array('template' => 'unit_wo_info')),
  187. 'form' => BxDolService::call($sDefault, 'get_create_post_form', array(array('context_id' => $mixedContextId, 'ajax_mode' => true, 'absolute_action_url' => true, 'custom' => $aCustom))),
  188. 'js_object' => $sJsObject,
  189. 'js_content' => $sJsContent
  190. )),
  191. 'menu' => $oMenu
  192. );
  193. }
  194. /**
  195. * @see iBxDolProfileService::serviceCheckSpacePrivacy
  196. */
  197. public function serviceCheckSpacePrivacy($iContentId)
  198. {
  199. return _t('_Access denied');
  200. }
  201. public function serviceFormsHelper ()
  202. {
  203. return new BxTemplAccountForms();
  204. }
  205. public function serviceActAsProfile ()
  206. {
  207. return false;
  208. }
  209. public function servicePrepareFields ($aFieldsProfile)
  210. {
  211. return $aFieldsProfile;
  212. }
  213. public function serviceProfilesSearch ($sTerm, $iLimit)
  214. {
  215. $oDb = BxDolAccountQuery::getInstance();
  216. $aRet = array();
  217. $a = $oDb->searchByTerm($sTerm, $iLimit);
  218. foreach ($a as $r)
  219. $aRet[] = array ('label' => $this->serviceProfileName($r['content_id']), 'value' => $r['profile_id']);
  220. return $aRet;
  221. }
  222. /**
  223. * @page service Service Calls
  224. * @section bx_system_general System Services
  225. * @subsection bx_system_general-general General
  226. * @subsubsection bx_system_general-keyword_search keyword_search
  227. *
  228. * @code bx_srv('system', 'keyword_search', ["bx_posts", ["keyword" => "test"}], 'TemplServices'); @endcode
  229. *
  230. * @code {{~system:keyword_search:TemplServices["bx_posts", {"keyword":"test"}]~}} @endcode
  231. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country", "keyword": "AU"}, "unit.html"]~}} @endcode
  232. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_state", "state":"NSW", "keyword": "AU"}, "unit.html"]~}} @endcode
  233. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"}, "unit.html"]~}} @endcode
  234. * @code {{~system:keyword_search:TemplServices["bx_posts", {"meta_type": "mention", "keyword": 2}, "unit_gallery.html"]~}} @endcode
  235. * @code {{~system:keyword_search:TemplServices["bx_posts", {"cat": "bx_posts_cats", "keyword": 3}, "unit_gallery.html"]~}} @endcode
  236. *
  237. * Search by keyword
  238. * @param $sSection - search object to search in, usually module name, for example: bx_posts
  239. * @param $aCondition - condition for search, supported conditions:
  240. * - search by keyword: ["keyword" => "test"]
  241. * - search by country: ["meta_type" => "location_country", "keyword" => "AU"]
  242. * - search by country and state: ["meta_type": "location_country_state", "state":"NSW", "keyword": "AU"]
  243. * - search by country, state and city: ["meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"]
  244. * - search for mentions: ["meta_type" => "mention", "keyword" => 2]
  245. * - search in category: ["cat": "bx_posts_cats", "keyword": 3]
  246. * @param $sTemplate - template for displaying search results, for example: unit.html
  247. * @param $iStart - paginate, display records starting from this number
  248. * @param $iPerPage - paginate, display this number of records per page
  249. * @param $bLiveSearch - search results like in live search
  250. *
  251. * @see BxBaseServices::serviceKeywordSearch
  252. */
  253. /**
  254. * @ref bx_system_general-keyword_search "keyword_search"
  255. */
  256. public function serviceKeywordSearch ($sSection, $aCondition, $sTemplate = '', $iStart = 0, $iPerPage = 0, $bLiveSearch = 0, $bPaginate = false)
  257. {
  258. if (!$sSection || !isset($aCondition['keyword']))
  259. return '';
  260. $sClass = 'BxTemplSearch';
  261. $sElsName = 'bx_elasticsearch';
  262. $sElsMethod = 'is_configured';
  263. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod)) {
  264. $oModule = BxDolModule::getInstance($sElsName);
  265. bx_import('Search', $oModule->_aModule);
  266. $sClass = 'BxElsSearch';
  267. }
  268. $oSearch = new $sClass(array($sSection));
  269. $oSearch->setLiveSearch($bLiveSearch);
  270. $oSearch->setMetaType(isset($aCondition['meta_type']) ? $aCondition['meta_type'] : '');
  271. $oSearch->setCategoryObject(isset($aCondition['cat']) ? $aCondition['cat'] : '');
  272. $oSearch->setCustomSearchCondition($aCondition);
  273. if (!$bPaginate)
  274. $oSearch->setRawProcessing(true);
  275. $oSearch->setCustomCurrentCondition(array(
  276. 'paginate' => array (
  277. 'start' => $iStart,
  278. 'perPage' => $iPerPage ? $iPerPage : BX_DOL_SEARCH_RESULTS_PER_PAGE_DEFAULT,
  279. )));
  280. if ($sTemplate)
  281. $oSearch->setUnitTemplate($sTemplate);
  282. return $oSearch->response();
  283. }
  284. /**
  285. * @page service Service Calls
  286. * @section bx_system_general System Services
  287. * @subsection bx_system_general-general General
  288. * @subsubsection bx_system_general-keyword_search keyword_search
  289. *
  290. * @code bx_srv('system', 'search_keyword_form', 'TemplServices'); @endcode
  291. *
  292. * Block with Search by Keywords Form
  293. *
  294. * @see BxBaseServices::serviceSearchKeywordForm
  295. */
  296. /**
  297. * @ref bx_system_general-keyword_search "keyword_search"
  298. */
  299. public function serviceSearchKeywordForm ()
  300. {
  301. return $this->_getSearchObject()->getForm(BX_DB_PADDING_DEF, false, true);
  302. }
  303. /**
  304. * @page service Service Calls
  305. * @section bx_system_general System Services
  306. * @subsection bx_system_general-general General
  307. * @subsubsection bx_system_general-keyword_search keyword_search
  308. *
  309. * @code bx_srv('system', 'search_keyword_result', 'TemplServices'); @endcode
  310. *
  311. * Block with Search by Keywords Results
  312. *
  313. * @see BxBaseServices::serviceSearchKeywordResult
  314. */
  315. /**
  316. * @ref bx_system_general-keyword_search "keyword_search"
  317. */
  318. public function serviceSearchKeywordResult ()
  319. {
  320. $oSearch = $this->_getSearchObject();
  321. $sCode = '';
  322. if (bx_get('keyword') !== false) {
  323. $sCode = $oSearch->response();
  324. if (!$sCode)
  325. $sCode = $oSearch->getEmptyResult();
  326. else
  327. $sCode = '<div class="bx-def-margin-sec-top-neg">' . $sCode . '</div>';
  328. }
  329. return $sCode;
  330. }
  331. /**
  332. * @page service Service Calls
  333. * @section bx_system_general System Services
  334. * @subsection bx_system_general-general General
  335. * @subsubsection bx_system_general-cmts cmts
  336. *
  337. * @code bx_srv('system', 'cmts', ["sys_blocks", 1], 'TemplServices'); @endcode
  338. *
  339. * @code {{~system:cmts:TemplServices["sys_blocks", 1]~}} @endcode
  340. *
  341. * Comments block
  342. * @param $sObject - comments object name
  343. * @param $sId - content id assiciated tith the comments
  344. *
  345. * @see BxBaseServices::serviceCmts
  346. */
  347. /**
  348. * @ref bx_system_general-cmts "cmts"
  349. */
  350. public function serviceCmts ($sObject, $sId)
  351. {
  352. $o = BxDolCmts::getObjectInstance($sObject, $sId);
  353. if (!$o || !$o->isEnabled())
  354. return '';
  355. return $o->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
  356. }
  357. public function _serviceProfileFunc ($sFunc, $iContentId, $aParams = array())
  358. {
  359. if (!$iContentId)
  360. return false;
  361. if (!($oAccount = BxDolAccount::getInstance($iContentId)))
  362. return false;
  363. return $oAccount->$sFunc(false, $aParams);
  364. }
  365. public function serviceAlertResponseProcessInstalled()
  366. {
  367. BxDolTranscoderImage::registerHandlersSystem();
  368. }
  369. public function serviceAlertResponseProcessStorageChange ($oAlert)
  370. {
  371. if ('sys_storage_default' != $oAlert->aExtras['option'])
  372. return;
  373. $aStorages = BxDolStorageQuery::getStorageObjects();
  374. foreach ($aStorages as $r) {
  375. if (0 == $r['current_size'] && 0 == $r['current_number'] && ($oStorage = BxDolStorage::getObjectInstance($r['object'])))
  376. $oStorage->changeStorageEngine($oAlert->aExtras['value']);
  377. }
  378. }
  379. public function serviceGetOptionsProfileBot()
  380. {
  381. $aResult = array(
  382. array('key' => '', 'value' => _t('_Select_one'))
  383. );
  384. $aAccountsIds = BxDolAccountQuery::getInstance()->getOperators();
  385. foreach($aAccountsIds as $iAccountId) {
  386. $aProfilesIds = BxDolAccount::getInstance($iAccountId)->getProfilesIds(true, false);
  387. foreach($aProfilesIds as $iProfileId) {
  388. $oProfile = BxDolProfile::getInstance($iProfileId);
  389. $aResult[] = array(
  390. 'key' => $iProfileId,
  391. 'value' => _t('_sys_profile_with_type', $oProfile->getDisplayName(), $oProfile->getModule()),
  392. );
  393. }
  394. }
  395. return $aResult;
  396. }
  397. public function serviceGetOptionsModuleListForPrivacySelector()
  398. {
  399. $aResult = array();
  400. $BxDolModuleQuery = BxDolModuleQuery::getInstance();
  401. $aModules = $BxDolModuleQuery->getModulesBy(array('type' => 'modules', 'active' => 1));
  402. foreach($aModules as $aModule){
  403. $oModule = BxDolModule::getInstance($aModule['name']);
  404. if($oModule instanceof iBxDolContentInfoService){
  405. if (!BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  406. continue;
  407. $aResult[$aModule['name']] = $aModule['title'];
  408. }
  409. }
  410. return $aResult;
  411. }
  412. public function serviceGetOptionsEmbedDefault()
  413. {
  414. $aResults = array(
  415. '' => _t('_None')
  416. );
  417. $aObjects = BxDolEmbedQuery::getObjects();
  418. foreach($aObjects as $aObject)
  419. $aResults[$aObject['object']] = $aObject['title'];
  420. return $aResults;
  421. }
  422. public function serviceGetOptionsRelations()
  423. {
  424. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
  425. $aProfiles = array();
  426. foreach($aModules as $aModule) {
  427. $sMethod = 'act_as_profile';
  428. if(!BxDolRequest::serviceExists($aModule['name'], $sMethod) || !BxDolService::call($aModule['name'], $sMethod))
  429. continue;
  430. $aProfiles[$aModule['name']] = _t('_' . $aModule['name']);
  431. }
  432. $aResults = array();
  433. foreach($aProfiles as $sName1 => $sTitle1)
  434. foreach($aProfiles as $sName2 => $sTitle2)
  435. $aResults[$sName1 . '_' . $sName2] = $sTitle1 . ' - ' . $sTitle2;
  436. return $aResults;
  437. }
  438. public function serviceGetBadge($aBadge, $bIsCompact = false)
  439. {
  440. $sClass = '';
  441. $sStyleFont = '';
  442. $sStyleBg = '';
  443. if ($aBadge['color'] == '')
  444. $aBadge['color'] = '#ff0000';
  445. if ($aBadge['fontcolor'] == '')
  446. $aBadge['fontcolor'] = '#ffffff';
  447. if ($bIsCompact){
  448. $aBadge['is_icon_only'] = 1;
  449. $sClass .= ' bx-badge-compact-to';
  450. $sStyleFont = 'color: ' . $aBadge['fontcolor'];
  451. }
  452. else{
  453. $sStyleBg = 'background-color: ' . $aBadge['color'] . '; color: ' . $aBadge['fontcolor'];
  454. }
  455. if ($aBadge['is_icon_only'] == 1){
  456. $sClass .= ' bx-badge-compact';
  457. }
  458. return BxDolTemplate::getInstance()->parseHtmlByName('badge.html', array(
  459. 'bx_if:content' => array(
  460. 'condition' => $aBadge['is_icon_only'] != '1',
  461. 'content' => array('content' => _t($aBadge['text'])),
  462. ),
  463. 'bx_if:icon' => array(
  464. 'condition' => $aBadge['icon'] != '',
  465. 'content' => array('content' => BxDolTemplate::getInstance()->getIcon($aBadge['icon'], array('class' => 'bx-badge-icon sys-colored', 'style' => $sStyleFont))),
  466. ),
  467. 'title' => $aBadge['text'],
  468. 'style_font' => $sStyleFont,
  469. 'style_bg' => $sStyleBg,
  470. 'class' => $sClass,
  471. )
  472. );
  473. }
  474. private function _getSearchObject()
  475. {
  476. $sClass = 'BxTemplSearch';
  477. $sElsName = 'bx_elasticsearch';
  478. $sElsMethod = 'is_configured';
  479. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod) && !bx_get('cat') && !bx_get('type')) {
  480. $oModule = BxDolModule::getInstance($sElsName);
  481. bx_import('Search', $oModule->_aModule);
  482. $sClass = 'BxElsSearch';
  483. }
  484. bx_alert('system', 'search_keyword', 0, 0, array('class' => &$sClass));
  485. $oSearch = new $sClass(bx_get('section'));
  486. $oSearch->setLiveSearch(bx_get('live_search') ? 1 : 0);
  487. $oSearch->setMetaType(bx_process_input(bx_get('type')));
  488. $oSearch->setCategoryObject(bx_process_input(bx_get('cat')));
  489. return $oSearch;
  490. }
  491. }
  492. /** @} */