Replace ereg with preg_*

This commit is contained in:
AngryPHPNerd 2012-02-27 22:14:02 +01:00
parent edf6cd6d83
commit 0e2cbb0b88
21 changed files with 76 additions and 72 deletions

View File

@ -143,7 +143,7 @@ class ContentNegotiator {
$content = str_replace(' ',' ', $content); $content = str_replace(' ',' ', $content);
$content = str_replace('<br>','<br />', $content); $content = str_replace('<br>','<br />', $content);
$content = eregi_replace('(<img[^>]*[^/>])>','\\1/>', $content); $content = preg_replace('#(<img[^>]*[^/>])>#i', '\\1/>', $content);
$response->setBody($content); $response->setBody($content);
@ -170,14 +170,14 @@ class ContentNegotiator {
$content = preg_replace('/<base href="([^"]*)" \/>/', $content = preg_replace('/<base href="([^"]*)" \/>/',
'<base href="$1"><!--[if lte IE 6]></base><![endif]-->', $content); '<base href="$1"><!--[if lte IE 6]></base><![endif]-->', $content);
$content = ereg_replace("<\\?xml[^>]+\\?>\n?",'',$content); $content = preg_replace("#<\\?xml[^>]+\\?>\n?#", '', $content);
$content = str_replace(array('/>','xml:lang','application/xhtml+xml'),array('>','lang','text/html'), $content); $content = str_replace(array('/>','xml:lang','application/xhtml+xml'),array('>','lang','text/html'), $content);
// Only replace the doctype in templates with the xml header // Only replace the doctype in templates with the xml header
if($hasXMLHeader) { if($hasXMLHeader) {
$content = ereg_replace('<!DOCTYPE[^>]+>', '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">', $content); $content = preg_replace('/<!DOCTYPE[^>]+>/', '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">', $content);
} }
$content = ereg_replace('<html xmlns="[^"]+"','<html ', $content); $content = preg_replace('/<html xmlns="[^"]+"/','<html ', $content);
$response->setBody($content); $response->setBody($content);
} }

View File

