]> git.mjollnir.org Git - moodle.git/commitdiff
Fixed a malformed if statement around 'get_site()'.
authormchurch <mchurch>
Wed, 1 Sep 2004 01:08:55 +0000 (01:08 +0000)
committermchurch <mchurch>
Wed, 1 Sep 2004 01:08:55 +0000 (01:08 +0000)
mod/wiki/filter.php

index 78a327c34c827fe8a3f5e90259e2b3fbaa17c8f0..80da61b7260a2647f218354d521f23ca9d2dad21 100755 (executable)
@@ -1 +1 @@
-<?PHP // $Id$\r\r    //This function provides automatic linking to\r\r    //wiki pages when its page title is found inside every Moodle text\r\r    //It's based in the glosssary filter by Williams Castillo\r\r    //Modifications by mchurch. Enjoy! :-)\r\r\r\r    require_once($CFG->dirroot.'/mod/wiki/lib.php');\r\r\r\r    function wiki_filter($courseid, $text) {\r\r\r\r        global $CFG;\r\r\r\r        if (empty($courseid)) {\r\r            $courseid = SITEID;\r\r            }\r\r        }\r\r\r\r        if (!($course = get_record('course', 'id', $courseid))) {\r\r            return $text;\r\r        }\r\r\r\r//      Get all wikis for this course.\r\r        $wikis = wiki_get_course_wikis($courseid);\r\r        if (empty($wikis)) {\r\r            return $text;\r\r        }\r\r\r\r//      Walk through each wiki, and get entries.\r\r        foreach ($wikis as $wiki) {\r\r            if ($wiki_entries = wiki_get_entries($wiki)) {\r\r\r\r//              Walk through each entry and get the pages.\r\r                foreach ($wiki_entries as $wiki_entry) {\r\r                    if ($wiki_pages = get_records('wiki_pages', 'wiki', $wiki_entry->id)) {\r\r\r\r//                      Walk through each page and filter.\r\r                        foreach ($wiki_pages as $wiki_page) {\r\r                            $startlink = '<a class="autolink" title="Wiki" href="'\r\r                                        .$CFG->wwwroot.'/mod/wiki/view.php?wid='.$wiki->id\r\r                                        .'&userid='.$wiki_entry->userid\r\r                                        .'&groupid='.$wiki_entry->groupid\r\r                                        .'&wikipage='.$wiki_page->pagename.'">';\r\r                            $text = wiki_link_names($text, $wiki_page->pagename, $startlink, '</a>');\r\r                        }\r\r                    }\r\r                }\r\r            }\r\r        }\r\r\r\r        return $text;\r\r    }\r\r    \r\r    function wiki_link_names($text,$name,$href_tag_begin,$href_tag_end = "</a>") {\r\r\r\r        $list_of_words_cp = strip_tags($name);\r\r\r\r        $list_of_words_cp = trim($list_of_words_cp,'|');\r\r\r\r        $list_of_words_cp = trim($list_of_words_cp);\r\r\r\r        $list_of_words_cp = preg_quote($list_of_words_cp,'/');\r\r\r\r        $invalidprefixs = "([a-zA-Z0-9])";\r\r        $invalidsufixs  = "([a-zA-Z0-9])";\r\r\r\r        //Avoid seaching in the string if it's inside invalidprefixs and invalidsufixs\r\r        $words = array();\r\r        $regexp = '/'.$invalidprefixs.'('.$list_of_words_cp.')|('.$list_of_words_cp.')'.$invalidsufixs.'/is';\r\r        preg_match_all($regexp,$text,$list_of_words);\r\r\r\r        foreach (array_unique($list_of_words[0]) as $key=>$value) {\r\r            $words['<*'.$key.'*>'] = $value;\r\r        }\r\r        if (!empty($words)) {\r\r            $text = str_replace($words,array_keys($words),$text);\r\r        }\r\r\r\r        //Now avoid searching inside the <nolink>tag\r\r        $excludes = array();\r\r        preg_match_all('/<nolink>(.+?)<\/nolink>/is',$text,$list_of_excludes);\r\r        foreach (array_unique($list_of_excludes[0]) as $key=>$value) {\r\r            $excludes['<+'.$key.'+>'] = $value;\r\r        }\r\r        if (!empty($excludes)) {\r\r            $text = str_replace($excludes,array_keys($excludes),$text);\r\r        }\r\r\r\r        //Now avoid searching inside links\r\r        $links = array();\r\r        preg_match_all('/<A[\s](.+?)>(.+?)<\/A>/is',$text,$list_of_links);\r\r        foreach (array_unique($list_of_links[0]) as $key=>$value) {\r\r            $links['<@'.$key.'@>'] = $value;\r\r        }\r\r        if (!empty($links)) {\r\r            $text = str_replace($links,array_keys($links),$text);\r\r        }\r\r\r\r        //Now avoid searching inside every tag\r\r        $final = array();\r\r        preg_match_all('/<(.+?)>/is',$text,$list_of_tags);\r\r        foreach (array_unique($list_of_tags[0]) as $key=>$value) {\r\r            $final['<|'.$key.'|>'] = $value;\r\r        }\r\r        if (!empty($final)) {\r\r            $text = str_replace($final,array_keys($final),$text);\r\r        }\r\r\r\r        $text = preg_replace('/('.$list_of_words_cp.')/is', $href_tag_begin.'$1'.$href_tag_end,$text);\r\r\r\r        //Now rebuild excluded areas\r\r        if (!empty($final)) {\r\r            $text = str_replace(array_keys($final),$final,$text);\r\r        }\r\r        if (!empty($links)) {\r\r            $text = str_replace(array_keys($links),$links,$text);\r\r        }\r\r        if (!empty($excludes)) {\r\r            $text = str_replace(array_keys($excludes),$excludes,$text);\r\r        }\r\r        if (!empty($words)) {\r\r            $text = str_replace(array_keys($words),$words,$text);\r\r        }\r\r        return $text;\r\r    }\r\r?>\r\r
\ No newline at end of file
+<?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                                        .'&wikipage='.$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