BxBaseServices.php 50 KB

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