Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  
  18  /**
  19   * Class simulating empty directories.
  20   *
  21   * @package    core_files
  22   * @copyright  2008 Petr Skoda (http://skodak.org)
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  /**
  29   * Represents the root directory of an empty file area in the tree navigated by {@link file_browser}.
  30   *
  31   * @package    core_files
  32   * @copyright  2008 Petr Skoda (http://skodak.org)
  33   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  34   */
  35  class virtual_root_file {
  36      /** @var int context id */
  37      protected $contextid;
  38      /** @var string file component */
  39      protected $component;
  40      /** @var string file area */
  41      protected $filearea;
  42      /** @var int file itemid */
  43      protected $itemid;
  44  
  45      /**
  46       * Constructor
  47       *
  48       * @param int $contextid context ID
  49       * @param string $component component
  50       * @param string $filearea file area
  51       * @param int $itemid item ID
  52       */
  53      public function __construct($contextid, $component, $filearea, $itemid) {
  54          $this->contextid = $contextid;
  55          $this->component = $component;
  56          $this->filearea  = $filearea;
  57          $this->itemid    = $itemid;
  58      }
  59  
  60      /**
  61       * Whether or not this is a directory
  62       *
  63       * @return bool
  64       */
  65      public function is_directory() {
  66          return true;
  67      }
  68  
  69      /**
  70       * Delete file
  71       *
  72       * @return success
  73       */
  74      public function delete() {
  75          return true;
  76      }
  77  
  78      /**
  79      * adds this file path to a curl request (POST only)
  80      *
  81      * @param curl $curlrequest the curl request object
  82      * @param string $key what key to use in the POST request
  83      */
  84      public function add_to_curl_request(&$curlrequest, $key) {
  85          return;
  86      }
  87  
  88      /**
  89       * Returns file handle - read only mode, no writing allowed into pool files!
  90       *
  91       * @return resource file handle
  92       */
  93      public function get_content_file_handle() {
  94          return null;
  95      }
  96  
  97      /**
  98       * Dumps file content to page
  99       *
 100       * @return resource file handle
 101       */
 102      public function readfile() {
 103          return;
 104      }
 105  
 106      /**
 107       * Returns file content as string
 108       *
 109       * @return string content
 110       */
 111      public function get_content() {
 112          return '';
 113      }
 114  
 115      /**
 116       * Copy content of file to given pathname
 117       *
 118       * @param string $pathname real path to new file
 119       * @return bool success
 120       */
 121      public function copy_content_to($pathname) {
 122          return false;
 123      }
 124  
 125      /**
 126       * List contents of archive
 127       *
 128       * @param file_packer $packer file packer instance
 129       * @return array of file infos
 130       */
 131      public function list_files(file_packer $packer) {
 132          return null;
 133      }
 134  
 135      /**
 136       * Extract file to given file path (real OS filesystem), existing files are overwrited
 137       *
 138       * @param file_packer $packer file packer instance
 139       * @param string $pathname target directory
 140       * @return mixed list of processed files; false if error
 141       */
 142      public function extract_to_pathname(file_packer $packer, $pathname) {
 143          return false;
 144      }
 145  
 146      /**
 147       * Extract file to given file path (real OS filesystem), existing files are overwrited
 148       *
 149       * @param file_packer $packer file packer instance
 150       * @param int $contextid context ID
 151       * @param string $component component
 152       * @param string $filearea file area
 153       * @param int $itemid item ID
 154       * @param string $pathbase path base
 155       * @param int $userid user ID
 156       * @return mixed list of processed files; false if error
 157       */
 158      public function extract_to_storage(file_packer $packer, $contextid, $component, $filearea, $itemid, $pathbase, $userid = NULL) {
 159          return false;
 160      }
 161  
 162      /**
 163       * Add file/directory into archive
 164       *
 165       * @param file_archive $filearch file archive instance
 166       * @param string $archivepath pathname in archive
 167       * @return bool success
 168       */
 169      public function archive_file(file_archive $filearch, $archivepath) {
 170          return false;
 171      }
 172  
 173      /**
 174       * Returns parent directory
 175       *
 176       * @return stored_file
 177       */
 178      public function get_parent_directory() {
 179          return null;
 180      }
 181  
 182      /**
 183       * Returns context ID
 184       *
 185       * @return int context ID
 186       */
 187      public function get_contextid() {
 188          return $this->contextid;
 189      }
 190  
 191      /**
 192       * Returns file component
 193       *
 194       * @return string component
 195       */
 196      public function get_component() {
 197          return $this->component;
 198      }
 199  
 200      /**
 201       * Returns file area
 202       *
 203       * @return string filearea
 204       */
 205      public function get_filearea() {
 206          return $this->filearea;
 207      }
 208  
 209      /**
 210       * Returns file itemid
 211       *
 212       * @return int itemid
 213       */
 214      public function get_itemid() {
 215          return $this->itemid;
 216      }
 217  
 218      /**
 219       * Returns file path
 220       *
 221       * @return string filepath
 222       */
 223      public function get_filepath() {
 224          return '/';
 225      }
 226  
 227      /**
 228       * Returns file name
 229       *
 230       * @return string filename
 231       */
 232      public function get_filename() {
 233          return '.';
 234      }
 235  
 236      /**
 237       * Returns user ID
 238       *
 239       * @return int userid
 240       */
 241      public function get_userid() {
 242          return null;
 243      }
 244  
 245      /**
 246       * Returns file size
 247       *
 248       * @return int filesize
 249       */
 250      public function get_filesize() {
 251          return 0;
 252      }
 253  
 254      /**
 255       * Returns mimetype
 256       *
 257       * @return string mimetype
 258       */
 259      public function get_mimetype() {
 260          return null;
 261      }
 262  
 263      /**
 264       * Returns time created
 265       *
 266       * @return int
 267       */
 268      public function get_timecreated() {
 269          return 0;
 270      }
 271  
 272      /**
 273       * Returns time modified
 274       *
 275       * @return int
 276       */
 277      public function get_timemodified() {
 278          return 0;
 279      }
 280  
 281      /**
 282       * Returns status
 283       *
 284       * @return int
 285       */
 286      public function get_status() {
 287          return 0;
 288      }
 289  
 290      /**
 291       * Returns ID
 292       *
 293       * @return int
 294       */
 295      public function get_id() {
 296          return 0;
 297      }
 298  
 299      /**
 300       * Returns sha1 hash code
 301       *
 302       * @return string
 303       */
 304      public function get_contenthash() {
 305          return sha1('');
 306      }
 307  
 308      /**
 309       * Returns path name hash
 310       *
 311       * @return string
 312       */
 313      public function get_pathnamehash() {
 314          return sha1('/'.$this->get_contextid().'/'.$this->get_component().'/'.$this->get_filearea().'/'.$this->get_itemid().$this->get_filepath().$this->get_filename());
 315      }
 316  
 317      /**
 318       * Returns license
 319       *
 320       * @return string
 321       */
 322      public function get_license() {
 323          return null;
 324      }
 325  
 326      /**
 327       * Returns file's author
 328       *
 329       * @return string
 330       */
 331      public function get_author() {
 332          return null;
 333      }
 334  
 335      /**
 336       * Returns file source
 337       *
 338       * @return string
 339       */
 340      public function get_source() {
 341          return null;
 342      }
 343  
 344      /**
 345       * Returns file sort order
 346       *
 347       * @return int
 348       */
 349      public function get_sortorder() {
 350          return null;
 351      }
 352  }