2001-04-22 09:09:14 +08:00
|
|
|
<?php
|
|
|
|
//
|
|
|
|
// +----------------------------------------------------------------------+
|
|
|
|
// | PHP version 4.0 |
|
|
|
|
// +----------------------------------------------------------------------+
|
|
|
|
// | Copyright (c) 1997-2001 The PHP Group |
|
|
|
|
// +----------------------------------------------------------------------+
|
|
|
|
// | This source file is subject to version 2.02 of the PHP license, |
|
|
|
|
// | that is bundled with this package in the file LICENSE, and is |
|
|
|
|
// | available at through the world-wide-web at |
|
|
|
|
// | http://www.php.net/license/2_02.txt. |
|
|
|
|
// | If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
// | obtain it through the world-wide-web, please send a note to |
|
|
|
|
// | license@php.net so we can mail you a copy immediately. |
|
|
|
|
// +----------------------------------------------------------------------+
|
|
|
|
// | Authors: Stig Bakken <ssb@fast.no> |
|
|
|
|
// | |
|
|
|
|
// +----------------------------------------------------------------------+
|
|
|
|
//
|
|
|
|
|
|
|
|
require_once "PEAR.php";
|
|
|
|
|
2001-04-22 15:43:34 +08:00
|
|
|
class PEAR_Common extends PEAR
|
2001-04-22 09:09:14 +08:00
|
|
|
{
|
|
|
|
// {{{ properties
|
|
|
|
|
|
|
|
/** stack of elements, gives some sort of XML context */
|
2001-07-17 02:01:09 +08:00
|
|
|
var $element_stack = array();
|
2001-04-22 09:09:14 +08:00
|
|
|
|
|
|
|
/** name of currently parsed XML element */
|
|
|
|
var $current_element;
|
|
|
|
|
|
|
|
/** array of attributes of the currently parsed XML element */
|
|
|
|
var $current_attributes = array();
|
|
|
|
|
|
|
|
/** list of temporary files created by this object */
|
|
|
|
var $_tempfiles = array();
|
|
|
|
|
|
|
|
/** assoc with information about a package */
|
|
|
|
var $pkginfo = array();
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
|
|
|
|
// {{{ constructor
|
|
|
|
|
|
|
|
function PEAR_Common()
|
|
|
|
{
|
|
|
|
$this->PEAR();
|
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
// {{{ destructor
|
|
|
|
|
2001-07-17 02:01:09 +08:00
|
|
|
function _PEAR_Common()
|
|
|
|
{
|
|
|
|
$this->_PEAR();
|
2001-04-22 09:09:14 +08:00
|
|
|
while (is_array($this->_tempfiles) &&
|
|
|
|
$file = array_shift($this->_tempfiles))
|
|
|
|
{
|
|
|
|
if (is_dir($file)) {
|
|
|
|
system("rm -rf $file"); // XXX FIXME Windows
|
|
|
|
} else {
|
|
|
|
unlink($file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
// {{{ addTempFile()
|
|
|
|
|
|
|
|
function addTempFile($file)
|
|
|
|
{
|
|
|
|
$this->_tempfiles[] = $file;
|
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
2001-04-22 15:43:34 +08:00
|
|
|
// {{{ _element_start()
|
2001-04-22 09:09:14 +08:00
|
|
|
|
|
|
|
function _element_start($xp, $name, $attribs)
|
|
|
|
{
|
2001-07-17 02:01:09 +08:00
|
|
|
array_push($this->element_stack, $name);
|
|
|
|
$this->current_element = $name;
|
|
|
|
$this->current_attributes = $attribs;
|
|
|
|
switch ($name) {
|
|
|
|
case 'Dir':
|
|
|
|
if (isset($this->dir_names)) {
|
|
|
|
$this->dir_names[] = $attribs['Name'];
|
|
|
|
} else {
|
|
|
|
// Don't add the root dir
|
|
|
|
$this->dir_names = array();
|
|
|
|
}
|
|
|
|
if (isset($attribs['BaseInstallDir'])) {
|
|
|
|
$this->dir_install = $attribs['BaseInstallDir'];
|
|
|
|
}
|
|
|
|
if (isset($attribs['Role'])) {
|
|
|
|
$this->dir_role = $attribs['Role'];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'LibFile':
|
|
|
|
$this->lib_atts = $attribs;
|
|
|
|
$this->lib_atts['Role'] = 'extension';
|
|
|
|
break;
|
|
|
|
}
|
2001-04-22 09:09:14 +08:00
|
|
|
}
|
|
|
|
|
2001-04-22 15:43:34 +08:00
|
|
|
// }}}
|
|
|
|
// {{{ _element_end()
|
2001-04-22 09:09:14 +08:00
|
|
|
|
|
|
|
function _element_end($xp, $name)
|
|
|
|
{
|
2001-07-17 02:01:09 +08:00
|
|
|
switch ($name) {
|
|
|
|
case 'Dir':
|
|
|
|
array_pop($this->dir_names);
|
|
|
|
unset($this->dir_install);
|
|
|
|
unset($this->dir_role);
|
|
|
|
break;
|
|
|
|
case 'File':
|
|
|
|
$path = '';
|
|
|
|
foreach ($this->dir_names as $dir) {
|
|
|
|
$path .= $dir . DIRECTORY_SEPARATOR;
|
|
|
|
}
|
|
|
|
$path .= $this->current_file;
|
|
|
|
$this->filelist[$path] = $this->current_attributes;
|
|
|
|
// Set the baseinstalldir only if the file don't have this attrib
|
|
|
|
if (!isset($this->filelist[$path]['BaseInstallDir']) &&
|
|
|
|
isset($this->dir_install))
|
|
|
|
{
|
|
|
|
$this->filelist[$path]['BaseInstallDir'] = $this->dir_install;
|
|
|
|
}
|
|
|
|
// Set the Role
|
|
|
|
if (!isset($this->filelist[$path]['Role']) && isset($this->dir_role)) {
|
|
|
|
$this->filelist[$path]['Role'] = $this->dir_role;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'LibFile':
|
|
|
|
$path = '';
|
|
|
|
foreach ($this->dir_names as $dir) {
|
|
|
|
$path .= $dir . DIRECTORY_SEPARATOR;
|
|
|
|
}
|
|
|
|
$path .= $this->lib_name;
|
|
|
|
$this->filelist[$path] = $this->lib_atts;
|
|
|
|
// Set the baseinstalldir only if the file don't have this attrib
|
|
|
|
if (!isset($this->filelist[$path]['BaseInstallDir']) &&
|
|
|
|
isset($this->dir_install))
|
|
|
|
{
|
|
|
|
$this->filelist[$path]['BaseInstallDir'] = $this->dir_install;
|
|
|
|
}
|
|
|
|
if (isset($this->lib_sources)) {
|
|
|
|
$this->filelist[$path]['sources'] = $this->lib_sources;
|
|
|
|
}
|
|
|
|
unset($this->lib_atts);
|
|
|
|
unset($this->lib_sources);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
array_pop($this->element_stack);
|
|
|
|
$this->current_element = $this->element_stack[sizeof($this->element_stack)-1];
|
2001-04-22 09:09:14 +08:00
|
|
|
}
|
|
|
|
|
2001-04-22 15:43:34 +08:00
|
|
|
// }}}
|
|
|
|
// {{{ _pkginfo_cdata()
|
2001-04-22 09:09:14 +08:00
|
|
|
|
|
|
|
function _pkginfo_cdata($xp, $data)
|
|
|
|
{
|
2001-07-17 02:01:09 +08:00
|
|
|
$prev = $this->element_stack[sizeof($this->element_stack)-2];
|
|
|
|
switch ($this->current_element) {
|
|
|
|
case 'Name':
|
|
|
|
switch ($prev) {
|
|
|
|
case 'Package':
|
|
|
|
$this->pkginfo['package'] .= $data;
|
2001-04-22 09:09:14 +08:00
|
|
|
break;
|
2001-07-17 02:01:09 +08:00
|
|
|
case 'Maintainer':
|
|
|
|
$this->pkginfo['maintainer_name'] .= $data;
|
2001-04-22 09:09:14 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2001-07-17 02:01:09 +08:00
|
|
|
case 'Summary':
|
|
|
|
$this->pkginfo['summary'] .= $data;
|
2001-04-22 09:09:14 +08:00
|
|
|
break;
|
2001-07-17 02:01:09 +08:00
|
|
|
case 'Initials':
|
|
|
|
$this->pkginfo['maintainer_handle'] .= $data;
|
2001-04-22 09:09:14 +08:00
|
|
|
break;
|
2001-07-17 02:01:09 +08:00
|
|
|
case 'Email':
|
|
|
|
$this->pkginfo['maintainer_email'] .= $data;
|
2001-04-22 09:09:14 +08:00
|
|
|
break;
|
2001-07-17 02:01:09 +08:00
|
|
|
case 'Version':
|
|
|
|
$this->pkginfo['version'] .= $data;
|
2001-04-22 09:09:14 +08:00
|
|
|
break;
|
2001-07-17 02:01:09 +08:00
|
|
|
case 'Date':
|
|
|
|
$this->pkginfo['release_date'] .= $data;
|
2001-04-22 09:09:14 +08:00
|
|
|
break;
|
2001-07-17 02:01:09 +08:00
|
|
|
case 'Notes':
|
|
|
|
$this->pkginfo['release_notes'] .= $data;
|
2001-04-22 09:09:14 +08:00
|
|
|
break;
|
2001-07-17 02:01:09 +08:00
|
|
|
case 'Dir':
|
|
|
|
if (!$this->phpdir) {
|
|
|
|
break;
|
|
|
|
}
|
2001-04-22 09:09:14 +08:00
|
|
|
$dir = trim($data);
|
|
|
|
// XXX add to file list
|
2001-07-17 02:01:09 +08:00
|
|
|
break;
|
|
|
|
case 'File':
|
|
|
|
$role = strtolower($this->current_attributes['Role']);
|
|
|
|
$this->current_file = trim($data);
|
|
|
|
break;
|
|
|
|
case 'LibName':
|
|
|
|
$this->lib_name = trim($data);
|
|
|
|
break;
|
|
|
|
case 'Sources':
|
|
|
|
$this->lib_sources[] = trim($data);
|
|
|
|
break;
|
|
|
|
}
|
2001-04-22 09:09:14 +08:00
|
|
|
}
|
|
|
|
|
2001-04-22 15:43:34 +08:00
|
|
|
// }}}
|
|
|
|
// {{{ infoFromDescriptionFile()
|
2001-04-22 09:09:14 +08:00
|
|
|
|
2001-04-22 15:43:34 +08:00
|
|
|
function infoFromDescriptionFile($descfile)
|
2001-04-22 09:09:14 +08:00
|
|
|
{
|
2001-07-17 02:01:09 +08:00
|
|
|
$fp = fopen($descfile, 'r');
|
|
|
|
$xp = @xml_parser_create();
|
|
|
|
if (!$xp) {
|
|
|
|
return $this->raiseError('Unable to create XML parser');
|
|
|
|
}
|
|
|
|
xml_set_object($xp, $this);
|
|
|
|
xml_set_element_handler($xp, '_element_start', '_element_end');
|
|
|
|
xml_set_character_data_handler($xp, '_pkginfo_cdata');
|
|
|
|
xml_parser_set_option($xp, XML_OPTION_CASE_FOLDING, false);
|
|
|
|
|
|
|
|
$this->element_stack = array();
|
|
|
|
$this->pkginfo = array();
|
|
|
|
$this->current_element = false;
|
|
|
|
$this->destdir = '';
|
|
|
|
$this->filelist = array();
|
2001-04-22 09:09:14 +08:00
|
|
|
|
|
|
|
// read the whole thing so we only get one cdata callback
|
|
|
|
// for each block of cdata
|
2001-07-17 02:01:09 +08:00
|
|
|
$data = fread($fp, filesize($descfile));
|
2001-04-22 15:43:34 +08:00
|
|
|
if (!@xml_parse($xp, $data, 1)) {
|
2001-04-22 09:09:14 +08:00
|
|
|
$msg = sprintf("XML error: %s at line %d",
|
|
|
|
xml_error_string(xml_get_error_code($xp)),
|
|
|
|
xml_get_current_line_number($xp));
|
|
|
|
xml_parser_free($xp);
|
|
|
|
return $this->raiseError($msg);
|
2001-07-17 02:01:09 +08:00
|
|
|
}
|
2001-04-22 09:09:14 +08:00
|
|
|
|
2001-07-17 02:01:09 +08:00
|
|
|
xml_parser_free($xp);
|
2001-04-22 09:09:14 +08:00
|
|
|
|
2001-04-22 15:43:34 +08:00
|
|
|
foreach ($this->pkginfo as $k => $v) {
|
|
|
|
$this->pkginfo[$k] = trim($v);
|
|
|
|
}
|
2001-07-17 02:01:09 +08:00
|
|
|
$this->pkginfo['filelist'] = &$this->filelist;
|
2001-04-22 09:09:14 +08:00
|
|
|
return $this->pkginfo;
|
|
|
|
}
|
2001-04-22 15:43:34 +08:00
|
|
|
|
|
|
|
// }}}
|
2001-04-22 09:09:14 +08:00
|
|
|
}
|
2001-07-17 02:01:09 +08:00
|
|
|
?>
|