$modinfo = unserialize($course->modinfo);
//Sort modinfo by name length
- usort($modinfo,'comparemodulenamesbylength');
+ usort($modinfo,'comparemodulenamesbylength');
if (!empty($modinfo)) {
$cm = '';
}
return $text;
}
-
+
function activity_link_names($text,$name,$href_tag_begin,$href_tag_end = "</a>") {
$list_of_words_cp = strip_tags($name);
$text = str_replace($excludes,array_keys($excludes),$text);
}
+ //Now avoid searching inside the <span class="nolink">tag
+ // This style doesn't break in editor. See bug #2428
+ $nolinkspan = array();
+ preg_match_all('/<span class=\"nolink\">(.+?)<\/span>/is',$text,$list_of_span);
+ foreach (array_unique($list_of_span[0]) as $key=>$value) {
+ $nolinkspan['<%'.$key.'%>'] = $value;
+ }
+
+ if (!empty($nolinkspan)) {
+ $text = str_replace($nolinkspan,array_keys($nolinkspan),$text);
+ }
+
//Now avoid searching inside links
$links = array();
preg_match_all('/<A[\s](.+?)>(.+?)<\/A>/is',$text,$list_of_links);
if (!empty($excludes)) {
$text = str_replace(array_keys($excludes),$excludes,$text);
}
+ if (!empty( $nolinkspan)) {
+ $text = str_replace(array_keys($nolinkspan),$nolinkspan,$text);
+ }
if (!empty($words)) {
$text = str_replace(array_keys($words),$words,$text);
}
case 'mysql':
$as = '';
break;
- }
+ }
- ///sorting by the lenght of the title in order to assure that large resources
+ ///sorting by the lenght of the title in order to assure that large resources
///could be linked first, if they exist in the text to parse
switch ($CFG->dbtype) {
$rbylenght = "";
break;
}
-
+
$resources = get_records_select("resource", "course = $courseid", "$rbylenght");
if (!empty($resources)) {
}
$title = strip_tags($resource->name);
$href_tag_begin = "<a class=\"autolink\" title=\"$title\" href=\"$CFG->wwwroot/mod/resource/view.php?id=$cm->id\">";
- $currentname = $resource->name;
+ $currentname = $resource->name;
if ($currentname = trim($currentname)) {
//Avoid integers < 1000 to be linked. See bug 1441.
$intcurrent = intval($currentname);
}
return $text;
}
-
+
function resource_link_names($text,$name,$href_tag_begin,$href_tag_end = "</a>") {
$list_of_words_cp = strip_tags($name);
$text = str_replace($excludes,array_keys($excludes),$text);
}
+ //Now avoid searching inside the <span class="nolink">tag
+ // This style doesn't break in editor. See bug #2428
+ $nolinkspan = array();
+ preg_match_all('/<span class=\"nolink\">(.+?)<\/span>/is',$text,$list_of_span);
+ foreach (array_unique($list_of_span[0]) as $key=>$value) {
+ $nolinkspan['<%'.$key.'%>'] = $value;
+ }
+
+ if (!empty($nolinkspan)) {
+ $text = str_replace($nolinkspan,array_keys($nolinkspan),$text);
+ }
+
//Now avoid searching inside links
$links = array();
preg_match_all('/<a[\s](.+?)>(.+?)<\/A>/is',$text,$list_of_links);
if (!empty($excludes)) {
$text = str_replace(array_keys($excludes),$excludes,$text);
}
+ if (!empty( $nolinkspan)) {
+ $text = str_replace(array_keys($nolinkspan),$nolinkspan,$text);
+ }
if (!empty($words)) {
$text = str_replace(array_keys($words),$words,$text);
}
-<?PHP // $Id$\r //This function provides automatic linking to\r //wiki pages when its page title is found inside every Moodle text\r //It's based in the glosssary filter by Williams Castillo\r //Modifications by mchurch. Enjoy! :-)\r\r require_once($CFG->dirroot.'/mod/wiki/lib.php');\r\r function wiki_filter($courseid, $text) {\r\r global $CFG;\r\r if (empty($courseid)) {\r if ($site = get_site()) {\r $courseid = $site->id;\r }\r }\r\r if (!($course = get_record('course', 'id', $courseid))) {\r return $text;\r }\r\r// Get all wikis for this course.\r $wikis = wiki_get_course_wikis($courseid);\r if (empty($wikis)) {\r return $text;\r }\r\r// Walk through each wiki, and get entries.\r foreach ($wikis as $wiki) {\r if ($wiki_entries = wiki_get_entries($wiki)) {\r\r// Walk through each entry and get the pages.\r foreach ($wiki_entries as $wiki_entry) {\r if ($wiki_pages = get_records('wiki_pages', 'wiki', $wiki_entry->id)) {\r\r// Walk through each page and filter.\r foreach ($wiki_pages as $wiki_page) {\r $startlink = '<a class="autolink" title="Wiki" href="'\r .$CFG->wwwroot.'/mod/wiki/view.php?wid='.$wiki->id\r .'&userid='.$wiki_entry->userid\r .'&groupid='.$wiki_entry->groupid\r .'&page='.$wiki_page->pagename.'">';\r $text = wiki_link_names($text, $wiki_page->pagename, $startlink, '</a>');\r }\r }\r }\r }\r }\r\r return $text;\r }\r\r function wiki_link_names($text,$name,$href_tag_begin,$href_tag_end = "</a>") {\r\r $list_of_words_cp = strip_tags($name);\r\r $list_of_words_cp = trim($list_of_words_cp,'|');\r\r $list_of_words_cp = trim($list_of_words_cp);\r\r $list_of_words_cp = preg_quote($list_of_words_cp,'/');\r\r $invalidprefixs = "([a-zA-Z0-9])";\r $invalidsufixs = "([a-zA-Z0-9])";\r\r //Avoid seaching in the string if it's inside invalidprefixs and invalidsufixs\r $words = array();\r $regexp = '/'.$invalidprefixs.'('.$list_of_words_cp.')|('.$list_of_words_cp.')'.$invalidsufixs.'/is';\r preg_match_all($regexp,$text,$list_of_words);\r\r foreach (array_unique($list_of_words[0]) as $key=>$value) {\r $words['<*'.$key.'*>'] = $value;\r }\r\r if (!empty($words)) {\r $text = str_replace($words,array_keys($words),$text);\r }\r\r //Now avoid searching inside the <nolink>tag\r $excludes = array();\r preg_match_all('/<nolink>(.+?)<\/nolink>/is',$text,$list_of_excludes);\r foreach (array_unique($list_of_excludes[0]) as $key=>$value) {\r $excludes['<+'.$key.'+>'] = $value;\r }\r\r if (!empty($excludes)) {\r $text = str_replace($excludes,array_keys($excludes),$text);\r }\r\r //Now avoid searching inside links\r $links = array();\r preg_match_all('/<A[\s](.+?)>(.+?)<\/A>/is',$text,$list_of_links);\r foreach (array_unique($list_of_links[0]) as $key=>$value) {\r $links['<@'.$key.'@>'] = $value;\r }\r\r if (!empty($links)) {\r $text = str_replace($links,array_keys($links),$text);\r }\r\r //Now avoid searching inside every tag\r $final = array();\r preg_match_all('/<(.+?)>/is',$text,$list_of_tags);\r foreach (array_unique($list_of_tags[0]) as $key=>$value) {\r $final['<|'.$key.'|>'] = $value;\r }\r\r if (!empty($final)) {\r $text = str_replace($final,array_keys($final),$text);\r }\r\r $text = preg_replace('/('.$list_of_words_cp.')/is', $href_tag_begin.'$1'.$href_tag_end,$text);\r\r //Now rebuild excluded areas\r if (!empty($final)) {\r $text = str_replace(array_keys($final),$final,$text);\r }\r\r if (!empty($links)) {\r $text = str_replace(array_keys($links),$links,$text);\r }\r\r if (!empty($excludes)) {\r $text = str_replace(array_keys($excludes),$excludes,$text);\r }\r\r if (!empty($words)) {\r $text = str_replace(array_keys($words),$words,$text);\r }\r\r return $text;\r }\r?>
\ No newline at end of file
+<?PHP // $Id$
+ //This function provides automatic linking to
+ //wiki pages when its page title is found inside every Moodle text
+ //It's based in the glosssary filter by Williams Castillo
+ //Modifications by mchurch. Enjoy! :-)
+
+ require_once($CFG->dirroot.'/mod/wiki/lib.php');
+
+ function wiki_filter($courseid, $text) {
+
+ global $CFG;
+
+ if (empty($courseid)) {
+ if ($site = get_site()) {
+ $courseid = $site->id;
+ }
+ }
+
+ if (!($course = get_record('course', 'id', $courseid))) {
+ return $text;
+ }
+
+// Get all wikis for this course.
+ $wikis = wiki_get_course_wikis($courseid);
+ if (empty($wikis)) {
+ return $text;
+ }
+
+// Walk through each wiki, and get entries.
+ foreach ($wikis as $wiki) {
+ if ($wiki_entries = wiki_get_entries($wiki)) {
+
+// Walk through each entry and get the pages.
+ foreach ($wiki_entries as $wiki_entry) {
+ if ($wiki_pages = get_records('wiki_pages', 'wiki', $wiki_entry->id)) {
+
+// Walk through each page and filter.
+ foreach ($wiki_pages as $wiki_page) {
+ $startlink = '<a class="autolink" title="Wiki" href="'
+ .$CFG->wwwroot.'/mod/wiki/view.php?wid='.$wiki->id
+ .'&userid='.$wiki_entry->userid
+ .'&groupid='.$wiki_entry->groupid
+ .'&page='.$wiki_page->pagename.'">';
+ $text = wiki_link_names($text, $wiki_page->pagename, $startlink, '</a>');
+ }
+ }
+ }
+ }
+ }
+
+ return $text;
+ }
+
+ function wiki_link_names($text,$name,$href_tag_begin,$href_tag_end = "</a>") {
+
+ $list_of_words_cp = strip_tags($name);
+
+ $list_of_words_cp = trim($list_of_words_cp,'|');
+
+ $list_of_words_cp = trim($list_of_words_cp);
+
+ $list_of_words_cp = preg_quote($list_of_words_cp,'/');
+
+ $invalidprefixs = "([a-zA-Z0-9])";
+ $invalidsufixs = "([a-zA-Z0-9])";
+
+ //Avoid seaching in the string if it's inside invalidprefixs and invalidsufixs
+ $words = array();
+ $regexp = '/'.$invalidprefixs.'('.$list_of_words_cp.')|('.$list_of_words_cp.')'.$invalidsufixs.'/is';
+ preg_match_all($regexp,$text,$list_of_words);
+
+ foreach (array_unique($list_of_words[0]) as $key=>$value) {
+ $words['<*'.$key.'*>'] = $value;
+ }
+
+ if (!empty($words)) {
+ $text = str_replace($words,array_keys($words),$text);
+ }
+
+ //Now avoid searching inside the <nolink>tag
+ $excludes = array();
+ preg_match_all('/<nolink>(.+?)<\/nolink>/is',$text,$list_of_excludes);
+ foreach (array_unique($list_of_excludes[0]) as $key=>$value) {
+ $excludes['<+'.$key.'+>'] = $value;
+ }
+
+ if (!empty($excludes)) {
+ $text = str_replace($excludes,array_keys($excludes),$text);
+ }
+
+ //Now avoid searching inside the <span class="nolink">tag
+ // This style doesn't break in editor. See bug #2428
+ $nolinkspan = array();
+ preg_match_all('/<span class=\"nolink\">(.+?)<\/span>/is',$text,$list_of_span);
+ foreach (array_unique($list_of_span[0]) as $key=>$value) {
+ $nolinkspan['<%'.$key.'%>'] = $value;
+ }
+
+ if (!empty($nolinkspan)) {
+ $text = str_replace($nolinkspan,array_keys($nolinkspan),$text);
+ }
+
+ //Now avoid searching inside links
+ $links = array();
+ preg_match_all('/<A[\s](.+?)>(.+?)<\/A>/is',$text,$list_of_links);
+ foreach (array_unique($list_of_links[0]) as $key=>$value) {
+ $links['<@'.$key.'@>'] = $value;
+ }
+
+ if (!empty($links)) {
+ $text = str_replace($links,array_keys($links),$text);
+ }
+
+ //Now avoid searching inside every tag
+ $final = array();
+ preg_match_all('/<(.+?)>/is',$text,$list_of_tags);
+ foreach (array_unique($list_of_tags[0]) as $key=>$value) {
+ $final['<|'.$key.'|>'] = $value;
+ }
+
+ if (!empty($final)) {
+ $text = str_replace($final,array_keys($final),$text);
+ }
+
+ $text = preg_replace('/('.$list_of_words_cp.')/is', $href_tag_begin.'$1'.$href_tag_end,$text);
+
+ //Now rebuild excluded areas
+ if (!empty($final)) {
+ $text = str_replace(array_keys($final),$final,$text);
+ }
+
+ if (!empty($links)) {
+ $text = str_replace(array_keys($links),$links,$text);
+ }
+
+ if (!empty($excludes)) {
+ $text = str_replace(array_keys($excludes),$excludes,$text);
+ }
+
+ if (!empty( $nolinkspan)) {
+ $text = str_replace(array_keys($nolinkspan),$nolinkspan,$text);
+ }
+
+ if (!empty($words)) {
+ $text = str_replace(array_keys($words),$words,$text);
+ }
+
+ return $text;
+ }
+?>
\ No newline at end of file