Language.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. *
  4. * PHP Pro Bid $Id$ jPnUxif+Zc8mhcDmJbY3ccffmXfzsD6JCiGMA+7vfRI=
  5. *
  6. * @link http://www.phpprobid.com
  7. * @copyright Copyright (c) 2017 Online Ventures Software & CodeCube SRL
  8. * @license http://www.phpprobid.com/license Commercial License
  9. *
  10. * @version 7.9 [rev.7.9.01]
  11. */
  12. /**
  13. * language selector widget view helper class
  14. * - the url will never change, just that we will add a param (lang = code) which will
  15. * then trigger the language change plugin
  16. */
  17. namespace Ppb\View\Helper;
  18. use Cube\View\Helper\AbstractHelper,
  19. Cube\Controller\Front;
  20. class Language extends AbstractHelper
  21. {
  22. /**
  23. *
  24. * create and output language selector widget
  25. *
  26. * @return string|null
  27. */
  28. public function language()
  29. {
  30. $output = null;
  31. $frontController = Front::getInstance();
  32. $settings = $frontController->getBootstrap()->getResource('settings');
  33. if ($settings['user_languages']) {
  34. $activeLangImg = null;
  35. $activeLocale = $this->getTranslate()->getLocale();
  36. $translateOption = $frontController->getOption('translate');
  37. if (array_key_exists('translations', $translateOption)) {
  38. $languages = $translateOption['translations'];
  39. $nbLanguages = count($languages);
  40. $view = $this->getView();
  41. $flagPath = $view->baseUrl . \Ppb\Utility::URI_DELIMITER . \Ppb\Utility::getFolder('img') . \Ppb\Utility::URI_DELIMITER;
  42. foreach ($languages as $language) {
  43. $img = '<img src="' . $flagPath . $language['img'] . '" alt="' . $language['desc'] . '">';
  44. if ($language['locale'] == $activeLocale) {
  45. $activeLangImg = $img;
  46. }
  47. $output[] = '<li>'
  48. . '<a href="' . $view->url(array('lang' => $language['locale']), null, true, null, true, false) . '">'
  49. . $img . ' <span>' . $language['desc'] . '</span>'
  50. . '</a>'
  51. . '</li>';
  52. }
  53. if ($nbLanguages > 0) {
  54. $output = '<div class="dropdown language-dropdown">'
  55. . '<button class="btn btn-link dropdown-toggle" type="button" id="languageDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">'
  56. . $activeLangImg
  57. . (($nbLanguages > 1) ? '<span class="caret"></span>' : '')
  58. . '</button>'
  59. . (($nbLanguages > 1) ? '<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">' . implode(' ', $output) . '</ul>' : '')
  60. . '</div>';
  61. }
  62. }
  63. }
  64. return $output;
  65. }
  66. }