@ -465,7 +465,7 @@ class Director {
*/ */
static function makeRelative($url) { static function makeRelative($url) {
// Allow for the accidental inclusion of a // in the URL // Allow for the accidental inclusion of a // in the URL
$url = ereg_replace('([^:])//','\\1/',$url); $url = preg_replace('#([^:])//#', '\\1/', $url);
$url = trim($url); $url = trim($url);
// Only bother comparing the URL to the absolute version if $url looks like a URL. // Only bother comparing the URL to the absolute version if $url looks like a URL.

View File

@ -38,7 +38,7 @@ class HTTP {
*/ */
static function absoluteURLs($html) { static function absoluteURLs($html) {
$html = str_replace('$CurrentPageURL', $_SERVER['REQUEST_URI'], $html); $html = str_replace('$CurrentPageURL', $_SERVER['REQUEST_URI'], $html);
return HTTP::urlRewriter($html, '(substr($URL,0,1) == "/") ? ( Director::protocolAndHost() . $URL ) : ( (ereg("^[A-Za-z]+:", $URL)) ? $URL : Director::absoluteBaseURL() . $URL )' ); return HTTP::urlRewriter($html, '(substr($URL,0,1) == "/") ? ( Director::protocolAndHost() . $URL ) : ( (preg_match("/^[A-Za-z]+:/", $URL)) ? $URL : Director::absoluteBaseURL() . $URL )' );
} }
/* /*

View File

@ -291,27 +291,26 @@ class Convert {
// Replace images with their alt tags // Replace images with their alt tags
if($config['ReplaceImagesWithAlt']) { if($config['ReplaceImagesWithAlt']) {
$data = eregi_replace('<img[^>]*alt *= *"([^"]*)"[^>]*>', ' \\1 ', $data); $data = preg_replace('/<img[^>]*alt *= *"([^"]*)"[^>]*>/i', ' \\1 ', $data);
$data = eregi_replace('<img[^>]*alt *= *([^ ]*)[^>]*>', ' \\1 ', $data); $data = preg_replace('/<img[^>]*alt *= *([^ ]*)[^>]*>/i', ' \\1 ', $data);
} }
// Compress whitespace // Compress whitespace
if($config['CompressWhitespace']) { if($config['CompressWhitespace']) {
$data = ereg_replace("[\n\r\t ]+", " ", $data); $data = preg_replace("/\s+/", " ", $data);
} }
// Parse newline tags // Parse newline tags
$data = ereg_replace("[ \n\r\t]*<[Hh][1-6]([^A-Za-z0-9>][^>]*)?> *", "\n\n", $data); $data = preg_replace("/\s*<[Hh][1-6]([^A-Za-z0-9>][^>]*)?> */", "\n\n", $data);
$data = ereg_replace("[ \n\r\t]*<[Pp]([^A-Za-z0-9>][^>]*)?> *", "\n\n", $data); $data = preg_replace("/\s*<[Pp]([^A-Za-z0-9>][^>]*)?> */", "\n\n", $data);
$data = ereg_replace("[ \n\r\t]*<[Dd][Ii][Vv]([^A-Za-z0-9>][^>]*)?> *", "\n\n", $data); $data = preg_replace("/\s*<[Dd][Ii][Vv]([^A-Za-z0-9>][^>]*)?> */", "\n\n", $data);
$data = ereg_replace("\n\n\n+","\n\n", $data); $data = preg_replace("/\n\n\n+/", "\n\n", $data);
$data = ereg_replace("<[Bb][Rr]([^A-Za-z0-9>][^>]*)?> *", "\n", $data); $data = preg_replace("/<[Bb][Rr]([^A-Za-z0-9>][^>]*)?> */", "\n", $data);
$data = ereg_replace("<[Tt][Rr]([^A-Za-z0-9>][^>]*)?> *", "\n", $data); $data = preg_replace("/<[Tt][Rr]([^A-Za-z0-9>][^>]*)?> */", "\n", $data);
$data = ereg_replace("</[Tt][Dd]([^A-Za-z0-9>][^>]*)?> *", " ", $data); $data = preg_replace("/</[Tt][Dd]([^A-Za-z0-9>][^>]*)?> */", " ", $data);
$data = preg_replace('/<\/p>/i', "\n\n", $data ); $data = preg_replace('/<\/p>/i', "\n\n", $data );
// Replace HTML entities // Replace HTML entities
//$data = preg_replace("/&#([0-9]+);/e", 'chr(\1)', $data); //$data = preg_replace("/&#([0-9]+);/e", 'chr(\1)', $data);
//$data = str_replace(array("&lt;","&gt;","&amp;","&nbsp;"), array("<", ">", "&", " "), $data); //$data = str_replace(array("&lt;","&gt;","&amp;","&nbsp;"), array("<", ">", "&", " "), $data);

View File

@ -257,7 +257,7 @@ class SapphireTestReporter implements PHPUnit_Framework_TestListener {
*/ */
private function getTestException(PHPUnit_Framework_Test $test, Exception $e) { private function getTestException(PHPUnit_Framework_Test $test, Exception $e) {
// get the name of the testFile from the test // get the name of the testFile from the test
$testName = ereg_replace('(.*)\((.*[^)])\)', '\\2', $test->toString()); $testName = preg_replace('/(.*)\((.*[^)])\)/', '\\2', $test->toString());
$trace = $e->getTrace(); $trace = $e->getTrace();
// loop through the exception trace to find the original exception // loop through the exception trace to find the original exception
for($i = 0; $i < count($trace); $i++) { for($i = 0; $i < count($trace); $i++) {

View File

@ -360,7 +360,11 @@ class Email extends ViewableData {
* @desc Validates the email address. Returns true of false * @desc Validates the email address. Returns true of false
*/ */
static function validEmailAddress($address) { static function validEmailAddress($address) {
return ereg('^([a-zA-Z0-9_+\.\-]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$', $address); if (function_exists('filter_var')) {
return filter_var($address, FILTER_VALIDATE_EMAIL);
} else {
return preg_match('#^([a-zA-Z0-9_+\.\-]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$#', $address);
}
} }
/** /**
@ -658,7 +662,7 @@ class Email_BounceHandler extends Controller {
} }
private function recordBounce( $email, $date = null, $time = null, $error = null ) { private function recordBounce( $email, $date = null, $time = null, $error = null ) {
if(ereg('<(.*)>', $email, $parts)) $email = $parts[1]; if(preg_match('/<(.*)>/', $email, $parts)) $email = $parts[1];
$SQL_email = Convert::raw2sql($email); $SQL_email = Convert::raw2sql($email);
$SQL_bounceTime = Convert::raw2sql("$date $time"); $SQL_bounceTime = Convert::raw2sql("$date $time");

View File

@ -134,7 +134,7 @@ function htmlEmail($to, $from, $subject, $htmlContent, $attachedFiles = false, $
} }
// Strip the human name from the bounce address // Strip the human name from the bounce address
if(ereg('^([^<>]*)<([^<>]+)> *$', $bounceAddress, $parts)) $bounceAddress = $parts[2]; if(preg_match('/^([^<>]*)<([^<>]+)> *$/', $bounceAddress, $parts)) $bounceAddress = $parts[2];
// $headers["Sender"] = $from; // $headers["Sender"] = $from;
$headers["X-Mailer"] = X_MAILER; $headers["X-Mailer"] = X_MAILER;
@ -215,7 +215,7 @@ function plaintextEmail($to, $from, $subject, $plainContent, $attachedFiles, $cu
if(isset($customheaders["X-SilverStripeMessageID"]) && defined('BOUNCE_EMAIL')) { if(isset($customheaders["X-SilverStripeMessageID"]) && defined('BOUNCE_EMAIL')) {
$bounceAddress = BOUNCE_EMAIL; $bounceAddress = BOUNCE_EMAIL;
// Get the human name from the from address, if there is one // Get the human name from the from address, if there is one
if(ereg('^([^<>]+)<([^<>])> *$', $from, $parts)) if(preg_match('/^([^<>]+)<([^<>])> *$/', $from, $parts))
$bounceAddress = "$parts[1]<$bounceAddress>"; $bounceAddress = "$parts[1]<$bounceAddress>";
} else { } else {
$bounceAddress = $from; $bounceAddress = $from;
@ -249,8 +249,7 @@ function plaintextEmail($to, $from, $subject, $plainContent, $attachedFiles, $cu
function encodeMultipart($parts, $contentType, $headers = false) { function encodeMultipart($parts, $contentType, $headers = false) {
$separator = "----=_NextPart_" . ereg_replace('[^0-9]','',rand() * 10000000000); $separator = "----=_NextPart_" . preg_replace('/[^0-9]/', '', rand() * 10000000000);
$headers["MIME-Version"] = "1.0"; $headers["MIME-Version"] = "1.0";
$headers["Content-Type"] = "$contentType; boundary=\"$separator\""; $headers["Content-Type"] = "$contentType; boundary=\"$separator\"";

View File

@ -144,7 +144,7 @@ class File extends DataObject {
*/ */
static function find($filename) { static function find($filename) {
// Get the base file if $filename points to a resampled file // Get the base file if $filename points to a resampled file
$filename = ereg_replace('_resampled/[^-]+-','',$filename); $filename = preg_replace('/_resampled/[^-]+-/', '', $filename);
// Split to folders and the actual filename, and traverse the structure. // Split to folders and the actual filename, and traverse the structure.
$parts = explode("/", $filename); $parts = explode("/", $filename);
@ -483,7 +483,7 @@ class File extends DataObject {
} }
// Update title // Update title
if(!$this->getField('Title')) $this->__set('Title', str_replace(array('-','_'),' ',ereg_replace('\.[^.]+$','',$name))); if(!$this->getField('Title')) $this->__set('Title', str_replace(array('-','_'),' ', preg_replace('/\.[^.]+$/', '', $name)));
// Update actual field value // Update actual field value
$this->setField('Name', $name); $this->setField('Name', $name);

View File

@ -261,11 +261,11 @@ class Folder extends File {
$oldFile = $file; $oldFile = $file;
if(strpos($file, '.') !== false) { if(strpos($file, '.') !== false) {
$file = ereg_replace('[0-9]*(\.[^.]+$)', $i . '\\1', $file); $file = preg_replace('/[0-9]*(\.[^.]+$)/', $i . '\\1', $file);
} elseif(strpos($file, '_') !== false) { } elseif(strpos($file, '_') !== false) {
$file = ereg_replace('_([^_]+$)', '_' . $i, $file); $file = preg_replace('/_([^_]+$)/', '_' . $i, $file);
} else { } else {
$file .= "_$i"; $file .= '_'.$i;
} }
if($oldFile == $file && $i > 2) user_error("Couldn't fix $file$ext with $i", E_USER_ERROR); if($oldFile == $file && $i > 2) user_error("Couldn't fix $file$ext with $i", E_USER_ERROR);

View File

@ -144,13 +144,13 @@ class Upload extends Controller {
// make sure archives retain valid extensions // make sure archives retain valid extensions
if(substr($relativeFilePath, strlen($relativeFilePath) - strlen('.tar.gz')) == '.tar.gz' || if(substr($relativeFilePath, strlen($relativeFilePath) - strlen('.tar.gz')) == '.tar.gz' ||
substr($relativeFilePath, strlen($relativeFilePath) - strlen('.tar.bz2')) == '.tar.bz2') { substr($relativeFilePath, strlen($relativeFilePath) - strlen('.tar.bz2')) == '.tar.bz2') {
$relativeFilePath = ereg_replace('[0-9]*(\.tar\.[^.]+$)',$i . '\\1', $relativeFilePath); $relativeFilePath = preg_replace('/[0-9]*(\.tar\.[^.]+$)/', $i . '\\1', $relativeFilePath);
} else if (strpos($relativeFilePath, '.') !== false) { } else if (strpos($relativeFilePath, '.') !== false) {
$relativeFilePath = ereg_replace('[0-9]*(\.[^.]+$)',$i . '\\1', $relativeFilePath); $relativeFilePath = preg_replace('/[0-9]*(\.[^.]+$)/', $i . '\\1', $relativeFilePath);
} else if (strpos($relativeFilePath, '_') !== false) { } else if (strpos($relativeFilePath, '_') !== false) {
$relativeFilePath = ereg_replace('_([^_]+$)', '_'.$i, $relativeFilePath); $relativeFilePath = preg_replace('/_([^_]+$)/', '_'.$i, $relativeFilePath);
} else { } else {
$relativeFilePath .= "_$i"; $relativeFilePath .= '_'.$i;
} }
if($oldFilePath == $relativeFilePath && $i > 2) user_error("Couldn't fix $relativeFilePath with $i tries", E_USER_ERROR); if($oldFilePath == $relativeFilePath && $i > 2) user_error("Couldn't fix $relativeFilePath with $i tries", E_USER_ERROR);
} }

View File

@ -86,7 +86,7 @@ JS;
$i=0; $i=0;
if($this->value) foreach($this->value as $part){ if($this->value) foreach($this->value as $part){
if(!$part || !(strlen($part) == 4) || !ereg("([0-9]{4})",$part)){ if(!$part || !(strlen($part) == 4) || !preg_match("/([0-9]{4})/", $part)){
switch($i){ switch($i){
case 0: $number = _t('CreditCardField.FIRST', 'first'); break; case 0: $number = _t('CreditCardField.FIRST', 'first'); break;
case 1: $number = _t('CreditCardField.SECOND', 'second'); break; case 1: $number = _t('CreditCardField.SECOND', 'second'); break;

View File

@ -79,10 +79,10 @@ class FieldGroup extends CompositeField {
if($subfield->getName()) $count++; if($subfield->getName()) $count++;
} }
if($count == 1) $compositeTitle .= 'Group'; if($count == 1) $compositeTitle .= 'Group';
return ereg_replace("[^a-zA-Z0-9]+","",$compositeTitle); return preg_replace("/[^a-zA-Z0-9]+/", "", $compositeTitle);
} }
return ereg_replace("[^a-zA-Z0-9]+","",$this->title); return preg_replace("/[^a-zA-Z0-9]+/", "", $this->title);
} }
/** /**

View File

@ -123,7 +123,7 @@ class FormField extends RequestHandler {
* that this ID is included in the field. * that this ID is included in the field.
*/ */
function ID() { function ID() {
$name = ereg_replace('(^-)|(-$)','',ereg_replace('[^A-Za-z0-9_-]+','-',$this->name)); $name = preg_replace('/(^-)|(-$)/', '', preg_replace('/[^A-Za-z0-9_-]+/', '-', $this->name));
if($this->form) return $this->form->FormName() . '_' . $name; if($this->form) return $this->form->FormName() . '_' . $name;
else return $name; else return $name;
} }
@ -648,7 +648,7 @@ class FormField extends RequestHandler {
* @return string * @return string
*/ */
function Type() { function Type() {
return strtolower(ereg_replace('Field$', '', $this->class)); return strtolower(preg_replace('/Field$/', '', $this->class));
} }
/** /**

View File

@ -425,7 +425,7 @@ class HtmlEditorField_Toolbar extends RequestHandler {
$file = null; $file = null;
} else { } else {
$url = Director::makeRelative($request->getVar('FileURL')); $url = Director::makeRelative($request->getVar('FileURL'));
$url = ereg_replace('_resampled/[^-]+-','',$url); $url = preg_replace('/_resampled/[^-]+-/', '', $url);
$file = DataList::create('File')->filter('Filename', $url)->first(); $file = DataList::create('File')->filter('Filename', $url)->first();
if(!$file) $file = new File(array('Title' => basename($url))); if(!$file) $file = new File(array('Title' => basename($url)));
} }

View File

@ -191,15 +191,15 @@ class i18nTextCollector extends Object {
public function collectFromCode($content, $module) { public function collectFromCode($content, $module) {
$entitiesArr = array(); $entitiesArr = array();
$regexRule = '_t[[:space:]]*\(' . $regexRule = '#_t[[:space:]]*\(' .
'[[:space:]]*("[^"]*"|\\\'[^\']*\\\')[[:space:]]*,' . // namespace.entity '[[:space:]]*("[^"]*"|\\\'[^\']*\\\')[[:space:]]*,' . // namespace.entity
'[[:space:]]*(("([^"]|\\\")*"|\'([^\']|\\\\\')*\')' . // value '[[:space:]]*(("([^"]|\\\")*"|\'([^\']|\\\\\')*\')' . // value
'([[:space:]]*\\.[[:space:]]*("([^"]|\\\")*"|\'([^\']|\\\\\')*\'))*)' . // concatenations '([[:space:]]*\\.[[:space:]]*("([^"]|\\\")*"|\'([^\']|\\\\\')*\'))*)' . // concatenations
'([[:space:]]*,[[:space:]]*[^,)]*)?([[:space:]]*,' . // priority (optional) '([[:space:]]*,[[:space:]]*[^,)]*)?([[:space:]]*,' . // priority (optional)
'[[:space:]]*("([^"]|\\\")*"|\'([^\']|\\\\\')*\'))?[[:space:]]*' . // comment (optional) '[[:space:]]*("([^"]|\\\")*"|\'([^\']|\\\\\')*\'))?[[:space:]]*' . // comment (optional)
'\)'; '\)#';
while (ereg($regexRule, $content, $regs)) { while (preg_match($regexRule, $content, $regs)) {
$entitiesArr = array_merge($entitiesArr, (array)$this->entitySpecFromRegexMatches($regs)); $entitiesArr = array_merge($entitiesArr, (array)$this->entitySpecFromRegexMatches($regs));
// remove parsed content to continue while() loop // remove parsed content to continue while() loop
@ -229,14 +229,15 @@ class i18nTextCollector extends Object {
} }
// @todo respect template tags (< % _t() % > instead of _t()) // @todo respect template tags (< % _t() % > instead of _t())
$regexRule = '_t[[:space:]]*\(' . $regexRule = '#_t[[:space:]]*\(' .
'[[:space:]]*("[^"]*"|\\\'[^\']*\\\')[[:space:]]*,' . // namespace.entity '[[:space:]]*("[^"]*"|\\\'[^\']*\\\')[[:space:]]*,' . // namespace.entity
'[[:space:]]*(("([^"]|\\\")*"|\'([^\']|\\\\\')*\')' . // value '[[:space:]]*(("([^"]|\\\")*"|\'([^\']|\\\\\')*\')' . // value
'([[:space:]]*\\.[[:space:]]*("([^"]|\\\")*"|\'([^\']|\\\\\')*\'))*)' . // concatenations '([[:space:]]*\\.[[:space:]]*("([^"]|\\\")*"|\'([^\']|\\\\\')*\'))*)' . // concatenations
'([[:space:]]*,[[:space:]]*[^,)]*)?([[:space:]]*,' . // priority (optional) '([[:space:]]*,[[:space:]]*[^,)]*)?([[:space:]]*,' . // priority (optional)
'[[:space:]]*("([^"]|\\\")*"|\'([^\']|\\\\\')*\'))?[[:space:]]*' . // comment (optional) '[[:space:]]*("([^"]|\\\")*"|\'([^\']|\\\\\')*\'))?[[:space:]]*' . // comment (optional)
'\)'; '\)#';
while(ereg($regexRule,$content,$regs)) {
while (preg_match($regexRule,$content,$regs)) {
$entitiesArr = array_merge($entitiesArr,(array)$this->entitySpecFromRegexMatches($regs, $fileName)); $entitiesArr = array_merge($entitiesArr,(array)$this->entitySpecFromRegexMatches($regs, $fileName));
// remove parsed content to continue while() loop // remove parsed content to continue while() loop
$content = str_replace($regs[0],"",$content); $content = str_replace($regs[0],"",$content);
@ -301,7 +302,7 @@ class i18nTextCollector extends Object {
// remove wrapping quotes // remove wrapping quotes
$value = ($regs[2]) ? substr($regs[2],1,-1) : null; $value = ($regs[2]) ? substr($regs[2],1,-1) : null;
$value = ereg_replace("([^\\])['\"][[:space:]]*\.[[:space:]]*['\"]",'\\1',$value); $value = preg_replace("/([^\\])['\"][[:space:]]*\.[[:space:]]*['\"]/", '\\1', $value);
// only escape quotes when wrapped in double quotes, to make them safe for insertion // only escape quotes when wrapped in double quotes, to make them safe for insertion
// into single-quoted PHP code. If they're wrapped in single quotes, the string should // into single-quoted PHP code. If they're wrapped in single quotes, the string should

View File

@ -395,8 +395,9 @@ abstract class SS_Database {
} }
//Indexes specified as arrays cannot be checked with this line: (it flattens out the array) //Indexes specified as arrays cannot be checked with this line: (it flattens out the array)
if(!is_array($spec)) if(!is_array($spec)) {
$spec = ereg_replace(" *, *",",",$spec); $spec = preg_replace('/\s*,\s*/', ',', $spec);
}
if(!isset($this->tableList[strtolower($table)])) $newTable = true; if(!isset($this->tableList[strtolower($table)])) $newTable = true;
@ -470,7 +471,7 @@ abstract class SS_Database {
// collations. // collations.
// TODO: move this to the MySQLDatabase file, or drop it altogether? // TODO: move this to the MySQLDatabase file, or drop it altogether?
if(!$this->supportsCollations()) { if(!$this->supportsCollations()) {
$spec = eregi_replace(' *character set [^ ]+( collate [^ ]+)?( |$)','\\2',$spec); $spec = preg_replace('/ *character set [^ ]+( collate [^ ]+)?( |$)/', '\\2', $spec);
} }
if(!isset($this->tableList[strtolower($table)])) $newTable = true; if(!isset($this->tableList[strtolower($table)])) $newTable = true;
@ -632,7 +633,7 @@ abstract class SS_Database {
* @param string $array Array where the replacement should happen * @param string $array Array where the replacement should happen
*/ */
static function replace_with_null(&$array) { static function replace_with_null(&$array) {
$array = ereg_replace('= *\'\'', "= null", $array); $array = preg_replace('/= *\'\'/', '= null', $array);
if(is_array($array)) { if(is_array($array)) {
foreach($array as $key => $value) { foreach($array as $key => $value) {

View File

@ -172,7 +172,7 @@ class Image extends File {
while(file_exists(BASE_PATH . "/$file")) { while(file_exists(BASE_PATH . "/$file")) {
$i = $i ? ($i+1) : 2; $i = $i ? ($i+1) : 2;
$oldFile = $file; $oldFile = $file;
$file = ereg_replace('[0-9]*(\.[^.]+$)',$i . '\\1', $file); $file = preg_replace('/[0-9]*(\.[^.]+$)/', $i . '\\1', $file);
if($oldFile == $file && $i > 2) user_error("Couldn't fix $file with $i", E_USER_ERROR); if($oldFile == $file && $i > 2) user_error("Couldn't fix $file with $i", E_USER_ERROR);
} }

View File

@ -30,7 +30,7 @@ class Date extends DBField {
} }
// Default to NZ date format - strtotime expects a US date // Default to NZ date format - strtotime expects a US date
if(ereg('^([0-9]+)/([0-9]+)/([0-9]+)$', $value, $parts)) { if(preg_match('#^([0-9]+)/([0-9]+)/([0-9]+)$#', $value, $parts)) {
$value = "$parts[2]/$parts[1]/$parts[3]"; $value = "$parts[2]/$parts[1]/$parts[3]";
} }

View File

@ -27,7 +27,7 @@ class SS_Datetime extends Date {
function setValue($value) { function setValue($value) {
// Default to NZ date format - strtotime expects a US date // Default to NZ date format - strtotime expects a US date
if(ereg('^([0-9]+)/([0-9]+)/([0-9]+)$', $value, $parts)) { if(preg_match('#^([0-9]+)/([0-9]+)/([0-9]+)$#', $value, $parts)) {
$value = "$parts[2]/$parts[1]/$parts[3]"; $value = "$parts[2]/$parts[1]/$parts[3]";
} }

View File

@ -63,7 +63,7 @@ class Varchar extends StringField {
* Ensure that the given value is an absolute URL. * Ensure that the given value is an absolute URL.
*/ */
function URL() { function URL() {
if(ereg('^[a-zA-Z]+://', $this->value)) return $this->value; if(preg_match('#^[a-zA-Z]+://#', $this->value)) return $this->value;
else return "http://" . $this->value; else return "http://" . $this->value;
} }

View File

@ -180,7 +180,7 @@ class PermissionCheckboxSetField extends FormField {
$odd = ($odd + 1) % 2; $odd = ($odd + 1) % 2;
$extraClass = $odd ? 'odd' : 'even'; $extraClass = $odd ? 'odd' : 'even';
$extraClass .= ' val' . str_replace(' ', '', $code); $extraClass .= ' val' . str_replace(' ', '', $code);
$itemID = $this->id() . '_' . ereg_replace('[^a-zA-Z0-9]+', '', $code); $itemID = $this->id() . '_' . preg_replace('/[^a-zA-Z0-9]+/', '', $code);
$checked = $disabled = $inheritMessage = ''; $checked = $disabled = $inheritMessage = '';
$checked = (isset($uninheritedCodes[$code]) || isset($inheritedCodes[$code])) ? ' checked="checked"' : ''; $checked = (isset($uninheritedCodes[$code]) || isset($inheritedCodes[$code])) ? ' checked="checked"' : '';
$title = $permission['help'] ? 'title="' . htmlentities($permission['help'], ENT_COMPAT, 'UTF-8') . '" ' : ''; $title = $permission['help'] ? 'title="' . htmlentities($permission['help'], ENT_COMPAT, 'UTF-8') . '" ' : '';