BxBaseServices.php 44 KB

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