Subversion Repositories Applications.gtt

Rev

Rev 94 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 94 Rev 187
Line 2... Line 2...
2
/**
2
/**
3
 * package.xml parsing class, package.xml version 1.0
3
 * package.xml parsing class, package.xml version 1.0
4
 *
4
 *
5
 * PHP versions 4 and 5
5
 * PHP versions 4 and 5
6
 *
6
 *
7
 * LICENSE: This source file is subject to version 3.0 of the PHP license
-
 
8
 * that is available through the world-wide-web at the following URI:
-
 
9
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
-
 
10
 * the PHP License and are unable to obtain it through the web, please
-
 
11
 * send a note to license@php.net so we can mail you a copy immediately.
-
 
12
 *
-
 
13
 * @category   pear
7
 * @category   pear
14
 * @package    PEAR
8
 * @package    PEAR
15
 * @author     Greg Beaver <cellog@php.net>
9
 * @author     Greg Beaver <cellog@php.net>
16
 * @copyright  1997-2006 The PHP Group
10
 * @copyright  1997-2009 The Authors
17
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
11
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
18
 * @version    CVS: $Id: v1.php,v 1.22 2006/03/27 05:25:48 cellog Exp $
-
 
19
 * @link       http://pear.php.net/package/PEAR
12
 * @link       http://pear.php.net/package/PEAR
20
 * @since      File available since Release 1.4.0a1
13
 * @since      File available since Release 1.4.0a1
21
 */
14
 */
22
/**
15
/**
23
 * package.xml abstraction class
16
 * package.xml abstraction class
Line 26... Line 19...
26
/**
19
/**
27
 * Parser for package.xml version 1.0
20
 * Parser for package.xml version 1.0
28
 * @category   pear
21
 * @category   pear
29
 * @package    PEAR
22
 * @package    PEAR
30
 * @author     Greg Beaver <cellog@php.net>
23
 * @author     Greg Beaver <cellog@php.net>
31
 * @copyright  1997-2006 The PHP Group
24
 * @copyright  1997-2009 The Authors
32
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
25
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
33
 * @version    Release: @PEAR-VER@
26
 * @version    Release: @PEAR-VER@
34
 * @link       http://pear.php.net/package/PEAR
27
 * @link       http://pear.php.net/package/PEAR
35
 * @since      Class available since Release 1.4.0a1
28
 * @since      Class available since Release 1.4.0a1
36
 */
29
 */
37
class PEAR_PackageFile_Parser_v1
30
class PEAR_PackageFile_Parser_v1
Line 64... Line 57...
64
 
57
 
65
    /**
58
    /**
66
     * @param string contents of package.xml file, version 1.0
59
     * @param string contents of package.xml file, version 1.0
67
     * @return bool success of parsing
60
     * @return bool success of parsing
68
     */
61
     */
69
    function parse($data, $file, $archive = false)
62
    function &parse($data, $file, $archive = false)
