Geeklog France

Images avec FCKEditor lors d'un submit story

Cette modification permet à un utilisateur anonyme d'ajouter des images lors de la soumission d'un article.

Créer le dossier images/submit

Afin de centraliser les images qui seront uploadées par les visiteurs anonymes lors de la soumission d'un article, créez le sous dossier submit dans le dossier images de votre installation geeklog. Attribuez les droits en écriture pour ce dossier.

Edit submitstory_fckeditor.js

Remplacer dans le fichier javascript/submitstory_fckeditor.js

        oFCKeditor1.Config['CustomConfigurationsPath'] = geeklogEditorBaseUrl + '/fckeditor/myconfig.js';
        oFCKeditor1.ToolbarSet = 'editor-toolbar1' ;

par

        oFCKeditor1.Config['CustomConfigurationsPath'] = geeklogEditorBaseUrl + '/fckeditor/myconfig2.js';
        oFCKeditor1.ToolbarSet = 'Submit' ;

Création de myconfig2.js

Dans le répertoire fckeditor créer le fichier myconfig2.js contenant le code suivant :

FCKConfig.ImageUploadURL = FCKConfig.BasePath + 'filemanager/upload/' + _QuickUploadLanguage + '/upload2.'
+ _QuickUploadLanguage + '?Type=Image' ;
FCKConfig.ImageBrowser = false ;
FCKConfig.FlashBrowser = false ;
FCKConfig.LinkBrowser = false ;


FCKConfig.ToolbarSets["Submit"] = [
    ['Bold','Italic','-','OrderedList','UnorderedList','-','Link','Unlink','-','Image']
] ;

Création de upload2.php et config2.php

Dans le dossier fckeditor/editor/filemanager/upload/php ajouter les fichier suivant :

  • upload2.php
<?php
/*
 * FCKeditor - The text editor for internet
 * Copyright (C) 2003-2006 Frederico Caldeira Knabben
 *
 * Licensed under the terms of the GNU Lesser General Public License:
 *         http://www.opensource.org/licenses/lgpl-license.php
 *
 * For further information visit:
 *         http://www.fckeditor.net/
 *
 * "Support Open Source software. What about a donation today?"
 *
 * File Name: upload.php
 *     This is the "File Uploader" for PHP.
 *
 * File Authors:
 *         Frederico Caldeira Knabben (fredck@fckeditor.net)
 */

require('config2.php') ;
require('util.php') ;

// This is the function that sends the results of the uploading process.
function SendResults( $errorNumber, $fileUrl = '', $fileName = '', $customMsg = '' )
{
    echo '<script type="text/javascript">' ;
    echo 'window.parent.OnUploadCompleted(' . $errorNumber . ',"' . str_replace( '"', '\\"', $fileUrl )
. '","' . str_replace( '"', '\\"', $fileName ) . '", "' . str_replace( '"', '\\"', $customMsg ) . '") ;' ;
    echo '</script>' ;
    exit ;
}

