BxBaseServices.php 44 KB

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