Ticket #2873: 2873.patch

File 2873.patch, 225.8 KB (added by Wiktor Walc, 18 years ago)
  • _source/core/config.js

     
    147147         * config.plugins = 'basicstyles,button,htmldataprocessor,toolbar,wysiwygarea';
    148148         */
    149149
    150         plugins : 'basicstyles,button,elementspath,horizontalrule,htmldataprocessor,keystrokes,newpage,pagebreak,preview,removeformat,smiley,indent,link,list,sourcearea,table,specialchar,tab,toolbar,wysiwygarea',
     150        plugins : 'basicstyles,button,elementspath,filebrowser,horizontalrule,htmldataprocessor,keystrokes,newpage,pagebreak,preview,removeformat,smiley,indent,link,list,sourcearea,table,specialchar,tab,toolbar,wysiwygarea',
    151151
    152152        /**
    153153         * The theme to be used to build the UI.
  • _source/core/loader.js

     
    4444                        'core/dom/text'                 : [ 'core/dom/node', 'core/dom/domobject' ],
    4545                        'core/dom/window'               : [ 'core/dom/domobject' ],
    4646                        'core/dtd'                              : [ 'core/tools' ],
    47                         'core/editor'                   : [ 'core/command', 'core/config', 'core/editor_basic', 'core/focusmanager', 'core/lang', 'core/plugins', 'core/skins', 'core/themes', 'core/tools', 'core/ui' ],
     47                        'core/editor'                   : [ 'core/ajax', 'core/command', 'core/config', 'core/editor_basic', 'core/focusmanager', 'core/lang', 'core/plugins', 'core/skins', 'core/themes', 'core/tools', 'core/ui' ],
    4848                        'core/editor_basic'             : [ 'core/event' ],
    4949                        'core/env'                              : [],
    5050                        'core/event'                    : [],
  • _source/lang/en.js

     
    365365                vSpace  : 'VSpace'
    366366        },
    367367
     368        filebrowser :
     369        {
     370                errors :
     371                {
     372                        10 : 'Invalid command.',
     373                        11 : 'The resource type was not specified in the request.',
     374                        12 : 'The requested resource type is not valid.',
     375                        102 : 'Invalid file or folder name.',
     376                        103 : 'It was not possible to complete the request due to authorization restrictions.',
     377                        104 : 'It was not possible to complete the request due to file system permission restrictions.',
     378                        105 : 'Invalid file extension.',
     379                        109 : 'Invalid request.',
     380                        110 : 'Unknown error.',
     381                        115 : 'A file or folder with the same name already exists.',
     382                        116 : 'Folder not found. Please refresh and try again.',
     383                        117 : 'File not found. Please refresh the files list and try again.',
     384                        201 : 'A file with the same name is already available. The uploaded file has been renamed to "%1"',
     385                        202 : 'Invalid file',
     386                        203 : 'Invalid file. The file size is too big.',
     387                        204 : 'The uploaded file is corrupt.',
     388                        205 : 'No temporary folder is available for upload in the server.',
     389                        206 : 'Upload cancelled for security reasons. The file contains HTML like data.',
     390                        500 : 'The file browser is disabled for security reasons. Please contact your system administrator and check the CKFinder configuration file.',
     391                        501 : 'The thumbnails support is disabled.'
     392                },
     393                errorUnknown : 'It was not possible to complete the request. (Error %1)',
     394                fileNotSelected : 'Please select a file from your computer',
     395                fileInvalidChar : 'The file name cannot contain any of the following characters: \n\\ / : * ? " < > |',
     396                folderCreate : 'Create Folder',
     397                folderCreateTip : 'Create folder in working directory',
     398                folderEmpty : 'The folder name cannot be empty',
     399                folderInvalidChar : 'The folder name cannot contain any of the following characters: \n\\ / : * ? " < > |',
     400                folderNew : 'Please type the new folder name: ',
     401                resourceType : 'Resource Type',
     402                title : 'File Browser',
     403                uploadProgressLbl : '(Upload in progress, please wait...)',
     404                uploadTip : 'Upload a new file in this folder',
     405        },
     406
    368407        smiley :
    369408        {
    370409                toolbar : 'Smiley',
  • _source/plugins/dialog/plugin.js

     
    709709                },
    710710
    711711                /**
     712                 * Gets the name of the dialog.
     713                 * @returns {String} The name of this dialog.
     714                 * @example
     715                 * var dialogName = dialogObj.getName();
     716                 */
     717                getName : function()
     718                {
     719                        return this._.name;
     720                },
     721
     722                /**
    712723                 * Gets a dialog UI element object from a dialog page.
    713724                 * @param {String} pageId id of dialog page.
    714725                 * @param {String} elementId id of UI element.
     
    19861997                 */
    19871998                selectParentTab : function()
    19881999                {
     2000                        tabId = this.getParentTab();
     2001
     2002                        this._.dialog.selectPage( tabId );
     2003                        return this;
     2004                },
     2005
     2006                /**
     2007                 * Gets the name of the parent tab of this element.
     2008                 * @returns {String} The name of selected tab.
     2009                 * @example
     2010                 * focus : function()
     2011                 * {
     2012                 *              this.getParentTab();
     2013                 *              // do something else.
     2014                 * }
     2015                 */
     2016                getParentTab : function()
     2017                {
    19892018                        var element = this.getInputElement(),
    19902019                                cursor = element,
    19912020                                tabId;
     
    19942023
    19952024                        tabId = cursor.getAttribute( 'name' );
    19962025
    1997                         this._.dialog.selectPage( tabId );
    1998                         return this;
     2026                        return tabId;
    19992027                },
    20002028
    20012029                /**
  • _source/plugins/dialogui/plugin.js

     
    656656                                        this.validate = elementDefinition.validate;
    657657
    658658                                var myDefinition = CKEDITOR.tools.extend( {}, elementDefinition );
     659                                var onClick = myDefinition.onClick;
    659660                                myDefinition.className = ( myDefinition.className ? myDefinition.className + ' ' : '' ) + 'cke_dialog_ui_button';
    660661                                myDefinition.onClick = function( evt )
    661662                                {
    662663                                        var target = elementDefinition[ 'for' ];                // [ pageId, elementId ]
    663                                         dialog.getContentElement( target[0], target[1] ).submit();
    664                                         this.disable();
     664                                        if ( !onClick || onClick.call( this, evt ) !== false )
     665                                        {
     666                                                dialog.getContentElement( target[0], target[1] ).submit();
     667                                                this.disable();
     668                                        }
    665669                                };
    666670
    667671                                dialog.on( 'load', function()
     
    11581162                                },
    11591163
    11601164                                /**
     1165                                 * Sets the action to given value.
     1166                                 * @param {String} value The new action.
     1167                                 * @returns {CKEDITOR.ui.dialog.file} This object.
     1168                                 * @example
     1169                                 */
     1170                                setAction : function( action )
     1171                                {
     1172                                        this.getInputElement().getParent().$.action = action;
     1173                                        return this;
     1174                                },
     1175
     1176                                /**
     1177                                 * Get the action assigned to the form.
     1178                                 * @returns {String} The value of the action.
     1179                                 * @example
     1180                                 */
     1181                                getAction : function( action )
     1182                                {
     1183                                        return this.getInputElement().getParent().$.action;
     1184                                },
     1185
     1186                                /**
    11611187                                 * Redraws the file input and resets the file path in the file input.
    11621188                                 * The redraw logic is necessary because non-IE browsers tend to clear
    11631189                                 * the &lt;iframe&gt; containing the file input after closing the dialog.
    11641190                                 * @example
    11651191                                 */
    1166                                 reset : function()
     1192                                reset : function( action )
    11671193                                {
    11681194                                        var frameElement = CKEDITOR.document.getById( this._.frameId ),
    11691195                                                frameDocument = frameElement.$.contentWindow.document,
     
    11721198                                        frameDocument.open();
    11731199                                        frameDocument.write( [ '<html><head><title></title></head><body style="margin: 0; overflow: hidden; background: transparent;">',
    11741200                                                        '<form enctype="multipart/form-data" method="POST" action="',
    1175                                                         CKEDITOR.tools.htmlEncode( elementDefinition.action ),
     1201                                                        CKEDITOR.tools.htmlEncode( action || elementDefinition.action ),
    11761202                                                        '">',
    11771203                                                        '<input type="file" name="',
    11781204                                                        CKEDITOR.tools.htmlEncode( elementDefinition.id || 'cke_upload' ),
  • _source/plugins/filebrowser/_dev/test.html

     
     1<!--
     2/*
     3 * Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4 * For licensing, see LICENSE.html or http://ckeditor.com/license
     5 */
     6-->
     7<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
     8<html xmlns="http://www.w3.org/1999/xhtml">
     9<head>
     10        <title>CKEditor File Manager - Connector Tests</title>
     11        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     12        <script type="text/javascript">
     13
     14function BuildBaseUrl( command )
     15{
     16        var sUrl =
     17                document.getElementById('cmbConnector').value +
     18                '?command=' + command ;
     19
     20        if ( command != 'Init' )
     21        {
     22                sUrl +=
     23                        '&type=' + document.getElementById('cmbType').value +
     24                        '&currentFolder=' + encodeURIComponent( document.getElementById('txtFolder').value ) ;
     25        }
     26
     27        return sUrl ;
     28}
     29
     30function SetFrameUrl( url )
     31{
     32        if ( document.all )
     33                eRunningFrame.document.location = url ;
     34        else
     35                document.getElementById('eRunningFrame').src = url ;
     36
     37        document.getElementById('eUrl').value = url ;
     38}
     39
     40function CallUrlField()
     41{
     42        SetFrameUrl( document.getElementById('eUrl').value ) ;
     43        return false ;
     44}
     45
     46function Init()
     47{
     48        SetFrameUrl( BuildBaseUrl( 'Init' ) ) ;
     49        return false ;
     50}
     51
     52function GetFolders()
     53{
     54        SetFrameUrl( BuildBaseUrl( 'GetFolders' ) ) ;
     55        return false ;
     56}
     57
     58function GetFoldersAndFiles()
     59{
     60        SetFrameUrl( BuildBaseUrl( 'GetFoldersAndFiles' ) ) ;
     61        return false ;
     62}
     63
     64function OnUploadCompleted( errorNumber, fileUrl, fileName )
     65{
     66        // QuickUpload uses 3 parameters and the order is different than the FileUpload
     67        if ( !fileName )
     68                fileName = fileUrl ;
     69
     70        switch ( errorNumber )
     71        {
     72                case 0 :
     73                        alert( 'File uploaded with no errors' ) ;
     74                        break ;
     75                case 201 :
     76                        alert( 'A file with the same name is already available. The uploaded file has been renamed to "' + fileName + '"' ) ;
     77                        break ;
     78                case 202 :
     79                        alert( 'Invalid file' ) ;
     80                        break ;
     81                case 500 :
     82                        alert( 'The connector is disabled' ) ;
     83                        break ;
     84                default :
     85                        alert( 'Error on file upload. Error number: ' + errorNumber ) ;
     86                        break ;
     87        }
     88}
     89
     90this.frames.frmUpload = this ;
     91
     92function SetCreateFolderAction()
     93{
     94        var sUrl = BuildBaseUrl( 'CreateFolder' ) ;
     95        document.getElementById('eUrl').value = sUrl ;
     96        document.getElementById('frmCreateFolder').action = sUrl ;   
     97}
     98
     99function SetAction()
     100{
     101        var sUrl = BuildBaseUrl( 'FileUpload' ) ;
     102        document.getElementById('eUrl').value = sUrl ;
     103        document.getElementById('frmUpload').action = sUrl ;
     104}
     105
     106function SetQuickAction()
     107{
     108        var sUrl = BuildBaseUrl( 'QuickUpload' ) ;
     109        document.getElementById('eUrl').value = sUrl ;
     110        document.getElementById('frmQuickUpload').action = sUrl ;
     111}
     112        </script>
     113</head>
     114<body>
     115        <table cellspacing="0" cellpadding="0" width="100%" border="0" style="height: 100%">
     116                <tr>
     117                        <td>
     118                                <table cellspacing="0" cellpadding="0" border="0">
     119                                        <tr>
     120                                                <td>
     121                                                        Connector:<br />
     122                                                        <select id="cmbConnector" name="cmbConnector">
     123                                                                <option value="../core/connector/asp/connector.asp">ASP</option>
     124                                                                <option value="../core/connector/aspx/connector.aspx">ASP.NET</option>
     125                                                                <option value="../core/connector/cfm/connector.cfm">CFM</option>
     126                                                                <option value="../core/connector/php/connector.php" selected="selected">PHP</option>
     127                                                        </select>
     128                                                </td>
     129                                                <td>
     130                                                        &nbsp;&nbsp;&nbsp;</td>
     131                                                <td>
     132                                                        Current Folder<br />
     133                                                        <input id="txtFolder" type="text" value="/" name="txtFolder" /></td>
     134                                                <td>
     135                                                        &nbsp;&nbsp;&nbsp;</td>
     136                                                <td>
     137                                                        Resource Type<br />
     138                                                        <select id="cmbType" name="cmbType">
     139                                                                <option value="Files" selected="selected">File</option>
     140                                                                <option value="Images">Image</option>
     141                                                                <option value="Flash">Flash</option>
     142                                                                <option value="Invalid">Invalid Type (for testing)</option>
     143                                                        </select>
     144                                                </td>
     145                                        </tr>
     146                                </table>
     147                                <br />
     148                                <table cellspacing="0" cellpadding="0" border="0">
     149                                        <tr>
     150                                                <td valign="top">
     151                                                        <a href="#" onclick="Init();">Init</a>
     152                                                </td>
     153                                                <td>&nbsp;&nbsp;&nbsp;</td>
     154                                                <td valign="top">
     155                                                        <a href="#" onclick="GetFolders();">Get Folders</a>
     156                                                </td>
     157                                                <td>&nbsp;&nbsp;&nbsp;</td>
     158                                                <td valign="top">
     159                                                        <a href="#" onclick="GetFoldersAndFiles();">Get Folders And Files</a>
     160                                                </td>
     161                                                <td>&nbsp;&nbsp;&nbsp;</td>
     162                                                <td valign="top">
     163                                                        <form id="frmCreateFolder" action="" target="eRunningFrame" method="post" enctype="multipart/form-data">
     164                                                                Create Folder
     165                                                                <input id="txtFolderName" type="text" name="newFolderName" />
     166                                                                <input type="submit" value="Create" onclick="SetCreateFolderAction();" />
     167                                                        </form>
     168                                                </td>
     169                                                <td>&nbsp;&nbsp;&nbsp;</td>
     170                                                <td valign="top">
     171                                                        <form id="frmUpload" action="" target="eRunningFrame" method="post" enctype="multipart/form-data">
     172                                                                Upload
     173                                                                <input id="txtFileUpload" type="file" name="NewFile" />
     174                                                                <input type="submit" value="Upload" onclick="SetAction();" />
     175                                                        </form>
     176
     177                                                        <form id="frmQuickUpload" action="" target="eRunningFrame" method="post" enctype="multipart/form-data">
     178                                                                Quick
     179                                                                <input id="txtQuickUpload" type="file" name="NewFile" />
     180                                                                <input type="submit" value="Upload" onclick="SetQuickAction();" />
     181                                                        </form>
     182                                                </td>
     183                                        </tr>
     184                                </table>
     185                                <table width="100%">
     186                                        <tr>
     187                                                <td style="white-space: nowrap">
     188                                                        URL:&nbsp;</td>
     189                                                <td style="width: 100%">
     190                                                        <input id="eUrl" style="width: 100%" /></td>
     191                                                <td>
     192                                                        <input id="xBtnUrl" type="button" value="Call URL" onclick="CallUrlField();" /></td>
     193                                        </tr>
     194                                </table>
     195                        </td>
     196                </tr>
     197                <tr>
     198                        <td valign="top" style="height: 100%">
     199                                <iframe id="eRunningFrame" name="eRunningFrame" width="100%" height="100%" src="javascript:''"></iframe>
     200                        </td>
     201                </tr>
     202        </table>
     203</body>
     204</html>
  • _source/plugins/filebrowser/config.php

     
     1<?php
     2/*
     3Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * This function must check the user session to be sure that he/she is
     9 * authorized to upload and access files in the File Browser.
     10 *
     11 * @return boolean
     12 */
     13function CheckAuthentication()
     14{
     15    // WARNING : DO NOT simply return "true". By doing so, you are allowing
     16    // "anyone" to upload and list the files in your server. You must implement
     17    // some kind of session validation here. Even something very simple as...
     18    //
     19    // return isset($_SESSION['IsAuthorized']) && $_SESSION['IsAuthorized'];
     20    //
     21    // ... where $_SESSION['IsAuthorized'] is set to "true" as soon as the
     22    // user logs in your system.
     23
     24    // %REMOVE_START%
     25    // Attention: In the development version (SVN) the PHP connector is enabled by default.
     26    return true;
     27    // %REMOVE_END%
     28    return false;
     29}
     30
     31// To make it easy to configure CKEditor file manager, the $baseUrl and $baseDir can be used.
     32// Those are helper variables used later in this config file.
     33
     34// $baseUrl : the base path used to build the final URL for the resources handled
     35// in CKEditor. If empty, the default value (/userfiles/) is used.
     36//
     37// Examples:
     38//  $baseUrl = 'http://example.com/userfiles/';
     39//  $baseUrl = '/userfiles/';
     40//
     41// ATTENTION: The trailing slash is required.
     42$baseUrl = '/userfiles/';
     43
     44// $baseDir : the path to the local directory (in the server) which points to the
     45// above $baseUrl URL. This is the path used by CKEditor to handle the files in
     46// the server. Full write permissions must be granted to this directory.
     47//
     48// Examples:
     49// You may point it to a directory directly:
     50//
     51//  $baseDir = '/home/login/public_html/userfiles/';
     52//  $baseDir = 'C:/SiteDir/userfiles/';
     53//
     54// Or you may let CKEditor discover the path, based on $baseUrl:
     55//
     56//  $baseDir = resolveUrl($baseUrl);
     57//
     58// ATTENTION: The trailing slash is required.
     59$baseDir = resolveUrl($baseUrl);
     60$baseDir = 'D:/xampp/htdocs/userfiles/'; //%REMOVE_LINE%
     61
     62// ResourceType : defines the "resource types" handled in CKEditor. A resource
     63// type is nothing more than a way to group files under different paths, each one
     64// having different configuration settings.
     65$config['ResourceType'][] = Array(
     66    'name' => 'Files', // Single quotes not allowed
     67    'url' => $baseUrl . 'files',
     68    'directory' => $baseDir . 'files',
     69    'allowedExtensions' => '7z,aiff,asf,avi,bmp,csv,doc,fla,flv,gif,gz,gzip,jpeg,jpg,mid,mov,mp3,mp4,mpc,mpeg,mpg,ods,odt,pdf,png,ppt,pxd,qt,ram,rar,rm,rmi,rmvb,rtf,sdc,sitd,swf,sxc,sxw,tar,tgz,tif,tiff,txt,vsd,wav,wma,wmv,xls,zip',
     70    'deniedExtensions' => ''
     71);
     72
     73$config['ResourceType'][] = Array(
     74    'name' => 'Images',
     75    'url' => $baseUrl . 'images',
     76    'directory' => $baseDir . 'images',
     77    'allowedExtensions' => 'bmp,gif,jpeg,jpg,png',
     78    'deniedExtensions' => ''
     79);
     80
     81$config['ResourceType'][] = Array(
     82    'name' => 'Flash',
     83    'url' => $baseUrl . 'flash',
     84    'directory' => $baseDir . 'flash',
     85    'allowedExtensions' => 'swf,flv',
     86    'deniedExtensions' => ''
     87);
     88
     89// Due to security issues with Apache modules, it is recommended to leave the
     90// following setting enabled.
     91$config['ForceSingleExtension'] = true ;
     92
     93// Perform additional checks for image files.
     94// If set to true, validate image size (using getimagesize).
     95$config['SecureImageUploads'] = true;
     96
     97// For security, HTML is allowed in the first Kb of data for files having the
     98// following extensions only.
     99$config['HtmlExtensions'] = array("html", "htm", "xml", "xsd", "txt", "js") ;
     100
     101// After file is uploaded, sometimes it is required to change its permissions
     102// so that it was possible to access it at the later time.
     103// If possible, it is recommended to set more restrictive permissions, like 0755.
     104// Set to 0 to disable this feature.
     105// Note: not needed on Windows-based servers.
     106$config['ChmodFiles'] = 0777 ;
     107
     108// See comments above.
     109// Used when creating folders that does not exist.
     110$config['ChmodFolders'] = 0755 ;
     111
     112// If you have iconv enabled (visit http://php.net/iconv for more information),
     113// you can use this directive to specify the encoding of file names in your
     114// operating system. Acceptable values can be found at:
     115//  http://www.gnu.org/software/libiconv/
     116//
     117// Examples:
     118//  $config['FilesystemEncoding'] = 'CP1250';
     119//  $config['FilesystemEncoding'] = 'ISO-8859-2';
     120$config['FilesystemEncoding'] = 'UTF-8';
     121$config['FilesystemEncoding'] = 'CP1250'; //%REMOVE_LINE%
     122 No newline at end of file
  • _source/plugins/filebrowser/core/connector/php/connector.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * define required constants
     9 */
     10require_once "./constants.php";
     11
     12/**
     13 * we need this class in each call
     14 */
     15require_once CKEDITOR_CONNECTOR_LIB_DIR . "/CommandHandler/CommandHandlerBase.php";
     16/**
     17 * singleton factory
     18 */
     19require_once CKEDITOR_CONNECTOR_LIB_DIR . "/Core/Factory.php";
     20/**
     21 * utils class
     22 */
     23require_once CKEDITOR_CONNECTOR_LIB_DIR . "/Utils/Misc.php";
     24
     25/**
     26 * Simple function required by config.php - discover the server side path
     27 * to the directory relative to the "$baseUrl" attribute
     28 *
     29 * @package CKEditor
     30 * @subpackage Connector
     31 * @param string $baseUrl
     32 * @return string
     33 */
     34function resolveUrl($baseUrl) {
     35    $fileSystem =& CKEditor_Connector_Core_Factory::getInstance("Utils_FileSystem");
     36    return $fileSystem->getDocumentRootPath() . $baseUrl;
     37}
     38
     39$utilsSecurity =& CKEditor_Connector_Core_Factory::getInstance("Utils_Security");
     40$utilsSecurity->getRidOfMagicQuotes();
     41
     42/**
     43 * $config must be initialised
     44 */
     45$config = array();
     46/**
     47 * read config file
     48 */
     49require_once CKEDITOR_CONNECTOR_CONFIG_FILE_PATH;
     50
     51CKEditor_Connector_Core_Factory::initFactory();
     52$connector =& CKEditor_Connector_Core_Factory::getInstance("Core_Connector");
     53
     54if (isset($_GET['command'])) {
     55    $connector->executeCommand($_GET['command']);
     56}
     57else {
     58    $connector->handleInvalidCommand();
     59}
  • _source/plugins/filebrowser/core/connector/php/constants.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * No errors
     9 */
     10define('CKEDITOR_CONNECTOR_ERROR_NONE',0);
     11define('CKEDITOR_CONNECTOR_ERROR_CUSTOM_ERROR',1);
     12define('CKEDITOR_CONNECTOR_ERROR_INVALID_COMMAND',10);
     13define('CKEDITOR_CONNECTOR_ERROR_TYPE_NOT_SPECIFIED',11);
     14define('CKEDITOR_CONNECTOR_ERROR_INVALID_TYPE',12);
     15define('CKEDITOR_CONNECTOR_ERROR_INVALID_NAME',102);
     16define('CKEDITOR_CONNECTOR_ERROR_UNAUTHORIZED',103);
     17define('CKEDITOR_CONNECTOR_ERROR_ACCESS_DENIED',104);
     18define('CKEDITOR_CONNECTOR_ERROR_INVALID_EXTENSION',105);
     19define('CKEDITOR_CONNECTOR_ERROR_INVALID_REQUEST',109);
     20define('CKEDITOR_CONNECTOR_ERROR_UNKNOWN',110);
     21define('CKEDITOR_CONNECTOR_ERROR_ALREADY_EXIST',115);
     22define('CKEDITOR_CONNECTOR_ERROR_FOLDER_NOT_FOUND',116);
     23define('CKEDITOR_CONNECTOR_ERROR_FILE_NOT_FOUND',117);
     24define('CKEDITOR_CONNECTOR_ERROR_UPLOADED_FILE_RENAMED',201);
     25define('CKEDITOR_CONNECTOR_ERROR_UPLOADED_INVALID',202);
     26define('CKEDITOR_CONNECTOR_ERROR_UPLOADED_TOO_BIG',203);
     27define('CKEDITOR_CONNECTOR_ERROR_UPLOADED_CORRUPT',204);
     28define('CKEDITOR_CONNECTOR_ERROR_UPLOADED_NO_TMP_DIR',205);
     29define('CKEDITOR_CONNECTOR_ERROR_UPLOADED_WRONG_HTML_FILE',206);
     30define('CKEDITOR_CONNECTOR_ERROR_CONNECTOR_DISABLED',500);
     31
     32define('CKEDITOR_CONNECTOR_DEFAULT_USER_FILES_PATH', "/userfiles/");
     33define('CKEDITOR_CONNECTOR_CONFIG_FILE_PATH', "./../../../config.php");
     34
     35if (version_compare(phpversion(), '6', '>=')) {
     36    define('CKEDITOR_CONNECTOR_PHP_MODE', 6);
     37}
     38else if (version_compare(phpversion(), '5', '>=')) {
     39    define('CKEDITOR_CONNECTOR_PHP_MODE', 5);
     40}
     41else {
     42    define('CKEDITOR_CONNECTOR_PHP_MODE', 4);
     43}
     44
     45if (CKEDITOR_CONNECTOR_PHP_MODE == 4) {
     46    define('CKEDITOR_CONNECTOR_LIB_DIR', "./php4");
     47} else {
     48    define('CKEDITOR_CONNECTOR_LIB_DIR', "./php5");
     49}
     50
     51define('CKEDITOR_REGEX_IMAGES_EXT', '/\.(jpg|gif|png|bmp|jpeg)$/i');
  • _source/plugins/filebrowser/core/connector/php/php4/CommandHandler/CommandHandlerBase.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage CommandHandlers
     10 */
     11
     12/**
     13 * Base commands handler
     14 *
     15 * @package CKEditor
     16 * @subpackage CommandHandlers
     17 * @abstract
     18 */
     19class CKEditor_Connector_CommandHandler_CommandHandlerBase
     20{
     21    /**
     22     * CKEditor_Connector_Core_Connector object
     23     *
     24     * @access protected
     25     * @var CKEditor_Connector_Core_Connector
     26     */
     27    var $_connector;
     28    /**
     29     * CKEditor_Connector_Core_FolderHandler object
     30     *
     31     * @access protected
     32     * @var CKEditor_Connector_Core_FolderHandler
     33     */
     34    var $_currentFolder;
     35    /**
     36     * Error handler object
     37     *
     38     * @access protected
     39     * @var CKEditor_Connector_ErrorHandler_Base|CKEditor_Connector_ErrorHandler_FileUpload|CKEditor_Connector_ErrorHandler_Http
     40     */
     41    var $_errorHandler;
     42
     43    function CKEditor_Connector_CommandHandler_CommandHandlerBase()
     44    {
     45        $this->_currentFolder =& CKEditor_Connector_Core_Factory::getInstance("Core_FolderHandler");
     46        $this->_connector =& CKEditor_Connector_Core_Factory::getInstance("Core_Connector");
     47        $this->_errorHandler =& $this->_connector->getErrorHandler();
     48    }
     49
     50    /**
     51     * Get Folder Handler
     52     *
     53     * @access public
     54     * @return CKEditor_Connector_Core_FolderHandler
     55     */
     56    function getFolderHandler()
     57    {
     58        if (is_null($this->_currentFolder)) {
     59            $this->_currentFolder =& CKEditor_Connector_Core_Factory::getInstance("Core_FolderHandler");
     60        }
     61
     62        return $this->_currentFolder;
     63    }
     64
     65    /**
     66     * Check whether Connector is enabled
     67     * @access protected
     68     *
     69     */
     70    function checkConnector()
     71    {
     72        $_config =& CKEditor_Connector_Core_Factory::getInstance("Core_Config");
     73        if (!$_config->getIsEnabled()) {
     74            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_CONNECTOR_DISABLED);
     75        }
     76    }
     77
     78    /**
     79     * Check request
     80     * @access protected
     81     *
     82     */
     83    function checkRequest()
     84    {
     85        if (preg_match(",(/\.)|[[:cntrl:]]|(//)|(\\\\)|([\:\*\?\"\<\>\|]),", $this->_currentFolder->getClientPath())) {
     86            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_INVALID_NAME);
     87        }
     88
     89        $_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig();
     90
     91        if (is_null($_resourceTypeConfig)) {
     92            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_INVALID_TYPE);
     93        }
     94
     95        $_clientPath = $this->_currentFolder->getClientPath();
     96
     97        if (!is_dir($this->_currentFolder->getServerPath())) {
     98            if ($_clientPath == "/") {
     99                if (!CKEditor_Connector_Utils_FileSystem::createDirectoryRecursively($this->_currentFolder->getServerPath())) {
     100                    /**
     101                     * @todo handle error
     102                     */
     103                }
     104            }
     105            else {
     106                $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_FOLDER_NOT_FOUND);
     107            }
     108        }
     109    }
     110}
     111 No newline at end of file
  • _source/plugins/filebrowser/core/connector/php/php4/CommandHandler/CreateFolder.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage CommandHandlers
     10 */
     11
     12/**
     13 * Include base XML command handler
     14 */
     15require_once CKEDITOR_CONNECTOR_LIB_DIR . "/CommandHandler/XmlCommandHandlerBase.php";
     16
     17/**
     18 * Handle CreateFolder command
     19 *
     20 * @package CKEditor
     21 * @subpackage CommandHandlers
     22 */
     23class CKEditor_Connector_CommandHandler_CreateFolder extends CKEditor_Connector_CommandHandler_XmlCommandHandlerBase
     24{
     25    /**
     26     * Command name
     27     *
     28     * @access private
     29     * @var string
     30     */
     31    var $command = "CreateFolder";
     32
     33    /**
     34     * handle request and build XML
     35     * @access protected
     36     *
     37     */
     38    function buildXml()
     39    {
     40        $_config =& CKEditor_Connector_Core_Factory::getInstance("Core_Config");
     41
     42        $_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig();
     43        $sNewFolderName = isset($_POST["newFolderName"]) ? $_POST["newFolderName"] : "";
     44        $sNewFolderName = CKEditor_Connector_Utils_FileSystem::convertToFilesystemEncoding($sNewFolderName);
     45
     46        if (!CKEditor_Connector_Utils_FileSystem::checkFileName($sNewFolderName)) {
     47            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_INVALID_NAME);
     48        }
     49
     50        $sServerDir = CKEditor_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $sNewFolderName);
     51        if (!is_writeable($this->_currentFolder->getServerPath())) {
     52            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_ACCESS_DENIED);
     53        }
     54
     55        $bCreated = false;
     56
     57        if (file_exists($sServerDir)) {
     58            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_ALREADY_EXIST);
     59        }
     60
     61        if ($perms = $_config->getChmodFolders()) {
     62            $oldUmask = umask(0);
     63            $bCreated = @mkdir($sServerDir, $perms);
     64            umask($oldUmask);
     65        }
     66        else {
     67            $bCreated = @mkdir($sServerDir);
     68        }
     69
     70        if (!$bCreated) {
     71            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_ACCESS_DENIED);
     72        } else {
     73            $oNewFolderNode = new CKEditor_Connector_Utils_XmlNode("NewFolder");
     74            $this->_connectorNode->addChild($oNewFolderNode);
     75            $oNewFolderNode->addAttribute("name", CKEditor_Connector_Utils_FileSystem::convertToConnectorEncoding($sNewFolderName));
     76        }
     77    }
     78}
     79 No newline at end of file
  • _source/plugins/filebrowser/core/connector/php/php4/CommandHandler/FileUpload.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage CommandHandlers
     10 */
     11
     12/**
     13 * Handle FileUpload command
     14 *
     15 * @package CKEditor
     16 * @subpackage CommandHandlers
     17 */
     18class CKEditor_Connector_CommandHandler_FileUpload extends CKEditor_Connector_CommandHandler_CommandHandlerBase
     19{
     20    /**
     21     * Command name
     22     *
     23     * @access protected
     24     * @var string
     25     */
     26    var $command = "FileUpload";
     27
     28    /**
     29     * send response (save uploaded file)
     30     * @access public
     31     *
     32     */
     33    function sendResponse()
     34    {
     35        $iErrorNumber = CKEDITOR_CONNECTOR_ERROR_NONE;
     36
     37        $oRegistry =& CKEditor_Connector_Core_Factory::getInstance("Core_Registry");
     38        $oRegistry->set("FileUpload_fileName", "unknown file");
     39
     40        $uploadedFile = array_shift($_FILES);
     41
     42        if (!isset($uploadedFile['name'])) {
     43            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_UPLOADED_INVALID);
     44        }
     45
     46        $sFileName = CKEditor_Connector_Utils_FileSystem::convertToFilesystemEncoding(basename($uploadedFile['name']));
     47        $oRegistry->set("FileUpload_fileName", $sFileName);
     48
     49        $this->checkConnector();
     50        $this->checkRequest();
     51
     52        if (!CKEditor_Connector_Utils_FileSystem::checkFileName($sFileName)) {
     53            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_INVALID_NAME);
     54        }
     55
     56        $_config =& CKEditor_Connector_Core_Factory::getInstance("Core_Config");
     57        $_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig();
     58
     59        $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig();
     60        if (!$resourceTypeInfo->checkExtension($sFileName)) {
     61            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_INVALID_EXTENSION);
     62        }
     63
     64        $sFileNameOrginal = $sFileName;
     65        $oRegistry->set("FileUpload_fileName", $sFileName);
     66
     67        $htmlExtensions = $_config->getHtmlExtensions();
     68        $sExtension = CKEditor_Connector_Utils_FileSystem::getExtension($sFileNameOrginal);
     69
     70        if ($htmlExtensions
     71        && !CKEditor_Connector_Utils_Misc::inArrayCaseInsensitive($sExtension, $htmlExtensions)
     72        && ($detectHtml = CKEditor_Connector_Utils_FileSystem::detectHtml($uploadedFile['tmp_name'])) === true ) {
     73            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_UPLOADED_WRONG_HTML_FILE);
     74        }
     75
     76        $sExtension = CKEditor_Connector_Utils_FileSystem::getExtension($sFileNameOrginal);
     77        $secureImageUploads = $_config->getSecureImageUploads();
     78        if ($secureImageUploads
     79        && ($isImageValid = CKEditor_Connector_Utils_FileSystem::isImageValid($uploadedFile['tmp_name'], $sExtension)) === false ) {
     80            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_UPLOADED_CORRUPT);
     81        }
     82
     83        switch ($uploadedFile['error']) {
     84            case UPLOAD_ERR_OK:
     85                break;
     86
     87            case UPLOAD_ERR_INI_SIZE:
     88            case UPLOAD_ERR_FORM_SIZE:
     89                $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_UPLOADED_TOO_BIG);
     90                break;
     91
     92            case UPLOAD_ERR_PARTIAL:
     93            case UPLOAD_ERR_NO_FILE:
     94                $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_UPLOADED_CORRUPT);
     95                break;
     96
     97            case UPLOAD_ERR_NO_TMP_DIR:
     98                $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_UPLOADED_NO_TMP_DIR);
     99                break;
     100
     101            case UPLOAD_ERR_CANT_WRITE:
     102                $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_ACCESS_DENIED);
     103                break;
     104
     105            case UPLOAD_ERR_EXTENSION:
     106                $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_ACCESS_DENIED);
     107                break;
     108        }
     109
     110        $sServerDir = $this->_currentFolder->getServerPath();
     111        $iCounter = 0;
     112
     113        while (true)
     114        {
     115            $sFilePath = CKEditor_Connector_Utils_FileSystem::combinePaths($sServerDir, $sFileName);
     116
     117            if (file_exists($sFilePath)) {
     118                $iCounter++;
     119                $sFileName =
     120                CKEditor_Connector_Utils_FileSystem::getFileNameWithoutExtension($sFileNameOrginal) .
     121                "(" . $iCounter . ")" . "." .
     122                CKEditor_Connector_Utils_FileSystem::getExtension($sFileNameOrginal);
     123                $oRegistry->set("FileUpload_fileName", $sFileName);
     124
     125                $iErrorNumber = CKEDITOR_CONNECTOR_ERROR_UPLOADED_FILE_RENAMED;
     126            } else {
     127                if (false === move_uploaded_file($uploadedFile['tmp_name'], $sFilePath)) {
     128                    $iErrorNumber = CKEDITOR_CONNECTOR_ERROR_ACCESS_DENIED;
     129                }
     130                else {
     131                    if (isset($detectHtml) && $detectHtml === -1 && CKEditor_Connector_Utils_FileSystem::detectHtml($sFilePath) === true) {
     132                        @unlink($sFilePath);
     133                        $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_UPLOADED_WRONG_HTML_FILE);
     134                    }
     135                    else if (isset($isImageValid) && $isImageValid === -1 && CKEditor_Connector_Utils_FileSystem::isImageValid($sFilePath, $sExtension) === false) {
     136                        @unlink($sFilePath);
     137                        $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_UPLOADED_CORRUPT);
     138                    }
     139                }
     140                if (is_file($sFilePath) && ($perms = $_config->getChmodFiles())) {
     141                    $oldumask = umask(0);
     142                    chmod($sFilePath, $perms);
     143                    umask($oldumask);
     144                }
     145                break;
     146            }
     147        }
     148
     149        $this->_errorHandler->throwError($iErrorNumber, $sFileName, false);
     150    }
     151}
  • _source/plugins/filebrowser/core/connector/php/php4/CommandHandler/GetFolders.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage CommandHandlers
     10 */
     11
     12/**
     13 * Include base XML command handler
     14 */
     15require_once CKEDITOR_CONNECTOR_LIB_DIR . "/CommandHandler/XmlCommandHandlerBase.php";
     16
     17/**
     18 * Handle GetFolders command
     19 *
     20 * @package CKEditor
     21 * @subpackage CommandHandlers
     22 */
     23class CKEditor_Connector_CommandHandler_GetFolders extends CKEditor_Connector_CommandHandler_XmlCommandHandlerBase
     24{
     25    /**
     26     * Command name
     27     *
     28     * @access private
     29     * @var string
     30     */
     31    var $command = "GetFolders";
     32
     33    /**
     34     * handle request and build XML
     35     * @access protected
     36     *
     37     */
     38    function buildXml()
     39    {
     40        $_config =& CKEditor_Connector_Core_Factory::getInstance("Core_Config");
     41
     42        // Map the virtual path to the local server path.
     43        $_sServerDir = $this->_currentFolder->getServerPath();
     44
     45        if (!is_dir($_sServerDir)) {
     46            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_FOLDER_NOT_FOUND);
     47        }
     48
     49        // Create the "Folders" node.
     50        $oFoldersNode = new CKEditor_Connector_Utils_XmlNode("Folders");
     51        $this->_connectorNode->addChild($oFoldersNode);
     52
     53        $files = array();
     54        if ($dh = @opendir($_sServerDir)) {
     55            while (($file = readdir($dh)) !== false) {
     56                if ($file != "." && $file != ".." && is_dir($_sServerDir . $file)) {
     57                    $files[] = $file;
     58                }
     59            }
     60            closedir($dh);
     61        } else {
     62            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_ACCESS_DENIED);
     63        }
     64
     65        $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig();
     66
     67        if (sizeof($files)>0) {
     68            natcasesort($files);
     69            $i=0;
     70            foreach ($files as $file) {
     71                // Create the "Folder" node.
     72                $oFolderNode[$i] = new CKEditor_Connector_Utils_XmlNode("Folder");
     73                $oFoldersNode->addChild($oFolderNode[$i]);
     74                $oFolderNode[$i]->addAttribute("name", CKEditor_Connector_Utils_FileSystem::convertToConnectorEncoding($file));
     75
     76                $i++;
     77            }
     78        }
     79    }
     80}
  • _source/plugins/filebrowser/core/connector/php/php4/CommandHandler/GetFoldersAndFiles.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage CommandHandlers
     10 */
     11
     12/**
     13 * Include base XML command handler
     14 */
     15require_once CKEDITOR_CONNECTOR_LIB_DIR . "/CommandHandler/XmlCommandHandlerBase.php";
     16
     17/**
     18 * Handle GetFiles command
     19 *
     20 * @package CKEditor
     21 * @subpackage CommandHandlers
     22 */
     23class CKEditor_Connector_CommandHandler_GetFoldersAndFiles extends CKEditor_Connector_CommandHandler_XmlCommandHandlerBase
     24{
     25    /**
     26     * Command name
     27     *
     28     * @access private
     29     * @var string
     30     */
     31    var $command = "GetFiles";
     32
     33    /**
     34     * handle request and build XML
     35     * @access protected
     36     *
     37     */
     38    function buildXml()
     39    {
     40        $_config =& CKEditor_Connector_Core_Factory::getInstance("Core_Config");
     41
     42        // Map the virtual path to the local server path.
     43        $_sServerDir = $this->_currentFolder->getServerPath();
     44
     45        $files = array();
     46        $folders = array();
     47        if ($dh = @opendir($_sServerDir)) {
     48            while (($file = readdir($dh)) !== false) {
     49                if ($file == "." || $file == "..") {
     50                    continue;
     51                }
     52                else if (!is_dir($_sServerDir . $file)) {
     53                    $files[] = $file;
     54                }
     55                else {
     56                    $folders[] = $file;
     57                }
     58            }
     59            closedir($dh);
     60        }
     61        else {
     62            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_ACCESS_DENIED);
     63        }
     64
     65        // Create the "Folders" node.
     66        $oFoldersNode = new CKEditor_Connector_Utils_XmlNode("Folders");
     67        $this->_connectorNode->addChild($oFoldersNode);
     68
     69
     70        $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig();
     71
     72        if (sizeof($folders)>0) {
     73            natcasesort($folders);
     74            $i=0;
     75            foreach ($folders as $file) {
     76                // Create the "Folder" node.
     77                $oFolderNode[$i] = new CKEditor_Connector_Utils_XmlNode("Folder");
     78                $oFoldersNode->addChild($oFolderNode[$i]);
     79                $oFolderNode[$i]->addAttribute("name", CKEditor_Connector_Utils_FileSystem::convertToConnectorEncoding($file));
     80
     81                $i++;
     82            }
     83        }
     84
     85        // Create the "Files" node.
     86        $oFilesNode = new CKEditor_Connector_Utils_XmlNode("Files");
     87        $this->_connectorNode->addChild($oFilesNode);
     88
     89        if (!is_dir($_sServerDir)) {
     90            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_FOLDER_NOT_FOUND);
     91        }
     92
     93        if (sizeof($files)>0) {
     94            natcasesort($files);
     95            $i=0;
     96            foreach ($files as $file) {
     97                $filemtime = @filemtime($_sServerDir . $file);
     98
     99                //otherwise file doesn't exist or we can't get it's filename properly
     100                if ($filemtime !== false) {
     101                    $filename = basename($file);
     102                    if (!$resourceTypeInfo->checkExtension($filename, false)) {
     103                        continue;
     104                    }
     105                    $oFileNode[$i] = new CKEditor_Connector_Utils_XmlNode("File");
     106                    $oFilesNode->addChild($oFileNode[$i]);
     107                    $oFileNode[$i]->addAttribute("name", CKEditor_Connector_Utils_FileSystem::convertToConnectorEncoding(basename($file)));
     108                    $oFileNode[$i]->addAttribute("date", @date("YmdHi", $filemtime));
     109                    $size = filesize($_sServerDir . $file);
     110                    if ($size && $size<1024) {
     111                        $size = 1;
     112                    }
     113                    else {
     114                        $size = (int)round($size / 1024);
     115                    }
     116                    $oFileNode[$i]->addAttribute("size", $size);
     117                    $i++;
     118                }
     119            }
     120        }
     121    }
     122}
  • _source/plugins/filebrowser/core/connector/php/php4/CommandHandler/Init.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage CommandHandlers
     10 */
     11
     12/**
     13 * Include base XML command handler
     14 */
     15require_once CKEDITOR_CONNECTOR_LIB_DIR . "/CommandHandler/XmlCommandHandlerBase.php";
     16
     17/**
     18 * Handle Init command
     19 *
     20 * @package CKEditor
     21 * @subpackage CommandHandlers
     22 */
     23class CKEditor_Connector_CommandHandler_Init extends CKEditor_Connector_CommandHandler_XmlCommandHandlerBase
     24{
     25    /**
     26     * Command name
     27     *
     28     * @access private
     29     * @var string
     30     */
     31    var $command = "Init";
     32
     33    function mustCheckRequest()
     34    {
     35        return false;
     36    }
     37
     38    /**
     39     * Must add CurrentFolder node?
     40     *
     41     * @return boolean
     42     * @access protected
     43     */
     44    function mustAddCurrentFolderNode()
     45    {
     46        return false;
     47    }
     48
     49    /**
     50     * handle request and build XML
     51     * @access protected
     52     *
     53     */
     54    function buildXml()
     55    {
     56        $_config =& CKEditor_Connector_Core_Factory::getInstance("Core_Config");
     57
     58        // Create the "ConnectorInfo" node.
     59        $_oConnInfo = new CKEditor_Connector_Utils_XmlNode("ConnectorInfo");
     60        $this->_connectorNode->addChild($_oConnInfo);
     61        $_oConnInfo->addAttribute("enabled", $_config->getIsEnabled() ? "true" : "false");
     62
     63        if (!$_config->getIsEnabled()) {
     64            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_CONNECTOR_DISABLED);
     65        }
     66
     67        // Create the "ResourceTypes" node.
     68        $_oResourceTypes = new CKEditor_Connector_Utils_XmlNode("ResourceTypes");
     69        $this->_connectorNode->addChild($_oResourceTypes);
     70
     71        // Load the resource types in an array.
     72        $_aTypes = $_config->getDefaultResourceTypes();
     73
     74        if (!sizeof($_aTypes)) {
     75            $_aTypes = $_config->getResourceTypeNames();
     76        }
     77
     78        $_aTypesSize = sizeof($_aTypes);
     79        if ($_aTypesSize) {
     80            for ($i = 0; $i < $_aTypesSize; $i++)
     81            {
     82                $_resourceTypeName = $_aTypes[$i];
     83
     84                if (!isset($_GET['type']) || $_GET['type'] === $_resourceTypeName) {
     85                    $_oTypeInfo = $_config->getResourceTypeConfig($_resourceTypeName);
     86                    $_oResourceType[$i] = new CKEditor_Connector_Utils_XmlNode("ResourceType");
     87                    $_oResourceTypes->addChild($_oResourceType[$i]);
     88
     89                    $_oResourceType[$i]->addAttribute("name", $_resourceTypeName);
     90                    $_oResourceType[$i]->addAttribute("url", $_oTypeInfo->getUrl());
     91                    $_oResourceType[$i]->addAttribute("allowedExtensions", implode(",", $_oTypeInfo->getAllowedExtensions()));
     92                    $_oResourceType[$i]->addAttribute("deniedExtensions", implode(",", $_oTypeInfo->getDeniedExtensions()));
     93                }
     94            }
     95        }
     96    }
     97}
  • _source/plugins/filebrowser/core/connector/php/php4/CommandHandler/QuickUpload.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage CommandHandlers
     10 */
     11
     12/**
     13 * Include file upload command handler
     14 */
     15require_once CKEDITOR_CONNECTOR_LIB_DIR . "/CommandHandler/FileUpload.php";
     16
     17/**
     18 * Handle QuickUpload command
     19 *
     20 * @package CKEditor
     21 * @subpackage CommandHandlers
     22 */
     23class CKEditor_Connector_CommandHandler_QuickUpload extends CKEditor_Connector_CommandHandler_FileUpload
     24{
     25    /**
     26     * Command name
     27     *
     28     * @access protected
     29     * @var string
     30     */
     31    var $command = "QuickUpload";
     32
     33    function sendResponse()
     34    {
     35        $oRegistry =& CKEditor_Connector_Core_Factory::getInstance("Core_Registry");
     36        $oRegistry->set("FileUpload_url", $this->_currentFolder->getUrl());
     37
     38        return parent::sendResponse();
     39    }
     40}
  • _source/plugins/filebrowser/core/connector/php/php4/CommandHandler/XmlCommandHandlerBase.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage CommandHandlers
     10 */
     11
     12/**
     13 * Include base command handler
     14 */
     15require_once CKEDITOR_CONNECTOR_LIB_DIR . "/CommandHandler/CommandHandlerBase.php";
     16/**
     17 * Include xml utils
     18 */
     19require_once CKEDITOR_CONNECTOR_LIB_DIR . "/Core/Xml.php";
     20
     21/**
     22 * Base XML commands handler
     23 *
     24 * @package CKEditor
     25 * @subpackage CommandHandlers
     26 * @abstract
     27 */
     28abstract class CKEditor_Connector_CommandHandler_XmlCommandHandlerBase extends CKEditor_Connector_CommandHandler_CommandHandlerBase
     29{
     30    /**
     31     * Connector node - CKEditor_Connector_Utils_XmlNode object
     32     *
     33     * @var CKEditor_Connector_Utils_XmlNode
     34     * @access protected
     35     */
     36    var $_connectorNode;
     37
     38    /**
     39     * send response
     40     * @access public
     41     *
     42     */
     43    function sendResponse()
     44    {
     45        $xml =& CKEditor_Connector_Core_Factory::getInstance("Core_Xml");
     46        $this->_connectorNode =& $xml->getConnectorNode();
     47
     48        $this->checkConnector();
     49        if ($this->mustCheckRequest()) {
     50            $this->checkRequest();
     51        }
     52
     53        $resourceTypeName = $this->_currentFolder->getResourceTypeName();
     54        if (!empty($resourceTypeName)) {
     55            $this->_connectorNode->addAttribute("resourceType", $this->_currentFolder->getResourceTypeName());
     56        }
     57
     58        if ($this->mustAddCurrentFolderNode()) {
     59            $_currentFolder = new CKEditor_Connector_Utils_XmlNode("CurrentFolder");
     60            $this->_connectorNode->addChild($_currentFolder);
     61            $_currentFolder->addAttribute("path", CKEditor_Connector_Utils_FileSystem::convertToConnectorEncoding($this->_currentFolder->getClientPath()));
     62
     63            $this->_errorHandler->setCatchAllErros(true);
     64            $_url = $this->_currentFolder->getUrl();
     65            $_currentFolder->addAttribute("url", is_null($_url) ? "" : CKEditor_Connector_Utils_FileSystem::convertToConnectorEncoding($_url));
     66            $this->_errorHandler->setCatchAllErros(false);
     67        }
     68
     69        $this->buildXml();
     70
     71        $_oErrorNode =& $xml->getErrorNode();
     72        $_oErrorNode->addAttribute("number", "0");
     73
     74        echo $this->_connectorNode->asXML();
     75        exit;
     76    }
     77
     78    /**
     79     * Must check request?
     80     *
     81     * @return boolean
     82     * @access protected
     83     */
     84    function mustCheckRequest()
     85    {
     86        return true;
     87    }
     88
     89    /**
     90     * Must add CurrentFolder node?
     91     *
     92     * @return boolean
     93     * @access protected
     94     */
     95    function mustAddCurrentFolderNode()
     96    {
     97        return true;
     98    }
     99
     100    /**
     101     * @access protected
     102     * @abstract
     103     * @return void
     104     */
     105    abstract function buildXml();
     106}
  • _source/plugins/filebrowser/core/connector/php/php4/Core/Config.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage Config
     10 */
     11
     12/**
     13 * Include resource type config class
     14 */
     15require_once CKEDITOR_CONNECTOR_LIB_DIR . "/Core/ResourceTypeConfig.php";
     16
     17/**
     18 * Main config parser
     19 *
     20 *
     21 * @package CKEditor
     22 * @subpackage Config
     23
     24 * @global string $GLOBALS['config']
     25 */
     26class CKEditor_Connector_Core_Config
     27{
     28    /**
     29     * Is CKEditor enabled
     30     *
     31     * @var boolean
     32     * @access private
     33     */
     34    var $_isEnabled = false;
     35    /**
     36     * ResourceType config cache
     37     *
     38     * @var array
     39     * @access private
     40     */
     41    var $_resourceTypeConfigCache = array();
     42    /**
     43     * Array with default resource types names
     44     *
     45     * @access private
     46     * @var array
     47     */
     48    var $_defaultResourceTypes = array();
     49    /**
     50     * Filesystem encoding
     51     *
     52     * @var string
     53     * @access private
     54     */
     55    var $_filesystemEncoding;
     56    /**
     57     * Check double extension
     58     *
     59     * @var boolean
     60     * @access private
     61     */
     62    var $_checkDoubleExtension = true;
     63    /**
     64     * If set to true, validate image size
     65     *
     66     * @var boolean
     67     * @access private
     68     */
     69    var $_secureImageUploads = true;
     70    /**
     71     * For security, HTML is allowed in the first Kb of data for files having the following extensions only
     72     *
     73     * @var array
     74     * @access private
     75     */
     76    var $_htmlExtensions = array('html', 'htm', 'xml', 'xsd', 'txt', 'js');
     77    /**
     78     * Chmod files after upload to the following permission
     79     *
     80     * @var integer
     81     * @access private
     82     */
     83    var $_chmodFiles = 0777;
     84    /**
     85     * Chmod directories after creation
     86     *
     87     * @var integer
     88     * @access private
     89     */
     90    var $_chmodFolders = 0755;
     91
     92    function CKEditor_Connector_Core_Config()
     93    {
     94        $this->loadValues();
     95    }
     96
     97    /**
     98         * Get file system encoding, returns null if encoding is not set
     99         *
     100         * @access public
     101         * @return string
     102         */
     103    function getFilesystemEncoding()
     104    {
     105        return $this->_filesystemEncoding;
     106    }
     107
     108    /**
     109         * Get "secureImageUploads" value
     110         *
     111         * @access public
     112         * @return boolean
     113         */
     114    function getSecureImageUploads()
     115    {
     116        return $this->_secureImageUploads;
     117    }
     118
     119    /**
     120         * Get "htmlExtensions" value
     121         *
     122         * @access public
     123         * @return array
     124         */
     125    function getHtmlExtensions()
     126    {
     127        return $this->_htmlExtensions;
     128    }
     129
     130    /**
     131         * Get "Check double extension" value
     132         *
     133         * @access public
     134         * @return boolean
     135         */
     136    function getCheckDoubleExtension()
     137    {
     138        return $this->_checkDoubleExtension;
     139    }
     140
     141    /**
     142         * Get default resource types
     143         *
     144         * @access public
     145         * @return array()
     146         */
     147    function getDefaultResourceTypes()
     148    {
     149        return $this->_defaultResourceTypes;
     150    }
     151
     152    /**
     153         * Is CKEditor enabled
     154         *
     155         * @access public
     156         * @return boolean
     157         */
     158    function getIsEnabled()
     159    {
     160        return $this->_isEnabled;
     161    }
     162
     163    /**
     164        * Get chmod settings for uploaded files
     165        *
     166        * @access public
     167        * @return integer
     168        */
     169    function getChmodFiles()
     170    {
     171        return $this->_chmodFiles;
     172    }
     173
     174    /**
     175        * Get chmod settings for created directories
     176        *
     177        * @access public
     178        * @return integer
     179        */
     180    function getChmodFolders()
     181    {
     182        return $this->_chmodFolders;
     183    }
     184
     185    /**
     186         * Get resourceTypeName config
     187         *
     188         * @param string $resourceTypeName
     189         * @return CKEditor_Connector_Core_ResourceTypeConfig|null
     190         * @access public
     191         */
     192    function &getResourceTypeConfig($resourceTypeName)
     193    {
     194        $_null = null;
     195
     196        if (isset($this->_resourceTypeConfigCache[$resourceTypeName])) {
     197            return $this->_resourceTypeConfigCache[$resourceTypeName];
     198        }
     199
     200        if (!isset($GLOBALS['config']['ResourceType']) || !is_array($GLOBALS['config']['ResourceType'])) {
     201            return $_null;
     202        }
     203
     204        reset($GLOBALS['config']['ResourceType']);
     205        while (list($_key,$_resourceTypeNode) = each($GLOBALS['config']['ResourceType'])) {
     206            if ($_resourceTypeNode['name'] === $resourceTypeName) {
     207                $this->_resourceTypeConfigCache[$resourceTypeName] = new CKEditor_Connector_Core_ResourceTypeConfig($_resourceTypeNode);
     208
     209                return $this->_resourceTypeConfigCache[$resourceTypeName];
     210            }
     211        }
     212
     213        return $_null;
     214    }
     215
     216    /**
     217     * Load values from config
     218     *
     219     * @access private
     220     */
     221    function loadValues()
     222    {
     223        if (function_exists('CheckAuthentication')) {
     224            $this->_isEnabled = CheckAuthentication();
     225        }
     226        if (isset($GLOBALS['config']['FilesystemEncoding'])) {
     227            $this->_filesystemEncoding = (string)$GLOBALS['config']['FilesystemEncoding'];
     228        }
     229        if (isset($GLOBALS['config']['CheckDoubleExtension'])) {
     230            $this->_checkDoubleExtension = CKEditor_Connector_Utils_Misc::booleanValue($GLOBALS['config']['CheckDoubleExtension']);
     231        }
     232        if (isset($GLOBALS['config']['SecureImageUploads'])) {
     233            $this->_secureImageUploads = CKEditor_Connector_Utils_Misc::booleanValue($GLOBALS['config']['SecureImageUploads']);
     234        }
     235        if (isset($GLOBALS['config']['HtmlExtensions'])) {
     236            $this->_htmlExtensions = (array)$GLOBALS['config']['HtmlExtensions'];
     237        }
     238        if (isset($GLOBALS['config']['ChmodFiles'])) {
     239            $this->_chmodFiles = $GLOBALS['config']['ChmodFiles'];
     240        }
     241        if (isset($GLOBALS['config']['ChmodFolders'])) {
     242            $this->_chmodFolders = $GLOBALS['config']['ChmodFolders'];
     243        }
     244        if (isset($GLOBALS['config']['DefaultResourceTypes'])) {
     245            $_defaultResourceTypes = (string)$GLOBALS['config']['DefaultResourceTypes'];
     246            if (strlen($_defaultResourceTypes)) {
     247                $this->_defaultResourceTypes = explode(",", $_defaultResourceTypes);
     248            }
     249        }
     250    }
     251
     252    /**
     253     * Get all resource type names defined in config
     254     *
     255     * @return array
     256     * @access public
     257     */
     258    function getResourceTypeNames()
     259    {
     260        if (!isset($GLOBALS['config']['ResourceType']) || !is_array($GLOBALS['config']['ResourceType'])) {
     261            return array();
     262        }
     263
     264        $_names = array();
     265        foreach ($GLOBALS['config']['ResourceType'] as $key => $_resourceType) {
     266            if (isset($_resourceType['name'])) {
     267                $_names[] = (string)$_resourceType['name'];
     268            }
     269        }
     270
     271        return $_names;
     272    }
     273}
     274 No newline at end of file
  • _source/plugins/filebrowser/core/connector/php/php4/Core/Connector.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage Core
     10 */
     11
     12/**
     13 * Executes all commands
     14 *
     15 * @package CKEditor
     16 * @subpackage Core
     17 */
     18class CKEditor_Connector_Core_Connector
     19{
     20    /**
     21     * Registry
     22     *
     23     * @var CKEditor_Connector_Core_Registry
     24     * @access private
     25     */
     26    var $_registry;
     27
     28    function CKEditor_Connector_Core_Connector()
     29    {
     30        $this->_registry =& CKEditor_Connector_Core_Factory::getInstance("Core_Registry");
     31        $this->_registry->set("errorHandler", "ErrorHandler_Base");
     32    }
     33
     34    /**
     35     * Generic handler for invalid commands
     36     * @access public
     37     *
     38     */
     39    function handleInvalidCommand()
     40    {
     41        $oErrorHandler =& $this->getErrorHandler();
     42        $oErrorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_INVALID_COMMAND);
     43    }
     44
     45    /**
     46     * Execute command
     47     *
     48     * @param string $command
     49     * @access public
     50     */
     51    function executeCommand($command)
     52    {
     53        switch ($command)
     54        {
     55            case 'FileUpload':
     56                $this->_registry->set("errorHandler", "ErrorHandler_FileUpload");
     57                $obj =& CKEditor_Connector_Core_Factory::getInstance("CommandHandler_".$command);
     58                $obj->sendResponse();
     59                break;
     60
     61            case 'QuickUpload':
     62                $this->_registry->set("errorHandler", "ErrorHandler_QuickUpload");
     63                $obj =& CKEditor_Connector_Core_Factory::getInstance("CommandHandler_".$command);
     64                $obj->sendResponse();
     65                break;
     66
     67            case 'CreateFolder':
     68            case 'GetFolders':
     69            case 'GetFoldersAndFiles':
     70            case 'Init':
     71                $obj =& CKEditor_Connector_Core_Factory::getInstance("CommandHandler_".$command);
     72                $obj->sendResponse();
     73                break;
     74
     75            default:
     76                $this->handleInvalidCommand();
     77                break;
     78        }
     79    }
     80
     81    /**
     82     * Get error handler
     83     *
     84     * @access public
     85     * @return CKEditor_Connector_ErrorHandler_Base|CKEditor_Connector_ErrorHandler_FileUpload|CKEditor_Connector_ErrorHandler_Http
     86     */
     87    function &getErrorHandler()
     88    {
     89        $_errorHandler = $this->_registry->get("errorHandler");
     90        $oErrorHandler =& CKEditor_Connector_Core_Factory::getInstance($_errorHandler);
     91        return $oErrorHandler;
     92    }
     93}
     94 No newline at end of file
  • _source/plugins/filebrowser/core/connector/php/php4/Core/Factory.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage Core
     10 */
     11
     12/**
     13 * Sigleton factory creating objects
     14 *
     15 * @package CKEditor
     16 * @subpackage Core
     17 */
     18class CKEditor_Connector_Core_Factory
     19{
     20    static $instances = array();
     21
     22    /**
     23     * Initiate factory
     24     * @static
     25     */
     26    function initFactory()
     27    {
     28    }
     29
     30    /**
     31     * Get instance of specified class
     32     * Short and Long class names are possible
     33     * <code>
     34     * $obj1 =& CKEditor_Connector_Core_Factory::getInstance("CKEditor_Connector_Core_Xml");
     35     * $obj2 =& CKEditor_Connector_Core_Factory::getInstance("Core_Xml");
     36     * </code>
     37     *
     38     * @param string $className class name
     39     * @static
     40     * @access public
     41     * @return object
     42     */
     43    function &getInstance($className)
     44    {
     45        $namespace = "CKEditor_Connector_";
     46
     47        $baseName = str_replace($namespace,"",$className);
     48
     49        $className = $namespace.$baseName;
     50
     51        if (!isset(CKEditor_Connector_Core_Factory::$instances[$className])) {
     52            require_once CKEDITOR_CONNECTOR_LIB_DIR . "/" . str_replace("_","/",$baseName).".php";
     53            CKEditor_Connector_Core_Factory::$instances[$className] = new $className;
     54        }
     55
     56        return CKEditor_Connector_Core_Factory::$instances[$className];
     57    }
     58}
     59 No newline at end of file
  • _source/plugins/filebrowser/core/connector/php/php4/Core/FolderHandler.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage Core
     10 */
     11
     12/**
     13 * Include file system utils class
     14 */
     15require_once CKEDITOR_CONNECTOR_LIB_DIR . "/Utils/FileSystem.php";
     16
     17/**
     18 * @package CKEditor
     19 * @subpackage Core
     20 */
     21class CKEditor_Connector_Core_FolderHandler
     22{
     23    /**
     24     * CKEditor_Connector_Core_ResourceTypeConfig object
     25     *
     26     * @var CKEditor_Connector_Core_ResourceTypeConfig
     27     * @access private
     28     */
     29    var $_resourceTypeConfig;
     30    /**
     31     * ResourceType name
     32     *
     33     * @var string
     34     * @access private
     35     */
     36    var $_resourceTypeName = "";
     37    /**
     38     * Client path
     39     *
     40     * @var string
     41     * @access private
     42     */
     43    var $_clientPath = "/";
     44    /**
     45     * Url
     46     *
     47     * @var string
     48     * @access private
     49     */
     50    var $_url;
     51    /**
     52     * Server path
     53     *
     54     * @var string
     55     * @access private
     56     */
     57    var $_serverPath;
     58    /**
     59     * Folder info
     60     *
     61     * @var mixed
     62     * @access private
     63     */
     64    var $_folderInfo;
     65
     66    function CKEditor_Connector_Core_FolderHandler()
     67    {
     68        if (isset($_GET["type"])) {
     69            $this->_resourceTypeName = (string)$_GET["type"];
     70        }
     71
     72        if (isset($_GET["currentFolder"])) {
     73            $this->_clientPath = CKEditor_Connector_Utils_FileSystem::convertToFilesystemEncoding((string)$_GET["currentFolder"]);
     74        }
     75
     76        if (!strlen($this->_clientPath)) {
     77            $this->_clientPath = "/";
     78        }
     79        else {
     80            if (substr($this->_clientPath, -1, 1) != "/") {
     81                $this->_clientPath .= "/";
     82            }
     83            if (substr($this->_clientPath, 0, 1) != "/") {
     84                $this->_clientPath = "/" . $this->_clientPath;
     85            }
     86        }
     87    }
     88
     89    /**
     90     * Get resource type config
     91     *
     92     * @return CKEditor_Connector_Core_ResourceTypeConfig
     93     * @access public
     94     */
     95    function &getResourceTypeConfig()
     96    {
     97        if (!isset($this->_resourceTypeConfig)) {
     98            $_config =& CKEditor_Connector_Core_Factory::getInstance("Core_Config");
     99            $this->_resourceTypeConfig = $_config->getResourceTypeConfig($this->_resourceTypeName);
     100        }
     101
     102        if (is_null($this->_resourceTypeConfig)) {
     103            $connector =& CKEditor_Connector_Core_Factory::getInstance("Core_Connector");
     104            $oErrorHandler =& $connector->getErrorHandler();
     105            $oErrorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_INVALID_TYPE);
     106        }
     107
     108        return $this->_resourceTypeConfig;
     109    }
     110
     111    /**
     112     * Get resource type name
     113     *
     114     * @return string
     115     * @access public
     116     */
     117    function getResourceTypeName()
     118    {
     119        return $this->_resourceTypeName;
     120    }
     121
     122    /**
     123     * Get Client path
     124     *
     125     * @return string
     126     * @access public
     127     */
     128    function getClientPath()
     129    {
     130        return $this->_clientPath;
     131    }
     132
     133    /**
     134     * Get Url
     135     *
     136     * @return string
     137     * @access public
     138     */
     139    function getUrl()
     140    {
     141        if (is_null($this->_url)) {
     142            $this->_resourceTypeConfig = $this->getResourceTypeConfig();
     143            if (is_null($this->_resourceTypeConfig)) {
     144                $connector =& CKEditor_Connector_Core_Factory::getInstance("Core_Connector");
     145                $oErrorHandler =& $connector->getErrorHandler();
     146                $oErrorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_INVALID_TYPE);
     147                $this->_url = "";
     148            }
     149            else {
     150                $this->_url = $this->_resourceTypeConfig->getUrl() . ltrim($this->getClientPath(), "/");
     151            }
     152        }
     153
     154        return $this->_url;
     155    }
     156
     157    /**
     158     * Get server path
     159     *
     160     * @return string
     161     * @access public
     162     */
     163    function getServerPath()
     164    {
     165        if (is_null($this->_serverPath)) {
     166            $this->_resourceTypeConfig = $this->getResourceTypeConfig();
     167            $this->_serverPath = CKEditor_Connector_Utils_FileSystem::combinePaths($this->_resourceTypeConfig->getDirectory(), ltrim($this->_clientPath, "/"));
     168        }
     169
     170        return $this->_serverPath;
     171    }
     172}
     173 No newline at end of file
  • _source/plugins/filebrowser/core/connector/php/php4/Core/Registry.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage Core
     10 */
     11
     12/**
     13 * Registry for storing global variables values (not references)
     14 *
     15 * @package CKEditor
     16 * @subpackage Core
     17 */
     18class CKEditor_Connector_Core_Registry
     19{
     20    /**
     21     * Arrat that stores all values
     22     *
     23     * @var array
     24     * @access private
     25     */
     26    var $_store = array();
     27
     28    /**
     29     * Chacke if value has been set
     30     *
     31     * @param string $key
     32     * @return boolean
     33     * @access private
     34     */
     35    function isValid($key)
     36    {
     37        return array_key_exists($key, $this->_store);
     38    }
     39
     40    /**
     41     * Set value
     42     *
     43     * @param string $key
     44     * @param mixed $obj
     45     * @access public
     46     */
     47    function set($key, $obj)
     48    {
     49        $this->_store[$key] = $obj;
     50    }
     51
     52    /**
     53     * Get value
     54     *
     55     * @param string $key
     56     * @return mixed
     57     * @access public
     58     */
     59    function get($key)
     60    {
     61        if ($this->isValid($key)) {
     62            return $this->_store[$key];
     63        }
     64    }
     65}
     66 No newline at end of file
  • _source/plugins/filebrowser/core/connector/php/php4/Core/ResourceTypeConfig.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage Config
     10 */
     11
     12/**
     13 * This class keeps resource types configuration
     14 *
     15 * @package CKEditor
     16 * @subpackage Config
     17 */
     18class CKEditor_Connector_Core_ResourceTypeConfig
     19{
     20    /**
     21     * Resource name
     22     *
     23     * @var string
     24     * @access private
     25     */
     26    var $_name = "";
     27    /**
     28     * Resource url
     29     *
     30     * @var string
     31     * @access private
     32     */
     33    var $_url = "";
     34    /**
     35     * Directory path on a server
     36     *
     37     * @var string
     38     * @access private
     39     */
     40    var $_directory = "";
     41    /**
     42     * Array with allowed extensions
     43     *
     44     * @var array[]string
     45     * @access private
     46     */
     47    var $_allowedExtensions = array();
     48    /**
     49     * Array with denied extensions
     50     *
     51     * @var array[]string
     52     * @access private
     53     */
     54    var $_deniedExtensions = array();
     55    /**
     56     * used for CKEditor_Connector_Core_Config object caching
     57     *
     58     * @var CKEditor_Connector_Core_Config
     59     * @access private
     60     */
     61    var $_config;
     62
     63    /**
     64     * Get ResourceType configuration
     65     *
     66     * @param string $resourceTypeNode
     67     * @return array
     68     *
     69     */
     70    function CKEditor_Connector_Core_ResourceTypeConfig($resourceTypeNode)
     71    {
     72        if (isset($resourceTypeNode["name"])) {
     73            $this->_name = $resourceTypeNode["name"];
     74        }
     75
     76        if (isset($resourceTypeNode["url"])) {
     77            $this->_url = $resourceTypeNode["url"];
     78        }
     79
     80        if (!strlen($this->_url)) {
     81            $this->_url = "/";
     82        }
     83        else if (substr($this->_url,-1,1) != "/") {
     84            $this->_url .= "/";
     85        }
     86
     87        if (isset($resourceTypeNode["directory"])) {
     88            $this->_directory = $resourceTypeNode["directory"];
     89        }
     90
     91        if (!strlen($this->_directory)) {
     92            $this->_directory = resolveUrl($this->_url);
     93        }
     94
     95        if (isset($resourceTypeNode["allowedExtensions"])) {
     96            if (is_array($resourceTypeNode["allowedExtensions"])) {
     97                foreach ($resourceTypeNode["allowedExtensions"] as $extension) {
     98                    $this->_allowedExtensions[] = strtolower(trim((string)$e));
     99                }
     100            }
     101            else {
     102                $resourceTypeNode["allowedExtensions"] = trim((string)$resourceTypeNode["allowedExtensions"]);
     103                if (strlen($resourceTypeNode["allowedExtensions"])) {
     104                    $extensions = explode(",", $resourceTypeNode["allowedExtensions"]);
     105                    foreach ($extensions as $e) {
     106                        $this->_allowedExtensions[] = strtolower(trim($e));
     107                    }
     108                }
     109            }
     110        }
     111
     112        if (isset($resourceTypeNode["deniedExtensions"])) {
     113            if (is_array($resourceTypeNode["deniedExtensions"])) {
     114
     115                foreach ($resourceTypeNode["deniedExtensions"] as $extension) {
     116                    $this->_deniedExtensions[] = strtolower(trim((string)$e));
     117                }
     118            }
     119            else {
     120                $resourceTypeNode["deniedExtensions"] = trim((string)$resourceTypeNode["deniedExtensions"]);
     121                if (strlen($resourceTypeNode["deniedExtensions"])) {
     122                    $extensions = explode(",", $resourceTypeNode["deniedExtensions"]);
     123                    foreach ($extensions as $e) {
     124                        $this->_deniedExtensions[] = strtolower(trim($e));
     125                    }
     126                }
     127            }
     128        }
     129    }
     130
     131    /**
     132     * Get name
     133     *
     134     * @access public
     135     * @return string
     136     */
     137    function getName()
     138    {
     139        return $this->_name;
     140    }
     141
     142    /**
     143     * Get url
     144     *
     145     * @access public
     146     * @return string
     147     */
     148    function getUrl()
     149    {
     150        return $this->_url;
     151    }
     152
     153    /**
     154     * Get directory
     155     *
     156     * @access public
     157     * @return string
     158     */
     159    function getDirectory()
     160    {
     161        return $this->_directory;
     162    }
     163
     164    /**
     165     * Get allowed extensions
     166     *
     167     * @access public
     168     * @return array[]string
     169     */
     170    function getAllowedExtensions()
     171    {
     172        return $this->_allowedExtensions;
     173    }
     174
     175    /**
     176     * Get denied extensions
     177     *
     178     * @access public
     179     * @return array[]string
     180     */
     181    function getDeniedExtensions()
     182    {
     183        return $this->_deniedExtensions;
     184    }
     185
     186    /**
     187     * Check extension, return true if file name is valid.
     188     * Return false if extension is on denied list.
     189     * If allowed extensions are defined, return false if extension isn't on allowed list.
     190     *
     191     * @access public
     192     * @param string $extension extension
     193     * @param boolean $renameIfRequired whether try to rename file or not
     194     * @return boolean
     195     */
     196    function checkExtension(&$fileName, $renameIfRequired = true)
     197    {
     198        if (strpos($fileName, '.') === false) {
     199            return true;
     200        }
     201
     202        if (is_null($this->_config)) {
     203            $this->_config =& CKEditor_Connector_Core_Factory::getInstance("Core_Config");
     204        }
     205
     206        $toCheck = array();
     207
     208        if ($this->_config->getCheckDoubleExtension()) {
     209            $pieces = explode('.', $fileName);
     210
     211            // First, check the last extension (ex. in file.php.jpg, the "jpg").
     212            if ( !$this->checkSingleExtension( $pieces[sizeof($pieces)-1] ) ) {
     213                return false;
     214            }
     215
     216            if ($renameIfRequired) {
     217                // Check the other extensions, rebuilding the file name. If an extension is
     218                // not allowed, replace the dot with an underscore.
     219                $fileName = $pieces[0] ;
     220                for ($i=1; $i<sizeof($pieces)-1; $i++) {
     221                    $fileName .= $this->checkSingleExtension( $pieces[$i] ) ? '.' : '_' ;
     222                    $fileName .= $pieces[$i];
     223                }
     224
     225                // Add the last extension to the final name.
     226                $fileName .= '.' . $pieces[sizeof($pieces)-1] ;
     227            }
     228        }
     229        else {
     230            // Check only the last extension (ex. in file.php.jpg, only "jpg").
     231            return $this->checkSingleExtension( substr($fileName, strrpos($fileName,'.')+1) );
     232        }
     233
     234        return true;
     235    }
     236
     237    function checkSingleExtension($extension)
     238    {
     239        $extension = strtolower(ltrim($extension,'.'));
     240
     241        if (sizeof($this->_deniedExtensions)) {
     242            if (in_array($extension, $this->_deniedExtensions)) {
     243                return false;
     244            }
     245        }
     246
     247        if (sizeof($this->_allowedExtensions)) {
     248            return in_array($extension, $this->_allowedExtensions);
     249        }
     250
     251        return true;
     252    }
     253}
  • _source/plugins/filebrowser/core/connector/php/php4/Core/Xml.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage Core
     10 */
     11
     12/**
     13 * Include basic Xml library
     14 */
     15require_once CKEDITOR_CONNECTOR_LIB_DIR . "/Utils/XmlNode.php";
     16
     17/**
     18 * XML document
     19 *
     20 * @package CKEditor
     21 * @subpackage Core
     22 */
     23class CKEditor_Connector_Core_Xml
     24{
     25    /**
     26     * Connector node (root)
     27     *
     28     * @var CKEditor_Connector_Utils_XmlNode
     29     * @access private
     30     */
     31    var $_connectorNode;
     32    /**
     33     * Error node
     34     *
     35     * @var CKEditor_Connector_Utils_XmlNode
     36     * @access private
     37     */
     38    var $_errorNode;
     39
     40    function CKEditor_Connector_Core_Xml()
     41    {
     42        $this->sendXmlHeaders();
     43        echo $this->getXMLDeclaration();
     44        $this->_connectorNode = new CKEditor_Connector_Utils_XmlNode("Connector");
     45        $this->_errorNode = new CKEditor_Connector_Utils_XmlNode("Error");
     46        $this->_connectorNode->addChild($this->_errorNode);
     47    }
     48
     49    /**
     50     * Return connector node
     51     *
     52     * @return CKEditor_Connector_Utils_XmlNode
     53     * @access public
     54     */
     55    function &getConnectorNode()
     56    {
     57        return $this->_connectorNode;
     58    }
     59
     60    /**
     61     * Return error node
     62     *
     63     * @return CKEditor_Connector_Utils_XmlNode
     64     * @access public
     65     */
     66    function &getErrorNode()
     67    {
     68        return $this->_errorNode;
     69    }
     70
     71    /**
     72     * Send XML headers to the browser (and force browser not to use cache)
     73     * @access private
     74     */
     75    function sendXmlHeaders()
     76    {
     77        // Prevent the browser from caching the result.
     78        // Date in the past
     79        header('Expires: Mon, 26 Jul 1997 05:00:00 GMT') ;
     80        // always modified
     81        header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT') ;
     82        // HTTP/1.1
     83        header('Cache-Control: no-store, no-cache, must-revalidate') ;
     84        header('Cache-Control: post-check=0, pre-check=0', false) ;
     85        // HTTP/1.0
     86        header('Pragma: no-cache') ;
     87
     88        // Set the response format.
     89        header( 'Content-Type:text/xml; charset=utf-8' ) ;
     90    }
     91
     92    /**
     93     * Return XML declaration
     94     *
     95     * @access private
     96     * @return string
     97     */
     98    function getXMLDeclaration()
     99    {
     100        return '<?xml version="1.0" encoding="utf-8"?>';
     101    }
     102
     103    /**
     104     * Send error message to the browser. If error number is set to 1, $text (custom error message) will be displayed
     105     * Don't call this function directly
     106     *
     107     * @access public
     108     * @param int $number error number
     109     * @param string $text Custom error message (optional)
     110     */
     111    function raiseError( $number, $text = false)
     112    {
     113        $this->_errorNode->addAttribute("number", intval($number));
     114        if (false!=$text) {
     115            $this->_errorNode->addAttribute("text", $text);
     116        }
     117
     118        echo $this->_connectorNode->asXML();
     119    }
     120}
     121 No newline at end of file
  • _source/plugins/filebrowser/core/connector/php/php4/ErrorHandler/Base.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage ErrorHandler
     10 */
     11
     12/**
     13 * Basic error handler
     14 *
     15 * @package CKEditor
     16 * @subpackage ErrorHandler
     17 */
     18class CKEditor_Connector_ErrorHandler_Base
     19{
     20    /**
     21     * Try/catch emulation, if set to true, error handler will not throw any error
     22     *
     23     * @var boolean
     24     * @access protected
     25     */
     26    var $_catchAllErrors = false;
     27    /**
     28     * Array with error numbers that should be ignored
     29     *
     30     * @var array[]int
     31     * @access protected
     32     */
     33    var $_skipErrorsArray = array();
     34
     35    /**
     36     * Set whether all errors should be ignored
     37     *
     38     * @param boolean $newValue
     39     * @access public
     40     */
     41    function setCatchAllErros($newValue)
     42    {
     43        $this->_catchAllErrors = $newValue ? true : false;
     44    }
     45
     46    /**
     47     * Set which errors should be ignored
     48     *
     49     * @param array $newArray
     50     */
     51    function setSkipErrorsArray($newArray)
     52    {
     53        if (is_array($newArray)) {
     54            $this->_skipErrorsArray = $newArray;
     55        }
     56    }
     57
     58    /**
     59     * Throw connector error, return true if error has been thrown, false if error has been catched
     60     *
     61     * @param int $number
     62     * @param string $text
     63     * @access public
     64     */
     65    function throwError($number, $text = false)
     66    {
     67        if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) {
     68            return false;
     69        }
     70
     71        $_xml =& CKEditor_Connector_Core_Factory::getInstance("Core_Xml");
     72        $_xml->raiseError($number,$text);
     73
     74        exit;
     75    }
     76}
     77 No newline at end of file
  • _source/plugins/filebrowser/core/connector/php/php4/ErrorHandler/FileUpload.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage ErrorHandler
     10 */
     11
     12/**
     13 * Include base error handling class
     14 */
     15require_once CKEDITOR_CONNECTOR_LIB_DIR . "/ErrorHandler/Base.php";
     16
     17/**
     18 * File upload error handler
     19 *
     20 * @package CKEditor
     21 * @subpackage ErrorHandler
     22 */
     23class CKEditor_Connector_ErrorHandler_FileUpload extends CKEditor_Connector_ErrorHandler_Base
     24{
     25    /**
     26     * Throw file upload error, return true if error has been thrown, false if error has been catched
     27     *
     28     * @param int $number
     29     * @param string $text
     30     * @access public
     31     */
     32    function throwError($number, $text = false, $exit = true)
     33    {
     34        if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) {
     35            return false;
     36        }
     37
     38        $oRegistry =& CKEditor_Connector_Core_Factory::getInstance("Core_Registry");
     39        $sFileName = $oRegistry->get("FileUpload_fileName");
     40
     41        echo "<script type=\"text/javascript\">";
     42        if (empty($text)) {
     43            echo "window.parent.OnUploadCompleted(" . $number . ") ;";
     44        }
     45        else {
     46            echo "window.parent.OnUploadCompleted(" . $number . ",'" . str_replace("'", "\\'", $sFileName) . "') ;";
     47        }
     48        echo "</script>";
     49
     50        if ($exit) {
     51            exit;
     52        }
     53    }
     54}
     55 No newline at end of file
  • _source/plugins/filebrowser/core/connector/php/php4/ErrorHandler/Http.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage ErrorHandler
     10 */
     11
     12/**
     13 * Include base error handling class
     14 */
     15require_once CKEDITOR_CONNECTOR_LIB_DIR . "/ErrorHandler/Base.php";
     16
     17/**
     18 * HTTP error handler
     19 *
     20 * @package CKEditor
     21 * @subpackage ErrorHandler
     22 */
     23class CKEditor_Connector_ErrorHandler_Http extends CKEditor_Connector_ErrorHandler_Base
     24{
     25    /**
     26     * Throw file upload error, return true if error has been thrown, false if error has been catched
     27     *
     28     * @param int $number
     29     * @param string $text
     30     * @access public
     31     */
     32    function throwError($number, $text = false, $exit = true)
     33    {
     34        if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) {
     35            return false;
     36        }
     37
     38        switch ($number)
     39        {
     40            case CKEDITOR_CONNECTOR_ERROR_INVALID_REQUEST:
     41            case CKEDITOR_CONNECTOR_ERROR_INVALID_NAME:
     42            case CKEDITOR_CONNECTOR_ERROR_UNAUTHORIZED:
     43                header("HTTP/1.0 403 Forbidden");
     44                header("X-CKEditor-Error: ". $number);
     45                break;
     46
     47            case CKEDITOR_CONNECTOR_ERROR_ACCESS_DENIED:
     48                header("HTTP/1.0 500 Internal Server Error");
     49                header("X-CKEditor-Error: ".$number);
     50                break;
     51
     52            default:
     53                header("HTTP/1.0 404 Not Found");
     54                header("X-CKEditor-Error: ". $number);
     55                break;
     56        }
     57
     58        if ($exit) {
     59            exit;
     60        }
     61    }
     62}
     63 No newline at end of file
  • _source/plugins/filebrowser/core/connector/php/php4/ErrorHandler/QuickUpload.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage ErrorHandler
     10 */
     11
     12/**
     13 * Include base error handling class
     14 */
     15require_once CKEDITOR_CONNECTOR_LIB_DIR . "/ErrorHandler/Base.php";
     16
     17/**
     18 * File upload error handler
     19 *
     20 * @package CKEditor
     21 * @subpackage ErrorHandler
     22 */
     23class CKEditor_Connector_ErrorHandler_QuickUpload extends CKEditor_Connector_ErrorHandler_Base
     24{
     25    /**
     26     * Throw file upload error, return true if error has been thrown, false if error has been catched
     27     *
     28     * @param int $number
     29     * @param string $text
     30     * @access public
     31     */
     32    function throwError($number, $text = false, $exit = true)
     33    {
     34        if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) {
     35            return false;
     36        }
     37
     38        $oRegistry =& CKEditor_Connector_Core_Factory::getInstance("Core_Registry");
     39        $sFileName = $oRegistry->get("FileUpload_fileName");
     40        $sFileUrl = $oRegistry->get("FileUpload_url");
     41
     42        echo "<script type=\"text/javascript\">";
     43        if (empty($text)) {
     44            echo "window.parent.OnUploadCompleted(" . $number . ", '', '', '') ;";
     45        }
     46        else {
     47            echo "window.parent.OnUploadCompleted(" . $number . ", '" .str_replace("'", "\\'", $sFileUrl . $sFileName). "', '" . str_replace("'", "\\'", $sFileName) . "', '') ;";
     48        }
     49        echo "</script>";
     50
     51        if ($exit) {
     52            exit;
     53        }
     54    }
     55}
     56 No newline at end of file
  • _source/plugins/filebrowser/core/connector/php/php4/Utils/FileSystem.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage Utils
     10 */
     11
     12/**
     13 * @package CKEditor
     14 * @subpackage Utils
     15 */
     16class CKEditor_Connector_Utils_FileSystem
     17{
     18
     19    /**
     20     * This function behaves similar to System.IO.Path.Combine in C#, the only diffrenece is that it also accepts null values and treat them as empty string
     21     *
     22     * @static
     23     * @access public
     24     * @param string $path1 first path
     25     * @param string $path2 scecond path
     26     * @return string
     27     */
     28    function combinePaths($path1, $path2)
     29    {
     30        if (is_null($path1))  {
     31            $path1 = "";
     32        }
     33        if (is_null($path2))  {
     34            $path2 = "";
     35        }
     36        if (!strlen($path2)) {
     37            if (strlen($path1)) {
     38                $_lastCharP1 = substr($path1, -1, 1);
     39                if ($_lastCharP1 != "/" && $_lastCharP1 != "\\") {
     40                    $path1 .= DIRECTORY_SEPARATOR;
     41                }
     42            }
     43        }
     44        else {
     45            $_firstCharP2 = substr($path2, 0, 1);
     46            if (strlen($path1)) {
     47                if (strpos($path2, $path1)===0) {
     48                    return $path2;
     49                }
     50                $_lastCharP1 = substr($path1, -1, 1);
     51                if ($_lastCharP1 != "/" && $_lastCharP1 != "\\" && $_firstCharP2 != "/" && $_firstCharP2 != "\\") {
     52                    $path1 .= DIRECTORY_SEPARATOR;
     53                }
     54            }
     55            else {
     56                return $path2;
     57            }
     58        }
     59        return $path1 . $path2;
     60    }
     61
     62    /**
     63     * Check whether $fileName is a valid file name, return true on success
     64     *
     65     * @static
     66     * @access public
     67     * @param string $fileName
     68     * @return boolean
     69     */
     70    function checkFileName($fileName)
     71    {
     72        if (is_null($fileName) || !strlen($fileName) || substr($fileName,-1,1)=="." || false!==strpos($fileName, "..")) {
     73            return false;
     74        }
     75
     76        if (preg_match(",[[:cntrl:]]|[/\\:\*\?\"\<\>\|],", $fileName)) {
     77            return false;
     78        }
     79
     80        return true;
     81    }
     82
     83    /**
     84     * Unlink file/folder
     85     *
     86     * @static
     87     * @access public
     88     * @param string $path
     89     * @return boolean
     90     */
     91    function unlink($path)
     92    {
     93        /*    make sure the path exists    */
     94        if (!file_exists($path)) {
     95            return false;
     96        }
     97
     98        /*    If it is a file or link, just delete it    */
     99        if (is_file($path) || is_link($path)) {
     100            return @unlink($path);
     101        }
     102
     103        /*    Scan the dir and recursively unlink    */
     104        $files = scandir($path);
     105        if ($files) {
     106            foreach($files as $filename)
     107            {
     108                if ($filename == '.' || $filename == '..') {
     109                    continue;
     110                }
     111                $file = str_replace('//','/',$path.'/'.$filename);
     112                CKEditor_Connector_Utils_FileSystem::unlink($file);
     113            }
     114        }
     115
     116        /*    Remove the parent dir    */
     117        if (!@rmdir($path)) {
     118            return false;
     119        }
     120
     121        return true;
     122    }
     123
     124    /**
     125     * Return file name without extension (without dot & last part after dot)
     126     *
     127     * @static
     128     * @access public
     129     * @param string $fileName
     130     * @return string
     131     */
     132    function getFileNameWithoutExtension($fileName)
     133    {
     134        $dotPos = strrpos( $fileName, '.' );
     135        if (false === $dotPos) {
     136            return $fileName;
     137        }
     138
     139        return substr($fileName, 0, $dotPos);
     140    }
     141
     142    /**
     143     * Get file extension (only last part - e.g. extension of file.foo.bar.jpg = jpg)
     144     *
     145     * @static
     146     * @access public
     147     * @param string $fileName
     148     * @return string
     149     */
     150    function getExtension( $fileName )
     151    {
     152        $dotPos = strrpos( $fileName, '.' );
     153        if (false === $dotPos) {
     154            return "";
     155        }
     156
     157        return substr( $fileName, strrpos( $fileName, '.' ) +1 ) ;
     158    }
     159
     160    /**
     161     * Convert file name from UTF-8 to system encoding
     162     *
     163     * @static
     164     * @access public
     165     * @param string $fileName
     166     * @return string
     167     */
     168    function convertToFilesystemEncoding($fileName)
     169    {
     170        $_config =& CKEditor_Connector_Core_Factory::getInstance("Core_Config");
     171        $encoding = $_config->getFilesystemEncoding();
     172        if (is_null($encoding) || strcasecmp($encoding, "UTF-8") == 0 || strcasecmp($encoding, "UTF8") == 0) {
     173            return $fileName;
     174        }
     175
     176        if (!function_exists("iconv")) {
     177            if (strcasecmp($encoding, "ISO-8859-1") == 0 || strcasecmp($encoding, "ISO8859-1") == 0 || strcasecmp($encoding, "Latin1") == 0) {
     178                return str_replace("\0", "_", utf8_decode($fileName));
     179            } else if (function_exists('mb_convert_encoding')) {
     180                /**
     181                 * @todo check whether charset is supported - mb_list_encodings
     182                 */
     183                $encoded = @mb_convert_encoding($fileName, $encoding, 'UTF-8');
     184                if (@mb_strlen($fileName, "UTF-8") != @mb_strlen($encoded, $encoding)) {
     185                    return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName));
     186                }
     187                else {
     188                    return str_replace("\0", "_", $encoded);
     189                }
     190            } else {
     191                return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName));
     192            }
     193        }
     194
     195        $converted = @iconv("UTF-8", $encoding . "//IGNORE//TRANSLIT", $fileName);
     196        if ($converted === false) {
     197            return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName));
     198        }
     199
     200        return $converted;
     201    }
     202
     203    /**
     204     * Convert file name from system encoding into UTF-8
     205     *
     206     * @static
     207     * @access public
     208     * @param string $fileName
     209     * @return string
     210     */
     211    function convertToConnectorEncoding($fileName)
     212    {
     213        $_config =& CKEditor_Connector_Core_Factory::getInstance("Core_Config");
     214        $encoding = $_config->getFilesystemEncoding();
     215        if (is_null($encoding) || strcasecmp($encoding, "UTF-8") == 0 || strcasecmp($encoding, "UTF8") == 0) {
     216            return $fileName;
     217        }
     218
     219        if (!function_exists("iconv")) {
     220            if (strcasecmp($encoding, "ISO-8859-1") == 0 || strcasecmp($encoding, "ISO8859-1") == 0 || strcasecmp($encoding, "Latin1") == 0) {
     221                return utf8_encode($fileName);
     222            } else {
     223                return $fileName;
     224            }
     225        }
     226
     227        $converted = @iconv($encoding, "UTF-8", $fileName);
     228
     229        if ($converted === false) {
     230            return $fileName;
     231        }
     232
     233        return $converted;
     234    }
     235
     236    /**
     237     * Find document root
     238     *
     239     * @return string
     240     * @access public
     241     */
     242    function getDocumentRootPath()
     243    {
     244        /**
     245         * The absolute pathname of the currently executing script.
     246         * If a script is executed with the CLI, as a relative path, such as file.php or ../file.php,
     247         * $_SERVER['SCRIPT_FILENAME'] will contain the relative path specified by the user.
     248         */
     249        if (isset($_SERVER['SCRIPT_FILENAME'])) {
     250            $sRealPath = dirname($_SERVER['SCRIPT_FILENAME']);
     251        }
     252        else {
     253            /**
     254             * realpath — Returns canonicalized absolute pathname
     255             */
     256            $sRealPath = realpath( './' ) ;
     257        }
     258
     259        /**
     260         * The filename of the currently executing script, relative to the document root.
     261         * For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar
     262         * would be /test.php/foo.bar.
     263         */
     264        $sSelfPath = dirname($_SERVER['PHP_SELF']);
     265
     266        return substr($sRealPath, 0, strlen($sRealPath) - strlen($sSelfPath));
     267    }
     268
     269    /**
     270     * Create directory recursively
     271     *
     272     * @access public
     273     * @static
     274     * @param string $dir
     275     * @return boolean
     276     */
     277    function createDirectoryRecursively($dir)
     278    {
     279        if (DIRECTORY_SEPARATOR === "\\") {
     280            $dir = str_replace("/", "\\", $dir);
     281        }
     282        else if (DIRECTORY_SEPARATOR === "/") {
     283            $dir = str_replace("\\", "/", $dir);
     284        }
     285
     286        $_config =& CKEditor_Connector_Core_Factory::getInstance("Core_Config");
     287        if ($perms = $_config->getChmodFolders()) {
     288            $oldUmask = umask(0);
     289            $bCreated = @mkdir($dir, $perms, true);
     290            umask($oldUmask);
     291        }
     292        else {
     293            $bCreated = @mkdir($dir, 0777, true);
     294        }
     295
     296        return $bCreated;
     297    }
     298
     299    /**
     300     * Detect HTML in the first KB to prevent against potential security issue with
     301     * IE/Safari/Opera file type auto detection bug.
     302     * Returns true if file contain insecure HTML code at the beginning.
     303     *
     304     * @static
     305     * @access public
     306     * @param string $filePath absolute path to file
     307     * @return boolean
     308    */
     309    function detectHtml($filePath)
     310    {
     311        $fp = @fopen($filePath, 'rb');
     312        if ( $fp === false || !flock( $fp, LOCK_SH ) ) {
     313            return -1 ;
     314        }
     315        $chunk = fread($fp, 1024);
     316        flock( $fp, LOCK_UN ) ;
     317        fclose($fp);
     318
     319        $chunk = strtolower($chunk);
     320
     321        if (!$chunk) {
     322            return false;
     323        }
     324
     325        $chunk = trim($chunk);
     326
     327        if (preg_match("/<!DOCTYPE\W*X?HTML/sim", $chunk)) {
     328            return true;
     329        }
     330
     331        $tags = array('<body', '<head', '<html', '<img', '<pre', '<script', '<table', '<title');
     332
     333        foreach( $tags as $tag ) {
     334            if (false !== strpos($chunk, $tag)) {
     335                return true ;
     336            }
     337        }
     338
     339        //type = javascript
     340        if (preg_match('!type\s*=\s*[\'"]?\s*(?:\w*/)?(?:ecma|java)!sim', $chunk)) {
     341            return true ;
     342        }
     343
     344        //href = javascript
     345        //src = javascript
     346        //data = javascript
     347        if (preg_match('!(?:href|src|data)\s*=\s*[\'"]?\s*(?:ecma|java)script:!sim',$chunk)) {
     348            return true ;
     349        }
     350
     351        //url(javascript
     352        if (preg_match('!url\s*\(\s*[\'"]?\s*(?:ecma|java)script:!sim', $chunk)) {
     353            return true ;
     354        }
     355
     356        return false ;
     357    }
     358
     359    /**
     360     * Check file content.
     361     * Currently this function validates only image files.
     362     * Returns false if file is invalid.
     363     *
     364     * @static
     365     * @access public
     366     * @param string $filePath absolute path to file
     367     * @param string $extension file extension
     368     * @param integer $detectionLevel 0 = none, 1 = use getimagesize for images, 2 = use DetectHtml for images
     369     * @return boolean
     370    */
     371    function isImageValid($filePath, $extension)
     372    {
     373        if (!@is_readable($filePath)) {
     374            return -1;
     375        }
     376
     377        $imageCheckExtensions = array('gif', 'jpeg', 'jpg', 'png', 'psd', 'bmp', 'tiff');
     378
     379        // version_compare is available since PHP4 >= 4.0.7
     380        if ( function_exists( 'version_compare' ) ) {
     381            $sCurrentVersion = phpversion();
     382            if ( version_compare( $sCurrentVersion, "4.2.0" ) >= 0 ) {
     383                $imageCheckExtensions[] = "tiff";
     384                $imageCheckExtensions[] = "tif";
     385            }
     386            if ( version_compare( $sCurrentVersion, "4.3.0" ) >= 0 ) {
     387                $imageCheckExtensions[] = "swc";
     388            }
     389            if ( version_compare( $sCurrentVersion, "4.3.2" ) >= 0 ) {
     390                $imageCheckExtensions[] = "jpc";
     391                $imageCheckExtensions[] = "jp2";
     392                $imageCheckExtensions[] = "jpx";
     393                $imageCheckExtensions[] = "jb2";
     394                $imageCheckExtensions[] = "xbm";
     395                $imageCheckExtensions[] = "wbmp";
     396            }
     397        }
     398
     399        if ( !in_array( $extension, $imageCheckExtensions ) ) {
     400            return true;
     401        }
     402
     403        if ( @getimagesize( $filePath ) === false ) {
     404            return false ;
     405        }
     406
     407        return true;
     408    }
     409}
  • _source/plugins/filebrowser/core/connector/php/php4/Utils/Misc.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage Utils
     10 */
     11
     12/**
     13 * @package CKEditor
     14 * @subpackage Utils
     15 */
     16class CKEditor_Connector_Utils_Misc
     17{
     18    /**
     19     * Convert any value to boolean, strings like "false", "FalSE" and "off" are also considered as false
     20     *
     21     * @static
     22     * @access public
     23     * @param mixed $value
     24     * @return boolean
     25     */
     26    function booleanValue($value)
     27    {
     28        if (strcasecmp("false", $value) == 0 || strcasecmp("off", $value) == 0 || !$value) {
     29            return false;
     30        } else {
     31            return true;
     32        }
     33    }
     34
     35    /**
     36    * Checks if a value exists in an array (case insensitive)
     37    *
     38    * @static
     39    * @access public
     40    * @param string $needle
     41    * @param array $haystack
     42    * @return boolean
     43    */
     44    function inArrayCaseInsensitive($needle, $haystack)
     45    {
     46        if (!$haystack || !is_array($haystack)) {
     47            return false;
     48        }
     49        $lcase = array();
     50        foreach ($haystack as $key => $val) {
     51            $lcase[$key] = strtolower($val);
     52        }
     53        return in_array($needle, $lcase);
     54    }
     55}
     56 No newline at end of file
  • _source/plugins/filebrowser/core/connector/php/php4/Utils/Security.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage Utils
     10 */
     11
     12/**
     13 * @package CKEditor
     14 * @subpackage Utils
     15 */
     16class CKEditor_Connector_Utils_Security
     17{
     18
     19    /**
     20     * Strip quotes from global arrays
     21     * @access public
     22     */
     23    function getRidOfMagicQuotes()
     24    {
     25        if (CKEDITOR_CONNECTOR_PHP_MODE<6 && get_magic_quotes_gpc()) {
     26            if (!empty($_GET)) {
     27                $this->stripQuotes($_GET);
     28            }
     29            if (!empty($_POST)) {
     30                $this->stripQuotes($_POST);
     31            }
     32            if (!empty($_COOKIE)) {
     33                $this->stripQuotes($_COOKIE);
     34            }
     35            if (!empty($_FILES)) {
     36                while (list($k,$v) = each($_FILES)) {
     37                    if (isset($_FILES[$k]['name'])) {
     38                        $this->stripQuotes($_FILES[$k]['name']);
     39                    }
     40                }
     41            }
     42        }
     43    }
     44
     45    /**
     46     * Strip quotes from variable
     47     *
     48     * @access public
     49     * @param mixed $var
     50     * @param int $depth current depth
     51     * @param int $howDeep maximum depth
     52     */
     53    function stripQuotes(&$var, $depth=0, $howDeep=5)
     54    {
     55        if (is_array($var)) {
     56            if ($depth++<$howDeep) {
     57                while (list($k,$v) = each($var)) {
     58                    $this->stripQuotes($var[$k], $depth, $howDeep);
     59                }
     60            }
     61        } else {
     62            $var = stripslashes($var);
     63        }
     64    }
     65}
  • _source/plugins/filebrowser/core/connector/php/php4/Utils/XmlNode.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage Utils
     10 */
     11
     12/**
     13 * Simple class which provides some basic API for creating XML nodes and adding attributes
     14 *
     15 * @package CKEditor
     16 * @subpackage Utils
     17 */
     18class CKEditor_Connector_Utils_XmlNode
     19{
     20    /**
     21     * Array that stores XML attributes
     22     *
     23     * @access private
     24     * @var array
     25     */
     26    var $_attributes = array();
     27    /**
     28     * Array that stores child nodes
     29     *
     30     * @access private
     31     * @var array
     32     */
     33    var $_childNodes = array();
     34    /**
     35     * Node name
     36     *
     37     * @access private
     38     * @var string
     39     */
     40    var $_name;
     41    /**
     42     * Node value
     43     *
     44     * @access private
     45     * @var string
     46     */
     47    var $_value;
     48
     49    /**
     50     * Create new node
     51     *
     52     * @param string $nodeName node name
     53     * @param string $nodeValue node value
     54     * @return CKEditor_Connector_Utils_XmlNode
     55     */
     56    function CKEditor_Connector_Utils_XmlNode($nodeName, $nodeValue = null)
     57    {
     58        $this->_name = $nodeName;
     59        if (!is_null($nodeValue)) {
     60            $this->_value = $nodeValue;
     61        }
     62    }
     63
     64    /**
     65     * Add attribute
     66     *
     67     * @param string $name
     68     * @param string $value
     69     * @access public
     70     */
     71    function addAttribute($name, $value)
     72    {
     73        $this->_attributes[$name] = $value;
     74    }
     75
     76    /**
     77     * Adds new child at the end of the children
     78     *
     79     * @param CKEditor_Connector_Utils_XmlNode $node
     80     * @access public
     81     */
     82    function addChild(&$node)
     83    {
     84        $this->_childNodes[] =& $node;
     85    }
     86
     87    /**
     88     * Return a well-formed XML string based on CKEditor_Connector_Utils_XmlNode element
     89     *
     90     * @return string
     91     * @access public
     92     */
     93    function asXML()
     94    {
     95        $ret = "<" . $this->_name;
     96
     97        //print Attributes
     98        if (sizeof($this->_attributes)>0) {
     99            foreach ($this->_attributes as $_name => $_value) {
     100                $ret .= " " . $_name . '="' . htmlspecialchars($_value) . '"';
     101            }
     102        }
     103
     104        //if there is nothing more todo, close empty tag and exit
     105        if (is_null($this->_value) && !sizeof($this->_childNodes)) {
     106            $ret .= " />";
     107            return $ret;
     108        }
     109
     110        //close opening tag
     111        $ret .= ">";
     112
     113        //print value
     114        if (!is_null($this->_value)) {
     115            $ret .= htmlspecialchars($this->_value);
     116        }
     117
     118        //print child nodes
     119        if (sizeof($this->_childNodes)>0) {
     120            foreach ($this->_childNodes as $_node) {
     121                $ret .= $_node->asXml();
     122            }
     123        }
     124
     125        $ret .= "</" . $this->_name . ">";
     126
     127        return $ret;
     128    }
     129}
     130 No newline at end of file
  • _source/plugins/filebrowser/core/connector/php/php5/CommandHandler/CommandHandlerBase.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage CommandHandlers
     10 */
     11
     12/**
     13 * Base commands handler
     14 *
     15 * @package CKEditor
     16 * @subpackage CommandHandlers
     17 * @abstract
     18 */
     19class CKEditor_Connector_CommandHandler_CommandHandlerBase
     20{
     21    /**
     22     * CKEditor_Connector_Core_Connector object
     23     *
     24     * @access protected
     25     * @var CKEditor_Connector_Core_Connector
     26     */
     27    protected $_connector;
     28    /**
     29     * CKEditor_Connector_Core_FolderHandler object
     30     *
     31     * @access protected
     32     * @var CKEditor_Connector_Core_FolderHandler
     33     */
     34    protected $_currentFolder;
     35    /**
     36     * Error handler object
     37     *
     38     * @access protected
     39     * @var CKEditor_Connector_ErrorHandler_Base|CKEditor_Connector_ErrorHandler_FileUpload|CKEditor_Connector_ErrorHandler_Http
     40     */
     41    protected $_errorHandler;
     42
     43    function __construct()
     44    {
     45        $this->_currentFolder =& CKEditor_Connector_Core_Factory::getInstance("Core_FolderHandler");
     46        $this->_connector =& CKEditor_Connector_Core_Factory::getInstance("Core_Connector");
     47        $this->_errorHandler =& $this->_connector->getErrorHandler();
     48    }
     49
     50    /**
     51     * Get Folder Handler
     52     *
     53     * @access public
     54     * @return CKEditor_Connector_Core_FolderHandler
     55     */
     56    public function getFolderHandler()
     57    {
     58        if (is_null($this->_currentFolder)) {
     59            $this->_currentFolder =& CKEditor_Connector_Core_Factory::getInstance("Core_FolderHandler");
     60        }
     61
     62        return $this->_currentFolder;
     63    }
     64
     65    /**
     66     * Check whether Connector is enabled
     67     * @access protected
     68     *
     69     */
     70    protected function checkConnector()
     71    {
     72        $_config =& CKEditor_Connector_Core_Factory::getInstance("Core_Config");
     73        if (!$_config->getIsEnabled()) {
     74            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_CONNECTOR_DISABLED);
     75        }
     76    }
     77
     78    /**
     79     * Check request
     80     * @access protected
     81     *
     82     */
     83    protected function checkRequest()
     84    {
     85        if (preg_match(",(/\.)|[[:cntrl:]]|(//)|(\\\\)|([\:\*\?\"\<\>\|]),", $this->_currentFolder->getClientPath())) {
     86            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_INVALID_NAME);
     87        }
     88
     89        $_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig();
     90
     91        if (is_null($_resourceTypeConfig)) {
     92            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_INVALID_TYPE);
     93        }
     94
     95        $_clientPath = $this->_currentFolder->getClientPath();
     96
     97        if (!is_dir($this->_currentFolder->getServerPath())) {
     98            if ($_clientPath == "/") {
     99                if (!CKEditor_Connector_Utils_FileSystem::createDirectoryRecursively($this->_currentFolder->getServerPath())) {
     100                    /**
     101                     * @todo handle error
     102                     */
     103                }
     104            }
     105            else {
     106                $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_FOLDER_NOT_FOUND);
     107            }
     108        }
     109    }
     110}
     111 No newline at end of file
  • _source/plugins/filebrowser/core/connector/php/php5/CommandHandler/CreateFolder.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage CommandHandlers
     10 */
     11
     12/**
     13 * Include base XML command handler
     14 */
     15require_once CKEDITOR_CONNECTOR_LIB_DIR . "/CommandHandler/XmlCommandHandlerBase.php";
     16
     17/**
     18 * Handle CreateFolder command
     19 *
     20 * @package CKEditor
     21 * @subpackage CommandHandlers
     22 */
     23class CKEditor_Connector_CommandHandler_CreateFolder extends CKEditor_Connector_CommandHandler_XmlCommandHandlerBase
     24{
     25    /**
     26     * Command name
     27     *
     28     * @access private
     29     * @var string
     30     */
     31    private $command = "CreateFolder";
     32
     33    /**
     34     * handle request and build XML
     35     * @access protected
     36     *
     37     */
     38    protected function buildXml()
     39    {
     40        $_config =& CKEditor_Connector_Core_Factory::getInstance("Core_Config");
     41
     42        $_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig();
     43        $sNewFolderName = isset($_POST["newFolderName"]) ? $_POST["newFolderName"] : "";
     44        $sNewFolderName = CKEditor_Connector_Utils_FileSystem::convertToFilesystemEncoding($sNewFolderName);
     45
     46        if (!CKEditor_Connector_Utils_FileSystem::checkFileName($sNewFolderName)) {
     47            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_INVALID_NAME);
     48        }
     49
     50        $sServerDir = CKEditor_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $sNewFolderName);
     51        if (!is_writeable($this->_currentFolder->getServerPath())) {
     52            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_ACCESS_DENIED);
     53        }
     54
     55        $bCreated = false;
     56
     57        if (file_exists($sServerDir)) {
     58            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_ALREADY_EXIST);
     59        }
     60
     61        if ($perms = $_config->getChmodFolders()) {
     62            $oldUmask = umask(0);
     63            $bCreated = @mkdir($sServerDir, $perms);
     64            umask($oldUmask);
     65        }
     66        else {
     67            $bCreated = @mkdir($sServerDir);
     68        }
     69
     70        if (!$bCreated) {
     71            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_ACCESS_DENIED);
     72        } else {
     73            $oNewFolderNode = new CKEditor_Connector_Utils_XmlNode("NewFolder");
     74            $this->_connectorNode->addChild($oNewFolderNode);
     75            $oNewFolderNode->addAttribute("name", CKEditor_Connector_Utils_FileSystem::convertToConnectorEncoding($sNewFolderName));
     76        }
     77    }
     78}
     79 No newline at end of file
  • _source/plugins/filebrowser/core/connector/php/php5/CommandHandler/FileUpload.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage CommandHandlers
     10 */
     11
     12/**
     13 * Handle FileUpload command
     14 *
     15 * @package CKEditor
     16 * @subpackage CommandHandlers
     17 */
     18class CKEditor_Connector_CommandHandler_FileUpload extends CKEditor_Connector_CommandHandler_CommandHandlerBase
     19{
     20    /**
     21     * Command name
     22     *
     23     * @access protected
     24     * @var string
     25     */
     26    protected $command = "FileUpload";
     27
     28    /**
     29     * send response (save uploaded file)
     30     * @access public
     31     *
     32     */
     33    public function sendResponse()
     34    {
     35        $iErrorNumber = CKEDITOR_CONNECTOR_ERROR_NONE;
     36
     37        $oRegistry =& CKEditor_Connector_Core_Factory::getInstance("Core_Registry");
     38        $oRegistry->set("FileUpload_fileName", "unknown file");
     39
     40        $uploadedFile = array_shift($_FILES);
     41
     42        if (!isset($uploadedFile['name'])) {
     43            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_UPLOADED_INVALID);
     44        }
     45
     46        $sFileName = CKEditor_Connector_Utils_FileSystem::convertToFilesystemEncoding(basename($uploadedFile['name']));
     47        $oRegistry->set("FileUpload_fileName", $sFileName);
     48
     49        $this->checkConnector();
     50        $this->checkRequest();
     51
     52        if (!CKEditor_Connector_Utils_FileSystem::checkFileName($sFileName)) {
     53            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_INVALID_NAME);
     54        }
     55
     56        $_config =& CKEditor_Connector_Core_Factory::getInstance("Core_Config");
     57        $_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig();
     58
     59        $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig();
     60        if (!$resourceTypeInfo->checkExtension($sFileName)) {
     61            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_INVALID_EXTENSION);
     62        }
     63
     64        $sFileNameOrginal = $sFileName;
     65        $oRegistry->set("FileUpload_fileName", $sFileName);
     66
     67        $htmlExtensions = $_config->getHtmlExtensions();
     68        $sExtension = CKEditor_Connector_Utils_FileSystem::getExtension($sFileNameOrginal);
     69
     70        if ($htmlExtensions
     71        && !CKEditor_Connector_Utils_Misc::inArrayCaseInsensitive($sExtension, $htmlExtensions)
     72        && ($detectHtml = CKEditor_Connector_Utils_FileSystem::detectHtml($uploadedFile['tmp_name'])) === true ) {
     73            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_UPLOADED_WRONG_HTML_FILE);
     74        }
     75
     76        $sExtension = CKEditor_Connector_Utils_FileSystem::getExtension($sFileNameOrginal);
     77        $secureImageUploads = $_config->getSecureImageUploads();
     78        if ($secureImageUploads
     79        && ($isImageValid = CKEditor_Connector_Utils_FileSystem::isImageValid($uploadedFile['tmp_name'], $sExtension)) === false ) {
     80            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_UPLOADED_CORRUPT);
     81        }
     82
     83        switch ($uploadedFile['error']) {
     84            case UPLOAD_ERR_OK:
     85                break;
     86
     87            case UPLOAD_ERR_INI_SIZE:
     88            case UPLOAD_ERR_FORM_SIZE:
     89                $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_UPLOADED_TOO_BIG);
     90                break;
     91
     92            case UPLOAD_ERR_PARTIAL:
     93            case UPLOAD_ERR_NO_FILE:
     94                $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_UPLOADED_CORRUPT);
     95                break;
     96
     97            case UPLOAD_ERR_NO_TMP_DIR:
     98                $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_UPLOADED_NO_TMP_DIR);
     99                break;
     100
     101            case UPLOAD_ERR_CANT_WRITE:
     102                $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_ACCESS_DENIED);
     103                break;
     104
     105            case UPLOAD_ERR_EXTENSION:
     106                $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_ACCESS_DENIED);
     107                break;
     108        }
     109
     110        $sServerDir = $this->_currentFolder->getServerPath();
     111        $iCounter = 0;
     112
     113        while (true)
     114        {
     115            $sFilePath = CKEditor_Connector_Utils_FileSystem::combinePaths($sServerDir, $sFileName);
     116
     117            if (file_exists($sFilePath)) {
     118                $iCounter++;
     119                $sFileName =
     120                CKEditor_Connector_Utils_FileSystem::getFileNameWithoutExtension($sFileNameOrginal) .
     121                "(" . $iCounter . ")" . "." .
     122                CKEditor_Connector_Utils_FileSystem::getExtension($sFileNameOrginal);
     123                $oRegistry->set("FileUpload_fileName", $sFileName);
     124
     125                $iErrorNumber = CKEDITOR_CONNECTOR_ERROR_UPLOADED_FILE_RENAMED;
     126            } else {
     127                if (false === move_uploaded_file($uploadedFile['tmp_name'], $sFilePath)) {
     128                    $iErrorNumber = CKEDITOR_CONNECTOR_ERROR_ACCESS_DENIED;
     129                }
     130                else {
     131                    if (isset($detectHtml) && $detectHtml === -1 && CKEditor_Connector_Utils_FileSystem::detectHtml($sFilePath) === true) {
     132                        @unlink($sFilePath);
     133                        $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_UPLOADED_WRONG_HTML_FILE);
     134                    }
     135                    else if (isset($isImageValid) && $isImageValid === -1 && CKEditor_Connector_Utils_FileSystem::isImageValid($sFilePath, $sExtension) === false) {
     136                        @unlink($sFilePath);
     137                        $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_UPLOADED_CORRUPT);
     138                    }
     139                }
     140                if (is_file($sFilePath) && ($perms = $_config->getChmodFiles())) {
     141                    $oldumask = umask(0);
     142                    chmod($sFilePath, $perms);
     143                    umask($oldumask);
     144                }
     145                break;
     146            }
     147        }
     148
     149        $this->_errorHandler->throwError($iErrorNumber, $sFileName, false);
     150    }
     151}
  • _source/plugins/filebrowser/core/connector/php/php5/CommandHandler/GetFolders.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage CommandHandlers
     10 */
     11
     12/**
     13 * Include base XML command handler
     14 */
     15require_once CKEDITOR_CONNECTOR_LIB_DIR . "/CommandHandler/XmlCommandHandlerBase.php";
     16
     17/**
     18 * Handle GetFolders command
     19 *
     20 * @package CKEditor
     21 * @subpackage CommandHandlers
     22 */
     23class CKEditor_Connector_CommandHandler_GetFolders extends CKEditor_Connector_CommandHandler_XmlCommandHandlerBase
     24{
     25    /**
     26     * Command name
     27     *
     28     * @access private
     29     * @var string
     30     */
     31    private $command = "GetFolders";
     32
     33    /**
     34     * handle request and build XML
     35     * @access protected
     36     *
     37     */
     38    protected function buildXml()
     39    {
     40        $_config =& CKEditor_Connector_Core_Factory::getInstance("Core_Config");
     41
     42        // Map the virtual path to the local server path.
     43        $_sServerDir = $this->_currentFolder->getServerPath();
     44
     45        if (!is_dir($_sServerDir)) {
     46            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_FOLDER_NOT_FOUND);
     47        }
     48
     49        // Create the "Folders" node.
     50        $oFoldersNode = new CKEditor_Connector_Utils_XmlNode("Folders");
     51        $this->_connectorNode->addChild($oFoldersNode);
     52
     53        $files = array();
     54        if ($dh = @opendir($_sServerDir)) {
     55            while (($file = readdir($dh)) !== false) {
     56                if ($file != "." && $file != ".." && is_dir($_sServerDir . $file)) {
     57                    $files[] = $file;
     58                }
     59            }
     60            closedir($dh);
     61        } else {
     62            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_ACCESS_DENIED);
     63        }
     64
     65        $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig();
     66
     67        if (sizeof($files)>0) {
     68            natcasesort($files);
     69            $i=0;
     70            foreach ($files as $file) {
     71                // Create the "Folder" node.
     72                $oFolderNode[$i] = new CKEditor_Connector_Utils_XmlNode("Folder");
     73                $oFoldersNode->addChild($oFolderNode[$i]);
     74                $oFolderNode[$i]->addAttribute("name", CKEditor_Connector_Utils_FileSystem::convertToConnectorEncoding($file));
     75
     76                $i++;
     77            }
     78        }
     79    }
     80}
  • _source/plugins/filebrowser/core/connector/php/php5/CommandHandler/GetFoldersAndFiles.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage CommandHandlers
     10 */
     11
     12/**
     13 * Include base XML command handler
     14 */
     15require_once CKEDITOR_CONNECTOR_LIB_DIR . "/CommandHandler/XmlCommandHandlerBase.php";
     16
     17/**
     18 * Handle GetFiles command
     19 *
     20 * @package CKEditor
     21 * @subpackage CommandHandlers
     22 */
     23class CKEditor_Connector_CommandHandler_GetFoldersAndFiles extends CKEditor_Connector_CommandHandler_XmlCommandHandlerBase
     24{
     25    /**
     26     * Command name
     27     *
     28     * @access private
     29     * @var string
     30     */
     31    private $command = "GetFiles";
     32
     33    /**
     34     * handle request and build XML
     35     * @access protected
     36     *
     37     */
     38    protected function buildXml()
     39    {
     40        $_config =& CKEditor_Connector_Core_Factory::getInstance("Core_Config");
     41
     42        // Map the virtual path to the local server path.
     43        $_sServerDir = $this->_currentFolder->getServerPath();
     44
     45        $files = array();
     46        $folders = array();
     47        if ($dh = @opendir($_sServerDir)) {
     48            while (($file = readdir($dh)) !== false) {
     49                if ($file == "." || $file == "..") {
     50                    continue;
     51                }
     52                else if (!is_dir($_sServerDir . $file)) {
     53                    $files[] = $file;
     54                }
     55                else {
     56                    $folders[] = $file;
     57                }
     58            }
     59            closedir($dh);
     60        }
     61        else {
     62            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_ACCESS_DENIED);
     63        }
     64
     65        // Create the "Folders" node.
     66        $oFoldersNode = new CKEditor_Connector_Utils_XmlNode("Folders");
     67        $this->_connectorNode->addChild($oFoldersNode);
     68
     69
     70        $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig();
     71
     72        if (sizeof($folders)>0) {
     73            natcasesort($folders);
     74            $i=0;
     75            foreach ($folders as $file) {
     76                // Create the "Folder" node.
     77                $oFolderNode[$i] = new CKEditor_Connector_Utils_XmlNode("Folder");
     78                $oFoldersNode->addChild($oFolderNode[$i]);
     79                $oFolderNode[$i]->addAttribute("name", CKEditor_Connector_Utils_FileSystem::convertToConnectorEncoding($file));
     80
     81                $i++;
     82            }
     83        }
     84
     85        // Create the "Files" node.
     86        $oFilesNode = new CKEditor_Connector_Utils_XmlNode("Files");
     87        $this->_connectorNode->addChild($oFilesNode);
     88
     89        if (!is_dir($_sServerDir)) {
     90            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_FOLDER_NOT_FOUND);
     91        }
     92
     93        if (sizeof($files)>0) {
     94            natcasesort($files);
     95            $i=0;
     96            foreach ($files as $file) {
     97                $filemtime = @filemtime($_sServerDir . $file);
     98
     99                //otherwise file doesn't exist or we can't get it's filename properly
     100                if ($filemtime !== false) {
     101                    $filename = basename($file);
     102                    if (!$resourceTypeInfo->checkExtension($filename, false)) {
     103                        continue;
     104                    }
     105                    $oFileNode[$i] = new CKEditor_Connector_Utils_XmlNode("File");
     106                    $oFilesNode->addChild($oFileNode[$i]);
     107                    $oFileNode[$i]->addAttribute("name", CKEditor_Connector_Utils_FileSystem::convertToConnectorEncoding(basename($file)));
     108                    $oFileNode[$i]->addAttribute("date", @date("YmdHi", $filemtime));
     109                    $size = filesize($_sServerDir . $file);
     110                    if ($size && $size<1024) {
     111                        $size = 1;
     112                    }
     113                    else {
     114                        $size = (int)round($size / 1024);
     115                    }
     116                    $oFileNode[$i]->addAttribute("size", $size);
     117                    $i++;
     118                }
     119            }
     120        }
     121    }
     122}
  • _source/plugins/filebrowser/core/connector/php/php5/CommandHandler/Init.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage CommandHandlers
     10 */
     11
     12/**
     13 * Include base XML command handler
     14 */
     15require_once CKEDITOR_CONNECTOR_LIB_DIR . "/CommandHandler/XmlCommandHandlerBase.php";
     16
     17/**
     18 * Handle Init command
     19 *
     20 * @package CKEditor
     21 * @subpackage CommandHandlers
     22 */
     23class CKEditor_Connector_CommandHandler_Init extends CKEditor_Connector_CommandHandler_XmlCommandHandlerBase
     24{
     25    /**
     26     * Command name
     27     *
     28     * @access private
     29     * @var string
     30     */
     31    private $command = "Init";
     32
     33    protected function mustCheckRequest()
     34    {
     35        return false;
     36    }
     37
     38    /**
     39     * Must add CurrentFolder node?
     40     *
     41     * @return boolean
     42     * @access protected
     43     */
     44    protected function mustAddCurrentFolderNode()
     45    {
     46        return false;
     47    }
     48
     49    /**
     50     * handle request and build XML
     51     * @access protected
     52     *
     53     */
     54    protected function buildXml()
     55    {
     56        $_config =& CKEditor_Connector_Core_Factory::getInstance("Core_Config");
     57
     58        // Create the "ConnectorInfo" node.
     59        $_oConnInfo = new CKEditor_Connector_Utils_XmlNode("ConnectorInfo");
     60        $this->_connectorNode->addChild($_oConnInfo);
     61        $_oConnInfo->addAttribute("enabled", $_config->getIsEnabled() ? "true" : "false");
     62
     63        if (!$_config->getIsEnabled()) {
     64            $this->_errorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_CONNECTOR_DISABLED);
     65        }
     66
     67        // Create the "ResourceTypes" node.
     68        $_oResourceTypes = new CKEditor_Connector_Utils_XmlNode("ResourceTypes");
     69        $this->_connectorNode->addChild($_oResourceTypes);
     70
     71        // Load the resource types in an array.
     72        $_aTypes = $_config->getDefaultResourceTypes();
     73
     74        if (!sizeof($_aTypes)) {
     75            $_aTypes = $_config->getResourceTypeNames();
     76        }
     77
     78        $_aTypesSize = sizeof($_aTypes);
     79        if ($_aTypesSize) {
     80            for ($i = 0; $i < $_aTypesSize; $i++)
     81            {
     82                $_resourceTypeName = $_aTypes[$i];
     83
     84                if (!isset($_GET['type']) || $_GET['type'] === $_resourceTypeName) {
     85                    $_oTypeInfo = $_config->getResourceTypeConfig($_resourceTypeName);
     86                    $_oResourceType[$i] = new CKEditor_Connector_Utils_XmlNode("ResourceType");
     87                    $_oResourceTypes->addChild($_oResourceType[$i]);
     88
     89                    $_oResourceType[$i]->addAttribute("name", $_resourceTypeName);
     90                    $_oResourceType[$i]->addAttribute("url", $_oTypeInfo->getUrl());
     91                    $_oResourceType[$i]->addAttribute("allowedExtensions", implode(",", $_oTypeInfo->getAllowedExtensions()));
     92                    $_oResourceType[$i]->addAttribute("deniedExtensions", implode(",", $_oTypeInfo->getDeniedExtensions()));
     93                }
     94            }
     95        }
     96    }
     97}
  • _source/plugins/filebrowser/core/connector/php/php5/CommandHandler/QuickUpload.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage CommandHandlers
     10 */
     11
     12/**
     13 * Include file upload command handler
     14 */
     15require_once CKEDITOR_CONNECTOR_LIB_DIR . "/CommandHandler/FileUpload.php";
     16
     17/**
     18 * Handle QuickUpload command
     19 *
     20 * @package CKEditor
     21 * @subpackage CommandHandlers
     22 */
     23class CKEditor_Connector_CommandHandler_QuickUpload extends CKEditor_Connector_CommandHandler_FileUpload
     24{
     25    /**
     26     * Command name
     27     *
     28     * @access protected
     29     * @var string
     30     */
     31    protected $command = "QuickUpload";
     32
     33    function sendResponse()
     34    {
     35        $oRegistry =& CKEditor_Connector_Core_Factory::getInstance("Core_Registry");
     36        $oRegistry->set("FileUpload_url", $this->_currentFolder->getUrl());
     37
     38        return parent::sendResponse();
     39    }
     40}
  • _source/plugins/filebrowser/core/connector/php/php5/CommandHandler/XmlCommandHandlerBase.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage CommandHandlers
     10 */
     11
     12/**
     13 * Include base command handler
     14 */
     15require_once CKEDITOR_CONNECTOR_LIB_DIR . "/CommandHandler/CommandHandlerBase.php";
     16/**
     17 * Include xml utils
     18 */
     19require_once CKEDITOR_CONNECTOR_LIB_DIR . "/Core/Xml.php";
     20
     21/**
     22 * Base XML commands handler
     23 *
     24 * @package CKEditor
     25 * @subpackage CommandHandlers
     26 * @abstract
     27 */
     28abstract class CKEditor_Connector_CommandHandler_XmlCommandHandlerBase extends CKEditor_Connector_CommandHandler_CommandHandlerBase
     29{
     30    /**
     31     * Connector node - CKEditor_Connector_Utils_XmlNode object
     32     *
     33     * @var CKEditor_Connector_Utils_XmlNode
     34     * @access protected
     35     */
     36    protected $_connectorNode;
     37
     38    /**
     39     * send response
     40     * @access public
     41     *
     42     */
     43    public function sendResponse()
     44    {
     45        $xml =& CKEditor_Connector_Core_Factory::getInstance("Core_Xml");
     46        $this->_connectorNode =& $xml->getConnectorNode();
     47
     48        $this->checkConnector();
     49        if ($this->mustCheckRequest()) {
     50            $this->checkRequest();
     51        }
     52
     53        $resourceTypeName = $this->_currentFolder->getResourceTypeName();
     54        if (!empty($resourceTypeName)) {
     55            $this->_connectorNode->addAttribute("resourceType", $this->_currentFolder->getResourceTypeName());
     56        }
     57
     58        if ($this->mustAddCurrentFolderNode()) {
     59            $_currentFolder = new CKEditor_Connector_Utils_XmlNode("CurrentFolder");
     60            $this->_connectorNode->addChild($_currentFolder);
     61            $_currentFolder->addAttribute("path", CKEditor_Connector_Utils_FileSystem::convertToConnectorEncoding($this->_currentFolder->getClientPath()));
     62
     63            $this->_errorHandler->setCatchAllErros(true);
     64            $_url = $this->_currentFolder->getUrl();
     65            $_currentFolder->addAttribute("url", is_null($_url) ? "" : CKEditor_Connector_Utils_FileSystem::convertToConnectorEncoding($_url));
     66            $this->_errorHandler->setCatchAllErros(false);
     67        }
     68
     69        $this->buildXml();
     70
     71        $_oErrorNode =& $xml->getErrorNode();
     72        $_oErrorNode->addAttribute("number", "0");
     73
     74        echo $this->_connectorNode->asXML();
     75        exit;
     76    }
     77
     78    /**
     79     * Must check request?
     80     *
     81     * @return boolean
     82     * @access protected
     83     */
     84    protected function mustCheckRequest()
     85    {
     86        return true;
     87    }
     88
     89    /**
     90     * Must add CurrentFolder node?
     91     *
     92     * @return boolean
     93     * @access protected
     94     */
     95    protected function mustAddCurrentFolderNode()
     96    {
     97        return true;
     98    }
     99
     100    /**
     101     * @access protected
     102     * @abstract
     103     * @return void
     104     */
     105    abstract protected function buildXml();
     106}
  • _source/plugins/filebrowser/core/connector/php/php5/Core/Config.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage Config
     10 */
     11
     12/**
     13 * Include resource type config class
     14 */
     15require_once CKEDITOR_CONNECTOR_LIB_DIR . "/Core/ResourceTypeConfig.php";
     16
     17/**
     18 * Main config parser
     19 *
     20 *
     21 * @package CKEditor
     22 * @subpackage Config
     23
     24 * @global string $GLOBALS['config']
     25 */
     26class CKEditor_Connector_Core_Config
     27{
     28    /**
     29     * Is CKEditor enabled
     30     *
     31     * @var boolean
     32     * @access private
     33     */
     34    private $_isEnabled = false;
     35    /**
     36     * ResourceType config cache
     37     *
     38     * @var array
     39     * @access private
     40     */
     41    private $_resourceTypeConfigCache = array();
     42    /**
     43     * Array with default resource types names
     44     *
     45     * @access private
     46     * @var array
     47     */
     48    private $_defaultResourceTypes = array();
     49    /**
     50     * Filesystem encoding
     51     *
     52     * @var string
     53     * @access private
     54     */
     55    private $_filesystemEncoding;
     56    /**
     57     * Check double extension
     58     *
     59     * @var boolean
     60     * @access private
     61     */
     62    private $_checkDoubleExtension = true;
     63    /**
     64     * If set to true, validate image size
     65     *
     66     * @var boolean
     67     * @access private
     68     */
     69    private $_secureImageUploads = true;
     70    /**
     71     * For security, HTML is allowed in the first Kb of data for files having the following extensions only
     72     *
     73     * @var array
     74     * @access private
     75     */
     76    private $_htmlExtensions = array('html', 'htm', 'xml', 'xsd', 'txt', 'js');
     77    /**
     78     * Chmod files after upload to the following permission
     79     *
     80     * @var integer
     81     * @access private
     82     */
     83    private $_chmodFiles = 0777;
     84    /**
     85     * Chmod directories after creation
     86     *
     87     * @var integer
     88     * @access private
     89     */
     90    private $_chmodFolders = 0755;
     91
     92    function __construct()
     93    {
     94        $this->loadValues();
     95    }
     96
     97    /**
     98         * Get file system encoding, returns null if encoding is not set
     99         *
     100         * @access public
     101         * @return string
     102         */
     103    public function getFilesystemEncoding()
     104    {
     105        return $this->_filesystemEncoding;
     106    }
     107
     108    /**
     109         * Get "secureImageUploads" value
     110         *
     111         * @access public
     112         * @return boolean
     113         */
     114    public function getSecureImageUploads()
     115    {
     116        return $this->_secureImageUploads;
     117    }
     118
     119    /**
     120         * Get "htmlExtensions" value
     121         *
     122         * @access public
     123         * @return array
     124         */
     125    public function getHtmlExtensions()
     126    {
     127        return $this->_htmlExtensions;
     128    }
     129
     130    /**
     131         * Get "Check double extension" value
     132         *
     133         * @access public
     134         * @return boolean
     135         */
     136    public function getCheckDoubleExtension()
     137    {
     138        return $this->_checkDoubleExtension;
     139    }
     140
     141    /**
     142         * Get default resource types
     143         *
     144         * @access public
     145         * @return array()
     146         */
     147    public function getDefaultResourceTypes()
     148    {
     149        return $this->_defaultResourceTypes;
     150    }
     151
     152    /**
     153         * Is CKEditor enabled
     154         *
     155         * @access public
     156         * @return boolean
     157         */
     158    public function getIsEnabled()
     159    {
     160        return $this->_isEnabled;
     161    }
     162
     163    /**
     164        * Get chmod settings for uploaded files
     165        *
     166        * @access public
     167        * @return integer
     168        */
     169    public function getChmodFiles()
     170    {
     171        return $this->_chmodFiles;
     172    }
     173
     174    /**
     175        * Get chmod settings for created directories
     176        *
     177        * @access public
     178        * @return integer
     179        */
     180    public function getChmodFolders()
     181    {
     182        return $this->_chmodFolders;
     183    }
     184
     185    /**
     186         * Get resourceTypeName config
     187         *
     188         * @param string $resourceTypeName
     189         * @return CKEditor_Connector_Core_ResourceTypeConfig|null
     190         * @access public
     191         */
     192    public function &getResourceTypeConfig($resourceTypeName)
     193    {
     194        $_null = null;
     195
     196        if (isset($this->_resourceTypeConfigCache[$resourceTypeName])) {
     197            return $this->_resourceTypeConfigCache[$resourceTypeName];
     198        }
     199
     200        if (!isset($GLOBALS['config']['ResourceType']) || !is_array($GLOBALS['config']['ResourceType'])) {
     201            return $_null;
     202        }
     203
     204        reset($GLOBALS['config']['ResourceType']);
     205        while (list($_key,$_resourceTypeNode) = each($GLOBALS['config']['ResourceType'])) {
     206            if ($_resourceTypeNode['name'] === $resourceTypeName) {
     207                $this->_resourceTypeConfigCache[$resourceTypeName] = new CKEditor_Connector_Core_ResourceTypeConfig($_resourceTypeNode);
     208
     209                return $this->_resourceTypeConfigCache[$resourceTypeName];
     210            }
     211        }
     212
     213        return $_null;
     214    }
     215
     216    /**
     217     * Load values from config
     218     *
     219     * @access private
     220     */
     221    private function loadValues()
     222    {
     223        if (function_exists('CheckAuthentication')) {
     224            $this->_isEnabled = CheckAuthentication();
     225        }
     226        if (isset($GLOBALS['config']['FilesystemEncoding'])) {
     227            $this->_filesystemEncoding = (string)$GLOBALS['config']['FilesystemEncoding'];
     228        }
     229        if (isset($GLOBALS['config']['CheckDoubleExtension'])) {
     230            $this->_checkDoubleExtension = CKEditor_Connector_Utils_Misc::booleanValue($GLOBALS['config']['CheckDoubleExtension']);
     231        }
     232        if (isset($GLOBALS['config']['SecureImageUploads'])) {
     233            $this->_secureImageUploads = CKEditor_Connector_Utils_Misc::booleanValue($GLOBALS['config']['SecureImageUploads']);
     234        }
     235        if (isset($GLOBALS['config']['HtmlExtensions'])) {
     236            $this->_htmlExtensions = (array)$GLOBALS['config']['HtmlExtensions'];
     237        }
     238        if (isset($GLOBALS['config']['ChmodFiles'])) {
     239            $this->_chmodFiles = $GLOBALS['config']['ChmodFiles'];
     240        }
     241        if (isset($GLOBALS['config']['ChmodFolders'])) {
     242            $this->_chmodFolders = $GLOBALS['config']['ChmodFolders'];
     243        }
     244        if (isset($GLOBALS['config']['DefaultResourceTypes'])) {
     245            $_defaultResourceTypes = (string)$GLOBALS['config']['DefaultResourceTypes'];
     246            if (strlen($_defaultResourceTypes)) {
     247                $this->_defaultResourceTypes = explode(",", $_defaultResourceTypes);
     248            }
     249        }
     250    }
     251
     252    /**
     253     * Get all resource type names defined in config
     254     *
     255     * @return array
     256     * @access public
     257     */
     258    public function getResourceTypeNames()
     259    {
     260        if (!isset($GLOBALS['config']['ResourceType']) || !is_array($GLOBALS['config']['ResourceType'])) {
     261            return array();
     262        }
     263
     264        $_names = array();
     265        foreach ($GLOBALS['config']['ResourceType'] as $key => $_resourceType) {
     266            if (isset($_resourceType['name'])) {
     267                $_names[] = (string)$_resourceType['name'];
     268            }
     269        }
     270
     271        return $_names;
     272    }
     273}
     274 No newline at end of file
  • _source/plugins/filebrowser/core/connector/php/php5/Core/Connector.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage Core
     10 */
     11
     12/**
     13 * Executes all commands
     14 *
     15 * @package CKEditor
     16 * @subpackage Core
     17 */
     18class CKEditor_Connector_Core_Connector
     19{
     20    /**
     21     * Registry
     22     *
     23     * @var CKEditor_Connector_Core_Registry
     24     * @access private
     25     */
     26    private $_registry;
     27
     28    function __construct()
     29    {
     30        $this->_registry =& CKEditor_Connector_Core_Factory::getInstance("Core_Registry");
     31        $this->_registry->set("errorHandler", "ErrorHandler_Base");
     32    }
     33
     34    /**
     35     * Generic handler for invalid commands
     36     * @access public
     37     *
     38     */
     39    public function handleInvalidCommand()
     40    {
     41        $oErrorHandler =& $this->getErrorHandler();
     42        $oErrorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_INVALID_COMMAND);
     43    }
     44
     45    /**
     46     * Execute command
     47     *
     48     * @param string $command
     49     * @access public
     50     */
     51    public function executeCommand($command)
     52    {
     53        switch ($command)
     54        {
     55            case 'FileUpload':
     56                $this->_registry->set("errorHandler", "ErrorHandler_FileUpload");
     57                $obj =& CKEditor_Connector_Core_Factory::getInstance("CommandHandler_".$command);
     58                $obj->sendResponse();
     59                break;
     60
     61            case 'QuickUpload':
     62                $this->_registry->set("errorHandler", "ErrorHandler_QuickUpload");
     63                $obj =& CKEditor_Connector_Core_Factory::getInstance("CommandHandler_".$command);
     64                $obj->sendResponse();
     65                break;
     66
     67            case 'CreateFolder':
     68            case 'GetFolders':
     69            case 'GetFoldersAndFiles':
     70            case 'Init':
     71                $obj =& CKEditor_Connector_Core_Factory::getInstance("CommandHandler_".$command);
     72                $obj->sendResponse();
     73                break;
     74
     75            default:
     76                $this->handleInvalidCommand();
     77                break;
     78        }
     79    }
     80
     81    /**
     82     * Get error handler
     83     *
     84     * @access public
     85     * @return CKEditor_Connector_ErrorHandler_Base|CKEditor_Connector_ErrorHandler_FileUpload|CKEditor_Connector_ErrorHandler_Http
     86     */
     87    public function &getErrorHandler()
     88    {
     89        $_errorHandler = $this->_registry->get("errorHandler");
     90        $oErrorHandler =& CKEditor_Connector_Core_Factory::getInstance($_errorHandler);
     91        return $oErrorHandler;
     92    }
     93}
     94 No newline at end of file
  • _source/plugins/filebrowser/core/connector/php/php5/Core/Factory.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage Core
     10 */
     11
     12/**
     13 * Sigleton factory creating objects
     14 *
     15 * @package CKEditor
     16 * @subpackage Core
     17 */
     18class CKEditor_Connector_Core_Factory
     19{
     20    static $instances = array();
     21
     22    /**
     23     * Initiate factory
     24     * @static
     25     */
     26    static function initFactory()
     27    {
     28    }
     29
     30    /**
     31     * Get instance of specified class
     32     * Short and Long class names are possible
     33     * <code>
     34     * $obj1 =& CKEditor_Connector_Core_Factory::getInstance("CKEditor_Connector_Core_Xml");
     35     * $obj2 =& CKEditor_Connector_Core_Factory::getInstance("Core_Xml");
     36     * </code>
     37     *
     38     * @param string $className class name
     39     * @static
     40     * @access public
     41     * @return object
     42     */
     43    public static function &getInstance($className)
     44    {
     45        $namespace = "CKEditor_Connector_";
     46
     47        $baseName = str_replace($namespace,"",$className);
     48
     49        $className = $namespace.$baseName;
     50
     51        if (!isset(CKEditor_Connector_Core_Factory::$instances[$className])) {
     52            require_once CKEDITOR_CONNECTOR_LIB_DIR . "/" . str_replace("_","/",$baseName).".php";
     53            CKEditor_Connector_Core_Factory::$instances[$className] = new $className;
     54        }
     55
     56        return CKEditor_Connector_Core_Factory::$instances[$className];
     57    }
     58}
     59 No newline at end of file
  • _source/plugins/filebrowser/core/connector/php/php5/Core/FolderHandler.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage Core
     10 */
     11
     12/**
     13 * Include file system utils class
     14 */
     15require_once CKEDITOR_CONNECTOR_LIB_DIR . "/Utils/FileSystem.php";
     16
     17/**
     18 * @package CKEditor
     19 * @subpackage Core
     20 */
     21class CKEditor_Connector_Core_FolderHandler
     22{
     23    /**
     24     * CKEditor_Connector_Core_ResourceTypeConfig object
     25     *
     26     * @var CKEditor_Connector_Core_ResourceTypeConfig
     27     * @access private
     28     */
     29    private $_resourceTypeConfig;
     30    /**
     31     * ResourceType name
     32     *
     33     * @var string
     34     * @access private
     35     */
     36    private $_resourceTypeName = "";
     37    /**
     38     * Client path
     39     *
     40     * @var string
     41     * @access private
     42     */
     43    private $_clientPath = "/";
     44    /**
     45     * Url
     46     *
     47     * @var string
     48     * @access private
     49     */
     50    private $_url;
     51    /**
     52     * Server path
     53     *
     54     * @var string
     55     * @access private
     56     */
     57    private $_serverPath;
     58    /**
     59     * Folder info
     60     *
     61     * @var mixed
     62     * @access private
     63     */
     64    private $_folderInfo;
     65
     66    function __construct()
     67    {
     68        if (isset($_GET["type"])) {
     69            $this->_resourceTypeName = (string)$_GET["type"];
     70        }
     71
     72        if (isset($_GET["currentFolder"])) {
     73            $this->_clientPath = CKEditor_Connector_Utils_FileSystem::convertToFilesystemEncoding((string)$_GET["currentFolder"]);
     74        }
     75
     76        if (!strlen($this->_clientPath)) {
     77            $this->_clientPath = "/";
     78        }
     79        else {
     80            if (substr($this->_clientPath, -1, 1) != "/") {
     81                $this->_clientPath .= "/";
     82            }
     83            if (substr($this->_clientPath, 0, 1) != "/") {
     84                $this->_clientPath = "/" . $this->_clientPath;
     85            }
     86        }
     87    }
     88
     89    /**
     90     * Get resource type config
     91     *
     92     * @return CKEditor_Connector_Core_ResourceTypeConfig
     93     * @access public
     94     */
     95    public function &getResourceTypeConfig()
     96    {
     97        if (!isset($this->_resourceTypeConfig)) {
     98            $_config =& CKEditor_Connector_Core_Factory::getInstance("Core_Config");
     99            $this->_resourceTypeConfig = $_config->getResourceTypeConfig($this->_resourceTypeName);
     100        }
     101
     102        if (is_null($this->_resourceTypeConfig)) {
     103            $connector =& CKEditor_Connector_Core_Factory::getInstance("Core_Connector");
     104            $oErrorHandler =& $connector->getErrorHandler();
     105            $oErrorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_INVALID_TYPE);
     106        }
     107
     108        return $this->_resourceTypeConfig;
     109    }
     110
     111    /**
     112     * Get resource type name
     113     *
     114     * @return string
     115     * @access public
     116     */
     117    public function getResourceTypeName()
     118    {
     119        return $this->_resourceTypeName;
     120    }
     121
     122    /**
     123     * Get Client path
     124     *
     125     * @return string
     126     * @access public
     127     */
     128    public function getClientPath()
     129    {
     130        return $this->_clientPath;
     131    }
     132
     133    /**
     134     * Get Url
     135     *
     136     * @return string
     137     * @access public
     138     */
     139    public function getUrl()
     140    {
     141        if (is_null($this->_url)) {
     142            $this->_resourceTypeConfig = $this->getResourceTypeConfig();
     143            if (is_null($this->_resourceTypeConfig)) {
     144                $connector =& CKEditor_Connector_Core_Factory::getInstance("Core_Connector");
     145                $oErrorHandler =& $connector->getErrorHandler();
     146                $oErrorHandler->throwError(CKEDITOR_CONNECTOR_ERROR_INVALID_TYPE);
     147                $this->_url = "";
     148            }
     149            else {
     150                $this->_url = $this->_resourceTypeConfig->getUrl() . ltrim($this->getClientPath(), "/");
     151            }
     152        }
     153
     154        return $this->_url;
     155    }
     156
     157    /**
     158     * Get server path
     159     *
     160     * @return string
     161     * @access public
     162     */
     163    public function getServerPath()
     164    {
     165        if (is_null($this->_serverPath)) {
     166            $this->_resourceTypeConfig = $this->getResourceTypeConfig();
     167            $this->_serverPath = CKEditor_Connector_Utils_FileSystem::combinePaths($this->_resourceTypeConfig->getDirectory(), ltrim($this->_clientPath, "/"));
     168        }
     169
     170        return $this->_serverPath;
     171    }
     172}
     173 No newline at end of file
  • _source/plugins/filebrowser/core/connector/php/php5/Core/Registry.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage Core
     10 */
     11
     12/**
     13 * Registry for storing global variables values (not references)
     14 *
     15 * @package CKEditor
     16 * @subpackage Core
     17 */
     18class CKEditor_Connector_Core_Registry
     19{
     20    /**
     21     * Arrat that stores all values
     22     *
     23     * @var array
     24     * @access private
     25     */
     26    private $_store = array();
     27
     28    /**
     29     * Chacke if value has been set
     30     *
     31     * @param string $key
     32     * @return boolean
     33     * @access private
     34     */
     35    private function isValid($key)
     36    {
     37        return array_key_exists($key, $this->_store);
     38    }
     39
     40    /**
     41     * Set value
     42     *
     43     * @param string $key
     44     * @param mixed $obj
     45     * @access public
     46     */
     47    public function set($key, $obj)
     48    {
     49        $this->_store[$key] = $obj;
     50    }
     51
     52    /**
     53     * Get value
     54     *
     55     * @param string $key
     56     * @return mixed
     57     * @access public
     58     */
     59    public function get($key)
     60    {
     61        if ($this->isValid($key)) {
     62            return $this->_store[$key];
     63        }
     64    }
     65}
     66 No newline at end of file
  • _source/plugins/filebrowser/core/connector/php/php5/Core/ResourceTypeConfig.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage Config
     10 */
     11
     12/**
     13 * This class keeps resource types configuration
     14 *
     15 * @package CKEditor
     16 * @subpackage Config
     17 */
     18class CKEditor_Connector_Core_ResourceTypeConfig
     19{
     20    /**
     21     * Resource name
     22     *
     23     * @var string
     24     * @access private
     25     */
     26    private $_name = "";
     27    /**
     28     * Resource url
     29     *
     30     * @var string
     31     * @access private
     32     */
     33    private $_url = "";
     34    /**
     35     * Directory path on a server
     36     *
     37     * @var string
     38     * @access private
     39     */
     40    private $_directory = "";
     41    /**
     42     * Array with allowed extensions
     43     *
     44     * @var array[]string
     45     * @access private
     46     */
     47    private $_allowedExtensions = array();
     48    /**
     49     * Array with denied extensions
     50     *
     51     * @var array[]string
     52     * @access private
     53     */
     54    private $_deniedExtensions = array();
     55    /**
     56     * used for CKEditor_Connector_Core_Config object caching
     57     *
     58     * @var CKEditor_Connector_Core_Config
     59     * @access private
     60     */
     61    private $_config;
     62
     63    /**
     64     * Get ResourceType configuration
     65     *
     66     * @param string $resourceTypeNode
     67     * @return array
     68     *
     69     */
     70    function __construct($resourceTypeNode)
     71    {
     72        if (isset($resourceTypeNode["name"])) {
     73            $this->_name = $resourceTypeNode["name"];
     74        }
     75
     76        if (isset($resourceTypeNode["url"])) {
     77            $this->_url = $resourceTypeNode["url"];
     78        }
     79
     80        if (!strlen($this->_url)) {
     81            $this->_url = "/";
     82        }
     83        else if (substr($this->_url,-1,1) != "/") {
     84            $this->_url .= "/";
     85        }
     86
     87        if (isset($resourceTypeNode["directory"])) {
     88            $this->_directory = $resourceTypeNode["directory"];
     89        }
     90
     91        if (!strlen($this->_directory)) {
     92            $this->_directory = resolveUrl($this->_url);
     93        }
     94
     95        if (isset($resourceTypeNode["allowedExtensions"])) {
     96            if (is_array($resourceTypeNode["allowedExtensions"])) {
     97                foreach ($resourceTypeNode["allowedExtensions"] as $extension) {
     98                    $this->_allowedExtensions[] = strtolower(trim((string)$e));
     99                }
     100            }
     101            else {
     102                $resourceTypeNode["allowedExtensions"] = trim((string)$resourceTypeNode["allowedExtensions"]);
     103                if (strlen($resourceTypeNode["allowedExtensions"])) {
     104                    $extensions = explode(",", $resourceTypeNode["allowedExtensions"]);
     105                    foreach ($extensions as $e) {
     106                        $this->_allowedExtensions[] = strtolower(trim($e));
     107                    }
     108                }
     109            }
     110        }
     111
     112        if (isset($resourceTypeNode["deniedExtensions"])) {
     113            if (is_array($resourceTypeNode["deniedExtensions"])) {
     114
     115                foreach ($resourceTypeNode["deniedExtensions"] as $extension) {
     116                    $this->_deniedExtensions[] = strtolower(trim((string)$e));
     117                }
     118            }
     119            else {
     120                $resourceTypeNode["deniedExtensions"] = trim((string)$resourceTypeNode["deniedExtensions"]);
     121                if (strlen($resourceTypeNode["deniedExtensions"])) {
     122                    $extensions = explode(",", $resourceTypeNode["deniedExtensions"]);
     123                    foreach ($extensions as $e) {
     124                        $this->_deniedExtensions[] = strtolower(trim($e));
     125                    }
     126                }
     127            }
     128        }
     129    }
     130
     131    /**
     132     * Get name
     133     *
     134     * @access public
     135     * @return string
     136     */
     137    public function getName()
     138    {
     139        return $this->_name;
     140    }
     141
     142    /**
     143     * Get url
     144     *
     145     * @access public
     146     * @return string
     147     */
     148    public function getUrl()
     149    {
     150        return $this->_url;
     151    }
     152
     153    /**
     154     * Get directory
     155     *
     156     * @access public
     157     * @return string
     158     */
     159    public function getDirectory()
     160    {
     161        return $this->_directory;
     162    }
     163
     164    /**
     165     * Get allowed extensions
     166     *
     167     * @access public
     168     * @return array[]string
     169     */
     170    public function getAllowedExtensions()
     171    {
     172        return $this->_allowedExtensions;
     173    }
     174
     175    /**
     176     * Get denied extensions
     177     *
     178     * @access public
     179     * @return array[]string
     180     */
     181    public function getDeniedExtensions()
     182    {
     183        return $this->_deniedExtensions;
     184    }
     185
     186    /**
     187     * Check extension, return true if file name is valid.
     188     * Return false if extension is on denied list.
     189     * If allowed extensions are defined, return false if extension isn't on allowed list.
     190     *
     191     * @access public
     192     * @param string $extension extension
     193     * @param boolean $renameIfRequired whether try to rename file or not
     194     * @return boolean
     195     */
     196    public function checkExtension(&$fileName, $renameIfRequired = true)
     197    {
     198        if (strpos($fileName, '.') === false) {
     199            return true;
     200        }
     201
     202        if (is_null($this->_config)) {
     203            $this->_config =& CKEditor_Connector_Core_Factory::getInstance("Core_Config");
     204        }
     205
     206        $toCheck = array();
     207
     208        if ($this->_config->getCheckDoubleExtension()) {
     209            $pieces = explode('.', $fileName);
     210
     211            // First, check the last extension (ex. in file.php.jpg, the "jpg").
     212            if ( !$this->checkSingleExtension( $pieces[sizeof($pieces)-1] ) ) {
     213                return false;
     214            }
     215
     216            if ($renameIfRequired) {
     217                // Check the other extensions, rebuilding the file name. If an extension is
     218                // not allowed, replace the dot with an underscore.
     219                $fileName = $pieces[0] ;
     220                for ($i=1; $i<sizeof($pieces)-1; $i++) {
     221                    $fileName .= $this->checkSingleExtension( $pieces[$i] ) ? '.' : '_' ;
     222                    $fileName .= $pieces[$i];
     223                }
     224
     225                // Add the last extension to the final name.
     226                $fileName .= '.' . $pieces[sizeof($pieces)-1] ;
     227            }
     228        }
     229        else {
     230            // Check only the last extension (ex. in file.php.jpg, only "jpg").
     231            return $this->checkSingleExtension( substr($fileName, strrpos($fileName,'.')+1) );
     232        }
     233
     234        return true;
     235    }
     236
     237    public function checkSingleExtension($extension)
     238    {
     239        $extension = strtolower(ltrim($extension,'.'));
     240
     241        if (sizeof($this->_deniedExtensions)) {
     242            if (in_array($extension, $this->_deniedExtensions)) {
     243                return false;
     244            }
     245        }
     246
     247        if (sizeof($this->_allowedExtensions)) {
     248            return in_array($extension, $this->_allowedExtensions);
     249        }
     250
     251        return true;
     252    }
     253}
  • _source/plugins/filebrowser/core/connector/php/php5/Core/Xml.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage Core
     10 */
     11
     12/**
     13 * Include basic Xml library
     14 */
     15require_once CKEDITOR_CONNECTOR_LIB_DIR . "/Utils/XmlNode.php";
     16
     17/**
     18 * XML document
     19 *
     20 * @package CKEditor
     21 * @subpackage Core
     22 */
     23class CKEditor_Connector_Core_Xml
     24{
     25    /**
     26     * Connector node (root)
     27     *
     28     * @var CKEditor_Connector_Utils_XmlNode
     29     * @access private
     30     */
     31    private $_connectorNode;
     32    /**
     33     * Error node
     34     *
     35     * @var CKEditor_Connector_Utils_XmlNode
     36     * @access private
     37     */
     38    private $_errorNode;
     39
     40    function __construct()
     41    {
     42        $this->sendXmlHeaders();
     43        echo $this->getXMLDeclaration();
     44        $this->_connectorNode = new CKEditor_Connector_Utils_XmlNode("Connector");
     45        $this->_errorNode = new CKEditor_Connector_Utils_XmlNode("Error");
     46        $this->_connectorNode->addChild($this->_errorNode);
     47    }
     48
     49    /**
     50     * Return connector node
     51     *
     52     * @return CKEditor_Connector_Utils_XmlNode
     53     * @access public
     54     */
     55    public function &getConnectorNode()
     56    {
     57        return $this->_connectorNode;
     58    }
     59
     60    /**
     61     * Return error node
     62     *
     63     * @return CKEditor_Connector_Utils_XmlNode
     64     * @access public
     65     */
     66    public function &getErrorNode()
     67    {
     68        return $this->_errorNode;
     69    }
     70
     71    /**
     72     * Send XML headers to the browser (and force browser not to use cache)
     73     * @access private
     74     */
     75    private function sendXmlHeaders()
     76    {
     77        // Prevent the browser from caching the result.
     78        // Date in the past
     79        header('Expires: Mon, 26 Jul 1997 05:00:00 GMT') ;
     80        // always modified
     81        header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT') ;
     82        // HTTP/1.1
     83        header('Cache-Control: no-store, no-cache, must-revalidate') ;
     84        header('Cache-Control: post-check=0, pre-check=0', false) ;
     85        // HTTP/1.0
     86        header('Pragma: no-cache') ;
     87
     88        // Set the response format.
     89        header( 'Content-Type:text/xml; charset=utf-8' ) ;
     90    }
     91
     92    /**
     93     * Return XML declaration
     94     *
     95     * @access private
     96     * @return string
     97     */
     98    private function getXMLDeclaration()
     99    {
     100        return '<?xml version="1.0" encoding="utf-8"?>';
     101    }
     102
     103    /**
     104     * Send error message to the browser. If error number is set to 1, $text (custom error message) will be displayed
     105     * Don't call this function directly
     106     *
     107     * @access public
     108     * @param int $number error number
     109     * @param string $text Custom error message (optional)
     110     */
     111    public function raiseError( $number, $text = false)
     112    {
     113        $this->_errorNode->addAttribute("number", intval($number));
     114        if (false!=$text) {
     115            $this->_errorNode->addAttribute("text", $text);
     116        }
     117
     118        echo $this->_connectorNode->asXML();
     119    }
     120}
     121 No newline at end of file
  • _source/plugins/filebrowser/core/connector/php/php5/ErrorHandler/Base.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage ErrorHandler
     10 */
     11
     12/**
     13 * Basic error handler
     14 *
     15 * @package CKEditor
     16 * @subpackage ErrorHandler
     17 */
     18class CKEditor_Connector_ErrorHandler_Base
     19{
     20    /**
     21     * Try/catch emulation, if set to true, error handler will not throw any error
     22     *
     23     * @var boolean
     24     * @access protected
     25     */
     26    protected $_catchAllErrors = false;
     27    /**
     28     * Array with error numbers that should be ignored
     29     *
     30     * @var array[]int
     31     * @access protected
     32     */
     33    protected $_skipErrorsArray = array();
     34
     35    /**
     36     * Set whether all errors should be ignored
     37     *
     38     * @param boolean $newValue
     39     * @access public
     40     */
     41    public function setCatchAllErros($newValue)
     42    {
     43        $this->_catchAllErrors = $newValue ? true : false;
     44    }
     45
     46    /**
     47     * Set which errors should be ignored
     48     *
     49     * @param array $newArray
     50     */
     51    public function setSkipErrorsArray($newArray)
     52    {
     53        if (is_array($newArray)) {
     54            $this->_skipErrorsArray = $newArray;
     55        }
     56    }
     57
     58    /**
     59     * Throw connector error, return true if error has been thrown, false if error has been catched
     60     *
     61     * @param int $number
     62     * @param string $text
     63     * @access public
     64     */
     65    public function throwError($number, $text = false)
     66    {
     67        if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) {
     68            return false;
     69        }
     70
     71        $_xml =& CKEditor_Connector_Core_Factory::getInstance("Core_Xml");
     72        $_xml->raiseError($number,$text);
     73
     74        exit;
     75    }
     76}
     77 No newline at end of file
  • _source/plugins/filebrowser/core/connector/php/php5/ErrorHandler/FileUpload.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage ErrorHandler
     10 */
     11
     12/**
     13 * Include base error handling class
     14 */
     15require_once CKEDITOR_CONNECTOR_LIB_DIR . "/ErrorHandler/Base.php";
     16
     17/**
     18 * File upload error handler
     19 *
     20 * @package CKEditor
     21 * @subpackage ErrorHandler
     22 */
     23class CKEditor_Connector_ErrorHandler_FileUpload extends CKEditor_Connector_ErrorHandler_Base
     24{
     25    /**
     26     * Throw file upload error, return true if error has been thrown, false if error has been catched
     27     *
     28     * @param int $number
     29     * @param string $text
     30     * @access public
     31     */
     32    public function throwError($number, $text = false, $exit = true)
     33    {
     34        if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) {
     35            return false;
     36        }
     37
     38        $oRegistry =& CKEditor_Connector_Core_Factory::getInstance("Core_Registry");
     39        $sFileName = $oRegistry->get("FileUpload_fileName");
     40
     41        echo "<script type=\"text/javascript\">";
     42        if (empty($text)) {
     43            echo "window.parent.OnUploadCompleted(" . $number . ") ;";
     44        }
     45        else {
     46            echo "window.parent.OnUploadCompleted(" . $number . ",'" . str_replace("'", "\\'", $sFileName) . "') ;";
     47        }
     48        echo "</script>";
     49
     50        if ($exit) {
     51            exit;
     52        }
     53    }
     54}
     55 No newline at end of file
  • _source/plugins/filebrowser/core/connector/php/php5/ErrorHandler/Http.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage ErrorHandler
     10 */
     11
     12/**
     13 * Include base error handling class
     14 */
     15require_once CKEDITOR_CONNECTOR_LIB_DIR . "/ErrorHandler/Base.php";
     16
     17/**
     18 * HTTP error handler
     19 *
     20 * @package CKEditor
     21 * @subpackage ErrorHandler
     22 */
     23class CKEditor_Connector_ErrorHandler_Http extends CKEditor_Connector_ErrorHandler_Base
     24{
     25    /**
     26     * Throw file upload error, return true if error has been thrown, false if error has been catched
     27     *
     28     * @param int $number
     29     * @param string $text
     30     * @access public
     31     */
     32    public function throwError($number, $text = false, $exit = true)
     33    {
     34        if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) {
     35            return false;
     36        }
     37
     38        switch ($number)
     39        {
     40            case CKEDITOR_CONNECTOR_ERROR_INVALID_REQUEST:
     41            case CKEDITOR_CONNECTOR_ERROR_INVALID_NAME:
     42            case CKEDITOR_CONNECTOR_ERROR_UNAUTHORIZED:
     43                header("HTTP/1.0 403 Forbidden");
     44                header("X-CKEditor-Error: ". $number);
     45                break;
     46
     47            case CKEDITOR_CONNECTOR_ERROR_ACCESS_DENIED:
     48                header("HTTP/1.0 500 Internal Server Error");
     49                header("X-CKEditor-Error: ".$number);
     50                break;
     51
     52            default:
     53                header("HTTP/1.0 404 Not Found");
     54                header("X-CKEditor-Error: ". $number);
     55                break;
     56        }
     57
     58        if ($exit) {
     59            exit;
     60        }
     61    }
     62}
     63 No newline at end of file
  • _source/plugins/filebrowser/core/connector/php/php5/ErrorHandler/QuickUpload.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage ErrorHandler
     10 */
     11
     12/**
     13 * Include base error handling class
     14 */
     15require_once CKEDITOR_CONNECTOR_LIB_DIR . "/ErrorHandler/Base.php";
     16
     17/**
     18 * File upload error handler
     19 *
     20 * @package CKEditor
     21 * @subpackage ErrorHandler
     22 */
     23class CKEditor_Connector_ErrorHandler_QuickUpload extends CKEditor_Connector_ErrorHandler_Base
     24{
     25    /**
     26     * Throw file upload error, return true if error has been thrown, false if error has been catched
     27     *
     28     * @param int $number
     29     * @param string $text
     30     * @access public
     31     */
     32    public function throwError($number, $text = false, $exit = true)
     33    {
     34        if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) {
     35            return false;
     36        }
     37
     38        $oRegistry =& CKEditor_Connector_Core_Factory::getInstance("Core_Registry");
     39        $sFileName = $oRegistry->get("FileUpload_fileName");
     40        $sFileUrl = $oRegistry->get("FileUpload_url");
     41
     42        echo "<script type=\"text/javascript\">";
     43        if (empty($text)) {
     44            echo "window.parent.OnUploadCompleted(" . $number . ", '', '', '') ;";
     45        }
     46        else {
     47            echo "window.parent.OnUploadCompleted(" . $number . ", '" .str_replace("'", "\\'", $sFileUrl . $sFileName). "', '" . str_replace("'", "\\'", $sFileName) . "', '') ;";
     48        }
     49        echo "</script>";
     50
     51        if ($exit) {
     52            exit;
     53        }
     54    }
     55}
     56 No newline at end of file
  • _source/plugins/filebrowser/core/connector/php/php5/Utils/FileSystem.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage Utils
     10 */
     11
     12/**
     13 * @package CKEditor
     14 * @subpackage Utils
     15 */
     16class CKEditor_Connector_Utils_FileSystem
     17{
     18
     19    /**
     20     * This function behaves similar to System.IO.Path.Combine in C#, the only diffrenece is that it also accepts null values and treat them as empty string
     21     *
     22     * @static
     23     * @access public
     24     * @param string $path1 first path
     25     * @param string $path2 scecond path
     26     * @return string
     27     */
     28    public static function combinePaths($path1, $path2)
     29    {
     30        if (is_null($path1))  {
     31            $path1 = "";
     32        }
     33        if (is_null($path2))  {
     34            $path2 = "";
     35        }
     36        if (!strlen($path2)) {
     37            if (strlen($path1)) {
     38                $_lastCharP1 = substr($path1, -1, 1);
     39                if ($_lastCharP1 != "/" && $_lastCharP1 != "\\") {
     40                    $path1 .= DIRECTORY_SEPARATOR;
     41                }
     42            }
     43        }
     44        else {
     45            $_firstCharP2 = substr($path2, 0, 1);
     46            if (strlen($path1)) {
     47                if (strpos($path2, $path1)===0) {
     48                    return $path2;
     49                }
     50                $_lastCharP1 = substr($path1, -1, 1);
     51                if ($_lastCharP1 != "/" && $_lastCharP1 != "\\" && $_firstCharP2 != "/" && $_firstCharP2 != "\\") {
     52                    $path1 .= DIRECTORY_SEPARATOR;
     53                }
     54            }
     55            else {
     56                return $path2;
     57            }
     58        }
     59        return $path1 . $path2;
     60    }
     61
     62    /**
     63     * Check whether $fileName is a valid file name, return true on success
     64     *
     65     * @static
     66     * @access public
     67     * @param string $fileName
     68     * @return boolean
     69     */
     70    public static function checkFileName($fileName)
     71    {
     72        if (is_null($fileName) || !strlen($fileName) || substr($fileName,-1,1)=="." || false!==strpos($fileName, "..")) {
     73            return false;
     74        }
     75
     76        if (preg_match(",[[:cntrl:]]|[/\\:\*\?\"\<\>\|],", $fileName)) {
     77            return false;
     78        }
     79
     80        return true;
     81    }
     82
     83    /**
     84     * Unlink file/folder
     85     *
     86     * @static
     87     * @access public
     88     * @param string $path
     89     * @return boolean
     90     */
     91    public static function unlink($path)
     92    {
     93        /*    make sure the path exists    */
     94        if (!file_exists($path)) {
     95            return false;
     96        }
     97
     98        /*    If it is a file or link, just delete it    */
     99        if (is_file($path) || is_link($path)) {
     100            return @unlink($path);
     101        }
     102
     103        /*    Scan the dir and recursively unlink    */
     104        $files = scandir($path);
     105        if ($files) {
     106            foreach($files as $filename)
     107            {
     108                if ($filename == '.' || $filename == '..') {
     109                    continue;
     110                }
     111                $file = str_replace('//','/',$path.'/'.$filename);
     112                CKEditor_Connector_Utils_FileSystem::unlink($file);
     113            }
     114        }
     115
     116        /*    Remove the parent dir    */
     117        if (!@rmdir($path)) {
     118            return false;
     119        }
     120
     121        return true;
     122    }
     123
     124    /**
     125     * Return file name without extension (without dot & last part after dot)
     126     *
     127     * @static
     128     * @access public
     129     * @param string $fileName
     130     * @return string
     131     */
     132    public static function getFileNameWithoutExtension($fileName)
     133    {
     134        $dotPos = strrpos( $fileName, '.' );
     135        if (false === $dotPos) {
     136            return $fileName;
     137        }
     138
     139        return substr($fileName, 0, $dotPos);
     140    }
     141
     142    /**
     143     * Get file extension (only last part - e.g. extension of file.foo.bar.jpg = jpg)
     144     *
     145     * @static
     146     * @access public
     147     * @param string $fileName
     148     * @return string
     149     */
     150    public static function getExtension( $fileName )
     151    {
     152        $dotPos = strrpos( $fileName, '.' );
     153        if (false === $dotPos) {
     154            return "";
     155        }
     156
     157        return substr( $fileName, strrpos( $fileName, '.' ) +1 ) ;
     158    }
     159
     160    /**
     161     * Convert file name from UTF-8 to system encoding
     162     *
     163     * @static
     164     * @access public
     165     * @param string $fileName
     166     * @return string
     167     */
     168    public static function convertToFilesystemEncoding($fileName)
     169    {
     170        $_config =& CKEditor_Connector_Core_Factory::getInstance("Core_Config");
     171        $encoding = $_config->getFilesystemEncoding();
     172        if (is_null($encoding) || strcasecmp($encoding, "UTF-8") == 0 || strcasecmp($encoding, "UTF8") == 0) {
     173            return $fileName;
     174        }
     175
     176        if (!function_exists("iconv")) {
     177            if (strcasecmp($encoding, "ISO-8859-1") == 0 || strcasecmp($encoding, "ISO8859-1") == 0 || strcasecmp($encoding, "Latin1") == 0) {
     178                return str_replace("\0", "_", utf8_decode($fileName));
     179            } else if (function_exists('mb_convert_encoding')) {
     180                /**
     181                 * @todo check whether charset is supported - mb_list_encodings
     182                 */
     183                $encoded = @mb_convert_encoding($fileName, $encoding, 'UTF-8');
     184                if (@mb_strlen($fileName, "UTF-8") != @mb_strlen($encoded, $encoding)) {
     185                    return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName));
     186                }
     187                else {
     188                    return str_replace("\0", "_", $encoded);
     189                }
     190            } else {
     191                return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName));
     192            }
     193        }
     194
     195        $converted = @iconv("UTF-8", $encoding . "//IGNORE//TRANSLIT", $fileName);
     196        if ($converted === false) {
     197            return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName));
     198        }
     199
     200        return $converted;
     201    }
     202
     203    /**
     204     * Convert file name from system encoding into UTF-8
     205     *
     206     * @static
     207     * @access public
     208     * @param string $fileName
     209     * @return string
     210     */
     211    public static function convertToConnectorEncoding($fileName)
     212    {
     213        $_config =& CKEditor_Connector_Core_Factory::getInstance("Core_Config");
     214        $encoding = $_config->getFilesystemEncoding();
     215        if (is_null($encoding) || strcasecmp($encoding, "UTF-8") == 0 || strcasecmp($encoding, "UTF8") == 0) {
     216            return $fileName;
     217        }
     218
     219        if (!function_exists("iconv")) {
     220            if (strcasecmp($encoding, "ISO-8859-1") == 0 || strcasecmp($encoding, "ISO8859-1") == 0 || strcasecmp($encoding, "Latin1") == 0) {
     221                return utf8_encode($fileName);
     222            } else {
     223                return $fileName;
     224            }
     225        }
     226
     227        $converted = @iconv($encoding, "UTF-8", $fileName);
     228
     229        if ($converted === false) {
     230            return $fileName;
     231        }
     232
     233        return $converted;
     234    }
     235
     236    /**
     237     * Find document root
     238     *
     239     * @return string
     240     * @access public
     241     */
     242    public function getDocumentRootPath()
     243    {
     244        /**
     245         * The absolute pathname of the currently executing script.
     246         * If a script is executed with the CLI, as a relative path, such as file.php or ../file.php,
     247         * $_SERVER['SCRIPT_FILENAME'] will contain the relative path specified by the user.
     248         */
     249        if (isset($_SERVER['SCRIPT_FILENAME'])) {
     250            $sRealPath = dirname($_SERVER['SCRIPT_FILENAME']);
     251        }
     252        else {
     253            /**
     254             * realpath — Returns canonicalized absolute pathname
     255             */
     256            $sRealPath = realpath( './' ) ;
     257        }
     258
     259        /**
     260         * The filename of the currently executing script, relative to the document root.
     261         * For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar
     262         * would be /test.php/foo.bar.
     263         */
     264        $sSelfPath = dirname($_SERVER['PHP_SELF']);
     265
     266        return substr($sRealPath, 0, strlen($sRealPath) - strlen($sSelfPath));
     267    }
     268
     269    /**
     270     * Create directory recursively
     271     *
     272     * @access public
     273     * @static
     274     * @param string $dir
     275     * @return boolean
     276     */
     277    public static function createDirectoryRecursively($dir)
     278    {
     279        if (DIRECTORY_SEPARATOR === "\\") {
     280            $dir = str_replace("/", "\\", $dir);
     281        }
     282        else if (DIRECTORY_SEPARATOR === "/") {
     283            $dir = str_replace("\\", "/", $dir);
     284        }
     285
     286        $_config =& CKEditor_Connector_Core_Factory::getInstance("Core_Config");
     287        if ($perms = $_config->getChmodFolders()) {
     288            $oldUmask = umask(0);
     289            $bCreated = @mkdir($dir, $perms, true);
     290            umask($oldUmask);
     291        }
     292        else {
     293            $bCreated = @mkdir($dir, 0777, true);
     294        }
     295
     296        return $bCreated;
     297    }
     298
     299    /**
     300     * Detect HTML in the first KB to prevent against potential security issue with
     301     * IE/Safari/Opera file type auto detection bug.
     302     * Returns true if file contain insecure HTML code at the beginning.
     303     *
     304     * @static
     305     * @access public
     306     * @param string $filePath absolute path to file
     307     * @return boolean
     308    */
     309    public static function detectHtml($filePath)
     310    {
     311        $fp = @fopen($filePath, 'rb');
     312        if ( $fp === false || !flock( $fp, LOCK_SH ) ) {
     313            return -1 ;
     314        }
     315        $chunk = fread($fp, 1024);
     316        flock( $fp, LOCK_UN ) ;
     317        fclose($fp);
     318
     319        $chunk = strtolower($chunk);
     320
     321        if (!$chunk) {
     322            return false;
     323        }
     324
     325        $chunk = trim($chunk);
     326
     327        if (preg_match("/<!DOCTYPE\W*X?HTML/sim", $chunk)) {
     328            return true;
     329        }
     330
     331        $tags = array('<body', '<head', '<html', '<img', '<pre', '<script', '<table', '<title');
     332
     333        foreach( $tags as $tag ) {
     334            if (false !== strpos($chunk, $tag)) {
     335                return true ;
     336            }
     337        }
     338
     339        //type = javascript
     340        if (preg_match('!type\s*=\s*[\'"]?\s*(?:\w*/)?(?:ecma|java)!sim', $chunk)) {
     341            return true ;
     342        }
     343
     344        //href = javascript
     345        //src = javascript
     346        //data = javascript
     347        if (preg_match('!(?:href|src|data)\s*=\s*[\'"]?\s*(?:ecma|java)script:!sim',$chunk)) {
     348            return true ;
     349        }
     350
     351        //url(javascript
     352        if (preg_match('!url\s*\(\s*[\'"]?\s*(?:ecma|java)script:!sim', $chunk)) {
     353            return true ;
     354        }
     355
     356        return false ;
     357    }
     358
     359    /**
     360     * Check file content.
     361     * Currently this function validates only image files.
     362     * Returns false if file is invalid.
     363     *
     364     * @static
     365     * @access public
     366     * @param string $filePath absolute path to file
     367     * @param string $extension file extension
     368     * @param integer $detectionLevel 0 = none, 1 = use getimagesize for images, 2 = use DetectHtml for images
     369     * @return boolean
     370    */
     371    public static function isImageValid($filePath, $extension)
     372    {
     373        if (!@is_readable($filePath)) {
     374            return -1;
     375        }
     376
     377        $imageCheckExtensions = array('gif', 'jpeg', 'jpg', 'png', 'psd', 'bmp', 'tiff');
     378
     379        // version_compare is available since PHP4 >= 4.0.7
     380        if ( function_exists( 'version_compare' ) ) {
     381            $sCurrentVersion = phpversion();
     382            if ( version_compare( $sCurrentVersion, "4.2.0" ) >= 0 ) {
     383                $imageCheckExtensions[] = "tiff";
     384                $imageCheckExtensions[] = "tif";
     385            }
     386            if ( version_compare( $sCurrentVersion, "4.3.0" ) >= 0 ) {
     387                $imageCheckExtensions[] = "swc";
     388            }
     389            if ( version_compare( $sCurrentVersion, "4.3.2" ) >= 0 ) {
     390                $imageCheckExtensions[] = "jpc";
     391                $imageCheckExtensions[] = "jp2";
     392                $imageCheckExtensions[] = "jpx";
     393                $imageCheckExtensions[] = "jb2";
     394                $imageCheckExtensions[] = "xbm";
     395                $imageCheckExtensions[] = "wbmp";
     396            }
     397        }
     398
     399        if ( !in_array( $extension, $imageCheckExtensions ) ) {
     400            return true;
     401        }
     402
     403        if ( @getimagesize( $filePath ) === false ) {
     404            return false ;
     405        }
     406
     407        return true;
     408    }
     409}
  • _source/plugins/filebrowser/core/connector/php/php5/Utils/Misc.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage Utils
     10 */
     11
     12/**
     13 * @package CKEditor
     14 * @subpackage Utils
     15 */
     16class CKEditor_Connector_Utils_Misc
     17{
     18    /**
     19     * Convert any value to boolean, strings like "false", "FalSE" and "off" are also considered as false
     20     *
     21     * @static
     22     * @access public
     23     * @param mixed $value
     24     * @return boolean
     25     */
     26    public static function booleanValue($value)
     27    {
     28        if (strcasecmp("false", $value) == 0 || strcasecmp("off", $value) == 0 || !$value) {
     29            return false;
     30        } else {
     31            return true;
     32        }
     33    }
     34
     35    /**
     36    * Checks if a value exists in an array (case insensitive)
     37    *
     38    * @static
     39    * @access public
     40    * @param string $needle
     41    * @param array $haystack
     42    * @return boolean
     43    */
     44    public static function inArrayCaseInsensitive($needle, $haystack)
     45    {
     46        if (!$haystack || !is_array($haystack)) {
     47            return false;
     48        }
     49        $lcase = array();
     50        foreach ($haystack as $key => $val) {
     51            $lcase[$key] = strtolower($val);
     52        }
     53        return in_array($needle, $lcase);
     54    }
     55}
     56 No newline at end of file
  • _source/plugins/filebrowser/core/connector/php/php5/Utils/Security.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage Utils
     10 */
     11
     12/**
     13 * @package CKEditor
     14 * @subpackage Utils
     15 */
     16class CKEditor_Connector_Utils_Security
     17{
     18
     19    /**
     20     * Strip quotes from global arrays
     21     * @access public
     22     */
     23    public function getRidOfMagicQuotes()
     24    {
     25        if (CKEDITOR_CONNECTOR_PHP_MODE<6 && get_magic_quotes_gpc()) {
     26            if (!empty($_GET)) {
     27                $this->stripQuotes($_GET);
     28            }
     29            if (!empty($_POST)) {
     30                $this->stripQuotes($_POST);
     31            }
     32            if (!empty($_COOKIE)) {
     33                $this->stripQuotes($_COOKIE);
     34            }
     35            if (!empty($_FILES)) {
     36                while (list($k,$v) = each($_FILES)) {
     37                    if (isset($_FILES[$k]['name'])) {
     38                        $this->stripQuotes($_FILES[$k]['name']);
     39                    }
     40                }
     41            }
     42        }
     43    }
     44
     45    /**
     46     * Strip quotes from variable
     47     *
     48     * @access public
     49     * @param mixed $var
     50     * @param int $depth current depth
     51     * @param int $howDeep maximum depth
     52     */
     53    public function stripQuotes(&$var, $depth=0, $howDeep=5)
     54    {
     55        if (is_array($var)) {
     56            if ($depth++<$howDeep) {
     57                while (list($k,$v) = each($var)) {
     58                    $this->stripQuotes($var[$k], $depth, $howDeep);
     59                }
     60            }
     61        } else {
     62            $var = stripslashes($var);
     63        }
     64    }
     65}
  • _source/plugins/filebrowser/core/connector/php/php5/Utils/XmlNode.php

     
     1<?php
     2/*
     3* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     4* For licensing, see LICENSE.html or http://ckeditor.com/license
     5*/
     6
     7/**
     8 * @package CKEditor
     9 * @subpackage Utils
     10 */
     11
     12/**
     13 * Simple class which provides some basic API for creating XML nodes and adding attributes
     14 *
     15 * @package CKEditor
     16 * @subpackage Utils
     17 */
     18class CKEditor_Connector_Utils_XmlNode
     19{
     20    /**
     21     * Array that stores XML attributes
     22     *
     23     * @access private
     24     * @var array
     25     */
     26    private $_attributes = array();
     27    /**
     28     * Array that stores child nodes
     29     *
     30     * @access private
     31     * @var array
     32     */
     33    private $_childNodes = array();
     34    /**
     35     * Node name
     36     *
     37     * @access private
     38     * @var string
     39     */
     40    private $_name;
     41    /**
     42     * Node value
     43     *
     44     * @access private
     45     * @var string
     46     */
     47    private $_value;
     48
     49    /**
     50     * Create new node
     51     *
     52     * @param string $nodeName node name
     53     * @param string $nodeValue node value
     54     * @return CKEditor_Connector_Utils_XmlNode
     55     */
     56    function __construct($nodeName, $nodeValue = null)
     57    {
     58        $this->_name = $nodeName;
     59        if (!is_null($nodeValue)) {
     60            $this->_value = $nodeValue;
     61        }
     62    }
     63
     64    /**
     65     * Add attribute
     66     *
     67     * @param string $name
     68     * @param string $value
     69     * @access public
     70     */
     71    public function addAttribute($name, $value)
     72    {
     73        $this->_attributes[$name] = $value;
     74    }
     75
     76    /**
     77     * Adds new child at the end of the children
     78     *
     79     * @param CKEditor_Connector_Utils_XmlNode $node
     80     * @access public
     81     */
     82    public function addChild(&$node)
     83    {
     84        $this->_childNodes[] =& $node;
     85    }
     86
     87    /**
     88     * Return a well-formed XML string based on CKEditor_Connector_Utils_XmlNode element
     89     *
     90     * @return string
     91     * @access public
     92     */
     93    public function asXML()
     94    {
     95        $ret = "<" . $this->_name;
     96
     97        //print Attributes
     98        if (sizeof($this->_attributes)>0) {
     99            foreach ($this->_attributes as $_name => $_value) {
     100                $ret .= " " . $_name . '="' . htmlspecialchars($_value) . '"';
     101            }
     102        }
     103
     104        //if there is nothing more todo, close empty tag and exit
     105        if (is_null($this->_value) && !sizeof($this->_childNodes)) {
     106            $ret .= " />";
     107            return $ret;
     108        }
     109
     110        //close opening tag
     111        $ret .= ">";
     112
     113        //print value
     114        if (!is_null($this->_value)) {
     115            $ret .= htmlspecialchars($this->_value);
     116        }
     117
     118        //print child nodes
     119        if (sizeof($this->_childNodes)>0) {
     120            foreach ($this->_childNodes as $_node) {
     121                $ret .= $_node->asXml();
     122            }
     123        }
     124
     125        $ret .= "</" . $this->_name . ">";
     126
     127        return $ret;
     128    }
     129}
     130 No newline at end of file
  • _source/plugins/filebrowser/dialogs/filebrowser.js

     
     1/*
     2Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     3For licensing, see LICENSE.html or http://ckeditor.com/license
     4*/
     5
     6CKEDITOR.dialog.add( 'filebrowser', function( editor )
     7{
     8        var dialog, editor,
     9                initialized = false,
     10                imagesDirectory = CKEDITOR.plugins.getPath( 'filebrowser' ) + 'images/',
     11                regexFolderUp = /[^\/]+\/$/,
     12                regexInvalidChars = /[\\\/:\*\?"<>\|]/,
     13                regexIconExt = new RegExp( '^(?:' + editor.config.filebrowser_icons.replace( /,/g,'|' ) + ')$', 'i' );
     14
     15        // This function is called by the server connector when file is uploaded.
     16        this.OnUploadCompleted = function( errorNumber, fileName, customErrorMsg )
     17        {
     18                if ( errorNumber == editor.plugins.filebrowser.ERROR_NONE || errorNumber == editor.plugins.filebrowser.ERROR_UPLOADEDFILERENAMED )
     19                        loadFoldersAndFiles( dialog.type, dialog.path );
     20
     21                dialog.getContentElement( 'tab1', 'inputFile' ).reset();
     22                dialog.getContentElement( 'tab1', 'uploadFile' ).enable();
     23                dialog.getContentElement( 'tab1', 'inputFile' ).setLabel( editor.lang.filebrowser.uploadTip );
     24                editor.plugins.filebrowser._detectError( editor, errorNumber, customErrorMsg, fileName );
     25        };
     26
     27        var createFolderButton =
     28        {
     29                id : 'createFolder',
     30                label : editor.lang.filebrowser.folderCreate,
     31                title : editor.lang.filebrowser.folderCreateTip,
     32                accessKey : 'C',
     33                type : 'button',
     34                disabled : false,
     35                onClick : function()
     36                {
     37                        var folderName;
     38
     39                        while ( true )
     40                        {
     41                                folderName = prompt( editor.lang.filebrowser.folderNew, '' );
     42                                if ( folderName == null )
     43                                        return;
     44                                else if ( folderName.length == 0 )
     45                                        alert( editor.lang.filebrowser.folderEmpty );
     46                                else if ( regexInvalidChars.test( folderName ) )
     47                                        alert( editor.lang.filebrowser.folderInvalidChar );
     48                                else
     49                                        break;
     50                        }
     51                        createFolder( dialog.type, dialog.path, folderName );
     52                }
     53        };
     54
     55        var resourceType = function( name, url, allowedExtensions, deniedExtensions )
     56        {
     57                this.name = name;
     58                this.url = url;
     59                this.allowedExtensions = allowedExtensions.toLowerCase().split( ',' );
     60                this.deniedExtensions = deniedExtensions.toLowerCase().split( ',' );
     61
     62                this.isExtensionAllowed = function( extension )
     63                {
     64                        extension = extension.toLowerCase();
     65
     66                        return ( ( !this.deniedExtensions.length || CKEDITOR.tools.indexOf( this.deniedExtensions, extension ) == -1 ) &&
     67                                        ( !this.allowedExtensions.length || CKEDITOR.tools.indexOf( this.allowedExtensions, extension ) !== -1 ) );
     68                };
     69        };
     70
     71        var getExtension = function( fileName )
     72        {
     73                return fileName.substr( fileName.lastIndexOf( '.' ) + 1 ).toLowerCase();
     74        };
     75
     76        var getIcon = function( fileName )
     77        {
     78                var extension = getExtension( fileName );
     79
     80                if ( regexIconExt.test( extension ) )
     81                        return extension;
     82                else
     83                        return 'default.icon';
     84        };
     85
     86        var clearFoldersPane = function()
     87        {
     88                dialog.getContentElement( 'tab1', 'folders' ).getElement().setHtml( "" );
     89        };
     90
     91        var clearResourcesList = function()
     92        {
     93                dialog.getContentElement( 'tab1', 'resourceslist' ).getElement().setHtml( "" );
     94        };
     95
     96        var updateFoldersPane = function( folders, selectedFolderIndex )
     97        {
     98                var td, tr,
     99                        table = new CKEDITOR.dom.element( 'table' ),
     100                        tbody = new CKEDITOR.dom.element( 'tbody' );
     101
     102                tr = new CKEDITOR.dom.element( 'tr' );
     103                td = new CKEDITOR.dom.element( 'td' );
     104                td.appendText( ".." );
     105                td.addClass( 'cke_folderUp' );
     106                td.on( 'click', function( evt )
     107                {
     108                        var folderUp = this.path.replace( regexFolderUp, '' );
     109
     110                        if ( folderUp != "/" )
     111                                loadFolders( this.type, folderUp.replace( regexFolderUp, '' ) );
     112                        else
     113                                clearFoldersPane();
     114
     115                        loadFoldersAndFiles( this.type, folderUp );
     116                }, dialog, {} );
     117                tr.append( td );
     118                tbody.append( tr );
     119
     120                for ( var i = 0 ; i < folders.length ; i++ )
     121                {
     122                        tr = new CKEDITOR.dom.element( 'tr' );
     123                        td = new CKEDITOR.dom.element( 'td' );
     124                        td.appendText( folders[ i ] );
     125                        td.addClass( i == selectedFolderIndex ? 'cke_folderOpened' : 'cke_folder' );
     126                        td.on( 'click', function( evt )
     127                        {
     128                                updateFoldersPane( evt.listenerData.folders, evt.listenerData.folder );
     129                                loadFoldersAndFiles( this.type, this.path.replace( regexFolderUp, '' )
     130                                                + evt.listenerData.folders[ evt.listenerData.folder ] + "/" );
     131                        }, dialog,
     132                        {
     133                                folders : folders,
     134                                folder : i
     135                        } );
     136                        tr.append( td );
     137                        tbody.append( tr );
     138                }
     139
     140                clearFoldersPane();
     141                table.setStyle( 'width', '100%' );
     142                table.append( tbody );
     143                dialog.getContentElement( 'tab1', 'folders' ).getElement().append( table );
     144        };
     145
     146        var getErrorNumber = function( xml )
     147        {
     148                return parseInt( xml.selectSingleNode( 'Connector/Error/@number' ).value );
     149        };
     150
     151        var getErrorMessage = function( xml )
     152        {
     153                var node = xml.selectSingleNode( 'Connector/Error/@text' );
     154                if ( !node )
     155                        return '';
     156                return node.value;
     157        };
     158
     159        var onInit = function( xml )
     160        {
     161                if ( editor.plugins.filebrowser._detectError( editor, getErrorNumber( xml ), getErrorMessage( xml ) ) )
     162                        return;
     163
     164                var name,
     165                        select = dialog.getContentElement( 'tab1', 'cmbResourceType' ),
     166                        nodes = xml.selectNodes( 'Connector/ResourceTypes/ResourceType' );
     167
     168                select.clear();
     169                dialog.resourceTypes = {};
     170
     171                for ( var i = 0 ; i < nodes.length ; i++ )
     172                {
     173                        name = nodes[ i ].attributes.getNamedItem( 'name' ).value;
     174
     175                        dialog.resourceTypes[ name ] = new resourceType( name, nodes[ i ].attributes.getNamedItem( 'url' ).value,
     176                                        nodes[ i ].attributes.getNamedItem( 'allowedExtensions' ).value, nodes[ i ].attributes.getNamedItem( 'deniedExtensions' ).value );
     177
     178                        select.add( name );
     179                }
     180
     181                initialized = true;
     182                loadFoldersAndFiles( nodes[ 0 ].attributes.getNamedItem( 'name' ).value, "/" );
     183        };
     184
     185        var onCreateFolder = function( xml )
     186        {
     187                if ( editor.plugins.filebrowser._detectError( editor, getErrorNumber( xml ), getErrorMessage( xml ) ) )
     188                        return;
     189
     190                loadFoldersAndFiles( dialog.type, dialog.path );
     191        };
     192
     193        var onGetFolders = function( xml )
     194        {
     195                if ( editor.plugins.filebrowser._detectError( editor, getErrorNumber( xml ), getErrorMessage( xml ) ) )
     196                        return;
     197
     198                var currentFolder = xml.selectSingleNode( 'Connector/CurrentFolder' ),
     199                        nodes = xml.selectNodes( 'Connector/Folders/Folder' ),
     200                        folders = [];
     201
     202                for ( var i = 0 ; i < nodes.length ; i++ )
     203                        folders.push( nodes[ i ].attributes.getNamedItem( 'name' ).value );
     204
     205                updateFoldersPane( folders, currentFolder );
     206        };
     207
     208        var onGetFoldersAndFiles = function( xml )
     209        {
     210                if ( editor.plugins.filebrowser._detectError( editor, getErrorNumber( xml ), getErrorMessage( xml ) ) )
     211                        return;
     212
     213                var img, td, tr,
     214                        table = new CKEDITOR.dom.element( 'table' ),
     215                        tbody = new CKEDITOR.dom.element( 'tbody' ),
     216                        nodes = xml.selectNodes( 'Connector/Folders/Folder' ),
     217                        currentFolder = xml.selectSingleNode( 'Connector/CurrentFolder' ),
     218                        connector = xml.selectSingleNode( '//Connector' ),
     219                        files = [],
     220                        folders = [];
     221
     222                dialog.type = connector.attributes.getNamedItem( 'resourceType' ).value;
     223                dialog.url = currentFolder.attributes.getNamedItem( 'url' ).value;
     224                dialog.path = currentFolder.attributes.getNamedItem( 'path' ).value;
     225
     226                // Add the scrollbar to the table.
     227                if ( CKEDITOR.env.ie )
     228                {
     229                        dialog.getContentElement( 'tab1', 'resourceslist' ).getElement().setStyle( 'overflow-y', 'scroll' );
     230                        table.setStyle( 'width', '510px' );
     231                }
     232                else
     233                {
     234                        table.setStyle( 'float', 'left' );
     235                        table.setStyle( 'display', 'table-cell' );
     236                        table.setStyle( 'height', '280px' );
     237                        table.setStyle( 'width', '100%' );
     238                }
     239
     240                table.setStyle( 'overflow', 'auto' );
     241
     242                CKEDITOR.document.getById( 'cke_actualFolder' ).setHtml( dialog.path );
     243
     244                for ( var i = 0 ; i < nodes.length ; i++ )
     245                {
     246                        folders.push( nodes[ i ].attributes.getNamedItem( 'name' ).value );
     247                        tr = new CKEDITOR.dom.element( 'tr' );
     248                        td = new CKEDITOR.dom.element( 'td' );
     249                        td.appendText( folders[ i ] );
     250                        td.setAttribute( 'colSpan', 3 ); // IE accepts this attribute only if "S" is uppercased.
     251                        td.addClass( 'cke_folder' );
     252                        tr.append( td );
     253                        tr.on( 'click', function( evt )
     254                                        {
     255                                                updateFoldersPane( evt.listenerData.folders, evt.listenerData.folder );
     256                                                loadFoldersAndFiles( this.type, this.path + evt.listenerData.folders[ evt.listenerData.folder ] + "/" );
     257                                        }, dialog, { folder : i, folders : folders } );
     258                        tbody.append( tr );
     259                }
     260
     261                nodes = xml.selectNodes( 'Connector/Files/File' );
     262
     263                for ( var i = 0 ; i < nodes.length ; i++ )
     264                {
     265                        files.push( nodes[ i ].attributes.getNamedItem( 'name' ).value );
     266                        tr = new CKEDITOR.dom.element( 'tr' );
     267                        td = new CKEDITOR.dom.element( 'td' );
     268                        img = new CKEDITOR.dom.element( 'img' );
     269                        img.setAttribute( "src", CKEDITOR.getUrl( imagesDirectory + 'icons/' + getIcon( files[ i ] ) + '.gif' ) );
     270                        td.setStyle( 'width', '20px' );
     271                        td.setStyle( 'text-align', 'center' );
     272                        td.append( img );
     273                        tr.append( td );
     274                        td = new CKEDITOR.dom.element( 'td' );
     275                        td.appendText( files[ i ] );
     276                        td.setStyle( 'vertical-align', 'middle' );
     277                        td.setStyle( 'width', '450px' );
     278                        tr.append( td );
     279                        td = new CKEDITOR.dom.element( 'td' );
     280                        td.appendText( nodes[ i ].attributes.getNamedItem( 'size' ).value + 'KB' );
     281                        td.setStyle( 'vertical-align', 'middle' );
     282                        td.setStyle( 'width', '50px' );
     283                        tr.append( td );
     284                        tr.on( 'click', function( evt )
     285                                        {
     286                                                var fileUrl = this.resourceTypes[ this.type ].url + this.path.substr( 1 ) + evt.listenerData.file ;
     287                                                editor.fire( 'fileSelected', { url : fileUrl }, editor );
     288                                                dialog.hide();
     289                                        }, dialog, { file : files[ i ] } );
     290                        tbody.append( tr );
     291                }
     292
     293                clearResourcesList();
     294                table.append( tbody );
     295                dialog.getContentElement( 'tab1', 'resourceslist' ).getElement().append( table );
     296                dialog.getContentElement( 'tab1', 'inputFile' ).getInputElement().getParent().setAttribute( "action",
     297                                editor.plugins.filebrowser._commandUrl( editor, 'FileUpload', { type : dialog.type, currentFolder : dialog.path } ) );
     298        };
     299
     300        var loadFoldersAndFiles = function( type, path )
     301        {
     302                CKEDITOR.ajax.loadXml( editor.plugins.filebrowser._commandUrl( editor, 'GetFoldersAndFiles', { type : type, currentFolder : path } ), onGetFoldersAndFiles );
     303        };
     304
     305        var loadFolders = function( type, path )
     306        {
     307                CKEDITOR.ajax.loadXml( editor.plugins.filebrowser._commandUrl( editor, 'GetFolders', { type : type, currentFolder : path } ), onGetFolders );
     308        };
     309
     310        var createFolder = function( type, path, folderName )
     311        {
     312                CKEDITOR.ajax.postXml( editor.plugins.filebrowser._commandUrl( editor, 'CreateFolder', { type : type, currentFolder : path } ), { newFolderName : folderName }, onCreateFolder );
     313        };
     314
     315        return {
     316                title : editor.lang.filebrowser.title,
     317                minWidth : '730',
     318                minHeight : '480',
     319                onLoad : function()
     320                {
     321                        dialog = this;
     322                        editor = this.getParentEditor();
     323                },
     324                onHide : function()
     325                {
     326                        initialized = false;
     327                },
     328                onShow : function()
     329                {
     330                        var params = {};
     331                        if ( editor.plugins.filebrowser.params.type )
     332                                params.type = editor.plugins.filebrowser.params.type;
     333
     334                        // Don't clear the window and call the Init command if we're going back to the same place.
     335                        if ( !dialog.type || !dialog.path || ( !!params.type && dialog.type != params.type) || ( !!params.path && dialog.path != params.path ) )
     336                        {
     337                                clearFoldersPane();
     338                                clearResourcesList();
     339                                CKEDITOR.ajax.loadXml( editor.plugins.filebrowser._commandUrl( editor, 'Init', params ), onInit );
     340                        }
     341                },
     342                contents :
     343                [
     344                        {
     345                                id : 'tab1',
     346                                label : editor.lang.filebrowser.title,
     347                                accessKey : 'B',
     348                                elements :
     349                                [
     350                                        {
     351                                                type : 'html',
     352                                                html : '<style type="text/css">' +
     353                                                                '.cke_folder { background: url("' + CKEDITOR.getUrl( imagesDirectory + 'folder.gif' ) + '"); }' +
     354                                                                '.cke_folderOpened{ background: url("' + CKEDITOR.getUrl( imagesDirectory + 'folderOpened.gif' ) + '"); }' +
     355                                                                '.cke_folderUp { background: url("' + CKEDITOR.getUrl( imagesDirectory + 'folderUp.gif' ) + '"); }' +
     356                                                                '.cke_filebrowser .cke_dialog_ui_hbox_first {vertical-align:top;}' +
     357                                                                '.cke_folder, .cke_folderOpened, .cke_folderUp {' +
     358                                                                'padding-left:20px;' +
     359                                                                'height:16px;' +
     360                                                                'background-repeat:no-repeat;' +
     361                                                                '}' +
     362                                                                '#cke_actualFolder {' +
     363                                                                'font-weight:bold;' +
     364                                                                'font-size:120%;' +
     365                                                                '}' +
     366                                                                '</style>'
     367                                        },
     368                                        {
     369                                                type : 'hbox',
     370                                                widths : [ '140px', '540px' ],
     371                                                align : 'left',
     372                                                padding : 0,
     373                                                className : 'cke_filebrowser',
     374                                                children :
     375                                                [
     376                                                        {
     377                                                                type : 'vbox',
     378                                                                children :
     379                                                                [
     380                                                                        {
     381                                                                                type : 'select',
     382                                                                                id : 'cmbResourceType',
     383                                                                                accessKey : 'R',
     384                                                                                labelLayout : 'vertical',
     385                                                                                label : editor.lang.filebrowser.resourceType,
     386                                                                                items : [ [ editor.lang.common.notSet, '' ] ],
     387                                                                                onChange : function()
     388                                                                                {
     389                                                                                        if ( this.isChanged() && initialized )
     390                                                                                        {
     391                                                                                                loadFoldersAndFiles( this.getValue(), "/" );
     392                                                                                                clearFoldersPane();
     393                                                                                        }
     394                                                                                }
     395                                                                        },
     396                                                                        {
     397                                                                                type : 'vbox',
     398                                                                                id : 'folders',
     399                                                                                style : 'display:table-cell;',
     400                                                                                children : []
     401                                                                        }
     402                                                                ]
     403                                                        },
     404                                                        {
     405                                                                type : 'vbox',
     406                                                                heights : [ '36px', '280px' ],
     407                                                                children :
     408                                                                [
     409                                                                        {
     410                                                                                type : 'hbox',
     411                                                                                widths : [ '36px', '' ],
     412                                                                                children :
     413                                                                                [
     414                                                                                        {
     415                                                                                                type : 'html',
     416                                                                                                align : 'left',
     417                                                                                                style : 'vertical-align:middle',
     418                                                                                                html : '<img width="32" height="32" src="' + CKEDITOR.getUrl( imagesDirectory + 'FolderOpened32.gif' ) + '" alt=""/>'
     419                                                                                        },
     420                                                                                        {
     421                                                                                                type : 'html',
     422                                                                                                style : 'vertical-align:middle',
     423                                                                                                html : '<div id="cke_actualFolder"></div>'
     424                                                                                        },
     425                                                                                ]
     426                                                                        },
     427                                                                        {
     428                                                                                type : 'vbox',
     429                                                                                id : 'resourceslist',
     430                                                                                style : 'height:280px;white-space: nowrap;',
     431                                                                                children : []
     432                                                                        },
     433                                                                        {
     434                                                                                type : 'hbox',
     435                                                                                children :
     436                                                                                [
     437                                                                                        {
     438                                                                                                type : 'file',
     439                                                                                                label : editor.lang.filebrowser.uploadTip,
     440                                                                                                labelLayout : 'vertical',
     441                                                                                                action : editor.plugins.filebrowser._commandUrl( editor, 'FileUpload', { type : 'Files', currentFolder : '/' } ),
     442                                                                                                id : 'inputFile'
     443                                                                                        },
     444                                                                                        {
     445                                                                                                type : 'fileButton',
     446                                                                                                label : editor.lang.common.uploadSubmit,
     447                                                                                                id : 'uploadFile',
     448                                                                                                accessKey : 'S',
     449                                                                                                onClick : function( evt )
     450                                                                                                {
     451                                                                                                        var dialog = this.getDialog(),
     452                                                                                                                file = dialog.getContentElement( 'tab1', 'inputFile' ).getValue();
     453
     454                                                                                                        if ( !file )
     455                                                                                                        {
     456                                                                                                                alert( editor.lang.filebrowser.fileNotSelected );
     457                                                                                                                return false;
     458                                                                                                        }
     459                                                                                                        else
     460                                                                                                        {
     461                                                                                                                if ( !dialog.resourceTypes[ dialog.type ].isExtensionAllowed( getExtension( file ) ) )
     462                                                                                                                {
     463                                                                                                                        alert( editor.lang.filebrowser.errors[ editor.plugins.filebrowser.ERROR_INVALID_EXTENSION ] );
     464                                                                                                                        return false;
     465                                                                                                                }
     466                                                                                                                dialog.getContentElement( 'tab1', 'inputFile' ).setLabel( editor.lang.filebrowser.uploadProgressLbl );
     467                                                                                                        }
     468                                                                                                },
     469                                                                                                'for' : [ 'tab1', 'inputFile' ]
     470                                                                                        }
     471                                                                                ]
     472                                                                        }
     473                                                                ]
     474                                                        }
     475                                                ]
     476                                        }
     477                                ]
     478                        }
     479                ],
     480                buttons : [ createFolderButton, CKEDITOR.dialog.cancelButton ]
     481        };
     482} );
  • _source/plugins/filebrowser/plugin.js

     
     1/*
     2Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     3For licensing, see LICENSE.html or http://ckeditor.com/license
     4*/
     5
     6/**
     7 * @fileOverview The "filebrowser" plugin, it adds support for file uploads and browsing.
     8 */
     9CKEDITOR.plugins.add( 'filebrowser',
     10{
     11        requires : [ 'dialog' ],
     12
     13        ERROR_NONE : 0,
     14        ERROR_CUSTOMERROR : 1,
     15        ERROR_INVALID_EXTENSION : 105,
     16        ERROR_UPLOADEDFILERENAMED : 201,
     17
     18        /**
     19         * Reference to the last opened dialog. Required by 'selectFunction' and 'uploadCompletedFunction'.
     20         * @type {CKEDITOR.dialog}
     21         */
     22        _dialog : null,
     23        /**
     24         * The "action" attribute that will be passed to the {@see CKEDITOR.ui.dialog.file#reset} function.
     25         * The "action" attribute is generated automatically in some cases.
     26         * @type String
     27         */
     28        _formAction : null,
     29        /**
     30         * Holds the reference to the file input element to reset after file is uploaded.
     31         * Syntax: [ pageId, elementId ]
     32         * @type Array
     33         */
     34        _targetInput : null,
     35        /**
     36         * Holds the reference to the UI element that will be updated when file is selected/uploaded.
     37         * Syntax: [ pageId, elementId ]
     38         * @type Array
     39         */
     40        _targetElement : null,
     41        /**
     42         * The user defined function (if defined) that will be called when file is uploaded.
     43         * @type Function
     44         */
     45        _onUpload : null,
     46
     47        _commandUrl : function( editor, command, params )
     48        {
     49                var url = [ CKEDITOR.getUrl( this.path + 'core/connector/' + editor.config.filebrowser_connector + '/connector.' + editor.config.filebrowser_connector ) ];
     50                url.push( ( url[0].indexOf( '?' ) >= 0 ? '&' : '?' ) + 'command=' + command );
     51                if ( params )
     52                {
     53                        for ( var i in params )
     54                                url.push( "&" + i + "=" + encodeURIComponent( params[i] ) );
     55                }
     56                return url.join( "" );
     57        },
     58
     59        _detectError : function( editor, errorNumber, customError )
     60        {
     61                if ( errorNumber == this.ERROR_NONE )
     62                        return false;
     63               
     64                var errorMessage;
     65               
     66                if ( errorNumber == this.ERROR_CUSTOMERROR )
     67                        errorMessage = customError;
     68                else
     69                {
     70                        errorMessage = editor.lang.filebrowser.errors[ errorNumber ];
     71
     72                        if ( errorMessage )
     73                        {
     74                                // Replace any string placeholder (%1, %2, ...), taking the values
     75                                // from the detectError arguments.
     76                                var replaceArgs = arguments;
     77                                var replacePlaceholders = function( match, number )
     78                                {
     79                                        return ( replaceArgs[ parseInt( number ) + 1 ] );
     80                                };
     81                                errorMessage = errorMessage.replace( /%(\d+)/g, replacePlaceholders );
     82                        }
     83                        else
     84                                errorMessage = editor.lang.filebrowser.errorUnknown.replace( /%1/, errorNumber );
     85                }
     86
     87                alert( errorMessage );
     88
     89                return ( errorNumber != this.ERROR_UPLOADEDFILERENAMED );
     90        },
     91
     92        init : function( editor, pluginPath )
     93        {
     94                editor.addCommand( 'filebrowser', new CKEDITOR.dialogCommand( 'filebrowser' ) );
     95                CKEDITOR.dialog.add( 'filebrowser', this.path + 'dialogs/filebrowser.js' );
     96
     97                /**
     98                 * Updates the target element with the url of uploaded/selected file.
     99                 * @param {String} url The url of a file.
     100                 */
     101                var updateTargetElement = function( url )
     102                {
     103                        url = encodeURI( url ).replace( /#/g, '%23' );
     104                        var plugin = editor.plugins.filebrowser;
     105
     106                        // If there is a reference to targetElement, update it.
     107                        if ( plugin._targetElement )
     108                        {
     109                                var element = plugin._dialog.getContentElement(
     110                                                plugin._targetElement[0], plugin._targetElement[1] );
     111                                if ( element )
     112                                        element.setValue( url );
     113                        }
     114                        // If targetElement is empty, find the first element with id 'url' and update it.
     115                        else
     116                        {
     117                                var widgetFound = false;
     118                                plugin._dialog.foreach( function( widget )
     119                                                {
     120                                                        if ( !widgetFound && widget.id == 'url' )
     121                                                        {
     122                                                                widget.setValue( url );
     123                                                                widget.getDialog().selectPage( widget.getParentTab() );
     124                                                                widgetFound = true;
     125                                                        }
     126                                                });
     127                        }
     128                };
     129
     130                /**
     131                 * Opens Browser in a popup. The "width" and "height" parameters accept
     132                 * numbers (pixels) or percent (of screen size) values.
     133                 * @param {String} url The url of the external file browser.
     134                 * @param {String} width Popup window width.
     135                 * @param {String} height Popup window height.
     136                 */
     137                var popup = function( url, width, height )
     138                {
     139                        width = width || '80%';
     140                        height = height || '70%';
     141
     142                        if ( typeof width == 'string' && width.length > 1 && width.substr( width.length - 1, 1 ) == '%' )
     143                                width = parseInt( window.screen.width * parseInt( width ) / 100 );
     144
     145                        if ( typeof height == 'string' && height.length > 1 && height.substr( height.length - 1, 1 ) == '%' )
     146                                height = parseInt( window.screen.height * parseInt( height ) / 100 );
     147
     148                        if ( width < 640 )
     149                                width = 640;
     150
     151                        if ( height < 420 )
     152                                height = 420;
     153
     154                        var top = parseInt( ( window.screen.height - height ) / 2 ),
     155                                left = parseInt( ( window.screen.width  - width ) / 2 ),
     156                                options = 'location=no,menubar=no,toolbar=no,dependent=yes,minimizable=no,modal=yes,alwaysRaised=yes,resizable=yes' +
     157                                ',width='  + width +
     158                                ',height=' + height +
     159                                ',top='  + top +
     160                                ',left=' + left;
     161
     162                        var popupWindow = window.open( '', null, options, true );
     163
     164                        // Blocked by a popup blocker.
     165                        if ( !popupWindow )
     166                                return false;
     167
     168                        try
     169                        {
     170                                popupWindow.moveTo( left, top );
     171                                popupWindow.resizeTo( width, height );
     172                                popupWindow.focus();
     173                                popupWindow.location.href = url;
     174                        }
     175                        catch (e)
     176                        {
     177                                popupWindow = window.open( url, null, options, true );
     178                        }
     179
     180                        return true ;
     181                };
     182
     183                /**
     184                 * The onlick function assigned to the 'Browse Server' button.
     185                 * Opens the file browser and updates target field when file is selected.
     186                 * @param {CKEDITOR.event} evt The event object.
     187                 */
     188                var browseServer = function( evt )
     189                {
     190                        var dialog = this.getDialog();
     191                        var editor = dialog.getParentEditor();
     192                        var plugin = editor.plugins.filebrowser;
     193
     194                        // Save references to fields required by the 'selectFunction'.
     195                        plugin._dialog = dialog;
     196                        if ( this.filebrowser.updateOnSelect )
     197                        {
     198                                plugin._targetElement = this.filebrowser.updateOnSelect;
     199                        }
     200                        else
     201                        {
     202                                var parentTab = this.getParentTab();
     203                                if ( dialog.getContentElement( parentTab, 'url' ) )
     204                                        plugin._targetElement = [ parentTab, 'url' ];
     205                                else
     206                                        plugin._targetElement = null;
     207                        }
     208
     209                        // If url attribute is set, call the external browser.
     210                        if ( this.filebrowser.url || editor.config.filebrowser_browse_url )
     211                        {
     212                                // Function that is called when the user selects a file in external file browser.
     213                                var selectFunction = this.filebrowser.selectFunction || 'SetUrl';
     214
     215                                this.getElement().getWindow().$[selectFunction] = function( fileUrl, data )
     216                                {
     217                                        updateTargetElement( fileUrl );
     218                                };
     219
     220                                popup( this.filebrowser.url || editor.config.filebrowser_browse_url );
     221                        }
     222                        // Call the built-in file browser otherwise.
     223                        else
     224                        {
     225                                if ( this.filebrowser.params )
     226                                {
     227                                        // If params is set to 'auto', create the default params object.
     228                                        if ( this.filebrowser.params == 'auto' )
     229                                        {
     230                                                plugin.params = { currentFolder : '/' };
     231
     232                                                // Assign initial resource type for image and flash dialogs.
     233                                                switch ( dialog.getName() )
     234                                                {
     235                                                        case 'image':
     236                                                                plugin.params.type = editor.config.filebrowser_resourcetype_image;
     237                                                                break;
     238                                                        case 'flash':
     239                                                                plugin.params.type = editor.config.filebrowser_resourcetype_flash;
     240                                                                break;
     241                                                }
     242                                        }
     243                                        else
     244                                                plugin.params = this.filebrowser.params;
     245                                }
     246                                else
     247                                        plugin.params = {};
     248
     249                                editor.openDialog( 'filebrowser' );
     250                        }
     251                };
     252
     253                /**
     254                 * The onlick function assigned to the 'Upload' button.
     255                 * Makes the final decision whether form is really submitted and updates target field when file is uploaded.
     256                 * @param {CKEDITOR.event} evt The event object.
     257                 */
     258                var uploadFile = function( evt )
     259                {
     260                        var dialog = this.getDialog();
     261                        var editor = dialog.getParentEditor();
     262                        var plugin = editor.plugins.filebrowser;
     263
     264                        // Update variables that will be used by the 'OnUploadCompleted' function.
     265                        plugin._onUpload = this.filebrowser.onUpload;
     266                        plugin._dialog = dialog;
     267                        plugin._targetInput = this['for'];
     268                        plugin._formAction = dialog.getContentElement( this['for'][0], this['for'][1] ).getAction();
     269
     270                        // If user didn't select the file, stop the upload.
     271                        if ( !dialog.getContentElement( this['for'][0], this['for'][1] ).getValue() )
     272                        {
     273                                alert( editor.lang.filebrowser.fileNotSelected );
     274                                return false;
     275                        }
     276
     277                        // targetElement will be updated with the url of uploaded file.
     278                        if ( this.filebrowser.updateOnUpload )
     279                                plugin._targetElement = this.filebrowser.updateOnUpload;
     280                        else
     281                        {
     282                                var parentTab = this.getParentTab();
     283                                if ( dialog.getContentElement( parentTab, 'url' ) )
     284                                        plugin._targetElement = [ parentTab, 'url' ];
     285                                else
     286                                        plugin._targetElement = null;
     287                        }
     288
     289                        // Function to be called by the server connector after file is uploaded.
     290                        var uploadCompletedFunction = this.filebrowser.uploadCompletedFunction || 'OnUploadCompleted';
     291
     292                        this.getElement().getWindow().$[uploadCompletedFunction] = function( errorNumber, fileName, customErrorMsg )
     293                        {
     294                                plugin._dialog.getContentElement( plugin._targetInput[0], plugin._targetInput[1] ).reset( plugin._formAction );
     295
     296                                if ( plugin._onUpload && plugin._onUpload( errorNumber, fileName, customErrorMsg ) === false )
     297                                        return;
     298
     299                                if ( !plugin._detectError( editor, errorNumber, customErrorMsg, fileName ) )
     300                                        updateTargetElement( fileName );
     301                        };
     302                };
     303
     304                /**
     305                 * Setups the file element.
     306                 * @param {CKEDITOR.ui.dialog.file} fileInput The file element used during file upload.
     307                 * @param {Object} filebrowser Object containing filebrowser settings assigned to the fileButton
     308                 * associated with this file element.
     309                 */
     310                var setupFileElement = function( fileInput, filebrowser )
     311                {
     312                        fileInput.filebrowser = filebrowser;
     313                        // Set the action attribute in parent form.
     314                        // This function is called only once, before the first upload.
     315                        fileInput.onChange = function( evt )
     316                        {
     317                                var dialog = this.getDialog();
     318                                var editor = dialog.getParentEditor();
     319
     320                                if ( this.filebrowser.url )
     321                                        this.setAction( this.filebrowser.url );
     322                                else if ( editor.config.filebrowser_upload_url )
     323                                        this.setAction( editor.config.filebrowser_upload_url );
     324                                else
     325                                {
     326                                        var params;
     327
     328                                        // If params is set to 'auto', create the default params object.
     329                                        if ( this.filebrowser.params == 'auto' )
     330                                        {
     331                                                params = { currentFolder : '/' };
     332
     333                                                // Assign initial resource type for image and flash dialogs.
     334                                                switch ( dialog.getName() )
     335                                                {
     336                                                        case 'image':
     337                                                                params.type = editor.config.filebrowser_resourcetype_image;
     338                                                                break;
     339                                                        case 'flash':
     340                                                                params.type = editor.config.filebrowser_resourcetype_flash;
     341                                                        default:
     342                                                                params.type = editor.config.filebrowser_resourcetype_default;
     343                                                                break;
     344                                                }
     345                                        }
     346                                        else
     347                                                params = this.filebrowser.params;
     348
     349                                        this.setAction( editor.plugins.filebrowser._commandUrl( editor, this.filebrowser.action, params ) );
     350                                }
     351                        };
     352                };
     353
     354                /**
     355                 * Traverse through the content definition and attach filebrowser
     356                 * to elements with 'filebrowser' attribute.
     357                 * @param {CKEDITOR.dialog.dialogDefinitionObject} definition
     358                 * @param {Array} elements Array of {@link CKEDITOR.dialog.contentDefinition} objects.
     359                 */
     360                var attachFileBrowser = function( definition, elements )
     361                {
     362                        var element, fileInput;
     363
     364                        for ( var i in elements )
     365                        {
     366                                element = elements[i];
     367
     368                                if ( element.type == 'hbox' || element.type == 'vbox' )
     369                                        attachFileBrowser( definition, element.children );
     370
     371                                if ( !element.filebrowser )
     372                                        continue;
     373
     374                                if ( element.filebrowser.action == 'Browse' )
     375                                {
     376                                        element.onClick = browseServer;
     377                                }
     378                                else if ( element.filebrowser.action == 'QuickUpload' && element['for'] )
     379                                {
     380                                        setupFileElement( definition.getContents( element['for'][0] ).get( element['for'][1] ), element.filebrowser );
     381                                        element.onClick = uploadFile;
     382                                }
     383                        }
     384                };
     385
     386                editor.on( 'fileSelected', function( evt )
     387                                {
     388                                        updateTargetElement( evt.data.url );
     389                                });
     390
     391                CKEDITOR.on( 'dialogDefinition', function( evt )
     392                                {
     393                                        var i, browseButton, fileButton;
     394
     395                                        // Attach 'filebrowser' attributes to elements with special id.
     396                                        for ( i in evt.data.definition.contents )
     397                                        {
     398                                                browseButton = evt.data.definition.contents[i].get( 'browse' );
     399                                                if ( browseButton )
     400                                                        browseButton.filebrowser = { action : 'Browse', params : 'auto' };
     401
     402                                                fileButton = evt.data.definition.contents[i].get( 'uploadButton' );
     403                                                if ( fileButton && evt.data.definition.getContents( fileButton['for'][0] ).get( fileButton['for'][1] ).action == 'filebrowser' )
     404                                                        fileButton.filebrowser = { action : 'QuickUpload', params : 'auto' };
     405                                        }
     406
     407                                        // Associate filebrowser to elements with 'filebrowser' attribute.
     408                                        for ( i in evt.data.definition.contents )
     409                                                attachFileBrowser( evt.data.definition, evt.data.definition.contents[i].elements );
     410                                });
     411        }
     412} );
     413
     414CKEDITOR.tools.extend( CKEDITOR.config, {
     415        filebrowser_connector : 'php',
     416        filebrowser_icons : 'ai,avi,bmp,cs,dll,doc,exe,fla,gif,htm,html,jpg,js,mdb,mp3,pdf,png,ppt,rdp,swf,swt,txt,vsd,xls,xml,zip',
     417        filebrowser_resourcetype_image : 'Images',
     418        filebrowser_resourcetype_flash : 'Flash',
     419        filebrowser_resourcetype_default : 'Files'
     420} );
  • _source/plugins/link/dialogs/link.js

     
    10081008                                case 'url':
    10091009                                        var protocol = ( data.url && data.url.protocol ) || 'http://',
    10101010                                                url = ( data.url && data.url.url ) || '';
    1011                                         attributes._cke_saved_href = protocol + url;
     1011                                        attributes._cke_saved_href = ( url.indexOf( '/' ) === 0 ) ? url : protocol + url;
    10121012                                        break;
    10131013                                case 'anchor':
    10141014                                        var name = ( data.anchor && data.anchor.name ),
  • _source/plugins/link/plugin.js

     
    125125{
    126126        linkUploadTab : true,
    127127        linkBrowseServer : true,
    128         linkUploadAction : 'nowhere.php',
     128        linkUploadAction : 'filebrowser',
    129129        linkShowAdvancedTab : true,
    130130        linkShowTargetTab : true
    131131} );
  • ckeditor.pack

     
    8282                                        '_source/core/dom.js',
    8383                                        '_source/core/tools.js',
    8484                                        '_source/core/dtd.js',
     85                                        '_source/core/xml.js',
     86                                        '_source/core/ajax.js',
    8587                                        '_source/core/dom/event.js',
    8688                                        '_source/core/dom/domobject.js',
    8789                                        '_source/core/dom/node.js',
     
    123125                                        '_source/plugins/keystrokes/plugin.js',
    124126                                        '_source/plugins/newpage/plugin.js',
    125127                                        '_source/plugins/removeformat/plugin.js',
     128                                        '_source/plugins/filebrowser/filebrowser.js',
    126129                                        '_source/plugins/smiley/plugin.js',
    127130                                        '_source/plugins/sourcearea/plugin.js',
    128131                                        '_source/plugins/specialchar/plugin.js',
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy