| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup UnaBaseView UNA Base Representation Classes
- * @{
- */
- /**
- * System services.
- */
- class BxBaseServices extends BxDol implements iBxDolProfileService
- {
- public function __construct()
- {
- parent::__construct();
- }
- public function serviceIsPublicService($s)
- {
- $sService = bx_gen_method_name($s);
- $aServices = $this->serviceGetPublicServices();
- return isset($aServices[$sService]);
- }
- public function serviceGetPublicServices()
- {
- return array (
- 'GetProductsNames' => 'BxBaseServices',
- 'GetPageByRequest' => 'BxBaseServicePages',
- );
- }
- public function serviceIsSafeService($s)
- {
- $sService = bx_gen_method_name($s);
- $aSafeServices = $this->serviceGetSafeServices();
- return isset($aSafeServices[$sService]);
- }
- public function serviceGetSafeServices()
- {
- return array(
- 'GetMenu' => 'BxBaseServices',
- 'GetCreatePostForm' => 'BxBaseServices',
- 'GetProductsNames' => 'BxBaseServices',
- 'KeywordSearch' => 'BxBaseServices',
- 'GetDataSearchApi' => 'BxBaseServices',
- 'Cmts' => 'BxBaseServices',
- 'GetFooter' => 'BxBaseServices',
- 'SetBadges' => 'BxBaseServices',
- 'GetPageContentByRequest' => 'BxBaseServicePages',
- 'GetPageBlockData' => 'BxBaseServicePages',
- 'SetPageBlockData' => 'BxBaseServicePages',
- 'GetPageBlockImageData' => 'BxBaseServicePages',
- 'GetUrlInfo' => 'BxBaseServicePages',
- 'CreateAccountForm' => 'BxBaseServiceAccount',
- 'AccountSettingsEmail' => 'BxBaseServiceAccount',
- 'AccountSettingsPassword' => 'BxBaseServiceAccount',
- 'AccountSettingsDelAccount' => 'BxBaseServiceAccount',
- 'AccountSettingsInfo' => 'BxBaseServiceAccount',
- 'ForgotPassword' => 'BxBaseServiceAccount',
- 'SwitchProfile' => 'BxBaseServiceAccount',
- 'AccountProfileSwitcher' => 'BxBaseServiceAccount',
- 'EmailConfirmation' => 'BxBaseServiceAccount',
- 'ConfirmEmail' => 'BxBaseServiceAccount',
-
- 'CategoriesList' => 'BxBaseServiceCategory',
- 'Test' => 'BxBaseServiceLogin',
- 'MemberAuthCode' => 'BxBaseServiceLogin',
- 'LoginForm' => 'BxBaseServiceLogin',
- 'LoginFormOnly' => 'BxBaseServiceLogin',
- 'Logout' => 'BxBaseServiceLogin',
-
- 'KeywordsCloud' => 'BxBaseServiceMetatags',
- 'AccountProfileSwitcher' => 'BxBaseServiceProfiles',
- 'ProfileMembership' => 'BxBaseServiceProfiles',
- 'ProfileNotifications' => 'BxBaseServiceProfiles',
- 'GetCountOnlineProfiles' => 'BxBaseServiceProfiles',
- 'BrowseRecommendationsFriends' => 'BxBaseServiceProfiles',
- 'BrowseRecommendationsSubscriptions' => 'BxBaseServiceProfiles',
- 'BrowseFriends' => 'BxBaseServiceProfiles',
- 'SetMembership' => 'BxBaseServiceProfiles',
- 'ResetMembership' => 'BxBaseServiceProfiles',
- 'BrowseFriendRequests' => 'BxBaseServiceProfiles',
- 'BrowseFriendRequested' => 'BxBaseServiceProfiles',
- 'BrowseSubscribedMe' => 'BxBaseServiceProfiles',
- 'BrowseSubscriptions' => 'BxBaseServiceProfiles',
- 'BrowseMembers' => 'BxBaseServiceProfiles',
- 'BrowseInvitations' => 'BxBaseServiceProfiles',
- 'UpdateSettings' => 'BxBaseServiceProfiles',
- 'Befriend' => 'BxBaseServiceProfiles',
- 'ProfileCounters' => 'BxBaseServiceProfiles',
- 'ProfileInfo' => 'BxBaseServiceProfiles',
-
- 'GetChartGrowth' => 'BxBaseChartServices',
- 'GetChartStats' => 'BxBaseChartServices',
- 'GetDataByInterval' => 'BxBaseChartServices',
-
- 'GetCartItemsCount' => 'BxBasePaymentsServices',
- 'GetOrdersCount' => 'BxBasePaymentsServices',
- 'Do' => 'BxBaseReportServices',
- 'GetPerformedBy' => 'BxBaseReportServices',
- 'Do' => 'BxBaseVoteServices',
- 'GetPerformedBy' => 'BxBaseVoteServices',
- 'Perform' => 'BxBaseFeatureServices',
-
- 'Perform' => 'BxBaseFavoriteServices',
- 'GetPerformedBy' => 'BxBaseFavoriteServices',
- 'Perform' => 'BxBaseServiceConnections',
- 'Perform' => 'BxBaseServiceRecommendations',
- 'GetDataApi' => 'BxBaseCmtsServices',
- 'GetDataApi' => 'BxBaseUploaderServices',
-
- 'GetStatBlock' => 'BxBaseDashboardServices',
-
- 'PerfomActionApi' => 'BxBaseServiceGrid',
- 'GetLabels' => 'BxBaseLabelsServices',
- 'GetForm' => 'BxBaseSearchExtendedServices',
- 'GetResults' => 'BxBaseSearchExtendedServices',
- 'WikiAction' => 'BxBaseServiceWiki',
- 'AiChat' => 'BxBaseServices',
- 'AiChatUpload' => 'BxBaseServices',
- 'GetBlockAiAgentOperator' => 'BxBaseServices',
- 'GetAiChatThreads' => 'BxBaseServices',
- 'GetAiChatThread' => 'BxBaseServices',
- );
- }
- public function serviceGetPreloaderContent($sName) {
- $sResult = '';
- switch($sName) {
- case 'icons_css':
- if(($sCss = BxDolIconset::getObjectInstance()->getPreloaderCss()) !== false)
- $sResult = $sCss;
- break;
- case 'icons_js':
- if(($sJs = BxDolIconset::getObjectInstance()->getPreloaderJs()) !== false)
- $sResult = $sJs;
- break;
- case 'tailwind':
- $sFile = getParam('sys_css_tailwind_default');
- if(empty($sFile))
- $sFile = 'tailwind.min.css';
- $sPath = '{dir_plugins_public}tailwind/css/|';
- if($sFile == 'cdn')
- $sResult = [
- 'https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4',
- $sPath . 'tailwind.min.css' //TODO: Replace this with correct file name.
- ];
- else
- $sResult = $sPath . $sFile;
- break;
- }
- return $sResult;
- }
-
- /**
- * @page service Service Calls
- * @section bx_system_general System Services
- * @subsection bx_system_general-general General
- * @subsubsection bx_system_general-module_check_for_update module_check_for_update
- *
- * @code bx_srv('system', 'module_check_for_update', ["bx_posts"]); @endcode
- * @code bx_srv('system', 'module_check_for_update', ["bx_posts"], 'TemplServices'); @endcode
- * @code {{~system:module_check_for_update:TemplServices["bx_posts"]~}} @endcode
- *
- * Checks whether an update is available for requested module or not.
- * @param $mixedModule - module ID/name to check the updates for.
- * @return array with information about the update, false if nothing was found
- *
- * @see BxBaseServices::serviceModuleCheckForUpdate
- */
- /**
- * @ref bx_system_general-module_check_for_update "module_check_for_update"
- */
- public function serviceModuleCheckForUpdate($mixedModule)
- {
- $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
- if(empty($aModule) || !is_array($aModule))
- return false;
- $aUpdates = BxDolStudioInstallerUtils::getInstance()->checkUpdatesByModule($aModule['name']);
- if(empty($aUpdates) || !is_array($aUpdates))
- return false;
- $aUpdate = array_shift($aUpdates);
- return array(
- 'version_from' => $aUpdate['file_version'],
- 'version_to' => $aUpdate['file_version_to'],
- 'file_id' => $aUpdate['file_id']
- );
- }
- /**
- * @page service Service Calls
- * @section bx_system_general System Services
- * @subsection bx_system_general-general General
- * @subsubsection bx_system_general-module_update module_update
- *
- * @code bx_srv('system', 'module_update', ["bx_posts"]); @endcode
- * @code bx_srv('system', 'module_update', ["bx_posts"], 'TemplServices'); @endcode
- * @code {{~system:module_update:TemplServices["bx_posts"]~}} @endcode
- *
- * Download and install an update for requested module. The operation may be performed
- * immediately or by Transient Cron task. The second way is more common.
- * @param $mixedModule - module ID/name to check the updates for.
- * @return integer value determining the result of the operation. It can be one of the following values:
- * BX_DOL_STUDIO_IU_RC_SUCCESS, BX_DOL_STUDIO_IU_RC_FAILED or BX_DOL_STUDIO_IU_RC_SCHEDULED.
- *
- * @see BxBaseServices::serviceModuleUpdate
- */
- /**
- * @ref bx_system_general-module_update "module_update"
- */
- public function serviceModuleUpdate($mixedModule)
- {
- $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
- if(empty($aModule) || !is_array($aModule))
- return BX_DOL_STUDIO_IU_RC_FAILED;
- $aResult = BxDolStudioInstallerUtils::getInstance()->downloadUpdatePublic($aModule['name'], true);
- return $aResult['code'];
- }
- /**
- * @page service Service Calls
- * @section bx_system_general System Services
- * @subsection bx_system_general-general General
- * @subsubsection bx_system_general-module_delete module_delete
- *
- * @code bx_srv('system', 'module_delete', ["bx_posts"]); @endcode
- * @code bx_srv('system', 'module_delete', ["bx_posts", true], 'TemplServices'); @endcode
- * @code {{~system:module_delete:TemplServices["bx_posts"]~}} @endcode
- *
- * Delete the requested module. By default only uninstalled module can be deleted.
- * The operation may be performed immediately or by Transient Cron task. The second way is more common.
- * @param $sModule - module name to delete.
- * @param $bForceUninstall - if 'true' is passed the module will be uninstalled before deletion.
- * @return integer value determining the result of the operation. It can be one of the following values:
- * BX_DOL_STUDIO_IU_RC_SUCCESS, BX_DOL_STUDIO_IU_RC_FAILED or BX_DOL_STUDIO_IU_RC_SCHEDULED.
- *
- * @see BxBaseServices::serviceModuleDelete
- */
- /**
- * @ref bx_system_general-module_delete "module_delete"
- */
- public function serviceModuleDelete($sModule, $bForceUninstall = false)
- {
- $sModulePath = '';
- $oInstallerUtils = BxDolStudioInstallerUtils::getInstance();
- $aModule = BxDolModuleQuery::getInstance()->getModuleByName($sModule, false);
- if(!empty($aModule) && is_array($aModule)) {
- if(!$bForceUninstall)
- return BX_DOL_STUDIO_IU_RC_FAILED;
- $sModulePath = $aModule['path'];
- $aResult = $oInstallerUtils->perform($sModulePath, 'uninstall', array('auto_disable' => $bForceUninstall));
- if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
- return BX_DOL_STUDIO_IU_RC_FAILED;
- }
- else {
- $aModules = $oInstallerUtils->getModules(false);
- if(!isset($aModules[$sModule]))
- return BX_DOL_STUDIO_IU_RC_FAILED;
-
- $sModulePath = $aModules[$sModule]['dir'];
- }
- $aResult = $oInstallerUtils->perform($sModulePath, 'delete');
- return $aResult['code'];
- }
- /**
- * @page service Service Calls
- * @section bx_system_general System Services
- * @subsection bx_system_general-general General
- * @subsubsection bx_system_general-module_install module_install
- *
- * @code bx_srv('system', 'module_install', ["bx_posts"]); @endcode
- * @code bx_srv('system', 'module_install', ["bx_posts", true], 'TemplServices'); @endcode
- * @code {{~system:module_install:TemplServices["bx_posts"]~}} @endcode
- *
- * Install the requested module. By default the module will be installed only.
- * @param $sModule - module name to install.
- * @param $bForceEnable - if 'true' is passed the module will be automatically enabled after installation.
- * @return boolean value determining the result of the operation.
- *
- * @see BxBaseServices::serviceModuleInstall
- */
- /**
- * @ref bx_system_general-module_install "module_install"
- */
- public function serviceModuleInstall($sModule, $bForceEnable = false)
- {
- $oInstallerUtils = BxDolStudioInstallerUtils::getInstance();
- $aModules = $oInstallerUtils->getModules(false);
- if(!isset($aModules[$sModule]))
- return false;
- $aResult = $oInstallerUtils->perform($aModules[$sModule]['dir'], 'install', array('auto_enable' => $bForceEnable));
- if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
- return false;
- return true;
- }
- /**
- * @page service Service Calls
- * @section bx_system_general System Services
- * @subsection bx_system_general-general General
- * @subsubsection bx_system_general-module_uninstall module_uninstall
- *
- * @code bx_srv('system', 'module_uninstall', ["bx_posts"]); @endcode
- * @code bx_srv('system', 'module_uninstall', ["bx_posts", true], 'TemplServices'); @endcode
- * @code {{~system:module_uninstall:TemplServices["bx_posts"]~}} @endcode
- *
- * Uninstall the requested module. By default only disabled module can be uninstalled.
- * @param $mixedModule - module ID/name to uninstall.
- * @param $bForceDisable - if 'true' is passed the module will be automatically disabled before uninstallation.
- * @return boolean value determining the result of the operation.
- *
- * @see BxBaseServices::serviceModuleUninstall
- */
- /**
- * @ref bx_system_general-module_uninstall "module_uninstall"
- */
- public function serviceModuleUninstall($mixedModule, $bForceDisable = false)
- {
- $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
- if(empty($aModule) || !is_array($aModule))
- return false;
- if((int)$aModule['enabled'] != 0 && !$bForceDisable)
- return false;
- $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aModule['path'], 'uninstall', array('auto_disable' => $bForceDisable));
- if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
- return false;
- return true;
- }
- /**
- * @page service Service Calls
- * @section bx_system_general System Services
- * @subsection bx_system_general-general General
- * @subsubsection bx_system_general-module_enable module_enable
- *
- * @code bx_srv('system', 'module_enable', ["bx_posts"]); @endcode
- * @code bx_srv('system', 'module_enable', ["bx_posts"], 'TemplServices'); @endcode
- * @code {{~system:module_enable:TemplServices["bx_posts"]~}} @endcode
- *
- * Enable the requested module.
- * @param $mixedModule - module ID/name to enable.
- * @return boolean value determining the result of the operation.
- *
- * @see BxBaseServices::serviceModuleEnable
- */
- /**
- * @ref bx_system_general-module_enable "module_enable"
- */
- public function serviceModuleEnable($mixedModule)
- {
- $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
- if(empty($aModule) || !is_array($aModule))
- return false;
- if((int)$aModule['enabled'] != 0)
- return false;
- $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aModule['path'], 'enable');
- if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
- return false;
- return true;
- }
- /**
- * @page service Service Calls
- * @section bx_system_general System Services
- * @subsection bx_system_general-general General
- * @subsubsection bx_system_general-module_disable module_disable
- *
- * @code bx_srv('system', 'module_disable', ["bx_posts"]); @endcode
- * @code bx_srv('system', 'module_disable', ["bx_posts"], 'TemplServices'); @endcode
- * @code {{~system:module_disable:TemplServices["bx_posts"]~}} @endcode
- *
- * Disable the requested module.
- * @param $mixedModule - module ID/name to disable.
- * @return boolean value determining the result of the operation.
- *
- * @see BxBaseServices::serviceModuleDisable
- */
- /**
- * @ref bx_system_general-module_disable "module_disable"
- */
- public function serviceModuleDisable($mixedModule)
- {
- $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
- if(empty($aModule) || !is_array($aModule))
- return false;
- if((int)$aModule['enabled'] == 0)
- return false;
- $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aModule['path'], 'disable');
- if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
- return false;
- return true;
- }
- /**
- * @page service Service Calls
- * @section bx_system_general System Services
- * @subsection bx_system_general-general General
- * @subsubsection bx_system_general-is_module_installed is_module_installed
- *
- * @code bx_srv('system', 'is_module_installed', ["bx_posts"]); @endcode
- * @code bx_srv('system', 'is_module_installed', ["bx_posts"], 'TemplServices'); @endcode
- * @code {{~system:is_module_installed:TemplServices["bx_posts"]~}} @endcode
- *
- * Checks whether the requested module is installed or not.
- * @param $mixedModule - module ID/name to check.
- * @return boolean value determining the result of the operation.
- *
- * @see BxBaseServices::serviceIsModuleInstalled
- */
- /**
- * @ref bx_system_general-is_module_installed "is_module_installed"
- */
- public function serviceIsModuleInstalled($mixedModule)
- {
- $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
- return !empty($aModule) && is_array($aModule);
- }
- /**
- * @page service Service Calls
- * @section bx_system_general System Services
- * @subsection bx_system_general-general General
- * @subsubsection bx_system_general-is_module_enabled is_module_enabled
- *
- * @code bx_srv('system', 'is_module_enabled', ["bx_posts"]); @endcode
- * @code bx_srv('system', 'is_module_enabled', ["bx_posts"], 'TemplServices'); @endcode
- * @code {{~system:is_module_enabled:TemplServices["bx_posts"]~}} @endcode
- *
- * Checks whether the requested module is enabled or not.
- * @param $mixedModule - module ID/name to check.
- * @return boolean value determining the result of the operation.
- *
- * @see BxBaseServices::serviceIsModuleEnabled
- */
- /**
- * @ref bx_system_general-is_module_enabled "is_module_enabled"
- */
- public function serviceIsModuleEnabled($mixedModule)
- {
- $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
- return !empty($aModule) && is_array($aModule) && (int)$aModule['enabled'] != 0;
- }
- /**
- * Checks whether a module is a 'Content' module or not.
- *
- * @param string $mixedModule - module name or an instance of Module class.
- * @return boolean result of operation.
- */
- public function serviceIsModuleContent($mixedModule)
- {
- if($mixedModule instanceof BxDolModule)
- $mixedModule = $mixedModule->getName();
- return BxDolModuleQuery::getInstance()->isModuleContent($mixedModule);
- }
- /**
- * Checks whether a module is a 'Context' module or not.
- *
- * @param string $mixedModule - module name or an instance of Module class.
- * @return boolean result of operation.
- */
- public function serviceIsModuleContext($mixedModule)
- {
- if($mixedModule instanceof BxDolModule)
- $mixedModule = $mixedModule->getName();
- return BxDolModuleQuery::getInstance()->isModuleContext($mixedModule);
- }
- /**
- * Checks whether a module is a 'Profile' module or not.
- *
- * @param string $mixedModule - module name or an instance of Module class.
- * @return boolean result of operation.
- */
- public function serviceIsModuleProfile($mixedModule)
- {
- if($mixedModule instanceof BxDolModule)
- $mixedModule = $mixedModule->getName();
- return BxDolModuleQuery::getInstance()->isModuleProfile($mixedModule);
- }
- /**
- * Get modules by type. Available types are 'content', 'context', 'profile'.
- *
- * @param type $sType - string with type.
- * @return array of modules.
- */
- public function serviceGetModulesByType($sType, $aParams = [])
- {
- $oModuleQuery = BxDolModuleQuery::getInstance();
- if(!$oModuleQuery->checkModulesSubtypes()) {
- $oInstallerUtils = new BxDolInstallerUtils();
- $aModules = $oModuleQuery->getModulesBy(['type' => 'modules']);
- foreach($aModules as $aModule)
- if(($iModuleSubtypes = $oInstallerUtils->getSubtypes($aModule['name'])) != 0)
- $oModuleQuery->updateModule(['subtypes' => $iModuleSubtypes], ['id' => $aModule['id']]);
- }
- $iSubtypes = 0;
- switch($sType) {
- case 'content':
- $iSubtypes = BX_DOL_MODULE_SUBTYPE_TEXT;
- break;
- case 'context':
- $iSubtypes = BX_DOL_MODULE_SUBTYPE_CONTEXT;
- break;
- case 'profile':
- $iSubtypes = BX_DOL_MODULE_SUBTYPE_PROFILE;
- break;
- }
- $aResults = $oModuleQuery->getModulesBy(array_merge([
- 'type' => 'modules_subtypes',
- 'value' => $iSubtypes,
- 'active' => 1
- ], array_intersect_key($aParams, array_flip(['id_as_key', 'name_as_key']))));
- return $aResults;
- }
- public function serviceGetModulesBySubtypeSimple($sType)
- {
- $a = $this->serviceGetModulesByType($sType, ['name_as_key' => true]);
- return array_map(function ($r) {
- return $r['title'];
- }, $a);
- }
- public function serviceProfileUnit ($iContentId, $aParams = array())
- {
- return $this->_serviceProfileFunc('getUnit', $iContentId, $aParams);
- }
-
- public function serviceProfileUnitApi ($iContentId, $aParams = [])
- {
- return $this->_serviceProfileFunc('getUnitApi', $iContentId, $aParams);
- }
- public function serviceHasImage ($iContentId)
- {
- return false;
- }
- public function serviceProfilePicture ($iContentId)
- {
- return $this->_serviceProfileFunc('getPicture', $iContentId);
- }
- public function serviceProfileAvatar ($iContentId)
- {
- return $this->_serviceProfileFunc('getAvatar', $iContentId);
- }
- public function serviceProfileAvatarBig ($iContentId)
- {
- return $this->_serviceProfileFunc('getAvatarBig', $iContentId);
- }
- public function serviceProfileCover ($iContentId)
- {
- return '';
- }
- public function serviceProfileEditUrl ($iContentId)
- {
- return bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=account-settings-info'));
- }
- public function serviceProfileThumb ($iContentId)
- {
- return $this->_serviceProfileFunc('getThumb', $iContentId);
- }
- public function serviceProfileIcon ($iContentId)
- {
- return $this->_serviceProfileFunc('getIcon', $iContentId);
- }
- public function serviceProfileName ($iContentId)
- {
- return $this->_serviceProfileFunc('getDisplayName', $iContentId);
- }
- public function serviceProfileUrl ($iContentId)
- {
- return $this->_serviceProfileFunc('getUrl', $iContentId);
- }
- /**
- * @see iBxDolProfileService::serviceCheckAllowedProfileView
- */
- public function serviceCheckAllowedProfileView($iContentId)
- {
- return _t('_Access denied');
- }
- /**
- * @see iBxDolProfileService::serviceCheckAllowedProfileContact
- */
- public function serviceCheckAllowedProfileContact($iContentId)
- {
- return _t('_Access denied');
- }
- /**
- * @see iBxDolProfileService::serviceCheckAllowedPostInProfile
- */
- public function serviceCheckAllowedPostInProfile($iContentId, $sPostModule = '')
- {
- return _t('_Access denied');
- }
- /**
- * @see iBxDolProfileService::serviceCheckAllowedModuleActionInProfile
- */
- public function serviceCheckAllowedModuleActionInProfile($iContentId, $sPostModule, $sActionName)
- {
- return _t('_Access denied');
- }
- /**
- * @see iBxDolProfileService::serviceGetSpaceTitle
- */
- public function serviceGetSpaceTitle()
- {
- return '';
- }
- /**
- * @see iBxDolProfileService::serviceGetParticipatingProfiles
- */
- public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObject = false)
- {
- return array();
- }
-
- /**
- * @page service Service Calls
- * @section bx_system_general System Services
- * @subsection bx_system_general-general General
- * @subsubsection bx_system_general-get_create_post_form get_create_post_form
- *
- * @code bx_srv('system', 'get_create_post_form', [false, "bx_posts"], 'TemplServices'); @endcode
- * @code {{~system:get_create_post_form:TemplServices[false,"bx_posts"]~}} @endcode
- *
- * Get United Create Post form.
- * @param $mixedContextId - context which the post will be created in:
- * - false = 'Public' post form;
- * - 0 = 'Profile' post form, which allows to post in your own profile and connections;
- * - n = 'Context' post form, which allows to post in context (3d party profile, group, event, etc).
- * @param $sDefault - tab selected by default.
- * @param $aCustom - an array with custom paramaters.
- * @return string with form content
- *
- * @see BxBaseServices::serviceGetCreatePostForm
- */
- /**
- * @ref bx_system_general-get_create_post_form "get_create_post_form"
- */
- public function serviceGetCreatePostForm($mixedContextId = false, $sDefault = '', $aCustom = array())
- {
- if(!isLogged() || ($mixedContextId !== false && !is_numeric($mixedContextId)))
- return '';
- $oProfile = BxDolProfile::getInstance();
- if(!$oProfile)
- return '';
- if($mixedContextId !== false)
- $mixedContextId = (int)(!empty($mixedContextId) ? -$mixedContextId : $oProfile->id());
- $oMenu = BxDolMenu::getObjectInstance('sys_create_post');
- if(!$oMenu)
- return '';
- $oMenu->setContextId($mixedContextId);
- $aMenuItems = $oMenu->getMenuItems();
- if(empty($aMenuItems) || !is_array($aMenuItems))
- return '';
- if(empty($sDefault)) {
- $aDefault = array_shift($aMenuItems);
- $sDefault = !empty($aDefault['module']) ? $aDefault['module'] : $aDefault['name'];
- }
- $oMenu->setSelected($sDefault, $sDefault);
- $oContext = false;
- $bContext = $mixedContextId !== false;
- if($bContext && ($oContext = BxDolProfile::getInstance(abs($mixedContextId))) !== false)
- if(bx_srv($oContext->getModule(), 'check_allowed_post_in_profile', [$oContext->getContentId(), $sDefault]) !== CHECK_ACTION_RESULT_ALLOWED)
- return '';
- $sTitle = '_sys_page_block_title_create_post';
- if(!$bContext)
- $sTitle = _t($sTitle . '_public');
- else if($mixedContextId < 0) {
- $sTitle = _t($sTitle . '_context');
- if($oContext)
- $sTitle = bx_replace_markers($sTitle, [
- 'display_name' => $oContext->getDisplayName()
- ]);
- }
- else
- $sTitle = _t($sTitle);
- $sPlaceholder = _t('_sys_txt_create_post_placeholder', $oProfile->getDisplayName());
- $oDbModules = BxDolModuleQuery::getInstance();
- $oTemplate = BxDolTemplate::getInstance();
- $oTemplate->addJs(['BxDolCreatePost.js']);
- $aPreloadingList = [];
- $aModules = explode(',', getParam('sys_create_post_form_preloading_list'));
- if(!empty($aModules))
- foreach($aModules as $sModule) {
- $aModule = $oDbModules->getModuleByName($sModule);
- if(empty($aModule) || !is_array($aModule))
- continue;
- $aPreloadingList[$sModule] = $aModule['uri'];
- }
- if(bx_is_api()) {
- return [
- 'title' => $sTitle,
- 'content' => [
- bx_api_get_block('get_create_post_form', [
- 'menu' => $oMenu->getCodeAPI(),
- 'params' => ['context_id' => $mixedContextId]])
- ]
- ];
- }
- $sJsObject = 'oBxDolCreatePost';
- $sJsContent = $oTemplate->_wrapInTagJsCode("var " . $sJsObject . " = new BxDolCreatePost(" . json_encode([
- 'sObjName' => $sJsObject,
- 'sRootUrl' => BX_DOL_URL_ROOT,
- 'sDefault' => $sDefault,
- 'iContextId' => $bContext ? $mixedContextId : 0,
- 'oPreloadingList' => $aPreloadingList,
- 'oCustom' => $aCustom
- ]) . ");");
- return [
- 'title' => $sTitle,
- 'content' => $oTemplate->parseHtmlByName('create_post_form.html', [
- 'default' => $sDefault,
- 'placeholder' => $sPlaceholder,
- 'user_thumb' => $oProfile->getUnit(0, ['template' => 'unit_wo_info_links']),
- 'form' => bx_srv($sDefault, 'get_create_post_form', [[
- 'context_id' => $mixedContextId,
- 'ajax_mode' => true,
- 'absolute_action_url' => true,
- 'custom' => $aCustom
- ]]),
- 'js_object' => $sJsObject,
- 'js_content' => $sJsContent
- ]),
- 'menu' => $oMenu->getMenuItemsCount() > 1 ? $oMenu : ''
- ];
- }
- public function serviceGetOptionsCreatePostFormPreloadingList()
- {
- $oMenu = BxDolMenu::getObjectInstance('sys_create_post');
- if(!$oMenu)
- return [];
- $aMenuItems = $oMenu->getMenuItems();
- $aResult = [];
- foreach($aMenuItems as $aMenuItem) {
- $sModule = !empty($aMenuItem['module']) ? $aMenuItem['module'] : $aMenuItem['name'];
- if(!bx_srv('system', 'is_module_enabled', [$sModule]))
- continue;
- $aResult[] = [
- 'key' => $sModule,
- 'value' => _t('_' . $sModule)
- ];
- }
- return $aResult;
- }
- public function serviceGetBlockStatic($sBlockName)
- {
- $bIsApi = bx_is_api();
- if(!$bIsApi)
- return '';
- return [bx_api_get_block('static', [
- 'element' => $sBlockName
- ])];
- }
- public function serviceGetBlockAuthor($sModule, $iContentId = 0)
- {
- if(!$iContentId && bx_get('id') !== false)
- $iContentId = (int)bx_get('id');
- $sMethodGetAuthor = 'get_author';
- if(!$sModule || !$iContentId || !BxDolRequest::serviceExists($sModule, $sMethodGetAuthor))
- return '';
- $iAuthor = bx_srv($sModule, $sMethodGetAuthor, [$iContentId]);
- if(!$iAuthor)
- return '';
- $oAuthor = BxDolProfile::getInstance($iAuthor);
- if(!$oAuthor)
- return '';
- $sModuleAuthor = $oAuthor->getModule();
- $sMethodGetCover = 'entity_cover';
- if(!BxDolRequest::serviceExists($sModuleAuthor, $sMethodGetCover))
- return '';
- return bx_srv($sModuleAuthor, $sMethodGetCover, [$oAuthor->getContentId(), [
- 'use_as_author' => true,
- 'show_text' => false
- ]]);
- }
- /**
- * AI agent chat block.
- *
- * Studio / `bx_srv('system', 'get_block_ai_agent', [...], 'TemplServices')`:
- *
- * array (
- * 'module' => 'system',
- * 'method' => 'get_block_ai_agent',
- * 'params' =>
- * array (
- * 0 => 6, // agent id
- * 1 => array (
- * 'context' => false, // profile id, or false = resolve from the page
- * 'require_post' => false, // only accept a page/post as context
- * 'allow_images' => true, // composer image attachments
- * 'allow_new' => false, // "Start new" extra threads (`?chat=`)
- * 'show_history' => false, // "Chats" panel with the viewer's earlier threads (App only; operator block turns it on)
- * ),
- * ),
- * 'class' => 'TemplServices',
- * )
- *
- * Legacy positional params still work: (id, context, require_post, allow_images, allow_new, show_history).
- *
- * @param int $iId Agent id
- * @param array|int|false $aParams Named options (preferred) or legacy context pid
- */
- public function serviceGetBlockAiAgent($iId = 0, $aParams = [], ...$aLegacy)
- {
- $bIsApi = bx_is_api();
- $aAgent = BxDolAiQuery::getAgentObject($iId);
- if(!$aAgent || !is_array($aAgent))
- return $bIsApi ? [] : '';
- $aParams = $this->_normalizeAiAgentBlockParams($aParams, $aLegacy);
- $mixedContextPid = $aParams['context'];
- $bRequirePost = $aParams['require_post'];
- $oAi = BxDolAi::getInstance();
- $oChat = BxDolAiChat::getInstance();
- if ($mixedContextPid === false || $mixedContextPid === null || $mixedContextPid === '')
- $iContextPid = $oAi ? (int)$oChat->resolveChatHistoryContextPidFromPage($bRequirePost) : 0;
- else
- $iContextPid = $oAi ? $oChat->filterContextPid((int)$mixedContextPid, $bRequirePost) : 0;
- if ($bIsApi)
- return [bx_api_get_block('ai_agent', [
- 'agent_id' => $iId,
- 'agent_profile' => BxDolProfile::getData($aAgent['profile_id']),
- 'context_profile_id' => $iContextPid,
- 'hidden_first_message' => (string)($aAgent['hidden_first_message'] ?? ''),
- 'allow_images' => $aParams['allow_images'] ? 1 : 0,
- 'allow_new' => $aParams['allow_new'] ? 1 : 0,
- 'show_history' => $aParams['show_history'] ? 1 : 0,
- 'max_images' => BxDolAiChatImages::MAX_PER_TURN,
- 'max_input_chars' => (int)($aAgent['max_input_chars'] ?? 0),
- ])];
- $sEndpoint = BX_DOL_URL_ROOT . 'sys-ai-chat/' . (int)$iId;
- if ($iContextPid > 0)
- $sEndpoint .= '&context=' . $iContextPid;
- $oTemplate = BxDolTemplate::getInstance();
- $oTemplate->addJs([BX_DOL_URL_ROOT . 'plugins_public/bundle.js']);
- return $oTemplate->parseHtmlByName('agent_ai_chat.html', [
- 'id' => (int)$iId,
- 'context_profile_id' => (int)$iContextPid,
- 'endpoint_js' => json_encode($sEndpoint),
- 'bundle_url' => BX_DOL_URL_ROOT . 'plugins_public/bundle.js',
- ]);
- }
- /**
- * Operator AI agent block: the single definition of "which agent, with which
- * settings" for site operators. The Dashboard page block and the App floating
- * bubble both call this service with no params, so they can never diverge.
- *
- * Agent id comes from Studio > Settings > Agents (`sys_agents_operator_agent`).
- * Block params are fixed here — change them here, and only here. This is the one
- * block with the "Chats" history panel (`show_history`): operators come back to
- * the same agent again and again, and need to find what it did last time.
- *
- * Studio: `{"module":"system","method":"get_block_ai_agent_operator","class":"TemplServices"}`
- * API: `api.php?r=system/get_block_ai_agent_operator/TemplServices`
- */
- public function serviceGetBlockAiAgentOperator()
- {
- $bIsApi = bx_is_api();
- $iId = (int)getParam('sys_agents_operator_agent');
- if ($iId <= 0)
- return $bIsApi ? [] : '';
- $aAgent = BxDolAiQuery::getAgentObject($iId);
- $oAi = BxDolAi::getInstance();
- if (!$aAgent || !is_array($aAgent) || !$oAi || !$oAi->canChatDirectly($aAgent))
- return $bIsApi ? [] : '';
- return $this->serviceGetBlockAiAgent($iId, [
- 'context' => false,
- 'require_post' => false,
- 'allow_images' => true,
- 'allow_new' => true,
- 'show_history' => true,
- ]);
- }
- /**
- * Studio > Settings select for `sys_agents_operator_agent`: active agents
- * that can be chatted with directly (see BxDolAi::canChatDirectly).
- */
- public function serviceGetOptionsOperatorAgent()
- {
- $aResult = [
- ['key' => '', 'value' => _t('_Select_one')],
- ];
- $aAgents = BxDolDb::getInstance()->getAll("SELECT `id`, `name` FROM `sys_agents_agents` WHERE `active` = 1 AND `trigger` IN ('manual', 'message') ORDER BY `name` ASC");
- foreach ($aAgents as $aAgent) {
- $aResult[] = [
- 'key' => (int)$aAgent['id'],
- 'value' => $aAgent['name'] . ' (#' . (int)$aAgent['id'] . ')',
- ];
- }
- return $aResult;
- }
- /**
- * Named options for {@see serviceGetBlockAiAgent}, plus legacy positional args.
- *
- * @return array{context:mixed,require_post:bool,allow_images:bool,allow_new:bool,show_history:bool}
- */
- protected function _normalizeAiAgentBlockParams($mixedParams, array $aLegacy = [])
- {
- $isOn = function ($v) {
- return $v === true || $v === 1 || $v === '1' || $v === 'true' || $v === 'on' || $v === 'yes';
- };
- $aOut = [
- 'context' => false,
- 'require_post' => false,
- 'allow_images' => false,
- 'allow_new' => false,
- 'show_history' => false,
- ];
- $aNamedKeys = ['context', 'context_profile_id', 'require_post', 'allow_images', 'allow_new', 'show_history'];
- $bNamed = is_array($mixedParams);
- if ($bNamed && $mixedParams) {
- $bNamed = false;
- foreach ($aNamedKeys as $sKey) {
- if (array_key_exists($sKey, $mixedParams)) {
- $bNamed = true;
- break;
- }
- }
- }
- if ($bNamed) {
- if (array_key_exists('context', $mixedParams))
- $aOut['context'] = $mixedParams['context'];
- elseif (array_key_exists('context_profile_id', $mixedParams))
- $aOut['context'] = $mixedParams['context_profile_id'];
- if (array_key_exists('require_post', $mixedParams))
- $aOut['require_post'] = $mixedParams['require_post'];
- if (array_key_exists('allow_images', $mixedParams))
- $aOut['allow_images'] = $mixedParams['allow_images'];
- if (array_key_exists('allow_new', $mixedParams))
- $aOut['allow_new'] = $mixedParams['allow_new'];
- if (array_key_exists('show_history', $mixedParams))
- $aOut['show_history'] = $mixedParams['show_history'];
- } else {
- $aOut['context'] = $mixedParams;
- if (array_key_exists(0, $aLegacy))
- $aOut['require_post'] = $aLegacy[0];
- if (array_key_exists(1, $aLegacy))
- $aOut['allow_images'] = $aLegacy[1];
- if (array_key_exists(2, $aLegacy))
- $aOut['allow_new'] = $aLegacy[2];
- if (array_key_exists(3, $aLegacy))
- $aOut['show_history'] = $aLegacy[3];
- }
- $aOut['require_post'] = $isOn($aOut['require_post']);
- $aOut['allow_images'] = $isOn($aOut['allow_images']);
- $aOut['allow_new'] = $isOn($aOut['allow_new']);
- $aOut['show_history'] = $isOn($aOut['show_history']);
- return $aOut;
- }
- public function serviceGetMenu($aParams)
- {
- $bIsApi = bx_is_api();
- $mixedResulEmpty = $bIsApi ? [] : '';
- if($bIsApi && is_string($aParams))
- $aParams = bx_api_get_browse_params($aParams);
- if(!isset($aParams['object']))
- return $mixedResulEmpty;
- $oMenu = BxDolMenu::getObjectInstance($aParams['object']);
- if(!$oMenu)
- return $mixedResulEmpty;
- if(!empty($aParams['params']) && is_array($aParams['params']))
- $oMenu->setContentParams($aParams['params']);
- return $bIsApi ? $oMenu->getCodeAPI() : $oMenu->getCode();
- }
- /**
- * @page service Service Calls
- * @section bx_system_general System Services
- * @subsection bx_system_general-general General
- * @subsubsection bx_system_general-get_site_submenu get_site_submenu
- *
- * @code bx_srv('system', 'get_site_submenu', [], 'TemplServices'); @endcode
- * @code {{~system:get_site_submenu:TemplServices[]~}} @endcode
- *
- * Get Site Submenu code.
- * @see BxBaseServices::serviceGetSiteSubmenu
- */
- /**
- * @ref bx_system_general-get_site_submenu "get_site_submenu"
- */
- public function serviceGetSiteSubmenu()
- {
- $oMenu = BxDolMenu::getObjectInstance('sys_site_submenu');
- return $oMenu ? $oMenu->getCode() : '';
- }
-
- /**
- * @page service Service Calls
- * @section bx_system_general System Services
- * @subsection bx_system_general-general General
- * @subsubsection bx_system_general-get_products_names get_products_names
- *
- * @code bx_srv('system', 'get_products_names', [], 'TemplServices');
- *
- * @code http://example.com/m/oauth2/com/get_products_names?module=system&class=BaseServices @endcode
- * @code http://hihi.una.io/modules/?r=oauth2/com/get_products_names&module=system&class=BaseServices @endcode
- *
- * Get an array of products names from all modules with payments functionality.
- * @param $iVendorId filter products by vendor ID.
- * @param $iLimit limit number of records from one module.
- * @return array of products where key id product name and value is module name
- *
- * @see BxBaseServices::serviceGetProductsNames
- */
- /**
- * @ref bx_system_general-get_products_names "get_products_names"
- */
- public function serviceGetProductsNames($iVendorId = 0, $iLimit = 1000)
- {
- $o = BxDolPayments::getInstance();
- if (!$o)
- return array();
- return $o->getProductsNames($iVendorId, $iLimit);
- }
- /**
- * @see iBxDolProfileService::serviceCheckSpacePrivacy
- */
- public function serviceCheckSpacePrivacy($iContentId)
- {
- return _t('_Access denied');
- }
-
- public function serviceFormsHelper ()
- {
- return new BxTemplAccountForms();
- }
- public function serviceActAsProfile ()
- {
- return false;
- }
- public function serviceGetModerators($iContentId)
- {
- $aModerators = BxDolAclQuery::getInstance()->getProfilesByMembership([
- MEMBERSHIP_ID_MODERATOR,
- MEMBERSHIP_ID_ADMINISTRATOR
- ]);
- $aIds = [];
- array_walk($aModerators, function ($aItem, $iKey, $aParams) {
- if(!empty($aItem['id']))
- $aParams[0][] = (int)$aItem['id'];
- }, [&$aIds]);
- return $aIds;
- }
- public function servicePrepareFields ($aFieldsProfile)
- {
- return $aFieldsProfile;
- }
- public function serviceProfilesSearch ($sTerm, $iLimit)
- {
- $oDb = BxDolAccountQuery::getInstance();
- $aRet = array();
- $a = $oDb->searchByTerm($sTerm, $iLimit);
- foreach ($a as $r)
- $aRet[] = array ('label' => $this->serviceProfileName($r['content_id']), 'value' => $r['profile_id']);
- return $aRet;
- }
- /**
- * @page service Service Calls
- * @section bx_system_general System Services
- * @subsection bx_system_general-general General
- * @subsubsection bx_system_general-keyword_search keyword_search
- *
- * @code bx_srv('system', 'keyword_search', ["bx_posts", ["keyword" => "test"}], 'TemplServices'); @endcode
- *
- * @code {{~system:keyword_search:TemplServices["bx_posts", {"keyword":"test"}]~}} @endcode
- * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country", "keyword": "AU"}, "unit.html"]~}} @endcode
- * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_state", "state":"NSW", "keyword": "AU"}, "unit.html"]~}} @endcode
- * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"}, "unit.html"]~}} @endcode
- * @code {{~system:keyword_search:TemplServices["bx_posts", {"meta_type": "mention", "keyword": 2}, "unit_gallery.html"]~}} @endcode
- * @code {{~system:keyword_search:TemplServices["bx_posts", {"cat": "bx_posts_cats", "keyword": 3}, "unit_gallery.html"]~}} @endcode
- *
- * Search by keyword
- * @param $sSection - search object to search in, usually module name, for example: bx_posts
- * @param $aCondition - condition for search, supported conditions:
- * - search by keyword: ["keyword" => "test"]
- * - search by country: ["meta_type" => "location_country", "keyword" => "AU"]
- * - search by country and state: ["meta_type": "location_country_state", "state":"NSW", "keyword": "AU"]
- * - search by country, state and city: ["meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"]
- * - search for mentions: ["meta_type" => "mention", "keyword" => 2]
- * - search in category: ["cat": "bx_posts_cats", "keyword": 3]
- * @param $sTemplate - template for displaying search results, for example: unit.html
- * @param $iStart - paginate, display records starting from this number
- * @param $iPerPage - paginate, display this number of records per page
- * @param $bLiveSearch - search results like in live search
- *
- * @see BxBaseServices::serviceKeywordSearch
- */
- /**
- * @ref bx_system_general-keyword_search "keyword_search"
- */
- public function serviceKeywordSearch ($sSection, $aCondition, $sTemplate = '', $iStart = 0, $iPerPage = 0, $bLiveSearch = 0, $bPaginate = false)
- {
- if (!$sSection || !isset($aCondition['keyword']))
- return '';
- $sClass = 'BxTemplSearch';
- $sElsName = 'bx_elasticsearch';
- $sElsMethod = 'is_configured';
- if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod)) {
- $oModule = BxDolModule::getInstance($sElsName);
- bx_import('Search', $oModule->_aModule);
- $sClass = 'BxElsSearch';
- }
- $oSearch = new $sClass(array($sSection));
- $oSearch->setLiveSearch($bLiveSearch);
- $oSearch->setMetaType(isset($aCondition['meta_type']) ? $aCondition['meta_type'] : '');
- $oSearch->setCategoryObject(isset($aCondition['cat']) ? $aCondition['cat'] : '');
- $oSearch->setCustomSearchCondition($aCondition);
- if (!$bPaginate)
- $oSearch->setRawProcessing(true);
- $oSearch->setCustomCurrentCondition(array(
- 'paginate' => array (
- 'start' => $iStart,
- 'perPage' => $iPerPage ? $iPerPage : BX_DOL_SEARCH_RESULTS_PER_PAGE_DEFAULT,
- )));
- if ($sTemplate)
- $oSearch->setUnitTemplate($sTemplate);
-
- return $oSearch->response();
- }
- /**
- * @page service Service Calls
- * @section bx_system_general System Services
- * @subsection bx_system_general-general General
- * @subsubsection bx_system_general-keyword_search keyword_search
- *
- * @code bx_srv('system', 'search_keyword_form', 'TemplServices'); @endcode
- *
- * Block with Search by Keywords Form
- *
- * @see BxBaseServices::serviceSearchKeywordForm
- */
- /**
- * @ref bx_system_general-keyword_search "keyword_search"
- */
- public function serviceSearchKeywordForm ()
- {
- return $this->_getSearchObject()->getForm(BX_DB_PADDING_DEF, false, true);
- }
-
- /**
- * @page service Service Calls
- * @section bx_system_general System Services
- * @subsection bx_system_general-general General
- * @subsubsection bx_system_general-keyword_search keyword_search
- *
- * @code bx_srv('system', 'search_keyword_result', 'TemplServices'); @endcode
- *
- * Block with Search by Keywords Results
- *
- * @see BxBaseServices::serviceSearchKeywordResult
- */
- /**
- * @ref bx_system_general-keyword_search "keyword_search"
- */
- public function serviceSearchKeywordResult ()
- {
- $sType = bx_process_input(bx_get('type'));
- $sKeyword = bx_process_input(bx_get('keyword'));
- $bKeyword = $sKeyword !== false;
- if(bx_is_api())
- return $this->serviceGetDataSearchApi(['params' => [
- 'type' => $sType,
- 'keyword' => $sKeyword,
- 'section' => bx_process_input(bx_get('section')),
- 'cat' => bx_process_input(bx_get('cat'))
- ]]);
- $sCode = '';
- if($bKeyword) {
- $oSearch = $this->_getSearchObject();
- if(($sCode = $oSearch->response()))
- $sCode = BxDolTemplate::getInstance()->parseHtmlByName('search_result_block.html', [
- 'html_id' => 'bx-search-results-keyword',
- 'class' => 'bx-search-results-container',
- 'attrs' => '',
- 'content' => $sCode,
- 'bx_if:do_center' => [
- 'condition' => false,
- 'content' => [
- 'html_id' => '',
- 'selector_content' => ''
- ]
- ]
- ]);
- else
- $sCode = $oSearch->getEmptyResult();
- }
- return $sCode;
- }
- /**
- * @ref bx_system_general-get_date_search_api "get_date_search_api"
- * @api @ref bx_system_general-get_date_search_api "get_date_search_api"
- */
- public function serviceGetDataSearchApi ($aParams)
- {
- if(!bx_is_api())
- return false;
- if(is_string($aParams))
- $aParams = bx_api_get_browse_params($aParams);
- $bForceAll = ($aParams['params']['type'] ?? '') == 'keyword';
- $aSectionsAvail = explode(',', getParam('sys_api_search_sections'));
- $aSectionsAll = BxDolDb::getInstance()->fromCache(
- 'sys_global_search_pairs',
- 'getPairs',
- 'SELECT `ObjectName` AS `name`, `Title` AS `title` FROM `sys_objects_search` WHERE `GlobalSearch`=\'1\' ORDER BY `Order` ASC',
- 'name', 'title'
- );
- $aSections = [];
- foreach($aSectionsAll as $sSectionName => $sSectionTitle)
- if(in_array($sSectionName, $aSectionsAvail) || $bForceAll)
- $aSections[$sSectionName] = [
- 'name' => $sSectionName,
- 'title' => _t($sSectionTitle)
- ];
- $aParamsBrowse = array_merge([
- 'keyword' => '',
- 'section' => '',
- 'sections' => array_values($aSections),
- 'start' => 0,
- 'per_page' => 12
- ], !empty($aParams['params']) && is_array($aParams['params']) ? $aParams['params'] : []);
- if(empty($aParamsBrowse['section']))
- $aParamsBrowse['section'] = array_keys($aSections);
- else if(is_string($aParamsBrowse['section']))
- $aParamsBrowse['section'] = explode(',', $aParamsBrowse['section']);
- $sClass = 'BxTemplSearch';
-
- $sSections = $aParamsBrowse['section'];
- if ($aParamsBrowse['live'] !== true && count($sSections) > 1){
-
- $aParamsBrowse['section'] = [];
- $aParamsBrowse['sections'] = [];
-
- $aDataRv = [];
- foreach ($sSections as $sSection) {
- $oSearch = new $sClass($sSection);
- $oSearch->setLiveSearch(true);
- $oSearch->setDataProcessing(true);
- $oSearch->setCustomSearchCondition(['keyword' => $aParamsBrowse['keyword']]);
- $oSearch->setCustomCurrentCondition([
- 'paginate' => [
- 'forceStart' => $aParamsBrowse['start'],
- 'perPage' => $aParamsBrowse['per_page'],
- ]
- ]);
- $aData = $oSearch->response();
- if(count($aData) > $aParamsBrowse['per_page'])
- $aData = array_slice($aData, $aParamsBrowse['start'], $aParamsBrowse['per_page']);
- if (count($aData) > 0) {
- $oSearchResult = $oSearch->getSearchResultObject($sSection);
- $sSectionTitle = $oSearchResult->aCurrent['title'];
- $aParamsBrowse['section'][] = $sSection;
- $aParamsBrowse['sections'][] = ['name' => $sSection, 'title' => $sSectionTitle];
- $aDataRv[] = [
- 'section' => $sSection,
- 'section_name' => $sSectionTitle,
- 'data' => $aData,
- 'is_profile' => bx_srv('system', 'is_module_profile', [$oSearchResult->aCurrent['module_name']])
- ];
- }
-
- }
- return [bx_api_get_block('search_sections', [
- 'data' => $aDataRv,
- 'params' => $aParamsBrowse
- ])];
- }
- else{
- $oSearch = new $sClass($aParamsBrowse['section']);
- $oSearch->setLiveSearch(true);
- $oSearch->setDataProcessing(true);
- $oSearch->setCustomSearchCondition(['keyword' => $aParamsBrowse['keyword']]);
- $oSearch->setCustomCurrentCondition([
- 'paginate' => [
- 'forceStart' => $aParamsBrowse['start'],
- 'perPage' => $aParamsBrowse['per_page'],
- ]
- ]);
- $aData = $oSearch->response();
- if(count($aData) > $aParamsBrowse['per_page'])
- $aData = array_slice($aData, $aParamsBrowse['start'], $aParamsBrowse['per_page']);
- return [
- bx_api_get_block('browse', [
- 'unit' => 'search-results',
- 'request_url' => '/api.php?r=system/get_data_search_api/TemplServices¶ms[]=',
- 'params' => $aParamsBrowse,
- 'data' => $aData
- ])
- ];
- }
- }
- /**
- * @page service Service Calls
- * @section bx_system_general System Services
- * @subsection bx_system_general-general General
- * @subsubsection bx_system_general-cmts cmts
- *
- * @code bx_srv('system', 'cmts', ["sys_blocks", 1], 'TemplServices'); @endcode
- *
- * @code {{~system:cmts:TemplServices["sys_blocks", 1]~}} @endcode
- *
- * Comments block
- * @param $sObject - comments object name
- * @param $sId - content id assiciated tith the comments
- *
- * @see BxBaseServices::serviceCmts
- */
- /**
- * @ref bx_system_general-cmts "cmts"
- */
- public function serviceCmts ($sObject, $sId)
- {
- $o = BxDolCmts::getObjectInstance($sObject, $sId);
- if (!$o || !$o->isEnabled())
- return '';
- return $o->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
- }
- public function _serviceProfileFunc ($sFunc, $iContentId, $aParams = array())
- {
- if (!$iContentId)
- return false;
- if (!($oAccount = BxDolAccount::getInstance($iContentId)))
- return false;
- return $oAccount->$sFunc(false, $aParams);
- }
- public function serviceAlertResponseProcessInstalled()
- {
- BxDolTranscoderImage::registerHandlersSystem();
- }
- public function serviceAlertResponseProcessStorageChange ($oAlert)
- {
- if ('sys_storage_default' != $oAlert->aExtras['option'])
- return;
- $aStorages = BxDolStorageQuery::getStorageObjects();
- foreach ($aStorages as $r) {
- if (0 == $r['current_size'] && 0 == $r['current_number'] && ($oStorage = BxDolStorage::getObjectInstance($r['object'])))
- $oStorage->changeStorageEngine($oAlert->aExtras['value']);
- }
- }
- public function serviceGetOptionsProfileBot()
- {
- $aResult = array(
- array('key' => '', 'value' => _t('_Select_one'))
- );
- $aAccountsIds = BxDolAccountQuery::getInstance()->getOperators();
- foreach($aAccountsIds as $iAccountId) {
- $aProfilesIds = BxDolAccount::getInstance($iAccountId)->getProfilesIds(true, false);
- foreach($aProfilesIds as $iProfileId) {
- $oProfile = BxDolProfile::getInstance($iProfileId);
- $aResult[] = array(
- 'key' => $iProfileId,
- 'value' => _t('_sys_profile_with_type', $oProfile->getDisplayName(), $oProfile->getModule()),
- );
- }
- }
- return $aResult;
- }
-
- public function serviceGetOptionsModuleListForPrivacySelector()
- {
- $aResult = array();
- $BxDolModuleQuery = BxDolModuleQuery::getInstance();
- $aModules = $BxDolModuleQuery->getModulesBy(array('type' => 'modules', 'active' => 1));
- foreach($aModules as $aModule){
- $oModule = BxDolModule::getInstance($aModule['name']);
- if($oModule instanceof iBxDolContentInfoService){
- if (!BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
- continue;
- $aResult[$aModule['name']] = $aModule['title'];
- }
- }
- return $aResult;
- }
-
- public function serviceGetOptionsCaptchaDefault()
- {
- $aResults = [];
- $aObjects = BxDolCaptchaQuery::getObjects();
- foreach($aObjects as $aObject)
- $aResults[$aObject['object']] = $aObject['title'];
- return $aResults;
- }
- public function serviceGetOptionsEmbedDefault()
- {
- $aResults = array(
- '' => _t('_None')
- );
- $aObjects = BxDolEmbedQuery::getObjects();
- foreach($aObjects as $aObject)
- $aResults[$aObject['object']] = _t($aObject['title']);
- return $aResults;
- }
- public function serviceGetOptionsLocationFieldDefault()
- {
- $aResults = array();
- $aObjects = BxDolLocationFieldQuery::getObjects();
- foreach($aObjects as $aObject)
- $aResults[$aObject['object']] = _t($aObject['title']);
- return $aResults;
- }
- public function serviceGetOptionsLocationMapDefault()
- {
- $aResults = array();
- $aObjects = BxDolLocationMapQuery::getObjects();
- foreach($aObjects as $aObject)
- $aResults[$aObject['object']] = _t($aObject['title']);
- return $aResults;
- }
- public function serviceGetOptionsPushDefault()
- {
- $aResults = [
- '' => _t('_None')
- ];
- $aObjects = BxDolPushQuery::getObjects();
- foreach($aObjects as $aObject)
- $aResults[$aObject['object']] = $aObject['title'];
- return $aResults;
- }
- public function serviceGetOptionsSmsDefault()
- {
- $aResults = [
- '' => _t('_None')
- ];
- $aObjects = BxDolSmsQuery::getObjects();
- foreach($aObjects as $aObject)
- $aResults[$aObject['object']] = $aObject['title'];
- return $aResults;
- }
- public function serviceGetOptionsSocketsFieldDefault()
- {
- $aResults = [];
- $aObjects = ['sys_sockets_disabled', 'sys_sockets_soketi'];
- foreach($aObjects as $sObject)
- $aResults[$sObject] = _t('_adm_stg_cpt_option_sys_sockets_type_' . $sObject);
- return $aResults;
- }
- public function serviceGetOptionsLocationLeafletGetProviders()
- {
- return BxDolLocationMapLeaflet::getProviders();
- }
- public function serviceGetOptionsRelations()
- {
- $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
- $aProfiles = array();
- foreach($aModules as $aModule) {
- $sMethod = 'act_as_profile';
- if(!BxDolRequest::serviceExists($aModule['name'], $sMethod) || !BxDolService::call($aModule['name'], $sMethod))
- continue;
- $aProfiles[$aModule['name']] = _t('_' . $aModule['name']);
- }
- $aResults = array();
- foreach($aProfiles as $sName1 => $sTitle1)
- foreach($aProfiles as $sName2 => $sTitle2)
- $aResults[$sName1 . '_' . $sName2] = $sTitle1 . ' - ' . $sTitle2;
- return $aResults;
- }
- public function serviceGetOptionsCfProhibited()
- {
- return BxDolFormQuery::getDataItems('sys_content_filter');
- }
- public function serviceGetOptionsCfUnauthenticated()
- {
- return BxDolFormQuery::getDataItems('sys_content_filter');
- }
- public function serviceGetOptionsTaiwindDefault()
- {
- $sPath = BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'tailwind/css';
- $aExcludes = ['.', '..', 'tailwind.css'];
- $aResults = [];
- if(($oHandle = opendir($sPath)) !== false) {
- while(($sFile = readdir($oHandle)) !== false) {
- if(in_array($sFile, $aExcludes))
- continue;
- if(($oHandlerFile = fopen($sPath . '/' . $sFile, 'r')) === false)
- continue;
- if(($sContent = fread($oHandlerFile, 1024)) !== false && strpos($sContent, '@tailwind base') === false)
- $aResults[$sFile] = $sFile;
- fclose($oHandlerFile);
- }
- closedir($oHandle);
- }
- /**
- * Disabled for now, because CDN and custom compiled build with own styles
- * don't work correctly together.
- *
- * $aResults['cdn'] = _t('_adm_stg_cpt_option_sys_css_tailwind_default_cdn');
- */
- return $aResults;
- }
- public function serviceGetOptionsIconsetDefault()
- {
- $aObjects = BxDolIconsetQuery::getObjects();
- foreach($aObjects as $aObject)
- $aResults[$aObject['object']] = $aObject['title'];
- return $aResults;
- }
- public function serviceGetOptionsApiRootPageGuest()
- {
- $sKey = '_adm_stg_cpt_option_sys_api_root_page_';
- return [
- 'home' => _t($sKey .'home'),
- 'splash' => _t($sKey . 'splash')
- ];
- }
- public function serviceGetOptionsApiRootPageMember()
- {
- $sKey = '_adm_stg_cpt_option_sys_api_root_page_';
- return [
- 'home' => _t($sKey .'home'),
- 'dashboard' => _t($sKey . 'dashboard'),
- 'profile' => _t($sKey . 'profile')
- ];
- }
- public function serviceGetOptionsApiMenuTop()
- {
- $aMenus = BxDolMenuQuery::getMenuObjects();
- $aResults = ['' => _t('_sys_please_select')];
- foreach($aMenus as $aMenu)
- if($aMenu['module'] == 'system')
- $aResults[$aMenu['object']] = _t($aMenu['title']);
- return $aResults;
- }
- public function serviceGetOptionsApiContextSwitcher()
- {
- $aContexts = bx_srv('system', 'get_modules_by_type', ['context']);
- $aResults = ['' => _t('_None')];
- foreach($aContexts as $aContext)
- $aResults[$aContext['name']] = _t('_' . $aContext['name']);
- return $aResults;
- }
- public function serviceGetOptionsApiContextConnection()
- {
- $aConnections = ['subscriptions', 'fans', 'participants'];
- $aResults = ['' => _t('_sys_please_select')];
- foreach($aConnections as $sConnection)
- $aResults[$sConnection] = _t('_adm_stg_cpt_option_sys_api_cnt_cnn_' . $sConnection);
- return $aResults;
- }
- public function serviceGetOptionsAgentsModel()
- {
- return ['' => _t('_Select_one')] + BxDolAi::getInstance()->getModels(['active' => true]);
- }
- public function serviceGetOptionsAgentsProfile($bSelectOne = true, $sSelectOneLangKey = '_Select_one')
- {
- $aResult = [];
- if($bSelectOne)
- $aResult[] = ['key' => '', 'value' => _t($sSelectOneLangKey)];
- $aAccountsIds = BxDolAccountQuery::getInstance()->getOperators();
- foreach($aAccountsIds as $iAccountId) {
- $aProfilesIds = BxDolAccount::getInstance($iAccountId)->getProfilesIds(true, false);
- foreach($aProfilesIds as $iProfileId) {
- $oProfile = BxDolProfile::getInstance($iProfileId);
- $sProfileModule = false === $oProfile ? '' : $oProfile->getModule();
- if ($sProfileModule && ($sProfileModule != 'system' || ($sProfileModule == 'system' && empty($oProfile->getAccountObject()->getEmail())))) {
- $aResult[] = [
- 'key' => $iProfileId,
- 'value' => _t('_sys_profile_with_type', $oProfile->getDisplayName(), $sProfileModule === 'system' ? 'System' : _t('_' . $sProfileModule))
- ];
- }
- }
- }
- return $aResult;
- }
- public function serviceRedirect($sUrl = false)
- {
- if (!getParam('sys_confirmation_before_redirect')) {
- BxDolTemplate::getInstance()->displayPageNotFound();
- exit;
- }
- if (false === $sUrl)
- $sUrl = bx_get('url');
- if (!$sUrl || !preg_match('@^https?://@', $sUrl)) {
- http_response_code(500);
- return MsgBox(_t('_error occured'));
- }
- else {
- $bSpam = null;
- /**
- * @hooks
- * @hookdef hook-system-check_spam_url 'system', 'check_spam_url' - hook to override sClass for search
- * - $unit_name - equals `system`
- * - $action - equals `check_spam_url`
- * - $object_id - not used
- * - $sender_id - logged account id
- * - $extra_params - array of additional params with the following array keys:
- * - `is_spam` - [bool] by ref, spam url or not, can be overridden in hook processing
- * - `content` - [string] by ref, url of link, can be overridden in hook processing
- * - `where` - [string] equal redirect
- * @hook @ref hook-system-check_spam_url
- */
- bx_alert('system', 'check_spam_url', 0, getLoggedId(), array(
- 'is_spam' => &$bSpam,
- 'content' => &$sUrl,
- 'is_spam_ref' => &$bSpam,
- 'content_ref' => &$sUrl,
- 'where' => 'redirect'
- ));
- $sLangKey = $bSpam ? '_sys_redirect_confirmation_harmful' : '_sys_redirect_confirmation';
- return BxDolTemplate::getInstance()->parseHtmlByName('redirect.html', [
- 'text' => _t($sLangKey, bx_process_output($sUrl), getParam('site_title')),
- 'url' => bx_js_string($sUrl, BX_ESCAPE_STR_APOS),
- ]);
- }
- }
- public function serviceSetBadges($iContentId, $sBadgesIds, $sModule)
- {
- $aSelectedBadges = explode(",", $sBadgesIds);
-
- $iPerformerId = bx_get_logged_profile_id();
- $aCheck = checkActionModule($iPerformerId, 'set badge', 'system', false);
- if(!isAdmin() && $aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
- return false;
- $oBadges = BxDolBadges::getInstance();
- $oBadges->delete([
- 'type' => 'by_module&object',
- 'object_id' => $iContentId,
- 'module' => $sModule
- ]);
- foreach ($aSelectedBadges as $iSelectedBadge)
- $oBadges->add($iSelectedBadge, $iContentId, $sModule);
- checkActionModule($iPerformerId, 'set badge', 'system', true);
- return true;
- }
-
- public function serviceGetBadge($aBadge, $bIsCompact = false)
- {
- $sClass = '';
- $sStyleFont = '';
- $sStyleBg = '';
- if ($aBadge['color'] == '')
- $aBadge['color'] = 'purple-600';
-
- if ($bIsCompact && $aBadge['icon'] != ''){
- $aBadge['is_icon_only'] = 1;
- }
- if ($aBadge['is_icon_only'] == 1){
- $sClass .= ' bx-badge-compact';
- if (substr_count($aBadge['color'], 'rgb('))
- $sStyleFont = 'color: ' . $aBadge['color'];
- else
- $sClass .= ' text-' . $aBadge['color'];
- }
- else{
- if (substr_count($aBadge['color'], 'rgb('))
- $sStyleBg = 'background-color: ' . $aBadge['color'];
- else
- $sClass .= ' bg-' . $aBadge['color'];
- }
-
- return BxDolTemplate::getInstance()->parseHtmlByName('badge.html', array(
- 'bx_if:content' => array(
- 'condition' => $aBadge['is_icon_only'] != '1',
- 'content' => array('content' => _t($aBadge['text'])),
- ),
- 'bx_if:icon' => array(
- 'condition' => $aBadge['icon'] != '',
- 'content' => array('content' => BxDolTemplate::getInstance()->getIcon($aBadge['icon'], array('class' => 'bx-badge-icon sys-colored', 'style' => $sStyleFont))),
- ),
- 'title' => $aBadge['text'],
- 'style_font' => $sStyleFont,
- 'style_bg' => $sStyleBg,
- 'class' => $sClass,
- )
- );
- }
-
- public function serviceGetFooter()
- {
- return BxDolTemplate::getInstance()->parseHtmlByName('footer.html', []);
- }
- private function _getSearchObject()
- {
- $sClass = 'BxTemplSearch';
- $sElsName = 'bx_elasticsearch';
- $sElsMethod = 'is_configured';
- if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod) && !bx_get('cat') && !bx_get('type')) {
- $oModule = BxDolModule::getInstance($sElsName);
- bx_import('Search', $oModule->_aModule);
- $sClass = 'BxElsSearch';
- }
- /**
- * @hooks
- * @hookdef hook-system-search_keyword 'system', 'search_keyword' - hook to override sClass for search
- * - $unit_name - equals `system`
- * - $action - equals `search_keyword`
- * - $object_id - not used
- * - $sender_id - not used
- * - $extra_params - array of additional params with the following array keys:
- * - `override_result` - [string] by ref, class name for search, can be overridden in hook processing
- * @hook @ref hook-system-search_keyword
- */
- bx_alert('system', 'search_keyword', 0, 0, array('class' => &$sClass, 'class_name_ref' => &$sClass));
- $oSearch = new $sClass(bx_get('section'));
- $oSearch->setLiveSearch(bx_get('live_search') ? 1 : 0);
- $oSearch->setMetaType(bx_process_input(bx_get('type')));
- $oSearch->setCategoryObject(bx_process_input(bx_get('cat')));
- return $oSearch;
- }
- public function serviceHomeRedirect()
- {
- header("Location:" . BX_DOL_URL_ROOT, true, 301);
- exit;
- }
- public function serviceProcessEmbed()
- {
- BxDolEmbed::getObjectInstance()->process();
- }
- public function serviceCallAgent($sType, $aAgent, $aParams)
- {
- $oAi = BxDolAi::getInstance();
- return $oAi->callAgent($sType, $aAgent, $aParams);
- }
- public function serviceCallAgentForFormInput($iAgentId)
- {
- return BxDolAiTrigger::getInstance('form-input')->handle($iAgentId);
- }
- public function serviceAiChat($iAgentId)
- {
- return BxDolAiTrigger::getInstance('chat')->handle($iAgentId);
- }
- /**
- * Composer image upload for the chat widget (`$_FILES['file']`).
- * → `{file_id, url, mime}` or `{error}`; the client sends the URL back as an image part of its next message.
- */
- public function serviceAiChatUpload($iAgentId)
- {
- return BxDolAiTrigger::getInstance('chat')->upload($iAgentId);
- }
- /**
- * The caller's own conversations with an agent — the "Chats" panel of the App
- * chat widget. Any context, base thread and `?chat=` partitions, newest first.
- *
- * API: `api.php?r=system/get_ai_chat_threads/TemplServices¶ms[]=<agent id>`
- * → `{threads: [{thread_id, chat, context_pid, context_name, status, closed_reason,
- * title, preview, messages_count, created_ts, updated_ts}]}`.
- * The row whose `chat` / context matches the widget (or the open one, when the
- * widget has no `?chat=`) is the live conversation; the rest are read-only —
- * see serviceGetAiChatThread.
- */
- public function serviceGetAiChatThreads($iAgentId)
- {
- return BxDolAiTrigger::getInstance('chat')->listThreads($iAgentId);
- }
- /**
- * One of the caller's earlier conversations, read-only.
- *
- * API: `api.php?r=system/get_ai_chat_thread/TemplServices¶ms[]=<agent id>¶ms[]=<thread id>`
- * → `{messages, status, closed_reason, artifacts}`; 403 for a thread of someone else.
- */
- public function serviceGetAiChatThread($iAgentId, $sThreadId = '')
- {
- return BxDolAiTrigger::getInstance('chat')->getThread($iAgentId, $sThreadId);
- }
- }
- /** @} */
|