1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-04 05:37:32 +02:00

ctype_*() replacement

This commit is contained in:
marj
2009-08-08 23:09:08 +00:00
parent c2de40c75b
commit 77e4edfb54
5 changed files with 173 additions and 119 deletions

View File

@@ -9,9 +9,9 @@
* General purpose file * General purpose file
* *
* $Source: /cvs_backup/e107_0.8/class2.php,v $ * $Source: /cvs_backup/e107_0.8/class2.php,v $
* $Revision: 1.121 $ * $Revision: 1.122 $
* $Date: 2009-08-06 22:39:36 $ * $Date: 2009-08-08 23:09:08 $
* $Author: secretr $ * $Author: marj_nl_fr $
* *
*/ */
// //
@@ -1316,20 +1316,21 @@ function check_class($var, $userclass = USERCLASS_LIST, $uid = 0)
if ($userclass == '') if ($userclass == '')
{ {
return false; return FALSE;
} }
$class_array = explode(',', $userclass); $class_array = explode(',', $userclass);
$varList = explode(',', trim($var)); $varList = explode(',', $var);
$latchedAccess = FALSE; $latchedAccess = FALSE;
foreach($varList as $v) foreach($varList as $v)
{
$invert = FALSE;
if(!is_numeric($v)) //value to test is a userclass name (or garbage, of course), go get the id
{ {
$v = trim($v); $v = trim($v);
$invert = FALSE;
//value to test is a userclass name (or garbage, of course), go get the id
if( ! is_numeric($v))
{
if (substr($v, 0, 1) == '-') if (substr($v, 0, 1) == '-')
{ {
$invert = TRUE; $invert = TRUE;
@@ -1343,8 +1344,9 @@ function check_class($var, $userclass = USERCLASS_LIST, $uid = 0)
$v = -$v; $v = -$v;
} }
if ($v !== FALSE) if ($v !== FALSE)
{ // Ignore non-valid userclass names {
if ((in_array($v, $class_array) || (ctype_digit($v) && ($v == 0)))) // Ignore non-valid userclass names
if (in_array($v, $class_array) || ($v === '0') || ($v === 0))
{ {
if ($invert) if ($invert)
{ {
@@ -1354,7 +1356,8 @@ function check_class($var, $userclass = USERCLASS_LIST, $uid = 0)
} }
elseif ($invert && count($varList) == 1) elseif ($invert && count($varList) == 1)
{ {
$latchedAccess = TRUE; // Handle scenario where only an 'exclude' class is passed // Handle scenario where only an 'exclude' class is passed
$latchedAccess = TRUE;
} }
} }
} }

View File

@@ -11,9 +11,9 @@
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| $Source: /cvs_backup/e107_0.8/e107_handlers/plugin_class.php,v $ | $Source: /cvs_backup/e107_0.8/e107_handlers/plugin_class.php,v $
| $Revision: 1.72 $ | $Revision: 1.73 $
| $Date: 2009-08-06 22:29:34 $ | $Date: 2009-08-08 23:09:08 $
| $Author: e107coders $ | $Author: marj_nl_fr $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
@@ -446,7 +446,7 @@ class e107plugin
{ {
global $sql, $tp; global $sql, $tp;
if(!ctype_digit($link_class)) if( ! is_numeric($link_class))
{ {
$link_class = strtolower($link_class); $link_class = strtolower($link_class);
$plug_perm['everyone'] = e_UC_PUBLIC; $plug_perm['everyone'] = e_UC_PUBLIC;

View File

@@ -9,9 +9,9 @@
* Handler - user-related functions * Handler - user-related functions
* *
* $Source: /cvs_backup/e107_0.8/e107_handlers/user_handler.php,v $ * $Source: /cvs_backup/e107_0.8/e107_handlers/user_handler.php,v $
* $Revision: 1.10 $ * $Revision: 1.11 $
* $Date: 2009-06-12 20:41:34 $ * $Date: 2009-08-08 23:09:08 $
* $Author: e107steved $ * $Author: marj_nl_fr $
* *
*/ */
@@ -279,45 +279,78 @@ class UserHandler
// alphanumerics are included 'as is' // alphanumerics are included 'as is'
function generateRandomString($pattern, $seed = '') function generateRandomString($pattern, $seed = '')
{ {
if (strlen($pattern) < 6) $pattern = '##....'; if (strlen($pattern) < 6)
$pattern = '##....';
$newname = ''; $newname = '';
$seed_ptr = 0; // Next character of seed (if used)
for ($i = 0; $i < strlen($pattern); $i++) // Create alpha [A-Z][a-z]
$alpha = '';
for($i = 65; $i < 91; $i++)
{
$alpha .= chr($i).chr($i+32);
}
$alphaLength = strlen($alpha) - 1;
// Create digit [0-9]
$digit = '';
for($i = 48; $i < 57; $i++)
{
$digit .= chr($i);
}
$digitLength = strlen($digit) - 1;
// Create alpha numeric [A-Z][a-z]
$alphaNum = $alpha.$digit;
$alphaNumLength = strlen($alphaNum) - 1;
// Next character of seed (if used)
$seed_ptr = 0;
for ($i = 0, $patternLength = strlen($pattern); $i < $patternLength; $i++)
{ {
$c = $pattern[$i]; $c = $pattern[$i];
switch ($c) switch ($c)
{ {
case '#' : // Alpha only (upper and lower case) // Alpha only (upper and lower case)
do case '#' :
{ $t = rand(0, $alphaLength);
$t = chr(rand(65,122)); $newname .= $alpha[$t];
} while (!ctype_alpha($t));
$newname .= $t;
break; break;
case '.' : // Numeric only
do // Numeric only - [0-9]
{ case '.' :
$t = chr(rand(48,57)); $t = rand(0, $digitLength);
} while (!ctype_digit($t)); $newname .= $digit[$t];
$newname .= $t;
break; break;
case '*' : // Alphanumeric
do // Alphanumeric
{ case '*' :
$t = chr(rand(48,122)); $t = rand(0, $alphaNumLength);
} while (!ctype_alnum($t)); $newname .= $alphaNum[$t];
$newname .= $t;
break; break;
case '^' : // Next character from seed
// Next character from seed
case '^' :
if ($seed_ptr < strlen($seed)) if ($seed_ptr < strlen($seed))
{ {
$newname .= $seed[$seed_ptr]; $newname .= $seed[$seed_ptr];
$seed_ptr++; $seed_ptr++;
} }
break; break;
default :
if (ctype_alnum($c)) $newname .= $c;
// (else just ignore other characters in pattern) // (else just ignore other characters in pattern)
default :
if (strrpos($alphaNum, $c) !== FALSE)
{
$newname .= $c;
}
/*
else
{
$t = rand(0, $alphaNumLength);
$newname .= $alphaNum[$t];
}
*/
} }
} }
return $newname; return $newname;

View File

@@ -9,9 +9,9 @@
* Handler - general purpose validation functions * Handler - general purpose validation functions
* *
* $Source: /cvs_backup/e107_0.8/e107_handlers/validator_class.php,v $ * $Source: /cvs_backup/e107_0.8/e107_handlers/validator_class.php,v $
* $Revision: 1.8 $ * $Revision: 1.9 $
* $Date: 2009-07-31 16:14:51 $ * $Date: 2009-08-08 23:09:08 $
* $Author: secretr $ * $Author: marj_nl_fr $
* *
*/ */
@@ -175,13 +175,17 @@ class validatorClass
{ {
switch ($defs['dataType']) switch ($defs['dataType'])
{ {
case 1 : // Assumes we're passed an array variable to be turned into a comma-separated list of integers case 1 : // Assumes we've passed an array variable to be turned into a comma-separated list of integers
if (is_array($value)) if (is_array($value))
{ {
$temp = array(); $temp = array();
foreach ($value as $v) foreach ($value as $v)
{ {
if (ctype_digit(trim($v))) { $temp[] = intval($v); } $v = trim($v);
if (is_numeric($v))
{
$temp[] = intval($v);
}
} }
$value = implode(',', array_unique($temp)); $value = implode(',', array_unique($temp));
} }

View File

@@ -11,9 +11,9 @@
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| $Source: /cvs_backup/e107_0.8/e107_plugins/calendar_menu/ec_pf_page.php,v $ | $Source: /cvs_backup/e107_0.8/e107_plugins/calendar_menu/ec_pf_page.php,v $
| $Revision: 1.2 $ | $Revision: 1.3 $
| $Date: 2007-12-26 18:30:13 $ | $Date: 2009-08-08 23:09:08 $
| $Author: e107steved $ | $Author: marj_nl_fr $
| |
| Generate a printer-friendly page of calendar events | Generate a printer-friendly page of calendar events
| Query is: ec_pf_page.php?ssssss.eeeeee[[[.cat].template].output] | Query is: ec_pf_page.php?ssssss.eeeeee[[[.cat].template].output]
@@ -333,15 +333,20 @@ switch ($ec_output_type)
} }
// We're assuming $date_string is a string of digits
// Which could begin with 'now' or 'now+'
function decode_date($date_string, $last_day = FALSE) function decode_date($date_string, $last_day = FALSE)
{ // Decode a date string { // Decode a date string
if (strpos($date_string, 'now') === 0) if (strpos($date_string, 'now') === 0)
{ // decode special dates {
// decode special dates
$today = getdate(); $today = getdate();
$date_string = trim(substr($date_string,3)); // Knock off the 'now' // Knock off the 'now'
$date_string = trim(substr($date_string, 3));
if (($date_string != '') && ($date_string[0] == '+')) if (($date_string != '') && ($date_string[0] == '+'))
{ {
$date_string = trim(substr($date_string,1)); // Knock off the '+' // Knock off the '+'
$date_string = trim(substr($date_string, 1));
if (is_numeric($date_string) && ($date_string >= 0) && ($date_string <= 12)) if (is_numeric($date_string) && ($date_string >= 0) && ($date_string <= 12))
{ {
$today['mon'] += $date_string; $today['mon'] += $date_string;
@@ -358,28 +363,37 @@ function decode_date($date_string,$last_day = FALSE)
} }
$date_string = $today['year'].$today['mon']; $date_string = $today['year'].$today['mon'];
} }
if (ctype_digit($date_string))
// Here, $date_string is a string of 5, 6 or 8 digits
// use preg_match()
if(preg_match('/^\d{5,8}$/D', $date_string))
{ {
$month = 0; $month = 0;
$day = 1; $day = 1;
if (strlen($date_string) == 5) $date_string = substr_replace($date_string,'0',-1,0); if (strlen($date_string) == 5)
$date_string = substr_replace($date_string, '0', -1, 0);
if (strlen($date_string) == 8) if (strlen($date_string) == 8)
{ {
$day = substr($date_string, -2, 2); $day = substr($date_string, -2, 2);
if ($last_day) $day += 1; if ($last_day)
$day += 1;
} }
elseif (strlen($date_string) == 6) elseif (strlen($date_string) == 6)
{ {
if ($last_day) $month = 1; if ($last_day)
$month = 1;
} }
else else
{ // Error {
// Error
return EC_LAN_149; return EC_LAN_149;
} }
$month += substr($date_string, 4, 2); $month += substr($date_string, 4, 2);
$year = substr($date_string, 0, 4); $year = substr($date_string, 0, 4);
$temp = mktime(0, 0, 0, $month, $day, $year); $temp = mktime(0, 0, 0, $month, $day, $year);
if ($last_day) $temp -= 1; // Always do this to get whole of last day // Always do this to get whole of last day
if ($last_day)
$temp -= 1;
return $temp; return $temp;
} }
else else