Source for file format.class.php
Documentation is available at format.class.php
*@=@=@=@ START LICENSE @=@=@=@*
Copyright or © or Copr. Stéphane TRICHET and Nicolas SOTRON
stephane.t@simpliciweb.net and nicolas.s@simpliciweb.net
This software is a computer program whose purpose is to make a
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
*@=@=@=@ END LICENSE @=@=@=@*
* @version $Id: format.class.php 910 2008-03-19 08:54:35Z nicolas_s $
* This class provid format validation
* @version $Id: format.class.php 910 2008-03-19 08:54:35Z nicolas_s $
* Constructor, init the requests and objects
* Test if it is not a valid value in 'YES','NO'
* @return bool TRUE = is NOT a good value
return $this->isNotEnum($p_value, array('YES', 'NO'));
* Test if it is not a date before today
* @return bool TRUE = is NOT a date before today
//echo("isNotDateAfterToday : ".$p_value."<br />");
$date_exploded =
explode("-", $p_value);
//print_r($date_exploded);
$year =
$date_exploded[0];
$month =
$date_exploded[1];
$day =
$date_exploded[2];
//echo($year." ".$month." ".$day);
$ts =
@mktime (0,0,0,$month,$day,$year);
//echo("mktime (0,0,0,$month,$day,$year)");
//echo("isNotDateAfterToday : ".($month*2)."<br />");
//echo("isNotDateAfterToday : ".$ts."<br />");
//echo("isNotDateAfterToday : ".$ts_now."<br />");
//echo("isNotDateAfterToday : return true <br />");
* Test if it is not a date
* @return bool TRUE = is NOT a date
if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $p_value)) {
* Test if it is not a domain
* @return bool TRUE = is NOT a domain
$p_value =
trim($p_value);
if (strtolower($p_value) ==
'localhost' ||
$p_value ==
'127.0.0.1') {
if (!eregi("^[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $p_value)) { // {2,3} => {2,4} pour les .info
* Test if it is not an email
* @return bool TRUE = is NOT an email
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $p_value)) {
* Return an empty $_FILES array
$r_result['tmp_name'] =
"";
$r_result['error'] =
"-999";
* Test if it is not a valid $_FILES array
* @return bool TRUE = is NOT a valid $_FILES array
//echo("isFileArray".$p_value);
if (!isset
($p_value['name'])) {
if (!isset
($p_value['type'])) {
if (!isset
($p_value['size'])) {
if (!isset
($p_value['tmp_name'])) {
if (!isset
($p_value['error'])) {
* Test if it is not varchar
* @param integer $p_length
* @param bool $is_good_if_len_zero
* @return bool TRUE = is NOT a varchar
function isNotVarchar($p_value, $p_length, $is_good_if_len_zero =
true) {
if ($is_good_if_len_zero)
return (strlen($p_value) ==
0);
* Test if it is not an unsigned integer
* @param integer $p_length
* @return bool TRUE = is NOT a medium text
/*// tesster si c pas null en premier
* on teste pas si c null, car pour PHP un int = NULL et egal a int = 0 :(
//echo("isUnsignedInteger".$p_value);
// si c'est un chiffre on teste ca valeur maximale
for ($i=
0;$i<
$p_length;$i++
) {
$max_value =
$max_value*
10 +
9;
//echo("integerXXX$p_value<=**$max_value**");
if ($p_value <=
$max_value) {
// on verifie qu'elle ne contient que des nombres
//echo("===$forTest===");
if ((strlen($p_value) <=
$p_length) &&
(strlen($for_test) ==
0)) {
* Test if it is not unsigned float
* @return bool TRUE = is NOT an unsigned float
/*// tesster si c pas null en premier
* on teste pas si c null, car pour PHP un int = NULL et egal a int = 0 :(
//echo("isUnsignedFloat<br />".$p_value);
// si c'est un chiffre on teste ca valeur maximale
//echo("is float $p_value");
for ($i=
0;$i<
$length;$i++
) {
$max_value =
$max_value*
10 +
9;
//echo("vraifloat<br />".$p_value);
return ($p_value >
$max_value);
// on verifie qu'elle ne contient que des nombres
//echo("is string but float $p_value<br />");
//echo("string float<br />".$p_value);
//echo("string test<br />".$forTest);
if ((strlen($p_value) <=
$length) &&
(strlen($for_test) ==
0)) {
* Test if it is not a medium text
* @return bool TRUE = is NOT a medium text
// tester si c pas null en premier
//echo("isMediumText".$p_value);
* Test if it is not a text
* @return bool TRUE = is NOT a text
// tester si c pas null en premier
//echo("isText".$p_value);
* Test if it is not a medium text
* @return bool TRUE = is NOT a medium text
* Test if it is not a valid enum value
* @param array $p_array_values
* @param bool $i_make_to_upper
* @return bool TRUE = is NOT a valid enum value
function isNotEnum(&$p_value, $p_array_values, $i_make_to_upper =
false) {
foreach($p_array_values as $key =>
$value) {
if ($value ==
$p_value) {
// for ($i=0;$i<sizeof($p_array_values);$i++) {
// if ($p_array_values[$i] == $p_value) {
* Test if it is not valid email
* @return bool TRUE = is NOT valid email
$HTTP_HOST =
$_SERVER['HTTP_HOST'];
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $Email)) { // test si le format de l'email est bon
* Ne sera jamais traité car si on fait un telnet sur
* wanadoo.com (et pas fr) ca fait un timeout et c pas
list
($Username, $Domain) =
split("@", $Email); // split le nom et le domaine
//echo "<br /><HR><br />";
$res =
& $g_object_loader->getNet_DNS_Resolver();
$answer =
$res->search($Domain, "MX");
//echo "<br /><HR><br /><PRE>";
if ($answer) { //verifie existance serveur de mail sur ce domaine
$ConnectAddress =
$answer->additional[0]->address;
} else { // Si pas d'enregistrement MX, on met simplement le domaine comme adresse de connexion
$ConnectAddress =
$Domain;
//if (!(($_SERVER["SERVER_NAME"]=="200.1.1.93") ||
//($_SERVER["SERVER_NAME"]=="200.1.1.108")))
if ($Connect) { // Si socket ouvert
//echo("connected<br />");
$Out =
fgets($Connect, 1024);
if (ereg("^220", $Out )) {
fputs($Connect, "HELO $HTTP_HOST\r\n");
$Out =
fgets($Connect, 1024);
fputs($Connect, "MAIL FROM: <{$Email}>\r\n");
$From =
fgets($Connect, 1024);
fputs($Connect, "RCPT TO: <{$Email}>\r\n");
$To =
fgets($Connect, 1024);
//echo("$Connect<br />");
fputs($Connect, "QUIT\r\n");
if (!ereg ("^250", $From) ||
!ereg ("^250", $To)) { // Si adresse n'existe pas
else { // Si le telnet échoue, ce n'est pas une preuve
* Test if it is not valid postal code
* @return bool TRUE = is NOT a valid postal code
if (ereg ("^(\d{2}(( \d{3})|\d( )?\d{1,2}(-\d{4})?))|([a-zA-Z]([a-zA-Z])?\d(([a-zA-Z])|\d)? \d([a-zA-Z]){2})", $p_value)) return true;
* Test if it is not a phone number
* @param bool $p_allow_empty Allow empty value
* @return bool TRUE = is NOT a phone number
$p_value =
trim($p_value);
if (ereg ("^[0-9 +.)(-]*$", $p_value)) return false;
Documentation generated on Tue, 25 Mar 2008 15:35:02 +0100 by phpDocumentor 1.3.2