phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] news_admin/js/fckeditor/editor/filemanager/browser/d


From: skwashd
Subject: [Phpgroupware-cvs] news_admin/js/fckeditor/editor/filemanager/browser/default/connectors/php basexml.php, 1.1 commands.php, 1.1 config.php, 1.1 connector.php, 1.1 io.php, 1.1 util.php, 1.1
Date: Tue, 24 May 2005 16:32:00 +0200

Update of 
news_admin/js/fckeditor/editor/filemanager/browser/default/connectors/php

Added Files:
     Branch: MAIN
            basexml.php 
            commands.php 
            config.php 
            connector.php 
            io.php 
            util.php 

Log Message:
I am working on a much better version of news_admin, this is just a taste of 
what is coming.

Adding FCKeditor, which has the following issues:
* Images and files support FCKd
* Spellcheck FCKing up

Didn't include non php code or samples other unneeded crap

====================================================
Index: basexml.php
<?php 
/*
 * FCKeditor - The text editor for internet
 * Copyright (C) 2003-2004 Frederico Caldeira Knabben
 *
 * Licensed under the terms of the GNU Lesser General Public License:
 *              http://www.opensource.org/licenses/lgpl-license.php
 *
 * For further information visit:
 *              http://www.fckeditor.net/
 *
 * File Name: basexml.php
 *      This is the File Manager Connector for ASP.
 *
 * Version:  2.0 RC3
 * Modified: 2004-12-10 17:49:19
 *
 * File Authors:
 *              Frederico Caldeira Knabben (address@hidden)
 */

function CreateXmlHeader( $command, $resourceType, $currentFolder )
{
        // Create the XML document header.
        echo '<?xml version="1.0" encoding="utf-8" ?>' ;

        // Create the main "Connector" node.
        echo '<Connector command="' . $command . '" resourceType="' . 
$resourceType . '">' ;

        // Add the current folder node.
        echo '<CurrentFolder path="' . ConvertToXmlAttribute( $currentFolder ) 
. '" url="' . ConvertToXmlAttribute( GetUrlFromPath( $resourceType, 
$currentFolder ) ) . '" />' ;
}

function CreateXmlFooter()
{
        echo '</Connector>' ;
}
?>

====================================================
Index: commands.php
<?php 
/*
 * FCKeditor - The text editor for internet
 * Copyright (C) 2003-2004 Frederico Caldeira Knabben
 *
 * Licensed under the terms of the GNU Lesser General Public License:
 *              http://www.opensource.org/licenses/lgpl-license.php
 *
 * For further information visit:
 *              http://www.fckeditor.net/
 *
 * File Name: commands.php
 *      This is the File Manager Connector for ASP.
 *
 * Version:  2.0 RC3
 * Modified: 2005-02-19 16:02:38
 *
 * File Authors:
 *              Frederico Caldeira Knabben (address@hidden)
 */

function GetFolders( $resourceType, $currentFolder )
{
        // Map the virtual path to the local server path.
        $sServerDir = ServerMapFolder( $resourceType, $currentFolder ) ;

        // Open the "Folders" node.
        echo "<Folders>" ;

        $oCurrentFolder = opendir( $sServerDir ) ;

        while ( $sFile = readdir( $oCurrentFolder ) )
        {
                if ( $sFile != '.' && $sFile != '..' && is_dir( $sServerDir . 
$sFile ) )
                        echo '<Folder name="' . ConvertToXmlAttribute( $sFile ) 
. '" />' ;
        }

        closedir( $oCurrentFolder ) ;

        // Close the "Folders" node.
        echo "</Folders>" ;
}

function GetFoldersAndFiles( $resourceType, $currentFolder )
{
        // Map the virtual path to the local server path.
        $sServerDir = ServerMapFolder( $resourceType, $currentFolder ) ;

        // Initialize the output buffers for "Folders" and "Files".
        $sFolders       = '<Folders>' ;
        $sFiles         = '<Files>' ;

        $oCurrentFolder = opendir( $sServerDir ) ;

        while ( $sFile = readdir( $oCurrentFolder ) )
        {
                if ( $sFile != '.' && $sFile != '..' )
                {
                        if ( is_dir( $sServerDir . $sFile ) )
                                $sFolders .= '<Folder name="' . 
ConvertToXmlAttribute( $sFile ) . '" />' ;
                        else
                        {
                                $iFileSize = filesize( $sServerDir . $sFile ) ;
                                if ( $iFileSize > 0 )
                                {
                                        $iFileSize = round( $iFileSize / 1024 ) 
;
                                        if ( $iFileSize < 1 ) $iFileSize = 1 ;
                                }

                                $sFiles .= '<File name="' . 
ConvertToXmlAttribute( $sFile ) . '" size="' . $iFileSize . '" />' ;
                        }
                }
        }

        echo $sFolders ;
        // Close the "Folders" node.
        echo '</Folders>' ;

        echo $sFiles ;
        // Close the "Files" node.
        echo '</Files>' ;
}

