This commit was manufactured as part of Drupal's Great Git Migration to
[project/fckeditor.git] / fckeditor.module
CommitLineData
d739bfad
JT
1<?php\r
2\r
3/** \r
4 * FCKEditor Module\r
5 * \r
6 * This module allows Drupal to replace textarea fields with FCKEditor. This HTML \r
7 * text editor brings to the web many of the powerful functionalities of known \r
8 * desktop editors like Word. It's really lightweight and doesn't require any \r
9 * kind of installation on the client computer.\r
10 * \r
11 * \r
12 * FCKeditor - The text editor for internet\r
13 * Copyright (C) 2003-2004 Frederico Caldeira Knabben\r
14 * \r
15 * Licensed under the terms of the GNU Lesser General Public License:\r
16 * http://www.opensource.org/licenses/lgpl-license.php\r
17 * \r
18 * For further information visit:\r
19 * http://www.fckeditor.net/\r
20 *\r
21 *\r
22 * @version 1.0\r
23 * @author LatPro Inc (George)\r
24 */\r
25\r
26\r
27/**\r
28 * Implementation of hook_help\r
29 */\r
30function fckeditor_help($section = '') {\r
31 if ($section == 'admin/modules#description') {\r
32 return $output = t("Allows Drupal to replace textarea fields with FCKEditor");\r
33 }\r
34 return $output;\r
35}\r
36\r
37\r
38/**\r
63a392a2
JT
39 * Implementation of hook_perm\r
40 */\r
41function fckeditor_perm() {\r
42 return array('use fckeditor');\r
43}\r
44\r
45\r
46/**\r
d739bfad
JT
47 * Implementation of textarea\r
48 */\r
49function fckeditor_textarea($op, $name) {\r
50 $output = '';\r
63a392a2
JT
51 $access = user_access('use fckeditor');\r
52\r
53 if ( fckeditor_is_compatible_client() && $access ) {\r
d739bfad
JT
54 if ( $op == 'pre' ) {\r
55 $output = '';\r
56 }\r
57 if ( $op == 'post' ) {\r
58 $output = "<script>document.getElementById('edit-$name').style.display = 'none';</script>";\r
59 $output .= fckeditor_create_editor($name);\r
60 }\r
61 }\r
62 return $output;\r
63}\r
64\r
d739bfad
JT
65\r
66/**\r
67 * Implementation of hook_setting().\r
68 */\r
69function fckeditor_settings() {\r
63a392a2
JT
70 $output = form_textfield(\r
71 t("Base Path"), \r
72 "fckeditor_base_path", \r
73 variable_get("fckeditor_base_path", '/modules/fckeditor/lib/'), \r
74 60, 255, t('The directory wich contains FCKEditor scripts'));\r
75 \r
76 $output .= form_select(\r
77 t('Toolbar'), \r
78 'fckeditor_toolbar', \r
79 variable_get('fckeditor_toolbar', 'Default'), \r
80 array('Default' => 'Default', 'Basic' => 'Basic'), \r
81 t('The toolbar set.'));\r
82\r
83 $output .= form_select(\r
84 t('Skin'), \r
85 'fckeditor_skin', \r
86 variable_get('fckeditor_skin', 'default'), \r
87 array('default' => 'Default', 'silver' => 'Silver', 'office2003' => 'Office 2003'), \r
88 t('The toolbar set.'));\r
89\r
90 $output .= form_select(\r
91 t('Toolbar start expanded'), \r
92 'fckeditor_toolbar_start_expanded', \r
93 variable_get('fckeditor_toolbar_start_expanded', 'true'), \r
94 array('true' => 'Yes', 'false' => 'No'), \r
95 t('The toolbar start expanded or colapced.'));\r
96\r
97 $output .= form_textfield(\r
98 t("Height"), \r
99 "fckeditor_height", \r
100 variable_get("fckeditor_height", 500), \r
101 10, 10, t("height (pixels/percent)"));\r
102 \r
103 $output .= form_textfield(\r
104 t("Width"), "fckeditor_width", \r
105 variable_get("fckeditor_width", '100%'), \r
106 10, 10, t("width (pixels/percent)"));\r
107 \r
108 return $output;\r
d739bfad
JT
109} \r
110\r
111\r
112\r
113/**\r
114 * This function create the HTML objects required for the FCKEditor\r
115 */\r
116function fckeditor_create_editor($name) {\r
117 $html = '';\r
63a392a2
JT
118 $base_path = variable_get("fckeditor_base_path", '/modules/fckeditor/lib/');\r
119 \r
120 $link = "$base_path/editor/fckeditor.html?InstanceName=edit-$name";\r
121 $link .= '&Toolbar=' . variable_get("fckeditor_toolbar", 'Default');\r
d739bfad
JT
122 \r
123 $height = variable_get("fckeditor_height", '500');\r
124 $width = variable_get("fckeditor_width", '100%');\r
125 \r
126 \r
127 // Render the configurations hidden field.\r
128 $html .= '<input type="hidden" id="edit-';\r
129 $html .= $name;\r
130 $html .= '___Config" value="';\r
131 $html .= fckeditor_config_string();\r
132 $html .= '">';\r
133\r
134 // Render the editor IFRAME.\r
135 $html .= '<iframe id="edit-';\r
136 $html .= $name;\r
137 $html .= '___Frame" src="';\r
138 $html .= $link;\r
139 $html .= "\" width=\"$width\" height=\"$height\" frameborder=\"no\" scrolling=\"no\"></iframe>" ;\r
140\r
141 return $html; \r
142}\r
143\r
144\r
145/**\r
146 * Test if client support the FCKEditor\r
147 */\r
148function fckeditor_is_compatible_client() {\r
149 $sAgent = $_SERVER['HTTP_USER_AGENT'] ;\r
150 \r
151 if ( strpos($sAgent, 'MSIE') !== false && strpos($sAgent, 'mac') === false && strpos($sAgent, 'Opera') === false ) {\r
152 $iVersion = (int)substr($sAgent, strpos($sAgent, 'MSIE') + 5, 3);\r
153 return ($iVersion >= 5.5);\r
154 }\r
155 else if ( strpos($sAgent, 'Gecko') !== false ) {\r
156 $iVersion = (int)substr($sAgent, strpos($sAgent, 'Gecko/') + 6, 8) ;\r
157 return ($iVersion >= 20030210) ;\r
158 }\r
159 else\r
160 return false;\r
161}\r
162\r
163\r
164/**\r
165 * Return the configuration string\r
166 */\r
167function fckeditor_config_string() {\r
63a392a2
JT
168 $base_path = variable_get("fckeditor_base_path", 'modules/fckeditor/lib');\r
169 $skin = variable_get("fckeditor_skin", 'default');\r
170 $start = variable_get('fckeditor_toolbar_start_expanded', 'true');\r
171 \r
172 $output = '&DefaultLanguage=en&AutoDetectLanguage=true';\r
173 $output .= '&SkinPath=' . $base_path . "editor/skins/$skin/";\r
174 $output .= '&ToolbarStartExpanded=' . $start;\r
175 \r
d739bfad
JT
176 return $output;\r
177}\r
178?>