Subversion Repositories Applications.gtt

Rev

Rev 94 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 94 Rev 187
1
<?php
1
<?php
2
/**
2
/**
3
 * package.xml generation class, package.xml version 1.0
3
 * package.xml generation 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.72 2006/05/10 02:56:19 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
 * needed for PEAR_VALIDATE_* constants
16
 * needed for PEAR_VALIDATE_* constants
24
 */
17
 */
25
require_once 'PEAR/Validate.php';
18
require_once 'PEAR/Validate.php';
26
require_once 'System.php';
19
require_once 'System.php';
27
require_once 'PEAR/PackageFile/v2.php';
20
require_once 'PEAR/PackageFile/v2.php';
28
/**
21
/**
29
 * This class converts a PEAR_PackageFile_v1 object into any output format.
22
 * This class converts a PEAR_PackageFile_v1 object into any output format.
30
 *
23
 *
31
 * Supported output formats include array, XML string, and a PEAR_PackageFile_v2
24
 * Supported output formats include array, XML string, and a PEAR_PackageFile_v2
32
 * object, for converting package.xml 1.0 into package.xml 2.0 with no sweat.
25
 * object, for converting package.xml 1.0 into package.xml 2.0 with no sweat.
33
 * @category   pear
26
 * @category   pear
34
 * @package    PEAR
27
 * @package    PEAR
35
 * @author     Greg Beaver <cellog@php.net>
28
 * @author     Greg Beaver <cellog@php.net>
36
 * @copyright  1997-2006 The PHP Group
29
 * @copyright  1997-2009 The Authors
37
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
30
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
38
 * @version    Release: 1.5.1
31
 * @version    Release: 1.10.1
39
 * @link       http://pear.php.net/package/PEAR
32
 * @link       http://pear.php.net/package/PEAR
40
 * @since      Class available since Release 1.4.0a1
33
 * @since      Class available since Release 1.4.0a1
41
 */
34
 */
42
class PEAR_PackageFile_Generator_v1
35
class PEAR_PackageFile_Generator_v1
43
{
36
{
44
    /**
37
    /**
45
     * @var PEAR_PackageFile_v1
38
     * @var PEAR_PackageFile_v1
46
     */
39
     */
47
    var $_packagefile;
40
    var $_packagefile;
48
    function PEAR_PackageFile_Generator_v1(&$packagefile)
41
    function __construct(&$packagefile)
49
    {
42
    {
50
        $this->_packagefile = &$packagefile;
43
        $this->_packagefile = &$packagefile;
51
    }
44
    }
52
 
45
 
53
    function getPackagerVersion()
46
    function getPackagerVersion()
54
    {
47
    {
55
        return '1.5.1';
48
        return '1.10.1';
56
    }
49
    }
57
 
50
 
58
    /**
51
    /**
59
     * @param PEAR_Packager
52
     * @param PEAR_Packager
60
     * @param bool if true, a .tgz is written, otherwise a .tar is written
53
     * @param bool if true, a .tgz is written, otherwise a .tar is written
61
     * @param string|null directory in which to save the .tgz
54
     * @param string|null directory in which to save the .tgz
62
     * @return string|PEAR_Error location of package or error object
55
     * @return string|PEAR_Error location of package or error object
63
     */
56
     */
64
    function toTgz(&$packager, $compress = true, $where = null)
57
    function toTgz(&$packager, $compress = true, $where = null)
65
    {
58
    {
66
        require_once 'Archive/Tar.php';
59
        require_once 'Archive/Tar.php';
67
        if ($where === null) {
60
        if ($where === null) {
68
            if (!($where = System::mktemp(array('-d')))) {
61
            if (!($where = System::mktemp(array('-d')))) {
69
                return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: mktemp failed');
62
                return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: mktemp failed');
70
            }
63
            }
71
        } elseif (!@System::mkDir(array('-p', $where))) {
64
        } elseif (!@System::mkDir(array('-p', $where))) {
72
            return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: "' . $where . '" could' .
65
            return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: "' . $where . '" could' .
73
                ' not be created');
66
                ' not be created');
74
        }
67
        }
75
        if (file_exists($where . DIRECTORY_SEPARATOR . 'package.xml') &&
68
        if (file_exists($where . DIRECTORY_SEPARATOR . 'package.xml') &&
76
              !is_file($where . DIRECTORY_SEPARATOR . 'package.xml')) {
69
              !is_file($where . DIRECTORY_SEPARATOR . 'package.xml')) {
77
            return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: unable to save package.xml as' .
70
            return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: unable to save package.xml as' .
78
                ' "' . $where . DIRECTORY_SEPARATOR . 'package.xml"');
71
                ' "' . $where . DIRECTORY_SEPARATOR . 'package.xml"');
79
        }
72
        }
80
        if (!$this->_packagefile->validate(PEAR_VALIDATE_PACKAGING)) {
73
        if (!$this->_packagefile->validate(PEAR_VALIDATE_PACKAGING)) {
81
            return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: invalid package file');
74
            return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: invalid package file');
82
        }
75
        }
83
        $pkginfo = $this->_packagefile->getArray();
76
        $pkginfo = $this->_packagefile->getArray();
84
        $ext = $compress ? '.tgz' : '.tar';
77
        $ext = $compress ? '.tgz' : '.tar';
85
        $pkgver = $pkginfo['package'] . '-' . $pkginfo['version'];
78
        $pkgver = $pkginfo['package'] . '-' . $pkginfo['version'];
86
        $dest_package = getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext;
79
        $dest_package = getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext;
87
        if (file_exists(getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext) &&
80
        if (file_exists(getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext) &&
88
              !is_file(getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext)) {
81
              !is_file(getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext)) {
89
            return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: cannot create tgz file "' .
82
            return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: cannot create tgz file "' .
90
                getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext . '"');
83
                getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext . '"');
91
        }
84
        }
92
        if ($pkgfile = $this->_packagefile->getPackageFile()) {
85
        if ($pkgfile = $this->_packagefile->getPackageFile()) {
93
            $pkgdir = dirname(realpath($pkgfile));
86
            $pkgdir = dirname(realpath($pkgfile));
94
            $pkgfile = basename($pkgfile);
87
            $pkgfile = basename($pkgfile);
95
        } else {
88
        } else {
96
            return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: package file object must ' .
89
            return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: package file object must ' .
97
                'be created from a real file');
90
                'be created from a real file');
98
        }
91
        }
99
        // {{{ Create the package file list
92
        // {{{ Create the package file list
100
        $filelist = array();
93
        $filelist = array();
101
        $i = 0;
94
        $i = 0;
102
 
95
 
103
        foreach ($this->_packagefile->getFilelist() as $fname => $atts) {
96
        foreach ($this->_packagefile->getFilelist() as $fname => $atts) {
104
            $file = $pkgdir . DIRECTORY_SEPARATOR . $fname;
97
            $file = $pkgdir . DIRECTORY_SEPARATOR . $fname;
105
            if (!file_exists($file)) {
98
            if (!file_exists($file)) {
106
                return PEAR::raiseError("File does not exist: $fname");
99
                return PEAR::raiseError("File does not exist: $fname");
107
            } else {
100
            } else {
108
                $filelist[$i++] = $file;
101
                $filelist[$i++] = $file;
109
                if (!isset($atts['md5sum'])) {
102
                if (!isset($atts['md5sum'])) {
110
                    $this->_packagefile->setFileAttribute($fname, 'md5sum', md5_file($file));
103
                    $this->_packagefile->setFileAttribute($fname, 'md5sum', md5_file($file));
111
                }
104
                }
112
                $packager->log(2, "Adding file $fname");
105
                $packager->log(2, "Adding file $fname");
113
            }
106
            }
114
        }
107
        }
115
        // }}}
108
        // }}}
116
        $packagexml = $this->toPackageFile($where, PEAR_VALIDATE_PACKAGING, 'package.xml', true);
109
        $packagexml = $this->toPackageFile($where, PEAR_VALIDATE_PACKAGING, 'package.xml', true);
117
        if ($packagexml) {
110
        if ($packagexml) {
118
            $tar =& new Archive_Tar($dest_package, $compress);
111
            $tar = new Archive_Tar($dest_package, $compress);
119
            $tar->setErrorHandling(PEAR_ERROR_RETURN); // XXX Don't print errors
112
            $tar->setErrorHandling(PEAR_ERROR_RETURN); // XXX Don't print errors
120
            // ----- Creates with the package.xml file
113
            // ----- Creates with the package.xml file
121
            $ok = $tar->createModify(array($packagexml), '', $where);
114
            $ok = $tar->createModify(array($packagexml), '', $where);
122
            if (PEAR::isError($ok)) {
115
            if (PEAR::isError($ok)) {
123
                return $ok;
116
                return $ok;
124
            } elseif (!$ok) {
117
            } elseif (!$ok) {
125
                return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: tarball creation failed');
118
                return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: tarball creation failed');
126
            }
119
            }
127
            // ----- Add the content of the package
120
            // ----- Add the content of the package
128
            if (!$tar->addModify($filelist, $pkgver, $pkgdir)) {
121
            if (!$tar->addModify($filelist, $pkgver, $pkgdir)) {
129
                return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: tarball creation failed');
122
                return PEAR::raiseError('PEAR_Packagefile_v1::toTgz: tarball creation failed');
130
            }
123
            }
131
            return $dest_package;
124
            return $dest_package;
132
        }
125
        }
133
    }
126
    }
134
 
127
 
135
    /**
128
    /**
136
     * @param string|null directory to place the package.xml in, or null for a temporary dir
129
     * @param string|null directory to place the package.xml in, or null for a temporary dir
137
     * @param int one of the PEAR_VALIDATE_* constants
130
     * @param int one of the PEAR_VALIDATE_* constants
138
     * @param string name of the generated file
131
     * @param string name of the generated file
139
     * @param bool if true, then no analysis will be performed on role="php" files
132
     * @param bool if true, then no analysis will be performed on role="php" files
140
     * @return string|PEAR_Error path to the created file on success
133
     * @return string|PEAR_Error path to the created file on success
141
     */
134
     */
142
    function toPackageFile($where = null, $state = PEAR_VALIDATE_NORMAL, $name = 'package.xml',
135
    function toPackageFile($where = null, $state = PEAR_VALIDATE_NORMAL, $name = 'package.xml',
143
                           $nofilechecking = false)
136
                           $nofilechecking = false)
144
    {
137
    {
145
        if (!$this->_packagefile->validate($state, $nofilechecking)) {
138
        if (!$this->_packagefile->validate($state, $nofilechecking)) {
146
            return PEAR::raiseError('PEAR_Packagefile_v1::toPackageFile: invalid package.xml',
139
            return PEAR::raiseError('PEAR_Packagefile_v1::toPackageFile: invalid package.xml',
147
                null, null, null, $this->_packagefile->getValidationWarnings());
140
                null, null, null, $this->_packagefile->getValidationWarnings());
148
        }
141
        }
149
        if ($where === null) {
142
        if ($where === null) {
150
            if (!($where = System::mktemp(array('-d')))) {
143
            if (!($where = System::mktemp(array('-d')))) {
151
                return PEAR::raiseError('PEAR_Packagefile_v1::toPackageFile: mktemp failed');
144
                return PEAR::raiseError('PEAR_Packagefile_v1::toPackageFile: mktemp failed');
152
            }
145
            }
153
        } elseif (!@System::mkDir(array('-p', $where))) {
146
        } elseif (!@System::mkDir(array('-p', $where))) {
154
            return PEAR::raiseError('PEAR_Packagefile_v1::toPackageFile: "' . $where . '" could' .
147
            return PEAR::raiseError('PEAR_Packagefile_v1::toPackageFile: "' . $where . '" could' .
155
                ' not be created');
148
                ' not be created');
156
        }
149
        }
157
        $newpkgfile = $where . DIRECTORY_SEPARATOR . $name;
150
        $newpkgfile = $where . DIRECTORY_SEPARATOR . $name;
158
        $np = @fopen($newpkgfile, 'wb');
151
        $np = @fopen($newpkgfile, 'wb');
159
        if (!$np) {
152
        if (!$np) {
160
            return PEAR::raiseError('PEAR_Packagefile_v1::toPackageFile: unable to save ' .
153
            return PEAR::raiseError('PEAR_Packagefile_v1::toPackageFile: unable to save ' .
161
               "$name as $newpkgfile");
154
               "$name as $newpkgfile");
162
        }
155
        }
163
        fwrite($np, $this->toXml($state, true));
156
        fwrite($np, $this->toXml($state, true));
164
        fclose($np);
157
        fclose($np);
165
        return $newpkgfile;
158
        return $newpkgfile;
166
    }
159
    }
