/branches/livraison_aha/api/fckeditor/editor/filemanager/browser/default/connectors/php/io.php |
---|
New file |
0,0 → 1,97 |
<?php |
/* |
* FCKeditor - The text editor for internet |
* Copyright (C) 2003-2006 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/ |
* |
* "Support Open Source software. What about a donation today?" |
* |
* File Name: io.php |
* This is the File Manager Connector for ASP. |
* |
* File Authors: |
* Frederico Caldeira Knabben (fredck@fckeditor.net) |
*/ |
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 . '/' ; |
// Ensure that the directory exists. |
CreateServerFolder( $sResourceTypePath ) ; |
// Return the resource type directory combined with the required path. |
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 = $_SERVER['PHP_SELF'] ; |
$sSelfPath = substr( $sSelfPath, 0, strrpos( $sSelfPath, '/' ) ) ; |
return substr( $sRealPath, 0, strlen( $sRealPath ) - strlen( $sSelfPath ) ) ; |
} |
?> |
/branches/livraison_aha/api/fckeditor/editor/filemanager/browser/default/connectors/php/connector.php |
---|
New file |
0,0 → 1,109 |
<?php |
/* |
* FCKeditor - The text editor for internet |
* Copyright (C) 2003-2006 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/ |
* |
* "Support Open Source software. What about a donation today?" |
* |
* File Name: connector.php |
* This is the File Manager Connector for PHP. |
* |
* File Authors: |
* Frederico Caldeira Knabben (fredck@fckeditor.net) |
*/ |
ob_start() ; |
include('config.php') ; |
include('util.php') ; |
include('io.php') ; |
include('basexml.php') ; |
include('commands.php') ; |
if ( !$Config['Enabled'] ) |
SendError( 1, 'This connector is disabled. Please check the "editor/filemanager/browser/default/connectors/php/config.php" file' ) ; |
// 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"] .= '/' ; |
if ( strlen( $Config['UserFilesAbsolutePath'] ) > 0 ) |
{ |
$GLOBALS["UserFilesDirectory"] = $Config['UserFilesAbsolutePath'] ; |
if ( ! ereg( '/$', $GLOBALS["UserFilesDirectory"] ) ) |
$GLOBALS["UserFilesDirectory"] .= '/' ; |
} |
else |
{ |
// Map the "UserFiles" path to a local directory. |
$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 ; |
// Check for invalid folder paths (..) |
if ( strpos( $sCurrentFolder, '..' ) ) |
SendError( 102, "" ) ; |
// File Upload doesn't have to Return XML, so it must be intercepted before anything. |
if ( $sCommand == 'FileUpload' ) |
{ |
FileUpload( $sResourceType, $sCurrentFolder ) ; |
return ; |
} |
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 ; |
} |
?> |
/branches/livraison_aha/api/fckeditor/editor/filemanager/browser/default/connectors/php/basexml.php |
---|
New file |
0,0 → 1,71 |
<?php |
/* |
* FCKeditor - The text editor for internet |
* Copyright (C) 2003-2006 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/ |
* |
* "Support Open Source software. What about a donation today?" |
* |
* File Name: basexml.php |
* These functions define the base of the XML response sent by the PHP |
* connector. |
* |
* File Authors: |
* Frederico Caldeira Knabben (fredck@fckeditor.net) |
*/ |
function SetXmlHeaders() |
{ |
ob_end_clean() ; |
// 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' ) ; |
} |
function CreateXmlHeader( $command, $resourceType, $currentFolder ) |
{ |
SetXmlHeaders() ; |
// 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>' ; |
} |
function SendError( $number, $text ) |
{ |
SetXmlHeaders() ; |
// Create the XML document header |
echo '<?xml version="1.0" encoding="utf-8" ?>' ; |
echo '<Connector><Error number="' . $number . '" text="' . htmlspecialchars( $text ) . '" /></Connector>' ; |
exit ; |
} |
?> |
/branches/livraison_aha/api/fckeditor/editor/filemanager/browser/default/connectors/php/util.php |
---|
New file |
0,0 → 1,37 |
<?php |
/* |
* FCKeditor - The text editor for internet |
* Copyright (C) 2003-2006 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/ |
* |
* "Support Open Source software. What about a donation today?" |
* |
* File Name: util.php |
* This is the File Manager Connector for ASP. |
* |
* File Authors: |
* Frederico Caldeira Knabben (fredck@fckeditor.net) |
*/ |
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 ) ) ; |
} |
?> |
/branches/livraison_aha/api/fckeditor/editor/filemanager/browser/default/connectors/php/commands.php |
---|
New file |
0,0 → 1,218 |
<?php |
/* |
* FCKeditor - The text editor for internet |
* Copyright (C) 2003-2006 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/ |
* |
* "Support Open Source software. What about a donation today?" |
* |
* File Name: commands.php |
* This is the File Manager Connector for PHP. |
* |
* File Authors: |
* Frederico Caldeira Knabben (fredck@fckeditor.net) |
*/ |
function GetFolders( $resourceType, $currentFolder ) |
{ |
// Map the virtual path to the local server path. |
$sServerDir = ServerMapFolder( $resourceType, $currentFolder ) ; |
// Array that will hold the folders names. |
$aFolders = array() ; |
$oCurrentFolder = opendir( $sServerDir ) ; |
while ( $sFile = readdir( $oCurrentFolder ) ) |
{ |
if ( $sFile != '.' && $sFile != '..' && is_dir( $sServerDir . $sFile ) ) |
$aFolders[] = '<Folder name="' . ConvertToXmlAttribute( $sFile ) . '" />' ; |
} |
closedir( $oCurrentFolder ) ; |
// Open the "Folders" node. |
echo "<Folders>" ; |
natcasesort( $aFolders ) ; |
foreach ( $aFolders as $sFolder ) |
echo $sFolder ; |
// Close the "Folders" node. |
echo "</Folders>" ; |
} |
function GetFoldersAndFiles( $resourceType, $currentFolder ) |
{ |
// Map the virtual path to the local server path. |
$sServerDir = ServerMapFolder( $resourceType, $currentFolder ) ; |
// Arrays that will hold the folders and files names. |
$aFolders = array() ; |
$aFiles = array() ; |
$oCurrentFolder = opendir( $sServerDir ) ; |
while ( $sFile = readdir( $oCurrentFolder ) ) |
{ |
if ( $sFile != '.' && $sFile != '..' ) |
{ |
if ( is_dir( $sServerDir . $sFile ) ) |
$aFolders[] = '<Folder name="' . ConvertToXmlAttribute( $sFile ) . '" />' ; |
else |
{ |
$iFileSize = filesize( $sServerDir . $sFile ) ; |
if ( $iFileSize > 0 ) |
{ |
$iFileSize = round( $iFileSize / 1024 ) ; |
if ( $iFileSize < 1 ) $iFileSize = 1 ; |
} |
$aFiles[] = '<File name="' . ConvertToXmlAttribute( $sFile ) . '" size="' . $iFileSize . '" />' ; |
} |
} |
} |
// Send the folders |
natcasesort( $aFolders ) ; |
echo '<Folders>' ; |
foreach ( $aFolders as $sFolder ) |
echo $sFolder ; |
echo '</Folders>' ; |
// Send the files |
natcasesort( $aFiles ) ; |
echo '<Files>' ; |
foreach ( $aFiles as $sFiles ) |
echo $sFiles ; |
echo '</Files>' ; |
} |
function CreateFolder( $resourceType, $currentFolder ) |
{ |
$sErrorNumber = '0' ; |
$sErrorMsg = '' ; |
if ( isset( $_GET['NewFolderName'] ) ) |
{ |
$sNewFolderName = $_GET['NewFolderName'] ; |
if ( strpos( $sNewFolderName, '..' ) !== FALSE ) |
$sErrorNumber = '102' ; // Invalid folder name. |
else |
{ |
// 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'] ) ) |
{ |
global $Config ; |
$oFile = $_FILES['NewFile'] ; |
// Map the virtual path to the local server path. |
$sServerDir = ServerMapFolder( $resourceType, $currentFolder ) ; |
// Get the uploaded file name. |
$sFileName = $oFile['name'] ; |
// Replace dots in the name with underscores (only one dot can be there... security issue). |
if ( $Config['ForceSingleExtension'] ) |
$sFileName = preg_replace( '/\\.(?![^.]*$)/', '_', $sFileName ) ; |
$sOriginalFileName = $sFileName ; |
// Get the extension. |
$sExtension = substr( $sFileName, ( strrpos($sFileName, '.') + 1 ) ) ; |
$sExtension = strtolower( $sExtension ) ; |
$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 ; |
} |
?> |
/branches/livraison_aha/api/fckeditor/editor/filemanager/browser/default/connectors/php/config.php |
---|
New file |
0,0 → 1,51 |
<?php |
/* |
* FCKeditor - The text editor for internet |
* Copyright (C) 2003-2006 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/ |
* |
* "Support Open Source software. What about a donation today?" |
* |
* File Name: config.php |
* Configuration file for the File Manager Connector for PHP. |
* |
* File Authors: |
* Frederico Caldeira Knabben (fredck@fckeditor.net) |
*/ |
global $Config ; |
// SECURITY: You must explicitelly enable this "connector". (Set it to "true"). |
$Config['Enabled'] = false ; |
// Path to user files relative to the document root. |
$Config['UserFilesPath'] = '/UserFiles/' ; |
// Fill the following value it you prefer to specify the absolute path for the |
// user files directory. Usefull if you are using a virtual directory, symbolic |
// link or alias. Examples: 'C:\\MySite\\UserFiles\\' or '/root/mysite/UserFiles/'. |
// Attention: The above 'UserFilesPath' must point to the same directory. |
$Config['UserFilesAbsolutePath'] = '' ; |
// Due to security issues with Apache modules, it is reccomended to leave the |
// following setting enabled. |
$Config['ForceSingleExtension'] = true ; |
$Config['AllowedExtensions']['File'] = array() ; |
$Config['DeniedExtensions']['File'] = array('php','php2','php3','php4','php5','phtml','pwml','inc','asp','aspx','ascx','jsp','cfm','cfc','pl','bat','exe','com','dll','vbs','js','reg','cgi','htaccess') ; |
$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() ; |
?> |