// Check if this uploader has been enabled.
if ( !$Config['Enabled'] )
    SendResults( '1', '', '', 'This file uploader is disabled. Please check the
"editor/filemanager/upload/php/config2.php" file' ) ;

// Check if the file has been correctly uploaded.
if ( !isset( $_FILES['NewFile'] ) || is_null( $_FILES['NewFile']['tmp_name'] ) || $_FILES['NewFile']['name'] == '' )
    SendResults( '202' ) ;

// Get the posted file.
$oFile = $_FILES['NewFile'] ;

// Get the uploaded file name extension.
$sFileName = $oFile['name'] ;

// Replace dots in the name with underscores (only one dot can be there... security issue).
if ( $Config['ForceSingleExtension'] )
    $sFileName = preg_replace( '/\\.(?![^.]*$)/', '_', $sFileName ) ;

$sOriginalFileName = $sFileName ;

// Get the extension.
$sExtension = substr( $sFileName, ( strrpos($sFileName, '.') + 1 ) ) ;
$sExtension = strtolower( $sExtension ) ;

// The the file type (from the QueryString, by default 'File').
$sType = isset( $_GET['Type'] ) ? $_GET['Type'] : 'File' ;

// Check if it is an allowed type.
if ( !in_array( $sType, array('File','Image','Flash','Media') ) )
    SendResults( 1, '', '', 'Invalid type specified' ) ;

// Get the allowed and denied extensions arrays.
$arAllowed    = $Config['AllowedExtensions'][$sType] ;
$arDenied    = $Config['DeniedExtensions'][$sType] ;

// Check if it is an allowed extension.
if ( ( count($arAllowed) > 0 && !in_array( $sExtension, $arAllowed ) ) || ( count($arDenied) > 0
&& in_array( $sExtension, $arDenied ) ) )
    SendResults( '202' ) ;

$sErrorNumber    = '0' ;
$sFileUrl        = '' ;

// Initializes the counter used to rename the file, if another one with the same name already exists.
$iCounter = 0 ;

// The the target directory.
if ( isset( $Config['UserFilesAbsolutePath'] ) && strlen( $Config['UserFilesAbsolutePath'] ) > 0 )
    $sServerDir = $Config['UserFilesAbsolutePath'] ;
else
    $sServerDir = GetRootPath() . $Config["UserFilesPath"] ;

while ( true )
{
    // Compose the file path.
    $sFilePath = $sServerDir . $sFileName ;

    // If a file with that name already exists.
    if ( is_file( $sFilePath ) )
    {
        $iCounter++ ;
        $sFileName = RemoveExtension( $sOriginalFileName ) . '(' . $iCounter . ').' . $sExtension ;
        $sErrorNumber = '201' ;
    }
    else
    {
        move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ;

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

        $sFileUrl = $Config["UserFilesPath"] . $sFileName ;

        break ;
    }
}

SendResults( $sErrorNumber, $sFileUrl, $sFileName ) ;
?>


  • config2.php
<?php
/*
 * FCKeditor - The text editor for internet
 * Copyright (C) 2003-2006 Frederico Caldeira Knabben
 *
 * Licensed under the terms of the GNU Lesser General Public License:
 *         http://www.opensource.org/licenses/lgpl-license.php
 *
 * For further information visit:
 *         http://www.fckeditor.net/
 *
 * "Support Open Source software. What about a donation today?"
 *
 * File Name: config.php
 *     Configuration file for the PHP File Uploader.
 *
 * File Authors:
 *         Frederico Caldeira Knabben (fredck@fckeditor.net)
 */

include ('../../../../../lib-common.php');
global $Config ;

// SECURITY: You must explicitelly enable this "uploader".
$Config['Enabled'] = true ;

// Path to uploaded files relative to the document root.
$Config['UserFilesPath'] = $_CONF['site_url'] . '/images/submit/' ;

// Fill the following value it you prefer to specify the absolute path for the
// user files directory. Usefull if you are using a virtual directory, symbolic
// link or alias. Examples: 'C:\\MySite\\UserFiles\\' or '/root/mysite/UserFiles/'.
// Attention: The above 'UserFilesPath' must point to the same directory.
$Config['UserFilesAbsolutePath'] = $_CONF['path_html'] . '/images/submit/';

// Due to security issues with Apache modules, it is reccomended to leave the
// following setting enabled.
$Config['ForceSingleExtension'] = true ;

$Config['AllowedExtensions']['File']    = array() ;
$Config['DeniedExtensions']['File']        = array('php','php2','php3','php4','php5','phtml','pwml',
'inc','asp','aspx','ascx','jsp','cfm','cfc','pl','bat','exe','com','dll','vbs','js','reg','cgi') ;

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

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

?>

Tout est en place, il ne vous reste plus qu'à tester.

Connecté en tant que : Guest (Guest)
hacks/sumit-story-fckeditor-image.txt · Dernière modification: 2008/08/01 17:56 par ::Ben
 

Download geeklog

Last version 1.8.1

Espace Membre





Devenir membre
Enregistrez-vous

Mot de passe oublié ?

Change language

Categories

  • Geeklog (38)
  • Plugins (53)
  • Thèmes (17)
  • My cart

    Votre panier (0 article)

    Votre panier est vide!

    0.00 EUR

    Visual Theme Switcher

    Test out available themes by selecting from one of the 6 available themes or give the Visual Switcher a try:

    Follow us on twitter

    En ligne

    Visiteurs: 7