BxBaseServices.php 44 KB

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