167
 
160
 
168
    /**
161
    /**
169
     * fix both XML encoding to be UTF8, and replace standard XML entities < > " & '
162
     * fix both XML encoding to be UTF8, and replace standard XML entities < > " & '
170
     *
163
     *
171
     * @param string $string
164
     * @param string $string
172
     * @return string
165
     * @return string
173
     * @access private
166
     * @access private
174
     */
167
     */
175
    function _fixXmlEncoding($string)
168
    function _fixXmlEncoding($string)
176
    {
169
    {
177
        if (version_compare(phpversion(), '5.0.0', 'lt')) {
-
 
178
            $string = utf8_encode($string);
-
 
179
        }
-
 
180
        return strtr($string, array(
170
        return strtr($string, array(
181
                                          '&'  => '&amp;',
171
                                          '&'  => '&amp;',
182
                                          '>'  => '&gt;',
172
                                          '>'  => '&gt;',
183
                                          '<'  => '&lt;',
173
                                          '<'  => '&lt;',
184
                                          '"'  => '&quot;',
174
                                          '"'  => '&quot;',
185
                                          '\'' => '&apos;' ));
175
                                          '\'' => '&apos;' ));
186
    }
176
    }
187
 
177
 
188
    /**
178
    /**
189
     * Return an XML document based on the package info (as returned
179
     * Return an XML document based on the package info (as returned
190
     * by the PEAR_Common::infoFrom* methods).
180
     * by the PEAR_Common::infoFrom* methods).
191
     *
181
     *
192
     * @return string XML data
182
     * @return string XML data
193
     */
183
     */
194
    function toXml($state = PEAR_VALIDATE_NORMAL, $nofilevalidation = false)
184
    function toXml($state = PEAR_VALIDATE_NORMAL, $nofilevalidation = false)
195
    {
185
    {
196
        $this->_packagefile->setDate(date('Y-m-d'));
186
        $this->_packagefile->setDate(date('Y-m-d'));
197
        if (!$this->_packagefile->validate($state, $nofilevalidation)) {
187
        if (!$this->_packagefile->validate($state, $nofilevalidation)) {
198
            return false;
188
            return false;
199
        }
189
        }
200
        $pkginfo = $this->_packagefile->getArray();
190
        $pkginfo = $this->_packagefile->getArray();
201
        static $maint_map = array(
191
        static $maint_map = array(
202
            "handle" => "user",
192
            "handle" => "user",
203
            "name" => "name",
193
            "name" => "name",
204
            "email" => "email",
194
            "email" => "email",
205
            "role" => "role",
195
            "role" => "role",
206
            );
196
            );
207
        $ret = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
197
        $ret = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
208
        $ret .= "<!DOCTYPE package SYSTEM \"http://pear.php.net/dtd/package-1.0\">\n";
198
        $ret .= "<!DOCTYPE package SYSTEM \"http://pear.php.net/dtd/package-1.0\">\n";
209
        $ret .= "<package version=\"1.0\" packagerversion=\"1.5.1\">\n" .
199
        $ret .= "<package version=\"1.0\" packagerversion=\"1.10.1\">\n" .
210
" <name>$pkginfo[package]</name>";
200
" <name>$pkginfo[package]</name>";
211
        if (isset($pkginfo['extends'])) {
201
        if (isset($pkginfo['extends'])) {
212
            $ret .= "\n<extends>$pkginfo[extends]</extends>";
202
            $ret .= "\n<extends>$pkginfo[extends]</extends>";
213
        }
203
        }
214
        $ret .=
204
        $ret .=
215
 "\n <summary>".$this->_fixXmlEncoding($pkginfo['summary'])."</summary>\n" .
205
 "\n <summary>".$this->_fixXmlEncoding($pkginfo['summary'])."</summary>\n" .
216
" <description>".trim($this->_fixXmlEncoding($pkginfo['description']))."\n </description>\n" .
206
" <description>".trim($this->_fixXmlEncoding($pkginfo['description']))."\n </description>\n" .
217
" <maintainers>\n";
207
" <maintainers>\n";
218
        foreach ($pkginfo['maintainers'] as $maint) {
208
        foreach ($pkginfo['maintainers'] as $maint) {
219
            $ret .= "  <maintainer>\n";
209
            $ret .= "  <maintainer>\n";
220
            foreach ($maint_map as $idx => $elm) {
210
            foreach ($maint_map as $idx => $elm) {
221
                $ret .= "   <$elm>";
211
                $ret .= "   <$elm>";
222
                $ret .= $this->_fixXmlEncoding($maint[$idx]);
212
                $ret .= $this->_fixXmlEncoding($maint[$idx]);
223
                $ret .= "</$elm>\n";
213
                $ret .= "</$elm>\n";
224
            }
214
            }
225
            $ret .= "  </maintainer>\n";
215
            $ret .= "  </maintainer>\n";
226
        }
216
        }
227
        $ret .= "  </maintainers>\n";
217
        $ret .= "  </maintainers>\n";
228
        $ret .= $this->_makeReleaseXml($pkginfo, false, $state);
218
        $ret .= $this->_makeReleaseXml($pkginfo, false, $state);
229
        if (isset($pkginfo['changelog']) && count($pkginfo['changelog']) > 0) {
219
        if (isset($pkginfo['changelog']) && count($pkginfo['changelog']) > 0) {
230
            $ret .= " <changelog>\n";
220
            $ret .= " <changelog>\n";
231
            foreach ($pkginfo['changelog'] as $oldrelease) {
221
            foreach ($pkginfo['changelog'] as $oldrelease) {
232
                $ret .= $this->_makeReleaseXml($oldrelease, true);
222
                $ret .= $this->_makeReleaseXml($oldrelease, true);
233
            }
223
            }
234
            $ret .= " </changelog>\n";
224
            $ret .= " </changelog>\n";
235
        }
225
        }
236
        $ret .= "</package>\n";
226
        $ret .= "</package>\n";
237
        return $ret;
227
        return $ret;
238
    }
228
    }
239
 
229
 
240
    // }}}
230
    // }}}
241
    // {{{ _makeReleaseXml()
231
    // {{{ _makeReleaseXml()
242
 
232
 
243
    /**
233
    /**
244
     * Generate part of an XML description with release information.
234
     * Generate part of an XML description with release information.
245
     *
235
     *
246
     * @param array  $pkginfo    array with release information
236
     * @param array  $pkginfo    array with release information
247
     * @param bool   $changelog  whether the result will be in a changelog element
237
     * @param bool   $changelog  whether the result will be in a changelog element
248
     *
238
     *
249
     * @return string XML data
239
     * @return string XML data
250
     *
240
     *
251
     * @access private
241
     * @access private
252
     */
242
     */
253
    function _makeReleaseXml($pkginfo, $changelog = false, $state = PEAR_VALIDATE_NORMAL)
243
    function _makeReleaseXml($pkginfo, $changelog = false, $state = PEAR_VALIDATE_NORMAL)
