BxBaseServices.php 50 KB

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