[pLog-svn] r7204 - in plog/branches/lifetype-1.2/class: bayesian dao data data/filter data/validator/rules gallery/resizers logger misc net net/xmlrpc xml/parser
jondaley at devel.lifetype.net
jondaley at devel.lifetype.net
Thu Apr 25 06:53:55 EDT 2013
Author: jondaley
Date: 2013-04-25 06:53:55 -0400 (Thu, 25 Apr 2013)
New Revision: 7204
Modified:
plog/branches/lifetype-1.2/class/bayesian/bayesiantokenizer.class.php
plog/branches/lifetype-1.2/class/dao/bayesiantoken.class.php
plog/branches/lifetype-1.2/class/dao/usercomment.class.php
plog/branches/lifetype-1.2/class/data/filter/urlconverter.class.php
plog/branches/lifetype-1.2/class/data/inputfilter.class.php
plog/branches/lifetype-1.2/class/data/textfilter.class.php
plog/branches/lifetype-1.2/class/data/validator/rules/emaildnsrule.class.php
plog/branches/lifetype-1.2/class/data/validator/rules/ipcidrformatrule.class.php
plog/branches/lifetype-1.2/class/data/validator/rules/ipformatrule.class.php
plog/branches/lifetype-1.2/class/data/validator/rules/regexprule.class.php
plog/branches/lifetype-1.2/class/gallery/resizers/gallerygdresizer.class.php
plog/branches/lifetype-1.2/class/logger/LogUtil.php
plog/branches/lifetype-1.2/class/misc/osdetect.class.php
plog/branches/lifetype-1.2/class/net/dns.class.php
plog/branches/lifetype-1.2/class/net/xmlrpc/xmlrpcserver.class.php
plog/branches/lifetype-1.2/class/xml/parser/Parser.php
Log:
first pass at removing all deprecated ereg functions. A couple of these need to be checked/changed for PCRE differences from POSIX. I didn't touch the getid library, hopefully, that can be updated to the latest version and have this stuff fixed
Modified: plog/branches/lifetype-1.2/class/bayesian/bayesiantokenizer.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/bayesian/bayesiantokenizer.class.php 2013-04-25 10:15:42 UTC (rev 7203)
+++ plog/branches/lifetype-1.2/class/bayesian/bayesiantokenizer.class.php 2013-04-25 10:53:55 UTC (rev 7204)
@@ -3,7 +3,7 @@
lt_include( PLOG_CLASS_PATH."class/dao/bayesiantoken.class.php" );
lt_include( PLOG_CLASS_PATH."class/bayesian/tokenizer.class.php" );
- define( "SPLIT_REG_EXP", "[^a-zA-Z0-9àáèéíïòóúüÀÁÈÉÍÏÒÓÚÜ'$!,.^-]+");
+ define( "SPLIT_REG_EXP", "/[^a-zA-Z0-9àáèéíïòóúüÀÁÈÉÍÏÒÓÚÜ'$!,.^-]+/");
/**
* \ingroup Bayesian
@@ -55,14 +55,14 @@
*/
function _tokenize($text)
{
- $tokensTemp = split(SPLIT_REG_EXP, $text);
+ $tokensTemp = preg_split(SPLIT_REG_EXP, $text);
$tokens = array();
foreach ($tokensTemp as $token)
{
if (strlen($token) > 0 && BayesianToken::isValid($token))
{
- if (ereg("\\$[0-9]+[-][0-9]+", $token))
+ if (preg_match("/\\$[0-9]+[-][0-9]+/", $token))
{
$temp = split("[-]", $token);
@@ -76,7 +76,7 @@
array_push($tokens, "$" . $temp[1]);
}
}
- else if (!ereg("[0-9]+[,.^][0-9]+", $token))
+ else if (!preg_match("/[0-9]+[,.^][0-9]+/", $token))
{
$splitted = split("[,.^]", $token);
@@ -107,7 +107,8 @@
foreach ($tags as $tag)
{
- if (eregi("^<a ", $tag) || eregi("^<img ", $tag) || eregi("^<font ", $tag))
+ // TODO: should this use the user's set valid HTML tags, instead of this hard-coded list?
+ if (preg_match("/^<a /i", $tag) || preg_match("/^<img /i", $tag) || preg_match("/^<font /i", $tag))
{
array_push($validTags, $tag);
}
@@ -164,7 +165,7 @@
$value = $regs[2][$i];
$prefix = "";
- if (eregi("(href|src)", $regs[1][$i]))
+ if (preg_match("/(href|src)/i", $regs[1][$i]))
{
$prefix = TOKEN_URL_MARK;
}
@@ -189,7 +190,7 @@
*/
function _unquoteToken($token)
{
- if (ereg("^['\"](.+)['\"]$", $token, $regs))
+ if (preg_match("/^['\"](.+)['\"]$/", $token, $regs))
{
return $regs[1];
}
@@ -208,7 +209,7 @@
for ($i = 0; $i < $count; $i++)
{
- if (!eregi("^" . TOKEN_URL_MARK, $tokens[$i]))
+ if (!preg_match("/^" . TOKEN_URL_MARK."/i", $tokens[$i]))
{
$tokens[$i] = $mark . $tokens[$i];
}
Modified: plog/branches/lifetype-1.2/class/dao/bayesiantoken.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/dao/bayesiantoken.class.php 2013-04-25 10:15:42 UTC (rev 7203)
+++ plog/branches/lifetype-1.2/class/dao/bayesiantoken.class.php 2013-04-25 10:53:55 UTC (rev 7204)
@@ -120,7 +120,7 @@
$token = $this->getToken();
}
- $valid = !ereg("^[0-9-]+$", $token);
+ $valid = !preg_match("/^[0-9-]+$/", $token);
if ($config->getValue("bayesian_filter_min_length_token") > 0)
{
@@ -151,11 +151,11 @@
while ($prefix)
{
- if (ereg("^(" . TOKEN_TOPIC_MARK . "|" .
+ if (preg_match("/^(" . TOKEN_TOPIC_MARK . "|" .
TOKEN_URL_MARK . "|" .
TOKEN_USER_NAME_MARK . "|" .
TOKEN_USER_EMAIL_MARK . "|" .
- TOKEN_USER_URL_MARK . ")(.*)$", $curToken, $regs))
+ TOKEN_USER_URL_MARK . ")(.*)$/", $curToken, $regs))
{
$curToken = $regs[2];
$prefix = $regs[1];
@@ -167,12 +167,12 @@
$degenerations = array_merge($degenerations, BayesianToken::getBasicsDegeneration($curToken, $prefix));
- if (ereg("([^!]+!)!+$", $curToken, $regs))
+ if (preg_match("/([^!]+!)!+$/", $curToken, $regs))
{
$degenerations = array_merge($degenerations, BayesianToken::getBasicsDegeneration($regs[1], $prefix));
}
- if (ereg("([^!]+)!+$", $curToken, $regs))
+ if (preg_match("/([^!]+)!+$/", $curToken, $regs))
{
$degenerations = array_merge($degenerations, BayesianToken::getBasicsDegeneration($regs[1], $prefix));
}
Modified: plog/branches/lifetype-1.2/class/dao/usercomment.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/dao/usercomment.class.php 2013-04-25 10:15:42 UTC (rev 7203)
+++ plog/branches/lifetype-1.2/class/dao/usercomment.class.php 2013-04-25 10:53:55 UTC (rev 7204)
@@ -198,10 +198,10 @@
function setUserUrl( $userUrl )
{
// fix from yousung
- if ( $userUrl != null && eregi("http", $userUrl) == null )
- $userUrl = "http://".$userUrl;
+ if ( $userUrl != null && preg_match("/^http/i", $userUrl) == null )
+ $userUrl = "http://".$userUrl;
- $this->_userUrl = $userUrl;
+ $this->_userUrl = $userUrl;
}
/**
Modified: plog/branches/lifetype-1.2/class/data/filter/urlconverter.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/data/filter/urlconverter.class.php 2013-04-25 10:15:42 UTC (rev 7203)
+++ plog/branches/lifetype-1.2/class/data/filter/urlconverter.class.php 2013-04-25 10:53:55 UTC (rev 7204)
@@ -27,7 +27,7 @@
*/
function filter( $data )
{
- if((strlen($data) != 0) && ereg('^https?://', $data) == false){
+ if((strlen($data) != 0) && preg_match('#^https?://#', $data) == false){
$data = "http://" . $data;
}
return(parent::filter($data));
Modified: plog/branches/lifetype-1.2/class/data/inputfilter.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/data/inputfilter.class.php 2013-04-25 10:15:42 UTC (rev 7203)
+++ plog/branches/lifetype-1.2/class/data/inputfilter.class.php 2013-04-25 10:53:55 UTC (rev 7204)
@@ -210,7 +210,7 @@
list($attrSubSet[0]) = explode(' ', $attrSubSet[0]);
// removes all "non-regular" attr names AND also attr blacklisted
- if ((!eregi("^[a-z]*$",$attrSubSet[0])) || (($this->xssAuto) && ((in_array(strtolower($attrSubSet[0]), $this->attrBlacklist)) || (substr($attrSubSet[0], 0, 2) == 'on'))))
+ if ((!preg_match("/^[a-z]*$/i",$attrSubSet[0])) || (($this->xssAuto) && ((in_array(strtolower($attrSubSet[0]), $this->attrBlacklist)) || (substr($attrSubSet[0], 0, 2) == 'on'))))
continue;
// xss attr value filtering
if ($attrSubSet[1]) {
Modified: plog/branches/lifetype-1.2/class/data/textfilter.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/data/textfilter.class.php 2013-04-25 10:15:42 UTC (rev 7203)
+++ plog/branches/lifetype-1.2/class/data/textfilter.class.php 2013-04-25 10:53:55 UTC (rev 7204)
@@ -275,7 +275,7 @@
// put all the html entities back to what they should be
$result = TextFilter::htmlDecode( $result );
// and remove everything which is not letters or numbers
- $result = ereg_replace( "/[^A-Za-z0-9_]/", " ", $result );
+ $result = preg_replace( "/[^A-Za-z0-9_]/", " ", $result );
// finally, remove the unnecessary spaces
$result = preg_replace( "/ +/", " ", $result );
Modified: plog/branches/lifetype-1.2/class/data/validator/rules/emaildnsrule.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/data/validator/rules/emaildnsrule.class.php 2013-04-25 10:15:42 UTC (rev 7203)
+++ plog/branches/lifetype-1.2/class/data/validator/rules/emaildnsrule.class.php 2013-04-25 10:53:55 UTC (rev 7204)
@@ -69,8 +69,8 @@
if ($connect = fsockopen($connectAddress, 25))
{
$greeting = fgets($connect, 1024);
-
- if (ereg("^220", $greeting))
+ // TODO: these non-regexp preg_matches should all be changed to strpos === 0
+ if (preg_match("/^220/", $greeting))
{
$server = &HttpVars::getServer();
fputs($connect, "HELO " . $server["HTTP_HOST"] . "\r\n");
@@ -90,9 +90,9 @@
fputs($connect, "QUIT\r\n");
fclose($connect);
- if (!ereg("^250", $from) || !ereg ("^250", $to))
+ if (!preg_match("/^250/", $from) || !preg_match ("/^250/", $to))
{
- if(ereg("^4[0-9][0-9]", $helo) || ereg("^4[0-9][0-9]", $from) || ereg ("^4[0-9][0-9]", $to)){
+ if(preg_match("/^4[0-9][0-9]/", $helo) || preg_match("/^4[0-9][0-9]/", $from) || preg_match ("/^4[0-9][0-9]/", $to)){
$this->_setError(ERROR_RULE_EMAIL_DNS_SERVER_TEMP_FAIL);
// Note: see http://bugs.lifetype.net/view.php?id=718 to fix this
return true;
@@ -103,7 +103,7 @@
}
}
}
- else if(ereg("^4[0-9][0-9]", $greeting)){
+ else if(preg_match("/^4[0-9][0-9]/", $greeting)){
$this->_setError(ERROR_RULE_EMAIL_DNS_SERVER_TEMP_FAIL);
return false;
}
Modified: plog/branches/lifetype-1.2/class/data/validator/rules/ipcidrformatrule.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/data/validator/rules/ipcidrformatrule.class.php 2013-04-25 10:15:42 UTC (rev 7203)
+++ plog/branches/lifetype-1.2/class/data/validator/rules/ipcidrformatrule.class.php 2013-04-25 10:53:55 UTC (rev 7204)
@@ -2,7 +2,7 @@
lt_include(PLOG_CLASS_PATH."class/data/validator/rules/regexprule.class.php");
- define( "IP_CIDR_FORMAT_RULE_REG_EXP", "^([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})/([0-9]{1,2})$");
+ define( "IP_CIDR_FORMAT_RULE_REG_EXP", "#^([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})/([0-9]{1,2})$#");
define( "ERROR_RULE_IP_CIDR_FORMAT_WRONG", "error_rule_ip_cidr_format_wrong");
/**
@@ -32,7 +32,7 @@
*/
function validate($value)
{
- if (!ereg($this->_regExp, $value, $regs))
+ if (!preg_match($this->_regExp, $value, $regs))
{
$this->_setError(ERROR_RULE_IP_CIDR_FORMAT_WRONG);
return false;
Modified: plog/branches/lifetype-1.2/class/data/validator/rules/ipformatrule.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/data/validator/rules/ipformatrule.class.php 2013-04-25 10:15:42 UTC (rev 7203)
+++ plog/branches/lifetype-1.2/class/data/validator/rules/ipformatrule.class.php 2013-04-25 10:53:55 UTC (rev 7204)
@@ -2,7 +2,7 @@
lt_include(PLOG_CLASS_PATH."class/data/validator/rules/regexprule.class.php");
- define( "IP_FORMAT_RULE_REG_EXP", "^([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})$");
+ define( "IP_FORMAT_RULE_REG_EXP", "#^([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})$#");
define( "ERROR_RULE_IP_FORMAT_WRONG", "error_rule_ip_format_wrong");
/**
@@ -32,7 +32,7 @@
*/
function validate($value)
{
- if (!ereg($this->_regExp, $value, $regs))
+ if (!preg_match($this->_regExp, $value, $regs))
{
$this->_setError(ERROR_RULE_IP_FORMAT_WRONG);
return false;
Modified: plog/branches/lifetype-1.2/class/data/validator/rules/regexprule.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/data/validator/rules/regexprule.class.php 2013-04-25 10:15:42 UTC (rev 7203)
+++ plog/branches/lifetype-1.2/class/data/validator/rules/regexprule.class.php 2013-04-25 10:53:55 UTC (rev 7204)
@@ -74,16 +74,13 @@
*/
function validate($value)
{
- if ($this->_caseSensitive && ereg($this->_regExp, $value))
+ // TODO: it would probably be better to make the regExp contain the / delimiter on its
+ // own, otherwise, someone wouldn't know to escape a / in the middle of their rule!
+ if (preg_match("/".$this->_regExp."/" . ($this->_caseSensitive ? '' : 'i'), $value))
{
$this->_setError(false);
return true;
}
- else if (!$this->_caseSensitive && eregi($this->_regExp, $value))
- {
- $this->_setError(false);
- return true;
- }
else
{
$this->_setError(ERROR_RULE_REGEXP_NOT_MATCH);
Modified: plog/branches/lifetype-1.2/class/gallery/resizers/gallerygdresizer.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/gallery/resizers/gallerygdresizer.class.php 2013-04-25 10:15:42 UTC (rev 7203)
+++ plog/branches/lifetype-1.2/class/gallery/resizers/gallerygdresizer.class.php 2013-04-25 10:53:55 UTC (rev 7204)
@@ -68,7 +68,7 @@
function thumbnail($imgfile)
{
//detect image format
- $this->img["format"]=ereg_replace(".*\.(.*)$","\\1",$imgfile);
+ $this->img["format"]=preg_replace("/.*\.(.*)$/","\\1",$imgfile);
$this->img["format"]=strtoupper($this->img["format"]);
if ($this->img["format"]=="JPG" || $this->img["format"]=="JPEG") {
$this->img["format"]="JPEG";
Modified: plog/branches/lifetype-1.2/class/logger/LogUtil.php
===================================================================
--- plog/branches/lifetype-1.2/class/logger/LogUtil.php 2013-04-25 10:15:42 UTC (rev 7203)
+++ plog/branches/lifetype-1.2/class/logger/LogUtil.php 2013-04-25 10:53:55 UTC (rev 7204)
@@ -83,7 +83,7 @@
$variable = str_replace("\x00", ' ', $variable);
$varlen = strlen($variable);
for ($i = 0; $i < $varlen; $i++) {
- if (ereg('['.chr(0x0A).chr(0x0D).' -;0-9A-Za-z]', $variable{$i})) {
+ if (preg_match('/['.chr(0x0A).chr(0x0D).' \-;0-9A-Za-z]/', $variable{$i})) {
$returnstring .= $variable{$i};
} else {
$returnstring .= '&#'.str_pad(ord($variable{$i}), 3, '0', STR_PAD_LEFT).';';
Modified: plog/branches/lifetype-1.2/class/misc/osdetect.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/misc/osdetect.class.php 2013-04-25 10:15:42 UTC (rev 7203)
+++ plog/branches/lifetype-1.2/class/misc/osdetect.class.php 2013-04-25 10:53:55 UTC (rev 7204)
@@ -33,7 +33,7 @@
{
$os = OsDetect::getOsString();
- if(eregi("win", $os))
+ if(preg_match("/win/i", $os))
return true;
else
return false;
@@ -49,7 +49,7 @@
{
$os = OsDetect::getOsString();
- if(eregi("linux", $os))
+ if(preg_match("/linux/i", $os))
return true;
else
return false;
Modified: plog/branches/lifetype-1.2/class/net/dns.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/net/dns.class.php 2013-04-25 10:15:42 UTC (rev 7203)
+++ plog/branches/lifetype-1.2/class/net/dns.class.php 2013-04-25 10:53:55 UTC (rev 7204)
@@ -108,11 +108,10 @@
if( !is_array( $mxhosts )) $mxhosts = array();
if( !empty( $hostname ) ) {
- @exec( "nslookup -type=MX $hostname", $output, $ret );
-
+ @exec( "nslookup -type=MX ".escapeshellarg($hostname), $output );
while( list( $k, $line ) = each( $output ) ) {
// Valid records begin with hostname:
- if( ereg( "^$hostname\tMX preference = ([0-9]+), mail exchanger = (.*)$", $line, $parts )) {
+ if( preg_match( "/^".str_replace("/", "\\/", $hostname)."\s+MX preference = ([0-9]+), mail exchanger = (.*)$/i", $line, $parts )) {
$mxhosts[ $parts[1] ] = $parts[2];
}
}
Modified: plog/branches/lifetype-1.2/class/net/xmlrpc/xmlrpcserver.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/net/xmlrpc/xmlrpcserver.class.php 2013-04-25 10:15:42 UTC (rev 7203)
+++ plog/branches/lifetype-1.2/class/net/xmlrpc/xmlrpcserver.class.php 2013-04-25 10:53:55 UTC (rev 7204)
@@ -1024,7 +1024,7 @@
// Remove all characters that would need to be urlencoded
// This may not be necessary, but this was causing problems when given file
// names with spaces in it.
- $tempFile = ereg_replace("[^a-zA-Z0-9._-]", "_", basename($file['name']));
+ $tempFile = preg_replace("/[^a-zA-Z0-9._-]/", "_", basename($file['name']));
// Make the tmp name
$tempFile = $tmp_dir . '/' . $tempFile;
Modified: plog/branches/lifetype-1.2/class/xml/parser/Parser.php
===================================================================
--- plog/branches/lifetype-1.2/class/xml/parser/Parser.php 2013-04-25 10:15:42 UTC (rev 7203)
+++ plog/branches/lifetype-1.2/class/xml/parser/Parser.php 2013-04-25 10:53:55 UTC (rev 7204)
@@ -375,7 +375,7 @@
/**
* check, if file is a remote file
*/
- if (eregi('^(http|ftp)://', substr($file, 0, 10))) {
+ if (preg_match('#^(http|ftp)://#i', substr($file, 0, 10))) {
if (!ini_get('safe_mode')) {
ini_set('allow_url_fopen', 1);
} else {
@@ -430,7 +430,7 @@
return true;
}
// see if it's an absolute URL (has a scheme at the beginning)
- elseif (eregi('^[a-z]+://', substr($fp, 0, 10))) {
+ elseif (preg_match('#^[a-z]+://#i', substr($fp, 0, 10))) {
return $this->setInputFile($fp);
}
// see if it's a local file
More information about the pLog-svn
mailing list