254
    {
244
    {
255
        // XXX QUOTE ENTITIES IN PCDATA, OR EMBED IN CDATA BLOCKS!!
245
        // XXX QUOTE ENTITIES IN PCDATA, OR EMBED IN CDATA BLOCKS!!
256
        $indent = $changelog ? "  " : "";
246
        $indent = $changelog ? "  " : "";
257
        $ret = "$indent <release>\n";
247
        $ret = "$indent <release>\n";
258
        if (!empty($pkginfo['version'])) {
248
        if (!empty($pkginfo['version'])) {
259
            $ret .= "$indent  <version>$pkginfo[version]</version>\n";
249
            $ret .= "$indent  <version>$pkginfo[version]</version>\n";
260
        }
250
        }
261
        if (!empty($pkginfo['release_date'])) {
251
        if (!empty($pkginfo['release_date'])) {
262
            $ret .= "$indent  <date>$pkginfo[release_date]</date>\n";
252
            $ret .= "$indent  <date>$pkginfo[release_date]</date>\n";
263
        }
253
        }
264
        if (!empty($pkginfo['release_license'])) {
254
        if (!empty($pkginfo['release_license'])) {
265
            $ret .= "$indent  <license>$pkginfo[release_license]</license>\n";
255
            $ret .= "$indent  <license>$pkginfo[release_license]</license>\n";
266
        }
256
        }
267
        if (!empty($pkginfo['release_state'])) {
257
        if (!empty($pkginfo['release_state'])) {
268
            $ret .= "$indent  <state>$pkginfo[release_state]</state>\n";
258
            $ret .= "$indent  <state>$pkginfo[release_state]</state>\n";
269
        }
259
        }
270
        if (!empty($pkginfo['release_notes'])) {
260
        if (!empty($pkginfo['release_notes'])) {
271
            $ret .= "$indent  <notes>".trim($this->_fixXmlEncoding($pkginfo['release_notes']))
261
            $ret .= "$indent  <notes>".trim($this->_fixXmlEncoding($pkginfo['release_notes']))
272
            ."\n$indent  </notes>\n";
262
            ."\n$indent  </notes>\n";
273
        }
263
        }
274
        if (!empty($pkginfo['release_warnings'])) {
264
        if (!empty($pkginfo['release_warnings'])) {
275
            $ret .= "$indent  <warnings>".$this->_fixXmlEncoding($pkginfo['release_warnings'])."</warnings>\n";
265
            $ret .= "$indent  <warnings>".$this->_fixXmlEncoding($pkginfo['release_warnings'])."</warnings>\n";
276
        }
266
        }
277
        if (isset($pkginfo['release_deps']) && sizeof($pkginfo['release_deps']) > 0) {
267
        if (isset($pkginfo['release_deps']) && sizeof($pkginfo['release_deps']) > 0) {
278
            $ret .= "$indent  <deps>\n";
268
            $ret .= "$indent  <deps>\n";
279
            foreach ($pkginfo['release_deps'] as $dep) {
269
            foreach ($pkginfo['release_deps'] as $dep) {
280
                $ret .= "$indent   <dep type=\"$dep[type]\" rel=\"$dep[rel]\"";
270
                $ret .= "$indent   <dep type=\"$dep[type]\" rel=\"$dep[rel]\"";
281
                if (isset($dep['version'])) {
271
                if (isset($dep['version'])) {
282
                    $ret .= " version=\"$dep[version]\"";
272
                    $ret .= " version=\"$dep[version]\"";
283
                }
273
                }
284
                if (isset($dep['optional'])) {
274
                if (isset($dep['optional'])) {
285
                    $ret .= " optional=\"$dep[optional]\"";
275
                    $ret .= " optional=\"$dep[optional]\"";
286
                }
276
                }
287
                if (isset($dep['name'])) {
277
                if (isset($dep['name'])) {
288
                    $ret .= ">$dep[name]</dep>\n";
278
                    $ret .= ">$dep[name]</dep>\n";
289
                } else {
279
                } else {
290
                    $ret .= "/>\n";
280
                    $ret .= "/>\n";
291
                }
281
                }
292
            }
282
            }
293
            $ret .= "$indent  </deps>\n";
283
            $ret .= "$indent  </deps>\n";
294
        }
284
        }
295
        if (isset($pkginfo['configure_options'])) {
285
        if (isset($pkginfo['configure_options'])) {
296
            $ret .= "$indent  <configureoptions>\n";
286
            $ret .= "$indent  <configureoptions>\n";
297
            foreach ($pkginfo['configure_options'] as $c) {
287
            foreach ($pkginfo['configure_options'] as $c) {
298
                $ret .= "$indent   <configureoption name=\"".
288
                $ret .= "$indent   <configureoption name=\"".
299
                    $this->_fixXmlEncoding($c['name']) . "\"";
289
                    $this->_fixXmlEncoding($c['name']) . "\"";
300
                if (isset($c['default'])) {
290
                if (isset($c['default'])) {
301
                    $ret .= " default=\"" . $this->_fixXmlEncoding($c['default']) . "\"";
291
                    $ret .= " default=\"" . $this->_fixXmlEncoding($c['default']) . "\"";
302
                }
292
                }
303
                $ret .= " prompt=\"" . $this->_fixXmlEncoding($c['prompt']) . "\"";
293
                $ret .= " prompt=\"" . $this->_fixXmlEncoding($c['prompt']) . "\"";
304
                $ret .= "/>\n";
294
                $ret .= "/>\n";
305
            }
295
            }
306
            $ret .= "$indent  </configureoptions>\n";
296
            $ret .= "$indent  </configureoptions>\n";
307
        }
297
        }
308
        if (isset($pkginfo['provides'])) {
298
        if (isset($pkginfo['provides'])) {
309
            foreach ($pkginfo['provides'] as $key => $what) {
299
            foreach ($pkginfo['provides'] as $key => $what) {
310
                $ret .= "$indent  <provides type=\"$what[type]\" ";
300
                $ret .= "$indent  <provides type=\"$what[type]\" ";
311
                $ret .= "name=\"$what[name]\" ";
301
                $ret .= "name=\"$what[name]\" ";
312
                if (isset($what['extends'])) {
302
                if (isset($what['extends'])) {
313
                    $ret .= "extends=\"$what[extends]\" ";
303
                    $ret .= "extends=\"$what[extends]\" ";
314
                }
304
                }
315
                $ret .= "/>\n";
305
                $ret .= "/>\n";
316
            }
306
            }
317
        }
307
        }
318
        if (isset($pkginfo['filelist'])) {
308
        if (isset($pkginfo['filelist'])) {
319
            $ret .= "$indent  <filelist>\n";
309
            $ret .= "$indent  <filelist>\n";
320
            if ($state ^ PEAR_VALIDATE_PACKAGING) {
310
            if ($state ^ PEAR_VALIDATE_PACKAGING) {
321
                $ret .= $this->recursiveXmlFilelist($pkginfo['filelist']);
311
                $ret .= $this->recursiveXmlFilelist($pkginfo['filelist']);
322
            } else {
312
            } else {
323
                foreach ($pkginfo['filelist'] as $file => $fa) {
313
                foreach ($pkginfo['filelist'] as $file => $fa) {
324
                    if (!isset($fa['role'])) {
314
                    if (!isset($fa['role'])) {
325
                        $fa['role'] = '';
315
                        $fa['role'] = '';
326
                    }
316
                    }
327
                    $ret .= "$indent   <file role=\"$fa[role]\"";
317
                    $ret .= "$indent   <file role=\"$fa[role]\"";
328
                    if (isset($fa['baseinstalldir'])) {
318
                    if (isset($fa['baseinstalldir'])) {
329
                        $ret .= ' baseinstalldir="' .
319
                        $ret .= ' baseinstalldir="' .
330
                            $this->_fixXmlEncoding($fa['baseinstalldir']) . '"';
320
                            $this->_fixXmlEncoding($fa['baseinstalldir']) . '"';
331
                    }
321
                    }
332
                    if (isset($fa['md5sum'])) {
322
                    if (isset($fa['md5sum'])) {
333
                        $ret .= " md5sum=\"$fa[md5sum]\"";
323
                        $ret .= " md5sum=\"$fa[md5sum]\"";
334
                    }
324
                    }
335
                    if (isset($fa['platform'])) {
325
                    if (isset($fa['platform'])) {
336
                        $ret .= " platform=\"$fa[platform]\"";
326
                        $ret .= " platform=\"$fa[platform]\"";
337
                    }
327
                    }
338
                    if (!empty($fa['install-as'])) {
328
                    if (!empty($fa['install-as'])) {
339
                        $ret .= ' install-as="' .
329
                        $ret .= ' install-as="' .
340
                            $this->_fixXmlEncoding($fa['install-as']) . '"';
330
                            $this->_fixXmlEncoding($fa['install-as']) . '"';
341
                    }
331
                    }
342
                    $ret .= ' name="' . $this->_fixXmlEncoding($file) . '"';
332
                    $ret .= ' name="' . $this->_fixXmlEncoding($file) . '"';
343
                    if (empty($fa['replacements'])) {
333
                    if (empty($fa['replacements'])) {
344
                        $ret .= "/>\n";
334
                        $ret .= "/>\n";
345
                    } else {
335
                    } else {
346
                        $ret .= ">\n";
336
                        $ret .= ">\n";
347
                        foreach ($fa['replacements'] as $r) {
337
                        foreach ($fa['replacements'] as $r) {
348
                            $ret .= "$indent    <replace";
338
                            $ret .= "$indent    <replace";
349
                            foreach ($r as $k => $v) {
339
                            foreach ($r as $k => $v) {
350
                                $ret .= " $k=\"" . $this->_fixXmlEncoding($v) .'"';
340
                                $ret .= " $k=\"" . $this->_fixXmlEncoding($v) .'"';
351
                            }
341
                            }
352
                            $ret .= "/>\n";
342
                            $ret .= "/>\n";
353
                        }
343
                        }
354
                        $ret .= "$indent   </file>\n";
344
                        $ret .= "$indent   </file>\n";
355
                    }
345
                    }
356
                }
346
                }
357
            }
347
            }
358
            $ret .= "$indent  </filelist>\n";
348
            $ret .= "$indent  </filelist>\n";
359
        }
349
        }
360
        $ret .= "$indent </release>\n";
350
        $ret .= "$indent </release>\n";
361
        return $ret;
351
        return $ret;
362
    }
352
    }
363
 
353
 
364
    /**
354
    /**
365
     * @param array
355
     * @param array
366
     * @access protected
356
     * @access protected
367
     */
357
     */
368
    function recursiveXmlFilelist($list)
358
    function recursiveXmlFilelist($list)
369
    {
359
    {
370
        $this->_dirs = array();
360
        $this->_dirs = array();
371
        foreach ($list as $file => $attributes) {
361
        foreach ($list as $file => $attributes) {
372
            $this->_addDir($this->_dirs, explode('/', dirname($file)), $file, $attributes);
362
            $this->_addDir($this->_dirs, explode('/', dirname($file)), $file, $attributes);
373
        }
363
        }
374
        return $this->_formatDir($this->_dirs);
364
        return $this->_formatDir($this->_dirs);
375
    }
365
    }
376
 
366
 
377
    /**
367
    /**
378
     * @param array
368
     * @param array
379
     * @param array
369
     * @param array
380
     * @param string|null
370
     * @param string|null
381
     * @param array|null
371
     * @param array|null
382
     * @access private
372
     * @access private
383
     */
373
     */
384
    function _addDir(&$dirs, $dir, $file = null, $attributes = null)
374
    function _addDir(&$dirs, $dir, $file = null, $attributes = null)
385
    {
375
    {
386
        if ($dir == array() || $dir == array('.')) {
376
        if ($dir == array() || $dir == array('.')) {
387
            $dirs['files'][basename($file)] = $attributes;
377
            $dirs['files'][basename($file)] = $attributes;
388
            return;
378
            return;
389
        }
379
        }
390
        $curdir = array_shift($dir);
380
        $curdir = array_shift($dir);
391
        if (!isset($dirs['dirs'][$curdir])) {
381
        if (!isset($dirs['dirs'][$curdir])) {
392
            $dirs['dirs'][$curdir] = array();
382
            $dirs['dirs'][$curdir] = array();
393
        }
383
        }
394
        $this->_addDir($dirs['dirs'][$curdir], $dir, $file, $attributes);
384
        $this->_addDir($dirs['dirs'][$curdir], $dir, $file, $attributes);
395
    }
385
    }
396
 
386
 
397
    /**
387
    /**
398
     * @param array
388
     * @param array
399
     * @param string
389
     * @param string
400
     * @param string
390
     * @param string
401
     * @access private
391
     * @access private
402
     */
392
     */
403
    function _formatDir($dirs, $indent = '', $curdir = '')
393
    function _formatDir($dirs, $indent = '', $curdir = '')
404
    {
394
    {
405
        $ret = '';
395
        $ret = '';
406
        if (!count($dirs)) {
396
        if (!count($dirs)) {
407
            return '';
397
            return '';
408
        }
398
        }
409
        if (isset($dirs['dirs'])) {
399
        if (isset($dirs['dirs'])) {
410
            uksort($dirs['dirs'], 'strnatcasecmp');
400
            uksort($dirs['dirs'], 'strnatcasecmp');
411
            foreach ($dirs['dirs'] as $dir => $contents) {
401
            foreach ($dirs['dirs'] as $dir => $contents) {
412
                $usedir = "$curdir/$dir";
402
                $usedir = "$curdir/$dir";
413
                $ret .= "$indent   <dir name=\"$dir\">\n";
403
                $ret .= "$indent   <dir name=\"$dir\">\n";
414
                $ret .= $this->_formatDir($contents, "$indent ", $usedir);
404
                $ret .= $this->_formatDir($contents, "$indent ", $usedir);
415
                $ret .= "$indent   </dir> <!-- $usedir -->\n";
405
                $ret .= "$indent   </dir> <!-- $usedir -->\n";
416
            }
406
            }
417
        }
407
        }
418
        if (isset($dirs['files'])) {
408
        if (isset($dirs['files'])) {
419
            uksort($dirs['files'], 'strnatcasecmp');
409
            uksort($dirs['files'], 'strnatcasecmp');
420
            foreach ($dirs['files'] as $file => $attribs) {
410
            foreach ($dirs['files'] as $file => $attribs) {
421
                $ret .= $this->_formatFile($file, $attribs, $indent);
411
                $ret .= $this->_formatFile($file, $attribs, $indent);
422
            }
412
            }
423
        }
413
        }
424
        return $ret;
414
        return $ret;
425
    }
415
    }
426
 
416
 
427
    /**
417
    /**
428
     * @param string
418
     * @param string
429
     * @param array
419
     * @param array
430
     * @param string
420
     * @param string
431
     * @access private
421
     * @access private
432
     */
422
     */
433
    function _formatFile($file, $attributes, $indent)
423
    function _formatFile($file, $attributes, $indent)
434
    {
424
    {
435
        $ret = "$indent   <file role=\"$attributes[role]\"";
425
        $ret = "$indent   <file role=\"$attributes[role]\"";
436
        if (isset($attributes['baseinstalldir'])) {
426
        if (isset($attributes['baseinstalldir'])) {
437
            $ret .= ' baseinstalldir="' .
427
            $ret .= ' baseinstalldir="' .
438
                $this->_fixXmlEncoding($attributes['baseinstalldir']) . '"';
428
                $this->_fixXmlEncoding($attributes['baseinstalldir']) . '"';
439
        }
429
        }
440
        if (isset($attributes['md5sum'])) {
430
        if (isset($attributes['md5sum'])) {
441
            $ret .= " md5sum=\"$attributes[md5sum]\"";
431
            $ret .= " md5sum=\"$attributes[md5sum]\"";
442
        }
432
        }
443
        if (isset($attributes['platform'])) {
433
        if (isset($attributes['platform'])) {
444
            $ret .= " platform=\"$attributes[platform]\"";
434
            $ret .= " platform=\"$attributes[platform]\"";
445
        }
435
        }
446
        if (!empty($attributes['install-as'])) {
436
        if (!empty($attributes['install-as'])) {
447
            $ret .= ' install-as="' .
437
            $ret .= ' install-as="' .
448
                $this->_fixXmlEncoding($attributes['install-as']) . '"';
438
                $this->_fixXmlEncoding($attributes['install-as']) . '"';
449
        }
439
        }
450
        $ret .= ' name="' . $this->_fixXmlEncoding($file) . '"';
440
        $ret .= ' name="' . $this->_fixXmlEncoding($file) . '"';
451
        if (empty($attributes['replacements'])) {
441
        if (empty($attributes['replacements'])) {
452
            $ret .= "/>\n";
442
            $ret .= "/>\n";
453
        } else {
443
        } else {
454
            $ret .= ">\n";
444
            $ret .= ">\n";
455
            foreach ($attributes['replacements'] as $r) {
445
            foreach ($attributes['replacements'] as $r) {
456
                $ret .= "$indent    <replace";
446
                $ret .= "$indent    <replace";
457
                foreach ($r as $k => $v) {
447
                foreach ($r as $k => $v) {
458
                    $ret .= " $k=\"" . $this->_fixXmlEncoding($v) .'"';
448
                    $ret .= " $k=\"" . $this->_fixXmlEncoding($v) .'"';
459
                }
449
                }
460
                $ret .= "/>\n";
450
                $ret .= "/>\n";
461
            }
451
            }
462
            $ret .= "$indent   </file>\n";
452
            $ret .= "$indent   </file>\n";
463
        }
453
        }
464
        return $ret;
454
        return $ret;
465
    }
455
    }
