Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
 
4
/**
5
 * Add a directory to the public name of all the files of a reader
6
 *
7
 * PHP versions 4 and 5
8
 *
9
 * This library is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU Lesser General Public
11
 * License as published by the Free Software Foundation; either
12
 * version 2.1 of the License, or (at your option) any later version.
13
 *
14
 * This library is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
 * Lesser General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public
20
 * License along with this library; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA
22
 *
23
 * @category   File Formats
24
 * @package    File_Archive
25
 * @author     Vincent Lascaux <vincentlascaux@php.net>
26
 * @copyright  1997-2005 The PHP Group
27
 * @license    http://www.gnu.org/copyleft/lesser.html  LGPL
28
 * @version    CVS: $Id: ChangeName.php,v 1.20 2005/08/29 15:14:08 vincentlascaux Exp $
29
 * @link       http://pear.php.net/package/File_Archive
30
 */
31
 
32
require_once "File/Archive/Reader/Relay.php";
33
 
34
/**
35
 * Base class for readers that need to modify the name of files
36
 */
37
class File_Archive_Reader_ChangeName extends File_Archive_Reader_Relay
38
{
39
    /**
40
     * Modify the name
41
     *
42
     * @param string $name Name as in the inner reader
43
     * @return string New name as shown by this reader or false is the
44
     *         file or directory has to be skipped
45
     */
46
    function modifyName($name)
47
    {
48
    }
49
 
50
    /**
51
     * Modify the name back to the inner reader naming style
52
     * If implemented, unmodifyName(modifyName($name)) should be true
53
     *
54
     * unmodifyName can be left unimplemented, this may only impact the
55
     * efficiency of the select function (a full look up will be done when
56
     * something more efficient with an index for example could be used on
57
     * the inner reader of the original name is known).
58
     *
59
     * unmodifyName may be provided some names that where not in the inner reader
60
     * and that cannot possibly be the result of modifyName. In this case
61
     * unmodifyName must return false.
62
     *
63
     * @param string $name Name as shown by this reader
64
     * @return string Name as in the inner reader, or false if there is no
65
     *         input such that modifyName would return $name or a file in
66
     *         a directory called $name
67
     */
68
    function unmodifyName($name)
69
    {
70
        return null;
71
    }
72
 
73
    /**
74
     * @see File_Archive_Reader::getFilename()
75
     */
76
    function getFilename()
77
    {
78
        return $this->getStandardURL($this->modifyName(parent::getFilename()));
79
    }
80
    /**
81
     * @see File_Archive_Reader::getFileList()
82
     */
83
    function getFileList()
84
    {
85
        $list = parent::getFileList();
86
        $result = array();
87
        foreach ($list as $name) {
88
            $result[] = $this->modifyName($name);
89
        }
90
        return $result;
91
    }
92
    /**
93
     * @see File_Archive_Reader::select()
94
     */
95
    function select($filename, $close = true)
96
    {
97
        $name = $this->unmodifyName($filename);
98
        if ($name === false) {
99
            return false;
100
        } else if($name === null) {
101
            $std = $this->getStandardURL($filename);
102
            if (substr($std, -1)=='/') {
103
                $std = substr($std, 0, -1);
104
            }
105
 
106
            if ($close) {
107
                $error = $this->close();
108
                if (PEAR::isError($error)) {
109
                    return $error;
110
                }
111
            }
112
            while (($error = $this->next()) === true) {
113
                $sourceName = $this->getFilename();
114
                $sourceName = $this->modifyName($sourceName, $this->isDirectory());
115
                $sourceName = $this->getStandardURL($sourceName);
116
                if (
117
                      empty($std) ||
118
 
119
                    //$std is a file
120
                      $std == $sourceName ||
121
 
122
                    //$std is a directory
123
                      (strncmp($std.'/', $sourceName, strlen($std)+1) == 0 &&
124
                       strlen($sourceName) > strlen($std)+1)
125
                   ) {
126
                    return true;
127
                }
128
            }
129
            return $error;
130
        } else {
131
            return $this->source->select($name, $close);
132
        }
133
    }
134
}
135
 
136
?>