BxBaseServices.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  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-cmts cmts
  289. *
  290. * @code bx_srv('system', 'cmts', ["sys_blocks", 1], 'TemplServices'); @endcode
  291. *
  292. * @code {{~system:cmts:TemplServices["sys_blocks", 1]~}} @endcode
  293. *
  294. * Comments block
  295. * @param $sObject - comments object name
  296. * @param $sId - content id assiciated tith the comments
  297. *
  298. * @see BxBaseServices::serviceCmts
  299. */
  300. /**
  301. * @ref bx_system_general-cmts "cmts"
  302. */
  303. public function serviceCmts ($sObject, $sId)
  304. {
  305. $o = BxDolCmts::getObjectInstance($sObject, $sId);
  306. if (!$o || !$o->isEnabled())
  307. return '';
  308. return $o->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
  309. }
  310. public function _serviceProfileFunc ($sFunc, $iContentId, $aParams = array())
  311. {
  312. if (!$iContentId)
  313. return false;
  314. if (!($oAccount = BxDolAccount::getInstance($iContentId)))
  315. return false;
  316. return $oAccount->$sFunc(false, $aParams);
  317. }
  318. public function serviceAlertResponseProcessInstalled()
  319. {
  320. BxDolTranscoderImage::registerHandlersSystem();
  321. }
  322. public function serviceAlertResponseProcessStorageChange ($oAlert)
  323. {
  324. if ('sys_storage_default' != $oAlert->aExtras['option'])
  325. return;
  326. $aStorages = BxDolStorageQuery::getStorageObjects();
  327. foreach ($aStorages as $r) {
  328. if (0 == $r['current_size'] && 0 == $r['current_number'] && ($oStorage = BxDolStorage::getObjectInstance($r['object'])))
  329. $oStorage->changeStorageEngine($oAlert->aExtras['value']);
  330. }
  331. }
  332. public function serviceGetOptionsProfileBot()
  333. {
  334. $aResult = array(
  335. array('key' => '', 'value' => _t('_Select_one'))
  336. );
  337. $aAccountsIds = BxDolAccountQuery::getInstance()->getOperators();
  338. foreach($aAccountsIds as $iAccountId) {
  339. $aProfilesIds = BxDolAccount::getInstance($iAccountId)->getProfilesIds(true, false);
  340. foreach($aProfilesIds as $iProfileId) {
  341. $oProfile = BxDolProfile::getInstance($iProfileId);
  342. $aResult[] = array(
  343. 'key' => $iProfileId,
  344. 'value' => _t('_sys_profile_with_type', $oProfile->getDisplayName(), $oProfile->getModule()),
  345. );
  346. }
  347. }
  348. return $aResult;
  349. }
  350. public function serviceGetOptionsModuleListForPrivacySelector()
  351. {
  352. $aResult = array();
  353. $BxDolModuleQuery = BxDolModuleQuery::getInstance();
  354. $aModules = $BxDolModuleQuery->getModulesBy(array('type' => 'modules', 'active' => 1));
  355. foreach($aModules as $aModule){
  356. $oModule = BxDolModule::getInstance($aModule['name']);
  357. if($oModule instanceof iBxDolContentInfoService){
  358. if (!BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  359. continue;
  360. $aResult[$aModule['name']] = $aModule['title'];
  361. }
  362. }
  363. return $aResult;
  364. }
  365. public function serviceGetOptionsEmbedDefault()
  366. {
  367. $aResults = array(
  368. '' => _t('_None')
  369. );
  370. $aObjects = BxDolEmbedQuery::getObjects();
  371. foreach($aObjects as $aObject)
  372. $aResults[$aObject['object']] = $aObject['title'];
  373. return $aResults;
  374. }
  375. public function serviceGetOptionsRelations()
  376. {
  377. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
  378. $aProfiles = array();
  379. foreach($aModules as $aModule) {
  380. $sMethod = 'act_as_profile';
  381. if(!BxDolRequest::serviceExists($aModule['name'], $sMethod) || !BxDolService::call($aModule['name'], $sMethod))
  382. continue;
  383. $aProfiles[$aModule['name']] = _t('_' . $aModule['name']);
  384. }
  385. $aResults = array();
  386. foreach($aProfiles as $sName1 => $sTitle1)
  387. foreach($aProfiles as $sName2 => $sTitle2)
  388. $aResults[$sName1 . '_' . $sName2] = $sTitle1 . ' - ' . $sTitle2;
  389. return $aResults;
  390. }
  391. public function serviceGetBadge($aBadge, $bIsCompact = false)
  392. {
  393. $sClass = '';
  394. $sStyleFont = '';
  395. $sStyleBg = '';
  396. if ($aBadge['color'] == '')
  397. $aBadge['color'] = '#ff0000';
  398. if ($aBadge['fontcolor'] == '')
  399. $aBadge['fontcolor'] = '#ffffff';
  400. if ($bIsCompact){
  401. $aBadge['is_icon_only'] = 1;
  402. $sClass .= ' bx-badge-compact-to';
  403. $sStyleFont = 'color: ' . $aBadge['fontcolor'];
  404. }
  405. else{
  406. $sStyleBg = 'background-color: ' . $aBadge['color'] . '; color: ' . $aBadge['fontcolor'];
  407. }
  408. if ($aBadge['is_icon_only'] == 1){
  409. $sClass .= ' bx-badge-compact';
  410. }
  411. return BxDolTemplate::getInstance()->parseHtmlByName('badge.html', array(
  412. 'bx_if:content' => array(
  413. 'condition' => $aBadge['is_icon_only'] != '1',
  414. 'content' => array('content' => _t($aBadge['text'])),
  415. ),
  416. 'bx_if:icon' => array(
  417. 'condition' => $aBadge['icon'] != '',
  418. 'content' => array('content' => BxDolTemplate::getInstance()->getIcon($aBadge['icon'], array('class' => 'bx-badge-icon sys-colored', 'style' => $sStyleFont))),
  419. ),
  420. 'title' => $aBadge['text'],
  421. 'style_font' => $sStyleFont,
  422. 'style_bg' => $sStyleBg,
  423. 'class' => $sClass,
  424. )
  425. );
  426. }
  427. }
  428. /** @} */