1
0

BxBaseServices.php 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368
  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 serviceIsPublicService($s)
  19. {
  20. $sService = bx_gen_method_name($s);
  21. $aServices = $this->serviceGetPublicServices();
  22. return isset($aServices[$sService]);
  23. }
  24. public function serviceGetPublicServices()
  25. {
  26. return array (
  27. 'GetProductsNames' => 'BxBaseServices',
  28. 'GetPageByRequest' => 'BxBaseServicePages',
  29. );
  30. }
  31. public function serviceIsSafeService($s)
  32. {
  33. $sService = bx_gen_method_name($s);
  34. $aSafeServices = $this->serviceGetSafeServices();
  35. return isset($aSafeServices[$sService]);
  36. }
  37. public function serviceGetSafeServices()
  38. {
  39. return array(
  40. 'GetCreatePostForm' => 'BxBaseServices',
  41. 'GetProductsNames' => 'BxBaseServices',
  42. 'KeywordSearch' => 'BxBaseServices',
  43. 'GetDataSearchApi' => 'BxBaseServices',
  44. 'Cmts' => 'BxBaseServices',
  45. 'GetFooter' => 'BxBaseServices',
  46. 'CreateAccountForm' => 'BxBaseServiceAccount',
  47. 'AccountSettingsEmail' => 'BxBaseServiceAccount',
  48. 'AccountSettingsPassword' => 'BxBaseServiceAccount',
  49. 'ForgotPassword' => 'BxBaseServiceAccount',
  50. 'SwitchProfile' => 'BxBaseServiceAccount',
  51. 'EmailConfirmation' => 'BxBaseServiceAccount',
  52. 'CategoriesList' => 'BxBaseServiceCategory',
  53. 'Test' => 'BxBaseServiceLogin',
  54. 'MemberAuthCode' => 'BxBaseServiceLogin',
  55. 'LoginForm' => 'BxBaseServiceLogin',
  56. 'LoginFormOnly' => 'BxBaseServiceLogin',
  57. 'Logout' => 'BxBaseServiceLogin',
  58. 'KeywordsCloud' => 'BxBaseServiceMetatags',
  59. 'AccountProfileSwitcher' => 'BxBaseServiceProfiles',
  60. 'ProfileMembership' => 'BxBaseServiceProfiles',
  61. 'ProfileNotifications' => 'BxBaseServiceProfiles',
  62. 'GetCountOnlineProfiles' => 'BxBaseServiceProfiles',
  63. 'BrowseRecommendationsFriends' => 'BxBaseServiceProfiles',
  64. 'BrowseRecommendationsSubscriptions' => 'BxBaseServiceProfiles',
  65. 'BrowseFriends' => 'BxBaseServiceProfiles',
  66. 'BrowseFriendRequests' => 'BxBaseServiceProfiles',
  67. 'BrowseFriendRequested' => 'BxBaseServiceProfiles',
  68. 'BrowseSubscribedMe' => 'BxBaseServiceProfiles',
  69. 'BrowseSubscriptions' => 'BxBaseServiceProfiles',
  70. 'BrowseMembers' => 'BxBaseServiceProfiles',
  71. 'GetChartGrowth' => 'BxBaseChartServices',
  72. 'GetChartStats' => 'BxBaseChartServices',
  73. 'GetCartItemsCount' => 'BxBasePaymentsServices',
  74. 'GetOrdersCount' => 'BxBasePaymentsServices',
  75. 'Do' => 'BxBaseReportServices',
  76. 'GetPerformedBy' => 'BxBaseReportServices',
  77. 'Do' => 'BxBaseVoteServices',
  78. 'GetPerformedBy' => 'BxBaseVoteServices',
  79. 'Perform' => 'BxBaseServiceConnections',
  80. 'Perform' => 'BxBaseServiceRecommendations',
  81. 'GetDataApi' => 'BxBaseCmtsServices',
  82. 'GetDataApi' => 'BxBaseUploaderServices',
  83. );
  84. }
  85. public function serviceGetPreloaderContent($sName) {
  86. $sResult = '';
  87. switch($sName) {
  88. case 'icons':
  89. $sResult = getParam('sys_css_icons_default');
  90. break;
  91. case 'tailwind':
  92. $sFile = getParam('sys_css_tailwind_default');
  93. if(empty($sFile))
  94. $sFile = 'tailwind.min.css';
  95. $sResult = '{dir_plugins_public}tailwind/css/|' . $sFile;
  96. break;
  97. }
  98. return $sResult;
  99. }
  100. /**
  101. * @page service Service Calls
  102. * @section bx_system_general System Services
  103. * @subsection bx_system_general-general General
  104. * @subsubsection bx_system_general-module_check_for_update module_check_for_update
  105. *
  106. * @code bx_srv('system', 'module_check_for_update', ["bx_posts"]); @endcode
  107. * @code bx_srv('system', 'module_check_for_update', ["bx_posts"], 'TemplServices'); @endcode
  108. * @code {{~system:module_check_for_update:TemplServices["bx_posts"]~}} @endcode
  109. *
  110. * Checks whether an update is available for requested module or not.
  111. * @param $mixedModule - module ID/name to check the updates for.
  112. * @return array with information about the update, false if nothing was found
  113. *
  114. * @see BxBaseServices::serviceModuleCheckForUpdate
  115. */
  116. /**
  117. * @ref bx_system_general-module_check_for_update "module_check_for_update"
  118. */
  119. public function serviceModuleCheckForUpdate($mixedModule)
  120. {
  121. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  122. if(empty($aModule) || !is_array($aModule))
  123. return false;
  124. $aUpdates = BxDolStudioInstallerUtils::getInstance()->checkUpdatesByModule($aModule['name']);
  125. if(empty($aUpdates) || !is_array($aUpdates))
  126. return false;
  127. $aUpdate = array_shift($aUpdates);
  128. return array(
  129. 'version_from' => $aUpdate['file_version'],
  130. 'version_to' => $aUpdate['file_version_to'],
  131. 'file_id' => $aUpdate['file_id']
  132. );
  133. }
  134. /**
  135. * @page service Service Calls
  136. * @section bx_system_general System Services
  137. * @subsection bx_system_general-general General
  138. * @subsubsection bx_system_general-module_update module_update
  139. *
  140. * @code bx_srv('system', 'module_update', ["bx_posts"]); @endcode
  141. * @code bx_srv('system', 'module_update', ["bx_posts"], 'TemplServices'); @endcode
  142. * @code {{~system:module_update:TemplServices["bx_posts"]~}} @endcode
  143. *
  144. * Download and install an update for requested module. The operation may be performed
  145. * immediately or by Transient Cron task. The second way is more common.
  146. * @param $mixedModule - module ID/name to check the updates for.
  147. * @return integer value determining the result of the operation. It can be one of the following values:
  148. * BX_DOL_STUDIO_IU_RC_SUCCESS, BX_DOL_STUDIO_IU_RC_FAILED or BX_DOL_STUDIO_IU_RC_SCHEDULED.
  149. *
  150. * @see BxBaseServices::serviceModuleUpdate
  151. */
  152. /**
  153. * @ref bx_system_general-module_update "module_update"
  154. */
  155. public function serviceModuleUpdate($mixedModule)
  156. {
  157. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  158. if(empty($aModule) || !is_array($aModule))
  159. return BX_DOL_STUDIO_IU_RC_FAILED;
  160. $aResult = BxDolStudioInstallerUtils::getInstance()->downloadUpdatePublic($aModule['name'], true);
  161. return $aResult['code'];
  162. }
  163. /**
  164. * @page service Service Calls
  165. * @section bx_system_general System Services
  166. * @subsection bx_system_general-general General
  167. * @subsubsection bx_system_general-module_delete module_delete
  168. *
  169. * @code bx_srv('system', 'module_delete', ["bx_posts"]); @endcode
  170. * @code bx_srv('system', 'module_delete', ["bx_posts", true], 'TemplServices'); @endcode
  171. * @code {{~system:module_delete:TemplServices["bx_posts"]~}} @endcode
  172. *
  173. * Delete the requested module. By default only uninstalled module can be deleted.
  174. * The operation may be performed immediately or by Transient Cron task. The second way is more common.
  175. * @param $sModule - module name to delete.
  176. * @param $bForceUninstall - if 'true' is passed the module will be uninstalled before deletion.
  177. * @return integer value determining the result of the operation. It can be one of the following values:
  178. * BX_DOL_STUDIO_IU_RC_SUCCESS, BX_DOL_STUDIO_IU_RC_FAILED or BX_DOL_STUDIO_IU_RC_SCHEDULED.
  179. *
  180. * @see BxBaseServices::serviceModuleDelete
  181. */
  182. /**
  183. * @ref bx_system_general-module_delete "module_delete"
  184. */
  185. public function serviceModuleDelete($sModule, $bForceUninstall = false)
  186. {
  187. $sModulePath = '';
  188. $oInstallerUtils = BxDolStudioInstallerUtils::getInstance();
  189. $aModule = BxDolModuleQuery::getInstance()->getModuleByName($sModule, false);
  190. if(!empty($aModule) && is_array($aModule)) {
  191. if(!$bForceUninstall)
  192. return BX_DOL_STUDIO_IU_RC_FAILED;
  193. $sModulePath = $aModule['path'];
  194. $aResult = $oInstallerUtils->perform($sModulePath, 'uninstall', array('auto_disable' => $bForceUninstall));
  195. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  196. return BX_DOL_STUDIO_IU_RC_FAILED;
  197. }
  198. else {
  199. $aModules = $oInstallerUtils->getModules(false);
  200. if(!isset($aModules[$sModule]))
  201. return BX_DOL_STUDIO_IU_RC_FAILED;
  202. $sModulePath = $aModules[$sModule]['dir'];
  203. }
  204. $aResult = $oInstallerUtils->perform($sModulePath, 'delete');
  205. return $aResult['code'];
  206. }
  207. /**
  208. * @page service Service Calls
  209. * @section bx_system_general System Services
  210. * @subsection bx_system_general-general General
  211. * @subsubsection bx_system_general-module_install module_install
  212. *
  213. * @code bx_srv('system', 'module_install', ["bx_posts"]); @endcode
  214. * @code bx_srv('system', 'module_install', ["bx_posts", true], 'TemplServices'); @endcode
  215. * @code {{~system:module_install:TemplServices["bx_posts"]~}} @endcode
  216. *
  217. * Install the requested module. By default the module will be installed only.
  218. * @param $sModule - module name to install.
  219. * @param $bForceEnable - if 'true' is passed the module will be automatically enabled after installation.
  220. * @return boolean value determining the result of the operation.
  221. *
  222. * @see BxBaseServices::serviceModuleInstall
  223. */
  224. /**
  225. * @ref bx_system_general-module_install "module_install"
  226. */
  227. public function serviceModuleInstall($sModule, $bForceEnable = false)
  228. {
  229. $oInstallerUtils = BxDolStudioInstallerUtils::getInstance();
  230. $aModules = $oInstallerUtils->getModules(false);
  231. if(!isset($aModules[$sModule]))
  232. return false;
  233. $aResult = $oInstallerUtils->perform($aModules[$sModule]['dir'], 'install', array('auto_enable' => $bForceEnable));
  234. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  235. return false;
  236. return true;
  237. }
  238. /**
  239. * @page service Service Calls
  240. * @section bx_system_general System Services
  241. * @subsection bx_system_general-general General
  242. * @subsubsection bx_system_general-module_uninstall module_uninstall
  243. *
  244. * @code bx_srv('system', 'module_uninstall', ["bx_posts"]); @endcode
  245. * @code bx_srv('system', 'module_uninstall', ["bx_posts", true], 'TemplServices'); @endcode
  246. * @code {{~system:module_uninstall:TemplServices["bx_posts"]~}} @endcode
  247. *
  248. * Uninstall the requested module. By default only disabled module can be uninstalled.
  249. * @param $mixedModule - module ID/name to uninstall.
  250. * @param $bForceDisable - if 'true' is passed the module will be automatically disabled before uninstallation.
  251. * @return boolean value determining the result of the operation.
  252. *
  253. * @see BxBaseServices::serviceModuleUninstall
  254. */
  255. /**
  256. * @ref bx_system_general-module_uninstall "module_uninstall"
  257. */
  258. public function serviceModuleUninstall($mixedModule, $bForceDisable = false)
  259. {
  260. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  261. if(empty($aModule) || !is_array($aModule))
  262. return false;
  263. if((int)$aModule['enabled'] != 0 && !$bForceDisable)
  264. return false;
  265. $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aModule['path'], 'uninstall', array('auto_disable' => $bForceDisable));
  266. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  267. return false;
  268. return true;
  269. }
  270. /**
  271. * @page service Service Calls
  272. * @section bx_system_general System Services
  273. * @subsection bx_system_general-general General
  274. * @subsubsection bx_system_general-module_enable module_enable
  275. *
  276. * @code bx_srv('system', 'module_enable', ["bx_posts"]); @endcode
  277. * @code bx_srv('system', 'module_enable', ["bx_posts"], 'TemplServices'); @endcode
  278. * @code {{~system:module_enable:TemplServices["bx_posts"]~}} @endcode
  279. *
  280. * Enable the requested module.
  281. * @param $mixedModule - module ID/name to enable.
  282. * @return boolean value determining the result of the operation.
  283. *
  284. * @see BxBaseServices::serviceModuleEnable
  285. */
  286. /**
  287. * @ref bx_system_general-module_enable "module_enable"
  288. */
  289. public function serviceModuleEnable($mixedModule)
  290. {
  291. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  292. if(empty($aModule) || !is_array($aModule))
  293. return false;
  294. if((int)$aModule['enabled'] != 0)
  295. return false;
  296. $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aModule['path'], 'enable');
  297. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  298. return false;
  299. return true;
  300. }
  301. /**
  302. * @page service Service Calls
  303. * @section bx_system_general System Services
  304. * @subsection bx_system_general-general General
  305. * @subsubsection bx_system_general-module_disable module_disable
  306. *
  307. * @code bx_srv('system', 'module_disable', ["bx_posts"]); @endcode
  308. * @code bx_srv('system', 'module_disable', ["bx_posts"], 'TemplServices'); @endcode
  309. * @code {{~system:module_disable:TemplServices["bx_posts"]~}} @endcode
  310. *
  311. * Disable the requested module.
  312. * @param $mixedModule - module ID/name to disable.
  313. * @return boolean value determining the result of the operation.
  314. *
  315. * @see BxBaseServices::serviceModuleDisable
  316. */
  317. /**
  318. * @ref bx_system_general-module_disable "module_disable"
  319. */
  320. public function serviceModuleDisable($mixedModule)
  321. {
  322. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  323. if(empty($aModule) || !is_array($aModule))
  324. return false;
  325. if((int)$aModule['enabled'] == 0)
  326. return false;
  327. $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aModule['path'], 'disable');
  328. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  329. return false;
  330. return true;
  331. }
  332. /**
  333. * @page service Service Calls
  334. * @section bx_system_general System Services
  335. * @subsection bx_system_general-general General
  336. * @subsubsection bx_system_general-is_module_installed is_module_installed
  337. *
  338. * @code bx_srv('system', 'is_module_installed', ["bx_posts"]); @endcode
  339. * @code bx_srv('system', 'is_module_installed', ["bx_posts"], 'TemplServices'); @endcode
  340. * @code {{~system:is_module_installed:TemplServices["bx_posts"]~}} @endcode
  341. *
  342. * Checks whether the requested module is installed or not.
  343. * @param $mixedModule - module ID/name to check.
  344. * @return boolean value determining the result of the operation.
  345. *
  346. * @see BxBaseServices::serviceIsModuleInstalled
  347. */
  348. /**
  349. * @ref bx_system_general-is_module_installed "is_module_installed"
  350. */
  351. public function serviceIsModuleInstalled($mixedModule)
  352. {
  353. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  354. return !empty($aModule) && is_array($aModule);
  355. }
  356. /**
  357. * @page service Service Calls
  358. * @section bx_system_general System Services
  359. * @subsection bx_system_general-general General
  360. * @subsubsection bx_system_general-is_module_enabled is_module_enabled
  361. *
  362. * @code bx_srv('system', 'is_module_enabled', ["bx_posts"]); @endcode
  363. * @code bx_srv('system', 'is_module_enabled', ["bx_posts"], 'TemplServices'); @endcode
  364. * @code {{~system:is_module_enabled:TemplServices["bx_posts"]~}} @endcode
  365. *
  366. * Checks whether the requested module is enabled or not.
  367. * @param $mixedModule - module ID/name to check.
  368. * @return boolean value determining the result of the operation.
  369. *
  370. * @see BxBaseServices::serviceIsModuleEnabled
  371. */
  372. /**
  373. * @ref bx_system_general-is_module_enabled "is_module_enabled"
  374. */
  375. public function serviceIsModuleEnabled($mixedModule)
  376. {
  377. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  378. return !empty($aModule) && is_array($aModule) && (int)$aModule['enabled'] != 0;
  379. }
  380. /**
  381. * Checks whether a module is a 'Content' module or not.
  382. *
  383. * @param string $mixedModule - module name or an instance of Module class.
  384. * @return boolean result of operation.
  385. */
  386. public function serviceIsModuleContent($mixedModule)
  387. {
  388. if(is_string($mixedModule))
  389. $mixedModule = BxDolModule::getInstance($mixedModule);
  390. return
  391. $mixedModule instanceof BxDolModule &&
  392. $mixedModule instanceof iBxDolContentInfoService &&
  393. !($mixedModule instanceof iBxDolProfileService) &&
  394. BxDolRequest::serviceExists($mixedModule->_aModule, 'is_allowed_post_in_context') &&
  395. bx_srv($mixedModule->getName(), 'is_allowed_post_in_context');
  396. }
  397. /**
  398. * Checks whether a module is a 'Context' module or not.
  399. *
  400. * @param string $mixedModule - module name or an instance of Module class.
  401. * @return boolean result of operation.
  402. */
  403. public function serviceIsModuleContext($mixedModule)
  404. {
  405. if(is_string($mixedModule))
  406. $mixedModule = BxDolModule::getInstance($mixedModule);
  407. return $mixedModule instanceof BxDolModule && $mixedModule instanceof iBxDolProfileService;
  408. }
  409. /**
  410. * Checks whether a module is a 'Profile' module or not.
  411. *
  412. * @param string $mixedModule - module name or an instance of Module class.
  413. * @return boolean result of operation.
  414. */
  415. public function serviceIsModuleProfile($mixedModule)
  416. {
  417. if(is_string($mixedModule))
  418. $mixedModule = BxDolModule::getInstance($mixedModule);
  419. return $mixedModule instanceof BxDolModule && $mixedModule instanceof iBxDolProfileService && $mixedModule->serviceActAsProfile();
  420. }
  421. /**
  422. * Get modules by type. Available types are 'content', 'context', 'profile'.
  423. *
  424. * @param type $sType - string with type.
  425. * @return array of modules.
  426. */
  427. public function serviceGetModulesByType($sType, $aParams = [])
  428. {
  429. $aResults = [];
  430. $bIdAsKey = isset($aParams['id_as_key']) && $aParams['id_as_key'] === true;
  431. $bNameAsKey = !$bIdAsKey && isset($aParams['name_as_key']) && $aParams['name_as_key'] === true;
  432. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(['type' => 'modules', 'active' => 1]);
  433. foreach($aModules as $aModule) {
  434. $oModule = BxDolModule::getInstance($aModule['name']);
  435. if(!$oModule)
  436. continue;
  437. if($sType == 'content' && !$this->serviceIsModuleContent($oModule))
  438. continue;
  439. if($sType == 'context' && !$this->serviceIsModuleContext($oModule))
  440. continue;
  441. if($sType == 'profile' && !$this->serviceIsModuleProfile($oModule))
  442. continue;
  443. if($bIdAsKey)
  444. $aResults[$aModule['id']] = $aModule;
  445. else if($bNameAsKey)
  446. $aResults[$aModule['name']] = $aModule;
  447. else
  448. $aResults[] = $aModule;
  449. }
  450. return $aResults;
  451. }
  452. public function serviceProfileUnit ($iContentId, $aParams = array())
  453. {
  454. return $this->_serviceProfileFunc('getUnit', $iContentId, $aParams);
  455. }
  456. public function serviceHasImage ($iContentId)
  457. {
  458. return false;
  459. }
  460. public function serviceProfilePicture ($iContentId)
  461. {
  462. return BxDolTemplate::getInstance()->getImageUrl('account.svg');
  463. }
  464. public function serviceProfileAvatar ($iContentId)
  465. {
  466. return BxDolTemplate::getInstance()->getImageUrl('account.svg');
  467. }
  468. public function serviceProfileCover ($iContentId)
  469. {
  470. return '';
  471. }
  472. public function serviceProfileEditUrl ($iContentId)
  473. {
  474. return bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=account-settings-info'));
  475. }
  476. public function serviceProfileThumb ($iContentId)
  477. {
  478. return $this->_serviceProfileFunc('getThumb', $iContentId);
  479. }
  480. public function serviceProfileIcon ($iContentId)
  481. {
  482. return $this->_serviceProfileFunc('getIcon', $iContentId);
  483. }
  484. public function serviceProfileName ($iContentId)
  485. {
  486. return $this->_serviceProfileFunc('getDisplayName', $iContentId);
  487. }
  488. public function serviceProfileUrl ($iContentId)
  489. {
  490. return $this->_serviceProfileFunc('getUrl', $iContentId);
  491. }
  492. /**
  493. * @see iBxDolProfileService::serviceCheckAllowedProfileView
  494. */
  495. public function serviceCheckAllowedProfileView($iContentId)
  496. {
  497. return _t('_Access denied');
  498. }
  499. /**
  500. * @see iBxDolProfileService::serviceCheckAllowedProfileContact
  501. */
  502. public function serviceCheckAllowedProfileContact($iContentId)
  503. {
  504. return _t('_Access denied');
  505. }
  506. /**
  507. * @see iBxDolProfileService::serviceCheckAllowedPostInProfile
  508. */
  509. public function serviceCheckAllowedPostInProfile($iContentId, $sPostModule = '')
  510. {
  511. return _t('_Access denied');
  512. }
  513. /**
  514. * @see iBxDolProfileService::serviceCheckAllowedModuleActionInProfile
  515. */
  516. public function serviceCheckAllowedModuleActionInProfile($iContentId, $sPostModule, $sActionName)
  517. {
  518. return _t('_Access denied');
  519. }
  520. /**
  521. * @see iBxDolProfileService::serviceGetSpaceTitle
  522. */
  523. public function serviceGetSpaceTitle()
  524. {
  525. return '';
  526. }
  527. /**
  528. * @see iBxDolProfileService::serviceGetParticipatingProfiles
  529. */
  530. public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObject = false)
  531. {
  532. return array();
  533. }
  534. /**
  535. * @page service Service Calls
  536. * @section bx_system_general System Services
  537. * @subsection bx_system_general-general General
  538. * @subsubsection bx_system_general-get_create_post_form get_create_post_form
  539. *
  540. * @code bx_srv('system', 'get_create_post_form', [false, "bx_posts"], 'TemplServices'); @endcode
  541. * @code {{~system:get_create_post_form:TemplServices[false,"bx_posts"]~}} @endcode
  542. *
  543. * Get United Create Post form.
  544. * @param $mixedContextId - context which the post will be created in:
  545. * - false = 'Public' post form;
  546. * - 0 = 'Profile' post form, which allows to post in your own profile and connections;
  547. * - n = 'Context' post form, which allows to post in context (3d party profile, group, event, etc).
  548. * @param $sDefault - tab selected by default.
  549. * @param $aCustom - an array with custom paramaters.
  550. * @return string with form content
  551. *
  552. * @see BxBaseServices::serviceGetCreatePostForm
  553. */
  554. /**
  555. * @ref bx_system_general-get_create_post_form "get_create_post_form"
  556. */
  557. public function serviceGetCreatePostForm($mixedContextId = false, $sDefault = '', $aCustom = array())
  558. {
  559. if(!isLogged() || ($mixedContextId !== false && !is_numeric($mixedContextId)))
  560. return '';
  561. $oProfile = BxDolProfile::getInstance();
  562. if(!$oProfile)
  563. return '';
  564. if($mixedContextId !== false)
  565. $mixedContextId = (int)(!empty($mixedContextId) ? -$mixedContextId : $oProfile->id());
  566. $oMenu = BxDolMenu::getObjectInstance('sys_create_post');
  567. if(!$oMenu)
  568. return '';
  569. $oMenu->setContextId($mixedContextId);
  570. $aMenuItems = $oMenu->getMenuItems();
  571. if(empty($aMenuItems) || !is_array($aMenuItems))
  572. return '';
  573. if(empty($sDefault)) {
  574. $aDefault = array_shift($aMenuItems);
  575. $sDefault = !empty($aDefault['module']) ? $aDefault['module'] : $aDefault['name'];
  576. }
  577. $oMenu->setSelected($sDefault, $sDefault);
  578. $bContext = $mixedContextId !== false;
  579. if($bContext && ($aContextInfo = BxDolProfileQuery::getInstance()->getInfoById(abs($mixedContextId))))
  580. if(bx_srv($aContextInfo['type'], 'check_allowed_post_in_profile', [$aContextInfo['content_id'], $sDefault]) !== CHECK_ACTION_RESULT_ALLOWED)
  581. return '';
  582. $sTitle = _t('_sys_page_block_title_create_post' . (!$bContext ? '_public' : ($mixedContextId < 0 ? '_context' : '')));
  583. $sPlaceholder = _t('_sys_txt_create_post_placeholder', $oProfile->getDisplayName());
  584. $oDbModules = BxDolModuleQuery::getInstance();
  585. $oTemplate = BxDolTemplate::getInstance();
  586. $oTemplate->addJs(['BxDolCreatePost.js']);
  587. $aPreloadingList = [];
  588. $aModules = explode(',', getParam('sys_create_post_form_preloading_list'));
  589. if(!empty($aModules))
  590. foreach($aModules as $sModule) {
  591. $aModule = $oDbModules->getModuleByName($sModule);
  592. if(empty($aModule) || !is_array($aModule))
  593. continue;
  594. $aPreloadingList[$sModule] = $aModule['uri'];
  595. }
  596. if(bx_is_api()) {
  597. return [
  598. 'title' => $sTitle,
  599. 'content' => '',
  600. 'menu' => $oMenu->getCodeAPI()
  601. ];
  602. }
  603. $sJsObject = 'oBxDolCreatePost';
  604. $sJsContent = $oTemplate->_wrapInTagJsCode("var " . $sJsObject . " = new BxDolCreatePost(" . json_encode([
  605. 'sObjName' => $sJsObject,
  606. 'sRootUrl' => BX_DOL_URL_ROOT,
  607. 'sDefault' => $sDefault,
  608. 'iContextId' => $bContext ? $mixedContextId : 0,
  609. 'oPreloadingList' => $aPreloadingList,
  610. 'oCustom' => $aCustom
  611. ]) . ");");
  612. return [
  613. 'title' => $sTitle,
  614. 'content' => $oTemplate->parseHtmlByName('create_post_form.html', [
  615. 'default' => $sDefault,
  616. 'placeholder' => $sPlaceholder,
  617. 'user_thumb' => $oProfile->getUnit(0, ['template' => 'unit_wo_info_links']),
  618. 'form' => bx_srv($sDefault, 'get_create_post_form', [[
  619. 'context_id' => $mixedContextId,
  620. 'ajax_mode' => true,
  621. 'absolute_action_url' => true,
  622. 'custom' => $aCustom
  623. ]]),
  624. 'js_object' => $sJsObject,
  625. 'js_content' => $sJsContent
  626. ]),
  627. 'menu' => $oMenu
  628. ];
  629. }
  630. public function serviceGetOptionsCreatePostFormPreloadingList()
  631. {
  632. $oMenu = BxDolMenu::getObjectInstance('sys_create_post');
  633. if(!$oMenu)
  634. return [];
  635. $aMenuItems = $oMenu->getMenuItems();
  636. $aResult = [];
  637. foreach($aMenuItems as $aMenuItem) {
  638. $sModule = !empty($aMenuItem['module']) ? $aMenuItem['module'] : $aMenuItem['name'];
  639. if(!bx_srv('system', 'is_module_enabled', [$sModule]))
  640. continue;
  641. $aResult[] = [
  642. 'key' => $sModule,
  643. 'value' => _t('_' . $sModule)
  644. ];
  645. }
  646. return $aResult;
  647. }
  648. public function serviceGetBlockAuthor($sModule, $iContentId = 0)
  649. {
  650. if(!$iContentId && bx_get('id') !== false)
  651. $iContentId = (int)bx_get('id');
  652. $sMethodGetAuthor = 'get_author';
  653. if(!$sModule || !$iContentId || !BxDolRequest::serviceExists($sModule, $sMethodGetAuthor))
  654. return '';
  655. $iAuthor = bx_srv($sModule, $sMethodGetAuthor, [$iContentId]);
  656. if(!$iAuthor)
  657. return '';
  658. $oAuthor = BxDolProfile::getInstance($iAuthor);
  659. if(!$oAuthor)
  660. return '';
  661. $sModuleAuthor = $oAuthor->getModule();
  662. $sMethodGetCover = 'entity_cover';
  663. if(!BxDolRequest::serviceExists($sModuleAuthor, $sMethodGetCover))
  664. return '';
  665. return bx_srv($sModuleAuthor, $sMethodGetCover, [$oAuthor->getContentId(), [
  666. 'use_as_author' => true,
  667. 'show_text' => false
  668. ]]);
  669. }
  670. /**
  671. * @page service Service Calls
  672. * @section bx_system_general System Services
  673. * @subsection bx_system_general-general General
  674. * @subsubsection bx_system_general-get_site_submenu get_site_submenu
  675. *
  676. * @code bx_srv('system', 'get_site_submenu', [], 'TemplServices'); @endcode
  677. * @code {{~system:get_site_submenu:TemplServices[]~}} @endcode
  678. *
  679. * Get Site Submenu code.
  680. * @see BxBaseServices::serviceGetSiteSubmenu
  681. */
  682. /**
  683. * @ref bx_system_general-get_site_submenu "get_site_submenu"
  684. */
  685. public function serviceGetSiteSubmenu()
  686. {
  687. $oMenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  688. return $oMenu ? $oMenu->getCode() : '';
  689. }
  690. /**
  691. * @page service Service Calls
  692. * @section bx_system_general System Services
  693. * @subsection bx_system_general-general General
  694. * @subsubsection bx_system_general-get_products_names get_products_names
  695. *
  696. * @code bx_srv('system', 'get_products_names', [], 'TemplServices');
  697. *
  698. * @code http://example.com/m/oauth2/com/get_products_names?module=system&class=BaseServices @endcode
  699. * @code http://hihi.una.io/modules/?r=oauth2/com/get_products_names&module=system&class=BaseServices @endcode
  700. *
  701. * Get an array of products names from all modules with payments functionality.
  702. * @param $iVendorId filter products by vendor ID.
  703. * @param $iLimit limit number of records from one module.
  704. * @return array of products where key id product name and value is module name
  705. *
  706. * @see BxBaseServices::serviceGetProductsNames
  707. */
  708. /**
  709. * @ref bx_system_general-get_products_names "get_products_names"
  710. */
  711. public function serviceGetProductsNames($iVendorId = 0, $iLimit = 1000)
  712. {
  713. $o = BxDolPayments::getInstance();
  714. if (!$o)
  715. return array();
  716. return $o->getProductsNames($iVendorId, $iLimit);
  717. }
  718. /**
  719. * @see iBxDolProfileService::serviceCheckSpacePrivacy
  720. */
  721. public function serviceCheckSpacePrivacy($iContentId)
  722. {
  723. return _t('_Access denied');
  724. }
  725. public function serviceFormsHelper ()
  726. {
  727. return new BxTemplAccountForms();
  728. }
  729. public function serviceActAsProfile ()
  730. {
  731. return false;
  732. }
  733. public function servicePrepareFields ($aFieldsProfile)
  734. {
  735. return $aFieldsProfile;
  736. }
  737. public function serviceProfilesSearch ($sTerm, $iLimit)
  738. {
  739. $oDb = BxDolAccountQuery::getInstance();
  740. $aRet = array();
  741. $a = $oDb->searchByTerm($sTerm, $iLimit);
  742. foreach ($a as $r)
  743. $aRet[] = array ('label' => $this->serviceProfileName($r['content_id']), 'value' => $r['profile_id']);
  744. return $aRet;
  745. }
  746. /**
  747. * @page service Service Calls
  748. * @section bx_system_general System Services
  749. * @subsection bx_system_general-general General
  750. * @subsubsection bx_system_general-keyword_search keyword_search
  751. *
  752. * @code bx_srv('system', 'keyword_search', ["bx_posts", ["keyword" => "test"}], 'TemplServices'); @endcode
  753. *
  754. * @code {{~system:keyword_search:TemplServices["bx_posts", {"keyword":"test"}]~}} @endcode
  755. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country", "keyword": "AU"}, "unit.html"]~}} @endcode
  756. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_state", "state":"NSW", "keyword": "AU"}, "unit.html"]~}} @endcode
  757. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"}, "unit.html"]~}} @endcode
  758. * @code {{~system:keyword_search:TemplServices["bx_posts", {"meta_type": "mention", "keyword": 2}, "unit_gallery.html"]~}} @endcode
  759. * @code {{~system:keyword_search:TemplServices["bx_posts", {"cat": "bx_posts_cats", "keyword": 3}, "unit_gallery.html"]~}} @endcode
  760. *
  761. * Search by keyword
  762. * @param $sSection - search object to search in, usually module name, for example: bx_posts
  763. * @param $aCondition - condition for search, supported conditions:
  764. * - search by keyword: ["keyword" => "test"]
  765. * - search by country: ["meta_type" => "location_country", "keyword" => "AU"]
  766. * - search by country and state: ["meta_type": "location_country_state", "state":"NSW", "keyword": "AU"]
  767. * - search by country, state and city: ["meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"]
  768. * - search for mentions: ["meta_type" => "mention", "keyword" => 2]
  769. * - search in category: ["cat": "bx_posts_cats", "keyword": 3]
  770. * @param $sTemplate - template for displaying search results, for example: unit.html
  771. * @param $iStart - paginate, display records starting from this number
  772. * @param $iPerPage - paginate, display this number of records per page
  773. * @param $bLiveSearch - search results like in live search
  774. *
  775. * @see BxBaseServices::serviceKeywordSearch
  776. */
  777. /**
  778. * @ref bx_system_general-keyword_search "keyword_search"
  779. */
  780. public function serviceKeywordSearch ($sSection, $aCondition, $sTemplate = '', $iStart = 0, $iPerPage = 0, $bLiveSearch = 0, $bPaginate = false)
  781. {
  782. if (!$sSection || !isset($aCondition['keyword']))
  783. return '';
  784. $sClass = 'BxTemplSearch';
  785. $sElsName = 'bx_elasticsearch';
  786. $sElsMethod = 'is_configured';
  787. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod)) {
  788. $oModule = BxDolModule::getInstance($sElsName);
  789. bx_import('Search', $oModule->_aModule);
  790. $sClass = 'BxElsSearch';
  791. }
  792. $oSearch = new $sClass(array($sSection));
  793. $oSearch->setLiveSearch($bLiveSearch);
  794. $oSearch->setMetaType(isset($aCondition['meta_type']) ? $aCondition['meta_type'] : '');
  795. $oSearch->setCategoryObject(isset($aCondition['cat']) ? $aCondition['cat'] : '');
  796. $oSearch->setCustomSearchCondition($aCondition);
  797. if (!$bPaginate)
  798. $oSearch->setRawProcessing(true);
  799. $oSearch->setCustomCurrentCondition(array(
  800. 'paginate' => array (
  801. 'start' => $iStart,
  802. 'perPage' => $iPerPage ? $iPerPage : BX_DOL_SEARCH_RESULTS_PER_PAGE_DEFAULT,
  803. )));
  804. if ($sTemplate)
  805. $oSearch->setUnitTemplate($sTemplate);
  806. return $oSearch->response();
  807. }
  808. /**
  809. * @page service Service Calls
  810. * @section bx_system_general System Services
  811. * @subsection bx_system_general-general General
  812. * @subsubsection bx_system_general-keyword_search keyword_search
  813. *
  814. * @code bx_srv('system', 'search_keyword_form', 'TemplServices'); @endcode
  815. *
  816. * Block with Search by Keywords Form
  817. *
  818. * @see BxBaseServices::serviceSearchKeywordForm
  819. */
  820. /**
  821. * @ref bx_system_general-keyword_search "keyword_search"
  822. */
  823. public function serviceSearchKeywordForm ()
  824. {
  825. return $this->_getSearchObject()->getForm(BX_DB_PADDING_DEF, false, true);
  826. }
  827. /**
  828. * @page service Service Calls
  829. * @section bx_system_general System Services
  830. * @subsection bx_system_general-general General
  831. * @subsubsection bx_system_general-keyword_search keyword_search
  832. *
  833. * @code bx_srv('system', 'search_keyword_result', 'TemplServices'); @endcode
  834. *
  835. * Block with Search by Keywords Results
  836. *
  837. * @see BxBaseServices::serviceSearchKeywordResult
  838. */
  839. /**
  840. * @ref bx_system_general-keyword_search "keyword_search"
  841. */
  842. public function serviceSearchKeywordResult ()
  843. {
  844. $sKeyword = bx_process_input(bx_get('keyword'));
  845. $bKeyword = $sKeyword !== false;
  846. if(bx_is_api())
  847. return $this->serviceGetDataSearchApi(['params' =>
  848. [
  849. 'keyword' => $sKeyword,
  850. 'section' => bx_process_input(bx_get('section')),
  851. 'cat' => bx_process_input(bx_get('cat'))
  852. ]
  853. ]);
  854. $sCode = '';
  855. if($bKeyword) {
  856. $oSearch = $this->_getSearchObject();
  857. $sCode = $oSearch->response();
  858. if(!$sCode)
  859. $sCode = $oSearch->getEmptyResult();
  860. }
  861. return $sCode;
  862. }
  863. /**
  864. * @ref bx_system_general-get_date_search_api "get_date_search_api"
  865. * @api @ref bx_system_general-get_date_search_api "get_date_search_api"
  866. */
  867. public function serviceGetDataSearchApi ($aParams)
  868. {
  869. if(!bx_is_api())
  870. return false;
  871. if(is_string($aParams))
  872. $aParams = json_decode($aParams, true);
  873. $aSections = [];
  874. $aSectionsAll = BxDolDb::getInstance()->fromCache(
  875. 'sys_global_search_pairs',
  876. 'getPairs',
  877. 'SELECT `ObjectName` AS `name`, `Title` AS `title` FROM `sys_objects_search` WHERE `GlobalSearch`=\'1\' ORDER BY `Order` ASC',
  878. 'name', 'title'
  879. );
  880. $aSectionNames = explode(',', getParam('sys_api_search_sections'));
  881. foreach($aSectionNames as $sSectionName) {
  882. if(!isset($aSectionsAll[$sSectionName]))
  883. continue;
  884. $aSections[$sSectionName] = [
  885. 'name' => $sSectionName,
  886. 'title' => _t($aSectionsAll[$sSectionName])
  887. ];
  888. }
  889. $aParamsBrowse = array_merge([
  890. 'keyword' => '',
  891. 'section' => '',
  892. 'sections' => array_values($aSections),
  893. 'start' => 0,
  894. 'per_page' => 12
  895. ], !empty($aParams['params']) && is_array($aParams['params']) ? $aParams['params'] : []);
  896. if(empty($aParamsBrowse['section']))
  897. $aParamsBrowse['section'] = array_keys($aSections);
  898. else if(is_string($aParamsBrowse['section']))
  899. $aParamsBrowse['section'] = explode(',', $aParamsBrowse['section']);
  900. $sClass = 'BxTemplSearch';
  901. $oSearch = new $sClass($aParamsBrowse['section']);
  902. $oSearch->setLiveSearch(true);
  903. $oSearch->setDataProcessing(true);
  904. $oSearch->setCustomSearchCondition(['keyword' => $aParamsBrowse['keyword']]);
  905. $oSearch->setCustomCurrentCondition([
  906. 'paginate' => [
  907. 'forceStart' => $aParamsBrowse['start'],
  908. 'perPage' => $aParamsBrowse['per_page'],
  909. ]
  910. ]);
  911. $aData = $oSearch->response();
  912. if(count($aData) > $aParamsBrowse['per_page'])
  913. $aData = array_slice($aData, $aParamsBrowse['start'], $aParamsBrowse['per_page']);
  914. return [
  915. bx_api_get_block('browse', [
  916. 'unit' => 'search-results',
  917. 'request_url' => '/api.php?r=system/get_data_search_api/TemplServices&params[]=',
  918. 'params' => $aParamsBrowse,
  919. 'data' => $aData
  920. ])
  921. ];
  922. }
  923. /**
  924. * @page service Service Calls
  925. * @section bx_system_general System Services
  926. * @subsection bx_system_general-general General
  927. * @subsubsection bx_system_general-cmts cmts
  928. *
  929. * @code bx_srv('system', 'cmts', ["sys_blocks", 1], 'TemplServices'); @endcode
  930. *
  931. * @code {{~system:cmts:TemplServices["sys_blocks", 1]~}} @endcode
  932. *
  933. * Comments block
  934. * @param $sObject - comments object name
  935. * @param $sId - content id assiciated tith the comments
  936. *
  937. * @see BxBaseServices::serviceCmts
  938. */
  939. /**
  940. * @ref bx_system_general-cmts "cmts"
  941. */
  942. public function serviceCmts ($sObject, $sId)
  943. {
  944. $o = BxDolCmts::getObjectInstance($sObject, $sId);
  945. if (!$o || !$o->isEnabled())
  946. return '';
  947. return $o->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
  948. }
  949. public function _serviceProfileFunc ($sFunc, $iContentId, $aParams = array())
  950. {
  951. if (!$iContentId)
  952. return false;
  953. if (!($oAccount = BxDolAccount::getInstance($iContentId)))
  954. return false;
  955. return $oAccount->$sFunc(false, $aParams);
  956. }
  957. public function serviceAlertResponseProcessInstalled()
  958. {
  959. BxDolTranscoderImage::registerHandlersSystem();
  960. }
  961. public function serviceAlertResponseProcessStorageChange ($oAlert)
  962. {
  963. if ('sys_storage_default' != $oAlert->aExtras['option'])
  964. return;
  965. $aStorages = BxDolStorageQuery::getStorageObjects();
  966. foreach ($aStorages as $r) {
  967. if (0 == $r['current_size'] && 0 == $r['current_number'] && ($oStorage = BxDolStorage::getObjectInstance($r['object'])))
  968. $oStorage->changeStorageEngine($oAlert->aExtras['value']);
  969. }
  970. }
  971. public function serviceGetOptionsProfileBot()
  972. {
  973. $aResult = array(
  974. array('key' => '', 'value' => _t('_Select_one'))
  975. );
  976. $aAccountsIds = BxDolAccountQuery::getInstance()->getOperators();
  977. foreach($aAccountsIds as $iAccountId) {
  978. $aProfilesIds = BxDolAccount::getInstance($iAccountId)->getProfilesIds(true, false);
  979. foreach($aProfilesIds as $iProfileId) {
  980. $oProfile = BxDolProfile::getInstance($iProfileId);
  981. $aResult[] = array(
  982. 'key' => $iProfileId,
  983. 'value' => _t('_sys_profile_with_type', $oProfile->getDisplayName(), $oProfile->getModule()),
  984. );
  985. }
  986. }
  987. return $aResult;
  988. }
  989. public function serviceGetOptionsModuleListForPrivacySelector()
  990. {
  991. $aResult = array();
  992. $BxDolModuleQuery = BxDolModuleQuery::getInstance();
  993. $aModules = $BxDolModuleQuery->getModulesBy(array('type' => 'modules', 'active' => 1));
  994. foreach($aModules as $aModule){
  995. $oModule = BxDolModule::getInstance($aModule['name']);
  996. if($oModule instanceof iBxDolContentInfoService){
  997. if (!BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  998. continue;
  999. $aResult[$aModule['name']] = $aModule['title'];
  1000. }
  1001. }
  1002. return $aResult;
  1003. }
  1004. public function serviceGetOptionsCaptchaDefault()
  1005. {
  1006. $aResults = [];
  1007. $aObjects = BxDolCaptchaQuery::getObjects();
  1008. foreach($aObjects as $aObject)
  1009. $aResults[$aObject['object']] = $aObject['title'];
  1010. return $aResults;
  1011. }
  1012. public function serviceGetOptionsEmbedDefault()
  1013. {
  1014. $aResults = array(
  1015. '' => _t('_None')
  1016. );
  1017. $aObjects = BxDolEmbedQuery::getObjects();
  1018. foreach($aObjects as $aObject)
  1019. $aResults[$aObject['object']] = $aObject['title'];
  1020. return $aResults;
  1021. }
  1022. public function serviceGetOptionsLocationFieldDefault()
  1023. {
  1024. $aResults = array();
  1025. $aObjects = BxDolLocationFieldQuery::getObjects();
  1026. foreach($aObjects as $aObject)
  1027. $aResults[$aObject['object']] = _t($aObject['title']);
  1028. return $aResults;
  1029. }
  1030. public function serviceGetOptionsLocationMapDefault()
  1031. {
  1032. $aResults = array();
  1033. $aObjects = BxDolLocationMapQuery::getObjects();
  1034. foreach($aObjects as $aObject)
  1035. $aResults[$aObject['object']] = _t($aObject['title']);
  1036. return $aResults;
  1037. }
  1038. public function serviceGetOptionsSocketsFieldDefault()
  1039. {
  1040. $aResults = [];
  1041. $aObjects = ['sys_sockets_disabled', 'sys_sockets_soketi'];
  1042. foreach($aObjects as $sObject)
  1043. $aResults[$sObject] = _t('_adm_stg_cpt_option_sys_sockets_type_' . $sObject);
  1044. return $aResults;
  1045. }
  1046. public function serviceGetOptionsLocationLeafletGetProviders()
  1047. {
  1048. return BxDolLocationMapLeaflet::getProviders();
  1049. }
  1050. public function serviceGetOptionsRelations()
  1051. {
  1052. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
  1053. $aProfiles = array();
  1054. foreach($aModules as $aModule) {
  1055. $sMethod = 'act_as_profile';
  1056. if(!BxDolRequest::serviceExists($aModule['name'], $sMethod) || !BxDolService::call($aModule['name'], $sMethod))
  1057. continue;
  1058. $aProfiles[$aModule['name']] = _t('_' . $aModule['name']);
  1059. }
  1060. $aResults = array();
  1061. foreach($aProfiles as $sName1 => $sTitle1)
  1062. foreach($aProfiles as $sName2 => $sTitle2)
  1063. $aResults[$sName1 . '_' . $sName2] = $sTitle1 . ' - ' . $sTitle2;
  1064. return $aResults;
  1065. }
  1066. public function serviceGetOptionsCfProhibited()
  1067. {
  1068. return BxDolFormQuery::getDataItems('sys_content_filter');
  1069. }
  1070. public function serviceGetOptionsTaiwindDefault()
  1071. {
  1072. $sPath = BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'tailwind/css';
  1073. $aExcludes = ['.', '..', 'tailwind.css'];
  1074. $aResults = [];
  1075. if(($oHandle = opendir($sPath)) !== false) {
  1076. while(($sFile = readdir($oHandle)) !== false) {
  1077. if(in_array($sFile, $aExcludes))
  1078. continue;
  1079. if(($oHandlerFile = fopen($sPath . '/' . $sFile, 'r')) === false)
  1080. continue;
  1081. if(($sContent = fread($oHandlerFile, 1024)) !== false && strpos($sContent, '@tailwind base') === false)
  1082. $aResults[$sFile] = $sFile;
  1083. fclose($oHandlerFile);
  1084. }
  1085. closedir($oHandle);
  1086. }
  1087. return $aResults;
  1088. }
  1089. public function serviceGetOptionsApiMenuTop()
  1090. {
  1091. $aMenus = BxDolMenuQuery::getMenuObjects();
  1092. $aResults = ['' => _t('_sys_please_select')];
  1093. foreach($aMenus as $aMenu)
  1094. if($aMenu['module'] == 'system')
  1095. $aResults[$aMenu['object']] = _t($aMenu['title']);
  1096. return $aResults;
  1097. }
  1098. public function serviceRedirect($sUrl = false)
  1099. {
  1100. if (false === $sUrl)
  1101. $sUrl = bx_get('url');
  1102. if (!$sUrl || !preg_match('@^https?://@', $sUrl)) {
  1103. return MsgBox(_t('_error occured'));
  1104. }
  1105. else {
  1106. $bSpam = null;
  1107. bx_alert('system', 'check_spam_url', 0, getLoggedId(), array('is_spam' => &$bSpam, 'content' => &$sUrl, 'where' => 'redirect'));
  1108. if (false === $bSpam) {
  1109. header('Location: ' . $sUrl);
  1110. }
  1111. elseif (true === $bSpam || null === $bSpam) {
  1112. return BxDolTemplate::getInstance()->parseHtmlByName('redirect.html', [
  1113. 'text' => _t('_sys_redirect_confirmation', bx_process_output($sUrl), getParam('site_title')),
  1114. 'url' => bx_js_string($sUrl, BX_ESCAPE_STR_APOS),
  1115. ]);
  1116. }
  1117. }
  1118. }
  1119. public function serviceGetBadge($aBadge, $bIsCompact = false)
  1120. {
  1121. $sClass = '';
  1122. $sStyleFont = '';
  1123. $sStyleBg = '';
  1124. if ($aBadge['color'] == '')
  1125. $aBadge['color'] = 'purple-600';
  1126. if ($bIsCompact && $aBadge['icon'] != ''){
  1127. $aBadge['is_icon_only'] = 1;
  1128. }
  1129. if ($aBadge['is_icon_only'] == 1){
  1130. $sClass .= ' bx-badge-compact';
  1131. if (substr_count($aBadge['color'], 'rgb('))
  1132. $sStyleFont = 'color: ' . $aBadge['color'];
  1133. else
  1134. $sClass .= ' text-' . $aBadge['color'];
  1135. }
  1136. else{
  1137. if (substr_count($aBadge['color'], 'rgb('))
  1138. $sStyleBg = 'background-color: ' . $aBadge['color'];
  1139. else
  1140. $sClass .= ' bg-' . $aBadge['color'];
  1141. }
  1142. return BxDolTemplate::getInstance()->parseHtmlByName('badge.html', array(
  1143. 'bx_if:content' => array(
  1144. 'condition' => $aBadge['is_icon_only'] != '1',
  1145. 'content' => array('content' => _t($aBadge['text'])),
  1146. ),
  1147. 'bx_if:icon' => array(
  1148. 'condition' => $aBadge['icon'] != '',
  1149. 'content' => array('content' => BxDolTemplate::getInstance()->getIcon($aBadge['icon'], array('class' => 'bx-badge-icon sys-colored', 'style' => $sStyleFont))),
  1150. ),
  1151. 'title' => $aBadge['text'],
  1152. 'style_font' => $sStyleFont,
  1153. 'style_bg' => $sStyleBg,
  1154. 'class' => $sClass,
  1155. )
  1156. );
  1157. }
  1158. public function serviceGetFooter()
  1159. {
  1160. return BxDolTemplate::getInstance()->parseHtmlByName('footer.html', []);
  1161. }
  1162. private function _getSearchObject()
  1163. {
  1164. $sClass = 'BxTemplSearch';
  1165. $sElsName = 'bx_elasticsearch';
  1166. $sElsMethod = 'is_configured';
  1167. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod) && !bx_get('cat') && !bx_get('type')) {
  1168. $oModule = BxDolModule::getInstance($sElsName);
  1169. bx_import('Search', $oModule->_aModule);
  1170. $sClass = 'BxElsSearch';
  1171. }
  1172. bx_alert('system', 'search_keyword', 0, 0, array('class' => &$sClass));
  1173. $oSearch = new $sClass(bx_get('section'));
  1174. $oSearch->setLiveSearch(bx_get('live_search') ? 1 : 0);
  1175. $oSearch->setMetaType(bx_process_input(bx_get('type')));
  1176. $oSearch->setCategoryObject(bx_process_input(bx_get('cat')));
  1177. return $oSearch;
  1178. }
  1179. }
  1180. /** @} */