# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: moodle/lib/weblib.php
--- moodle/lib/weblib.php Base (1.970.2.155)
+++ moodle/lib/weblib.php Locally Modified (Based On 1.970.2.155)
@@ -2303,14 +2303,53 @@
  * @param string $text Passed in by reference. The string to be searched for urls.
  */
 function convert_urls_into_links(&$text) {
+    $filterignoretagsopen  = array('<a\s[^>]+?>');
+    $filterignoretagsclose = array('</a>');
+    filter_save_ignore_tags($text,$filterignoretagsopen,$filterignoretagsclose,$ignoretags);
+    
+     /*$URL_FORMAT = '~((?:^|\>)[^\<]*)' # make sure the last tag is closed
+    .   '(?<![\w\>])' # make sure there's a non-word, non '>' char before the url
+    .   '((?:[a-zA-Z]*):' # protocol + :
+    .   '/*(?!/)(?:' # get any starting /'s
+    .   '[\w$\+\*@&=\-/]' # reserved | unreserved
+    .   '|%[a-fA-F0-9]{2}' # escape
+    .   '|[\?\.:\(\),;!\'](?!(?:\s|$|\<))' # punctuation
+    .   '|(?:(?<=[^/:]{2})#)' # fragment id
+    .   '){2,}' # at least two characters in the main url part
+    .   ')~m';
+
+    $text = preg_replace($URL_FORMAT,'${1}<a href="${2}" target="_blank">${2}</a>', $text);
+
+    $WWW_FORMAT = '~((?:^|\>)[^\<]*)' # make sure the last tag is closed
+    .   '(?<![\w\>/])' # make sure there's a non-word, non '>', non '/' char before the url
+    .   '((?:www)(?:' # www
+    .   '[\w$\+\*@&=\-/]' # reserved | unreserved
+    .   '|%[a-fA-F0-9]{2}' # escape
+    .   '|[\?\.:\(\),;!\'](?!(?:\s|$|\<))' # punctuation
+    .   '|(?:(?<=[^/:]{2})#)' # fragment id
+    .   '){2,}' # at least two characters in the main url part
+    .   ')~m';
+    $text = preg_replace($WWW_FORMAT,'${1}<a href="http://${2}" target="_blank">${2}</a>', $text);*/
+
 /// Make lone URLs into links.   eg http://moodle.com/
-    $text = eregi_replace("([[:space:]]|^|\(|\[)([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])",
-                          "\\1<a href=\"\\2://\\3\\4\" target=\"_blank\">\\2://\\3\\4</a>", $text);
 
+    //the originall
+    //$text = eregi_replace("([[:space:]]|^|\(|\[)([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])",
+    //                      "\\1<a href=\"\\2://\\3\\4\" target=\"_blank\">\\2://\\3\\4</a>", $text);
+
+    //work in progress
+    $text = eregi_replace("([[:space:]]|^|\(|\[)([[:alnum:]]+)://([[:alnum:]#?/&=\.:]*)",
+                          "\\1<a href=\"\\2://\\3\" target=\"_blank\">\\2://\\3</a>", $text);
+
 /// eg www.moodle.com
     $text = eregi_replace("([[:space:]]|^|\(|\[)www\.([^[:space:]]*)([[:alnum:]#?/&=])",
                           "\\1<a href=\"http://www.\\2\\3\" target=\"_blank\">www.\\2\\3</a>", $text);
+
+     if (!empty($ignoretags)) {
+        $ignoretags = array_reverse($ignoretags); /// Reversed so "progressive" str_replace() will solve some nesting problems.
+        $text = str_replace(array_keys($ignoretags),$ignoretags,$text);
 }
+}
 
 /**
  * This function will highlight search words in a given string
@@ -6236,7 +6275,7 @@
     $length = strlen($email);
     $obfuscated = '';
     while ($i < $length) {
-        if (rand(0,2)) {
+        if (rand(0,2) && $email{$i}!='@') {
             $obfuscated.='%'.dechex(ord($email{$i}));
         } else {
             $obfuscated.=$email{$i};
@@ -6264,7 +6303,7 @@
         $numerical = ($c >= ord('0')) && ($c <= ord('9'));
         if ($prev_obfuscated and $numerical ) {
             $obfuscated.='&#'.ord($plaintext{$i}).';';
-        } else if (rand(0,2)) {
+        } else if (rand(0,2) && $plaintext{$i}!='@') {
             $obfuscated.='&#'.ord($plaintext{$i}).';';
             $prev_obfuscated = true;
         } else {
