# 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,15 +2303,39 @@
  * @param string $text Passed in by reference. The string to be searched for urls.
  */
 function convert_urls_into_links(&$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);
+    $filterignoretagsopen  = array('<a\s[^>]+?>');
+    $filterignoretagsclose = array('</a>');
+    filter_save_ignore_tags($text,$filterignoretagsopen,$filterignoretagsclose,$ignoretags);
 
-/// 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);
+    // Check if we support unicode modifiers in regular expressions. Cache it.
+    // TODO: this check should be a environment requirement in Moodle 2.0, as far as unicode
+    // chars are going to arrive to URLs officially really soon (2010?)
+    // Original RFC regex from: http://www.bytemycode.com/snippets/snippet/796/
+    // Various ideas from: http://alanstorm.com/url_regex_explained
+    // Unicode check, negative assertion and other bits from Moodle.
+    static $unicoderegexp;
+    if (!isset($unicoderegexp)) {
+        $unicoderegexp = @preg_match('/\pL/u', 'a'); // This will fail silenty, returning false,
 }
 
+    if ($unicoderegexp) { //We can use unicode modifiers
+        $text = preg_replace('#(((http(s?))://)(((([\pLl0-9]([\pLl0-9]|-)*[\pLl0-9]|[\pLl0-9])\.)+([\pLl]([\pLl0-9]|-)*[\pLl0-9]|[\pLl]))|(([0-9]{1,3}\.){3}[0-9]{1,3}))(:[\pL0-9]*)?(/([\pLl0-9\.!$&\'\(\)*+,;=_~:@-]|%[a-fA-F0-9]{2})*)*(\?[\pLl0-9\.!$&\'\(\)*+,;=_~:@/?-]*)?(\#[\pLl0-9\.!$&\'\(\)*+,;=_~:@/?-]*)?(?<![,.;]))#i',
+                             '<a href="\\1" target="_blank">\\1</a>', $text);
+        $text = preg_replace('#((www\.([\pLl0-9]([\pLl0-9]|-)*[\pLl0-9]|[\pLl0-9])\.)+([\pLl]([\pLl0-9]|-)*[\pLl0-9]|[\pLl])(:[\pL0-9]*)?(/([\pLl0-9\.!$&\'\(\)*+,;=_~:@-]|%[a-fA-F0-9]{2})*)*(\?[\pLl0-9\.!$&\'\(\)*+,;=_~:@/?-]*)?(\#[\pLl0-9\.!$&\'\(\)*+,;=_~:@/?-]*)?(?<![,.;]))#i',
+                             '<a href="http://\\1" target="_blank">\\1</a>', $text);
+    } else { //We cannot use unicode modifiers
+        $text = preg_replace('#(((http(s?))://)(((([a-z0-9]([a-z0-9]|-)*[a-z0-9]|[a-z0-9])\.)+([a-z]([a-z0-9]|-)*[a-z0-9]|[a-z]))|(([0-9]{1,3}\.){3}[0-9]{1,3}))(:[a-zA-Z0-9]*)?(/([a-z0-9\.!$&\'\(\)*+,;=_~:@-]|%[a-f0-9]{2})*)*(\?[a-z0-9\.!$&\'\(\)*+,;=_~:@/?-]*)?(\#[a-z0-9\.!$&\'\(\)*+,;=_~:@/?-]*)?(?<![,.;]))#i',
+                             '<a href="\\1" target="_blank">\\1</a>', $text);
+        $text = preg_replace('#((www\.([a-z0-9]([a-z0-9]|-)*[a-z0-9]|[a-z0-9])\.)+([a-z]([a-z0-9]|-)*[a-z0-9]|[a-z])(:[a-zA-Z0-9]*)?(/([a-z0-9\.!$&\'\(\)*+,;=_~:@-]|%[a-f0-9]{2})*)*(\?[a-z0-9\.!$&\'\(\)*+,;=_~:@/?-]*)?(\#[a-z0-9\.!$&\'\(\)*+,;=_~:@/?-]*)?(?<![,.;]))#i',
+                             '<a href="http://\\1" target="_blank">\\1</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
  * It cares about HTML and will not ruin links.  It's best to use
