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() {
37 parent::__construct();
38 $this->name = "ckeditor";
39 $this->text = _("HTML editor (ckeditor)");
41 _("CKEditor is a WYSIWYG text editor that displays within a web browser.");
42 $this->hooks[] = "user_create";
43 $this->hooks[] = "userisactivecheckbox";
44 $this->hooks[] = "userisactivecheckboxpost";
45 $this->hooks[] = "text_editor";
46 $this->ckeditor_path = forge_get_config('ckeditor_path', 'ckeditor');
49 $this->toolBar['complete'] = array(
50 array('Source','-','Cut','Copy','Paste','-','SpellChecker','Scayt'),
51 array('Undo','Redo','-','Find','Replace'),
52 array('JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'),
53 array('Outdent','Indent'),
54 array('Maximize','-','About'),
56 array('Bold','Italic','Underline','Strike','-','Subscript','Superscript'),
57 array('Format','FontSize'),
58 array('TextColor','BGColor'),
59 array('NumberedList','BulletedList'),
60 array('Link','Unlink','Anchor'),
61 array('Table','HorizontalRule','Smiley','SpecialChar','PageBreak')
63 $this->toolBar['fusionforge-basic'] = array(
65 array('JustifyLeft','JustifyCenter'),
66 array('Bold','Italic','Underline','Strike'),
68 array('TextColor','BGColor'),
69 array('NumberedList','BulletedList'),
70 array('Link','Unlink'),
71 array('Table','HorizontalRule')
76 * The function to be called for a Hook
78 * @param string $hookname The name of the hookname that has been happened
79 * @param string $params The params of the Hook
82 function CallHook($hookname, &$params) {
83 if ($hookname == "user_create") {
84 // Activate the plugin by default for new user.
85 $params['user']->setPluginUse($this->name);
86 } elseif ($hookname == "text_editor") {
87 // Check if activated as user side.
88 if (session_loggedin()) {
89 $user = session_get_user();
90 if ($user->usesPlugin($this->name)) {
91 return $this->displayCKeditorArea($params);
97 private function displayCKeditorArea(&$params) {
98 $name = isset($params['name'])? $params['name'] : 'body';
99 if (file_exists("/usr/share/ckeditor/ckeditor.php")) {
100 require_once '/usr/share/ckeditor/ckeditor.php';
101 $editor = new CKeditor($name);
102 $editor->basePath = util_make_uri('/ckeditor/');
103 } else if (is_file($this->ckeditor_path.'/ckeditor.php')) {
104 require_once $this->ckeditor_path.'/ckeditor.php';
105 $editor = new CKeditor($name);
106 $editor->basePath = util_make_uri('/ckeditor/');
107 } else if (is_file($GLOBALS['gfplugins'].'ckeditor/www/ckeditor.php')) {
108 include_once $GLOBALS['gfplugins'].'ckeditor/www/ckeditor.php';
109 if (class_exists('CKeditor')) {
110 $editor = new CKeditor($name) ;
111 $editor->basePath = util_make_uri('/plugins/' . $this->name . '/');
113 $this->setError(_("Unable to activate ckeditor plugin, package ckeditor not found."));
117 $this->setError(_("Unable to activate ckeditor plugin, package ckeditor not found."));
120 if (isset($params['width'])) {
121 $editor->config['width'] = $params['width'];
123 if (isset($params['height'])) {
124 $editor->config['height'] = $params['height'];
126 if (isset($params['toolbar']) && array_key_exists(strtolower($params['toolbar']), $this->toolBar)) {
127 $editor->config['toolbar'] = $this->toolBar[strtolower($params['toolbar'])];
129 $editor->config['toolbar'] = $this->toolBar['complete'];
131 $editor->returnOutput = true;
132 $content = '<input type="hidden" name="_'.$name.'_content_type" value="html" />'."\n";
133 $content .= $editor->editor($name, $params['body']) ;
135 // If content is present, return the html code in content.
136 if (isset($params['content'])) {
137 $params['content'] = $content;
139 $GLOBALS['editor_was_set_up'] = true;
147 // c-file-style: "bsd"