BxBaseServices.php 65 KB

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