BxBaseServices.php 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795
  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. 'GetMenu' => 'BxBaseServices',
  41. 'GetCreatePostForm' => 'BxBaseServices',
  42. 'GetProductsNames' => 'BxBaseServices',
  43. 'KeywordSearch' => 'BxBaseServices',
  44. 'GetDataSearchApi' => 'BxBaseServices',
  45. 'Cmts' => 'BxBaseServices',
  46. 'GetFooter' => 'BxBaseServices',
  47. 'SetBadges' => 'BxBaseServices',
  48. 'GetPageContentByRequest' => 'BxBaseServicePages',
  49. 'GetPageBlockData' => 'BxBaseServicePages',
  50. 'SetPageBlockData' => 'BxBaseServicePages',
  51. 'GetPageBlockImageData' => 'BxBaseServicePages',
  52. 'GetUrlInfo' => 'BxBaseServicePages',
  53. 'CreateAccountForm' => 'BxBaseServiceAccount',
  54. 'AccountSettingsEmail' => 'BxBaseServiceAccount',
  55. 'AccountSettingsPassword' => 'BxBaseServiceAccount',
  56. 'AccountSettingsDelAccount' => 'BxBaseServiceAccount',
  57. 'AccountSettingsInfo' => 'BxBaseServiceAccount',
  58. 'ForgotPassword' => 'BxBaseServiceAccount',
  59. 'SwitchProfile' => 'BxBaseServiceAccount',
  60. 'AccountProfileSwitcher' => 'BxBaseServiceAccount',
  61. 'EmailConfirmation' => 'BxBaseServiceAccount',
  62. 'ConfirmEmail' => 'BxBaseServiceAccount',
  63. 'CategoriesList' => 'BxBaseServiceCategory',
  64. 'Test' => 'BxBaseServiceLogin',
  65. 'MemberAuthCode' => 'BxBaseServiceLogin',
  66. 'LoginForm' => 'BxBaseServiceLogin',
  67. 'LoginFormOnly' => 'BxBaseServiceLogin',
  68. 'Logout' => 'BxBaseServiceLogin',
  69. 'KeywordsCloud' => 'BxBaseServiceMetatags',
  70. 'AccountProfileSwitcher' => 'BxBaseServiceProfiles',
  71. 'ProfileMembership' => 'BxBaseServiceProfiles',
  72. 'ProfileNotifications' => 'BxBaseServiceProfiles',
  73. 'GetCountOnlineProfiles' => 'BxBaseServiceProfiles',
  74. 'BrowseRecommendationsFriends' => 'BxBaseServiceProfiles',
  75. 'BrowseRecommendationsSubscriptions' => 'BxBaseServiceProfiles',
  76. 'BrowseFriends' => 'BxBaseServiceProfiles',
  77. 'SetMembership' => 'BxBaseServiceProfiles',
  78. 'ResetMembership' => 'BxBaseServiceProfiles',
  79. 'BrowseFriendRequests' => 'BxBaseServiceProfiles',
  80. 'BrowseFriendRequested' => 'BxBaseServiceProfiles',
  81. 'BrowseSubscribedMe' => 'BxBaseServiceProfiles',
  82. 'BrowseSubscriptions' => 'BxBaseServiceProfiles',
  83. 'BrowseMembers' => 'BxBaseServiceProfiles',
  84. 'BrowseInvitations' => 'BxBaseServiceProfiles',
  85. 'UpdateSettings' => 'BxBaseServiceProfiles',
  86. 'Befriend' => 'BxBaseServiceProfiles',
  87. 'ProfileCounters' => 'BxBaseServiceProfiles',
  88. 'ProfileInfo' => 'BxBaseServiceProfiles',
  89. 'GetChartGrowth' => 'BxBaseChartServices',
  90. 'GetChartStats' => 'BxBaseChartServices',
  91. 'GetDataByInterval' => 'BxBaseChartServices',
  92. 'GetCartItemsCount' => 'BxBasePaymentsServices',
  93. 'GetOrdersCount' => 'BxBasePaymentsServices',
  94. 'Do' => 'BxBaseReportServices',
  95. 'GetPerformedBy' => 'BxBaseReportServices',
  96. 'Do' => 'BxBaseVoteServices',
  97. 'GetPerformedBy' => 'BxBaseVoteServices',
  98. 'Perform' => 'BxBaseFeatureServices',
  99. 'Perform' => 'BxBaseFavoriteServices',
  100. 'GetPerformedBy' => 'BxBaseFavoriteServices',
  101. 'Perform' => 'BxBaseServiceConnections',
  102. 'Perform' => 'BxBaseServiceRecommendations',
  103. 'GetDataApi' => 'BxBaseCmtsServices',
  104. 'GetDataApi' => 'BxBaseUploaderServices',
  105. 'GetStatBlock' => 'BxBaseDashboardServices',
  106. 'PerfomActionApi' => 'BxBaseServiceGrid',
  107. 'GetLabels' => 'BxBaseLabelsServices',
  108. 'GetForm' => 'BxBaseSearchExtendedServices',
  109. 'GetResults' => 'BxBaseSearchExtendedServices',
  110. 'WikiAction' => 'BxBaseServiceWiki'
  111. );
  112. }
  113. public function serviceGetPreloaderContent($sName) {
  114. $sResult = '';
  115. switch($sName) {
  116. case 'icons_css':
  117. if(($sCss = BxDolIconset::getObjectInstance()->getPreloaderCss()) !== false)
  118. $sResult = $sCss;
  119. break;
  120. case 'icons_js':
  121. if(($sJs = BxDolIconset::getObjectInstance()->getPreloaderJs()) !== false)
  122. $sResult = $sJs;
  123. break;
  124. case 'tailwind':
  125. $sFile = getParam('sys_css_tailwind_default');
  126. if(empty($sFile))
  127. $sFile = 'tailwind.min.css';
  128. $sPath = '{dir_plugins_public}tailwind/css/|';
  129. if($sFile == 'cdn')
  130. $sResult = [
  131. 'https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4',
  132. $sPath . 'tailwind.min.css' //TODO: Replace this with correct file name.
  133. ];
  134. else
  135. $sResult = $sPath . $sFile;
  136. break;
  137. }
  138. return $sResult;
  139. }
  140. /**
  141. * @page service Service Calls
  142. * @section bx_system_general System Services
  143. * @subsection bx_system_general-general General
  144. * @subsubsection bx_system_general-module_check_for_update module_check_for_update
  145. *
  146. * @code bx_srv('system', 'module_check_for_update', ["bx_posts"]); @endcode
  147. * @code bx_srv('system', 'module_check_for_update', ["bx_posts"], 'TemplServices'); @endcode
  148. * @code {{~system:module_check_for_update:TemplServices["bx_posts"]~}} @endcode
  149. *
  150. * Checks whether an update is available for requested module or not.
  151. * @param $mixedModule - module ID/name to check the updates for.
  152. * @return array with information about the update, false if nothing was found
  153. *
  154. * @see BxBaseServices::serviceModuleCheckForUpdate
  155. */
  156. /**
  157. * @ref bx_system_general-module_check_for_update "module_check_for_update"
  158. */
  159. public function serviceModuleCheckForUpdate($mixedModule)
  160. {
  161. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  162. if(empty($aModule) || !is_array($aModule))
  163. return false;
  164. $aUpdates = BxDolStudioInstallerUtils::getInstance()->checkUpdatesByModule($aModule['name']);
  165. if(empty($aUpdates) || !is_array($aUpdates))
  166. return false;
  167. $aUpdate = array_shift($aUpdates);
  168. return array(
  169. 'version_from' => $aUpdate['file_version'],
  170. 'version_to' => $aUpdate['file_version_to'],
  171. 'file_id' => $aUpdate['file_id']
  172. );
  173. }
  174. /**
  175. * @page service Service Calls
  176. * @section bx_system_general System Services
  177. * @subsection bx_system_general-general General
  178. * @subsubsection bx_system_general-module_update module_update
  179. *
  180. * @code bx_srv('system', 'module_update', ["bx_posts"]); @endcode
  181. * @code bx_srv('system', 'module_update', ["bx_posts"], 'TemplServices'); @endcode
  182. * @code {{~system:module_update:TemplServices["bx_posts"]~}} @endcode
  183. *
  184. * Download and install an update for requested module. The operation may be performed
  185. * immediately or by Transient Cron task. The second way is more common.
  186. * @param $mixedModule - module ID/name to check the updates for.
  187. * @return integer value determining the result of the operation. It can be one of the following values:
  188. * BX_DOL_STUDIO_IU_RC_SUCCESS, BX_DOL_STUDIO_IU_RC_FAILED or BX_DOL_STUDIO_IU_RC_SCHEDULED.
  189. *
  190. * @see BxBaseServices::serviceModuleUpdate
  191. */
  192. /**
  193. * @ref bx_system_general-module_update "module_update"
  194. */
  195. public function serviceModuleUpdate($mixedModule)
  196. {
  197. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  198. if(empty($aModule) || !is_array($aModule))
  199. return BX_DOL_STUDIO_IU_RC_FAILED;
  200. $aResult = BxDolStudioInstallerUtils::getInstance()->downloadUpdatePublic($aModule['name'], true);
  201. return $aResult['code'];
  202. }
  203. /**
  204. * @page service Service Calls
  205. * @section bx_system_general System Services
  206. * @subsection bx_system_general-general General
  207. * @subsubsection bx_system_general-module_delete module_delete
  208. *
  209. * @code bx_srv('system', 'module_delete', ["bx_posts"]); @endcode
  210. * @code bx_srv('system', 'module_delete', ["bx_posts", true], 'TemplServices'); @endcode
  211. * @code {{~system:module_delete:TemplServices["bx_posts"]~}} @endcode
  212. *
  213. * Delete the requested module. By default only uninstalled module can be deleted.
  214. * The operation may be performed immediately or by Transient Cron task. The second way is more common.
  215. * @param $sModule - module name to delete.
  216. * @param $bForceUninstall - if 'true' is passed the module will be uninstalled before deletion.
  217. * @return integer value determining the result of the operation. It can be one of the following values:
  218. * BX_DOL_STUDIO_IU_RC_SUCCESS, BX_DOL_STUDIO_IU_RC_FAILED or BX_DOL_STUDIO_IU_RC_SCHEDULED.
  219. *
  220. * @see BxBaseServices::serviceModuleDelete
  221. */
  222. /**
  223. * @ref bx_system_general-module_delete "module_delete"
  224. */
  225. public function serviceModuleDelete($sModule, $bForceUninstall = false)
  226. {
  227. $sModulePath = '';
  228. $oInstallerUtils = BxDolStudioInstallerUtils::getInstance();
  229. $aModule = BxDolModuleQuery::getInstance()->getModuleByName($sModule, false);
  230. if(!empty($aModule) && is_array($aModule)) {
  231. if(!$bForceUninstall)
  232. return BX_DOL_STUDIO_IU_RC_FAILED;
  233. $sModulePath = $aModule['path'];
  234. $aResult = $oInstallerUtils->perform($sModulePath, 'uninstall', array('auto_disable' => $bForceUninstall));
  235. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  236. return BX_DOL_STUDIO_IU_RC_FAILED;
  237. }
  238. else {
  239. $aModules = $oInstallerUtils->getModules(false);
  240. if(!isset($aModules[$sModule]))
  241. return BX_DOL_STUDIO_IU_RC_FAILED;
  242. $sModulePath = $aModules[$sModule]['dir'];
  243. }
  244. $aResult = $oInstallerUtils->perform($sModulePath, 'delete');
  245. return $aResult['code'];
  246. }
  247. /**
  248. * @page service Service Calls
  249. * @section bx_system_general System Services
  250. * @subsection bx_system_general-general General
  251. * @subsubsection bx_system_general-module_install module_install
  252. *
  253. * @code bx_srv('system', 'module_install', ["bx_posts"]); @endcode
  254. * @code bx_srv('system', 'module_install', ["bx_posts", true], 'TemplServices'); @endcode
  255. * @code {{~system:module_install:TemplServices["bx_posts"]~}} @endcode
  256. *
  257. * Install the requested module. By default the module will be installed only.
  258. * @param $sModule - module name to install.
  259. * @param $bForceEnable - if 'true' is passed the module will be automatically enabled after installation.
  260. * @return boolean value determining the result of the operation.
  261. *
  262. * @see BxBaseServices::serviceModuleInstall
  263. */
  264. /**
  265. * @ref bx_system_general-module_install "module_install"
  266. */
  267. public function serviceModuleInstall($sModule, $bForceEnable = false)
  268. {
  269. $oInstallerUtils = BxDolStudioInstallerUtils::getInstance();
  270. $aModules = $oInstallerUtils->getModules(false);
  271. if(!isset($aModules[$sModule]))
  272. return false;
  273. $aResult = $oInstallerUtils->perform($aModules[$sModule]['dir'], 'install', array('auto_enable' => $bForceEnable));
  274. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  275. return false;
  276. return true;
  277. }
  278. /**
  279. * @page service Service Calls
  280. * @section bx_system_general System Services
  281. * @subsection bx_system_general-general General
  282. * @subsubsection bx_system_general-module_uninstall module_uninstall
  283. *
  284. * @code bx_srv('system', 'module_uninstall', ["bx_posts"]); @endcode
  285. * @code bx_srv('system', 'module_uninstall', ["bx_posts", true], 'TemplServices'); @endcode
  286. * @code {{~system:module_uninstall:TemplServices["bx_posts"]~}} @endcode
  287. *
  288. * Uninstall the requested module. By default only disabled module can be uninstalled.
  289. * @param $mixedModule - module ID/name to uninstall.
  290. * @param $bForceDisable - if 'true' is passed the module will be automatically disabled before uninstallation.
  291. * @return boolean value determining the result of the operation.
  292. *
  293. * @see BxBaseServices::serviceModuleUninstall
  294. */
  295. /**
  296. * @ref bx_system_general-module_uninstall "module_uninstall"
  297. */
  298. public function serviceModuleUninstall($mixedModule, $bForceDisable = false)
  299. {
  300. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  301. if(empty($aModule) || !is_array($aModule))
  302. return false;
  303. if((int)$aModule['enabled'] != 0 && !$bForceDisable)
  304. return false;
  305. $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aModule['path'], 'uninstall', array('auto_disable' => $bForceDisable));
  306. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  307. return false;
  308. return true;
  309. }
  310. /**
  311. * @page service Service Calls
  312. * @section bx_system_general System Services
  313. * @subsection bx_system_general-general General
  314. * @subsubsection bx_system_general-module_enable module_enable
  315. *
  316. * @code bx_srv('system', 'module_enable', ["bx_posts"]); @endcode
  317. * @code bx_srv('system', 'module_enable', ["bx_posts"], 'TemplServices'); @endcode
  318. * @code {{~system:module_enable:TemplServices["bx_posts"]~}} @endcode
  319. *
  320. * Enable the requested module.
  321. * @param $mixedModule - module ID/name to enable.
  322. * @return boolean value determining the result of the operation.
  323. *
  324. * @see BxBaseServices::serviceModuleEnable
  325. */
  326. /**
  327. * @ref bx_system_general-module_enable "module_enable"
  328. */
  329. public function serviceModuleEnable($mixedModule)
  330. {
  331. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  332. if(empty($aModule) || !is_array($aModule))
  333. return false;
  334. if((int)$aModule['enabled'] != 0)
  335. return false;
  336. $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aModule['path'], 'enable');
  337. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  338. return false;
  339. return true;
  340. }
  341. /**
  342. * @page service Service Calls
  343. * @section bx_system_general System Services
  344. * @subsection bx_system_general-general General
  345. * @subsubsection bx_system_general-module_disable module_disable
  346. *
  347. * @code bx_srv('system', 'module_disable', ["bx_posts"]); @endcode
  348. * @code bx_srv('system', 'module_disable', ["bx_posts"], 'TemplServices'); @endcode
  349. * @code {{~system:module_disable:TemplServices["bx_posts"]~}} @endcode
  350. *
  351. * Disable the requested module.
  352. * @param $mixedModule - module ID/name to disable.
  353. * @return boolean value determining the result of the operation.
  354. *
  355. * @see BxBaseServices::serviceModuleDisable
  356. */
  357. /**
  358. * @ref bx_system_general-module_disable "module_disable"
  359. */
  360. public function serviceModuleDisable($mixedModule)
  361. {
  362. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  363. if(empty($aModule) || !is_array($aModule))
  364. return false;
  365. if((int)$aModule['enabled'] == 0)
  366. return false;
  367. $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aModule['path'], 'disable');
  368. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  369. return false;
  370. return true;
  371. }
  372. /**
  373. * @page service Service Calls
  374. * @section bx_system_general System Services
  375. * @subsection bx_system_general-general General
  376. * @subsubsection bx_system_general-is_module_installed is_module_installed
  377. *
  378. * @code bx_srv('system', 'is_module_installed', ["bx_posts"]); @endcode
  379. * @code bx_srv('system', 'is_module_installed', ["bx_posts"], 'TemplServices'); @endcode
  380. * @code {{~system:is_module_installed:TemplServices["bx_posts"]~}} @endcode
  381. *
  382. * Checks whether the requested module is installed or not.
  383. * @param $mixedModule - module ID/name to check.
  384. * @return boolean value determining the result of the operation.
  385. *
  386. * @see BxBaseServices::serviceIsModuleInstalled
  387. */
  388. /**
  389. * @ref bx_system_general-is_module_installed "is_module_installed"
  390. */
  391. public function serviceIsModuleInstalled($mixedModule)
  392. {
  393. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  394. return !empty($aModule) && is_array($aModule);
  395. }
  396. /**
  397. * @page service Service Calls
  398. * @section bx_system_general System Services
  399. * @subsection bx_system_general-general General
  400. * @subsubsection bx_system_general-is_module_enabled is_module_enabled
  401. *
  402. * @code bx_srv('system', 'is_module_enabled', ["bx_posts"]); @endcode
  403. * @code bx_srv('system', 'is_module_enabled', ["bx_posts"], 'TemplServices'); @endcode
  404. * @code {{~system:is_module_enabled:TemplServices["bx_posts"]~}} @endcode
  405. *
  406. * Checks whether the requested module is enabled or not.
  407. * @param $mixedModule - module ID/name to check.
  408. * @return boolean value determining the result of the operation.
  409. *
  410. * @see BxBaseServices::serviceIsModuleEnabled
  411. */
  412. /**
  413. * @ref bx_system_general-is_module_enabled "is_module_enabled"
  414. */
  415. public function serviceIsModuleEnabled($mixedModule)
  416. {
  417. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  418. return !empty($aModule) && is_array($aModule) && (int)$aModule['enabled'] != 0;
  419. }
  420. /**
  421. * Checks whether a module is a 'Content' module or not.
  422. *
  423. * @param string $mixedModule - module name or an instance of Module class.
  424. * @return boolean result of operation.
  425. */
  426. public function serviceIsModuleContent($mixedModule)
  427. {
  428. if($mixedModule instanceof BxDolModule)
  429. $mixedModule = $mixedModule->getName();
  430. return BxDolModuleQuery::getInstance()->isModuleContent($mixedModule);
  431. }
  432. /**
  433. * Checks whether a module is a 'Context' module or not.
  434. *
  435. * @param string $mixedModule - module name or an instance of Module class.
  436. * @return boolean result of operation.
  437. */
  438. public function serviceIsModuleContext($mixedModule)
  439. {
  440. if($mixedModule instanceof BxDolModule)
  441. $mixedModule = $mixedModule->getName();
  442. return BxDolModuleQuery::getInstance()->isModuleContext($mixedModule);
  443. }
  444. /**
  445. * Checks whether a module is a 'Profile' module or not.
  446. *
  447. * @param string $mixedModule - module name or an instance of Module class.
  448. * @return boolean result of operation.
  449. */
  450. public function serviceIsModuleProfile($mixedModule)
  451. {
  452. if($mixedModule instanceof BxDolModule)
  453. $mixedModule = $mixedModule->getName();
  454. return BxDolModuleQuery::getInstance()->isModuleProfile($mixedModule);
  455. }
  456. /**
  457. * Get modules by type. Available types are 'content', 'context', 'profile'.
  458. *
  459. * @param type $sType - string with type.
  460. * @return array of modules.
  461. */
  462. public function serviceGetModulesByType($sType, $aParams = [])
  463. {
  464. $oModuleQuery = BxDolModuleQuery::getInstance();
  465. if(!$oModuleQuery->checkModulesSubtypes()) {
  466. $oInstallerUtils = new BxDolInstallerUtils();
  467. $aModules = $oModuleQuery->getModulesBy(['type' => 'modules']);
  468. foreach($aModules as $aModule)
  469. if(($iModuleSubtypes = $oInstallerUtils->getSubtypes($aModule['name'])) != 0)
  470. $oModuleQuery->updateModule(['subtypes' => $iModuleSubtypes], ['id' => $aModule['id']]);
  471. }
  472. $iSubtypes = 0;
  473. switch($sType) {
  474. case 'content':
  475. $iSubtypes = BX_DOL_MODULE_SUBTYPE_TEXT;
  476. break;
  477. case 'context':
  478. $iSubtypes = BX_DOL_MODULE_SUBTYPE_CONTEXT;
  479. break;
  480. case 'profile':
  481. $iSubtypes = BX_DOL_MODULE_SUBTYPE_PROFILE;
  482. break;
  483. }
  484. $aResults = $oModuleQuery->getModulesBy(array_merge([
  485. 'type' => 'modules_subtypes',
  486. 'value' => $iSubtypes,
  487. 'active' => 1
  488. ], array_intersect_key($aParams, array_flip(['id_as_key', 'name_as_key']))));
  489. return $aResults;
  490. }
  491. public function serviceGetModulesBySubtypeSimple($sType)
  492. {
  493. $a = $this->serviceGetModulesByType($sType, ['name_as_key' => true]);
  494. return array_map(function ($r) {
  495. return $r['title'];
  496. }, $a);
  497. }
  498. public function serviceProfileUnit ($iContentId, $aParams = array())
  499. {
  500. return $this->_serviceProfileFunc('getUnit', $iContentId, $aParams);
  501. }
  502. public function serviceProfileUnitApi ($iContentId, $aParams = [])
  503. {
  504. return $this->_serviceProfileFunc('getUnitApi', $iContentId, $aParams);
  505. }
  506. public function serviceHasImage ($iContentId)
  507. {
  508. return false;
  509. }
  510. public function serviceProfilePicture ($iContentId)
  511. {
  512. return $this->_serviceProfileFunc('getPicture', $iContentId);
  513. }
  514. public function serviceProfileAvatar ($iContentId)
  515. {
  516. return $this->_serviceProfileFunc('getAvatar', $iContentId);
  517. }
  518. public function serviceProfileAvatarBig ($iContentId)
  519. {
  520. return $this->_serviceProfileFunc('getAvatarBig', $iContentId);
  521. }
  522. public function serviceProfileCover ($iContentId)
  523. {
  524. return '';
  525. }
  526. public function serviceProfileEditUrl ($iContentId)
  527. {
  528. return bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=account-settings-info'));
  529. }
  530. public function serviceProfileThumb ($iContentId)
  531. {
  532. return $this->_serviceProfileFunc('getThumb', $iContentId);
  533. }
  534. public function serviceProfileIcon ($iContentId)
  535. {
  536. return $this->_serviceProfileFunc('getIcon', $iContentId);
  537. }
  538. public function serviceProfileName ($iContentId)
  539. {
  540. return $this->_serviceProfileFunc('getDisplayName', $iContentId);
  541. }
  542. public function serviceProfileUrl ($iContentId)
  543. {
  544. return $this->_serviceProfileFunc('getUrl', $iContentId);
  545. }
  546. /**
  547. * @see iBxDolProfileService::serviceCheckAllowedProfileView
  548. */
  549. public function serviceCheckAllowedProfileView($iContentId)
  550. {
  551. return _t('_Access denied');
  552. }
  553. /**
  554. * @see iBxDolProfileService::serviceCheckAllowedProfileContact
  555. */
  556. public function serviceCheckAllowedProfileContact($iContentId)
  557. {
  558. return _t('_Access denied');
  559. }
  560. /**
  561. * @see iBxDolProfileService::serviceCheckAllowedPostInProfile
  562. */
  563. public function serviceCheckAllowedPostInProfile($iContentId, $sPostModule = '')
  564. {
  565. return _t('_Access denied');
  566. }
  567. /**
  568. * @see iBxDolProfileService::serviceCheckAllowedModuleActionInProfile
  569. */
  570. public function serviceCheckAllowedModuleActionInProfile($iContentId, $sPostModule, $sActionName)
  571. {
  572. return _t('_Access denied');
  573. }
  574. /**
  575. * @see iBxDolProfileService::serviceGetSpaceTitle
  576. */
  577. public function serviceGetSpaceTitle()
  578. {
  579. return '';
  580. }
  581. /**
  582. * @see iBxDolProfileService::serviceGetParticipatingProfiles
  583. */
  584. public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObject = false)
  585. {
  586. return array();
  587. }
  588. /**
  589. * @page service Service Calls
  590. * @section bx_system_general System Services
  591. * @subsection bx_system_general-general General
  592. * @subsubsection bx_system_general-get_create_post_form get_create_post_form
  593. *
  594. * @code bx_srv('system', 'get_create_post_form', [false, "bx_posts"], 'TemplServices'); @endcode
  595. * @code {{~system:get_create_post_form:TemplServices[false,"bx_posts"]~}} @endcode
  596. *
  597. * Get United Create Post form.
  598. * @param $mixedContextId - context which the post will be created in:
  599. * - false = 'Public' post form;
  600. * - 0 = 'Profile' post form, which allows to post in your own profile and connections;
  601. * - n = 'Context' post form, which allows to post in context (3d party profile, group, event, etc).
  602. * @param $sDefault - tab selected by default.
  603. * @param $aCustom - an array with custom paramaters.
  604. * @return string with form content
  605. *
  606. * @see BxBaseServices::serviceGetCreatePostForm
  607. */
  608. /**
  609. * @ref bx_system_general-get_create_post_form "get_create_post_form"
  610. */
  611. public function serviceGetCreatePostForm($mixedContextId = false, $sDefault = '', $aCustom = array())
  612. {
  613. if(!isLogged() || ($mixedContextId !== false && !is_numeric($mixedContextId)))
  614. return '';
  615. $oProfile = BxDolProfile::getInstance();
  616. if(!$oProfile)
  617. return '';
  618. if($mixedContextId !== false)
  619. $mixedContextId = (int)(!empty($mixedContextId) ? -$mixedContextId : $oProfile->id());
  620. $oMenu = BxDolMenu::getObjectInstance('sys_create_post');
  621. if(!$oMenu)
  622. return '';
  623. $oMenu->setContextId($mixedContextId);
  624. $aMenuItems = $oMenu->getMenuItems();
  625. if(empty($aMenuItems) || !is_array($aMenuItems))
  626. return '';
  627. if(empty($sDefault)) {
  628. $aDefault = array_shift($aMenuItems);
  629. $sDefault = !empty($aDefault['module']) ? $aDefault['module'] : $aDefault['name'];
  630. }
  631. $oMenu->setSelected($sDefault, $sDefault);
  632. $oContext = false;
  633. $bContext = $mixedContextId !== false;
  634. if($bContext && ($oContext = BxDolProfile::getInstance(abs($mixedContextId))) !== false)
  635. if(bx_srv($oContext->getModule(), 'check_allowed_post_in_profile', [$oContext->getContentId(), $sDefault]) !== CHECK_ACTION_RESULT_ALLOWED)
  636. return '';
  637. $sTitle = '_sys_page_block_title_create_post';
  638. if(!$bContext)
  639. $sTitle = _t($sTitle . '_public');
  640. else if($mixedContextId < 0) {
  641. $sTitle = _t($sTitle . '_context');
  642. if($oContext)
  643. $sTitle = bx_replace_markers($sTitle, [
  644. 'display_name' => $oContext->getDisplayName()
  645. ]);
  646. }
  647. else
  648. $sTitle = _t($sTitle);
  649. $sPlaceholder = _t('_sys_txt_create_post_placeholder', $oProfile->getDisplayName());
  650. $oDbModules = BxDolModuleQuery::getInstance();
  651. $oTemplate = BxDolTemplate::getInstance();
  652. $oTemplate->addJs(['BxDolCreatePost.js']);
  653. $aPreloadingList = [];
  654. $aModules = explode(',', getParam('sys_create_post_form_preloading_list'));
  655. if(!empty($aModules))
  656. foreach($aModules as $sModule) {
  657. $aModule = $oDbModules->getModuleByName($sModule);
  658. if(empty($aModule) || !is_array($aModule))
  659. continue;
  660. $aPreloadingList[$sModule] = $aModule['uri'];
  661. }
  662. if(bx_is_api()) {
  663. return [
  664. 'title' => $sTitle,
  665. 'content' => [
  666. bx_api_get_block('get_create_post_form', [
  667. 'menu' => $oMenu->getCodeAPI(),
  668. 'params' => ['context_id' => $mixedContextId]])
  669. ]
  670. ];
  671. }
  672. $sJsObject = 'oBxDolCreatePost';
  673. $sJsContent = $oTemplate->_wrapInTagJsCode("var " . $sJsObject . " = new BxDolCreatePost(" . json_encode([
  674. 'sObjName' => $sJsObject,
  675. 'sRootUrl' => BX_DOL_URL_ROOT,
  676. 'sDefault' => $sDefault,
  677. 'iContextId' => $bContext ? $mixedContextId : 0,
  678. 'oPreloadingList' => $aPreloadingList,
  679. 'oCustom' => $aCustom
  680. ]) . ");");
  681. return [
  682. 'title' => $sTitle,
  683. 'content' => $oTemplate->parseHtmlByName('create_post_form.html', [
  684. 'default' => $sDefault,
  685. 'placeholder' => $sPlaceholder,
  686. 'user_thumb' => $oProfile->getUnit(0, ['template' => 'unit_wo_info_links']),
  687. 'form' => bx_srv($sDefault, 'get_create_post_form', [[
  688. 'context_id' => $mixedContextId,
  689. 'ajax_mode' => true,
  690. 'absolute_action_url' => true,
  691. 'custom' => $aCustom
  692. ]]),
  693. 'js_object' => $sJsObject,
  694. 'js_content' => $sJsContent
  695. ]),
  696. 'menu' => $oMenu->getMenuItemsCount() > 1 ? $oMenu : ''
  697. ];
  698. }
  699. public function serviceGetOptionsCreatePostFormPreloadingList()
  700. {
  701. $oMenu = BxDolMenu::getObjectInstance('sys_create_post');
  702. if(!$oMenu)
  703. return [];
  704. $aMenuItems = $oMenu->getMenuItems();
  705. $aResult = [];
  706. foreach($aMenuItems as $aMenuItem) {
  707. $sModule = !empty($aMenuItem['module']) ? $aMenuItem['module'] : $aMenuItem['name'];
  708. if(!bx_srv('system', 'is_module_enabled', [$sModule]))
  709. continue;
  710. $aResult[] = [
  711. 'key' => $sModule,
  712. 'value' => _t('_' . $sModule)
  713. ];
  714. }
  715. return $aResult;
  716. }
  717. public function serviceGetBlockStatic($sBlockName)
  718. {
  719. $bIsApi = bx_is_api();
  720. if(!$bIsApi)
  721. return '';
  722. return [bx_api_get_block('static', [
  723. 'element' => $sBlockName
  724. ])];
  725. }
  726. public function serviceGetBlockAuthor($sModule, $iContentId = 0)
  727. {
  728. if(!$iContentId && bx_get('id') !== false)
  729. $iContentId = (int)bx_get('id');
  730. $sMethodGetAuthor = 'get_author';
  731. if(!$sModule || !$iContentId || !BxDolRequest::serviceExists($sModule, $sMethodGetAuthor))
  732. return '';
  733. $iAuthor = bx_srv($sModule, $sMethodGetAuthor, [$iContentId]);
  734. if(!$iAuthor)
  735. return '';
  736. $oAuthor = BxDolProfile::getInstance($iAuthor);
  737. if(!$oAuthor)
  738. return '';
  739. $sModuleAuthor = $oAuthor->getModule();
  740. $sMethodGetCover = 'entity_cover';
  741. if(!BxDolRequest::serviceExists($sModuleAuthor, $sMethodGetCover))
  742. return '';
  743. return bx_srv($sModuleAuthor, $sMethodGetCover, [$oAuthor->getContentId(), [
  744. 'use_as_author' => true,
  745. 'show_text' => false
  746. ]]);
  747. }
  748. public function serviceGetBlockAiAgent($iId = 0, $mixedContextPid = false, $bRequirePost = false)
  749. {
  750. $bIsApi = bx_is_api();
  751. $aAgent = BxDolAiQuery::getAgentObject($iId);
  752. if(!$aAgent || !is_array($aAgent))
  753. return $bIsApi ? [] : '';
  754. $oAi = BxDolAi::getInstance();
  755. $oChat = BxDolAiChat::getInstance();
  756. $bRequirePost = (bool)$bRequirePost;
  757. if ($mixedContextPid === false || $mixedContextPid === null || $mixedContextPid === '')
  758. $iContextPid = $oAi ? (int)$oChat->resolveChatHistoryContextPidFromPage($bRequirePost) : 0;
  759. else
  760. $iContextPid = $oAi ? $oChat->filterContextPid((int)$mixedContextPid, $bRequirePost) : 0;
  761. if ($bIsApi)
  762. return [bx_api_get_block('ai_agent', [
  763. 'agent_id' => $iId,
  764. 'agent_profile' => BxDolProfile::getData($aAgent['profile_id']),
  765. 'context_profile_id' => $iContextPid,
  766. 'hidden_first_message' => (string)($aAgent['hidden_first_message'] ?? ''),
  767. ])];
  768. $sEndpoint = BX_DOL_URL_ROOT . 'sys-ai-chat/' . (int)$iId;
  769. if ($iContextPid > 0)
  770. $sEndpoint .= '&context=' . $iContextPid;
  771. $oTemplate = BxDolTemplate::getInstance();
  772. $oTemplate->addJs([BX_DOL_URL_ROOT . 'plugins_public/bundle.js']);
  773. return $oTemplate->parseHtmlByName('agent_ai_chat.html', [
  774. 'id' => (int)$iId,
  775. 'context_profile_id' => (int)$iContextPid,
  776. 'endpoint_js' => json_encode($sEndpoint),
  777. 'bundle_url' => BX_DOL_URL_ROOT . 'plugins_public/bundle.js',
  778. ]);
  779. }
  780. public function serviceGetMenu($aParams)
  781. {
  782. $bIsApi = bx_is_api();
  783. $mixedResulEmpty = $bIsApi ? [] : '';
  784. if($bIsApi && is_string($aParams))
  785. $aParams = bx_api_get_browse_params($aParams);
  786. if(!isset($aParams['object']))
  787. return $mixedResulEmpty;
  788. $oMenu = BxDolMenu::getObjectInstance($aParams['object']);
  789. if(!$oMenu)
  790. return $mixedResulEmpty;
  791. if(!empty($aParams['params']) && is_array($aParams['params']))
  792. $oMenu->setContentParams($aParams['params']);
  793. return $bIsApi ? $oMenu->getCodeAPI() : $oMenu->getCode();
  794. }
  795. /**
  796. * @page service Service Calls
  797. * @section bx_system_general System Services
  798. * @subsection bx_system_general-general General
  799. * @subsubsection bx_system_general-get_site_submenu get_site_submenu
  800. *
  801. * @code bx_srv('system', 'get_site_submenu', [], 'TemplServices'); @endcode
  802. * @code {{~system:get_site_submenu:TemplServices[]~}} @endcode
  803. *
  804. * Get Site Submenu code.
  805. * @see BxBaseServices::serviceGetSiteSubmenu
  806. */
  807. /**
  808. * @ref bx_system_general-get_site_submenu "get_site_submenu"
  809. */
  810. public function serviceGetSiteSubmenu()
  811. {
  812. $oMenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  813. return $oMenu ? $oMenu->getCode() : '';
  814. }
  815. /**
  816. * @page service Service Calls
  817. * @section bx_system_general System Services
  818. * @subsection bx_system_general-general General
  819. * @subsubsection bx_system_general-get_products_names get_products_names
  820. *
  821. * @code bx_srv('system', 'get_products_names', [], 'TemplServices');
  822. *
  823. * @code http://example.com/m/oauth2/com/get_products_names?module=system&class=BaseServices @endcode
  824. * @code http://hihi.una.io/modules/?r=oauth2/com/get_products_names&module=system&class=BaseServices @endcode
  825. *
  826. * Get an array of products names from all modules with payments functionality.
  827. * @param $iVendorId filter products by vendor ID.
  828. * @param $iLimit limit number of records from one module.
  829. * @return array of products where key id product name and value is module name
  830. *
  831. * @see BxBaseServices::serviceGetProductsNames
  832. */
  833. /**
  834. * @ref bx_system_general-get_products_names "get_products_names"
  835. */
  836. public function serviceGetProductsNames($iVendorId = 0, $iLimit = 1000)
  837. {
  838. $o = BxDolPayments::getInstance();
  839. if (!$o)
  840. return array();
  841. return $o->getProductsNames($iVendorId, $iLimit);
  842. }
  843. /**
  844. * @see iBxDolProfileService::serviceCheckSpacePrivacy
  845. */
  846. public function serviceCheckSpacePrivacy($iContentId)
  847. {
  848. return _t('_Access denied');
  849. }
  850. public function serviceFormsHelper ()
  851. {
  852. return new BxTemplAccountForms();
  853. }
  854. public function serviceActAsProfile ()
  855. {
  856. return false;
  857. }
  858. public function serviceGetModerators($iContentId)
  859. {
  860. $aModerators = BxDolAclQuery::getInstance()->getProfilesByMembership([
  861. MEMBERSHIP_ID_MODERATOR,
  862. MEMBERSHIP_ID_ADMINISTRATOR
  863. ]);
  864. $aIds = [];
  865. array_walk($aModerators, function ($aItem, $iKey, $aParams) {
  866. if(!empty($aItem['id']))
  867. $aParams[0][] = (int)$aItem['id'];
  868. }, [&$aIds]);
  869. return $aIds;
  870. }
  871. public function servicePrepareFields ($aFieldsProfile)
  872. {
  873. return $aFieldsProfile;
  874. }
  875. public function serviceProfilesSearch ($sTerm, $iLimit)
  876. {
  877. $oDb = BxDolAccountQuery::getInstance();
  878. $aRet = array();
  879. $a = $oDb->searchByTerm($sTerm, $iLimit);
  880. foreach ($a as $r)
  881. $aRet[] = array ('label' => $this->serviceProfileName($r['content_id']), 'value' => $r['profile_id']);
  882. return $aRet;
  883. }
  884. /**
  885. * @page service Service Calls
  886. * @section bx_system_general System Services
  887. * @subsection bx_system_general-general General
  888. * @subsubsection bx_system_general-keyword_search keyword_search
  889. *
  890. * @code bx_srv('system', 'keyword_search', ["bx_posts", ["keyword" => "test"}], 'TemplServices'); @endcode
  891. *
  892. * @code {{~system:keyword_search:TemplServices["bx_posts", {"keyword":"test"}]~}} @endcode
  893. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country", "keyword": "AU"}, "unit.html"]~}} @endcode
  894. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_state", "state":"NSW", "keyword": "AU"}, "unit.html"]~}} @endcode
  895. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"}, "unit.html"]~}} @endcode
  896. * @code {{~system:keyword_search:TemplServices["bx_posts", {"meta_type": "mention", "keyword": 2}, "unit_gallery.html"]~}} @endcode
  897. * @code {{~system:keyword_search:TemplServices["bx_posts", {"cat": "bx_posts_cats", "keyword": 3}, "unit_gallery.html"]~}} @endcode
  898. *
  899. * Search by keyword
  900. * @param $sSection - search object to search in, usually module name, for example: bx_posts
  901. * @param $aCondition - condition for search, supported conditions:
  902. * - search by keyword: ["keyword" => "test"]
  903. * - search by country: ["meta_type" => "location_country", "keyword" => "AU"]
  904. * - search by country and state: ["meta_type": "location_country_state", "state":"NSW", "keyword": "AU"]
  905. * - search by country, state and city: ["meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"]
  906. * - search for mentions: ["meta_type" => "mention", "keyword" => 2]
  907. * - search in category: ["cat": "bx_posts_cats", "keyword": 3]
  908. * @param $sTemplate - template for displaying search results, for example: unit.html
  909. * @param $iStart - paginate, display records starting from this number
  910. * @param $iPerPage - paginate, display this number of records per page
  911. * @param $bLiveSearch - search results like in live search
  912. *
  913. * @see BxBaseServices::serviceKeywordSearch
  914. */
  915. /**
  916. * @ref bx_system_general-keyword_search "keyword_search"
  917. */
  918. public function serviceKeywordSearch ($sSection, $aCondition, $sTemplate = '', $iStart = 0, $iPerPage = 0, $bLiveSearch = 0, $bPaginate = false)
  919. {
  920. if (!$sSection || !isset($aCondition['keyword']))
  921. return '';
  922. $sClass = 'BxTemplSearch';
  923. $sElsName = 'bx_elasticsearch';
  924. $sElsMethod = 'is_configured';
  925. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod)) {
  926. $oModule = BxDolModule::getInstance($sElsName);
  927. bx_import('Search', $oModule->_aModule);
  928. $sClass = 'BxElsSearch';
  929. }
  930. $oSearch = new $sClass(array($sSection));
  931. $oSearch->setLiveSearch($bLiveSearch);
  932. $oSearch->setMetaType(isset($aCondition['meta_type']) ? $aCondition['meta_type'] : '');
  933. $oSearch->setCategoryObject(isset($aCondition['cat']) ? $aCondition['cat'] : '');
  934. $oSearch->setCustomSearchCondition($aCondition);
  935. if (!$bPaginate)
  936. $oSearch->setRawProcessing(true);
  937. $oSearch->setCustomCurrentCondition(array(
  938. 'paginate' => array (
  939. 'start' => $iStart,
  940. 'perPage' => $iPerPage ? $iPerPage : BX_DOL_SEARCH_RESULTS_PER_PAGE_DEFAULT,
  941. )));
  942. if ($sTemplate)
  943. $oSearch->setUnitTemplate($sTemplate);
  944. return $oSearch->response();
  945. }
  946. /**
  947. * @page service Service Calls
  948. * @section bx_system_general System Services
  949. * @subsection bx_system_general-general General
  950. * @subsubsection bx_system_general-keyword_search keyword_search
  951. *
  952. * @code bx_srv('system', 'search_keyword_form', 'TemplServices'); @endcode
  953. *
  954. * Block with Search by Keywords Form
  955. *
  956. * @see BxBaseServices::serviceSearchKeywordForm
  957. */
  958. /**
  959. * @ref bx_system_general-keyword_search "keyword_search"
  960. */
  961. public function serviceSearchKeywordForm ()
  962. {
  963. return $this->_getSearchObject()->getForm(BX_DB_PADDING_DEF, false, true);
  964. }
  965. /**
  966. * @page service Service Calls
  967. * @section bx_system_general System Services
  968. * @subsection bx_system_general-general General
  969. * @subsubsection bx_system_general-keyword_search keyword_search
  970. *
  971. * @code bx_srv('system', 'search_keyword_result', 'TemplServices'); @endcode
  972. *
  973. * Block with Search by Keywords Results
  974. *
  975. * @see BxBaseServices::serviceSearchKeywordResult
  976. */
  977. /**
  978. * @ref bx_system_general-keyword_search "keyword_search"
  979. */
  980. public function serviceSearchKeywordResult ()
  981. {
  982. $sType = bx_process_input(bx_get('type'));
  983. $sKeyword = bx_process_input(bx_get('keyword'));
  984. $bKeyword = $sKeyword !== false;
  985. if(bx_is_api())
  986. return $this->serviceGetDataSearchApi(['params' => [
  987. 'type' => $sType,
  988. 'keyword' => $sKeyword,
  989. 'section' => bx_process_input(bx_get('section')),
  990. 'cat' => bx_process_input(bx_get('cat'))
  991. ]]);
  992. $sCode = '';
  993. if($bKeyword) {
  994. $oSearch = $this->_getSearchObject();
  995. if(($sCode = $oSearch->response()))
  996. $sCode = BxDolTemplate::getInstance()->parseHtmlByName('search_result_block.html', [
  997. 'html_id' => 'bx-search-results-keyword',
  998. 'class' => 'bx-search-results-container',
  999. 'attrs' => '',
  1000. 'content' => $sCode,
  1001. 'bx_if:do_center' => [
  1002. 'condition' => false,
  1003. 'content' => [
  1004. 'html_id' => '',
  1005. 'selector_content' => ''
  1006. ]
  1007. ]
  1008. ]);
  1009. else
  1010. $sCode = $oSearch->getEmptyResult();
  1011. }
  1012. return $sCode;
  1013. }
  1014. /**
  1015. * @ref bx_system_general-get_date_search_api "get_date_search_api"
  1016. * @api @ref bx_system_general-get_date_search_api "get_date_search_api"
  1017. */
  1018. public function serviceGetDataSearchApi ($aParams)
  1019. {
  1020. if(!bx_is_api())
  1021. return false;
  1022. if(is_string($aParams))
  1023. $aParams = bx_api_get_browse_params($aParams);
  1024. $bForceAll = ($aParams['params']['type'] ?? '') == 'keyword';
  1025. $aSectionsAvail = explode(',', getParam('sys_api_search_sections'));
  1026. $aSectionsAll = BxDolDb::getInstance()->fromCache(
  1027. 'sys_global_search_pairs',
  1028. 'getPairs',
  1029. 'SELECT `ObjectName` AS `name`, `Title` AS `title` FROM `sys_objects_search` WHERE `GlobalSearch`=\'1\' ORDER BY `Order` ASC',
  1030. 'name', 'title'
  1031. );
  1032. $aSections = [];
  1033. foreach($aSectionsAll as $sSectionName => $sSectionTitle)
  1034. if(in_array($sSectionName, $aSectionsAvail) || $bForceAll)
  1035. $aSections[$sSectionName] = [
  1036. 'name' => $sSectionName,
  1037. 'title' => _t($sSectionTitle)
  1038. ];
  1039. $aParamsBrowse = array_merge([
  1040. 'keyword' => '',
  1041. 'section' => '',
  1042. 'sections' => array_values($aSections),
  1043. 'start' => 0,
  1044. 'per_page' => 12
  1045. ], !empty($aParams['params']) && is_array($aParams['params']) ? $aParams['params'] : []);
  1046. if(empty($aParamsBrowse['section']))
  1047. $aParamsBrowse['section'] = array_keys($aSections);
  1048. else if(is_string($aParamsBrowse['section']))
  1049. $aParamsBrowse['section'] = explode(',', $aParamsBrowse['section']);
  1050. $sClass = 'BxTemplSearch';
  1051. $sSections = $aParamsBrowse['section'];
  1052. if ($aParamsBrowse['live'] !== true && count($sSections) > 1){
  1053. $aParamsBrowse['section'] = [];
  1054. $aParamsBrowse['sections'] = [];
  1055. $aDataRv = [];
  1056. foreach ($sSections as $sSection) {
  1057. $oSearch = new $sClass($sSection);
  1058. $oSearch->setLiveSearch(true);
  1059. $oSearch->setDataProcessing(true);
  1060. $oSearch->setCustomSearchCondition(['keyword' => $aParamsBrowse['keyword']]);
  1061. $oSearch->setCustomCurrentCondition([
  1062. 'paginate' => [
  1063. 'forceStart' => $aParamsBrowse['start'],
  1064. 'perPage' => $aParamsBrowse['per_page'],
  1065. ]
  1066. ]);
  1067. $aData = $oSearch->response();
  1068. if(count($aData) > $aParamsBrowse['per_page'])
  1069. $aData = array_slice($aData, $aParamsBrowse['start'], $aParamsBrowse['per_page']);
  1070. if (count($aData) > 0) {
  1071. $oSearchResult = $oSearch->getSearchResultObject($sSection);
  1072. $sSectionTitle = $oSearchResult->aCurrent['title'];
  1073. $aParamsBrowse['section'][] = $sSection;
  1074. $aParamsBrowse['sections'][] = ['name' => $sSection, 'title' => $sSectionTitle];
  1075. $aDataRv[] = [
  1076. 'section' => $sSection,
  1077. 'section_name' => $sSectionTitle,
  1078. 'data' => $aData,
  1079. 'is_profile' => bx_srv('system', 'is_module_profile', [$oSearchResult->aCurrent['module_name']])
  1080. ];
  1081. }
  1082. }
  1083. return [bx_api_get_block('search_sections', [
  1084. 'data' => $aDataRv,
  1085. 'params' => $aParamsBrowse
  1086. ])];
  1087. }
  1088. else{
  1089. $oSearch = new $sClass($aParamsBrowse['section']);
  1090. $oSearch->setLiveSearch(true);
  1091. $oSearch->setDataProcessing(true);
  1092. $oSearch->setCustomSearchCondition(['keyword' => $aParamsBrowse['keyword']]);
  1093. $oSearch->setCustomCurrentCondition([
  1094. 'paginate' => [
  1095. 'forceStart' => $aParamsBrowse['start'],
  1096. 'perPage' => $aParamsBrowse['per_page'],
  1097. ]
  1098. ]);
  1099. $aData = $oSearch->response();
  1100. if(count($aData) > $aParamsBrowse['per_page'])
  1101. $aData = array_slice($aData, $aParamsBrowse['start'], $aParamsBrowse['per_page']);
  1102. return [
  1103. bx_api_get_block('browse', [
  1104. 'unit' => 'search-results',
  1105. 'request_url' => '/api.php?r=system/get_data_search_api/TemplServices&params[]=',
  1106. 'params' => $aParamsBrowse,
  1107. 'data' => $aData
  1108. ])
  1109. ];
  1110. }
  1111. }
  1112. /**
  1113. * @page service Service Calls
  1114. * @section bx_system_general System Services
  1115. * @subsection bx_system_general-general General
  1116. * @subsubsection bx_system_general-cmts cmts
  1117. *
  1118. * @code bx_srv('system', 'cmts', ["sys_blocks", 1], 'TemplServices'); @endcode
  1119. *
  1120. * @code {{~system:cmts:TemplServices["sys_blocks", 1]~}} @endcode
  1121. *
  1122. * Comments block
  1123. * @param $sObject - comments object name
  1124. * @param $sId - content id assiciated tith the comments
  1125. *
  1126. * @see BxBaseServices::serviceCmts
  1127. */
  1128. /**
  1129. * @ref bx_system_general-cmts "cmts"
  1130. */
  1131. public function serviceCmts ($sObject, $sId)
  1132. {
  1133. $o = BxDolCmts::getObjectInstance($sObject, $sId);
  1134. if (!$o || !$o->isEnabled())
  1135. return '';
  1136. return $o->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
  1137. }
  1138. public function _serviceProfileFunc ($sFunc, $iContentId, $aParams = array())
  1139. {
  1140. if (!$iContentId)
  1141. return false;
  1142. if (!($oAccount = BxDolAccount::getInstance($iContentId)))
  1143. return false;
  1144. return $oAccount->$sFunc(false, $aParams);
  1145. }
  1146. public function serviceAlertResponseProcessInstalled()
  1147. {
  1148. BxDolTranscoderImage::registerHandlersSystem();
  1149. }
  1150. public function serviceAlertResponseProcessStorageChange ($oAlert)
  1151. {
  1152. if ('sys_storage_default' != $oAlert->aExtras['option'])
  1153. return;
  1154. $aStorages = BxDolStorageQuery::getStorageObjects();
  1155. foreach ($aStorages as $r) {
  1156. if (0 == $r['current_size'] && 0 == $r['current_number'] && ($oStorage = BxDolStorage::getObjectInstance($r['object'])))
  1157. $oStorage->changeStorageEngine($oAlert->aExtras['value']);
  1158. }
  1159. }
  1160. public function serviceGetOptionsProfileBot()
  1161. {
  1162. $aResult = array(
  1163. array('key' => '', 'value' => _t('_Select_one'))
  1164. );
  1165. $aAccountsIds = BxDolAccountQuery::getInstance()->getOperators();
  1166. foreach($aAccountsIds as $iAccountId) {
  1167. $aProfilesIds = BxDolAccount::getInstance($iAccountId)->getProfilesIds(true, false);
  1168. foreach($aProfilesIds as $iProfileId) {
  1169. $oProfile = BxDolProfile::getInstance($iProfileId);
  1170. $aResult[] = array(
  1171. 'key' => $iProfileId,
  1172. 'value' => _t('_sys_profile_with_type', $oProfile->getDisplayName(), $oProfile->getModule()),
  1173. );
  1174. }
  1175. }
  1176. return $aResult;
  1177. }
  1178. public function serviceGetOptionsModuleListForPrivacySelector()
  1179. {
  1180. $aResult = array();
  1181. $BxDolModuleQuery = BxDolModuleQuery::getInstance();
  1182. $aModules = $BxDolModuleQuery->getModulesBy(array('type' => 'modules', 'active' => 1));
  1183. foreach($aModules as $aModule){
  1184. $oModule = BxDolModule::getInstance($aModule['name']);
  1185. if($oModule instanceof iBxDolContentInfoService){
  1186. if (!BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  1187. continue;
  1188. $aResult[$aModule['name']] = $aModule['title'];
  1189. }
  1190. }
  1191. return $aResult;
  1192. }
  1193. public function serviceGetOptionsCaptchaDefault()
  1194. {
  1195. $aResults = [];
  1196. $aObjects = BxDolCaptchaQuery::getObjects();
  1197. foreach($aObjects as $aObject)
  1198. $aResults[$aObject['object']] = $aObject['title'];
  1199. return $aResults;
  1200. }
  1201. public function serviceGetOptionsEmbedDefault()
  1202. {
  1203. $aResults = array(
  1204. '' => _t('_None')
  1205. );
  1206. $aObjects = BxDolEmbedQuery::getObjects();
  1207. foreach($aObjects as $aObject)
  1208. $aResults[$aObject['object']] = _t($aObject['title']);
  1209. return $aResults;
  1210. }
  1211. public function serviceGetOptionsLocationFieldDefault()
  1212. {
  1213. $aResults = array();
  1214. $aObjects = BxDolLocationFieldQuery::getObjects();
  1215. foreach($aObjects as $aObject)
  1216. $aResults[$aObject['object']] = _t($aObject['title']);
  1217. return $aResults;
  1218. }
  1219. public function serviceGetOptionsLocationMapDefault()
  1220. {
  1221. $aResults = array();
  1222. $aObjects = BxDolLocationMapQuery::getObjects();
  1223. foreach($aObjects as $aObject)
  1224. $aResults[$aObject['object']] = _t($aObject['title']);
  1225. return $aResults;
  1226. }
  1227. public function serviceGetOptionsPushDefault()
  1228. {
  1229. $aResults = [
  1230. '' => _t('_None')
  1231. ];
  1232. $aObjects = BxDolPushQuery::getObjects();
  1233. foreach($aObjects as $aObject)
  1234. $aResults[$aObject['object']] = $aObject['title'];
  1235. return $aResults;
  1236. }
  1237. public function serviceGetOptionsSmsDefault()
  1238. {
  1239. $aResults = [
  1240. '' => _t('_None')
  1241. ];
  1242. $aObjects = BxDolSmsQuery::getObjects();
  1243. foreach($aObjects as $aObject)
  1244. $aResults[$aObject['object']] = $aObject['title'];
  1245. return $aResults;
  1246. }
  1247. public function serviceGetOptionsSocketsFieldDefault()
  1248. {
  1249. $aResults = [];
  1250. $aObjects = ['sys_sockets_disabled', 'sys_sockets_soketi'];
  1251. foreach($aObjects as $sObject)
  1252. $aResults[$sObject] = _t('_adm_stg_cpt_option_sys_sockets_type_' . $sObject);
  1253. return $aResults;
  1254. }
  1255. public function serviceGetOptionsLocationLeafletGetProviders()
  1256. {
  1257. return BxDolLocationMapLeaflet::getProviders();
  1258. }
  1259. public function serviceGetOptionsRelations()
  1260. {
  1261. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
  1262. $aProfiles = array();
  1263. foreach($aModules as $aModule) {
  1264. $sMethod = 'act_as_profile';
  1265. if(!BxDolRequest::serviceExists($aModule['name'], $sMethod) || !BxDolService::call($aModule['name'], $sMethod))
  1266. continue;
  1267. $aProfiles[$aModule['name']] = _t('_' . $aModule['name']);
  1268. }
  1269. $aResults = array();
  1270. foreach($aProfiles as $sName1 => $sTitle1)
  1271. foreach($aProfiles as $sName2 => $sTitle2)
  1272. $aResults[$sName1 . '_' . $sName2] = $sTitle1 . ' - ' . $sTitle2;
  1273. return $aResults;
  1274. }
  1275. public function serviceGetOptionsCfProhibited()
  1276. {
  1277. return BxDolFormQuery::getDataItems('sys_content_filter');
  1278. }
  1279. public function serviceGetOptionsCfUnauthenticated()
  1280. {
  1281. return BxDolFormQuery::getDataItems('sys_content_filter');
  1282. }
  1283. public function serviceGetOptionsTaiwindDefault()
  1284. {
  1285. $sPath = BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'tailwind/css';
  1286. $aExcludes = ['.', '..', 'tailwind.css'];
  1287. $aResults = [];
  1288. if(($oHandle = opendir($sPath)) !== false) {
  1289. while(($sFile = readdir($oHandle)) !== false) {
  1290. if(in_array($sFile, $aExcludes))
  1291. continue;
  1292. if(($oHandlerFile = fopen($sPath . '/' . $sFile, 'r')) === false)
  1293. continue;
  1294. if(($sContent = fread($oHandlerFile, 1024)) !== false && strpos($sContent, '@tailwind base') === false)
  1295. $aResults[$sFile] = $sFile;
  1296. fclose($oHandlerFile);
  1297. }
  1298. closedir($oHandle);
  1299. }
  1300. /**
  1301. * Disabled for now, because CDN and custom compiled build with own styles
  1302. * don't work correctly together.
  1303. *
  1304. * $aResults['cdn'] = _t('_adm_stg_cpt_option_sys_css_tailwind_default_cdn');
  1305. */
  1306. return $aResults;
  1307. }
  1308. public function serviceGetOptionsIconsetDefault()
  1309. {
  1310. $aObjects = BxDolIconsetQuery::getObjects();
  1311. foreach($aObjects as $aObject)
  1312. $aResults[$aObject['object']] = $aObject['title'];
  1313. return $aResults;
  1314. }
  1315. public function serviceGetOptionsApiRootPageGuest()
  1316. {
  1317. $sKey = '_adm_stg_cpt_option_sys_api_root_page_';
  1318. return [
  1319. 'home' => _t($sKey .'home'),
  1320. 'splash' => _t($sKey . 'splash')
  1321. ];
  1322. }
  1323. public function serviceGetOptionsApiRootPageMember()
  1324. {
  1325. $sKey = '_adm_stg_cpt_option_sys_api_root_page_';
  1326. return [
  1327. 'home' => _t($sKey .'home'),
  1328. 'dashboard' => _t($sKey . 'dashboard'),
  1329. 'profile' => _t($sKey . 'profile')
  1330. ];
  1331. }
  1332. public function serviceGetOptionsApiMenuTop()
  1333. {
  1334. $aMenus = BxDolMenuQuery::getMenuObjects();
  1335. $aResults = ['' => _t('_sys_please_select')];
  1336. foreach($aMenus as $aMenu)
  1337. if($aMenu['module'] == 'system')
  1338. $aResults[$aMenu['object']] = _t($aMenu['title']);
  1339. return $aResults;
  1340. }
  1341. public function serviceGetOptionsApiContextSwitcher()
  1342. {
  1343. $aContexts = bx_srv('system', 'get_modules_by_type', ['context']);
  1344. $aResults = ['' => _t('_None')];
  1345. foreach($aContexts as $aContext)
  1346. $aResults[$aContext['name']] = _t('_' . $aContext['name']);
  1347. return $aResults;
  1348. }
  1349. public function serviceGetOptionsApiContextConnection()
  1350. {
  1351. $aConnections = ['subscriptions', 'fans', 'participants'];
  1352. $aResults = ['' => _t('_sys_please_select')];
  1353. foreach($aConnections as $sConnection)
  1354. $aResults[$sConnection] = _t('_adm_stg_cpt_option_sys_api_cnt_cnn_' . $sConnection);
  1355. return $aResults;
  1356. }
  1357. public function serviceGetOptionsAgentsModel()
  1358. {
  1359. return ['' => _t('_Select_one')] + BxDolAi::getInstance()->getModels(['active' => true]);
  1360. }
  1361. public function serviceGetOptionsAgentsProfile($bSelectOne = true, $sSelectOneLangKey = '_Select_one')
  1362. {
  1363. $aResult = [];
  1364. if($bSelectOne)
  1365. $aResult[] = ['key' => '', 'value' => _t($sSelectOneLangKey)];
  1366. $aAccountsIds = BxDolAccountQuery::getInstance()->getOperators();
  1367. foreach($aAccountsIds as $iAccountId) {
  1368. $aProfilesIds = BxDolAccount::getInstance($iAccountId)->getProfilesIds(true, false);
  1369. foreach($aProfilesIds as $iProfileId) {
  1370. $oProfile = BxDolProfile::getInstance($iProfileId);
  1371. $sProfileModule = false === $oProfile ? '' : $oProfile->getModule();
  1372. if ($sProfileModule && ($sProfileModule != 'system' || ($sProfileModule == 'system' && empty($oProfile->getAccountObject()->getEmail())))) {
  1373. $aResult[] = [
  1374. 'key' => $iProfileId,
  1375. 'value' => _t('_sys_profile_with_type', $oProfile->getDisplayName(), $sProfileModule === 'system' ? 'System' : _t('_' . $sProfileModule))
  1376. ];
  1377. }
  1378. }
  1379. }
  1380. return $aResult;
  1381. }
  1382. public function serviceRedirect($sUrl = false)
  1383. {
  1384. if (!getParam('sys_confirmation_before_redirect')) {
  1385. BxDolTemplate::getInstance()->displayPageNotFound();
  1386. exit;
  1387. }
  1388. if (false === $sUrl)
  1389. $sUrl = bx_get('url');
  1390. if (!$sUrl || !preg_match('@^https?://@', $sUrl)) {
  1391. http_response_code(500);
  1392. return MsgBox(_t('_error occured'));
  1393. }
  1394. else {
  1395. $bSpam = null;
  1396. /**
  1397. * @hooks
  1398. * @hookdef hook-system-check_spam_url 'system', 'check_spam_url' - hook to override sClass for search
  1399. * - $unit_name - equals `system`
  1400. * - $action - equals `check_spam_url`
  1401. * - $object_id - not used
  1402. * - $sender_id - logged account id
  1403. * - $extra_params - array of additional params with the following array keys:
  1404. * - `is_spam` - [bool] by ref, spam url or not, can be overridden in hook processing
  1405. * - `content` - [string] by ref, url of link, can be overridden in hook processing
  1406. * - `where` - [string] equal redirect
  1407. * @hook @ref hook-system-check_spam_url
  1408. */
  1409. bx_alert('system', 'check_spam_url', 0, getLoggedId(), array(
  1410. 'is_spam' => &$bSpam,
  1411. 'content' => &$sUrl,
  1412. 'is_spam_ref' => &$bSpam,
  1413. 'content_ref' => &$sUrl,
  1414. 'where' => 'redirect'
  1415. ));
  1416. $sLangKey = $bSpam ? '_sys_redirect_confirmation_harmful' : '_sys_redirect_confirmation';
  1417. return BxDolTemplate::getInstance()->parseHtmlByName('redirect.html', [
  1418. 'text' => _t($sLangKey, bx_process_output($sUrl), getParam('site_title')),
  1419. 'url' => bx_js_string($sUrl, BX_ESCAPE_STR_APOS),
  1420. ]);
  1421. }
  1422. }
  1423. public function serviceSetBadges($iContentId, $sBadgesIds, $sModule)
  1424. {
  1425. $aSelectedBadges = explode(",", $sBadgesIds);
  1426. $iPerformerId = bx_get_logged_profile_id();
  1427. $aCheck = checkActionModule($iPerformerId, 'set badge', 'system', false);
  1428. if(!isAdmin() && $aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1429. return false;
  1430. $oBadges = BxDolBadges::getInstance();
  1431. $oBadges->delete([
  1432. 'type' => 'by_module&object',
  1433. 'object_id' => $iContentId,
  1434. 'module' => $sModule
  1435. ]);
  1436. foreach ($aSelectedBadges as $iSelectedBadge)
  1437. $oBadges->add($iSelectedBadge, $iContentId, $sModule);
  1438. checkActionModule($iPerformerId, 'set badge', 'system', true);
  1439. return true;
  1440. }
  1441. public function serviceGetBadge($aBadge, $bIsCompact = false)
  1442. {
  1443. $sClass = '';
  1444. $sStyleFont = '';
  1445. $sStyleBg = '';
  1446. if ($aBadge['color'] == '')
  1447. $aBadge['color'] = 'purple-600';
  1448. if ($bIsCompact && $aBadge['icon'] != ''){
  1449. $aBadge['is_icon_only'] = 1;
  1450. }
  1451. if ($aBadge['is_icon_only'] == 1){
  1452. $sClass .= ' bx-badge-compact';
  1453. if (substr_count($aBadge['color'], 'rgb('))
  1454. $sStyleFont = 'color: ' . $aBadge['color'];
  1455. else
  1456. $sClass .= ' text-' . $aBadge['color'];
  1457. }
  1458. else{
  1459. if (substr_count($aBadge['color'], 'rgb('))
  1460. $sStyleBg = 'background-color: ' . $aBadge['color'];
  1461. else
  1462. $sClass .= ' bg-' . $aBadge['color'];
  1463. }
  1464. return BxDolTemplate::getInstance()->parseHtmlByName('badge.html', array(
  1465. 'bx_if:content' => array(
  1466. 'condition' => $aBadge['is_icon_only'] != '1',
  1467. 'content' => array('content' => _t($aBadge['text'])),
  1468. ),
  1469. 'bx_if:icon' => array(
  1470. 'condition' => $aBadge['icon'] != '',
  1471. 'content' => array('content' => BxDolTemplate::getInstance()->getIcon($aBadge['icon'], array('class' => 'bx-badge-icon sys-colored', 'style' => $sStyleFont))),
  1472. ),
  1473. 'title' => $aBadge['text'],
  1474. 'style_font' => $sStyleFont,
  1475. 'style_bg' => $sStyleBg,
  1476. 'class' => $sClass,
  1477. )
  1478. );
  1479. }
  1480. public function serviceGetFooter()
  1481. {
  1482. return BxDolTemplate::getInstance()->parseHtmlByName('footer.html', []);
  1483. }
  1484. private function _getSearchObject()
  1485. {
  1486. $sClass = 'BxTemplSearch';
  1487. $sElsName = 'bx_elasticsearch';
  1488. $sElsMethod = 'is_configured';
  1489. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod) && !bx_get('cat') && !bx_get('type')) {
  1490. $oModule = BxDolModule::getInstance($sElsName);
  1491. bx_import('Search', $oModule->_aModule);
  1492. $sClass = 'BxElsSearch';
  1493. }
  1494. /**
  1495. * @hooks
  1496. * @hookdef hook-system-search_keyword 'system', 'search_keyword' - hook to override sClass for search
  1497. * - $unit_name - equals `system`
  1498. * - $action - equals `search_keyword`
  1499. * - $object_id - not used
  1500. * - $sender_id - not used
  1501. * - $extra_params - array of additional params with the following array keys:
  1502. * - `override_result` - [string] by ref, class name for search, can be overridden in hook processing
  1503. * @hook @ref hook-system-search_keyword
  1504. */
  1505. bx_alert('system', 'search_keyword', 0, 0, array('class' => &$sClass, 'class_name_ref' => &$sClass));
  1506. $oSearch = new $sClass(bx_get('section'));
  1507. $oSearch->setLiveSearch(bx_get('live_search') ? 1 : 0);
  1508. $oSearch->setMetaType(bx_process_input(bx_get('type')));
  1509. $oSearch->setCategoryObject(bx_process_input(bx_get('cat')));
  1510. return $oSearch;
  1511. }
  1512. public function serviceHomeRedirect()
  1513. {
  1514. header("Location:" . BX_DOL_URL_ROOT, true, 301);
  1515. exit;
  1516. }
  1517. public function serviceProcessEmbed()
  1518. {
  1519. BxDolEmbed::getObjectInstance()->process();
  1520. }
  1521. public function serviceCallAgent($sType, $aAgent, $aParams)
  1522. {
  1523. $oAi = BxDolAi::getInstance();
  1524. return $oAi->callAgent($sType, $aAgent, $aParams);
  1525. }
  1526. public function serviceCallAgentForFormInput($iAgentId)
  1527. {
  1528. return BxDolAiTrigger::getInstance('form-input')->handle($iAgentId);
  1529. }
  1530. public function serviceAiChat($iAgentId)
  1531. {
  1532. return BxDolAiTrigger::getInstance('chat')->handle($iAgentId);
  1533. }
  1534. }
  1535. /** @} */