BxBaseServices.php 52 KB

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