BxBaseServices.php 73 KB

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