/**
* Class for creating and manipulating urls.
- *
+ *
* See short write up here http://docs.moodle.org/en/Development:lib/weblib.php_moodle_url
*/
class moodle_url {
- var $scheme = '';// e.g. http
- var $host = '';
+ var $scheme = '';// e.g. http
+ var $host = '';
var $port = '';
var $user = '';
- var $pass = '';
+ var $pass = '';
var $path = '';
var $fragment = '';
var $params = array(); //associative array of query string params
-
+
/**
* Pass no arguments to create a url that refers to this page. Use empty string to create empty url.
- *
+ *
* @param string $url url default null means use this page url with no query string
* empty string means empty url.
* if you pass any other type of url it will be parsed into it's bits, including query string
foreach ($parts as $key => $value){
$this->$key = $value;
}
- $this->params($params);
+ $this->params($params);
}
- }
+ }
/**
- * Add an array of params to the params for this page. The added params override existing ones if they
+ * Add an array of params to the params for this page. The added params override existing ones if they
* have the same name.
*
* @param array $params
function params($params){
$this->params = $params + $this->params;
}
-
+
/**
- * Remove all params if no arguments passed. Or else remove param $arg1, $arg2, etc.
+ * Remove all params if no arguments passed. Or else remove param $arg1, $arg2, etc.
*
* @param string $arg1
* @param string $arg2
}
/**
- * Add a param to the params for this page. The added param overrides existing one if they
+ * Add a param to the params for this page. The added param overrides existing one if they
* have the same name.
*
* @param string $paramname name
$this->params = array($paramname => $param) + $this->params;
}
-
+
function get_query_string($overrideparams = array()){
$arr = array();
$params = $overrideparams + $this->params;
}
/**
* Output url
- *
+ *
* @param boolean $noquerystring whether to output page params as a query string in the url.
* @param array $overrideparams params to add to the output url, these override existing ones with the same name.
* @return string url
*/
- function out($noquerystring = false, $overrideparams = array()) {
+ function out($noquerystring = false, $overrideparams = array()) {
$uri = $this->scheme ? $this->scheme.':'.((strtolower($this->scheme) == 'mailto') ? '':'//'): '';
$uri .= $this->user ? $this->user.($this->pass? ':'.$this->pass:'').'@':'';
$uri .= $this->host ? $this->host : '';
$uri .= (count($this->params)||count($overrideparams)) ? '?'.$this->get_query_string($overrideparams) : '';
}
$uri .= $this->fragment ? '#'.$this->fragment : '';
- return $uri;
+ return $uri;
}
/**
* Output action url with sesskey
- *
+ *
* @param boolean $noquerystring whether to output page params as a query string in the url.
* @return string url
*/
- function out_action($overrideparams = array()) {
+ function out_action($overrideparams = array()) {
$overrideparams = array('sesskey'=> sesskey()) + $overrideparams;
return $this->out(false, $overrideparams);
}
}
if (!empty($options)) {
foreach ($options as $section => $values) {
-
+
$output .= ' <optgroup label="'. s(format_string($section)) .'">'."\n";
foreach ($values as $value => $label) {
$output .= ' <option value="'. format_string($value) .'"';
if ($strcache === false or count($strcache) > 2000 ) { // this number might need some tuning to limit memory usage in cron
$strcache = array();
}
-
+
//init course id
if (empty($courseid)) {
$courseid = $COURSE->id;
if (!empty($CFG->filterall)) {
$string = filter_string($string, $courseid);
}
-
+
// If the site requires it, strip ALL tags from this string
if (!empty($CFG->formatstringstriptags)) {
$string = strip_tags($string);
//Store to cache
$strcache[$md5] = $string;
-
+
return $string;
}
}
if (empty($courseid)) {
- $courseid = $COURSE->id;
+ $courseid = $COURSE->id;
}
require_once($CFG->libdir.'/filterlib.php');
global $ALLOWED_TAGS, $CFG;
if (empty($text) or is_numeric($text)) {
- return (string)$text;
+ return (string)$text;
}
switch ($format) {
/// Fix non standard entity notations
$text = preg_replace('/(&#[0-9]+)(;?)/', "\\1;", $text);
$text = preg_replace('/(&#x[0-9a-fA-F]+)(;?)/', "\\1;", $text);
-
+
/// Remove tags that are not allowed
$text = strip_tags($text, $ALLOWED_TAGS);
-
+
/// Clean up embedded scripts and , using kses
$text = cleanAttributes($text);
}
//Accessibility: added the 'lang' attribute to $direction, used in theme <html> tag.
$language = str_replace('_', '-', str_replace('_utf8', '', current_language()));
@header('Content-Language: '.$language);
- return ($direction.' lang="'.$language.'" xml:lang="'.$language.'"');
+ return ($direction.' lang="'.$language.'" xml:lang="'.$language.'"');
}
$usexml=false, $bodytags='', $return=false) {
global $USER, $CFG, $THEME, $SESSION, $ME, $SITE, $COURSE;
-
+
$heading = format_string($heading); // Fix for MDL-8582
-
+
/// This makes sure that the header is never repeated twice on a page
if (defined('HEADER_PRINTED')) {
debugging('print_header() was called more than once - this should not happen. Please check the code for this page closely. Note: error() and redirect() are now safe to call after print_header().');
}
$meta = $stylesheetshtml.$meta;
-
+
/// Add the meta page from the themes if any were requested
$metapage = '';
$pageclass .= ' course-'.$COURSE->id;
- if (($pageid != 'site-index') && ($pageid != 'course-view') &&
+ if (($pageid != 'site-index') && ($pageid != 'course-view') &&
(strstr($pageid, 'admin') === FALSE)) {
$pageclass .= ' nocoursepage';
}
if (!empty($CFG->langdirection)) {
$pageclass .= ' ' . $CFG->langdirection;
}
-
+
$pageclass .= ' lang-'.$currentlanguage;
$bodytags .= ' class="'.$pageclass.'" id="'.$pageid.'"';
$shortname = '<a href="'.$CFG->wwwroot.'/course/view.php?id='. $COURSE->id .'">'. $COURSE->shortname .'</a> ->';
}
- // If old style nav prepend course short name otherwise leave $navigation object alone
+ // If old style nav prepend course short name otherwise leave $navigation object alone
if (!is_newnav($navigation)) {
$navigation = $shortname.' '.$navigation;
}
foreach ($themeorder as $themetype) {
if (!empty($theme)) continue;
-
+
switch ($themetype) {
case 'page': // Page theme is for special page-only themes set by code
if (!empty($CFG->pagetheme)) {
*/
function current_category_theme($categoryid=0) {
global $COURSE;
-
+
/// Use the COURSE global if the categoryid not set
if (empty($categoryid)) {
if (!empty($COURSE->category)) {
return false;
}
}
-
+
/// Retrieve the current category
if ($category = get_record('course_categories', 'id', $categoryid)) {
-
+
/// Return the category theme if it exists
if (!empty($category->theme)) {
return $category->theme;
} else {
$extra='?file=';
}
-
+
$CFG->pixpath = $CFG->wwwroot. '/pix/smartpix.php'.$extra.'/'.$theme;
$CFG->modpixpath = $CFG->wwwroot .'/pix/smartpix.php'.$extra.'/'.$theme.'/mod';
} else if (empty($THEME->custompix)) { // Could be set in the above file
if ($navigation) {
- if (is_newnav($navigation)) {
+ if (is_newnav($navigation)) {
if ($return) {
return($navigation['breadcrumbs']);
} else {
} else {
debugging('Navigation needs to be updated to use build_navigation()', DEBUG_DEVELOPER);
}
-
+
if (!is_array($navigation)) {
$ar = explode('->', $navigation);
$navigation = array();
-
+
foreach ($ar as $a) {
if (strpos($a, '</a>') === false) {
$navigation[] = array('title' => $a, 'url' => '');
} else {
- if (preg_match('/<a.*href="([^"]*)">(.*)<\/a>/', $a, $matches)) {
+ if (preg_match('/<a.*href="([^"]*)">(.*)<\/a>/', $a, $matches)) {
$navigation[] = array('title' => $matches[2], 'url' => $matches[1]);
}
}
.$CFG->wwwroot.((!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))
&& !empty($USER->id) && !empty($CFG->mymoodleredirect) && !isguest())
? '/my' : '') .'/">'. format_string($site->shortname) ."</a>\n</li>\n";
-
-
+
+
foreach ($navigation as $navitem) {
$title = trim(strip_tags(format_string($navitem['title'], false)));
$url = $navitem['url'];
$output .= '<li class="first">'."$separator\n<a ".$CFG->frametarget.' onclick="this.target=\''.$CFG->framename.'\'" href="'
.$url.'">'."$title</a>\n</li>\n";
}
- }
-
+ }
+
$output .= "</ul>\n";
}
if ($link == '') {
if (!empty($_SERVER['HTTP_REFERER'])) {
$link = $_SERVER['HTTP_REFERER'];
- $link = str_replace('&', '&', $link); // make it valid XHTML
+ $link = str_replace('&', '&', $link); // make it valid XHTML
} else {
$link = $CFG->wwwroot .'/';
}
$link = str_replace('"', '"', $link); //basic XSS protection
$output .= '<div class="singlebutton">';
// taking target out, will need to add later target="'.$target.'"
- $output .= '<form action="'. $link .'" method="'. $method .'">';
+ $output .= '<form action="'. $link .'" method="'. $method .'">';
$output .= '<div>';
if ($options) {
foreach ($options as $name => $value) {
if (!isset($align[$key])) {
$align[$key] = '';
}
-
+
$output .= '<th class="header c'.$key.'" scope="col">'. $heading .'</th>';
// commenting the following code out as <th style does not validate MDL-7861
//$output .= '<th sytle="vertical-align:top;'. $align[$key].$size[$key] .';white-space:nowrap;" class="header c'.$key.'" scope="col">'. $heading .'</th>';
if ($usehtmleditor) {
if (!empty($courseid) and has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $courseid))) {
- $httpsrequired = empty($HTTPSPAGEREQUIRED) ? '' : '&httpsrequired=1';
+ $httpsrequired = empty($HTTPSPAGEREQUIRED) ? '' : '&httpsrequired=1';
// needed for course file area browsing in image insert plugin
$str .= ($scriptcount < 1) ? '<script type="text/javascript" src="'.
$CFG->httpswwwroot .'/lib/editor/htmlarea/htmlarea.php?id='.$courseid.$httpsrequired.'"></script>'."\n" : '';
} else {
- $httpsrequired = empty($HTTPSPAGEREQUIRED) ? '' : '?httpsrequired=1';
+ $httpsrequired = empty($HTTPSPAGEREQUIRED) ? '' : '?httpsrequired=1';
$str .= ($scriptcount < 1) ? '<script type="text/javascript" src="'.
$CFG->httpswwwroot .'/lib/editor/htmlarea/htmlarea.php'.$httpsrequired.'"></script>'."\n" : '';
-
+
}
$str .= ($scriptcount < 1) ? '<script type="text/javascript" src="'.
$CFG->httpswwwroot .'/lib/editor/htmlarea/lang/en.php"></script>'."\n" : '';
$coursecontext = get_context_instance(CONTEXT_COURSE, $courseid);
- $capcheck = false;
+ $capcheck = false;
if (has_capability('moodle/course:manageactivities', $coursecontext) ||
has_capability('moodle/site:manageblocks', $coursecontext)) {
- $capcheck = true;
+ $capcheck = true;
} else {
- // loop through all child context, see if user has moodle/course:manageactivities or moodle/site:manageblocks
+ // loop through all child context, see if user has moodle/course:manageactivities or moodle/site:manageblocks
if ($children = get_child_contexts($coursecontext)) {
foreach ($children as $child) {
$childcontext = get_record('context', 'id', $child);
has_capability('moodle/site:manageblocks', $childcontext)) {
$capcheck = true;
break;
- }
- }
+ }
+ }
}
}
-
-
+
+
if ($capcheck) {
if (!empty($USER->editing)) {
$string = get_string('turneditingoff');
}
/**
- * Provide an definition of error_get_last for PHP before 5.2.0. This simply
+ * Provide an definition of error_get_last for PHP before 5.2.0. This simply
* returns NULL, since there is not way to get the right answer.
*/
if (!function_exists('error_get_last')) {
} else {
$output .= ' <a href="'. $baseurl->out(false, array($pagevar => $currpage)).'">'. $displaypage .'</a>';
}
-
+
}
$displaycount++;
$currpage++;
function print_side_block_start($heading='', $attributes = array()) {
global $CFG, $THEME;
-
+
if (!empty($THEME->customcorners)) {
require_once($CFG->dirroot.'/lib/custom_corners_lib.php');
}
-
+
// If there are no special attributes, give a default CSS class
if (empty($attributes) || !is_array($attributes)) {
$attributes = array('class' => 'sideblock');
*/
function print_side_block_end($attributes = array()) {
global $CFG, $THEME;
-
+
echo '</div>';
if (!empty($THEME->customcorners)) {
/**
* Prints out code needed for spellchecking.
* Original idea by Ludo (Marc Alier).
- *
+ *
* Opening CDATA and <script> are output by weblib::use_html_editor()
* @uses $CFG
* @param boolean $usehtmleditor Normally set by $CFG->htmleditor, can be overriden here
$str .= "\tspeller.openChecker();\n";
$str .= '}'."\n";
}
-
+
if ($return) {
return $str;
}
}
/// Print out the current tree of tabs (this function is recursive)
-
+
$output = convert_tree_to_html($tree);
$output = "\n\n".'<div class="tabtree">'.$output.'</div><div class="clearer"> </div>'."\n\n";
}
if ($tab->inactive || $tab->active || ($tab->selected && !$tab->linkedwhenselected)) {
- if ($tab->selected) {
+ if ($tab->selected) {
$liclass .= (empty($liclass)) ? 'here selected' : ' here selected';
- } else if ($tab->active) {
+ } else if ($tab->active) {
$liclass .= (empty($liclass)) ? 'here active' : ' here active';
}
}
$str .= '<a href="'.$tab->link.'" title="'.$tab->title.'"><span>'.$tab->text.'</span></a>';
}
- if (!empty($tab->subtree)) {
+ if (!empty($tab->subtree)) {
$str .= convert_tree_to_html($tab->subtree, $row+1);
} else if ($tab->selected) {
$str .= '<div class="tabrow'.($row+1).' empty"> </div>'."\n";
function page_doc_link($text='', $iconpath='') {
global $ME, $CFG;
- if (empty($CFG->docroot) || !has_capability('moodle/site:doclinks')) {
- return '';
- }
-
if (empty($CFG->pagepath)) {
$CFG->pagepath = $ME;
}
- $target = '';
- if (!empty($CFG->doctonewwindow)) {
- $target = ' target="_blank"';
- }
-
$path = str_replace($CFG->httpswwwroot.'/','', $CFG->pagepath); // Because the page could be HTTPSPAGEREQUIRED
$path = str_replace('.php', '', $path);
if (empty($path)) { // Not for home page
return '';
}
+ return doc_link($path, $text, $iconpath);
+}
+
+/**
+ * Returns a string containing a link to the user documentation.
+ * Also contains an icon by default. Shown to teachers and admin only.
+ *
+ * @param string $path The relative link
+ * @param string $text The text to be displayed for the link
+ * @param string $iconpath The path to the icon to be displayed
+ */
+function doc_link($path='', $text='', $iconpath='') {
+ global $CFG;
+
+ if (empty($CFG->docroot) || !has_capability('moodle/site:doclinks')) {
+ return '';
+ }
+
+ $target = '';
+ if (!empty($CFG->doctonewwindow)) {
+ $target = ' target="_blank"';
+ }
$lang = str_replace('_utf8', '', current_language());
$caller['line'] = '?'; // probably call_user_func()
}
if (!isset($caller['file'])) {
- $caller['file'] = $CFG->dirroot.'/unknownfile'; // probably call_user_func()
+ $caller['file'] = $CFG->dirroot.'/unknownfile'; // probably call_user_func()
}
$from .= '<li>line ' . $caller['line'] . ' of ' . substr($caller['file'], strlen($CFG->dirroot) + 1);
if (isset($caller['function'])) {