⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 downloader.php

📁 FP2 CRM code+Mysql DB
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php//// +----------------------------------------------------------------------+// | PHP Version 5                                                        |// +----------------------------------------------------------------------+// | Copyright (c) 1997-2004 The PHP Group                                |// +----------------------------------------------------------------------+// | This source file is subject to version 3.0 of the PHP license,       |// | that is bundled with this package in the file LICENSE, and is        |// | available through the world-wide-web at the following url:           |// | http://www.php.net/license/3_0.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@php.net>                                   |// |          Tomas V.V.Cox <cox@idecnet.com>                             |// |          Martin Jansen <mj@php.net>                                  |// +----------------------------------------------------------------------+//// $Id: Downloader.php,v 1.14 2004/02/29 15:58:17 avsm Exp $require_once 'PEAR/Common.php';require_once 'PEAR/Registry.php';require_once 'PEAR/Dependency.php';require_once 'PEAR/Remote.php';require_once 'System.php';/** * Administration class used to download PEAR packages and maintain the * installed package database. * * @since PEAR 1.4 * @author Greg Beaver <cellog@php.net> */class PEAR_Downloader extends PEAR_Common{    /**     * @var PEAR_Config     * @access private     */    var $_config;    /**     * @var PEAR_Registry     * @access private     */    var $_registry;    /**     * @var PEAR_Remote     * @access private     */    var $_remote;    /**     * Preferred Installation State (snapshot, devel, alpha, beta, stable)     * @var string|null     * @access private     */    var $_preferredState;    /**     * Options from command-line passed to Install.     *      * Recognized options:<br />     *  - onlyreqdeps   : install all required dependencies as well     *  - alldeps       : install all dependencies, including optional     *  - installroot   : base relative path to install files in     *  - force         : force a download even if warnings would prevent it     * @see PEAR_Command_Install     * @access private     * @var array     */    var $_options;    /**     * Downloaded Packages after a call to download().     *      * Format of each entry:     *     * <code>     * array('pkg' => 'package_name', 'file' => '/path/to/local/file',     *    'info' => array() // parsed package.xml     * );     * </code>     * @access private     * @var array     */    var $_downloadedPackages = array();    /**     * Packages slated for download.     *      * This is used to prevent downloading a package more than once should it be a dependency     * for two packages to be installed.     * Format of each entry:     *     * <pre>     * array('package_name1' => parsed package.xml, 'package_name2' => parsed package.xml,     * );     * </pre>     * @access private     * @var array     */    var $_toDownload = array();        /**     * Array of every package installed, with names lower-cased.     *      * Format:     * <code>     * array('package1' => 0, 'package2' => 1, );     * </code>     * @var array     */    var $_installed = array();        /**     * @var array     * @access private     */    var $_errorStack = array();    // {{{ PEAR_Downloader()        function PEAR_Downloader(&$ui, $options, &$config)    {        $this->_options = $options;        $this->_config = &$config;        $this->_preferredState = $this->_config->get('preferred_state');        $this->ui = &$ui;        if (!$this->_preferredState) {            // don't inadvertantly use a non-set preferred_state            $this->_preferredState = null;        }        $php_dir = $this->_config->get('php_dir');        if (isset($this->_options['installroot'])) {            if (substr($this->_options['installroot'], -1) == DIRECTORY_SEPARATOR) {                $this->_options['installroot'] = substr($this->_options['installroot'], 0, -1);            }            $php_dir = $this->_prependPath($php_dir, $this->_options['installroot']);        }        $this->_registry = &new PEAR_Registry($php_dir);        $this->_remote = &new PEAR_Remote($config);        if (isset($this->_options['alldeps']) || isset($this->_options['onlyreqdeps'])) {            $this->_installed = $this->_registry->listPackages();            array_walk($this->_installed, create_function('&$v,$k','$v = strtolower($v);'));            $this->_installed = array_flip($this->_installed);        }        parent::PEAR_Common();    }        // }}}    // {{{ configSet()    function configSet($key, $value, $layer = 'user')    {        $this->_config->set($key, $value, $layer);        $this->_preferredState = $this->_config->get('preferred_state');        if (!$this->_preferredState) {            // don't inadvertantly use a non-set preferred_state            $this->_preferredState = null;        }    }        // }}}    // {{{ setOptions()    function setOptions($options)    {        $this->_options = $options;    }        // }}}    // {{{ _downloadFile()    /**     * @param string filename to download     * @param string version/state     * @param string original value passed to command-line     * @param string|null preferred state (snapshot/devel/alpha/beta/stable)     *                    Defaults to configuration preferred state     * @return null|PEAR_Error|string     * @access private     */    function _downloadFile($pkgfile, $version, $origpkgfile, $state = null)    {        if (is_null($state)) {            $state = $this->_preferredState;        }        // {{{ check the package filename, and whether it's already installed        $need_download = false;        if (preg_match('#^(http|ftp)://#', $pkgfile)) {            $need_download = true;        } elseif (!@is_file($pkgfile)) {            if ($this->validPackageName($pkgfile)) {                if ($this->_registry->packageExists($pkgfile)) {                    if (empty($this->_options['upgrade']) && empty($this->_options['force'])) {                        $errors[] = "$pkgfile already installed";                        return;                    }                }                $pkgfile = $this->getPackageDownloadUrl($pkgfile, $version);                $need_download = true;            } else {                if (strlen($pkgfile)) {                    $errors[] = "Could not open the package file: $pkgfile";                } else {                    $errors[] = "No package file given";                }                return;            }        }        // }}}        // {{{ Download package -----------------------------------------------        if ($need_download) {            $downloaddir = $this->_config->get('download_dir');            if (empty($downloaddir)) {                if (PEAR::isError($downloaddir = System::mktemp('-d'))) {                    return $downloaddir;                }                $this->log(3, '+ tmp dir created at ' . $downloaddir);            }            $callback = $this->ui ? array(&$this, '_downloadCallback') : null;            $this->pushErrorHandling(PEAR_ERROR_RETURN);            $file = $this->downloadHttp($pkgfile, $this->ui, $downloaddir, $callback);            $this->popErrorHandling();            if (PEAR::isError($file)) {                if ($this->validPackageName($origpkgfile)) {                    if (!PEAR::isError($info = $this->_remote->call('package.info',                          $origpkgfile))) {                        if (!count($info['releases'])) {                            return $this->raiseError('Package ' . $origpkgfile .                            ' has no releases');                        } else {                            return $this->raiseError('No releases of preferred state "'                            . $state . '" exist for package ' . $origpkgfile .                            '.  Use ' . $origpkgfile . '-state to install another' .                            ' state (like ' . $origpkgfile .'-beta)',                            PEAR_INSTALLER_ERROR_NO_PREF_STATE);                        }                    } else {                        return $pkgfile;                    }                } else {                    return $this->raiseError($file);                }            }            $pkgfile = $file;        }        // }}}        return $pkgfile;    }    // }}}    // {{{ getPackageDownloadUrl()    function getPackageDownloadUrl($package, $version = null)    {        if ($version) {            $package .= "-$version";        }        if ($this === null || $this->_config === null) {            $package = "http://pear.php.net/get/$package";        } else {            $package = "http://" . $this->_config->get('master_server') .                "/get/$package";        }        if (!extension_loaded("zlib")) {            $package .= '?uncompress=yes';        }        return $package;    }    // }}}    // {{{ extractDownloadFileName($pkgfile, &$version)    function extractDownloadFileName($pkgfile, &$version)    {        if (@is_file($pkgfile)) {            return $pkgfile;        }        // regex defined in Common.php        if (preg_match(PEAR_COMMON_PACKAGE_DOWNLOAD_PREG, $pkgfile, $m)) {            $version = (isset($m[3])) ? $m[3] : null;            return $m[1];        }        $version = null;        return $pkgfile;    }    // }}}    // }}}    // {{{ getDownloadedPackages()    /**     * Retrieve a list of downloaded packages after a call to {@link download()}.     *      * Also resets the list of downloaded packages.     * @return array     */    function getDownloadedPackages()    {        $ret = $this->_downloadedPackages;        $this->_downloadedPackages = array();        $this->_toDownload = array();        return $ret;    }    // }}}    // {{{ download()    /**     * Download any files and their dependencies, if necessary     *     * BC-compatible method name     * @param array a mixed list of package names, local files, or package.xml     */    function download($packages)    {        return $this->doDownload($packages);    }        // }}}    // {{{ doDownload()    /**     * Download any files and their dependencies, if necessary     *

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -