new function course_setup() thats does proper $CFG-> , locale and themes setup much sooner than print_header() originally (needed for MDL-8067), cleanup of forgotten global $course issues
MDL-8067 Fixed several $HTTPSREQUIRED issues - html editor now loads from https (the old hack did not wotk with IE7, new hack is uglier but works), fixed formlibs images (we can not set them in library global scope, we must wait for httpsrequired() and require_login() and od that in function), fixed links in meta.php, fixed help images
fixed setting of new $USER values in user edit forms
include("../../../config.php");
require_once($CFG->dirroot.'/lib/languages.php');
- $id = optional_param('id', 0, PARAM_INT);
+ $id = optional_param('id', 0, PARAM_INT);
+ $httpsrequired = optional_param('httpsrequired', 0, PARAM_BOOL);//flag indicating editor on page with required https
$lastmodified = filemtime("htmlarea.php");
$lifetime = 1800;
$lang = "en";
}
+ if ($httpsrequired) {
+ // this is an ugly hack to allow partial operation of editor on pages that require https when loginhttps enabled
+ // please note that some popups still show nonsecurre items and fullscreen may not function properly in IE
+ $url = preg_replace('|https?://[^/]+|', '', $CFG->wwwroot).'/lib/editor/htmlarea/';
+ } else {
+ $url = $CFG->wwwroot.'/lib/editor/htmlarea/';
+ }
+
$strheading = get_string("heading", "editor");
$strnormal = get_string("normal", "editor");
$straddress = get_string("address", "editor");
_editor_url = _editor_url.replace(/\x2f*$/, '/');
} else {
//alert("WARNING: _editor_url is not set! You should set this variable to the editor files path; it should preferably be an absolute path, like in '/htmlarea', but it can be relative if you prefer. Further we will try to load the editor files correctly but we'll probably fail.");
- _editor_url = '<?php print ($CFG->wwwroot); ?>/lib/editor/htmlarea/';
+ _editor_url = '<?php echo $url; ?>';// we need relative path to site root for editor in pages wit hrequired https
}
// make sure we have a language
// create the IFRAME
var iframe = document.createElement("iframe");
- if (HTMLArea.is_ie) { // http://moodle.org/mod/forum/discuss.php?d=8555
- // tricky! set src to local url to turn off SSL security alert
- iframe.src = _editor_url + this.config.popupURL+"blank.html";
- } else {
- iframe.src = "about:blank";
- }
+ iframe.src = "about:blank";
iframe.className = "iframe";
require_once $CFG->libdir.'/uploadlib.php';
-define('FORM_ADVANCEDIMAGEURL', $CFG->pixpath.'/adv.gif');
-define('FORM_REQIMAGEURL', $CFG->pixpath.'/req.gif');
-
/**
* Callback called when PEAR throws an error
*
* @access public
*/
function MoodleQuickForm($formName, $method, $action, $target='', $attributes=null){
+ global $CFG;
+
static $formcounter = 1;
HTML_Common::HTML_Common($attributes);
}else {
$this->updateAttributes(array('class'=>'mform'));
}
- $this->_reqHTML = '<img class="req" alt="'.get_string('requiredelement', 'form').'" src="'.FORM_REQIMAGEURL.'" />';
- $this->_advancedHTML = '<img class="adv" alt="'.get_string('advancedelement', 'form').'" src="'.FORM_ADVANCEDIMAGEURL.'" />';
+ $this->_reqHTML = '<img class="req" alt="'.get_string('requiredelement', 'form').'" src="'.$CFG->pixpath.'/req.gif'.'" />';
+ $this->_advancedHTML = '<img class="adv" alt="'.get_string('advancedelement', 'form').'" src="'.$CFG->pixpath.'/adv.gif'.'" />';
$this->setRequiredNote(get_string('somefieldsrequired', 'form').
helpbutton('requiredelement', get_string('requiredelement', 'form'), 'moodle', true, false, '', true));
}
return ($USER->sesskey === $sesskey);
}
+/**
+ * Setup all global $CFG course variables, set locale and also
+ * @param mixed $courseorid id of the course or course object
+ */
+function course_setup($courseorid=0) {
+ global $COURSE, $HTTPSPAGEREQUIRED, $CFG;
+
+/// Redefine global $COURSE if needed
+ if (empty($courseorid)) {
+ // no change in global $COURSE - for backwards compatibiltiy
+ // if require_rogin() used after require_login($courseid);
+ } else if (is_object($courseorid)) {
+ $COURSE = clone($courseorid);
+ } else {
+ global $course; // used here only to prevent repeated fetching from DB - may be removed later
+ if ($course->id == $courseorid) {
+ $COURSE = clone($course);
+ } else {
+ if (!$COURSE = get_record('course', 'id', $courseorid)) {
+ error('Invalid course ID');
+ }
+ }
+ }
+
+/// set locale - we should use $COURSE->lang directly in the future
+/// $CFG->courselang is now used in cron and chat to override current language and locale
+ if ($COURSE->id == SITEID or empty($COURSE->lang)) {
+ unset($CFG->courselang);
+ } else {
+ $CFG->courselang = $COURSE->lang;
+ }
+ moodle_setlocale();
+
+/// setup themes - $COURSE->theme should be used instead of $CFG->coursetheme soon
+ if ($COURSE->id == SITEID or empty($CFG->allowcoursethemes) or empty($COURSE->theme)) {
+ unset($CFG->coursetheme);
+ } else {
+ $CFG->coursetheme = $COURSE->theme;
+ }
+ theme_setup();
+
+/// We have to change some URLs in styles if we are in a $HTTPSPAGEREQUIRED page
+/// in case theme changed after call to httpsrequired();
+ if (!empty($HTTPSPAGEREQUIRED)) {
+ $CFG->themewww = str_replace('http:', 'https:', $CFG->themewww);
+ $CFG->pixpath = str_replace('http:', 'https:', $CFG->pixpath);
+ $CFG->modpixpath = str_replace('http:', 'https:', $CFG->modpixpath);
+ foreach ($CFG->stylesheets as $key => $stylesheet) {
+ $CFG->stylesheets[$key] = str_replace('http:', 'https:', $stylesheet);
+ }
+ }
+}
/**
* This function checks that the current user is logged in and has the
global $CFG, $SESSION, $USER, $COURSE, $FULLME, $SITE;
-/// Redefine global $COURSE if needed
- if (empty($courseorid)) {
- // keep previous value - usually $SITE
- } else if (is_object($courseorid)) {
- $COURSE = clone($courseorid);
- } else {
- global $course; // used here only to prevent repeated fetching from DB
- if ($course->id == $courseorid) {
- $COURSE = clone($course);
- } else {
- if (!$COURSE = get_record('course', 'id', $courseorid)) {
- error('Invalid course ID');
- }
- }
- }
-
- if (!empty($COURSE->lang)) {
- $CFG->courselang = $COURSE->lang;
- moodle_setlocale();
- }
+ course_setup($courseorid);
/// If the user is not even logged in yet then make sure they are
if (! (isset($USER->loggedin) and $USER->confirmed and ($USER->site == $CFG->wwwroot)) ) {
$SESSION->fromurl = $_SERVER['HTTP_REFERER'];
}
$USER = NULL;
- if ($autologinguest && !empty($CFG->autologinguests) and
- $COURSE->id and ($COURSE->id == SITEID or $COURSE->guest) ) {
+ if ($autologinguest and !empty($CFG->autologinguests) and ($COURSE->id == SITEID or $COURSE->guest) ) {
$loginguest = '?loginguest=true';
} else {
$loginguest = '';
*/
function email_to_user($user, $from, $subject, $messagetext, $messagehtml='', $attachment='', $attachname='', $usetrueaddress=true, $replyto='', $replytoname='') {
- global $CFG, $FULLME, $COURSE;
-
- if (!empty($COURSE->lang)) { // Course language is defined
- $CFG->courselang = $COURSE->lang;
- }
- if (!empty($COURSE->theme)) { // Course theme is defined
- $CFG->coursetheme = $COURSE->theme;
- }
+ global $CFG, $FULLME;
include_once($CFG->libdir .'/phpmailer/class.phpmailer.php');
global $CFG;
- global $COURSE;
- if (empty($CFG->courselang)) {
- if (!empty($COURSE->lang)) {
- $CFG->courselang = $COURSE->lang;
- }
- }
-
/// originally these special strings were stored in moodle.php now we are only in langconfig.php
$langconfigstrs = array('alphabet', 'backupnameformat', 'firstdayofweek', 'locale',
'localewin', 'localewincharset', 'oldcharset',
$HTTPSPAGEREQUIRED = true;
$CFG->httpswwwroot = str_replace('http:', 'https:', $CFG->wwwroot);
$CFG->httpsthemewww = str_replace('http:', 'https:', $CFG->themewww);
+
+ // change theme paths to pictures
+ $CFG->themewww = str_replace('http:', 'https:', $CFG->themewww);
+ $CFG->pixpath = str_replace('http:', 'https:', $CFG->pixpath);
+ $CFG->modpixpath = str_replace('http:', 'https:', $CFG->modpixpath);
+ foreach ($CFG->stylesheets as $key => $stylesheet) {
+ $CFG->stylesheets[$key] = str_replace('http:', 'https:', $stylesheet);
+ }
} else {
$CFG->httpswwwroot = $CFG->wwwroot;
$CFG->httpsthemewww = $CFG->themewww;
function report_session_error() {
global $CFG, $FULLME;
+
+ theme_setup(); // Sets up theme global variables
if (empty($CFG->lang)) {
$CFG->lang = "en";
}
$CFG->theme = 'standardwhite';
}
- theme_setup(); // Sets up theme global variables
-
/// now do a session test to prevent random user switching - observed on some PHP/Apache combinations,
/// disable checks when working in cookieless mode
if (empty($CFG->usesid) || !empty($_COOKIE['MoodleSession'.$CFG->sessioncookie])) {
}
}
- // set default locale - might be changed again later in require_login()
- moodle_setlocale();
+ // set default locale and themes - might be changed again later from require_login()
+ course_setup();
if (!empty($CFG->opentogoogle)) {
if (empty($USER->id)) { // Ignore anyone logged in
*/
function format_text($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=NULL) {
- global $CFG, $course;
+ global $CFG, $COURSE;
if ($text === '') {
return ''; // no need to do any filters and cleaning
}
if (empty($courseid)) {
- if (!empty($course->id)) { // An ugly hack for better compatibility
- $courseid = $course->id;
- }
+ $courseid = $COURSE->id;
}
if (!empty($CFG->cachetext) and empty($options->nocache)) {
}
if (empty($courseid)) {
- if (!empty($COURSE->id)) { // An ugly hack for better compatibility
- $courseid = $COURSE->id; // (copied from format_text)
- }
+ $courseid = $COURSE->id; // (copied from format_text)
}
if (!empty($CFG->filterall)) {
* @todo Finish documenting this function
*/
function filter_text($text, $courseid=NULL) {
- global $CFG;
+ global $CFG, $COURSE;
+
+ if (empty($courseid)) {
+ $courseid = $COURSE->id; // (copied from format_text)
+ }
require_once($CFG->libdir.'/filterlib.php');
if (!empty($CFG->textfilters)) {
$meta='', $cache=true, $button=' ', $menu='',
$usexml=false, $bodytags='', $return=false) {
- global $USER, $CFG, $THEME, $SESSION, $ME, $SITE, $HTTPSPAGEREQUIRED;
+ global $USER, $CFG, $THEME, $SESSION, $ME, $SITE, $COURSE;
/// This makes sure that the header is never repeated twice on a page
if (defined('HEADER_PRINTED')) {
define('HEADER_PRINTED', 'true');
- global $COURSE;
- if (!empty($COURSE->lang)) {
- $CFG->courselang = $COURSE->lang;
- moodle_setlocale();
- }
- if (!empty($COURSE->theme)) {
- if (!empty($CFG->allowcoursethemes)) {
- $CFG->coursetheme = $COURSE->theme;
- theme_setup();
- }
- }
-
-/// We have to change some URLs in styles if we are in a $HTTPSPAGEREQUIRED page
- if (!empty($HTTPSPAGEREQUIRED)) {
- $CFG->themewww = str_replace('http:', 'https:', $CFG->themewww);
- $CFG->pixpath = str_replace('http:', 'https:', $CFG->pixpath);
- $CFG->modpixpath = str_replace('http:', 'https:', $CFG->modpixpath);
- foreach ($CFG->stylesheets as $key => $stylesheet) {
- $CFG->stylesheets[$key] = str_replace('http:', 'https:', $stylesheet);
- }
- }
-
/// Add the required stylesheets
$stylesheetshtml = '';
foreach ($CFG->stylesheets as $stylesheet) {
* @todo Finish documenting this function
*/
function print_footer($course=NULL, $usercourse=NULL, $return=false) {
- global $USER, $CFG, $THEME;
+ global $USER, $CFG, $THEME, $COURSE;
/// Course links
if ($course) {
* @return string
*/
function current_theme() {
- global $CFG, $USER, $SESSION, $course;
+ global $CFG, $USER, $SESSION;
if (!empty($CFG->pagetheme)) { // Page theme is for special page-only themes set by code
return $CFG->pagetheme;
/// $width and height are legacy fields and no longer used as pixels like they used to be.
/// However, you can set them to zero to override the mincols and minrows values below.
- global $CFG, $course;
- static $scriptcount; // For loading the htmlarea script only once.
+ global $CFG, $COURSE, $HTTPSPAGEREQUIRED;
+ static $scriptcount = 0; // For loading the htmlarea script only once.
$mincols = 65;
$minrows = 10;
if ( empty($CFG->editorsrc) ) { // for backward compatibility.
if (empty($courseid)) {
- if (!empty($course->id)) { // search for it in global context
- $courseid = $course->id;
- }
- }
-
- if (empty($scriptcount)) {
- $scriptcount = 0;
+ $courseid = $COURSE->id;
}
if ($usehtmleditor) {
if (!empty($courseid) and has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $courseid))) {
+ $httpsrequired = empty($HTTPSPAGEREQUIRED) ? '' : '&httpsrequired=1';
// needed for course file area browsing in image insert plugin
$str .= ($scriptcount < 1) ? '<script type="text/javascript" src="'.
- $CFG->wwwroot .'/lib/editor/htmlarea/htmlarea.php?id='. $courseid .'"></script>'."\n" : '';
+ $CFG->httpswwwroot .'/lib/editor/htmlarea/htmlarea.php?id='.$courseid.$httpsrequired.'"></script>'."\n" : '';
} else {
+ $httpsrequired = empty($HTTPSPAGEREQUIRED) ? '' : '?httpsrequired=1';
$str .= ($scriptcount < 1) ? '<script type="text/javascript" src="'.
- $CFG->wwwroot .'/lib/editor/htmlarea/htmlarea.php"></script>'."\n" : '';
+ $CFG->httpswwwroot .'/lib/editor/htmlarea/htmlarea.php'.$httpsrequired.'"></script>'."\n" : '';
+
}
$str .= ($scriptcount < 1) ? '<script type="text/javascript" src="'.
- $CFG->wwwroot .'/lib/editor/htmlarea/lang/en.php"></script>'."\n" : '';
+ $CFG->httpswwwroot .'/lib/editor/htmlarea/lang/en.php"></script>'."\n" : '';
$scriptcount++;
if ($height) { // Usually with legacy calls
function editorshortcutshelpbutton() {
global $CFG;
- $imagetext = '<img src="' . $CFG->wwwroot . '/lib/editor/htmlarea/images/kbhelp.gif" alt="'.
+ $imagetext = '<img src="' . $CFG->httpswwwroot . '/lib/editor/htmlarea/images/kbhelp.gif" alt="'.
get_string('editorshortcutkeys').'" class="iconkbhelp" />';
return helpbutton('editorshortcuts', get_string('editorshortcutkeys'), 'moodle', true, false, '', true, $imagetext);
$str = '<a href="' .$CFG->docroot. '/' .$lang. '/' .$path. '"' .$target. '>';
if (empty($iconpath)) {
- $iconpath = $CFG->wwwroot . '/pix/docs.gif';
+ $iconpath = $CFG->httpswwwroot . '/pix/docs.gif';
}
// alt left blank intentionally to prevent repetition in screenreaders
$id = optional_param('id', SITEID, PARAM_INT);
- $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
-
//HTTPS is potentially required in this page
httpsrequired();
+ $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
+
if (!$course = get_record('course', 'id', $id)) {
error('No such course!');
}
}
if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $forum->course)) {
error('Could not get the course module for the forum instance.');
- } else {
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
}
+ if (!$course = get_record('course', 'id', $forum->course)) {
+ error('Incorrect course');
+ }
+
+ require_login($course, false, $cm);
+ $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+
if ( !(($post->userid == $USER->id && has_capability('mod/forum:deleteownpost', $modcontext))
|| has_capability('mod/forum:deleteanypost', $modcontext)) ) {
error("You can't delete this post!");
}
- if (!empty($forum->course)) {
- if ($course = get_record('course', 'id', $forum->course)) {
- if (!empty($course->lang)) {
- $CFG->courselang = $course->lang;
- }
- }
- }
$replycount = forum_count_replies($post);
if ($fromform = $mform_post->get_data()) {
- if (!empty($course->lang)) { // Override current language
- $CFG->courselang = $course->lang;
- }
+ require_login($course, false, $cm);
if (empty($SESSION->fromurl)) {
$errordestination = "$CFG->wwwroot/mod/forum/view.php?f=$forum->id";
function set_parameters() {
global $USER, $CFG;
- if (! empty($this->course->lang)) {
- $CFG->courselang = $this->course->lang;
- }
-
$site = get_site();
function set_parameters() {
global $USER, $CFG;
- if (! empty($this->course->lang)) {
- $CFG->courselang = $this->course->lang;
- }
-
if (empty($USER->id)) { // No need to set up parameters
$this->parameters = array();
return;
<!--[if IE 7]>
- <link rel="stylesheet" type="text/css" href="<?php echo $CFG->wwwroot ?>/theme/standard/styles_ie7.css" />
+ <link rel="stylesheet" type="text/css" href="<?php echo $CFG->httpswwwroot ?>/theme/standard/styles_ie7.css" />
<![endif]-->
<!--[if IE 6]>
- <link rel="stylesheet" type="text/css" href="<?php echo $CFG->wwwroot ?>/theme/standard/styles_ie6.css" />
+ <link rel="stylesheet" type="text/css" href="<?php echo $CFG->httpswwwroot ?>/theme/standard/styles_ie6.css" />
<![endif]-->
require_once($CFG->dirroot.'/user/editlib.php');
require_once($CFG->dirroot.'/user/profile/lib.php');
+ httpsrequired();
+
$course = optional_param('course', SITEID, PARAM_INT); // course id (defaults to Site)
if (!$course = get_record('course', 'id', $course)) {
}
require_login($course->id);
- httpsrequired();
if (isguest()) { //TODO: add proper capability to edit own profile and change password too
print_error('guestnoeditprofile');
profile_save_data($usernew);
// Override old $USER session variable
- $usernew = (array)get_record('user', 'id', $newuser->id); // reload from db
+ $usernew = (array)get_record('user', 'id', $usernew->id); // reload from db
foreach ($usernew as $variable => $value) {
$USER->$variable = $value;
}
require_once($CFG->dirroot.'/user/editlib.php');
require_once($CFG->dirroot.'/user/profile/lib.php');
+ httpsrequired();
+
$id = optional_param('id', $USER->id, PARAM_INT); // user id; -1 if creating new user
$course = optional_param('course', SITEID, PARAM_INT); // course id (defaults to Site)
error('Course ID was incorrect');
}
require_login($course->id);
- httpsrequired(); // HTTPS is potentially required in this page because there are passwords
if ($id == -1) {
// creating new user
if ($user->id == $USER->id) {
// Override old $USER session variable
- $usernew = (array)get_record('user', 'id', $newuser->id); // reload from db
+ $usernew = (array)get_record('user', 'id', $usernew->id); // reload from db
foreach ($usernew as $variable => $value) {
$USER->$variable = $value;
}