Permalink
Browse files

Move vendor/Joomla to src/Joomla. Update necessary paths.

  • Loading branch information...
0 parents commit 71a91e9ab7a13372fbe05745a7e28ac1096d3bd5 @dongilbert dongilbert committed Mar 27, 2013
@@ -0,0 +1,4 @@
+vendor/
+composer.phar
+composer.lock
+phpunit.xml
@@ -0,0 +1,161 @@
+<?php
+/**
+ * Part of the Joomla Framework Language Package
+ *
+ * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE
+ */
+
+namespace Joomla\Language;
+
+use Joomla\Factory;
+
+/**
+ * Language helper class
+ *
+ * @since 1.0
+ */
+class Helper
+{
+ /**
+ * Builds a list of the system languages which can be used in a select option
+ *
+ * @param string $actualLanguage Client key for the area
+ * @param string $basePath Base path to use
+ * @param boolean $caching True if caching is used
+ * @param boolean $installed Get only installed languages
+ *
+ * @return array List of system languages
+ *
+ * @since 1.0
+ */
+ public static function createLanguageList($actualLanguage, $basePath = JPATH_BASE, $caching = false, $installed = false)
+ {
+ $list = array();
+
+ // Cache activation
+ $langs = Language::getKnownLanguages($basePath);
+
+ if ($installed)
+ {
+ $db = Factory::getDBO();
+ $query = $db->getQuery(true);
+ $query->select('element');
+ $query->from('#__extensions');
+ $query->where('type=' . $db->quote('language'));
+ $query->where('state=0');
+ $query->where('enabled=1');
+ $query->where('client_id=' . ($basePath == JPATH_ADMINISTRATOR ? 1 : 0));
+ $db->setQuery($query);
+ $installed_languages = $db->loadObjectList('element');
+ }
+
+ foreach ($langs as $lang => $metadata)
+ {
+ if (!$installed || array_key_exists($lang, $installed_languages))
+ {
+ $option = array();
+
+ $option['text'] = $metadata['name'];
+ $option['value'] = $lang;
+
+ if ($lang == $actualLanguage)
+ {
+ $option['selected'] = 'selected="selected"';
+ }
+
+ $list[] = $option;
+ }
+ }
+
+ return $list;
+ }
+
+ /**
+ * Tries to detect the language.
+ *
+ * @return string locale or null if not found
+ *
+ * @since 1.0
+ */
+ public static function detectLanguage()
+ {
+ if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
+ {
+ $browserLangs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
+ $systemLangs = self::getLanguages();
+
+ foreach ($browserLangs as $browserLang)
+ {
+ // Slice out the part before ; on first step, the part before - on second, place into array
+ $browserLang = substr($browserLang, 0, strcspn($browserLang, ';'));
+ $primary_browserLang = substr($browserLang, 0, 2);
+
+ foreach ($systemLangs as $systemLang)
+ {
+ // Take off 3 letters iso code languages as they can't match browsers' languages and default them to en
+ $Jinstall_lang = $systemLang->lang_code;
+
+ if (strlen($Jinstall_lang) < 6)
+ {
+ if (strtolower($browserLang) == strtolower(substr($systemLang->lang_code, 0, strlen($browserLang))))
+ {
+ return $systemLang->lang_code;
+ }
+ elseif ($primary_browserLang == substr($systemLang->lang_code, 0, 2))
+ {
+ $primaryDetectedLang = $systemLang->lang_code;
+ }
+ }
+ }
+
+ if (isset($primaryDetectedLang))
+ {
+ return $primaryDetectedLang;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Get available languages
+ *
+ * @param string $key Array key
+ *
+ * @return array An array of published languages
+ *
+ * @since 1.0
+ */
+ public static function getLanguages($key = 'default')
+ {
+ static $languages;
+
+ if (empty($languages))
+ {
+ $db = Factory::getDBO();
+ $query = $db->getQuery(true);
+ $query->select('*')
+ ->from('#__languages')
+ ->where('published=1')
+ ->order('ordering ASC');
+ $db->setQuery($query);
+
+ $languages['default'] = $db->loadObjectList();
+ $languages['sef'] = array();
+ $languages['lang_code'] = array();
+
+ if (isset($languages['default'][0]))
+ {
+ foreach ($languages['default'] as $lang)
+ {
+ $languages['sef'][$lang->sef] = $lang;
+ $languages['lang_code'][$lang->lang_code] = $lang;
+ }
+ }
+ }
+
+ return $languages[$key];
+ }
+}
Oops, something went wrong.

0 comments on commit 71a91e9

Please sign in to comment.