BxBaseServices.php 74 KB

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