BxBaseServices.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  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('content' => BxDolTemplate::getInstance()->parseHtmlByName('create_post_form.html', array(
  182. 'default' => $sDefault,
  183. 'title' => $sTitle,
  184. 'placeholder' => $sPlaceholder,
  185. 'user_thumb' => $oProfile->getUnit(0, array('template' => 'unit_wo_info')),
  186. 'menu' => $oMenu->getCode(),
  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. }
  192. /**
  193. * @see iBxDolProfileService::serviceCheckSpacePrivacy
  194. */
  195. public function serviceCheckSpacePrivacy($iContentId)
  196. {
  197. return _t('_Access denied');
  198. }
  199. public function serviceFormsHelper ()
  200. {
  201. return new BxTemplAccountForms();
  202. }
  203. public function serviceActAsProfile ()
  204. {
  205. return false;
  206. }
  207. public function servicePrepareFields ($aFieldsProfile)
  208. {
  209. return $aFieldsProfile;
  210. }
  211. public function serviceProfilesSearch ($sTerm, $iLimit)
  212. {
  213. $oDb = BxDolAccountQuery::getInstance();
  214. $aRet = array();
  215. $a = $oDb->searchByTerm($sTerm, $iLimit);
  216. foreach ($a as $r)
  217. $aRet[] = array ('label' => $this->serviceProfileName($r['content_id']), 'value' => $r['profile_id']);
  218. return $aRet;
  219. }
  220. /**
  221. * @page service Service Calls
  222. * @section bx_system_general System Services
  223. * @subsection bx_system_general-general General
  224. * @subsubsection bx_system_general-keyword_search keyword_search
  225. *
  226. * @code bx_srv('system', 'keyword_search', ["bx_posts", ["keyword" => "test"}], 'TemplServices'); @endcode
  227. *
  228. * @code {{~system:keyword_search:TemplServices["bx_posts", {"keyword":"test"}]~}} @endcode
  229. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country", "keyword": "AU"}, "unit.html"]~}} @endcode
  230. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_state", "state":"NSW", "keyword": "AU"}, "unit.html"]~}} @endcode
  231. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"}, "unit.html"]~}} @endcode
  232. * @code {{~system:keyword_search:TemplServices["bx_posts", {"meta_type": "mention", "keyword": 2}, "unit_gallery.html"]~}} @endcode
  233. * @code {{~system:keyword_search:TemplServices["bx_posts", {"cat": "bx_posts_cats", "keyword": 3}, "unit_gallery.html"]~}} @endcode
  234. *
  235. * Search by keyword
  236. * @param $sSection - search object to search in, usually module name, for example: bx_posts
  237. * @param $aCondition - condition for search, supported conditions:
  238. * - search by keyword: ["keyword" => "test"]
  239. * - search by country: ["meta_type" => "location_country", "keyword" => "AU"]
  240. * - search by country and state: ["meta_type": "location_country_state", "state":"NSW", "keyword": "AU"]
  241. * - search by country, state and city: ["meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"]
  242. * - search for mentions: ["meta_type" => "mention", "keyword" => 2]
  243. * - search in category: ["cat": "bx_posts_cats", "keyword": 3]
  244. * @param $sTemplate - template for displaying search results, for example: unit.html
  245. * @param $iStart - paginate, display records starting from this number
  246. * @param $iPerPage - paginate, display this number of records per page
  247. * @param $bLiveSearch - search results like in live search
  248. *
  249. * @see BxBaseServices::serviceKeywordSearch
  250. */
  251. /**
  252. * @ref bx_system_general-keyword_search "keyword_search"
  253. */
  254. public function serviceKeywordSearch ($sSection, $aCondition, $sTemplate = '', $iStart = 0, $iPerPage = 0, $bLiveSearch = 0)
  255. {
  256. if (!$sSection || !isset($aCondition['keyword']))
  257. return '';
  258. $sClass = 'BxTemplSearch';
  259. $sElsName = 'bx_elasticsearch';
  260. $sElsMethod = 'is_configured';
  261. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod)) {
  262. $oModule = BxDolModule::getInstance($sElsName);
  263. bx_import('Search', $oModule->_aModule);
  264. $sClass = 'BxElsSearch';
  265. }
  266. $oSearch = new $sClass(array($sSection));
  267. $oSearch->setLiveSearch($bLiveSearch);
  268. $oSearch->setMetaType(isset($aCondition['meta_type']) ? $aCondition['meta_type'] : '');
  269. $oSearch->setCategoryObject(isset($aCondition['cat']) ? $aCondition['cat'] : '');
  270. $oSearch->setCustomSearchCondition($aCondition);
  271. $oSearch->setRawProcessing(true);
  272. $oSearch->setCustomCurrentCondition(array(
  273. 'paginate' => array (
  274. 'start' => $iStart,
  275. 'perPage' => $iPerPage ? $iPerPage : BX_DOL_SEARCH_RESULTS_PER_PAGE_DEFAULT,
  276. )));
  277. if ($sTemplate)
  278. $oSearch->setUnitTemplate($sTemplate);
  279. return $oSearch->response();
  280. }
  281. /**
  282. * @page service Service Calls
  283. * @section bx_system_general System Services
  284. * @subsection bx_system_general-general General
  285. * @subsubsection bx_system_general-cmts cmts
  286. *
  287. * @code bx_srv('system', 'cmts', ["sys_blocks", 1], 'TemplServices'); @endcode
  288. *
  289. * @code {{~system:cmts:TemplServices["sys_blocks", 1]~}} @endcode
  290. *
  291. * Comments block
  292. * @param $sObject - comments object name
  293. * @param $sId - content id assiciated tith the comments
  294. *
  295. * @see BxBaseServices::serviceCmts
  296. */
  297. /**
  298. * @ref bx_system_general-cmts "cmts"
  299. */
  300. public function serviceCmts ($sObject, $sId)
  301. {
  302. $o = BxDolCmts::getObjectInstance($sObject, $sId);
  303. if (!$o || !$o->isEnabled())
  304. return '';
  305. return $o->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
  306. }
  307. public function _serviceProfileFunc ($sFunc, $iContentId, $aParams = array())
  308. {
  309. if (!$iContentId)
  310. return false;
  311. if (!($oAccount = BxDolAccount::getInstance($iContentId)))
  312. return false;
  313. return $oAccount->$sFunc(false, $aParams);
  314. }
  315. public function serviceAlertResponseProcessInstalled()
  316. {
  317. BxDolTranscoderImage::registerHandlersSystem();
  318. }
  319. public function serviceAlertResponseProcessStorageChange ($oAlert)
  320. {
  321. if ('sys_storage_default' != $oAlert->aExtras['option'])
  322. return;
  323. $aStorages = BxDolStorageQuery::getStorageObjects();
  324. foreach ($aStorages as $r) {
  325. if (0 == $r['current_size'] && 0 == $r['current_number'] && ($oStorage = BxDolStorage::getObjectInstance($r['object'])))
  326. $oStorage->changeStorageEngine($oAlert->aExtras['value']);
  327. }
  328. }
  329. public function serviceGetOptionsProfileBot()
  330. {
  331. $aResult = array(
  332. array('key' => '', 'value' => _t('_Select_one'))
  333. );
  334. $aAccountsIds = BxDolAccountQuery::getInstance()->getOperators();
  335. foreach($aAccountsIds as $iAccountId) {
  336. $aProfilesIds = BxDolAccount::getInstance($iAccountId)->getProfilesIds(true, false);
  337. foreach($aProfilesIds as $iProfileId) {
  338. $oProfile = BxDolProfile::getInstance($iProfileId);
  339. $aResult[] = array(
  340. 'key' => $iProfileId,
  341. 'value' => _t('_sys_profile_with_type', $oProfile->getDisplayName(), $oProfile->getModule()),
  342. );
  343. }
  344. }
  345. return $aResult;
  346. }
  347. public function serviceGetOptionsModuleListForPrivacySelector()
  348. {
  349. $aResult = array();
  350. $BxDolModuleQuery = BxDolModuleQuery::getInstance();
  351. $aModules = $BxDolModuleQuery->getModulesBy(array('type' => 'modules', 'active' => 1));
  352. foreach($aModules as $aModule){
  353. $oModule = BxDolModule::getInstance($aModule['name']);
  354. if($oModule instanceof iBxDolContentInfoService){
  355. if (!BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  356. continue;
  357. $aResult[$aModule['name']] = $aModule['title'];
  358. }
  359. }
  360. return $aResult;
  361. }
  362. public function serviceGetOptionsEmbedDefault()
  363. {
  364. $aResults = array(
  365. '' => _t('_None')
  366. );
  367. $aObjects = BxDolEmbedQuery::getObjects();
  368. foreach($aObjects as $aObject)
  369. $aResults[$aObject['object']] = $aObject['title'];
  370. return $aResults;
  371. }
  372. public function serviceGetOptionsRelations()
  373. {
  374. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
  375. $aProfiles = array();
  376. foreach($aModules as $aModule) {
  377. $sMethod = 'act_as_profile';
  378. if(!BxDolRequest::serviceExists($aModule['name'], $sMethod) || !BxDolService::call($aModule['name'], $sMethod))
  379. continue;
  380. $aProfiles[$aModule['name']] = _t('_' . $aModule['name']);
  381. }
  382. $aResults = array();
  383. foreach($aProfiles as $sName1 => $sTitle1)
  384. foreach($aProfiles as $sName2 => $sTitle2)
  385. $aResults[$sName1 . '_' . $sName2] = $sTitle1 . ' - ' . $sTitle2;
  386. return $aResults;
  387. }
  388. public function serviceGetBadge($aBadge, $bIsCompact = false)
  389. {
  390. $sClass = '';
  391. $sStyleFont = '';
  392. $sStyleBg = '';
  393. if ($aBadge['color'] == '')
  394. $aBadge['color'] = '#ff0000';
  395. if ($aBadge['fontcolor'] == '')
  396. $aBadge['fontcolor'] = '#ffffff';
  397. if ($bIsCompact){
  398. $aBadge['is_icon_only'] = 1;
  399. $sClass .= ' bx-badge-compact-to';
  400. $sStyleFont = 'color: ' . $aBadge['fontcolor'];
  401. }
  402. else{
  403. $sStyleBg = 'background-color: ' . $aBadge['color'] . '; color: ' . $aBadge['fontcolor'];
  404. }
  405. if ($aBadge['is_icon_only'] == 1){
  406. $sClass .= ' bx-badge-compact';
  407. }
  408. return BxDolTemplate::getInstance()->parseHtmlByName('badge.html', array(
  409. 'bx_if:content' => array(
  410. 'condition' => $aBadge['is_icon_only'] != '1',
  411. 'content' => array('content' => _t($aBadge['text'])),
  412. ),
  413. 'bx_if:icon' => array(
  414. 'condition' => $aBadge['icon'] != '',
  415. 'content' => array('content' => BxDolTemplate::getInstance()->getIcon($aBadge['icon'], array('class' => 'bx-badge-icon sys-colored', 'style' => $sStyleFont))),
  416. ),
  417. 'title' => $aBadge['text'],
  418. 'style_font' => $sStyleFont,
  419. 'style_bg' => $sStyleBg,
  420. 'class' => $sClass,
  421. )
  422. );
  423. }
  424. }
  425. /** @} */