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. '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. if ($bIsApi)
  761. return [bx_api_get_block('ai_agent', [
  762. 'agent_id' => $iId,
  763. 'agent_profile' => BxDolProfile::getData($aAgent['profile_id']),
  764. 'context_profile_id' => $iContextPid,
  765. 'hidden_first_message' => (string)($aAgent['hidden_first_message'] ?? ''),
  766. ])];
  767. $sEndpoint = BX_DOL_URL_ROOT . 'sys-ai-chat/' . (int)$iId;
  768. if ($iContextPid > 0)
  769. $sEndpoint .= '&context=' . $iContextPid;
  770. $oTemplate = BxDolTemplate::getInstance();
  771. $oTemplate->addJs([BX_DOL_URL_ROOT . 'plugins_public/bundle.js']);
  772. return $oTemplate->parseHtmlByName('agent_ai_chat.html', [
  773. 'id' => (int)$iId,
  774. 'context_profile_id' => (int)$iContextPid,
  775. 'endpoint_js' => json_encode($sEndpoint),
  776. 'bundle_url' => BX_DOL_URL_ROOT . 'plugins_public/bundle.js',
  777. ]);
  778. }
  779. public function serviceGetMenu($aParams)
  780. {
  781. $bIsApi = bx_is_api();
  782. $mixedResulEmpty = $bIsApi ? [] : '';
  783. if($bIsApi && is_string($aParams))
  784. $aParams = bx_api_get_browse_params($aParams);
  785. if(!isset($aParams['object']))
  786. return $mixedResulEmpty;
  787. $oMenu = BxDolMenu::getObjectInstance($aParams['object']);
  788. if(!$oMenu)
  789. return $mixedResulEmpty;
  790. if(!empty($aParams['params']) && is_array($aParams['params']))
  791. $oMenu->setContentParams($aParams['params']);
  792. return $bIsApi ? $oMenu->getCodeAPI() : $oMenu->getCode();
  793. }
  794. /**
  795. * @page service Service Calls
  796. * @section bx_system_general System Services
  797. * @subsection bx_system_general-general General
  798. * @subsubsection bx_system_general-get_site_submenu get_site_submenu
  799. *
  800. * @code bx_srv('system', 'get_site_submenu', [], 'TemplServices'); @endcode
  801. * @code {{~system:get_site_submenu:TemplServices[]~}} @endcode
  802. *
  803. * Get Site Submenu code.
  804. * @see BxBaseServices::serviceGetSiteSubmenu
  805. */
  806. /**
  807. * @ref bx_system_general-get_site_submenu "get_site_submenu"
  808. */
  809. public function serviceGetSiteSubmenu()
  810. {
  811. $oMenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  812. return $oMenu ? $oMenu->getCode() : '';
  813. }
  814. /**
  815. * @page service Service Calls
  816. * @section bx_system_general System Services
  817. * @subsection bx_system_general-general General
  818. * @subsubsection bx_system_general-get_products_names get_products_names
  819. *
  820. * @code bx_srv('system', 'get_products_names', [], 'TemplServices');
  821. *
  822. * @code http://example.com/m/oauth2/com/get_products_names?module=system&class=BaseServices @endcode
  823. * @code http://hihi.una.io/modules/?r=oauth2/com/get_products_names&module=system&class=BaseServices @endcode
  824. *
  825. * Get an array of products names from all modules with payments functionality.
  826. * @param $iVendorId filter products by vendor ID.
  827. * @param $iLimit limit number of records from one module.
  828. * @return array of products where key id product name and value is module name
  829. *
  830. * @see BxBaseServices::serviceGetProductsNames
  831. */
  832. /**
  833. * @ref bx_system_general-get_products_names "get_products_names"
  834. */
  835. public function serviceGetProductsNames($iVendorId = 0, $iLimit = 1000)
  836. {
  837. $o = BxDolPayments::getInstance();
  838. if (!$o)
  839. return array();
  840. return $o->getProductsNames($iVendorId, $iLimit);
  841. }
  842. /**
  843. * @see iBxDolProfileService::serviceCheckSpacePrivacy
  844. */
  845. public function serviceCheckSpacePrivacy($iContentId)
  846. {
  847. return _t('_Access denied');
  848. }
  849. public function serviceFormsHelper ()
  850. {
  851. return new BxTemplAccountForms();
  852. }
  853. public function serviceActAsProfile ()
  854. {
  855. return false;
  856. }
  857. public function serviceGetModerators($iContentId)
  858. {
  859. $aModerators = BxDolAclQuery::getInstance()->getProfilesByMembership([
  860. MEMBERSHIP_ID_MODERATOR,
  861. MEMBERSHIP_ID_ADMINISTRATOR
  862. ]);
  863. $aIds = [];
  864. array_walk($aModerators, function ($aItem, $iKey, $aParams) {
  865. if(!empty($aItem['id']))
  866. $aParams[0][] = (int)$aItem['id'];
  867. }, [&$aIds]);
  868. return $aIds;
  869. }
  870. public function servicePrepareFields ($aFieldsProfile)
  871. {
  872. return $aFieldsProfile;
  873. }
  874. public function serviceProfilesSearch ($sTerm, $iLimit)
  875. {
  876. $oDb = BxDolAccountQuery::getInstance();
  877. $aRet = array();
  878. $a = $oDb->searchByTerm($sTerm, $iLimit);
  879. foreach ($a as $r)
  880. $aRet[] = array ('label' => $this->serviceProfileName($r['content_id']), 'value' => $r['profile_id']);
  881. return $aRet;
  882. }
  883. /**
  884. * @page service Service Calls
  885. * @section bx_system_general System Services
  886. * @subsection bx_system_general-general General
  887. * @subsubsection bx_system_general-keyword_search keyword_search
  888. *
  889. * @code bx_srv('system', 'keyword_search', ["bx_posts", ["keyword" => "test"}], 'TemplServices'); @endcode
  890. *
  891. * @code {{~system:keyword_search:TemplServices["bx_posts", {"keyword":"test"}]~}} @endcode
  892. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country", "keyword": "AU"}, "unit.html"]~}} @endcode
  893. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_state", "state":"NSW", "keyword": "AU"}, "unit.html"]~}} @endcode
  894. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"}, "unit.html"]~}} @endcode
  895. * @code {{~system:keyword_search:TemplServices["bx_posts", {"meta_type": "mention", "keyword": 2}, "unit_gallery.html"]~}} @endcode
  896. * @code {{~system:keyword_search:TemplServices["bx_posts", {"cat": "bx_posts_cats", "keyword": 3}, "unit_gallery.html"]~}} @endcode
  897. *
  898. * Search by keyword
  899. * @param $sSection - search object to search in, usually module name, for example: bx_posts
  900. * @param $aCondition - condition for search, supported conditions:
  901. * - search by keyword: ["keyword" => "test"]
  902. * - search by country: ["meta_type" => "location_country", "keyword" => "AU"]
  903. * - search by country and state: ["meta_type": "location_country_state", "state":"NSW", "keyword": "AU"]
  904. * - search by country, state and city: ["meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"]
  905. * - search for mentions: ["meta_type" => "mention", "keyword" => 2]
  906. * - search in category: ["cat": "bx_posts_cats", "keyword": 3]
  907. * @param $sTemplate - template for displaying search results, for example: unit.html
  908. * @param $iStart - paginate, display records starting from this number
  909. * @param $iPerPage - paginate, display this number of records per page
  910. * @param $bLiveSearch - search results like in live search
  911. *
  912. * @see BxBaseServices::serviceKeywordSearch
  913. */
  914. /**
  915. * @ref bx_system_general-keyword_search "keyword_search"
  916. */
  917. public function serviceKeywordSearch ($sSection, $aCondition, $sTemplate = '', $iStart = 0, $iPerPage = 0, $bLiveSearch = 0, $bPaginate = false)
  918. {
  919. if (!$sSection || !isset($aCondition['keyword']))
  920. return '';
  921. $sClass = 'BxTemplSearch';
  922. $sElsName = 'bx_elasticsearch';
  923. $sElsMethod = 'is_configured';
  924. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod)) {
  925. $oModule = BxDolModule::getInstance($sElsName);
  926. bx_import('Search', $oModule->_aModule);
  927. $sClass = 'BxElsSearch';
  928. }
  929. $oSearch = new $sClass(array($sSection));
  930. $oSearch->setLiveSearch($bLiveSearch);
  931. $oSearch->setMetaType(isset($aCondition['meta_type']) ? $aCondition['meta_type'] : '');
  932. $oSearch->setCategoryObject(isset($aCondition['cat']) ? $aCondition['cat'] : '');
  933. $oSearch->setCustomSearchCondition($aCondition);
  934. if (!$bPaginate)
  935. $oSearch->setRawProcessing(true);
  936. $oSearch->setCustomCurrentCondition(array(
  937. 'paginate' => array (
  938. 'start' => $iStart,
  939. 'perPage' => $iPerPage ? $iPerPage : BX_DOL_SEARCH_RESULTS_PER_PAGE_DEFAULT,
  940. )));
  941. if ($sTemplate)
  942. $oSearch->setUnitTemplate($sTemplate);
  943. return $oSearch->response();
  944. }
  945. /**
  946. * @page service Service Calls
  947. * @section bx_system_general System Services
  948. * @subsection bx_system_general-general General
  949. * @subsubsection bx_system_general-keyword_search keyword_search
  950. *
  951. * @code bx_srv('system', 'search_keyword_form', 'TemplServices'); @endcode
  952. *
  953. * Block with Search by Keywords Form
  954. *
  955. * @see BxBaseServices::serviceSearchKeywordForm
  956. */
  957. /**
  958. * @ref bx_system_general-keyword_search "keyword_search"
  959. */
  960. public function serviceSearchKeywordForm ()
  961. {
  962. return $this->_getSearchObject()->getForm(BX_DB_PADDING_DEF, false, true);
  963. }
  964. /**
  965. * @page service Service Calls
  966. * @section bx_system_general System Services
  967. * @subsection bx_system_general-general General
  968. * @subsubsection bx_system_general-keyword_search keyword_search
  969. *
  970. * @code bx_srv('system', 'search_keyword_result', 'TemplServices'); @endcode
  971. *
  972. * Block with Search by Keywords Results
  973. *
  974. * @see BxBaseServices::serviceSearchKeywordResult
  975. */
  976. /**
  977. * @ref bx_system_general-keyword_search "keyword_search"
  978. */
  979. public function serviceSearchKeywordResult ()
  980. {
  981. $sType = bx_process_input(bx_get('type'));
  982. $sKeyword = bx_process_input(bx_get('keyword'));
  983. $bKeyword = $sKeyword !== false;
  984. if(bx_is_api())
  985. return $this->serviceGetDataSearchApi(['params' => [
  986. 'type' => $sType,
  987. 'keyword' => $sKeyword,
  988. 'section' => bx_process_input(bx_get('section')),
  989. 'cat' => bx_process_input(bx_get('cat'))
  990. ]]);
  991. $sCode = '';
  992. if($bKeyword) {
  993. $oSearch = $this->_getSearchObject();
  994. if(($sCode = $oSearch->response()))
  995. $sCode = BxDolTemplate::getInstance()->parseHtmlByName('search_result_block.html', [
  996. 'html_id' => 'bx-search-results-keyword',
  997. 'class' => 'bx-search-results-container',
  998. 'attrs' => '',
  999. 'content' => $sCode,
  1000. 'bx_if:do_center' => [
  1001. 'condition' => false,
  1002. 'content' => [
  1003. 'html_id' => '',
  1004. 'selector_content' => ''
  1005. ]
  1006. ]
  1007. ]);
  1008. else
  1009. $sCode = $oSearch->getEmptyResult();
  1010. }
  1011. return $sCode;
  1012. }
  1013. /**
  1014. * @ref bx_system_general-get_date_search_api "get_date_search_api"
  1015. * @api @ref bx_system_general-get_date_search_api "get_date_search_api"
  1016. */
  1017. public function serviceGetDataSearchApi ($aParams)
  1018. {
  1019. if(!bx_is_api())
  1020. return false;
  1021. if(is_string($aParams))
  1022. $aParams = bx_api_get_browse_params($aParams);
  1023. $bForceAll = ($aParams['params']['type'] ?? '') == 'keyword';
  1024. $aSectionsAvail = explode(',', getParam('sys_api_search_sections'));
  1025. $aSectionsAll = BxDolDb::getInstance()->fromCache(
  1026. 'sys_global_search_pairs',
  1027. 'getPairs',
  1028. 'SELECT `ObjectName` AS `name`, `Title` AS `title` FROM `sys_objects_search` WHERE `GlobalSearch`=\'1\' ORDER BY `Order` ASC',
  1029. 'name', 'title'
  1030. );
  1031. $aSections = [];
  1032. foreach($aSectionsAll as $sSectionName => $sSectionTitle)
  1033. if(in_array($sSectionName, $aSectionsAvail) || $bForceAll)
  1034. $aSections[$sSectionName] = [
  1035. 'name' => $sSectionName,
  1036. 'title' => _t($sSectionTitle)
  1037. ];
  1038. $aParamsBrowse = array_merge([
  1039. 'keyword' => '',
  1040. 'section' => '',
  1041. 'sections' => array_values($aSections),
  1042. 'start' => 0,
  1043. 'per_page' => 12
  1044. ], !empty($aParams['params']) && is_array($aParams['params']) ? $aParams['params'] : []);
  1045. if(empty($aParamsBrowse['section']))
  1046. $aParamsBrowse['section'] = array_keys($aSections);
  1047. else if(is_string($aParamsBrowse['section']))
  1048. $aParamsBrowse['section'] = explode(',', $aParamsBrowse['section']);
  1049. $sClass = 'BxTemplSearch';
  1050. $sSections = $aParamsBrowse['section'];
  1051. if ($aParamsBrowse['live'] !== true && count($sSections) > 1){
  1052. $aParamsBrowse['section'] = [];
  1053. $aParamsBrowse['sections'] = [];
  1054. $aDataRv = [];
  1055. foreach ($sSections as $sSection) {
  1056. $oSearch = new $sClass($sSection);
  1057. $oSearch->setLiveSearch(true);
  1058. $oSearch->setDataProcessing(true);
  1059. $oSearch->setCustomSearchCondition(['keyword' => $aParamsBrowse['keyword']]);
  1060. $oSearch->setCustomCurrentCondition([
  1061. 'paginate' => [
  1062. 'forceStart' => $aParamsBrowse['start'],
  1063. 'perPage' => $aParamsBrowse['per_page'],
  1064. ]
  1065. ]);
  1066. $aData = $oSearch->response();
  1067. if(count($aData) > $aParamsBrowse['per_page'])
  1068. $aData = array_slice($aData, $aParamsBrowse['start'], $aParamsBrowse['per_page']);
  1069. if (count($aData) > 0) {
  1070. $oSearchResult = $oSearch->getSearchResultObject($sSection);
  1071. $sSectionTitle = $oSearchResult->aCurrent['title'];
  1072. $aParamsBrowse['section'][] = $sSection;
  1073. $aParamsBrowse['sections'][] = ['name' => $sSection, 'title' => $sSectionTitle];
  1074. $aDataRv[] = [
  1075. 'section' => $sSection,
  1076. 'section_name' => $sSectionTitle,
  1077. 'data' => $aData,
  1078. 'is_profile' => bx_srv('system', 'is_module_profile', [$oSearchResult->aCurrent['module_name']])
  1079. ];
  1080. }
  1081. }
  1082. return [bx_api_get_block('search_sections', [
  1083. 'data' => $aDataRv,
  1084. 'params' => $aParamsBrowse
  1085. ])];
  1086. }
  1087. else{
  1088. $oSearch = new $sClass($aParamsBrowse['section']);
  1089. $oSearch->setLiveSearch(true);
  1090. $oSearch->setDataProcessing(true);
  1091. $oSearch->setCustomSearchCondition(['keyword' => $aParamsBrowse['keyword']]);
  1092. $oSearch->setCustomCurrentCondition([
  1093. 'paginate' => [
  1094. 'forceStart' => $aParamsBrowse['start'],
  1095. 'perPage' => $aParamsBrowse['per_page'],
  1096. ]
  1097. ]);
  1098. $aData = $oSearch->response();
  1099. if(count($aData) > $aParamsBrowse['per_page'])
  1100. $aData = array_slice($aData, $aParamsBrowse['start'], $aParamsBrowse['per_page']);
  1101. return [
  1102. bx_api_get_block('browse', [
  1103. 'unit' => 'search-results',
  1104. 'request_url' => '/api.php?r=system/get_data_search_api/TemplServices&params[]=',
  1105. 'params' => $aParamsBrowse,
  1106. 'data' => $aData
  1107. ])
  1108. ];
  1109. }
  1110. }
  1111. /**
  1112. * @page service Service Calls
  1113. * @section bx_system_general System Services
  1114. * @subsection bx_system_general-general General
  1115. * @subsubsection bx_system_general-cmts cmts
  1116. *
  1117. * @code bx_srv('system', 'cmts', ["sys_blocks", 1], 'TemplServices'); @endcode
  1118. *
  1119. * @code {{~system:cmts:TemplServices["sys_blocks", 1]~}} @endcode
  1120. *
  1121. * Comments block
  1122. * @param $sObject - comments object name
  1123. * @param $sId - content id assiciated tith the comments
  1124. *
  1125. * @see BxBaseServices::serviceCmts
  1126. */
  1127. /**
  1128. * @ref bx_system_general-cmts "cmts"
  1129. */
  1130. public function serviceCmts ($sObject, $sId)
  1131. {
  1132. $o = BxDolCmts::getObjectInstance($sObject, $sId);
  1133. if (!$o || !$o->isEnabled())
  1134. return '';
  1135. return $o->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
  1136. }
  1137. public function _serviceProfileFunc ($sFunc, $iContentId, $aParams = array())
  1138. {
  1139. if (!$iContentId)
  1140. return false;
  1141. if (!($oAccount = BxDolAccount::getInstance($iContentId)))
  1142. return false;
  1143. return $oAccount->$sFunc(false, $aParams);
  1144. }
  1145. public function serviceAlertResponseProcessInstalled()
  1146. {
  1147. BxDolTranscoderImage::registerHandlersSystem();
  1148. }
  1149. public function serviceAlertResponseProcessStorageChange ($oAlert)
  1150. {
  1151. if ('sys_storage_default' != $oAlert->aExtras['option'])
  1152. return;
  1153. $aStorages = BxDolStorageQuery::getStorageObjects();
  1154. foreach ($aStorages as $r) {
  1155. if (0 == $r['current_size'] && 0 == $r['current_number'] && ($oStorage = BxDolStorage::getObjectInstance($r['object'])))
  1156. $oStorage->changeStorageEngine($oAlert->aExtras['value']);
  1157. }
  1158. }
  1159. public function serviceGetOptionsProfileBot()
  1160. {
  1161. $aResult = array(
  1162. array('key' => '', 'value' => _t('_Select_one'))
  1163. );
  1164. $aAccountsIds = BxDolAccountQuery::getInstance()->getOperators();
  1165. foreach($aAccountsIds as $iAccountId) {
  1166. $aProfilesIds = BxDolAccount::getInstance($iAccountId)->getProfilesIds(true, false);
  1167. foreach($aProfilesIds as $iProfileId) {
  1168. $oProfile = BxDolProfile::getInstance($iProfileId);
  1169. $aResult[] = array(
  1170. 'key' => $iProfileId,
  1171. 'value' => _t('_sys_profile_with_type', $oProfile->getDisplayName(), $oProfile->getModule()),
  1172. );
  1173. }
  1174. }
  1175. return $aResult;
  1176. }
  1177. public function serviceGetOptionsModuleListForPrivacySelector()
  1178. {
  1179. $aResult = array();
  1180. $BxDolModuleQuery = BxDolModuleQuery::getInstance();
  1181. $aModules = $BxDolModuleQuery->getModulesBy(array('type' => 'modules', 'active' => 1));
  1182. foreach($aModules as $aModule){
  1183. $oModule = BxDolModule::getInstance($aModule['name']);
  1184. if($oModule instanceof iBxDolContentInfoService){
  1185. if (!BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  1186. continue;
  1187. $aResult[$aModule['name']] = $aModule['title'];
  1188. }
  1189. }
  1190. return $aResult;
  1191. }
  1192. public function serviceGetOptionsCaptchaDefault()
  1193. {
  1194. $aResults = [];
  1195. $aObjects = BxDolCaptchaQuery::getObjects();
  1196. foreach($aObjects as $aObject)
  1197. $aResults[$aObject['object']] = $aObject['title'];
  1198. return $aResults;
  1199. }
  1200. public function serviceGetOptionsEmbedDefault()
  1201. {
  1202. $aResults = array(
  1203. '' => _t('_None')
  1204. );
  1205. $aObjects = BxDolEmbedQuery::getObjects();
  1206. foreach($aObjects as $aObject)
  1207. $aResults[$aObject['object']] = _t($aObject['title']);
  1208. return $aResults;
  1209. }
  1210. public function serviceGetOptionsLocationFieldDefault()
  1211. {
  1212. $aResults = array();
  1213. $aObjects = BxDolLocationFieldQuery::getObjects();
  1214. foreach($aObjects as $aObject)
  1215. $aResults[$aObject['object']] = _t($aObject['title']);
  1216. return $aResults;
  1217. }
  1218. public function serviceGetOptionsLocationMapDefault()
  1219. {
  1220. $aResults = array();
  1221. $aObjects = BxDolLocationMapQuery::getObjects();
  1222. foreach($aObjects as $aObject)
  1223. $aResults[$aObject['object']] = _t($aObject['title']);
  1224. return $aResults;
  1225. }
  1226. public function serviceGetOptionsPushDefault()
  1227. {
  1228. $aResults = [
  1229. '' => _t('_None')
  1230. ];
  1231. $aObjects = BxDolPushQuery::getObjects();
  1232. foreach($aObjects as $aObject)
  1233. $aResults[$aObject['object']] = $aObject['title'];
  1234. return $aResults;
  1235. }
  1236. public function serviceGetOptionsSmsDefault()
  1237. {
  1238. $aResults = [
  1239. '' => _t('_None')
  1240. ];
  1241. $aObjects = BxDolSmsQuery::getObjects();
  1242. foreach($aObjects as $aObject)
  1243. $aResults[$aObject['object']] = $aObject['title'];
  1244. return $aResults;
  1245. }
  1246. public function serviceGetOptionsSocketsFieldDefault()
  1247. {
  1248. $aResults = [];
  1249. $aObjects = ['sys_sockets_disabled', 'sys_sockets_soketi'];
  1250. foreach($aObjects as $sObject)
  1251. $aResults[$sObject] = _t('_adm_stg_cpt_option_sys_sockets_type_' . $sObject);
  1252. return $aResults;
  1253. }
  1254. public function serviceGetOptionsLocationLeafletGetProviders()
  1255. {
  1256. return BxDolLocationMapLeaflet::getProviders();
  1257. }
  1258. public function serviceGetOptionsRelations()
  1259. {
  1260. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
  1261. $aProfiles = array();
  1262. foreach($aModules as $aModule) {
  1263. $sMethod = 'act_as_profile';
  1264. if(!BxDolRequest::serviceExists($aModule['name'], $sMethod) || !BxDolService::call($aModule['name'], $sMethod))
  1265. continue;
  1266. $aProfiles[$aModule['name']] = _t('_' . $aModule['name']);
  1267. }
  1268. $aResults = array();
  1269. foreach($aProfiles as $sName1 => $sTitle1)
  1270. foreach($aProfiles as $sName2 => $sTitle2)
  1271. $aResults[$sName1 . '_' . $sName2] = $sTitle1 . ' - ' . $sTitle2;
  1272. return $aResults;
  1273. }
  1274. public function serviceGetOptionsCfProhibited()
  1275. {
  1276. return BxDolFormQuery::getDataItems('sys_content_filter');
  1277. }
  1278. public function serviceGetOptionsCfUnauthenticated()
  1279. {
  1280. return BxDolFormQuery::getDataItems('sys_content_filter');
  1281. }
  1282. public function serviceGetOptionsTaiwindDefault()
  1283. {
  1284. $sPath = BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'tailwind/css';
  1285. $aExcludes = ['.', '..', 'tailwind.css'];
  1286. $aResults = [];
  1287. if(($oHandle = opendir($sPath)) !== false) {
  1288. while(($sFile = readdir($oHandle)) !== false) {
  1289. if(in_array($sFile, $aExcludes))
  1290. continue;
  1291. if(($oHandlerFile = fopen($sPath . '/' . $sFile, 'r')) === false)
  1292. continue;
  1293. if(($sContent = fread($oHandlerFile, 1024)) !== false && strpos($sContent, '@tailwind base') === false)
  1294. $aResults[$sFile] = $sFile;
  1295. fclose($oHandlerFile);
  1296. }
  1297. closedir($oHandle);
  1298. }
  1299. /**
  1300. * Disabled for now, because CDN and custom compiled build with own styles
  1301. * don't work correctly together.
  1302. *
  1303. * $aResults['cdn'] = _t('_adm_stg_cpt_option_sys_css_tailwind_default_cdn');
  1304. */
  1305. return $aResults;
  1306. }
  1307. public function serviceGetOptionsIconsetDefault()
  1308. {
  1309. $aObjects = BxDolIconsetQuery::getObjects();
  1310. foreach($aObjects as $aObject)
  1311. $aResults[$aObject['object']] = $aObject['title'];
  1312. return $aResults;
  1313. }
  1314. public function serviceGetOptionsApiRootPageGuest()
  1315. {
  1316. $sKey = '_adm_stg_cpt_option_sys_api_root_page_';
  1317. return [
  1318. 'home' => _t($sKey .'home'),
  1319. 'splash' => _t($sKey . 'splash')
  1320. ];
  1321. }
  1322. public function serviceGetOptionsApiRootPageMember()
  1323. {
  1324. $sKey = '_adm_stg_cpt_option_sys_api_root_page_';
  1325. return [
  1326. 'home' => _t($sKey .'home'),
  1327. 'dashboard' => _t($sKey . 'dashboard'),
  1328. 'profile' => _t($sKey . 'profile')
  1329. ];
  1330. }
  1331. public function serviceGetOptionsApiMenuTop()
  1332. {
  1333. $aMenus = BxDolMenuQuery::getMenuObjects();
  1334. $aResults = ['' => _t('_sys_please_select')];
  1335. foreach($aMenus as $aMenu)
  1336. if($aMenu['module'] == 'system')
  1337. $aResults[$aMenu['object']] = _t($aMenu['title']);
  1338. return $aResults;
  1339. }
  1340. public function serviceGetOptionsApiContextSwitcher()
  1341. {
  1342. $aContexts = bx_srv('system', 'get_modules_by_type', ['context']);
  1343. $aResults = ['' => _t('_None')];
  1344. foreach($aContexts as $aContext)
  1345. $aResults[$aContext['name']] = _t('_' . $aContext['name']);
  1346. return $aResults;
  1347. }
  1348. public function serviceGetOptionsApiContextConnection()
  1349. {
  1350. $aConnections = ['subscriptions', 'fans', 'participants'];
  1351. $aResults = ['' => _t('_sys_please_select')];
  1352. foreach($aConnections as $sConnection)
  1353. $aResults[$sConnection] = _t('_adm_stg_cpt_option_sys_api_cnt_cnn_' . $sConnection);
  1354. return $aResults;
  1355. }
  1356. public function serviceGetOptionsAgentsModel()
  1357. {
  1358. return ['' => _t('_Select_one')] + BxDolAi::getInstance()->getModels(['active' => true]);
  1359. }
  1360. public function serviceGetOptionsAgentsProfile($bSelectOne = true, $sSelectOneLangKey = '_Select_one')
  1361. {
  1362. $aResult = [];
  1363. if($bSelectOne)
  1364. $aResult[] = ['key' => '', 'value' => _t($sSelectOneLangKey)];
  1365. $aAccountsIds = BxDolAccountQuery::getInstance()->getOperators();
  1366. foreach($aAccountsIds as $iAccountId) {
  1367. $aProfilesIds = BxDolAccount::getInstance($iAccountId)->getProfilesIds(true, false);
  1368. foreach($aProfilesIds as $iProfileId) {
  1369. $oProfile = BxDolProfile::getInstance($iProfileId);
  1370. $sProfileModule = false === $oProfile ? '' : $oProfile->getModule();
  1371. if ($sProfileModule && ($sProfileModule != 'system' || ($sProfileModule == 'system' && empty($oProfile->getAccountObject()->getEmail())))) {
  1372. $aResult[] = [
  1373. 'key' => $iProfileId,
  1374. 'value' => _t('_sys_profile_with_type', $oProfile->getDisplayName(), $sProfileModule === 'system' ? 'System' : _t('_' . $sProfileModule))
  1375. ];
  1376. }
  1377. }
  1378. }
  1379. return $aResult;
  1380. }
  1381. public function serviceRedirect($sUrl = false)
  1382. {
  1383. if (!getParam('sys_confirmation_before_redirect')) {
  1384. BxDolTemplate::getInstance()->displayPageNotFound();
  1385. exit;
  1386. }
  1387. if (false === $sUrl)
  1388. $sUrl = bx_get('url');
  1389. if (!$sUrl || !preg_match('@^https?://@', $sUrl)) {
  1390. http_response_code(500);
  1391. return MsgBox(_t('_error occured'));
  1392. }
  1393. else {
  1394. $bSpam = null;
  1395. /**
  1396. * @hooks
  1397. * @hookdef hook-system-check_spam_url 'system', 'check_spam_url' - hook to override sClass for search
  1398. * - $unit_name - equals `system`
  1399. * - $action - equals `check_spam_url`
  1400. * - $object_id - not used
  1401. * - $sender_id - logged account id
  1402. * - $extra_params - array of additional params with the following array keys:
  1403. * - `is_spam` - [bool] by ref, spam url or not, can be overridden in hook processing
  1404. * - `content` - [string] by ref, url of link, can be overridden in hook processing
  1405. * - `where` - [string] equal redirect
  1406. * @hook @ref hook-system-check_spam_url
  1407. */
  1408. bx_alert('system', 'check_spam_url', 0, getLoggedId(), array(
  1409. 'is_spam' => &$bSpam,
  1410. 'content' => &$sUrl,
  1411. 'is_spam_ref' => &$bSpam,
  1412. 'content_ref' => &$sUrl,
  1413. 'where' => 'redirect'
  1414. ));
  1415. $sLangKey = $bSpam ? '_sys_redirect_confirmation_harmful' : '_sys_redirect_confirmation';
  1416. return BxDolTemplate::getInstance()->parseHtmlByName('redirect.html', [
  1417. 'text' => _t($sLangKey, bx_process_output($sUrl), getParam('site_title')),
  1418. 'url' => bx_js_string($sUrl, BX_ESCAPE_STR_APOS),
  1419. ]);
  1420. }
  1421. }
  1422. public function serviceSetBadges($iContentId, $sBadgesIds, $sModule)
  1423. {
  1424. $aSelectedBadges = explode(",", $sBadgesIds);
  1425. $iPerformerId = bx_get_logged_profile_id();
  1426. $aCheck = checkActionModule($iPerformerId, 'set badge', 'system', false);
  1427. if(!isAdmin() && $aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1428. return false;
  1429. $oBadges = BxDolBadges::getInstance();
  1430. $oBadges->delete([
  1431. 'type' => 'by_module&object',
  1432. 'object_id' => $iContentId,
  1433. 'module' => $sModule
  1434. ]);
  1435. foreach ($aSelectedBadges as $iSelectedBadge)
  1436. $oBadges->add($iSelectedBadge, $iContentId, $sModule);
  1437. checkActionModule($iPerformerId, 'set badge', 'system', true);
  1438. return true;
  1439. }
  1440. public function serviceGetBadge($aBadge, $bIsCompact = false)
  1441. {
  1442. $sClass = '';
  1443. $sStyleFont = '';
  1444. $sStyleBg = '';
  1445. if ($aBadge['color'] == '')
  1446. $aBadge['color'] = 'purple-600';
  1447. if ($bIsCompact && $aBadge['icon'] != ''){
  1448. $aBadge['is_icon_only'] = 1;
  1449. }
  1450. if ($aBadge['is_icon_only'] == 1){
  1451. $sClass .= ' bx-badge-compact';
  1452. if (substr_count($aBadge['color'], 'rgb('))
  1453. $sStyleFont = 'color: ' . $aBadge['color'];
  1454. else
  1455. $sClass .= ' text-' . $aBadge['color'];
  1456. }
  1457. else{
  1458. if (substr_count($aBadge['color'], 'rgb('))
  1459. $sStyleBg = 'background-color: ' . $aBadge['color'];
  1460. else
  1461. $sClass .= ' bg-' . $aBadge['color'];
  1462. }
  1463. return BxDolTemplate::getInstance()->parseHtmlByName('badge.html', array(
  1464. 'bx_if:content' => array(
  1465. 'condition' => $aBadge['is_icon_only'] != '1',
  1466. 'content' => array('content' => _t($aBadge['text'])),
  1467. ),
  1468. 'bx_if:icon' => array(
  1469. 'condition' => $aBadge['icon'] != '',
  1470. 'content' => array('content' => BxDolTemplate::getInstance()->getIcon($aBadge['icon'], array('class' => 'bx-badge-icon sys-colored', 'style' => $sStyleFont))),
  1471. ),
  1472. 'title' => $aBadge['text'],
  1473. 'style_font' => $sStyleFont,
  1474. 'style_bg' => $sStyleBg,
  1475. 'class' => $sClass,
  1476. )
  1477. );
  1478. }
  1479. public function serviceGetFooter()
  1480. {
  1481. return BxDolTemplate::getInstance()->parseHtmlByName('footer.html', []);
  1482. }
  1483. private function _getSearchObject()
  1484. {
  1485. $sClass = 'BxTemplSearch';
  1486. $sElsName = 'bx_elasticsearch';
  1487. $sElsMethod = 'is_configured';
  1488. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod) && !bx_get('cat') && !bx_get('type')) {
  1489. $oModule = BxDolModule::getInstance($sElsName);
  1490. bx_import('Search', $oModule->_aModule);
  1491. $sClass = 'BxElsSearch';
  1492. }
  1493. /**
  1494. * @hooks
  1495. * @hookdef hook-system-search_keyword 'system', 'search_keyword' - hook to override sClass for search
  1496. * - $unit_name - equals `system`
  1497. * - $action - equals `search_keyword`
  1498. * - $object_id - not used
  1499. * - $sender_id - not used
  1500. * - $extra_params - array of additional params with the following array keys:
  1501. * - `override_result` - [string] by ref, class name for search, can be overridden in hook processing
  1502. * @hook @ref hook-system-search_keyword
  1503. */
  1504. bx_alert('system', 'search_keyword', 0, 0, array('class' => &$sClass, 'class_name_ref' => &$sClass));
  1505. $oSearch = new $sClass(bx_get('section'));
  1506. $oSearch->setLiveSearch(bx_get('live_search') ? 1 : 0);
  1507. $oSearch->setMetaType(bx_process_input(bx_get('type')));
  1508. $oSearch->setCategoryObject(bx_process_input(bx_get('cat')));
  1509. return $oSearch;
  1510. }
  1511. public function serviceHomeRedirect()
  1512. {
  1513. header("Location:" . BX_DOL_URL_ROOT, true, 301);
  1514. exit;
  1515. }
  1516. public function serviceProcessEmbed()
  1517. {
  1518. BxDolEmbed::getObjectInstance()->process();
  1519. }
  1520. public function serviceCallAgent($sType, $aAgent, $aParams)
  1521. {
  1522. $oAi = BxDolAi::getInstance();
  1523. return $oAi->callAgent($sType, $aAgent, $aParams);
  1524. }
  1525. public function serviceCallAgentForFormInput($iAgentId)
  1526. {
  1527. return BxDolAiTrigger::getInstance('form-input')->handle($iAgentId);
  1528. }
  1529. public function serviceAiChat($iAgentId)
  1530. {
  1531. return BxDolAiTrigger::getInstance('chat')->handle($iAgentId);
  1532. }
  1533. }
  1534. /** @} */