BxBaseServices.php 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876
  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 serviceGetBlockAuthor($sModule, $iContentId = 0)
  718. {
  719. if(!$iContentId && bx_get('id') !== false)
  720. $iContentId = (int)bx_get('id');
  721. $sMethodGetAuthor = 'get_author';
  722. if(!$sModule || !$iContentId || !BxDolRequest::serviceExists($sModule, $sMethodGetAuthor))
  723. return '';
  724. $iAuthor = bx_srv($sModule, $sMethodGetAuthor, [$iContentId]);
  725. if(!$iAuthor)
  726. return '';
  727. $oAuthor = BxDolProfile::getInstance($iAuthor);
  728. if(!$oAuthor)
  729. return '';
  730. $sModuleAuthor = $oAuthor->getModule();
  731. $sMethodGetCover = 'entity_cover';
  732. if(!BxDolRequest::serviceExists($sModuleAuthor, $sMethodGetCover))
  733. return '';
  734. return bx_srv($sModuleAuthor, $sMethodGetCover, [$oAuthor->getContentId(), [
  735. 'use_as_author' => true,
  736. 'show_text' => false
  737. ]]);
  738. }
  739. public function serviceGetBlockAskAssistant($aParams = [])
  740. {
  741. $iAssistant = BxDolAI::getAssistantForAskBlock();
  742. if(!$iAssistant)
  743. return '';
  744. return BxDolAIAssistant::getObjectInstance($iAssistant)->getAskBlock($aParams);
  745. }
  746. public function serviceGetMenu($aParams)
  747. {
  748. $bIsApi = bx_is_api();
  749. $mixedResulEmpty = $bIsApi ? [] : '';
  750. if($bIsApi && is_string($aParams))
  751. $aParams = bx_api_get_browse_params($aParams);
  752. if(!isset($aParams['object']))
  753. return $mixedResulEmpty;
  754. $oMenu = BxDolMenu::getObjectInstance($aParams['object']);
  755. if(!$oMenu)
  756. return $mixedResulEmpty;
  757. if(!empty($aParams['params']) && is_array($aParams['params']))
  758. $oMenu->setContentParams($aParams['params']);
  759. return $bIsApi ? $oMenu->getCodeAPI() : $oMenu->getCode();
  760. }
  761. /**
  762. * @page service Service Calls
  763. * @section bx_system_general System Services
  764. * @subsection bx_system_general-general General
  765. * @subsubsection bx_system_general-get_site_submenu get_site_submenu
  766. *
  767. * @code bx_srv('system', 'get_site_submenu', [], 'TemplServices'); @endcode
  768. * @code {{~system:get_site_submenu:TemplServices[]~}} @endcode
  769. *
  770. * Get Site Submenu code.
  771. * @see BxBaseServices::serviceGetSiteSubmenu
  772. */
  773. /**
  774. * @ref bx_system_general-get_site_submenu "get_site_submenu"
  775. */
  776. public function serviceGetSiteSubmenu()
  777. {
  778. $oMenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  779. return $oMenu ? $oMenu->getCode() : '';
  780. }
  781. /**
  782. * @page service Service Calls
  783. * @section bx_system_general System Services
  784. * @subsection bx_system_general-general General
  785. * @subsubsection bx_system_general-get_products_names get_products_names
  786. *
  787. * @code bx_srv('system', 'get_products_names', [], 'TemplServices');
  788. *
  789. * @code http://example.com/m/oauth2/com/get_products_names?module=system&class=BaseServices @endcode
  790. * @code http://hihi.una.io/modules/?r=oauth2/com/get_products_names&module=system&class=BaseServices @endcode
  791. *
  792. * Get an array of products names from all modules with payments functionality.
  793. * @param $iVendorId filter products by vendor ID.
  794. * @param $iLimit limit number of records from one module.
  795. * @return array of products where key id product name and value is module name
  796. *
  797. * @see BxBaseServices::serviceGetProductsNames
  798. */
  799. /**
  800. * @ref bx_system_general-get_products_names "get_products_names"
  801. */
  802. public function serviceGetProductsNames($iVendorId = 0, $iLimit = 1000)
  803. {
  804. $o = BxDolPayments::getInstance();
  805. if (!$o)
  806. return array();
  807. return $o->getProductsNames($iVendorId, $iLimit);
  808. }
  809. /**
  810. * @see iBxDolProfileService::serviceCheckSpacePrivacy
  811. */
  812. public function serviceCheckSpacePrivacy($iContentId)
  813. {
  814. return _t('_Access denied');
  815. }
  816. public function serviceFormsHelper ()
  817. {
  818. return new BxTemplAccountForms();
  819. }
  820. public function serviceActAsProfile ()
  821. {
  822. return false;
  823. }
  824. public function serviceGetModerators($iContentId)
  825. {
  826. $aModerators = BxDolAclQuery::getInstance()->getProfilesByMembership([
  827. MEMBERSHIP_ID_MODERATOR,
  828. MEMBERSHIP_ID_ADMINISTRATOR
  829. ]);
  830. $aIds = [];
  831. array_walk($aModerators, function ($aItem, $iKey, $aParams) {
  832. if(!empty($aItem['id']))
  833. $aParams[0][] = (int)$aItem['id'];
  834. }, [&$aIds]);
  835. return $aIds;
  836. }
  837. public function servicePrepareFields ($aFieldsProfile)
  838. {
  839. return $aFieldsProfile;
  840. }
  841. public function serviceProfilesSearch ($sTerm, $iLimit)
  842. {
  843. $oDb = BxDolAccountQuery::getInstance();
  844. $aRet = array();
  845. $a = $oDb->searchByTerm($sTerm, $iLimit);
  846. foreach ($a as $r)
  847. $aRet[] = array ('label' => $this->serviceProfileName($r['content_id']), 'value' => $r['profile_id']);
  848. return $aRet;
  849. }
  850. /**
  851. * @page service Service Calls
  852. * @section bx_system_general System Services
  853. * @subsection bx_system_general-general General
  854. * @subsubsection bx_system_general-keyword_search keyword_search
  855. *
  856. * @code bx_srv('system', 'keyword_search', ["bx_posts", ["keyword" => "test"}], 'TemplServices'); @endcode
  857. *
  858. * @code {{~system:keyword_search:TemplServices["bx_posts", {"keyword":"test"}]~}} @endcode
  859. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country", "keyword": "AU"}, "unit.html"]~}} @endcode
  860. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_state", "state":"NSW", "keyword": "AU"}, "unit.html"]~}} @endcode
  861. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"}, "unit.html"]~}} @endcode
  862. * @code {{~system:keyword_search:TemplServices["bx_posts", {"meta_type": "mention", "keyword": 2}, "unit_gallery.html"]~}} @endcode
  863. * @code {{~system:keyword_search:TemplServices["bx_posts", {"cat": "bx_posts_cats", "keyword": 3}, "unit_gallery.html"]~}} @endcode
  864. *
  865. * Search by keyword
  866. * @param $sSection - search object to search in, usually module name, for example: bx_posts
  867. * @param $aCondition - condition for search, supported conditions:
  868. * - search by keyword: ["keyword" => "test"]
  869. * - search by country: ["meta_type" => "location_country", "keyword" => "AU"]
  870. * - search by country and state: ["meta_type": "location_country_state", "state":"NSW", "keyword": "AU"]
  871. * - search by country, state and city: ["meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"]
  872. * - search for mentions: ["meta_type" => "mention", "keyword" => 2]
  873. * - search in category: ["cat": "bx_posts_cats", "keyword": 3]
  874. * @param $sTemplate - template for displaying search results, for example: unit.html
  875. * @param $iStart - paginate, display records starting from this number
  876. * @param $iPerPage - paginate, display this number of records per page
  877. * @param $bLiveSearch - search results like in live search
  878. *
  879. * @see BxBaseServices::serviceKeywordSearch
  880. */
  881. /**
  882. * @ref bx_system_general-keyword_search "keyword_search"
  883. */
  884. public function serviceKeywordSearch ($sSection, $aCondition, $sTemplate = '', $iStart = 0, $iPerPage = 0, $bLiveSearch = 0, $bPaginate = false)
  885. {
  886. if (!$sSection || !isset($aCondition['keyword']))
  887. return '';
  888. $sClass = 'BxTemplSearch';
  889. $sElsName = 'bx_elasticsearch';
  890. $sElsMethod = 'is_configured';
  891. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod)) {
  892. $oModule = BxDolModule::getInstance($sElsName);
  893. bx_import('Search', $oModule->_aModule);
  894. $sClass = 'BxElsSearch';
  895. }
  896. $oSearch = new $sClass(array($sSection));
  897. $oSearch->setLiveSearch($bLiveSearch);
  898. $oSearch->setMetaType(isset($aCondition['meta_type']) ? $aCondition['meta_type'] : '');
  899. $oSearch->setCategoryObject(isset($aCondition['cat']) ? $aCondition['cat'] : '');
  900. $oSearch->setCustomSearchCondition($aCondition);
  901. if (!$bPaginate)
  902. $oSearch->setRawProcessing(true);
  903. $oSearch->setCustomCurrentCondition(array(
  904. 'paginate' => array (
  905. 'start' => $iStart,
  906. 'perPage' => $iPerPage ? $iPerPage : BX_DOL_SEARCH_RESULTS_PER_PAGE_DEFAULT,
  907. )));
  908. if ($sTemplate)
  909. $oSearch->setUnitTemplate($sTemplate);
  910. return $oSearch->response();
  911. }
  912. /**
  913. * @page service Service Calls
  914. * @section bx_system_general System Services
  915. * @subsection bx_system_general-general General
  916. * @subsubsection bx_system_general-keyword_search keyword_search
  917. *
  918. * @code bx_srv('system', 'search_keyword_form', 'TemplServices'); @endcode
  919. *
  920. * Block with Search by Keywords Form
  921. *
  922. * @see BxBaseServices::serviceSearchKeywordForm
  923. */
  924. /**
  925. * @ref bx_system_general-keyword_search "keyword_search"
  926. */
  927. public function serviceSearchKeywordForm ()
  928. {
  929. return $this->_getSearchObject()->getForm(BX_DB_PADDING_DEF, false, true);
  930. }
  931. /**
  932. * @page service Service Calls
  933. * @section bx_system_general System Services
  934. * @subsection bx_system_general-general General
  935. * @subsubsection bx_system_general-keyword_search keyword_search
  936. *
  937. * @code bx_srv('system', 'search_keyword_result', 'TemplServices'); @endcode
  938. *
  939. * Block with Search by Keywords Results
  940. *
  941. * @see BxBaseServices::serviceSearchKeywordResult
  942. */
  943. /**
  944. * @ref bx_system_general-keyword_search "keyword_search"
  945. */
  946. public function serviceSearchKeywordResult ()
  947. {
  948. $sType = bx_process_input(bx_get('type'));
  949. $sKeyword = bx_process_input(bx_get('keyword'));
  950. $bKeyword = $sKeyword !== false;
  951. if(bx_is_api())
  952. return $this->serviceGetDataSearchApi(['params' => [
  953. 'type' => $sType,
  954. 'keyword' => $sKeyword,
  955. 'section' => bx_process_input(bx_get('section')),
  956. 'cat' => bx_process_input(bx_get('cat'))
  957. ]]);
  958. $sCode = '';
  959. if($bKeyword) {
  960. $oSearch = $this->_getSearchObject();
  961. if(($sCode = $oSearch->response()))
  962. $sCode = BxDolTemplate::getInstance()->parseHtmlByName('search_result_block.html', [
  963. 'html_id' => 'bx-search-results-keyword',
  964. 'class' => 'bx-search-results-container',
  965. 'attrs' => '',
  966. 'content' => $sCode,
  967. 'bx_if:do_center' => [
  968. 'condition' => false,
  969. 'content' => [
  970. 'html_id' => '',
  971. 'selector_content' => ''
  972. ]
  973. ]
  974. ]);
  975. else
  976. $sCode = $oSearch->getEmptyResult();
  977. }
  978. return $sCode;
  979. }
  980. /**
  981. * @ref bx_system_general-get_date_search_api "get_date_search_api"
  982. * @api @ref bx_system_general-get_date_search_api "get_date_search_api"
  983. */
  984. public function serviceGetDataSearchApi ($aParams)
  985. {
  986. if(!bx_is_api())
  987. return false;
  988. if(is_string($aParams))
  989. $aParams = bx_api_get_browse_params($aParams);
  990. $bForceAll = ($aParams['params']['type'] ?? '') == 'keyword';
  991. $aSectionsAvail = explode(',', getParam('sys_api_search_sections'));
  992. $aSectionsAll = BxDolDb::getInstance()->fromCache(
  993. 'sys_global_search_pairs',
  994. 'getPairs',
  995. 'SELECT `ObjectName` AS `name`, `Title` AS `title` FROM `sys_objects_search` WHERE `GlobalSearch`=\'1\' ORDER BY `Order` ASC',
  996. 'name', 'title'
  997. );
  998. $aSections = [];
  999. foreach($aSectionsAll as $sSectionName => $sSectionTitle)
  1000. if(in_array($sSectionName, $aSectionsAvail) || $bForceAll)
  1001. $aSections[$sSectionName] = [
  1002. 'name' => $sSectionName,
  1003. 'title' => _t($sSectionTitle)
  1004. ];
  1005. $aParamsBrowse = array_merge([
  1006. 'keyword' => '',
  1007. 'section' => '',
  1008. 'sections' => array_values($aSections),
  1009. 'start' => 0,
  1010. 'per_page' => 12
  1011. ], !empty($aParams['params']) && is_array($aParams['params']) ? $aParams['params'] : []);
  1012. if(empty($aParamsBrowse['section']))
  1013. $aParamsBrowse['section'] = array_keys($aSections);
  1014. else if(is_string($aParamsBrowse['section']))
  1015. $aParamsBrowse['section'] = explode(',', $aParamsBrowse['section']);
  1016. $sClass = 'BxTemplSearch';
  1017. $sSections = $aParamsBrowse['section'];
  1018. if ($aParamsBrowse['live'] !== true && count($sSections) > 1){
  1019. $aParamsBrowse['section'] = [];
  1020. $aParamsBrowse['sections'] = [];
  1021. $aDataRv = [];
  1022. foreach ($sSections as $sSection) {
  1023. $oSearch = new $sClass($sSection);
  1024. $oSearch->setLiveSearch(true);
  1025. $oSearch->setDataProcessing(true);
  1026. $oSearch->setCustomSearchCondition(['keyword' => $aParamsBrowse['keyword']]);
  1027. $oSearch->setCustomCurrentCondition([
  1028. 'paginate' => [
  1029. 'forceStart' => $aParamsBrowse['start'],
  1030. 'perPage' => $aParamsBrowse['per_page'],
  1031. ]
  1032. ]);
  1033. $aData = $oSearch->response();
  1034. if(count($aData) > $aParamsBrowse['per_page'])
  1035. $aData = array_slice($aData, $aParamsBrowse['start'], $aParamsBrowse['per_page']);
  1036. if (count($aData) > 0) {
  1037. $oSearchResult = $oSearch->getSearchResultObject($sSection);
  1038. $sSectionTitle = $oSearchResult->aCurrent['title'];
  1039. $aParamsBrowse['section'][] = $sSection;
  1040. $aParamsBrowse['sections'][] = ['name' => $sSection, 'title' => $sSectionTitle];
  1041. $aDataRv[] = [
  1042. 'section' => $sSection,
  1043. 'section_name' => $sSectionTitle,
  1044. 'data' => $aData,
  1045. 'is_profile' => bx_srv('system', 'is_module_profile', [$oSearchResult->aCurrent['module_name']])
  1046. ];
  1047. }
  1048. }
  1049. return [bx_api_get_block('search_sections', [
  1050. 'data' => $aDataRv,
  1051. 'params' => $aParamsBrowse
  1052. ])];
  1053. }
  1054. else{
  1055. $oSearch = new $sClass($aParamsBrowse['section']);
  1056. $oSearch->setLiveSearch(true);
  1057. $oSearch->setDataProcessing(true);
  1058. $oSearch->setCustomSearchCondition(['keyword' => $aParamsBrowse['keyword']]);
  1059. $oSearch->setCustomCurrentCondition([
  1060. 'paginate' => [
  1061. 'forceStart' => $aParamsBrowse['start'],
  1062. 'perPage' => $aParamsBrowse['per_page'],
  1063. ]
  1064. ]);
  1065. $aData = $oSearch->response();
  1066. if(count($aData) > $aParamsBrowse['per_page'])
  1067. $aData = array_slice($aData, $aParamsBrowse['start'], $aParamsBrowse['per_page']);
  1068. return [
  1069. bx_api_get_block('browse', [
  1070. 'unit' => 'search-results',
  1071. 'request_url' => '/api.php?r=system/get_data_search_api/TemplServices&params[]=',
  1072. 'params' => $aParamsBrowse,
  1073. 'data' => $aData
  1074. ])
  1075. ];
  1076. }
  1077. }
  1078. /**
  1079. * @page service Service Calls
  1080. * @section bx_system_general System Services
  1081. * @subsection bx_system_general-general General
  1082. * @subsubsection bx_system_general-cmts cmts
  1083. *
  1084. * @code bx_srv('system', 'cmts', ["sys_blocks", 1], 'TemplServices'); @endcode
  1085. *
  1086. * @code {{~system:cmts:TemplServices["sys_blocks", 1]~}} @endcode
  1087. *
  1088. * Comments block
  1089. * @param $sObject - comments object name
  1090. * @param $sId - content id assiciated tith the comments
  1091. *
  1092. * @see BxBaseServices::serviceCmts
  1093. */
  1094. /**
  1095. * @ref bx_system_general-cmts "cmts"
  1096. */
  1097. public function serviceCmts ($sObject, $sId)
  1098. {
  1099. $o = BxDolCmts::getObjectInstance($sObject, $sId);
  1100. if (!$o || !$o->isEnabled())
  1101. return '';
  1102. return $o->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
  1103. }
  1104. public function _serviceProfileFunc ($sFunc, $iContentId, $aParams = array())
  1105. {
  1106. if (!$iContentId)
  1107. return false;
  1108. if (!($oAccount = BxDolAccount::getInstance($iContentId)))
  1109. return false;
  1110. return $oAccount->$sFunc(false, $aParams);
  1111. }
  1112. public function serviceAlertResponseProcessInstalled()
  1113. {
  1114. BxDolTranscoderImage::registerHandlersSystem();
  1115. }
  1116. public function serviceAlertResponseProcessStorageChange ($oAlert)
  1117. {
  1118. if ('sys_storage_default' != $oAlert->aExtras['option'])
  1119. return;
  1120. $aStorages = BxDolStorageQuery::getStorageObjects();
  1121. foreach ($aStorages as $r) {
  1122. if (0 == $r['current_size'] && 0 == $r['current_number'] && ($oStorage = BxDolStorage::getObjectInstance($r['object'])))
  1123. $oStorage->changeStorageEngine($oAlert->aExtras['value']);
  1124. }
  1125. }
  1126. public function serviceGetOptionsProfileBot()
  1127. {
  1128. $aResult = array(
  1129. array('key' => '', 'value' => _t('_Select_one'))
  1130. );
  1131. $aAccountsIds = BxDolAccountQuery::getInstance()->getOperators();
  1132. foreach($aAccountsIds as $iAccountId) {
  1133. $aProfilesIds = BxDolAccount::getInstance($iAccountId)->getProfilesIds(true, false);
  1134. foreach($aProfilesIds as $iProfileId) {
  1135. $oProfile = BxDolProfile::getInstance($iProfileId);
  1136. $aResult[] = array(
  1137. 'key' => $iProfileId,
  1138. 'value' => _t('_sys_profile_with_type', $oProfile->getDisplayName(), $oProfile->getModule()),
  1139. );
  1140. }
  1141. }
  1142. return $aResult;
  1143. }
  1144. public function serviceGetOptionsModuleListForPrivacySelector()
  1145. {
  1146. $aResult = array();
  1147. $BxDolModuleQuery = BxDolModuleQuery::getInstance();
  1148. $aModules = $BxDolModuleQuery->getModulesBy(array('type' => 'modules', 'active' => 1));
  1149. foreach($aModules as $aModule){
  1150. $oModule = BxDolModule::getInstance($aModule['name']);
  1151. if($oModule instanceof iBxDolContentInfoService){
  1152. if (!BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  1153. continue;
  1154. $aResult[$aModule['name']] = $aModule['title'];
  1155. }
  1156. }
  1157. return $aResult;
  1158. }
  1159. public function serviceGetOptionsCaptchaDefault()
  1160. {
  1161. $aResults = [];
  1162. $aObjects = BxDolCaptchaQuery::getObjects();
  1163. foreach($aObjects as $aObject)
  1164. $aResults[$aObject['object']] = $aObject['title'];
  1165. return $aResults;
  1166. }
  1167. public function serviceGetOptionsEmbedDefault()
  1168. {
  1169. $aResults = array(
  1170. '' => _t('_None')
  1171. );
  1172. $aObjects = BxDolEmbedQuery::getObjects();
  1173. foreach($aObjects as $aObject)
  1174. $aResults[$aObject['object']] = _t($aObject['title']);
  1175. return $aResults;
  1176. }
  1177. public function serviceGetOptionsLocationFieldDefault()
  1178. {
  1179. $aResults = array();
  1180. $aObjects = BxDolLocationFieldQuery::getObjects();
  1181. foreach($aObjects as $aObject)
  1182. $aResults[$aObject['object']] = _t($aObject['title']);
  1183. return $aResults;
  1184. }
  1185. public function serviceGetOptionsLocationMapDefault()
  1186. {
  1187. $aResults = array();
  1188. $aObjects = BxDolLocationMapQuery::getObjects();
  1189. foreach($aObjects as $aObject)
  1190. $aResults[$aObject['object']] = _t($aObject['title']);
  1191. return $aResults;
  1192. }
  1193. public function serviceGetOptionsPushDefault()
  1194. {
  1195. $aResults = [
  1196. '' => _t('_None')
  1197. ];
  1198. $aObjects = BxDolPushQuery::getObjects();
  1199. foreach($aObjects as $aObject)
  1200. $aResults[$aObject['object']] = $aObject['title'];
  1201. return $aResults;
  1202. }
  1203. public function serviceGetOptionsSmsDefault()
  1204. {
  1205. $aResults = [
  1206. '' => _t('_None')
  1207. ];
  1208. $aObjects = BxDolSmsQuery::getObjects();
  1209. foreach($aObjects as $aObject)
  1210. $aResults[$aObject['object']] = $aObject['title'];
  1211. return $aResults;
  1212. }
  1213. public function serviceGetOptionsSocketsFieldDefault()
  1214. {
  1215. $aResults = [];
  1216. $aObjects = ['sys_sockets_disabled', 'sys_sockets_soketi'];
  1217. foreach($aObjects as $sObject)
  1218. $aResults[$sObject] = _t('_adm_stg_cpt_option_sys_sockets_type_' . $sObject);
  1219. return $aResults;
  1220. }
  1221. public function serviceGetOptionsLocationLeafletGetProviders()
  1222. {
  1223. return BxDolLocationMapLeaflet::getProviders();
  1224. }
  1225. public function serviceGetOptionsRelations()
  1226. {
  1227. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
  1228. $aProfiles = array();
  1229. foreach($aModules as $aModule) {
  1230. $sMethod = 'act_as_profile';
  1231. if(!BxDolRequest::serviceExists($aModule['name'], $sMethod) || !BxDolService::call($aModule['name'], $sMethod))
  1232. continue;
  1233. $aProfiles[$aModule['name']] = _t('_' . $aModule['name']);
  1234. }
  1235. $aResults = array();
  1236. foreach($aProfiles as $sName1 => $sTitle1)
  1237. foreach($aProfiles as $sName2 => $sTitle2)
  1238. $aResults[$sName1 . '_' . $sName2] = $sTitle1 . ' - ' . $sTitle2;
  1239. return $aResults;
  1240. }
  1241. public function serviceGetOptionsCfProhibited()
  1242. {
  1243. return BxDolFormQuery::getDataItems('sys_content_filter');
  1244. }
  1245. public function serviceGetOptionsCfUnauthenticated()
  1246. {
  1247. return BxDolFormQuery::getDataItems('sys_content_filter');
  1248. }
  1249. public function serviceGetOptionsTaiwindDefault()
  1250. {
  1251. $sPath = BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'tailwind/css';
  1252. $aExcludes = ['.', '..', 'tailwind.css'];
  1253. $aResults = [];
  1254. if(($oHandle = opendir($sPath)) !== false) {
  1255. while(($sFile = readdir($oHandle)) !== false) {
  1256. if(in_array($sFile, $aExcludes))
  1257. continue;
  1258. if(($oHandlerFile = fopen($sPath . '/' . $sFile, 'r')) === false)
  1259. continue;
  1260. if(($sContent = fread($oHandlerFile, 1024)) !== false && strpos($sContent, '@tailwind base') === false)
  1261. $aResults[$sFile] = $sFile;
  1262. fclose($oHandlerFile);
  1263. }
  1264. closedir($oHandle);
  1265. }
  1266. /**
  1267. * Disabled for now, because CDN and custom compiled build with own styles
  1268. * don't work correctly together.
  1269. *
  1270. * $aResults['cdn'] = _t('_adm_stg_cpt_option_sys_css_tailwind_default_cdn');
  1271. */
  1272. return $aResults;
  1273. }
  1274. public function serviceGetOptionsIconsetDefault()
  1275. {
  1276. $aObjects = BxDolIconsetQuery::getObjects();
  1277. foreach($aObjects as $aObject)
  1278. $aResults[$aObject['object']] = $aObject['title'];
  1279. return $aResults;
  1280. }
  1281. public function serviceGetOptionsApiRootPageGuest()
  1282. {
  1283. $sKey = '_adm_stg_cpt_option_sys_api_root_page_';
  1284. return [
  1285. 'home' => _t($sKey .'home'),
  1286. 'splash' => _t($sKey . 'splash')
  1287. ];
  1288. }
  1289. public function serviceGetOptionsApiRootPageMember()
  1290. {
  1291. $sKey = '_adm_stg_cpt_option_sys_api_root_page_';
  1292. return [
  1293. 'home' => _t($sKey .'home'),
  1294. 'dashboard' => _t($sKey . 'dashboard'),
  1295. 'profile' => _t($sKey . 'profile')
  1296. ];
  1297. }
  1298. public function serviceGetOptionsApiMenuTop()
  1299. {
  1300. $aMenus = BxDolMenuQuery::getMenuObjects();
  1301. $aResults = ['' => _t('_sys_please_select')];
  1302. foreach($aMenus as $aMenu)
  1303. if($aMenu['module'] == 'system')
  1304. $aResults[$aMenu['object']] = _t($aMenu['title']);
  1305. return $aResults;
  1306. }
  1307. public function serviceGetOptionsApiContextSwitcher()
  1308. {
  1309. $aContexts = bx_srv('system', 'get_modules_by_type', ['context']);
  1310. $aResults = ['' => _t('_None')];
  1311. foreach($aContexts as $aContext)
  1312. $aResults[$aContext['name']] = _t('_' . $aContext['name']);
  1313. return $aResults;
  1314. }
  1315. public function serviceGetOptionsApiContextConnection()
  1316. {
  1317. $aConnections = ['subscriptions', 'fans', 'participants'];
  1318. $aResults = ['' => _t('_sys_please_select')];
  1319. foreach($aConnections as $sConnection)
  1320. $aResults[$sConnection] = _t('_adm_stg_cpt_option_sys_api_cnt_cnn_' . $sConnection);
  1321. return $aResults;
  1322. }
  1323. public function serviceGetOptionsAgentsModel()
  1324. {
  1325. return ['' => _t('_Select_one')] + BxDolAI::getInstance()->getModels(['active' => true, 'hidden' => false]);
  1326. }
  1327. public function serviceGetOptionsAgentsProfile($bSelectOne = true, $sSelectOneLangKey = '_Select_one')
  1328. {
  1329. $aResult = [];
  1330. if($bSelectOne)
  1331. $aResult[] = ['key' => '', 'value' => _t($sSelectOneLangKey)];
  1332. $aAccountsIds = BxDolAccountQuery::getInstance()->getOperators();
  1333. foreach($aAccountsIds as $iAccountId) {
  1334. $aProfilesIds = BxDolAccount::getInstance($iAccountId)->getProfilesIds(true, false);
  1335. foreach($aProfilesIds as $iProfileId) {
  1336. $oProfile = BxDolProfile::getInstance($iProfileId);
  1337. $sProfileModule = false === $oProfile ? '' : $oProfile->getModule();
  1338. if ($sProfileModule && ($sProfileModule != 'system' || ($sProfileModule == 'system' && empty($oProfile->getAccountObject()->getEmail())))) {
  1339. $aResult[] = [
  1340. 'key' => $iProfileId,
  1341. 'value' => _t('_sys_profile_with_type', $oProfile->getDisplayName(), $sProfileModule === 'system' ? 'System' : _t('_' . $sProfileModule))
  1342. ];
  1343. }
  1344. }
  1345. }
  1346. return $aResult;
  1347. }
  1348. public function serviceGetOptionsStudioAssistant()
  1349. {
  1350. return $this->_getOptionsAiAssistants();
  1351. }
  1352. public function serviceGetOptionsLiveSearchAssistant()
  1353. {
  1354. return $this->_getOptionsAiAssistants();
  1355. }
  1356. public function serviceGetOptionsAskBlockAssistant()
  1357. {
  1358. return $this->_getOptionsAiAssistants();
  1359. }
  1360. public function serviceRedirect($sUrl = false)
  1361. {
  1362. if (!getParam('sys_confirmation_before_redirect')) {
  1363. BxDolTemplate::getInstance()->displayPageNotFound();
  1364. exit;
  1365. }
  1366. if (false === $sUrl)
  1367. $sUrl = bx_get('url');
  1368. if (!$sUrl || !preg_match('@^https?://@', $sUrl)) {
  1369. http_response_code(500);
  1370. return MsgBox(_t('_error occured'));
  1371. }
  1372. else {
  1373. $bSpam = null;
  1374. /**
  1375. * @hooks
  1376. * @hookdef hook-system-check_spam_url 'system', 'check_spam_url' - hook to override sClass for search
  1377. * - $unit_name - equals `system`
  1378. * - $action - equals `check_spam_url`
  1379. * - $object_id - not used
  1380. * - $sender_id - logged account id
  1381. * - $extra_params - array of additional params with the following array keys:
  1382. * - `is_spam` - [bool] by ref, spam url or not, can be overridden in hook processing
  1383. * - `content` - [string] by ref, url of link, can be overridden in hook processing
  1384. * - `where` - [string] equal redirect
  1385. * @hook @ref hook-system-check_spam_url
  1386. */
  1387. bx_alert('system', 'check_spam_url', 0, getLoggedId(), array(
  1388. 'is_spam' => &$bSpam,
  1389. 'content' => &$sUrl,
  1390. 'is_spam_ref' => &$bSpam,
  1391. 'content_ref' => &$sUrl,
  1392. 'where' => 'redirect'
  1393. ));
  1394. $sLangKey = $bSpam ? '_sys_redirect_confirmation_harmful' : '_sys_redirect_confirmation';
  1395. return BxDolTemplate::getInstance()->parseHtmlByName('redirect.html', [
  1396. 'text' => _t($sLangKey, bx_process_output($sUrl), getParam('site_title')),
  1397. 'url' => bx_js_string($sUrl, BX_ESCAPE_STR_APOS),
  1398. ]);
  1399. }
  1400. }
  1401. public function serviceSetBadges($iContentId, $sBadgesIds, $sModule)
  1402. {
  1403. $aSelectedBadges = explode(",", $sBadgesIds);
  1404. $iPerformerId = bx_get_logged_profile_id();
  1405. $aCheck = checkActionModule($iPerformerId, 'set badge', 'system', false);
  1406. if(!isAdmin() && $aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1407. return false;
  1408. $oBadges = BxDolBadges::getInstance();
  1409. $aBadges = $oBadges->getData(array('type' => 'by_module&object', 'object_id' => $iContentId, 'module' => $sModule));
  1410. foreach ($aBadges as $aBadge) {
  1411. if (isset($aBadge['badge_id'])){
  1412. $oBadges->delete($aBadge['badge_id']);
  1413. }
  1414. }
  1415. foreach ($aSelectedBadges as $iSelectedBadge) {
  1416. $oBadges->add($iSelectedBadge, $iContentId, $sModule);
  1417. }
  1418. checkActionModule($iPerformerId, 'set badge', 'system', true); // perform action
  1419. return true;
  1420. }
  1421. public function serviceGetBadge($aBadge, $bIsCompact = false)
  1422. {
  1423. $sClass = '';
  1424. $sStyleFont = '';
  1425. $sStyleBg = '';
  1426. if ($aBadge['color'] == '')
  1427. $aBadge['color'] = 'purple-600';
  1428. if ($bIsCompact && $aBadge['icon'] != ''){
  1429. $aBadge['is_icon_only'] = 1;
  1430. }
  1431. if ($aBadge['is_icon_only'] == 1){
  1432. $sClass .= ' bx-badge-compact';
  1433. if (substr_count($aBadge['color'], 'rgb('))
  1434. $sStyleFont = 'color: ' . $aBadge['color'];
  1435. else
  1436. $sClass .= ' text-' . $aBadge['color'];
  1437. }
  1438. else{
  1439. if (substr_count($aBadge['color'], 'rgb('))
  1440. $sStyleBg = 'background-color: ' . $aBadge['color'];
  1441. else
  1442. $sClass .= ' bg-' . $aBadge['color'];
  1443. }
  1444. return BxDolTemplate::getInstance()->parseHtmlByName('badge.html', array(
  1445. 'bx_if:content' => array(
  1446. 'condition' => $aBadge['is_icon_only'] != '1',
  1447. 'content' => array('content' => _t($aBadge['text'])),
  1448. ),
  1449. 'bx_if:icon' => array(
  1450. 'condition' => $aBadge['icon'] != '',
  1451. 'content' => array('content' => BxDolTemplate::getInstance()->getIcon($aBadge['icon'], array('class' => 'bx-badge-icon sys-colored', 'style' => $sStyleFont))),
  1452. ),
  1453. 'title' => $aBadge['text'],
  1454. 'style_font' => $sStyleFont,
  1455. 'style_bg' => $sStyleBg,
  1456. 'class' => $sClass,
  1457. )
  1458. );
  1459. }
  1460. public function serviceGetFooter()
  1461. {
  1462. return BxDolTemplate::getInstance()->parseHtmlByName('footer.html', []);
  1463. }
  1464. private function _getSearchObject()
  1465. {
  1466. $sClass = 'BxTemplSearch';
  1467. $sElsName = 'bx_elasticsearch';
  1468. $sElsMethod = 'is_configured';
  1469. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod) && !bx_get('cat') && !bx_get('type')) {
  1470. $oModule = BxDolModule::getInstance($sElsName);
  1471. bx_import('Search', $oModule->_aModule);
  1472. $sClass = 'BxElsSearch';
  1473. }
  1474. /**
  1475. * @hooks
  1476. * @hookdef hook-system-search_keyword 'system', 'search_keyword' - hook to override sClass for search
  1477. * - $unit_name - equals `system`
  1478. * - $action - equals `search_keyword`
  1479. * - $object_id - not used
  1480. * - $sender_id - not used
  1481. * - $extra_params - array of additional params with the following array keys:
  1482. * - `override_result` - [string] by ref, class name for search, can be overridden in hook processing
  1483. * @hook @ref hook-system-search_keyword
  1484. */
  1485. bx_alert('system', 'search_keyword', 0, 0, array('class' => &$sClass, 'class_name_ref' => &$sClass));
  1486. $oSearch = new $sClass(bx_get('section'));
  1487. $oSearch->setLiveSearch(bx_get('live_search') ? 1 : 0);
  1488. $oSearch->setMetaType(bx_process_input(bx_get('type')));
  1489. $oSearch->setCategoryObject(bx_process_input(bx_get('cat')));
  1490. return $oSearch;
  1491. }
  1492. public function serviceHomeRedirect()
  1493. {
  1494. header("Location:" . BX_DOL_URL_ROOT, true, 301);
  1495. exit;
  1496. }
  1497. public function serviceProcessEmbed()
  1498. {
  1499. BxDolEmbed::getObjectInstance()->process();
  1500. }
  1501. public function serviceCallAgent($sType, $aAgent, $aParams)
  1502. {
  1503. $oAi = BxDolAI::getInstance();
  1504. return $oAi->callAgent($sType, $aAgent, $aParams);
  1505. }
  1506. public function serviceCallAgentForFormInput($iAgentId)
  1507. {
  1508. if (!bx_get_logged_profile_id())
  1509. return echoJson(['code' => 403, 'msg' => _t('_sys_agents_unauthorized')]);
  1510. $sJson = file_get_contents('php://input');
  1511. $aData = json_decode($sJson, true);
  1512. if (json_last_error() !== JSON_ERROR_NONE)
  1513. return echoJson(['code' => 500, 'msg' => _t('_sys_agents_json_field_err')]);
  1514. $sPrompt = $aData['prompt'] ?? null;
  1515. $sInputName = $aData['input_name'] ?? null;
  1516. $aValues = $aData['values'] ?? [];
  1517. $aAgent = BxDolAiQuery::getAgentObject($iAgentId);
  1518. if (!$aAgent || !$aAgent['active'])
  1519. return echoJson(['code' => 404, 'msg' => _t('_sys_agents_agent_not_found')]);
  1520. $aParams = [
  1521. 'sender_profile_id' => bx_get_logged_profile_id(),
  1522. 'user_prompt' => $sPrompt,
  1523. 'form_field_name' => $sInputName,
  1524. 'form_values' => $aValues,
  1525. ];
  1526. $oAi = BxDolAI::getInstance();
  1527. $mixed = $oAi->callAgent('form-input', $aAgent, $aParams);
  1528. return echoJson(['code' => 200, 'msg' => $mixed]);
  1529. }
  1530. public function serviceAiChat($iAgentId)
  1531. {
  1532. // TODO: tmp
  1533. // if (!bx_get_logged_profile_id())
  1534. // return echoJson(['code' => 403, 'msg' => _t('_sys_agents_unauthorized')]);
  1535. $sMethod = $_SERVER['REQUEST_METHOD'] ?? '';
  1536. if ('GET' === $sMethod)
  1537. return $this->_aiChatHydrate($iAgentId);
  1538. if ('POST' !== $sMethod)
  1539. return echoJson(['code' => 405, 'msg' => _t('_error occured')]);
  1540. $iAgentId = (int)$iAgentId;
  1541. if (!$iAgentId)
  1542. return echoJson(['code' => 400, 'msg' => _t('_sys_agents_agent_not_found')]);
  1543. $aAgent = BxDolAiQuery::getAgentObject($iAgentId);
  1544. if (!$aAgent || !$aAgent['active'])
  1545. return echoJson(['code' => 404, 'msg' => _t('_sys_agents_agent_not_found')]);
  1546. $sJson = file_get_contents('php://input');
  1547. $aData = json_decode($sJson, true);
  1548. if (json_last_error() !== JSON_ERROR_NONE)
  1549. return echoJson(['code' => 400, 'msg' => _t('_sys_agents_json_field_err')]);
  1550. $oAi = BxDolAI::getInstance();
  1551. if (!$oAi)
  1552. return echoJson(['code' => 503, 'msg' => _t('_sys_agents_exception')]);
  1553. $sPrompt = $oAi->extractChatPromptFromRequest($aData);
  1554. if (!$sPrompt)
  1555. return echoJson(['code' => 400, 'msg' => _t('_sys_agents_json_field_err')]);
  1556. $oAi->streamAgentChat($iAgentId, $sPrompt, [
  1557. 'sender_profile_id' => bx_get_logged_profile_id(),
  1558. ], $aData['threadId'] ?? null);
  1559. }
  1560. /**
  1561. * GET hydrate for TanStack `useChat({ persistence: true })`.
  1562. * Same route as the SSE POST; join/resume (`?offset=`) is not supported.
  1563. */
  1564. protected function _aiChatHydrate($iAgentId)
  1565. {
  1566. if (false !== bx_get('offset'))
  1567. return echoJson(['code' => 405, 'msg' => _t('_error occured')]);
  1568. $iAgentId = (int)$iAgentId;
  1569. if (!$iAgentId)
  1570. return echoJson(['code' => 400, 'msg' => _t('_sys_agents_agent_not_found')]);
  1571. $aAgent = BxDolAiQuery::getAgentObject($iAgentId);
  1572. if (!$aAgent || !$aAgent['active'])
  1573. return echoJson(['code' => 404, 'msg' => _t('_sys_agents_agent_not_found')]);
  1574. $oAi = BxDolAI::getInstance();
  1575. if (!$oAi)
  1576. return echoJson(['code' => 503, 'msg' => _t('_sys_agents_exception')]);
  1577. return echoJson([
  1578. 'messages' => $oAi->getChatHistoryUiMessages($iAgentId, [
  1579. 'sender_profile_id' => bx_get_logged_profile_id(),
  1580. ]),
  1581. 'activeRun' => null,
  1582. 'interrupts' => null,
  1583. ]);
  1584. }
  1585. protected function _getOptionsAiAssistants()
  1586. {
  1587. $aResult = ['' => _t('_Select_one')];
  1588. $aAgents = BxDolAI::getInstance()->getAgentsByTriggerType('manual');
  1589. if($aAgents && is_array($aAgents))
  1590. foreach($aAgents as $aAgent)
  1591. $aResult[$aAgent['id']] = $aAgent['title'];
  1592. return $aResult;
  1593. }
  1594. }
  1595. /** @} */