BxBaseServices.php 55 KB

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