function CreateFolder( $resourceType, $currentFolder )
{
        $sErrorNumber   = '0' ;
        $sErrorMsg              = '' ;

        if ( isset( $_GET['NewFolderName'] ) )
        {
                $sNewFolderName = $_GET['NewFolderName'] ;

                // Map the virtual path to the local server path of the current 
folder.
                $sServerDir = ServerMapFolder( $resourceType, $currentFolder ) ;

                if ( is_writable( $sServerDir ) )
                {
                        $sServerDir .= $sNewFolderName ;

                        $sErrorMsg = CreateServerFolder( $sServerDir ) ;

                        switch ( $sErrorMsg )
                        {
                                case '' :
                                        $sErrorNumber = '0' ;
                                        break ;
                                case 'Invalid argument' :
                                case 'No such file or directory' :
                                        $sErrorNumber = '102' ;         // Path 
too long.
                                        break ;
                                default :
                                        $sErrorNumber = '110' ;
                                        break ;
                        }
                }
                else
                        $sErrorNumber = '103' ;
        }
        else
                $sErrorNumber = '102' ;

        // Create the "Error" node.
        echo '<Error number="' . $sErrorNumber . '" originalDescription="' . 
ConvertToXmlAttribute( $sErrorMsg ) . '" />' ;
}

function FileUpload( $resourceType, $currentFolder )
{
        $sErrorNumber = '0' ;
        $sFileName = '' ;

        if ( isset( $_FILES['NewFile'] ) && !is_null( 
$_FILES['NewFile']['tmp_name'] ) )
        {
                $oFile = $_FILES['NewFile'] ;

                // Map the virtual path to the local server path.
                $sServerDir = ServerMapFolder( $resourceType, $currentFolder ) ;

                // Get the uploaded file name.
                $sFileName = $oFile['name'] ;
                $sOriginalFileName = $sFileName ;
                $sExtension = substr( $sFileName, ( strrpos($sFileName, '.') + 
1 ) ) ;

                global $Config ;

                $arAllowed      = $Config['AllowedExtensions'][$resourceType] ;
                $arDenied       = $Config['DeniedExtensions'][$resourceType] ;

                if ( ( count($arAllowed) == 0 || in_array( $sExtension, 
$arAllowed ) ) && ( count($arDenied) == 0 || !in_array( $sExtension, $arDenied 
) ) )
                {
                        $iCounter = 0 ;

                        while ( true )
                        {
                                $sFilePath = $sServerDir . $sFileName ;

                                if ( is_file( $sFilePath ) )
                                {
                                        $iCounter++ ;
                                        $sFileName = RemoveExtension( 
$sOriginalFileName ) . '(' . $iCounter . ').' . $sExtension ;
                                        $sErrorNumber = '201' ;
                                }
                                else
                                {
                                        move_uploaded_file( $oFile['tmp_name'], 
$sFilePath ) ;

                                        if ( is_file( $sFilePath ) )
                                        {
                                                $oldumask = umask(0) ;
                                                chmod( $sFilePath, 0777 ) ;
                                                umask( $oldumask ) ;
                                        }

                                        break ;
                                }
                        }
                }
                else
                        $sErrorNumber = '202' ;
        }
        else
                $sErrorNumber = '202' ;

        echo '<script type="text/javascript">' ;
        echo 'window.parent.frames["frmUpload"].OnUploadCompleted(' . 
$sErrorNumber . ',"' . str_replace( '"', '\\"', $sFileName ) . '") ;' ;
        echo '</script>' ;

        exit ;
}
?>

====================================================
Index: config.php
<?php 
/*
 * FCKeditor - The text editor for internet
 * Copyright (C) 2003-2004 Frederico Caldeira Knabben
 *
 * Licensed under the terms of the GNU Lesser General Public License:
 *              http://www.opensource.org/licenses/lgpl-license.php
 *
 * For further information visit:
 *              http://www.fckeditor.net/
 *
 * File Name: config.php
 *      Configuration file for the File Manager Connector for PHP.
 *
 * Version:  2.0 RC3
 * Modified: 2005-02-08 12:01:53
 *
 * File Authors:
 *              Frederico Caldeira Knabben (address@hidden)
 */

global $Config ;

// Path to user files relative to the document root.
// SECURITY TIP: Uncomment the following line to set a fixed path.
//$Config['UserFilesPath'] = '/UserFiles/' ;

