git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3092 3807eeeb-6ff5-0310-8944-8be069107fe0

This commit is contained in:
phpnut 2006-06-14 19:06:14 +00:00
parent 4423f4d400
commit 0801dce999
15 changed files with 3193 additions and 6 deletions

View file

@ -910,21 +910,169 @@
}
}
/**
*
* Returns a translated string if one is found,
* or the submitted message if not found.
*
* @param unknown_type $msg
* @param unknown_type $return
* @param unknown_type $msg
* @param unknown_type $return
* @return unknown
* @todo Not implemented fully till 2.0
*/
function __($msg, $return = null) {
if (is_null($return)) {
echo($msg);
if(!class_exists('I18n')) {
uses('i18n');
}
$calledFrom = debug_backtrace();
$dir = dirname($calledFrom[0]['file']);
if(is_null($return)) {
echo I18n::translate($msg, $msg2=NULL, $domain=NULL, $category=NULL, $count=NULL, $dir);
} else {
return $msg;
return I18n::translate($msg, $msg2=NULL, $domain=NULL, $category=NULL, $count=NULL, $dir);
}
}
/**
*
* Returns correct plural form of message identified by $msg1 and $msg2 for count $count.
* Some languages have more than one form for plural messages dependent on the count.
*
* @param unknown_type $msg1
* @param unknown_type $msg2
* @param unknown_type $count
* @param unknown_type $return
* @return unknown
*/
function __n($msg1, $msg2, $count, $return = null) {
if(!class_exists('I18n')) {
uses('i18n');
}
$calledFrom = debug_backtrace();
$dir = dirname($calledFrom[0]['file']);
if(is_null($return)) {
echo I18n::translate($msg1, $msg2, NULL, NULL, $count, $dir);
} else {
return I18n::translate($msg1, $msg2, NULL, NULL, $count, $dir);
}
}
/**
*
* Allows you to override the current domain for a single plural message lookup
* Returns correct plural form of message identified by $msg1 and $msg2 for count $count
* from domain $domain
*
* @param unknown_type $domain
* @param unknown_type $msg1
* @param unknown_type $msg2
* @param unknown_type $count
* @param unknown_type $return
* @return unknown
*/
function __dn($domain, $msg1, $msg2, $count, $return = null) {
if(!class_exists('I18n')) {
uses('i18n');
}
$calledFrom = debug_backtrace();
$dir = dirname($calledFrom[0]['file']);
if(is_null($return)) {
echo I18n::translate($msg1, $msg2, $domain, NULL, $count, $dir);;
} else {
return I18n::translate($msg1, $msg2, $domain, NULL, $count, $dir);
}
}
/**
*
* Allows you to override the current domain for a single plural message lookup.
* It also allows you to specify a category.
* Returns correct plural form of message identified by $msg1 and $msg2 for count $count
* from domain $domain
*
* The category argument allows a specific category of the locale settings to be used for fetching a message.
* Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.
*
* Note that the category must be specified with a numeric value, instead of the constant name. The values are:
* LC_CTYPE 0
* LC_NUMERIC 1
* LC_TIME 2
* LC_COLLATE 3
* LC_MONETARY 4
* LC_MESSAGES 5
* LC_ALL 6
*
* @param unknown_type $domain
* @param unknown_type $msg1
* @param unknown_type $msg2
* @param unknown_type $count
* @param unknown_type $category
* @param unknown_type $return
* @return unknown
*/
function __dcn($domain, $msg1, $msg2, $count, $category, $return = null) {
if(!class_exists('I18n')) {
uses('i18n');
}
$calledFrom = debug_backtrace();
$dir = dirname($calledFrom[0]['file']);
if(is_null($return)) {
echo I18n::translate($msg1, $msg2, $domain, $category, $count, $dir);
} else {
return I18n::translate($msg1, $msg2, $domain, $category, $count, $dir);
}
}
/**
*
* Allows you to override the current domain for a single message lookup.
* It also allows you to specify a category.
*
* The category argument allows a specific category of the locale settings to be used for fetching a message.
* Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.
*
* Note that the category must be specified with a numeric value, instead of the constant name. The values are:
* LC_CTYPE 0
* LC_NUMERIC 1
* LC_TIME 2
* LC_COLLATE 3
* LC_MONETARY 4
* LC_MESSAGES 5
* LC_ALL 6
*
* @param unknown_type $domain
* @param unknown_type $msg
* @param unknown_type $category
* @param unknown_type $return
* @return unknown
*/
function __dc($domain, $msg, $category, $return = null) {
if(!class_exists('I18n')) {
uses('i18n');
}
$calledFrom = debug_backtrace();
$dir = dirname($calledFrom[0]['file']);
if(is_null($return)) {
echo I18n::translate($msg, NULL, $domain, $category, NULL, $dir);
} else {
return I18n::translate($msg, NULL, $domain, $category, NULL, $dir);
}
}
/**
*
* Allows you to override the current domain for a single message lookup.
*
* @param unknown_type $domain
* @param unknown_type $msg
* @param unknown_type $return
* @return unknown
*/
function __d($domain, $msg, $return = null) {
if(!class_exists('I18n')) {
uses('i18n');
}
$calledFrom = debug_backtrace();
$dir = dirname($calledFrom[0]['file']);
if(is_null($return)) {
echo I18n::translate($msg, NULL, $domain, NULL, NULL, $dir);
} else {
return I18n::translate($msg, NULL, $domain, NULL, NULL, $dir);
}
}
/**
* Counts the dimensions of an array
*

627
cake/libs/i18n.php Normal file
View file

@ -0,0 +1,627 @@
<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
* Copyright (c) 2005, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
* @package cake
* @subpackage cake.cake.libs
* @since CakePHP v 0.10.3.1465
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Included libraries.
*/
uses('l10n');
/**
* Short description for file.
*
* Long description for file
*
* @package cake
* @subpackage cake.cake.libs
* @since CakePHP v 0.10.3.1465
*/
class I18n extends Object
{
/**
* Enter description here...
*
* @var unknown_type
* @access private
*/
var $_l10n = null;
/**
* Enter description here...
*
* @var unknown_type
*/
var $locale = null;
/**
* Enter description here...
*
* @var unknown_type
* @access private
*/
var $_domains = array();
/**
* Enter description here...
*
* @var unknown_type
* @access private
*/
var $_noLocal = null;
/**
* Enter description here...
*
* @return unknown
*/
function &getInstance()
{
static $instance = array();
if (!$instance)
{
$instance[0] =& new I18n();
$instance[0]->_l10n =& new L10n();
}
return $instance[0];
}
/**
* Enter description here...
*
* @param unknown_type $message
* @param unknown_type $message2
* @param unknown_type $domain
* @param unknown_type $category
* @param unknown_type $count
* @param unknown_type $directory
* @return unknown
*/
function translate($message, $message2 = NULL, $domain = NULL, $category = NULL, $count = NULL, $directory)
{
$_this =& I18n::getInstance();
if(!empty($_SESSION['Config']['locale']))
{
$_this->locale = $_SESSION['Config']['locale'];
}
else
{
$_this->locale = $_this->_l10n->locale;
}
if(is_null($domain))
{
if (preg_match('/views{0,1}\\'.DS.'([^\/]*)/', $directory, $regs))
{
$domain = $regs[1];
}
elseif (preg_match('/controllers{0,1}\\'.DS.'([^\/]*)/', $directory, $regs))
{
$domain = ($regs[1]);
}
if(isset($domain) && $domain == 'templates')
{
if (preg_match('/templates{0,1}\\'.DS.'([^\/]*)/', $directory, $regs))
{
$domain = ($regs[1]);
}
}
}
if(!isset($_this->_domains[$domain]))
{
$_this->_bindTextDomain($domain);
}
if (!isset($count))
{
$pli = 0;
}
elseif (!empty($_this->_domains[$domain]["%plural-c"]) && is_null($_this->_noLocal))
{
$ph = $_this->_domains[$domain]["%plural-c"];
$pli = $_this->_pluralGuess($ph, $count);
}
else
{
if ($count != 1)
{
$pli = 1;
}
else
{
$pli = 0;
}
}
if(!empty($_this->_domains[$domain][$message]))
{
if (($trans = $_this->_domains[$domain][$message]) || ($pli) && ($trans = $_this->_domains[$domain][$message2]))
{
if (is_array($trans))
{
if (!isset($trans[$pli]))
{
$pli = 0;
}
$trans = $trans[$pli];
}
if (strlen($trans))
{
$message = $trans;
return $message;
}
}
}
if(!empty($pli))
{
return($message2);
}
else
{
return($message);
}
}
/**
* Enter description here...
*
* @param unknown_type $type
* @param unknown_type $n
* @return unknown
* @access private
*/
function _pluralGuess(&$type, $n)
{
if (is_string($type))
{
if (($type == "nplurals=1;plural=0;") || !strlen($type))
{
$type = -1;
}
elseif ($type == "nplurals=2;plural=n!=1;")
{
$type = 1;
}
elseif ($type == "nplurals=2;plural=n>1;")
{
$type = 2;
}
elseif (strpos($type, "n%100!=11"))
{
if (strpos($type, "n!=0"))
{
$type == 21;
}
if (strpos($type, "n%10<=4"))
{
$type = 22;
}
if (strpos($type, "n%10>=2"))
{
$type = 23;
}
}
elseif (strpos($type, "n<=4"))
{
$type = 25;
}
elseif (strpos($type, "n==2"))
{
$type = 31;
}
elseif (strpos($type, "n%10>=2"))
{
$type = 26;
}
elseif (strpos($type, "n%100==3"))
{
$type = 28;
}
elseif (strpos($type, ";plural=n;"))
{
$type = 7;
}
else
{
$type = 0;
}
}
switch ($type)
{
case -1:
return (0);
case 1:
if ($n != 1)
{
return (1);
}
else
{
return (0);
}
case 2:
if ($n > 1)
{
return (1);
}
else
{
return (0);
}
case 7:
return ($n);
case 21:
if (($n % 10 == 1) && ($n % 100 != 11))
{
return (0);
}
else
{
if ($n != 0 )
{
return (1);
}
else
{
return (2);
}
}
case 22:
if (($n % 10 == 1) && ($n % 100 != 11))
{
return (0);
}
else
{
if (($n % 10 >= 2) && ($n % 10 <= 4) && ($n % 100 < 10 || $n % 100 >= 20))
{
return (1);
}
else
{
return (2);
}
}
case 23:
if (($n % 10 == 1) && ($n % 100 != 11))
{
return (0);
}
else
{
if (($n %10 >= 2) && ($n % 100 < 10 || $n % 100 >= 20))
{
return (1);
}
else
{
return (2);
}
}
case 25:
if ($n==1)
{
return (0);
}
else
{
if ($n >= 2 && $n <= 4)
{
return (1);
}
else
{
return (2);
}
}
case 26:
if ($n==1)
{
return (0);
}
else
{
if ($n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20))
{
return (1);
}
else
{
return (2);
}
}
case 28:
if ($n % 100 == 1)
{
return (0);
}
else
{
if ($n % 100 == 2 || $n % 100 == 3 || $n % 100 == 4)
{
return (2);
}
else
{
return (3);
}
}
case 31:
if ($n == 1)
{
return (0);
}
else
{
if ($n == 2)
{
return (1);
}
else
{
return (2);
}
}
default:
$type = -1;
}
return(0);
}
/**
* Enter description here...
*
* @param unknown_type $domain
* @return unknown
* @access private
*/
function _bindTextDomain($domain)
{
$_this =& I18n::getInstance();
$_this->_noLocal = true;
$searchPath[] = VIEWS.$domain.DS."locale";
$searchPath[] = CAKE."locale";
foreach (explode(",",$_this->locale) as $d)
{
$d = trim($d);
$d = strtok($d, "@.-+=%:; ");
if (strlen($d))
{
$dir[] = $d;
}
if (strpos($d, "_"))
{
$dir[] = strtok($d, "_");
}
}
foreach ($searchPath as $directory)
{
foreach ($dir as $lang)
{
$file = "$directory".DS."$lang".DS."LC_MESSAGES".DS."$domain";
if (file_exists($fn = "$file.mo") && ($f = fopen($fn, "rb")))
{
$_this->_loadMo($f, $domain);
$_this->_noLocal = null;
break 2;
}
elseif (file_exists($fn = "$file.po") && ($f = fopen($fn, "r")))
{
$_this->_loadPo($f, $domain);
$_this->_noLocal = null;
break 2;
}
}
}
if(empty($_this->_domains[$domain]))
{
return($domain);
}
if ($head = $_this->_domains[$domain][""])
{
foreach (explode("\n", $head) as $line)
{
$header = strtok($line,":");
$line = trim(strtok("\n"));
$_this->_domains[$domain]["%po-header"][strtolower($header)] = $line;
}
if(isset($_this->_domains[$domain]["%po-header"]["plural-forms"]))
{
$switch = preg_replace("/[(){}\\[\\]^\\s*\\]]+/", "", $_this->_domains[$domain]["%po-header"]["plural-forms"]);
$_this->_domains[$domain]["%plural-c"] = $switch;
}
}
return($domain);
}
/**
* Enter description here...
*
* @param unknown_type $file
* @param unknown_type $domain
* @access private
*/
function _loadMo($file, $domain)
{
$_this =& I18n::getInstance();
$data = fread($file, 1<<20);
fclose($file);
if ($data)
{
$header = substr($data, 0, 20);
$header = unpack("L1magic/L1version/L1count/L1o_msg/L1o_trn", $header);
extract($header);
if ((dechex($magic) == "950412de") && ($version == 0))
{
for ($n=0; $n<$count; $n++)
{
$r = unpack("L1len/L1offs", substr($data, $o_msg + $n * 8, 8));
$msgid = substr($data, $r["offs"], $r["len"]);
unset($msgid_plural);
if (strpos($msgid, "\000"))
{
list($msgid, $msgid_plural) = explode("\000", $msgid);
}
$r = unpack("L1len/L1offs", substr($data, $o_trn + $n * 8, 8));
$msgstr = substr($data, $r["offs"], $r["len"]);
if (strpos($msgstr, "\000"))
{
$msgstr = explode("\000", $msgstr);
}
$_this->_domains[$domain][$msgid] = $msgstr;
if (isset($msgid_plural))
{
$_this->_domains[$domain][$msgid_plural] = &$_this->_domains[$domain][$msgid];
}
}
}
}
}
/**
* Enter description here...
*
* @param unknown_type $file
* @param unknown_type $domain
* @return unknown
* @access private
*/
function _loadPo($file, $domain)
{
$_this =& I18n::getInstance();
$type = 0;
$translations = array();
$translationKey = "";
$plural = 0;
$header = "";
do
{
$line = trim(fgets($file,1024));
if ($line == "" || $line[0] == "#")
{
continue;
}
if (preg_match("/msgid[[:space:]]+\"(.+)\"$/i", $line, $regs))
{
$type = 1;
$translationKey = stripcslashes($regs[1]);
}
elseif (preg_match("/msgid[[:space:]]+\"\"$/i", $line, $regs))
{
$type = 2;
$translationKey = "";
}
elseif (preg_match("/^\"(.*)\"$/i", $line, $regs) && ($type == 1 || $type == 2 || $type == 3))
{
$type = 3;
$translationKey .= stripcslashes($regs[1]);
}
elseif (preg_match("/msgstr[[:space:]]+\"(.+)\"$/i", $line, $regs) && ($type == 1 || $type == 3) && $translationKey)
{
$translations[$translationKey] = stripcslashes($regs[1]);
$type = 4;
} elseif (preg_match("/msgstr[[:space:]]+\"\"$/i", $line, $regs) && ($type == 1 || $type == 3) && $translationKey)
{
$type = 4;
$translations[$translationKey] = "";
} elseif (preg_match("/^\"(.*)\"$/i", $line, $regs) && $type == 4 && $translationKey)
{
$translations[$translationKey] .= stripcslashes($regs[1]);
} elseif (preg_match("/msgid_plural[[:space:]]+\".*\"$/i", $line, $regs))
{
$type = 6;
}
elseif (preg_match("/msgstr\[(\d+)\][[:space:]]+\"(.+)\"$/i", $line, $regs) && ($type == 6) && $translationKey)
{
$plural = $regs[1];
$translations[$translationKey][$plural] = stripcslashes($regs[2]);
$type = 6;
}
elseif (preg_match("/msgstr\[(\d+)\][[:space:]]+\"\"$/i", $line, $regs) && ($type == 6) && $translationKey)
{
$plural = $regs[1];
$translations[$translationKey][$plural] = "";
$type = 6;
}
elseif (preg_match("/^\"(.*)\"$/i", $line, $regs) && $type == 6 && $translationKey)
{
$translations[$translationKey][$plural] .= stripcslashes($regs[1]);
}
elseif (preg_match("/msgstr[[:space:]]+\"(.+)\"$/i", $line, $regs) && $type == 2 && !$translationKey)
{
$header = stripcslashes($regs[1]);
$type = 5;
}
elseif (preg_match("/msgstr[[:space:]]+\"\"$/i", $line, $regs) && !$translationKey)
{
$header = "";
$type = 5;
}
elseif (preg_match("/^\"(.*)\"$/i", $line, $regs) && $type == 5)
{
$header .= stripcslashes($regs[1]);
}
else
{
unset($translations[$translationKey]);
$type = 0;
$translationKey = "";
$plural = 0;
}
} while(!feof($file));
fclose($file);
$merge[""] = $header;
return $_this->_domains[$domain] = array_merge($merge ,$translations);
}
/**
* Enter description here...
*
* @param unknown_type $domain
* @param unknown_type $codeset
* @return unknown
* @access private
* @todo Not implemented
*/
function _bindTextDomainCodeset($domain, $codeset)
{
return($domain);
}
}
?>