466
 
456
 
467
    // {{{ _unIndent()
457
    // {{{ _unIndent()
468
 
458
 
469
    /**
459
    /**
470
     * Unindent given string (?)
460
     * Unindent given string (?)
471
     *
461
     *
472
     * @param string $str The string that has to be unindented.
462
     * @param string $str The string that has to be unindented.
473
     * @return string
463
     * @return string
474
     * @access private
464
     * @access private
475
     */
465
     */
476
    function _unIndent($str)
466
    function _unIndent($str)
477
    {
467
    {
478
        // remove leading newlines
468
        // remove leading newlines
479
        $str = preg_replace('/^[\r\n]+/', '', $str);
469
        $str = preg_replace('/^[\r\n]+/', '', $str);
480
        // find whitespace at the beginning of the first line
470
        // find whitespace at the beginning of the first line
481
        $indent_len = strspn($str, " \t");
471
        $indent_len = strspn($str, " \t");
482
        $indent = substr($str, 0, $indent_len);
472
        $indent = substr($str, 0, $indent_len);
483
        $data = '';
473
        $data = '';
484
        // remove the same amount of whitespace from following lines
474
        // remove the same amount of whitespace from following lines
485
        foreach (explode("\n", $str) as $line) {
475
        foreach (explode("\n", $str) as $line) {
486
            if (substr($line, 0, $indent_len) == $indent) {
476
            if (substr($line, 0, $indent_len) == $indent) {
487
                $data .= substr($line, $indent_len) . "\n";
477
                $data .= substr($line, $indent_len) . "\n";
488
            }
478
            }
489
        }
479
        }
490
        return $data;
480
        return $data;
491
    }
481
    }
492
 
482
 
493
    /**
483
    /**
494
     * @return array
484
     * @return array
495
     */
485
     */
496
    function dependenciesToV2()
486
    function dependenciesToV2()
497
    {
487
    {
498
        $arr = array();
488
        $arr = array();
499
        $this->_convertDependencies2_0($arr);
489
        $this->_convertDependencies2_0($arr);
500
        return $arr['dependencies'];
490
        return $arr['dependencies'];
501
    }
491
    }
502
 
492
 
503
    /**
493
    /**
504
     * Convert a package.xml version 1.0 into version 2.0
494
     * Convert a package.xml version 1.0 into version 2.0
505
     *
495
     *
506
     * Note that this does a basic conversion, to allow more advanced
496
     * Note that this does a basic conversion, to allow more advanced
507
     * features like bundles and multiple releases
497
     * features like bundles and multiple releases
508
     * @param string the classname to instantiate and return.  This must be
498
     * @param string the classname to instantiate and return.  This must be
509
     *               PEAR_PackageFile_v2 or a descendant
499
     *               PEAR_PackageFile_v2 or a descendant
510
     * @param boolean if true, only valid, deterministic package.xml 1.0 as defined by the
500
     * @param boolean if true, only valid, deterministic package.xml 1.0 as defined by the
511
     *                strictest parameters will be converted
501
     *                strictest parameters will be converted
512
     * @return PEAR_PackageFile_v2|PEAR_Error
502
     * @return PEAR_PackageFile_v2|PEAR_Error
513
     */
503
     */
514
    function &toV2($class = 'PEAR_PackageFile_v2', $strict = false)
504
    function &toV2($class = 'PEAR_PackageFile_v2', $strict = false)
515
    {
505
    {
516
        if ($strict) {
506
        if ($strict) {
517
            if (!$this->_packagefile->validate()) {
507
            if (!$this->_packagefile->validate()) {
518
                $a = PEAR::raiseError('invalid package.xml version 1.0 cannot be converted' .
508
                $a = PEAR::raiseError('invalid package.xml version 1.0 cannot be converted' .
519
                    ' to version 2.0', null, null, null,
509
                    ' to version 2.0', null, null, null,
520
                    $this->_packagefile->getValidationWarnings(true));
510
                    $this->_packagefile->getValidationWarnings(true));
521
                return $a;
511
                return $a;
522
            }
512
            }
523
        }
513
        }
-
 
514
 
524
        $arr = array(
515
        $arr = array(
525
            'attribs' => array(
516
            'attribs' => array(
526
                             'version' => '2.0',
517
                             'version' => '2.0',
527
                             'xmlns' => 'http://pear.php.net/dtd/package-2.0',
518
                             'xmlns' => 'http://pear.php.net/dtd/package-2.0',
528
                             'xmlns:tasks' => 'http://pear.php.net/dtd/tasks-1.0',
519
                             'xmlns:tasks' => 'http://pear.php.net/dtd/tasks-1.0',
529
                             'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
520
                             'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
530
                             'xsi:schemaLocation' => "http://pear.php.net/dtd/tasks-1.0\n" .
521
                             'xsi:schemaLocation' => "http://pear.php.net/dtd/tasks-1.0\n" .
531
"http://pear.php.net/dtd/tasks-1.0.xsd\n" .
522
"http://pear.php.net/dtd/tasks-1.0.xsd\n" .
532
"http://pear.php.net/dtd/package-2.0\n" .
523
"http://pear.php.net/dtd/package-2.0\n" .
533
'http://pear.php.net/dtd/package-2.0.xsd',
524
'http://pear.php.net/dtd/package-2.0.xsd',
534
                         ),
525
                         ),
535
            'name' => $this->_packagefile->getPackage(),
526
            'name' => $this->_packagefile->getPackage(),
536
            'channel' => 'pear.php.net',
527
            'channel' => 'pear.php.net',
537
        );
528
        );
538
        $arr['summary'] = $this->_packagefile->getSummary();
529
        $arr['summary'] = $this->_packagefile->getSummary();
539
        $arr['description'] = $this->_packagefile->getDescription();
530
        $arr['description'] = $this->_packagefile->getDescription();
540
        $maintainers = $this->_packagefile->getMaintainers();
531
        $maintainers = $this->_packagefile->getMaintainers();
541
        foreach ($maintainers as $maintainer) {
532
        foreach ($maintainers as $maintainer) {
542
            if ($maintainer['role'] != 'lead') {
533
            if ($maintainer['role'] != 'lead') {
543
                continue;
534
                continue;
544
            }
535
            }
545
            $new = array(
536
            $new = array(
546
                'name' => $maintainer['name'],
537
                'name' => $maintainer['name'],
547
                'user' => $maintainer['handle'],
538
                'user' => $maintainer['handle'],
548
                'email' => $maintainer['email'],
539
                'email' => $maintainer['email'],
549
                'active' => 'yes',
540
                'active' => 'yes',
550
            );
541
            );
551
            $arr['lead'][] = $new;
542
            $arr['lead'][] = $new;
552
        }
543
        }
-
 
544
 
553
        if (!isset($arr['lead'])) { // some people... you know?
545
        if (!isset($arr['lead'])) { // some people... you know?
554
            $arr['lead'] = array(
546
            $arr['lead'] = array(
555
                'name' => 'unknown',
547
                'name' => 'unknown',
556
                'user' => 'unknown',
548
                'user' => 'unknown',
557
                'email' => 'noleadmaintainer@example.com',
549
                'email' => 'noleadmaintainer@example.com',
558
                'active' => 'no',
550
                'active' => 'no',
559
            );
551
            );
560
        }
552
        }
-
 
553
 
561
        if (count($arr['lead']) == 1) {
554
        if (count($arr['lead']) == 1) {
562
            $arr['lead'] = $arr['lead'][0];
555
            $arr['lead'] = $arr['lead'][0];
563
        }
556
        }
-
 
557
 
564
        foreach ($maintainers as $maintainer) {
558
        foreach ($maintainers as $maintainer) {
565
            if ($maintainer['role'] == 'lead') {
559
            if ($maintainer['role'] == 'lead') {
566
                continue;
560
                continue;
567
            }
561
            }
568
            $new = array(
562
            $new = array(
569
                'name' => $maintainer['name'],
563
                'name' => $maintainer['name'],
570
                'user' => $maintainer['handle'],
564
                'user' => $maintainer['handle'],
571
                'email' => $maintainer['email'],
565
                'email' => $maintainer['email'],
572
                'active' => 'yes',
566
                'active' => 'yes',
573
            );
567
            );
574
            $arr[$maintainer['role']][] = $new;
568
            $arr[$maintainer['role']][] = $new;
575
        }
569
        }
-
 
570
 
576
        if (isset($arr['developer']) && count($arr['developer']) == 1) {
571
        if (isset($arr['developer']) && count($arr['developer']) == 1) {
577
            $arr['developer'] = $arr['developer'][0];
572
            $arr['developer'] = $arr['developer'][0];
578
        }
573
        }
-
 
574
 
579
        if (isset($arr['contributor']) && count($arr['contributor']) == 1) {
575
        if (isset($arr['contributor']) && count($arr['contributor']) == 1) {
580
            $arr['contributor'] = $arr['contributor'][0];
576
            $arr['contributor'] = $arr['contributor'][0];
581
        }
577
        }
-
 
578
 
582
        if (isset($arr['helper']) && count($arr['helper']) == 1) {
579
        if (isset($arr['helper']) && count($arr['helper']) == 1) {
583
            $arr['helper'] = $arr['helper'][0];
580
            $arr['helper'] = $arr['helper'][0];
584
        }
581
        }
-
 
582
 
585
        $arr['date'] = $this->_packagefile->getDate();
583
        $arr['date'] = $this->_packagefile->getDate();
586
        $arr['version'] =
584
        $arr['version'] =
587
            array(
585
            array(
588
                'release' => $this->_packagefile->getVersion(),
586
                'release' => $this->_packagefile->getVersion(),
589
                'api' => $this->_packagefile->getVersion(),
587
                'api' => $this->_packagefile->getVersion(),
590
            );
588
            );
591
        $arr['stability'] =
589
        $arr['stability'] =
592
            array(
590
            array(
593
                'release' => $this->_packagefile->getState(),
591
                'release' => $this->_packagefile->getState(),
594
                'api' => $this->_packagefile->getState(),
592
                'api' => $this->_packagefile->getState(),
595
            );
593
            );
596
        $licensemap =
594
        $licensemap =
597
            array(
595
            array(
598
                'php' => 'http://www.php.net/license',
596
                'php' => 'http://www.php.net/license',
599
                'php license' => 'http://www.php.net/license',
597
                'php license' => 'http://www.php.net/license',
600
                'lgpl' => 'http://www.gnu.org/copyleft/lesser.html',
598
                'lgpl' => 'http://www.gnu.org/copyleft/lesser.html',
601
                'bsd' => 'http://www.opensource.org/licenses/bsd-license.php',
599
                'bsd' => 'http://www.opensource.org/licenses/bsd-license.php',
602
                'bsd style' => 'http://www.opensource.org/licenses/bsd-license.php',
600
                'bsd style' => 'http://www.opensource.org/licenses/bsd-license.php',
603
                'bsd-style' => 'http://www.opensource.org/licenses/bsd-license.php',
601
                'bsd-style' => 'http://www.opensource.org/licenses/bsd-license.php',
604
                'mit' => 'http://www.opensource.org/licenses/mit-license.php',
602
                'mit' => 'http://www.opensource.org/licenses/mit-license.php',
605
                'gpl' => 'http://www.gnu.org/copyleft/gpl.html',
603
                'gpl' => 'http://www.gnu.org/copyleft/gpl.html',
606
                'apache' => 'http://www.opensource.org/licenses/apache2.0.php'
604
                'apache' => 'http://www.opensource.org/licenses/apache2.0.php'
607
            );
605
            );
-
 
606
 
608
        if (isset($licensemap[strtolower($this->_packagefile->getLicense())])) {
607
        if (isset($licensemap[strtolower($this->_packagefile->getLicense())])) {
609
            $arr['license'] = array(
608
            $arr['license'] = array(
610
                'attribs' => array('uri' =>
609
                'attribs' => array('uri' =>
611
                    $licensemap[strtolower($this->_packagefile->getLicense())]),
610
                    $licensemap[strtolower($this->_packagefile->getLicense())]),
612
                '_content' => $this->_packagefile->getLicense()
611
                '_content' => $this->_packagefile->getLicense()
613
                );
612
                );
614
        } else {
613
        } else {
615
            // don't use bogus uri
614
            // don't use bogus uri
616
            $arr['license'] = $this->_packagefile->getLicense();
615
            $arr['license'] = $this->_packagefile->getLicense();
617
        }
616
        }
-
 
617
 
618
        $arr['notes'] = $this->_packagefile->getNotes();
618
        $arr['notes'] = $this->_packagefile->getNotes();
619
        $temp = array();
619
        $temp = array();
620
        $arr['contents'] = $this->_convertFilelist2_0($temp);
620
        $arr['contents'] = $this->_convertFilelist2_0($temp);
621
        $this->_convertDependencies2_0($arr);
621
        $this->_convertDependencies2_0($arr);
622
        $release = ($this->_packagefile->getConfigureOptions() || $this->_isExtension) ?
622
        $release = ($this->_packagefile->getConfigureOptions() || $this->_isExtension) ?
623
            'extsrcrelease' : 'phprelease';
623
            'extsrcrelease' : 'phprelease';
624
        if ($release == 'extsrcrelease') {
624
        if ($release == 'extsrcrelease') {
625
            $arr['channel'] = 'pecl.php.net';
625
            $arr['channel'] = 'pecl.php.net';
626
            $arr['providesextension'] = $arr['name']; // assumption
626
            $arr['providesextension'] = $arr['name']; // assumption
627
        }
627
        }
-
 
628
 
628
        $arr[$release] = array();
629
        $arr[$release] = array();
629
        if ($this->_packagefile->getConfigureOptions()) {
630
        if ($this->_packagefile->getConfigureOptions()) {
630
            $arr[$release]['configureoption'] = $this->_packagefile->getConfigureOptions();
631
            $arr[$release]['configureoption'] = $this->_packagefile->getConfigureOptions();
631
            foreach ($arr[$release]['configureoption'] as $i => $opt) {
632
            foreach ($arr[$release]['configureoption'] as $i => $opt) {
632
                $arr[$release]['configureoption'][$i] = array('attribs' => $opt);
633
                $arr[$release]['configureoption'][$i] = array('attribs' => $opt);
633
            }
634
            }
634
            if (count($arr[$release]['configureoption']) == 1) {
635
            if (count($arr[$release]['configureoption']) == 1) {
635
                $arr[$release]['configureoption'] = $arr[$release]['configureoption'][0];
636
                $arr[$release]['configureoption'] = $arr[$release]['configureoption'][0];
636
            }
637
            }
637
        }
638
        }
-
 
639
 
638
        $this->_convertRelease2_0($arr[$release], $temp);
640
        $this->_convertRelease2_0($arr[$release], $temp);
639
        if ($release == 'extsrcrelease' && count($arr[$release]) > 1) {
641
        if ($release == 'extsrcrelease' && count($arr[$release]) > 1) {
640
            // multiple extsrcrelease tags added in PEAR 1.4.1
642
            // multiple extsrcrelease tags added in PEAR 1.4.1
641
            $arr['dependencies']['required']['pearinstaller']['min'] = '1.4.1';
643
            $arr['dependencies']['required']['pearinstaller']['min'] = '1.4.1';
642
        }
644
        }
-
 
645
 
643
        if ($cl = $this->_packagefile->getChangelog()) {
646
        if ($cl = $this->_packagefile->getChangelog()) {
644
            foreach ($cl as $release) {
647
            foreach ($cl as $release) {
645
                $rel = array();
648
                $rel = array();
646
                $rel['version'] =
649
                $rel['version'] =
647
                    array(
650
                    array(
648
                        'release' => $release['version'],
651
                        'release' => $release['version'],
649
                        'api' => $release['version'],
652
                        'api' => $release['version'],
650
                    );
653
                    );
651
                if (!isset($release['release_state'])) {
654
                if (!isset($release['release_state'])) {
652
                    $release['release_state'] = 'stable';
655
                    $release['release_state'] = 'stable';
653
                }
656
                }
-
 
657
 
654
                $rel['stability'] =
658
                $rel['stability'] =
655
                    array(
659
                    array(
656
                        'release' => $release['release_state'],
660
                        'release' => $release['release_state'],
657
                        'api' => $release['release_state'],
661
                        'api' => $release['release_state'],
658
                    );
662
                    );
659
                if (isset($release['release_date'])) {
663
                if (isset($release['release_date'])) {
660
                    $rel['date'] = $release['release_date'];
664
                    $rel['date'] = $release['release_date'];
661
                } else {
665
                } else {
662
                    $rel['date'] = date('Y-m-d');
666
                    $rel['date'] = date('Y-m-d');
663
                }
667
                }
-
 
668
 
664
                if (isset($release['release_license'])) {
669
                if (isset($release['release_license'])) {
665
                    if (isset($licensemap[strtolower($release['release_license'])])) {
670
                    if (isset($licensemap[strtolower($release['release_license'])])) {
666
                        $uri = $licensemap[strtolower($release['release_license'])];
671
                        $uri = $licensemap[strtolower($release['release_license'])];
667
                    } else {
672
                    } else {
668
                        $uri = 'http://www.example.com';
673
                        $uri = 'http://www.example.com';
669
                    }
674
                    }
670
                    $rel['license'] = array(
675
                    $rel['license'] = array(
671
                            'attribs' => array('uri' => $uri),
676
                            'attribs' => array('uri' => $uri),
672
                            '_content' => $release['release_license']
677
                            '_content' => $release['release_license']
673
                        );
678
                        );
674
                } else {
679
                } else {
675
                    $rel['license'] = $arr['license'];
680
                    $rel['license'] = $arr['license'];
676
                }
681
                }
-
 
682
 
677
                if (!isset($release['release_notes'])) {
683
                if (!isset($release['release_notes'])) {
678
                    $release['release_notes'] = 'no release notes';
684
                    $release['release_notes'] = 'no release notes';
679
                }
685
                }
-
 
686
 
680
                $rel['notes'] = $release['release_notes'];
687
                $rel['notes'] = $release['release_notes'];
681
                $arr['changelog']['release'][] = $rel;
688
                $arr['changelog']['release'][] = $rel;
682
            }
689
            }
683
        }
690
        }
-
 
691
 
684
        $ret = new $class;
692
        $ret = new $class;
685
        $ret->setConfig($this->_packagefile->_config);
693
        $ret->setConfig($this->_packagefile->_config);
686
        if (isset($this->_packagefile->_logger) && is_object($this->_packagefile->_logger)) {
694
        if (isset($this->_packagefile->_logger) && is_object($this->_packagefile->_logger)) {
687
            $ret->setLogger($this->_packagefile->_logger);
695
            $ret->setLogger($this->_packagefile->_logger);
688
        }
696
        }
-
 
697
 
689
        $ret->fromArray($arr);
698
        $ret->fromArray($arr);
690
        return $ret;
699
        return $ret;
691
    }
700
    }