$Config['AllowedExtensions']['File']    = array() ;
$Config['DeniedExtensions']['File']             = 
array('php','asp','aspx','ascx','jsp','cfm','cfc','pl','bat','exe','dll','reg') 
;

$Config['AllowedExtensions']['Image']   = array('jpg','gif','jpeg','png') ;
$Config['DeniedExtensions']['Image']    = array() ;

$Config['AllowedExtensions']['Flash']   = array('swf','fla') ;
$Config['DeniedExtensions']['Flash']    = array() ;

$Config['AllowedExtensions']['Media']   = 
array('swf','fla','jpg','gif','jpeg','png','avi','mpg','mpeg') ;
$Config['DeniedExtensions']['Media']    = array() ;

?>

====================================================
Index: connector.php
<?php 
/*
 * FCKeditor - The text editor for internet
 * Copyright (C) 2003-2004 Frederico Caldeira Knabben
 *
 * Licensed under the terms of the GNU Lesser General Public License:
 *              http://www.opensource.org/licenses/lgpl-license.php
 *
 * For further information visit:
 *              http://www.fckeditor.net/
 *
 * File Name: connector.php
 *      This is the File Manager Connector for PHP.
 *
 * Version:  2.0 RC3
 * Modified: 2005-02-08 11:48:55
 *
 * File Authors:
 *              Frederico Caldeira Knabben (address@hidden)
 */

include('config.php') ;
include('util.php') ;
include('io.php') ;
include('basexml.php') ;
include('commands.php') ;

// Get the "UserFiles" path.
$GLOBALS["UserFilesPath"] = '' ;

if ( isset( $Config['UserFilesPath'] ) )
        $GLOBALS["UserFilesPath"] = $Config['UserFilesPath'] ;
else if ( isset( $_GET['ServerPath'] ) )
        $GLOBALS["UserFilesPath"] = $_GET['ServerPath'] ;
else
        $GLOBALS["UserFilesPath"] = '/UserFiles/' ;

if ( ! ereg( '/$', $GLOBALS["UserFilesPath"] ) )
        $GLOBALS["UserFilesPath"] .= '/' ;

// Map the "UserFiles" path to a local directory.
//$GLOBALS["UserFilesDirectory"] = GetRootPath() . str_replace( '/', '\\', 
$GLOBALS["UserFilesPath"] ) ;
$GLOBALS["UserFilesDirectory"] = GetRootPath() . $GLOBALS["UserFilesPath"] ;

DoResponse() ;

function DoResponse()
{
        if ( !isset( $_GET['Command'] ) || !isset( $_GET['Type'] ) || !isset( 
$_GET['CurrentFolder'] ) )
                return ;

        // Get the main request informaiton.
        $sCommand               = $_GET['Command'] ;
        $sResourceType  = $_GET['Type'] ;
        $sCurrentFolder = $_GET['CurrentFolder'] ;

        // Check if it is an allowed type.
        if ( !in_array( $sResourceType, array('File','Image','Flash','Media') ) 
)
                return ;

        // Check the current folder syntax (must begin and start with a slash).
        if ( ! ereg( '/$', $sCurrentFolder ) ) $sCurrentFolder .= '/' ;
        if ( strpos( $sCurrentFolder, '/' ) !== 0 ) $sCurrentFolder = '/' . 
$sCurrentFolder ;

        // File Upload doesn't have to Return XML, so it must be intercepted 
before anything.
        if ( $sCommand == 'FileUpload' )
        {
                FileUpload( $sResourceType, $sCurrentFolder ) ;
                return ;
        }

        // Prevent the browser from caching the result.
        // Date in the past
        header('Expires: Mon, 26 Jul 1997 05:00:00 GMT') ;
        // always modified
        header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT') ;
        // HTTP/1.1
        header('Cache-Control: no-store, no-cache, must-revalidate') ;
        header('Cache-Control: post-check=0, pre-check=0', false) ;
        // HTTP/1.0
        header('Pragma: no-cache') ;

        // Set the response format.
        header( 'Content-Type:text/xml; charset=utf-8' ) ;

        CreateXmlHeader( $sCommand, $sResourceType, $sCurrentFolder ) ;

        // Execute the required command.
        switch ( $sCommand )
        {
                case 'GetFolders' :
                        GetFolders( $sResourceType, $sCurrentFolder ) ;
                        break ;
                case 'GetFoldersAndFiles' :
                        GetFoldersAndFiles( $sResourceType, $sCurrentFolder ) ;
                        break ;
                case 'CreateFolder' :
                        CreateFolder( $sResourceType, $sCurrentFolder ) ;
                        break ;
        }

        CreateXmlFooter() ;

        exit ;
}
?>

