BxBaseServices.php 44 KB

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