692
 
701
 
693
    /**
702
    /**
694
     * @param array
703
     * @param array
695
     * @param bool
704
     * @param bool
696
     * @access private
705
     * @access private
697
     */
706
     */
698
    function _convertDependencies2_0(&$release, $internal = false)
707
    function _convertDependencies2_0(&$release, $internal = false)
699
    {
708
    {
700
        $peardep = array('pearinstaller' =>
709
        $peardep = array('pearinstaller' =>
701
            array('min' => '1.4.0b1')); // this is a lot safer
710
            array('min' => '1.4.0b1')); // this is a lot safer
702
        $required = $optional = array();
711
        $required = $optional = array();
703
        $release['dependencies'] = array();
712
        $release['dependencies'] = array('required' => array());
704
        if ($this->_packagefile->hasDeps()) {
713
        if ($this->_packagefile->hasDeps()) {
705
            foreach ($this->_packagefile->getDeps() as $dep) {
714
            foreach ($this->_packagefile->getDeps() as $dep) {
706
                if (!isset($dep['optional']) || $dep['optional'] == 'no') {
715
                if (!isset($dep['optional']) || $dep['optional'] == 'no') {
707
                    $required[] = $dep;
716
                    $required[] = $dep;
708
                } else {
717
                } else {
709
                    $optional[] = $dep;
718
                    $optional[] = $dep;
710
                }
719
                }
711
            }
720
            }
712
            foreach (array('required', 'optional') as $arr) {
721
            foreach (array('required', 'optional') as $arr) {
713
                $deps = array();
722
                $deps = array();
714
                foreach ($$arr as $dep) {
723
                foreach ($$arr as $dep) {
715
                    // organize deps by dependency type and name
724
                    // organize deps by dependency type and name
716
                    if (!isset($deps[$dep['type']])) {
725
                    if (!isset($deps[$dep['type']])) {
717
                        $deps[$dep['type']] = array();
726
                        $deps[$dep['type']] = array();
718
                    }
727
                    }
719
                    if (isset($dep['name'])) {
728
                    if (isset($dep['name'])) {
720
                        $deps[$dep['type']][$dep['name']][] = $dep;
729
                        $deps[$dep['type']][$dep['name']][] = $dep;
721
                    } else {
730
                    } else {
722
                        $deps[$dep['type']][] = $dep;
731
                        $deps[$dep['type']][] = $dep;
723
                    }
732
                    }
724
                }
733
                }
725
                do {
734
                do {
726
                    if (isset($deps['php'])) {
735
                    if (isset($deps['php'])) {
727
                        $php = array();
736
                        $php = array();
728
                        if (count($deps['php']) > 1) {
737
                        if (count($deps['php']) > 1) {
729
                            $php = $this->_processPhpDeps($deps['php']);
738
                            $php = $this->_processPhpDeps($deps['php']);
730
                        } else {
739
                        } else {
731
                            if (!isset($deps['php'][0])) {
740
                            if (!isset($deps['php'][0])) {
732
                                list($key, $blah) = each ($deps['php']); // stupid buggy versions
741
                                list($key, $blah) = each ($deps['php']); // stupid buggy versions
733
                                $deps['php'] = array($blah[0]);
742
                                $deps['php'] = array($blah[0]);
734
                            }
743
                            }
735
                            $php = $this->_processDep($deps['php'][0]);
744
                            $php = $this->_processDep($deps['php'][0]);
736
                            if (!$php) {
745
                            if (!$php) {
737
                                break; // poor mans throw
746
                                break; // poor mans throw
738
                            }
747
                            }
739
                        }
748
                        }
740
                        $release['dependencies'][$arr]['php'] = $php;
749
                        $release['dependencies'][$arr]['php'] = $php;
741
                    }
750
                    }
742
                } while (false);
751
                } while (false);
743
                do {
752
                do {
744
                    if (isset($deps['pkg'])) {
753
                    if (isset($deps['pkg'])) {
745
                        $pkg = array();
754
                        $pkg = array();
746
                        $pkg = $this->_processMultipleDepsName($deps['pkg']);
755
                        $pkg = $this->_processMultipleDepsName($deps['pkg']);
747
                        if (!$pkg) {
756
                        if (!$pkg) {
748
                            break; // poor mans throw
757
                            break; // poor mans throw
749
                        }
758
                        }
750
                        $release['dependencies'][$arr]['package'] = $pkg;
759
                        $release['dependencies'][$arr]['package'] = $pkg;
751
                    }
760
                    }
752
                } while (false);
761
                } while (false);
753
                do {
762
                do {
754
                    if (isset($deps['ext'])) {
763
                    if (isset($deps['ext'])) {
755
                        $pkg = array();
764
                        $pkg = array();
756
                        $pkg = $this->_processMultipleDepsName($deps['ext']);
765
                        $pkg = $this->_processMultipleDepsName($deps['ext']);
757
                        $release['dependencies'][$arr]['extension'] = $pkg;
766
                        $release['dependencies'][$arr]['extension'] = $pkg;
758
                    }
767
                    }
759
                } while (false);
768
                } while (false);
760
                // skip sapi - it's not supported so nobody will have used it
769
                // skip sapi - it's not supported so nobody will have used it
761
                // skip os - it's not supported in 1.0
770
                // skip os - it's not supported in 1.0
762
            }
771
            }
763
        }
772
        }
764
        if (isset($release['dependencies']['required'])) {
773
        if (isset($release['dependencies']['required'])) {
765
            $release['dependencies']['required'] =
774
            $release['dependencies']['required'] =
766
                array_merge($peardep, $release['dependencies']['required']);
775
                array_merge($peardep, $release['dependencies']['required']);
767
        } else {
776
        } else {
768
            $release['dependencies']['required'] = $peardep;
777
            $release['dependencies']['required'] = $peardep;
769
        }
778
        }
770
        if (!isset($release['dependencies']['required']['php'])) {
779
        if (!isset($release['dependencies']['required']['php'])) {
771
            $release['dependencies']['required']['php'] =
780
            $release['dependencies']['required']['php'] =
772
                array('min' => '4.0.0');
781
                array('min' => '4.0.0');
773
        }
782
        }
774
        $order = array();
783
        $order = array();
775
        $bewm = $release['dependencies']['required'];
784
        $bewm = $release['dependencies']['required'];
776
        $order['php'] = $bewm['php'];
785
        $order['php'] = $bewm['php'];
777
        $order['pearinstaller'] = $bewm['pearinstaller'];
786
        $order['pearinstaller'] = $bewm['pearinstaller'];
778
        isset($bewm['package']) ? $order['package'] = $bewm['package'] :0;
787
        isset($bewm['package']) ? $order['package'] = $bewm['package'] :0;
779
        isset($bewm['extension']) ? $order['extension'] = $bewm['extension'] :0;
788
        isset($bewm['extension']) ? $order['extension'] = $bewm['extension'] :0;
780
        $release['dependencies']['required'] = $order;
789
        $release['dependencies']['required'] = $order;
781
    }
790
    }
