BxBaseServices.php 44 KB

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