1202
cake/libs/l10n.php Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,18 @@
CREATE TABLE `i18n` (
`id` int(11) NOT NULL auto_increment,
`locale` varchar(8) NOT NULL default '',
`i18n_content_id` int(11) NOT NULL default '0',
`model` varchar(255) NOT NULL default '',
`row_id` int(11) NOT NULL default '0',
`field` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`),
KEY `row_id` (`row_id`),
KEY `model` (`model`),
KEY `field` (`field`)
);
CREATE TABLE `i18n_content` (
`id` int(11) NOT NULL auto_increment,
`content` text,
PRIMARY KEY (`id`)
);

View file

@ -0,0 +1,688 @@
<?php
/* SVN FILE: $Id$*
/**
* Short description for file.
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
* Copyright (c) 2005, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
* @package cake
* @subpackage cake.cake.libs.model.i18n
* @since CakePHP v 0.10.0.1554
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Short description for file.
*
* Long description for file
*
* @package cake
* @subpackage cake.cake.libs.model.i18n
* @since CakePHP v 0.10.0.1554
*
*/
class Translate extends Model
{
var $locale = array('Afar' => 'aa',
'Abkhazian' => 'ab',
'Achinese' => 'ace',
'Acoli' => 'ach',
'Adangme' => 'ada',
'Adyghe; Adygei' => 'ady',
'Avestan' => 'ae',
'Afrikaans' => 'af',
'Afro-Asiatic (Other)' => 'afa',
'Afrihili' => 'afh',
'Ainu' => 'ain',
'Akan' => 'ak',
'Akkadian' => 'akk',
'Aleut' => 'ale',
'Algonquian Languages' => 'alg',
'Southern Altai' => 'alt',
'Amharic' => 'am',
'Aragonese' => 'an',
'English Old' => 'ang',
'Apache languages' => 'apa',
'Arabic' => 'ar',
'Arabic (U.A.E.)' => 'ar-ae',
'Arabic (Bahrain)' => 'ar-bh',
'Arabic (Algeria)' => 'ar-dz',
'Arabic (Egypt)' => 'ar-eg',
'Arabic (Iraq)' => 'ar-iq',
'Arabic (Jordan)' => 'ar-jo',
'Arabic (Kuwait)' => 'ar-kw',
'Arabic (Lebanon)' => 'ar-lb',
'Arabic (Libya)' => 'ar-ly',
'Arabic (Morocco)' => 'ar-ma',
'Arabic (Oman)' => 'ar-om',
'Arabic (Qatar)' => 'ar-qa',
'Arabic (Saudi Arabia)' => 'ar-sa',
'Arabic (Syria)' => 'ar-sy',
'Arabic (Tunisia)' => 'ar-tn',
'Arabic (Yemen)' => 'ar-ye',
'Aramaic' => 'arc',
'Araucanian' => 'arn',
'Arapaho' => 'arp',
'Arawak' => 'arw',
'Assamese' => 'as',
'Asturian' => 'ast',
'Athapascan languages' => 'ath',
'Australian languages' => 'aus',
'Avaric' => 'av',
'Awadhi' => 'awa',
'Aymara' => 'ay',
'Azerbaijani' => 'az',
'Bashkir' => 'ba',
'Banda' => 'bad',
'Bamileke languages' => 'bai',
'Baluchi' => 'bal',
'Bambara' => 'bam',
'Balinese' => 'ban',
'Basa' => 'bas',
'Baltic (Other)' => 'bat',
'Belarusian' => 'be',
'Beja' => 'bej',
'Belarusian' => 'bel',
'Bemba' => 'bem',
'Bengali' => 'ben',
'Berber (Other)' => 'ber',
'Bulgarian' => 'bg',
'Bihari' => 'bh',
'Bhojpuri' => 'bho',
'Bislama' => 'bi',
'Bihari' => 'bih',
'Bikol' => 'bik',
'Bini' => 'bin',
'Bislama' => 'bis',
'Siksika' => 'bla',
'Bambara' => 'bm',
'Bengali' => 'bn',
'Bantu (Other)' => 'bnt',
'Tibetan' => 'bo',
'Breton' => 'br',
'Braj' => 'bra',
'Bosnian' => 'bs',
'Batak (Indonesia)' => 'btk',
'Buriat' => 'bua',
'Buginese' => 'bug',
'Blin; Bilin' => 'byn',
'Catalan' => 'ca',
'Caddo' => 'cad',
'Central American Indian (Other)' => 'cai',
'Carib' => 'car',
'Caucasian (Other)' => 'cau',
'Chechen' => 'ce',
'Cebuano' => 'ceb',
'Celtic (Other)' => 'cel',
'Chamorro' => 'ch',
'Chamorro' => 'cha',
'Chibcha' => 'chb',
'Chagatai' => 'chg',
'Chuukese' => 'chk',
'Mari' => 'chm',
'Chinook jargon' => 'chn',
'Choctaw' => 'cho',
'Chipewyan' => 'chp',
'Cherokee' => 'chr',
'Cheyenne' => 'chy',
'Chamic languages' => 'cmc',
'Corsican' => 'co',
'Coptic' => 'cop',
'Creoles and pidgins English based (Other)' => 'cpe',
'Creoles and pidgins French-based (Other)' => 'cpf',
'Creoles and pidgins' => 'cpp',
'Cree' => 'cr',
'Crimean Tatar; Crimean Turkish' => 'crh',
'Creoles and pidgins (Other)' => 'crp',
'Czech' => 'cs',
'Kashubian' => 'csb',
'Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic' => 'cu',
'Cushitic (Other)' => 'cus',
'Chuvash' => 'cv',
'Welsh' => 'cy',
'Danish' => 'da',
'Dakota' => 'dak',
'Dargwa' => 'dar',
'Dayak' => 'day',
'German (Germany)' => 'de',
'German (Austria)' => 'de-at',
'German (Switzerland)' => 'de-ch',
'German (Germany)' => 'de-de',
'German (Liechtenstein)' => 'de-li',
'German (luxembourg)' => 'de-lu',
'Delaware' => 'del',
'Slave (Athapascan)' => 'den',
'Dogrib' => 'dgr',
'Dinka' => 'din',
'Dogri' => 'doi',
'Dravidian (Other)' => 'dra',
'Lower Sorbian' => 'dsb',
'Duala' => 'dua',
'Dutch Middle' => 'dum',
'Divehi' => 'dv',
'Dyula' => 'dyu',
'Dzongkha' => 'dz',
'Dzongkha' => 'dzo',
'Ewe' => 'ee',
'Efik' => 'efi',
'Egyptian (Ancient)' => 'egy',
'Ekajuk' => 'eka',
'Greek' => 'el',
'Elamite' => 'elx',
'English' => 'en',
'English (Australia)' => 'en-au',
'English (Belize)' => 'en-bz',
'English (Canada)' => 'en-ca',
'English (United Kingdom)' => 'en-gb',
'English (Ireland)' => 'en-ie',
'English (Jamaica)' => 'en-jm',
'English (New Zealand)' => 'en-nz',
'English (Philippines)' => 'en-ph',
'English (Trinidad)' => 'en-tt',
'English (United States)' => 'en-us',
'English (South Africa)' => 'en-za',
'English (Zimbabwe)' => 'en-zw',
'English Middle' => 'enm',
'Esperanto' => 'eo',
'Spanish (Spain)' => 'es',
'Spanish (Argentina)' => 'es-ar',
'Spanish (Bolivia)' => 'es-bo',
'Spanish (Chile)' => 'es-cl',
'Spanish (Colombia)' => 'es-co',
'Spanish (Costa Rica)' => 'es-cr',
'Spanish (Dominican Republic)' => 'es-do',
'Spanish (Ecuador)' => 'es-ec',
'Spanish (Guatemala)' => 'es-gt',
'Spanish (Honduras)' => 'es-hn',
'Spanish (Mexico)' => 'es-mx',
'Spanish (Nicaragua)' => 'es-ni',
'Spanish (Panama)' => 'es-pa',
'Spanish (Peru)' => 'es-pe',
'Spanish (Puerto Rico)' => 'es-pr',
'Spanish (Paraguay)' => 'es-py',
'Spanish (El Salvador)' => 'es-sv',
'Spanish (United States)' => 'es-us',
'Spanish (Uruguay)' => 'es-uy',
'Spanish (Venezuela)' => 'es-ve',
'Estonian' => 'et',
'Basque' => 'eu',
'Ewondo' => 'ewo',
'Persian' => 'fa',
'Fang' => 'fan',
'Fanti' => 'fat',
'Fulah' => 'ff',
'Finnish' => 'fi',
'Filipino; Pilipino' => 'fil',
'Finno-Ugrian (Other)' => 'fiu',
'Fijian' => 'fj',
'Faeroese' => 'fo',
'Fon' => 'fon',
'French (France)' => 'fr',
'French (Belgium)' => 'fr-be',
'French (Canada)' => 'fr-ca',
'French (Switzerland)' => 'fr-ch',
'French (Luxembourg)' => 'fr-lu',
'French (Monaco)' => 'fr-mc',
'French Middle' => 'frm',
'French Old' => 'fro',
'Friulian' => 'fur',
'Frisian' => 'fy',
'Irish' => 'ga',
'Ga' => 'gaa',
'Gayo' => 'gay',
'Gbaya' => 'gba',
'Gaelic Hiberno-Scottish' => 'gd',
'Germanic (Other)' => 'gem',
'Geez' => 'gez',
'Gilbertese' => 'gil',
'Galician' => 'gl',
'German Middle High' => 'gmh',
'Guarani' => 'gn',
'German Old High' => 'goh',
'Gondi' => 'gon',
'Gorontalo' => 'gor',
'Gothic' => 'got',
'Grebo' => 'grb',
'Greek Ancient' => 'grc',
'Greek Modern' => 'gre',
'Gujarati' => 'gu',
'Manx' => 'gv',
'Gwich´in' => 'gwi',
'Hausa' => 'ha',
'Haida' => 'hai',
'Hawaiian' => 'haw',
'Hebrew' => 'he',
'Hindi' => 'hi',
'Hiligaynon' => 'hil',
'Himachali' => 'him',
'Hmong' => 'hmn',
'Hiri Motu' => 'ho',
'Croatian' => 'hr',
'Upper Sorbian' => 'hsb',
'Haitian; Haitian Creole' => 'ht',
'Hungarian' => 'hu',
'Hupa' => 'hup',
'Armenian' => 'hy',
'Herero' => 'hz',
'Interlingua (International Auxiliary Language Association)' => 'ia',
'Iban' => 'iba',
'Igbo' => 'ibo',
'Indonesian' => 'id',
'Interlingue' => 'ie',
'Igbo' => 'ig',
'Sichuan Yi' => 'ii',
'Ijo' => 'ijo',
'Inupiaq' => 'ik',
'Inuktitut' => 'iku',
'Interlingue' => 'ile',
'Iloko' => 'ilo',
'Indic (Other)' => 'inc',
'Indonesian' => 'ind',
'Indo-European (Other)' => 'ine',
'Ingush' => 'inh',
'Ido' => 'io',
'Inupiaq' => 'ipk',
'Iranian (Other)' => 'ira',
'Iroquoian languages' => 'iro',
'Icelandic' => 'is',
'Italian (Italy)' => 'it',
'Italian (Switzerland)' => 'it-ch',
'Italian' => 'ita',
'Inuktitut' => 'iu',
'Japanese' => 'ja',
'Javanese' => 'jav',
'Lojban' => 'jbo',
'Japanese' => 'jpn',
'Judeo-Arabic' => 'jrb',
'Javanese' => 'jv',
'Georgian' => 'ka',
'Kara-Kalpak' => 'kaa',
'Kabyle' => 'kab',
'Kachin' => 'kac',
'Kalaallisut; Greenlandic' => 'kal',
'Kamba' => 'kam',
'Kannada' => 'kan',
'Karen' => 'kar',
'Kashmiri' => 'kas',
'Kanuri' => 'kau',
'Kawi' => 'kaw',
'Kazakh' => 'kaz',
'Kabardian' => 'kbd',
'Kongo' => 'kg',
'Khasi' => 'kha',
'Khoisan (Other)' => 'khi',
'Khmer' => 'khm',
'Khotanese' => 'kho',
'Kikuyu; Gikuyu' => 'ki',
'Kikuyu; Gikuyu' => 'kik',
'Kinyarwanda' => 'kin',
'Kirghiz' => 'kir',
'Kazakh' => 'kk',
'Kalaallisut; Greenlandic' => 'kl',
'Khmer' => 'km',
'Kimbundu' => 'kmb',
'Kannada' => 'kn',
'Korean' => 'ko',
'Korea (North) Dem. Rep' => 'ko-kp',
'Korea (South)' => 'ko-kr',
'Russian' => 'koi8-r',
'Konkani' => 'kok',
'Komi' => 'kom',
'Kongo' => 'kon',
'Kosraean' => 'kos',
'Kpelle' => 'kpe',
'Kanuri' => 'kr',
'Karachay-Balkar' => 'krc',
'Kru' => 'kro',
'Kurukh' => 'kru',
'Kashmiri' => 'ks',
'Kurdish' => 'ku',
'Kuanyama; Kwanyama' => 'kua',
'Kumyk' => 'kum',
'Kutenai' => 'kut',
'Komi' => 'kv',
'Cornish' => 'kw',
'Kirghiz' => 'ky',
'Latin' => 'la',
'Ladino' => 'lad',
'Lahnda' => 'lah',
'Lamba' => 'lam',
'Latin' => 'lat',
'Latvian' => 'lav',
'Luxembourgish; Letzeburgesch' => 'lb',
'Lezghian' => 'lez',
'Ganda' => 'lg',
'Limburgan; Limburger; Limburgish' => 'li',
'Limburgan; Limburger; Limburgish' => 'lim',
'Lingala' => 'lin',
'Lingala' => 'ln',
'Lao' => 'lo',
'Mongo' => 'lol',
'Lozi' => 'loz',
'Lithuanian' => 'lt',
'Luxembourgish; Letzeburgesch' => 'ltz',
'Luba-Katanga' => 'lu',
'Luba-Lulua' => 'lua',
'Luba-Katanga' => 'lub',
'Ganda' => 'lug',
'Luiseno' => 'lui',
'Lunda' => 'lun',
'Luo (Kenya and Tanzania)' => 'luo',
'Lushai' => 'lus',
'Latvian' => 'lv',
'Madurese' => 'mad',
'Magahi' => 'mag',
'Marshallese' => 'mah',
'Maithili' => 'mai',
'Makasar' => 'mak',
'Malayalam' => 'mal',
'Mandingo' => 'man',
'Austronesian (Other)' => 'map',
'Marathi' => 'mar',
'Masai' => 'mas',
'Moksha' => 'mdf',
'Mandar' => 'mdr',
'Mende' => 'men',
'Malagasy' => 'mg',
'Irish Middle' => 'mga',
'Marshallese' => 'mh',
'Maori' => 'mi',
'Micmac' => 'mic',
'Minangkabau' => 'min',
'FYRO Macedonian' => 'mk',
'Macedonian' => 'mk-mk',
'Mon-Khmer (Other)' => 'mkh',
'Malayalam' => 'ml',
'Malagasy' => 'mlg',
'Maltese' => 'mlt',
'Mongolian' => 'mn',
'Manchu' => 'mnc',
'Manipuri' => 'mni',
'Manobo languages' => 'mno',
'Moldavian' => 'mo',
'Mohawk' => 'moh',
'Moldavian' => 'mol',
'Mongolian' => 'mon',
'Mossi' => 'mos',
'Marathi' => 'mr',
'Malay' => 'ms',
'Maltese' => 'mt',
'Munda languages' => 'mun',
'Creek' => 'mus',
'Mirandese' => 'mwl',
'Marwari' => 'mwr',
'Burmese' => 'my',
'Mayan languages' => 'myn',
'Erzya' => 'myv',
'Nauru' => 'na',
'Nahuatl' => 'nah',
'North American Indian' => 'nai',
'Neapolitan' => 'nap',
'Nauru' => 'nau',
'Navajo; Navaho' => 'nav',
'Norwegian (Bokmal)' => 'nb',
'Ndebele South; South Ndebele' => 'nbl',
'North Ndebele' => 'nd',
'Ndebele North; North Ndebele' => 'nde',
'Ndonga' => 'ndo',
'Low German; Low Saxon;' => 'nds',
'Nepali (India)' => 'ne',
'Nepali' => 'nep',
'Newari; Nepal Bhasa' => 'new',
'Ndonga' => 'ng',
'Nias' => 'nia',
'Niger-Kordofanian (Other)' => 'nic',
'Niuean' => 'niu',
'Dutch (Netherlands)' => 'nl',
'Dutch (Belgium)' => 'nl-be',
'Norwegian (Nynorsk)' => 'nn',
'Norwegian Nynorsk; Nynorsk Norwegian' => 'nno',
'Norwegian Bokmål' => 'no',
'Norwegian Bokmål; Bokmål Norwegian' => 'nob',
'Nogai' => 'nog',
'Norse Old' => 'non',
'Norwegian' => 'nor',
'South Ndebele' => 'nr',
'Northern Sotho; Pedi; Sepedi' => 'nso',
'Nubian languages' => 'nub',
'Navajo; Navaho' => 'nv',
'Classical Newari; Old Newari; Classical Nepal Bhasa' => 'nwc',
'Chichewa; Chewa; Nyanja' => 'ny',
'Chichewa; Chewa; Nyanja' => 'nya',
'Nyamwezi' => 'nym',
'Nyankole' => 'nyn',
'Nyoro' => 'nyo',
'Nzima' => 'nzi',
'Occitan (post 1500); Provençal' => 'oc',
'Occitan; Provençal' => 'oci',
'Ojibwa' => 'oj',
'Ojibwa' => 'oji',
'Oromo' => 'om',
'Oriya' => 'or',
'Oriya' => 'ori',
'Oromo' => 'orm',
'Ossetian; Ossetic' => 'os',
'Osage' => 'osa',
'Ossetian; Ossetic' => 'oss',
'Turkish Ottoman' => 'ota',
'Otomian languages' => 'oto',
'Panjabi; Punjabi' => 'pa',
'Punjabi (India)' => 'pa-in',
'Punjabi (Pakistan)' => 'pa-pk',
'Papuan (Other)' => 'paa',
'Pangasinan' => 'pag',
'Pahlavi' => 'pal',
'Pampanga' => 'pam',
'Panjabi; Punjabi' => 'pan',
'Papiamento' => 'pap',
'Palauan' => 'pau',
'Persian Old' => 'peo',
'Philippine (Other)' => 'phi',
'Phoenician' => 'phn',
'Pali' => 'pi',
'Polish' => 'pl',
'Pali' => 'pli',
'Polish' => 'pol',
'Pohnpeian' => 'pon',
'Portuguese' => 'por',
'Prakrit languages' => 'pra',
'Provençal Old' => 'pro',
'Pushto' => 'ps',
'Portuguese (Portugal)' => 'pt',
'Portuguese (Brazil)' => 'pt-br',
'Pushto' => 'pus',
'Quechua' => 'qu',
'Quechua' => 'que',
'Rajasthani' => 'raj',
'Rapanui' => 'rap',
'Rarotongan' => 'rar',
'Raeto-Romance' => 'rm',
'Rundi' => 'rn',
'Romanian' => 'ro',
'Romanian (Moldova)' => 'ro-md',
'Romance (Other)' => 'roa',
'Raeto-Romance' => 'roh',
'Romany' => 'rom',
'Russian' => 'ru',
'Russian (Moldova)' => 'ru-md',
'Aromanian' => 'rup',
'Sanskrit' => 'sa',
'Sandawe' => 'sad',
'Yakut' => 'sah',
'South American Indian (Other)' => 'sai',
'Salishan languages' => 'sal',
'Samaritan Aramaic' => 'sam',
'Sasak' => 'sas',
'Santali' => 'sat',
'Sardinian' => 'sc',
'Sicilian' => 'scn',
'Scots' => 'sco',
'Sindhi' => 'sd',
'Northern Sami' => 'se',
'Selkup' => 'sel',
'Semitic (Other)' => 'sem',
'Sango' => 'sg',
'Irish Old' => 'sga',
'Shan' => 'shn',
'Sinhala; Sinhalese' => 'si',
'Sidamo' => 'sid',
'Siouan languages' => 'sio',
'Sino-Tibetan (Other)' => 'sit',
'Slovak' => 'sk',
'Slovenian' => 'sl',
'Slavic (Other)' => 'sla',
'Samoan' => 'sm',
'Southern Sami' => 'sma',
'Sami languages (Other)' => 'smi',
'Lule Sami' => 'smj',
'Inari Sami' => 'smn',
'Skolt Sami' => 'sms',
'Shona' => 'sn',
'Soninke' => 'snk',
'Somali' => 'so',
'Sogdian' => 'sog',
'Songhai' => 'son',
'Albanian' => 'sq',
'Serbian' => 'sr',
'Serer' => 'srr',
'Swati' => 'ss',
'Nilo-Saharan (Other)' => 'ssa',
'Southern Sotho' => 'st',
'Sundanese' => 'su',
'Sukuma' => 'suk',
'Susu' => 'sus',
'Sumerian' => 'sux',
'Swedish' => 'sv',
'Swedish (Finland)' => 'sv-fi',
'Swahili' => 'sw',
'Swahili' => 'swa',
'Swedish' => 'swe',
'Syriac' => 'syr',
'Tamil' => 'ta',
'Tai (Other)' => 'tai',
'Telugu' => 'te',
'Timne' => 'tem',
'Tereno' => 'ter',
'Tetum' => 'tet',
'Tajik' => 'tg',
'Thai' => 'th',
'Tigre' => 'tig',
'Tigrinya|' => 'tir',
'Tiv' => 'tiv',
'Turkmen' => 'tk',
'Tokelau' => 'tkl',
'Tagalog' => 'tl',
'Klingon; tlhIngan-Hol' => 'tlh',
'Tlingit' => 'tli',
'Tamashek' => 'tmh',
'Tswana' => 'tn',
'Tonga (Tonga Islands)' => 'to',
'Tonga (Nyasa)' => 'tog',
'Tok Pisin' => 'tpi',
'Turkish' => 'tr',
'Tsonga' => 'ts',
'Tsimshian' => 'tsi',
'Tatar' => 'tt',
'Tumbuka' => 'tum',
'Tupi languages' => 'tup',
'Altaic (Other)' => 'tut',
'Tuvalu' => 'tvl',
'Twi' => 'tw',
'Tahitian' => 'ty',
'Tuvinian' => 'tyv',
'Udmurt' => 'udm',
'Uighur; Uyghur' => 'ug',
'Ugaritic' => 'uga',
'Ukrainian' => 'uk',
'Umbundu' => 'umb',
'Urdu' => 'ur',
'English (United States)' => 'us',
'Uzbek' => 'uz',
'Vai' => 'vai',
'Venda' => 've',
'Vietnamese' => 'vi',
'Volapük' => 'vo',
'Votic' => 'vot',
'Walloon' => 'wa',
'Wakashan languages' => 'wak',
'Walamo' => 'wal',
'Waray' => 'war',
'Washo' => 'was',
'Sorbian languages' => 'wen',
'Wolof' => 'wo',
'Kalmyk' => 'xal',
'Xhosa' => 'xh',
'Yao' => 'yao',
'Yapese' => 'yap',
'Yiddish' => 'yi',
'Yoruba' => 'yo',
'Yupik languages' => 'ypk',
'Zhuang; Chuang' => 'za',
'Zapotec' => 'zap',
'Zenaga' => 'zen',
'Chinese' => 'zh',
'Chinese (China)' => 'zh-cn',
'Chinese (Hong Kong SAR)' => 'zh-hk',
'Chinese (Macau SAR)' => 'zh-mo',
'Chinese (Singapore)' => 'zh-sg',
'Chinese (Taiwan)' => 'zh-tw',
'Zande' => 'znd',
'Zulu' => 'zu',
'Zuni' => 'zun');
function read ($id = null, $fields = null)
{
$result = parent::read($id, $fields);
}
function field ($name, $conditions = null, $order = null)
{
$result = parent::field ($name, $conditions, $order);
}
function saveField($name, $value, $validate = false)
{
$result = parent::saveField($name, $value, $validate );
}
function save ($data=null, $validate=true)
{
$result = parent::save ($data, $validate);
}
function del ($id = null)
{
$result = parent::del($id);
}
function find ($conditions = null, $fields = null, $order = null, $recursive = 1)
{
$result = parent::find($conditions , $fields , $order , $recursive);
}
function findAll ($conditions = null, $fields = null, $order = null, $limit = 50, $page = 1, $recursive = 1)
{
$result = parent::findAll($conditions , $fields , $order , $limit , $page , $recursive);
}
}
?>

504
cake/libs/validation.php Normal file
View file

@ -0,0 +1,504 @@
<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
* Copyright (c) 2005, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
* @package cake
* @subpackage cake.cake.libs
* @since CakePHP v 0.10.3.1343
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Short description for file.
*
* Long description for file
*
* @package cake
* @subpackage cake.cake.libs
* @since CakePHP v 0.10.3.1343
*/
class Validation //extends Object
{
/**
* Enter description here...
*
* @var unknown_type
*/
var $check = null;
/**
* Enter description here...
*
* @var unknown_type
*/
var $regex = null;
/**
* Enter description here...
*
* @var unknown_type
*/
var $country = null;
/**
* Enter description here...
*
* @var unknown_type
*/
var $deep = null;
/**
* Enter description here...
*
* @var unknown_type
*/
var $type = null;
/**
* Enter description here...
*
* @var unknown_type
*/
var $errors = array();
function __construct()
{
//parent::__construct();
}
function alphaNumeric($check)
{
}
function between($check, $min, $max)
{
$length = strlen($check);
if ($length >= $min && $length <= $max)
{
return true;
}
else
{
return false;
}
}
/**
* Returns false if field is left blank -OR- only whitespace characters are present in it's value
* Whitespace characters include Space, Tab, Carriage Return, Newline, Formfeed
*
* @param array or string $check
* @return boolean
*/
function blank($check)
{
if (is_array($check))
{
$this->_extract($check);
$this->regex = '/\\S*/';
}
else
{
$this->check = $check;
$this->regex = '/\\S*/';
}
return $this->_check();
}
function cc($check, $regex = null, $type = 'fast')
{
$this->type = $type;
if (is_array($check))
{
$this->_extract($check);
}
else
{
$this->check = $check;
}
if(isset($this->regex))
{
return $this->_check();
}
$cards = array('all' => array('visa' => '/^4\\d{12}(\\d{3})?$/',
'mc' => '/^5[1-5]\\d{14}$/',
'disc' => '/^6011\\d{12}$/',
'amex' => '/^3[4|7]\\d{13}$/',
'diners' => '/^3[0|6|8]\\d{12}$/',
'enroute' => '/^2[014|149]\\d{11}$/',
'jcb' => '/^3[088|096|112|158|337|528]\\d{12}$/',
'switch' => '/^(49030[2-9]|49033[5-9]|49110[1-2]|4911(7[4-9]|8[1-2])|4936[0-9]{2}|564182|6333[0-4][0-9]|6759[0-9]{2})\\d{10}(\\d{2,3})?$/',
'delta' => '/^4(1373[3-7]|462[0-9]{2}|5397[8|9]|54313|5443[2-5]|54742|567(2[5-9]|3[0-9]|4[0-5])|658[3-7][0-9]|659(0[1-9]|[1-4][0-9]|50)|844[09|10]|909[6-7][0-9]|9218[1|2]|98824)\\d{10}$/',
'solo' => '/^(6334[5-9][0-9]|6767[0-9]{2})\\d{10}(\\d{2,3})?$/'),
'fast' => '/^(6334[5-9][0-9]|6767[0-9]{2})\\d{10}(\\d{2,3})?$/');
if (is_array($this->type))
{
foreach ($this->type as $key => $value)
{
$card = low($key);
$this->regex = $cards['all'][$card];
if($this->_check())
{
return true;
}
}
}
else
{
if($this->type == 'all')
{
foreach ($cards['all'] as $key => $value)
{
$this->regex = $value;
if($this->_check())
{
return true;
}
}
}
else
{
$this->regex = $cards['fast'];
return $this->_check();
}
}
}
function comparison($check1, $operator = null, $check2 = null)
{
$return = false;
if (is_array($check1))
{
extract($params, EXTR_OVERWRITE);
}
switch($operator)
{
case 'is greater':
if($check1 > $check2)
{
$return = true;
}
break;
case 'is less':
if($check1 < $check2)
{
$return = true;
}
break;
case 'greater or equal':
if($check1 >= $check2)
{
$return = true;
}
break;
case 'less or equal':
if($check1 > $check2)
{
$return = true;
}
break;
case 'equal to':
if($check1 == $check2)
{
$return = true;
}
break;
case 'not equal':
if($check1 != $check2)
{
$return = true;
}
break;
}
return $return;
}
function custom($check, $regex = null)
{
if (is_array($check))
{
$this->_extract($check);
}
else
{
$this->check = $check;
$this->regex = $regex;
}
return $this->_check();
}
function date($check)
{
}
function decimal($check, $type, $regex= null)
{
//Validates a simple decimal format
//Validate a complex decimal format.
}
function email($check, $regex= null, $deep = false)
{
if (is_array($check))
{
$this->_extract($check);
}
else
{
$this->check = $check;
$this->regex = $regex;
$this->deep = $deep;
}
if(is_null($this->regex))
{
$this->regex = '/\\A(?:^([a-z0-9][a-z0-9_\\-\\.\\+]*)@([a-z0-9][a-z0-9\\.\\-]{0,63}\\.(com|org|net|biz|info|name|net|pro|aero|coop|museum|[a-z]{2,4}))$)\\z/i';
}
if($this->_check() && $this->deep)
{
if (preg_match('/@([a-z0-9][a-z0-9\\.\\-]{0,63}\\.([a-z]*))/', $check, $regs))
{
$host = gethostbynamel($regs[1]);
if (is_array($host))
{
$this->error[] = false;
return true;
}
else
{
$this->error[] = true;
return false;
}
}
}
}
function equalTo($check, $comparedTo)
{
}
function file($check)
{
}
function ip($check)
{
}
function minLength($check, $min)
{
$length = strlen($check);
}
function maxLength($check, $max)
{
$length = strlen($check);
}
function money($check, $symbolPosition = 'left')
{
$this->check = $check;
switch ($symbolPosition)
{
case 'left':
$this->regex = '/^(?!\\u00a2)\\p{Sc}?(?!0,?\\d)(?:\\d{1,3}(?:([, .])\\d{3})?(?:\\1\\d{3})*|(?:\\d+))((?!\\1)[,.]\\d{2})?$/';
break;
case 'right':
$this->regex = '/^(?!0,?\\d)(?:\\d{1,3}(?:([, .])\\d{3})?(?:\\1\\d{3})*|(?:\\d+))((?!\\1)[,.]\\d{2})?(?<!\\u00a2)\\p{Sc}?$/';
break;
}
return $this->_check();
}
function multiple($check, $type, $regex= null)
{
//Validate a select object for a selected index past 0.
//Validate a select against a list of restriced indexes.
//Validate a multiple-select for the quantity selected.
}
function number($check, $lower = null, $upper = null )
{
if (isset($lower) && isset($upper) && $lower > $upper)
{
//error
}
if(is_float($check))
{
}
}
function numeric($check)
{
return is_numeric($check);
}
function phone($check, $regex= null, $country = 'all')
{
if (is_array($check))
{
$this->_extract($check);
}
else
{
$this->check = $check;
$this->regex = $regex;
$this->country = $country;
}
if(is_null($this->regex))
{
switch ($this->country)
{
case 'us':
$this->regex = '/1?[-. ]?\\(?([0-9]{3})\\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})/';
break;
}
}
return $this->_check();
}
function postal($check, $regex= null, $country = null)
{
if (is_array($check))
{
$this->_extract($check);
}
else
{
$this->check = $check;
$this->regex = $regex;
$this->country = $country;
}
if(is_null($this->regex))
{
switch ($this->country)
{
case 'us':
$this->regex = '/\\A\\b[0-9]{5}(?:-[0-9]{4})?\\b\\z/i';
break;
case 'uk':
$this->regex = '/\\A\\b[A-Z]{1,2}[0-9][A-Z0-9]? [0-9][ABD-HJLNP-UW-Z]{2}\\b\\z/i';
break;
case 'ca':
$this->regex = '/\\A\\b[ABCEGHJKLMNPRSTVXY][0-9][A-Z] [0-9][A-Z][0-9]\\b\\z/i';
break;
}
}
return $this->_check();
}
function ssn($check, $regex= null, $country = null)
{
if (is_array($check))
{
$this->_extract($check);
}
else
{
$this->check = $check;
$this->regex = $regex;
$this->country = $country;
}
if(is_null($this->regex))
{
switch ($this->country)
{
case 'us':
$this->regex = '/\\A\\b[0-9]{3}-[0-9]{2}-[0-9]{4}\\b\\z/i';
break;
case 'dk':
$this->regex = '/\\A\\b[0-9]{6}-[0-9]{4}\\b\\z/i';
break;
case 'nl':
$this->regex = '/\\A\\b[0-9]{9}\\b\\z/i';
break;
}
}
return $this->_check();
}
function url($check)
{
$this->check = $check;
$this->regex = '/\\A(?:(https?|ftps?|file|news|gopher):\\/\\/[\\w\\-_]+(\\.[\\w\\-_]+)+([\\w\\-\\.,@?^=%&:\/~\\+#]*[\\w\\-\\@?^=%&\/~\\+#])?)\\z/i';
return $this->_check();
}
function userDefined($object, $method, $args)
{
return call_user_func_array(array(&$object, $method), $args);
}
function _check()
{
if (preg_match($this->regex, $this->check))
{
$this->error[] = false;
return true;
}
else
{
$this->error[] = true;
return false;
}
}
function _extract($params)
{
extract($params, EXTR_OVERWRITE);
if (isset($check))
{
$this->check = $check;
}
if (isset($regex))
{
$this->regex = $regex;
}
if (isset($country))
{
$this->country = strtolower($country);
}
if (isset($deep))
{
$this->deep = $deep;
}
if (isset($type))
{
$this->type = $type;
}
}
}
?>