782
 
791
 
783
    /**
792
    /**
784
     * @param array
793
     * @param array
785
     * @access private
794
     * @access private
786
     */
795
     */
787
    function _convertFilelist2_0(&$package)
796
    function _convertFilelist2_0(&$package)
788
    {
797
    {
789
        $ret = array('dir' =>
798
        $ret = array('dir' =>
790
                    array(
799
                    array(
791
                        'attribs' => array('name' => '/'),
800
                        'attribs' => array('name' => '/'),
792
                        'file' => array()
801
                        'file' => array()
793
                        )
802
                        )
794
                    );
803
                    );
795
        $package['platform'] =
804
        $package['platform'] =
796
        $package['install-as'] = array();
805
        $package['install-as'] = array();
797
        $this->_isExtension = false;
806
        $this->_isExtension = false;
798
        foreach ($this->_packagefile->getFilelist() as $name => $file) {
807
        foreach ($this->_packagefile->getFilelist() as $name => $file) {
799
            $file['name'] = $name;
808
            $file['name'] = $name;
800
            if (isset($file['role']) && $file['role'] == 'src') {
809
            if (isset($file['role']) && $file['role'] == 'src') {
801
                $this->_isExtension = true;
810
                $this->_isExtension = true;
802
            }
811
            }
803
            if (isset($file['replacements'])) {
812
            if (isset($file['replacements'])) {
804
                $repl = $file['replacements'];
813
                $repl = $file['replacements'];
805
                unset($file['replacements']);
814
                unset($file['replacements']);
806
            } else {
815
            } else {
807
                unset($repl);
816
                unset($repl);
808
            }
817
            }
809
            if (isset($file['install-as'])) {
818
            if (isset($file['install-as'])) {
810
                $package['install-as'][$name] = $file['install-as'];
819
                $package['install-as'][$name] = $file['install-as'];
811
                unset($file['install-as']);
820
                unset($file['install-as']);
812
            }
821
            }
813
            if (isset($file['platform'])) {
822
            if (isset($file['platform'])) {
814
                $package['platform'][$name] = $file['platform'];
823
                $package['platform'][$name] = $file['platform'];
815
                unset($file['platform']);
824
                unset($file['platform']);
816
            }
825
            }
817
            $file = array('attribs' => $file);
826
            $file = array('attribs' => $file);
818
            if (isset($repl)) {
827
            if (isset($repl)) {
819
                foreach ($repl as $replace ) {
828
                foreach ($repl as $replace ) {
820
                    $file['tasks:replace'][] = array('attribs' => $replace);
829
                    $file['tasks:replace'][] = array('attribs' => $replace);
821
                }
830
                }
822
                if (count($repl) == 1) {
831
                if (count($repl) == 1) {
823
                    $file['tasks:replace'] = $file['tasks:replace'][0];
832
                    $file['tasks:replace'] = $file['tasks:replace'][0];
824
                }
833
                }
825
            }
834
            }
826
            $ret['dir']['file'][] = $file;
835
            $ret['dir']['file'][] = $file;
827
        }
836
        }
828
        return $ret;
837
        return $ret;
829
    }
838
    }
830
 
839
 
831
    /**
840
    /**
832
     * Post-process special files with install-as/platform attributes and
841
     * Post-process special files with install-as/platform attributes and
833
     * make the release tag.
842
     * make the release tag.
834
     * 
843
     *
835
     * This complex method follows this work-flow to create the release tags:
844
     * This complex method follows this work-flow to create the release tags:
836
     * 
845
     *
837
     * <pre>
846
     * <pre>
838
     * - if any install-as/platform exist, create a generic release and fill it with
847
     * - if any install-as/platform exist, create a generic release and fill it with
839
     *   o <install as=..> tags for <file name=... install-as=...>
848
     *   o <install as=..> tags for <file name=... install-as=...>
840
     *   o <install as=..> tags for <file name=... platform=!... install-as=..>
849
     *   o <install as=..> tags for <file name=... platform=!... install-as=..>
841
     *   o <ignore> tags for <file name=... platform=...>
850
     *   o <ignore> tags for <file name=... platform=...>
842
     *   o <ignore> tags for <file name=... platform=... install-as=..>
851
     *   o <ignore> tags for <file name=... platform=... install-as=..>
843
     * - create a release for each platform encountered and fill with
852
     * - create a release for each platform encountered and fill with
844
     *   o <install as..> tags for <file name=... install-as=...>
853
     *   o <install as..> tags for <file name=... install-as=...>
845
     *   o <install as..> tags for <file name=... platform=this platform install-as=..>
854
     *   o <install as..> tags for <file name=... platform=this platform install-as=..>
846
     *   o <install as..> tags for <file name=... platform=!other platform install-as=..>
855
     *   o <install as..> tags for <file name=... platform=!other platform install-as=..>
847
     *   o <ignore> tags for <file name=... platform=!this platform>
856
     *   o <ignore> tags for <file name=... platform=!this platform>
848
     *   o <ignore> tags for <file name=... platform=other platform>
857
     *   o <ignore> tags for <file name=... platform=other platform>
849
     *   o <ignore> tags for <file name=... platform=other platform install-as=..>
858
     *   o <ignore> tags for <file name=... platform=other platform install-as=..>
850
     *   o <ignore> tags for <file name=... platform=!this platform install-as=..>
859
     *   o <ignore> tags for <file name=... platform=!this platform install-as=..>
851
     * </pre>
860
     * </pre>
852
     * 
861
     *
853
     * It does this by accessing the $package parameter, which contains an array with
862
     * It does this by accessing the $package parameter, which contains an array with
854
     * indices:
863
     * indices:
855
     * 
864
     *
856
     *  - platform: mapping of file => OS the file should be installed on
865
     *  - platform: mapping of file => OS the file should be installed on
857
     *  - install-as: mapping of file => installed name
866
     *  - install-as: mapping of file => installed name
858
     *  - osmap: mapping of OS => list of files that should be installed
867
     *  - osmap: mapping of OS => list of files that should be installed
859
     *    on that OS
868
     *    on that OS
860
     *  - notosmap: mapping of OS => list of files that should not be
869
     *  - notosmap: mapping of OS => list of files that should not be
861
     *    installed on that OS
870
     *    installed on that OS
862
     *
871
     *
863
     * @param array
872
     * @param array
864
     * @param array
873
     * @param array
865
     * @access private
874
     * @access private
866
     */
875
     */
867
    function _convertRelease2_0(&$release, $package)
876
    function _convertRelease2_0(&$release, $package)
