From 0e2cbb0b88cf3913d850942992448d3c4a0ffd70 Mon Sep 17 00:00:00 2001 From: AngryPHPNerd Date: Mon, 27 Feb 2012 22:14:02 +0100 Subject: [PATCH] Replace ereg with preg_* --- control/ContentNegotiator.php | 8 ++++---- control/Director.php | 4 ++-- control/HTTP.php | 2 +- core/Convert.php | 27 ++++++++++++------------- dev/SapphireTestReporter.php | 2 +- email/Email.php | 10 ++++++--- email/Mailer.php | 9 ++++----- filesystem/File.php | 4 ++-- filesystem/Folder.php | 8 ++++---- filesystem/Upload.php | 10 ++++----- forms/CreditCardField.php | 2 +- forms/FieldGroup.php | 6 +++--- forms/FormField.php | 6 +++--- forms/HtmlEditorField.php | 4 ++-- i18n/i18nTextCollector.php | 17 ++++++++-------- model/Database.php | 11 +++++----- model/Image.php | 2 +- model/fieldtypes/Date.php | 6 +++--- model/fieldtypes/Datetime.php | 4 ++-- model/fieldtypes/Varchar.php | 2 +- security/PermissionCheckboxSetField.php | 4 ++-- 21 files changed, 76 insertions(+), 72 deletions(-) diff --git a/control/ContentNegotiator.php b/control/ContentNegotiator.php index c39317758..9ccf29e40 100644 --- a/control/ContentNegotiator.php +++ b/control/ContentNegotiator.php @@ -143,7 +143,7 @@ class ContentNegotiator { $content = str_replace(' ',' ', $content); $content = str_replace('
','
', $content); - $content = eregi_replace('(]*[^/>])>','\\1/>', $content); + $content = preg_replace('#(]*[^/>])>#i', '\\1/>', $content); $response->setBody($content); @@ -170,14 +170,14 @@ class ContentNegotiator { $content = preg_replace('//', '', $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); // Only replace the doctype in templates with the xml header if($hasXMLHeader) { - $content = ereg_replace(']+>', '', $content); + $content = preg_replace('/]+>/', '', $content); } - $content = ereg_replace('setBody($content); } diff --git a/control/Director.php b/control/Director.php index a7cf8b428..81f1fa29f 100644 --- a/control/Director.php +++ b/control/Director.php @@ -465,7 +465,7 @@ class Director { */ static function makeRelative($url) { // Allow for the accidental inclusion of a // in the URL - $url = ereg_replace('([^:])//','\\1/',$url); + $url = preg_replace('#([^:])//#', '\\1/', $url); $url = trim($url); // Only bother comparing the URL to the absolute version if $url looks like a URL. @@ -866,4 +866,4 @@ class Director { return false; } -} \ No newline at end of file +} diff --git a/control/HTTP.php b/control/HTTP.php index 0a2f08bf7..dcbe3f0a2 100644 --- a/control/HTTP.php +++ b/control/HTTP.php @@ -38,7 +38,7 @@ class HTTP { */ static function absoluteURLs($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 )' ); } /* diff --git a/core/Convert.php b/core/Convert.php index 8501cf530..7404da50b 100644 --- a/core/Convert.php +++ b/core/Convert.php @@ -291,26 +291,25 @@ class Convert { // Replace images with their alt tags if($config['ReplaceImagesWithAlt']) { - $data = eregi_replace(']*alt *= *"([^"]*)"[^>]*>', ' \\1 ', $data); - $data = eregi_replace(']*alt *= *([^ ]*)[^>]*>', ' \\1 ', $data); + $data = preg_replace('/]*alt *= *"([^"]*)"[^>]*>/i', ' \\1 ', $data); + $data = preg_replace('/]*alt *= *([^ ]*)[^>]*>/i', ' \\1 ', $data); } // Compress whitespace if($config['CompressWhitespace']) { - $data = ereg_replace("[\n\r\t ]+", " ", $data); + $data = preg_replace("/\s+/", " ", $data); } // Parse newline tags - $data = ereg_replace("[ \n\r\t]*<[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 = ereg_replace("[ \n\r\t]*<[Dd][Ii][Vv]([^A-Za-z0-9>][^>]*)?> *", "\n\n", $data); - $data = ereg_replace("\n\n\n+","\n\n", $data); - - $data = ereg_replace("<[Bb][Rr]([^A-Za-z0-9>][^>]*)?> *", "\n", $data); - $data = ereg_replace("<[Tt][Rr]([^A-Za-z0-9>][^>]*)?> *", "\n", $data); - $data = ereg_replace("][^>]*)?> *", " ", $data); + $data = preg_replace("/\s*<[Hh][1-6]([^A-Za-z0-9>][^>]*)?> */", "\n\n", $data); + $data = preg_replace("/\s*<[Pp]([^A-Za-z0-9>][^>]*)?> */", "\n\n", $data); + $data = preg_replace("/\s*<[Dd][Ii][Vv]([^A-Za-z0-9>][^>]*)?> */", "\n\n", $data); + $data = preg_replace("/\n\n\n+/", "\n\n", $data); + + $data = preg_replace("/<[Bb][Rr]([^A-Za-z0-9>][^>]*)?> */", "\n", $data); + $data = preg_replace("/<[Tt][Rr]([^A-Za-z0-9>][^>]*)?> */", "\n", $data); + $data = preg_replace("/][^>]*)?> */", " ", $data); $data = preg_replace('/<\/p>/i', "\n\n", $data ); - // Replace HTML entities //$data = preg_replace("/&#([0-9]+);/e", 'chr(\1)', $data); @@ -327,7 +326,7 @@ class Convert { } return trim(wordwrap(trim($data), $wordWrap)); } - + /** * There are no real specifications on correctly encoding mailto-links, * but this seems to be compatible with most of the user-agents. @@ -358,4 +357,4 @@ class Convert { $f = Object::create('URLSegmentFilter'); return $f->filter($title); } -} \ No newline at end of file +} diff --git a/dev/SapphireTestReporter.php b/dev/SapphireTestReporter.php index 4785fcfbb..78f05b156 100644 --- a/dev/SapphireTestReporter.php +++ b/dev/SapphireTestReporter.php @@ -257,7 +257,7 @@ class SapphireTestReporter implements PHPUnit_Framework_TestListener { */ private function getTestException(PHPUnit_Framework_Test $test, Exception $e) { // get the name of the testFile from the test - $testName = ereg_replace('(.*)\((.*[^)])\)', '\\2', $test->toString()); + $testName = preg_replace('/(.*)\((.*[^)])\)/', '\\2', $test->toString()); $trace = $e->getTrace(); // loop through the exception trace to find the original exception for($i = 0; $i < count($trace); $i++) { diff --git a/email/Email.php b/email/Email.php index aab92c8cf..a00e5df7e 100644 --- a/email/Email.php +++ b/email/Email.php @@ -360,9 +360,13 @@ class Email extends ViewableData { * @desc Validates the email address. Returns true of false */ 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); + } } - + /** * Send the email in plaintext. * @@ -658,7 +662,7 @@ class Email_BounceHandler extends Controller { } 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_bounceTime = Convert::raw2sql("$date $time"); diff --git a/email/Mailer.php b/email/Mailer.php index e21f0c492..0a06b67e8 100644 --- a/email/Mailer.php +++ b/email/Mailer.php @@ -134,8 +134,8 @@ function htmlEmail($to, $from, $subject, $htmlContent, $attachedFiles = false, $ } // 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["X-Mailer"] = X_MAILER; if (!isset($customheaders["X-Priority"])) $headers["X-Priority"] = 3; @@ -215,7 +215,7 @@ function plaintextEmail($to, $from, $subject, $plainContent, $attachedFiles, $cu if(isset($customheaders["X-SilverStripeMessageID"]) && defined('BOUNCE_EMAIL')) { $bounceAddress = BOUNCE_EMAIL; // 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>"; } else { $bounceAddress = $from; @@ -249,8 +249,7 @@ function plaintextEmail($to, $from, $subject, $plainContent, $attachedFiles, $cu 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["Content-Type"] = "$contentType; boundary=\"$separator\""; diff --git a/filesystem/File.php b/filesystem/File.php index f7a8b4ef7..d21e56366 100644 --- a/filesystem/File.php +++ b/filesystem/File.php @@ -144,7 +144,7 @@ class File extends DataObject { */ static function find($filename) { // 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. $parts = explode("/", $filename); @@ -483,7 +483,7 @@ class File extends DataObject { } // 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 $this->setField('Name', $name); diff --git a/filesystem/Folder.php b/filesystem/Folder.php index 319e5daf8..ceb5cc16b 100644 --- a/filesystem/Folder.php +++ b/filesystem/Folder.php @@ -261,13 +261,13 @@ class Folder extends File { $oldFile = $file; if(strpos($file, '.') !== false) { - $file = ereg_replace('[0-9]*(\.[^.]+$)', $i . '\\1', $file); + $file = preg_replace('/[0-9]*(\.[^.]+$)/', $i . '\\1', $file); } elseif(strpos($file, '_') !== false) { - $file = ereg_replace('_([^_]+$)', '_' . $i, $file); + $file = preg_replace('/_([^_]+$)/', '_' . $i, $file); } else { - $file .= "_$i"; + $file .= '_'.$i; } - + if($oldFile == $file && $i > 2) user_error("Couldn't fix $file$ext with $i", E_USER_ERROR); } diff --git a/filesystem/Upload.php b/filesystem/Upload.php index fdfeec3ce..97a214933 100644 --- a/filesystem/Upload.php +++ b/filesystem/Upload.php @@ -144,13 +144,13 @@ class Upload extends Controller { // make sure archives retain valid extensions if(substr($relativeFilePath, strlen($relativeFilePath) - strlen('.tar.gz')) == '.tar.gz' || 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) { - $relativeFilePath = ereg_replace('[0-9]*(\.[^.]+$)',$i . '\\1', $relativeFilePath); + $relativeFilePath = preg_replace('/[0-9]*(\.[^.]+$)/', $i . '\\1', $relativeFilePath); } else if (strpos($relativeFilePath, '_') !== false) { - $relativeFilePath = ereg_replace('_([^_]+$)', '_'.$i, $relativeFilePath); + $relativeFilePath = preg_replace('/_([^_]+$)/', '_'.$i, $relativeFilePath); } else { - $relativeFilePath .= "_$i"; + $relativeFilePath .= '_'.$i; } if($oldFilePath == $relativeFilePath && $i > 2) user_error("Couldn't fix $relativeFilePath with $i tries", E_USER_ERROR); } @@ -525,4 +525,4 @@ class Upload_Validator { return true; } -} \ No newline at end of file +} diff --git a/forms/CreditCardField.php b/forms/CreditCardField.php index c6c059d55..2505d7af6 100644 --- a/forms/CreditCardField.php +++ b/forms/CreditCardField.php @@ -86,7 +86,7 @@ JS; $i=0; 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){ case 0: $number = _t('CreditCardField.FIRST', 'first'); break; case 1: $number = _t('CreditCardField.SECOND', 'second'); break; diff --git a/forms/FieldGroup.php b/forms/FieldGroup.php index a0c7181a4..73b9b082b 100644 --- a/forms/FieldGroup.php +++ b/forms/FieldGroup.php @@ -79,12 +79,12 @@ class FieldGroup extends CompositeField { if($subfield->getName()) $count++; } 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); } - + /** * Returns a set of tags, each containing a sub-field. * You can also use <% control FieldSet %>, if you'd like more control over the generated HTML diff --git a/forms/FormField.php b/forms/FormField.php index 7cec10618..15d39773e 100644 --- a/forms/FormField.php +++ b/forms/FormField.php @@ -123,7 +123,7 @@ class FormField extends RequestHandler { * that this ID is included in the field. */ 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; else return $name; } @@ -648,7 +648,7 @@ class FormField extends RequestHandler { * @return string */ function Type() { - return strtolower(ereg_replace('Field$', '', $this->class)); + return strtolower(preg_replace('/Field$/', '', $this->class)); } /** @@ -769,4 +769,4 @@ class FormField extends RequestHandler { else user_error("rootFieldSet() called on $this->class object without a containerFieldSet", E_USER_ERROR); } -} \ No newline at end of file +} diff --git a/forms/HtmlEditorField.php b/forms/HtmlEditorField.php index 7f697bfc2..60e0a7db0 100644 --- a/forms/HtmlEditorField.php +++ b/forms/HtmlEditorField.php @@ -425,7 +425,7 @@ class HtmlEditorField_Toolbar extends RequestHandler { $file = null; } else { $url = Director::makeRelative($request->getVar('FileURL')); - $url = ereg_replace('_resampled/[^-]+-','',$url); + $url = preg_replace('/_resampled/[^-]+-/', '', $url); $file = DataList::create('File')->filter('Filename', $url)->first(); if(!$file) $file = new File(array('Title' => basename($url))); } @@ -663,4 +663,4 @@ class HtmlEditorField_Image extends HtmlEditorField_File { return ($this->file) ? $this->file->CMSThumbnail() : sprintf('', $this->url); } -} \ No newline at end of file +} diff --git a/i18n/i18nTextCollector.php b/i18n/i18nTextCollector.php index ea0509280..5547b33cf 100644 --- a/i18n/i18nTextCollector.php +++ b/i18n/i18nTextCollector.php @@ -191,15 +191,15 @@ class i18nTextCollector extends Object { public function collectFromCode($content, $module) { $entitiesArr = array(); - $regexRule = '_t[[:space:]]*\(' . + $regexRule = '#_t[[:space:]]*\(' . '[[:space:]]*("[^"]*"|\\\'[^\']*\\\')[[:space:]]*,' . // namespace.entity '[[:space:]]*(("([^"]|\\\")*"|\'([^\']|\\\\\')*\')' . // value '([[:space:]]*\\.[[:space:]]*("([^"]|\\\")*"|\'([^\']|\\\\\')*\'))*)' . // concatenations '([[:space:]]*,[[:space:]]*[^,)]*)?([[:space:]]*,' . // priority (optional) '[[:space:]]*("([^"]|\\\")*"|\'([^\']|\\\\\')*\'))?[[:space:]]*' . // comment (optional) - '\)'; - - while (ereg($regexRule, $content, $regs)) { + '\)#'; + + while (preg_match($regexRule, $content, $regs)) { $entitiesArr = array_merge($entitiesArr, (array)$this->entitySpecFromRegexMatches($regs)); // remove parsed content to continue while() loop @@ -229,14 +229,15 @@ class i18nTextCollector extends Object { } // @todo respect template tags (< % _t() % > instead of _t()) - $regexRule = '_t[[:space:]]*\(' . + $regexRule = '#_t[[:space:]]*\(' . '[[:space:]]*("[^"]*"|\\\'[^\']*\\\')[[:space:]]*,' . // namespace.entity '[[:space:]]*(("([^"]|\\\")*"|\'([^\']|\\\\\')*\')' . // value '([[:space:]]*\\.[[:space:]]*("([^"]|\\\")*"|\'([^\']|\\\\\')*\'))*)' . // concatenations '([[:space:]]*,[[:space:]]*[^,)]*)?([[:space:]]*,' . // priority (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)); // remove parsed content to continue while() loop $content = str_replace($regs[0],"",$content); @@ -301,7 +302,7 @@ class i18nTextCollector extends Object { // remove wrapping quotes $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 // into single-quoted PHP code. If they're wrapped in single quotes, the string should diff --git a/model/Database.php b/model/Database.php index cfaf06485..0af0b8353 100644 --- a/model/Database.php +++ b/model/Database.php @@ -395,8 +395,9 @@ abstract class SS_Database { } //Indexes specified as arrays cannot be checked with this line: (it flattens out the array) - if(!is_array($spec)) - $spec = ereg_replace(" *, *",",",$spec); + if(!is_array($spec)) { + $spec = preg_replace('/\s*,\s*/', ',', $spec); + } if(!isset($this->tableList[strtolower($table)])) $newTable = true; @@ -470,7 +471,7 @@ abstract class SS_Database { // collations. // TODO: move this to the MySQLDatabase file, or drop it altogether? 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; @@ -632,8 +633,8 @@ abstract class SS_Database { * @param string $array Array where the replacement should happen */ static function replace_with_null(&$array) { - $array = ereg_replace('= *\'\'', "= null", $array); - + $array = preg_replace('/= *\'\'/', '= null', $array); + if(is_array($array)) { foreach($array as $key => $value) { if(is_array($value)) { diff --git a/model/Image.php b/model/Image.php index 7986da6c5..52d9b1d85 100644 --- a/model/Image.php +++ b/model/Image.php @@ -172,7 +172,7 @@ class Image extends File { while(file_exists(BASE_PATH . "/$file")) { $i = $i ? ($i+1) : 2; $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); } diff --git a/model/fieldtypes/Date.php b/model/fieldtypes/Date.php index 736179911..f108c530b 100644 --- a/model/fieldtypes/Date.php +++ b/model/fieldtypes/Date.php @@ -30,10 +30,10 @@ class Date extends DBField { } // 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]"; } - + if(is_numeric($value)) { $this->value = date('Y-m-d', $value); } elseif(is_string($value)) { @@ -357,4 +357,4 @@ class Date extends DBField { public function scaffoldFormField($title = null, $params = null) { return new DateField($this->name, $title); } -} \ No newline at end of file +} diff --git a/model/fieldtypes/Datetime.php b/model/fieldtypes/Datetime.php index 77a56688a..ac6d5b91f 100644 --- a/model/fieldtypes/Datetime.php +++ b/model/fieldtypes/Datetime.php @@ -27,10 +27,10 @@ class SS_Datetime extends Date { function setValue($value) { // 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]"; } - + if(is_numeric($value)) { $this->value = date('Y-m-d H:i:s', $value); } elseif(is_string($value)) { diff --git a/model/fieldtypes/Varchar.php b/model/fieldtypes/Varchar.php index 0ca396907..5ea03f0dc 100644 --- a/model/fieldtypes/Varchar.php +++ b/model/fieldtypes/Varchar.php @@ -63,7 +63,7 @@ class Varchar extends StringField { * Ensure that the given value is an absolute 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; } diff --git a/security/PermissionCheckboxSetField.php b/security/PermissionCheckboxSetField.php index 4a25d2b7f..30a55e746 100644 --- a/security/PermissionCheckboxSetField.php +++ b/security/PermissionCheckboxSetField.php @@ -180,7 +180,7 @@ class PermissionCheckboxSetField extends FormField { $odd = ($odd + 1) % 2; $extraClass = $odd ? 'odd' : 'even'; $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 = (isset($uninheritedCodes[$code]) || isset($inheritedCodes[$code])) ? ' checked="checked"' : ''; $title = $permission['help'] ? 'title="' . htmlentities($permission['help'], ENT_COMPAT, 'UTF-8') . '" ' : ''; @@ -281,4 +281,4 @@ class PermissionCheckboxSetField_Readonly extends PermissionCheckboxSetField { function saveInto($record) { return false; } -} \ No newline at end of file +}