3 * FusionForge Plugin CKeditor Plugin Class
5 * Copyright 2011 (c) Alcatel-Lucent
6 * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
8 * This file is part of FusionForge-plugin-ckeditor
10 * FusionForge-plugin-ckeditor is free software; you can redistribute it
11 * and/or modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
15 * FusionForge-plugin-ckeditor is distributed in the hope that it will
16 * be useful, but WITHOUT ANY WARRANTY; without even the implied
17 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 * See the GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with FusionForge-plugin-ckeditor; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * The ckeditorPlugin class. It implements the Hooks for the presentation
27 * of the text editor whenever needed
31 class ckeditorPlugin extends Plugin {
33 var $toolBar = array();
35 function __construct() {
37 $this->name = "ckeditor" ;
38 $this->text = _("HTML editor (ckeditor)");
39 $this->hooks[] = "user_create";
40 $this->hooks[] = "userisactivecheckbox";
41 $this->hooks[] = "userisactivecheckboxpost";
42 $this->hooks[] = "text_editor";
45 $this->toolBar['complete'] = array(
46 array('Source','-','Cut','Copy','Paste','-','SpellChecker','Scayt'),
47 array('Undo','Redo','-','Find','Replace'),
48 array('JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'),
49 array('Outdent','Indent'),
50 array('Maximize','-','About'),
52 array('Bold','Italic','Underline','Strike','-','Subscript','Superscript'),
53 array('Format','FontSize'),
54 array('TextColor','BGColor'),
55 array('NumberedList','BulletedList'),
56 array('Link','Unlink','Anchor'),
57 array('Table','HorizontalRule','Smiley','SpecialChar','PageBreak')
59 $this->toolBar['fusionforge-basic'] = array(
61 array('JustifyLeft','JustifyCenter'),
62 array('Bold','Italic','Underline','Strike'),
64 array('TextColor','BGColor'),
65 array('NumberedList','BulletedList'),
66 array('Link','Unlink'),
67 array('Table','HorizontalRule')
72 * The function to be called for a Hook
74 * @param String $hookname The name of the hookname that has been happened
75 * @param String $params The params of the Hook
78 function CallHook ($hookname, &$params) {
80 if ($hookname == "user_create") {
81 // Activate the plugin by default for new user.
82 $params['user']->setPluginUse ( $this->name );
83 } elseif ($hookname == "text_editor") {
84 // Check if activated as user side.
85 if (session_loggedin()) {
86 $user = session_get_user();
87 if ($user->usesPlugin ( $this->name )) {
88 return $this->displayCKeditorArea($params);
94 private function displayCKeditorArea(&$params) {
95 $name = isset($params['name'])? $params['name'] : 'body';
96 if (file_exists ("/usr/share/ckeditor/ckeditor.php")) {
97 require_once("/usr/share/ckeditor/ckeditor.php");
98 $editor = new CKeditor($name) ;
99 $editor->basePath = util_make_uri('/ckeditor/');
101 include_once $GLOBALS['gfplugins'].'ckeditor/www/ckeditor.php';
102 if (class_exists('CKeditor')) {
103 $editor = new CKeditor($name) ;
104 $editor->basePath = util_make_uri('/plugins/' . $this->name . '/');
106 $this->setError("Unable to activate ckeditor plugin, package ckeditor not found.");
110 if (isset($params['width'])) $editor->config['width'] = $params['width'];
111 if (isset($params['height'])) $editor->config['height'] = $params['height'];
112 if (isset($params['toolbar']) && array_key_exists(strtolower($params['toolbar']), $this->toolBar)) {
113 $editor->config['toolbar'] = $this->toolBar[strtolower($params['toolbar'])];
115 $editor->config['toolbar'] = $this->toolBar['complete'];
117 $editor->returnOutput = true;
118 $content = '<input type="hidden" name="_'.$name.'_content_type" value="html" />'."\n";
119 $content .= $editor->editor($name, $params['body']) ;
121 // If content is present, return the html code in content.
122 if (isset($params['content'])) {
123 $params['content'] = $content;
125 $GLOBALS['editor_was_set_up'] = true;
133 // c-file-style: "bsd"