BxBaseServices.php 44 KB

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