Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/filestorage/file_archive.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00018 
00028 defined('MOODLE_INTERNAL') || die();
00029 
00038 abstract class file_archive implements Iterator {
00039 
00041     const OPEN      = 1;
00042 
00044     const CREATE    = 2;
00045 
00047     const OVERWRITE = 4;
00048 
00050     protected $encoding = 'utf-8';
00051 
00059     public abstract function open($archivepathname, $mode=file_archive::CREATE, $encoding='utf-8');
00060 
00065     public abstract function close();
00066 
00072     public abstract function get_stream($index);
00073 
00079     public abstract function get_info($index);
00080 
00085     public abstract function list_files();
00086 
00091     public abstract function count();
00092 
00099     public abstract function add_file_from_pathname($localname, $pathname);
00100 
00107     public abstract function add_file_from_string($localname, $contents);
00108 
00114     public abstract function add_directory($localname);
00115 
00122     protected function mangle_pathname($localname) {
00123         if ($this->encoding === 'utf-8') {
00124             return $localname;
00125         }
00126         $textlib = textlib_get_instance();
00127 
00128         $converted = $textlib->convert($localname, 'utf-8', $this->encoding);
00129         $original  = $textlib->convert($converted, $this->encoding, 'utf-8');
00130 
00131         if ($original === $localname) {
00132             $result = $converted;
00133 
00134         } else {
00135             // try ascii conversion
00136             $converted2 = $textlib->specialtoascii($localname);
00137             $converted2 = $textlib->convert($converted2, 'utf-8', $this->encoding);
00138             $original2  = $textlib->convert($converted, $this->encoding, 'utf-8');
00139 
00140             if ($original2 === $localname) {
00141                 //this looks much better
00142                 $result = $converted2;
00143             } else {
00144                 //bad luck - the file name may not be usable at all
00145                 $result = $converted;
00146             }
00147         }
00148 
00149         $result = preg_replace('/\.\.+/', '', $result);
00150         $result = ltrim($result); // no leading /
00151 
00152         if ($result === '.') {
00153             $result = '';
00154         }
00155 
00156         return $result;
00157     }
00158 
00167     protected function unmangle_pathname($localname) {
00168         $result = str_replace('\\', '/', $localname); // no MS \ separators
00169         $result = ltrim($result, '/');                // no leading /
00170 
00171         if ($this->encoding !== 'utf-8') {
00172             $result = textlib_get_instance()->convert($result, $this->encoding, 'utf-8');
00173         }
00174 
00175         return clean_param($result, PARAM_PATH);
00176     }
00177 
00182     //public abstract function current();
00183 
00188     //public abstract function key();
00189 
00194     //public abstract function next();
00195 
00200     //public abstract function rewind();
00201 
00206     //public abstract function valid();
00207 
00208 }
 All Data Structures Namespaces Files Functions Variables Enumerations