*** empty log message ***
[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
65/**\r
66 * Implementation of hook_init().\r
67 */\r
68function fckeditor_init() {\r
63a392a2 69 $output = '<script language="JavaScript1.2" src="modules/fckeditor/lib/fckeditor.js"></script>';\r
d739bfad
JT
70 drupal_set_html_head($output);\r
71}\r
72\r
73\r
74/**\r
75 * Implementation of hook_setting().\r
76 */\r
77function fckeditor_settings() {\r
63a392a2
JT
78 $output = form_textfield(\r
79 t("Base Path"), \r
80 "fckeditor_base_path", \r
81 variable_get("fckeditor_base_path", '/modules/fckeditor/lib/'), \r
82 60, 255, t('The directory wich contains FCKEditor scripts'));\r
83 \r
84 $output .= form_select(\r
85 t('Toolbar'), \r
86 'fckeditor_toolbar', \r
87 variable_get('fckeditor_toolbar', 'Default'), \r
88 array('Default' => 'Default', 'Basic' => 'Basic'), \r
89 t('The toolbar set.'));\r
90\r
91 $output .= form_select(\r
92 t('Skin'), \r
93 'fckeditor_skin', \r
94 variable_get('fckeditor_skin', 'default'), \r
95 array('default' => 'Default', 'silver' => 'Silver', 'office2003' => 'Office 2003'), \r
96 t('The toolbar set.'));\r
97\r
98 $output .= form_select(\r
99 t('Toolbar start expanded'), \r
100 'fckeditor_toolbar_start_expanded', \r
101 variable_get('fckeditor_toolbar_start_expanded', 'true'), \r
102 array('true' => 'Yes', 'false' => 'No'), \r
103 t('The toolbar start expanded or colapced.'));\r
104\r
105 $output .= form_textfield(\r
106 t("Height"), \r
107 "fckeditor_height", \r
108 variable_get("fckeditor_height", 500), \r
109 10, 10, t("height (pixels/percent)"));\r
110 \r
111 $output .= form_textfield(\r
112 t("Width"), "fckeditor_width", \r
113 variable_get("fckeditor_width", '100%'), \r
114 10, 10, t("width (pixels/percent)"));\r
115 \r
116 return $output;\r
d739bfad
JT
117} \r
118\r
119\r
120\r
121/**\r
122 * This function create the HTML objects required for the FCKEditor\r
123 */\r
124function fckeditor_create_editor($name) {\r
125 $html = '';\r
63a392a2
JT
126 $base_path = variable_get("fckeditor_base_path", '/modules/fckeditor/lib/');\r
127 \r
128 $link = "$base_path/editor/fckeditor.html?InstanceName=edit-$name";\r
129 $link .= '&Toolbar=' . variable_get("fckeditor_toolbar", 'Default');\r
d739bfad
JT
130 \r
131 $height = variable_get("fckeditor_height", '500');\r
132 $width = variable_get("fckeditor_width", '100%');\r
133 \r
134 \r
135 // Render the configurations hidden field.\r
136 $html .= '<input type="hidden" id="edit-';\r
137 $html .= $name;\r
138 $html .= '___Config" value="';\r
139 $html .= fckeditor_config_string();\r
140 $html .= '">';\r
141\r
142 // Render the editor IFRAME.\r
143 $html .= '<iframe id="edit-';\r
144 $html .= $name;\r
145 $html .= '___Frame" src="';\r
146 $html .= $link;\r
147 $html .= "\" width=\"$width\" height=\"$height\" frameborder=\"no\" scrolling=\"no\"></iframe>" ;\r
148\r
149 return $html; \r
150}\r
151\r
152\r
153/**\r
154 * Test if client support the FCKEditor\r
155 */\r
156function fckeditor_is_compatible_client() {\r
157 $sAgent = $_SERVER['HTTP_USER_AGENT'] ;\r
158 \r
159 if ( strpos($sAgent, 'MSIE') !== false && strpos($sAgent, 'mac') === false && strpos($sAgent, 'Opera') === false ) {\r
160 $iVersion = (int)substr($sAgent, strpos($sAgent, 'MSIE') + 5, 3);\r
161 return ($iVersion >= 5.5);\r
162 }\r
163 else if ( strpos($sAgent, 'Gecko') !== false ) {\r
164 $iVersion = (int)substr($sAgent, strpos($sAgent, 'Gecko/') + 6, 8) ;\r
165 return ($iVersion >= 20030210) ;\r
166 }\r
167 else\r
168 return false;\r
169}\r
170\r
171\r
172/**\r
173 * Return the configuration string\r
174 */\r
175function fckeditor_config_string() {\r
63a392a2
JT
176 $base_path = variable_get("fckeditor_base_path", 'modules/fckeditor/lib');\r
177 $skin = variable_get("fckeditor_skin", 'default');\r
178 $start = variable_get('fckeditor_toolbar_start_expanded', 'true');\r
179 \r
180 $output = '&DefaultLanguage=en&AutoDetectLanguage=true';\r
181 $output .= '&SkinPath=' . $base_path . "editor/skins/$skin/";\r
182 $output .= '&ToolbarStartExpanded=' . $start;\r
183 \r
d739bfad
JT
184 return $output;\r
185}\r
186?>