1
0

BxBaseServices.php 60 KB

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