|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
sairda Smarty n00b
Joined: 16 May 2011 Posts: 1
|
Posted: Mon May 16, 2011 11:17 pm Post subject: CKEditor CKFinder Plugin using PHP implementation method |
|
|
The following plugin provides a PHP implementation of CKEditor with CKFinder integration. When performing PHP form validation, I was having issue passing POST data back into the editor. This was because the JavaScript implementation does not support passing HTML back into the editor. As a work around, CKEditor forum moderator suggested using the PHP implementation. The plugin is loosly based on the CKEditor examples as well as cezaryece's version.
Code: |
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty function plugin
* Requires PHP >= 5.2.0
* -------------------------------------------------------------
* Type: function
* Name: ckeditor
* Version: 0.1
* Author: aarias239 at gmail dot com
* Purpose: Creates a CKeditor, with CKFinder, textarea.
* -------------------------------------------------------------
* @param name Editor instance name (form field name)
* @param value optional data that control will start with.
* @param configoption optional any config option accepted by editor function
*
*
*/
function smarty_function_ckeditor($params, &$smarty) {
function printNotFound( $ver ) {
static $warned;
if (!empty($warned))
return;
echo '<p><br><strong><span class="error">Error</span>: '.$ver.' not found</strong>. ' .
'This plugin assumes that '.$ver.' is installed in ' .
'the "ckeditor" sibling folder of the CKFinder installation folder. If you have it installed in ' .
'a different place, just edit this file, changing the wrong paths in the include ' .
'(line 47) and the "basePath" values (line 58).</p>' ;
$warned = true;
}
if ( !@file_exists( 'ckeditor/ckeditor.php' ) )
{
if ( @file_exists('ckeditor/ckeditor.js') || @file_exists('ckeditor/ckeditor_source.js') )
printNotFound('CKEditor 3.1+');
else
printNotFound('CKEditor');
}
include_once 'ckeditor/ckeditor.php' ;
require_once 'ckfinder/ckfinder.php' ;
// This is a check for the CKEditor class. If not defined, the paths in lines 57 and 70 must be checked.
if (!class_exists('CKEditor')) {
printNotFound('CKEditor');
}
else {
$ckeditor = new CKEditor( ) ;
$ckeditor->basePath = 'ckeditor/' ;
$arguments = array();
$base_config = array();
if (!isset($params['name']) || empty($params['name'])) {
$smarty->trigger_error('ckeditor: required parameter "name" missing');
} else {
$base_config['name'] = $params['name'];
$base_config['value'] = $params['value'];
$config = array_diff_assoc($params, $base_config);
}
// Just call CKFinder::SetupCKEditor before calling editor(), replace() or replaceAll()
// in CKEditor. The second parameter (optional), is the path for the
// CKFinder installation (default = "/ckfinder/").
CKFinder::SetupCKEditor( $ckeditor ) ;
$ckeditor->editor($base_config['name'], $base_config['value'], $config);
}
}
?>
|
Remember to save this as "fuction.ckeditor.php" in the plugins directory. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|