BxBaseServices.php 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489
  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. 'GetPageBlockData' => 'BxBaseServicePages',
  48. 'SetPageBlockData' => 'BxBaseServicePages',
  49. 'GetUrlInfo' => 'BxBaseServicePages',
  50. 'CreateAccountForm' => 'BxBaseServiceAccount',
  51. 'AccountSettingsEmail' => 'BxBaseServiceAccount',
  52. 'AccountSettingsPassword' => 'BxBaseServiceAccount',
  53. 'AccountSettingsDelAccount' => 'BxBaseServiceAccount',
  54. 'AccountSettingsInfo' => 'BxBaseServiceAccount',
  55. 'ForgotPassword' => 'BxBaseServiceAccount',
  56. 'SwitchProfile' => 'BxBaseServiceAccount',
  57. 'AccountProfileSwitcher' => 'BxBaseServiceAccount',
  58. 'EmailConfirmation' => 'BxBaseServiceAccount',
  59. 'ConfirmEmail' => 'BxBaseServiceAccount',
  60. 'CategoriesList' => 'BxBaseServiceCategory',
  61. 'Test' => 'BxBaseServiceLogin',
  62. 'MemberAuthCode' => 'BxBaseServiceLogin',
  63. 'LoginForm' => 'BxBaseServiceLogin',
  64. 'LoginFormOnly' => 'BxBaseServiceLogin',
  65. 'Logout' => 'BxBaseServiceLogin',
  66. 'KeywordsCloud' => 'BxBaseServiceMetatags',
  67. 'AccountProfileSwitcher' => 'BxBaseServiceProfiles',
  68. 'ProfileMembership' => 'BxBaseServiceProfiles',
  69. 'ProfileNotifications' => 'BxBaseServiceProfiles',
  70. 'GetCountOnlineProfiles' => 'BxBaseServiceProfiles',
  71. 'BrowseRecommendationsFriends' => 'BxBaseServiceProfiles',
  72. 'BrowseRecommendationsSubscriptions' => 'BxBaseServiceProfiles',
  73. 'BrowseFriends' => 'BxBaseServiceProfiles',
  74. 'SetMembership' => 'BxBaseServiceProfiles',
  75. 'BrowseFriendRequests' => 'BxBaseServiceProfiles',
  76. 'BrowseFriendRequested' => 'BxBaseServiceProfiles',
  77. 'BrowseSubscribedMe' => 'BxBaseServiceProfiles',
  78. 'BrowseSubscriptions' => 'BxBaseServiceProfiles',
  79. 'BrowseMembers' => 'BxBaseServiceProfiles',
  80. 'UpdateSettings' => 'BxBaseServiceProfiles',
  81. 'Befriend' => 'BxBaseServiceProfiles',
  82. 'GetChartGrowth' => 'BxBaseChartServices',
  83. 'GetChartStats' => 'BxBaseChartServices',
  84. 'GetDataByInterval' => 'BxBaseChartServices',
  85. 'GetCartItemsCount' => 'BxBasePaymentsServices',
  86. 'GetOrdersCount' => 'BxBasePaymentsServices',
  87. 'Do' => 'BxBaseReportServices',
  88. 'GetPerformedBy' => 'BxBaseReportServices',
  89. 'Do' => 'BxBaseVoteServices',
  90. 'GetPerformedBy' => 'BxBaseVoteServices',
  91. 'Perform' => 'BxBaseFeatureServices',
  92. 'Perform' => 'BxBaseServiceConnections',
  93. 'Perform' => 'BxBaseServiceRecommendations',
  94. 'GetDataApi' => 'BxBaseCmtsServices',
  95. 'GetDataApi' => 'BxBaseUploaderServices',
  96. 'GetStatBlock' => 'BxBaseDashboardServices',
  97. 'PerfomActionApi' => 'BxBaseServiceGrid',
  98. 'GetLabels' => 'BxBaseLabelsServices',
  99. 'GetForm' => 'BxBaseSearchExtendedServices',
  100. 'GetResults' => 'BxBaseSearchExtendedServices'
  101. );
  102. }
  103. public function serviceGetPreloaderContent($sName) {
  104. $sResult = '';
  105. switch($sName) {
  106. case 'icons':
  107. $sResult = getParam('sys_css_icons_default');
  108. break;
  109. case 'tailwind':
  110. $sFile = getParam('sys_css_tailwind_default');
  111. if(empty($sFile))
  112. $sFile = 'tailwind.min.css';
  113. $sResult = '{dir_plugins_public}tailwind/css/|' . $sFile;
  114. break;
  115. }
  116. return $sResult;
  117. }
  118. /**
  119. * @page service Service Calls
  120. * @section bx_system_general System Services
  121. * @subsection bx_system_general-general General
  122. * @subsubsection bx_system_general-module_check_for_update module_check_for_update
  123. *
  124. * @code bx_srv('system', 'module_check_for_update', ["bx_posts"]); @endcode
  125. * @code bx_srv('system', 'module_check_for_update', ["bx_posts"], 'TemplServices'); @endcode
  126. * @code {{~system:module_check_for_update:TemplServices["bx_posts"]~}} @endcode
  127. *
  128. * Checks whether an update is available for requested module or not.
  129. * @param $mixedModule - module ID/name to check the updates for.
  130. * @return array with information about the update, false if nothing was found
  131. *
  132. * @see BxBaseServices::serviceModuleCheckForUpdate
  133. */
  134. /**
  135. * @ref bx_system_general-module_check_for_update "module_check_for_update"
  136. */
  137. public function serviceModuleCheckForUpdate($mixedModule)
  138. {
  139. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  140. if(empty($aModule) || !is_array($aModule))
  141. return false;
  142. $aUpdates = BxDolStudioInstallerUtils::getInstance()->checkUpdatesByModule($aModule['name']);
  143. if(empty($aUpdates) || !is_array($aUpdates))
  144. return false;
  145. $aUpdate = array_shift($aUpdates);
  146. return array(
  147. 'version_from' => $aUpdate['file_version'],
  148. 'version_to' => $aUpdate['file_version_to'],
  149. 'file_id' => $aUpdate['file_id']
  150. );
  151. }
  152. /**
  153. * @page service Service Calls
  154. * @section bx_system_general System Services
  155. * @subsection bx_system_general-general General
  156. * @subsubsection bx_system_general-module_update module_update
  157. *
  158. * @code bx_srv('system', 'module_update', ["bx_posts"]); @endcode
  159. * @code bx_srv('system', 'module_update', ["bx_posts"], 'TemplServices'); @endcode
  160. * @code {{~system:module_update:TemplServices["bx_posts"]~}} @endcode
  161. *
  162. * Download and install an update for requested module. The operation may be performed
  163. * immediately or by Transient Cron task. The second way is more common.
  164. * @param $mixedModule - module ID/name to check the updates for.
  165. * @return integer value determining the result of the operation. It can be one of the following values:
  166. * BX_DOL_STUDIO_IU_RC_SUCCESS, BX_DOL_STUDIO_IU_RC_FAILED or BX_DOL_STUDIO_IU_RC_SCHEDULED.
  167. *
  168. * @see BxBaseServices::serviceModuleUpdate
  169. */
  170. /**
  171. * @ref bx_system_general-module_update "module_update"
  172. */
  173. public function serviceModuleUpdate($mixedModule)
  174. {
  175. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  176. if(empty($aModule) || !is_array($aModule))
  177. return BX_DOL_STUDIO_IU_RC_FAILED;
  178. $aResult = BxDolStudioInstallerUtils::getInstance()->downloadUpdatePublic($aModule['name'], true);
  179. return $aResult['code'];
  180. }
  181. /**
  182. * @page service Service Calls
  183. * @section bx_system_general System Services
  184. * @subsection bx_system_general-general General
  185. * @subsubsection bx_system_general-module_delete module_delete
  186. *
  187. * @code bx_srv('system', 'module_delete', ["bx_posts"]); @endcode
  188. * @code bx_srv('system', 'module_delete', ["bx_posts", true], 'TemplServices'); @endcode
  189. * @code {{~system:module_delete:TemplServices["bx_posts"]~}} @endcode
  190. *
  191. * Delete the requested module. By default only uninstalled module can be deleted.
  192. * The operation may be performed immediately or by Transient Cron task. The second way is more common.
  193. * @param $sModule - module name to delete.
  194. * @param $bForceUninstall - if 'true' is passed the module will be uninstalled before deletion.
  195. * @return integer value determining the result of the operation. It can be one of the following values:
  196. * BX_DOL_STUDIO_IU_RC_SUCCESS, BX_DOL_STUDIO_IU_RC_FAILED or BX_DOL_STUDIO_IU_RC_SCHEDULED.
  197. *
  198. * @see BxBaseServices::serviceModuleDelete
  199. */
  200. /**
  201. * @ref bx_system_general-module_delete "module_delete"
  202. */
  203. public function serviceModuleDelete($sModule, $bForceUninstall = false)
  204. {
  205. $sModulePath = '';
  206. $oInstallerUtils = BxDolStudioInstallerUtils::getInstance();
  207. $aModule = BxDolModuleQuery::getInstance()->getModuleByName($sModule, false);
  208. if(!empty($aModule) && is_array($aModule)) {
  209. if(!$bForceUninstall)
  210. return BX_DOL_STUDIO_IU_RC_FAILED;
  211. $sModulePath = $aModule['path'];
  212. $aResult = $oInstallerUtils->perform($sModulePath, 'uninstall', array('auto_disable' => $bForceUninstall));
  213. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  214. return BX_DOL_STUDIO_IU_RC_FAILED;
  215. }
  216. else {
  217. $aModules = $oInstallerUtils->getModules(false);
  218. if(!isset($aModules[$sModule]))
  219. return BX_DOL_STUDIO_IU_RC_FAILED;
  220. $sModulePath = $aModules[$sModule]['dir'];
  221. }
  222. $aResult = $oInstallerUtils->perform($sModulePath, 'delete');
  223. return $aResult['code'];
  224. }
  225. /**
  226. * @page service Service Calls
  227. * @section bx_system_general System Services
  228. * @subsection bx_system_general-general General
  229. * @subsubsection bx_system_general-module_install module_install
  230. *
  231. * @code bx_srv('system', 'module_install', ["bx_posts"]); @endcode
  232. * @code bx_srv('system', 'module_install', ["bx_posts", true], 'TemplServices'); @endcode
  233. * @code {{~system:module_install:TemplServices["bx_posts"]~}} @endcode
  234. *
  235. * Install the requested module. By default the module will be installed only.
  236. * @param $sModule - module name to install.
  237. * @param $bForceEnable - if 'true' is passed the module will be automatically enabled after installation.
  238. * @return boolean value determining the result of the operation.
  239. *
  240. * @see BxBaseServices::serviceModuleInstall
  241. */
  242. /**
  243. * @ref bx_system_general-module_install "module_install"
  244. */
  245. public function serviceModuleInstall($sModule, $bForceEnable = false)
  246. {
  247. $oInstallerUtils = BxDolStudioInstallerUtils::getInstance();
  248. $aModules = $oInstallerUtils->getModules(false);
  249. if(!isset($aModules[$sModule]))
  250. return false;
  251. $aResult = $oInstallerUtils->perform($aModules[$sModule]['dir'], 'install', array('auto_enable' => $bForceEnable));
  252. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  253. return false;
  254. return true;
  255. }
  256. /**
  257. * @page service Service Calls
  258. * @section bx_system_general System Services
  259. * @subsection bx_system_general-general General
  260. * @subsubsection bx_system_general-module_uninstall module_uninstall
  261. *
  262. * @code bx_srv('system', 'module_uninstall', ["bx_posts"]); @endcode
  263. * @code bx_srv('system', 'module_uninstall', ["bx_posts", true], 'TemplServices'); @endcode
  264. * @code {{~system:module_uninstall:TemplServices["bx_posts"]~}} @endcode
  265. *
  266. * Uninstall the requested module. By default only disabled module can be uninstalled.
  267. * @param $mixedModule - module ID/name to uninstall.
  268. * @param $bForceDisable - if 'true' is passed the module will be automatically disabled before uninstallation.
  269. * @return boolean value determining the result of the operation.
  270. *
  271. * @see BxBaseServices::serviceModuleUninstall
  272. */
  273. /**
  274. * @ref bx_system_general-module_uninstall "module_uninstall"
  275. */
  276. public function serviceModuleUninstall($mixedModule, $bForceDisable = false)
  277. {
  278. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  279. if(empty($aModule) || !is_array($aModule))
  280. return false;
  281. if((int)$aModule['enabled'] != 0 && !$bForceDisable)
  282. return false;
  283. $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aModule['path'], 'uninstall', array('auto_disable' => $bForceDisable));
  284. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  285. return false;
  286. return true;
  287. }
  288. /**
  289. * @page service Service Calls
  290. * @section bx_system_general System Services
  291. * @subsection bx_system_general-general General
  292. * @subsubsection bx_system_general-module_enable module_enable
  293. *
  294. * @code bx_srv('system', 'module_enable', ["bx_posts"]); @endcode
  295. * @code bx_srv('system', 'module_enable', ["bx_posts"], 'TemplServices'); @endcode
  296. * @code {{~system:module_enable:TemplServices["bx_posts"]~}} @endcode
  297. *
  298. * Enable the requested module.
  299. * @param $mixedModule - module ID/name to enable.
  300. * @return boolean value determining the result of the operation.
  301. *
  302. * @see BxBaseServices::serviceModuleEnable
  303. */
  304. /**
  305. * @ref bx_system_general-module_enable "module_enable"
  306. */
  307. public function serviceModuleEnable($mixedModule)
  308. {
  309. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  310. if(empty($aModule) || !is_array($aModule))
  311. return false;
  312. if((int)$aModule['enabled'] != 0)
  313. return false;
  314. $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aModule['path'], 'enable');
  315. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  316. return false;
  317. return true;
  318. }
  319. /**
  320. * @page service Service Calls
  321. * @section bx_system_general System Services
  322. * @subsection bx_system_general-general General
  323. * @subsubsection bx_system_general-module_disable module_disable
  324. *
  325. * @code bx_srv('system', 'module_disable', ["bx_posts"]); @endcode
  326. * @code bx_srv('system', 'module_disable', ["bx_posts"], 'TemplServices'); @endcode
  327. * @code {{~system:module_disable:TemplServices["bx_posts"]~}} @endcode
  328. *
  329. * Disable the requested module.
  330. * @param $mixedModule - module ID/name to disable.
  331. * @return boolean value determining the result of the operation.
  332. *
  333. * @see BxBaseServices::serviceModuleDisable
  334. */
  335. /**
  336. * @ref bx_system_general-module_disable "module_disable"
  337. */
  338. public function serviceModuleDisable($mixedModule)
  339. {
  340. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  341. if(empty($aModule) || !is_array($aModule))
  342. return false;
  343. if((int)$aModule['enabled'] == 0)
  344. return false;
  345. $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aModule['path'], 'disable');
  346. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  347. return false;
  348. return true;
  349. }
  350. /**
  351. * @page service Service Calls
  352. * @section bx_system_general System Services
  353. * @subsection bx_system_general-general General
  354. * @subsubsection bx_system_general-is_module_installed is_module_installed
  355. *
  356. * @code bx_srv('system', 'is_module_installed', ["bx_posts"]); @endcode
  357. * @code bx_srv('system', 'is_module_installed', ["bx_posts"], 'TemplServices'); @endcode
  358. * @code {{~system:is_module_installed:TemplServices["bx_posts"]~}} @endcode
  359. *
  360. * Checks whether the requested module is installed or not.
  361. * @param $mixedModule - module ID/name to check.
  362. * @return boolean value determining the result of the operation.
  363. *
  364. * @see BxBaseServices::serviceIsModuleInstalled
  365. */
  366. /**
  367. * @ref bx_system_general-is_module_installed "is_module_installed"
  368. */
  369. public function serviceIsModuleInstalled($mixedModule)
  370. {
  371. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  372. return !empty($aModule) && is_array($aModule);
  373. }
  374. /**
  375. * @page service Service Calls
  376. * @section bx_system_general System Services
  377. * @subsection bx_system_general-general General
  378. * @subsubsection bx_system_general-is_module_enabled is_module_enabled
  379. *
  380. * @code bx_srv('system', 'is_module_enabled', ["bx_posts"]); @endcode
  381. * @code bx_srv('system', 'is_module_enabled', ["bx_posts"], 'TemplServices'); @endcode
  382. * @code {{~system:is_module_enabled:TemplServices["bx_posts"]~}} @endcode
  383. *
  384. * Checks whether the requested module is enabled or not.
  385. * @param $mixedModule - module ID/name to check.
  386. * @return boolean value determining the result of the operation.
  387. *
  388. * @see BxBaseServices::serviceIsModuleEnabled
  389. */
  390. /**
  391. * @ref bx_system_general-is_module_enabled "is_module_enabled"
  392. */
  393. public function serviceIsModuleEnabled($mixedModule)
  394. {
  395. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  396. return !empty($aModule) && is_array($aModule) && (int)$aModule['enabled'] != 0;
  397. }
  398. /**
  399. * Checks whether a module is a 'Content' module or not.
  400. *
  401. * @param string $mixedModule - module name or an instance of Module class.
  402. * @return boolean result of operation.
  403. */
  404. public function serviceIsModuleContent($mixedModule)
  405. {
  406. if($mixedModule instanceof BxDolModule)
  407. $mixedModule = $mixedModule->getName();
  408. return BxDolModuleQuery::getInstance()->isModuleContent($mixedModule);
  409. }
  410. /**
  411. * Checks whether a module is a 'Context' module or not.
  412. *
  413. * @param string $mixedModule - module name or an instance of Module class.
  414. * @return boolean result of operation.
  415. */
  416. public function serviceIsModuleContext($mixedModule)
  417. {
  418. if($mixedModule instanceof BxDolModule)
  419. $mixedModule = $mixedModule->getName();
  420. return BxDolModuleQuery::getInstance()->isModuleContext($mixedModule);
  421. }
  422. /**
  423. * Checks whether a module is a 'Profile' module or not.
  424. *
  425. * @param string $mixedModule - module name or an instance of Module class.
  426. * @return boolean result of operation.
  427. */
  428. public function serviceIsModuleProfile($mixedModule)
  429. {
  430. if($mixedModule instanceof BxDolModule)
  431. $mixedModule = $mixedModule->getName();
  432. return BxDolModuleQuery::getInstance()->isModuleProfile($mixedModule);
  433. }
  434. /**
  435. * Get modules by type. Available types are 'content', 'context', 'profile'.
  436. *
  437. * @param type $sType - string with type.
  438. * @return array of modules.
  439. */
  440. public function serviceGetModulesByType($sType, $aParams = [])
  441. {
  442. $oModuleQuery = BxDolModuleQuery::getInstance();
  443. if(!$oModuleQuery->checkModulesSubtypes()) {
  444. $oInstallerUtils = new BxDolInstallerUtils();
  445. $aModules = $oModuleQuery->getModulesBy(['type' => 'modules']);
  446. foreach($aModules as $aModule)
  447. if(($iModuleSubtypes = $oInstallerUtils->getSubtypes($aModule['name'])) != 0)
  448. $oModuleQuery->updateModule(['subtypes' => $iModuleSubtypes], ['id' => $aModule['id']]);
  449. }
  450. $iSubtypes = 0;
  451. switch($sType) {
  452. case 'content';
  453. $iSubtypes = BX_DOL_MODULE_SUBTYPE_TEXT;
  454. break;
  455. case 'context';
  456. $iSubtypes = BX_DOL_MODULE_SUBTYPE_CONTEXT;
  457. break;
  458. case 'profile';
  459. $iSubtypes = BX_DOL_MODULE_SUBTYPE_PROFILE;
  460. break;
  461. }
  462. $aResults = $oModuleQuery->getModulesBy(array_merge([
  463. 'type' => 'modules_subtypes',
  464. 'value' => $iSubtypes,
  465. 'active' => 1
  466. ], array_intersect_key($aParams, array_flip(['id_as_key', 'name_as_key']))));
  467. return $aResults;
  468. }
  469. public function serviceProfileUnit ($iContentId, $aParams = array())
  470. {
  471. return $this->_serviceProfileFunc('getUnit', $iContentId, $aParams);
  472. }
  473. public function serviceHasImage ($iContentId)
  474. {
  475. return false;
  476. }
  477. public function serviceProfilePicture ($iContentId)
  478. {
  479. return BxDolTemplate::getInstance()->getImageUrl('account.svg');
  480. }
  481. public function serviceProfileAvatar ($iContentId)
  482. {
  483. return BxDolTemplate::getInstance()->getImageUrl('account.svg');
  484. }
  485. public function serviceProfileCover ($iContentId)
  486. {
  487. return '';
  488. }
  489. public function serviceProfileEditUrl ($iContentId)
  490. {
  491. return bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=account-settings-info'));
  492. }
  493. public function serviceProfileThumb ($iContentId)
  494. {
  495. return $this->_serviceProfileFunc('getThumb', $iContentId);
  496. }
  497. public function serviceProfileIcon ($iContentId)
  498. {
  499. return $this->_serviceProfileFunc('getIcon', $iContentId);
  500. }
  501. public function serviceProfileName ($iContentId)
  502. {
  503. return $this->_serviceProfileFunc('getDisplayName', $iContentId);
  504. }
  505. public function serviceProfileUrl ($iContentId)
  506. {
  507. return $this->_serviceProfileFunc('getUrl', $iContentId);
  508. }
  509. /**
  510. * @see iBxDolProfileService::serviceCheckAllowedProfileView
  511. */
  512. public function serviceCheckAllowedProfileView($iContentId)
  513. {
  514. return _t('_Access denied');
  515. }
  516. /**
  517. * @see iBxDolProfileService::serviceCheckAllowedProfileContact
  518. */
  519. public function serviceCheckAllowedProfileContact($iContentId)
  520. {
  521. return _t('_Access denied');
  522. }
  523. /**
  524. * @see iBxDolProfileService::serviceCheckAllowedPostInProfile
  525. */
  526. public function serviceCheckAllowedPostInProfile($iContentId, $sPostModule = '')
  527. {
  528. return _t('_Access denied');
  529. }
  530. /**
  531. * @see iBxDolProfileService::serviceCheckAllowedModuleActionInProfile
  532. */
  533. public function serviceCheckAllowedModuleActionInProfile($iContentId, $sPostModule, $sActionName)
  534. {
  535. return _t('_Access denied');
  536. }
  537. /**
  538. * @see iBxDolProfileService::serviceGetSpaceTitle
  539. */
  540. public function serviceGetSpaceTitle()
  541. {
  542. return '';
  543. }
  544. /**
  545. * @see iBxDolProfileService::serviceGetParticipatingProfiles
  546. */
  547. public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObject = false)
  548. {
  549. return array();
  550. }
  551. /**
  552. * @page service Service Calls
  553. * @section bx_system_general System Services
  554. * @subsection bx_system_general-general General
  555. * @subsubsection bx_system_general-get_create_post_form get_create_post_form
  556. *
  557. * @code bx_srv('system', 'get_create_post_form', [false, "bx_posts"], 'TemplServices'); @endcode
  558. * @code {{~system:get_create_post_form:TemplServices[false,"bx_posts"]~}} @endcode
  559. *
  560. * Get United Create Post form.
  561. * @param $mixedContextId - context which the post will be created in:
  562. * - false = 'Public' post form;
  563. * - 0 = 'Profile' post form, which allows to post in your own profile and connections;
  564. * - n = 'Context' post form, which allows to post in context (3d party profile, group, event, etc).
  565. * @param $sDefault - tab selected by default.
  566. * @param $aCustom - an array with custom paramaters.
  567. * @return string with form content
  568. *
  569. * @see BxBaseServices::serviceGetCreatePostForm
  570. */
  571. /**
  572. * @ref bx_system_general-get_create_post_form "get_create_post_form"
  573. */
  574. public function serviceGetCreatePostForm($mixedContextId = false, $sDefault = '', $aCustom = array())
  575. {
  576. if(!isLogged() || ($mixedContextId !== false && !is_numeric($mixedContextId)))
  577. return '';
  578. $oProfile = BxDolProfile::getInstance();
  579. if(!$oProfile)
  580. return '';
  581. if($mixedContextId !== false)
  582. $mixedContextId = (int)(!empty($mixedContextId) ? -$mixedContextId : $oProfile->id());
  583. $oMenu = BxDolMenu::getObjectInstance('sys_create_post');
  584. if(!$oMenu)
  585. return '';
  586. $oMenu->setContextId($mixedContextId);
  587. $aMenuItems = $oMenu->getMenuItems();
  588. if(empty($aMenuItems) || !is_array($aMenuItems))
  589. return '';
  590. if(empty($sDefault)) {
  591. $aDefault = array_shift($aMenuItems);
  592. $sDefault = !empty($aDefault['module']) ? $aDefault['module'] : $aDefault['name'];
  593. }
  594. $oMenu->setSelected($sDefault, $sDefault);
  595. $bContext = $mixedContextId !== false;
  596. if($bContext && ($aContextInfo = BxDolProfileQuery::getInstance()->getInfoById(abs($mixedContextId))))
  597. if(bx_srv($aContextInfo['type'], 'check_allowed_post_in_profile', [$aContextInfo['content_id'], $sDefault]) !== CHECK_ACTION_RESULT_ALLOWED)
  598. return '';
  599. $sTitle = _t('_sys_page_block_title_create_post' . (!$bContext ? '_public' : ($mixedContextId < 0 ? '_context' : '')));
  600. $sPlaceholder = _t('_sys_txt_create_post_placeholder', $oProfile->getDisplayName());
  601. $oDbModules = BxDolModuleQuery::getInstance();
  602. $oTemplate = BxDolTemplate::getInstance();
  603. $oTemplate->addJs(['BxDolCreatePost.js']);
  604. $aPreloadingList = [];
  605. $aModules = explode(',', getParam('sys_create_post_form_preloading_list'));
  606. if(!empty($aModules))
  607. foreach($aModules as $sModule) {
  608. $aModule = $oDbModules->getModuleByName($sModule);
  609. if(empty($aModule) || !is_array($aModule))
  610. continue;
  611. $aPreloadingList[$sModule] = $aModule['uri'];
  612. }
  613. if(bx_is_api()) {
  614. return [
  615. 'title' => $sTitle,
  616. 'content' => '',
  617. 'menu' => $oMenu->getCodeAPI()
  618. ];
  619. }
  620. $sJsObject = 'oBxDolCreatePost';
  621. $sJsContent = $oTemplate->_wrapInTagJsCode("var " . $sJsObject . " = new BxDolCreatePost(" . json_encode([
  622. 'sObjName' => $sJsObject,
  623. 'sRootUrl' => BX_DOL_URL_ROOT,
  624. 'sDefault' => $sDefault,
  625. 'iContextId' => $bContext ? $mixedContextId : 0,
  626. 'oPreloadingList' => $aPreloadingList,
  627. 'oCustom' => $aCustom
  628. ]) . ");");
  629. return [
  630. 'title' => $sTitle,
  631. 'content' => $oTemplate->parseHtmlByName('create_post_form.html', [
  632. 'default' => $sDefault,
  633. 'placeholder' => $sPlaceholder,
  634. 'user_thumb' => $oProfile->getUnit(0, ['template' => 'unit_wo_info_links']),
  635. 'form' => bx_srv($sDefault, 'get_create_post_form', [[
  636. 'context_id' => $mixedContextId,
  637. 'ajax_mode' => true,
  638. 'absolute_action_url' => true,
  639. 'custom' => $aCustom
  640. ]]),
  641. 'js_object' => $sJsObject,
  642. 'js_content' => $sJsContent
  643. ]),
  644. 'menu' => $oMenu
  645. ];
  646. }
  647. public function serviceGetOptionsCreatePostFormPreloadingList()
  648. {
  649. $oMenu = BxDolMenu::getObjectInstance('sys_create_post');
  650. if(!$oMenu)
  651. return [];
  652. $aMenuItems = $oMenu->getMenuItems();
  653. $aResult = [];
  654. foreach($aMenuItems as $aMenuItem) {
  655. $sModule = !empty($aMenuItem['module']) ? $aMenuItem['module'] : $aMenuItem['name'];
  656. if(!bx_srv('system', 'is_module_enabled', [$sModule]))
  657. continue;
  658. $aResult[] = [
  659. 'key' => $sModule,
  660. 'value' => _t('_' . $sModule)
  661. ];
  662. }
  663. return $aResult;
  664. }
  665. public function serviceGetBlockAuthor($sModule, $iContentId = 0)
  666. {
  667. if(!$iContentId && bx_get('id') !== false)
  668. $iContentId = (int)bx_get('id');
  669. $sMethodGetAuthor = 'get_author';
  670. if(!$sModule || !$iContentId || !BxDolRequest::serviceExists($sModule, $sMethodGetAuthor))
  671. return '';
  672. $iAuthor = bx_srv($sModule, $sMethodGetAuthor, [$iContentId]);
  673. if(!$iAuthor)
  674. return '';
  675. $oAuthor = BxDolProfile::getInstance($iAuthor);
  676. if(!$oAuthor)
  677. return '';
  678. $sModuleAuthor = $oAuthor->getModule();
  679. $sMethodGetCover = 'entity_cover';
  680. if(!BxDolRequest::serviceExists($sModuleAuthor, $sMethodGetCover))
  681. return '';
  682. return bx_srv($sModuleAuthor, $sMethodGetCover, [$oAuthor->getContentId(), [
  683. 'use_as_author' => true,
  684. 'show_text' => false
  685. ]]);
  686. }
  687. public function serviceGetBlockAskAssistant($aParams = [])
  688. {
  689. $iAssistant = BxDolAI::getAssistantForAskBlock();
  690. if(!$iAssistant)
  691. return '';
  692. return BxDolAIAssistant::getObjectInstance($iAssistant)->getAskBlock($aParams);
  693. }
  694. public function serviceGetMenu($aParams)
  695. {
  696. $bIsApi = bx_is_api();
  697. $mixedResulEmpty = $bIsApi ? [] : '';
  698. if($bIsApi && is_string($aParams))
  699. $aParams = bx_api_get_browse_params($aParams);
  700. if(!isset($aParams['object']))
  701. return $mixedResulEmpty;
  702. $oMenu = BxDolMenu::getObjectInstance($aParams['object']);
  703. if(!$oMenu)
  704. return $mixedResulEmpty;
  705. if(!empty($aParams['params']) && is_array($aParams['params']))
  706. $oMenu->setContentParams($aParams['params']);
  707. return $bIsApi ? $oMenu->getCodeAPI() : $oMenu->getCode();
  708. }
  709. /**
  710. * @page service Service Calls
  711. * @section bx_system_general System Services
  712. * @subsection bx_system_general-general General
  713. * @subsubsection bx_system_general-get_site_submenu get_site_submenu
  714. *
  715. * @code bx_srv('system', 'get_site_submenu', [], 'TemplServices'); @endcode
  716. * @code {{~system:get_site_submenu:TemplServices[]~}} @endcode
  717. *
  718. * Get Site Submenu code.
  719. * @see BxBaseServices::serviceGetSiteSubmenu
  720. */
  721. /**
  722. * @ref bx_system_general-get_site_submenu "get_site_submenu"
  723. */
  724. public function serviceGetSiteSubmenu()
  725. {
  726. $oMenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  727. return $oMenu ? $oMenu->getCode() : '';
  728. }
  729. /**
  730. * @page service Service Calls
  731. * @section bx_system_general System Services
  732. * @subsection bx_system_general-general General
  733. * @subsubsection bx_system_general-get_products_names get_products_names
  734. *
  735. * @code bx_srv('system', 'get_products_names', [], 'TemplServices');
  736. *
  737. * @code http://example.com/m/oauth2/com/get_products_names?module=system&class=BaseServices @endcode
  738. * @code http://hihi.una.io/modules/?r=oauth2/com/get_products_names&module=system&class=BaseServices @endcode
  739. *
  740. * Get an array of products names from all modules with payments functionality.
  741. * @param $iVendorId filter products by vendor ID.
  742. * @param $iLimit limit number of records from one module.
  743. * @return array of products where key id product name and value is module name
  744. *
  745. * @see BxBaseServices::serviceGetProductsNames
  746. */
  747. /**
  748. * @ref bx_system_general-get_products_names "get_products_names"
  749. */
  750. public function serviceGetProductsNames($iVendorId = 0, $iLimit = 1000)
  751. {
  752. $o = BxDolPayments::getInstance();
  753. if (!$o)
  754. return array();
  755. return $o->getProductsNames($iVendorId, $iLimit);
  756. }
  757. /**
  758. * @see iBxDolProfileService::serviceCheckSpacePrivacy
  759. */
  760. public function serviceCheckSpacePrivacy($iContentId)
  761. {
  762. return _t('_Access denied');
  763. }
  764. public function serviceFormsHelper ()
  765. {
  766. return new BxTemplAccountForms();
  767. }
  768. public function serviceActAsProfile ()
  769. {
  770. return false;
  771. }
  772. public function servicePrepareFields ($aFieldsProfile)
  773. {
  774. return $aFieldsProfile;
  775. }
  776. public function serviceProfilesSearch ($sTerm, $iLimit)
  777. {
  778. $oDb = BxDolAccountQuery::getInstance();
  779. $aRet = array();
  780. $a = $oDb->searchByTerm($sTerm, $iLimit);
  781. foreach ($a as $r)
  782. $aRet[] = array ('label' => $this->serviceProfileName($r['content_id']), 'value' => $r['profile_id']);
  783. return $aRet;
  784. }
  785. /**
  786. * @page service Service Calls
  787. * @section bx_system_general System Services
  788. * @subsection bx_system_general-general General
  789. * @subsubsection bx_system_general-keyword_search keyword_search
  790. *
  791. * @code bx_srv('system', 'keyword_search', ["bx_posts", ["keyword" => "test"}], 'TemplServices'); @endcode
  792. *
  793. * @code {{~system:keyword_search:TemplServices["bx_posts", {"keyword":"test"}]~}} @endcode
  794. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country", "keyword": "AU"}, "unit.html"]~}} @endcode
  795. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_state", "state":"NSW", "keyword": "AU"}, "unit.html"]~}} @endcode
  796. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"}, "unit.html"]~}} @endcode
  797. * @code {{~system:keyword_search:TemplServices["bx_posts", {"meta_type": "mention", "keyword": 2}, "unit_gallery.html"]~}} @endcode
  798. * @code {{~system:keyword_search:TemplServices["bx_posts", {"cat": "bx_posts_cats", "keyword": 3}, "unit_gallery.html"]~}} @endcode
  799. *
  800. * Search by keyword
  801. * @param $sSection - search object to search in, usually module name, for example: bx_posts
  802. * @param $aCondition - condition for search, supported conditions:
  803. * - search by keyword: ["keyword" => "test"]
  804. * - search by country: ["meta_type" => "location_country", "keyword" => "AU"]
  805. * - search by country and state: ["meta_type": "location_country_state", "state":"NSW", "keyword": "AU"]
  806. * - search by country, state and city: ["meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"]
  807. * - search for mentions: ["meta_type" => "mention", "keyword" => 2]
  808. * - search in category: ["cat": "bx_posts_cats", "keyword": 3]
  809. * @param $sTemplate - template for displaying search results, for example: unit.html
  810. * @param $iStart - paginate, display records starting from this number
  811. * @param $iPerPage - paginate, display this number of records per page
  812. * @param $bLiveSearch - search results like in live search
  813. *
  814. * @see BxBaseServices::serviceKeywordSearch
  815. */
  816. /**
  817. * @ref bx_system_general-keyword_search "keyword_search"
  818. */
  819. public function serviceKeywordSearch ($sSection, $aCondition, $sTemplate = '', $iStart = 0, $iPerPage = 0, $bLiveSearch = 0, $bPaginate = false)
  820. {
  821. if (!$sSection || !isset($aCondition['keyword']))
  822. return '';
  823. $sClass = 'BxTemplSearch';
  824. $sElsName = 'bx_elasticsearch';
  825. $sElsMethod = 'is_configured';
  826. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod)) {
  827. $oModule = BxDolModule::getInstance($sElsName);
  828. bx_import('Search', $oModule->_aModule);
  829. $sClass = 'BxElsSearch';
  830. }
  831. $oSearch = new $sClass(array($sSection));
  832. $oSearch->setLiveSearch($bLiveSearch);
  833. $oSearch->setMetaType(isset($aCondition['meta_type']) ? $aCondition['meta_type'] : '');
  834. $oSearch->setCategoryObject(isset($aCondition['cat']) ? $aCondition['cat'] : '');
  835. $oSearch->setCustomSearchCondition($aCondition);
  836. if (!$bPaginate)
  837. $oSearch->setRawProcessing(true);
  838. $oSearch->setCustomCurrentCondition(array(
  839. 'paginate' => array (
  840. 'start' => $iStart,
  841. 'perPage' => $iPerPage ? $iPerPage : BX_DOL_SEARCH_RESULTS_PER_PAGE_DEFAULT,
  842. )));
  843. if ($sTemplate)
  844. $oSearch->setUnitTemplate($sTemplate);
  845. return $oSearch->response();
  846. }
  847. /**
  848. * @page service Service Calls
  849. * @section bx_system_general System Services
  850. * @subsection bx_system_general-general General
  851. * @subsubsection bx_system_general-keyword_search keyword_search
  852. *
  853. * @code bx_srv('system', 'search_keyword_form', 'TemplServices'); @endcode
  854. *
  855. * Block with Search by Keywords Form
  856. *
  857. * @see BxBaseServices::serviceSearchKeywordForm
  858. */
  859. /**
  860. * @ref bx_system_general-keyword_search "keyword_search"
  861. */
  862. public function serviceSearchKeywordForm ()
  863. {
  864. return $this->_getSearchObject()->getForm(BX_DB_PADDING_DEF, false, true);
  865. }
  866. /**
  867. * @page service Service Calls
  868. * @section bx_system_general System Services
  869. * @subsection bx_system_general-general General
  870. * @subsubsection bx_system_general-keyword_search keyword_search
  871. *
  872. * @code bx_srv('system', 'search_keyword_result', 'TemplServices'); @endcode
  873. *
  874. * Block with Search by Keywords Results
  875. *
  876. * @see BxBaseServices::serviceSearchKeywordResult
  877. */
  878. /**
  879. * @ref bx_system_general-keyword_search "keyword_search"
  880. */
  881. public function serviceSearchKeywordResult ()
  882. {
  883. $sKeyword = bx_process_input(bx_get('keyword'));
  884. $bKeyword = $sKeyword !== false;
  885. if(bx_is_api())
  886. return $this->serviceGetDataSearchApi(['params' =>
  887. [
  888. 'keyword' => $sKeyword,
  889. 'section' => bx_process_input(bx_get('section')),
  890. 'cat' => bx_process_input(bx_get('cat'))
  891. ]
  892. ]);
  893. $sCode = '';
  894. if($bKeyword) {
  895. $oSearch = $this->_getSearchObject();
  896. $sCode = $oSearch->response();
  897. if(!$sCode)
  898. $sCode = $oSearch->getEmptyResult();
  899. }
  900. return $sCode;
  901. }
  902. /**
  903. * @ref bx_system_general-get_date_search_api "get_date_search_api"
  904. * @api @ref bx_system_general-get_date_search_api "get_date_search_api"
  905. */
  906. public function serviceGetDataSearchApi ($aParams)
  907. {
  908. if(!bx_is_api())
  909. return false;
  910. if(is_string($aParams))
  911. $aParams = json_decode($aParams, true);
  912. $aSections = [];
  913. $aSectionsAll = BxDolDb::getInstance()->fromCache(
  914. 'sys_global_search_pairs',
  915. 'getPairs',
  916. 'SELECT `ObjectName` AS `name`, `Title` AS `title` FROM `sys_objects_search` WHERE `GlobalSearch`=\'1\' ORDER BY `Order` ASC',
  917. 'name', 'title'
  918. );
  919. $aSectionNames = explode(',', getParam('sys_api_search_sections'));
  920. foreach($aSectionNames as $sSectionName) {
  921. if(!isset($aSectionsAll[$sSectionName]))
  922. continue;
  923. $aSections[$sSectionName] = [
  924. 'name' => $sSectionName,
  925. 'title' => _t($aSectionsAll[$sSectionName])
  926. ];
  927. }
  928. $aParamsBrowse = array_merge([
  929. 'keyword' => '',
  930. 'section' => '',
  931. 'sections' => array_values($aSections),
  932. 'start' => 0,
  933. 'per_page' => 12
  934. ], !empty($aParams['params']) && is_array($aParams['params']) ? $aParams['params'] : []);
  935. if(empty($aParamsBrowse['section']))
  936. $aParamsBrowse['section'] = array_keys($aSections);
  937. else if(is_string($aParamsBrowse['section']))
  938. $aParamsBrowse['section'] = explode(',', $aParamsBrowse['section']);
  939. $sClass = 'BxTemplSearch';
  940. $oSearch = new $sClass($aParamsBrowse['section']);
  941. $oSearch->setLiveSearch(true);
  942. $oSearch->setDataProcessing(true);
  943. $oSearch->setCustomSearchCondition(['keyword' => $aParamsBrowse['keyword']]);
  944. $oSearch->setCustomCurrentCondition([
  945. 'paginate' => [
  946. 'forceStart' => $aParamsBrowse['start'],
  947. 'perPage' => $aParamsBrowse['per_page'],
  948. ]
  949. ]);
  950. $aData = $oSearch->response();
  951. if(count($aData) > $aParamsBrowse['per_page'])
  952. $aData = array_slice($aData, $aParamsBrowse['start'], $aParamsBrowse['per_page']);
  953. return [
  954. bx_api_get_block('browse', [
  955. 'unit' => 'search-results',
  956. 'request_url' => '/api.php?r=system/get_data_search_api/TemplServices&params[]=',
  957. 'params' => $aParamsBrowse,
  958. 'data' => $aData
  959. ])
  960. ];
  961. }
  962. /**
  963. * @page service Service Calls
  964. * @section bx_system_general System Services
  965. * @subsection bx_system_general-general General
  966. * @subsubsection bx_system_general-cmts cmts
  967. *
  968. * @code bx_srv('system', 'cmts', ["sys_blocks", 1], 'TemplServices'); @endcode
  969. *
  970. * @code {{~system:cmts:TemplServices["sys_blocks", 1]~}} @endcode
  971. *
  972. * Comments block
  973. * @param $sObject - comments object name
  974. * @param $sId - content id assiciated tith the comments
  975. *
  976. * @see BxBaseServices::serviceCmts
  977. */
  978. /**
  979. * @ref bx_system_general-cmts "cmts"
  980. */
  981. public function serviceCmts ($sObject, $sId)
  982. {
  983. $o = BxDolCmts::getObjectInstance($sObject, $sId);
  984. if (!$o || !$o->isEnabled())
  985. return '';
  986. return $o->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
  987. }
  988. public function _serviceProfileFunc ($sFunc, $iContentId, $aParams = array())
  989. {
  990. if (!$iContentId)
  991. return false;
  992. if (!($oAccount = BxDolAccount::getInstance($iContentId)))
  993. return false;
  994. return $oAccount->$sFunc(false, $aParams);
  995. }
  996. public function serviceAlertResponseProcessInstalled()
  997. {
  998. BxDolTranscoderImage::registerHandlersSystem();
  999. }
  1000. public function serviceAlertResponseProcessStorageChange ($oAlert)
  1001. {
  1002. if ('sys_storage_default' != $oAlert->aExtras['option'])
  1003. return;
  1004. $aStorages = BxDolStorageQuery::getStorageObjects();
  1005. foreach ($aStorages as $r) {
  1006. if (0 == $r['current_size'] && 0 == $r['current_number'] && ($oStorage = BxDolStorage::getObjectInstance($r['object'])))
  1007. $oStorage->changeStorageEngine($oAlert->aExtras['value']);
  1008. }
  1009. }
  1010. public function serviceGetOptionsProfileBot()
  1011. {
  1012. $aResult = array(
  1013. array('key' => '', 'value' => _t('_Select_one'))
  1014. );
  1015. $aAccountsIds = BxDolAccountQuery::getInstance()->getOperators();
  1016. foreach($aAccountsIds as $iAccountId) {
  1017. $aProfilesIds = BxDolAccount::getInstance($iAccountId)->getProfilesIds(true, false);
  1018. foreach($aProfilesIds as $iProfileId) {
  1019. $oProfile = BxDolProfile::getInstance($iProfileId);
  1020. $aResult[] = array(
  1021. 'key' => $iProfileId,
  1022. 'value' => _t('_sys_profile_with_type', $oProfile->getDisplayName(), $oProfile->getModule()),
  1023. );
  1024. }
  1025. }
  1026. return $aResult;
  1027. }
  1028. public function serviceGetOptionsModuleListForPrivacySelector()
  1029. {
  1030. $aResult = array();
  1031. $BxDolModuleQuery = BxDolModuleQuery::getInstance();
  1032. $aModules = $BxDolModuleQuery->getModulesBy(array('type' => 'modules', 'active' => 1));
  1033. foreach($aModules as $aModule){
  1034. $oModule = BxDolModule::getInstance($aModule['name']);
  1035. if($oModule instanceof iBxDolContentInfoService){
  1036. if (!BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  1037. continue;
  1038. $aResult[$aModule['name']] = $aModule['title'];
  1039. }
  1040. }
  1041. return $aResult;
  1042. }
  1043. public function serviceGetOptionsCaptchaDefault()
  1044. {
  1045. $aResults = [];
  1046. $aObjects = BxDolCaptchaQuery::getObjects();
  1047. foreach($aObjects as $aObject)
  1048. $aResults[$aObject['object']] = $aObject['title'];
  1049. return $aResults;
  1050. }
  1051. public function serviceGetOptionsEmbedDefault()
  1052. {
  1053. $aResults = array(
  1054. '' => _t('_None')
  1055. );
  1056. $aObjects = BxDolEmbedQuery::getObjects();
  1057. foreach($aObjects as $aObject)
  1058. $aResults[$aObject['object']] = $aObject['title'];
  1059. return $aResults;
  1060. }
  1061. public function serviceGetOptionsLocationFieldDefault()
  1062. {
  1063. $aResults = array();
  1064. $aObjects = BxDolLocationFieldQuery::getObjects();
  1065. foreach($aObjects as $aObject)
  1066. $aResults[$aObject['object']] = _t($aObject['title']);
  1067. return $aResults;
  1068. }
  1069. public function serviceGetOptionsLocationMapDefault()
  1070. {
  1071. $aResults = array();
  1072. $aObjects = BxDolLocationMapQuery::getObjects();
  1073. foreach($aObjects as $aObject)
  1074. $aResults[$aObject['object']] = _t($aObject['title']);
  1075. return $aResults;
  1076. }
  1077. public function serviceGetOptionsSocketsFieldDefault()
  1078. {
  1079. $aResults = [];
  1080. $aObjects = ['sys_sockets_disabled', 'sys_sockets_soketi'];
  1081. foreach($aObjects as $sObject)
  1082. $aResults[$sObject] = _t('_adm_stg_cpt_option_sys_sockets_type_' . $sObject);
  1083. return $aResults;
  1084. }
  1085. public function serviceGetOptionsLocationLeafletGetProviders()
  1086. {
  1087. return BxDolLocationMapLeaflet::getProviders();
  1088. }
  1089. public function serviceGetOptionsRelations()
  1090. {
  1091. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
  1092. $aProfiles = array();
  1093. foreach($aModules as $aModule) {
  1094. $sMethod = 'act_as_profile';
  1095. if(!BxDolRequest::serviceExists($aModule['name'], $sMethod) || !BxDolService::call($aModule['name'], $sMethod))
  1096. continue;
  1097. $aProfiles[$aModule['name']] = _t('_' . $aModule['name']);
  1098. }
  1099. $aResults = array();
  1100. foreach($aProfiles as $sName1 => $sTitle1)
  1101. foreach($aProfiles as $sName2 => $sTitle2)
  1102. $aResults[$sName1 . '_' . $sName2] = $sTitle1 . ' - ' . $sTitle2;
  1103. return $aResults;
  1104. }
  1105. public function serviceGetOptionsCfProhibited()
  1106. {
  1107. return BxDolFormQuery::getDataItems('sys_content_filter');
  1108. }
  1109. public function serviceGetOptionsCfUnauthenticated()
  1110. {
  1111. return BxDolFormQuery::getDataItems('sys_content_filter');
  1112. }
  1113. public function serviceGetOptionsTaiwindDefault()
  1114. {
  1115. $sPath = BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'tailwind/css';
  1116. $aExcludes = ['.', '..', 'tailwind.css'];
  1117. $aResults = [];
  1118. if(($oHandle = opendir($sPath)) !== false) {
  1119. while(($sFile = readdir($oHandle)) !== false) {
  1120. if(in_array($sFile, $aExcludes))
  1121. continue;
  1122. if(($oHandlerFile = fopen($sPath . '/' . $sFile, 'r')) === false)
  1123. continue;
  1124. if(($sContent = fread($oHandlerFile, 1024)) !== false && strpos($sContent, '@tailwind base') === false)
  1125. $aResults[$sFile] = $sFile;
  1126. fclose($oHandlerFile);
  1127. }
  1128. closedir($oHandle);
  1129. }
  1130. return $aResults;
  1131. }
  1132. public function serviceGetOptionsApiMenuTop()
  1133. {
  1134. $aMenus = BxDolMenuQuery::getMenuObjects();
  1135. $aResults = ['' => _t('_sys_please_select')];
  1136. foreach($aMenus as $aMenu)
  1137. if($aMenu['module'] == 'system')
  1138. $aResults[$aMenu['object']] = _t($aMenu['title']);
  1139. return $aResults;
  1140. }
  1141. public function serviceGetOptionsAgentsModel()
  1142. {
  1143. return ['' => _t('_Select_one')] + BxDolAI::getInstance()->getModels(['active' => true, 'hidden' => false]);
  1144. }
  1145. public function serviceGetOptionsAgentsProfile($bSelectOne = true)
  1146. {
  1147. $aResult = [];
  1148. if($bSelectOne)
  1149. $aResult[] = ['key' => '', 'value' => _t('_Select_one')];
  1150. $aAccountsIds = BxDolAccountQuery::getInstance()->getOperators();
  1151. foreach($aAccountsIds as $iAccountId) {
  1152. $aProfilesIds = BxDolAccount::getInstance($iAccountId)->getProfilesIds(true, false);
  1153. foreach($aProfilesIds as $iProfileId)
  1154. if(($oProfile = BxDolProfile::getInstance($iProfileId)) !== false && ($sProfileModule = $oProfile->getModule()) != 'system')
  1155. $aResult[] = [
  1156. 'key' => $iProfileId,
  1157. 'value' => _t('_sys_profile_with_type', $oProfile->getDisplayName(), _t('_' . $sProfileModule))
  1158. ];
  1159. }
  1160. return $aResult;
  1161. }
  1162. public function serviceGetOptionsStudioAssistant()
  1163. {
  1164. return ['' => _t('_Select_one')] + BxDolAI::getInstance()->getAssistants(['active' => true, 'hidden' => false]);
  1165. }
  1166. public function serviceGetOptionsLiveSearchAssistant()
  1167. {
  1168. return ['' => _t('_Select_one')] + BxDolAI::getInstance()->getAssistants(['active' => true, 'hidden' => false]);
  1169. }
  1170. public function serviceGetOptionsAskBlockAssistant()
  1171. {
  1172. return ['' => _t('_Select_one')] + BxDolAI::getInstance()->getAssistants(['active' => true, 'hidden' => false]);
  1173. }
  1174. public function serviceRedirect($sUrl = false)
  1175. {
  1176. if (!getParam('sys_confirmation_before_redirect')) {
  1177. BxDolTemplate::getInstance()->displayPageNotFound();
  1178. exit;
  1179. }
  1180. if (false === $sUrl)
  1181. $sUrl = bx_get('url');
  1182. if (!$sUrl || !preg_match('@^https?://@', $sUrl)) {
  1183. http_response_code(500);
  1184. return MsgBox(_t('_error occured'));
  1185. }
  1186. else {
  1187. $bSpam = null;
  1188. /**
  1189. * @hooks
  1190. * @hookdef hook-system-check_spam_url 'system', 'check_spam_url' - hook to override sClass for search
  1191. * - $unit_name - equals `system`
  1192. * - $action - equals `check_spam_url`
  1193. * - $object_id - not used
  1194. * - $sender_id - logged account id
  1195. * - $extra_params - array of additional params with the following array keys:
  1196. * - `is_spam` - [bool] by ref, spam url or not, can be overridden in hook processing
  1197. * - `content` - [string] by ref, url of link, can be overridden in hook processing
  1198. * - `where` - [string] equal redirect
  1199. * @hook @ref hook-system-check_spam_url
  1200. */
  1201. bx_alert('system', 'check_spam_url', 0, getLoggedId(), array('is_spam' => &$bSpam, 'content' => &$sUrl, 'where' => 'redirect'));
  1202. $sLangKey = $bSpam ? '_sys_redirect_confirmation_harmful' : '_sys_redirect_confirmation';
  1203. return BxDolTemplate::getInstance()->parseHtmlByName('redirect.html', [
  1204. 'text' => _t($sLangKey, bx_process_output($sUrl), getParam('site_title')),
  1205. 'url' => bx_js_string($sUrl, BX_ESCAPE_STR_APOS),
  1206. ]);
  1207. }
  1208. }
  1209. public function serviceGetBadge($aBadge, $bIsCompact = false)
  1210. {
  1211. $sClass = '';
  1212. $sStyleFont = '';
  1213. $sStyleBg = '';
  1214. if ($aBadge['color'] == '')
  1215. $aBadge['color'] = 'purple-600';
  1216. if ($bIsCompact && $aBadge['icon'] != ''){
  1217. $aBadge['is_icon_only'] = 1;
  1218. }
  1219. if ($aBadge['is_icon_only'] == 1){
  1220. $sClass .= ' bx-badge-compact';
  1221. if (substr_count($aBadge['color'], 'rgb('))
  1222. $sStyleFont = 'color: ' . $aBadge['color'];
  1223. else
  1224. $sClass .= ' text-' . $aBadge['color'];
  1225. }
  1226. else{
  1227. if (substr_count($aBadge['color'], 'rgb('))
  1228. $sStyleBg = 'background-color: ' . $aBadge['color'];
  1229. else
  1230. $sClass .= ' bg-' . $aBadge['color'];
  1231. }
  1232. return BxDolTemplate::getInstance()->parseHtmlByName('badge.html', array(
  1233. 'bx_if:content' => array(
  1234. 'condition' => $aBadge['is_icon_only'] != '1',
  1235. 'content' => array('content' => _t($aBadge['text'])),
  1236. ),
  1237. 'bx_if:icon' => array(
  1238. 'condition' => $aBadge['icon'] != '',
  1239. 'content' => array('content' => BxDolTemplate::getInstance()->getIcon($aBadge['icon'], array('class' => 'bx-badge-icon sys-colored', 'style' => $sStyleFont))),
  1240. ),
  1241. 'title' => $aBadge['text'],
  1242. 'style_font' => $sStyleFont,
  1243. 'style_bg' => $sStyleBg,
  1244. 'class' => $sClass,
  1245. )
  1246. );
  1247. }
  1248. public function serviceGetFooter()
  1249. {
  1250. return BxDolTemplate::getInstance()->parseHtmlByName('footer.html', []);
  1251. }
  1252. private function _getSearchObject()
  1253. {
  1254. $sClass = 'BxTemplSearch';
  1255. $sElsName = 'bx_elasticsearch';
  1256. $sElsMethod = 'is_configured';
  1257. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod) && !bx_get('cat') && !bx_get('type')) {
  1258. $oModule = BxDolModule::getInstance($sElsName);
  1259. bx_import('Search', $oModule->_aModule);
  1260. $sClass = 'BxElsSearch';
  1261. }
  1262. /**
  1263. * @hooks
  1264. * @hookdef hook-system-search_keyword 'system', 'search_keyword' - hook to override sClass for search
  1265. * - $unit_name - equals `system`
  1266. * - $action - equals `search_keyword`
  1267. * - $object_id - not used
  1268. * - $sender_id - not used
  1269. * - $extra_params - array of additional params with the following array keys:
  1270. * - `override_result` - [string] by ref, class name for search, can be overridden in hook processing
  1271. * @hook @ref hook-system-search_keyword
  1272. */
  1273. bx_alert('system', 'search_keyword', 0, 0, array('class' => &$sClass));
  1274. $oSearch = new $sClass(bx_get('section'));
  1275. $oSearch->setLiveSearch(bx_get('live_search') ? 1 : 0);
  1276. $oSearch->setMetaType(bx_process_input(bx_get('type')));
  1277. $oSearch->setCategoryObject(bx_process_input(bx_get('cat')));
  1278. return $oSearch;
  1279. }
  1280. }
  1281. /** @} */