868
    {
877
    {
869
        //- if any install-as/platform exist, create a generic release and fill it with 
878
        //- if any install-as/platform exist, create a generic release and fill it with
870
        if (count($package['platform']) || count($package['install-as'])) {
879
        if (count($package['platform']) || count($package['install-as'])) {
871
            $generic = array();
880
            $generic = array();
872
            $genericIgnore = array();
881
            $genericIgnore = array();
873
            foreach ($package['install-as'] as $file => $as) {
882
            foreach ($package['install-as'] as $file => $as) {
874
                //o <install as=..> tags for <file name=... install-as=...>
883
                //o <install as=..> tags for <file name=... install-as=...>
875
                if (!isset($package['platform'][$file])) {
884
                if (!isset($package['platform'][$file])) {
876
                    $generic[] = $file;
885
                    $generic[] = $file;
877
                    continue;
886
                    continue;
878
                }
887
                }
879
                //o <install as=..> tags for <file name=... platform=!... install-as=..>
888
                //o <install as=..> tags for <file name=... platform=!... install-as=..>
880
                if (isset($package['platform'][$file]) &&
889
                if (isset($package['platform'][$file]) &&
881
                      $package['platform'][$file]{0} == '!') {
890
                      $package['platform'][$file]{0} == '!') {
882
                    $generic[] = $file;
891
                    $generic[] = $file;
883
                    continue;
892
                    continue;
884
                }
893
                }
885
                //o <ignore> tags for <file name=... platform=... install-as=..>
894
                //o <ignore> tags for <file name=... platform=... install-as=..>
886
                if (isset($package['platform'][$file]) &&
895
                if (isset($package['platform'][$file]) &&
887
                      $package['platform'][$file]{0} != '!') {
896
                      $package['platform'][$file]{0} != '!') {
888
                    $genericIgnore[] = $file;
897
                    $genericIgnore[] = $file;
889
                    continue;
898
                    continue;
890
                }
899
                }
891
            }
900
            }
892
            foreach ($package['platform'] as $file => $platform) {
901
            foreach ($package['platform'] as $file => $platform) {
893
                if (isset($package['install-as'][$file])) {
902
                if (isset($package['install-as'][$file])) {
894
                    continue;
903
                    continue;
895
                }
904
                }
896
                if ($platform{0} != '!') {
905
                if ($platform{0} != '!') {
897
                    //o <ignore> tags for <file name=... platform=...>
906
                    //o <ignore> tags for <file name=... platform=...>
898
                    $genericIgnore[] = $file;
907
                    $genericIgnore[] = $file;
899
                }
908
                }
900
            }
909
            }
901
            if (count($package['platform'])) {
910
            if (count($package['platform'])) {
902
                $oses = $notplatform = $platform = array();
911
                $oses = $notplatform = $platform = array();
903
                foreach ($package['platform'] as $file => $os) {
912
                foreach ($package['platform'] as $file => $os) {
904
                    // get a list of oses
913
                    // get a list of oses
905
                    if ($os{0} == '!') {
914
                    if ($os{0} == '!') {
906
                        if (isset($oses[substr($os, 1)])) {
915
                        if (isset($oses[substr($os, 1)])) {
907
                            continue;
916
                            continue;
908
                        }
917
                        }
909
                        $oses[substr($os, 1)] = count($oses);
918
                        $oses[substr($os, 1)] = count($oses);
910
                    } else {
919
                    } else {
911
                        if (isset($oses[$os])) {
920
                        if (isset($oses[$os])) {
912
                            continue;
921
                            continue;
913
                        }
922
                        }
914
                        $oses[$os] = count($oses);
923
                        $oses[$os] = count($oses);
915
                    }
924
                    }
916
                }
925
                }
917
                //- create a release for each platform encountered and fill with
926
                //- create a release for each platform encountered and fill with
918
                foreach ($oses as $os => $releaseNum) {
927
                foreach ($oses as $os => $releaseNum) {
919
                    $release[$releaseNum]['installconditions']['os']['name'] = $os;
928
                    $release[$releaseNum]['installconditions']['os']['name'] = $os;
920
                    $release[$releaseNum]['filelist'] = array('install' => array(),
929
                    $release[$releaseNum]['filelist'] = array('install' => array(),
921
                        'ignore' => array());
930
                        'ignore' => array());
922
                    foreach ($package['install-as'] as $file => $as) {
931
                    foreach ($package['install-as'] as $file => $as) {
923
                        //o <install as=..> tags for <file name=... install-as=...>
932
                        //o <install as=..> tags for <file name=... install-as=...>
924
                        if (!isset($package['platform'][$file])) {
933
                        if (!isset($package['platform'][$file])) {
925
                            $release[$releaseNum]['filelist']['install'][] =
934
                            $release[$releaseNum]['filelist']['install'][] =
926
                                array(
935
                                array(
927
                                    'attribs' => array(
936
                                    'attribs' => array(
928
                                        'name' => $file,
937
                                        'name' => $file,
929
                                        'as' => $as,
938
                                        'as' => $as,
930
                                    ),
939
                                    ),
931
                                );
940
                                );
932
                            continue;
941
                            continue;
933
                        }
942
                        }
934
                        //o <install as..> tags for
943
                        //o <install as..> tags for
935
                        //  <file name=... platform=this platform install-as=..>
944
                        //  <file name=... platform=this platform install-as=..>
936
                        if (isset($package['platform'][$file]) &&
945
                        if (isset($package['platform'][$file]) &&
937
                              $package['platform'][$file] == $os) {
946
                              $package['platform'][$file] == $os) {
938
                            $release[$releaseNum]['filelist']['install'][] =
947
                            $release[$releaseNum]['filelist']['install'][] =
939
                                array(
948
                                array(
940
                                    'attribs' => array(
949
                                    'attribs' => array(
941
                                        'name' => $file,
950
                                        'name' => $file,
942
                                        'as' => $as,
951
                                        'as' => $as,
943
                                    ),
952
                                    ),
944
                                );
953
                                );
945
                            continue;
954
                            continue;
946
                        }
955
                        }
947
                        //o <install as..> tags for
956
                        //o <install as..> tags for
948
                        //  <file name=... platform=!other platform install-as=..>
957
                        //  <file name=... platform=!other platform install-as=..>
949
                        if (isset($package['platform'][$file]) &&
958
                        if (isset($package['platform'][$file]) &&
950
                              $package['platform'][$file] != "!$os" &&
959
                              $package['platform'][$file] != "!$os" &&
951
                              $package['platform'][$file]{0} == '!') {
960
                              $package['platform'][$file]{0} == '!') {
952
                            $release[$releaseNum]['filelist']['install'][] =
961
                            $release[$releaseNum]['filelist']['install'][] =
953
                                array(
962
                                array(
954
                                    'attribs' => array(
963
                                    'attribs' => array(
955
                                        'name' => $file,
964
                                        'name' => $file,
956
                                        'as' => $as,
965
                                        'as' => $as,
957
                                    ),
966
                                    ),
958
                                );
967
                                );
959
                            continue;
968
                            continue;
960
                        }
969
                        }
961
                        //o <ignore> tags for
970
                        //o <ignore> tags for
962
                        //  <file name=... platform=!this platform install-as=..>
971
                        //  <file name=... platform=!this platform install-as=..>
963
                        if (isset($package['platform'][$file]) &&
972
                        if (isset($package['platform'][$file]) &&
964
                              $package['platform'][$file] == "!$os") {
973
                              $package['platform'][$file] == "!$os") {
965
                            $release[$releaseNum]['filelist']['ignore'][] =
974
                            $release[$releaseNum]['filelist']['ignore'][] =
966
                                array(
975
                                array(
967
                                    'attribs' => array(
976
                                    'attribs' => array(
968
                                        'name' => $file,
977
                                        'name' => $file,
969
                                    ),
978
                                    ),
970
                                );
979
                                );
971
                            continue;
980
                            continue;
972
                        }
981
                        }
973
                        //o <ignore> tags for
982
                        //o <ignore> tags for
974
                        //  <file name=... platform=other platform install-as=..>
983
                        //  <file name=... platform=other platform install-as=..>
975
                        if (isset($package['platform'][$file]) &&
984
                        if (isset($package['platform'][$file]) &&
976
                              $package['platform'][$file]{0} != '!' &&
985
                              $package['platform'][$file]{0} != '!' &&
977
                              $package['platform'][$file] != $os) {
986
                              $package['platform'][$file] != $os) {
978
                            $release[$releaseNum]['filelist']['ignore'][] =
987
                            $release[$releaseNum]['filelist']['ignore'][] =
979
                                array(
988
                                array(
980
                                    'attribs' => array(
989
                                    'attribs' => array(
981
                                        'name' => $file,
990
                                        'name' => $file,
982
                                    ),
991
                                    ),
983
                                );
992
                                );
984
                            continue;
993
                            continue;
985
                        }
994
                        }
986
                    }
995
                    }
987
                    foreach ($package['platform'] as $file => $platform) {
996
                    foreach ($package['platform'] as $file => $platform) {
988
                        if (isset($package['install-as'][$file])) {
997
                        if (isset($package['install-as'][$file])) {
989
                            continue;
998
                            continue;
990
                        }
999
                        }
991
                        //o <ignore> tags for <file name=... platform=!this platform>
1000
                        //o <ignore> tags for <file name=... platform=!this platform>
992
                        if ($platform == "!$os") {
1001
                        if ($platform == "!$os") {
993
                            $release[$releaseNum]['filelist']['ignore'][] =
1002
                            $release[$releaseNum]['filelist']['ignore'][] =
994
                                array(
1003
                                array(
995
                                    'attribs' => array(
1004
                                    'attribs' => array(
996
                                        'name' => $file,
1005
                                        'name' => $file,
997
                                    ),
1006
                                    ),
998
                                );
1007
                                );
999
                            continue;
1008
                            continue;
1000
                        }
1009
                        }
1001
                        //o <ignore> tags for <file name=... platform=other platform>
1010
                        //o <ignore> tags for <file name=... platform=other platform>
1002
                        if ($platform{0} != '!' && $platform != $os) {
1011
                        if ($platform{0} != '!' && $platform != $os) {
1003
                            $release[$releaseNum]['filelist']['ignore'][] =
1012
                            $release[$releaseNum]['filelist']['ignore'][] =
1004
                                array(
1013
                                array(
1005
                                    'attribs' => array(
1014
                                    'attribs' => array(
1006
                                        'name' => $file,
1015
                                        'name' => $file,
1007
                                    ),
1016
                                    ),
1008
                                );
1017
                                );
1009
                        }
1018
                        }
1010
                    }
1019
                    }
1011
                    if (!count($release[$releaseNum]['filelist']['install'])) {
1020
                    if (!count($release[$releaseNum]['filelist']['install'])) {
1012
                        unset($release[$releaseNum]['filelist']['install']);
1021
                        unset($release[$releaseNum]['filelist']['install']);
1013
                    }
1022
                    }
1014
                    if (!count($release[$releaseNum]['filelist']['ignore'])) {
1023
                    if (!count($release[$releaseNum]['filelist']['ignore'])) {
1015
                        unset($release[$releaseNum]['filelist']['ignore']);
1024
                        unset($release[$releaseNum]['filelist']['ignore']);
1016
                    }
1025
                    }
1017
                }
1026
                }
1018
                if (count($generic) || count($genericIgnore)) {
1027
                if (count($generic) || count($genericIgnore)) {
1019
                    $release[count($oses)] = array();
1028
                    $release[count($oses)] = array();
1020
                    if (count($generic)) {
1029
                    if (count($generic)) {
1021
                        foreach ($generic as $file) {
1030
                        foreach ($generic as $file) {
1022
                            if (isset($package['install-as'][$file])) {
1031
                            if (isset($package['install-as'][$file])) {
1023
                                $installas = $package['install-as'][$file];
1032
                                $installas = $package['install-as'][$file];
1024
                            } else {
1033
                            } else {
1025
                                $installas = $file;
1034
                                $installas = $file;
1026
                            }
1035
                            }
1027
                            $release[count($oses)]['filelist']['install'][] =
1036
                            $release[count($oses)]['filelist']['install'][] =
1028
                                array(
1037
                                array(
1029
                                    'attribs' => array(
1038
                                    'attribs' => array(
1030
                                        'name' => $file,
1039
                                        'name' => $file,
1031
                                        'as' => $installas,
1040
                                        'as' => $installas,
1032
                                    )
1041
                                    )
1033
                                );
1042
                                );
1034
                        }
1043
                        }
1035
                    }
1044
                    }
1036
                    if (count($genericIgnore)) {
1045
                    if (count($genericIgnore)) {
1037
                        foreach ($genericIgnore as $file) {
1046
                        foreach ($genericIgnore as $file) {
1038
                            $release[count($oses)]['filelist']['ignore'][] =
1047
                            $release[count($oses)]['filelist']['ignore'][] =
1039
                                array(
1048
                                array(
1040
                                    'attribs' => array(
1049
                                    'attribs' => array(
1041
                                        'name' => $file,
1050
                                        'name' => $file,
1042
                                    )
1051
                                    )
1043
                                );
1052
                                );
1044
                        }
1053
                        }
1045
                    }
1054
                    }
1046
                }
1055
                }
1047
                // cleanup
1056
                // cleanup
1048
                foreach ($release as $i => $rel) {
1057
                foreach ($release as $i => $rel) {
1049
                    if (isset($rel['filelist']['install']) &&
1058
                    if (isset($rel['filelist']['install']) &&
1050
                          count($rel['filelist']['install']) == 1) {
1059
                          count($rel['filelist']['install']) == 1) {
1051
                        $release[$i]['filelist']['install'] =
1060
                        $release[$i]['filelist']['install'] =
1052
                            $release[$i]['filelist']['install'][0];
1061
                            $release[$i]['filelist']['install'][0];
1053
                    }
1062
                    }
1054
                    if (isset($rel['filelist']['ignore']) &&
1063
                    if (isset($rel['filelist']['ignore']) &&
1055
                          count($rel['filelist']['ignore']) == 1) {
1064
                          count($rel['filelist']['ignore']) == 1) {
1056
                        $release[$i]['filelist']['ignore'] =
1065
                        $release[$i]['filelist']['ignore'] =
1057
                            $release[$i]['filelist']['ignore'][0];
1066
                            $release[$i]['filelist']['ignore'][0];
1058
                    }
1067
                    }
1059
                }
1068
                }
1060
                if (count($release) == 1) {
1069
                if (count($release) == 1) {
1061
                    $release = $release[0];
1070
                    $release = $release[0];
1062
                }
1071
                }
1063
            } else {
1072
            } else {
1064
                // no platform atts, but some install-as atts
1073
                // no platform atts, but some install-as atts
1065
                foreach ($package['install-as'] as $file => $value) {
1074
                foreach ($package['install-as'] as $file => $value) {
1066
                    $release['filelist']['install'][] =
1075
                    $release['filelist']['install'][] =
1067
                        array(
1076
                        array(
1068
                            'attribs' => array(
1077
                            'attribs' => array(
1069
                                'name' => $file,
1078
                                'name' => $file,
1070
                                'as' => $value
1079
                                'as' => $value
1071
                            )
1080
                            )
1072
                        );
1081
                        );
1073
                }
1082
                }
1074
                if (count($release['filelist']['install']) == 1) {
1083
                if (count($release['filelist']['install']) == 1) {
1075
                    $release['filelist']['install'] = $release['filelist']['install'][0];
1084
                    $release['filelist']['install'] = $release['filelist']['install'][0];
1076
                }
1085
                }
1077
            }
1086
            }
1078
        }
1087
        }
1079
    }
1088
    }
