]> git.mjollnir.org Git - moodle.git/commitdiff
all areas MDL-20821 Replaced instances of ereg_replace and eregi_replace with preg_re...
authorAndrew Davis <andrew@affinitysoftware.net>
Tue, 17 Nov 2009 01:36:35 +0000 (01:36 +0000)
committerAndrew Davis <andrew@affinitysoftware.net>
Tue, 17 Nov 2009 01:36:35 +0000 (01:36 +0000)
auth/shibboleth/logout.php
filter/tex/filter.php
lib/htmlpurifier/HTMLPurifier/AttrDef/Lang.php
lib/packer/file_archive.php
lib/typo3/class.t3lib_cs.php
lib/typo3/class.t3lib_div.php
lib/wiki_to_markdown.php
lib/xmldb/xmldb_object.php

index 5690a9e06218417b3677d9f58f71adf83f766109..1586457cbbe658c04f9880e01bfa74474e37a52f 100644 (file)
@@ -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);
index 58136060bd48742d1d39dbb2041d85dab9b2fe32..7e1bfb7ea1b61b25bfff8d96fce3c93555a7fb2f 100644 (file)
@@ -147,7 +147,7 @@ class tex_filter extends moodle_text_filter {
             $texexp = str_replace('</nolink>','',$texexp);
             $texexp = str_replace('<span class="nolink">','',$texexp);
             $texexp = str_replace('</span>','',$texexp);
-            $texexp = eregi_replace("<br[[:space:]]*\/?>", '', $texexp);  //dlnsk
+            $texexp = preg_replace("/<br[[:space:]]*\/?>/i", '', $texexp);  //dlnsk
             $align = "middle";
             if (preg_match('/^align=bottom /',$texexp)) {
               $align = "text-bottom";
index 0de496c6abeef757a1548988f92a5207c26f0bf7..f70e7aa1bdd6673681664e99c73fc3fa538cfdc7 100644 (file)
@@ -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);
index 81543ee3bd0cbb418f55cac703f82134b2e17ba7..cad7f10b4d7a73775638ff5e7cf3454ac570ed62 100644 (file)
@@ -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 === '.') {
index a596cb72c5bb01e9fd544aacb773a0a275cfa568..5c998929564c48f000553dd7b5b334cb799381f5 100644 (file)
@@ -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:
index 984f5212d952710d1edbe99ca400478ebfd2abdf..831bd90db888da4f70ef35f2384b885e445e3034 100644 (file)
@@ -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('&amp;([#[:alnum:]]*;)','&\1',$str);
+               return preg_replace('/&amp;([#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/');
index a40002c2a6ace4bf0ab14496bde35834a3657dd3..d0484070aeffdd908b9fe5704921352567eeda56 100644 (file)
@@ -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</'.$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;
   }
@@ -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</'.$tag.'>';
 
-    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", "&#188;", $line );
     $line = str_replace( "1/2", "&#189;", $line );
     $line = str_replace( "3/4", "&#190;", $line );
-    $line = eregi_replace( "([[:digit:]]+[[:space:]]*)x([[:space:]]*[[:digit:]]+)", "\\1&#215;\\2", $line ); // (digits) x (digits) - multiply
+    $line = preg_replace( "/([[:digit:]]+[[:space:]]*)x([[:space:]]*[[:digit:]]+)/i", "\\1&#215;\\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<http://www.\\2\\3\>", $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<a href=\"mailto:\\2\">\\3</a>", $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]+)\(([^)]+)\)", "<acronym title=\"\\2\">\\1</acronym>", $line );
+    $line = preg_replace( "/([A-Z]+)\(([^)]+)\)/", "<acronym title=\"\\2\">\\1</acronym>", $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 {
index a5c182e19a9d425fd241a13c53adfdc59556cee7..f0e0dc1acd698726892440b3ad71d5f613c01fe3 100644 (file)
@@ -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;