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) {
81 if ($hookname == "user_create") {
82 // Activate the plugin by default for new user.
83 $params['user']->setPluginUse($this->name);
84 } elseif ($hookname == "text_editor") {
85 // Check if activated as user side.
86 if (session_loggedin()) {
87 $user = session_get_user();
88 if ($user->usesPlugin($this->name)) {
89 return $this->displayCKeditorArea($params);
95 private function displayCKeditorArea(&$params) {
96 $name = isset($params['name'])? $params['name'] : 'body';
97 if (file_exists("/usr/share/ckeditor/ckeditor.php")) {
98 require_once '/usr/share/ckeditor/ckeditor.php';
99 $editor = new CKeditor($name);
100 $editor->basePath = util_make_uri('/ckeditor/');
101 } else if (is_file($this->ckeditor_path.'/ckeditor.php')) {
102 require_once $this->ckeditor_path.'/ckeditor.php';
103 $editor = new CKeditor($name);
104 $editor->basePath = util_make_uri('/ckeditor/');
105 } else if (is_file($GLOBALS['gfplugins'].'ckeditor/www/ckeditor.php')) {
106 include_once $GLOBALS['gfplugins'].'ckeditor/www/ckeditor.php';
107 if (class_exists('CKeditor')) {
108 $editor = new CKeditor($name) ;
109 $editor->basePath = util_make_uri('/plugins/' . $this->name . '/');
111 $this->setError(_("Unable to activate ckeditor plugin, package ckeditor not found."));
115 $this->setError(_("Unable to activate ckeditor plugin, package ckeditor not found."));
118 if (isset($params['width'])) $editor->config['width'] = $params['width'];
119 if (isset($params['height'])) $editor->config['height'] = $params['height'];
120 if (isset($params['toolbar']) && array_key_exists(strtolower($params['toolbar']), $this->toolBar)) {
121 $editor->config['toolbar'] = $this->toolBar[strtolower($params['toolbar'])];
123 $editor->config['toolbar'] = $this->toolBar['complete'];
125 $editor->returnOutput = true;
126 $content = '<input type="hidden" name="_'.$name.'_content_type" value="html" />'."\n";
127 $content .= $editor->editor($name, $params['body']) ;
129 // If content is present, return the html code in content.
130 if (isset($params['content'])) {
131 $params['content'] = $content;
133 $GLOBALS['editor_was_set_up'] = true;
141 // c-file-style: "bsd"