File: ckeditorPlugin.class.php

package info (click to toggle)
fusionforge 5.3.2%2B20141104-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 60,472 kB
  • sloc: php: 271,846; sql: 36,817; python: 14,575; perl: 6,406; sh: 5,980; xml: 4,294; pascal: 1,411; makefile: 911; cpp: 52; awk: 27
file content (142 lines) | stat: -rw-r--r-- 5,023 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
/**
 * FusionForge Plugin CKeditor Plugin Class
 *
 * Copyright 2011 (c) Alcatel-Lucent
 * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
 * Copyright 2013, Franck Villaume - TrivialDev
 *
 * This file is part of FusionForge-plugin-ckeditor
 *
 * FusionForge-plugin-ckeditor is free software; you can redistribute it
 * and/or modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * FusionForge-plugin-ckeditor is distributed in the hope that it will
 * be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with FusionForge-plugin-ckeditor; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

/**
 * The ckeditorPlugin class. It implements the Hooks for the presentation
 *  of the text editor whenever needed
 *
 */

class ckeditorPlugin extends Plugin {

	var $toolBar = array();

	function __construct() {
		$this->Plugin() ;
		$this->name = "ckeditor" ;
		$this->text = _("HTML editor (ckeditor)");
		$this->hooks[] = "user_create";
		$this->hooks[] = "userisactivecheckbox";
		$this->hooks[] = "userisactivecheckboxpost";
		$this->hooks[] = "text_editor";
		$this->ckeditor_path = forge_get_config('ckeditor_path', 'ckeditor');

		// Toolbar
		$this->toolBar['complete'] = array(
			array('Source','-','Cut','Copy','Paste','-','SpellChecker','Scayt'),
			array('Undo','Redo','-','Find','Replace'),
			array('JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'),
			array('Outdent','Indent'),
			array('Maximize','-','About'),
			'/',
			array('Bold','Italic','Underline','Strike','-','Subscript','Superscript'),
			array('Format','FontSize'),
			array('TextColor','BGColor'),
			array('NumberedList','BulletedList'),
			array('Link','Unlink','Anchor'),
			array('Table','HorizontalRule','Smiley','SpecialChar','PageBreak')
		);
		$this->toolBar['fusionforge-basic'] = array(
			array('Source'),
			array('JustifyLeft','JustifyCenter'),
			array('Bold','Italic','Underline','Strike'),
			array('Format'),
			array('TextColor','BGColor'),
			array('NumberedList','BulletedList'),
			array('Link','Unlink'),
			array('Table','HorizontalRule')
		);
	}

	/**
	 * The function to be called for a Hook
	 *
	 * @param string  $hookname  The name of the hookname that has been happened
	 * @param string  $params    The params of the Hook
	 * @return bool
	 */
	function CallHook($hookname, &$params) {
		if ($hookname == "user_create") {
			// Activate the plugin by default for new user.
			$params['user']->setPluginUse($this->name);
		} elseif ($hookname == "text_editor") {
			// Check if activated as user side.
			if (session_loggedin()) {
				$user = session_get_user();
				if ($user->usesPlugin($this->name)) {
					return $this->displayCKeditorArea($params);
				}
			}
		}
	}

	private function displayCKeditorArea(&$params) {
		$name = isset($params['name'])? $params['name'] : 'body';
		if (file_exists("/usr/share/ckeditor/ckeditor.php")) {
			require_once '/usr/share/ckeditor/ckeditor.php';
			$editor = new CKeditor($name);
			$editor->basePath = util_make_uri('/ckeditor/');
		} else if (is_file($this->ckeditor_path.'/ckeditor.php')) {
			require_once $this->ckeditor_path.'/ckeditor.php';
			$editor = new CKeditor($name);
			$editor->basePath = util_make_uri('/ckeditor/');
		} else if (is_file($GLOBALS['gfplugins'].'ckeditor/www/ckeditor.php')) {
			include_once $GLOBALS['gfplugins'].'ckeditor/www/ckeditor.php';
			if (class_exists('CKeditor')) {
				$editor = new CKeditor($name) ;
				$editor->basePath = util_make_uri('/plugins/' . $this->name . '/');
			} else {
				$this->setError(_("Unable to activate ckeditor plugin, package ckeditor not found."));
				return false;
			}
		} else {
			$this->setError(_("Unable to activate ckeditor plugin, package ckeditor not found."));
			return false;
		}
		if (isset($params['width'])) $editor->config['width'] = $params['width'];
		if (isset($params['height'])) $editor->config['height'] = $params['height'];
		if (isset($params['toolbar']) && array_key_exists(strtolower($params['toolbar']), $this->toolBar)) {
			$editor->config['toolbar'] = $this->toolBar[strtolower($params['toolbar'])];
		} else {
			$editor->config['toolbar'] = $this->toolBar['complete'];
		}
		$editor->returnOutput = true;
		$content = '<input type="hidden" name="_'.$name.'_content_type" value="html" />'."\n";
		$content .= $editor->editor($name, $params['body']) ;

		// If content is present, return the html code in content.
		if (isset($params['content'])) {
			$params['content'] = $content;
		} else {
			$GLOBALS['editor_was_set_up'] = true;
			echo $content ;
		}
	}
}

// Local Variables:
// mode: php
// c-file-style: "bsd"
// End: