2001-04-22 09:09:14 +08:00
|
|
|
<?php
|
|
|
|
//
|
|
|
|
// +----------------------------------------------------------------------+
|
2001-12-11 23:32:16 +08:00
|
|
|
// | PHP Version 4 |
|
2001-04-22 09:09:14 +08:00
|
|
|
// +----------------------------------------------------------------------+
|
2001-12-11 23:32:16 +08:00
|
|
|
// | Copyright (c) 1997-2002 The PHP Group |
|
2001-04-22 09:09:14 +08:00
|
|
|
// +----------------------------------------------------------------------+
|
|
|
|
// | 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> |
|
2001-08-18 22:40:25 +08:00
|
|
|
// | Tomas V.V.Cox <cox@idecnet.com> |
|
2001-04-22 09:09:14 +08:00
|
|
|
// +----------------------------------------------------------------------+
|
|
|
|
//
|
2001-07-19 18:32:06 +08:00
|
|
|
// $Id$
|
2001-04-22 09:09:14 +08:00
|
|
|
|
2001-07-18 03:13:40 +08:00
|
|
|
require_once 'PEAR.php';
|
2001-09-28 08:55:16 +08:00
|
|
|
require_once 'Archive/Tar.php';
|
2001-10-29 20:15:53 +08:00
|
|
|
require_once 'System.php';
|
2002-04-29 14:23:05 +08:00
|
|
|
require_once 'PEAR/Config.php';
|
2001-04-22 09:09:14 +08:00
|
|
|
|
2002-06-06 18:16:42 +08:00
|
|
|
// {{{ constants and globals
|
|
|
|
|
|
|
|
define('PEAR_COMMON_PACKAGE_NAME_PREG', '/^([A-Z][a-zA-Z0-9_]+|[a-z][a-z0-9_]+)$/');
|
2002-04-23 14:28:44 +08:00
|
|
|
|
2002-03-29 08:05:55 +08:00
|
|
|
/**
|
|
|
|
* List of temporary files and directories registered by
|
|
|
|
* PEAR_Common::addTempFile().
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
$GLOBALS['_PEAR_Common_tempfiles'] = array();
|
|
|
|
|
2002-04-23 14:28:44 +08:00
|
|
|
/**
|
|
|
|
* Valid maintainer roles
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
$GLOBALS['_PEAR_Common_maintainer_roles'] = array('lead','developer','contributor','helper');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Valid release states
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
$GLOBALS['_PEAR_Common_release_states'] = array('alpha','beta','stable','snapshot','devel');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Valid dependency types
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
$GLOBALS['_PEAR_Common_dependency_types'] = array('pkg','ext','php','prog','ldlib','rtlib','os','websrv','sapi');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Valid dependency relations
|
|
|
|
* @var array
|
2001-10-29 20:15:53 +08:00
|
|
|
*/
|
2002-04-23 14:28:44 +08:00
|
|
|
$GLOBALS['_PEAR_Common_dependency_relations'] = array('has','eq','lt','le','gt','ge');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Valid file roles
|
|
|
|
* @var array
|
|
|
|
*/
|
2002-05-27 09:20:10 +08:00
|
|
|
$GLOBALS['_PEAR_Common_file_roles'] = array('php','ext','test','doc','data','src','script');
|
2002-04-23 14:28:44 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Valid replacement types
|
|
|
|
* @var array
|
|
|
|
*/
|
2002-06-02 21:07:19 +08:00
|
|
|
$GLOBALS['_PEAR_Common_replacement_types'] = array('php-const', 'pear-config', 'package-info');
|
2002-04-23 14:28:44 +08:00
|
|
|
|
2002-04-28 15:52:00 +08:00
|
|
|
/**
|
|
|
|
* Valid "provide" types
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
$GLOBALS['_PEAR_Common_provide_types'] = array('ext', 'prog', 'class', 'function', 'feature', 'api');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Valid "provide" types
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
$GLOBALS['_PEAR_Common_script_phases'] = array('pre-install', 'post-install', 'pre-uninstall', 'post-uninstall', 'pre-build', 'post-build', 'pre-configure', 'post-configure', 'pre-setup', 'post-setup');
|
|
|
|
|
2002-04-23 14:28:44 +08:00
|
|
|
// }}}
|
2002-03-28 22:07:33 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class providing common functionality for PEAR adminsitration classes.
|
|
|
|
*/
|
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();
|
|
|
|
|
|
|
|
/** assoc with information about a package */
|
|
|
|
var $pkginfo = array();
|
|
|
|
|
2002-04-02 17:21:08 +08:00
|
|
|
/**
|
|
|
|
* User Interface object (PEAR_Frontend_* class). If null,
|
2002-04-24 07:36:54 +08:00
|
|
|
* the log() method uses print.
|
2002-04-02 17:21:08 +08:00
|
|
|
* @var object
|
|
|
|
*/
|
|
|
|
var $ui = null;
|
|
|
|
|
2002-04-29 14:23:05 +08:00
|
|
|
/**
|
|
|
|
* Configuration object (PEAR_Config).
|
|
|
|
* @var object
|
|
|
|
*/
|
|
|
|
var $config = null;
|
|
|
|
|
2002-04-09 16:10:12 +08:00
|
|
|
var $current_path = null;
|
|
|
|
|
2001-04-22 09:09:14 +08:00
|
|
|
// }}}
|
|
|
|
|
|
|
|
// {{{ constructor
|
|
|
|
|
2002-03-28 22:07:33 +08:00
|
|
|
/**
|
|
|
|
* PEAR_Common constructor
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
2001-04-22 09:09:14 +08:00
|
|
|
function PEAR_Common()
|
|
|
|
{
|
2002-05-21 09:20:51 +08:00
|
|
|
parent::PEAR();
|
2002-04-29 14:23:05 +08:00
|
|
|
$this->config = &PEAR_Config::singleton();
|
2002-06-02 21:07:19 +08:00
|
|
|
$this->debug = $this->config->get('verbose');
|
2001-04-22 09:09:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
// {{{ destructor
|
|
|
|
|
2002-03-28 22:07:33 +08:00
|
|
|
/**
|
|
|
|
* PEAR_Common destructor
|
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
*/
|
2001-07-17 02:01:09 +08:00
|
|
|
function _PEAR_Common()
|
|
|
|
{
|
2001-12-29 03:27:08 +08:00
|
|
|
// doesn't work due to bug #14744
|
|
|
|
//$tempfiles = $this->_tempfiles;
|
|
|
|
$tempfiles =& $GLOBALS['_PEAR_Common_tempfiles'];
|
2002-03-29 08:05:55 +08:00
|
|
|
while ($file = array_shift($tempfiles)) {
|
2001-07-19 01:11:28 +08:00
|
|
|
if (@is_dir($file)) {
|
2001-10-08 14:10:54 +08:00
|
|
|
System::rm("-rf $file");
|
2001-07-19 01:11:28 +08:00
|
|
|
} elseif (file_exists($file)) {
|
2001-04-22 09:09:14 +08:00
|
|
|
unlink($file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
// {{{ addTempFile()
|
|
|
|
|
2002-03-28 22:07:33 +08:00
|
|
|
/**
|
|
|
|
* Register a temporary file or directory. When the destructor is
|
|
|
|
* executed, all registered temporary files and directories are
|
|
|
|
* removed.
|
|
|
|
*
|
2002-04-23 14:28:44 +08:00
|
|
|
* @param string $file name of file or directory
|
2002-03-28 22:07:33 +08:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
2001-04-22 09:09:14 +08:00
|
|
|
function addTempFile($file)
|
|
|
|
{
|
2002-03-29 08:05:55 +08:00
|
|
|
$GLOBALS['_PEAR_Common_tempfiles'][] = $file;
|
2001-04-22 09:09:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
2001-07-18 03:13:40 +08:00
|
|
|
// {{{ mkDirHier()
|
|
|
|
|
2002-03-28 22:07:33 +08:00
|
|
|
/**
|
|
|
|
* Wrapper to System::mkDir(), creates a directory as well as
|
|
|
|
* any necessary parent directories.
|
|
|
|
*
|
2002-04-23 14:28:44 +08:00
|
|
|
* @param string $dir directory name
|
2002-03-28 22:07:33 +08:00
|
|
|
*
|
|
|
|
* @return bool TRUE on success, or a PEAR error
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
2001-07-18 03:13:40 +08:00
|
|
|
function mkDirHier($dir)
|
|
|
|
{
|
2001-12-16 23:14:00 +08:00
|
|
|
$this->log(2, "+ create dir $dir");
|
|
|
|
return System::mkDir("-p $dir");
|
2001-07-18 03:13:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
// {{{ log()
|
|
|
|
|
2002-03-28 22:07:33 +08:00
|
|
|
/**
|
|
|
|
* Logging method.
|
|
|
|
*
|
2002-04-23 14:28:44 +08:00
|
|
|
* @param int $level log level (0 is quiet, higher is noisier)
|
|
|
|
* @param string $msg message to write to the log
|
2002-03-28 22:07:33 +08:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
2001-07-18 03:13:40 +08:00
|
|
|
function log($level, $msg)
|
|
|
|
{
|
|
|
|
if ($this->debug >= $level) {
|
2002-04-02 17:21:08 +08:00
|
|
|
if (is_object($this->ui)) {
|
2002-06-02 21:07:19 +08:00
|
|
|
$this->ui->log($msg);
|
2002-04-02 17:21:08 +08:00
|
|
|
} else {
|
|
|
|
print "$msg\n";
|
|
|
|
}
|
2001-07-18 03:13:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
2001-10-30 20:19:36 +08:00
|
|
|
// {{{ mkTempDir()
|
2001-07-18 03:13:40 +08:00
|
|
|
|
2002-03-28 22:07:33 +08:00
|
|
|
/**
|
|
|
|
* Create and register a temporary directory.
|
2002-04-01 03:04:53 +08:00
|
|
|
*
|
2002-04-23 14:28:44 +08:00
|
|
|
* @param string $tmpdir (optional) Directory to use as tmpdir.
|
|
|
|
* Will use system defaults (for example
|
|
|
|
* /tmp or c:\windows\temp) if not specified
|
2002-03-29 07:44:31 +08:00
|
|
|
*
|
2002-03-28 22:07:33 +08:00
|
|
|
* @return string name of created directory
|
2002-04-01 03:04:53 +08:00
|
|
|
*
|
2002-03-28 22:07:33 +08:00
|
|
|
* @access public
|
|
|
|
*/
|
2002-03-29 07:44:31 +08:00
|
|
|
function mkTempDir($tmpdir = '')
|
2001-10-08 14:10:54 +08:00
|
|
|
{
|
2002-03-29 07:44:31 +08:00
|
|
|
if ($tmpdir) {
|
|
|
|
$topt = "-t $tmpdir ";
|
|
|
|
} else {
|
|
|
|
$topt = '';
|
|
|
|
}
|
|
|
|
if (!$tmpdir = System::mktemp($topt . '-d pear')) {
|
2002-02-11 01:23:04 +08:00
|
|
|
return false;
|
2001-10-08 14:10:54 +08:00
|
|
|
}
|
|
|
|
$this->addTempFile($tmpdir);
|
|
|
|
return $tmpdir;
|
|
|
|
}
|
|
|
|
|
2001-10-30 20:19:36 +08:00
|
|
|
// }}}
|
2002-04-29 14:23:05 +08:00
|
|
|
// {{{ setFrontendObject()
|
2002-04-02 17:21:08 +08:00
|
|
|
|
2002-08-16 01:07:12 +08:00
|
|
|
/**
|
|
|
|
* Set object that represents the frontend to be used.
|
|
|
|
*
|
|
|
|
* @param object Reference of the frontend object
|
|
|
|
* @return void
|
|
|
|
* @access public
|
|
|
|
*/
|
2002-04-29 14:23:05 +08:00
|
|
|
function setFrontendObject(&$ui)
|
2002-04-02 17:21:08 +08:00
|
|
|
{
|
|
|
|
$this->ui = &$ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
|
2002-05-27 07:38:22 +08:00
|
|
|
// {{{ _unIndent()
|
|
|
|
|
2002-08-16 01:07:12 +08:00
|
|
|
/**
|
|
|
|
* Unindent given string (?)
|
|
|
|
*
|
|
|
|
* @param string $str The string that has to be unindented.
|
|
|
|
* @return string
|
|
|
|
* @access private
|
|
|
|
*/
|
2002-05-27 07:38:22 +08:00
|
|
|
function _unIndent($str)
|
|
|
|
{
|
|
|
|
// remove leading newlines
|
|
|
|
$str = preg_replace('/^[\r\n]+/', '', $str);
|
|
|
|
// find whitespace at the beginning of the first line
|
|
|
|
$indent_len = strspn($str, " \t");
|
|
|
|
$indent = substr($str, 0, $indent_len);
|
|
|
|
$data = '';
|
|
|
|
// remove the same amount of whitespace from following lines
|
|
|
|
foreach (explode("\n", $str) as $line) {
|
|
|
|
if (substr($line, 0, $indent_len) == $indent) {
|
|
|
|
$data .= substr($line, $indent_len) . "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
2001-04-22 15:43:34 +08:00
|
|
|
// {{{ _element_start()
|
2001-04-22 09:09:14 +08:00
|
|
|
|
2002-03-28 22:07:33 +08:00
|
|
|
/**
|
|
|
|
* XML parser callback for starting elements. Used while package
|
|
|
|
* format version is not yet known.
|
|
|
|
*
|
2002-04-23 14:28:44 +08:00
|
|
|
* @param resource $xp XML parser resource
|
|
|
|
* @param string $name name of starting element
|
|
|
|
* @param array $attribs element attributes, name => value
|
2002-03-28 22:07:33 +08:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
*/
|
2001-04-22 09:09:14 +08:00
|
|
|
function _element_start($xp, $name, $attribs)
|
2002-03-28 22:07:33 +08:00
|
|
|
{
|
|
|
|
array_push($this->element_stack, $name);
|
|
|
|
$this->current_element = $name;
|
|
|
|
$spos = sizeof($this->element_stack) - 2;
|
|
|
|
$this->prev_element = ($spos >= 0) ? $this->element_stack[$spos] : '';
|
|
|
|
$this->current_attributes = $attribs;
|
|
|
|
switch ($name) {
|
|
|
|
case 'package': {
|
|
|
|
if (isset($attribs['version'])) {
|
|
|
|
$vs = preg_replace('/[^0-9a-z]/', '_', $attribs['version']);
|
|
|
|
} else {
|
|
|
|
$vs = '1_0';
|
|
|
|
}
|
|
|
|
$elem_start = '_element_start_'. $vs;
|
|
|
|
$elem_end = '_element_end_'. $vs;
|
|
|
|
$cdata = '_pkginfo_cdata_'. $vs;
|
|
|
|
xml_set_element_handler($xp, $elem_start, $elem_end);
|
|
|
|
xml_set_character_data_handler($xp, $cdata);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
// {{{ _element_end()
|
|
|
|
|
|
|
|
/**
|
|
|
|
* XML parser callback for ending elements. Used while package
|
|
|
|
* format version is not yet known.
|
|
|
|
*
|
2002-04-23 14:28:44 +08:00
|
|
|
* @param resource $xp XML parser resource
|
|
|
|
* @param string $name name of ending element
|
2002-03-28 22:07:33 +08:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
function _element_end($xp, $name)
|
|
|
|
{
|
|
|
|
}
|
2002-04-01 03:04:53 +08:00
|
|
|
|
2002-03-28 22:07:33 +08:00
|
|
|
// }}}
|
|
|
|
|
|
|
|
// Support for package DTD v1.0:
|
|
|
|
// {{{ _element_start_1_0()
|
|
|
|
|
|
|
|
/**
|
|
|
|
* XML parser callback for ending elements. Used for version 1.0
|
|
|
|
* packages.
|
|
|
|
*
|
2002-04-23 14:28:44 +08:00
|
|
|
* @param resource $xp XML parser resource
|
|
|
|
* @param string $name name of ending element
|
2002-03-28 22:07:33 +08:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
function _element_start_1_0($xp, $name, $attribs)
|
2001-04-22 09:09:14 +08:00
|
|
|
{
|
2001-07-17 02:01:09 +08:00
|
|
|
array_push($this->element_stack, $name);
|
|
|
|
$this->current_element = $name;
|
2001-11-06 08:22:18 +08:00
|
|
|
$spos = sizeof($this->element_stack) - 2;
|
|
|
|
$this->prev_element = ($spos >= 0) ? $this->element_stack[$spos] : '';
|
2001-07-17 02:01:09 +08:00
|
|
|
$this->current_attributes = $attribs;
|
2001-12-27 19:10:56 +08:00
|
|
|
$this->cdata = '';
|
2001-07-17 02:01:09 +08:00
|
|
|
switch ($name) {
|
2001-10-30 20:29:55 +08:00
|
|
|
case 'dir':
|
2002-04-10 06:30:44 +08:00
|
|
|
if ($this->in_changelog) {
|
|
|
|
break;
|
|
|
|
}
|
2002-03-22 03:12:49 +08:00
|
|
|
if ($attribs['name'] != '/') {
|
2001-10-30 20:29:55 +08:00
|
|
|
$this->dir_names[] = $attribs['name'];
|
2001-07-17 02:01:09 +08:00
|
|
|
}
|
2001-10-30 20:29:55 +08:00
|
|
|
if (isset($attribs['baseinstalldir'])) {
|
|
|
|
$this->dir_install = $attribs['baseinstalldir'];
|
2001-07-17 02:01:09 +08:00
|
|
|
}
|
2001-10-30 20:29:55 +08:00
|
|
|
if (isset($attribs['role'])) {
|
|
|
|
$this->dir_role = $attribs['role'];
|
2001-07-17 02:01:09 +08:00
|
|
|
}
|
|
|
|
break;
|
2002-04-09 16:10:12 +08:00
|
|
|
case 'file':
|
2002-04-10 05:48:19 +08:00
|
|
|
if ($this->in_changelog) {
|
|
|
|
break;
|
|
|
|
}
|
2002-04-09 16:10:12 +08:00
|
|
|
if (isset($attribs['name'])) {
|
|
|
|
$path = '';
|
|
|
|
if (count($this->dir_names)) {
|
|
|
|
foreach ($this->dir_names as $dir) {
|
|
|
|
$path .= $dir . DIRECTORY_SEPARATOR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$path .= $attribs['name'];
|
|
|
|
unset($attribs['name']);
|
|
|
|
$this->current_path = $path;
|
|
|
|
$this->filelist[$path] = $attribs;
|
|
|
|
// 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 'replace':
|
2002-04-10 06:30:44 +08:00
|
|
|
if (!$this->in_changelog) {
|
|
|
|
$this->filelist[$this->current_path]['replacements'][] = $attribs;
|
|
|
|
}
|
2002-04-09 16:10:12 +08:00
|
|
|
break;
|
|
|
|
|
2001-10-30 20:29:55 +08:00
|
|
|
case 'libfile':
|
2002-04-10 06:30:44 +08:00
|
|
|
if (!$this->in_changelog) {
|
|
|
|
$this->lib_atts = $attribs;
|
|
|
|
$this->lib_atts['role'] = 'extsrc';
|
|
|
|
}
|
2001-07-17 02:01:09 +08:00
|
|
|
break;
|
2001-10-30 20:29:55 +08:00
|
|
|
case 'maintainers':
|
2001-08-18 22:40:25 +08:00
|
|
|
$this->pkginfo['maintainers'] = array();
|
|
|
|
$this->m_i = 0; // maintainers array index
|
|
|
|
break;
|
2001-10-30 20:29:55 +08:00
|
|
|
case 'maintainer':
|
2001-08-18 22:40:25 +08:00
|
|
|
// compatibility check
|
|
|
|
if (!isset($this->pkginfo['maintainers'])) {
|
|
|
|
$this->pkginfo['maintainers'] = array();
|
|
|
|
$this->m_i = 0;
|
|
|
|
}
|
|
|
|
$this->pkginfo['maintainers'][$this->m_i] = array();
|
|
|
|
$this->current_maintainer =& $this->pkginfo['maintainers'][$this->m_i];
|
|
|
|
break;
|
2001-10-30 20:29:55 +08:00
|
|
|
case 'changelog':
|
2001-08-18 22:40:25 +08:00
|
|
|
$this->pkginfo['changelog'] = array();
|
|
|
|
$this->c_i = 0; // changelog array index
|
|
|
|
$this->in_changelog = true;
|
|
|
|
break;
|
2001-10-30 20:29:55 +08:00
|
|
|
case 'release':
|
2001-08-18 22:40:25 +08:00
|
|
|
if ($this->in_changelog) {
|
|
|
|
$this->pkginfo['changelog'][$this->c_i] = array();
|
2002-04-10 06:30:44 +08:00
|
|
|
$this->current_release = &$this->pkginfo['changelog'][$this->c_i];
|
|
|
|
} else {
|
|
|
|
$this->current_release = &$this->pkginfo;
|
2001-08-18 22:40:25 +08:00
|
|
|
}
|
|
|
|
break;
|
2001-12-17 00:21:35 +08:00
|
|
|
case 'deps':
|
2002-03-28 22:07:33 +08:00
|
|
|
if (!$this->in_changelog) {
|
|
|
|
$this->pkginfo['release_deps'] = array();
|
|
|
|
}
|
2001-12-17 00:21:35 +08:00
|
|
|
break;
|
|
|
|
case 'dep':
|
|
|
|
// dependencies array index
|
2002-03-28 22:07:33 +08:00
|
|
|
if (!$this->in_changelog) {
|
2002-06-07 18:18:59 +08:00
|
|
|
$this->d_i++;
|
2002-03-28 22:07:33 +08:00
|
|
|
$this->pkginfo['release_deps'][$this->d_i] = $attribs;
|
|
|
|
}
|
2001-12-17 00:21:35 +08:00
|
|
|
break;
|
2002-05-27 09:20:10 +08:00
|
|
|
case 'configureoptions':
|
|
|
|
if (!$this->in_changelog) {
|
|
|
|
$this->pkginfo['configure_options'] = array();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'configureoption':
|
|
|
|
if (!$this->in_changelog) {
|
|
|
|
$this->pkginfo['configure_options'][] = $attribs;
|
|
|
|
}
|
|
|
|
break;
|
2001-07-17 02:01:09 +08:00
|
|
|
}
|
2001-04-22 09:09:14 +08:00
|
|
|
}
|
|
|
|
|
2001-04-22 15:43:34 +08:00
|
|
|
// }}}
|
2002-03-28 22:07:33 +08:00
|
|
|
// {{{ _element_end_1_0()
|
2001-04-22 09:09:14 +08:00
|
|
|
|
2002-03-28 22:07:33 +08:00
|
|
|
/**
|
|
|
|
* XML parser callback for ending elements. Used for version 1.0
|
|
|
|
* packages.
|
|
|
|
*
|
2002-04-23 14:28:44 +08:00
|
|
|
* @param resource $xp XML parser resource
|
|
|
|
* @param string $name name of ending element
|
2002-03-28 22:07:33 +08:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
function _element_end_1_0($xp, $name)
|
2001-04-22 09:09:14 +08:00
|
|
|
{
|
2001-12-27 19:10:56 +08:00
|
|
|
$data = trim($this->cdata);
|
2001-07-17 02:01:09 +08:00
|
|
|
switch ($name) {
|
2001-10-30 20:29:55 +08:00
|
|
|
case 'name':
|
2001-08-18 22:40:25 +08:00
|
|
|
switch ($this->prev_element) {
|
2001-10-30 20:29:55 +08:00
|
|
|
case 'package':
|
2002-06-06 18:16:42 +08:00
|
|
|
// XXX should we check the package name here?
|
2001-12-27 19:10:56 +08:00
|
|
|
$this->pkginfo['package'] = ereg_replace('[^a-zA-Z0-9._]', '_', $data);
|
2001-04-22 09:09:14 +08:00
|
|
|
break;
|
2001-10-30 20:29:55 +08:00
|
|
|
case 'maintainer':
|
2001-11-06 08:22:18 +08:00
|
|
|
$this->current_maintainer['name'] = $data;
|
2001-04-22 09:09:14 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2001-10-30 20:29:55 +08:00
|
|
|
case 'summary':
|
2001-11-06 08:22:18 +08:00
|
|
|
$this->pkginfo['summary'] = $data;
|
2001-04-22 09:09:14 +08:00
|
|
|
break;
|
2001-12-29 03:27:08 +08:00
|
|
|
case 'description':
|
2002-05-27 07:38:22 +08:00
|
|
|
$data = $this->_unIndent($this->cdata);
|
2001-12-29 03:27:08 +08:00
|
|
|
$this->pkginfo['description'] = $data;
|
|
|
|
break;
|
2001-10-30 20:29:55 +08:00
|
|
|
case 'user':
|
2001-11-06 08:22:18 +08:00
|
|
|
$this->current_maintainer['handle'] = $data;
|
2001-04-22 09:09:14 +08:00
|
|
|
break;
|
2001-10-30 20:29:55 +08:00
|
|
|
case 'email':
|
2001-11-06 08:22:18 +08:00
|
|
|
$this->current_maintainer['email'] = $data;
|
2001-08-18 22:40:25 +08:00
|
|
|
break;
|
2001-10-30 20:29:55 +08:00
|
|
|
case 'role':
|
2002-04-07 23:49:23 +08:00
|
|
|
$this->current_maintainer['role'] = $data;
|
2001-04-22 09:09:14 +08:00
|
|
|
break;
|
2001-10-30 20:29:55 +08:00
|
|
|
case 'version':
|
2001-12-27 19:10:56 +08:00
|
|
|
$data = ereg_replace ('[^a-zA-Z0-9._\-]', '_', $data);
|
2001-08-18 22:40:25 +08:00
|
|
|
if ($this->in_changelog) {
|
2001-11-06 08:22:18 +08:00
|
|
|
$this->current_release['version'] = $data;
|
2001-08-18 22:40:25 +08:00
|
|
|
} else {
|
2001-11-06 08:22:18 +08:00
|
|
|
$this->pkginfo['version'] = $data;
|
2001-08-18 22:40:25 +08:00
|
|
|
}
|
2001-04-22 09:09:14 +08:00
|
|
|
break;
|
2001-10-30 20:29:55 +08:00
|
|
|
case 'date':
|
2001-08-18 22:40:25 +08:00
|
|
|
if ($this->in_changelog) {
|
2001-11-06 08:22:18 +08:00
|
|
|
$this->current_release['release_date'] = $data;
|
2001-08-18 22:40:25 +08:00
|
|
|
} else {
|
2001-11-06 08:22:18 +08:00
|
|
|
$this->pkginfo['release_date'] = $data;
|
2001-08-18 22:40:25 +08:00
|
|
|
}
|
2001-04-22 09:09:14 +08:00
|
|
|
break;
|
2001-10-30 20:29:55 +08:00
|
|
|
case 'notes':
|
2002-05-27 07:33:01 +08:00
|
|
|
// try to "de-indent" release notes in case someone
|
|
|
|
// has been over-indenting their xml ;-)
|
2002-05-27 07:38:22 +08:00
|
|
|
$data = $this->_unIndent($this->cdata);
|
2001-08-18 22:40:25 +08:00
|
|
|
if ($this->in_changelog) {
|
2001-11-06 08:22:18 +08:00
|
|
|
$this->current_release['release_notes'] = $data;
|
2001-08-18 22:40:25 +08:00
|
|
|
} else {
|
2001-11-06 08:22:18 +08:00
|
|
|
$this->pkginfo['release_notes'] = $data;
|
2001-08-18 22:40:25 +08:00
|
|
|
}
|
2001-04-22 09:09:14 +08:00
|
|
|
break;
|
2002-11-13 22:17:26 +08:00
|
|
|
case 'warnings':
|
|
|
|
if ($this->in_changelog) {
|
|
|
|
$this->current_release['release_warnings'] = $data;
|
|
|
|
} else {
|
|
|
|
$this->pkginfo['release_warnings'] = $data;
|
|
|
|
}
|
|
|
|
break;
|
2001-10-30 20:29:55 +08:00
|
|
|
case 'state':
|
2002-04-07 23:49:23 +08:00
|
|
|
if ($this->in_changelog) {
|
2001-08-18 22:40:25 +08:00
|
|
|
$this->current_release['release_state'] = $data;
|
|
|
|
} else {
|
2001-11-06 08:22:18 +08:00
|
|
|
$this->pkginfo['release_state'] = $data;
|
2001-07-17 02:01:09 +08:00
|
|
|
}
|
2001-08-18 22:40:25 +08:00
|
|
|
break;
|
2001-12-24 05:32:09 +08:00
|
|
|
case 'license':
|
2001-12-27 19:10:56 +08:00
|
|
|
$this->pkginfo['release_license'] = $data;
|
2001-07-17 02:01:09 +08:00
|
|
|
break;
|
2001-10-30 20:29:55 +08:00
|
|
|
case 'sources':
|
2001-12-27 19:10:56 +08:00
|
|
|
$this->lib_sources[] = $data;
|
2001-07-17 02:01:09 +08:00
|
|
|
break;
|
2001-12-17 00:21:35 +08:00
|
|
|
case 'dep':
|
2002-06-07 18:18:59 +08:00
|
|
|
if ($data && !$this->in_changelog) {
|
2001-12-17 00:21:35 +08:00
|
|
|
$this->pkginfo['release_deps'][$this->d_i]['name'] = $data;
|
|
|
|
}
|
|
|
|
break;
|
2001-12-27 19:10:56 +08:00
|
|
|
case 'dir':
|
2002-04-10 06:30:44 +08:00
|
|
|
if ($this->in_changelog) {
|
|
|
|
break;
|
|
|
|
}
|
2001-12-27 19:10:56 +08:00
|
|
|
array_pop($this->dir_names);
|
|
|
|
break;
|
|
|
|
case 'file':
|
2002-04-10 05:48:19 +08:00
|
|
|
if ($this->in_changelog) {
|
|
|
|
break;
|
|
|
|
}
|
2002-04-09 16:10:12 +08:00
|
|
|
if ($data) {
|
|
|
|
$path = '';
|
|
|
|
if (count($this->dir_names)) {
|
|
|
|
foreach ($this->dir_names as $dir) {
|
|
|
|
$path .= $dir . DIRECTORY_SEPARATOR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$path .= $data;
|
|
|
|
$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;
|
2002-01-30 20:18:10 +08:00
|
|
|
}
|
2001-12-27 19:10:56 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'libfile':
|
2002-04-10 06:30:44 +08:00
|
|
|
if ($this->in_changelog) {
|
|
|
|
break;
|
|
|
|
}
|
2001-12-27 19:10:56 +08:00
|
|
|
$path = '';
|
2002-01-30 20:18:10 +08:00
|
|
|
if (!empty($this->dir_names)) {
|
|
|
|
foreach ($this->dir_names as $dir) {
|
|
|
|
$path .= $dir . DIRECTORY_SEPARATOR;
|
|
|
|
}
|
2001-12-27 19:10:56 +08:00
|
|
|
}
|
|
|
|
$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)) {
|
2002-03-28 22:07:33 +08:00
|
|
|
$this->filelist[$path]['sources'] = implode(' ', $this->lib_sources);
|
2001-12-27 19:10:56 +08:00
|
|
|
}
|
|
|
|
unset($this->lib_atts);
|
|
|
|
unset($this->lib_sources);
|
2002-03-28 22:07:33 +08:00
|
|
|
unset($this->lib_name);
|
|
|
|
break;
|
|
|
|
case 'libname':
|
2002-04-10 06:30:44 +08:00
|
|
|
if ($this->in_changelog) {
|
|
|
|
break;
|
|
|
|
}
|
2002-03-28 22:07:33 +08:00
|
|
|
$this->lib_name = $data;
|
2001-12-27 19:10:56 +08:00
|
|
|
break;
|
|
|
|
case 'maintainer':
|
2002-03-28 22:07:33 +08:00
|
|
|
if (empty($this->pkginfo['maintainers'][$this->m_i]['role'])) {
|
|
|
|
$this->pkginfo['maintainers'][$this->m_i]['role'] = 'lead';
|
|
|
|
}
|
2001-12-27 19:10:56 +08:00
|
|
|
$this->m_i++;
|
|
|
|
break;
|
|
|
|
case 'release':
|
|
|
|
if ($this->in_changelog) {
|
|
|
|
$this->c_i++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'changelog':
|
|
|
|
$this->in_changelog = false;
|
|
|
|
break;
|
|
|
|
case 'summary':
|
|
|
|
$this->pkginfo['summary'] = $data;
|
|
|
|
break;
|
2001-07-17 02:01:09 +08:00
|
|
|
}
|
2001-12-27 19:10:56 +08:00
|
|
|
array_pop($this->element_stack);
|
|
|
|
$spos = sizeof($this->element_stack) - 1;
|
|
|
|
$this->current_element = ($spos > 0) ? $this->element_stack[$spos] : '';
|
2002-06-07 18:18:59 +08:00
|
|
|
$this->cdata = '';
|
2001-12-27 19:10:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
2002-03-28 22:07:33 +08:00
|
|
|
// {{{ _pkginfo_cdata_1_0()
|
2001-12-27 19:10:56 +08:00
|
|
|
|
2002-03-28 22:07:33 +08:00
|
|
|
/**
|
|
|
|
* XML parser callback for character data. Used for version 1.0
|
|
|
|
* packages.
|
|
|
|
*
|
2002-04-23 14:28:44 +08:00
|
|
|
* @param resource $xp XML parser resource
|
|
|
|
* @param string $name character data
|
2002-03-28 22:07:33 +08:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
function _pkginfo_cdata_1_0($xp, $data)
|
2001-12-27 19:10:56 +08:00
|
|
|
{
|
2002-03-31 11:16:02 +08:00
|
|
|
if (isset($this->cdata)) {
|
|
|
|
$this->cdata .= $data;
|
|
|
|
}
|
2001-04-22 09:09:14 +08:00
|
|
|
}
|
|
|
|
|
2002-03-28 22:07:33 +08:00
|
|
|
// }}}
|
|
|
|
|
|
|
|
// {{{ infoFromTgzFile()
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns information about a package file. Expects the name of
|
|
|
|
* a gzipped tar file as input.
|
|
|
|
*
|
2002-04-23 14:28:44 +08:00
|
|
|
* @param string $file name of .tgz file
|
2002-03-28 22:07:33 +08:00
|
|
|
*
|
2002-04-23 14:28:44 +08:00
|
|
|
* @return array array with package information
|
2002-03-28 22:07:33 +08:00
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function infoFromTgzFile($file)
|
|
|
|
{
|
|
|
|
if (!@is_file($file)) {
|
2002-05-21 10:31:23 +08:00
|
|
|
return $this->raiseError("tgz :: could not open file \"$file\"");
|
2002-03-28 22:07:33 +08:00
|
|
|
}
|
2002-05-28 05:36:28 +08:00
|
|
|
$tar = new Archive_Tar($file);
|
2002-03-28 22:07:33 +08:00
|
|
|
$content = $tar->listContent();
|
|
|
|
if (!is_array($content)) {
|
2002-05-21 10:31:23 +08:00
|
|
|
return $this->raiseError("tgz :: could not get contents of package \"$file\"");
|
2002-03-28 22:07:33 +08:00
|
|
|
}
|
|
|
|
$xml = null;
|
|
|
|
foreach ($content as $file) {
|
|
|
|
$name = $file['filename'];
|
|
|
|
if ($name == 'package.xml') {
|
|
|
|
$xml = $name;
|
|
|
|
} elseif (ereg('^.*/package.xml$', $name, $match)) {
|
|
|
|
$xml = $match[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$tmpdir = System::mkTemp('-d pear');
|
|
|
|
$this->addTempFile($tmpdir);
|
|
|
|
if (!$xml || !$tar->extractList($xml, $tmpdir)) {
|
|
|
|
return $this->raiseError('tgz :: could not extract the package.xml file');
|
|
|
|
}
|
|
|
|
return $this->infoFromDescriptionFile("$tmpdir/$xml");
|
|
|
|
}
|
|
|
|
|
2001-04-22 15:43:34 +08:00
|
|
|
// }}}
|
|
|
|
// {{{ infoFromDescriptionFile()
|
2001-04-22 09:09:14 +08:00
|
|
|
|
2002-03-28 22:07:33 +08:00
|
|
|
/**
|
|
|
|
* Returns information about a package file. Expects the name of
|
|
|
|
* a package xml file as input.
|
|
|
|
*
|
2002-04-23 14:28:44 +08:00
|
|
|
* @param string $descfile name of package xml file
|
2002-03-28 22:07:33 +08:00
|
|
|
*
|
2002-04-23 14:28:44 +08:00
|
|
|
* @return array array with package information
|
2002-03-28 22:07:33 +08:00
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*
|
|
|
|
*/
|
2001-04-22 15:43:34 +08:00
|
|
|
function infoFromDescriptionFile($descfile)
|
2001-04-22 09:09:14 +08:00
|
|
|
{
|
2001-08-12 00:11:49 +08:00
|
|
|
if (!@is_file($descfile) || !is_readable($descfile) ||
|
2001-07-19 18:32:06 +08:00
|
|
|
(!$fp = @fopen($descfile, 'r'))) {
|
|
|
|
return $this->raiseError("Unable to open $descfile");
|
|
|
|
}
|
2002-03-28 22:07:33 +08:00
|
|
|
|
|
|
|
// read the whole thing so we only get one cdata callback
|
|
|
|
// for each block of cdata
|
|
|
|
$data = fread($fp, filesize($descfile));
|
|
|
|
return $this->infoFromString($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
// {{{ infoFromString()
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns information about a package file. Expects the contents
|
|
|
|
* of a package xml file as input.
|
|
|
|
*
|
2002-04-23 14:28:44 +08:00
|
|
|
* @param string $data name of package xml file
|
2002-03-28 22:07:33 +08:00
|
|
|
*
|
|
|
|
* @return array array with package information
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function infoFromString($data)
|
|
|
|
{
|
2002-06-17 12:49:14 +08:00
|
|
|
require_once('PEAR/Dependency.php');
|
2002-06-17 18:52:21 +08:00
|
|
|
if ($error = PEAR_Dependency::checkExtension('xml')) {
|
2002-06-17 12:49:14 +08:00
|
|
|
return $this->raiseError($error);
|
2002-06-17 18:52:21 +08:00
|
|
|
}
|
2001-07-17 02:01:09 +08:00
|
|
|
$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');
|
2001-10-30 20:29:55 +08:00
|
|
|
xml_parser_set_option($xp, XML_OPTION_CASE_FOLDING, false);
|
2001-07-17 02:01:09 +08:00
|
|
|
|
|
|
|
$this->element_stack = array();
|
|
|
|
$this->pkginfo = array();
|
|
|
|
$this->current_element = false;
|
2002-05-20 09:17:09 +08:00
|
|
|
unset($this->dir_install);
|
2001-08-18 22:40:25 +08:00
|
|
|
$this->pkginfo['filelist'] = array();
|
|
|
|
$this->filelist =& $this->pkginfo['filelist'];
|
2002-03-22 03:12:49 +08:00
|
|
|
$this->dir_names = array();
|
2001-08-18 22:40:25 +08:00
|
|
|
$this->in_changelog = false;
|
2002-06-07 18:18:59 +08:00
|
|
|
$this->d_i = 0;
|
|
|
|
$this->cdata = '';
|
2001-04-22 09:09:14 +08:00
|
|
|
|
2001-08-18 22:40:25 +08:00
|
|
|
if (!xml_parse($xp, $data, 1)) {
|
2002-03-28 22:07:33 +08:00
|
|
|
$code = xml_get_error_code($xp);
|
2001-04-22 09:09:14 +08:00
|
|
|
$msg = sprintf("XML error: %s at line %d",
|
2002-03-28 22:07:33 +08:00
|
|
|
xml_error_string($code),
|
2001-04-22 09:09:14 +08:00
|
|
|
xml_get_current_line_number($xp));
|
|
|
|
xml_parser_free($xp);
|
2002-03-28 22:07:33 +08:00
|
|
|
return $this->raiseError($msg, $code);
|
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) {
|
2001-08-18 22:40:25 +08:00
|
|
|
if (!is_array($v)) {
|
|
|
|
$this->pkginfo[$k] = trim($v);
|
|
|
|
}
|
2001-04-22 15:43:34 +08:00
|
|
|
}
|
2001-04-22 09:09:14 +08:00
|
|
|
return $this->pkginfo;
|
|
|
|
}
|
2001-04-22 15:43:34 +08:00
|
|
|
// }}}
|
2002-03-28 22:07:33 +08:00
|
|
|
// {{{ xmlFromInfo()
|
2001-08-18 22:40:25 +08:00
|
|
|
|
|
|
|
/**
|
2002-03-28 22:07:33 +08:00
|
|
|
* Return an XML document based on the package info (as returned
|
|
|
|
* by the PEAR_Common::infoFrom* methods).
|
|
|
|
*
|
2002-04-23 14:28:44 +08:00
|
|
|
* @param array $pkginfo package info
|
2002-03-28 22:07:33 +08:00
|
|
|
*
|
|
|
|
* @return string XML data
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function xmlFromInfo($pkginfo)
|
2001-08-18 22:40:25 +08:00
|
|
|
{
|
2002-03-28 22:07:33 +08:00
|
|
|
static $maint_map = array(
|
|
|
|
"handle" => "user",
|
|
|
|
"name" => "name",
|
|
|
|
"email" => "email",
|
|
|
|
"role" => "role",
|
|
|
|
);
|
|
|
|
$ret = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n";
|
|
|
|
//$ret .= "<!DOCTYPE package SYSTEM \"http://pear.php.net/package10.dtd\">\n";
|
|
|
|
$ret .= "<package version=\"1.0\">
|
|
|
|
<name>$pkginfo[package]</name>
|
|
|
|
<summary>".htmlspecialchars($pkginfo['summary'])."</summary>
|
|
|
|
<description>".htmlspecialchars($pkginfo['description'])."</description>
|
|
|
|
<maintainers>
|
|
|
|
";
|
|
|
|
foreach ($pkginfo['maintainers'] as $maint) {
|
|
|
|
$ret .= " <maintainer>\n";
|
|
|
|
foreach ($maint_map as $idx => $elm) {
|
|
|
|
$ret .= " <$elm>";
|
|
|
|
$ret .= htmlspecialchars($maint[$idx]);
|
|
|
|
$ret .= "</$elm>\n";
|
|
|
|
}
|
|
|
|
$ret .= " </maintainer>\n";
|
2001-09-28 08:55:16 +08:00
|
|
|
}
|
2002-03-28 22:07:33 +08:00
|
|
|
$ret .= " </maintainers>\n";
|
|
|
|
$ret .= $this->_makeReleaseXml($pkginfo);
|
|
|
|
if (@sizeof($pkginfo['changelog']) > 0) {
|
|
|
|
$ret .= " <changelog>\n";
|
|
|
|
foreach ($pkginfo['changelog'] as $oldrelease) {
|
|
|
|
$ret .= $this->_makeReleaseXml($oldrelease, true);
|
|
|
|
}
|
|
|
|
$ret .= " </changelog>\n";
|
2001-10-08 11:31:14 +08:00
|
|
|
}
|
2002-03-28 22:07:33 +08:00
|
|
|
$ret .= "</package>\n";
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
// {{{ _makeReleaseXml()
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate part of an XML description with release information.
|
|
|
|
*
|
2002-04-23 14:28:44 +08:00
|
|
|
* @param array $pkginfo array with release information
|
|
|
|
* @param bool $changelog whether the result will be in a changelog element
|
2002-03-28 22:07:33 +08:00
|
|
|
*
|
|
|
|
* @return string XML data
|
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
function _makeReleaseXml($pkginfo, $changelog = false)
|
|
|
|
{
|
2002-04-06 08:58:22 +08:00
|
|
|
// XXX QUOTE ENTITIES IN PCDATA, OR EMBED IN CDATA BLOCKS!!
|
2002-03-28 22:07:33 +08:00
|
|
|
$indent = $changelog ? " " : "";
|
|
|
|
$ret = "$indent <release>\n";
|
|
|
|
if (!empty($pkginfo['version'])) {
|
|
|
|
$ret .= "$indent <version>$pkginfo[version]</version>\n";
|
|
|
|
}
|
|
|
|
if (!empty($pkginfo['release_date'])) {
|
|
|
|
$ret .= "$indent <date>$pkginfo[release_date]</date>\n";
|
|
|
|
}
|
|
|
|
if (!empty($pkginfo['release_license'])) {
|
|
|
|
$ret .= "$indent <license>$pkginfo[release_license]</license>\n";
|
|
|
|
}
|
|
|
|
if (!empty($pkginfo['release_state'])) {
|
|
|
|
$ret .= "$indent <state>$pkginfo[release_state]</state>\n";
|
|
|
|
}
|
|
|
|
if (!empty($pkginfo['release_notes'])) {
|
2002-04-06 08:58:22 +08:00
|
|
|
$ret .= "$indent <notes>".htmlspecialchars($pkginfo['release_notes'])."</notes>\n";
|
2002-03-28 22:07:33 +08:00
|
|
|
}
|
2002-11-13 22:17:26 +08:00
|
|
|
if (!empty($pkginfo['release_warnings'])) {
|
|
|
|
$ret .= "$indent <warnings>".htmlspecialchars($pkginfo['release_warnings'])."</warnings>\n";
|
|
|
|
}
|
2002-04-01 03:04:53 +08:00
|
|
|
if (isset($pkginfo['release_deps']) && sizeof($pkginfo['release_deps']) > 0) {
|
2002-03-28 22:07:33 +08:00
|
|
|
$ret .= "$indent <deps>\n";
|
|
|
|
foreach ($pkginfo['release_deps'] as $dep) {
|
|
|
|
$ret .= "$indent <dep type=\"$dep[type]\" rel=\"$dep[rel]\"";
|
|
|
|
if (isset($dep['version'])) {
|
|
|
|
$ret .= " version=\"$dep[version]\"";
|
|
|
|
}
|
|
|
|
if (isset($dep['name'])) {
|
|
|
|
$ret .= ">$dep[name]</dep>\n";
|
|
|
|
} else {
|
|
|
|
$ret .= "/>\n";
|
|
|
|
}
|
2001-12-29 03:27:08 +08:00
|
|
|
}
|
2002-03-28 22:07:33 +08:00
|
|
|
$ret .= "$indent </deps>\n";
|
2001-12-29 03:27:08 +08:00
|
|
|
}
|
2002-05-27 09:20:10 +08:00
|
|
|
if (isset($pkginfo['configure_options'])) {
|
|
|
|
$ret .= "$indent <configureoptions>\n";
|
|
|
|
foreach ($pkginfo['configure_options'] as $c) {
|
|
|
|
$ret .= "$indent <configureoption name=\"".
|
|
|
|
htmlspecialchars($c['name']) . "\"";
|
|
|
|
if (isset($c['default'])) {
|
|
|
|
$ret .= " default=\"" . htmlspecialchars($c['default']) . "\"";
|
|
|
|
}
|
|
|
|
$ret .= " prompt=\"" . htmlspecialchars($c['prompt']) . "\"";
|
|
|
|
$ret .= "/>\n";
|
|
|
|
}
|
|
|
|
$ret .= "$indent </configureoptions>\n";
|
|
|
|
}
|
2002-03-29 07:44:31 +08:00
|
|
|
if (isset($pkginfo['filelist'])) {
|
|
|
|
$ret .= "$indent <filelist>\n";
|
|
|
|
foreach ($pkginfo['filelist'] as $file => $fa) {
|
2002-04-09 16:10:12 +08:00
|
|
|
if (@$fa['role'] == 'extsrc') {
|
2002-03-29 07:44:31 +08:00
|
|
|
$ret .= "$indent <libfile>\n";
|
|
|
|
$ret .= "$indent <libname>$file</libname>\n";
|
|
|
|
$ret .= "$indent <sources>$fa[sources]</sources>\n";
|
|
|
|
$ret .= "$indent </libfile>\n";
|
|
|
|
} else {
|
2002-04-09 16:10:12 +08:00
|
|
|
@$ret .= "$indent <file role=\"$fa[role]\"";
|
2002-03-29 07:44:31 +08:00
|
|
|
if (isset($fa['baseinstalldir'])) {
|
2002-04-09 16:10:12 +08:00
|
|
|
$ret .= ' baseinstalldir="' .
|
|
|
|
htmlspecialchars($fa['baseinstalldir']) . '"';
|
2002-03-29 07:44:31 +08:00
|
|
|
}
|
|
|
|
if (isset($fa['md5sum'])) {
|
|
|
|
$ret .= " md5sum=\"$fa[md5sum]\"";
|
|
|
|
}
|
2002-10-12 08:39:49 +08:00
|
|
|
if (isset($fa['platform'])) {
|
|
|
|
$ret .= " platform=\"$fa[platform]\"";
|
|
|
|
}
|
2002-04-09 16:10:12 +08:00
|
|
|
if (!empty($fa['install-as'])) {
|
|
|
|
$ret .= ' install-as="' .
|
|
|
|
htmlspecialchars($fa['install-as']) . '"';
|
|
|
|
}
|
|
|
|
$ret .= ' name="' . htmlspecialchars($file) . '"';
|
|
|
|
if (empty($fa['replacements'])) {
|
|
|
|
$ret .= "/>\n";
|
|
|
|
} else {
|
|
|
|
$ret .= ">\n";
|
|
|
|
foreach ($fa['replacements'] as $r) {
|
|
|
|
$ret .= "$indent <replace";
|
|
|
|
foreach ($r as $k => $v) {
|
|
|
|
$ret .= " $k=\"" . htmlspecialchars($v) .'"';
|
|
|
|
}
|
|
|
|
$ret .= "/>\n";
|
|
|
|
}
|
|
|
|
@$ret .= "$indent </file>\n";
|
|
|
|
}
|
2002-03-28 22:07:33 +08:00
|
|
|
}
|
|
|
|
}
|
2002-03-29 07:44:31 +08:00
|
|
|
$ret .= "$indent </filelist>\n";
|
2001-12-29 03:27:08 +08:00
|
|
|
}
|
2002-03-28 22:07:33 +08:00
|
|
|
$ret .= "$indent </release>\n";
|
|
|
|
return $ret;
|
|
|
|
}
|
2001-10-30 20:19:36 +08:00
|
|
|
|
2002-04-07 18:38:04 +08:00
|
|
|
// }}}
|
2002-05-20 18:45:23 +08:00
|
|
|
// {{{ infoFromAny()
|
2002-04-07 18:38:04 +08:00
|
|
|
|
2002-08-16 01:07:12 +08:00
|
|
|
/**
|
|
|
|
* Returns package information from different sources
|
|
|
|
*
|
|
|
|
* This method is able to extract information about a package
|
|
|
|
* from a .tgz archive or from a XML package definition file.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param string Filename of the source ('package.xml', '<package>.tgz')
|
|
|
|
* @return string
|
|
|
|
*/
|
2002-05-20 18:45:23 +08:00
|
|
|
function infoFromAny($info)
|
2002-04-07 18:38:04 +08:00
|
|
|
{
|
|
|
|
if (is_string($info) && file_exists($info)) {
|
|
|
|
$tmp = substr($info, -4);
|
|
|
|
if ($tmp == '.xml') {
|
|
|
|
$info = $this->infoFromDescriptionFile($info);
|
|
|
|
} elseif ($tmp == '.tar' || $tmp == '.tgz') {
|
|
|
|
$info = $this->infoFromTgzFile($info);
|
|
|
|
} else {
|
2002-05-21 09:20:51 +08:00
|
|
|
$fp = fopen($info, "r");
|
2002-04-07 18:38:04 +08:00
|
|
|
$test = fread($fp, 5);
|
|
|
|
fclose($fp);
|
|
|
|
if ($test == "<?xml") {
|
2002-05-21 09:20:51 +08:00
|
|
|
$info = $this->infoFromDescriptionFile($info);
|
2002-04-07 18:38:04 +08:00
|
|
|
} else {
|
2002-05-21 09:20:51 +08:00
|
|
|
$info = $this->infoFromTgzFile($info);
|
2002-04-07 18:38:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (PEAR::isError($info)) {
|
|
|
|
return $this->raiseError($info);
|
|
|
|
}
|
|
|
|
}
|
2002-04-16 21:27:42 +08:00
|
|
|
return $info;
|
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
// {{{ validatePackageInfo()
|
|
|
|
|
2002-08-16 01:07:12 +08:00
|
|
|
/**
|
|
|
|
* Validate XML package definition file.
|
|
|
|
*
|
|
|
|
* @param string Filename of the package archive or of the package definition file
|
|
|
|
* @param array Array that will contain the errors
|
|
|
|
* @param array Array that will contain the warnings
|
|
|
|
* @access public
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2002-04-16 21:27:42 +08:00
|
|
|
function validatePackageInfo($info, &$errors, &$warnings)
|
|
|
|
{
|
2002-04-24 07:36:54 +08:00
|
|
|
global $_PEAR_Common_maintainer_roles,
|
2002-06-20 07:38:59 +08:00
|
|
|
$_PEAR_Common_release_states,
|
|
|
|
$_PEAR_Common_dependency_types,
|
|
|
|
$_PEAR_Common_dependency_relations,
|
|
|
|
$_PEAR_Common_file_roles,
|
|
|
|
$_PEAR_Common_replacement_types;
|
2002-05-20 18:45:23 +08:00
|
|
|
if (PEAR::isError($info = $this->infoFromAny($info))) {
|
2002-04-16 21:27:42 +08:00
|
|
|
return $this->raiseError($info);
|
|
|
|
}
|
2002-04-07 18:38:04 +08:00
|
|
|
if (!is_array($info)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$errors = array();
|
|
|
|
$warnings = array();
|
|
|
|
if (empty($info['package'])) {
|
|
|
|
$errors[] = 'missing package name';
|
|
|
|
}
|
|
|
|
if (empty($info['summary'])) {
|
|
|
|
$errors[] = 'missing summary';
|
|
|
|
} elseif (strpos(trim($info['summary']), "\n") !== false) {
|
|
|
|
$warnings[] = 'summary should be on a single line';
|
|
|
|
}
|
|
|
|
if (empty($info['description'])) {
|
|
|
|
$errors[] = 'missing description';
|
|
|
|
}
|
|
|
|
if (empty($info['release_license'])) {
|
|
|
|
$errors[] = 'missing license';
|
|
|
|
}
|
|
|
|
if (empty($info['version'])) {
|
|
|
|
$errors[] = 'missing version';
|
|
|
|
}
|
|
|
|
if (empty($info['release_state'])) {
|
|
|
|
$errors[] = 'missing release state';
|
2002-04-24 07:36:54 +08:00
|
|
|
} elseif (!in_array($info['release_state'], $_PEAR_Common_release_states)) {
|
|
|
|
$errors[] = "invalid release state `$info[release_state]', should be one of: ".implode(' ', $_PEAR_Common_release_states);
|
2002-04-07 18:38:04 +08:00
|
|
|
}
|
|
|
|
if (empty($info['release_date'])) {
|
|
|
|
$errors[] = 'missing release date';
|
|
|
|
} elseif (!preg_match('/^\d{4}-\d\d-\d\d$/', $info['release_date'])) {
|
|
|
|
$errors[] = "invalid release date `$info[release_date]', format is YYYY-MM-DD";
|
|
|
|
}
|
|
|
|
if (empty($info['release_notes'])) {
|
|
|
|
$errors[] = "missing release notes";
|
|
|
|
}
|
|
|
|
if (empty($info['maintainers'])) {
|
|
|
|
$errors[] = 'no maintainer(s)';
|
|
|
|
} else {
|
|
|
|
$i = 1;
|
|
|
|
foreach ($info['maintainers'] as $m) {
|
|
|
|
if (empty($m['handle'])) {
|
|
|
|
$errors[] = "maintainer $i: missing handle";
|
|
|
|
}
|
|
|
|
if (empty($m['role'])) {
|
|
|
|
$errors[] = "maintainer $i: missing role";
|
2002-04-24 07:36:54 +08:00
|
|
|
} elseif (!in_array($m['role'], $_PEAR_Common_maintainer_roles)) {
|
|
|
|
$errors[] = "maintainer $i: invalid role `$m[role]', should be one of: ".implode(' ', $_PEAR_Common_maintainer_roles);
|
2002-04-07 18:38:04 +08:00
|
|
|
}
|
|
|
|
if (empty($m['name'])) {
|
|
|
|
$errors[] = "maintainer $i: missing name";
|
|
|
|
}
|
|
|
|
if (empty($m['email'])) {
|
|
|
|
$errors[] = "maintainer $i: missing email";
|
|
|
|
}
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!empty($info['deps'])) {
|
|
|
|
$i = 1;
|
|
|
|
foreach ($info['deps'] as $d) {
|
|
|
|
if (empty($d['type'])) {
|
|
|
|
$errors[] = "depenency $i: missing type";
|
2002-04-24 07:36:54 +08:00
|
|
|
} elseif (!in_array($d['type'], $_PEAR_Common_dependency_types)) {
|
|
|
|
$errors[] = "dependency $i: invalid type, should be one of: ".implode(' ', $_PEAR_Common_depenency_types);
|
2002-04-07 18:38:04 +08:00
|
|
|
}
|
|
|
|
if (empty($d['rel'])) {
|
|
|
|
$errors[] = "dependency $i: missing relation";
|
2002-04-24 07:36:54 +08:00
|
|
|
} elseif (!in_array($d['rel'], $_PEAR_Common_dependency_relations)) {
|
|
|
|
$errors[] = "dependency $i: invalid relation, should be one of: ".implode(' ', $_PEAR_Common_dependency_relations);
|
2002-04-07 18:38:04 +08:00
|
|
|
}
|
|
|
|
if ($d['rel'] != 'has' && empty($d['version'])) {
|
|
|
|
$warnings[] = "dependency $i: missing version";
|
|
|
|
} elseif ($d['rel'] == 'has' && !empty($d['version'])) {
|
|
|
|
$warnings[] = "dependency $i: version ignored for `has' dependencies";
|
|
|
|
}
|
|
|
|
if ($d['type'] == 'php' && !empty($d['name'])) {
|
|
|
|
$warnings[] = "dependency $i: name ignored for php type dependencies";
|
|
|
|
} elseif ($d['type'] != 'php' && empty($d['name'])) {
|
|
|
|
$errors[] = "dependency $i: missing name";
|
|
|
|
}
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
}
|
2002-05-27 09:20:10 +08:00
|
|
|
if (!empty($info['configure_options'])) {
|
|
|
|
$i = 1;
|
|
|
|
foreach ($info['configure_options'] as $c) {
|
|
|
|
if (empty($c['name'])) {
|
|
|
|
$errors[] = "configure option $i: missing name";
|
|
|
|
}
|
|
|
|
if (empty($c['prompt'])) {
|
|
|
|
$errors[] = "configure option $i: missing prompt";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-04-07 18:38:04 +08:00
|
|
|
if (empty($info['filelist'])) {
|
|
|
|
$errors[] = 'no files';
|
|
|
|
} else {
|
|
|
|
foreach ($info['filelist'] as $file => $fa) {
|
|
|
|
if (empty($fa['role'])) {
|
2002-04-13 08:20:40 +08:00
|
|
|
$errors[] = "file $file: missing role";
|
2002-04-24 07:36:54 +08:00
|
|
|
} elseif (!in_array($fa['role'], $_PEAR_Common_file_roles)) {
|
|
|
|
$errors[] = "file $file: invalid role, should be one of: ".implode(' ', $_PEAR_Common_file_roles);
|
2002-04-07 18:38:04 +08:00
|
|
|
} elseif ($fa['role'] == 'extsrc' && empty($fa['sources'])) {
|
2002-04-13 08:20:40 +08:00
|
|
|
$errors[] = "file $file: no source files";
|
2002-04-07 18:38:04 +08:00
|
|
|
}
|
2002-04-08 04:47:04 +08:00
|
|
|
// (ssb) Any checks we can do for baseinstalldir?
|
|
|
|
// (cox) Perhaps checks that either the target dir and baseInstall
|
|
|
|
// doesn't cointain "../../"
|
2002-04-07 18:38:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2001-10-30 20:19:36 +08:00
|
|
|
// }}}
|
2002-04-16 21:27:42 +08:00
|
|
|
// {{{ analyzeSourceCode()
|
|
|
|
|
2002-08-16 01:07:12 +08:00
|
|
|
/**
|
|
|
|
* Analyze the source code of the given PHP file
|
|
|
|
*
|
|
|
|
* @param string Filename of the PHP file
|
|
|
|
* @return mixed
|
|
|
|
* @access public
|
|
|
|
*/
|
2002-04-16 21:27:42 +08:00
|
|
|
function analyzeSourceCode($file)
|
|
|
|
{
|
|
|
|
if (!function_exists("token_get_all")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!$fp = @fopen($file, "r")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$contents = fread($fp, filesize($file));
|
|
|
|
$tokens = token_get_all($contents);
|
2002-05-26 20:51:32 +08:00
|
|
|
/*
|
2002-04-16 21:27:42 +08:00
|
|
|
for ($i = 0; $i < sizeof($tokens); $i++) {
|
|
|
|
list($token, $data) = $tokens[$i];
|
|
|
|
if (is_string($token)) {
|
|
|
|
var_dump($token);
|
|
|
|
} else {
|
|
|
|
print token_name($token) . ' ';
|
|
|
|
var_dump(rtrim($data));
|
|
|
|
}
|
|
|
|
}
|
2002-05-26 20:51:32 +08:00
|
|
|
*/
|
2002-04-16 21:27:42 +08:00
|
|
|
$look_for = 0;
|
|
|
|
$paren_level = 0;
|
|
|
|
$bracket_level = 0;
|
|
|
|
$brace_level = 0;
|
|
|
|
$lastphpdoc = '';
|
|
|
|
$current_class = '';
|
|
|
|
$current_class_level = -1;
|
|
|
|
$current_function = '';
|
|
|
|
$current_function_level = -1;
|
|
|
|
$declared_classes = array();
|
|
|
|
$declared_functions = array();
|
|
|
|
$declared_methods = array();
|
|
|
|
$used_classes = array();
|
|
|
|
$used_functions = array();
|
2002-05-26 20:51:32 +08:00
|
|
|
$nodeps = array();
|
2002-04-16 21:27:42 +08:00
|
|
|
for ($i = 0; $i < sizeof($tokens); $i++) {
|
|
|
|
list($token, $data) = $tokens[$i];
|
|
|
|
switch ($token) {
|
2002-05-26 20:51:32 +08:00
|
|
|
case '{': $brace_level++; continue 2;
|
2002-04-16 21:27:42 +08:00
|
|
|
case '}':
|
|
|
|
$brace_level--;
|
|
|
|
if ($current_class_level == $brace_level) {
|
|
|
|
$current_class = '';
|
|
|
|
$current_class_level = -1;
|
|
|
|
}
|
|
|
|
if ($current_function_level == $brace_level) {
|
|
|
|
$current_function = '';
|
|
|
|
$current_function_level = -1;
|
|
|
|
}
|
|
|
|
continue 2;
|
|
|
|
case '[': $bracket_level++; continue 2;
|
|
|
|
case ']': $bracket_level--; continue 2;
|
|
|
|
case '(': $paren_level++; continue 2;
|
|
|
|
case ')': $paren_level--; continue 2;
|
|
|
|
case T_CLASS:
|
|
|
|
case T_FUNCTION:
|
|
|
|
case T_NEW:
|
|
|
|
$look_for = $token;
|
|
|
|
continue 2;
|
|
|
|
case T_STRING:
|
|
|
|
if ($look_for == T_CLASS) {
|
|
|
|
$current_class = $data;
|
|
|
|
$current_class_level = $brace_level;
|
|
|
|
$declared_classes[] = $current_class;
|
|
|
|
} elseif ($look_for == T_FUNCTION) {
|
|
|
|
if ($current_class) {
|
|
|
|
$current_function = "$current_class::$data";
|
|
|
|
$declared_methods[$current_class][] = $data;
|
|
|
|
} else {
|
|
|
|
$current_function = $data;
|
2002-05-26 20:51:32 +08:00
|
|
|
$declared_functions[] = $current_function;
|
2002-04-16 21:27:42 +08:00
|
|
|
}
|
|
|
|
$current_function_level = $brace_level;
|
2002-05-26 20:51:32 +08:00
|
|
|
$m = array();
|
2002-04-16 21:27:42 +08:00
|
|
|
} elseif ($look_for == T_NEW) {
|
|
|
|
$used_classes[$data] = true;
|
|
|
|
}
|
|
|
|
$look_for = 0;
|
|
|
|
continue 2;
|
2002-05-26 20:51:32 +08:00
|
|
|
case T_VARIABLE:
|
|
|
|
$look_for = 0;
|
|
|
|
continue 2;
|
2002-04-16 21:27:42 +08:00
|
|
|
case T_COMMENT:
|
|
|
|
if (preg_match('!^/\*\*\s!', $data)) {
|
|
|
|
$lastphpdoc = $data;
|
2002-05-26 20:51:32 +08:00
|
|
|
if (preg_match_all('/@nodep\s+(\S+)/', $lastphpdoc, $m)) {
|
|
|
|
$nodeps = array_merge($nodeps, $m[1]);
|
|
|
|
}
|
2002-04-16 21:27:42 +08:00
|
|
|
}
|
|
|
|
continue 2;
|
|
|
|
case T_DOUBLE_COLON:
|
2002-05-26 20:51:32 +08:00
|
|
|
$class = $tokens[$i - 1][1];
|
|
|
|
if (strtolower($class) != 'parent') {
|
|
|
|
$used_classes[$class] = true;
|
|
|
|
}
|
2002-04-16 21:27:42 +08:00
|
|
|
continue 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return array(
|
|
|
|
"declared_classes" => $declared_classes,
|
|
|
|
"declared_methods" => $declared_methods,
|
|
|
|
"declared_functions" => $declared_functions,
|
2002-05-26 20:51:32 +08:00
|
|
|
"used_classes" => array_diff(array_keys($used_classes), $nodeps),
|
2002-04-16 21:27:42 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
// {{{ detectDependencies()
|
|
|
|
|
2002-04-23 14:28:44 +08:00
|
|
|
function detectDependencies($any, $status_callback = null)
|
2002-04-16 21:27:42 +08:00
|
|
|
{
|
|
|
|
if (!function_exists("token_get_all")) {
|
|
|
|
return false;
|
|
|
|
}
|
2002-05-20 18:45:23 +08:00
|
|
|
if (PEAR::isError($info = $this->infoFromAny($any))) {
|
2002-04-16 21:27:42 +08:00
|
|
|
return $this->raiseError($info);
|
|
|
|
}
|
|
|
|
if (!is_array($info)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$deps = array();
|
2002-05-26 20:51:32 +08:00
|
|
|
$used_c = $decl_c = $decl_f = $decl_m = array();
|
2002-04-16 21:27:42 +08:00
|
|
|
foreach ($info['filelist'] as $file => $fa) {
|
2002-04-23 14:28:44 +08:00
|
|
|
$tmp = $this->analyzeSourceCode($file);
|
|
|
|
$used_c = @array_merge($used_c, $tmp['used_classes']);
|
|
|
|
$decl_c = @array_merge($decl_c, $tmp['declared_classes']);
|
2002-05-26 20:51:32 +08:00
|
|
|
$decl_f = @array_merge($decl_f, $tmp['declared_functions']);
|
|
|
|
$decl_m = @array_merge($decl_m, $tmp['declared_methods']);
|
2002-04-16 21:27:42 +08:00
|
|
|
}
|
2002-04-23 14:28:44 +08:00
|
|
|
$used_c = array_unique($used_c);
|
|
|
|
$decl_c = array_unique($decl_c);
|
|
|
|
$undecl_c = array_diff($used_c, $decl_c);
|
|
|
|
return array('used_classes' => $used_c,
|
|
|
|
'declared_classes' => $decl_c,
|
2002-05-26 20:51:32 +08:00
|
|
|
'declared_methods' => $decl_m,
|
|
|
|
'declared_functions' => $decl_f,
|
|
|
|
'undeclared_classes' => $undecl_c,
|
|
|
|
);
|
2002-04-16 21:27:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
// {{{ getUserRoles()
|
|
|
|
|
2002-04-08 04:47:04 +08:00
|
|
|
/**
|
2002-04-16 21:27:42 +08:00
|
|
|
* Get the valid roles for a PEAR package maintainer
|
|
|
|
*
|
2002-04-23 14:28:44 +08:00
|
|
|
* @return array
|
2002-04-16 21:27:42 +08:00
|
|
|
* @static
|
|
|
|
*/
|
2002-04-08 04:47:04 +08:00
|
|
|
function getUserRoles()
|
|
|
|
{
|
2002-04-23 14:28:44 +08:00
|
|
|
return $GLOBALS['_PEAR_Common_maintainer_roles'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
// {{{ getReleaseStates()
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the valid package release states of packages
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
function getReleaseStates()
|
|
|
|
{
|
|
|
|
return $GLOBALS['_PEAR_Common_release_states'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
// {{{ getDependencyTypes()
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the implemented dependency types (php, ext, pkg etc.)
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
function getDependencyTypes()
|
|
|
|
{
|
|
|
|
return $GLOBALS['_PEAR_Common_dependency_types'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
// {{{ getDependencyRelations()
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the implemented dependency relations (has, lt, ge etc.)
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
function getDependencyRelations()
|
|
|
|
{
|
|
|
|
return $GLOBALS['_PEAR_Common_dependency_relations'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
// {{{ getFileRoles()
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the implemented file roles
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
function getFileRoles()
|
|
|
|
{
|
|
|
|
return $GLOBALS['_PEAR_Common_file_roles'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
// {{{ getReplacementTypes()
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the implemented file replacement types in
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
function getReplacementTypes()
|
|
|
|
{
|
|
|
|
return $GLOBALS['_PEAR_Common_replacement_types'];
|
|
|
|
}
|
|
|
|
|
2002-04-28 15:52:00 +08:00
|
|
|
// }}}
|
2002-06-13 05:23:22 +08:00
|
|
|
// {{{ getProvideTypes()
|
2002-04-28 15:52:00 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the implemented file replacement types in
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
function getProvideTypes()
|
|
|
|
{
|
|
|
|
return $GLOBALS['_PEAR_Common_provide_types'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
2002-06-13 05:23:22 +08:00
|
|
|
// {{{ getScriptPhases()
|
2002-04-28 15:52:00 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the implemented file replacement types in
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
function getScriptPhases()
|
|
|
|
{
|
|
|
|
return $GLOBALS['_PEAR_Common_script_phases'];
|
|
|
|
}
|
|
|
|
|
2002-04-29 14:23:05 +08:00
|
|
|
// }}}
|
|
|
|
// {{{ validPackageName()
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test whether a string contains a valid package name.
|
|
|
|
*
|
|
|
|
* @param string $name the package name to test
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function validPackageName($name)
|
|
|
|
{
|
2002-06-06 18:16:42 +08:00
|
|
|
return (bool)preg_match(PEAR_COMMON_PACKAGE_NAME_PREG, $name);
|
2002-04-29 14:23:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-04-23 14:28:44 +08:00
|
|
|
// }}}
|
|
|
|
|
|
|
|
// {{{ downloadHttp()
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Download a file through HTTP. Considers suggested file name in
|
|
|
|
* Content-disposition: header and can run a callback function for
|
|
|
|
* different events. The callback will be called with two
|
|
|
|
* parameters: the callback type, and parameters. The implemented
|
|
|
|
* callback types are:
|
|
|
|
*
|
2002-04-29 14:23:05 +08:00
|
|
|
* 'setup' called at the very beginning, parameter is a UI object
|
|
|
|
* that should be used for all output
|
|
|
|
* 'message' the parameter is a string with an informational message
|
|
|
|
* 'saveas' may be used to save with a different file name, the
|
|
|
|
* parameter is the filename that is about to be used.
|
|
|
|
* If a 'saveas' callback returns a non-empty string,
|
|
|
|
* that file name will be used as the filename instead.
|
|
|
|
* Note that $save_dir will not be affected by this, only
|
|
|
|
* the basename of the file.
|
|
|
|
* 'start' download is starting, parameter is number of bytes
|
|
|
|
* that are expected, or -1 if unknown
|
|
|
|
* 'bytesread' parameter is the number of bytes read so far
|
|
|
|
* 'done' download is complete, parameter is the total number
|
|
|
|
* of bytes read
|
|
|
|
* 'connfailed' if the TCP connection fails, this callback is called
|
|
|
|
* with array(host,port,errno,errmsg)
|
|
|
|
* 'writefailed' if writing to disk fails, this callback is called
|
|
|
|
* with array(destfile,errmsg)
|
2002-04-23 14:28:44 +08:00
|
|
|
*
|
|
|
|
* If an HTTP proxy has been configured (http_proxy PEAR_Config
|
|
|
|
* setting), the proxy will be used.
|
|
|
|
*
|
|
|
|
* @param string $url the URL to download
|
|
|
|
* @param object $ui PEAR_Frontend_* instance
|
|
|
|
* @param object $config PEAR_Config instance
|
2002-04-23 14:49:10 +08:00
|
|
|
* @param string $save_dir (optional) directory to save file in
|
|
|
|
* @param mixed $callback (optional) function/method to call for status
|
2002-04-23 14:28:44 +08:00
|
|
|
* updates
|
|
|
|
*
|
|
|
|
* @return string Returns the full path of the downloaded file or a PEAR
|
|
|
|
* error on failure. If the error is caused by
|
|
|
|
* socket-related errors, the error object will
|
|
|
|
* have the fsockopen error code available through
|
|
|
|
* getCode().
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
2002-04-29 14:23:05 +08:00
|
|
|
function downloadHttp($url, &$ui, $save_dir = '.', $callback = null)
|
2002-04-23 14:28:44 +08:00
|
|
|
{
|
2002-04-29 14:23:05 +08:00
|
|
|
if ($callback) {
|
|
|
|
call_user_func($callback, 'setup', array(&$ui));
|
|
|
|
}
|
2002-04-23 14:28:44 +08:00
|
|
|
if (preg_match('!^http://([^/:?#]*)(:(\d+))?(/.*)!', $url, $matches)) {
|
|
|
|
list(,$host,,$port,$path) = $matches;
|
|
|
|
}
|
2002-04-29 14:23:05 +08:00
|
|
|
if (isset($this)) {
|
|
|
|
$config = &$this->config;
|
|
|
|
} else {
|
|
|
|
$config = &PEAR_Config::singleton();
|
|
|
|
}
|
2002-10-03 05:27:25 +08:00
|
|
|
$proxy_host = $proxy_port = $proxy_user = $proxy_pass = '';
|
|
|
|
if ($proxy = parse_url($config->get('http_proxy'))) {
|
|
|
|
$proxy_host = @$proxy['host'];
|
|
|
|
$proxy_port = @$proxy['port'];
|
|
|
|
$proxy_user = @$proxy['user'];
|
|
|
|
$proxy_pass = @$proxy['pass'];
|
|
|
|
|
|
|
|
if ($proxy_port == '') {
|
2002-04-23 14:28:44 +08:00
|
|
|
$proxy_port = 8080;
|
|
|
|
}
|
|
|
|
if ($callback) {
|
|
|
|
call_user_func($callback, 'message', "Using HTTP proxy $host:$port");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (empty($port)) {
|
|
|
|
$port = 80;
|
|
|
|
}
|
2002-10-03 05:27:25 +08:00
|
|
|
if ($proxy_host != '') {
|
2002-04-23 14:28:44 +08:00
|
|
|
$fp = @fsockopen($proxy_host, $proxy_port, $errno, $errstr);
|
|
|
|
if (!$fp) {
|
2002-04-29 14:23:05 +08:00
|
|
|
if ($callback) {
|
|
|
|
call_user_func($callback, 'connfailed', array($proxy_host, $proxy_port,
|
|
|
|
$errno, $errstr));
|
|
|
|
}
|
2002-04-23 14:28:44 +08:00
|
|
|
return PEAR::raiseError("Connection to `$proxy_host:$proxy_port' failed: $errstr", $errno);
|
|
|
|
}
|
|
|
|
$request = "GET $url HTTP/1.0\r\n";
|
|
|
|
} else {
|
|
|
|
$fp = @fsockopen($host, $port, $errno, $errstr);
|
|
|
|
if (!$fp) {
|
2002-04-29 14:23:05 +08:00
|
|
|
if ($callback) {
|
|
|
|
call_user_func($callback, 'connfailed', array($host, $port,
|
|
|
|
$errno, $errstr));
|
|
|
|
}
|
2002-04-23 14:28:44 +08:00
|
|
|
return PEAR::raiseError("Connection to `$host:$port' failed: $errstr", $errno);
|
2002-08-16 01:07:12 +08:00
|
|
|
}
|
2002-04-23 14:28:44 +08:00
|
|
|
$request = "GET $path HTTP/1.0\r\n";
|
|
|
|
}
|
|
|
|
$request .= "Host: $host:$port\r\n".
|
2002-10-03 05:27:25 +08:00
|
|
|
"User-Agent: PHP/".PHP_VERSION."\r\n";
|
|
|
|
if ($proxy_host != '' && $proxy_user != '') {
|
|
|
|
$request .= 'Proxy-Authorization: Basic ' .
|
|
|
|
base64_encode($proxy_user . ':' . $proxy_pass) . "\r\n";
|
|
|
|
}
|
|
|
|
$request .= "\r\n";
|
2002-04-23 14:28:44 +08:00
|
|
|
fwrite($fp, $request);
|
|
|
|
$headers = array();
|
|
|
|
while (trim($line = fgets($fp, 1024))) {
|
|
|
|
if (preg_match('/^([^:]+):\s+(.*)\s*$/', $line, $matches)) {
|
|
|
|
$headers[strtolower($matches[1])] = trim($matches[2]);
|
2002-05-15 19:23:01 +08:00
|
|
|
} elseif (preg_match('|^HTTP/1.[01] ([0-9]{3}) |', $line, $matches)) {
|
|
|
|
if ($matches[1] != 200) {
|
|
|
|
return PEAR::raiseError("File http://$host:$port$path not valid (received: $line)");
|
|
|
|
}
|
2002-04-23 14:28:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isset($headers['content-disposition']) &&
|
|
|
|
preg_match('/\sfilename=\"([^;]*\S)\"\s*(;|$)/', $headers['content-disposition'], $matches)) {
|
|
|
|
$save_as = basename($matches[1]);
|
|
|
|
} else {
|
|
|
|
$save_as = basename($url);
|
|
|
|
}
|
|
|
|
if ($callback) {
|
2002-04-29 14:23:05 +08:00
|
|
|
$tmp = call_user_func($callback, 'saveas', $save_as);
|
2002-04-23 14:28:44 +08:00
|
|
|
if ($tmp) {
|
|
|
|
$save_as = $tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$dest_file = $save_dir . DIRECTORY_SEPARATOR . $save_as;
|
|
|
|
if (!$wp = @fopen($dest_file, 'wb')) {
|
|
|
|
fclose($fp);
|
2002-04-29 14:23:05 +08:00
|
|
|
if ($callback) {
|
|
|
|
call_user_func($callback, 'writefailed', array($dest_file, $php_errormsg));
|
|
|
|
}
|
2002-04-23 14:28:44 +08:00
|
|
|
return PEAR::raiseError("could not open $dest_file for writing");
|
|
|
|
}
|
|
|
|
if (isset($headers['content-length'])) {
|
|
|
|
$length = $headers['content-length'];
|
|
|
|
} else {
|
|
|
|
$length = -1;
|
|
|
|
}
|
|
|
|
$bytes = 0;
|
|
|
|
if ($callback) {
|
|
|
|
call_user_func($callback, 'start', $length);
|
|
|
|
}
|
|
|
|
while ($data = @fread($fp, 1024)) {
|
|
|
|
$bytes += strlen($data);
|
|
|
|
if ($callback) {
|
|
|
|
call_user_func($callback, 'bytesread', $bytes);
|
|
|
|
}
|
|
|
|
if (!@fwrite($wp, $data)) {
|
|
|
|
fclose($fp);
|
2002-04-29 14:23:05 +08:00
|
|
|
if ($callback) {
|
|
|
|
call_user_func($callback, 'writefailed', array($dest_file, $php_errormsg));
|
|
|
|
}
|
|
|
|
return PEAR::raiseError("$dest_file: write failed ($php_errormsg)");
|
2002-04-23 14:28:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose($fp);
|
|
|
|
fclose($wp);
|
|
|
|
if ($callback) {
|
2002-04-23 14:49:10 +08:00
|
|
|
call_user_func($callback, 'done', $bytes);
|
2002-04-23 14:28:44 +08:00
|
|
|
}
|
|
|
|
return $dest_file;
|
2002-04-08 04:47:04 +08:00
|
|
|
}
|
2002-04-16 21:27:42 +08:00
|
|
|
|
|
|
|
// }}}
|
2001-04-22 09:09:14 +08:00
|
|
|
}
|
2002-04-23 14:28:44 +08:00
|
|
|
|
|
|
|
?>
|