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

📄 downloader.php

📁 FP2 CRM code+Mysql DB
💻 PHP
📖 第 1 页 / 共 2 页
字号:
     * @param array a mixed list of package names, local files, or package.xml     */    function doDownload($packages)    {        $mywillinstall = array();        $state = $this->_preferredState;        // {{{ download files in this list if necessary        foreach($packages as $pkgfile) {            $need_download = false;            if (!is_file($pkgfile)) {                if (preg_match('#^(http|ftp)://#', $pkgfile)) {                    $need_download = true;                }                $pkgfile = $this->_downloadNonFile($pkgfile);                if (PEAR::isError($pkgfile)) {                    return $pkgfile;                }                if ($pkgfile === false) {                    continue;                }            } // end is_file()            $tempinfo = $this->infoFromAny($pkgfile);            if ($need_download) {                $this->_toDownload[] = $tempinfo['package'];            }            if (isset($this->_options['alldeps']) || isset($this->_options['onlyreqdeps'])) {                // ignore dependencies if there are any errors                if (!PEAR::isError($tempinfo)) {                    $mywillinstall[strtolower($tempinfo['package'])] = @$tempinfo['release_deps'];                }            }            $this->_downloadedPackages[] = array('pkg' => $tempinfo['package'],                                       'file' => $pkgfile, 'info' => $tempinfo);        } // end foreach($packages)        // }}}        // {{{ extract dependencies from downloaded files and then download        // them if necessary        if (isset($this->_options['alldeps']) || isset($this->_options['onlyreqdeps'])) {            $deppackages = array();            foreach ($mywillinstall as $package => $alldeps) {                if (!is_array($alldeps)) {                    // there are no dependencies                    continue;                }                foreach($alldeps as $info) {                    if ($info['type'] != 'pkg') {                        continue;                    }                    $ret = $this->_processDependency($package, $info, $mywillinstall);                    if ($ret === false) {                        continue;                    }                    if (PEAR::isError($ret)) {                        return $ret;                    }                    $deppackages[] = $ret;                } // foreach($alldeps            }            if (count($deppackages)) {                $this->doDownload($deppackages);            }        } // }}} if --alldeps or --onlyreqdeps    }    // }}}    // {{{ _downloadNonFile($pkgfile)        /**     * @return false|PEAR_Error|string false if loop should be broken out of,     *                                 string if the file was downloaded,     *                                 PEAR_Error on exception     * @access private     */    function _downloadNonFile($pkgfile)    {        $origpkgfile = $pkgfile;        $state = null;        $pkgfile = $this->extractDownloadFileName($pkgfile, $version);        if (preg_match('#^(http|ftp)://#', $pkgfile)) {            return $this->_downloadFile($pkgfile, $version, $origpkgfile);        }        if (!$this->validPackageName($pkgfile)) {            return $this->raiseError("Package name '$pkgfile' not valid");        }        // ignore packages that are installed unless we are upgrading        $curinfo = $this->_registry->packageInfo($pkgfile);        if ($this->_registry->packageExists($pkgfile)              && empty($this->_options['upgrade']) && empty($this->_options['force'])) {            $this->log(0, "Package '{$curinfo['package']}' already installed, skipping");            return false;        }        if (in_array($pkgfile, $this->_toDownload)) {            return false;        }        $releases = $this->_remote->call('package.info', $pkgfile, 'releases', true);        if (!count($releases)) {            return $this->raiseError("No releases found for package '$pkgfile'");        }        // Want a specific version/state        if ($version !== null) {            // Passed Foo-1.2            if ($this->validPackageVersion($version)) {                if (!isset($releases[$version])) {                    return $this->raiseError("No release with version '$version' found for '$pkgfile'");                }            // Passed Foo-alpha            } elseif (in_array($version, $this->getReleaseStates())) {                $state = $version;                $version = 0;                foreach ($releases as $ver => $inf) {                    if ($inf['state'] == $state && version_compare("$version", "$ver") < 0) {                        $version = $ver;                        break;                    }                }                if ($version == 0) {                    return $this->raiseError("No release with state '$state' found for '$pkgfile'");                }            // invalid postfix passed            } else {                return $this->raiseError("Invalid postfix '-$version', be sure to pass a valid PEAR ".                                         "version number or release state");            }        // Guess what to download        } else {            $states = $this->betterStates($this->_preferredState, true);            $possible = false;            $version = 0;            foreach ($releases as $ver => $inf) {                if (in_array($inf['state'], $states) && version_compare("$version", "$ver") < 0) {                    $version = $ver;                    break;                }            }            if ($version === 0 && !isset($this->_options['force'])) {                return $this->raiseError('No release with state equal to: \'' . implode(', ', $states) .                                         "' found for '$pkgfile'");            } elseif ($version === 0) {                $this->log(0, "Warning: $pkgfile is state '$inf[state]' which is less stable " .                              "than state '$this->_preferredState'");            }        }        // Check if we haven't already the version        if (empty($this->_options['force']) && !is_null($curinfo)) {            if ($curinfo['version'] == $version) {                $this->log(0, "Package '{$curinfo['package']}-{$curinfo['version']}' already installed, skipping");                return false;            } elseif (version_compare("$version", "{$curinfo['version']}") < 0) {                $this->log(0, "Package '{$curinfo['package']}' version '{$curinfo['version']}' " .                              " is installed and {$curinfo['version']} is > requested '$version', skipping");                return false;            }        }        $this->_toDownload[] = $pkgfile;        return $this->_downloadFile($pkgfile, $version, $origpkgfile, $state);    }        // }}}    // {{{ _processDependency($package, $info, $mywillinstall)        /**     * Process a dependency, download if necessary     * @param array dependency information from PEAR_Remote call     * @param array packages that will be installed in this iteration     * @return false|string|PEAR_Error     * @access private     * @todo Add test for relation 'lt'/'le' -> make sure that the dependency requested is     *       in fact lower than the required value.  This will be very important for BC dependencies     */    function _processDependency($package, $info, $mywillinstall)    {        $state = $this->_preferredState;        if (!isset($this->_options['alldeps']) && isset($info['optional']) &&              $info['optional'] == 'yes') {            // skip optional deps            $this->log(0, "skipping Package '$package' optional dependency '$info[name]'");            return false;        }        // {{{ get releases        $releases = $this->_remote->call('package.info', $info['name'], 'releases', true);        if (PEAR::isError($releases)) {            return $releases;        }        if (!count($releases)) {            if (!isset($this->_installed[strtolower($info['name'])])) {                $this->pushError("Package '$package' dependency '$info[name]' ".                            "has no releases");            }            return false;        }        $found = false;        $save = $releases;        while(count($releases) && !$found) {            if (!empty($state) && $state != 'any') {                list($release_version, $release) = each($releases);                if ($state != $release['state'] &&                    !in_array($release['state'], $this->betterStates($state)))                {                    // drop this release - it ain't stable enough                    array_shift($releases);                } else {                    $found = true;                }            } else {                $found = true;            }        }        if (!count($releases) && !$found) {            $get = array();            foreach($save as $release) {                $get = array_merge($get,                    $this->betterStates($release['state'], true));            }            $savestate = array_shift($get);            $this->pushError( "Release for '$package' dependency '$info[name]' " .                "has state '$savestate', requires '$state'");            return false;        }        if (in_array(strtolower($info['name']), $this->_toDownload) ||              isset($mywillinstall[strtolower($info['name'])])) {            // skip upgrade check for packages we will install            return false;        }        if (!isset($this->_installed[strtolower($info['name'])])) {            // check to see if we can install the specific version required            if ($info['rel'] == 'eq') {                return $info['name'] . '-' . $info['version'];            }            // skip upgrade check for packages we don't have installed            return $info['name'];        }        // }}}        // {{{ see if a dependency must be upgraded        $inst_version = $this->_registry->packageInfo($info['name'], 'version');        if (!isset($info['version'])) {            // this is a rel='has' dependency, check against latest            if (version_compare($release_version, $inst_version, 'le')) {                return false;            } else {                return $info['name'];            }        }        if (version_compare($info['version'], $inst_version, 'le')) {            // installed version is up-to-date            return false;        }        return $info['name'];    }        // }}}    // {{{ _downloadCallback()    function _downloadCallback($msg, $params = null)    {        switch ($msg) {            case 'saveas':                $this->log(1, "downloading $params ...");                break;            case 'done':                $this->log(1, '...done: ' . number_format($params, 0, '', ',') . ' bytes');                break;            case 'bytesread':                static $bytes;                if (empty($bytes)) {                    $bytes = 0;                }                if (!($bytes % 10240)) {                    $this->log(1, '.', false);                }                $bytes += $params;                break;            case 'start':                $this->log(1, "Starting to download {$params[0]} (".number_format($params[1], 0, '', ',')." bytes)");                break;        }        if (method_exists($this->ui, '_downloadCallback'))            $this->ui->_downloadCallback($msg, $params);    }    // }}}    // {{{ _prependPath($path, $prepend)    function _prependPath($path, $prepend)    {        if (strlen($prepend) > 0) {            if (OS_WINDOWS && preg_match('/^[a-z]:/i', $path)) {                $path = $prepend . substr($path, 2);            } else {                $path = $prepend . $path;            }        }        return $path;    }    // }}}    // {{{ pushError($errmsg, $code)        /**     * @param string     * @param integer     */    function pushError($errmsg, $code = -1)    {        array_push($this->_errorStack, array($errmsg, $code));    }        // }}}    // {{{ getErrorMsgs()        function getErrorMsgs()    {        $msgs = array();        $errs = $this->_errorStack;        foreach ($errs as $err) {            $msgs[] = $err[0];        }        $this->_errorStack = array();        return $msgs;    }        // }}}}// }}}?>

⌨️ 快捷键说明

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