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

📄 channelfile.php

📁 php-4.4.7学习linux时下载的源代码
💻 PHP
📖 第 1 页 / 共 4 页
字号:
        } else {            $data = fread($fp, filesize($descfile));            fclose($fp);        }        return $this->fromXmlString($data);    }    /**     * Parse channel information from different sources     *     * This method is able to extract information about a channel     * from an .xml file or a string     *     * @access public     * @param  string Filename of the source or the source itself     * @return bool     */    function fromAny($info)    {        if (is_string($info) && file_exists($info) && strlen($info) < 255) {            $tmp = substr($info, -4);            if ($tmp == '.xml') {                $info = $this->fromXmlFile($info);            } else {                $fp = fopen($info, "r");                $test = fread($fp, 5);                fclose($fp);                if ($test == "<?xml") {                    $info = $this->fromXmlFile($info);                }            }            if (PEAR::isError($info)) {                require_once 'PEAR.php';                return PEAR::raiseError($info);            }        }        if (is_string($info)) {            $info = $this->fromXmlString($info);        }        return $info;    }    /**     * Return an XML document based on previous parsing and modifications     *     * @return string XML data     *     * @access public     */    function toXml()    {        if (!$this->_isValid && !$this->validate()) {            $this->_validateError(PEAR_CHANNELFILE_ERROR_INVALID);            return false;        }        if (!isset($this->_channelInfo['attribs']['version'])) {            $this->_channelInfo['attribs']['version'] = '1.0';        }        $channelInfo = $this->_channelInfo;        $ret = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n";        $ret .= "<channel version=\"" .            $channelInfo['attribs']['version'] . "\" xmlns=\"http://pear.php.net/channel-1.0\"  xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"  xsi:schemaLocation=\"http://pear.php.net/dtd/channel-"            . $channelInfo['attribs']['version'] . " http://pear.php.net/dtd/channel-" .            $channelInfo['attribs']['version'] . ".xsd\"> <name>$channelInfo[name]</name> <summary>" . htmlspecialchars($channelInfo['summary'])."</summary>";        if (isset($channelInfo['suggestedalias'])) {            $ret .= ' <suggestedalias>' . $channelInfo['suggestedalias'] . "</suggestedalias>\n";        }        if (isset($channelInfo['validatepackage'])) {            $ret .= ' <validatepackage version="' .                $channelInfo['validatepackage']['attribs']['version']. '">' .                htmlspecialchars($channelInfo['validatepackage']['_content']) .                "</validatepackage>\n";        }        $ret .= " <servers>\n";        $ret .= '  <primary';        if (isset($channelInfo['servers']['primary']['attribs']['ssl'])) {            $ret .= ' ssl="' . $channelInfo['servers']['primary']['attribs']['ssl'] . '"';        }        if (isset($channelInfo['servers']['primary']['attribs']['port'])) {            $ret .= ' port="' . $channelInfo['servers']['primary']['attribs']['port'] . '"';        }        $ret .= ">\n";        if (isset($channelInfo['servers']['primary']['xmlrpc'])) {            $ret .= $this->_makeXmlrpcXml($channelInfo['servers']['primary']['xmlrpc'], '   ');        }        if (isset($channelInfo['servers']['primary']['rest'])) {            $ret .= $this->_makeRestXml($channelInfo['servers']['primary']['rest'], '   ');        }        if (isset($channelInfo['servers']['primary']['soap'])) {            $ret .= $this->_makeSoapXml($channelInfo['servers']['primary']['soap'], '   ');        }        $ret .= "  </primary>\n";        if (isset($channelInfo['servers']['mirror'])) {            $ret .= $this->_makeMirrorsXml($channelInfo);        }        $ret .= " </servers>\n";        $ret .= "</channel>";        return str_replace("\r", "\n", str_replace("\r\n", "\n", $ret));    }    /**     * Generate the <xmlrpc> tag     * @access private     */    function _makeXmlrpcXml($info, $indent)    {        $ret = $indent . "<xmlrpc";        if (isset($info['attribs']['path'])) {            $ret .= ' path="' . htmlspecialchars($info['attribs']['path']) . '"';        }        $ret .= ">\n";        $ret .= $this->_makeFunctionsXml($info['function'], "$indent ");        $ret .= $indent . "</xmlrpc>\n";        return $ret;    }    /**     * Generate the <soap> tag     * @access private     */    function _makeSoapXml($info, $indent)    {        $ret = $indent . "<soap";        if (isset($info['attribs']['path'])) {            $ret .= ' path="' . htmlspecialchars($info['attribs']['path']) . '"';        }        $ret .= ">\n";        $ret .= $this->_makeFunctionsXml($info['function'], "$indent ");        $ret .= $indent . "</soap>\n";        return $ret;    }    /**     * Generate the <rest> tag     * @access private     */    function _makeRestXml($info, $indent)    {        $ret = $indent . "<rest>\n";        if (!isset($info['baseurl'][0])) {            $info['baseurl'] = array($info['baseurl']);        }        foreach ($info['baseurl'] as $url) {            $ret .= "$indent <baseurl type=\"" . $url['attribs']['type'] . "\"";            $ret .= ">" . $url['_content'] . "</baseurl>\n";        }        $ret .= $indent . "</rest>\n";        return $ret;    }    /**     * Generate the <mirrors> tag     * @access private     */    function _makeMirrorsXml($channelInfo)    {        $ret = "";        if (!isset($channelInfo['servers']['mirror'][0])) {            $channelInfo['servers']['mirror'] = array($channelInfo['servers']['mirror']);        }        foreach ($channelInfo['servers']['mirror'] as $mirror) {            $ret .= '  <mirror host="' . $mirror['attribs']['host'] . '"';            if (isset($mirror['attribs']['port'])) {                $ret .= ' port="' . $mirror['attribs']['port'] . '"';            }            if (isset($mirror['attribs']['ssl'])) {                $ret .= ' ssl="' . $mirror['attribs']['ssl'] . '"';            }            $ret .= ">\n";            if (isset($mirror['xmlrpc']) || isset($mirror['soap'])) {                if (isset($mirror['xmlrpc'])) {                    $ret .= $this->_makeXmlrpcXml($mirror['xmlrpc'], '   ');                }                if (isset($mirror['rest'])) {                    $ret .= $this->_makeRestXml($mirror['rest'], '   ');                }                if (isset($mirror['soap'])) {                    $ret .= $this->_makeSoapXml($mirror['soap'], '   ');                }                $ret .= "  </mirror>\n";            } else {                $ret .= "/>\n";            }        }        return $ret;    }    /**     * Generate the <functions> tag     * @access private     */    function _makeFunctionsXml($functions, $indent, $rest = false)    {        $ret = '';        if (!isset($functions[0])) {            $functions = array($functions);        }        foreach ($functions as $function) {            $ret .= "$indent<function version=\"" . $function['attribs']['version'] . "\"";            if ($rest) {                $ret .= ' uri="' . $function['attribs']['uri'] . '"';            }            $ret .= ">" . $function['_content'] . "</function>\n";        }        return $ret;    }    /**     * Validation error.  Also marks the object contents as invalid     * @param error code     * @param array error information     * @access private     */    function _validateError($code, $params = array())    {        $this->_stack->push($code, 'error', $params);        $this->_isValid = false;    }    /**     * Validation warning.  Does not mark the object contents invalid.     * @param error code     * @param array error information     * @access private     */    function _validateWarning($code, $params = array())    {        $this->_stack->push($code, 'warning', $params);    }    /**     * Validate parsed file.     *     * @access public     * @return boolean     */    function validate()    {        $this->_isValid = true;        $info = $this->_channelInfo;        if (empty($info['name'])) {            $this->_validateError(PEAR_CHANNELFILE_ERROR_NO_NAME);        } elseif (!$this->validChannelServer($info['name'])) {            if ($info['name'] != '__uri') {                $this->_validateError(PEAR_CHANNELFILE_ERROR_INVALID_NAME, array('tag' => 'name',                    'name' => $info['name']));            }        }        if (empty($info['summary'])) {            $this->_validateError(PEAR_CHANNELFILE_ERROR_NO_SUMMARY);        } elseif (strpos(trim($info['summary']), "\n") !== false) {            $this->_validateWarning(PEAR_CHANNELFILE_ERROR_MULTILINE_SUMMARY,                array('summary' => $info['summary']));        }        if (isset($info['suggestedalias'])) {            if (!$this->validChannelServer($info['suggestedalias'])) {                $this->_validateError(PEAR_CHANNELFILE_ERROR_INVALID_NAME,                    array('tag' => 'suggestedalias', 'name' =>$info['suggestedalias']));            }        }        if (isset($info['localalias'])) {            if (!$this->validChannelServer($info['localalias'])) {                $this->_validateError(PEAR_CHANNELFILE_ERROR_INVALID_NAME,                    array('tag' => 'localalias', 'name' =>$info['localalias']));            }        }        if (isset($info['validatepackage'])) {            if (!isset($info['validatepackage']['_content'])) {                $this->_validateError(PEAR_CHANNELFILE_ERROR_NOVALIDATE_NAME);            }            if (!isset($info['validatepackage']['attribs']['version'])) {                $this->_validateError(PEAR_CHANNELFILE_ERROR_NOVALIDATE_VERSION,                    array('package' => @$info['validatepackage']['_content']));            }        }        if (isset($info['servers']['primary']['attribs']['port']) &&              !is_numeric($info['servers']['primary']['attribs']['port'])) {            $this->_validateError(PEAR_CHANNELFILE_ERROR_INVALID_PORT,                array('port' => $info['servers']['primary']['attribs']['port']));        }        if (isset($info['servers']['primary']['attribs']['ssl']) &&              $info['servers']['primary']['attribs']['ssl'] != 'yes') {            $this->_validateError(PEAR_CHANNELFILE_ERROR_INVALID_SSL,                array('ssl' => $info['servers']['primary']['attribs']['ssl'],                    'server' => $info['name']));        }        if (isset($info['servers']['primary']['xmlrpc']) &&              isset($info['servers']['primary']['xmlrpc']['function'])) {            $this->_validateFunctions('xmlrpc', $info['servers']['primary']['xmlrpc']['function']);        }        if (isset($info['servers']['primary']['soap']) &&              isset($info['servers']['primary']['soap']['function'])) {            $this->_validateFunctions('soap', $info['servers']['primary']['soap']['function']);        }        if (isset($info['servers']['primary']['rest']) &&              isset($info['servers']['primary']['rest']['baseurl'])) {            $this->_validateFunctions('rest', $info['servers']['primary']['rest']['baseurl']);        }        if (isset($info['servers']['mirror'])) {            if ($this->_channelInfo['name'] == '__uri') {                $this->_validateError(PEAR_CHANNELFILE_URI_CANT_MIRROR);            }            if (!isset($info['servers']['mirror'][0])) {                $info['servers']['mirror'] = array($info['servers']['mirror']);            }            $i = 0;            foreach ($info['servers']['mirror'] as $mirror) {                if (!isset($mirror['attribs']['host'])) {                    $this->_validateError(PEAR_CHANNELFILE_ERROR_NO_HOST,                      array('type' => 'mirror'));                } elseif (!$this->validChannelServer($mirror['attribs']['host'])) {                    $this->_validateError(PEAR_CHANNELFILE_ERROR_INVALID_HOST,                        array('server' => $mirror['attribs']['host'], 'type' => 'mirror'));                }                if (isset($mirror['attribs']['ssl']) && $mirror['attribs']['ssl'] != 'yes') {                    $this->_validateError(PEAR_CHANNELFILE_ERROR_INVALID_SSL,                        array('ssl' => $info['ssl'], 'server' => $mirror['attribs']['host']));                }                if (isset($mirror['xmlrpc'])) {                    $this->_validateFunctions('xmlrpc',                        $mirror['xmlrpc']['function'], $mirror['attribs']['host']);                }                if (isset($mirror['soap'])) {                    $this->_validateFunctions('soap', $mirror['soap']['function'],                        $mirror['attribs']['host']);                }                if (isset($mirror['rest'])) {                    $this->_validateFunctions('rest', $mirror['rest']['baseurl'],                        $mirror['attribs']['host']);                }            }        }        return $this->_isValid;    }    /**     * @param string xmlrpc or soap - protocol name this function applies to     * @param array the functions     * @param string the name of the parent element (mirror name, for instance)     */    function _validateFunctions($protocol, $functions, $parent = '')    {        if (!isset($functions[0])) {            $functions = array($functions);        }        foreach ($functions as $function) {            if (!isset($function['_content']) || empty($function['_content'])) {                $this->_validateError(PEAR_CHANNELFILE_ERROR_NO_FUNCTIONNAME,                    array('parent' => $parent, 'protocol' => $protocol));            }            if ($protocol == 'rest') {                if (!isset($function['attribs']['type']) ||                      empty($function['attribs']['type'])) {                    $this->_validateError(PEAR_CHANNELFILE_ERROR_NO_BASEURLTYPE,                        array('parent' => $parent, 'protocol' => $protocol));                }            } else {                if (!isset($function['attribs']['version']) ||                      empty($function['attribs']['version'])) {                    $this->_validateError(PEAR_CHANNELFILE_ERROR_NO_FUNCTIONVERSION,                        array('parent' => $parent, 'protocol' => $protocol));                }            }        }    }    /**     * Test whether a string contains a valid channel server.     * @param string $ver the package version to test     * @return bool     */    function validChannelServer($server)    {        if ($server == '__uri') {            return true;        }        return (bool) preg_match(PEAR_CHANNELS_SERVER_PREG, $server);    }    /**     * @return string|false     */    function getName()    {        if (isset($this->_channelInfo['name'])) {            return $this->_channelInfo['name'];        } else {            return false;        }    }    /**     * @return string|false     */    function getServer()    {        if (isset($this->_channelInfo['name'])) {            return $this->_channelInfo['name'];

⌨️ 快捷键说明

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