From c78a948e8c652e56b61a31c614c1798712d95a04 Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Tue, 17 Nov 2009 01:36:35 +0000 Subject: [PATCH] all areas MDL-20821 Replaced instances of ereg_replace and eregi_replace with preg_replace --- auth/shibboleth/logout.php | 2 +- filter/tex/filter.php | 2 +- .../HTMLPurifier/AttrDef/Lang.php | 2 +- lib/packer/file_archive.php | 2 +- lib/typo3/class.t3lib_cs.php | 4 +- lib/typo3/class.t3lib_div.php | 24 +++++----- lib/wiki_to_markdown.php | 48 +++++++++---------- lib/xmldb/xmldb_object.php | 2 +- 8 files changed, 43 insertions(+), 43 deletions(-) diff --git a/auth/shibboleth/logout.php b/auth/shibboleth/logout.php index 5690a9e062..1586457cbb 100644 --- a/auth/shibboleth/logout.php +++ b/auth/shibboleth/logout.php @@ -139,7 +139,7 @@ function LogoutNotification($SessionID){ while (($file = readdir($dh)) !== false) { // Check if it is a file if (is_file($dir.'/'.$file)){ - $session_key = ereg_replace('sess_', '', $file); + $session_key = preg_replace('/sess_/', '', $file); // Read session file data $data = file($dir.'/'.$file); diff --git a/filter/tex/filter.php b/filter/tex/filter.php index 58136060bd..7e1bfb7ea1 100644 --- a/filter/tex/filter.php +++ b/filter/tex/filter.php @@ -147,7 +147,7 @@ class tex_filter extends moodle_text_filter { $texexp = str_replace('','',$texexp); $texexp = str_replace('','',$texexp); $texexp = str_replace('','',$texexp); - $texexp = eregi_replace("", '', $texexp); //dlnsk + $texexp = preg_replace("//i", '', $texexp); //dlnsk $align = "middle"; if (preg_match('/^align=bottom /',$texexp)) { $align = "text-bottom"; diff --git a/lib/htmlpurifier/HTMLPurifier/AttrDef/Lang.php b/lib/htmlpurifier/HTMLPurifier/AttrDef/Lang.php index 0de496c6ab..f70e7aa1bd 100644 --- a/lib/htmlpurifier/HTMLPurifier/AttrDef/Lang.php +++ b/lib/htmlpurifier/HTMLPurifier/AttrDef/Lang.php @@ -10,7 +10,7 @@ class HTMLPurifier_AttrDef_Lang extends HTMLPurifier_AttrDef public function validate($string, $config, $context) { // moodle change - we use special lang strings unfortunatelly - return ereg_replace('[^0-9a-zA-Z_-]', '', $string); + return preg_replace('/[^0-9a-zA-Z_-]/', '', $string); // moodle change end $string = trim($string); diff --git a/lib/packer/file_archive.php b/lib/packer/file_archive.php index 81543ee3bd..cad7f10b4d 100644 --- a/lib/packer/file_archive.php +++ b/lib/packer/file_archive.php @@ -136,7 +136,7 @@ abstract class file_archive implements Iterator { } } - $result = ereg_replace('\.\.+', '', $result); + $result = preg_replace('/\.\.+/', '', $result); $result = ltrim($result); // no leadin / if ($result === '.') { diff --git a/lib/typo3/class.t3lib_cs.php b/lib/typo3/class.t3lib_cs.php index a596cb72c5..5c99892956 100644 --- a/lib/typo3/class.t3lib_cs.php +++ b/lib/typo3/class.t3lib_cs.php @@ -794,8 +794,8 @@ class t3lib_cs { $trans_tbl = array_flip(get_html_translation_table(HTML_ENTITIES)); // Getting them in iso-8859-1 - but thats ok since this is observed below. } - $token = md5(microtime()); - $parts = explode($token,ereg_replace('(&([#[:alnum:]]*);)',$token.'\2'.$token,$str)); + $token = 'a'.md5(microtime());//token must start with a letter or preg_replace substitution won't work + $parts = explode($token,preg_replace('/(&([#[:alnum:]]*);)/',$token.'\2'.$token,$str)); foreach($parts as $k => $v) { if ($k%2) { if (substr($v,0,1)=='#') { // Dec or hex entities: diff --git a/lib/typo3/class.t3lib_div.php b/lib/typo3/class.t3lib_div.php index 984f5212d9..831bd90db8 100644 --- a/lib/typo3/class.t3lib_div.php +++ b/lib/typo3/class.t3lib_div.php @@ -1147,7 +1147,7 @@ final class t3lib_div { * @return string */ public static function rm_endcomma($string) { - return ereg_replace(',$','',$string); + return preg_replace('/,$/','',$string); } /** @@ -1287,7 +1287,7 @@ final class t3lib_div { * @see calcParenthesis() */ public static function calcPriority($string) { - $string=ereg_replace('[[:space:]]*','',$string); // removing all whitespace + $string=preg_replace('/[ ]*/','',$string); // removing all whitespace $string='+'.$string; // Ensuring an operator for the first entrance $qm='\*\/\+-^%'; $regex = '(['.$qm.'])(['.$qm.']?[0-9\.]*)'; @@ -1370,7 +1370,7 @@ final class t3lib_div { * @return string Converted result. */ public static function deHSCentities($str) { - return ereg_replace('&([#[:alnum:]]*;)','&\1',$str); + return preg_replace('/&([#A-Za-z0-9]*;)/','&\1',$str); } /** @@ -1894,7 +1894,7 @@ final class t3lib_div { $name = ''; } } else { - if ($key = strtolower(ereg_replace('[^a-zA-Z0-9]','',$val))) { + if ($key = strtolower(preg_replace('/[^a-zA-Z0-9]/','',$val))) { $attributes[$key] = ''; $name = $key; } @@ -1917,9 +1917,9 @@ final class t3lib_div { * @internal */ public static function split_tag_attributes($tag) { - $tag_tmp = trim(eregi_replace ('^<[^[:space:]]*','',trim($tag))); + $tag_tmp = trim(preg_replace ('/^<[^[:space:]]*/i','',trim($tag))); // Removes any > in the end of the string - $tag_tmp = trim(eregi_replace ('>$','',$tag_tmp)); + $tag_tmp = trim(preg_replace ('/>$/i','',$tag_tmp)); $value = array(); while (strcmp($tag_tmp,'')) { // Compared with empty string instead , 030102 @@ -2184,7 +2184,7 @@ final class t3lib_div { } // The tag name is cleaned up so only alphanumeric chars (plus - and _) are in there and not longer than 100 chars either. - $tagName = substr(ereg_replace('[^[:alnum:]_-]','',$tagName),0,100); + $tagName = substr(preg_replace('/[^[:alnum:]_-]/','',$tagName),0,100); // If the value is an array then we will call this function recursively: if (is_array($v)) { @@ -2848,7 +2848,7 @@ final class t3lib_div { // Initialize variabels: $filearray = array(); $sortarray = array(); - $path = ereg_replace('\/$','',$path); + $path = preg_replace('#\/$#','',$path); // Find files+directories: if (@is_dir($path)) { @@ -3266,7 +3266,7 @@ final class t3lib_div { $pString = t3lib_div::implodeArrayForUrl('',$params); - return $pString ? $parts.'?'.ereg_replace('^&','',$pString) : $parts; + return $pString ? $parts.'?'.preg_replace('/^&/','',$pString) : $parts; } /** @@ -3389,7 +3389,7 @@ final class t3lib_div { list($v,$n) = explode('|',$GLOBALS['TYPO3_CONF_VARS']['SYS']['requestURIvar']); $retVal = $GLOBALS[$v][$n]; } elseif (!$_SERVER['REQUEST_URI']) { // This is for ISS/CGI which does not have the REQUEST_URI available. - $retVal = '/'.ereg_replace('^/','',t3lib_div::getIndpEnv('SCRIPT_NAME')). + $retVal = '/'.preg_replace('#^/#','',t3lib_div::getIndpEnv('SCRIPT_NAME')). ($_SERVER['QUERY_STRING']?'?'.$_SERVER['QUERY_STRING']:''); } else { $retVal = $_SERVER['REQUEST_URI']; @@ -3612,11 +3612,11 @@ final class t3lib_div { break; case 'msie': $tmp = strstr($useragent,'MSIE'); - $bInfo['VERSION'] = doubleval(ereg_replace('^[^0-9]*','',substr($tmp,4))); + $bInfo['VERSION'] = doubleval(preg_replace('/^[^0-9]*/','',substr($tmp,4))); break; case 'opera': $tmp = strstr($useragent,'Opera'); - $bInfo['VERSION'] = doubleval(ereg_replace('^[^0-9]*','',substr($tmp,5))); + $bInfo['VERSION'] = doubleval(preg_replace('/^[^0-9]*/','',substr($tmp,5))); break; case 'konqu': $tmp = strstr($useragent,'Konqueror/'); diff --git a/lib/wiki_to_markdown.php b/lib/wiki_to_markdown.php index a40002c2a6..d0484070ae 100644 --- a/lib/wiki_to_markdown.php +++ b/lib/wiki_to_markdown.php @@ -90,14 +90,14 @@ class WikiToMarkdown { // BODGE: replace inline $mark characters in places where we want them ignored // they will be put back after main substitutue, stops problems with eg, and/or $bodge = chr(1); - $line = eregi_replace( '([[:alnum:]])'.$mark.'([[:alnum:]])', '\\1'.$bodge.'\\2',$line ); + $line = preg_replace( '/([[:alnum:]])'.$mark.'([[:alnum:]])/i', '\\1'.$bodge.'\\2',$line ); - $regex = '(^| |[(.,])'.$mark.'([^'.$mark.']*)'.$mark.'([^[:alnum:]]|$)'; + $regex = '/(^| |[(.,])'.$mark.'([^'.$mark.']*)'.$mark.'([^[:alnum:]]|$)/i'; $replace = '\\1<'.$tag.'>\\2\\3'; - $line = eregi_replace( $regex, $replace, $line ); + $line = preg_replace( $regex, $replace, $line ); // BODGE: back we go - $line = eregi_replace( $bodge, $mark, $line ); + $line = preg_replace( '/'.$bodge.'/i', $mark, $line ); return $line; } @@ -111,14 +111,14 @@ class WikiToMarkdown { // BODGE: replace inline $mark characters in places where we want them ignored // they will be put back after main substitutue, stops problems with eg, and/or $bodge = chr(1); - $line = eregi_replace( '([[:alnum:]])'.$mark.'([[:alnum:]])', '\\1'.$bodge.'\\2',$line ); + $line = preg_replace( '/([[:alnum:]])'.$mark.'([[:alnum:]])/i', '\\1'.$bodge.'\\2',$line ); - $regex = '(^| |[(.,])'.$mark.'([^'.$mark.']*)'.$mark.'([^[:alnum:]]|$)'; + $regex = '/(^| |[(.,])'.$mark.'([^'.$mark.']*)'.$mark.'([^[:alnum:]]|$)/i'; $replace = '\\1'.$tag.'\\2'.$tag.'\\3'; - $line = eregi_replace( $regex, $replace, $line ); + $line = preg_replace( $regex, $replace, $line ); // BODGE: back we go - $line = eregi_replace( $bodge, $mark, $line ); + $line = preg_replace( '/'.$bodge.'/i', $mark, $line ); return $line; } @@ -128,10 +128,10 @@ class WikiToMarkdown { // do regex for subscript and superscript (slightly different) // $mark is the magic character and $tag the HTML tag to insert - $regex = $mark.'([^'.$mark.']*)'.$mark; + $regex = '/'.$mark.'([^'.$mark.']*)'.$mark.'/i'; $replace = '<'.$tag.'>\\1'; - return eregi_replace( $regex, $replace, $line ); + return preg_replace( $regex, $replace, $line ); } function do_list( $line, $blank=false ) { @@ -146,7 +146,7 @@ class WikiToMarkdown { else { $listchar = $line{0}; $count = strspn( $line, $listchar ); - $line = eregi_replace( "^[".$listchar."]+ ", "", $line ); + $line = preg_replace( "/^[".$listchar."]+ /i", "", $line ); } // find what sort of list this character represents @@ -246,7 +246,7 @@ class WikiToMarkdown { $line = str_replace( "1/4", "¼", $line ); $line = str_replace( "1/2", "½", $line ); $line = str_replace( "3/4", "¾", $line ); - $line = eregi_replace( "([[:digit:]]+[[:space:]]*)x([[:space:]]*[[:digit:]]+)", "\\1×\\2", $line ); // (digits) x (digits) - multiply + $line = preg_replace( "/([[:digit:]]+[[:space:]]*)x([[:space:]]*[[:digit:]]+)/i", "\\1×\\2", $line ); // (digits) x (digits) - multiply // do formatting tags // NOTE: The / replacement *has* to be first, or it will screw the // HTML tags that are added by the other ones @@ -262,48 +262,48 @@ class WikiToMarkdown { // convert urls into proper link with optional link text URL(text) // MARDOWN: HTML conversion should work fine - $line = eregi_replace("([[:space:]]|^)([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])\(([^)]+)\)", + $line = preg_replace("/([[:space:]]|^)([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])\(([^)]+)\)/i", "\\1[\\5](\\2://\\3\\4)", $line); - $line = eregi_replace("([[:space:]])www\.([^[:space:]]*)([[:alnum:]#?/&=])\(([^)]+)\)", + $line = preg_replace("/([[:space:]])www\.([^[:space:]]*)([[:alnum:]#?/&=])\(([^)]+)\)/i", "\\1[\\5](http://www.\\2\\3)", $line); // make urls (with and without httpd) into proper links - $line = eregi_replace("([[:space:]]|^)([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])", + $line = preg_replace("/([[:space:]]|^)([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])/i", "\\1<\\2://\\3\\4>", $line); - $line = eregi_replace("([[:space:]])www\.([^[:space:]]*)([[:alnum:]#?/&=])", + $line = preg_replace("/([[:space:]])www\.([^[:space:]]*)([[:alnum:]#?/&=])/i", "\\1", $line); // make email addresses into mailtos.... // MARKDOWN doesn't quite support this, so do as html - $line = eregi_replace("([[:space:]]|^)([[:alnum:]._-]+@[[:alnum:]._-]+)\(([^)]+)\)", + $line = preg_replace("/([[:space:]]|^)([[:alnum:]._-]+@[[:alnum:]._-]+)\(([^)]+)\)/i", "\\1\\3", $line); // !# at the beginning of any lines means a heading // MARKDOWN: value (1-6) becomes number of hashes - if (eregi( "^!([1-6]) (.*)$", $line, $regs )) { + if (preg_match( "/^!([1-6]) (.*)$/i", $line, $regs )) { $depth = substr( $line, 1, 1 ); $out = substr( '##########', 0, $depth); - $line = eregi_replace( "^!([1-6]) (.*)$", "$out \\2", $line ); + $line = preg_replace( "/^!([1-6]) (.*)$/i", "$out \\2", $line ); } // acronym handing, example HTML(Hypertext Markyp Language) // MARKDOWN: no equiv. so just leave as HTML - $line = ereg_replace( "([A-Z]+)\(([^)]+)\)", "\\1", $line ); + $line = preg_replace( "/([A-Z]+)\(([^)]+)\)/", "\\1", $line ); // Replace resource link >>##(Description Text) // MARKDOWN: change to MD web link style - $line = eregi_replace( " ([a-zA-Z]+):([0-9]+)\(([^)]+)\)", + $line = preg_replace("/ ([a-zA-Z]+):([0-9]+)\(([^)]+)\)/i", " [\\3](".$CFG->wwwroot."/mod/\\1/view.php?id=\\2) ", $line ); require_once($CFG->libdir.'/filelib.php'); $coursefileurl = get_file_url($this->courseid); // Replace picture resource link - $line = eregi_replace( "/([a-zA-Z0-9./_-]+)(png|gif|jpg)\(([^)]+)\)", + $line = preg_replace("#/([a-zA-Z0-9./_-]+)(png|gif|jpg)\(([^)]+)\)#i", "![\\3](".$coursefileurl."/\\1\\2)", $line ); // Replace file resource link - $line = eregi_replace( "file:/([[:alnum:]/._-]+)\(([^)]+)\)", + $line = preg_replace("#file:/([[:alnum:]/._-]+)\(([^)]+)\)#i", "[\\2](".$coursefileurl."/\\1)", $line ); return $line; @@ -359,7 +359,7 @@ class WikiToMarkdown { if (eregi("^\% ",$line) ) { // preformatted text - no processing // MARKDOWN: this is MD code form of a paragraph - $buffer = $buffer . " " . eregi_replace( "^\%","",$line) . "\n"; + $buffer = $buffer . " " . preg_replace( "/^\%/i","",$line) . "\n"; $this->block_state = STATE_NOTIKI; } else { diff --git a/lib/xmldb/xmldb_object.php b/lib/xmldb/xmldb_object.php index a5c182e19a..f0e0dc1acd 100644 --- a/lib/xmldb/xmldb_object.php +++ b/lib/xmldb/xmldb_object.php @@ -164,7 +164,7 @@ class xmldb_object { function checkName () { $result = true; - if ($this->name != eregi_replace('[^a-z0-9_ -]', '', $this->name)) { + if ($this->name != preg_replace('/[^a-z0-9_ -]/i', '', $this->name)) { $result = false; } return $result; -- 2.39.5