BxBaseServices.php 48 KB

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