70
    {
63
    {
71
        if (!extension_loaded('xml')) {
64
        if (!extension_loaded('xml')) {
72
            return PEAR::raiseError('Cannot create xml parser for parsing package.xml, no xml extension');
65
            return PEAR::raiseError('Cannot create xml parser for parsing package.xml, no xml extension');
73
        }
66
        }
74
        $xp = xml_parser_create();
67
        $xp = xml_parser_create();
75
        if (!$xp) {
68
        if (!$xp) {
-
 
69
            $a = &PEAR::raiseError('Cannot create xml parser for parsing package.xml');
76
            return PEAR::raiseError('Cannot create xml parser for parsing package.xml');
70
            return $a;
77
        }
71
        }
78
        xml_set_object($xp, $this);
72
        xml_set_object($xp, $this);
79
        xml_set_element_handler($xp, '_element_start_1_0', '_element_end_1_0');
73
        xml_set_element_handler($xp, '_element_start_1_0', '_element_end_1_0');
80
        xml_set_character_data_handler($xp, '_pkginfo_cdata_1_0');
74
        xml_set_character_data_handler($xp, '_pkginfo_cdata_1_0');
Line 94... Line 88...
94
 
88
 
95
        if (!xml_parse($xp, $data, 1)) {
89
        if (!xml_parse($xp, $data, 1)) {
96
            $code = xml_get_error_code($xp);
90
            $code = xml_get_error_code($xp);
97
            $line = xml_get_current_line_number($xp);
91
            $line = xml_get_current_line_number($xp);
98
            xml_parser_free($xp);
92
            xml_parser_free($xp);
99
            return PEAR::raiseError(sprintf("XML error: %s at line %d",
93
            $a = PEAR::raiseError(sprintf("XML error: %s at line %d",
-
 
94
                           $str = xml_error_string($code), $line), 2);
100
                           $str = xml_error_string($code), $line), 2);
95
            return $a;
Line 101... Line 96...
101
        }
96
        }
Line 102... Line 97...
102
 
97
 
Line 130... Line 125...
130
        $data = '';
125
        $data = '';
131
        // remove the same amount of whitespace from following lines
126
        // remove the same amount of whitespace from following lines
132
        foreach (explode("\n", $str) as $line) {
127
        foreach (explode("\n", $str) as $line) {
133
            if (substr($line, 0, $indent_len) == $indent) {
128
            if (substr($line, 0, $indent_len) == $indent) {
134
                $data .= substr($line, $indent_len) . "\n";
129
                $data .= substr($line, $indent_len) . "\n";
-
 
130
            } elseif (trim(substr($line, 0, $indent_len))) {
-
 
131
                $data .= ltrim($line);
135
            }
132
            }
136
        }
133
        }
137
        return $data;
134
        return $data;
138
    }
135
    }
Line 165... Line 162...
165
                    break;
162
                    break;
166
                }
163
                }
167
                if (array_key_exists('name', $attribs) && $attribs['name'] != '/') {
164
                if (array_key_exists('name', $attribs) && $attribs['name'] != '/') {
168
                    $attribs['name'] = preg_replace(array('!\\\\+!', '!/+!'), array('/', '/'),
165
                    $attribs['name'] = preg_replace(array('!\\\\+!', '!/+!'), array('/', '/'),
169
                        $attribs['name']);
166
                        $attribs['name']);
170
                    if (strrpos($attribs['name'], '/') == strlen($attribs['name']) - 1) {
167
                    if (strrpos($attribs['name'], '/') === strlen($attribs['name']) - 1) {
171
                        $attribs['name'] = substr($attribs['name'], 0,
168
                        $attribs['name'] = substr($attribs['name'], 0,
172
                            strlen($attribs['name']) - 1);
169
                            strlen($attribs['name']) - 1);
173
                    }
170
                    }
174
                    if (strpos($attribs['name'], '/') === 0) {
171
                    if (strpos($attribs['name'], '/') === 0) {
175
                        $attribs['name'] = substr($attribs['name'], 1);
172
                        $attribs['name'] = substr($attribs['name'], 1);
Line 331... Line 328...
331
                break;
328
                break;
332
            case 'role':
329
            case 'role':
333
                $this->current_maintainer['role'] = $data;
330
                $this->current_maintainer['role'] = $data;
334
                break;
331
                break;
335
            case 'version':
332
            case 'version':
336
                //$data = ereg_replace ('[^a-zA-Z0-9._\-]', '_', $data);
-
 
337
                if ($this->in_changelog) {
333
                if ($this->in_changelog) {
338
                    $this->current_release['version'] = $data;
334
                    $this->current_release['version'] = $data;
339
                } else {
335
                } else {
340
                    $this->_packageInfo['version'] = $data;
336
                    $this->_packageInfo['version'] = $data;
341
                }
337
                }
Line 348... Line 344...
348
                }
344
                }
349
                break;
345
                break;
350
            case 'notes':
346
            case 'notes':
351
                // try to "de-indent" release notes in case someone
347
                // try to "de-indent" release notes in case someone
352
                // has been over-indenting their xml ;-)
348
                // has been over-indenting their xml ;-)
-
 
349
                // Trim only on the right side
353
                $data = $this->_unIndent($this->cdata);
350
                $data = rtrim($this->_unIndent($this->cdata));
354
                if ($this->in_changelog) {
351
                if ($this->in_changelog) {
355
                    $this->current_release['release_notes'] = $data;
352
                    $this->current_release['release_notes'] = $data;
356
                } else {
353
                } else {
357
                    $this->_packageInfo['release_notes'] = $data;
354
                    $this->_packageInfo['release_notes'] = $data;
358
                }
355
                }