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

📄 v2.php

📁 php-4.4.7学习linux时下载的源代码
💻 PHP
📖 第 1 页 / 共 4 页
字号:
        $this->_deFormat($dirs);        return $dirs;    }    function _addDir(&$dirs, $dir, $file = null, $attributes = null, $tasks = null)    {        if (!$tasks) {            $tasks = array();        }        if ($dir == array() || $dir == array('.')) {            $dirs['file'][basename($file)] = $tasks;            $attributes['name'] = basename($file);            $dirs['file'][basename($file)]['attribs'] = $attributes;            return;        }        $curdir = array_shift($dir);        if (!isset($dirs['dir'][$curdir])) {            $dirs['dir'][$curdir] = array();        }        $this->_addDir($dirs['dir'][$curdir], $dir, $file, $attributes, $tasks);    }    function _formatDir(&$dirs)    {        if (!count($dirs)) {            return array();        }        $newdirs = array();        if (isset($dirs['dir'])) {            $newdirs['dir'] = $dirs['dir'];        }        if (isset($dirs['file'])) {            $newdirs['file'] = $dirs['file'];        }        $dirs = $newdirs;        if (isset($dirs['dir'])) {            uksort($dirs['dir'], 'strnatcasecmp');            foreach ($dirs['dir'] as $dir => $contents) {                $this->_formatDir($dirs['dir'][$dir]);            }        }        if (isset($dirs['file'])) {            uksort($dirs['file'], 'strnatcasecmp');        };    }    function _deFormat(&$dirs)    {        if (!count($dirs)) {            return array();        }        $newdirs = array();        if (isset($dirs['dir'])) {            foreach ($dirs['dir'] as $dir => $contents) {                $newdir = array();                $newdir['attribs']['name'] = $dir;                $this->_deFormat($contents);                foreach ($contents as $tag => $val) {                    $newdir[$tag] = $val;                }                $newdirs['dir'][] = $newdir;            }            if (count($newdirs['dir']) == 1) {                $newdirs['dir'] = $newdirs['dir'][0];            }        }        if (isset($dirs['file'])) {            foreach ($dirs['file'] as $name => $file) {                $newdirs['file'][] = $file;            }            if (count($newdirs['file']) == 1) {                $newdirs['file'] = $newdirs['file'][0];            }        }        $dirs = $newdirs;    }    /**    * reset all options to default options    *    * @access   public    * @see      setOption(), XML_Unserializer()    */    function resetOptions()    {        $this->options = $this->_defaultOptions;    }   /**    * set an option    *    * You can use this method if you do not want to set all options in the constructor    *    * @access   public    * @see      resetOption(), XML_Serializer()    */    function setOption($name, $value)    {        $this->options[$name] = $value;    }       /**    * sets several options at once    *    * You can use this method if you do not want to set all options in the constructor    *    * @access   public    * @see      resetOption(), XML_Unserializer(), setOption()    */    function setOptions($options)    {        $this->options = array_merge($this->options, $options);    }   /**    * serialize data    *    * @access   public    * @param    mixed    $data data to serialize    * @return   boolean  true on success, pear error on failure    */    function serialize($data, $options = null)    {        // if options have been specified, use them instead        // of the previously defined ones        if (is_array($options)) {            $optionsBak = $this->options;            if (isset($options['overrideOptions']) && $options['overrideOptions'] == true) {                $this->options = array_merge($this->_defaultOptions, $options);            } else {                $this->options = array_merge($this->options, $options);            }        }        else {            $optionsBak = null;        }                //  start depth is zero        $this->_tagDepth = 0;        $this->_serializedData = '';        // serialize an array        if (is_array($data)) {            if (isset($this->options['rootName'])) {                $tagName = $this->options['rootName'];            } else {                $tagName = 'array';            }            $this->_serializedData .= $this->_serializeArray($data, $tagName, $this->options['rootAttributes']);        }                // add doctype declaration        if ($this->options['addDoctype'] === true) {            $this->_serializedData = XML_Util::getDoctypeDeclaration($tagName, $this->options['doctype'])                                   . $this->options['linebreak']                                   . $this->_serializedData;        }        //  build xml declaration        if ($this->options['addDecl']) {            $atts = array();            if (isset($this->options['encoding']) ) {                $encoding = $this->options['encoding'];            } else {                $encoding = null;            }            $this->_serializedData = XML_Util::getXMLDeclaration('1.0', $encoding)                                   . $this->options['linebreak']                                   . $this->_serializedData;        }                		if ($optionsBak !== null) {			$this->options = $optionsBak;		}		        return  true;    }   /**    * get the result of the serialization    *    * @access public    * @return string serialized XML    */    function getSerializedData()    {        if ($this->_serializedData == null ) {            return  $this->raiseError('No serialized data available. Use XML_Serializer::serialize() first.', XML_SERIALIZER_ERROR_NO_SERIALIZATION);        }        return $this->_serializedData;    }       /**    * serialize any value    *    * This method checks for the type of the value and calls the appropriate method    *    * @access private    * @param  mixed     $value    * @param  string    $tagName    * @param  array     $attributes    * @return string    */    function _serializeValue($value, $tagName = null, $attributes = array())    {        if (is_array($value)) {            $xml = $this->_serializeArray($value, $tagName, $attributes);        } elseif (is_object($value)) {            $xml = $this->_serializeObject($value, $tagName);        } else {            $tag = array(                          'qname'      => $tagName,                          'attributes' => $attributes,                          'content'    => $value                        );            $xml = $this->_createXMLTag($tag);        }        return $xml;    }       /**    * serialize an array    *    * @access   private    * @param    array   $array       array to serialize    * @param    string  $tagName     name of the root tag    * @param    array   $attributes  attributes for the root tag    * @return   string  $string      serialized data    * @uses     XML_Util::isValidName() to check, whether key has to be substituted    */    function _serializeArray(&$array, $tagName = null, $attributes = array())    {        $_content = null;                /**         * check for special attributes         */        if ($this->options['attributesArray'] !== null) {            if (isset($array[$this->options['attributesArray']])) {                $attributes = $array[$this->options['attributesArray']];                unset($array[$this->options['attributesArray']]);            }            /**             * check for special content             */            if ($this->options['contentName'] !== null) {                if (isset($array[$this->options['contentName']])) {                    $_content = $array[$this->options['contentName']];                    unset($array[$this->options['contentName']]);                }            }        }        /*        * if mode is set to simpleXML, check whether        * the array is associative or indexed        */        if (is_array($array) && $this->options['mode'] == 'simplexml') {            $indexed = true;            if (!count($array)) {                $indexed = false;            }            foreach ($array as $key => $val) {                if (!is_int($key)) {                    $indexed = false;                    break;                }            }            if ($indexed && $this->options['mode'] == 'simplexml') {                $string = '';                foreach ($array as $key => $val) {                    if ($this->options['beautifyFilelist'] && $tagName == 'dir') {                        if (!isset($this->_curdir)) {                            $this->_curdir = '';                        }                        $savedir = $this->_curdir;                        if (isset($val['attribs'])) {                            if ($val['attribs']['name'] == '/') {                                $this->_curdir = '/';                            } else {                                if ($this->_curdir == '/') {                                    $this->_curdir = '';                                }                                $this->_curdir .= '/' . $val['attribs']['name'];                            }                        }                    }                    $string .= $this->_serializeValue( $val, $tagName, $attributes);                    if ($this->options['beautifyFilelist'] && $tagName == 'dir') {                        $string .= ' <!-- ' . $this->_curdir . ' -->';                        if (empty($savedir)) {                            unset($this->_curdir);                        } else {                            $this->_curdir = $savedir;                        }                    }                                        $string .= $this->options['linebreak'];        			//	do indentation                    if ($this->options['indent']!==null && $this->_tagDepth>0) {                        $string .= str_repeat($this->options['indent'], $this->_tagDepth);                    }                }                return rtrim($string);            }        }        		if ($this->options['scalarAsAttributes'] === true) {	        foreach ($array as $key => $value) {				if (is_scalar($value) && (XML_Util::isValidName($key) === true)) {					unset($array[$key]);					$attributes[$this->options['prependAttributes'].$key] = $value;				}			}		}        // check for empty array => create empty tag        if (empty($array)) {            $tag = array(                            'qname'      => $tagName,                            'content'    => $_content,                            'attributes' => $attributes                        );        } else {            $this->_tagDepth++;            $tmp = $this->options['linebreak'];            foreach ($array as $key => $value) {    			//	do indentation                if ($this->options['indent']!==null && $this->_tagDepth>0) {                    $tmp .= str_repeat($this->options['indent'], $this->_tagDepth);                }        			//	copy key    			$origKey	=	$key;    			//	key cannot be used as tagname => use default tag                $valid = XML_Util::isValidName($key);    	        if (PEAR::isError($valid)) {    	            if ($this->options['classAsTagName'] && is_object($value)) {    	                $key = get_class($value);    	            } else {            	        $key = $this->options['defaultTagName'];    	            }           	 	}                $atts = array();                if ($this->options['typeHints'] === true) {                    $atts[$this->options['typeAttribute']] = gettype($value);    				if ($key !== $origKey) {    					$atts[$this->options['keyAttribute']] = (string)$origKey;    				}                    }                if ($this->options['beautifyFilelist'] && $key == 'dir') {                    if (!isset($this->_curdir)) {                        $this->_curdir = '';                    }                    $savedir = $this->_curdir;                    if (isset($value['attribs'])) {                        if ($value['attribs']['name'] == '/') {                            $this->_curdir = '/';                        } else {                            $this->_curdir .= '/' . $value['attribs']['name'];                        }                    }                }                if (is_string($value) && $value && ($value{strlen($value) - 1} == "\n")) {                    $value .= str_repeat($this->options['indent'], $this->_tagDepth);                }                $tmp .= $this->_createXMLTag(array(                                                    'qname'      => $key,                                                    'attributes' => $atts,                                                    'content'    => $value )                                            );                if ($this->options['beautifyFilelist'] && $key == 'dir') {                    if (isset($value['attribs'])) {                        $tmp .= ' <!-- ' . $this->_curdir . ' -->';                        if (empty($savedir)) {                            unset($this->_curdir);                        } else {                            $this->_curdir = $savedir;                        }

⌨️ 快捷键说明

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