Location: PHPKode > projects > Entier Studio > entierstudio/framework/ssh2.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: ssh2.explorer.php 84 2008-01-19 23:49:20Z yannromefort $
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefSSH2Explorer")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefSSH2Explorer", "1");
    //-------------------------------------------------------------------------
    //	Include
    @require_once (FRAMEWORK_DIR . "datasource.explorer.php");
    @require_once (FRAMEWORK_DIR . "ssh2.datasource.php");
    //-------------------------------------------------------------------------
    //	Class
    class SSH2Explorer extends DataSourceExplorer {
        //---------------------------------------------------------------------
        //	Constructor
        
        /**
         * Data source constructor
         * @param	string	host
         * @param	string	port
         * @param	string	user
         * @param	string	pass
         * @param	string	base
         */
        function SSH2Explorer($hostName = "", $hostPort = 0, $userName = "", $passWord = "", $directory = "") {
            //
            $this->m_Source = new SSH2DataSource($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":
					//
					if ("" == $directory)
					    return (false);
					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->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($this->m_Source->URLocator($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;
                }
            }
            //
            $this->m_Element->sortElements();
            $this->m_Element->resetElements();
            //
            return ($this->sizeOfElements());
        }
    };
    //	Class
    //-------------------------------------------------------------------------
        
}
//	namespace
//-----------------------------------------------------------------------------
    
?>
Return current item: Entier Studio