BxBaseServices.php 44 KB

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