BxBaseServices.php 52 KB

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