/lib/deprecatedlib.php
PHP | 4708 lines | 3174 code | 320 blank | 1214 comment | 134 complexity | e83db44b6a623570d008321a8d2afa47 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, Apache-2.0, BSD-3-Clause, AGPL-3.0
Large files files are truncated, but you can click here to view the full 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();
- /**
- * Factory method that was returning moodle_session object.
- *
- * @deprecated since 2.6
- * @return \core\session\manager
- */
- function session_get_instance() {
- // Note: the new session manager includes all methods from the original session class.
- static $deprecatedinstance = null;
- debugging('session_get_instance() is deprecated, use \core\session\manager instead', DEBUG_DEVELOPER);
- if (!$deprecatedinstance) {
- $deprecatedinstance = new \core\session\manager();
- }
- return $deprecatedinstance;
- }
- /**
- * Returns true if legacy session used.
- *
- * @deprecated since 2.6
- * @return bool
- */
- function session_is_legacy() {
- debugging('session_is_legacy() is deprecated, do not use any more', DEBUG_DEVELOPER);
- return false;
- }
- /**
- * Terminates all sessions, auth hooks are not executed.
- * Useful in upgrade scripts.
- *
- * @deprecated since 2.6
- */
- function session_kill_all() {
- debugging('session_kill_all() is deprecated, use \core\session\manager::kill_all_sessions() instead', DEBUG_DEVELOPER);
- \core\session\manager::kill_all_sessions();
- }
- /**
- * Mark session as accessed, prevents timeouts.
- *
- * @deprecated since 2.6
- * @param string $sid
- */
- function session_touch($sid) {
- debugging('session_touch() is deprecated, use \core\session\manager::touch_session() instead', DEBUG_DEVELOPER);
- \core\session\manager::touch_session($sid);
- }
- /**
- * Terminates one sessions, auth hooks are not executed.
- *
- * @deprecated since 2.6
- * @param string $sid session id
- */
- function session_kill($sid) {
- debugging('session_kill() is deprecated, use \core\session\manager::kill_session() instead', DEBUG_DEVELOPER);
- \core\session\manager::kill_session($sid);
- }
- /**
- * Terminates all sessions of one user, auth hooks are not executed.
- * NOTE: This can not work for file based sessions!
- *
- * @deprecated since 2.6
- * @param int $userid user id
- */
- function session_kill_user($userid) {
- debugging('session_kill_user() is deprecated, use \core\session\manager::kill_user_sessions() instead', DEBUG_DEVELOPER);
- \core\session\manager::kill_user_sessions($userid);
- }
- // PHP 5.6 includes session_gc(), we cannot define it any more.
- if (!function_exists('session_gc')) {
- /**
- * Session garbage collection
- * - verify timeout for all users
- * - kill sessions of all deleted users
- * - kill sessions of users with disabled plugins or 'nologin' plugin
- *
- * @deprecated since 2.6
- */
- function session_gc()
- {
- debugging('session_gc() is deprecated, use \core\session\manager::gc() instead', DEBUG_DEVELOPER);
- \core\session\manager::gc();
- }
- }
- /**
- * Setup $USER object - called during login, loginas, etc.
- *
- * Call sync_user_enrolments() manually after log-in, or log-in-as.
- *
- * @deprecated since 2.6
- * @param stdClass $user full user record object
- * @return void
- */
- function session_set_user($user) {
- debugging('session_set_user() is deprecated, use \core\session\manager::set_user() instead', DEBUG_DEVELOPER);
- \core\session\manager::set_user($user);
- }
- /**
- * Is current $USER logged-in-as somebody else?
- * @deprecated since 2.6
- * @return bool
- */
- function session_is_loggedinas() {
- debugging('session_is_loggedinas() is deprecated, use \core\session\manager::is_loggedinas() instead', DEBUG_DEVELOPER);
- return \core\session\manager::is_loggedinas();
- }
- /**
- * Returns the $USER object ignoring current login-as session
- * @deprecated since 2.6
- * @return stdClass user object
- */
- function session_get_realuser() {
- debugging('session_get_realuser() is deprecated, use \core\session\manager::get_realuser() instead', DEBUG_DEVELOPER);
- return \core\session\manager::get_realuser();
- }
- /**
- * Login as another user - no security checks here.
- * @deprecated since 2.6
- * @param int $userid
- * @param stdClass $context
- * @return void
- */
- function session_loginas($userid, $context) {
- debugging('session_loginas() is deprecated, use \core\session\manager::loginas() instead', DEBUG_DEVELOPER);
- \core\session\manager::loginas($userid, $context);
- }
- /**
- * Minify JavaScript files.
- *
- * @deprecated since 2.6
- *
- * @param array $files
- * @return string
- */
- function js_minify($files) {
- debugging('js_minify() is deprecated, use core_minify::js_files() or core_minify::js() instead.');
- return core_minify::js_files($files);
- }
- /**
- * Minify CSS files.
- *
- * @deprecated since 2.6
- *
- * @param array $files
- * @return string
- */
- function css_minify_css($files) {
- debugging('css_minify_css() is deprecated, use core_minify::css_files() or core_minify::css() instead.');
- return core_minify::css_files($files);
- }
- /**
- * Function to call all event handlers when triggering an event
- *
- * @deprecated since 2.6
- *
- * @param string $eventname name of the event
- * @param mixed $eventdata event data object
- * @return int number of failed events
- */
- function events_trigger($eventname, $eventdata) {
- // TODO: uncomment after conversion of all events in standard distribution
- // debugging('events_trigger() is deprecated, please use new events instead', DEBUG_DEVELOPER);
- return events_trigger_legacy($eventname, $eventdata);
- }
- /**
- * List all core subsystems and their location
- *
- * This is a whitelist of components that are part of the core and their
- * language strings are defined in /lang/en/<<subsystem>>.php. If a given
- * plugin is not listed here and it does not have proper plugintype prefix,
- * then it is considered as course activity module.
- *
- * The location is optionally dirroot relative path. NULL means there is no special
- * directory for this subsystem. If the location is set, the subsystem's
- * renderer.php is expected to be there.
- *
- * @deprecated since 2.6, use core_component::get_core_subsystems()
- *
- * @param bool $fullpaths false means relative paths from dirroot, use true for performance reasons
- * @return array of (string)name => (string|null)location
- */
- function get_core_subsystems($fullpaths = false) {
- global $CFG;
- // NOTE: do not add any other debugging here, keep forever.
- $subsystems = core_component::get_core_subsystems();
- if ($fullpaths) {
- return $subsystems;
- }
- debugging('Short paths are deprecated when using get_core_subsystems(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER);
- $dlength = strlen($CFG->dirroot);
- foreach ($subsystems as $k => $v) {
- if ($v === null) {
- continue;
- }
- $subsystems[$k] = substr($v, $dlength+1);
- }
- return $subsystems;
- }
- /**
- * Lists all plugin types.
- *
- * @deprecated since 2.6, use core_component::get_plugin_types()
- *
- * @param bool $fullpaths false means relative paths from dirroot
- * @return array Array of strings - name=>location
- */
- function get_plugin_types($fullpaths = true) {
- global $CFG;
- // NOTE: do not add any other debugging here, keep forever.
- $types = core_component::get_plugin_types();
- if ($fullpaths) {
- return $types;
- }
- debugging('Short paths are deprecated when using get_plugin_types(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER);
- $dlength = strlen($CFG->dirroot);
- foreach ($types as $k => $v) {
- if ($k === 'theme') {
- $types[$k] = 'theme';
- continue;
- }
- $types[$k] = substr($v, $dlength+1);
- }
- return $types;
- }
- /**
- * Use when listing real plugins of one type.
- *
- * @deprecated since 2.6, use core_component::get_plugin_list()
- *
- * @param string $plugintype type of plugin
- * @return array name=>fulllocation pairs of plugins of given type
- */
- function get_plugin_list($plugintype) {
- // NOTE: do not add any other debugging here, keep forever.
- if ($plugintype === '') {
- $plugintype = 'mod';
- }
- return core_component::get_plugin_list($plugintype);
- }
- /**
- * Get a list of all the plugins of a given type that define a certain class
- * in a certain file. The plugin component names and class names are returned.
- *
- * @deprecated since 2.6, use core_component::get_plugin_list_with_class()
- *
- * @param string $plugintype the type of plugin, e.g. 'mod' or 'report'.
- * @param string $class the part of the name of the class after the
- * frankenstyle prefix. e.g 'thing' if you are looking for classes with
- * names like report_courselist_thing. If you are looking for classes with
- * the same name as the plugin name (e.g. qtype_multichoice) then pass ''.
- * @param string $file the name of file within the plugin that defines the class.
- * @return array with frankenstyle plugin names as keys (e.g. 'report_courselist', 'mod_forum')
- * and the class names as values (e.g. 'report_courselist_thing', 'qtype_multichoice').
- */
- function get_plugin_list_with_class($plugintype, $class, $file) {
- // NOTE: do not add any other debugging here, keep forever.
- return core_component::get_plugin_list_with_class($plugintype, $class, $file);
- }
- /**
- * Returns the exact absolute path to plugin directory.
- *
- * @deprecated since 2.6, use core_component::get_plugin_directory()
- *
- * @param string $plugintype type of plugin
- * @param string $name name of the plugin
- * @return string full path to plugin directory; NULL if not found
- */
- function get_plugin_directory($plugintype, $name) {
- // NOTE: do not add any other debugging here, keep forever.
- if ($plugintype === '') {
- $plugintype = 'mod';
- }
- return core_component::get_plugin_directory($plugintype, $name);
- }
- /**
- * Normalize the component name using the "frankenstyle" names.
- *
- * @deprecated since 2.6, use core_component::normalize_component()
- *
- * @param string $component
- * @return array as (string)$type => (string)$plugin
- */
- function normalize_component($component) {
- // NOTE: do not add any other debugging here, keep forever.
- return core_component::normalize_component($component);
- }
- /**
- * Return exact absolute path to a plugin directory.
- *
- * @deprecated since 2.6, use core_component::normalize_component()
- *
- * @param string $component name such as 'moodle', 'mod_forum'
- * @return string full path to component directory; NULL if not found
- */
- function get_component_directory($component) {
- // NOTE: do not add any other debugging here, keep forever.
- return core_component::get_component_directory($component);
- }
- // === Deprecated before 2.6.0 ===
- /**
- * 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');
- }
- /**
- * 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 (http://docs.moodle.org/dev/Output_functions)
- * this was abused mostly for embedding of attachments
- * @todo final deprecation of this function in MDL-40607
- * @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;
- debugging('filter_text() is deprecated, use format_text(), format_string() etc instead.', DEBUG_DEVELOPER);
- 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
- * @todo final deprecation of this function in MDL-40607
- */
- function httpsrequired() {
- global $PAGE;
- debugging('httpsrequired() is deprecated use $PAGE->https_required() instead.', DEBUG_DEVELOPER);
- $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;
- }
- /**
- * @deprecated use get_string("pluginname", "auth_[PLUINNAME]") instead.
- * @todo remove completely in MDL-40517
- */
- function auth_get_plugin_title($authtype) {
- throw new coding_exception('Function auth_get_plugin_title() is deprecated, please use standard get_string("pluginname", "auth_'.$authtype.'")!');
- }
- /**
- * @deprecated use indivividual enrol plugin settings instead
- * @todo remove completely in MDL-40517
- */
- function get_default_course_role($course) {
- throw new coding_exception('get_default_course_role() can not be used any more, please use enrol plugin settings instead!');
- }
- /**
- * @deprecated use get_string_manager()->get_list_of_translations() instead.
- * @todo remove completely in MDL-40517
- */
- function get_list_of_languages($refreshcache=false, $returnall=false) {
- throw new coding_exception('get_list_of_languages() can not be used any more, please use get_string_manager()->get_list_of_translations() instead.');
- }
- /**
- * @deprecated use get_string_manager()->get_list_of_currencies() instead.
- * @todo remove completely in MDL-40517
- */
- function get_list_of_currencies() {
- throw new coding_exception('get_list_of_currencies() can not be used any more, please use get_string_manager()->get_list_of_currencies() instead.');
- }
- /**
- * @deprecated use get_string_manager()->get_list_of_countries() instead.
- * @todo remove completely in MDL-40517
- */
- function get_list_of_countries() {
- throw new coding_exception('get_list_of_countries() can not be used any more, please use get_string_manager()->get_list_of_countries() instead.');
- }
- /**
- * Return all course participant for a given course
- *
- * @deprecated use get_enrolled_users($context) instead.
- * @todo final deprecation of this function in MDL-40607
- * @param integer $courseid
- * @return array of user
- */
- function get_course_participants($courseid) {
- debugging('get_course_participants() is deprecated, use get_enrolled_users() instead.', DEBUG_DEVELOPER);
- return get_enrolled_users(context_course::instance($courseid));
- }
- /**
- * Return true if the user is a participant for a given course
- *
- * @deprecated use is_enrolled($context, $userid) instead.
- * @todo final deprecation of this function in MDL-40607
- * @param integer $userid
- * @param integer $courseid
- * @return boolean
- */
- function is_course_participant($userid, $courseid) {
- debugging('is_course_participant() is deprecated, use is_enrolled() instead.', DEBUG_DEVELOPER);
- return is_enrolled(context_course::instance($courseid), $userid);
- }
- /**
- * Searches logs to find all enrolments since a certain date
- *
- * used to print recent activity
- *
- * @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;
- debugging('get_recent_enrolments() is deprecated as it returned inaccurate results.', DEBUG_DEVELOPER);
- $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);
- }
- ########### FROM weblib.php ##########################################################################
- /**
- * @deprecated use $OUTPUT->box() instead.
- * @todo remove completely in MDL-40517
- */
- function print_simple_box($message, $align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
- throw new coding_exception('print_simple_box can not be used any more. Please use $OUTPUT->box() instead');
- }
- /**
- * @deprecated use $OUTPUT->box_start instead.
- * @todo remove completely in MDL-40517
- */
- function print_simple_box_start($align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
- throw new coding_exception('print_simple_box_start can not be used any more. Please use $OUTPUT->box_start instead');
- }
- /**
- * @deprecated use $OUTPUT->box_end instead.
- * @todo remove completely in MDL-40517
- */
- function print_simple_box_end($return=false) {
- throw new coding_exception('print_simple_box_end can not be used any more. Please use $OUTPUT->box_end instead');
- }
- /**
- * @deprecated the urltolink filter now does this job.
- * @todo remove completely in MDL-40517
- */
- function convert_urls_into_links($text) {
- throw new coding_exception('convert_urls_into_links() can not be used any more and replaced by the urltolink filter');
- }
- /**
- * @deprecated use the emoticon_manager class instead.
- * @todo remove completely in MDL-40517
- */
- function get_emoticons_list_for_help_file() {
- throw new coding_exception('get_emoticons_list_for_help_file() can not be used any more, use the new emoticon_manager API instead');
- }
- /**
- * @deprecated use emoticon filter now does this job.
- * @todo remove completely in MDL-40517
- */
- function replace_smilies(&$text) {
- throw new coding_exception('replace_smilies() can not be used any more and replaced with the emoticon filter.');
- }
- /**
- * @deprecated use clean_param($string, PARAM_FILE) instead.
- * @todo final deprecation of this function in MDL-40607
- *
- * @param string $string ?
- * @param int $allowdots ?
- * @return bool
- */
- function detect_munged_arguments($string, $allowdots=1) {
- debugging('detect_munged_arguments() is deprecated, please use clean_param(,PARAM_FILE) instead.', DEBUG_DEVELOPER);
- 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);
- }
- /**
- * 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!)
- * @deprecated use groups_get_all_groups() instead.
- * @todo final deprecation of this function in MDL-40607
- */
- function mygroupid($courseid) {
- global $USER;
- debugging('mygroupid() is deprecated, please use groups_get_all_groups() instead.', DEBUG_DEVELOPER);
- 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()');
- }
- /**
- * @deprecated use $PAGE->requires->js_module() instead.
- */
- function require_js($lib) {
- throw new coding_exception('require_js() was removed, use new JS api');
- }
- /**
- * @deprecated use $PAGE->theme->name instead.
- * @todo final deprecation of this function in MDL-40607
- * @return string the name of the current theme.
- */
- function current_theme() {
- global $PAGE;
- debugging('current_theme() is deprecated, please 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.
- * @todo final deprecation of this function in MDL-40607
- * @return string HTML element.
- */
- function skip_main_destination() {
- global $OUTPUT;
- debugging('skip_main_destination() is deprecated, please use $OUTPUT->skip_link_target() instead.', DEBUG_DEVELOPER);
- return $OUTPUT->skip_link_target();
- }
- /**
- * @deprecated use $OUTPUT->heading() instead.
- * @todo remove completely in MDL-40517
- */
- function print_headline($text, $size=2, $return=false) {
- throw new coding_exception('print_headline() can not be used any more. Please use $OUTPUT->heading() instead.');
- }
- /**
- * @deprecated use $OUTPUT->heading() instead.
- * @todo remove completely in MDL-40517
- */
- function print_heading($text, $deprecated = '', $size = 2, $class = 'main', $return = false, $id = '') {
- throw new coding_exception('print_heading() can not be used any more. Please use $OUTPUT->heading() instead.');
- }
- /**
- * @deprecated use $OUTPUT->heading() instead.
- * @todo remove completely in MDL-40517
- */
- function print_heading_block($heading, $class='', $return=false) {
- throw new coding_exception('print_heading_with_block() can not be used any more. Please use $OUTPUT->heading() instead.');
- }
- /**
- * @deprecated use $OUTPUT->box() instead.
- * @todo remove completely in MDL-40517
- */
- function print_box($message, $classes='generalbox', $ids='', $return=false) {
- throw new coding_exception('print_box() can not be used any more. Please use $OUTPUT->box() instead.');
- }
- /**
- * @deprecated use $OUTPUT->box_start() instead.
- * @todo remove completely in MDL-40517
- */
- function print_box_start($classes='generalbox', $ids='', $return=false) {
- throw new coding_exception('print_box_start() can not be used any more. Please use $OUTPUT->box_start() instead.');
- }
- /**
- * @deprecated use $OUTPUT->box_end() instead.
- * @todo remove completely in MDL-40517
- */
- function print_box_end($return=false) {
- throw new coding_exception('print_box_end() can not be used any more. Please use $OUTPUT->box_end() instead.');
- }
- /**
- * Print a message in a standard themed container.
- *
- * @deprecated use $OUTPUT->container() instead.
- * @todo final deprecation of this function in MDL-40607
- * @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;
- debugging('print_container() is deprecated. Please use $OUTPUT->container() instead.', DEBUG_DEVELOPER);
- if ($clearfix) {
- $classes .= ' clearfix';
- }
- $output = $OUTPUT->container($message, $classes, $idbase);
- if ($return) {
- return $output;
- } else {
- echo $output;
- }
- }
- /**
- * Starts a container using divs
- *
- * @deprecated use $OUTPUT->container_start() instead.
- * @todo final deprecation of this function in MDL-40607
- * @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;
- debugging('print_container_start() is deprecated. Please use $OUTPUT->container_start() instead.', DEBUG_DEVELOPER);
- if ($clearfix) {
- $classes .= ' clearfix';
- }
- $output = $OUTPUT->container_start($classes, $idbase);
- if ($return) {
- return $output;
- } else {
- echo $output;
- }
- }
- /**
- * @deprecated do not use any more, is not automatic
- * @todo remove completely in MDL-40517
- */
- function check_theme_arrows() {
- throw new coding_exception('check_theme_arrows() has been deprecated, do not use it anymore, it is now automatic.');
- }
- /**
- * Simple function to end a container (see above)
- *
- * @deprecated use $OUTPUT->container_end() instead.
- * @todo final deprecation of this function in MDL-40607
- * @param boolean $return, return as string or just print it
- * @return string|void Based on $return
- */
- function print_container_end($return=false) {
- global $OUTPUT;
- debugging('print_container_end() is deprecated. Please use $OUTPUT->container_end() instead.', DEBUG_DEVELOPER);
- $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 use $OUTPUT->continue_button() instead.
- * @todo final deprecation of this function in MDL-40607
- *
- * @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;
- debugging('print_continue() is deprecated. Please use $OUTPUT->continue_button() instead.', DEBUG_DEVELOPER);
- 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
- *
- * @deprecated use $PAGE methods instead.
- * @todo final deprecation of this function in MDL-40607
- * @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;
- debugging('print_header() is deprecated. Please use $PAGE methods instead.', DEBUG_DEVELOPER);
- $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 use $PAGE methods instead.
- * @todo final deprecation of this function in MDL-40607
- * @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;
- debugging('print_header_simple() is deprecated. Please use $PAGE methods instead.', DEBUG_DEVELOPER);
- 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;
- }
- }
- /**
- * @deprecated use $OUTPUT->footer() instead.
- * @todo remove completely in MDL-40517
- */
- function print_footer($course = NULL, $usercourse = NULL, $return = false) {
- throw new coding_exception('print_footer() cant be used anymore. Please use $OUTPUT->footer() instead.');
- }
- /**
- * @deprecated use theme layouts instead.
- * @todo remove completely in MDL-40517
- */
- function user_login_string($course='ignored', $user='ignored') {
- throw new coding_exception('user_login_info() cant be used anymore. User login info is now handled via themes layouts.');
- }
- /**
- * 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.
- *
- * @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 use $OUTPUT->block() instead.
- * @todo final deprecation of this function in MDL-40607
- */
- function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') {
- global $OUTPUT;
- debugging('print_side_block() is deprecated, please use $OUTPUT->block() instead.', DEBUG_DEVELOPER);
- // 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.
- }
- /**
- * @deprecated blocks are now printed by theme.
- * @todo remove completely in MDL-40517
- */
- function blocks_have_content(&$blockmanager, $region) {
- throw new coding_exception('blocks_have_content() can no longer be used. Blocks are now printed by the theme.');
- }
- /**
- * @deprecated blocks are now printed by the theme.
- * @todo remove completely in MDL-40517
- */
- function blocks_print_group($page, $blockmanager, $region) {
- throw new coding_exception('function blocks_print_group() can no longer be used. Blocks are now printed by the theme.');
- }
- /**
- * @deprecated blocks are now printed by the theme.
- * @todo remove completely in MDL-40517
- */
- function blocks_setup(&$page, $pinned = BLOCKS_PINNED_FALSE) {
- throw new coding_exception('blocks_print_group() can no longer be used. Blocks are now printed by the theme.');
- }
- /**
- * @deprecated Layout is now controlled by the theme.
- * @todo remove completely in MDL-40517
- */
- function blocks_preferred_width($instances) {
- throw new coding_exception('blocks_print_group() can no longer be used. Blocks are now printed by the theme.');
- }
- /**
- * @deprecated use html_writer::table() instead.
- * @todo remove completely in MDL-40517
- */
- function print_table($table, $return=false) {
- throw new coding_exception('print_table() can no longer be used. Use html_writer::table() instead.');
- }
- /**
- * @deprecated use $OUTPUT->action_link() instead (note: popups are discouraged for accesibility reasons)
- * @todo remove completely in MDL-40517
- */
- function link_to_popup_window ($url, $name=null, $linkname=null, $height=400, $width=500, $title=null, $options=null, $return=false) {
- throw new coding_exception('link_to_popup_window() can no longer be used. Please to use $OUTPUT->action_link() instead.');
- }
- /**
- * @deprecated use $OUTPUT->single_button() instead.
- * @todo remove completely in MDL-40517
- */
- function button_to_popup_window ($url, $name=null, $linkname=null,
- $height=400, $width=500, $title=null, $options=null, $return=false,
- $id=null, $class=null) {
- throw new coding_exception('button_to_popup_window() can no longer be used. Please use $OUTPUT->single_button() instead.');
- }
- /**
- * @deprecated use $OUTPUT->single_button() instead.
- * @todo remove completely in MDL-40517
- */
- function print_single_button($link, $options, $label='OK', $method='get', $notusedanymore='',
- $return=false, $tooltip='', $disabled = false, $jsconfirmmessage='', $formid = '') {
- throw new coding_exception('print_single_button() can no longer be used. Please use $OUTPUT->single_button() instead.');
- }
- /**
- * @deprecated use $OUTPUT->spacer() instead.
- * @todo remove completely in MDL-40517
- */
- function print_spacer($height=1, $width=1, $br=true, $return=false) {
- throw new coding_exception('print_spacer() can no longer be used. Please use $OUTPUT->spacer() instead.');
- }
- /**
- * @deprecated use $OUTPUT->user_picture() instead.
- * @todo remove completely in MDL-40517
- */
- function print_user_picture($user, $courseid, $picture=NULL, $size=0, $return=false, $link=true, $target='', $alttext=true) {
- throw new coding_exception('print_user_picture() can no longer be used. Please use $OUTPUT->user_picture($user, array(\'courseid\'=>$courseid) instead.');
- }
- /**
- * Prints a basic textarea field.
- *
- * @deprecated since Moodle 2.0
- *
- * When using this function, you should
- *
- * @global object
- * @param bool $unused No longer used.
- * @param int $rows Number of rows to display (minimum of 10 when $height is non-null)
- * @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
- * @param null $width (Deprecated) Width of the element; if a value is passed, the minimum value for $cols will be 65. Value is otherwise ignored.
- * @param null $height (Deprecated) Height of the element; if a value is passe, the minimum value for $rows will be 10. Value is otherwise ignored.
- * @param string $name Name to use for the textarea element.
- * @param string $value Initial content to display in the textarea.
- * @param int $obsolete deprecated
- * @param bool $return If false, will output string. If true, will return string value.
- * @param string $id CSS ID to add to the textarea element.
- * @return string|void depending on the value of $return
- */
- function print_textarea($unused, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
- /// $width and height are legacy fi…
Large files files are truncated, but you can click here to view the full file