/lib/deprecatedlib.php
PHP | 1518 lines | 659 code | 170 blank | 689 comment | 119 complexity | 5c0cfc61fdebe8cbaa6433843b865c21 MD5 | raw file
- <?php
- // This file is part of Moodle - http://moodle.org/
- //
- // Moodle is free software: you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- //
- // Moodle is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
- /**
- * deprecatedlib.php - Old functions retained only for backward compatibility
- *
- * Old functions retained only for backward compatibility. New code should not
- * use any of these functions.
- *
- * @package core
- * @subpackage deprecated
- * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @deprecated
- */
- defined('MOODLE_INTERNAL') || die();
- /**
- * Hack to find out the GD version by parsing phpinfo output
- *
- * @return int GD version (1, 2, or 0)
- */
- function check_gd_version() {
- // TODO: delete function in Moodle 2.7
- debugging('check_gd_version() is deprecated, GD extension is always available now');
- $gdversion = 0;
- if (function_exists('gd_info')){
- $gd_info = gd_info();
- if (substr_count($gd_info['GD Version'], '2.')) {
- $gdversion = 2;
- } else if (substr_count($gd_info['GD Version'], '1.')) {
- $gdversion = 1;
- }
- } else {
- ob_start();
- phpinfo(INFO_MODULES);
- $phpinfo = ob_get_contents();
- ob_end_clean();
- $phpinfo = explode("\n", $phpinfo);
- foreach ($phpinfo as $text) {
- $parts = explode('</td>', $text);
- foreach ($parts as $key => $val) {
- $parts[$key] = trim(strip_tags($val));
- }
- if ($parts[0] == 'GD Version') {
- if (substr_count($parts[1], '2.0')) {
- $parts[1] = '2.0';
- }
- $gdversion = intval($parts[1]);
- }
- }
- }
- return $gdversion; // 1, 2 or 0
- }
- /**
- * Not used any more, the account lockout handling is now
- * part of authenticate_user_login().
- * @deprecated
- */
- function update_login_count() {
- // TODO: delete function in Moodle 2.6
- debugging('update_login_count() is deprecated, all calls need to be removed');
- }
- /**
- * Not used any more, replaced by proper account lockout.
- * @deprecated
- */
- function reset_login_count() {
- // TODO: delete function in Moodle 2.6
- debugging('reset_login_count() is deprecated, all calls need to be removed');
- }
- /**
- * Unsupported session id rewriting.
- * @deprecated
- * @param string $buffer
- */
- function sid_ob_rewrite($buffer) {
- throw new coding_exception('$CFG->usesid support was removed completely and can not be used.');
- }
- /**
- * Insert or update log display entry. Entry may already exist.
- * $module, $action must be unique
- * @deprecated
- *
- * @param string $module
- * @param string $action
- * @param string $mtable
- * @param string $field
- * @return void
- *
- */
- function update_log_display_entry($module, $action, $mtable, $field) {
- global $DB;
- debugging('The update_log_display_entry() is deprecated, please use db/log.php description file instead.');
- }
- /**
- * Given some text in HTML format, this function will pass it
- * through any filters that have been configured for this context.
- *
- * @deprecated use the text formatting in a standard way instead,
- * this was abused mostly for embedding of attachments
- *
- * @param string $text The text to be passed through format filters
- * @param int $courseid The current course.
- * @return string the filtered string.
- */
- function filter_text($text, $courseid = NULL) {
- global $CFG, $COURSE;
- if (!$courseid) {
- $courseid = $COURSE->id;
- }
- if (!$context = context_course::instance($courseid, IGNORE_MISSING)) {
- return $text;
- }
- return filter_manager::instance()->filter_text($text, $context);
- }
- /**
- * This function indicates that current page requires the https
- * when $CFG->loginhttps enabled.
- *
- * By using this function properly, we can ensure 100% https-ized pages
- * at our entire discretion (login, forgot_password, change_password)
- * @deprecated use $PAGE->https_required() instead
- */
- function httpsrequired() {
- global $PAGE;
- $PAGE->https_required();
- }
- /**
- * Given a physical path to a file, returns the URL through which it can be reached in Moodle.
- *
- * @deprecated use moodle_url factory methods instead
- *
- * @param string $path Physical path to a file
- * @param array $options associative array of GET variables to append to the URL
- * @param string $type (questionfile|rssfile|httpscoursefile|coursefile)
- * @return string URL to file
- */
- function get_file_url($path, $options=null, $type='coursefile') {
- global $CFG;
- $path = str_replace('//', '/', $path);
- $path = trim($path, '/'); // no leading and trailing slashes
- // type of file
- switch ($type) {
- case 'questionfile':
- $url = $CFG->wwwroot."/question/exportfile.php";
- break;
- case 'rssfile':
- $url = $CFG->wwwroot."/rss/file.php";
- break;
- case 'httpscoursefile':
- $url = $CFG->httpswwwroot."/file.php";
- break;
- case 'coursefile':
- default:
- $url = $CFG->wwwroot."/file.php";
- }
- if ($CFG->slasharguments) {
- $parts = explode('/', $path);
- foreach ($parts as $key => $part) {
- /// anchor dash character should not be encoded
- $subparts = explode('#', $part);
- $subparts = array_map('rawurlencode', $subparts);
- $parts[$key] = implode('#', $subparts);
- }
- $path = implode('/', $parts);
- $ffurl = $url.'/'.$path;
- $separator = '?';
- } else {
- $path = rawurlencode('/'.$path);
- $ffurl = $url.'?file='.$path;
- $separator = '&';
- }
- if ($options) {
- foreach ($options as $name=>$value) {
- $ffurl = $ffurl.$separator.$name.'='.$value;
- $separator = '&';
- }
- }
- return $ffurl;
- }
- /**
- * If there has been an error uploading a file, print the appropriate error message
- * Numerical constants used as constant definitions not added until PHP version 4.2.0
- * @deprecated removed - use new file api
- */
- function print_file_upload_error($filearray = '', $returnerror = false) {
- throw new coding_exception('print_file_upload_error() can not be used any more, please use new file API');
- }
- /**
- * Handy function for resolving file conflicts
- * @deprecated removed - use new file api
- */
- function resolve_filename_collisions($destination,$files,$format='%s_%d.%s') {
- throw new coding_exception('resolve_filename_collisions() can not be used any more, please use new file API');
- }
- /**
- * Checks a file name for any conflicts
- * @deprecated removed - use new file api
- */
- function check_potential_filename($destination,$filename,$files) {
- throw new coding_exception('check_potential_filename() can not be used any more, please use new file API');
- }
- /**
- * This function prints out a number of upload form elements.
- * @deprecated removed - use new file api
- */
- function upload_print_form_fragment($numfiles=1, $names=null, $descriptions=null, $uselabels=false, $labelnames=null, $coursebytes=0, $modbytes=0, $return=false) {
- throw new coding_exception('upload_print_form_fragment() can not be used any more, please use new file API');
- }
- /**
- * Return the authentication plugin title
- *
- * @param string $authtype plugin type
- * @return string
- */
- function auth_get_plugin_title($authtype) {
- debugging('Function auth_get_plugin_title() is deprecated, please use standard get_string("pluginname", "auth_'.$authtype.'")!');
- return get_string('pluginname', "auth_{$authtype}");
- }
- /**
- * Enrol someone without using the default role in a course
- * @deprecated
- */
- function enrol_into_course($course, $user, $enrol) {
- error('Function enrol_into_course() was removed, please use new enrol plugins instead!');
- }
- /**
- * Returns a role object that is the default role for new enrolments in a given course
- *
- * @deprecated
- * @param object $course
- * @return object returns a role or NULL if none set
- */
- function get_default_course_role($course) {
- debugging('Function get_default_course_role() is deprecated, please use individual enrol plugin settings instead!');
- $student = get_archetype_roles('student');
- $student = reset($student);
- return $student;
- }
- /**
- * Extremely slow enrolled courses query.
- * @deprecated
- */
- function get_my_courses($userid, $sort='visible DESC,sortorder ASC', $fields=NULL, $doanything=false,$limit=0) {
- error('Function get_my_courses() was removed, please use new enrol_get_my_courses() or enrol_get_users_courses()!');
- }
- /**
- * Was returning list of translations, use new string_manager instead
- *
- * @deprecated
- * @param bool $refreshcache force refreshing of lang cache
- * @param bool $returnall ignore langlist, return all languages available
- * @return array An associative array with contents in the form of LanguageCode => LanguageName
- */
- function get_list_of_languages($refreshcache=false, $returnall=false) {
- debugging('get_list_of_languages() is deprecated, please use get_string_manager()->get_list_of_translations() instead.');
- if ($refreshcache) {
- get_string_manager()->reset_caches();
- }
- return get_string_manager()->get_list_of_translations($returnall);
- }
- /**
- * Returns a list of currencies in the current language
- * @deprecated
- * @return array
- */
- function get_list_of_currencies() {
- debugging('get_list_of_currencies() is deprecated, please use get_string_manager()->get_list_of_currencies() instead.');
- return get_string_manager()->get_list_of_currencies();
- }
- /**
- * Returns a list of all enabled country names in the current translation
- * @deprecated
- * @return array two-letter country code => translated name.
- */
- function get_list_of_countries() {
- debugging('get_list_of_countries() is deprecated, please use get_string_manager()->get_list_of_countries() instead.');
- return get_string_manager()->get_list_of_countries(false);
- }
- /**
- * @deprecated
- */
- function isteacher() {
- error('Function isteacher() was removed, please use capabilities instead!');
- }
- /**
- * @deprecated
- */
- function isteacherinanycourse() {
- throw new coding_Exception('Function isteacherinanycourse() was removed, please use capabilities instead!');
- }
- /**
- * @deprecated
- */
- function get_guest() {
- throw new coding_Exception('Function get_guest() was removed, please use capabilities instead!');
- }
- /**
- * @deprecated
- */
- function isguest() {
- throw new coding_Exception('Function isguest() was removed, please use capabilities instead!');
- }
- /**
- * @deprecated
- */
- function get_teacher() {
- throw new coding_Exception('Function get_teacher() was removed, please use capabilities instead!');
- }
- /**
- * Return all course participant for a given course
- *
- * @deprecated
- * @param integer $courseid
- * @return array of user
- */
- function get_course_participants($courseid) {
- return get_enrolled_users(context_course::instance($courseid));
- }
- /**
- * Return true if the user is a participant for a given course
- *
- * @deprecated
- * @param integer $userid
- * @param integer $courseid
- * @return boolean
- */
- function is_course_participant($userid, $courseid) {
- return is_enrolled(context_course::instance($courseid), $userid);
- }
- /**
- * Searches logs to find all enrolments since a certain date
- *
- * used to print recent activity
- *
- * @todo MDL-36993 this function is still used in block_recent_activity, deprecate properly
- * @global object
- * @uses CONTEXT_COURSE
- * @param int $courseid The course in question.
- * @param int $timestart The date to check forward of
- * @return object|false {@link $USER} records or false if error.
- */
- function get_recent_enrolments($courseid, $timestart) {
- global $DB;
- $context = context_course::instance($courseid);
- $sql = "SELECT u.id, u.firstname, u.lastname, MAX(l.time)
- FROM {user} u, {role_assignments} ra, {log} l
- WHERE l.time > ?
- AND l.course = ?
- AND l.module = 'course'
- AND l.action = 'enrol'
- AND ".$DB->sql_cast_char2int('l.info')." = u.id
- AND u.id = ra.userid
- AND ra.contextid ".get_related_contexts_string($context)."
- GROUP BY u.id, u.firstname, u.lastname
- ORDER BY MAX(l.time) ASC";
- $params = array($timestart, $courseid);
- return $DB->get_records_sql($sql, $params);
- }
- /**
- * Turn the ctx* fields in an objectlike record into a context subobject
- * This allows us to SELECT from major tables JOINing with
- * context at no cost, saving a ton of context lookups...
- *
- * Use context_instance_preload() instead.
- *
- * @deprecated since 2.0
- * @param object $rec
- * @return object
- */
- function make_context_subobj($rec) {
- throw new coding_Exception('make_context_subobj() was removed, use new context preloading');
- }
- /**
- * Do some basic, quick checks to see whether $rec->context looks like a valid context object.
- *
- * Use context_instance_preload() instead.
- *
- * @deprecated since 2.0
- * @param object $rec a think that has a context, for example a course,
- * course category, course modules, etc.
- * @param int $contextlevel the type of thing $rec is, one of the CONTEXT_... constants.
- * @return bool whether $rec->context looks like the correct context object
- * for this thing.
- */
- function is_context_subobj_valid($rec, $contextlevel) {
- throw new coding_Exception('is_context_subobj_valid() was removed, use new context preloading');
- }
- /**
- * Ensure that $rec->context is present and correct before you continue
- *
- * When you have a record (for example a $category, $course, $user or $cm that may,
- * or may not, have come from a place that does make_context_subobj, you can use
- * this method to ensure that $rec->context is present and correct before you continue.
- *
- * Use context_instance_preload() instead.
- *
- * @deprecated since 2.0
- * @param object $rec a thing that has an associated context.
- * @param integer $contextlevel the type of thing $rec is, one of the CONTEXT_... constants.
- */
- function ensure_context_subobj_present(&$rec, $contextlevel) {
- throw new coding_Exception('ensure_context_subobj_present() was removed, use new context preloading');
- }
- ########### FROM weblib.php ##########################################################################
- /**
- * Print a message in a standard themed box.
- * This old function used to implement boxes using tables. Now it uses a DIV, but the old
- * parameters remain. If possible, $align, $width and $color should not be defined at all.
- * Preferably just use print_box() in weblib.php
- *
- * @deprecated
- * @param string $message The message to display
- * @param string $align alignment of the box, not the text (default center, left, right).
- * @param string $width width of the box, including units %, for example '100%'.
- * @param string $color background colour of the box, for example '#eee'.
- * @param int $padding padding in pixels, specified without units.
- * @param string $class space-separated class names.
- * @param string $id space-separated id names.
- * @param boolean $return return as string or just print it
- * @return string|void Depending on $return
- */
- function print_simple_box($message, $align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
- $output = '';
- $output .= print_simple_box_start($align, $width, $color, $padding, $class, $id, true);
- $output .= $message;
- $output .= print_simple_box_end(true);
- if ($return) {
- return $output;
- } else {
- echo $output;
- }
- }
- /**
- * This old function used to implement boxes using tables. Now it uses a DIV, but the old
- * parameters remain. If possible, $align, $width and $color should not be defined at all.
- * Even better, please use print_box_start() in weblib.php
- *
- * @param string $align alignment of the box, not the text (default center, left, right). DEPRECATED
- * @param string $width width of the box, including % units, for example '100%'. DEPRECATED
- * @param string $color background colour of the box, for example '#eee'. DEPRECATED
- * @param int $padding padding in pixels, specified without units. OBSOLETE
- * @param string $class space-separated class names.
- * @param string $id space-separated id names.
- * @param boolean $return return as string or just print it
- * @return string|void Depending on $return
- */
- function print_simple_box_start($align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
- debugging('print_simple_box(_start/_end) is deprecated. Please use $OUTPUT->box(_start/_end) instead', DEBUG_DEVELOPER);
- $output = '';
- $divclasses = 'box '.$class.' '.$class.'content';
- $divstyles = '';
- if ($align) {
- $divclasses .= ' boxalign'.$align; // Implement alignment using a class
- }
- if ($width) { // Hopefully we can eliminate these in calls to this function (inline styles are bad)
- if (substr($width, -1, 1) == '%') { // Width is a % value
- $width = (int) substr($width, 0, -1); // Extract just the number
- if ($width < 40) {
- $divclasses .= ' boxwidthnarrow'; // Approx 30% depending on theme
- } else if ($width > 60) {
- $divclasses .= ' boxwidthwide'; // Approx 80% depending on theme
- } else {
- $divclasses .= ' boxwidthnormal'; // Approx 50% depending on theme
- }
- } else {
- $divstyles .= ' width:'.$width.';'; // Last resort
- }
- }
- if ($color) { // Hopefully we can eliminate these in calls to this function (inline styles are bad)
- $divstyles .= ' background:'.$color.';';
- }
- if ($divstyles) {
- $divstyles = ' style="'.$divstyles.'"';
- }
- if ($id) {
- $id = ' id="'.$id.'"';
- }
- $output .= '<div'.$id.$divstyles.' class="'.$divclasses.'">';
- if ($return) {
- return $output;
- } else {
- echo $output;
- }
- }
- /**
- * Print the end portion of a standard themed box.
- * Preferably just use print_box_end() in weblib.php
- *
- * @param boolean $return return as string or just print it
- * @return string|void Depending on $return
- */
- function print_simple_box_end($return=false) {
- $output = '</div>';
- if ($return) {
- return $output;
- } else {
- echo $output;
- }
- }
- /**
- * Given some text this function converted any URLs it found into HTML links
- *
- * This core function has been replaced with filter_urltolink since Moodle 2.0
- *
- * @param string $text Passed in by reference. The string to be searched for urls.
- */
- function convert_urls_into_links($text) {
- debugging('convert_urls_into_links() has been deprecated and replaced by a new filter');
- }
- /**
- * Used to be called from help.php to inject a list of smilies into the
- * emoticons help file.
- *
- * @return string HTML
- */
- function get_emoticons_list_for_help_file() {
- debugging('get_emoticons_list_for_help_file() has been deprecated, see the new emoticon_manager API');
- return '';
- }
- /**
- * Was used to replace all known smileys in the text with image equivalents
- *
- * This core function has been replaced with filter_emoticon since Moodle 2.0
- */
- function replace_smilies(&$text) {
- debugging('replace_smilies() has been deprecated and replaced with the new filter_emoticon');
- }
- /**
- * deprecated - use clean_param($string, PARAM_FILE); instead
- * Check for bad characters ?
- *
- * @todo Finish documenting this function - more detail needed in description as well as details on arguments
- *
- * @param string $string ?
- * @param int $allowdots ?
- * @return bool
- */
- function detect_munged_arguments($string, $allowdots=1) {
- if (substr_count($string, '..') > $allowdots) { // Sometimes we allow dots in references
- return true;
- }
- if (preg_match('/[\|\`]/', $string)) { // check for other bad characters
- return true;
- }
- if (empty($string) or $string == '/') {
- return true;
- }
- return false;
- }
- /**
- * Unzip one zip file to a destination dir
- * Both parameters must be FULL paths
- * If destination isn't specified, it will be the
- * SAME directory where the zip file resides.
- *
- * @global object
- * @param string $zipfile The zip file to unzip
- * @param string $destination The location to unzip to
- * @param bool $showstatus_ignored Unused
- */
- function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) {
- global $CFG;
- //Extract everything from zipfile
- $path_parts = pathinfo(cleardoubleslashes($zipfile));
- $zippath = $path_parts["dirname"]; //The path of the zip file
- $zipfilename = $path_parts["basename"]; //The name of the zip file
- $extension = $path_parts["extension"]; //The extension of the file
- //If no file, error
- if (empty($zipfilename)) {
- return false;
- }
- //If no extension, error
- if (empty($extension)) {
- return false;
- }
- //Clear $zipfile
- $zipfile = cleardoubleslashes($zipfile);
- //Check zipfile exists
- if (!file_exists($zipfile)) {
- return false;
- }
- //If no destination, passed let's go with the same directory
- if (empty($destination)) {
- $destination = $zippath;
- }
- //Clear $destination
- $destpath = rtrim(cleardoubleslashes($destination), "/");
- //Check destination path exists
- if (!is_dir($destpath)) {
- return false;
- }
- $packer = get_file_packer('application/zip');
- $result = $packer->extract_to_pathname($zipfile, $destpath);
- if ($result === false) {
- return false;
- }
- foreach ($result as $status) {
- if ($status !== true) {
- return false;
- }
- }
- return true;
- }
- /**
- * Zip an array of files/dirs to a destination zip file
- * Both parameters must be FULL paths to the files/dirs
- *
- * @global object
- * @param array $originalfiles Files to zip
- * @param string $destination The destination path
- * @return bool Outcome
- */
- function zip_files ($originalfiles, $destination) {
- global $CFG;
- //Extract everything from destination
- $path_parts = pathinfo(cleardoubleslashes($destination));
- $destpath = $path_parts["dirname"]; //The path of the zip file
- $destfilename = $path_parts["basename"]; //The name of the zip file
- $extension = $path_parts["extension"]; //The extension of the file
- //If no file, error
- if (empty($destfilename)) {
- return false;
- }
- //If no extension, add it
- if (empty($extension)) {
- $extension = 'zip';
- $destfilename = $destfilename.'.'.$extension;
- }
- //Check destination path exists
- if (!is_dir($destpath)) {
- return false;
- }
- //Check destination path is writable. TODO!!
- //Clean destination filename
- $destfilename = clean_filename($destfilename);
- //Now check and prepare every file
- $files = array();
- $origpath = NULL;
- foreach ($originalfiles as $file) { //Iterate over each file
- //Check for every file
- $tempfile = cleardoubleslashes($file); // no doubleslashes!
- //Calculate the base path for all files if it isn't set
- if ($origpath === NULL) {
- $origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/");
- }
- //See if the file is readable
- if (!is_readable($tempfile)) { //Is readable
- continue;
- }
- //See if the file/dir is in the same directory than the rest
- if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) {
- continue;
- }
- //Add the file to the array
- $files[] = $tempfile;
- }
- $zipfiles = array();
- $start = strlen($origpath)+1;
- foreach($files as $file) {
- $zipfiles[substr($file, $start)] = $file;
- }
- $packer = get_file_packer('application/zip');
- return $packer->archive_to_pathname($zipfiles, $destpath . '/' . $destfilename);
- }
- /////////////////////////////////////////////////////////////
- /// Old functions not used anymore - candidates for removal
- /////////////////////////////////////////////////////////////
- /** various deprecated groups function **/
- /**
- * Get the IDs for the user's groups in the given course.
- *
- * @global object
- * @param int $courseid The course being examined - the 'course' table id field.
- * @return array|bool An _array_ of groupids, or false
- * (Was return $groupids[0] - consequences!)
- */
- function mygroupid($courseid) {
- global $USER;
- if ($groups = groups_get_all_groups($courseid, $USER->id)) {
- return array_keys($groups);
- } else {
- return false;
- }
- }
- /**
- * Returns the current group mode for a given course or activity module
- *
- * Could be false, SEPARATEGROUPS or VISIBLEGROUPS (<-- Martin)
- *
- * @param object $course Course Object
- * @param object $cm Course Manager Object
- * @return mixed $course->groupmode
- */
- function groupmode($course, $cm=null) {
- if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
- return $cm->groupmode;
- }
- return $course->groupmode;
- }
- /**
- * Sets the current group in the session variable
- * When $SESSION->currentgroup[$courseid] is set to 0 it means, show all groups.
- * Sets currentgroup[$courseid] in the session variable appropriately.
- * Does not do any permission checking.
- *
- * @global object
- * @param int $courseid The course being examined - relates to id field in
- * 'course' table.
- * @param int $groupid The group being examined.
- * @return int Current group id which was set by this function
- */
- function set_current_group($courseid, $groupid) {
- global $SESSION;
- return $SESSION->currentgroup[$courseid] = $groupid;
- }
- /**
- * Gets the current group - either from the session variable or from the database.
- *
- * @global object
- * @param int $courseid The course being examined - relates to id field in
- * 'course' table.
- * @param bool $full If true, the return value is a full record object.
- * If false, just the id of the record.
- * @return int|bool
- */
- function get_current_group($courseid, $full = false) {
- global $SESSION;
- if (isset($SESSION->currentgroup[$courseid])) {
- if ($full) {
- return groups_get_group($SESSION->currentgroup[$courseid]);
- } else {
- return $SESSION->currentgroup[$courseid];
- }
- }
- $mygroupid = mygroupid($courseid);
- if (is_array($mygroupid)) {
- $mygroupid = array_shift($mygroupid);
- set_current_group($courseid, $mygroupid);
- if ($full) {
- return groups_get_group($mygroupid);
- } else {
- return $mygroupid;
- }
- }
- if ($full) {
- return false;
- } else {
- return 0;
- }
- }
- /**
- * Inndicates fatal error. This function was originally printing the
- * error message directly, since 2.0 it is throwing exception instead.
- * The error printing is handled in default exception handler.
- *
- * Old method, don't call directly in new code - use print_error instead.
- *
- * @param string $message The message to display to the user about the error.
- * @param string $link The url where the user will be prompted to continue. If no url is provided the user will be directed to the site index page.
- * @return void, always throws moodle_exception
- */
- function error($message, $link='') {
- throw new moodle_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a deprecated function, please call print_error() instead of error()');
- }
- //////////////////////////
- /// removed functions ////
- //////////////////////////
- /**
- * @deprecated
- * @param mixed $name
- * @param mixed $editorhidebuttons
- * @param mixed $id
- * @return void Throws an error and does nothing
- */
- function use_html_editor($name='', $editorhidebuttons='', $id='') {
- error('use_html_editor() not available anymore');
- }
- /**
- * The old method that was used to include JavaScript libraries.
- * Please use $PAGE->requires->js_module() instead.
- *
- * @param mixed $lib The library or libraries to load (a string or array of strings)
- * There are three way to specify the library:
- * 1. a shorname like 'yui_yahoo'. This translates into a call to $PAGE->requires->yui2_lib('yahoo');
- * 2. the path to the library relative to wwwroot, for example 'lib/javascript-static.js'
- * 3. (legacy) a full URL like $CFG->wwwroot . '/lib/javascript-static.js'.
- * 2. and 3. lead to a call $PAGE->requires->js('/lib/javascript-static.js').
- */
- function require_js($lib) {
- throw new coding_exception('require_js() was removed, use new JS api');
- }
- /**
- * Makes an upload directory for a particular module.
- *
- * This function has been deprecated by the file API changes in Moodle 2.0.
- *
- * @deprecated
- * @param int $courseid The id of the course in question - maps to id field of 'course' table.
- * @return string|false Returns full path to directory if successful, false if not
- */
- function make_mod_upload_directory($courseid) {
- throw new coding_exception('make_mod_upload_directory has been deprecated by the file API changes in Moodle 2.0.');
- }
- /**
- * Used to be used for setting up the theme. No longer used by core code, and
- * should not have been used elsewhere.
- *
- * The theme is now automatically initialised before it is first used. If you really need
- * to force this to happen, just reference $PAGE->theme.
- *
- * To force a particular theme on a particular page, you can use $PAGE->force_theme(...).
- * However, I can't think of any valid reason to do that outside the theme selector UI.
- *
- * @deprecated
- * @param string $theme The theme to use defaults to current theme
- * @param array $params An array of parameters to use
- */
- function theme_setup($theme = '', $params=NULL) {
- throw new coding_exception('The function theme_setup is no longer required, and should no longer be used. ' .
- 'The current theme gets initialised automatically before it is first used.');
- }
- /**
- * @deprecated use $PAGE->theme->name instead.
- * @return string the name of the current theme.
- */
- function current_theme() {
- global $PAGE;
- // TODO, uncomment this once we have eliminated all references to current_theme in core code.
- // debugging('current_theme is deprecated, use $PAGE->theme->name instead', DEBUG_DEVELOPER);
- return $PAGE->theme->name;
- }
- /**
- * Prints some red text using echo
- *
- * @deprecated
- * @param string $error The text to be displayed in red
- */
- function formerr($error) {
- debugging('formerr() has been deprecated. Please change your code to use $OUTPUT->error_text($string).');
- global $OUTPUT;
- echo $OUTPUT->error_text($error);
- }
- /**
- * Return the markup for the destination of the 'Skip to main content' links.
- * Accessibility improvement for keyboard-only users.
- *
- * Used in course formats, /index.php and /course/index.php
- *
- * @deprecated use $OUTPUT->skip_link_target() in instead.
- * @return string HTML element.
- */
- function skip_main_destination() {
- global $OUTPUT;
- return $OUTPUT->skip_link_target();
- }
- /**
- * Prints a string in a specified size (retained for backward compatibility)
- *
- * @deprecated
- * @param string $text The text to be displayed
- * @param int $size The size to set the font for text display.
- * @param bool $return If set to true output is returned rather than echoed Default false
- * @return string|void String if return is true
- */
- function print_headline($text, $size=2, $return=false) {
- global $OUTPUT;
- debugging('print_headline() has been deprecated. Please change your code to use $OUTPUT->heading().');
- $output = $OUTPUT->heading($text, $size);
- if ($return) {
- return $output;
- } else {
- echo $output;
- }
- }
- /**
- * Prints text in a format for use in headings.
- *
- * @deprecated
- * @param string $text The text to be displayed
- * @param string $deprecated No longer used. (Use to do alignment.)
- * @param int $size The size to set the font for text display.
- * @param string $class
- * @param bool $return If set to true output is returned rather than echoed, default false
- * @param string $id The id to use in the element
- * @return string|void String if return=true nothing otherwise
- */
- function print_heading($text, $deprecated = '', $size = 2, $class = 'main', $return = false, $id = '') {
- global $OUTPUT;
- debugging('print_heading() has been deprecated. Please change your code to use $OUTPUT->heading().');
- if (!empty($deprecated)) {
- debugging('Use of deprecated align attribute of print_heading. ' .
- 'Please do not specify styling in PHP code like that.', DEBUG_DEVELOPER);
- }
- $output = $OUTPUT->heading($text, $size, $class, $id);
- if ($return) {
- return $output;
- } else {
- echo $output;
- }
- }
- /**
- * Output a standard heading block
- *
- * @deprecated
- * @param string $heading The text to write into the heading
- * @param string $class An additional Class Attr to use for the heading
- * @param bool $return If set to true output is returned rather than echoed, default false
- * @return string|void HTML String if return=true nothing otherwise
- */
- function print_heading_block($heading, $class='', $return=false) {
- global $OUTPUT;
- debugging('print_heading_with_block() has been deprecated. Please change your code to use $OUTPUT->heading().');
- $output = $OUTPUT->heading($heading, 2, 'headingblock header ' . renderer_base::prepare_classes($class));
- if ($return) {
- return $output;
- } else {
- echo $output;
- }
- }
- /**
- * Print a message in a standard themed box.
- * Replaces print_simple_box (see deprecatedlib.php)
- *
- * @deprecated
- * @param string $message, the content of the box
- * @param string $classes, space-separated class names.
- * @param string $ids
- * @param boolean $return, return as string or just print it
- * @return string|void mixed string or void
- */
- function print_box($message, $classes='generalbox', $ids='', $return=false) {
- global $OUTPUT;
- debugging('print_box() has been deprecated. Please change your code to use $OUTPUT->box().');
- $output = $OUTPUT->box($message, $classes, $ids);
- if ($return) {
- return $output;
- } else {
- echo $output;
- }
- }
- /**
- * Starts a box using divs
- * Replaces print_simple_box_start (see deprecatedlib.php)
- *
- * @deprecated
- * @param string $classes, space-separated class names.
- * @param string $ids
- * @param boolean $return, return as string or just print it
- * @return string|void string or void
- */
- function print_box_start($classes='generalbox', $ids='', $return=false) {
- global $OUTPUT;
- debugging('print_box_start() has been deprecated. Please change your code to use $OUTPUT->box_start().');
- $output = $OUTPUT->box_start($classes, $ids);
- if ($return) {
- return $output;
- } else {
- echo $output;
- }
- }
- /**
- * Simple function to end a box (see above)
- * Replaces print_simple_box_end (see deprecatedlib.php)
- *
- * @deprecated
- * @param boolean $return, return as string or just print it
- * @return string|void Depending on value of return
- */
- function print_box_end($return=false) {
- global $OUTPUT;
- debugging('print_box_end() has been deprecated. Please change your code to use $OUTPUT->box_end().');
- $output = $OUTPUT->box_end();
- if ($return) {
- return $output;
- } else {
- echo $output;
- }
- }
- /**
- * Print a message in a standard themed container.
- *
- * @deprecated
- * @param string $message, the content of the container
- * @param boolean $clearfix clear both sides
- * @param string $classes, space-separated class names.
- * @param string $idbase
- * @param boolean $return, return as string or just print it
- * @return string|void Depending on value of $return
- */
- function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) {
- global $OUTPUT;
- if ($clearfix) {
- $classes .= ' clearfix';
- }
- $output = $OUTPUT->container($message, $classes, $idbase);
- if ($return) {
- return $output;
- } else {
- echo $output;
- }
- }
- /**
- * Starts a container using divs
- *
- * @deprecated
- * @param boolean $clearfix clear both sides
- * @param string $classes, space-separated class names.
- * @param string $idbase
- * @param boolean $return, return as string or just print it
- * @return string|void Based on value of $return
- */
- function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) {
- global $OUTPUT;
- if ($clearfix) {
- $classes .= ' clearfix';
- }
- $output = $OUTPUT->container_start($classes, $idbase);
- if ($return) {
- return $output;
- } else {
- echo $output;
- }
- }
- /**
- * Deprecated, now handled automatically in themes
- */
- function check_theme_arrows() {
- debugging('check_theme_arrows() has been deprecated, do not use it anymore, it is now automatic.');
- }
- /**
- * Simple function to end a container (see above)
- *
- * @deprecated
- * @param boolean $return, return as string or just print it
- * @return string|void Based on $return
- */
- function print_container_end($return=false) {
- global $OUTPUT;
- $output = $OUTPUT->container_end();
- if ($return) {
- return $output;
- } else {
- echo $output;
- }
- }
- /**
- * Print a bold message in an optional color.
- *
- * @deprecated use $OUTPUT->notification instead.
- * @param string $message The message to print out
- * @param string $style Optional style to display message text in
- * @param string $align Alignment option
- * @param bool $return whether to return an output string or echo now
- * @return string|bool Depending on $result
- */
- function notify($message, $classes = 'notifyproblem', $align = 'center', $return = false) {
- global $OUTPUT;
- if ($classes == 'green') {
- debugging('Use of deprecated class name "green" in notify. Please change to "notifysuccess".', DEBUG_DEVELOPER);
- $classes = 'notifysuccess'; // Backward compatible with old color system
- }
- $output = $OUTPUT->notification($message, $classes);
- if ($return) {
- return $output;
- } else {
- echo $output;
- }
- }
- /**
- * Print a continue button that goes to a particular URL.
- *
- * @deprecated since Moodle 2.0
- *
- * @param string $link The url to create a link to.
- * @param bool $return If set to true output is returned rather than echoed, default false
- * @return string|void HTML String if return=true nothing otherwise
- */
- function print_continue($link, $return = false) {
- global $CFG, $OUTPUT;
- if ($link == '') {
- if (!empty($_SERVER['HTTP_REFERER'])) {
- $link = $_SERVER['HTTP_REFERER'];
- $link = str_replace('&', '&', $link); // make it valid XHTML
- } else {
- $link = $CFG->wwwroot .'/';
- }
- }
- $output = $OUTPUT->continue_button($link);
- if ($return) {
- return $output;
- } else {
- echo $output;
- }
- }
- /**
- * Print a standard header
- *
- * @param string $title Appears at the top of the window
- * @param string $heading Appears at the top of the page
- * @param string $navigation Array of $navlinks arrays (keys: name, link, type) for use as breadcrumbs links
- * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
- * @param string $meta Meta tags to be added to the header
- * @param boolean $cache Should this page be cacheable?
- * @param string $button HTML code for a button (usually for module editing)
- * @param string $menu HTML code for a popup menu
- * @param boolean $usexml use XML for this page
- * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
- * @param bool $return If true, return the visible elements of the header instead of echoing them.
- * @return string|void If return=true then string else void
- */
- function print_header($title='', $heading='', $navigation='', $focus='',
- $meta='', $cache=true, $button=' ', $menu=null,
- $usexml=false, $bodytags='', $return=false) {
- global $PAGE, $OUTPUT;
- $PAGE->set_title($title);
- $PAGE->set_heading($heading);
- $PAGE->set_cacheable($cache);
- if ($button == '') {
- $button = ' ';
- }
- $PAGE->set_button($button);
- $PAGE->set_headingmenu($menu);
- // TODO $menu
- if ($meta) {
- throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
- 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
- }
- if ($usexml) {
- throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
- }
- if ($bodytags) {
- throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
- }
- $output = $OUTPUT->header();
- if ($return) {
- return $output;
- } else {
- echo $output;
- }
- }
- /**
- * This version of print_header is simpler because the course name does not have to be
- * provided explicitly in the strings. It can be used on the site page as in courses
- * Eventually all print_header could be replaced by print_header_simple
- *
- * @deprecated since Moodle 2.0
- * @param string $title Appears at the top of the window
- * @param string $heading Appears at the top of the page
- * @param string $navigation Premade navigation string (for use as breadcrumbs links)
- * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
- * @param string $meta Meta tags to be added to the header
- * @param boolean $cache Should this page be cacheable?
- * @param string $button HTML code for a button (usually for module editing)
- * @param string $menu HTML code for a popup menu
- * @param boolean $usexml use XML for this page
- * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
- * @param bool $return If true, return the visible elements of the header instead of echoing them.
- * @return string|void If $return=true the return string else nothing
- */
- function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='',
- $cache=true, $button=' ', $menu='', $usexml=false, $bodytags='', $return=false) {
- global $COURSE, $CFG, $PAGE, $OUTPUT;
- if ($meta) {
- throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
- 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
- }
- if ($usexml) {
- throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
- }
- if ($bodytags) {
- throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
- }
- $PAGE->set_title($title);
- $PAGE->set_heading($heading);
- $PAGE->set_cacheable(true);
- $PAGE->set_button($button);
- $output = $OUTPUT->header();
- if ($return) {
- return $output;
- } else {
- echo $output;
- }
- }
- function print_footer($course = NULL, $usercourse = NULL, $return = false) {
- global $PAGE, $OUTPUT;
- debugging('print_footer() has been deprecated. Please change your code to use $OUTPUT->footer().');
- // TODO check arguments.
- if (is_string($course)) {
- debugging("Magic values like 'home', 'empty' passed to print_footer no longer have any effect. " .
- 'To achieve a similar effect, call $PAGE->set_pagelayout before you call print_header.', DEBUG_DEVELOPER);
- } else if (!empty($course->id) && $course->id != $PAGE->course->id) {
- throw new coding_exception('The $course object you passed to print_footer does not match $PAGE->course.');
- }
- if (!is_null($usercourse)) {
- debugging('The second parameter ($usercourse) to print_footer is no longer supported. ' .
- '(I did not think it was being used anywhere.)', DEBUG_DEVELOPER);
- }
- $output = $OUTPUT->footer();
- if ($return) {
- return $output;
- } else {
- echo $output;
- }
- }
- /**
- * Returns text to be displayed to the user which reflects their login status
- *
- * @global object
- * @global object
- * @global object
- * @global object
- * @uses CONTEXT_COURSE
- * @param course $course {@link $COURSE} object containing course information
- * @param user $user {@link $USER} object containing user information
- * @return string HTML
- */
- function user_login_string($course='ignored', $user='ignored') {
- debugging('user_login_info() has been deprecated. User login info is now handled via themes layouts.');
- return '';
- }
- /**
- * Prints a nice side block with an optional header. The content can either
- * be a block of HTML or a list of text with optional icons.
- *
- * @todo Finish documenting this function. Show example of various attributes, etc.
- *
- * @static int $block_id Increments for each call to the function
- * @param string $heading HTML for the heading. Can include full HTML or just
- * plain text - plain text will automatically be enclosed in the appropriate
- * heading tags.
- * @param string $content HTML for the content
- * @param array $list an alternative to $content, it you want a list of things with optional icons.
- * @param array $icons optional icons for the things in $list.
- * @param string $footer Extra HTML content that gets output at the end, inside a <div class="footer">
- * @param array $attributes an array of attribute => value pairs that are put on the
- * outer div of this block. If there is a class attribute ' block' gets appended to it. If there isn't
- * already a class, class='block' is used.
- * @param string $title Plain text title, as embedded in the $heading.
- * @deprecated
- */
- function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') {
- global $OUTPUT;
- // We don't use $heading, becuse it often contains HTML that we don't want.
- // However, sometimes $title is not set, but $heading is.
- if (empty($title)) {
- $title = strip_tags($heading);
- }
- // Render list contents to HTML if required.
- if (empty($content) && $list) {
- $content = $OUTPUT->list_block_contents($icons, $list);
- }
- $bc = new block_contents();
- $bc->content = $content;
- $bc->footer = $footer;
- $bc->title = $title;
- if (isset($attributes['id'])) {
- $bc->id = $attributes['id'];
- unset($attributes['id']);
- }
- $bc->attributes = $attributes;
- echo $OUTPUT->block($bc, BLOCK_POS_LEFT); // POS LEFT may be wrong, but no way to get a better guess here.
- }
- /**
- * Starts a nice side block with an optional header.
- *
- * @todo Finish documenting this function
- *
- * @global object
- * @global object
- * @param string $heading HTML for the heading. Can include full HTML or just
- * plain text - plain text will automatically be enclosed in the appropriate
- * heading tags.
- * @param array $attributes HTML attributes to apply if possible
- * @deprecated
- */
- function print_side_block_start($heading='', $attributes = array()) {
- throw new coding_exception('print_side_block_start has been deprecated. Please change your code to use $OUTPUT->block().');
- }
- /**
- * Print table ending tags for a side block box.
- *
- * @global object
- * @global object
- * @param array $attributes HTML attributes to apply if possible [id]
- * @param string $title
- * @deprecated
- */
- function print_side_block_end($attributes = array(), $title='') {
- throw new coding_exception('print_side_block_end has been deprecated. Please change your code to use $OUTPUT->block().');
- }
- /**
- * This was used by old code to see whether a block region had anything in it,
- * and hence wether that region should be printed.
- *
- * We don't ever want old code to print blocks, so we now always return false.
- * The function only exists to avoid fatal errors in old code.
- *
- * @deprecated since Moodle 2.0. always returns false.
- *
- * @param object $blockmanager
- * @param string $region
- * @return bool
- */
- function blocks_have_content(&$blockmanager, $region) {
- debugging('The function blocks_have_content should no longer be used. Blocks are now printed by the theme.');
- return false;
- }
- /**
- * This was used by old code to print the blocks in a region.
- *
- * We don't ever want old code to print blocks, so this is now a no-op.
- * The function only exists to avoid fatal errors in old code.
- *
- * @deprecated since Moodle 2.0. does nothing.
- *
- * @param object $page
- * @param object $blockmanager
- * @param string $region
- */
- function blocks_print_group($page, $blockmanager, $region) {
- debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
- }
- /**
- * This used to be the old entry point for anyone that wants to use blocks.
- * Since we don't want people people dealing with blocks this way any more,
- * just return a suitable empty array.
- *
- * @deprecated since Moodle 2.0.
- *
- * @param object $page
- * @return array
- */
- function blocks_setup(&$page, $pinned = BLOCKS_PINNED_FALSE) {
- debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
- return array(BLOCK_POS_LEFT => array(),