BxBaseServices.php 17 KB

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