file.php

来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· PHP 代码 · 共 422 行 · 第 1/2 页

PHP
422
字号
<?php
//
// +------------------------------------------------------------------------+
// | PEAR :: Package File Manager                                           |
// +------------------------------------------------------------------------+
// | Copyright (c) 2003-2004 Gregory Beaver                                 |
// | Email         cellog@phpdoc.org                                        |
// +------------------------------------------------------------------------+
// | This source file is subject to version 3.00 of the PHP License,        |
// | that is available at 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.                 |
// +------------------------------------------------------------------------+
// | Portions of this code based on phpDocumentor                           |
// | Web           http://www.phpdoc.org                                    |
// | Mirror        http://phpdocu.sourceforge.net/                          |
// +------------------------------------------------------------------------+
// $Id: File.php,v 1.21 2005/03/28 06:37:35 cellog Exp $
//
/**
 * Retrieve the files from a directory listing
 * @package PEAR_PackageFileManager
 */
/**
 * Retrieve the files from a directory listing
 *
 * This class is used to retrieve a raw directory
 * listing.  Use the {@link PEAR_PackageFileManager_CVS}
 * class to only retrieve the contents of a cvs
 * repository when generating the package.xml
 * @package PEAR_PackageFileManager
 */
class PEAR_PackageFileManager_File {
    /**
     * @var array
     * @access private
     */
    var $_options = 
            array(
                 );

    /**
     * @access private
     * @var PEAR_PackageFileManager
     */
    var $_parent;

    /**
     * @access private
     * @var array|false
     */
    var $_ignore = false;

    /**
     * Set up the File filelist generator
     *
     * 'ignore' and 'include' are the only options that this class uses.  See
     * {@link PEAR_PackageFileManager::setOptions()} for
     * more information and formatting of this option
     * @param PEAR_PackageFileManager
     * @param array
     */
    function PEAR_PackageFileManager_File(&$parent, $options)
    {
        $this->_parent = &$parent;
        $this->_options = array_merge($this->_options, $options);
    }
    
    /**
     * Generate the <filelist></filelist> section
     * of the package file.
     *
     * This function performs the backend generation of the array
     * containing all files in this package
     * @return array
     */
    function getFileList()
    {
        $package_directory = $this->_options['packagedirectory'];
        $ignore = $this->_options['ignore'];
        // implicitly ignore packagefile
        $ignore[] = $this->_options['packagefile'];
        if ($this->_options['packagefile'] == 'package.xml') {
            // ignore auto-generated package2.xml from PEAR 1.4.0
            $ignore[] = 'package2.xml';
        }
        $include = $this->_options['include'];
        $this->ignore = array(false, false);
        $this->_setupIgnore($ignore, 1);
        $this->_setupIgnore($include, 0);
        $allfiles = $this->dirList(substr($package_directory, 0, strlen($package_directory) - 1));
        if (PEAR::isError($allfiles)) {
            return $allfiles;
        }
        if (!count($allfiles)) {
            return PEAR_PackageFileManager::raiseError(PEAR_PACKAGEFILEMANAGER_NO_FILES,
                substr($package_directory, 0, strlen($package_directory) - 1));
        }
        $struc = array();
        foreach($allfiles as $file) {
        	$path = substr(dirname($file), strlen(str_replace(DIRECTORY_SEPARATOR, 
                                                              '/',
                                                              realpath($package_directory))) + 1);
        	if (!$path) {
                $path = '/';
            }
        	$ext = array_pop(explode('.', $file));
        	if (strlen($ext) == strlen($file)) {
                $ext = '';
            }
        	$struc[$path][] = array('file' => basename($file),
                                    'ext' => $ext,
                                    'path' => (($path == '/') ? basename($file) : $path . '/' . basename($file)),
                                    'fullpath' => $file);
        }
        if (!count($struc)) {
            $newig = implode($this->_options['ignore'], ', ');
            return PEAR_PackageFileManager::raiseError(PEAR_PACKAGEFILEMANAGER_IGNORED_EVERYTHING,
                substr($package_directory, 0, strlen($package_directory) - 1), $newig);
        }
        uksort($struc,'strnatcasecmp');
        foreach($struc as $key => $ind) {
        	usort($ind, array($this, 'sortfiles'));
        	$struc[$key] = $ind;
        }

        $tempstruc = $struc;
        if (!isset($tempstruc['/'])) {
            $tempstruc['/'] = array();
        }
        $struc = array('/' => $tempstruc['/']);
        $bv = 0;
        foreach($tempstruc as $key => $ind) {
        	$save = $key;
        	if ($key != '/')
        	{
                $struc['/'] = $this->_setupDirs($struc['/'], explode('/',$key), $tempstruc[$key]);
        	}
        }
        uksort($struc['/'], array($this, 'mystrucsort'));

        return $struc;
    }
    
    /**
     * Retrieve a listing of every file in $directory and
     * all subdirectories.
     *
     * The return format is an array of full paths to files
     * @access protected
     * @return array list of files in a directory
     * @param string $directory full path to the directory you want the list of
     * @throws PEAR_PACKAGEFILEMANAGER_DIR_DOESNT_EXIST
     */
    function dirList($directory)
    {
        $ret = false;
        if (@is_dir($directory)) {
            $ret = array();
            $d = @dir($directory); // thanks to Jason E Sweat (jsweat@users.sourceforge.net) for fix
            while($d && false !== ($entry=$d->read())) {
                if ($this->_testFile($directory, $entry)) {
                    if (is_file($directory . '/' . $entry)) {
                        // if include option was set, then only pass included files
                        if ($this->ignore[0]) {
                            if ($this->_checkIgnore($entry, $directory . '/' . $entry, 0)) {
                                continue;
                            }
                        }
                        // if ignore option was set, then only pass included files
                        if ($this->ignore[1]) {
                            if ($this->_checkIgnore($entry, $directory . '/' . $entry, 1)) {
                                continue;
                            }
                        }
                        $ret[] = $directory . '/' . $entry;
                    }
                    if (is_dir($directory . '/' . $entry)) {
                        $tmp = $this->dirList($directory . '/' . $entry);
                        if (is_array($tmp)) {
                            foreach($tmp as $ent) {
                                $ret[] = $ent;
                            }
                        }
                    }
                }
            }
            if ($d) {
                $d->close();
            }
        } else {
            return PEAR_PackageFileManager::raiseError(PEAR_PACKAGEFILEMANAGER_DIR_DOESNT_EXIST, $directory);
        }
        return $ret;
    }
    
    /**
     * Test whether an entry should be processed.
     * 
     * Normally, it ignores all files and directories that begin with "."  addhiddenfiles option
     * instead only ignores "." and ".." entries
     * @access private
     * @param string directory name of entry
     * @param string name
     */
    function _testFile($directory, $entry)
    {
        if ($this->_options['addhiddenfiles']) {
            return is_file($directory . '/' . $entry) || (is_dir($directory . '/' . $entry) && !in_array($entry, array('.', '..')));
        } else {

⌨️ 快捷键说明

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