Location: PHPKode > projects > Entier Studio > entierstudio/framework/ftp.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
 * @copyright  Copyright (c) 2006 Entier Studio team. All rights reserved.
 * @version	   $Id: ftp.explorer.php 83 2008-01-18 22:24:14Z yannromefort $
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefFTPExplorer")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefFTPExplorer", "1");
    //-------------------------------------------------------------------------
    //	Include
    @require_once (FRAMEWORK_DIR . "datasource.explorer.php");
    @require_once (FRAMEWORK_DIR . "ftp.datasource.php");
    //-------------------------------------------------------------------------
    //	Class
    class FTPExplorer extends DataSourceExplorer {
        //---------------------------------------------------------------------
        //	Constructor
        
        /**
         * Data source constructor
         * @param	string	host
         * @param	string	port
         * @param	string	user
         * @param	string	pass
         * @param	string	base
         */
        function FTPExplorer($hostName = "", $hostPort = 0, $userName = "", $passWord = "", $directory = "") {
            //
            $this->m_Source = new FTPDataSource($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;
                    //
					if (strcmp('/', $name))
					    $this->m_Element = new ModelElement("root", "host", HOST_NODE, $root);
					else
                        $this->m_Element = new ModelElement("root", "host", HOST_NODE, $name);
                    //
                break;
                default:
                    //
                    return (0);
                    //
                break;
            }
            // normalisation point
            $root = ($root . DS);
            //
            if ($this->openSource() == false) 
                return (false);
            //
            $systype = @ftp_systype($this->m_Source->Connection());
            $dirlist = @ftp_rawlist($this->m_Source->Connection() , $root);
            //
            while (list($code, $line) = @each($dirlist)) {
                //
                switch ($systype) {
                    case "UNIX":
                        //	http://inebria.com/phpftp/ftp.phps
                        //$regs	= split( "[ ]+", $line, 9 );
                        $regs = @preg_split("/[ ]+/", $line, 9);
                        $type = substr($regs[0], 0, 1);
                        $name = $regs[8];
                        $size = $regs[4];
                        //
                        switch ($type) {
                            case "d":
                                // directory
                                if (("." != $name ) && (".." != $name)) {
	                                //
                                    $this->m_Element->addElement("$name", new ModelElement($name, "directory", DIRECTORY_NODE, "$root$name", "", "-"));
                                }
                            //
                            break;
                            case "l":
                                // link
                                $this->m_Element->addElement("$name", new ModelElement($name, "symlink", LINK_NODE, "$root$name"));
                            //
                            break;
                            case "-":
                                // file
                                $this->m_Element->addElement("$name", new ModelElement($name, "file", FILE_NODE, "$root$name", "", $size));
                            //
                            break;
                            case "+":
                                // anonftp server
                                /*
                                $eplf= split(",",implode(" ",$item[$i]),5);
                                if( $eplf[2] == "r" ) {
                                    // it's a file
                                    $nlist_files[$f_i]=trim($eplf[4]);
                                    $nlist_filesize[$f_i]=substr($eplf[3],1);
                                    $f_i++;
                                }
                                elseif ($eplf[2] == "/") {
                                    //it's a directory
                                    $nlist_dirs[$d_i]=trim($eplf[3]);
                                    $d_i++;
                                }
                                */
                            //
                            break;
                        } // $type
                    //
                    break;
					default:
                        //
                        $regs = @preg_split("/[ ]+/", $line, 5);
                        $type = $regs[2];
                        //
                        switch ($regs[2]) {
                            case "<DIR>":
                                // directory
                                $name = $regs[3];
                                if (("." != $name ) && (".." != $name)) {
                                    //
                                    $this->m_Element->addElement("$name", new ModelElement($name, "directory", DIRECTORY_NODE, "$root$name", "", "-"));
                                }
                            //
                            break;
                            default:
                                // file
                                $size = $regs[2];
                                $name = $regs[3];
                                //
                                $this->m_Element->addElement("$name", new ModelElement($name, "file", FILE_NODE, "$root$name", "", $size));
                            //
                            break;                                
                        }
                    //
                    break;
                } // $systype
            } // loop            
            //
            $this->m_Element->sortElements();
            $this->m_Element->resetElements();
            //
            return ($this->sizeOfElements());
        }
    };
    //	Class
    //-------------------------------------------------------------------------
}
//	namespace
//-----------------------------------------------------------------------------                
?>
Return current item: Entier Studio