BxBaseServices.php 73 KB

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