BxBaseServices.php 69 KB

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