Location: PHPKode > projects > Entier Studio > entierstudio/framework/file.explorer.php
<?php
/**
 * Entier Studio
 *
 * LICENSE
 *
 *	Copyright 2006 Entier Studio team.
 *
 *	Licensed under the Apache License, Version 2.0 (the "License");
 *	you may not use this file except in compliance with the License.
 *	You may obtain a copy of the License at
 *
 *		http://www.apache.org/licenses/LICENSE-2.0
 *
 *	Unless required by applicable law or agreed to in writing, software
 *	distributed under the License is distributed on an "AS IS" BASIS,
 *	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *	See the License for the specific language governing permissions and
 *	limitations under the License.
 *
 * @package    entier.framework 
 * @version	   $Id: file.explorer.php 82 2008-01-18 18:04:17Z yannromefort $
 * @copyright  Copyright (c) 2006 Entier Studio team. All rights reserved.
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefFILEExplorer")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefFILEExplorer", "1");
    //-------------------------------------------------------------------------
    //	Include
    @require_once (FRAMEWORK_DIR . "datasource.explorer.php");
    @require_once (FRAMEWORK_DIR . "file.datasource.php");
    //-------------------------------------------------------------------------
    //	Class
    class FILEExplorer extends DataSourceExplorer {
        //---------------------------------------------------------------------
        //	Constructor
        
        /**
         * Data source constructor
         * @param	string	host
         * @param	string	port
         * @param	string	user
         * @param	string	pass
         * @param	string	base
         */
        function FILEExplorer($hostName = "", $hostPort = 0, $userName = "", $passWord = "", $directory = "") {
            //
            $this->m_Source = new FILEDataSource($hostName, $hostPort, $userName, $passWord, $directory);
        }
        //---------------------------------------------------------------------
        //	Methods
        //	DataSourceExplorer interface
        
        /**
         * Parse a data source schema
         * @param	string	Target element name
         * @param	string	Target element type
         * @return	integer parsed set size
         */
        function parseObject($name = "", $type = "") {
            //
            if (empty($name) || empty($type)) return (0);
            //
            $this->resetObject();
            //
            $directory = $this->m_Source->Directory();
            //
            switch ($type) {
                case "directory":
                    //
                    if (empty($name))
                        $root = $directory;
                    else
                        $root = $name;
                    //
                    $this->m_Element = new ModelElement($name, "directory", DIRECTORY_NODE, $root);
                    //
                break;
                case "host":
					// FIXME check path
                    if ("" == $directory)
					    $root = "";
                    else 
					    $root = $directory;
                    //
                    $this->m_Element = new ModelElement("root", "host", HOST_NODE, $root);                   
                    //
                break;
                default:
                    //
                    return (false);
                    //
                break;
            }
            // normalisation point
            $root = ($root . DS);
            //
            if ($this->m_Source->openDirectory($root) == false) {
				return (false);
			}
            //
            $dirlist = array();
            while (false !== ($file = @readdir($this->m_Source->Connection()))) {
                $dirlist[] = $file;
            }
            //
            $this->m_Source->closeDirectory();   
            //
            while (list($code, $name) = @each($dirlist)) {
                //                
                $type = @filetype($root . $name);                
                //
                switch ($type) {
                    case "dir":
                        // directory
                        if (("." != $name ) && (".." != $name)) {
                            //
                            $this->m_Element->addElement("$name", new ModelElement($name, "directory", DIRECTORY_NODE, "$root$name"));
                        }
                        //
                    break;
                    case "link":
                        // link
                        $this->m_Element->addElement("$name", new ModelElement($name, "symlink", LINK_NODE, "$root$name"));
                        //
                    break;
                    case "file":
                        // file
                        $size = @filesize($root . $name);
                        //
                        $this->m_Element->addElement("$name", new ModelElement($name, "file", FILE_NODE, "$root$name", "", $size));
                        //
                    break;
                }
            }
            //
            @clearstatcache();
            //
            $this->m_Element->sortElements();
            $this->m_Element->resetElements();
            //
            return ($this->sizeOfElements());            
        }
    };
    //	Class
    //-------------------------------------------------------------------------
}
//	namespace
//-----------------------------------------------------------------------------
    
?>
Return current item: Entier Studio