mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
removed unnecessary calls to get_site()
This commit is contained in:
parent
afd97e8449
commit
222ac91bc9
26 changed files with 219 additions and 415 deletions
|
@ -1,126 +1 @@
|
|||
<?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
|
||||
.'&wikipage='.$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 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($words)) {
|
||||
$text = str_replace(array_keys($words),$words,$text);
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
?>
|
||||
<?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)) {
$courseid = SITEID;
}
}
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
.'&wikipage='.$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 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($words)) {
$text = str_replace(array_keys($words),$words,$text);
}
return $text;
}
?>
|
|
@ -407,18 +407,17 @@ function wiki_get_other_wikis(&$wiki, &$user, &$course, $currentid=0) {
|
|||
$mygroupid = mygroupid($course->id);
|
||||
$isteacher = isteacher($course->id, $user->id);
|
||||
$isteacheredit = isteacheredit($course->id, $user->id);
|
||||
$site = get_site();
|
||||
|
||||
switch ($wiki->wtype) {
|
||||
|
||||
case 'student':
|
||||
/// Get all the existing entries for this wiki.
|
||||
$wiki_entries = wiki_get_entries($wiki, 'student');
|
||||
if ($isteacher and ($site->id != $course->id)) {
|
||||
if ($isteacher and (SITEID != $course->id)) {
|
||||
|
||||
/// If the user is an editing teacher, or a non-editing teacher not assigned to a group, show all student
|
||||
/// wikis, regardless of creation.
|
||||
if (($site->id != $course->id) and ($isteacheredit or ($groupmode == NOGROUPS))) {
|
||||
if ((SITEID != $course->id) and ($isteacheredit or ($groupmode == NOGROUPS))) {
|
||||
|
||||
if ($students = get_course_students($course->id)) {
|
||||
/// Default pagename is dependent on the wiki settings.
|
||||
|
@ -494,7 +493,7 @@ function wiki_get_other_wikis(&$wiki, &$user, &$course, $currentid=0) {
|
|||
/// group (for separate groups) or there are visible groups, or if this is
|
||||
/// a site-level wiki, and they are an administrator.
|
||||
if (($groupmode == VISIBLEGROUPS) or
|
||||
(($site->id == $course->id) and isadmin())) {
|
||||
((SITEID == $course->id) and isadmin())) {
|
||||
$viewall = true;
|
||||
}
|
||||
else if ($groupmode == SEPARATEGROUPS) {
|
||||
|
@ -706,7 +705,6 @@ function wiki_can_add_entry(&$wiki, &$user, &$course, $userid=0, $groupid=0) {
|
|||
/// Get the groupmode. It's been added to the wiki object.
|
||||
$groupmode = groupmode($course, $wiki);
|
||||
$mygroupid = mygroupid($course->id);
|
||||
$site = get_site();
|
||||
|
||||
switch ($wiki->wtype) {
|
||||
|
||||
|
@ -715,7 +713,7 @@ function wiki_can_add_entry(&$wiki, &$user, &$course, $userid=0, $groupid=0) {
|
|||
/// A user can create their own wiki at the site level.
|
||||
if ($userid == 0) {
|
||||
return (isstudent($course->id, $user->id) or
|
||||
(($site->id == $course->id) and !empty($user) and !isguest()));
|
||||
((SITEID == $course->id) and !empty($user) and !isguest()));
|
||||
}
|
||||
/// An editing teacher can create any student wiki, or
|
||||
/// a non-editing teacher, if not assigned to a group can create any student wiki, or if assigned to a group can
|
||||
|
@ -730,7 +728,7 @@ function wiki_can_add_entry(&$wiki, &$user, &$course, $userid=0, $groupid=0) {
|
|||
/// If mode is 'nogroups', then all participants can add wikis.
|
||||
if (!$groupmode) {
|
||||
return (isstudent($course->id, $user->id) or isteacher($course->id, $user->id) or
|
||||
(($site->id == $course->id) and !empty($user) and !isguest()));
|
||||
((SITEID == $course->id) and !empty($user) and !isguest()));
|
||||
}
|
||||
/// If not requesting a group, must be a member of a group.
|
||||
else if ($groupid == 0) {
|
||||
|
@ -747,7 +745,7 @@ function wiki_can_add_entry(&$wiki, &$user, &$course, $userid=0, $groupid=0) {
|
|||
case 'teacher':
|
||||
/// If mode is 'nogroups', then all teachers can add wikis.
|
||||
if (!$groupmode) {
|
||||
return (isteacher($course->id, $user->id) or (($site->id == $course->id) and isadmin()));
|
||||
return (isteacher($course->id, $user->id) or ((SITEID == $course->id) and isadmin()));
|
||||
}
|
||||
/// If not requesting a group, must be a member of a group.
|
||||
else if ($groupid == 0) {
|
||||
|
@ -771,7 +769,6 @@ function wiki_can_edit_entry(&$wiki_entry, &$wiki, &$user, &$course) {
|
|||
$can_edit = false;
|
||||
$groupmode = groupmode($course, $wiki);
|
||||
$mygroupid = mygroupid($course->id);
|
||||
$site = get_site();
|
||||
|
||||
/// Editing teacher's and admins can edit all wikis, non-editing teachers can edit wikis in their groups,
|
||||
/// or all wikis if group mode is 'no groups' or they don't belong to a group.
|
||||
|
@ -798,7 +795,7 @@ function wiki_can_edit_entry(&$wiki_entry, &$wiki, &$user, &$course) {
|
|||
/// If mode is 'nogroups', then all participants can edit the wiki.
|
||||
else {
|
||||
$can_edit = (isstudent($course->id, $user->id) or isteacher($course->id, $user->id) or
|
||||
(($site->id == $course->id) and !empty($user) and !isguest()));
|
||||
((SITEID == $course->id) and !empty($user) and !isguest()));
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -809,7 +806,7 @@ function wiki_can_edit_entry(&$wiki_entry, &$wiki, &$user, &$course) {
|
|||
$can_edit = (isteacher($course->id, $user->id) and ismember($wiki_entry->groupid, $user->id));
|
||||
}
|
||||
else {
|
||||
$can_edit = (isteacher($course->id, $user->id) or (($site->id == $course->id) and isadmin()));
|
||||
$can_edit = (isteacher($course->id, $user->id) or ((SITEID == $course->id) and isadmin()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -37,11 +37,7 @@
|
|||
|
||||
global $CFG, $THEME, $ME;
|
||||
|
||||
if (! $site = get_site()) {
|
||||
error("Invalid site!");
|
||||
}
|
||||
|
||||
if ($course->id == $site->id) {
|
||||
if ($course->id == SITEID) {
|
||||
$strfiles = get_string("sitefiles");
|
||||
} else {
|
||||
$strfiles = get_string("files");
|
||||
|
@ -64,14 +60,14 @@
|
|||
|
||||
print_header();
|
||||
?>
|
||||
<script language="javascript" type="text/javascript">
|
||||
<!--
|
||||
function set_value(txt) {
|
||||
opener.document.forms['form'].initialcontent.value = txt;
|
||||
window.close();
|
||||
}
|
||||
<script language="javascript" type="text/javascript">
|
||||
<!--
|
||||
function set_value(txt) {
|
||||
opener.document.forms['form'].initialcontent.value = txt;
|
||||
window.close();
|
||||
}
|
||||
-->
|
||||
</script>
|
||||
</script>
|
||||
<?php
|
||||
|
||||
echo '<table border="0" cellpadding="3" cellspacing="0" width="100%">';
|
||||
|
@ -82,7 +78,7 @@
|
|||
echo '</tr>';
|
||||
echo '</table>';
|
||||
|
||||
if ($course->id == $site->id) {
|
||||
if ($course->id == SITEID) {
|
||||
print_heading(get_string("publicsitefileswarning"), "center", 2);
|
||||
}
|
||||
|
||||
|
@ -531,33 +527,33 @@
|
|||
break;
|
||||
|
||||
case "torte":
|
||||
if($_POST)
|
||||
{
|
||||
while(list($key, $val) = each($_POST))
|
||||
{
|
||||
if(ereg("file([0-9]+)", $key, $regs))
|
||||
{
|
||||
$file = $val;
|
||||
}
|
||||
}
|
||||
if(@filetype($CFG->dataroot ."/". $course->id . $file) == "file")
|
||||
{
|
||||
if(mimeinfo("icon", $file) == "image.gif")
|
||||
{
|
||||
$url = $CFG->wwwroot ."/file.php?file=/" .$course->id . $file;
|
||||
runjavascript($url);
|
||||
}
|
||||
else
|
||||
{
|
||||
print "File is not a image!";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "You cannot insert FOLDER into richtext editor!!!";
|
||||
}
|
||||
}
|
||||
break;
|
||||
if($_POST)
|
||||
{
|
||||
while(list($key, $val) = each($_POST))
|
||||
{
|
||||
if(ereg("file([0-9]+)", $key, $regs))
|
||||
{
|
||||
$file = $val;
|
||||
}
|
||||
}
|
||||
if(@filetype($CFG->dataroot ."/". $course->id . $file) == "file")
|
||||
{
|
||||
if(mimeinfo("icon", $file) == "image.gif")
|
||||
{
|
||||
$url = $CFG->wwwroot ."/file.php?file=/" .$course->id . $file;
|
||||
runjavascript($url);
|
||||
}
|
||||
else
|
||||
{
|
||||
print "File is not a image!";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "You cannot insert FOLDER into richtext editor!!!";
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "cancel";
|
||||
clearfilelist();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue