You've already forked joomla_test
first commit
This commit is contained in:
178
libraries/joomla/language/helper.php
Normal file
178
libraries/joomla/language/helper.php
Normal file
@ -0,0 +1,178 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Language
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Language helper class
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Language
|
||||
* @since 11.1
|
||||
*/
|
||||
class JLanguageHelper
|
||||
{
|
||||
/**
|
||||
* 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 array $installed An array of arrays (text, value, selected)
|
||||
*
|
||||
* @return array List of system languages
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public static function createLanguageList($actualLanguage, $basePath = JPATH_BASE, $caching = false, $installed = false)
|
||||
{
|
||||
$list = array();
|
||||
|
||||
// Cache activation
|
||||
$langs = JLanguage::getKnownLanguages($basePath);
|
||||
if ($installed)
|
||||
{
|
||||
$db = JFactory::getDbo();
|
||||
$query = $db->getQuery(true)
|
||||
->select('element')
|
||||
->from('#__extensions')
|
||||
->where('type=' . $db->quote('language'))
|
||||
->where('state=0')
|
||||
->where('enabled=1')
|
||||
->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 11.1
|
||||
*/
|
||||
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 11.1
|
||||
*/
|
||||
public static function getLanguages($key = 'default')
|
||||
{
|
||||
static $languages;
|
||||
|
||||
if (empty($languages))
|
||||
{
|
||||
// Installation uses available languages
|
||||
if (JFactory::getApplication()->getClientId() == 2)
|
||||
{
|
||||
$languages[$key] = array();
|
||||
$knownLangs = JLanguage::getKnownLanguages(JPATH_BASE);
|
||||
foreach ($knownLangs as $metadata)
|
||||
{
|
||||
// Take off 3 letters iso code languages as they can't match browsers' languages and default them to en
|
||||
$obj = new stdClass;
|
||||
$obj->lang_code = $metadata['tag'];
|
||||
$languages[$key][] = $obj;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$cache = JFactory::getCache('com_languages', '');
|
||||
if (!$languages = $cache->get('languages'))
|
||||
{
|
||||
$db = JFactory::getDbo();
|
||||
$query = $db->getQuery(true)
|
||||
->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;
|
||||
}
|
||||
}
|
||||
|
||||
$cache->store($languages, 'languages');
|
||||
}
|
||||
}
|
||||
}
|
||||
return $languages[$key];
|
||||
}
|
||||
}
|
1
libraries/joomla/language/index.html
Normal file
1
libraries/joomla/language/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
1326
libraries/joomla/language/language.php
Normal file
1326
libraries/joomla/language/language.php
Normal file
File diff suppressed because it is too large
Load Diff
78
libraries/joomla/language/stemmer.php
Normal file
78
libraries/joomla/language/stemmer.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Language
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Stemmer base class.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Language
|
||||
* @since 12.1
|
||||
*/
|
||||
abstract class JLanguageStemmer
|
||||
{
|
||||
/**
|
||||
* An internal cache of stemmed tokens.
|
||||
*
|
||||
* @var array
|
||||
* @since 12.1
|
||||
*/
|
||||
protected $cache = array();
|
||||
|
||||
/**
|
||||
* @var array JLanguageStemmer instances.
|
||||
* @since 12.1
|
||||
*/
|
||||
protected static $instances = array();
|
||||
|
||||
/**
|
||||
* Method to get a stemmer, creating it if necessary.
|
||||
*
|
||||
* @param string $adapter The type of stemmer to load.
|
||||
*
|
||||
* @return JLanguageStemmer A JLanguageStemmer instance.
|
||||
*
|
||||
* @since 12.1
|
||||
* @throws RuntimeException on invalid stemmer.
|
||||
*/
|
||||
public static function getInstance($adapter)
|
||||
{
|
||||
// Only create one stemmer for each adapter.
|
||||
if (isset(self::$instances[$adapter]))
|
||||
{
|
||||
return self::$instances[$adapter];
|
||||
}
|
||||
|
||||
// Setup the adapter for the stemmer.
|
||||
$class = 'JLanguageStemmer' . ucfirst(trim($adapter));
|
||||
|
||||
// Check if a stemmer exists for the adapter.
|
||||
if (!class_exists($class))
|
||||
{
|
||||
// Throw invalid adapter exception.
|
||||
throw new RuntimeException(JText::sprintf('JLIB_STEMMER_INVALID_STEMMER', $adapter));
|
||||
}
|
||||
|
||||
self::$instances[$adapter] = new $class;
|
||||
return self::$instances[$adapter];
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to stem a token and return the root.
|
||||
*
|
||||
* @param string $token The token to stem.
|
||||
* @param string $lang The language of the token.
|
||||
*
|
||||
* @return string The root token.
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
abstract public function stem($token, $lang);
|
||||
}
|
1
libraries/joomla/language/stemmer/index.html
Normal file
1
libraries/joomla/language/stemmer/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
448
libraries/joomla/language/stemmer/porteren.php
Normal file
448
libraries/joomla/language/stemmer/porteren.php
Normal file
@ -0,0 +1,448 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Language
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @copyright Copyright (C) 2005 Richard Heyes (http://www.phpguru.org/). All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Porter English stemmer class.
|
||||
*
|
||||
* This class was adapted from one written by Richard Heyes.
|
||||
* See copyright and link information above.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Language
|
||||
* @since 12.1
|
||||
*/
|
||||
class JLanguageStemmerPorteren extends JLanguageStemmer
|
||||
{
|
||||
/**
|
||||
* Regex for matching a consonant.
|
||||
*
|
||||
* @var string
|
||||
* @since 12.1
|
||||
*/
|
||||
private static $_regex_consonant = '(?:[bcdfghjklmnpqrstvwxz]|(?<=[aeiou])y|^y)';
|
||||
|
||||
/**
|
||||
* Regex for matching a vowel
|
||||
* @var string
|
||||
* @since 12.1
|
||||
*/
|
||||
private static $_regex_vowel = '(?:[aeiou]|(?<![aeiou])y)';
|
||||
|
||||
/**
|
||||
* Method to stem a token and return the root.
|
||||
*
|
||||
* @param string $token The token to stem.
|
||||
* @param string $lang The language of the token.
|
||||
*
|
||||
* @return string The root token.
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
public function stem($token, $lang)
|
||||
{
|
||||
// Check if the token is long enough to merit stemming.
|
||||
if (strlen($token) <= 2)
|
||||
{
|
||||
return $token;
|
||||
}
|
||||
|
||||
// Check if the language is English or All.
|
||||
if ($lang !== 'en')
|
||||
{
|
||||
return $token;
|
||||
}
|
||||
|
||||
// Stem the token if it is not in the cache.
|
||||
if (!isset($this->cache[$lang][$token]))
|
||||
{
|
||||
// Stem the token.
|
||||
$result = $token;
|
||||
$result = self::_step1ab($result);
|
||||
$result = self::_step1c($result);
|
||||
$result = self::_step2($result);
|
||||
$result = self::_step3($result);
|
||||
$result = self::_step4($result);
|
||||
$result = self::_step5($result);
|
||||
|
||||
// Add the token to the cache.
|
||||
$this->cache[$lang][$token] = $result;
|
||||
}
|
||||
|
||||
return $this->cache[$lang][$token];
|
||||
}
|
||||
|
||||
/**
|
||||
* Step 1
|
||||
*
|
||||
* @param string $word The token to stem.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
private static function _step1ab($word)
|
||||
{
|
||||
// Part a
|
||||
if (substr($word, -1) == 's')
|
||||
{
|
||||
self::_replace($word, 'sses', 'ss')
|
||||
or self::_replace($word, 'ies', 'i')
|
||||
or self::_replace($word, 'ss', 'ss')
|
||||
or self::_replace($word, 's', '');
|
||||
}
|
||||
|
||||
// Part b
|
||||
if (substr($word, -2, 1) != 'e' or !self::_replace($word, 'eed', 'ee', 0))
|
||||
{
|
||||
// First rule
|
||||
$v = self::$_regex_vowel;
|
||||
|
||||
// Check ing and ed
|
||||
// Note use of && and OR, for precedence reasons
|
||||
if (preg_match("#$v+#", substr($word, 0, -3)) && self::_replace($word, 'ing', '')
|
||||
or preg_match("#$v+#", substr($word, 0, -2)) && self::_replace($word, 'ed', ''))
|
||||
{
|
||||
// If one of above two test successful
|
||||
if (!self::_replace($word, 'at', 'ate') and !self::_replace($word, 'bl', 'ble') and !self::_replace($word, 'iz', 'ize'))
|
||||
{
|
||||
// Double consonant ending
|
||||
if (self::_doubleConsonant($word) and substr($word, -2) != 'll' and substr($word, -2) != 'ss' and substr($word, -2) != 'zz')
|
||||
{
|
||||
$word = substr($word, 0, -1);
|
||||
}
|
||||
elseif (self::_m($word) == 1 and self::_cvc($word))
|
||||
{
|
||||
$word .= 'e';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $word;
|
||||
}
|
||||
|
||||
/**
|
||||
* Step 1c
|
||||
*
|
||||
* @param string $word The token to stem.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
private static function _step1c($word)
|
||||
{
|
||||
$v = self::$_regex_vowel;
|
||||
|
||||
if (substr($word, -1) == 'y' && preg_match("#$v+#", substr($word, 0, -1)))
|
||||
{
|
||||
self::_replace($word, 'y', 'i');
|
||||
}
|
||||
|
||||
return $word;
|
||||
}
|
||||
|
||||
/**
|
||||
* Step 2
|
||||
*
|
||||
* @param string $word The token to stem.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
private static function _step2($word)
|
||||
{
|
||||
switch (substr($word, -2, 1))
|
||||
{
|
||||
case 'a':
|
||||
self::_replace($word, 'ational', 'ate', 0)
|
||||
or self::_replace($word, 'tional', 'tion', 0);
|
||||
break;
|
||||
case 'c':
|
||||
self::_replace($word, 'enci', 'ence', 0)
|
||||
or self::_replace($word, 'anci', 'ance', 0);
|
||||
break;
|
||||
case 'e':
|
||||
self::_replace($word, 'izer', 'ize', 0);
|
||||
break;
|
||||
case 'g':
|
||||
self::_replace($word, 'logi', 'log', 0);
|
||||
break;
|
||||
case 'l':
|
||||
self::_replace($word, 'entli', 'ent', 0)
|
||||
or self::_replace($word, 'ousli', 'ous', 0)
|
||||
or self::_replace($word, 'alli', 'al', 0)
|
||||
or self::_replace($word, 'bli', 'ble', 0)
|
||||
or self::_replace($word, 'eli', 'e', 0);
|
||||
break;
|
||||
case 'o':
|
||||
self::_replace($word, 'ization', 'ize', 0)
|
||||
or self::_replace($word, 'ation', 'ate', 0)
|
||||
or self::_replace($word, 'ator', 'ate', 0);
|
||||
break;
|
||||
case 's':
|
||||
self::_replace($word, 'iveness', 'ive', 0)
|
||||
or self::_replace($word, 'fulness', 'ful', 0)
|
||||
or self::_replace($word, 'ousness', 'ous', 0)
|
||||
or self::_replace($word, 'alism', 'al', 0);
|
||||
break;
|
||||
case 't':
|
||||
self::_replace($word, 'biliti', 'ble', 0)
|
||||
or self::_replace($word, 'aliti', 'al', 0)
|
||||
or self::_replace($word, 'iviti', 'ive', 0);
|
||||
break;
|
||||
}
|
||||
|
||||
return $word;
|
||||
}
|
||||
|
||||
/**
|
||||
* Step 3
|
||||
*
|
||||
* @param string $word The token to stem.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
private static function _step3($word)
|
||||
{
|
||||
switch (substr($word, -2, 1))
|
||||
{
|
||||
case 'a':
|
||||
self::_replace($word, 'ical', 'ic', 0);
|
||||
break;
|
||||
case 's':
|
||||
self::_replace($word, 'ness', '', 0);
|
||||
break;
|
||||
case 't':
|
||||
self::_replace($word, 'icate', 'ic', 0)
|
||||
or self::_replace($word, 'iciti', 'ic', 0);
|
||||
break;
|
||||
case 'u':
|
||||
self::_replace($word, 'ful', '', 0);
|
||||
break;
|
||||
case 'v':
|
||||
self::_replace($word, 'ative', '', 0);
|
||||
break;
|
||||
case 'z':
|
||||
self::_replace($word, 'alize', 'al', 0);
|
||||
break;
|
||||
}
|
||||
|
||||
return $word;
|
||||
}
|
||||
|
||||
/**
|
||||
* Step 4
|
||||
*
|
||||
* @param string $word The token to stem.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
private static function _step4($word)
|
||||
{
|
||||
switch (substr($word, -2, 1))
|
||||
{
|
||||
case 'a':
|
||||
self::_replace($word, 'al', '', 1);
|
||||
break;
|
||||
case 'c':
|
||||
self::_replace($word, 'ance', '', 1)
|
||||
or self::_replace($word, 'ence', '', 1);
|
||||
break;
|
||||
case 'e':
|
||||
self::_replace($word, 'er', '', 1);
|
||||
break;
|
||||
case 'i':
|
||||
self::_replace($word, 'ic', '', 1);
|
||||
break;
|
||||
case 'l':
|
||||
self::_replace($word, 'able', '', 1)
|
||||
or self::_replace($word, 'ible', '', 1);
|
||||
break;
|
||||
case 'n':
|
||||
self::_replace($word, 'ant', '', 1)
|
||||
or self::_replace($word, 'ement', '', 1)
|
||||
or self::_replace($word, 'ment', '', 1)
|
||||
or self::_replace($word, 'ent', '', 1);
|
||||
break;
|
||||
case 'o':
|
||||
if (substr($word, -4) == 'tion' or substr($word, -4) == 'sion')
|
||||
{
|
||||
self::_replace($word, 'ion', '', 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
self::_replace($word, 'ou', '', 1);
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
self::_replace($word, 'ism', '', 1);
|
||||
break;
|
||||
case 't':
|
||||
self::_replace($word, 'ate', '', 1)
|
||||
or self::_replace($word, 'iti', '', 1);
|
||||
break;
|
||||
case 'u':
|
||||
self::_replace($word, 'ous', '', 1);
|
||||
break;
|
||||
case 'v':
|
||||
self::_replace($word, 'ive', '', 1);
|
||||
break;
|
||||
case 'z':
|
||||
self::_replace($word, 'ize', '', 1);
|
||||
break;
|
||||
}
|
||||
|
||||
return $word;
|
||||
}
|
||||
|
||||
/**
|
||||
* Step 5
|
||||
*
|
||||
* @param string $word The token to stem.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
private static function _step5($word)
|
||||
{
|
||||
// Part a
|
||||
if (substr($word, -1) == 'e')
|
||||
{
|
||||
if (self::_m(substr($word, 0, -1)) > 1)
|
||||
{
|
||||
self::_replace($word, 'e', '');
|
||||
}
|
||||
elseif (self::_m(substr($word, 0, -1)) == 1)
|
||||
{
|
||||
if (!self::_cvc(substr($word, 0, -1)))
|
||||
{
|
||||
self::_replace($word, 'e', '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Part b
|
||||
if (self::_m($word) > 1 and self::_doubleConsonant($word) and substr($word, -1) == 'l')
|
||||
{
|
||||
$word = substr($word, 0, -1);
|
||||
}
|
||||
|
||||
return $word;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the first string with the second, at the end of the string. If third
|
||||
* arg is given, then the preceding string must match that m count at least.
|
||||
*
|
||||
* @param string &$str String to check
|
||||
* @param string $check Ending to check for
|
||||
* @param string $repl Replacement string
|
||||
* @param integer $m Optional minimum number of m() to meet
|
||||
*
|
||||
* @return boolean Whether the $check string was at the end
|
||||
* of the $str string. True does not necessarily mean
|
||||
* that it was replaced.
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
private static function _replace(&$str, $check, $repl, $m = null)
|
||||
{
|
||||
$len = 0 - strlen($check);
|
||||
|
||||
if (substr($str, $len) == $check)
|
||||
{
|
||||
$substr = substr($str, 0, $len);
|
||||
if (is_null($m) or self::_m($substr) > $m)
|
||||
{
|
||||
$str = $substr . $repl;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* m() measures the number of consonant sequences in $str. if c is
|
||||
* a consonant sequence and v a vowel sequence, and <..> indicates arbitrary
|
||||
* presence,
|
||||
*
|
||||
* <c><v> gives 0
|
||||
* <c>vc<v> gives 1
|
||||
* <c>vcvc<v> gives 2
|
||||
* <c>vcvcvc<v> gives 3
|
||||
*
|
||||
* @param string $str The string to return the m count for
|
||||
*
|
||||
* @return integer The m count
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
private static function _m($str)
|
||||
{
|
||||
$c = self::$_regex_consonant;
|
||||
$v = self::$_regex_vowel;
|
||||
|
||||
$str = preg_replace("#^$c+#", '', $str);
|
||||
$str = preg_replace("#$v+$#", '', $str);
|
||||
|
||||
preg_match_all("#($v+$c+)#", $str, $matches);
|
||||
|
||||
return count($matches[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true/false as to whether the given string contains two
|
||||
* of the same consonant next to each other at the end of the string.
|
||||
*
|
||||
* @param string $str String to check
|
||||
*
|
||||
* @return boolean Result
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
private static function _doubleConsonant($str)
|
||||
{
|
||||
$c = self::$_regex_consonant;
|
||||
|
||||
return preg_match("#$c{2}$#", $str, $matches) and $matches[0]{0} == $matches[0]{1};
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for ending CVC sequence where second C is not W, X or Y
|
||||
*
|
||||
* @param string $str String to check
|
||||
*
|
||||
* @return boolean Result
|
||||
*
|
||||
* @since 12.1
|
||||
*/
|
||||
private static function _cvc($str)
|
||||
{
|
||||
$c = self::$_regex_consonant;
|
||||
$v = self::$_regex_vowel;
|
||||
|
||||
$result = preg_match("#($c$v$c)$#", $str, $matches)
|
||||
and strlen($matches[1]) == 3
|
||||
and $matches[1]{2} != 'w'
|
||||
and $matches[1]{2} != 'x'
|
||||
and $matches[1]{2} != 'y';
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
333
libraries/joomla/language/text.php
Normal file
333
libraries/joomla/language/text.php
Normal file
@ -0,0 +1,333 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Language
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Text handling class.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Language
|
||||
* @since 11.1
|
||||
*/
|
||||
class JText
|
||||
{
|
||||
/**
|
||||
* javascript strings
|
||||
*
|
||||
* @var array
|
||||
* @since 11.1
|
||||
*/
|
||||
protected static $strings = array();
|
||||
|
||||
/**
|
||||
* Translates a string into the current language.
|
||||
*
|
||||
* Examples:
|
||||
* <script>alert(Joomla.JText._('<?php echo JText::_("JDEFAULT", array("script"=>true));?>'));</script>
|
||||
* will generate an alert message containing 'Default'
|
||||
* <?php echo JText::_("JDEFAULT");?> it will generate a 'Default' string
|
||||
*
|
||||
* @param string $string The string to translate.
|
||||
* @param mixed $jsSafe Boolean: Make the result javascript safe.
|
||||
* @param boolean $interpretBackSlashes To interpret backslashes (\\=\, \n=carriage return, \t=tabulation)
|
||||
* @param boolean $script To indicate that the string will be push in the javascript language store
|
||||
*
|
||||
* @return string The translated string or the key is $script is true
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public static function _($string, $jsSafe = false, $interpretBackSlashes = true, $script = false)
|
||||
{
|
||||
$lang = JFactory::getLanguage();
|
||||
if (is_array($jsSafe))
|
||||
{
|
||||
if (array_key_exists('interpretBackSlashes', $jsSafe))
|
||||
{
|
||||
$interpretBackSlashes = (boolean) $jsSafe['interpretBackSlashes'];
|
||||
}
|
||||
if (array_key_exists('script', $jsSafe))
|
||||
{
|
||||
$script = (boolean) $jsSafe['script'];
|
||||
}
|
||||
if (array_key_exists('jsSafe', $jsSafe))
|
||||
{
|
||||
$jsSafe = (boolean) $jsSafe['jsSafe'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$jsSafe = false;
|
||||
}
|
||||
}
|
||||
if (!(strpos($string, ',') === false))
|
||||
{
|
||||
$test = substr($string, strpos($string, ','));
|
||||
if (strtoupper($test) === $test)
|
||||
{
|
||||
$strs = explode(',', $string);
|
||||
foreach ($strs as $i => $str)
|
||||
{
|
||||
$strs[$i] = $lang->_($str, $jsSafe, $interpretBackSlashes);
|
||||
if ($script)
|
||||
{
|
||||
self::$strings[$str] = $strs[$i];
|
||||
}
|
||||
}
|
||||
$str = array_shift($strs);
|
||||
$str = vsprintf($str, $strs);
|
||||
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
if ($script)
|
||||
{
|
||||
self::$strings[$string] = $lang->_($string, $jsSafe, $interpretBackSlashes);
|
||||
return $string;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $lang->_($string, $jsSafe, $interpretBackSlashes);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates a string into the current language.
|
||||
*
|
||||
* Examples:
|
||||
* <?php echo JText::alt("JALL","language");?> it will generate a 'All' string in English but a "Toutes" string in French
|
||||
* <?php echo JText::alt("JALL","module");?> it will generate a 'All' string in English but a "Tous" string in French
|
||||
*
|
||||
* @param string $string The string to translate.
|
||||
* @param string $alt The alternate option for global string
|
||||
* @param mixed $jsSafe Boolean: Make the result javascript safe.
|
||||
* @param boolean $interpretBackSlashes To interpret backslashes (\\=\, \n=carriage return, \t=tabulation)
|
||||
* @param boolean $script To indicate that the string will be pushed in the javascript language store
|
||||
*
|
||||
* @return string The translated string or the key if $script is true
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public static function alt($string, $alt, $jsSafe = false, $interpretBackSlashes = true, $script = false)
|
||||
{
|
||||
$lang = JFactory::getLanguage();
|
||||
if ($lang->hasKey($string . '_' . $alt))
|
||||
{
|
||||
return self::_($string . '_' . $alt, $jsSafe, $interpretBackSlashes);
|
||||
}
|
||||
else
|
||||
{
|
||||
return self::_($string, $jsSafe, $interpretBackSlashes);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Like JText::sprintf but tries to pluralise the string.
|
||||
*
|
||||
* Note that this method can take a mixed number of arguments as for the sprintf function.
|
||||
*
|
||||
* The last argument can take an array of options:
|
||||
*
|
||||
* array('jsSafe'=>boolean, 'interpretBackSlashes'=>boolean, 'script'=>boolean)
|
||||
*
|
||||
* where:
|
||||
*
|
||||
* jsSafe is a boolean to generate a javascript safe strings.
|
||||
* interpretBackSlashes is a boolean to interpret backslashes \\->\, \n->new line, \t->tabulation.
|
||||
* script is a boolean to indicate that the string will be push in the javascript language store.
|
||||
*
|
||||
* Examples:
|
||||
* <script>alert(Joomla.JText._('<?php echo JText::plural("COM_PLUGINS_N_ITEMS_UNPUBLISHED", 1, array("script"=>true));?>'));</script>
|
||||
* will generate an alert message containing '1 plugin successfully disabled'
|
||||
* <?php echo JText::plural("COM_PLUGINS_N_ITEMS_UNPUBLISHED", 1);?> it will generate a '1 plugin successfully disabled' string
|
||||
*
|
||||
* @param string $string The format string.
|
||||
* @param integer $n The number of items
|
||||
*
|
||||
* @return string The translated strings or the key if 'script' is true in the array of options
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public static function plural($string, $n)
|
||||
{
|
||||
$lang = JFactory::getLanguage();
|
||||
$args = func_get_args();
|
||||
$count = count($args);
|
||||
|
||||
if ($count > 1)
|
||||
{
|
||||
// Try the key from the language plural potential suffixes
|
||||
$found = false;
|
||||
$suffixes = $lang->getPluralSuffixes((int) $n);
|
||||
array_unshift($suffixes, (int) $n);
|
||||
foreach ($suffixes as $suffix)
|
||||
{
|
||||
$key = $string . '_' . $suffix;
|
||||
if ($lang->hasKey($key))
|
||||
{
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$found)
|
||||
{
|
||||
// Not found so revert to the original.
|
||||
$key = $string;
|
||||
}
|
||||
if (is_array($args[$count - 1]))
|
||||
{
|
||||
$args[0] = $lang->_(
|
||||
$key, array_key_exists('jsSafe', $args[$count - 1]) ? $args[$count - 1]['jsSafe'] : false,
|
||||
array_key_exists('interpretBackSlashes', $args[$count - 1]) ? $args[$count - 1]['interpretBackSlashes'] : true
|
||||
);
|
||||
if (array_key_exists('script', $args[$count - 1]) && $args[$count - 1]['script'])
|
||||
{
|
||||
self::$strings[$key] = call_user_func_array('sprintf', $args);
|
||||
return $key;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$args[0] = $lang->_($key);
|
||||
}
|
||||
return call_user_func_array('sprintf', $args);
|
||||
}
|
||||
elseif ($count > 0)
|
||||
{
|
||||
|
||||
// Default to the normal sprintf handling.
|
||||
$args[0] = $lang->_($string);
|
||||
return call_user_func_array('sprintf', $args);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Passes a string thru a sprintf.
|
||||
*
|
||||
* Note that this method can take a mixed number of arguments as for the sprintf function.
|
||||
*
|
||||
* The last argument can take an array of options:
|
||||
*
|
||||
* array('jsSafe'=>boolean, 'interpretBackSlashes'=>boolean, 'script'=>boolean)
|
||||
*
|
||||
* where:
|
||||
*
|
||||
* jsSafe is a boolean to generate a javascript safe strings.
|
||||
* interpretBackSlashes is a boolean to interpret backslashes \\->\, \n->new line, \t->tabulation.
|
||||
* script is a boolean to indicate that the string will be push in the javascript language store.
|
||||
*
|
||||
* @param string $string The format string.
|
||||
*
|
||||
* @return string The translated strings or the key if 'script' is true in the array of options.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public static function sprintf($string)
|
||||
{
|
||||
$lang = JFactory::getLanguage();
|
||||
$args = func_get_args();
|
||||
$count = count($args);
|
||||
if ($count > 0)
|
||||
{
|
||||
if (is_array($args[$count - 1]))
|
||||
{
|
||||
$args[0] = $lang->_(
|
||||
$string, array_key_exists('jsSafe', $args[$count - 1]) ? $args[$count - 1]['jsSafe'] : false,
|
||||
array_key_exists('interpretBackSlashes', $args[$count - 1]) ? $args[$count - 1]['interpretBackSlashes'] : true
|
||||
);
|
||||
|
||||
if (array_key_exists('script', $args[$count - 1]) && $args[$count - 1]['script'])
|
||||
{
|
||||
self::$strings[$string] = call_user_func_array('sprintf', $args);
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$args[0] = $lang->_($string);
|
||||
}
|
||||
return call_user_func_array('sprintf', $args);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Passes a string thru an printf.
|
||||
*
|
||||
* Note that this method can take a mixed number of arguments as for the sprintf function.
|
||||
*
|
||||
* @param format $string The format string.
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public static function printf($string)
|
||||
{
|
||||
$lang = JFactory::getLanguage();
|
||||
$args = func_get_args();
|
||||
$count = count($args);
|
||||
if ($count > 0)
|
||||
{
|
||||
if (is_array($args[$count - 1]))
|
||||
{
|
||||
$args[0] = $lang->_(
|
||||
$string, array_key_exists('jsSafe', $args[$count - 1]) ? $args[$count - 1]['jsSafe'] : false,
|
||||
array_key_exists('interpretBackSlashes', $args[$count - 1]) ? $args[$count - 1]['interpretBackSlashes'] : true
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$args[0] = $lang->_($string);
|
||||
}
|
||||
return call_user_func_array('printf', $args);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a string into the current language and stores it in the JavaScript language store.
|
||||
*
|
||||
* @param string $string The JText key.
|
||||
* @param boolean $jsSafe Ensure the output is JavaScript safe.
|
||||
* @param boolean $interpretBackSlashes Interpret \t and \n.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public static function script($string = null, $jsSafe = false, $interpretBackSlashes = true)
|
||||
{
|
||||
if (is_array($jsSafe))
|
||||
{
|
||||
if (array_key_exists('interpretBackSlashes', $jsSafe))
|
||||
{
|
||||
$interpretBackSlashes = (boolean) $jsSafe['interpretBackSlashes'];
|
||||
}
|
||||
|
||||
if (array_key_exists('jsSafe', $jsSafe))
|
||||
{
|
||||
$jsSafe = (boolean) $jsSafe['jsSafe'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$jsSafe = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Add the string to the array if not null.
|
||||
if ($string !== null)
|
||||
{
|
||||
// Normalize the key and translate the string.
|
||||
self::$strings[strtoupper($string)] = JFactory::getLanguage()->_($string, $jsSafe, $interpretBackSlashes);
|
||||
}
|
||||
|
||||
return self::$strings;
|
||||
}
|
||||
}
|
266
libraries/joomla/language/transliterate.php
Normal file
266
libraries/joomla/language/transliterate.php
Normal file
@ -0,0 +1,266 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Language
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Class to transliterate strings
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Language
|
||||
* @since 11.1
|
||||
* @note Port of phputf8's utf8_accents_to_ascii()
|
||||
*/
|
||||
class JLanguageTransliterate
|
||||
{
|
||||
/**
|
||||
* Returns strings transliterated from UTF-8 to Latin
|
||||
*
|
||||
* @param string $string String to transliterate
|
||||
* @param boolean $case Optionally specify upper or lower case. Default to null.
|
||||
*
|
||||
* @return string Transliterated string
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public static function utf8_latin_to_ascii($string, $case = 0)
|
||||
{
|
||||
static $UTF8_LOWER_ACCENTS = null;
|
||||
static $UTF8_UPPER_ACCENTS = null;
|
||||
|
||||
if ($case <= 0)
|
||||
{
|
||||
if (is_null($UTF8_LOWER_ACCENTS))
|
||||
{
|
||||
$UTF8_LOWER_ACCENTS = array(
|
||||
'à' => 'a',
|
||||
'ô' => 'o',
|
||||
'ď' => 'd',
|
||||
'ḟ' => 'f',
|
||||
'ë' => 'e',
|
||||
'š' => 's',
|
||||
'ơ' => 'o',
|
||||
'ß' => 'ss',
|
||||
'ă' => 'a',
|
||||
'ř' => 'r',
|
||||
'ț' => 't',
|
||||
'ň' => 'n',
|
||||
'ā' => 'a',
|
||||
'ķ' => 'k',
|
||||
'ŝ' => 's',
|
||||
'ỳ' => 'y',
|
||||
'ņ' => 'n',
|
||||
'ĺ' => 'l',
|
||||
'ħ' => 'h',
|
||||
'ṗ' => 'p',
|
||||
'ó' => 'o',
|
||||
'ú' => 'u',
|
||||
'ě' => 'e',
|
||||
'é' => 'e',
|
||||
'ç' => 'c',
|
||||
'ẁ' => 'w',
|
||||
'ċ' => 'c',
|
||||
'õ' => 'o',
|
||||
'ṡ' => 's',
|
||||
'ø' => 'o',
|
||||
'ģ' => 'g',
|
||||
'ŧ' => 't',
|
||||
'ș' => 's',
|
||||
'ė' => 'e',
|
||||
'ĉ' => 'c',
|
||||
'ś' => 's',
|
||||
'î' => 'i',
|
||||
'ű' => 'u',
|
||||
'ć' => 'c',
|
||||
'ę' => 'e',
|
||||
'ŵ' => 'w',
|
||||
'ṫ' => 't',
|
||||
'ū' => 'u',
|
||||
'č' => 'c',
|
||||
'ö' => 'oe',
|
||||
'è' => 'e',
|
||||
'ŷ' => 'y',
|
||||
'ą' => 'a',
|
||||
'ł' => 'l',
|
||||
'ų' => 'u',
|
||||
'ů' => 'u',
|
||||
'ş' => 's',
|
||||
'ğ' => 'g',
|
||||
'ļ' => 'l',
|
||||
'ƒ' => 'f',
|
||||
'ž' => 'z',
|
||||
'ẃ' => 'w',
|
||||
'ḃ' => 'b',
|
||||
'å' => 'a',
|
||||
'ì' => 'i',
|
||||
'ï' => 'i',
|
||||
'ḋ' => 'd',
|
||||
'ť' => 't',
|
||||
'ŗ' => 'r',
|
||||
'ä' => 'ae',
|
||||
'í' => 'i',
|
||||
'ŕ' => 'r',
|
||||
'ê' => 'e',
|
||||
'ü' => 'ue',
|
||||
'ò' => 'o',
|
||||
'ē' => 'e',
|
||||
'ñ' => 'n',
|
||||
'ń' => 'n',
|
||||
'ĥ' => 'h',
|
||||
'ĝ' => 'g',
|
||||
'đ' => 'd',
|
||||
'ĵ' => 'j',
|
||||
'ÿ' => 'y',
|
||||
'ũ' => 'u',
|
||||
'ŭ' => 'u',
|
||||
'ư' => 'u',
|
||||
'ţ' => 't',
|
||||
'ý' => 'y',
|
||||
'ő' => 'o',
|
||||
'â' => 'a',
|
||||
'ľ' => 'l',
|
||||
'ẅ' => 'w',
|
||||
'ż' => 'z',
|
||||
'ī' => 'i',
|
||||
'ã' => 'a',
|
||||
'ġ' => 'g',
|
||||
'ṁ' => 'm',
|
||||
'ō' => 'o',
|
||||
'ĩ' => 'i',
|
||||
'ù' => 'u',
|
||||
'į' => 'i',
|
||||
'ź' => 'z',
|
||||
'á' => 'a',
|
||||
'û' => 'u',
|
||||
'þ' => 'th',
|
||||
'ð' => 'dh',
|
||||
'æ' => 'ae',
|
||||
'µ' => 'u',
|
||||
'ĕ' => 'e',
|
||||
'œ' => 'oe');
|
||||
}
|
||||
|
||||
$string = str_replace(array_keys($UTF8_LOWER_ACCENTS), array_values($UTF8_LOWER_ACCENTS), $string);
|
||||
}
|
||||
|
||||
if ($case >= 0)
|
||||
{
|
||||
if (is_null($UTF8_UPPER_ACCENTS))
|
||||
{
|
||||
$UTF8_UPPER_ACCENTS = array(
|
||||
'À' => 'A',
|
||||
'Ô' => 'O',
|
||||
'Ď' => 'D',
|
||||
'Ḟ' => 'F',
|
||||
'Ë' => 'E',
|
||||
'Š' => 'S',
|
||||
'Ơ' => 'O',
|
||||
'Ă' => 'A',
|
||||
'Ř' => 'R',
|
||||
'Ț' => 'T',
|
||||
'Ň' => 'N',
|
||||
'Ā' => 'A',
|
||||
'Ķ' => 'K',
|
||||
'Ŝ' => 'S',
|
||||
'Ỳ' => 'Y',
|
||||
'Ņ' => 'N',
|
||||
'Ĺ' => 'L',
|
||||
'Ħ' => 'H',
|
||||
'Ṗ' => 'P',
|
||||
'Ó' => 'O',
|
||||
'Ú' => 'U',
|
||||
'Ě' => 'E',
|
||||
'É' => 'E',
|
||||
'Ç' => 'C',
|
||||
'Ẁ' => 'W',
|
||||
'Ċ' => 'C',
|
||||
'Õ' => 'O',
|
||||
'Ṡ' => 'S',
|
||||
'Ø' => 'O',
|
||||
'Ģ' => 'G',
|
||||
'Ŧ' => 'T',
|
||||
'Ș' => 'S',
|
||||
'Ė' => 'E',
|
||||
'Ĉ' => 'C',
|
||||
'Ś' => 'S',
|
||||
'Î' => 'I',
|
||||
'Ű' => 'U',
|
||||
'Ć' => 'C',
|
||||
'Ę' => 'E',
|
||||
'Ŵ' => 'W',
|
||||
'Ṫ' => 'T',
|
||||
'Ū' => 'U',
|
||||
'Č' => 'C',
|
||||
'Ö' => 'Oe',
|
||||
'È' => 'E',
|
||||
'Ŷ' => 'Y',
|
||||
'Ą' => 'A',
|
||||
'Ł' => 'L',
|
||||
'Ų' => 'U',
|
||||
'Ů' => 'U',
|
||||
'Ş' => 'S',
|
||||
'Ğ' => 'G',
|
||||
'Ļ' => 'L',
|
||||
'Ƒ' => 'F',
|
||||
'Ž' => 'Z',
|
||||
'Ẃ' => 'W',
|
||||
'Ḃ' => 'B',
|
||||
'Å' => 'A',
|
||||
'Ì' => 'I',
|
||||
'Ï' => 'I',
|
||||
'Ḋ' => 'D',
|
||||
'Ť' => 'T',
|
||||
'Ŗ' => 'R',
|
||||
'Ä' => 'Ae',
|
||||
'Í' => 'I',
|
||||
'Ŕ' => 'R',
|
||||
'Ê' => 'E',
|
||||
'Ü' => 'Ue',
|
||||
'Ò' => 'O',
|
||||
'Ē' => 'E',
|
||||
'Ñ' => 'N',
|
||||
'Ń' => 'N',
|
||||
'Ĥ' => 'H',
|
||||
'Ĝ' => 'G',
|
||||
'Đ' => 'D',
|
||||
'Ĵ' => 'J',
|
||||
'Ÿ' => 'Y',
|
||||
'Ũ' => 'U',
|
||||
'Ŭ' => 'U',
|
||||
'Ư' => 'U',
|
||||
'Ţ' => 'T',
|
||||
'Ý' => 'Y',
|
||||
'Ő' => 'O',
|
||||
'Â' => 'A',
|
||||
'Ľ' => 'L',
|
||||
'Ẅ' => 'W',
|
||||
'Ż' => 'Z',
|
||||
'Ī' => 'I',
|
||||
'Ã' => 'A',
|
||||
'Ġ' => 'G',
|
||||
'Ṁ' => 'M',
|
||||
'Ō' => 'O',
|
||||
'Ĩ' => 'I',
|
||||
'Ù' => 'U',
|
||||
'Į' => 'I',
|
||||
'Ź' => 'Z',
|
||||
'Á' => 'A',
|
||||
'Û' => 'U',
|
||||
'Þ' => 'Th',
|
||||
'Ð' => 'Dh',
|
||||
'Æ' => 'Ae',
|
||||
'Ĕ' => 'E',
|
||||
'Œ' => 'Oe');
|
||||
}
|
||||
$string = str_replace(array_keys($UTF8_UPPER_ACCENTS), array_values($UTF8_UPPER_ACCENTS), $string);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user