BxBaseMenuSwitchLanguage.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup TridentCore Trident Core
  7. * @{
  8. */
  9. /**
  10. * Site main menu representation.
  11. */
  12. class BxBaseMenuSwitchLanguage extends BxTemplMenu
  13. {
  14. public function __construct ($aObject, $oTemplate)
  15. {
  16. parent::__construct ($aObject, $oTemplate);
  17. }
  18. public function getMenuItems ()
  19. {
  20. $this->loadData();
  21. return parent::getMenuItems();
  22. }
  23. protected function loadData()
  24. {
  25. $sLanguage = BxDolLanguages::getInstance()->getCurrentLangName();
  26. $this->setSelected('', $sLanguage);
  27. $oPermalink = BxDolPermalinks::getInstance();
  28. $sPageLink = ltrim($_SERVER['REQUEST_URI'], '/');
  29. $sPageLink = $oPermalink->unpermalink($sPageLink);
  30. list($sPageLink, $sPageParams) = explode('?', $sPageLink);
  31. $aPageParams = array();
  32. if(!empty($sPageParams))
  33. parse_str($sPageParams, $aPageParams);
  34. $aPageParamsAdd = array();
  35. if(!empty($_SERVER['QUERY_STRING'])) {
  36. parse_str($_SERVER['QUERY_STRING'], $aPageParamsAdd);
  37. if(!empty($aPageParamsAdd) && is_array($aPageParamsAdd))
  38. $aPageParams = array_merge($aPageParams, $aPageParamsAdd);
  39. }
  40. $aLanguages = BxDolLanguagesQuery::getInstance()->getLanguages(false, true);
  41. $aItems = array();
  42. foreach( $aLanguages as $sName => $sLang ) {
  43. $aPageParams['lang'] = $sName;
  44. $aItems[] = array(
  45. 'id' => $sName,
  46. 'name' => $sName,
  47. 'class' => '',
  48. 'title' => $this->getItemTitle($sName, $sLang),
  49. 'target' => '_self',
  50. 'icon' => '',
  51. 'link' => bx_html_attribute(bx_append_url_params($oPermalink->permalink($sPageLink), $aPageParams)),
  52. 'onclick' => ''
  53. );
  54. }
  55. $this->_aObject['menu_items'] = $aItems;
  56. }
  57. protected function getItemTitle($sName, $sTitle)
  58. {
  59. return genFlag($sName);
  60. }
  61. }
  62. /** @} */