1080
 
1089
 
1081
    /**
1090
    /**
1082
     * @param array
1091
     * @param array
1083
     * @return array
1092
     * @return array
1084
     * @access private
1093
     * @access private
1085
     */
1094
     */
1086
    function _processDep($dep)
1095
    function _processDep($dep)
1087
    {
1096
    {
1088
        if ($dep['type'] == 'php') {
1097
        if ($dep['type'] == 'php') {
1089
            if ($dep['rel'] == 'has') {
1098
            if ($dep['rel'] == 'has') {
1090
                // come on - everyone has php!
1099
                // come on - everyone has php!
1091
                return false;
1100
                return false;
1092
            }
1101
            }
1093
        }
1102
        }
1094
        $php = array();
1103
        $php = array();
1095
        if ($dep['type'] != 'php') {
1104
        if ($dep['type'] != 'php') {
1096
            $php['name'] = $dep['name'];
1105
            $php['name'] = $dep['name'];
1097
            if ($dep['type'] == 'pkg') {
1106
            if ($dep['type'] == 'pkg') {
1098
                $php['channel'] = 'pear.php.net';
1107
                $php['channel'] = 'pear.php.net';
1099
            }
1108
            }
1100
        }
1109
        }
1101
        switch ($dep['rel']) {
1110
        switch ($dep['rel']) {
1102
            case 'gt' :
1111
            case 'gt' :
1103
                $php['min'] = $dep['version'];
1112
                $php['min'] = $dep['version'];
1104
                $php['exclude'] = $dep['version'];
1113
                $php['exclude'] = $dep['version'];
1105
            break;
1114
            break;
1106
            case 'ge' :
1115
            case 'ge' :
1107
                if (!isset($dep['version'])) {
1116
                if (!isset($dep['version'])) {
1108
                    if ($dep['type'] == 'php') {
1117
                    if ($dep['type'] == 'php') {
1109
                        if (isset($dep['name'])) {
1118
                        if (isset($dep['name'])) {
1110
                            $dep['version'] = $dep['name'];
1119
                            $dep['version'] = $dep['name'];
1111
                        }
1120
                        }
1112
                    }
1121
                    }
1113
                }
1122
                }
1114
                $php['min'] = $dep['version'];
1123
                $php['min'] = $dep['version'];
1115
            break;
1124
            break;
1116
            case 'lt' :
1125
            case 'lt' :
1117
                $php['max'] = $dep['version'];
1126
                $php['max'] = $dep['version'];
1118
                $php['exclude'] = $dep['version'];
1127
                $php['exclude'] = $dep['version'];
1119
            break;
1128
            break;
1120
            case 'le' :
1129
            case 'le' :
1121
                $php['max'] = $dep['version'];
1130
                $php['max'] = $dep['version'];
1122
            break;
1131
            break;
1123
            case 'eq' :
1132
            case 'eq' :
1124
                $php['min'] = $dep['version'];
1133
                $php['min'] = $dep['version'];
1125
                $php['max'] = $dep['version'];
1134
                $php['max'] = $dep['version'];
1126
            break;
1135
            break;
1127
            case 'ne' :
1136
            case 'ne' :
1128
                $php['exclude'] = $dep['version'];
1137
                $php['exclude'] = $dep['version'];
1129
            break;
1138
            break;
1130
            case 'not' :
1139
            case 'not' :
1131
                $php['conflicts'] = 'yes';
1140
                $php['conflicts'] = 'yes';
1132
            break;
1141
            break;
1133
        }
1142
        }
1134
        return $php;
1143
        return $php;
1135
    }
1144
    }
1136
 
1145
 
1137
    /**
1146
    /**
1138
     * @param array
1147
     * @param array
1139
     * @return array
1148
     * @return array
1140
     */
1149
     */
1141
    function _processPhpDeps($deps)
1150
    function _processPhpDeps($deps)
1142
    {
1151
    {
1143
        $test = array();
1152
        $test = array();
1144
        foreach ($deps as $dep) {
1153
        foreach ($deps as $dep) {
1145
            $test[] = $this->_processDep($dep);
1154
            $test[] = $this->_processDep($dep);
1146
        }
1155
        }
1147
        $min = array();
1156
        $min = array();
1148
        $max = array();
1157
        $max = array();
1149
        foreach ($test as $dep) {
1158
        foreach ($test as $dep) {
1150
            if (!$dep) {
1159
            if (!$dep) {
1151
                continue;
1160
                continue;
1152
            }
1161
            }
1153
            if (isset($dep['min'])) {
1162
            if (isset($dep['min'])) {
1154
                $min[$dep['min']] = count($min);
1163
                $min[$dep['min']] = count($min);
1155
            }
1164
            }
1156
            if (isset($dep['max'])) {
1165
            if (isset($dep['max'])) {
1157
                $max[$dep['max']] = count($max);
1166
                $max[$dep['max']] = count($max);
1158
            }
1167
            }
1159
        }
1168
        }
1160
        if (count($min) > 0) {
1169
        if (count($min) > 0) {
1161
            uksort($min, 'version_compare');
1170
            uksort($min, 'version_compare');
1162
        }
1171
        }
1163
        if (count($max) > 0) {
1172
        if (count($max) > 0) {
1164
            uksort($max, 'version_compare');
1173
            uksort($max, 'version_compare');
1165
        }
1174
        }
1166
        if (count($min)) {
1175
        if (count($min)) {
1167
            // get the highest minimum
1176
            // get the highest minimum
1168
            $min = array_pop($a = array_flip($min));
1177
            $a = array_flip($min);
-
 
1178
            $min = array_pop($a);
1169
        } else {
1179
        } else {
1170
            $min = false;
1180
            $min = false;
1171
        }
1181
        }
1172
        if (count($max)) {
1182
        if (count($max)) {
1173
            // get the lowest maximum
1183
            // get the lowest maximum
-
 
1184
            $a = array_flip($max);
1174
            $max = array_shift($a = array_flip($max));
1185
            $max = array_shift($a);
1175
        } else {
1186
        } else {
1176
            $max = false;
1187
            $max = false;
1177
        }
1188
        }
1178
        if ($min) {
1189
        if ($min) {
1179
            $php['min'] = $min;
1190
            $php['min'] = $min;
1180
        }
1191
        }
1181
        if ($max) {
1192
        if ($max) {
1182
            $php['max'] = $max;
1193
            $php['max'] = $max;
1183
        }
1194
        }
1184
        $exclude = array();
1195
        $exclude = array();
1185
        foreach ($test as $dep) {
1196
        foreach ($test as $dep) {
1186
            if (!isset($dep['exclude'])) {
1197
            if (!isset($dep['exclude'])) {
1187
                continue;
1198
                continue;
1188
            }
1199
            }
1189
            $exclude[] = $dep['exclude'];
1200
            $exclude[] = $dep['exclude'];
1190
        }
1201
        }
1191
        if (count($exclude)) {
1202
        if (count($exclude)) {
1192
            $php['exclude'] = $exclude;
1203
            $php['exclude'] = $exclude;
1193
        }
1204
        }
1194
        return $php;
1205
        return $php;
1195
    }
1206
    }
1196
 
1207
 
1197
    /**
1208
    /**
1198
     * process multiple dependencies that have a name, like package deps
1209
     * process multiple dependencies that have a name, like package deps
1199
     * @param array
1210
     * @param array
1200
     * @return array
1211
     * @return array
1201
     * @access private
1212
     * @access private
1202
     */
1213
     */
1203
    function _processMultipleDepsName($deps)
1214
    function _processMultipleDepsName($deps)
1204
    {
1215
    {
1205
        $tests = array();
1216
        $ret = $tests = array();
1206
        foreach ($deps as $name => $dep) {
1217
        foreach ($deps as $name => $dep) {
1207
            foreach ($dep as $d) {
1218
            foreach ($dep as $d) {
1208
                $tests[$name][] = $this->_processDep($d);
1219
                $tests[$name][] = $this->_processDep($d);
1209
            }
1220
            }
1210
        }
1221
        }
-
 
1222
 
1211
        foreach ($tests as $name => $test) {
1223
        foreach ($tests as $name => $test) {
1212
            $php = array();
-
 
1213
            $min = array();
-
 
1214
            $max = array();
1224
            $max = $min = $php = array();
1215
            $php['name'] = $name;
1225
            $php['name'] = $name;
1216
            foreach ($test as $dep) {
1226
            foreach ($test as $dep) {
1217
                if (!$dep) {
1227
                if (!$dep) {
1218
                    continue;
1228
                    continue;
1219
                }
1229
                }
1220
                if (isset($dep['channel'])) {
1230
                if (isset($dep['channel'])) {
1221
                    $php['channel'] = 'pear.php.net';
1231
                    $php['channel'] = 'pear.php.net';
1222
                }
1232
                }
1223
                if (isset($dep['conflicts']) && $dep['conflicts'] == 'yes') {
1233
                if (isset($dep['conflicts']) && $dep['conflicts'] == 'yes') {
1224
                    $php['conflicts'] = 'yes';
1234
                    $php['conflicts'] = 'yes';
1225
                }
1235
                }
1226
                if (isset($dep['min'])) {
1236
                if (isset($dep['min'])) {
1227
                    $min[$dep['min']] = count($min);
1237
                    $min[$dep['min']] = count($min);
1228
                }
1238
                }
1229
                if (isset($dep['max'])) {
1239
                if (isset($dep['max'])) {
1230
                    $max[$dep['max']] = count($max);
1240
                    $max[$dep['max']] = count($max);
1231
                }
1241
                }
1232
            }
1242
            }
1233
            if (count($min) > 0) {
1243
            if (count($min) > 0) {
1234
                uksort($min, 'version_compare');
1244
                uksort($min, 'version_compare');
1235
            }
1245
            }
1236
            if (count($max) > 0) {
1246
            if (count($max) > 0) {
1237
                uksort($max, 'version_compare');
1247
                uksort($max, 'version_compare');
1238
            }
1248
            }
1239
            if (count($min)) {
1249
            if (count($min)) {
1240
                // get the highest minimum
1250
                // get the highest minimum
1241
                $min = array_pop($a = array_flip($min));
1251
                $a = array_flip($min);
-
 
1252
                $min = array_pop($a);
1242
            } else {
1253
            } else {
1243
                $min = false;
1254
                $min = false;
1244
            }
1255
            }
1245
            if (count($max)) {
1256
            if (count($max)) {
1246
                // get the lowest maximum
1257
                // get the lowest maximum
-
 
1258
                $a = array_flip($max);
1247
                $max = array_shift($a = array_flip($max));
1259
                $max = array_shift($a);
1248
            } else {
1260
            } else {
1249
                $max = false;
1261
                $max = false;
1250
            }
1262
            }
1251
            if ($min) {
1263
            if ($min) {
1252
                $php['min'] = $min;
1264
                $php['min'] = $min;
1253
            }
1265
            }
1254
            if ($max) {
1266
            if ($max) {
1255
                $php['max'] = $max;
1267
                $php['max'] = $max;
1256
            }
1268
            }
1257
            $exclude = array();
1269
            $exclude = array();
1258
            foreach ($test as $dep) {
1270
            foreach ($test as $dep) {
1259
                if (!isset($dep['exclude'])) {
1271
                if (!isset($dep['exclude'])) {
1260
                    continue;
1272
                    continue;
1261
                }
1273
                }
1262
                $exclude[] = $dep['exclude'];
1274
                $exclude[] = $dep['exclude'];
1263
            }
1275
            }
1264
            if (count($exclude)) {
1276
            if (count($exclude)) {
1265
                $php['exclude'] = $exclude;
1277
                $php['exclude'] = $exclude;
1266
            }
1278
            }
1267
            $ret[] = $php;
1279
            $ret[] = $php;
1268
        }
1280
        }
1269
        return $ret;
1281
        return $ret;
1270
    }
1282
    }
1271
}
1283
}
1272
?>
-
 
1273
1284
?>
-
 
1285