PageRenderTime 63ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/filebrowser/file_info.php

https://github.com/kpike/moodle
PHP | 292 lines | 90 code | 36 blank | 166 comment | 1 complexity | 538872caad658e9fa2a4dd19233fcf3c MD5 | raw file
  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. * Base for all file browsing classes.
  18. *
  19. * @package core
  20. * @subpackage filebrowser
  21. * @copyright 2008 Petr Skoda (http://skodak.org)
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. */
  24. defined('MOODLE_INTERNAL') || die();
  25. /**
  26. * Base class for things in the tree navigated by @see{file_browser}.
  27. *
  28. * @package core
  29. * @subpackage filebrowser
  30. * @copyright 2008 Petr Skoda (http://skodak.org)
  31. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32. */
  33. abstract class file_info {
  34. protected $context;
  35. protected $browser;
  36. public function __construct($browser, $context) {
  37. $this->browser = $browser;
  38. $this->context = $context;
  39. }
  40. /**
  41. * Returns list of standard virtual file/directory identification.
  42. * The difference from stored_file parameters is that null values
  43. * are allowed in all fields
  44. * @return array with keys contextid, component, filearea, itemid, filepath and filename
  45. */
  46. public function get_params() {
  47. return array('contextid' => $this->context->id,
  48. 'component' => null,
  49. 'filearea' => null,
  50. 'itemid' => null,
  51. 'filepath' => null,
  52. 'filename' => null);
  53. }
  54. /**
  55. * Returns localised visible name.
  56. * @return string
  57. */
  58. public abstract function get_visible_name();
  59. /**
  60. * Is directory?
  61. * @return bool
  62. */
  63. public abstract function is_directory();
  64. /**
  65. * Returns list of children.
  66. * @return array of file_info instances
  67. */
  68. public abstract function get_children();
  69. /**
  70. * Returns parent file_info instance
  71. * @return file_info or null for root
  72. */
  73. public abstract function get_parent();
  74. /**
  75. * Returns array of url encoded params.
  76. * @return array with numeric keys
  77. */
  78. public function get_params_rawencoded() {
  79. $params = $this->get_params();
  80. $encoded = array();
  81. $encoded[] = 'contextid='.$params['contextid'];
  82. $encoded[] = 'component='.$params['component'];
  83. $encoded[] = 'filearea='.$params['filearea'];
  84. $encoded[] = 'itemid='.(is_null($params['itemid']) ? -1 : $params['itemid']);
  85. $encoded[] = 'filepath='.(is_null($params['filepath']) ? '' : rawurlencode($params['filepath']));
  86. $encoded[] = 'filename='.((is_null($params['filename']) or $params['filename'] === '.') ? '' : rawurlencode($params['filename']));
  87. return $encoded;
  88. }
  89. /**
  90. * Returns file download url
  91. * @param bool $forcedownload
  92. * @param bool $htts force https
  93. * @return string url
  94. */
  95. public function get_url($forcedownload=false, $https=false) {
  96. return null;
  97. }
  98. /**
  99. * Can I read content of this file or enter directory?
  100. * @return bool
  101. */
  102. public function is_readable() {
  103. return true;
  104. }
  105. /**
  106. * Can I add new files or directories?
  107. * @return bool
  108. */
  109. public function is_writable() {
  110. return true;
  111. }
  112. /**
  113. * Is this info area and is it "empty"? Are there any files in subfolders?
  114. *
  115. * This is used mostly in repositories to reduce the
  116. * number of empty folders. This method may be very slow,
  117. * use with care.
  118. *
  119. * @return bool
  120. */
  121. public function is_empty_area() {
  122. return false;
  123. }
  124. /**
  125. * Returns file size in bytes, null for directories
  126. * @return int bytes or null if not known
  127. */
  128. public function get_filesize() {
  129. return null;
  130. }
  131. /**
  132. * Returns mimetype
  133. * @return string mimetype or null if not known
  134. */
  135. public function get_mimetype() {
  136. return null;
  137. }
  138. /**
  139. * Returns time created unix timestamp if known
  140. * @return int timestamp or null
  141. */
  142. public function get_timecreated() {
  143. return null;
  144. }
  145. /**
  146. * Returns time modified unix timestamp if known
  147. * @return int timestamp or null
  148. */
  149. public function get_timemodified() {
  150. return null;
  151. }
  152. /**
  153. * Returns the license type of the file
  154. * @return string license short name or null
  155. */
  156. public function get_license() {
  157. return null;
  158. }
  159. /**
  160. * Returns the author name of the file
  161. * @return string author name or null
  162. */
  163. public function get_author() {
  164. return null;
  165. }
  166. /**
  167. * Returns the source of the file
  168. * @return string a source url or null
  169. */
  170. public function get_source() {
  171. return null;
  172. }
  173. /**
  174. * Returns the sort order of the file
  175. * @return int
  176. */
  177. public function get_sortorder() {
  178. return 0;
  179. }
  180. /**
  181. * Create new directory, may throw exception - make sure
  182. * params are valid.
  183. * @param string $newdirname name of new directory
  184. * @param int id of author, default $USER->id
  185. * @return file_info new directory
  186. */
  187. public function create_directory($newdirname, $userid = NULL) {
  188. return null;
  189. }
  190. /**
  191. * Create new file from string - make sure
  192. * params are valid.
  193. * @param string $newfilename name of new file
  194. * @param string $content of file
  195. * @param int id of author, default $USER->id
  196. * @return file_info new file
  197. */
  198. public function create_file_from_string($newfilename, $content, $userid = NULL) {
  199. return null;
  200. }
  201. /**
  202. * Create new file from pathname - make sure
  203. * params are valid.
  204. * @param string $newfilename name of new file
  205. * @param string $pathname location of file
  206. * @param int id of author, default $USER->id
  207. * @return file_info new file
  208. */
  209. public function create_file_from_pathname($newfilename, $pathname, $userid = NULL) {
  210. return null;
  211. }
  212. /**
  213. * Create new file from stored file - make sure
  214. * params are valid.
  215. * @param string $newfilename name of new file
  216. * @param mixed dile id or stored_file of file
  217. * @param int id of author, default $USER->id
  218. * @return file_info new file
  219. */
  220. public function create_file_from_storedfile($newfilename, $fid, $userid = NULL) {
  221. return null;
  222. }
  223. /**
  224. * Delete file, make sure file is deletable first.
  225. * @return bool success
  226. */
  227. public function delete() {
  228. return false;
  229. }
  230. /**
  231. * Copy content of this file to local storage, overriding current file if needed.
  232. * @param int $contextid
  233. * @param string $component
  234. * @param string $filearea
  235. * @param int $itemid
  236. * @param string $filepath
  237. * @param string $filename
  238. * @return boolean success
  239. */
  240. public function copy_to_storage($contextid, $component, $filearea, $itemid, $filepath, $filename) {
  241. return false;
  242. }
  243. /**
  244. * Copy content of this file to local storage, overriding current file if needed.
  245. * @param string $pathname real local full file name
  246. * @return boolean success
  247. */
  248. public function copy_to_pathname($pathname) {
  249. return false;
  250. }
  251. //TODO: following methods are not implemented yet ;-)
  252. //public abstract function move(location params);
  253. //public abstract function rename(new name);
  254. //public abstract function unzip(location params);
  255. //public abstract function zip(zip file, file info);
  256. }