BxBaseServices.php 44 KB

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