Permalink
Browse files

MDL-20821 reverting untested ereg cleanup, not acceptable for stable,…

… sorry
  • Loading branch information...
1 parent 58693ff commit c2d4c1661a302a4b982ebe728c835f219ea5b26d @skodak skodak committed Nov 19, 2009
Showing with 35 additions and 36 deletions.
  1. +6 −7 lib/validateurlsyntax.php
  2. +29 −29 lib/wiki_to_markdown.php
View
@@ -174,7 +174,7 @@ function validateUrlSyntax( $urladdr, $options="" ){
// $options = strtolower($options);
// Check Options Parameter
- if (!preg_match( '/^([sHSEFuPaIpfqr][+?-])*$/', $options ))
+ if (!ereg( '^([sHSEFuPaIpfqr][+?-])*$', $options ))
{
trigger_error("Options attribute malformed", E_USER_ERROR);
}
@@ -305,18 +305,17 @@ function validateUrlSyntax( $urladdr, $options="" ){
$querystring = '(\?(' . $reserved . '|' . $unreserved . '|' . $escaped . ')*)' . $aOptions['q'];
// Fragment Section - Accepts anchors such as #top
- $fragment = '(\#(' . $reserved . '|' . $unreserved . '|' . $escaped . ')*)' . $aOptions['r'];
+ $fragment = '(#(' . $reserved . '|' . $unreserved . '|' . $escaped . ')*)' . $aOptions['r'];
// Building Regular Expression
- $regexp = '#^' . $scheme . $userinfo . $address . $port_number . $path . $querystring . $fragment . '$' . '#i';
- //die($regexp);
+ $regexp = '^' . $scheme . $userinfo . $address . $port_number . $path . $querystring . $fragment . '$';
// DEBUGGING - Uncomment Line Below To Display The Regular Expression Built
// echo '<pre>' . htmlentities(wordwrap($regexp,70,"\n",1)) . '</pre>';
// Running the regular expression
- if (preg_match( $regexp, $urladdr ))
+ if (eregi( $regexp, $urladdr ))
{
return true; // The domain passed
}
@@ -378,7 +377,7 @@ function validateUrlSyntax( $urladdr, $options="" ){
function validateEmailSyntax( $emailaddr, $options="" ){
// Check Options Parameter
- if (!preg_match( '/^([sHSEFuPaIpfqr][+?-])*$/', $options ))
+ if (!ereg( '^([sHSEFuPaIpfqr][+?-])*$', $options ))
{
trigger_error("Options attribute malformed", E_USER_ERROR);
}
@@ -484,7 +483,7 @@ function validateEmailSyntax( $emailaddr, $options="" ){
function validateFtpSyntax( $ftpaddr, $options="" ){
// Check Options Parameter
- if (!preg_match( '/^([sHSEFuPaIpfqr][+?-])*$/', $options ))
+ if (!ereg( '^([sHSEFuPaIpfqr][+?-])*$', $options ))
{
trigger_error("Options attribute malformed", E_USER_ERROR);
}
View
@@ -59,14 +59,14 @@ function do_replace( $line, $mark, $tag ) {
// 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 = preg_replace( '/([[:alnum:]])'.$mark.'([[:alnum:]])/i', '\\1'.$bodge.'\\2',$line );
+ $line = eregi_replace( '([[:alnum:]])'.$mark.'([[:alnum:]])', '\\1'.$bodge.'\\2',$line );
- $regex = '/(^| |[(.,])'.$mark.'([^'.$mark.']*)'.$mark.'([^[:alnum:]]|$)/i';
+ $regex = '(^| |[(.,])'.$mark.'([^'.$mark.']*)'.$mark.'([^[:alnum:]]|$)';
$replace = '\\1<'.$tag.'>\\2</'.$tag.'>\\3';
- $line = preg_replace( $regex, $replace, $line );
+ $line = eregi_replace( $regex, $replace, $line );
// BODGE: back we go
- $line = preg_replace( '/'.$bodge.'/i', $mark, $line );
+ $line = eregi_replace( $bodge, $mark, $line );
return $line;
}
@@ -80,14 +80,14 @@ function do_replace_markdown( $line, $mark, $tag ) {
// 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 = preg_replace( '/([[:alnum:]])'.$mark.'([[:alnum:]])/i', '\\1'.$bodge.'\\2',$line );
+ $line = eregi_replace( '([[:alnum:]])'.$mark.'([[:alnum:]])', '\\1'.$bodge.'\\2',$line );
- $regex = '/(^| |[(.,])'.$mark.'([^'.$mark.']*)'.$mark.'([^[:alnum:]]|$)/i';
+ $regex = '(^| |[(.,])'.$mark.'([^'.$mark.']*)'.$mark.'([^[:alnum:]]|$)';
$replace = '\\1'.$tag.'\\2'.$tag.'\\3';
- $line = preg_replace( $regex, $replace, $line );
+ $line = eregi_replace( $regex, $replace, $line );
// BODGE: back we go
- $line = preg_replace( '/'.$bodge.'/i', $mark, $line );
+ $line = eregi_replace( $bodge, $mark, $line );
return $line;
}
@@ -97,10 +97,10 @@ function do_replace_sub( $line, $mark, $tag ) {
// do regex for subscript and superscript (slightly different)
// $mark is the magic character and $tag the HTML tag to insert
- $regex = '/'.$mark.'([^'.$mark.']*)'.$mark.'/i';
+ $regex = $mark.'([^'.$mark.']*)'.$mark;
$replace = '<'.$tag.'>\\1</'.$tag.'>';
- return preg_replace( $regex, $replace, $line );
+ return eregi_replace( $regex, $replace, $line );
}
function do_list( $line, $blank=false ) {
@@ -115,7 +115,7 @@ function do_list( $line, $blank=false ) {
else {
$listchar = $line{0};
$count = strspn( $line, $listchar );
- $line = preg_replace( "/^[".$listchar."]+ /i", "", $line );
+ $line = eregi_replace( "^[".$listchar."]+ ", "", $line );
}
// find what sort of list this character represents
@@ -198,7 +198,7 @@ function line_replace( $line ) {
// MARKDOWN: no change so leave
// is this a list line (starts with * # ; :)
- if (preg_match( "/^([*]+|[#]+|[;]+|[:]+) /i", $line )) {
+ if (eregi( "^([*]+|[#]+|[;]+|[:]+) ", $line )) {
$line = $this->do_list( $line );
}
@@ -215,7 +215,7 @@ function line_replace( $line ) {
$line = str_replace( "1/4", "&#188;", $line );
$line = str_replace( "1/2", "&#189;", $line );
$line = str_replace( "3/4", "&#190;", $line );
- $line = preg_replace( "/([[:digit:]]+[[:space:]]*)x([[:space:]]*[[:digit:]]+)/i", "\\1&#215;\\2", $line ); // (digits) x (digits) - multiply
+ $line = eregi_replace( "([[:digit:]]+[[:space:]]*)x([[:space:]]*[[:digit:]]+)", "\\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
@@ -231,48 +231,48 @@ function line_replace( $line ) {
// convert urls into proper link with optional link text URL(text)
// MARDOWN: HTML conversion should work fine
- $line = preg_replace("#([[:space:]]|^)([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]\#?/&=])\(([^)]+)\)#i",
+ $line = eregi_replace("([[:space:]]|^)([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])\(([^)]+)\)",
"\\1[\\5](\\2://\\3\\4)", $line);
- $line = preg_replace("/([[:space:]])www\.([^[:space:]]*)([[:alnum:]#?\/&=])\(([^)]+)\)/i",
+ $line = eregi_replace("([[:space:]])www\.([^[:space:]]*)([[:alnum:]#?/&=])\(([^)]+)\)",
"\\1[\\5](http://www.\\2\\3)", $line);
// make urls (with and without httpd) into proper links
- $line = preg_replace("#([[:space:]]|^)([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]\#?/&=])#i",
+ $line = eregi_replace("([[:space:]]|^)([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])",
"\\1<\\2://\\3\\4>", $line);
- $line = preg_replace("/([[:space:]])www\.([^[:space:]]*)([[:alnum:]#?/&=])/i",
+ $line = eregi_replace("([[:space:]])www\.([^[:space:]]*)([[:alnum:]#?/&=])",
"\\1<http://www.\\2\\3\>", $line);
// make email addresses into mailtos....
// MARKDOWN doesn't quite support this, so do as html
- $line = preg_replace("/([[:space:]]|^)([[:alnum:]._-]+@[[:alnum:]._-]+)\(([^)]+)\)/i",
+ $line = eregi_replace("([[:space:]]|^)([[:alnum:]._-]+@[[:alnum:]._-]+)\(([^)]+)\)",
"\\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 (preg( "/^!([1-6]) (.*)$/i", $line, $regs )) {
+ if (eregi( "^!([1-6]) (.*)$", $line, $regs )) {
$depth = substr( $line, 1, 1 );
$out = substr( '##########', 0, $depth);
- $line = preg_replace( "/^!([1-6]) (.*)$/i", "$out \\2", $line );
+ $line = eregi_replace( "^!([1-6]) (.*)$", "$out \\2", $line );
}
// acronym handing, example HTML(Hypertext Markyp Language)
// MARKDOWN: no equiv. so just leave as HTML
- $line = preg_replace( "/([A-Z]+)\(([^)]+)\)/", "<acronym title=\"\\2\">\\1</acronym>", $line );
+ $line = ereg_replace( "([A-Z]+)\(([^)]+)\)", "<acronym title=\"\\2\">\\1</acronym>", $line );
// Replace resource link >>##(Description Text)
// MARKDOWN: change to MD web link style
- $line = preg_replace( "/ ([a-zA-Z]+):([0-9]+)\(([^)]+)\)/i",
+ $line = eregi_replace( " ([a-zA-Z]+):([0-9]+)\(([^)]+)\)",
" [\\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 = preg_replace( "#/([a-zA-Z0-9./_-]+)(png|gif|jpg)\(([^)]+)\)#i",
+ $line = eregi_replace( "/([a-zA-Z0-9./_-]+)(png|gif|jpg)\(([^)]+)\)",
"![\\3](".$coursefileurl."/\\1\\2)", $line );
// Replace file resource link
- $line = preg_replace( "#file:/([[:alnum:]/._-]+)\(([^)]+)\)#i",
+ $line = eregi_replace( "file:/([[:alnum:]/._-]+)\(([^)]+)\)",
"[\\2](".$coursefileurl."/\\1)", $line );
return $line;
@@ -300,7 +300,7 @@ function convert( $content,$courseid ) {
// run through lines
foreach( $lines as $line ) {
// is this a blank line?
- $blank_line = preg_match( "/^[[:blank:]\r]*$/i", $line );
+ $blank_line = eregi( "^[[:blank:]\r]*$", $line );
if ($blank_line) {
// first end current block according to state
$buffer = $buffer . $this->close_block( $this->block_state );
@@ -311,24 +311,24 @@ function convert( $content,$courseid ) {
// act now depending on current block state
if ($this->block_state == STATE_NONE) {
// first character of line defines block type
- if (preg_match( "/^> /i",$line )) {
+ if (eregi( "^> ",$line )) {
// blockquote
$buffer = $buffer . $this->line_replace( $line ). "\n";
$this->block_state = STATE_BLOCKQUOTE;
}
else
- if (preg_match( "/^ /i",$line) ) {
+ if (eregi( "^ ",$line) ) {
// preformatted text
// MARKDOWN: no real equiv. so just use <pre>
$buffer = $buffer . "<pre>\n";
$buffer = $buffer . $this->line_replace($line) . "\n";
$this->block_state = STATE_PREFORM;
}
else
- if (preg_match("/^\% /i",$line) ) {
+ if (eregi("^\% ",$line) ) {
// preformatted text - no processing
// MARKDOWN: this is MD code form of a paragraph
- $buffer = $buffer . " " . preg_replace( "/^\%/i","",$line) . "\n";
+ $buffer = $buffer . " " . eregi_replace( "^\%","",$line) . "\n";
$this->block_state = STATE_NOTIKI;
}
else {

0 comments on commit c2d4c16

Please sign in to comment.