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