====================================================
Index: io.php
<?php 
/*
 * FCKeditor - The text editor for internet
 * Copyright (C) 2003-2004 Frederico Caldeira Knabben
 *
 * Licensed under the terms of the GNU Lesser General Public License:
 *              http://www.opensource.org/licenses/lgpl-license.php
 *
 * For further information visit:
 *              http://www.fckeditor.net/
 *
 * File Name: io.php
 *      This is the File Manager Connector for ASP.
 *
 * Version:  2.0 RC3
 * Modified: 2005-02-19 16:03:39
 *
 * File Authors:
 *              Frederico Caldeira Knabben (address@hidden)
 */

function GetUrlFromPath( $resourceType, $folderPath )
{
        if ( $resourceType == '' )
                return RemoveFromEnd( $GLOBALS["UserFilesPath"], '/' ) . 
$folderPath ;
        else
                return $GLOBALS["UserFilesPath"] . $resourceType . $folderPath ;
}

function RemoveExtension( $fileName )
{
        return substr( $fileName, 0, strrpos( $fileName, '.' ) ) ;
}

function ServerMapFolder( $resourceType, $folderPath )
{
        // Get the resource type directory.
//      $sResourceTypePath = $GLOBALS["UserFilesDirectory"] . $resourceType . 
'\\' ;
        $sResourceTypePath = $GLOBALS["UserFilesDirectory"] . $resourceType . 
'/' ;

        // Ensure that the directory exists.
        CreateServerFolder( $sResourceTypePath ) ;

        // Return the resource type directory combined with the required path.
//      return $sResourceTypePath . str_replace( '/', '\\', RemoveFromStart( 
$folderPath, '/' ) ) ;
        return $sResourceTypePath . RemoveFromStart( $folderPath, '/' ) ;
}

function GetParentFolder( $folderPath )
{
        $sPattern = "-[/\\\\][^/\\\\]+[/\\\\]?$-" ;
        return preg_replace( $sPattern, '', $folderPath ) ;
}

function CreateServerFolder( $folderPath )
{
        $sParent = GetParentFolder( $folderPath ) ;

        // Check if the parent exists, or create it.
        if ( !file_exists( $sParent ) )
        {
                $sErrorMsg = CreateServerFolder( $sParent ) ;
                if ( $sErrorMsg != '' )
                        return $sErrorMsg ;
        }

        if ( !file_exists( $folderPath ) )
        {
                // Turn off all error reporting.
                error_reporting( 0 ) ;
                // Enable error tracking to catch the error.
                ini_set( 'track_errors', '1' ) ;

                // To create the folder with 0777 permissions, we need to set 
umask to zero.
                $oldumask = umask(0) ;
                mkdir( $folderPath, 0777 ) ;
                umask( $oldumask ) ;

                $sErrorMsg = $php_errormsg ;

                // Restore the configurations.
                ini_restore( 'track_errors' ) ;
                ini_restore( 'error_reporting' ) ;

                return $sErrorMsg ;
        }
        else
                return '' ;
}

function GetRootPath()
{
        $sRealPath = realpath( './' ) ;

//      $sSelfPath = str_replace( '/', '\\', $_SERVER['PHP_SELF'] ) ;
        $sSelfPath = $_SERVER['PHP_SELF'] ;
//      $sSelfPath = substr( $sSelfPath, 0, strrpos( $sSelfPath, '\\' ) ) ;
        $sSelfPath = substr( $sSelfPath, 0, strrpos( $sSelfPath, '/' ) ) ;

        return substr( $sRealPath, 0, strlen( $sRealPath ) - strlen( $sSelfPath 
) ) ;
}
?>

====================================================
Index: util.php
<?php 
/*
 * FCKeditor - The text editor for internet
 * Copyright (C) 2003-2004 Frederico Caldeira Knabben
 *
 * Licensed under the terms of the GNU Lesser General Public License:
 *              http://www.opensource.org/licenses/lgpl-license.php
 *
 * For further information visit:
 *              http://www.fckeditor.net/
 *
 * File Name: util.php
 *      This is the File Manager Connector for ASP.
 *
 * Version:  2.0 RC3
 * Modified: 2004-12-10 17:46:39
 *
 * File Authors:
 *              Frederico Caldeira Knabben (address@hidden)
 */

function RemoveFromStart( $sourceString, $charToRemove )
{
        $sPattern = '|^' . $charToRemove . '+|' ;
        return preg_replace( $sPattern, '', $sourceString ) ;
}

function RemoveFromEnd( $sourceString, $charToRemove )
{
        $sPattern = '|' . $charToRemove . '+$|' ;
        return preg_replace( $sPattern, '', $sourceString ) ;
}

function ConvertToXmlAttribute( $value )
{
        return utf8_encode( htmlspecialchars( $value ) ) ;
}
?>






reply via email to

[Prev in Thread] Current Thread [Next in Thread]