MDL-30973 Files API, check and update DocBlock

This commit is contained in:
Dongsheng Cai
2012-02-15 12:48:57 +08:00
parent baa5cd8240
commit d2b7803e5a
47 changed files with 1497 additions and 785 deletions
+10 -3
View File
@@ -18,11 +18,18 @@
/**
* Form for editing HTML block instances.
*
* @package block_html
* @copyright 2010 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package block_html
* @category files
* @param stdClass $course course object
* @param stdClass $birecord_or_cm block instance record
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @return bool
*/
function block_html_pluginfile($course, $birecord_or_cm, $context, $filearea, $args, $forcedownload) {
global $SCRIPT;
@@ -79,4 +86,4 @@ function block_html_global_db_replace($search, $replace) {
}
}
$instances->close();
}
}
+55 -52
View File
@@ -1,5 +1,4 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -19,10 +18,9 @@
/**
* Utility class for browsing of files.
*
* @package core
* @subpackage filebrowser
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
@@ -41,8 +39,7 @@ require_once("$CFG->libdir/filebrowser/file_info_context_course.php");
require_once("$CFG->libdir/filebrowser/file_info_context_module.php");
/**
* This class provides the main entry point for other code wishing to get
* information about files.
* This class provides the main entry point for other code wishing to get information about files.
*
* The whole file storage for a Moodle site can be seen as a huge virtual tree.
* The spine of the tree is the tree of contexts (system, course-categories,
@@ -56,22 +53,23 @@ require_once("$CFG->libdir/filebrowser/file_info_context_module.php");
*
* Always use this abstraction when you need to access module files from core code.
*
* @package core
* @subpackage filebrowser
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core_files
* @category files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class file_browser {
/**
* Looks up file_info instance
* @param object $context
* @param string $component
* @param string $filearea
* @param int $itemid
* @param string $filepath
* @param string $filename
* @return file_info instance or null if not found or access not allowed
*
* @param stdClass $context context object
* @param string $component component
* @param string $filearea file area
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info|null file_info instance or null if not found or access not allowed
*/
public function get_file_info($context = NULL, $component = NULL, $filearea = NULL, $itemid = NULL, $filepath = NULL, $filename = NULL) {
if (!$context) {
@@ -95,12 +93,13 @@ class file_browser {
/**
* Returns info about the files at System context
* @param object $context
* @param string $component
* @param string $filearea
* @param int $itemid
* @param string $filepath
* @param string $filename
*
* @param object $context context object
* @param string $component component
* @param string $filearea file area
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info instance or null if not found or access not allowed
*/
private function get_file_info_context_system($context, $component, $filearea, $itemid, $filepath, $filename) {
@@ -111,13 +110,14 @@ class file_browser {
/**
* Returns info about the files at User context
* @param object $context
* @param string $component
* @param string $filearea
* @param int $itemid
* @param string $filepath
* @param string $filename
* @return file_info instance or null if not found or access not allowed
*
* @param stdClass $context context object
* @param string $component component
* @param string $filearea file area
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info|null file_info instance or null if not found or access not allowed
*/
private function get_file_info_context_user($context, $component, $filearea, $itemid, $filepath, $filename) {
global $DB, $USER;
@@ -142,13 +142,14 @@ class file_browser {
/**
* Returns info about the files at Course category context
* @param object $context
* @param string $component
* @param string $filearea
* @param int $itemid
* @param string $filepath
* @param string $filename
* @return file_info instance or null if not found or access not allowed
*
* @param stdClass $context context object
* @param string $component component
* @param string $filearea file area
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info|null file_info instance or null if not found or access not allowed
*/
private function get_file_info_context_coursecat($context, $component, $filearea, $itemid, $filepath, $filename) {
global $DB;
@@ -163,13 +164,14 @@ class file_browser {
/**
* Returns info about the files at Course category context
* @param object $context
* @param string $component
* @param string $filearea
* @param int $itemid
* @param string $filepath
* @param string $filename
* @return file_info instance or null if not found or access not allowed
*
* @param stdClass $context context object
* @param string $component component
* @param string $filearea file area
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info|null file_info instance or null if not found or access not allowed
*/
private function get_file_info_context_course($context, $component, $filearea, $itemid, $filepath, $filename) {
global $DB, $COURSE;
@@ -186,13 +188,14 @@ class file_browser {
/**
* Returns info about the files at Course category context
* @param object $context
* @param string $component
* @param string $filearea
* @param int $itemid
* @param string $filepath
* @param string $filename
* @return file_info instance or null if not found or access not allowed
*
* @param stdClass $context context object
* @param string $component component
* @param string $filearea file area
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info|null file_info instance or null if not found or access not allowed
*/
private function get_file_info_context_module($context, $component, $filearea, $itemid, $filepath, $filename) {
global $COURSE, $DB, $CFG;
+51 -22
View File
@@ -1,5 +1,4 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -19,8 +18,7 @@
/**
* Base for all file browsing classes.
*
* @package core
* @subpackage filebrowser
* @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -28,19 +26,26 @@
defined('MOODLE_INTERNAL') || die();
/**
* Base class for things in the tree navigated by @see{file_browser}.
* Base class for things in the tree navigated by {@link file_browser}.
*
* @package core
* @subpackage filebrowser
* @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class file_info {
/** @var stdClass File context */
protected $context;
/** @var file_browser File browser instance */
protected $browser;
/**
* Constructor
*
* @param file_browser $browser file_browser instance
* @param stdClass $context
*/
public function __construct($browser, $context) {
$this->browser = $browser;
$this->context = $context;
@@ -50,6 +55,7 @@ abstract class file_info {
* Returns list of standard virtual file/directory identification.
* The difference from stored_file parameters is that null values
* are allowed in all fields
*
* @return array with keys contextid, component, filearea, itemid, filepath and filename
*/
public function get_params() {
@@ -63,30 +69,35 @@ abstract class file_info {
/**
* Returns localised visible name.
*
* @return string
*/
public abstract function get_visible_name();
/**
* Is directory?
* Whether or not this is a directory
*
* @return bool
*/
public abstract function is_directory();
/**
* Returns list of children.
*
* @return array of file_info instances
*/
public abstract function get_children();
/**
* Returns parent file_info instance
*
* @return file_info or null for root
*/
public abstract function get_parent();
/**
* Returns array of url encoded params.
*
* @return array with numeric keys
*/
public function get_params_rawencoded() {
@@ -104,8 +115,9 @@ abstract class file_info {
/**
* Returns file download url
* @param bool $forcedownload
* @param bool $htts force https
*
* @param bool $forcedownload whether or not force download
* @param bool $https whether or not force https
* @return string url
*/
public function get_url($forcedownload=false, $https=false) {
@@ -113,7 +125,8 @@ abstract class file_info {
}
/**
* Can I read content of this file or enter directory?
* Whether or not I can read content of this file or enter directory
*
* @return bool
*/
public function is_readable() {
@@ -121,7 +134,8 @@ abstract class file_info {
}
/**
* Can I add new files or directories?
* Whether or not new files or directories can be added
*
* @return bool
*/
public function is_writable() {
@@ -143,6 +157,7 @@ abstract class file_info {
/**
* Returns file size in bytes, null for directories
*
* @return int bytes or null if not known
*/
public function get_filesize() {
@@ -151,6 +166,7 @@ abstract class file_info {
/**
* Returns mimetype
*
* @return string mimetype or null if not known
*/
public function get_mimetype() {
@@ -159,6 +175,7 @@ abstract class file_info {
/**
* Returns time created unix timestamp if known
*
* @return int timestamp or null
*/
public function get_timecreated() {
@@ -167,6 +184,7 @@ abstract class file_info {
/**
* Returns time modified unix timestamp if known
*
* @return int timestamp or null
*/
public function get_timemodified() {
@@ -183,6 +201,7 @@ abstract class file_info {
/**
* Returns the author name of the file
*
* @return string author name or null
*/
public function get_author() {
@@ -191,6 +210,7 @@ abstract class file_info {
/**
* Returns the source of the file
*
* @return string a source url or null
*/
public function get_source() {
@@ -199,6 +219,7 @@ abstract class file_info {
/**
* Returns the sort order of the file
*
* @return int
*/
public function get_sortorder() {
@@ -208,8 +229,9 @@ abstract class file_info {
/**
* Create new directory, may throw exception - make sure
* params are valid.
*
* @param string $newdirname name of new directory
* @param int id of author, default $USER->id
* @param int $userid id of author, default $USER->id
* @return file_info new directory
*/
public function create_directory($newdirname, $userid = NULL) {
@@ -219,9 +241,10 @@ abstract class file_info {
/**
* Create new file from string - make sure
* params are valid.
*
* @param string $newfilename name of new file
* @param string $content of file
* @param int id of author, default $USER->id
* @param int $userid id of author, default $USER->id
* @return file_info new file
*/
public function create_file_from_string($newfilename, $content, $userid = NULL) {
@@ -231,9 +254,10 @@ abstract class file_info {
/**
* Create new file from pathname - make sure
* params are valid.
*
* @param string $newfilename name of new file
* @param string $pathname location of file
* @param int id of author, default $USER->id
* @param int $userid id of author, default $USER->id
* @return file_info new file
*/
public function create_file_from_pathname($newfilename, $pathname, $userid = NULL) {
@@ -243,9 +267,10 @@ abstract class file_info {
/**
* Create new file from stored file - make sure
* params are valid.
*
* @param string $newfilename name of new file
* @param mixed dile id or stored_file of file
* @param int id of author, default $USER->id
* @param int|stored_file $fid id or stored_file of file
* @param int $userid id of author, default $USER->id
* @return file_info new file
*/
public function create_file_from_storedfile($newfilename, $fid, $userid = NULL) {
@@ -254,6 +279,7 @@ abstract class file_info {
/**
* Delete file, make sure file is deletable first.
*
* @return bool success
*/
public function delete() {
@@ -262,12 +288,13 @@ abstract class file_info {
/**
* Copy content of this file to local storage, overriding current file if needed.
* @param int $contextid
* @param string $component
* @param string $filearea
* @param int $itemid
* @param string $filepath
* @param string $filename
*
* @param int $contextid context ID
* @param string $component component
* @param string $filearea file area
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return boolean success
*/
public function copy_to_storage($contextid, $component, $filearea, $itemid, $filepath, $filename) {
@@ -276,6 +303,8 @@ abstract class file_info {
/**
* Copy content of this file to local storage, overriding current file if needed.
*
* @todo MDL-31068 implement move() rename() unzip() zip()
* @param string $pathname real local full file name
* @return boolean success
*/
+129 -39
View File
@@ -1,5 +1,4 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -19,8 +18,7 @@
/**
* Utility class for browsing of course files.
*
* @package core
* @subpackage filebrowser
* @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -28,16 +26,23 @@
defined('MOODLE_INTERNAL') || die();
/**
* Represents a course context in the tree navigated by @see{file_browser}.
* Represents a course context in the tree navigated by {@link file_browser}.
*
* @package core
* @subpackage filebrowser
* @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class file_info_context_course extends file_info {
/** @var stdClass course object */
protected $course;
/**
* Constructor
*
* @param file_browser $browser file browser instance
* @param stdClass $context context object
* @param stdClass $course course object
*/
public function __construct($browser, $context, $course) {
parent::__construct($browser, $context);
$this->course = $course;
@@ -46,11 +51,12 @@ class file_info_context_course extends file_info {
/**
* Return information about this specific context level
*
* @param $component
* @param $filearea
* @param $itemid
* @param $filepath
* @param $filename
* @param string $component component
* @param string $filearea file area
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info|null file_info instance or null if not found or access not allowed
*/
public function get_file_info($component, $filearea, $itemid, $filepath, $filename) {
// try to emulate require_login() tests here
@@ -80,6 +86,14 @@ class file_info_context_course extends file_info {
return null;
}
/**
* Gets a stored file for the course summary filearea directory
*
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info|null file_info instance or null if not found or access not allowed
*/
protected function get_area_course_summary($itemid, $filepath, $filename) {
global $CFG;
@@ -106,7 +120,14 @@ class file_info_context_course extends file_info {
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, get_string('areacourseintro', 'repository'), false, true, true, false);
}
/**
* Gets a stored file for the course section filearea directory
*
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info|null file_info instance or null if not found or access not allowed
*/
protected function get_area_course_section($itemid, $filepath, $filename) {
global $CFG, $DB;
@@ -139,7 +160,14 @@ class file_info_context_course extends file_info {
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, $section->section, true, true, true, false);
}
/**
* Gets a stored file for the course legacy filearea directory
*
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info|null file_info instance or null if not found or access not allowed
*/
protected function get_area_course_legacy($itemid, $filepath, $filename) {
if (!has_capability('moodle/course:managefiles', $this->context)) {
return null;
@@ -169,6 +197,14 @@ class file_info_context_course extends file_info {
return new file_info_area_course_legacy($this->browser, $this->context, $storedfile);
}
/**
* Gets a stored file for the backup course filearea directory
*
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info|null file_info instance or null if not found or access not allowed
*/
protected function get_area_backup_course($itemid, $filepath, $filename) {
global $CFG;
@@ -202,10 +238,10 @@ class file_info_context_course extends file_info {
/**
* Gets a stored file for the automated backup filearea directory
*
* @param int $itemid
* @param string $filepath
* @param string $filename
* @return file_info_context_course
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info|null
*/
protected function get_area_backup_automated($itemid, $filepath, $filename) {
global $CFG;
@@ -237,6 +273,14 @@ class file_info_context_course extends file_info {
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, get_string('automatedbackup', 'repository'), true, $downloadable, $uploadable, false);
}
/**
* Gets a stored file for the backup section filearea directory
*
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info|null file_info instance or null if not found or access not allowed
*/
protected function get_area_backup_section($itemid, $filepath, $filename) {
global $CFG, $DB;
@@ -273,12 +317,18 @@ class file_info_context_course extends file_info {
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, $section->id, true, $downloadable, $uploadable, false);
}
/**
* Returns localised visible name.
*
* @return string
*/
public function get_visible_name() {
return ($this->course->id == SITEID) ? get_string('frontpage', 'admin') : format_string($this->course->fullname, true, array('context'=>$this->context));
}
/**
* Can I add new files or directories?
* Whether or not new files or directories can be added
*
* @return bool
*/
public function is_writable() {
@@ -286,7 +336,8 @@ class file_info_context_course extends file_info {
}
/**
* Is directory?
* Whether or not this is a directory
*
* @return bool
*/
public function is_directory() {
@@ -295,6 +346,7 @@ class file_info_context_course extends file_info {
/**
* Returns list of children.
*
* @return array of file_info instances
*/
public function get_children() {
@@ -336,6 +388,8 @@ class file_info_context_course extends file_info {
/**
* Returns parent file_info instance
*
* @todo error checking if get_parent_contextid() returns false
* @return file_info or null for root
*/
public function get_parent() {
@@ -350,12 +404,18 @@ class file_info_context_course extends file_info {
/**
* Subclass of file_info_stored for files in the course files area.
*
* @package core
* @subpackage filebrowser
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class file_info_area_course_legacy extends file_info_stored {
/**
* Constructor
*
* @param file_browser $browser file browser instance
* @param stdClass $context context object
* @param stored_file $storedfile stored_file instance
*/
public function __construct($browser, $context, $storedfile) {
global $CFG;
$urlbase = $CFG->wwwroot.'/file.php';
@@ -364,8 +424,9 @@ class file_info_area_course_legacy extends file_info_stored {
/**
* Returns file download url
* @param bool $forcedownload
* @param bool $htts force https
*
* @param bool $forcedownload whether or not force download
* @param bool $https whether or not force https
* @return string url
*/
public function get_url($forcedownload=false, $https=false) {
@@ -388,6 +449,7 @@ class file_info_area_course_legacy extends file_info_stored {
/**
* Returns list of children.
*
* @return array of file_info instances
*/
public function get_children() {
@@ -408,17 +470,26 @@ class file_info_area_course_legacy extends file_info_stored {
}
/**
* Represents a course category context in the tree navigated by @see{file_browser}.
* Represents a course category context in the tree navigated by {@link file_browser}.
*
* @package core
* @subpackage filebrowser
* @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class file_info_area_course_section extends file_info {
/** @var stdClass course object */
protected $course;
/** @var file_info_context_course course file info object */
protected $courseinfo;
/**
* Constructor
*
* @param file_browser $browser file browser instance
* @param stdClass $context context object
* @param stdClass $course course object
* @param file_info_context_course $courseinfo file info instance
*/
public function __construct($browser, $context, $course, file_info_context_course $courseinfo) {
parent::__construct($browser, $context);
$this->course = $course;
@@ -429,6 +500,7 @@ class file_info_area_course_section extends file_info {
* Returns list of standard virtual file/directory identification.
* The difference from stored_file parameters is that null values
* are allowed in all fields
*
* @return array with keys contextid, filearea, itemid, filepath and filename
*/
public function get_params() {
@@ -442,6 +514,7 @@ class file_info_area_course_section extends file_info {
/**
* Returns localised visible name.
*
* @return string
*/
public function get_visible_name() {
@@ -452,7 +525,8 @@ class file_info_area_course_section extends file_info {
}
/**
* Can I add new files or directories?
* Return whether or not new files or directories can be added
*
* @return bool
*/
public function is_writable() {
@@ -460,7 +534,7 @@ class file_info_area_course_section extends file_info {
}
/**
* Is this empty area?
* Return whether or not this is a empty area
*
* @return bool
*/
@@ -470,7 +544,8 @@ class file_info_area_course_section extends file_info {
}
/**
* Is directory?
* Return whether or not this is a empty area
*
* @return bool
*/
public function is_directory() {
@@ -479,6 +554,7 @@ class file_info_area_course_section extends file_info {
/**
* Returns list of children.
*
* @return array of file_info instances
*/
public function get_children() {
@@ -498,7 +574,8 @@ class file_info_area_course_section extends file_info {
/**
* Returns parent file_info instance
* @return file_info or null for root
*
* @return file_info|null file_info or null for root
*/
public function get_parent() {
return $this->courseinfo;
@@ -509,15 +586,24 @@ class file_info_area_course_section extends file_info {
/**
* Implementation of course section backup area
*
* @package core
* @subpackage filebrowser
* @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class file_info_area_backup_section extends file_info {
/** @var stdClass course object */
protected $course;
/** @var file_info_context_course course file info object */
protected $courseinfo;
/**
* Constructor
*
* @param file_browser $browser file browser instance
* @param stdClass $context context object
* @param stdClass $course course object
* @param file_info_context_course $courseinfo file info instance
*/
public function __construct($browser, $context, $course, file_info_context_course $courseinfo) {
parent::__construct($browser, $context);
$this->course = $course;
@@ -528,6 +614,7 @@ class file_info_area_backup_section extends file_info {
* Returns list of standard virtual file/directory identification.
* The difference from stored_file parameters is that null values
* are allowed in all fields
*
* @return array with keys contextid, component, filearea, itemid, filepath and filename
*/
public function get_params() {
@@ -541,6 +628,7 @@ class file_info_area_backup_section extends file_info {
/**
* Returns localised visible name.
*
* @return string
*/
public function get_visible_name() {
@@ -548,7 +636,8 @@ class file_info_area_backup_section extends file_info {
}
/**
* Can I add new files or directories?
* Return whether or not new files and directories can be added
*
* @return bool
*/
public function is_writable() {
@@ -556,7 +645,7 @@ class file_info_area_backup_section extends file_info {
}
/**
* Is this empty area?
* Whether or not this is an empty area
*
* @return bool
*/
@@ -566,7 +655,8 @@ class file_info_area_backup_section extends file_info {
}
/**
* Is directory?
* Return whether or not this is a directory
*
* @return bool
*/
public function is_directory() {
@@ -575,6 +665,7 @@ class file_info_area_backup_section extends file_info {
/**
* Returns list of children.
*
* @return array of file_info instances
*/
public function get_children() {
@@ -594,11 +685,10 @@ class file_info_area_backup_section extends file_info {
/**
* Returns parent file_info instance
*
* @return file_info or null for root
*/
public function get_parent() {
return $this->browser->get_file_info($this->context);
}
}
+33 -14
View File
@@ -1,5 +1,4 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -19,8 +18,7 @@
/**
* Utility class for browsing of curse category files.
*
* @package core
* @subpackage filebrowser
* @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -28,16 +26,23 @@
defined('MOODLE_INTERNAL') || die();
/**
* Represents a course category context in the tree navigated by @see{file_browser}.
* Represents a course category context in the tree navigated by {@link file_browser}.
*
* @package core
* @subpackage filebrowser
* @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class file_info_context_coursecat extends file_info {
/** @var stdClass Category object */
protected $category;
/**
* Constructor
*
* @param file_browser $browser file browser instance
* @param stdClass $context context object
* @param stdClass $category category object
*/
public function __construct($browser, $context, $category) {
parent::__construct($browser, $context);
$this->category = $category;
@@ -46,11 +51,12 @@ class file_info_context_coursecat extends file_info {
/**
* Return information about this specific context level
*
* @param $component
* @param $filearea
* @param $itemid
* @param $filepath
* @param $filename
* @param string $component component
* @param string $filearea file area
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return fileinfo|null
*/
public function get_file_info($component, $filearea, $itemid, $filepath, $filename) {
global $DB;
@@ -80,6 +86,14 @@ class file_info_context_coursecat extends file_info {
return null;
}
/**
* Return a file from course category description area
*
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return fileinfo|null
*/
protected function get_area_coursecat_description($itemid, $filepath, $filename) {
global $CFG;
@@ -110,6 +124,7 @@ class file_info_context_coursecat extends file_info {
/**
* Returns localised visible name.
*
* @return string
*/
public function get_visible_name() {
@@ -117,7 +132,8 @@ class file_info_context_coursecat extends file_info {
}
/**
* Can I add new files or directories?
* Whether or not new files or directories can be added
*
* @return bool
*/
public function is_writable() {
@@ -125,7 +141,8 @@ class file_info_context_coursecat extends file_info {
}
/**
* Is directory?
* Whether or not this is a directory
*
* @return bool
*/
public function is_directory() {
@@ -134,6 +151,7 @@ class file_info_context_coursecat extends file_info {
/**
* Returns list of children.
*
* @return array of file_info instances
*/
public function get_children() {
@@ -172,7 +190,8 @@ class file_info_context_coursecat extends file_info {
/**
* Returns parent file_info instance
* @return file_info or null for root
*
* @return file_info|null fileinfo instance or null for root directory
*/
public function get_parent() {
$cid = get_parent_contextid($this->context);
+47 -15
View File
@@ -1,5 +1,4 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -19,8 +18,7 @@
/**
* Utility class for browsing of module files.
*
* @package core
* @subpackage filebrowser
* @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -28,19 +26,31 @@
defined('MOODLE_INTERNAL') || die();
/**
* Represents a module context in the tree navigated by @see{file_browser}.
* Represents a module context in the tree navigated by {@link file_browser}.
*
* @package core
* @subpackage filebrowser
* @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class file_info_context_module extends file_info {
/** @var stdClass Course object */
protected $course;
/** @var stdClass Course module object */
protected $cm;
/** @var string Module name */
protected $modname;
/** @var array Available file areas */
protected $areas;
/**
* Constructor
*
* @param file_browser $browser file browser instance
* @param stdClass $context context object
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param string $modname module name
*/
public function __construct($browser, $context, $course, $cm, $modname) {
global $CFG;
@@ -68,11 +78,12 @@ class file_info_context_module extends file_info {
/**
* Return information about this specific context level
*
* @param $component
* @param $filearea
* @param $itemid
* @param $filepath
* @param $filename
* @param string $component component
* @param string $filearea file area
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info|null
*/
public function get_file_info($component, $filearea, $itemid, $filepath, $filename) {
// try to emulate require_login() tests here
@@ -119,6 +130,14 @@ class file_info_context_module extends file_info {
return null;
}
/**
* Get a file from module intro area
*
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info|null
*/
protected function get_area_intro($itemid, $filepath, $filename) {
global $CFG;
@@ -143,6 +162,14 @@ class file_info_context_module extends file_info {
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, get_string('moduleintro'), false, true, true, false);
}
/**
* Get a file from module backup area
*
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info|null
*/
protected function get_area_backup($itemid, $filepath, $filename) {
global $CFG;
@@ -172,6 +199,7 @@ class file_info_context_module extends file_info {
/**
* Returns localised visible name.
*
* @return string
*/
public function get_visible_name() {
@@ -179,7 +207,8 @@ class file_info_context_module extends file_info {
}
/**
* Can I add new files or directories?
* Whether or not files or directories can be added
*
* @return bool
*/
public function is_writable() {
@@ -187,7 +216,7 @@ class file_info_context_module extends file_info {
}
/**
* Is this empty area?
* Whether or not this is an emtpy area
*
* @return bool
*/
@@ -215,7 +244,8 @@ class file_info_context_module extends file_info {
}
/**
* Is directory?
* Whether or not this is a directory
*
* @return bool
*/
public function is_directory() {
@@ -224,6 +254,7 @@ class file_info_context_module extends file_info {
/**
* Returns list of children.
*
* @return array of file_info instances
*/
public function get_children() {
@@ -247,7 +278,8 @@ class file_info_context_module extends file_info {
/**
* Returns parent file_info instance
* @return file_info or null for root
*
* @return file_info|null file_info or null for root
*/
public function get_parent() {
$pcid = get_parent_contextid($this->context);
+24 -14
View File
@@ -1,5 +1,4 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -19,8 +18,7 @@
/**
* Utility class for browsing of system files.
*
* @package core
* @subpackage filebrowser
* @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -28,25 +26,32 @@
defined('MOODLE_INTERNAL') || die();
/**
* Represents the system context in the tree navigated by @see{file_browser}.
* Represents the system context in the tree navigated by {@link file_browser}.
*
* @package core
* @subpackage filebrowser
* @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class file_info_context_system extends file_info {
/**
* Constructor
*
* @param file_browser $browser file_browser instance
* @param stdClass $context context object
*/
public function __construct($browser, $context) {
parent::__construct($browser, $context);
}
/**
* Return information about this specific part of context level
* @param $component
* @param $filearea
* @param $itemid
* @param $filepath
* @param $filename
*
* @param string $component component
* @param string $filearea file area
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
*/
public function get_file_info($component, $filearea, $itemid, $filepath, $filename) {
if (empty($component)) {
@@ -59,6 +64,7 @@ class file_info_context_system extends file_info {
/**
* Returns localised visible name.
*
* @return string
*/
public function get_visible_name() {
@@ -66,7 +72,8 @@ class file_info_context_system extends file_info {
}
/**
* Can I add new files or directories?
* Whether or not new files or directories can be added
*
* @return bool
*/
public function is_writable() {
@@ -74,7 +81,8 @@ class file_info_context_system extends file_info {
}
/**
* Is directory?
* Whether or not this is a directory
*
* @return bool
*/
public function is_directory() {
@@ -83,6 +91,7 @@ class file_info_context_system extends file_info {
/**
* Returns list of children.
*
* @return array of file_info instances
*/
public function get_children() {
@@ -121,7 +130,8 @@ class file_info_context_system extends file_info {
/**
* Returns parent file_info instance
* @return file_info or null for root
*
* @return file_info|null file_info instance or null for root
*/
public function get_parent() {
return null;
+59 -14
View File
@@ -1,5 +1,4 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -19,8 +18,7 @@
/**
* Utility class for browsing of user files.
*
* @package core
* @subpackage filebrowser
* @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -28,16 +26,23 @@
defined('MOODLE_INTERNAL') || die();
/**
* Represents a user context in the tree navigated by @see{file_browser}.
* Represents a user context in the tree navigated by {@link file_browser}.
*
* @package core
* @subpackage filebrowser
* @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class file_info_context_user extends file_info {
/** @var stdClass User object */
protected $user;
/**
* Constructor
*
* @param file_browser $browser
* @param stdClass $context
* @param stdClass $user
*/
public function __construct($browser, $context, $user) {
parent::__construct($browser, $context);
$this->user = $user;
@@ -46,11 +51,12 @@ class file_info_context_user extends file_info {
/**
* Return information about this specific context level
*
* @param $component
* @param $filearea
* @param $itemid
* @param $filepath
* @param $filename
* @param string $component componet
* @param string $filearea file area
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info|null
*/
public function get_file_info($component, $filearea, $itemid, $filepath, $filename) {
global $USER;
@@ -76,6 +82,15 @@ class file_info_context_user extends file_info {
return null;
}
/**
* Get a file from user private area
*
* @todo MDL-31070 this method should respect $CFG->userquota
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info|null
*/
protected function get_area_user_private($itemid, $filepath, $filename) {
global $USER, $CFG;
@@ -110,6 +125,14 @@ class file_info_context_user extends file_info {
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, get_string('areauserpersonal', 'repository'), false, true, true, false);
}
/**
* Get a file from user profile area
*
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info|null
*/
protected function get_area_user_profile($itemid, $filepath, $filename) {
global $CFG;
@@ -144,6 +167,14 @@ class file_info_context_user extends file_info {
get_string('areauserprofile', 'repository'), false, $readaccess, $writeaccess, false);
}
/**
* Get a file from user draft area
*
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info|null
*/
protected function get_area_user_draft($itemid, $filepath, $filename) {
global $USER, $CFG;
@@ -174,6 +205,15 @@ class file_info_context_user extends file_info {
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, get_string('areauserdraft', 'repository'), true, true, true, true);
}
/**
* Get a file from user backup area
*
* @todo MDL-31091 maybe we need new caability for access control
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info|null
*/
protected function get_area_user_backup($itemid, $filepath, $filename) {
global $USER, $CFG;
@@ -206,6 +246,7 @@ class file_info_context_user extends file_info {
/**
* Returns localised visible name.
*
* @return string
*/
public function get_visible_name() {
@@ -213,7 +254,8 @@ class file_info_context_user extends file_info {
}
/**
* Can I add new files or directories?
* Whether or not new files or directories can be added
*
* @return bool
*/
public function is_writable() {
@@ -221,7 +263,8 @@ class file_info_context_user extends file_info {
}
/**
* Is directory?
* Whether or not this is a directory
*
* @return bool
*/
public function is_directory() {
@@ -230,6 +273,7 @@ class file_info_context_user extends file_info {
/**
* Returns list of children.
*
* @return array of file_info instances
*/
public function get_children() {
@@ -253,7 +297,8 @@ class file_info_context_user extends file_info {
/**
* Returns parent file_info instance
* @return file_info or null for root
*
* @return file_info|null file_info instance or null for root
*/
public function get_parent() {
return $this->browser->get_file_info();
+64 -37
View File
@@ -1,5 +1,4 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -19,38 +18,42 @@
/**
* Utility class for browsing of stored files.
*
* @package core
* @subpackage filebrowser
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Represents an actual file or folder - a row in the file table -
* in the tree navigated by @see{file_browser}.
* Represents an actual file or folder - a row in the file table in the tree navigated by {@link file_browser}.
*
* @package core
* @subpackage filebrowser
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class file_info_stored extends file_info {
/** @var stored_file|virtual_root_file stored_file or virtual_root_file instance */
protected $lf;
/** @var string the serving script */
protected $urlbase;
/** @var string the human readable name of this area */
protected $topvisiblename;
/** @var int|bool it's false if itemid is 0 and not included in URL */
protected $itemidused;
/** @var bool allow file reading */
protected $readaccess;
/** @var bool allow file write, delee */
protected $writeaccess;
/** @var string do not show links to parent context/area */
protected $areaonly;
/**
* Constructor
*
* @param file_browser $browser
* @param stdClass $context
* @param stored_file|virtual_root_file $storedfile
* @param file_browser $browser file browser instance
* @param stdClass $context context object
* @param stored_file|virtual_root_file $storedfile stored_file instance
* @param string $urlbase the serving script - usually the $CFG->wwwroot/.'pluginfile.php'
* @param string $topvisiblename the human readable name of this area
* @param int|bool $itemidused false if itemid always 0 and not included in URL
@@ -74,6 +77,7 @@ class file_info_stored extends file_info {
* Returns list of standard virtual file/directory identification.
* The difference from stored_file parameters is that null values
* are allowed in all fields
*
* @return array with keys contextid, component, filearea, itemid, filepath and filename
*/
public function get_params() {
@@ -87,6 +91,7 @@ class file_info_stored extends file_info {
/**
* Returns localised visible name.
*
* @return string
*/
public function get_visible_name() {
@@ -110,8 +115,9 @@ class file_info_stored extends file_info {
/**
* Returns file download url
* @param bool $forcedownload
* @param bool $htts force https
*
* @param bool $forcedownload Whether or not force download
* @param bool $https whether or not force https
* @return string url
*/
public function get_url($forcedownload=false, $https=false) {
@@ -140,7 +146,8 @@ class file_info_stored extends file_info {
}
/**
* Can I read content of this file or enter directory?
* Whether or not I can read content of this file or enter directory
*
* @return bool
*/
public function is_readable() {
@@ -148,7 +155,8 @@ class file_info_stored extends file_info {
}
/**
* Can I add new files or directories?
* Whether or not new files or directories can be added
*
* @return bool
*/
public function is_writable() {
@@ -156,7 +164,7 @@ class file_info_stored extends file_info {
}
/**
* Is this top of empty area?
* Whether or not this is an empty area
*
* @return bool
*/
@@ -172,6 +180,7 @@ class file_info_stored extends file_info {
/**
* Returns file size in bytes, null for directories
*
* @return int bytes or null if not known
*/
public function get_filesize() {
@@ -180,6 +189,7 @@ class file_info_stored extends file_info {
/**
* Returns mimetype
*
* @return string mimetype or null if not known
*/
public function get_mimetype() {
@@ -188,6 +198,7 @@ class file_info_stored extends file_info {
/**
* Returns time created unix timestamp if known
*
* @return int timestamp or null
*/
public function get_timecreated() {
@@ -196,6 +207,7 @@ class file_info_stored extends file_info {
/**
* Returns time modified unix timestamp if known
*
* @return int timestamp or null
*/
public function get_timemodified() {
@@ -203,7 +215,8 @@ class file_info_stored extends file_info {
}
/**
* Is directory?
* Whether or not this is a directory
*
* @return bool
*/
public function is_directory() {
@@ -212,6 +225,7 @@ class file_info_stored extends file_info {
/**
* Returns the license type of the file
*
* @return string license short name or null
*/
public function get_license() {
@@ -220,6 +234,7 @@ class file_info_stored extends file_info {
/**
* Returns the author name of the file
*
* @return string author name or null
*/
public function get_author() {
@@ -228,6 +243,7 @@ class file_info_stored extends file_info {
/**
* Returns the source of the file
*
* @return string a source url or null
*/
public function get_source() {
@@ -236,6 +252,7 @@ class file_info_stored extends file_info {
/**
* Returns the sort order of the file
*
* @return int
*/
public function get_sortorder() {
@@ -244,6 +261,7 @@ class file_info_stored extends file_info {
/**
* Returns list of children.
*
* @return array of file_info instances
*/
public function get_children() {
@@ -266,7 +284,8 @@ class file_info_stored extends file_info {
/**
* Returns parent file_info instance
* @return file_info or null for root
*
* @return file_info|null file_info instance or null for root
*/
public function get_parent() {
if ($this->lf->get_filepath() === '/' and $this->lf->is_directory()) {
@@ -296,9 +315,10 @@ class file_info_stored extends file_info {
/**
* Create new directory, may throw exception - make sure
* params are valid.
*
* @param string $newdirname name of new directory
* @param int id of author, default $USER->id
* @return file_info new directory
* @param int $userid id of author, default $USER->id
* @return file_info|null new directory's file_info instance or null if failed
*/
public function create_directory($newdirname, $userid = NULL) {
if (!$this->is_writable() or !$this->lf->is_directory()) {
@@ -324,10 +344,11 @@ class file_info_stored extends file_info {
/**
* Create new file from string - make sure
* params are valid.
*
* @param string $newfilename name of new file
* @param string $content of file
* @param int id of author, default $USER->id
* @return file_info new file
* @param int $userid id of author, default $USER->id
* @return file_info|null new file's file_info instance or null if failed
*/
public function create_file_from_string($newfilename, $content, $userid = NULL) {
if (!$this->is_writable() or !$this->lf->is_directory()) {
@@ -370,10 +391,11 @@ class file_info_stored extends file_info {
/**
* Create new file from pathname - make sure
* params are valid.
*
* @param string $newfilename name of new file
* @param string $pathname location of file
* @param int id of author, default $USER->id
* @return file_info new file
* @param int $userid id of author, default $USER->id
* @return file_info|null new file's file_info instance or null if failed
*/
public function create_file_from_pathname($newfilename, $pathname, $userid = NULL) {
if (!$this->is_writable() or !$this->lf->is_directory()) {
@@ -416,10 +438,11 @@ class file_info_stored extends file_info {
/**
* Create new file from stored file - make sure
* params are valid.
*
* @param string $newfilename name of new file
* @param mixed file id or stored_file of file
* @param int id of author, default $USER->id
* @return file_info new file
* @param int|stored_file $fid file id or stored_file of file
* @param int $userid id of author, default $USER->id
* @return file_info|null new file's file_info instance or null if failed
*/
public function create_file_from_storedfile($newfilename, $fid, $userid = NULL) {
if (!$this->is_writable() or $this->lf->get_filename() !== '.') {
@@ -461,6 +484,7 @@ class file_info_stored extends file_info {
/**
* Delete file, make sure file is deletable first.
*
* @return bool success
*/
public function delete() {
@@ -484,12 +508,14 @@ class file_info_stored extends file_info {
/**
* Copy content of this file to local storage, overriding current file if needed.
* @param int $contextid
* @param string $filearea
* @param int $itemid
* @param string $filepath
* @param string $filename
* @return boolean success
*
* @param int $contextid context ID
* @param string $component file component
* @param string $filearea file area
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return bool success
*/
public function copy_to_storage($contextid, $component, $filearea, $itemid, $filepath, $filename) {
if (!$this->is_readable() or $this->is_directory()) {
@@ -508,8 +534,9 @@ class file_info_stored extends file_info {
/**
* Copy content of this file to local storage, overriding current file if needed.
*
* @param string $pathname real local full file name
* @return boolean success
* @return bool success
*/
public function copy_to_pathname($pathname) {
if (!$this->is_readable() or $this->is_directory()) {
+132 -21
View File
@@ -1,5 +1,4 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -19,8 +18,7 @@
/**
* Class simulating empty directories.
*
* @package core
* @subpackage filebrowser
* @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -28,22 +26,29 @@
defined('MOODLE_INTERNAL') || die();
/**
* Represents the root directory of an empty file area in the tree navigated by
* @see{file_browser}.
* Represents the root directory of an empty file area in the tree navigated by {@link file_browser}.
*
* @package core
* @subpackage filebrowser
* @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class virtual_root_file {
/** @var int context id */
protected $contextid;
/** @var string file component */
protected $component;
/** @var string file area */
protected $filearea;
/** @var int file itemid */
protected $itemid;
/**
* Constructor
*
* @param int $contextid context ID
* @param string $component component
* @param string $filearea file area
* @param int $itemid item ID
*/
public function __construct($contextid, $component, $filearea, $itemid) {
$this->contextid = $contextid;
@@ -53,7 +58,8 @@ class virtual_root_file {
}
/**
* Is this a directory?
* Whether or not this is a directory
*
* @return bool
*/
public function is_directory() {
@@ -62,6 +68,7 @@ class virtual_root_file {
/**
* Delete file
*
* @return success
*/
public function delete() {
@@ -80,7 +87,8 @@ class virtual_root_file {
/**
* Returns file handle - read only mode, no writing allowed into pool files!
* @return file handle
*
* @return resource file handle
*/
public function get_content_file_handle() {
return null;
@@ -88,7 +96,8 @@ class virtual_root_file {
/**
* Dumps file content to page
* @return file handle
*
* @return resource file handle
*/
public function readfile() {
return;
@@ -96,6 +105,7 @@ class virtual_root_file {
/**
* Returns file content as string
*
* @return string content
*/
public function get_content() {
@@ -104,6 +114,7 @@ class virtual_root_file {
/**
* Copy content of file to given pathname
*
* @param string $pathname real path to new file
* @return bool success
*/
@@ -113,7 +124,8 @@ class virtual_root_file {
/**
* List contents of archive
* @param object $file_packer
*
* @param file_packer $packer file packer instance
* @return array of file infos
*/
public function list_files(file_packer $packer) {
@@ -122,7 +134,8 @@ class virtual_root_file {
/**
* Extract file to given file path (real OS filesystem), existing files are overwrited
* @param object $file_packer
*
* @param file_packer $packer file packer instance
* @param string $pathname target directory
* @return mixed list of processed files; false if error
*/
@@ -132,13 +145,14 @@ class virtual_root_file {
/**
* Extract file to given file path (real OS filesystem), existing files are overwrited
* @param object $file_packer
* @param int $contextid
* @param string $component
* @param string $filearea
* @param int $itemid
* @param string $pathbase
* @param int $userid
*
* @param file_packer $packer file packer instance
* @param int $contextid context ID
* @param string $component component
* @param string $filearea file area
* @param int $itemid item ID
* @param string $pathbase path base
* @param int $userid user ID
* @return mixed list of processed files; false if error
*/
public function extract_to_storage(file_packer $packer, $contextid, $component, $filearea, $itemid, $pathbase, $userid = NULL) {
@@ -147,7 +161,8 @@ class virtual_root_file {
/**
* Add file/directory into archive
* @param object $filearch
*
* @param file_archive $filearch file archive instance
* @param string $archivepath pathname in archive
* @return bool success
*/
@@ -157,84 +172,180 @@ class virtual_root_file {
/**
* Returns parent directory
* @return object stored_file
*
* @return stored_file
*/
public function get_parent_directory() {
return null;
}
/**
* Returns context ID
*
* @return int context ID
*/
public function get_contextid() {
return $this->contextid;
}
/**
* Returns file component
*
* @return string component
*/
public function get_component() {
return $this->component;
}
/**
* Returns file area
*
* @return string filearea
*/
public function get_filearea() {
return $this->filearea;
}
/**
* Returns file itemid
*
* @return int itemid
*/
public function get_itemid() {
return $this->itemid;
}
/**
* Returns file path
*
* @return string filepath
*/
public function get_filepath() {
return '/';
}
/**
* Returns file name
*
* @return string filename
*/
public function get_filename() {
return '.';
}
/**
* Returns user ID
*
* @return int userid
*/
public function get_userid() {
return null;
}
/**
* Returns file size
*
* @return int filesize
*/
public function get_filesize() {
return 0;
}
/**
* Returns mimetype
*
* @return string mimetype
*/
public function get_mimetype() {
return null;
}
/**
* Returns time created
*
* @return int
*/
public function get_timecreated() {
return 0;
}
/**
* Returns time modified
*
* @return int
*/
public function get_timemodified() {
return 0;
}
/**
* Returns status
*
* @return int
*/
public function get_status() {
return 0;
}
/**
* Returns ID
*
* @return int
*/
public function get_id() {
return 0;
}
/**
* Returns sha1 hash code
*
* @return string
*/
public function get_contenthash() {
return sha1('');
}
/**
* Returns path name hash
*
* @return string
*/
public function get_pathnamehash() {
return sha1('/'.$this->get_contextid().'/'.$this->get_component().'/'.$this->get_filearea().'/'.$this->get_itemid().$this->get_filepath().$this->get_filename());
}
/**
* Returns license
*
* @return string
*/
public function get_license() {
return null;
}
/**
* Returns file's author
*
* @return string
*/
public function get_author() {
return null;
}
/**
* Returns file source
*
* @return string
*/
public function get_source() {
return null;
}
/**
* Returns file sort order
*
* @return int
*/
public function get_sortorder() {
return null;
}
+182 -131
View File
@@ -1,5 +1,4 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -18,15 +17,16 @@
/**
* Functions for file handling.
*
* @package core
* @subpackage file
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core_files
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/** @var string unique string constant. */
/**
* BYTESERVING_BOUNDARY - string unique string constant.
*/
define('BYTESERVING_BOUNDARY', 's1k2o3d4a5k6s7');
require_once("$CFG->libdir/filestorage/file_exceptions.php");
@@ -39,7 +39,8 @@ require_once("$CFG->libdir/filebrowser/file_browser.php");
*
* @deprecated use moodle_url factory methods instead
*
* @global object
* @todo MDL-31071 deprecate this function
* @global stdClass $CFG
* @param string $urlbase
* @param string $path /filearea/itemid/dir/dir/file.exe
* @param bool $forcedownload
@@ -84,14 +85,15 @@ function file_encode_url($urlbase, $path, $forcedownload=false, $https=false) {
* In your mform definition, you must have an 'editor' element called foobar_editor. Then you call
* your mform's set_data() supplying the object returned by this function.
*
* @param object $data database field that holds the html text with embedded media
* @category files
* @param stdClass $data database field that holds the html text with embedded media
* @param string $field the name of the database field that holds the html text with embedded media
* @param array $options editor options (like maxifiles, maxbytes etc.)
* @param object $context context of the editor
* @param stdClass $context context of the editor
* @param string $component
* @param string $filearea file area name
* @param int $itemid item id, required if item exists
* @return object modified data object
* @return stdClass modified data object
*/
function file_prepare_standard_editor($data, $field, array $options, $context=null, $component=null, $filearea=null, $itemid=null) {
$options = (array)$options;
@@ -178,14 +180,15 @@ function file_prepare_standard_editor($data, $field, array $options, $context=nu
* function automatically adds $data properties foobar, foobarformat and
* foobartrust, where foobar has URL to embedded files encoded.
*
* @param object $data raw data submitted by the form
* @category files
* @param stdClass $data raw data submitted by the form
* @param string $field name of the database field containing the html with embedded media files
* @param array $options editor options (trusttext, subdirs, maxfiles, maxbytes etc.)
* @param object $context context, required for existing data
* @param string component
* @param stdClass $context context, required for existing data
* @param string $component file component
* @param string $filearea file area name
* @param int $itemid item id, required if item exists
* @return object modified data object
* @return stdClass modified data object
*/
function file_postupdate_standard_editor($data, $field, array $options, $context, $component=null, $filearea=null, $itemid=null) {
$options = (array)$options;
@@ -226,14 +229,15 @@ function file_postupdate_standard_editor($data, $field, array $options, $context
/**
* Saves text and files modified by Editor formslib element
*
* @param object $data $database entry field
* @category files
* @param stdClass $data $database entry field
* @param string $field name of data field
* @param array $options various options
* @param object $context context - must already exist
* @param stdClass $context context - must already exist
* @param string $component
* @param string $filearea file area name
* @param int $itemid must already exist, usually means data is in db
* @return object modified data obejct
* @return stdClass modified data obejct
*/
function file_prepare_standard_filemanager($data, $field, array $options, $context=null, $component=null, $filearea=null, $itemid=null) {
$options = (array)$options;
@@ -257,14 +261,16 @@ function file_prepare_standard_filemanager($data, $field, array $options, $conte
/**
* Saves files modified by File manager formslib element
*
* @param object $data $database entry field
* @todo MDL-31073 review this function
* @category files
* @param stdClass $data $database entry field
* @param string $field name of data field
* @param array $options various options
* @param object $context context - must already exist
* @param stdClass $context context - must already exist
* @param string $component
* @param string $filearea file area name
* @param int $itemid must already exist, usually means data is in db
* @return object modified data obejct
* @return stdClass modified data obejct
*/
function file_postupdate_standard_filemanager($data, $field, array $options, $context, $component, $filearea, $itemid) {
$options = (array)$options;
@@ -296,9 +302,11 @@ function file_postupdate_standard_filemanager($data, $field, array $options, $co
}
/**
* Generate a draft itemid
*
* @global object
* @global object
* @category files
* @global moodle_database $DB
* @global stdClass $USER
* @return int a random but available draft itemid that can be used to create a new draft
* file area.
*/
@@ -326,16 +334,17 @@ function file_get_unused_draft_itemid() {
* area will be created if one does not already exist. Normally you should
* get $draftitemid by calling file_get_submitted_draft_itemid('elementname');
*
* @global object
* @global object
* @param int &$draftitemid the id of the draft area to use, or 0 to create a new one, in which case this parameter is updated.
* @param integer $contextid This parameter and the next two identify the file area to copy files from.
* @category files
* @global stdClass $CFG
* @global stdClass $USER
* @param int $draftitemid the id of the draft area to use, or 0 to create a new one, in which case this parameter is updated.
* @param int $contextid This parameter and the next two identify the file area to copy files from.
* @param string $component
* @param string $filearea helps indentify the file area.
* @param integer $itemid helps identify the file area. Can be null if there are no files yet.
* @param int $itemid helps identify the file area. Can be null if there are no files yet.
* @param array $options text and file options ('subdirs'=>false, 'forcehttps'=>false)
* @param string $text some html content that needs to have embedded links rewritten to point to the draft area.
* @return string if $text was passed in, the rewritten $text is returned. Otherwise NULL.
* @return string|null returns string if $text was passed in, the rewritten $text is returned. Otherwise NULL.
*/
function file_prepare_draft_area(&$draftitemid, $contextid, $component, $filearea, $itemid, array $options=null, $text=null) {
global $CFG, $USER, $CFG;
@@ -389,13 +398,14 @@ function file_prepare_draft_area(&$draftitemid, $contextid, $component, $fileare
/**
* Convert encoded URLs in $text from the @@PLUGINFILE@@/... form to an actual URL.
*
* @global object
* @category files
* @global stdClass $CFG
* @param string $text The content that may contain ULRs in need of rewriting.
* @param string $file The script that should be used to serve these files. pluginfile.php, draftfile.php, etc.
* @param integer $contextid This parameter and the next two identify the file area to use.
* @param int $contextid This parameter and the next two identify the file area to use.
* @param string $component
* @param string $filearea helps identify the file area.
* @param integer $itemid helps identify the file area.
* @param int $itemid helps identify the file area.
* @param array $options text and file options ('forcehttps'=>false)
* @return string the processed text.
*/
@@ -427,9 +437,9 @@ function file_rewrite_pluginfile_urls($text, $file, $contextid, $component, $fil
/**
* Returns information about files in a draft area.
*
* @global object
* @global object
* @param integer $draftitemid the draft area item id.
* @global stdClass $CFG
* @global stdClass $USER
* @param int $draftitemid the draft area item id.
* @return array with the following entries:
* 'filecount' => number of files in the draft area.
* (more information will be added as needed).
@@ -455,6 +465,8 @@ function file_get_draft_area_info($draftitemid) {
/**
* Get used space of files
* @global moodle_database $DB
* @global stdClass $USER
* @return int total bytes
*/
function file_get_user_used_space() {
@@ -473,6 +485,7 @@ function file_get_user_used_space() {
/**
* Convert any string to a valid filepath
* @todo review this function
* @param string $str
* @return string path
*/
@@ -486,9 +499,11 @@ function file_correct_filepath($str) { //TODO: what is this? (skodak)
/**
* Generate a folder tree of draft area of current USER recursively
* @param int $itemid
*
* @todo MDL-31073 use normal return value instead, this does not fit the rest of api here (skodak)
* @param int $draftitemid
* @param string $filepath
* @param mixed $data //TODO: use normal return value instead, this does not fit the rest of api here (skodak)
* @param mixed $data
*/
function file_get_drafarea_folders($draftitemid, $filepath, &$data) {
global $USER, $OUTPUT, $CFG;
@@ -520,7 +535,7 @@ function file_get_drafarea_folders($draftitemid, $filepath, &$data) {
* used by file manager
* @param int $draftitemid
* @param string $filepath
* @return mixed
* @return stdClass
*/
function file_get_drafarea_files($draftitemid, $filepath = '/') {
global $USER, $OUTPUT, $CFG;
@@ -587,8 +602,9 @@ function file_get_drafarea_files($draftitemid, $filepath = '/') {
/**
* Returns draft area itemid for a given element.
*
* @category files
* @param string $elname name of formlib editor element, or a hidden form field that stores the draft area item id, etc.
* @return integer the itemid, or 0 if there is not one yet.
* @return int the itemid, or 0 if there is not one yet.
*/
function file_get_submitted_draft_itemid($elname) {
// this is a nasty hack, ideally all new elements should use arrays here or there should be a new parameter
@@ -619,19 +635,19 @@ function file_get_submitted_draft_itemid($elname) {
* Saves files from a draft file area to a real one (merging the list of files).
* Can rewrite URLs in some content at the same time if desired.
*
* @global object
* @global object
* @param integer $draftitemid the id of the draft area to use. Normally obtained
* @category files
* @global stdClass $USER
* @param int $draftitemid the id of the draft area to use. Normally obtained
* from file_get_submitted_draft_itemid('elementname') or similar.
* @param integer $contextid This parameter and the next two identify the file area to save to.
* @param int $contextid This parameter and the next two identify the file area to save to.
* @param string $component
* @param string $filearea indentifies the file area.
* @param integer $itemid helps identifies the file area.
* @param int $itemid helps identifies the file area.
* @param array $options area options (subdirs=>false, maxfiles=-1, maxbytes=0)
* @param string $text some html content that needs to have embedded links rewritten
* to the @@PLUGINFILE@@ form for saving in the database.
* @param boolean $forcehttps force https urls.
* @return string if $text was passed in, the rewritten $text is returned. Otherwise NULL.
* @param bool $forcehttps force https urls.
* @return string|null if $text was passed in, the rewritten $text is returned. Otherwise NULL.
*/
function file_save_draft_area_files($draftitemid, $contextid, $component, $filearea, $itemid, array $options=null, $text=null, $forcehttps=false) {
global $USER;
@@ -752,6 +768,8 @@ function file_save_draft_area_files($draftitemid, $contextid, $component, $filea
* Convert the draft file area URLs in some content to @@PLUGINFILE@@ tokens
* ready to be saved in the database. Normally, this is done automatically by
* {@link file_save_draft_area_files()}.
*
* @category files
* @param string $text the content to process.
* @param int $draftitemid the draft file area the content was using.
* @param bool $forcehttps whether the content contains https URLs. Default false.
@@ -787,15 +805,16 @@ function file_rewrite_urls_to_pluginfile($text, $draftitemid, $forcehttps = fals
/**
* Set file sort order
* @global object $DB
* @param integer $contextid the context id
* @param string $component
*
* @global moodle_database $DB
* @param int $contextid the context id
* @param string $component file component
* @param string $filearea file area.
* @param integer $itemid itemid.
* @param int $itemid itemid.
* @param string $filepath file path.
* @param string $filename file name.
* @param integer $sortorer the sort order of file.
* @return boolean
* @param int $sortorder the sort order of file.
* @return bool
*/
function file_set_sortorder($contextid, $component, $filearea, $itemid, $filepath, $filename, $sortorder) {
global $DB;
@@ -811,12 +830,12 @@ function file_set_sortorder($contextid, $component, $filearea, $itemid, $filepat
/**
* reset file sort order number to 0
* @global object $DB
* @param integer $contextid the context id
* @global moodle_database $DB
* @param int $contextid the context id
* @param string $component
* @param string $filearea file area.
* @param integer $itemid itemid.
* @return boolean
* @param int|bool $itemid itemid.
* @return bool
*/
function file_reset_sortorder($contextid, $component, $filearea, $itemid=false) {
global $DB;
@@ -923,13 +942,12 @@ function format_postdata_for_curlcall($postdata) {
return $convertedpostdata;
}
/**
* Fetches content of file from Internet (using proxy if defined). Uses cURL extension if present.
* Due to security concerns only downloads from http(s) sources are supported.
*
* @todo MDL-31073 add version test for '7.10.5'
* @category files
* @param string $url file url starting with http(s)://
* @param array $headers http headers, null if none. If set, should be an
* associative array of header name => value pairs.
@@ -1160,6 +1178,10 @@ function download_file_content($url, $headers=null, $postdata=null, $fullrespons
/**
* internal implementation
* @param stdClass $received
* @param resource $ch
* @param mixed $header
* @return int header length
*/
function download_file_content_header_handler($received, $ch, $header) {
$received->headers[] = $header;
@@ -1168,6 +1190,9 @@ function download_file_content_header_handler($received, $ch, $header) {
/**
* internal implementation
* @param stdClass $received
* @param resource $ch
* @param mixed $data
*/
function download_file_content_write_handler($received, $ch, $data) {
if (!$received->fh) {
@@ -1185,6 +1210,9 @@ function download_file_content_write_handler($received, $ch, $data) {
}
/**
* Returns a list of information about file t ypes based on extensions
*
* @category files
* @return array List of information about file types based on extensions.
* Associative array of extension (lower-case) to associative array
* from 'element name' to data. Current element names are 'type' and 'icon'.
@@ -1372,6 +1400,7 @@ function get_mimetypes_array() {
* use a default if no information is present about that particular
* extension.
*
* @category files
* @param string $element Desired information (usually 'icon'
* for icon filename or 'type' for MIME type)
* @param string $filename Filename we're looking up
@@ -1413,6 +1442,7 @@ function mimeinfo($element, $filename) {
* Obtains information about a filetype based on the MIME type rather than
* the other way around.
*
* @category files
* @param string $element Desired information (usually 'icon')
* @param string $mimetype MIME type we're looking up
* @return string Requested piece of information from array
@@ -1434,9 +1464,10 @@ function mimeinfo_from_type($element, $mimetype) {
/**
* Get information about a filetype based on the icon file.
*
* @category files
* @param string $element Desired information (usually 'icon')
* @param string $icon Icon file name without extension
* @param boolean $all return all matching entries (defaults to false - best (by ext)/last match)
* @param bool $all return all matching entries (defaults to false - best (by ext)/last match)
* @return string Requested piece of information from array
*/
function mimeinfo_from_icon($element, $icon, $all=false) {
@@ -1486,9 +1517,9 @@ function mimeinfo_from_icon($element, $icon, $all=false) {
* echo '<img src="'.$icon.'" alt="'.$mimetype.'" />';
* </code>
*
* @todo When an $OUTPUT->icon method is available this function should be altered
* @category files
* @todo MDL-31074 When an $OUTPUT->icon method is available this function should be altered
* to conform with that.
*
* @param string $mimetype The mimetype to fetch an icon for
* @param int $size The size of the icon. Not yet implemented
* @return string The relative path to the icon
@@ -1517,11 +1548,11 @@ function file_mimetype_icon($mimetype, $size = NULL) {
* echo '<img src="'.$icon.'" alt="blah" />';
* </code>
*
* @todo When an $OUTPUT->icon method is available this function should be altered
* @todo MDL-31074 When an $OUTPUT->icon method is available this function should be altered
* to conform with that.
* @todo Implement $size
*
* @param string filename The filename to get the icon for
* @todo MDL-31074 Implement $size
* @category files
* @param string $filename The filename to get the icon for
* @param int $size The size of the icon. Defaults to null can also be 32
* @return string
*/
@@ -1558,9 +1589,10 @@ function get_mimetype_description($mimetype, $capitalise=false) {
}
/**
* Requested file is not found or not accessible
* Requested file is not found or not accessible, does not return, terminates script
*
* @return does not return, terminates script
* @global stdClass $CFG
* @global stdClass $COURSE
*/
function send_file_not_found() {
global $CFG, $COURSE;
@@ -1572,8 +1604,7 @@ function send_file_not_found() {
* Check output buffering settings before sending file.
* Please note you should not send any other headers after calling this function.
*
* @private to be called only from lib/filelib.php !
* @return void
* To be called only from lib/filelib.php !
*/
function prepare_file_content_sending() {
// We needed to be able to send headers up until now
@@ -1606,12 +1637,11 @@ function prepare_file_content_sending() {
/**
* Handles the sending of temporary file to user, download is forced.
* File is deleted after abort or successful sending.
* File is deleted after abort or successful sending, does not return, script terminated
*
* @param string $path path to file, preferably from moodledata/temp/something; or content of file itself
* @param string $filename proposed file name when saving file
* @param bool $path is content of file
* @return does not return, script terminated
* @param bool $pathisstring If the path is string
*/
function send_temp_file($path, $filename, $pathisstring=false) {
global $CFG;
@@ -1664,6 +1694,8 @@ function send_temp_file($path, $filename, $pathisstring=false) {
/**
* Internal callback function used by send_temp_file()
*
* @param string $path
*/
function send_temp_file_finished($path) {
if (file_exists($path)) {
@@ -1675,9 +1707,10 @@ function send_temp_file_finished($path) {
* Handles the sending of file data to the user's browser, including support for
* byteranges etc.
*
* @global object
* @global object
* @global object
* @category files
* @global stdClass $CFG
* @global stdClass $COURSE
* @global moodle_session $SESSION
* @param string $path Path of file on disk (including real filename), or actual content of file as string
* @param string $filename Filename to send
* @param int $lifetime Number of seconds before the file should expire from caches (default 24 hours)
@@ -1689,7 +1722,7 @@ function send_temp_file_finished($path) {
* if this is passed as true, ignore_user_abort is called. if you don't want your processing to continue on cancel,
* you must detect this case when control is returned using connection_aborted. Please not that session is closed
* and should not be reopened.
* @return no return or void, script execution stopped unless $dontdie is true
* @return null script execution stopped unless $dontdie is true
*/
function send_file($path, $filename, $lifetime = 'default' , $filter=0, $pathisstring=false, $forcedownload=false, $mimetype='', $dontdie=false) {
global $CFG, $COURSE, $SESSION;
@@ -1907,10 +1940,11 @@ function send_file($path, $filename, $lifetime = 'default' , $filter=0, $pathiss
* Handles the sending of file data to the user's browser, including support for
* byteranges etc.
*
* @global object
* @global object
* @global object
* @param object $stored_file local file object
* @category files
* @global stdClass $CFG
* @global stdClass $COURSE
* @global moodle_session $SESSION
* @param stored_file $stored_file local file object
* @param int $lifetime Number of seconds before the file should expire from caches (default 24 hours)
* @param int $filter 0 (default)=no filtering, 1=all files, 2=html files only
* @param bool $forcedownload If true (default false), forces download of file rather than view in browser/plugin
@@ -1919,7 +1953,7 @@ function send_file($path, $filename, $lifetime = 'default' , $filter=0, $pathiss
* if this is passed as true, ignore_user_abort is called. if you don't want your processing to continue on cancel,
* you must detect this case when control is returned using connection_aborted. Please not that session is closed
* and should not be reopened.
* @return void no return or void, script execution stopped unless $dontdie is true
* @return null script execution stopped unless $dontdie is true
*/
function send_stored_file($stored_file, $lifetime=86400 , $filter=0, $forcedownload=false, $filename=null, $dontdie=false) {
global $CFG, $COURSE, $SESSION;
@@ -2110,8 +2144,8 @@ function send_stored_file($stored_file, $lifetime=86400 , $filter=0, $forcedownl
* Retrieves an array of records from a CSV file and places
* them into a given table structure
*
* @global object
* @global object
* @global stdClass $CFG
* @global moodle_database $DB
* @param string $file The path to a CSV file
* @param string $table The table to retrieve columns from
* @return bool|array Returns an array of CSV records or false
@@ -2157,9 +2191,10 @@ function get_records_csv($file, $table) {
}
/**
* Create a file with CSV contents
*
* @global object
* @global object
* @global stdClass $CFG
* @global moodle_database $DB
* @param string $file The file to put the CSV content into
* @param array $records An array of records to write to a CSV file
* @param string $table The table to get columns from
@@ -2271,10 +2306,11 @@ function fulldelete($location) {
/**
* Send requested byterange of file.
*
* @param object $handle A file handle
* @param resource $handle A file handle
* @param string $mimetype The mimetype for the output
* @param array $ranges An array of ranges to send
* @param string $filesize The size of the content if only one range is used
* @todo MDL-31088 check if "multipart/x-byteranges" is more compatible with current readers/browsers/servers
*/
function byteserving_send_file($handle, $mimetype, $ranges, $filesize) {
$chunksize = 1*(1024*1024); // 1MB chunks - must be less than 2MB!
@@ -2341,9 +2377,10 @@ function byteserving_send_file($handle, $mimetype, $ranges, $filesize) {
* add includes (js and css) into uploaded files
* before returning them, useful for themes and utf.js includes
*
* @global object
* @global stdClass $CFG
* @param string $text text to search and replace
* @return string text with added head includes
* @todo MDL-21120
*/
function file_modify_html_header($text) {
// first look for <head> tag
@@ -2412,37 +2449,44 @@ function file_modify_html_header($text) {
* $html = $c->put('http://example.com/', array('file'=>'/var/www/test.txt');
* </code>
*
* @package core
* @subpackage file
* @author Dongsheng Cai <dongsheng@cvs.moodle.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package core_files
* @category files
* @copyright Dongsheng Cai <dongsheng@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
class curl {
/** @var bool */
/** @var bool Caches http request contents */
public $cache = false;
/** @var bool Uses proxy */
public $proxy = false;
/** @var string */
/** @var string library version */
public $version = '0.4 dev';
/** @var array */
/** @var array http's response */
public $response = array();
/** @var array http header */
public $header = array();
/** @var string */
/** @var string cURL information */
public $info;
/** @var string error */
public $error;
/** @var array */
/** @var array cURL options */
private $options;
/** @var string */
/** @var string Proxy host */
private $proxy_host = '';
/** @var string Proxy auth */
private $proxy_auth = '';
/** @var string Proxy type */
private $proxy_type = '';
/** @var bool */
/** @var bool Debug mode on */
private $debug = false;
/** @var bool|string Path to cookie file */
private $cookie = false;
/**
* @global object
* Constructor
*
* @global stdClass $CFG
* @param array $options
*/
public function __construct($options = array()){
@@ -2545,7 +2589,6 @@ class curl {
*
* @param array $options If array is null, this function will
* reset the options to default value.
*
*/
public function setopt($options = array()) {
if (is_array($options)) {
@@ -2557,9 +2600,9 @@ class curl {
}
}
}
/**
* Reset http method
*
*/
public function cleanopt(){
unset($this->options['CURLOPT_HTTPGET']);
@@ -2574,8 +2617,7 @@ class curl {
/**
* Set HTTP Request Header
*
* @param array $headers
*
* @param array $header
*/
public function setHeader($header) {
if (is_array($header)){
@@ -2586,6 +2628,7 @@ class curl {
$this->header[] = $header;
}
}
/**
* Set HTTP Response Header
*
@@ -2593,11 +2636,12 @@ class curl {
public function getResponse(){
return $this->response;
}
/**
* private callback function
* Formatting HTTP Response Header
*
* @param mixed $ch Apparently not used
* @param resource $ch Apparently not used
* @param string $header
* @return int The strlen of the header
*/
@@ -2627,9 +2671,9 @@ class curl {
/**
* Set options for individual curl instance
*
* @param object $curl A curl handle
* @param resource $curl A curl handle
* @param array $options
* @return object The curl handle
* @return resource The curl handle
*/
private function apply_opt($curl, $options) {
// Clean up
@@ -2674,6 +2718,7 @@ class curl {
}
return $curl;
}
/**
* Download multiple files in parallel
*
@@ -2696,7 +2741,8 @@ class curl {
$options['RETURNTRANSFER'] = false;
return $this->multi($requests, $options);
}
/*
/**
* Mulit HTTP Requests
* This function could run multi-requests in parallel.
*
@@ -2733,6 +2779,7 @@ class curl {
curl_multi_close($main);
return $results;
}
/**
* Single HTTP Request
*
@@ -2869,7 +2916,7 @@ class curl {
* HTTP DELETE method
*
* @param string $url
* @param array $params
* @param array $param
* @param array $options
* @return bool
*/
@@ -2881,6 +2928,7 @@ class curl {
$ret = $this->request($url, $options);
return $ret;
}
/**
* HTTP TRACE method
*
@@ -2893,6 +2941,7 @@ class curl {
$ret = $this->request($url, $options);
return $ret;
}
/**
* HTTP OPTIONS method
*
@@ -2905,6 +2954,12 @@ class curl {
$ret = $this->request($url, $options);
return $ret;
}
/**
* Get curl information
*
* @return string
*/
public function get_info() {
return $this->info;
}
@@ -2921,19 +2976,19 @@ class curl {
* $ret = $c->get('http://www.google.com');
* </code>
*
* @package core
* @subpackage file
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core_files
* @copyright Dongsheng Cai <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class curl_cache {
/** @var string */
/** @var string Path to cache directory */
public $dir = '';
/**
* Constructor
*
* @global object
* @param string @module which module is using curl_cache
*
* @global stdClass $CFG
* @param string $module which module is using curl_cache
*/
function __construct($module = 'repository'){
global $CFG;
@@ -2961,8 +3016,8 @@ class curl_cache {
/**
* Get cached value
*
* @global object
* @global object
* @global stdClass $CFG
* @global stdClass $USER
* @param mixed $param
* @return bool|string
*/
@@ -3039,20 +3094,20 @@ class curl_cache {
}
/**
* This class is used to parse lib/file/file_types.mm which help get file
* extensions by file types.
* This class is used to parse lib/file/file_types.mm which help get file extensions by file types.
*
* The file_types.mm file can be edited by freemind in graphic environment.
*
* @package core
* @subpackage file
* @copyright 2009 Dongsheng Cai <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core_files
* @category files
* @copyright 2009 Dongsheng Cai <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class filetype_parser {
/**
* Check file_types.mm file, setup variables
*
* @global object $CFG
* @global stdClass $CFG
* @param string $file
*/
public function __construct($file = '') {
@@ -3146,11 +3201,7 @@ class filetype_parser {
*
* @param string $relativepath
* @param bool $forcedownload
*
* @package core
* @subpackage file
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @todo MDL-31088 file serving improments
*/
function file_pluginfile($relativepath, $forcedownload) {
global $DB, $CFG, $USER;
+26 -19
View File
@@ -1,5 +1,4 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -19,10 +18,9 @@
/**
* Abstraction of general file archives.
*
* @package core
* @subpackage filestorage
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
@@ -30,10 +28,9 @@ defined('MOODLE_INTERNAL') || die();
/**
* Each file archive type must extend this class.
*
* @package core
* @subpackage filestorage
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class file_archive implements Iterator {
@@ -46,12 +43,13 @@ abstract class file_archive implements Iterator {
/** Always create new archive */
const OVERWRITE = 4;
/** Encoding of file names - windows usually expects DOS single-byte charset*/
/** @var string Encoding of file names - windows usually expects DOS single-byte charset*/
protected $encoding = 'utf-8';
/**
* Open or create archive (depending on $mode)
* @param string $archivepathname
*
* @param string $archivepathname archive path name
* @param int $mode OPEN, CREATE or OVERWRITE constant
* @param string $encoding archive local paths encoding
* @return bool success
@@ -60,38 +58,44 @@ abstract class file_archive implements Iterator {
/**
* Close archive
*
* @return bool success
*/
public abstract function close();
/**
* Returns file stream for reading of content
* @param int $index of file
* @return stream or false if error
*
* @param int $index index of file
* @return stream|bool stream or false if error
*/
public abstract function get_stream($index);
/**
* Returns file information
* @param int $index of file
* @return info object or false if error
*
* @param int $index index of file
* @return stdClass|bool object or false if error
*/
public abstract function get_info($index);
/**
* Returns array of info about all files in archive
*
* @return array of file infos
*/
public abstract function list_files();
/**
* Returns number of files in archive
*
* @return int number of files
*/
public abstract function count();
/**
* Add file into archive
*
* @param string $localname name of file in archive
* @param string $pathname location of file
* @return bool success
@@ -100,15 +104,17 @@ abstract class file_archive implements Iterator {
/**
* Add content of string into archive
*
* @param string $localname name of file in archive
* @param string $contents
* @param string $contents contents
* @return bool success
*/
public abstract function add_file_from_string($localname, $contents);
/**
* Add empty directory into archive
* @param string $local
*
* @param string $localname name of file in archive
* @return bool success
*/
public abstract function add_directory($localname);
@@ -116,7 +122,8 @@ abstract class file_archive implements Iterator {
/**
* Tries to convert $localname into another encoding,
* please note that it may fail really badly.
* @param string $localname in utf-8 encoding
*
* @param string $localname name of file in utf-8 encoding
* @return string
*/
protected function mangle_pathname($localname) {
@@ -161,7 +168,7 @@ abstract class file_archive implements Iterator {
* please note that it may fail really badly.
* The resulting file name is cleaned.
*
* @param string $localname in $this->encoding
* @param string $localname name of file in $this->encoding
* @return string in utf-8
*/
protected function unmangle_pathname($localname) {
+48 -21
View File
@@ -1,5 +1,4 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -18,10 +17,9 @@
/**
* File handling related exceptions.
*
* @package core
* @subpackage filestorage
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
@@ -29,12 +27,19 @@ defined('MOODLE_INTERNAL') || die();
/**
* Basic file related exception class
*
* @package core
* @subpackage filestorage
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core_files
* @category files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class file_exception extends moodle_exception {
/**
* Constructor
*
* @param string $errorcode error code
* @param stdClass $a Extra words and phrases that might be required in the error string
* @param string $debuginfo optional debugging information
*/
function __construct($errorcode, $a=NULL, $debuginfo = NULL) {
parent::__construct($errorcode, '', '', $a, $debuginfo);
}
@@ -43,12 +48,23 @@ class file_exception extends moodle_exception {
/**
* Can not create file exception
*
* @package core
* @subpackage filestorage
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core_files
* @category files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class stored_file_creation_exception extends file_exception {
/**
* Constructor
*
* @param int $contextid context ID
* @param string $component component
* @param string $filearea file area
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @param string $debuginfo extra debug info
*/
function __construct($contextid, $component, $filearea, $itemid, $filepath, $filename, $debuginfo = NULL) {
$a = new stdClass();
$a->contextid = $contextid;
@@ -64,12 +80,17 @@ class stored_file_creation_exception extends file_exception {
/**
* No file access exception.
*
* @package core
* @subpackage filestorage
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core_files
* @category files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class file_access_exception extends file_exception {
/**
* Constructor
*
* @param string $debuginfo extra debug info
*/
function __construct($debuginfo = NULL) {
parent::__construct('nopermissions', NULL, $debuginfo);
}
@@ -78,12 +99,18 @@ class file_access_exception extends file_exception {
/**
* Hash file content problem exception.
*
* @package core
* @subpackage filestorage
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core_files
* @category files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class file_pool_content_exception extends file_exception {
/**
* Constructor
*
* @param string $contenthash content hash
* @param string $debuginfo extra debug info
*/
function __construct($contenthash, $debuginfo = NULL) {
parent::__construct('hashpoolproblem', $contenthash, $debuginfo);
}
+30 -25
View File
@@ -1,5 +1,4 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -19,10 +18,9 @@
/**
* Abstraction of general file packer.
*
* @package core
* @subpackage filestorage
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
@@ -30,28 +28,30 @@ defined('MOODLE_INTERNAL') || die();
/**
* Abstract class for archiving of files.
*
* @package core
* @subpackage filestorage
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class file_packer {
/**
* Archive files and store the result in file storage
*
* @param array $files array with zip paths as keys (archivepath=>ospathname or archivepath=>stored_file)
* @param int $contextid
* @param string $component
* @param string $filearea
* @param int $itemid
* @param string $filepath
* @param string $filename
* @return mixed false if error stored file instance if ok
* @param int $contextid context ID
* @param string $component component
* @param string $filearea file area
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @param int $userid user ID
* @return stored_file|bool false if error stored file instance if ok
*/
public abstract function archive_to_storage($files, $contextid, $component, $filearea, $itemid, $filepath, $filename, $userid = NULL);
/**
* Archive files and store the result in os file
*
* @param array $files array with zip paths as keys (archivepath=>ospathname or archivepath=>stored_file)
* @param string $archivefile path to target zip file
* @return bool success
@@ -60,26 +60,31 @@ abstract class file_packer {
/**
* Extract file to given file path (real OS filesystem), existing files are overwrited
* @param mixed $archivefile full pathname of zip file or stored_file instance
*
* @param stored_file|string $archivefile full pathname of zip file or stored_file instance
* @param string $pathname target directory
* @return mixed list of processed files; false if error
* @return array|bool list of processed files; false if error
*/
public abstract function extract_to_pathname($archivefile, $pathname);
/**
* Extract file to given file path (real OS filesystem), existing files are overwrited
* @param mixed $archivefile full pathname of zip file or stored_file instance
* @param int $contextid
* @param string $component
* @param string $filearea
* @param int $itemid
* @param string $filepath
* @return mixed list of processed files; false if error
*
* @param string|stored_file $archivefile full pathname of zip file or stored_file instance
* @param int $contextid context ID
* @param string $component component
* @param string $filearea file area
* @param int $itemid item ID
* @param string $pathbase file path
* @param int $userid user ID
* @return array|bool list of processed files; false if error
*/
public abstract function extract_to_storage($archivefile, $contextid, $component, $filearea, $itemid, $pathbase, $userid = NULL);
/**
* Returns array of info about all files in archive
*
* @param file_archive $archivefile
* @return array of file infos
*/
public abstract function list_files($archivefile);
+85 -85
View File
@@ -1,5 +1,4 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -19,10 +18,9 @@
/**
* Core file storage class definition.
*
* @package core
* @subpackage filestorage
* @copyright 2008 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core_files
* @copyright 2008 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
@@ -38,6 +36,8 @@ require_once("$CFG->libdir/filestorage/stored_file.php");
* files of modules it has to use file_browser class instead or there
* has to be some callback API.
*
* @package core_files
* @category files
* @copyright 2008 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
@@ -55,7 +55,7 @@ class file_storage {
private $filepermissions;
/**
* Constructor - do not use directly use @see get_file_storage() call instead.
* Constructor - do not use directly use {@link get_file_storage()} call instead.
*
* @param string $filedir full path to pool directory
* @param string $trashdir temporary storage of deleted area
@@ -95,12 +95,12 @@ class file_storage {
* This hash is a unique file identifier - it is used to improve
* performance and overcome db index size limits.
*
* @param int $contextid
* @param string $component
* @param string $filearea
* @param int $itemid
* @param string $filepath
* @param string $filename
* @param int $contextid context ID
* @param string $component component
* @param string $filearea file area
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return string sha1 hash
*/
public static function get_pathname_hash($contextid, $component, $filearea, $itemid, $filepath, $filename) {
@@ -110,12 +110,12 @@ class file_storage {
/**
* Does this file exist?
*
* @param int $contextid
* @param string $component
* @param string $filearea
* @param int $itemid
* @param string $filepath
* @param string $filename
* @param int $contextid context ID
* @param string $component component
* @param string $filearea file area
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return bool
*/
public function file_exists($contextid, $component, $filearea, $itemid, $filepath, $filename) {
@@ -131,9 +131,9 @@ class file_storage {
}
/**
* Does this file exist?
* Whether or not the file exist
*
* @param string $pathnamehash
* @param string $pathnamehash path name hash
* @return bool
*/
public function file_exists_by_hash($pathnamehash) {
@@ -158,8 +158,8 @@ class file_storage {
* Please do not rely on file ids, it is usually easier to use
* pathname hashes instead.
*
* @param int $fileid
* @return stored_file instance if exists, false if not
* @param int $fileid file ID
* @return stored_file|bool stored_file instance if exists, false if not
*/
public function get_file_by_id($fileid) {
global $DB;
@@ -174,8 +174,8 @@ class file_storage {
/**
* Fetch file using local file full pathname hash
*
* @param string $pathnamehash
* @return stored_file instance if exists, false if not
* @param string $pathnamehash path name hash
* @return stored_file|bool stored_file instance if exists, false if not
*/
public function get_file_by_hash($pathnamehash) {
global $DB;
@@ -190,13 +190,13 @@ class file_storage {
/**
* Fetch locally stored file.
*
* @param int $contextid
* @param string $component
* @param string $filearea
* @param int $itemid
* @param string $filepath
* @param string $filename
* @return stored_file instance if exists, false if not
* @param int $contextid context ID
* @param string $component component
* @param string $filearea file area
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return stored_file|bool stored_file instance if exists, false if not
*/
public function get_file($contextid, $component, $filearea, $itemid, $filepath, $filename) {
$filepath = clean_param($filepath, PARAM_PATH);
@@ -212,11 +212,12 @@ class file_storage {
/**
* Are there any files (or directories)
* @param int $contextid
* @param string $component
* @param string $filearea
* @param bool|int $itemid tem id or false if all items
* @param bool $ignoredirs
*
* @param int $contextid context ID
* @param string $component component
* @param string $filearea file area
* @param bool|int $itemid item id or false if all items
* @param bool $ignoredirs whether or not ignore directories
* @return bool empty
*/
public function is_area_empty($contextid, $component, $filearea, $itemid = false, $ignoredirs = true) {
@@ -246,12 +247,12 @@ class file_storage {
/**
* Returns all area files (optionally limited by itemid)
*
* @param int $contextid
* @param string $component
* @param string $filearea
* @param int $itemid (all files if not specified)
* @param string $sort
* @param bool $includedirs
* @param int $contextid context ID
* @param string $component component
* @param string $filearea file area
* @param int $itemid item ID or all files if not specified
* @param string $sort sort fields
* @param bool $includedirs whether or not include directories
* @return array of stored_files indexed by pathanmehash
*/
public function get_area_files($contextid, $component, $filearea, $itemid = false, $sort="sortorder, itemid, filepath, filename", $includedirs = true) {
@@ -276,10 +277,10 @@ class file_storage {
/**
* Returns array based tree structure of area files
*
* @param int $contextid
* @param string $component
* @param string $filearea
* @param int $itemid
* @param int $contextid context ID
* @param string $component component
* @param string $filearea file area
* @param int $itemid item ID
* @return array each dir represented by dirname, subdirs, files and dirfile array elements
*/
public function get_area_tree($contextid, $component, $filearea, $itemid) {
@@ -327,14 +328,14 @@ class file_storage {
/**
* Returns all files and optionally directories
*
* @param int $contextid
* @param string $component
* @param string $filearea
* @param int $itemid
* @param int $contextid context ID
* @param string $component component
* @param string $filearea file area
* @param int $itemid item ID
* @param int $filepath directory path
* @param bool $recursive include all subdirectories
* @param bool $includedirs include files and directories
* @param string $sort
* @param string $sort sort fields
* @return array of stored_files indexed by pathanmehash
*/
public function get_directory_files($contextid, $component, $filearea, $itemid, $filepath, $recursive = false, $includedirs = true, $sort = "filepath, filename") {
@@ -412,10 +413,10 @@ class file_storage {
/**
* Delete all area files (optionally limited by itemid).
*
* @param int $contextid
* @param string $component
* @param string $filearea (all areas in context if not specified)
* @param int $itemid (all files if not specified)
* @param int $contextid context ID
* @param string $component component
* @param string $filearea file area or all areas in context if not specified
* @param int $itemid item ID or all files if not specified
* @return bool success
*/
public function delete_area_files($contextid, $component = false, $filearea = false, $itemid = false) {
@@ -473,11 +474,13 @@ class file_storage {
/**
* Move all the files in a file area from one context to another.
* @param integer $oldcontextid the context the files are being moved from.
* @param integer $newcontextid the context the files are being moved to.
*
* @param int $oldcontextid the context the files are being moved from.
* @param int $newcontextid the context the files are being moved to.
* @param string $component the plugin that these files belong to.
* @param string $filearea the name of the file area.
* @return integer the number of files moved, for information.
* @param int $itemid file item ID
* @return int the number of files moved, for information.
*/
public function move_area_files_to_new_context($oldcontextid, $newcontextid, $component, $filearea, $itemid = false) {
// Note, this code is based on some code that Petr wrote in
@@ -503,12 +506,12 @@ class file_storage {
/**
* Recursively creates directory.
*
* @param int $contextid
* @param string $component
* @param string $filearea
* @param int $itemid
* @param string $filepath
* @param string $filename
* @param int $contextid context ID
* @param string $component component
* @param string $filearea file area
* @param int $itemid item ID
* @param string $filepath file path
* @param int $userid the user ID
* @return bool success
*/
public function create_directory($contextid, $component, $filearea, $itemid, $filepath, $userid = null) {
@@ -589,8 +592,8 @@ class file_storage {
/**
* Add new local file based on existing local file.
*
* @param mixed $file_record object or array describing changes
* @param mixed $fileorid id or stored_file instance of the existing local file
* @param stdClass|array $file_record object or array describing changes
* @param stored_file|int $fileorid id or stored_file instance of the existing local file
* @return stored_file instance of newly created file
*/
public function create_file_from_storedfile($file_record, $fileorid) {
@@ -695,11 +698,11 @@ class file_storage {
/**
* Add new local file.
*
* @param mixed $file_record object or array describing file
* @param string $path path to file or content of file
* @param array $options @see download_file_content() options
* @param stdClass|array $file_record object or array describing file
* @param string $url the URL to the file
* @param array $options {@link download_file_content()} options
* @param bool $usetempfile use temporary file for download, may prevent out of memory problems
* @return stored_file instance
* @return stored_file
*/
public function create_file_from_url($file_record, $url, array $options = NULL, $usetempfile = false) {
@@ -750,9 +753,9 @@ class file_storage {
/**
* Add new local file.
*
* @param mixed $file_record object or array describing file
* @param string $path path to file or content of file
* @return stored_file instance
* @param stdClass|array $file_record object or array describing file
* @param string $pathname path to file or content of file
* @return stored_file
*/
public function create_file_from_pathname($file_record, $pathname) {
global $DB;
@@ -864,9 +867,9 @@ class file_storage {
/**
* Add new local file.
*
* @param mixed $file_record object or array describing file
* @param stdClass|array $file_record object or array describing file
* @param string $content content of file
* @return stored_file instance
* @return stored_file
*/
public function create_file_from_string($file_record, $content) {
global $DB;
@@ -978,13 +981,13 @@ class file_storage {
/**
* Creates new image file from existing.
*
* @param mixed $file_record object or array describing new file
* @param mixed file id or stored file object
* @param stdClass|array $file_record object or array describing new file
* @param int|stored_file $fid file id or stored file object
* @param int $newwidth in pixels
* @param int $newheight in pixels
* @param bool $keepaspectratio
* @param bool $keepaspectratio whether or not keep aspect ratio
* @param int $quality depending on image type 0-100 for jpeg, 0-9 (0 means no compression) for png
* @return stored_file instance
* @return stored_file
*/
public function convert_image($file_record, $fid, $newwidth = NULL, $newheight = NULL, $keepaspectratio = true, $quality = NULL) {
if (!function_exists('imagecreatefromstring')) {
@@ -1189,7 +1192,7 @@ class file_storage {
*
* NOTE: must not be public, files in pool must not be modified
*
* @param string $contenthash
* @param string $contenthash content hash
* @return string expected file location
*/
protected function path_from_hash($contenthash) {
@@ -1203,7 +1206,7 @@ class file_storage {
*
* NOTE: must not be public, files in pool must not be modified
*
* @param string $contenthash
* @param string $contenthash content hash
* @return string expected file location
*/
protected function trash_path_from_hash($contenthash) {
@@ -1215,7 +1218,7 @@ class file_storage {
/**
* Tries to recover missing content of file from trash.
*
* @param object $file_record
* @param stored_file $file stored_file instance
* @return bool success
*/
public function try_content_recovery($file) {
@@ -1252,7 +1255,6 @@ class file_storage {
* DO NOT call directly - reserved for core!!
*
* @param string $contenthash
* @return void
*/
public function deleted_file_cleanup($contenthash) {
global $DB;
@@ -1285,8 +1287,6 @@ class file_storage {
/**
* Cron cleanup job.
*
* @return void
*/
public function cron() {
global $CFG, $DB;
+19 -20
View File
@@ -1,5 +1,4 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -19,10 +18,9 @@
/**
* Definition of a class stored_file.
*
* @package core
* @subpackage filestorage
* @copyright 2008 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core_files
* @copyright 2008 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
@@ -35,6 +33,8 @@ require_once("$CFG->libdir/filestorage/stored_file.php");
* Since Moodle 2.0 file contents are stored in sha1 pool and
* all other file information is stored in new "files" database table.
*
* @package core_files
* @category files
* @copyright 2008 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
@@ -42,7 +42,7 @@ require_once("$CFG->libdir/filestorage/stored_file.php");
class stored_file {
/** @var file_storage file storage pool instance */
private $fs;
/** @var object record from the files table */
/** @var stdClass record from the files table */
private $file_record;
/** @var string location of content files */
private $filedir;
@@ -51,8 +51,8 @@ class stored_file {
* Constructor, this constructor should be called ONLY from the file_storage class!
*
* @param file_storage $fs file storage instance
* @param object $file_record description of file
* @param string $filepool location of file directory with sh1 named content files
* @param stdClass $file_record description of file
* @param string $filedir location of file directory with sh1 named content files
*/
public function __construct(file_storage $fs, stdClass $file_record, $filedir) {
$this->fs = $fs;
@@ -133,8 +133,6 @@ class stored_file {
/**
* Dumps file content to page.
*
* @return void
*/
public function readfile() {
$path = $this->get_content_file_location();
@@ -180,7 +178,7 @@ class stored_file {
/**
* List contents of archive.
*
* @param file_packer $file_packer
* @param file_packer $packer file packer instance
* @return array of file infos
*/
public function list_files(file_packer $packer) {
@@ -191,7 +189,7 @@ class stored_file {
/**
* Extract file to given file path (real OS filesystem), existing files are overwritten.
*
* @param file_packer $file_packer
* @param file_packer $packer file packer instance
* @param string $pathname target directory
* @return array|bool list of processed files; false if error
*/
@@ -203,13 +201,13 @@ class stored_file {
/**
* Extract file to given file path (real OS filesystem), existing files are overwritten.
*
* @param file_packer $file_packer
* @param int $contextid
* @param string $component
* @param string $filearea
* @param int $itemid
* @param string $pathbase
* @param int $userid
* @param file_packer $packer file packer instance
* @param int $contextid context ID
* @param string $component component
* @param string $filearea file area
* @param int $itemid item ID
* @param string $pathbase path base
* @param int $userid user ID
* @return array|bool list of processed files; false if error
*/
public function extract_to_storage(file_packer $packer, $contextid, $component, $filearea, $itemid, $pathbase, $userid = NULL) {
@@ -220,7 +218,7 @@ class stored_file {
/**
* Add file/directory into archive.
*
* @param file_archive $filearch
* @param file_archive $filearch file archive instance
* @param string $archivepath pathname in archive
* @return bool success
*/
@@ -239,6 +237,7 @@ class stored_file {
/**
* Returns information about image,
* information is determined from the file content
*
* @return mixed array with width, height and mimetype; false if not an image
*/
public function get_imageinfo() {
+35 -26
View File
@@ -1,5 +1,4 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -19,10 +18,9 @@
/**
* Implementation of zip file archive.
*
* @package core
* @subpackage filestorage
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
@@ -32,27 +30,29 @@ require_once("$CFG->libdir/filestorage/file_archive.php");
/**
* zip file archive class.
*
* @package core
* @subpackage filestorage
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core_files
* @category files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class zip_archive extends file_archive {
/** Pathname of archive */
/** @var string Pathname of archive */
protected $archivepathname = null;
/** Used memory tracking */
/** @var int Used memory tracking */
protected $usedmem = 0;
/** Iteration position */
/** @var int Iteration position */
protected $pos = 0;
/** TipArchive instance */
/** @var zip_archive TipArchive instance */
protected $za;
/**
* Open or create archive (depending on $mode)
*
* @todo MDL-31048 return error message
* @param string $archivepathname
* @param int $mode OPEN, CREATE or OVERWRITE constant
* @param string $encoding archive local paths encoding
@@ -95,6 +95,7 @@ class zip_archive extends file_archive {
/**
* Close archive
*
* @return bool success
*/
public function close() {
@@ -110,8 +111,9 @@ class zip_archive extends file_archive {
/**
* Returns file stream for reading of content
* @param int $index of file
* @return resource or false if error
*
* @param int $index index of file
* @return resource|bool file handle or false if error
*/
public function get_stream($index) {
if (!isset($this->za)) {
@@ -128,8 +130,9 @@ class zip_archive extends file_archive {
/**
* Returns file information
* @param int $index of file
* @return info object or false if error
*
* @param int $index index of file
* @return stdClass info object or false if error
*/
public function get_info($index) {
if (!isset($this->za)) {
@@ -165,6 +168,7 @@ class zip_archive extends file_archive {
/**
* Returns array of info about all files in archive
*
* @return array of file infos
*/
public function list_files() {
@@ -187,6 +191,7 @@ class zip_archive extends file_archive {
/**
* Returns number of files in archive
*
* @return int number of files
*/
public function count() {
@@ -199,6 +204,7 @@ class zip_archive extends file_archive {
/**
* Add file into archive
*
* @param string $localname name of file in archive
* @param string $pathname location of file
* @return bool success
@@ -230,7 +236,7 @@ class zip_archive extends file_archive {
$this->close();
$res = $this->open($this->archivepathname, file_archive::OPEN, $this->encoding);
if ($res !== true) {
print_error('cannotopenzip'); //TODO ??
print_error('cannotopenzip');
}
}
}
@@ -240,8 +246,9 @@ class zip_archive extends file_archive {
/**
* Add content of string into archive
*
* @param string $localname name of file in archive
* @param string $contents
* @param string $contents contents
* @return bool success
*/
public function add_file_from_string($localname, $contents) {
@@ -258,11 +265,11 @@ class zip_archive extends file_archive {
}
if ($this->usedmem > 2097151) {
/// this prevents running out of memory when adding many large files using strings
// this prevents running out of memory when adding many large files using strings
$this->close();
$res = $this->open($this->archivepathname, file_archive::OPEN, $this->encoding);
if ($res !== true) {
print_error('cannotopenzip'); //TODO ??
print_error('cannotopenzip');
}
}
$this->usedmem += strlen($contents);
@@ -273,7 +280,8 @@ class zip_archive extends file_archive {
/**
* Add empty directory into archive
* @param string $local
*
* @param string $localname name of file in archive
* @return bool success
*/
public function add_directory($localname) {
@@ -293,7 +301,8 @@ class zip_archive extends file_archive {
/**
* Returns current file info
* @return object
*
* @return stdClass
*/
public function current() {
if (!isset($this->za)) {
@@ -305,6 +314,7 @@ class zip_archive extends file_archive {
/**
* Returns the index of current file
*
* @return int current file index
*/
public function key() {
@@ -313,7 +323,6 @@ class zip_archive extends file_archive {
/**
* Moves forward to next file
* @return void
*/
public function next() {
$this->pos++;
@@ -321,7 +330,6 @@ class zip_archive extends file_archive {
/**
* Rewinds back to the first file
* @return void
*/
public function rewind() {
$this->pos = 0;
@@ -329,7 +337,8 @@ class zip_archive extends file_archive {
/**
* Did we reach the end?
* @return boolean
*
* @return bool
*/
public function valid() {
if (!isset($this->za)) {
+47 -25
View File
@@ -1,5 +1,4 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -19,10 +18,9 @@
/**
* Implementation of zip packer.
*
* @package core
* @subpackage filestorage
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
@@ -33,24 +31,26 @@ require_once("$CFG->libdir/filestorage/zip_archive.php");
/**
* Utility class - handles all zipping and unzipping operations.
*
* @package core
* @subpackage filestorage
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package core_files
* @category files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class zip_packer extends file_packer {
/**
* Zip files and store the result in file storage
*
* @param array $files array with full zip paths (including directory information)
* as keys (archivepath=>ospathname or archivepath/subdir=>stored_file or archivepath=>array('content_as_string'))
* @param int $contextid
* @param string $component
* @param string $filearea
* @param int $itemid
* @param string $filepath
* @param string $filename
* @return mixed false if error stored file instance if ok
* @param int $contextid context ID
* @param string $component component
* @param string $filearea file area
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @param int $userid user ID
* @return stored_file|bool false if error stored file instance if ok
*/
public function archive_to_storage($files, $contextid, $component, $filearea, $itemid, $filepath, $filename, $userid = NULL) {
global $CFG;
@@ -85,6 +85,7 @@ class zip_packer extends file_packer {
/**
* Zip files and store the result in os file
*
* @param array $files array with zip paths as keys (archivepath=>ospathname or archivepath=>stored_file or archivepath=>array('content_as_string'))
* @param string $archivefile path to target zip file
* @return bool success
@@ -121,6 +122,13 @@ class zip_packer extends file_packer {
return $ziparch->close();
}
/**
* Perform archiving file from stored file
*
* @param zip_archive $ziparch zip archive instance
* @param string $archivepath file path to archive
* @param stored_file $file stored_file object
*/
private function archive_stored($ziparch, $archivepath, $file) {
$file->archive_file($ziparch, $archivepath);
@@ -143,6 +151,13 @@ class zip_packer extends file_packer {
}
}
/**
* Perform archiving file from file path
*
* @param zip_archive $ziparch zip archive instance
* @param string $archivepath file path to archive
* @param string $file path name of the file
*/
private function archive_pathname($ziparch, $archivepath, $file) {
if (!file_exists($file)) {
return;
@@ -174,9 +189,11 @@ class zip_packer extends file_packer {
/**
* Unzip file to given file path (real OS filesystem), existing files are overwrited
* @param mixed $archivefile full pathname of zip file or stored_file instance
*
* @todo MDL-31048 localise messages
* @param string|stored_file $archivefile full pathname of zip file or stored_file instance
* @param string $pathname target directory
* @return mixed list of processed files; false if error
* @return bool|array list of processed files; false if error
*/
public function extract_to_pathname($archivefile, $pathname) {
global $CFG;
@@ -267,13 +284,16 @@ class zip_packer extends file_packer {
/**
* Unzip file to given file path (real OS filesystem), existing files are overwrited
* @param mixed $archivefile full pathname of zip file or stored_file instance
* @param int $contextid
* @param string $component
* @param string $filearea
* @param int $itemid
* @param string $filepath
* @return mixed list of processed files; false if error
*
* @todo MDL-31048 localise messages
* @param string|stored_file $archivefile full pathname of zip file or stored_file instance
* @param int $contextid context ID
* @param string $component component
* @param string $filearea file area
* @param int $itemid item ID
* @param string $pathbase file path
* @param int $userid user ID
* @return array|bool list of processed files; false if error
*/
public function extract_to_storage($archivefile, $contextid, $component, $filearea, $itemid, $pathbase, $userid = NULL) {
global $CFG;
@@ -414,6 +434,8 @@ class zip_packer extends file_packer {
/**
* Returns array of info about all files in archive
*
* @param file_archive $archivefile
* @return array of file infos
*/
public function list_files($archivefile) {
+13 -6
View File
@@ -1649,14 +1649,16 @@ class question_edit_contexts {
/**
* Helps call file_rewrite_pluginfile_urls with the right parameters.
*
* @package core_question
* @category files
* @param string $text text being processed
* @param string $file the php script used to serve files
* @param int $contextid
* @param int $contextid context ID
* @param string $component component
* @param string $filearea filearea
* @param array $ids other IDs will be used to check file permission
* @param int $itemid
* @param array $options
* @param int $itemid item ID
* @param array $options options
* @return string
*/
function question_rewrite_question_urls($text, $file, $contextid, $component,
@@ -1729,8 +1731,10 @@ function question_send_questiontext_file($questionid, $args, $forcedownload) {
*
* Does not return, either calls send_file_not_found(); or serves the file.
*
* @param object $course course settings object
* @param object $context context object
* @package core_question
* @category files
* @param stdClass $course course settings object
* @param stdClass $context context object
* @param string $component the name of the component we are serving files for.
* @param string $filearea the name of the file area.
* @param array $args the remaining bits of the file path.
@@ -1840,7 +1844,10 @@ function question_pluginfile($course, $context, $component, $filearea, $args, $f
/**
* Serve questiontext files in the question text when they are displayed in this report.
* @param context $context the context
*
* @package core_files
* @category files
* @param stdClass $context the context
* @param int $questionid the question id
* @param array $args remaining file args
* @param bool $forcedownload
+14 -10
View File
@@ -3025,12 +3025,14 @@ function assignment_get_participants($assignmentid) {
/**
* Serves assignment submissions and other files.
*
* @param object $course
* @param object $cm
* @param object $context
* @param string $filearea
* @param array $args
* @param bool $forcedownload
* @package mod_assignment
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @return bool false if file not found, does not return if found - just send the file
*/
function assignment_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
@@ -3927,10 +3929,12 @@ function assignment_pack_files($filesforzipping) {
/**
* Lists all file areas current user may browse
*
* @param object $course
* @param object $cm
* @param object $context
* @return array
* @package mod_assignment
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @return array available file areas
*/
function assignment_get_file_areas($course, $cm, $context) {
$areas = array();
+13 -9
View File
@@ -2844,9 +2844,11 @@ function data_get_exportdata($dataid, $fields, $selectedfields) {
/**
* Lists all browsable file areas
*
* @param object $course
* @param object $cm
* @param object $context
* @package mod_data
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @return array
*/
function data_get_file_areas($course, $cm, $context) {
@@ -2857,12 +2859,14 @@ function data_get_file_areas($course, $cm, $context) {
/**
* Serves the data attachments. Implements needed access control ;-)
*
* @param object $course
* @param object $cm
* @param object $context
* @param string $filearea
* @param array $args
* @param bool $forcedownload
* @package mod_data
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @return bool false if file not found, does not return if found - justsend the file
*/
function data_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
+8 -6
View File
@@ -140,12 +140,14 @@ function feedback_update_instance($feedback) {
* There are two situations in general where the files will be sent.
* 1) filearea = item, 2) filearea = template
*
* @param object $course
* @param object $cm
* @param object $context
* @param string $filearea
* @param array $args
* @param bool $forcedownload
* @package mod_feedback
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @return bool false if file not found, does not return if found - justsend the file
*/
function feedback_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
+27 -19
View File
@@ -217,9 +217,12 @@ function folder_get_participants($folderid) {
/**
* Lists all browsable file areas
* @param object $course
* @param object $cm
* @param object $context
*
* @package mod_folder
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @return array
*/
function folder_get_file_areas($course, $cm, $context) {
@@ -231,16 +234,19 @@ function folder_get_file_areas($course, $cm, $context) {
/**
* File browsing support for folder module content area.
* @param object $browser
* @param object $areas
* @param object $course
* @param object $cm
* @param object $context
* @param string $filearea
* @param int $itemid
* @param string $filepath
* @param string $filename
* @return object file_info instance or null if not found
*
* @package mod_folder
* @category files
* @param file_browser $browser file browser instance
* @param array $areas file areas
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info instance or null if not found
*/
function folder_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename) {
global $CFG;
@@ -279,12 +285,14 @@ function folder_get_file_info($browser, $areas, $course, $cm, $context, $fileare
/**
* Serves the folder files.
*
* @param object $course
* @param object $cm
* @param object $context
* @param string $filearea
* @param array $args
* @param bool $forcedownload
* @package mod_folder
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @return bool false if file not found, does not return if found - just send the file
*/
function folder_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
+25 -19
View File
@@ -4005,9 +4005,11 @@ function forum_print_attachments($post, $cm, $type) {
/**
* Lists all browsable file areas
*
* @param object $course
* @param object $cm
* @param object $context
* @package mod_forum
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @return array
*/
function forum_get_file_areas($course, $cm, $context) {
@@ -4018,16 +4020,18 @@ function forum_get_file_areas($course, $cm, $context) {
/**
* File browsing support for forum module.
*
* @param object $browser
* @param object $areas
* @param object $course
* @param object $cm
* @param object $context
* @param string $filearea
* @param int $itemid
* @param string $filepath
* @param string $filename
* @return object file_info instance or null if not found
* @package mod_forum
* @category files
* @param stdClass $browser file browser object
* @param stdClass $areas file areas
* @param stdClass $course course object
* @param stdClass $cm course module
* @param stdClass $context context module
* @param string $filearea file area
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info instance or null if not found
*/
function forum_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename) {
global $CFG, $DB;
@@ -4084,12 +4088,14 @@ function forum_get_file_info($browser, $areas, $course, $cm, $context, $filearea
/**
* Serves the forum attachments. Implements needed access control ;-)
*
* @param object $course
* @param object $cm
* @param object $context
* @param string $filearea
* @param array $args
* @param bool $forcedownload
* @package mod_forum
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @return bool false if file not found, does not return if found - justsend the file
*/
function forum_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
+13 -9
View File
@@ -1451,9 +1451,11 @@ function glossary_print_attachments($entry, $cm, $type=NULL, $align="left") {
/**
* Lists all browsable file areas
*
* @param object $course
* @param object $cm
* @param object $context
* @package mod_glossary
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @return array
*/
function glossary_get_file_areas($course, $cm, $context) {
@@ -1464,12 +1466,14 @@ function glossary_get_file_areas($course, $cm, $context) {
/**
* Serves the glossary attachments. Implements needed access control ;-)
*
* @param object $course
* @param object $cm
* @param object $context
* @param string $filearea
* @param array $args
* @param bool $forcedownload
* @package mod_glossary
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClsss $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @return bool false if file not found, does not return if found - justsend the file
*/
function glossary_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
+27 -19
View File
@@ -261,9 +261,12 @@ function imscp_get_participants($imscpid) {
/**
* Lists all browsable file areas
* @param object $course
* @param object $cm
* @param object $context
*
* @package mod_imscp
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @return array
*/
function imscp_get_file_areas($course, $cm, $context) {
@@ -277,16 +280,19 @@ function imscp_get_file_areas($course, $cm, $context) {
/**
* File browsing support for imscp module ontent area.
* @param object $browser
* @param object $areas
* @param object $course
* @param object $cm
* @param object $context
* @param string $filearea
* @param int $itemid
* @param string $filepath
* @param string $filename
* @return object file_info instance or null if not found
*
* @package mod_imscp
* @category files
* @param stdClass $browser file browser
* @param stdClass $areas file areas
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info instance or null if not found
*/
function imscp_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename) {
global $CFG, $DB;
@@ -323,12 +329,14 @@ function imscp_get_file_info($browser, $areas, $course, $cm, $context, $filearea
/**
* Serves the imscp files.
*
* @param object $course
* @param object $cm
* @param object $context
* @param string $filearea
* @param array $args
* @param bool $forcedownload
* @package mod_imscp
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @return bool false if file not found, does not return if found - justsend the file
*/
function imscp_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
+25 -17
View File
@@ -887,12 +887,14 @@ function lesson_get_import_export_formats($type) {
/**
* Serves the lesson attachments. Implements needed access control ;-)
*
* @param object $course
* @param object $cm
* @param object $context
* @param string $filearea
* @param array $args
* @param bool $forcedownload
* @package mod_lesson
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @return bool false if file not found, does not return if found - justsend the file
*/
function lesson_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
@@ -939,7 +941,11 @@ function lesson_pluginfile($course, $cm, $context, $filearea, $args, $forcedownl
/**
* Returns an array of file areas
* @return array
*
* @package mod_lesson
* @category files
* @todo MDL-31048 localize
* @return array a list of available file areas
*/
function lesson_get_file_areas() {
$areas = array();
@@ -952,16 +958,18 @@ function lesson_get_file_areas() {
/**
* Returns a file_info_stored object for the file being requested here
*
* @global <type> $CFG
* @param file_browse $browser
* @param array $areas
* @param object $course
* @param object $cm
* @param object $context
* @param string $filearea
* @param int $itemid
* @param string $filepath
* @param string $filename
* @package mod_lesson
* @category files
* @global stdClass $CFG
* @param file_browse $browser file browser instance
* @param array $areas file areas
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info_stored
*/
function lesson_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename) {
+28 -19
View File
@@ -285,9 +285,12 @@ function page_get_coursemodule_info($coursemodule) {
/**
* Lists all browsable file areas
* @param object $course
* @param object $cm
* @param object $context
*
* @package mod_page
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @return array
*/
function page_get_file_areas($course, $cm, $context) {
@@ -298,16 +301,19 @@ function page_get_file_areas($course, $cm, $context) {
/**
* File browsing support for page module content area.
* @param object $browser
* @param object $areas
* @param object $course
* @param object $cm
* @param object $context
* @param string $filearea
* @param int $itemid
* @param string $filepath
* @param string $filename
* @return object file_info instance or null if not found
*
* @package mod_page
* @category files
* @param stdClass $browser file browser instance
* @param stdClass $areas file areas
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info instance or null if not found
*/
function page_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename) {
global $CFG;
@@ -343,12 +349,15 @@ function page_get_file_info($browser, $areas, $course, $cm, $context, $filearea,
/**
* Serves the page files.
* @param object $course
* @param object $cm
* @param object $context
* @param string $filearea
* @param array $args
* @param bool $forcedownload
*
* @package mod_page
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @return bool false if file not found, does not return if found - just send the file
*/
function page_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
+14 -8
View File
@@ -1634,12 +1634,14 @@ function quiz_extend_settings_navigation($settings, $quiznode) {
/**
* Serves the quiz files.
*
* @param object $course
* @param object $cm
* @param object $context
* @param string $filearea
* @param array $args
* @param bool $forcedownload
* @package mod_quiz
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @return bool false if file not found, does not return if found - justsend the file
*/
function quiz_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
@@ -1679,10 +1681,14 @@ function quiz_pluginfile($course, $cm, $context, $filearea, $args, $forcedownloa
* Called via pluginfile.php -> question_pluginfile to serve files belonging to
* a question in a question_attempt when that attempt is a quiz attempt.
*
* @param object $course course settings object
* @param object $context context object
* @package mod_quiz
* @category files
* @param stdClass $course course settings object
* @param stdClass $context context object
* @param string $component the name of the component we are serving files for.
* @param string $filearea the name of the file area.
* @param int $qubaid the attempt usage id.
* @param int $slot the id of a question in this quiz attempt.
* @param array $args the remaining bits of the file path.
* @param bool $forcedownload whether the user must be forced to download the file.
* @return bool false if file not found, does not return if found - justsend the file
+4 -1
View File
@@ -29,7 +29,10 @@ defined('MOODLE_INTERNAL') || die();
/**
* Serve questiontext files in the question text when they are displayed in this report.
* @param context $context the context
*
* @package mod_quiz
* @category files
* @param stdClass $context the context
* @param int $questionid the question id
* @param array $args remaining file args
* @param bool $forcedownload
+28 -19
View File
@@ -309,9 +309,12 @@ function resource_cm_info_view(cm_info $cm) {
/**
* Lists all browsable file areas
* @param object $course
* @param object $cm
* @param object $context
*
* @package mod_resource
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @return array
*/
function resource_get_file_areas($course, $cm, $context) {
@@ -322,16 +325,19 @@ function resource_get_file_areas($course, $cm, $context) {
/**
* File browsing support for resource module content area.
* @param object $browser
* @param object $areas
* @param object $course
* @param object $cm
* @param object $context
* @param string $filearea
* @param int $itemid
* @param string $filepath
* @param string $filename
* @return object file_info instance or null if not found
*
* @package mod_resource
* @category files
* @param stdClass $browser file browser instance
* @param stdClass $areas file areas
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info instance or null if not found
*/
function resource_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename) {
global $CFG;
@@ -367,12 +373,15 @@ function resource_get_file_info($browser, $areas, $course, $cm, $context, $filea
/**
* Serves the resource files.
* @param object $course
* @param object $cm
* @param object $context
* @param string $filearea
* @param array $args
* @param bool $forcedownload
*
* @package mod_resource
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @return bool false if file not found, does not return if found - just send the file
*/
function resource_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
+20 -16
View File
@@ -819,16 +819,18 @@ function scorm_get_file_areas($course, $cm, $context) {
/**
* File browsing support for SCORM file areas
*
* @param stdclass $browser
* @param stdclass $areas
* @param stdclass $course
* @param stdclass $cm
* @param stdclass $context
* @param string $filearea
* @param int $itemid
* @param string $filepath
* @param string $filename
* @return stdclass file_info instance or null if not found
* @package mod_scorm
* @category files
* @param file_browser $browser file browser instance
* @param array $areas file areas
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info instance or null if not found
*/
function scorm_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename) {
global $CFG;
@@ -882,12 +884,14 @@ function scorm_get_file_info($browser, $areas, $course, $cm, $context, $filearea
/**
* Serves scorm content, introduction images and packages. Implements needed access control ;-)
*
* @param object $course
* @param object $cm
* @param object $context
* @param string $filearea
* @param array $args
* @param bool $forcedownload
* @package mod_scorm
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @return bool false if file not found, does not return if found - just send the file
*/
function scorm_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
+10 -2
View File
@@ -434,9 +434,17 @@ function wiki_scale_used_anywhere($scaleid) {
}
/**
* Pluginfile hook
* file serving callback
*
* @author Josep Arus
* @copyright Josep Arus
* @package mod_wiki
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
*/
function wiki_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
global $CFG;
+13
View File
@@ -29,6 +29,19 @@ defined('MOODLE_INTERNAL') || die();
require_once(dirname(dirname(__FILE__)) . '/lib.php'); // interface definition
require_once($CFG->libdir . '/gradelib.php'); // to handle float vs decimal issues
/**
* Server workshop files
*
* @package mod_workshop
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @return bool
*/
function workshopform_accumulative_pluginfile($course, $cm, $context, $filearea, array $args, $forcedownload) {
global $DB;
+13
View File
@@ -29,6 +29,19 @@ defined('MOODLE_INTERNAL') || die();
require_once(dirname(dirname(__FILE__)) . '/lib.php'); // interface definition
require_once($CFG->libdir . '/gradelib.php'); // to handle float vs decimal issues
/**
* Server workshop files
*
* @package mod_workshop
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @return bool
*/
function workshopform_comments_pluginfile($course, $cm, $context, $filearea, array $args, $forcedownload) {
global $DB;
+13
View File
@@ -29,6 +29,19 @@ defined('MOODLE_INTERNAL') || die();
require_once(dirname(dirname(__FILE__)) . '/lib.php'); // interface definition
require_once($CFG->libdir . '/gradelib.php'); // to handle float vs decimal issues
/**
* Server workshop files
*
* @package mod_workshop
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @return bool
*/
function workshopform_numerrors_pluginfile($course, $cm, $context, $filearea, array $args, $forcedownload) {
global $DB;
+12 -3
View File
@@ -1144,6 +1144,9 @@ function workshop_grade_item_category_update($workshop) {
* The file area workshop_intro for the activity introduction field is added automatically
* by {@link file_browser::get_file_info_context_module()}
*
* @package mod_workshop
* @category files
*
* @param stdClass $course
* @param stdClass $cm
* @param stdClass $context
@@ -1170,6 +1173,9 @@ function workshop_get_file_areas($course, $cm, $context) {
* Besides that, areas workshop_instructauthors and mod_workshop instructreviewers contain the media
* embedded using the mod_form.php.
*
* @package mod_workshop
* @category files
*
* @param stdClass $course
* @param stdClass $cm
* @param stdClass $context
@@ -1254,8 +1260,11 @@ function workshop_pluginfile($course, $cm, $context, $filearea, array $args, $fo
/**
* File browsing support for workshop file areas
*
* @param stdClass $browser
* @param stdClass $areas
* @package mod_workshop
* @category files
*
* @param file_browser $browser
* @param array $areas
* @param stdClass $course
* @param stdClass $cm
* @param stdClass $context
@@ -1263,7 +1272,7 @@ function workshop_pluginfile($course, $cm, $context, $filearea, array $args, $fo
* @param int $itemid
* @param string $filepath
* @param string $filename
* @return stdclass file_info instance or null if not found
* @return file_info instance or null if not found
*/
function workshop_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename) {
global $CFG, $DB;
+4 -2
View File
@@ -214,8 +214,10 @@ class question_preview_options extends question_display_options {
* Called via pluginfile.php -> question_pluginfile to serve files belonging to
* a question in a question_attempt when that attempt is a preview.
*
* @param object $course course settings object
* @param object $context context object
* @package core_question
* @category files
* @param stdClass $course course settings object
* @param stdClass $context context object
* @param string $component the name of the component we are serving files for.
* @param string $filearea the name of the file area.
* @param int $qubaid the question_usage this image belongs to.
+11 -2
View File
@@ -18,8 +18,7 @@
* Serve question type files
*
* @since 2.0
* @package qtype
* @subpackage calculated
* @package qtype_calculated
* @copyright Dongsheng Cai <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -30,6 +29,16 @@ defined('MOODLE_INTERNAL') || die();
/**
* Checks file access for calculated questions.
*
* @package qtype_calculated
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @return bool
*/
function qtype_calculated_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
global $CFG;
+11 -2
View File
@@ -18,8 +18,7 @@
* Serve question type files
*
* @since 2.0
* @package qtype
* @subpackage calculatedmulti
* @package qtype_calculatedmulti
* @copyright Dongsheng Cai <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -30,6 +29,16 @@ defined('MOODLE_INTERNAL') || die();
/**
* Checks file access for calculated multiple-choice questions.
*
* @package qtype_calculatedmulti
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @return bool
*/
function qtype_calculatedmulti_pluginfile($course, $cm, $context, $filearea, $args,
$forcedownload) {
+12 -2
View File
@@ -18,8 +18,7 @@
* Serve question type files
*
* @since 2.0
* @package qtype
* @subpackage calculatedsimple
* @package qtype_calculatedsimple
* @copyright Dongsheng Cai <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -30,6 +29,17 @@ defined('MOODLE_INTERNAL') || die();
/**
* Checks file access for simple calculated questions.
*
* @package qtype_calculatedsimple
* @category files
*
* @param stdClass $course
* @param stdClass $cm
* @param stdClass $context
* @param string $filearea
* @param array $args
* @param bool $forcedownload
* @return bool
*/
function qtype_calculatedsimple_pluginfile($course, $cm, $context, $filearea,
$args, $forcedownload) {
+11 -2
View File
@@ -18,8 +18,7 @@
* Serve question type files
*
* @since 2.0
* @package qtype
* @subpackage essay
* @package qtype_essay
* @copyright Dongsheng Cai <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -30,6 +29,16 @@ defined('MOODLE_INTERNAL') || die();
/**
* Checks file access for essay questions.
*
* @package qtype_essay
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @return bool
*/
function qtype_essay_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
global $CFG;
+10 -2
View File
@@ -18,8 +18,7 @@
* Serve question type files
*
* @since 2.0
* @package qtype
* @subpackage match
* @package qtype_match
* @copyright Dongsheng Cai <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -30,6 +29,15 @@ defined('MOODLE_INTERNAL') || die();
/**
* Checks file access for matching questions.
* @package qtype_match
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @return bool
*/
function qtype_match_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
global $DB, $CFG;
+11 -2
View File
@@ -18,8 +18,7 @@
* Serve question type files
*
* @since 2.0
* @package qtype
* @subpackage multichoice
* @package qtype_multichoice
* @copyright Dongsheng Cai <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -30,6 +29,16 @@ defined('MOODLE_INTERNAL') || die();
/**
* Checks file access for multiple choice questions.
*
* @package qtype_multichoice
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @return bool
*/
function qtype_multichoice_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
global $CFG;
+11 -2
View File
@@ -18,8 +18,7 @@
* Serve question type files
*
* @since 2.0
* @package qtype
* @subpackage numerical
* @package qtype_numerical
* @copyright Dongsheng Cai <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -30,6 +29,16 @@ defined('MOODLE_INTERNAL') || die();
/**
* Checks file access for numerical questions.
*
* @package qtype_numerical
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @return bool
*/
function qtype_numerical_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
global $CFG;
+10 -2
View File
@@ -18,8 +18,7 @@
* Serve question type files
*
* @since 2.0
* @package qtype
* @subpackage shortanswer
* @package qtype_shortanswer
* @copyright Dongsheng Cai <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -30,6 +29,15 @@ defined('MOODLE_INTERNAL') || die();
/**
* Checks file access for short answer questions.
* @package qtype_shortanswer
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @return bool
*/
function qtype_shortanswer_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
global $DB, $CFG;
+10 -2
View File
@@ -18,8 +18,7 @@
* Serve question type files
*
* @since 2.0
* @package qtype
* @subpackage truefalse
* @package qtype_truefalse
* @copyright 2010 The Open Unviersity
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -30,6 +29,15 @@ defined('MOODLE_INTERNAL') || die();
/**
* Checks file access for true-false questions.
* @package qtype_truefalse
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @return bool
*/
function qtype_truefalse_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
global $CFG;