BxBaseServices.php 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886
  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. $sJson = file_get_contents('php://input');
  1509. $aData = json_decode($sJson, true);
  1510. if (json_last_error() !== JSON_ERROR_NONE)
  1511. return echoJson(['code' => 500, 'msg' => _t('_sys_agents_json_field_err')]);
  1512. $sPrompt = $aData['prompt'] ?? null;
  1513. $sInputName = $aData['input_name'] ?? null;
  1514. $aValues = $aData['values'] ?? [];
  1515. $aAgent = BxDolAiQuery::getAgentObject($iAgentId);
  1516. if (!$aAgent || !$aAgent['active'] || $aAgent['trigger'] !== 'form-input')
  1517. return echoJson(['code' => 404, 'msg' => _t('_sys_agents_agent_not_found')]);
  1518. $oAi = BxDolAI::getInstance();
  1519. if (!$oAi || !$oAi->canInteract($aAgent))
  1520. return echoJson(['code' => 403, 'msg' => _t('_sys_agents_unauthorized')]);
  1521. $aParams = [
  1522. 'sender_profile_id' => bx_get_logged_profile_id(),
  1523. 'user_prompt' => $sPrompt,
  1524. 'form_field_name' => $sInputName,
  1525. 'form_values' => $aValues,
  1526. ];
  1527. $mixed = $oAi->callAgent('form-input', $aAgent, $aParams);
  1528. return echoJson(['code' => 200, 'msg' => $mixed]);
  1529. }
  1530. public function serviceAiChat($iAgentId)
  1531. {
  1532. $sMethod = $_SERVER['REQUEST_METHOD'] ?? '';
  1533. if ('GET' === $sMethod)
  1534. return $this->_aiChatHydrate($iAgentId);
  1535. if ('POST' !== $sMethod)
  1536. return echoJson(['code' => 405, 'msg' => _t('_error occured')]);
  1537. $aAgent = $this->_aiChatLoadAgent($iAgentId);
  1538. if (!$aAgent)
  1539. return;
  1540. $sJson = file_get_contents('php://input');
  1541. $aData = json_decode($sJson, true);
  1542. if (json_last_error() !== JSON_ERROR_NONE)
  1543. return echoJson(['code' => 400, 'msg' => _t('_sys_agents_json_field_err')]);
  1544. $oAi = BxDolAI::getInstance();
  1545. $sPrompt = $oAi->extractChatPromptFromRequest($aData);
  1546. if (!$sPrompt)
  1547. return echoJson(['code' => 400, 'msg' => _t('_sys_agents_json_field_err')]);
  1548. $oAi->streamAgentChat($aAgent['id'], $sPrompt, [
  1549. 'sender_profile_id' => bx_get_logged_profile_id(),
  1550. ], $aData['threadId'] ?? null);
  1551. }
  1552. /**
  1553. * GET hydrate for TanStack `useChat({ persistence: true })`.
  1554. * Same route as the SSE POST; join/resume (`?offset=`) is not supported.
  1555. */
  1556. protected function _aiChatHydrate($iAgentId)
  1557. {
  1558. if (false !== bx_get('offset'))
  1559. return echoJson(['code' => 405, 'msg' => _t('_error occured')]);
  1560. $aAgent = $this->_aiChatLoadAgent($iAgentId);
  1561. if (!$aAgent)
  1562. return;
  1563. $oAi = BxDolAI::getInstance();
  1564. return echoJson([
  1565. 'messages' => $oAi->getChatHistoryUiMessages($aAgent['id'], [
  1566. 'sender_profile_id' => bx_get_logged_profile_id(),
  1567. ]),
  1568. 'activeRun' => null,
  1569. 'interrupts' => null,
  1570. ]);
  1571. }
  1572. protected function _aiChatLoadAgent($iAgentId)
  1573. {
  1574. $iAgentId = (int)$iAgentId;
  1575. if (!$iAgentId) {
  1576. echoJson(['code' => 400, 'msg' => _t('_sys_agents_agent_not_found')]);
  1577. return false;
  1578. }
  1579. $aAgent = BxDolAiQuery::getAgentObject($iAgentId);
  1580. if (!$aAgent || !$aAgent['active']) {
  1581. echoJson(['code' => 404, 'msg' => _t('_sys_agents_agent_not_found')]);
  1582. return false;
  1583. }
  1584. $oAi = BxDolAI::getInstance();
  1585. if (!$oAi) {
  1586. echoJson(['code' => 503, 'msg' => _t('_sys_agents_exception')]);
  1587. return false;
  1588. }
  1589. if (!$oAi->canChatDirectly($aAgent)) {
  1590. echoJson(['code' => 403, 'msg' => _t('_sys_agents_unauthorized')]);
  1591. return false;
  1592. }
  1593. return $aAgent;
  1594. }
  1595. protected function _getOptionsAiAssistants()
  1596. {
  1597. $aResult = ['' => _t('_Select_one')];
  1598. $aAgents = BxDolAI::getInstance()->getAgentsByTriggerType('manual');
  1599. if($aAgents && is_array($aAgents))
  1600. foreach($aAgents as $aAgent)
  1601. $aResult[$aAgent['id']] = $aAgent['title'];
  1602. return $aResult;
  1603. }
  1604. }
  1605. /** @} */