| Commit | Line | Data |
|---|---|---|
| 04b827fa | 1 | <?php |
| e44c2389 | 2 | // $Id$ |
| 8de1e54a | 3 | /** |
| 0c87a920 | 4 | * FCKeditor - The text editor for Internet - http://www.fckeditor.net |
| 20c63aec | 5 | * Copyright (C) 2003-2008 Frederico Caldeira Knabben |
| ebc6fdec | 6 | * |
| 0c87a920 | 7 | * == BEGIN LICENSE == |
| 9b429add | 8 | * |
| 0c87a920 WW |
9 | * Licensed under the terms of any of the following licenses at your |
| 10 | * choice: | |
| f3d88ca0 | 11 | * |
| 0c87a920 WW |
12 | * - GNU General Public License Version 2 or later (the "GPL") |
| 13 | * http://www.gnu.org/licenses/gpl.html | |
| 9b429add | 14 | * |
| 0c87a920 WW |
15 | * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") |
| 16 | * http://www.gnu.org/licenses/lgpl.html | |
| ebc6fdec | 17 | * |
| 0c87a920 WW |
18 | * - Mozilla Public License Version 1.1 or later (the "MPL") |
| 19 | * http://www.mozilla.org/MPL/MPL-1.1.html | |
| ebc6fdec | 20 | * |
| 0c87a920 | 21 | * == END LICENSE == |
| 9b429add | 22 | * |
| 0c87a920 | 23 | * @file |
| 20c63aec | 24 | * FCKeditor Module for Drupal 6.x |
| 0c87a920 WW |
25 | * |
| 26 | * This module allows Drupal to replace textarea fields with FCKeditor. | |
| 04b827fa | 27 | * |
| 0c87a920 WW |
28 | * This HTML text editor brings to the web many of the powerful functionalities |
| 29 | * of known desktop editors like Word. It's really lightweight and doesn't | |
| 30 | * require any kind of installation on the client computer. | |
| 04b827fa DS |
31 | */ |
| 32 | ||
| 0c87a920 WW |
33 | /** |
| 34 | * The name of simplified toolbar which should be forced | |
| 35 | * Be sure that this toolbar is defined in fckeditor.config.js or fckconfig.js | |
| 36 | */ | |
| 37 | define('FCKEDITOR_FORCE_SIMPLE_TOOLBAR_NAME', 'DrupalBasic') ; | |
| 04b827fa | 38 | |
| c3f50453 WW |
39 | global $_fckeditor_configuration; |
| 40 | global $_fckeditor_js_ids; | |
| dedd64a9 | 41 | |
| c3f50453 WW |
42 | $_fckeditor_configuration = array(); |
| 43 | $_fckeditor_js_ids = array(); | |
| dedd64a9 | 44 | |
| 04b827fa DS |
45 | /** |
| 46 | * Implementation of hook_help | |
| 47 | */ | |
| 0c87a920 WW |
48 | function fckeditor_help($path, $arg) { |
| 49 | switch ($path) { | |
| 9b429add | 50 | case 'admin/settings/help#description': |
| e44c2389 | 51 | $output = t("Enables the usage of FCKeditor (WYSIWYG editor) instead of plain text fields."); |
| 52 | break; | |
| 31a6dbc3 | 53 | case 'admin/settings/fckeditor': |
| cc0fc71b WW |
54 | if (!empty($arg[3]) && in_array($arg[3], array("addg", "editg"))) { |
| 55 | $output = t("<p>The Global Profile allows you to define settings that are common for all profiles. Values defined in other profiles will be appended to the global configuration. This way you can avoid repeating some of the settings that are usually the same in each profile.</p>"); | |
| 56 | break; | |
| 57 | } | |
| 58 | else if (!empty($arg[3]) && in_array($arg[3], array("add", "edit"))) { | |
| 59 | $output = t("<p>Note: FCKeditor is highly configurable. The most commonly used features are listed below. If you want to take a look at all available settings, open <code>!fckconfig</code> and then customize <code>!fckeditor_config</code> to your needs. This is also the only way to define new toolbar sets. It is advised to not edit <code>fckconfig.js</code> because you may overwrite it accidentally when you update the editor.</p>", array('!fckconfig' => drupal_get_path('module', 'fckeditor') ."/fckeditor/fckconfig.js", '!fckeditor_config' => drupal_get_path('module', 'fckeditor') ."/fckeditor.config.js")); | |
| 60 | break; | |
| 61 | } | |
| 62 | else if (!empty($arg[3]) && in_array($arg[3], array("delete", "deleteg"))) { | |
| 63 | break; | |
| 64 | } | |
| 8de1e54a | 65 | $output = t("<p>The FCKeditor module allows Drupal to replace textarea fields with a rich text or <acronym title=\"What You See Is What You Get\">WYSIWYG</acronym> editor. This editor brings many of the powerful functionalities of known desktop editors like Word to the web. It's relatively lightweight and doesn't require any kind of installation on the client computer.</p><p>More information about the editor is located at the !fckeditorlink. A small user guide is located at !userguidelink.</p>", |
| 0c87a920 WW |
66 | array( |
| 67 | '!fckeditorlink' => l(t('FCKeditor homepage'), 'http://www.fckeditor.net'), | |
| 8de1e54a | 68 | '!userguidelink' => l(t('FCKeditor userguide'), 'http://docs.fckeditor.net/FCKeditor/Users_Guide')) |
| 0c87a920 | 69 | ); |
| 8de1e54a | 70 | $output .= t('<p>Profiles can be defined based on user roles. A FCKeditor profile can define which pages receive this FCKeditor capability, what buttons or themes are enabled for the editor, how the editor is displayed, and a few other editor functions. It is possible also to define the Global Profile that will hold values that will be appended to all other profiles.</p><p>Lastly, only users with the <code>!access1</code> !permission will be able to use FCKeditor. </p>', array('!permission' => l(t('permission'), 'admin/user/permissions'), '!access1' => t('access fckeditor'))); |
| 31a6dbc3 | 71 | break; |
| e44c2389 | 72 | case 'admin/help#fckeditor': |
| 0c87a920 WW |
73 | $output = t("<p>The FCKeditor module allows Drupal to replace textarea fields with a rich text or <acronym title=\"What You See Is What You Get\">WYSIWYG</acronym> editor. This editor brings many of the powerful functionalities of known desktop editors like Word to the web. It's relatively lightweight and doesn't require any kind of installation on the client computer.</p><p>More information is located at the !fckeditorlink. A small user guide is located at !userguidelink.</p>", |
| 74 | array( | |
| 75 | '!fckeditorlink' => l(t('FCKeditor homepage'), 'http://www.fckeditor.net'), | |
| 8de1e54a | 76 | '!userguidelink' => l(t('FCKeditor userguide'), 'http://docs.fckeditor.net/FCKeditor/Users_Guide')) |
| 0c87a920 | 77 | ); |
| 20c63aec | 78 | $output .= t('<h3>Configuration</h3><ol><li>Go to the !fckeditorlink and download the latest version of FCKeditor. Then uncompress the contents of the "fckeditor" directory of the downloaded file to %fckeditordir.</li><li>Enable the module as usual from Drupal\'s admin pages.</li><li>Grant permissions for use of FCKeditor in <code>!path2</code><br/>Note: to enable the file browser, read also the <i>How to enable the file browser</i> section.</li><li>Under <code>!path1</code>, adjust the fckeditor profiles. In each profile you can choose which textareas will be replaced by FCKeditor, select default toolbar and configure some more advanced settings.</li><li>For the Rich Text Editing to work you also need to configure your !filterlink for the users that may access Rich Text Editing. Either grant those users Full HTML access or use the following: <br/><code>!filter</code>. </li><li>To have a better control over line breaks, you may disable <code>Line break converter</code> in the chosen filter (recommended).</li><li>Modify the fckeditor.config.js file to custom your needs (optional).<br />You may copy the needed configuration lines from the default FCKeditor configuration settings (!fckconfig), the lines in fckeditor.config.js will override most settings.</li></ol>', |
| 0c87a920 | 79 | array( |
| 8de1e54a | 80 | '!fckeditorlink' => l(t('FCKeditor homepage'), 'http://www.fckeditor.net/download'), |
| 20c63aec WW |
81 | '%fckeditordir' => base_path() . drupal_get_path('module', 'fckeditor') .'/fckeditor/', |
| 82 | '!path1' => l(t('Administer > Site configuration > FCKeditor'), 'admin/settings/fckeditor'), | |
| 83 | '!path2' => l(t('Administer > User Management > Permissions'), 'admin/user/permissions'), | |
| 0c87a920 WW |
84 | '!filter' => htmlentities('<a> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> |
| 85 | <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <em> | |
| 86 | <b> <u> <i> <strong> <font> <del> <ins> <sub> <sup> <quote> <blockquote> | |
| dd8adb08 | 87 | <pre> <address> <code> <cite> <embed> <object> <param> <strike> <caption>'), |
| 20c63aec | 88 | '!fckconfig' => base_path() . drupal_get_path('module', 'fckeditor') .'/fckeditor/fckconfig.js', |
| d3cf16a0 | 89 | '!moduledir' => base_path() . drupal_get_path('module', 'fckeditor') .'/fckeditor', |
| 8de1e54a WW |
90 | '!filterlink' => l(t('filters'), 'admin/settings/filters')) |
| 91 | ); | |
| 20c63aec | 92 | $output .= t('<h3>Installation troubleshooting</h3><p>If your FCKeditor does not show you must check if all files are extracted correctly. The directory %fckeditordir should have the following files: <code>fckeditor.js, fckconfig.js, fckstyles.xml, fcktemplates.xml</code> and a directory named <code>editor</code>.</p>', |
| 8de1e54a WW |
93 | array( |
| 94 | '%fckeditordir' => base_path() . drupal_get_path('module', 'fckeditor') .'/fckeditor/') | |
| 0c87a920 | 95 | ); |
| 8de1e54a WW |
96 | $output .= t('The correct directory structure is as follows: <blockquote><pre>!structure</pre></blockquote>', array( |
| 97 | '!structure' => "modules\n fckeditor\n <em>fckeditor.module</em>\n fckeditor\n _samples\n editor\n <em>COPY_HERE.txt</em>\n <em>fckconfig.js</em>\n ..." | |
| 98 | )); | |
| 034070a8 | 99 | $output .= t("<h3>Plugins: Teaser break and Pagebreak</h3><p>By default, FCKeditor module comes with two plugins that can handle teaser break (<!--break-->) and pagebreak (<!--pagebreak-->). You can enable any (or even both) of them.<ol><li>Open <code>!fckeditor.config.js</code> and uncomment these three lines: <pre>!code</pre></li><li>The second step is to add buttons to the toolbar (in the same file). The button names are: <code>DrupalBreak, DrupalPageBreak</code>. For example if you have a toolbar with an array of buttons defined as follows: <pre>!buttons1</pre> simply add those two buttons at the end of array: <pre>!buttons2</pre> (remember about single quotes).</li><li>Note that the <--pagebreak--> tag is not supported by default in Drupal. You should install the <a href=\"!paging\" target=\"_blank\">Paging</a> module to enable the <!--pagebreak--> tag support. Please refer to the Paging module documentation for detailed installation instructions.</li></ol></p>", |
| 0c87a920 | 100 | array( |
| 8de1e54a WW |
101 | '!fckeditor.config.js' => base_path() . drupal_get_path('module', 'fckeditor') .'/fckeditor.config.js', |
| 102 | '!code' => " | |
| 103 | FCKConfig.PluginsPath = '../../plugins/' ; | |
| 104 | FCKConfig.Plugins.Add( 'drupalbreak' ) ; | |
| 105 | FCKConfig.Plugins.Add( 'drupalpagebreak' ) ; | |
| 106 | ", | |
| 034070a8 | 107 | "!paging" => "http://drupal.org/project/paging", |
| 8de1e54a WW |
108 | '!buttons1' => "['Image','Flash','Table','Rule','SpecialChar']", |
| 109 | '!buttons2' => "['Image','Flash','Table','Rule','SpecialChar', 'DrupalBreak', 'DrupalPageBreak']", | |
| 0c87a920 | 110 | )); |
| 730747a1 | 111 | $output .= t('<h3>Uploading images and files</h3><p>There are three ways of uploading files: by using the built-in file browser, by using modules like !imce, !ib or by using the core upload module.</p>', |
| 0c87a920 | 112 | array( |
| 7d26d749 WW |
113 | '!imce' => l(t('IMCE'), 'http://drupal.org/project/imce'), |
| 114 | '!ib' => l(t('Image Browser'), 'http://drupal.org/project/imagebrowser') | |
| 0c87a920 WW |
115 | ) |
| 116 | ); | |
| e44c2389 | 117 | // the rest is untranslated for the moment |
| 8de1e54a | 118 | $output .= t("<h3>How to enable the file browser</h3><p>The editor gives the end user the flexibility to create a custom file browser that can be integrated on it. The included file browser allows users to view the content of a specific directory on the server and add new content to that directory (create folders and upload files).</p><p><ol><li>To enable file browsing you need to edit the connector configuration file in your fckeditor module directory, the file should be in:<blockquote><code>!config3</code> <br/> (FCKeditor 2.5+)<br/><br/> or <br/><br/><code>!config1</code><br/> and <br/><code>!config2</code> <br/> (FCKeditor 2.3.x - 2.4.x)</blockquote></p><p>In this file(s) you will need to enable the file browser by adding one line that includes file with the special authentication function for Drupal (<code>filemanager.config.php</code>). Add this code: <blockquote><code>!code1</code><br/> (FCKeditor 2.5+)</blockquote> or <blockquote><code>!code2</code> <br/> (FCKeditor 2.3.x - 2.4.x)</blockquote> straight below this line: <blockquote><code>!code3</code></blockquote> The config.php file also holds some other important settings, please take a look at it and adjust it to your needs (optional).</p></li>", |
| 0c87a920 WW |
119 | array('!config1' => base_path() . drupal_get_path('module', 'fckeditor') ."/fckeditor/editor/filemanager/browser/default/connectors/php/config.php", |
| 120 | '!config2' => base_path() . drupal_get_path('module', 'fckeditor') ."/fckeditor/editor/filemanager/upload/php/config.php", | |
| 121 | '!config3' => base_path() . drupal_get_path('module', 'fckeditor') ."/fckeditor/editor/filemanager/connectors/php/config.php", | |
| 122 | '!filesdir' => file_directory_path(), | |
| 8de1e54a WW |
123 | '!code1' => 'require_once "../../../../../filemanager.config.php";', //2.5 |
| 124 | '!code2' => 'require_once "'. str_replace("\\", "\\\\", dirname(__FILE__) . DIRECTORY_SEPARATOR .'filemanager.config.php"'), //2.4 | |
| 125 | '!code3' => "\$Config['UserFilesAbsolutePath'] = '' ;", | |
| 0c87a920 | 126 | ) |
| 8de1e54a WW |
127 | ); |
| 128 | $output .= t("<li>As of Drupal 5.2, additional step is required: locate file named <code>settings.php</code> inside your drupal directory (usually <code>sites/default/settings.php</code>) and set <strong><code>$cookie_domain</code></strong> variable to the appropiate domain (remember to uncomment that line). If you not do this, FCKeditor will claim that file browser is disabled</li>"); | |
| 7ef7dbd4 | 129 | $output .= t('<li>Enabling file uploads is <strong>a security risk</strong>. That\'s why you have to grant a !link to enable the file browser to certain groups (assign the "!allowupload" permissions).</li>', array('!link' => l(t('separate permission'), 'admin/user/permissions'), "!allowupload" => t("allow fckeditor file uploads"))); |
| 8de1e54a | 130 | $output .= t('<li>Lastly, adjust the !fb for each !profile.</li></ol>', array('!fb' => t('File browser settings'), '!profile' => l(t('profile'), 'admin/settings/fckeditor'))); |
| 4265186e | 131 | $output .= t("<h3>Modules: Image Assist</h3><p>Image Assist can be integrated with FCKeditor. To do this, simply copy the <code>!iaf1</code> file to <code>!iaf2</code>.</p>", array("!iaf1" => drupal_get_path('module', 'fckeditor') ."/img_assist_fckeditor.js", "!iaf2" => drupal_get_path('module', 'img_assist') ."/img_assist_fckeditor.js")); |
| 0c87a920 | 132 | |
| e44c2389 | 133 | break; |
| 04b827fa | 134 | } |
| d7fbc905 | 135 | return !empty($output) ? $output : ""; |
| 04b827fa DS |
136 | } |
| 137 | ||
| 04b827fa DS |
138 | /** |
| 139 | * Implementation of hook_perm | |
| 20c63aec | 140 | * Administer -> User management -> Permissions |
| 04b827fa DS |
141 | */ |
| 142 | function fckeditor_perm() { | |
| 0c87a920 | 143 | return array('administer fckeditor', 'access fckeditor', 'allow fckeditor file uploads'); |
| 04b827fa DS |
144 | } |
| 145 | ||
| 9b429add | 146 | |
| 04b827fa | 147 | /** |
| 9b429add | 148 | * Implementation of textarea |
| 0c87a920 | 149 | * Replace textarea with FCKeditor using callback function (fckeditor_process_textarea) |
| 04b827fa | 150 | */ |
| f3d88ca0 | 151 | function fckeditor_elements() { |
| 152 | $type = array(); | |
| e794befa | 153 | $type['textfield'] = array( |
| 0c87a920 WW |
154 | '#process' => array( |
| 155 | 'fckeditor_process_input' | |
| e794befa WW |
156 | ), |
| 157 | ); | |
| 0c87a920 | 158 | if (user_access('access fckeditor')) { |
| f3d88ca0 | 159 | // only roles with permission get the fckeditor |
| 160 | if (fckeditor_is_compatible_client()) { | |
| 161 | // it would be useless to dig deeper if we're not able or allowed to | |
| dedd64a9 WW |
162 | $type['textarea'] = array('#process' => array('fckeditor_process_textarea')); |
| 163 | $type['form'] = array('#after_build' => array('fckeditor_process_form')); | |
| 04b827fa DS |
164 | } |
| 165 | } | |
| f3d88ca0 | 166 | return $type; |
| 04b827fa DS |
167 | } |
| 168 | ||
| dedd64a9 | 169 | function fckeditor_process_form(&$form) { |
| c3f50453 | 170 | global $_fckeditor_configuration, $_fckeditor_js_ids; |
| dedd64a9 WW |
171 | static $processed_textareas = array(); |
| 172 | static $found_textareas = array(); | |
| 173 | ||
| 174 | //Skip if: | |
| 175 | // - we're not editing an element | |
| 176 | // - fckeditor is not enabled (configuration is empty) | |
| c3f50453 | 177 | if (arg(1) == "add" || arg(1) == "reply" || !count($_fckeditor_configuration)) { |
| dedd64a9 WW |
178 | return $form; |
| 179 | } | |
| 180 | ||
| 181 | $fckeditor_filters = array(); | |
| 182 | ||
| 183 | // Iterate over element children; resetting array keys to access last index. | |
| 184 | if ($children = array_values(element_children($form))) { | |
| 185 | foreach ($children as $index => $item) { | |
| 186 | $element = &$form[$item]; | |
| 187 | ||
| c3f50453 | 188 | if (isset($element['#id']) && in_array($element['#id'], array_keys($_fckeditor_js_ids))) { |
| dedd64a9 WW |
189 | $found_textareas[$element['#id']] = &$element; |
| 190 | } | |
| 191 | ||
| 192 | // filter_form() always uses the key 'format'. We need a type-agnostic | |
| 193 | // match to prevent false positives. Also, there must have been at least | |
| 194 | // one element on this level. | |
| 195 | if ($item === 'format' && $index > 0) { | |
| 196 | ||
| 197 | // Make sure we either match a input format selector or input format | |
| 198 | // guidelines (displayed if user has access to one input format only). | |
| 199 | if ((isset($element['#type']) && $element['#type'] == 'fieldset') || isset($element['format']['guidelines'])) { | |
| 200 | // The element before this element is the target form field. | |
| 201 | $field = &$form[$children[$index - 1]]; | |
| 202 | $textarea_id = $field['#id']; | |
| c3f50453 | 203 | $js_id = $_fckeditor_js_ids[$textarea_id]; |
| dedd64a9 WW |
204 | |
| 205 | array_push($processed_textareas, $js_id); | |
| 206 | ||
| 207 | //search for checkxss1/2 class | |
| c3f50453 | 208 | if (empty($field['#attributes']['class']) || strpos($field['#attributes']['class'], "checkxss") === FALSE) { |
| dedd64a9 WW |
209 | continue; |
| 210 | } | |
| 211 | ||
| 212 | // Determine the available input formats. The last child element is a | |
| 213 | // link to "More information about formatting options". When only one | |
| 214 | // input format is displayed, we also have to remove formatting | |
| 215 | // guidelines, stored in the child 'format'. | |
| 216 | $formats = element_children($element); | |
| 217 | ||
| 218 | foreach ($formats as $format_id) { | |
| 18bd52b0 | 219 | $format = !empty($element[$format_id]['#default_value']) ? $element[$format_id]['#default_value'] : $element[$format_id]['#value']; |
| dedd64a9 WW |
220 | break; |
| 221 | } | |
| 222 | ||
| 223 | $enabled = filter_list_format($format); | |
| 224 | $fckeditor_filters = array(); | |
| 225 | ||
| 226 | //loop through all enabled filters | |
| 227 | foreach ($enabled as $id => $filter) { | |
| 228 | //but use only that one selected in FCKeditor profile | |
| c3f50453 | 229 | if (in_array($id, array_keys($_fckeditor_configuration[$textarea_id]['filters']))) { |
| dedd64a9 WW |
230 | if (!isset($fckeditor_filters[$js_id])) { |
| 231 | $fckeditor_filters[$js_id] = array(); | |
| 232 | } | |
| c3f50453 | 233 | $fckeditor_filters[$js_id][] = $id ."/". $format; |
| dedd64a9 WW |
234 | } |
| 235 | } | |
| 236 | ||
| 237 | //No filters assigned, remove xss class | |
| 238 | if (empty($fckeditor_filters[$js_id])) { | |
| 239 | $field['#attributes']['class'] = preg_replace("/checkxss(1|2)/", "", $field['#attributes']['class']); | |
| 240 | } | |
| 241 | else { | |
| 242 | $field['#attributes']['class'] = strtr($field['#attributes']['class'], array("checkxss1" => "filterxss1", "checkxss2" => "filterxss2")); | |
| 243 | } | |
| 244 | ||
| 245 | array_pop($formats); | |
| 246 | unset($formats['format']); | |
| 247 | } | |
| 248 | // If this element is 'format', do not recurse further. | |
| 249 | continue; | |
| 250 | } | |
| 251 | // Recurse into children. | |
| 252 | fckeditor_process_form($element); | |
| 253 | } | |
| 254 | } | |
| 255 | ||
| 256 | //We're in a form | |
| 257 | if (isset($form['#action'])) { | |
| 258 | //some textareas associated with FCKeditor has not been processed | |
| c3f50453 | 259 | if (count($processed_textareas) < count($_fckeditor_js_ids)) { |
| dedd64a9 | 260 | //loop through all found textfields |
| e388c81a | 261 | foreach (array_keys($found_textareas) as $id) { |
| c3f50453 | 262 | $element = &$found_textareas[$id]; |
| dedd64a9 | 263 | //if not processed yet (checkxss class is before final processing) |
| c3f50453 | 264 | if (strpos($element['#attributes']['class'], "checkxss") !== FALSE && !in_array($_fckeditor_js_ids[$element['#id']], $processed_textareas)) { |
| dedd64a9 | 265 | //assign default Filtered HTML to be safe on fields that do not have input format assigned |
| c3f50453 | 266 | $js_id = $_fckeditor_js_ids[$element['#id']]; |
| dedd64a9 WW |
267 | $fckeditor_filters[$js_id][] = "filter/0/1"; |
| 268 | $element['#attributes']['class'] = strtr($element['#attributes']['class'], array("checkxss1" => "filterxss1", "checkxss2" => "filterxss2")); | |
| 269 | } | |
| 270 | } | |
| 271 | } | |
| 272 | } | |
| 273 | ||
| 274 | if (!empty($fckeditor_filters)) { | |
| 275 | drupal_add_js(array('fckeditor_filters' => $fckeditor_filters), 'setting'); | |
| 276 | } | |
| 277 | ||
| 278 | return $form; | |
| 279 | } | |
| 280 | ||
| 0c87a920 WW |
281 | /** |
| 282 | * Allow more than 255 chars in Allowed HTML tags textfield | |
| 283 | * | |
| 284 | */ | |
| 285 | function fckeditor_process_input($element) { | |
| 286 | if ($element['#id']=='edit-allowed-html-1') { | |
| 287 | $element['#maxlength'] = max($element['#maxlength'], 1024); | |
| 9b429add | 288 | } |
| 0c87a920 | 289 | return $element; |
| 9b429add | 290 | } |
| 291 | ||
| 0c87a920 WW |
292 | /** |
| 293 | * Add link to FCKeditor configuration in "Administer -> Site configuration" section | |
| 294 | * | |
| 295 | */ | |
| 296 | function fckeditor_menu() { | |
| 8de1e54a | 297 | |
| 0c87a920 | 298 | $items = array(); |
| ebc6fdec | 299 | |
| dedd64a9 WW |
300 | $items['fckeditor/xss'] = array( |
| 301 | 'title' => 'XSS Filter', | |
| 302 | 'description' => 'XSS Filter.', | |
| 303 | 'page callback' => 'fckeditor_filter_xss', | |
| 304 | 'access arguments' => array('access fckeditor'), | |
| 305 | 'type' => MENU_CALLBACK, | |
| 306 | ); | |
| 307 | ||
| 0c87a920 | 308 | $items['admin/settings/fckeditor'] = array( |
| f00844bc WW |
309 | 'title' => 'FCKeditor', |
| 310 | 'description' => 'Configure the rich editor.', | |
| 0c87a920 WW |
311 | 'page callback' => 'fckeditor_admin', |
| 312 | 'access arguments' => array('administer fckeditor'), | |
| 313 | 'type' => MENU_NORMAL_ITEM, | |
| f3d88ca0 | 314 | ); |
| 0c87a920 WW |
315 | |
| 316 | return $items; | |
| 317 | } | |
| 318 | ||
| dedd64a9 WW |
319 | /** |
| 320 | * AJAX callback - XSS filter | |
| 321 | */ | |
| 322 | function fckeditor_filter_xss() { | |
| 4da0d34e WW |
323 | $GLOBALS['devel_shutdown'] = FALSE; |
| 324 | ||
| dedd64a9 WW |
325 | if (!isset($_POST['text']) || !is_string($_POST['text']) || !is_array($_POST['filters'])) { |
| 326 | exit; | |
| 327 | } | |
| 328 | ||
| 329 | $text = $_POST['text']; | |
| 330 | $text = strtr($text, array('<!--' => '__COMMENT__START__', '-->' => '__COMMENT__END__')); | |
| 331 | ||
| 332 | foreach ($_POST['filters'] as $module_delta) { | |
| 333 | $module = strtok($module_delta, "/"); | |
| 334 | $delta = strtok("/"); | |
| 335 | $format = strtok("/"); | |
| 336 | ||
| 4da0d34e WW |
337 | if (!module_hook($module, 'filter')) { |
| 338 | continue; | |
| 339 | } | |
| 340 | ||
| dedd64a9 WW |
341 | //built-in filter module, a special case where we would like to strip XSS and nothing more |
| 342 | if ($module == 'filter' && $delta == 0) { | |
| 343 | preg_match_all("|</?([a-z][a-z0-9]*)(?:\b[^>]*)>|i", $text, $matches); | |
| 344 | if ($matches[1]) { | |
| 345 | $tags = array_unique($matches[1]); | |
| 346 | $text = filter_xss($text, $tags); | |
| 347 | } | |
| 348 | } | |
| 349 | else { | |
| 350 | $text = module_invoke($module, 'filter', 'process', $delta, $format, $text); | |
| 351 | } | |
| 352 | } | |
| 353 | ||
| 354 | $text = strtr($text, array('__COMMENT__START__' => '<!--', '__COMMENT__END__' => '-->')); | |
| 355 | ||
| 356 | echo $text; | |
| 357 | exit; | |
| 358 | } | |
| 359 | ||
| 0c87a920 WW |
360 | //Remove a profile from the database. |
| 361 | function fckeditor_profile_delete($name) { | |
| 362 | db_query("DELETE FROM {fckeditor_settings} WHERE name = '%s'", $name); | |
| 363 | db_query("DELETE FROM {fckeditor_role} WHERE name = '%s'", $name); | |
| 364 | } | |
| 365 | ||
| 366 | /** | |
| 367 | * Profile validation. | |
| 368 | */ | |
| 369 | function fckeditor_profile_validate($edit) { | |
| 370 | $errors = array(); | |
| 8de1e54a | 371 | |
| 09aae5b1 WW |
372 | //include mode and all other fields are empty, invalid |
| 373 | if ($edit['excl_mode'] == 1 && !$edit['excl_fields'] && !$edit['excl_paths']) { | |
| 7e1cf369 | 374 | $errors['excl_mode'] = t('Include mode selected, but no fields/paths given. Enter at least one path or field where FCKeditor should appear.'); |
| 09aae5b1 WW |
375 | } |
| 376 | ||
| 8de1e54a WW |
377 | if (!preg_match("/^\d+$/", trim($edit['min_rows']))) { |
| 378 | $errors['min_rows'] = t('Minimum rows must be a valid number'); | |
| 379 | } | |
| 380 | ||
| 381 | if ($edit['default'] == 't' && $edit['popup'] == 't') { | |
| 382 | $errors['popup'] = t('If FCKeditor is enabled by default, popup window must be disabled.'); | |
| 383 | } | |
| 384 | ||
| 385 | if ($edit['show_toggle'] == 't' && $edit['popup'] == 't') { | |
| 386 | $errors['popup'] = t('If toggle is enabled, popup window must be disabled.'); | |
| 387 | } | |
| 388 | ||
| 0c87a920 WW |
389 | if (!$edit['name']) { |
| 390 | $errors['name'] = t('You must give a profile name.'); | |
| 391 | } | |
| 392 | ||
| 8de1e54a WW |
393 | if (!preg_match("/^\d+%?$/", $edit['width'])) { |
| 394 | $errors['width'] = t('Enter valid width. Ex: 400 or 100%'); | |
| 395 | } | |
| 396 | ||
| 397 | if (!empty($edit['css_path'])) { | |
| 398 | if ($edit['css_mode'] != 'self') { | |
| 399 | $errors['css_path'] = t('CSS path is not empty. Please set the "Editor CSS" option to "define css" mode.'); | |
| 400 | } | |
| 401 | else if (false !== strpos($edit['css_path'], '"')) { | |
| 402 | $errors['css_path'] = t('Double quotes are not allowed in CSS path.'); | |
| 403 | } | |
| 404 | else if (substr($edit['css_path'], 0, 1) == "'" && substr($edit['css_path'], -1) == "'") { | |
| 405 | $errors['css_path'] = t('Enter valid path, do not surround it with quotes.'); | |
| 406 | } | |
| 407 | } | |
| 408 | ||
| 409 | if (!empty($edit['styles_path'])) { | |
| 410 | if ($edit['css_style'] != 'self') { | |
| 411 | $errors['styles_path'] = t('Path to predefined styles is not empty. Please set the "Predefined styles" option to "define path to fckstyles.xml" mode.'); | |
| 412 | } | |
| 413 | else if (false !== strpos($edit['styles_path'], '"')) { | |
| 414 | $errors['styles_path'] = t('Double quotes are not allowed in path.'); | |
| 415 | } | |
| 416 | else if (substr($edit['styles_path'], 0, 1) == "'" && substr($edit['styles_path'], -1) == "'") { | |
| 417 | $errors['styles_path'] = t('Enter valid path, do not surround it with quotes.'); | |
| 418 | } | |
| 419 | } | |
| 420 | ||
| 421 | if (!empty($edit['font_format'])) { | |
| 422 | if (!preg_match("/^((p|div|pre|address|h1|h2|h3|h4|h5|h6);)*(p|div|pre|address|h1|h2|h3|h4|h5|h6)$/", $edit['font_format'])) { | |
| 423 | $errors['font_format'] = t('Enter valid, semicolon separated, list of HTML font formats (no semicolon at the end of list expected).'); | |
| 424 | } | |
| 425 | } | |
| 426 | ||
| 427 | //validate fields | |
| 428 | $fields = preg_split("/[\s,]+/", strip_tags($edit['excl_fields'])); | |
| 429 | foreach ($fields as $field) { | |
| a2e37d18 | 430 | if ($field && !preg_match("/^[a-z]+(\-[[:alnum:]]+|\\*|\-\\*)+$/i", $field)) { |
| 8de1e54a WW |
431 | $errors['excl_fields'] = t("Invalid field specified: %1", array("%1" => $field)); |
| 432 | break; | |
| 433 | } | |
| 434 | } | |
| 435 | ||
| 436 | $fields = preg_split("/[\s,]+/", strip_tags($edit['simple_incl_fields'])); | |
| 437 | foreach ($fields as $field) { | |
| a2e37d18 | 438 | if ($field && !preg_match("/^[a-z]+(\-[[:alnum:]]+|\\*|\-\\*)+$/i", $field)) { |
| 50caf8cb | 439 | $errors['simple_incl_fields'] = t("Invalid field specified: %1", array("%1" => $field)); |
| 8de1e54a WW |
440 | break; |
| 441 | } | |
| 442 | } | |
| 443 | ||
| 444 | //validate paths | |
| 445 | $paths = preg_split("/[\s,]+/", strip_tags($edit['excl_paths'])); | |
| 446 | foreach ($paths as $path) { | |
| 2b726a41 | 447 | if ($path && !preg_match("|^[_a-z0-9-\*/]*$|i", $path)) { |
| 8de1e54a WW |
448 | $errors['excl_paths'] = t("Invalid path specified: %1", array("%1" => $path)); |
| 449 | break; | |
| 450 | } | |
| 451 | } | |
| 452 | ||
| 453 | $paths = preg_split("/[\s,]+/", strip_tags($edit['simple_incl_paths'])); | |
| 454 | foreach ($paths as $path) { | |
| 2b726a41 | 455 | if ($path && !preg_match("|^[_a-z0-9-\*/]*$|i", $path)) { |
| 50caf8cb | 456 | $errors['simple_incl_paths'] = t("Invalid path specified: %1", array("%1" => $path)); |
| 8de1e54a WW |
457 | break; |
| 458 | } | |
| 459 | } | |
| 460 | ||
| 5b62271f | 461 | if (variable_get('file_downloads', '') !== FILE_DOWNLOADS_PRIVATE) { |
| 0a4de7b0 | 462 | if (!empty($edit['UserFilesAbsolutePath']) && empty($edit['UserFilesPath'])) { |
| 5b62271f WW |
463 | $errors['UserFilesPath'] = t("Path to uploaded files is required."); |
| 464 | } | |
| 0a4de7b0 | 465 | if (!empty($edit['UserFilesPath']) && empty($edit['UserFilesAbsolutePath'])) { |
| 5b62271f WW |
466 | $errors['UserFilesPath'] = t("Absolute path to uploaded files is required."); |
| 467 | } | |
| 0c87a920 WW |
468 | } |
| 469 | ||
| 470 | foreach ($errors as $name => $message) { | |
| 471 | form_set_error($name, $message); | |
| 472 | } | |
| 473 | ||
| 474 | return count($errors) == 0; | |
| ebc6fdec | 475 | } |
| 04b827fa | 476 | |
| 8de1e54a WW |
477 | /** |
| 478 | * Global profile validation. | |
| 479 | */ | |
| 480 | function fckeditor_global_profile_validate($edit) { | |
| 481 | $errors = array(); | |
| 482 | ||
| 09aae5b1 WW |
483 | //include mode and all other fields are empty, invalid |
| 484 | if ($edit['excl_mode'] == 1 && !$edit['excl_fields'] && !$edit['excl_paths']) { | |
| 7e1cf369 | 485 | $errors['excl_mode'] = t('Include mode selected, but no fields/paths given. Enter at least one path or field where FCKeditor should appear.'); |
| 09aae5b1 WW |
486 | } |
| 487 | ||
| 8de1e54a WW |
488 | //validate fields |
| 489 | $fields = preg_split("/[\s,]+/", strip_tags($edit['excl_fields'])); | |
| 490 | foreach ($fields as $field) { | |
| a2e37d18 | 491 | if ($field && !preg_match("/^[a-z]+(\-[[:alnum:]]+|\\*|\-\\*)+$/i", $field)) { |
| 8de1e54a WW |
492 | $errors['excl_fields'] = t("Invalid field specified: %1", array("%1" => $field)); |
| 493 | break; | |
| 494 | } | |
| 495 | } | |
| 496 | ||
| 497 | $fields = preg_split("/[\s,]+/", strip_tags($edit['simple_incl_fields'])); | |
| 498 | foreach ($fields as $field) { | |
| a2e37d18 | 499 | if ($field && !preg_match("/^[a-z]+(\-[[:alnum:]]+|\\*|\-\\*)+$/i", $field)) { |
| 8de1e54a WW |
500 | $errors['excl_fields'] = t("Invalid field specified: %1", array("%1" => $field)); |
| 501 | break; | |
| 502 | } | |
| 503 | } | |
| 504 | ||
| 505 | //validate paths | |
| 506 | $paths = preg_split("/[\s,]+/", strip_tags($edit['excl_paths'])); | |
| 507 | foreach ($paths as $path) { | |
| 2b726a41 | 508 | if ($path && !preg_match("|^[_a-z0-9-\*/]*$|i", $path)) { |
| 8de1e54a WW |
509 | $errors['excl_paths'] = t("Invalid path specified: %1", array("%1" => $path)); |
| 510 | break; | |
| 511 | } | |
| 512 | } | |
| 513 | ||
| 514 | $paths = preg_split("/[\s,]+/", strip_tags($edit['simple_incl_paths'])); | |
| 515 | foreach ($paths as $path) { | |
| 2b726a41 | 516 | if ($path && !preg_match("|^[_a-z0-9-\*/]*$|i", $path)) { |
| 8de1e54a WW |
517 | $errors['excl_paths'] = t("Invalid path specified: %1", array("%1" => $path)); |
| 518 | break; | |
| 519 | } | |
| 520 | } | |
| 521 | ||
| 522 | foreach ($errors as $name => $message) { | |
| 523 | form_set_error($name, $message); | |
| 524 | } | |
| 525 | ||
| 526 | return count($errors) == 0; | |
| 527 | } | |
| 04b827fa DS |
528 | |
| 529 | /** | |
| 0c87a920 WW |
530 | * Controller for FCKeditor administrative settings. |
| 531 | */ | |
| 532 | function fckeditor_admin($arg = NULL) { | |
| 533 | ||
| 8de1e54a WW |
534 | $module_drupal_path = drupal_get_path('module', 'fckeditor'); |
| 535 | $fckconfig_file = $module_drupal_path .'/fckeditor/fckconfig.js'; | |
| 0c87a920 WW |
536 | if (!file_exists($fckconfig_file)) { |
| 537 | drupal_set_message(t('checking for %filename', array('%filename' => $fckconfig_file))); | |
| 538 | drupal_set_message( | |
| 8de1e54a WW |
539 | t('The FCKeditor component is not installed correctly. Please go to the !fckeditorlink to download the latest version. After that you must extract the files to %modulepath and make sure that the directory %modulesubdir and the file %modulefile exist. Refer to the !readme for more information.', |
| 540 | array( | |
| 541 | '!fckeditorlink' => l(t('FCKeditor homepage'), 'http://www.fckeditor.net/download'), | |
| 542 | '!readme' => l('readme.txt', 'admin/help/fckeditor'), | |
| 543 | '%modulepath' => base_path() . $module_drupal_path .'/fckeditor/', | |
| 544 | '%modulesubdir' => base_path() . $module_drupal_path .'/fckeditor/editor', | |
| 545 | '%modulefile' => base_path() . $module_drupal_path .'/fckeditor/fckeditor.js')), | |
| 546 | 'error'); | |
| cc67ac84 | 547 | return FALSE; |
| 0c87a920 WW |
548 | } |
| 549 | ||
| 550 | $edit = $_POST; | |
| 8de1e54a | 551 | $op = isset($_POST['op']) ? $_POST['op'] : ""; |
| 0c87a920 WW |
552 | |
| 553 | $op = $arg && !$op ? $arg : $op; | |
| 554 | ||
| 555 | switch ($op) { | |
| 556 | case 'add': | |
| 0c87a920 WW |
557 | $output = fckeditor_profile_form($edit); |
| 558 | break; | |
| 559 | ||
| 8de1e54a WW |
560 | case 'addg': |
| 561 | $output = fckeditor_global_profile_form($edit); | |
| 562 | break; | |
| 563 | ||
| 0c87a920 WW |
564 | case 'edit': |
| 565 | drupal_set_title(t('Edit FCKeditor profile')); | |
| 566 | $output = fckeditor_profile_form(fckeditor_profile_load(urldecode(arg(4)))); | |
| 567 | break; | |
| 568 | ||
| 8de1e54a WW |
569 | case 'editg': |
| 570 | drupal_set_title(t('Edit FCKeditor profile')); | |
| 571 | $output = fckeditor_global_profile_form(fckeditor_profile_load("FCKeditor Global Profile")); | |
| 572 | break; | |
| 573 | ||
| cc0fc71b | 574 | case 'deleteg': |
| cc67ac84 | 575 | $output = fckeditor_ask_delete_confirmation(TRUE); |
| cc0fc71b WW |
576 | break; |
| 577 | ||
| 0c87a920 | 578 | case 'delete': |
| cc67ac84 | 579 | $output = fckeditor_ask_delete_confirmation(FALSE, urldecode(arg(4))); |
| cc0fc71b WW |
580 | break; |
| 581 | ||
| 582 | case 'deleteconfirmed': | |
| 0c87a920 WW |
583 | fckeditor_profile_delete(urldecode(arg(4))); |
| 584 | drupal_set_message(t('Deleted profile')); | |
| 585 | drupal_goto('admin/settings/fckeditor'); | |
| 586 | break; | |
| 587 | ||
| cc0fc71b | 588 | case 'deletegconfirmed': |
| 8de1e54a WW |
589 | fckeditor_profile_delete("FCKeditor Global Profile"); |
| 590 | drupal_set_message(t('Deleted Global profile')); | |
| 591 | drupal_goto('admin/settings/fckeditor'); | |
| 592 | break; | |
| 593 | ||
| 0c87a920 WW |
594 | case t('Create profile'); |
| 595 | case t('Update profile'); | |
| 596 | if (fckeditor_profile_validate($edit)) { | |
| 597 | fckeditor_profile_save($edit); | |
| d7fbc905 | 598 | !empty($edit['old_name']) ? drupal_set_message(t('Your FCKeditor profile has been updated.')) : drupal_set_message(t('Your FCKeditor profile has been created.')); |
| 0c87a920 WW |
599 | drupal_goto('admin/settings/fckeditor'); |
| 600 | } | |
| 601 | else { | |
| 602 | $output = fckeditor_profile_form($edit); | |
| 603 | } | |
| 604 | break; | |
| 605 | ||
| 8de1e54a WW |
606 | case t('Create global profile'); |
| 607 | case t('Update global profile'); | |
| 608 | if (fckeditor_global_profile_validate($edit)) { | |
| 609 | $edit['name'] = 'FCKeditor Global Profile'; | |
| 610 | fckeditor_global_profile_save($edit); | |
| 611 | drupal_set_message(t('FCKeditor global profile has been saved.')); | |
| 612 | drupal_goto('admin/settings/fckeditor'); | |
| 613 | } | |
| 614 | else { | |
| 615 | $output = fckeditor_global_profile_form($edit); | |
| 616 | } | |
| 617 | break; | |
| 618 | ||
| 0c87a920 WW |
619 | default: |
| 620 | drupal_set_title(t('FCKeditor settings')); | |
| 621 | //Check if FCKeditor is installed. | |
| 622 | $fckeditor_loc = drupal_get_path('module', 'fckeditor') .'/fckeditor/'; | |
| 623 | if (!is_dir($fckeditor_loc)) { | |
| 8de1e54a | 624 | drupal_set_message(t('Could not find the FCKeditor engine installed at <strong>!fckeditor-directory</strong>. Please !download, uncompress it and copy the folder into !fckeditor-path.', array('!fckeditor-path' => drupal_get_path('module', 'fckeditor'), '!fckeditor-directory' => $fckeditor_loc, '!download' => l(t("download FCKeditor"), "http://www.fckeditor.net/download"))), 'error'); |
| 0c87a920 | 625 | } |
| 1ecd439a WW |
626 | |
| 627 | $access_fckeditor_roles = user_roles(FALSE, 'access fckeditor'); | |
| 628 | if (!$access_fckeditor_roles) { | |
| 629 | drupal_set_message(t('There is currently no role with the <strong>!access</strong> permission. Visit !acl administration section.', | |
| 630 | array("!access" => t("access fckeditor"), "!acl" => l(t("Permissions"), "admin/user/permissions"))), "warning"); | |
| 631 | } | |
| 632 | else { | |
| 633 | $result = db_query_range("SELECT name FROM {fckeditor_settings} WHERE name<>'FCKeditor Global Profile'", 0, 1); | |
| cc67ac84 | 634 | $has_profiles = FALSE; |
| 1ecd439a WW |
635 | //find profile other than Global |
| 636 | if ($obj = db_fetch_object($result)) { | |
| cc67ac84 | 637 | $has_profiles = TRUE; |
| 1ecd439a WW |
638 | } |
| 639 | ||
| 640 | //find roles with profiles | |
| 641 | $result = db_query("SELECT rid FROM {fckeditor_role}"); | |
| 642 | $rids = array(); | |
| 643 | while ($obj = db_fetch_object($result)) { | |
| 644 | $rids[] = $obj->rid; | |
| 645 | } | |
| 646 | $rids = array_unique($rids); | |
| 647 | if (!$has_profiles) { | |
| 648 | drupal_set_message(t("No FCKeditor profiles found. At this moment, nobody is able to use FCKeditor. Create new profile below."), "error"); | |
| 649 | } | |
| 650 | else { | |
| 651 | //not all roles with access fckeditor has their FCKeditor profile assigned | |
| 652 | $diff = array_diff(array_keys($access_fckeditor_roles), $rids); | |
| 653 | if ($diff) { | |
| 654 | $list = "<ul>"; | |
| 655 | foreach ($diff as $rid) { | |
| 656 | $list .= "<li>". $access_fckeditor_roles[$rid] ."</li>"; | |
| 657 | } | |
| 658 | $list .= "</ul>"; | |
| 659 | drupal_set_message(t("Not all roles with <strong>!access</strong> permission are associated with FCKeditor profiles. As a result, users having the following roles may be unable to use FCKeditor: !list Create new or edit FCKeditor profiles below and in the <strong>Basic setup</strong> section, check "Roles allowed to use this profile".", array("!access" => l(t("access fckeditor"), "admin/user/permissions"), "!list" => $list)), "warning"); | |
| 660 | } | |
| 661 | } | |
| 662 | } | |
| 663 | ||
| 0c87a920 WW |
664 | $output = fckeditor_profile_overview(); |
| 665 | } | |
| 666 | ||
| 667 | return $output; | |
| 668 | } | |
| 669 | ||
| 670 | /** | |
| 671 | * Save a profile to the database. | |
| 672 | * @todo add more entries to array in the user_save line | |
| 673 | */ | |
| 674 | function fckeditor_profile_save($edit) { | |
| d7fbc905 WW |
675 | db_query("DELETE FROM {fckeditor_settings} WHERE name = '%s' or name = '%s'", $edit['name'], empty($edit['old_name']) ? "" : $edit['old_name']); |
| 676 | db_query("DELETE FROM {fckeditor_role} WHERE name = '%s' or name = '%s'", $edit['name'], empty($edit['old_name']) ? "" : $edit['old_name']); | |
| 0c87a920 | 677 | db_query("INSERT INTO {fckeditor_settings} (name, settings) VALUES ('%s', '%s')", $edit['name'], serialize($edit)); |
| d7fbc905 | 678 | if (!empty($edit['rids'])) |
| 0c87a920 WW |
679 | foreach ($edit['rids'] as $rid => $value) { |
| 680 | db_query("INSERT INTO {fckeditor_role} (name, rid) VALUES ('%s', %d)", $edit['name'], $rid); | |
| 681 | } | |
| 682 | ||
| 683 | // if users can't set their own defaults, make sure to remove $user->fckeditor_status so their default doesn't override the main default | |
| d7fbc905 | 684 | if (!empty($edit['user_choose']) && $edit['user_choose'] == 'false') { |
| 0c87a920 WW |
685 | global $user; |
| 686 | user_save($user, array('fckeditor_status' => NULL)); | |
| 687 | } | |
| 688 | } | |
| 689 | ||
| 8de1e54a WW |
690 | function fckeditor_global_profile_save($edit) { |
| 691 | if (isset($edit['rank'])) { | |
| 692 | $edit['rank'] = explode('>', str_replace(' ', '', $edit['rank'])); | |
| 693 | } | |
| 694 | ||
| d7fbc905 WW |
695 | db_query("DELETE FROM {fckeditor_settings} WHERE name = '%s' or name = '%s'", $edit['name'], empty($edit['old_name']) ? "" : $edit['old_name']); |
| 696 | db_query("DELETE FROM {fckeditor_role} WHERE name = '%s' or name = '%s'", $edit['name'], empty($edit['old_name']) ? "" : $edit['old_name']); | |
| 8de1e54a WW |
697 | db_query("INSERT INTO {fckeditor_settings} (name, settings) VALUES ('%s', '%s')", $edit['name'], serialize($edit)); |
| 698 | } | |
| 699 | ||
| 0c87a920 WW |
700 | /** |
| 701 | * Controller for fckeditor profiles. | |
| 702 | */ | |
| 703 | function fckeditor_profile_overview() { | |
| 704 | $output = ''; | |
| 705 | ||
| 706 | $profiles = fckeditor_profile_load(); | |
| 707 | if ($profiles) { | |
| 708 | $roles = user_roles(); | |
| 1ecd439a | 709 | $access_fckeditor_roles = user_roles(FALSE, 'access fckeditor'); |
| 0c87a920 WW |
710 | $header = array(t('Profile'), t('Roles'), t('Operations')); |
| 711 | foreach ($profiles as $p) { | |
| 1ecd439a | 712 | $rids = $p->rids; |
| 8de1e54a | 713 | if ($p->name !== "FCKeditor Global Profile") { |
| 1ecd439a WW |
714 | foreach ($p->rids as $rid => $name) { |
| 715 | if (!isset($access_fckeditor_roles[$rid])) { | |
| 716 | unset($rids[$rid]); | |
| 717 | } | |
| 718 | } | |
| 719 | $rows[] = array(array('data' => $p->name, 'valign' => 'top'), array('data' => implode("<br />\n", $rids)), array('data' => l(t('edit'), 'admin/settings/fckeditor/edit/'. urlencode($p->name)) .' '. l(t('delete'), 'admin/settings/fckeditor/delete/'. urlencode($p->name)), 'valign' => 'top')); | |
| 8de1e54a | 720 | } |
| 0c87a920 | 721 | } |
| 8de1e54a | 722 | $output .= "<h3>". t("Profiles") ."</h3>"; |
| 0c87a920 | 723 | $output .= theme('table', $header, $rows); |
| 8de1e54a | 724 | $output .= '<p>'. l(t('Create new profile'), 'admin/settings/fckeditor/add') .'</p>'; |
| 0c87a920 WW |
725 | } |
| 726 | else { | |
| 8de1e54a WW |
727 | drupal_set_message(t('No profiles found. Click here to !create.', array('!create' => l(t("create a new profile"), 'admin/settings/fckeditor/add')))); |
| 728 | } | |
| 729 | ||
| 730 | $rows = array(); | |
| 731 | if (!isset($profiles['FCKeditor Global Profile'])) { | |
| 732 | drupal_set_message(t('Global Profile not found. Click here to !create.', array('!create' => l(t("create the global profile"), 'admin/settings/fckeditor/addg')))); | |
| 733 | } | |
| 734 | else { | |
| 735 | $output .= "<h3>". t("Global Settings") ."</h3>"; | |
| 736 | $rows[] = array(array('data' => t('FCKeditor Global Profile'), 'valign' => 'top'), array('data' => l(t('edit'), 'admin/settings/fckeditor/editg') ." ". l(t('delete'), 'admin/settings/fckeditor/deleteg'), 'valign' => 'top')); | |
| 737 | $output .= theme('table', array(t('Profile'), t('Operations')), $rows); | |
| 0c87a920 WW |
738 | } |
| 739 | ||
| 740 | return $output; | |
| 741 | } | |
| 742 | ||
| 743 | /** | |
| 744 | * Load all profiles. Just load one profile if $name is passed in. | |
| 745 | */ | |
| 746 | function fckeditor_profile_load($name = '') { | |
| 747 | static $profiles = array(); | |
| 748 | ||
| 749 | if (!$profiles) { | |
| 750 | $roles = user_roles(); | |
| 751 | $result = db_query('SELECT * FROM {fckeditor_settings}'); | |
| 752 | while ($data = db_fetch_object($result)) { | |
| 753 | $data->settings = unserialize($data->settings); | |
| 754 | $result2 = db_query("SELECT rid FROM {fckeditor_role} WHERE name = '%s'", $data->name); | |
| 755 | $role = array(); | |
| 756 | while ($r = db_fetch_object($result2)) { | |
| 757 | $role[$r->rid] = $roles[$r->rid]; | |
| 758 | } | |
| 759 | $data->rids = $role; | |
| 760 | ||
| 761 | $profiles[$data->name] = $data; | |
| 762 | } | |
| 763 | } | |
| 764 | ||
| 765 | return ($name ? $profiles[$name] : $profiles); | |
| 766 | } | |
| 767 | ||
| 8de1e54a WW |
768 | /** |
| 769 | * @param int $excl_mode 1/include, exclude otherwise | |
| 770 | * @param string $excl_fields fields (HTML IDs) | |
| 771 | * @param string $excl_paths paths (drupal paths) | |
| 772 | * @param string $element_id current ID | |
| 773 | * @param string $get_q current path | |
| 774 | * | |
| 775 | * @return boolean | |
| 776 | * returns true if FCKeditor is enabled | |
| 777 | */ | |
| 778 | function fckeditor_is_enabled($excl_mode, $excl_fields, $excl_paths, $element_id, $get_q) { | |
| 779 | $arr_excl_fields = preg_split("/[\s,]+/", strip_tags($excl_fields)); | |
| 780 | $field_found = fckeditor_idsearch($element_id, $arr_excl_fields); | |
| 781 | ||
| 782 | $path = drupal_get_path_alias($get_q); | |
| 783 | $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($excl_paths, '/')) .')$/'; | |
| 784 | $path_found = preg_match($regexp, $path); | |
| 0c87a920 | 785 | |
| 8de1e54a | 786 | $found = $field_found || $path_found; |
| 0c87a920 | 787 | |
| 8de1e54a WW |
788 | $result = ($excl_mode == 1) ? $found : !$found; |
| 789 | return $result; | |
| 0c87a920 WW |
790 | } |
| 791 | ||
| 792 | /** | |
| 9286dec5 | 793 | * This function create the HTML objects required for the FCKeditor |
| e44c2389 | 794 | * |
| 795 | * @param $element | |
| 796 | * A fully populated form elment to add the editor to | |
| 797 | * @return | |
| 798 | * The same $element with extra FCKeditor markup and initialization | |
| 04b827fa | 799 | */ |
| f3d88ca0 | 800 | function fckeditor_process_textarea($element) { |
| 0c87a920 WW |
801 | static $is_running = FALSE; |
| 802 | static $num = 1; | |
| 79a1deba WW |
803 | static $id2id = array(); |
| 804 | static $processed_elements = array(); | |
| c3f50453 | 805 | global $user, $fckeditor_simple_toolbar_ids, $_fckeditor_configuration, $_fckeditor_js_ids; |
| f3d88ca0 | 806 | |
| 79a1deba WW |
807 | $processed = in_array($element['#id'], $processed_elements); |
| 808 | ||
| 052a729e | 809 | //hack for module developers that want to disable FCKeditor on their textareas |
| 4dc52146 | 810 | if (key_exists('#wysiwyg', $element) && !$element['#wysiwyg']) { |
| 052a729e WW |
811 | return $element; |
| 812 | } | |
| 813 | ||
| 0c87a920 WW |
814 | //skip this one, surely nobody wants WYSIWYG here |
| 815 | switch ($element['#id']) { | |
| 816 | case 'edit-excl-list': | |
| 817 | case 'edit-simple-incl-list': | |
| 8de1e54a WW |
818 | case 'edit-simple-incl-paths': |
| 819 | case 'edit-simple-incl-fields': | |
| 0c87a920 | 820 | case 'edit-log': |
| 8de1e54a WW |
821 | case 'edit-excl-fields': |
| 822 | case 'edit-excl-paths': | |
| 823 | case 'edit-js-conf': | |
| ce3861a6 | 824 | case 'edit-teaser-js': |
| 0c87a920 WW |
825 | return $element; |
| 826 | break; | |
| 827 | } | |
| ce3861a6 | 828 | |
| 0c87a920 | 829 | if (isset($element['#attributes']['disabled']) && $element['#attributes']['disabled'] == 'disabled') { |
| 8de1e54a WW |
830 | return $element; |
| 831 | } | |
| d3cf16a0 | 832 | |
| 8bdf4d22 WW |
833 | $profile = fckeditor_user_get_profile($user); |
| 834 | if (!$profile) { | |
| 835 | return $element; | |
| 0c87a920 WW |
836 | } |
| 837 | ||
| 0c87a920 WW |
838 | $conf = array(); |
| 839 | $conf = $profile->settings; | |
| 840 | ||
| 8de1e54a WW |
841 | if ($conf['allow_user_conf']=='t') { |
| 842 | foreach (array('default', 'show_toggle', 'popup', 'skin', 'toolbar', 'expand', 'width', 'lang', 'auto_lang') as $setting) { | |
| 0c87a920 WW |
843 | $conf[$setting] = fckeditor_user_get_setting($user, $profile, $setting); |
| 844 | } | |
| 845 | } | |
| 846 | if ($conf["popup"]=="t" && $conf["show_toggle"]=="t") { | |
| 847 | $conf["show_toggle"]="f"; | |
| 848 | } | |
| 849 | ||
| dedd64a9 WW |
850 | //old profile info, assume Filtered HTML is enabled |
| 851 | if (!isset($conf['ss'])) { | |
| 852 | $conf['ss'] = 2; | |
| 853 | $conf['filters']['filter/0'] = 1; | |
| 854 | } | |
| 855 | if (!isset($conf['filters'])) { | |
| 856 | $conf['filters'] = array(); | |
| 857 | } | |
| 858 | ||
| 8de1e54a | 859 | $themepath = path_to_theme() .'/'; |
| 0c87a920 WW |
860 | $host = base_path(); |
| 861 | ||
| e9a59651 | 862 | $enabled = fckeditor_is_enabled(empty($conf['excl_mode']) ? "" : $conf['excl_mode'], empty($conf['excl_fields']) ? "" : $conf['excl_fields'], empty($conf['excl_paths']) ? "" : $conf['excl_paths'], $element['#id'], $_GET['q']); |
| 8de1e54a WW |
863 | if ($enabled) { |
| 864 | $global_profile = fckeditor_profile_load("FCKeditor Global Profile"); | |
| 865 | $global_conf = $global_profile->settings; | |
| 866 | if ($global_conf) { | |
| e9a59651 | 867 | $enabled = fckeditor_is_enabled(empty($global_conf['excl_mode']) ? "" : $global_conf['excl_mode'], empty($global_conf['excl_fields']) ? "" : $global_conf['excl_fields'], empty($global_conf['excl_paths']) ? "" : $global_conf['excl_paths'], $element['#id'], $_GET['q']); |
| 8de1e54a WW |
868 | } |
| 869 | } | |
| 3a55ac1f WW |
870 | if (!isset($element['#suffix'])) { |
| 871 | $element['#suffix'] = ""; | |
| 872 | } | |
| 0c87a920 | 873 | |
| b5eff96f | 874 | if ((($element['#rows'] > $conf['min_rows']) || ($conf['min_rows'] <= 1 && empty($element['#rows']))) && $enabled) { |
| 0c87a920 | 875 | // only replace textarea when it has enough rows and it is enabled |
| 0c87a920 | 876 | |
| e6589905 WW |
877 | // Set resizable to false to avoid drupal.js resizable function from taking control of the textarea |
| 878 | if ($conf["popup"]=="f") { | |
| 879 | $element['#resizable'] = FALSE; | |
| 880 | } | |
| d3cf16a0 | 881 | |
| 79a1deba WW |
882 | if (in_array($element['#id'], $processed_elements)) { |
| 883 | $js_id = $id2id[$element['#id']]; | |
| 884 | } | |
| 885 | else { | |
| 886 | $js_id = 'oFCK_'. $num++; | |
| 887 | $id2id[$element['#id']] = $js_id; | |
| 888 | } | |
| 8de1e54a WW |
889 | $fckeditor_on = ($conf['default']=='t') ? 1 : 0 ; |
| 890 | ||
| dedd64a9 WW |
891 | $xss_check = 0; |
| 892 | //it's not a problem when adding new content/comment | |
| 893 | if (arg(1) != "add" && arg(1) != "reply") { | |
| c3f50453 | 894 | $_fckeditor_configuration[$element['#id']] = $conf; |
| dedd64a9 WW |
895 | |
| 896 | //let FCKeditor know when perform XSS checks auto/manual | |
| 897 | if ($conf['ss'] == 1) { | |
| 898 | $xss_class = 'checkxss1'; | |
| 899 | } | |
| 900 | else { | |
| 901 | $xss_class = 'checkxss2'; | |
| 902 | } | |
| 903 | ||
| 904 | if (!isset($element['#attributes']['class'])) { | |
| 905 | $element['#attributes']['class'] = ''; | |
| 906 | } | |
| 907 | ||
| 908 | $element['#attributes']['class'] .= ' '. $xss_class; | |
| 909 | $xss_check = 1; | |
| 910 | } | |
| 911 | ||
| 62a6dbd0 WW |
912 | $content = ""; |
| 913 | if (isset($element['#post']['teaser_js'])) { | |
| 7e1cf369 | 914 | $content .= $element['#post']['teaser_js'] ."<!--break-->"; |
| 62a6dbd0 WW |
915 | } |
| 916 | $content .= $element['#value']; | |
| 917 | $wysiwyg_link = "<div id=\"fck_{$js_id}\"><textarea id=\"{$js_id}\">". htmlspecialchars($content) ."</textarea></div>\n"; | |
| dedd64a9 | 918 | $wysiwyg_link .= "<a href=\"javascript:Toggle('{$js_id}','{$element['#id']}','". str_replace("'", "\\'", t("Switch to plain text editor")) ."','". str_replace("'", "\\'", t("Switch to rich text editor")) ."',". $xss_check .");\" id=\"switch_{$js_id}\" ". ($fckeditor_on?"style=\"display:none\"":"") .">"; |
| 8de1e54a | 919 | $wysiwyg_link .= $fckeditor_on ? t("Switch to plain text editor") : t("Switch to rich text editor"); |
| 0c87a920 | 920 | $wysiwyg_link .= "</a>"; |
| 79a1deba | 921 | if ($conf['show_toggle'] == 't' && !$processed) { |
| c3f50453 | 922 | drupal_add_js('if (Drupal.jsEnabled) {$(document).ready(function() {CreateToggle("'. $element['#id'] .'","'. $js_id .'", '. $fckeditor_on .');});}', 'inline'); |
| 5d7a6961 | 923 | } |
| 0c87a920 | 924 | //settings are saved as strings, not booleans |
| 5d7a6961 | 925 | if ($conf['show_toggle'] == 't') { |
| 0c87a920 WW |
926 | // Make sure to append to #suffix so it isn't completely overwritten |
| 927 | $element['#suffix'] .= $wysiwyg_link; | |
| 928 | } | |
| f3d88ca0 | 929 | // setting some variables |
| 8de1e54a | 930 | $module_drupal_path = drupal_get_path('module', 'fckeditor'); |
| d3cf16a0 | 931 | $module_full_path = $host . $module_drupal_path; |
| e2610d9c | 932 | // get the default drupal files path |
| d3cf16a0 | 933 | $files_path = $host . file_directory_path(); |
| 0c87a920 WW |
934 | // module_drupal_path: |
| 935 | // 'modules/fckeditor' (length=17) | |
| 936 | // module_full_path: | |
| 937 | // '/drupal5/modules/fckeditor' (length=26) | |
| 938 | // files_path: | |
| 939 | // '/drupal5/files' (length=14) | |
| f3d88ca0 | 940 | // configured in settings |
| 0c87a920 | 941 | $width = $conf['width']; |
| f3d88ca0 | 942 | |
| 943 | // sensible default for small toolbars | |
| 0c87a920 | 944 | $height = $element['#rows'] * 14 + 140; |
| f3d88ca0 | 945 | |
| 0c87a920 | 946 | if (!$is_running) { |
| 8de1e54a | 947 | drupal_add_js($module_drupal_path .'/fckeditor/fckeditor.js'); |
| 2d2ff83b | 948 | drupal_add_js($module_drupal_path .'/fckeditor.utils.js'); |
| cc67ac84 | 949 | $is_running = TRUE; |
| e44c2389 | 950 | } |
| 0c87a920 WW |
951 | |
| 952 | $toolbar = $conf['toolbar']; | |
| 953 | //$height += 100; // for larger toolbars | |
| 954 | ||
| e9a59651 | 955 | $force_simple_toolbar = fckeditor_is_enabled(1, empty($conf['simple_incl_fields']) ? "" : $conf['simple_incl_fields'], empty($conf['simple_incl_paths']) ? "" : $conf['simple_incl_paths'], $element['#id'], $_GET['q']); |
| 8de1e54a | 956 | if (!$force_simple_toolbar) { |
| e9a59651 | 957 | $force_simple_toolbar = fckeditor_is_enabled(1, empty($global_conf['simple_incl_fields']) ? "" : $global_conf['simple_incl_fields'], empty($global_conf['simple_incl_paths']) ? "" : $global_conf['simple_incl_paths'], $element['#id'], $_GET['q']); |
| 8de1e54a WW |
958 | } |
| 959 | if ($force_simple_toolbar) { | |
| 0c87a920 | 960 | $toolbar = FCKEDITOR_FORCE_SIMPLE_TOOLBAR_NAME; |
| f3d88ca0 | 961 | } |
| 5d7a6961 | 962 | $textarea_id = $conf['show_toggle'] == 't' ? $js_id : $element['#id']; |
| 4da0d34e | 963 | $_fckeditor_js_ids[$element['#id']] = $textarea_id; |
| bb840a2a | 964 | $js = $js_id ." = new FCKeditor( '". $textarea_id ."' ); |
| 8de1e54a | 965 | ". $js_id .".BasePath = '". $module_full_path ."/fckeditor/'; |
| cb02e2d0 | 966 | ". $js_id .".Config['CustomConfigurationsPath'] = \"". $module_full_path ."/fckeditor.config.js?". @filemtime($module_drupal_path ."/fckeditor.config.js") ."\"; |
| 8de1e54a | 967 | ". $js_id .".Config['TextareaID'] = \"". $element['#id'] ."\";"; |
| 0c87a920 WW |
968 | |
| 969 | //if ($conf['appearance_conf'] == 'f') { | |
| bb840a2a | 970 | $js .= "\n". $js_id .".ToolbarSet = \"". $toolbar ."\"; |
| 8de1e54a WW |
971 | ". $js_id .".Config['SkinPath'] = ". $js_id .".BasePath + \"editor/skins/". $conf['skin'] ."/\"; |
| 972 | ". $js_id .".Config['DefaultLanguage'] = \"". $conf['lang'] ."\"; | |
| 973 | ". $js_id .".Config['AutoDetectLanguage'] = ". ($conf['auto_lang']=="t"?"true":"false") ."; | |
| 974 | ". $js_id .".Height = \"". $height ."\"; | |
| 975 | ". $js_id .".Config['ToolbarStartExpanded'] = ". ($conf['expand']=="t"?"true":"false") ."; | |
| 976 | ". $js_id .".Width = \"". $width ."\";\n"; | |
| 0c87a920 WW |
977 | //} |
| 978 | //if ($conf['output_conf'] == 'f') { | |
| bb840a2a | 979 | $js .= "\n". $js_id .".Config['EnterMode'] = '". $conf['enter_mode'] ."'; |
| 8de1e54a WW |
980 | ". $js_id .".Config['ShiftEnterMode'] = \"". $conf['shift_enter_mode'] ."\"; |
| 981 | ". $js_id .".Config['FontFormats'] = \"". str_replace(",", ";", $conf['font_format']) ."\"; | |
| 982 | ". $js_id .".Config['FormatSource'] = ". ($conf['format_source']=="t"?"true":"false") ."; | |
| 983 | ". $js_id .".Config['FormatOutput'] = ". ($conf['format_output']=="t"?"true":"false") .";\n"; | |
| 0c87a920 | 984 | //} |
| 0a4de7b0 | 985 | |
| 924d15ba | 986 | if (function_exists('img_assist_perm')) { //#275158 |
| bb840a2a | 987 | drupal_add_js("var fckImgAssistPath = '". base_path() . drupal_get_path('module', 'img_assist') ."';", 'inline'); |
| 924d15ba | 988 | } |
| e44c2389 | 989 | // add code for filebrowser for users that have access |
| 0c87a920 | 990 | if (user_access('allow fckeditor file uploads')==1) { |
| dedd64a9 | 991 | $filebrowser = !empty($conf['filebrowser']) ? $conf['filebrowser'] : 'none'; |
| 924d15ba WW |
992 | if ($filebrowser == 'imce' && !module_exists('imce')) { |
| 993 | $filebrowser = 'none'; | |
| 0c87a920 | 994 | } |
| 025a3cca WW |
995 | if ($filebrowser == 'ib' && !module_exists('imagebrowser')) { |
| 996 | $filebrowser = 'none'; | |
| 997 | } | |
| dedd64a9 | 998 | $quickupload = (!empty($conf['quickupload']) && $conf['quickupload'] == 't'); |
| 924d15ba WW |
999 | |
| 1000 | // load variables used by both quick upload and filebrowser | |
| 1001 | // and assure that the $_SESSION variables are loaded | |
| 1002 | if ($quickupload || $filebrowser == 'builtin') { | |
| 5ec02696 WW |
1003 | |
| 1004 | $connector_path = $module_drupal_path ."/fckeditor/editor/filemanager/connectors/php/connector.php"; | |
| 1005 | if (file_exists($connector_path)) { | |
| 1006 | //FCKeditor 2.5 and above | |
| 1007 | $connector_path = $module_full_path ."/fckeditor/editor/filemanager/connectors/php/connector.php"; | |
| 1008 | } | |
| 1009 | else { | |
| 1010 | //FCKeditor 2.4.3- | |
| 1011 | $connector_path = "connectors/php/connector.php"; | |
| 1012 | } | |
| 1013 | $upload_path = $module_drupal_path ."/fckeditor/editor/filemanager/connectors/php/upload.php"; | |
| 1014 | if (file_exists($upload_path)) { | |
| 1015 | //FCKeditor 2.5 and above | |
| 1016 | $upload_path = $module_full_path ."/fckeditor/editor/filemanager/connectors/php/upload.php"; | |
| 1017 | } | |
| 1018 | else { | |
| 1019 | //FCKeditor 2.4.3- | |
| 1020 | $upload_path = "/fckeditor/editor/filemanager/upload/php/upload.php"; | |
| 1021 | } | |
| 1022 | ||
| e9a59651 WW |
1023 | if (!empty($profile->settings['UserFilesPath'])) $_SESSION['FCKeditor']['UserFilesPath'] = strtr($profile->settings['UserFilesPath'], array("%f" => file_directory_path(), "%u" => $user->uid, "%b" => $host)); |
| 1024 | if (!empty($profile->settings['UserFilesAbsolutePath'])) $_SESSION['FCKeditor']['UserFilesAbsolutePath'] = strtr($profile->settings['UserFilesAbsolutePath'], array("%f" => file_directory_path(), "%u" => $user->uid, "%b" => base_path(), "%d" => $_SERVER['DOCUMENT_ROOT'])); | |
| 5b62271f | 1025 | if (variable_get('file_downloads', '') == FILE_DOWNLOADS_PRIVATE) { |
| 8c659c8f WW |
1026 | $private_dir = trim(isset($global_profile->settings['private_dir']) ? $global_profile->settings['private_dir'] : "", "/\\"); |
| 1027 | if (strlen($private_dir)) { | |
| 1028 | $_SESSION['FCKeditor']['UserFilesPath'] = url('system/files') .'/'. $private_dir .'/'; | |
| 1029 | $_SESSION['FCKeditor']['UserFilesAbsolutePath'] = realpath(file_directory_path()) . DIRECTORY_SEPARATOR . $private_dir . DIRECTORY_SEPARATOR; | |
| 1030 | } | |
| 1031 | else { | |
| 1032 | $_SESSION['FCKeditor']['UserFilesPath'] = url('system/files') .'/'; | |
| 1033 | $_SESSION['FCKeditor']['UserFilesAbsolutePath'] = realpath(file_directory_path()) . DIRECTORY_SEPARATOR; | |
| 1034 | } | |
| 5b62271f | 1035 | } |
| 0c87a920 | 1036 | } |
| 924d15ba WW |
1037 | |
| 1038 | if ($quickupload) { | |
| bb840a2a WW |
1039 | $js .= $js_id .".Config['LinkUpload'] = true;\n"; |
| 1040 | $js .= $js_id .".Config['ImageUpload'] = true;\n"; | |
| 1041 | $js .= $js_id .".Config['FlashUpload'] = true;\n"; | |
| 5ec02696 WW |
1042 | $js .= $js_id .".Config['LinkUploadURL'] = '". $upload_path ."';\n"; |
| 1043 | $js .= $js_id .".Config['ImageUploadURL'] = '". $upload_path ."?Type=Image';\n"; | |
| 1044 | $js .= $js_id .".Config['FlashUploadURL'] = '". $upload_path ."?Type=Flash';\n"; | |
| cc67ac84 WW |
1045 | } |
| 1046 | else { | |
| bb840a2a WW |
1047 | $js .= $js_id .".Config['LinkUpload'] = false;\n"; |
| 1048 | $js .= $js_id .".Config['ImageUpload'] = false;\n"; | |
| 1049 | $js .= $js_id .".Config['FlashUpload'] = false;\n"; | |
| 924d15ba WW |
1050 | } |
| 1051 | ||
| cc67ac84 | 1052 | switch ($filebrowser) { |
| 924d15ba | 1053 | case 'imce': |
| bb840a2a WW |
1054 | $js .= $js_id .".Config['LinkBrowser']= true;\n"; |
| 1055 | $js .= $js_id .".Config['ImageBrowser']= true;\n"; | |
| 1056 | $js .= $js_id .".Config['FlashBrowser']= true;\n"; | |
| 1057 | $js .= $js_id .".Config['LinkBrowserURL']= '". $host ."?q=imce&app=FCKEditor|url@txtUrl';\n"; | |
| 1058 | $js .= $js_id .".Config['ImageBrowserURL']= '". $host ."?q=imce&app=FCKEditor|url@txtUrl|width@txtWidth|height@txtHeight';\n"; | |
| 1059 | $js .= $js_id .".Config['FlashBrowserURL']= '". $host ."?q=imce&app=FCKEditor|url@txtUrl';\n"; | |
| 924d15ba WW |
1060 | break; |
| 1061 | case 'builtin': | |
| bb840a2a WW |
1062 | $js .= $js_id .".Config['LinkBrowser'] = true;\n"; |
| 1063 | $js .= $js_id .".Config['ImageBrowser'] = true;\n"; | |
| 1064 | $js .= $js_id .".Config['FlashBrowser'] = true;\n"; | |
| 1065 | $js .= $js_id .".Config['LinkBrowserURL'] = '". $module_full_path ."/fckeditor/editor/filemanager/browser/default/browser.html?Connector=". $connector_path ."&ServerPath=". $files_path ."';\n"; | |
| 1066 | $js .= $js_id .".Config['ImageBrowserURL'] = '". $module_full_path ."/fckeditor/editor/filemanager/browser/default/browser.html?Type=Image&Connector=". $connector_path ."&ServerPath=". $files_path ."';\n"; | |
| 1067 | $js .= $js_id .".Config['FlashBrowserURL'] = '". $module_full_path ."/fckeditor/editor/filemanager/browser/default/browser.html?Type=Flash&Connector=". $connector_path ."&ServerPath=". $files_path ."';\n"; | |
| 924d15ba | 1068 | break; |
| cc735e40 WW |
1069 | case 'ib': |
| 1070 | $js .= $js_id .".Config['ImageBrowser']= true;\n"; | |
| 1071 | $js .= $js_id .".Config['LinkBrowser']= true;\n"; | |
| 1072 | $js .= $js_id .".Config['FlashBrowser']= false;\n"; | |
| 1073 | $js .= $js_id .".Config['ImageBrowserURL']= '". $host ."?q=imagebrowser/view/browser&app=FCKEditor';\n"; | |
| 1074 | $js .= $js_id .".Config['LinkBrowserURL']= '". $host ."?q=imagebrowser/view/browser&app=FCKEditor';\n"; | |
| 1075 | $js .= $js_id .".Config['ImageBrowserWindowWidth']= '680';"; | |
| 1076 | $js .= $js_id .".Config['ImageBrowserWindowHeight'] = '439';"; | |
| 1077 | $js .= $js_id .".Config['LinkBrowserWindowWidth']= '680';"; | |
| 1078 | $js .= $js_id .".Config['LinkBrowserWindowHeight'] = '439';"; | |
| beb373b4 | 1079 | break; |
| 924d15ba WW |
1080 | default: |
| 1081 | case 'none': | |
| bb840a2a WW |
1082 | $js .= $js_id .".Config['LinkBrowser'] = false;\n"; |
| 1083 | $js .= $js_id .".Config['ImageBrowser'] = false;\n"; | |
| 1084 | $js .= $js_id .".Config['FlashBrowser'] = false;\n"; | |
| 924d15ba WW |
1085 | break; |
| 1086 | } | |
| 0c87a920 WW |
1087 | } |
| 1088 | else { | |
| bb840a2a WW |
1089 | $js .= $js_id .".Config['LinkBrowser'] = false;\n"; |
| 1090 | $js .= $js_id .".Config['ImageBrowser'] = false;\n"; | |
| 1091 | $js .= $js_id .".Config['FlashBrowser'] = false;\n"; | |
| 1092 | $js .= $js_id .".Config['LinkUpload'] = false;\n"; | |
| 1093 | $js .= $js_id .".Config['ImageUpload'] = false;\n"; | |
| 1094 | $js .= $js_id .".Config['FlashUpload'] = false;\n"; | |
| 8de1e54a | 1095 | } |
| 924d15ba | 1096 | |
| e9a59651 | 1097 | if (!empty($conf['js_conf'])) { |
| 8de1e54a WW |
1098 | $lines = preg_split("/[\n\r]+/", $conf['js_conf']); |
| 1099 | foreach ($lines as $l) | |
| 1100 | if ($l && strlen($l) > 5) { | |
| 1101 | $eqpos = strpos($l, "="); | |
| 1102 | if (false !== $eqpos) { | |
| 1103 | $option = str_replace("FCKConfig.", "", substr($l, 0, $eqpos)); | |
| bb840a2a | 1104 | $js .= "\n". $js_id .".Config['". trim($option) ."'] =". substr($l, $eqpos + 1); |
| 8de1e54a WW |
1105 | } |
| 1106 | } | |
| 92b2e6cf | 1107 | } |
| e44c2389 | 1108 | |
| 0c87a920 | 1109 | // add custom xml stylesheet if it exists |
| e9a59651 | 1110 | if (!empty($conf['css_style']) && $conf['css_style'] == 'theme') { |
| 151bddc3 WW |
1111 | if (file_exists($themepath .'fckstyles.xml')) { |
| 1112 | $styles_xml_path = $host . $themepath .'fckstyles.xml'; | |
| bb840a2a | 1113 | $js .= $js_id .".Config['StylesXmlPath'] = \"". $styles_xml_path ."\";\n"; |
| 8de1e54a WW |
1114 | } |
| 1115 | } | |
| e9a59651 | 1116 | else if (!empty($conf['css_style']) && $conf['css_style'] == 'self') { |
| 0ee41c0b | 1117 | $conf['styles_path'] = str_replace("%h%t", "%t", $conf['styles_path']); |
| bb840a2a | 1118 | $js .= $js_id .".Config['StylesXmlPath'] = \"". str_replace(array('%h', '%t', '%m'), array($host, $host . $themepath, $module_drupal_path), $conf['styles_path']) ."\";\n"; |
| 0c87a920 | 1119 | } |
| 0c87a920 WW |
1120 | // add custom stylesheet if configured |
| 1121 | // lets hope it exists but we'll leave that to the site admin | |
| 1122 | if ($conf['css_mode'] == 'theme') { | |
| 8de1e54a | 1123 | $css = $themepath .'style.css'; |
| 0c87a920 | 1124 | if (file_exists($css)) { |
| bb840a2a | 1125 | $js .= $js_id .".Config['EditorAreaCSS'] = \"". $host . $css .",". $module_full_path ."/fckeditor.css\";"; |
| 0c87a920 | 1126 | } |
| 3e74a194 WW |
1127 | else { |
| 1128 | $js .= $js_id .".Config['EditorAreaCSS'] = \"". $module_full_path ."/fckeditor.css\";"; | |
| 1129 | } | |
| 0c87a920 WW |
1130 | } |
| 1131 | else if ($conf['css_mode'] == 'self') { | |
| 0ee41c0b | 1132 | $conf['css_path'] = str_replace("%h%t", "%t", $conf['css_path']); |
| bb840a2a | 1133 | $js .= $js_id .".Config['EditorAreaCSS'] = \"". str_replace(array('%h', '%t'), array($host, $host . $themepath), $conf['css_path']) .",". $module_full_path ."/fckeditor.css\";"; |
| 0c87a920 | 1134 | } |
| bb840a2a | 1135 | |
| 79a1deba WW |
1136 | if (!$processed) { |
| 1137 | drupal_add_js('var '. $js_id .';if (Drupal.jsEnabled) {$(document).ready(function() {'. $js .'});}', 'inline'); | |
| 1138 | } | |
| f3d88ca0 | 1139 | |
| 0c87a920 WW |
1140 | if ($conf['popup']=="t") { |
| 1141 | // Add the script file with the popup open function. | |
| 79a1deba WW |
1142 | if (!$processed) { |
| 1143 | drupal_add_js($module_drupal_path .'/fckeditor.popup.js'); | |
| 1144 | } | |
| 8de1e54a | 1145 | $element['#suffix'] .= " <span class=\"fckeditor_popuplink\">(<a href=\"#\" onclick=\"FCKeditor_OpenPopup('". $module_full_path ."/fckeditor.popup.html?var=". $js_id ."&el=". $element['#id'] ."');return false;\">". t('Open rich editor') ."</a>)</span>"; |
| 0c87a920 | 1146 | } |
| 5d34da9a WW |
1147 | else { |
| 1148 | // if no popup mode, add the editor initialization to the footer | |
| 1149 | // this obviously needs print($closure) in page.tpl.php | |
| 79a1deba | 1150 | if ($fckeditor_on && !$processed) { |
| 18bd52b0 WW |
1151 | $str = ""; |
| 1152 | if ($element['#id'] == 'edit-body') { | |
| 1153 | $str = 'if ($("#edit-teaser-js").size() && $("#edit-teaser-js").val().length){ | |
| 1154 | $("#edit-body").val($("#edit-teaser-js").val() + "<!--break-->" + $("#edit-body").val()); | |
| 1155 | }'; | |
| 1156 | } | |
| 1157 | drupal_add_js('if (Drupal.jsEnabled) {$(document).ready(function() {if (typeof ('. $js_id .') != "undefined") { '. $str .' | |
| dedd64a9 | 1158 | window.setTimeout("FCKeditorReplaceTextarea(\''. $textarea_id .'\','. $js_id .','. $xss_check .');",100);}});}', 'inline', 'footer'); |
| cc67ac84 WW |
1159 | } |
| 1160 | } | |
| f3d88ca0 | 1161 | } |
| 9b429add | 1162 | |
| 0c87a920 WW |
1163 | // display the field id for administrators |
| 1164 | if (user_access('administer fckeditor')) { | |
| b0c12ff3 | 1165 | $element['#suffix'] .= '<div class="textarea-identifier description">'. t('The ID for !excluding this element is: !id - the path is: !path', array( |
| 8de1e54a WW |
1166 | '!excluding' => l(t("excluding or including"), 'admin/settings/fckeditor'), |
| 1167 | '!id' => $element['#id'], | |
| 1168 | '!path' => $_GET['q'], | |
| b0c12ff3 | 1169 | )) .'</div>'; |
| 0c87a920 | 1170 | } |
| 79a1deba WW |
1171 | |
| 1172 | $processed_elements[] = $element['#id']; | |
| 0c87a920 | 1173 | |
| f3d88ca0 | 1174 | return $element; |
| 04b827fa DS |
1175 | } |
| 1176 | ||
| 23824481 | 1177 | /** |
| 0c87a920 WW |
1178 | * Implementation of hook_user(). |
| 1179 | */ | |
| 1180 | function fckeditor_user($type, &$edit, &$user, $category = NULL) { | |
| 1181 | if ($type == 'form' && $category == 'account' && user_access('access fckeditor')) { | |
| 1182 | $profile = fckeditor_user_get_profile($user); | |
| 1183 | $toolbar_options = fckeditor_load_toolbar_options(); | |
| 1184 | $skin_options = fckeditor_load_skin_options(); | |
| 1185 | $lang_options = fckeditor_load_lang_options(); | |
| 1186 | ||
| 1187 | // because the settings are saved as strings we need to test for the string 'true' | |
| 1188 | if ($profile->settings['allow_user_conf'] == 't') { | |
| 1189 | $form['fckeditor'] = array( | |
| 1190 | '#type' => 'fieldset', | |
| 1191 | '#title' => t('Rich Text Editor settings'), | |
| 1192 | '#weight' => 10, | |
| 1193 | '#collapsible' => TRUE, | |
| 1194 | '#collapsed' => TRUE | |
| 1195 | ); | |
| 1196 | ||
| 1197 | $form['fckeditor']['fckeditor_default'] = array( | |
| 1198 | '#type' => 'select', | |
| 1199 | '#title' => t('Default state'), | |
| 1200 | '#default_value' => isset($user->fckeditor_default) ? $user->fckeditor_default : (isset($profile->settings['default']) ? $profile->settings['default'] : 'f'), | |
| 8de1e54a | 1201 | '#options' => array('t' => t('enabled'), 'f' => t('disabled')), |
| 0c87a920 WW |
1202 | '#description' => t('Should rich-text editing be enabled or disabled by default in textarea fields? If disabled, rich text editor may still be enabled using toggle or popup window.'), |
| 1203 | ); | |
| 1204 | ||
| 1205 | $form['fckeditor']['fckeditor_show_toggle'] = array( | |
| 1206 | '#type' => 'select', | |
| 1207 | '#title' => t('Show disable/enable rich text editor toggle'), | |
| 1208 | '#default_value' => isset($user->fckeditor_show_toggle) ? $user->fckeditor_show_toggle : (isset($profile->settings['show_toggle']) ? $profile->settings['show_toggle'] : 't'), | |
| 1209 | '#options' => array('t' => t('true'), 'f' => t('false')), | |
| 1210 | '#description' => t('Whether or not to show the disable/enable rich text editor toggle below the textarea. Works only if FCKeditor is not running a popup window (see below).'), | |
| 1211 | ); | |
| 1212 | ||
| 1213 | $form['fckeditor']['fckeditor_popup'] = array( | |
| 1214 | '#type' => 'select', | |
| 1215 | '#title' => t('Use FCKeditor in a popup window'), | |
| 1216 | '#default_value' => isset($user->fckeditor_popup) ? $user->fckeditor_popup : (isset($profile->settings['popup']) ? $profile->settings['popup'] : 'f'), | |
| 1217 | '#options' => array('f' => t('false'), 't' => t('true')), | |
| 1218 | '#description' => t('If this option is enabled a link to a popup window will be used instead of a textarea replace.'), | |
| 1219 | ); | |
| 1220 | ||
| 1221 | $form['fckeditor']['fckeditor_skin'] = array( | |
| 1222 | '#type' => 'select', | |
| 1223 | '#title' => t('Skin'), | |
| 1224 | '#default_value' => isset($user->fckeditor_skin) ? $user->fckeditor_skin : (isset($profile->settings['skin']) ? $profile->settings['skin'] : 'default'), | |
| 1225 | '#options' => $skin_options, | |
| 1226 | '#description' => t('Choose a FCKeditor skin.'), | |
| 1227 | ); | |
| 1228 | ||
| 1229 | $form['fckeditor']['fckeditor_toolbar'] = array( | |
| 1230 | '#type' => 'select', | |
| 1231 | '#title' => t('Toolbar'), | |
| 1232 | '#default_value' => isset($user->fckeditor_toolbar) ? $user->fckeditor_toolbar : (isset($profile->settings['toolbar']) ? $profile->settings['toolbar'] : 'default'), | |
| 1233 | '#options' => $toolbar_options, | |
| 1234 | '#description' => t('Choose a FCKeditor toolbar set.'), | |
| 1235 | ); | |
| 1236 | ||
| 1237 | $form['fckeditor']['fckeditor_expand'] = array( | |
| 1238 | '#type' => 'select', | |
| 1239 | '#title' => t('Start the toolbar expanded'), | |
| 1240 | '#default_value' => isset($user->fckeditor_expand) ? $user->fckeditor_expand : (isset($profile->settings['expand']) ? $profile->settings['expand'] : 't'), | |
| 1241 | '#options' => array('t' => t('enabled'), 'f' => t('disabled')), | |
| 1242 | '#description' => t('The toolbar start expanded or collapsed.'), | |
| 1243 | ); | |
| 1244 | ||
| 1245 | $form['fckeditor']['fckeditor_width'] = array( | |
| 1246 | '#type' => 'textfield', | |
| 1247 | '#title' => t('Width'), | |
| 1248 | '#default_value' => isset($user->fckeditor_width) ? $user->fckeditor_width : (isset($profile->settings['width']) ? $profile->settings['width'] : '100%'), | |
| 1249 | '#description' => t("Width in pixels or percent. Ex: 400 or 100%"), | |
| 1250 | '#size' => 40, | |
| 1251 | '#maxlength' => 128, | |
| 1252 | ); | |
| 1253 | ||
| 1254 | $form['fckeditor']['fckeditor_lang'] = array( | |
| 1255 | '#type' => 'select', | |
| 1256 | '#title' => t('Language'), | |
| 1257 | '#default_value' => isset($user->fckeditor_lang) ? $user->fckeditor_lang : (isset($profile->settings['lang']) ? $profile->settings['lang'] : 'en'), | |
| 1258 | '#options' => $lang_options, | |
| 1259 | '#description' => t('The language for the FCKeditor interface.') | |
| 1260 | ); | |
| 1261 | ||
| 1262 | $form['fckeditor']['fckeditor_auto_lang'] = array( | |
| 1263 | '#type' => 'select', | |
| 1264 | '#title' => t('Auto-detect language'), | |
| 1265 | '#default_value' => isset($user->fckeditor_auto_lang) ? $user->fckeditor_auto_lang : (isset($profile->settings['auto_lang']) ? $profile->settings['auto_lang'] : 't'), | |
| 1266 | '#options' => array('t' => t('true'), 'f' => t('false')), | |
| 1267 | '#description' => t('Use auto detect user language feature.') | |
| 1268 | ); | |
| 1269 | ||
| 1270 | return array('fckeditor' => $form); | |
| 1271 | } | |
| 1272 | } | |
| 8c9e81b2 WW |
1273 | |
| 1274 | if ($type == 'validate') { | |
| 1275 | if (isset($edit['fckeditor_default'], $edit['fckeditor_popup']) && $edit['fckeditor_default'] == 't' && $edit['fckeditor_popup'] == 't') { | |
| 1276 | form_set_error('fckeditor_popup', t('If FCKeditor is enabled by default, popup window must be disabled.')); | |
| 1277 | } | |
| 1278 | ||
| 1279 | if (isset($edit['fckeditor_show_toggle'], $edit['fckeditor_popup']) && $edit['fckeditor_show_toggle'] == 't' && $edit['fckeditor_popup'] == 't') { | |
| 1280 | form_set_error('fckeditor_popup', t('If toggle is enabled, popup window must be disabled.')); | |
| 1281 | } | |
| 1282 | ||
| 1283 | if (isset($edit['fckeditor_width']) && !preg_match('/^\d+%?$/', $edit['fckeditor_width'])) { | |
| 1284 | form_set_error('fckeditor_width', t('Enter valid width. Example: 400 or 100%.')); | |
| 1285 | } | |
| 1286 | } | |
| 0c87a920 WW |
1287 | } |
| 1288 | ||
| 1289 | /** | |
| 1290 | * Return an HTML form for profile configuration. | |
| 1291 | */ | |
| 1292 | function fckeditor_profile_form($edit) { | |
| 1293 | ||
| d7fbc905 | 1294 | $output = drupal_get_form('fckeditor_profile_form_build', $edit); |
| 0c87a920 WW |
1295 | |
| 1296 | return $output; | |
| 1297 | } | |
| 1298 | ||
| 8de1e54a WW |
1299 | /** |
| 1300 | * Return an HTML form for global profile configuration. | |
| 1301 | */ | |
| 1302 | function fckeditor_global_profile_form($edit) { | |
| 1303 | ||
| d7fbc905 | 1304 | $output = drupal_get_form('fckeditor_global_profile_form_build', $edit); |
| 8de1e54a WW |
1305 | |
| 1306 | return $output; | |
| 1307 | } | |
| 1308 | ||
| 0c87a920 WW |
1309 | function fckeditor_load_toolbar_options() { |
| 1310 | $arr = array(); | |
| 8de1e54a WW |
1311 | $module_drupal_path = drupal_get_path('module', 'fckeditor'); |
| 1312 | $fckconfig_js = $module_drupal_path .'/fckeditor/fckconfig.js'; | |
| 1313 | $fckeditor_config_js = $module_drupal_path .'/fckeditor.config.js'; | |
| 0c87a920 WW |
1314 | if (file_exists($fckconfig_js) && is_readable($fckconfig_js)) { |
| 1315 | $fp = @fopen($fckconfig_js, "r"); | |
| 1316 | if ($fp) { | |
| 1317 | while (!feof($fp)) { | |
| 8de1e54a | 1318 | $line = fgets($fp, 1024); |
| 0c87a920 WW |
1319 | if (preg_match("/FCKConfig\.ToolbarSets\[(\"|')(.*?)\\1\]/i", $line, $matches)) { |
| 1320 | $arr[$matches[2]] = ucfirst($matches[2]); | |
| 1321 | } | |
| 1322 | } | |
| 1323 | fclose($fp); | |
| 1324 | } | |
| 1325 | } | |
| 1326 | if (file_exists($fckeditor_config_js) && is_readable($fckeditor_config_js)) { | |
| 1327 | $fp = @fopen($fckeditor_config_js, "r"); | |
| 1328 | if ($fp) { | |
| 1329 | while (!feof($fp)) { | |
| 8de1e54a | 1330 | $line = fgets($fp, 1024); |
| 0c87a920 WW |
1331 | if (preg_match("/FCKConfig\.ToolbarSets\[(\"|')(.*?)\\1\]/i", $line, $matches)) { |
| 1332 | $arr[$matches[2]] = ucfirst($matches[2]); | |
| 1333 | } | |
| 1334 | } | |
| 1335 | fclose($fp); | |
| 1336 | } | |
| 1337 | } | |
| 1338 | ||
| 1339 | //oops, we have no information about toolbars, let's use hardcoded array | |
| 1340 | if (empty($arr)) { | |
| 1341 | $arr = array( | |
| 1342 | 'Basic' => 'Basic', | |
| 1343 | 'Default' => 'Default', | |
| 1344 | ); | |
| 1345 | } | |
| 1346 | asort($arr); | |
| 1347 | ||
| 1348 | return $arr; | |
| 1349 | } | |
| 1350 | ||
| 1351 | function fckeditor_load_skin_options() { | |
| 1352 | $arr = array(); | |
| 8de1e54a WW |
1353 | $module_drupal_path = drupal_get_path('module', 'fckeditor'); |
| 1354 | $skin_dir = $module_drupal_path .'/fckeditor/editor/skins'; | |
| 0c87a920 WW |
1355 | if (is_dir($skin_dir)) { |
| 1356 | $dh = @opendir($skin_dir); | |
| cc67ac84 WW |
1357 | if (FALSE !== $dh) { |
| 1358 | while (($file = readdir($dh)) !== FALSE ) { | |
| 8de1e54a | 1359 | if (in_array($file, array(".", "..", "CVS", ".svn"))) { |
| 0c87a920 WW |
1360 | continue; |
| 1361 | } | |
| 8de1e54a | 1362 | if (is_dir($skin_dir . DIRECTORY_SEPARATOR . $file)) { |
| 0c87a920 WW |
1363 | $arr[$file] = ucfirst($file); |
| 1364 | } | |
| 1365 | } | |
| 1366 | closedir( $dh ); | |
| 1367 | } | |
| 1368 | } | |
| 1369 | ||
| 1370 | //oops, we have no information about skins, let's use only default | |
| 1371 | if (empty($arr)) { | |
| 1372 | $arr = array( | |
| 1373 | 'default' => 'Default', | |
| 1374 | ); | |
| 1375 | } | |
| 1376 | asort($arr); | |
| 1377 | ||
| 1378 | return $arr; | |
| 1379 | } | |
| 1380 | ||
| 1381 | function fckeditor_load_lang_options() { | |
| 1382 | $arr = array(); | |
| 8de1e54a WW |
1383 | $module_drupal_path = drupal_get_path('module', 'fckeditor'); |
| 1384 | $lang_dir = $module_drupal_path .'/fckeditor/editor/lang'; | |
| 0c87a920 WW |
1385 | if (is_dir($lang_dir)) { |
| 1386 | $dh = @opendir($lang_dir); | |
| 8de1e54a | 1387 | if (false !== $dh ) { |
| cc67ac84 | 1388 | while (($file = readdir($dh)) !== FALSE) { |
| 8de1e54a | 1389 | if (in_array($file, array(".", "..", "CVS", ".svn"))) { |
| 0c87a920 WW |
1390 | continue; |
| 1391 | } | |
| 8de1e54a | 1392 | if (is_file($lang_dir . DIRECTORY_SEPARATOR . $file) && preg_match("/^(.*?)\.js$/", $file, $matches)) { |
| 0c87a920 WW |
1393 | $lang = $matches[1]; |
| 1394 | $arr[$lang] = strtoupper($lang); | |
| 1395 | } | |
| 1396 | } | |
| 1397 | closedir( $dh ); | |
| 1398 | } | |
| 1399 | } | |
| 1400 | ||
| 1401 | //oops, we have no information about languages, let's use those available in FCKeditor 2.4.3 | |
| 1402 | if (empty($arr)) { | |
| 1403 | $arr = array( | |
| 1404 | 'af' => 'Afrikaans', | |
| 1405 | 'ar' => 'Arabic', | |
| 1406 | 'bg' => 'Bulgarian', | |
| 1407 | 'bn' => 'Bengali/Bangla', | |
| 1408 | 'bs' => 'Bosnian', | |
| 1409 | 'ca' => 'Catalan', | |
| 1410 | 'cs' => 'Czech', | |
| 1411 | 'da' => 'Danish', | |
| 1412 | 'de' => 'German', | |
| 1413 | 'el' => 'Greek', | |
| 1414 | 'en' => 'English', | |
| 8de1e54a WW |
1415 | 'en-au' => 'English (Australia)', |
| 1416 | 'en-ca' => 'English (Canadian)', | |
| 1417 | 'en-uk' => 'English (United Kingdom)', | |
| 0c87a920 WW |
1418 | 'eo' => 'Esperanto', |
| 1419 | 'es' => 'Spanish', | |
| 1420 | 'et' => 'Estonian', | |
| 1421 | 'eu' => 'Basque', | |
| 1422 | 'fa' => 'Persian', | |
| 1423 | 'fi' => 'Finnish', | |
| 1424 | 'fo' => 'Faroese', | |
| 1425 | 'fr' => 'French', | |
| 1426 | 'gl' => 'Galician', | |
| 1427 | 'he' => 'Hebrew', | |
| 1428 | 'hi' => 'Hindi', | |
| 1429 | 'hr' => 'Croatian', | |
| 1430 | 'hu' => 'Hungarian', | |
| 1431 | 'it' => 'Italian', | |
| 1432 | 'ja' => 'Japanese', | |
| 1433 | 'km' => 'Khmer', | |
| 1434 | 'ko' => 'Korean', | |
| 1435 | 'lt' => 'Lithuanian', | |
| 1436 | 'lv' => 'Latvian', | |
| 1437 | 'mn' => 'Mongolian', | |
| 1438 | 'ms' => 'Malay', | |
| 1439 | 'nb' => 'Norwegian Bokmal', | |
| 1440 | 'nl' => 'Dutch', | |
| 1441 | 'no' => 'Norwegian', | |
| 1442 | 'pl' => 'Polish', | |
| 1443 | 'pt' => 'Portuguese (Portugal)', | |
| 8de1e54a | 1444 | 'pt-br' => 'Portuguese (Brazil)', |
| 0c87a920 WW |
1445 | 'ro' => 'Romanian', |
| 1446 | 'ru' => 'Russian', | |
| 1447 | 'sk' => 'Slovak', | |
| 1448 | 'sl' => 'Slovenian', | |
| 1449 | 'sr' => 'Serbian (Cyrillic)', | |
| 8de1e54a | 1450 | 'sr-latn' => 'Serbian (Latin)', |
| 0c87a920 WW |
1451 | 'sv' => 'Swedish', |
| 1452 | 'th' => 'Thai', | |
| 1453 | 'tr' => 'Turkish', | |
| 1454 | 'uk' => 'Ukrainian', | |
| 1455 | 'vi' => 'Vietnamese', | |
| 1456 | 'zh' => 'Chinese Traditional', | |
| 8de1e54a | 1457 | 'zh-cn' => 'Chinese Simplified', |
| 0c87a920 WW |
1458 | ); |
| 1459 | } | |
| 1460 | ||
| 1461 | asort($arr); | |
| 1462 | ||
| 1463 | return $arr; | |
| 1464 | } | |
| 1465 | ||
| 1466 | /** | |
| 8de1e54a WW |
1467 | * sort roles according to precedence settings. previously sorted roles are followed by latest added roles. |
| 1468 | */ | |
| 1469 | function fckeditor_sorted_roles() { | |
| 1470 | static $order; | |
| 1471 | if (isset($order)) { | |
| 1472 | return $order; | |
| 1473 | } | |
| 1474 | $order = array(); | |
| 1475 | $roles = user_roles(0, 'access fckeditor'); | |
| 1476 | ||
| 1477 | $result = db_query("SELECT settings FROM {fckeditor_settings} WHERE name='FCKeditor Global Profile'"); | |
| 1478 | $data = db_fetch_object($result); | |
| d7fbc905 | 1479 | if (!empty($data->settings)) { |
| 8de1e54a WW |
1480 | $settings = unserialize($data->settings); |
| 1481 | if (isset($settings['rank']) && !empty($settings['rank'])) | |
| 1482 | foreach ($settings['rank'] as $rid) { | |
| 1483 | if (isset($roles[$rid])) { | |
| 1484 | $order[$rid] = $roles[$rid]; | |
| 1485 | unset($roles[$rid]); | |
| 1486 | } | |
| 1487 | } | |
| 1488 | } | |
| 1489 | krsort($roles);//sort the remaining unsorted roles by id, descending. | |
| 1490 | $order += $roles; | |
| 1491 | return $order; | |
| 1492 | } | |
| 1493 | ||
| 1494 | function fckeditor_global_profile_form_build($sth, $edit) { | |
| 1495 | $edit = (object) $edit; | |
| 1496 | ||
| 1497 | if (arg(3) == 'addg') { | |
| 1498 | drupal_set_breadcrumb(array(l(t('administer'), 'admin'), l(t('fckeditor'), 'admin/settings/fckeditor'), l(t('Add new FCKeditor Global Profile'), 'admin/settings/fckeditor/addg'))); | |
| 1499 | ||
| 1500 | $result = db_query("SELECT DISTINCT(rid) FROM {fckeditor_role} WHERE name='FCKeditor Global Profile'"); | |
| 1501 | $data = db_fetch_object($result); | |
| 1502 | ||
| d7fbc905 | 1503 | if (!empty($data->rid)) { |
| 8de1e54a WW |
1504 | drupal_set_message(t("Global profile already exist. Only one global profile is allowed."), "error"); |
| 1505 | return array(); | |
| 1506 | } | |
| 1507 | ||
| 1508 | $btn = t('Create global profile'); | |
| 1509 | } | |
| 1510 | else { | |
| 1511 | $form['old_name'] = array('#type' => 'hidden', '#value' => $edit->name); | |
| 1512 | $btn = t('Update global profile'); | |
| 1513 | } | |
| 1514 | ||
| 1515 | $form['common'] = array( | |
| 1516 | '#type' => 'fieldset', | |
| 1517 | '#title' => t('Main setup'), | |
| 1518 | '#collapsible' => TRUE, | |
| 1519 | '#collapsed' => TRUE | |
| 1520 | ); | |
| 1521 | ||
| 1522 | $roles = fckeditor_sorted_roles(); | |
| 1523 | $rids = $rtext = array(); | |
| 1524 | foreach ($roles as $rid => $name) { | |
| 1525 | $rids[] = $rid; | |
| 1526 | $rtext[] = '<strong>'. $rid .' - </strong>'. $name; | |
| 1527 | } | |
| 1528 | $form['common']['rank'] = array('#type' => 'textfield', | |
| 1529 | '#title' => t('Role precedence'), | |
| 1530 | '#default_value' => implode('>', $rids), | |
| 1531 | '#description' => t('A user having <strong>multiple roles</strong> gets the permissions of the highest one. Sort role IDs according to their <strong>precedence from higher to lower</strong> by putting > in between.<br />'), | |
| 1532 | ); | |
| 1533 | if ($rids) { | |
| 1534 | $form['common']['rank']['#description'] .= t('Here is the id-name pairs of roles having access to FCKeditor:') .'<div>'. implode('<br />', $rtext) .'</div>'; | |
| 1535 | } | |
| 1536 | else { | |
| 1537 | $form['common']['rank']['#description'] .= t('You haven\'t assigned the <code>!access1</code> !permissions yet.', array('!access1' => t('access fckeditor'), '!permissions' => l(t('permissions'), 'admin/user/permissions'))); | |
| 1538 | } | |
| 1539 | ||
| 1540 | $form['fckeditor_exclude_settings'] = array( | |
| 1541 | '#type' => 'fieldset', | |
| 1542 | '#title' => t('Visibility settings'), | |
| 1543 | '#collapsible' => TRUE, | |
| 1544 | '#collapsed' => TRUE, | |
| 1545 | ); | |
| 1546 | ||
| 1547 | $form['fckeditor_exclude_settings']['excl_mode'] = array( | |
| 1548 | '#type' => 'select', | |
| 1549 | '#title' => t('Use inclusion or exclusion mode'), | |
| 09aae5b1 | 1550 | '#default_value' => (empty($edit->settings['excl_mode']) || in_array($edit->settings['excl_mode'], array(0, 2))) ? 0 : 1, |
| 8de1e54a WW |
1551 | '#options' => array('0' => t('exclude'), '1' => t('include')), |
| 1552 | '#description' => t('Choose the way of disabling/enabling FCKeditor on selected fields/paths (see below). Use exclude to disable FCKeditor on selected fields/paths. Use include if you want to load FCKeditor only on selected paths/fields.'), | |
| 1553 | ); | |
| 8de1e54a WW |
1554 | /** |
| 1555 | * get excluded fields - so we can have normal textareas too | |
| 1556 | * split the phrase by any number of commas or space characters, | |
| 1557 | * which include " ", \r, \t, \n and \f | |
| 1558 | */ | |
| 1559 | $form['fckeditor_exclude_settings']['excl_fields'] = array( | |
| 1560 | '#type' => 'textarea', | |
| 1561 | '#title' => t('Fields to exclude/include'), | |
| 1562 | '#cols' => 60, | |
| 1563 | '#rows' => 5, | |
| 1564 | '#prefix' => '<div style="margin-left:20px">', | |
| 1565 | '#suffix' => '</div>', | |
| d7fbc905 | 1566 | '#default_value' => !empty($edit->settings['excl_fields']) ? $edit->settings['excl_fields'] : '', |
| a2e37d18 | 1567 | '#description' => t("Enter names (HTML ID's) of fields that may or may not have an FCKeditor, depending on the chosen option for the inclusion/exclusion mode.<br />You may separate the different entries by commas, spaces or newlines.<br />You may also use * as a wildcard character."), |
| 8de1e54a WW |
1568 | ); |
| 1569 | ||
| 1570 | /** | |
| 1571 | * get excluded paths - so we can have normal textareas too | |
| 1572 | * split the phrase by any number of commas or space characters, | |
| 1573 | * which include " ", \r, \t, \n and \f | |
| 1574 | */ | |
| 1575 | $form['fckeditor_exclude_settings']['excl_paths'] = array( | |
| 1576 | '#type' => 'textarea', | |
| 1577 | '#title' => t('Paths to exclude/include'), | |
| 1578 | '#prefix' => '<div style="margin-left:20px">', | |
| 1579 | '#suffix' => '</div>', | |
| 1580 | '#cols' => 60, | |
| 1581 | '#rows' => 5, | |
| d7fbc905 | 1582 | '#default_value' => !empty($edit->settings['excl_paths']) ? $edit->settings['excl_paths'] : '', |
| 8de1e54a WW |
1583 | '#description' => t("Enter drupal paths here, depending on the chosen option for the inclusion/exclusion mode.<br />Paths may be used the same way as in the drupal blocks configuration.<br />You may separate the different entries by commas, spaces or newlines. <br />You may also use * as a wildcard character (for example <code>comment/*</code>)."), |
| 1584 | ); | |
| 1585 | ||
| 1586 | $form['fckeditor_exclude_settings']['simple_incl_fields'] = array( | |
| 1587 | '#type' => 'textarea', | |
| 1588 | '#title' => t('Force simplified toolbar on the following fields'), | |
| 1589 | '#cols' => 60, | |
| 1590 | '#rows' => 5, | |
| d7fbc905 | 1591 | '#default_value' => !empty($edit->settings['simple_incl_fields']) ? $edit->settings['simple_incl_fields'] : '', |
| 8de1e54a WW |
1592 | '#description' => t("Enter names (HTML ID's) of fields that should have the simplified toolbar.<br />If you don't want to use this feature, simply leave this field empty.<br />You may separate the different entries by commas, spaces or newlines."), |
| 1593 | ); | |
| 1594 | ||
| 1595 | $form['fckeditor_exclude_settings']['simple_incl_paths'] = array( | |
| 1596 | '#type' => 'textarea', | |
| 1597 | '#title' => t('Force simplified toolbar on the following paths'), | |
| 1598 | '#cols' => 60, | |
| 1599 | '#rows' => 5, | |
| d7fbc905 | 1600 | '#default_value' => !empty($edit->settings['simple_incl_paths']) ? $edit->settings['simple_incl_paths'] : '', |
| 8de1e54a WW |
1601 | '#description' => t("Enter drupal paths that should have the simplified toolbar.<br />If you don't want to use this feature, simply leave this field empty.<br />Paths may be used the same way as in the drupal blocks configuration.<br />You may separate the different entries by commas, spaces or newlines.<br />You may also use * as a wildcard character (for example <code>comment/*</code>)."), |
| 1602 | ); | |
| 1603 | ||
| 0a4de7b0 WW |
1604 | if (variable_get('file_downloads', '') == FILE_DOWNLOADS_PRIVATE) { |
| 1605 | $form['fckeditor_advanced_settings'] = array( | |
| 1606 | '#type' => 'fieldset', | |
| 1607 | '#title' => t('Advanced settings'), | |
| 1608 | '#collapsible' => TRUE, | |
| 1609 | '#collapsed' => TRUE, | |
| 1610 | ); | |
| 1611 | ||
| 63b05f42 | 1612 | $current_private_dir = !isset($edit->settings['private_dir']) ? "" : $edit->settings['private_dir']; |
| 0a4de7b0 WW |
1613 | $form['fckeditor_advanced_settings']['private_dir'] = array( |
| 1614 | '#type' => 'textfield', | |
| 1615 | '#title' => t('Location of files uploaded with FCKeditor in the private folder'), | |
| bbb4a78f | 1616 | '#default_value' => $current_private_dir, |
| 0a4de7b0 WW |
1617 | '#size' => 40, |
| 1618 | '#maxlength' => 255, | |
| bbb4a78f | 1619 | '#description' => t('The path relative to the location of the private directory where FCKeditor should store uploaded files.') .'<br />'. t('<strong>Warning:</strong> FCKeditor does not implement any kind of access protection on files available in this location. All files stored in the directory defined above might be accessible by unathenticated users if there is no information about the file in the Drupal\'s database.') .'<br />'. t('System path to the private folder is: !system_path.', array('!system_path' => realpath(file_directory_path()) . DIRECTORY_SEPARATOR)). '<br />'. t('Available wildcard characters:<br/><strong>%u</strong> - User ID.') .'<br />'. t('Current path: !path', array('!path' => $current_private_dir .' ('. file_create_path($current_private_dir) .')')), |
| 0a4de7b0 WW |
1620 | ); |
| 1621 | } | |
| 1622 | ||
| 8de1e54a WW |
1623 | $form['submit'] = array( |
| 1624 | '#type' => 'submit', | |
| 1625 | '#value' => $btn | |
| 1626 | ); | |
| 1627 | ||
| 1628 | return $form; | |
| 1629 | } | |
| 1630 | ||
| 1631 | /** | |
| 0c87a920 WW |
1632 | * Return an HTML form for profile configuration. |
| 1633 | */ | |
| 1634 | function fckeditor_profile_form_build($sth, $edit) { | |
| 1635 | $edit = (object) $edit; | |
| 1636 | ||
| 1637 | $toolbar_options = fckeditor_load_toolbar_options(); | |
| 1638 | $skin_options = fckeditor_load_skin_options(); | |
| 1639 | $lang_options = fckeditor_load_lang_options(); | |
| 1640 | ||
| 1641 | // Only display the roles that currently don't have a fckeditor profile. One | |
| 1642 | // profile per role. | |
| 1643 | $orig_roles = user_roles(FALSE, 'access fckeditor'); | |
| 1644 | $roles = $orig_roles; | |
| 8bdf4d22 | 1645 | |
| d7fbc905 | 1646 | if (!empty($edit->rids) && !user_roles(false, 'access fckeditor')) { |
| d3cf16a0 | 1647 | drupal_set_message(t('You haven\'t assigned <code>!access1</code> !permissions yet.<br/>It is recommended to assign the <code>!access1</code> !permissions before updating FCKeditor profiles.', |
| 8bdf4d22 | 1648 | array( |
| d3cf16a0 | 1649 | '!access1' => t('access fckeditor'), |
| 8bdf4d22 WW |
1650 | '!permissions' => l(t('permissions'), 'admin/user/permissions'))), 'warning'); |
| 1651 | } | |
| d3cf16a0 | 1652 | |
| 0c87a920 | 1653 | if (arg(3) == 'add') { |
| 8de1e54a WW |
1654 | drupal_set_breadcrumb(array(l(t('administer'), 'admin'), l(t('fckeditor'), 'admin/settings/fckeditor'), l(t('Add new FCKeditor profile'), 'admin/settings/fckeditor/add'))); |
| 1655 | ||
| 0c87a920 WW |
1656 | $result = db_query('SELECT DISTINCT(rid) FROM {fckeditor_role}'); |
| 1657 | while ($data = db_fetch_object($result)) { | |
| d7fbc905 | 1658 | if ((empty($edit->rids) || !in_array($data->rid, array_keys((array) $edit->rids))) && !form_get_errors()) { |
| 0c87a920 WW |
1659 | unset($roles[$data->rid]); |
| 1660 | } | |
| 1661 | } | |
| 8de1e54a | 1662 | if (count($orig_roles) != count($roles)) { |
| 0c87a920 WW |
1663 | drupal_set_message(t('Not all user roles are shown since they already have fckeditor profiles. You must first unassign profiles in order to add them to a new one.')); |
| 1664 | } | |
| 1665 | $btn = t('Create profile'); | |
| 1666 | } | |
| 1667 | else { | |
| 1668 | $form['old_name'] = array('#type' => 'hidden', '#value' => $edit->name); | |
| 1669 | $btn = t('Update profile'); | |
| 1670 | } | |
| 1671 | ||
| 1672 | $form['basic'] = array( | |
| 1673 | '#type' => 'fieldset', | |
| 1674 | '#title' => t('Basic setup'), | |
| 1675 | '#collapsible' => TRUE, | |
| 1676 | '#collapsed' => TRUE | |
| 1677 | ); | |
| 1678 | ||
| 1679 | $form['basic']['name'] = array( | |
| 1680 | '#type' => 'textfield', | |
| 1681 | '#title' => t('Profile name'), | |
| d7fbc905 | 1682 | '#default_value' => !empty($edit->name) ? $edit->name : "", |
| 0c87a920 WW |
1683 | '#size' => 40, |
| 1684 | '#maxlength' => 128, | |
| 1685 | '#description' => t('Enter a name for this profile. This name is only visible within the fckeditor administration page.'), | |
| 1686 | '#required' => TRUE | |
| 1687 | ); | |
| 1688 | ||
| 1689 | $form['basic']['rids'] = array( | |
| 1690 | '#type' => 'checkboxes', | |
| 1691 | '#title' => t('Roles allowed to use this profile'), | |
| d7fbc905 | 1692 | '#default_value' => !empty($edit->rids) ? array_keys((array) $edit->rids) : array(), |
| 0c87a920 | 1693 | '#options' => $roles, |
| 8de1e54a | 1694 | '#description' => t('Only roles with \'!access1\' permission will be shown here. If no role is available, make sure that you have assigned the \'!access1\' !permission.', array('!access1' => t('access fckeditor'), '!permission' => l(t("permission"), "admin/user/permissions"))), |
| 0c87a920 WW |
1695 | '#required' => TRUE |
| 1696 | ); | |
| 1697 | ||
| 1698 | $form['basic']['allow_user_conf'] = array( | |
| 1699 | '#type' => 'select', | |
| 1700 | '#title' => t('Allow users to customize FCKeditor appearance'), | |
| d7fbc905 | 1701 | '#default_value' => !empty($edit->settings['allow_user_conf']) ? $edit->settings['allow_user_conf'] : 'f', |
| 0c87a920 WW |
1702 | '#options' => array('f' => t('false'), 't' => t('true')), |
| 1703 | '#description' => t('If allowed, users will be able to override <code>Editor appearance</code> by visiting their profile page.'), | |
| 1704 | ); | |
| dedd64a9 WW |
1705 | |
| 1706 | $form['security'] = array( | |
| 1707 | '#type' => 'fieldset', | |
| 1708 | '#title' => t('Security'), | |
| de10001e | 1709 | '#description' => '<p>' . t("When Drupal saves user data input through a textarea, it's saved in the database in unmodified form. That's why all untrusted textarea input should be run through an input format filter before outputting it to the screen.") . '</p>' .'<p>' . t("Drupal will not, however, filter data for content editor's editing a textarea. Normally, there is no security risk because the unmodified code is displayed as text and will not be rendered as HTML. But with FCKeditor installed, this is not the case, and content editor's are subject to having raw, untrusted code running inside their browsers.") . '</p>' . '<p>' . t("To address this issue, you should select a security filters below to prevent FCKeditor from rendering malicious code. Note that if a textarea's input format is set to \"Full HTML\" (or if the input format of the node doesn't include the filter), FCKeditor will properly ignore the setting below and will not run the code through the security filter.") . '</p>' . '<p>' . t("If any textareas on your site are accessible to unwanted users, we recommend checking the \"HTML Filter\". You may have other modules installed that provide other kinds of security filters and you may use those as long as you trust them to properly filter out malicious code. Note that not all the filters below are security filters and will provide no protection.") . '</p>', |
| dedd64a9 WW |
1710 | '#collapsible' => TRUE, |
| 1711 | '#collapsed' => TRUE | |
| 1712 | ); | |
| 1713 | ||
| 1714 | $all = filter_list_all(); | |
| 1715 | ||
| 1716 | $form['security']['filters'] = array( | |
| 1717 | '#type' => 'fieldset', | |
| 1718 | '#title' => t('Security filters'), | |
| 1719 | '#description' => t('Please choose carefully all filters that protect your content (probably not all filters listed below are security filters).'), | |
| 1720 | '#tree' => TRUE, | |
| 1721 | ); | |
| 1722 | ||
| 1723 | //don't bother administrator with filters that definitely are not security filters | |
| 9b607043 | 1724 | $modules_with_filters_to_skip = array('amazon_filter', 'asy', 'bbcode', 'biblio', 'blockquote', 'bookpost', 'chessboard', 'citation_filter', 'codefilter', 'collapse_text', 'contextlinks', 'coolfilter', 'dialectic', 'dript', 'dme', 'drutex', 'embedfilter', 'ext_link_page', 'extlink', 'elf', 'flickr', 'flickrstickr', 'footnotes', 'formdefaults', 'freelinking', 'gallery', 'geogebra', 'geshifilter', 'gotwo', 'googtube', 'gotcha', 'gtspam', 'hidden_content', 'img_assist', 'image_filter', 'inlinetags', 'insert_view', 'insertframe', 'insertnode', 'interwiki', 'jlightbox', 'jsmath', 'language_sections', 'link_node', 'lootz', 'markdown', 'marksmarty', 'mobile_codes', 'mykml', 'nofollowlist', 'oagwt', 'paging', 'pathfilter', 'pearwiki_filter', 'php', 'pirate', 'reptag', 'scrippet', 'scripturefilter', 'signwriter', 'slideshowpro', 'smartlinebreakconverter', 'smartypants', 'smileys', 'spamspan', 'spam_tokens', 'spoiler', 'table_altrow', 'tablemanager', 'tableofcontents', 'textile', 'tooltips', 'twikifilter', 'typogrify', 'unwrap', 'urlclass', 'urlicon', 'url_replace_filter', 'username_highlighter', 'video_filter', 'quote'); |
| dedd64a9 WW |
1725 | |
| 1726 | if (!isset($edit->settings['ss'])) { | |
| 1727 | $edit->settings['filters']['filter/0'] = 1; | |
| 1728 | } | |
| 1729 | foreach ($all as $id => $filter) { | |
| 1730 | if (in_array(strtolower($filter->module), $modules_with_filters_to_skip)) { | |
| 1731 | continue; | |
| 1732 | } | |
| 1733 | //skip line break converter and email -> link | |
| 1734 | if ($filter->module == 'filter' && in_array($filter->delta, array(1, 2))) { | |
| 1735 | continue; | |
| 1736 | } | |
| 1737 | $form['security']['filters'][$id] = array( | |
| 1738 | '#type' => 'checkbox', | |
| 1739 | '#title' => $filter->name, | |
| 1740 | '#default_value' => !empty($edit->settings['filters'][$id]), | |
| 1741 | '#description' => module_invoke($filter->module, 'filter', 'description', $filter->delta), | |
| 1742 | ); | |
| 1743 | } | |
| 1744 | ||
| 1745 | $form['security']['ss'] = array( | |
| 1746 | '#type' => 'radios', | |
| 1747 | '#title' => t('Security settings'), | |
| 1748 | '#default_value' => isset($edit->settings['ss']) ? $edit->settings['ss'] : '2', | |
| 1749 | '#options' => array( | |
| 1750 | '2' => t('Always run security filters for FCKeditor.'), | |
| 1751 | '1' => t('Run security filters only when FCKeditor is set to start automatically.'), | |
| 1752 | ), | |
| 1753 | '#description' => t('There are two ways of starting FCKeditor: automatically and manually (via toggle or in a popup). If you decide to apply security filters only when FCKeditor starts automatically, you\'ll not be protected when toggling manually from plain textarea to FCKeditor or when using FCKeditor in a popup mode. So choose this option only, if you can detect various attacks (mainly XSS) by yourself just by looking at the HTML code.'), | |
| 1754 | ); | |
| efbffe46 | 1755 | |
| 0c87a920 WW |
1756 | $form['fckeditor_exclude_settings'] = array( |
| 1757 | '#type' => 'fieldset', | |
| 1758 | '#title' => t('Visibility settings'), | |
| 1759 | '#collapsible' => TRUE, | |
| 1760 | '#collapsed' => TRUE, | |
| 1761 | ); | |
| 1762 | ||
| 1763 | $form['fckeditor_exclude_settings']['min_rows'] = array( | |
| 1764 | '#type' => 'textfield', | |
| 1765 | '#title' => t('Minimum rows'), | |
| d7fbc905 | 1766 | '#default_value' => !empty($edit->settings['min_rows']) ? $edit->settings['min_rows'] : '5', |
| 0c87a920 WW |
1767 | '#description' => t("FCKeditor will be triggered if the textarea has more rows than entered here. Enter '1' if you do not want to use this feature."), |
| 1768 | ); | |
| 1769 | ||
| 1770 | $form['fckeditor_exclude_settings']['excl_mode'] = array( | |
| 8de1e54a | 1771 | '#type' => 'select', |
| 0c87a920 | 1772 | '#title' => t('Use inclusion or exclusion mode'), |
| 09aae5b1 | 1773 | '#default_value' => (empty($edit->settings['excl_mode']) || in_array($edit->settings['excl_mode'], array(0, 2))) ? 0 : 1, |
| 8de1e54a WW |
1774 | '#options' => array('0' => t('exclude'), '1' => t('include')), |
| 1775 | '#description' => t('Choose the way of disabling/enabling FCKeditor on selected fields/paths (see below). Use exclude to disable FCKeditor on selected fields/paths. Use include if you want to load FCKeditor only on selected paths/fields.'), | |
| 0c87a920 WW |
1776 | ); |
| 1777 | ||
| 1778 | /** | |
| 1779 | * get excluded fields - so we can have normal textareas too | |
| 1780 | * split the phrase by any number of commas or space characters, | |
| 1781 | * which include " ", \r, \t, \n and \f | |
| 1782 | */ | |
| 8de1e54a | 1783 | $form['fckeditor_exclude_settings']['excl_fields'] = array( |
| 0c87a920 | 1784 | '#type' => 'textarea', |
| 8de1e54a | 1785 | '#title' => t('Fields to exclude/include'), |
| 0c87a920 WW |
1786 | '#cols' => 60, |
| 1787 | '#rows' => 5, | |
| 8de1e54a WW |
1788 | '#prefix' => '<div style="margin-left:20px">', |
| 1789 | '#suffix' => '</div>', | |
| d7fbc905 | 1790 | '#default_value' => !empty($edit->settings['excl_fields']) ? $edit->settings['excl_fields'] : '', |
| a2e37d18 | 1791 | '#description' => t("Enter names (HTML ID's) of fields that may or may not have an FCKeditor, depending on the chosen option for the inclusion/exclusion mode.<br />You may separate the different entries by commas, spaces or newlines.<br />You may also use * as a wildcard character."), |
| 0c87a920 WW |
1792 | ); |
| 1793 | ||
| 1794 | /** | |
| 8de1e54a | 1795 | * get excluded paths - so we can have normal textareas too |
| 0c87a920 WW |
1796 | * split the phrase by any number of commas or space characters, |
| 1797 | * which include " ", \r, \t, \n and \f | |
| 1798 | */ | |
| 8de1e54a | 1799 | $form['fckeditor_exclude_settings']['excl_paths'] = array( |
| 0c87a920 | 1800 | '#type' => 'textarea', |
| 8de1e54a WW |
1801 | '#title' => t('Paths to exclude/include'), |
| 1802 | '#prefix' => '<div style="margin-left:20px">', | |
| 1803 | '#suffix' => '</div>', | |
| 0c87a920 WW |
1804 | '#cols' => 60, |
| 1805 | '#rows' => 5, | |
| d7fbc905 | 1806 | '#default_value' => !empty($edit->settings['excl_paths']) ? $edit->settings['excl_paths'] : '', |
| 8de1e54a WW |
1807 | '#description' => t("Enter drupal paths here, depending on the chosen option for the inclusion/exclusion mode.<br />Paths may be used the same way as in the drupal blocks configuration.<br />You may separate the different entries by commas, spaces or newlines. <br />You may also use * as a wildcard character (for example <code>comment/*</code>)."), |
| 1808 | ); | |
| 1809 | ||
| 1810 | $form['fckeditor_exclude_settings']['simple_incl_fields'] = array( | |
| 1811 | '#type' => 'textarea', | |
| 1812 | '#title' => t('Force simplified toolbar on the following fields'), | |
| 1813 | '#cols' => 60, | |
| 1814 | '#rows' => 5, | |
| 1815 | //'#prefix' => t('Here you can define where FCKeditor should force the <code>!simple</code> toolbar.<br/>Useful for smaller textareas where we usually don\'t use very complicated HTML code, like in signatures.', array('!simple' => FCKEDITOR_FORCE_SIMPLE_TOOLBAR_NAME)), | |
| d7fbc905 | 1816 | '#default_value' => !empty($edit->settings['simple_incl_fields']) ? $edit->settings['simple_incl_fields'] : '', |
| 8de1e54a WW |
1817 | '#description' => t("Enter names (HTML ID's) of fields that should have the simplified toolbar.<br />If you don't want to use this feature, simply leave this field empty.<br />You may separate the different entries by commas, spaces or newlines."), |
| 1818 | ); | |
| 1819 | ||
| 1820 | $form['fckeditor_exclude_settings']['simple_incl_paths'] = array( | |
| 1821 | '#type' => 'textarea', | |
| 1822 | '#title' => t('Force simplified toolbar on the following paths'), | |
| 1823 | '#cols' => 60, | |
| 1824 | '#rows' => 5, | |
| 1825 | //'#prefix' => t('Here you can define where FCKeditor should force the <code>!simple</code> toolbar.<br/>Useful for smaller textareas where we usually don\'t use very complicated HTML code, like in signatures.', array('!simple' => FCKEDITOR_FORCE_SIMPLE_TOOLBAR_NAME)), | |
| d7fbc905 | 1826 | '#default_value' => !empty($edit->settings['simple_incl_paths']) ? $edit->settings['simple_incl_paths'] : '', |
| 8de1e54a WW |
1827 | '#description' => t("Enter drupal paths that should have the simplified toolbar.<br />If you don't want to use this feature, simply leave this field empty.<br />Paths may be used the same way as in the drupal blocks configuration.<br />You may separate the different entries by commas, spaces or newlines.<br />You may also use * as a wildcard character (for example <code>comment/*</code>)."), |
| 1828 | ); | |
| 0c87a920 WW |
1829 | |
| 1830 | $form['appearance'] = array( | |
| 1831 | '#type' => 'fieldset', | |
| 1832 | '#title' => t('Editor appearance'), | |
| 1833 | '#collapsible' => TRUE, | |
| 1834 | '#collapsed' => TRUE, | |
| 1835 | ); | |
| 1836 | ||
| 1837 | $form['appearance']['default'] = array( | |
| 1838 | '#type' => 'select', | |
| 1839 | '#title' => t('Default state'), | |
| d7fbc905 | 1840 | '#default_value' => !empty($edit->settings['default']) ? $edit->settings['default'] : 't', |
| 8de1e54a | 1841 | '#options' => array('t' => t('enabled'), 'f' => t('disabled')), |
| 0c87a920 WW |
1842 | '#description' => t('Default editor state. If disabled, rich text editor may still be enabled using toggle or popup window.'), |
| 1843 | ); | |
| 1844 | ||
| 1845 | $form['appearance']['show_toggle'] = array( | |
| 1846 | '#type' => 'select', | |
| 1847 | '#title' => t('Show disable/enable rich text editor toggle'), | |
| d7fbc905 | 1848 | '#default_value' => !empty($edit->settings['show_toggle']) ? $edit->settings['show_toggle'] : 't', |
| 0c87a920 WW |
1849 | '#options' => array('t' => t('true'), 'f' => t('false')), |
| 1850 | '#description' => t('Whether or not to show the disable/enable rich text editor toggle below the textarea. Works only if FCKeditor is not running in a popup window (see below).'), | |
| 1851 | ); | |
| 1852 | ||
| 1853 | $form['appearance']['popup'] = array( | |
| 1854 | '#type' => 'select', | |
| 1855 | '#title' => t('Use FCKeditor in a popup window'), | |
| d7fbc905 | 1856 | '#default_value' => !empty($edit->settings['popup']) ? $edit->settings['popup'] : 'f', |
| 0c87a920 WW |
1857 | '#options' => array('f' => t('false'), 't' => t('true')), |
| 1858 | '#description' => t('If this option is enabled a link to a popup window will be used instead of a textarea replace.'), | |
| 1859 | ); | |
| 1860 | ||
| 1861 | $form['appearance']['skin'] = array( | |
| 1862 | '#type' => 'select', | |
| 1863 | '#title' => t('Skin'), | |
| d7fbc905 | 1864 | '#default_value' => !empty($edit->settings['skin']) ? $edit->settings['skin'] : 'default', |
| 0c87a920 WW |
1865 | '#options' => $skin_options, |
| 1866 | '#description' => t('Choose a default skin.'), | |
| 1867 | ); | |
| 1868 | ||
| 1869 | $form['appearance']['toolbar'] = array( | |
| 1870 | '#type' => 'select', | |
| 1871 | '#title' => t('Toolbar'), | |
| d7fbc905 | 1872 | '#default_value' => !empty($edit->settings['toolbar']) ? $edit->settings['toolbar'] : 'default', |
| 0c87a920 WW |
1873 | '#options' => $toolbar_options, |
| 1874 | '#description' => t('Choose a default toolbar set. To define new toolbar, edit <code>fckeditor.config.js</code> located in !module_path.', array('!module_path' => drupal_get_path('module', 'fckeditor'))), | |
| 1875 | ); | |
| 1876 | ||
| 1877 | $form['appearance']['expand'] = array( | |
| 1878 | '#type' => 'select', | |
| 1879 | '#title' => t('Start the toolbar expanded'), | |
| d7fbc905 | 1880 | '#default_value' => !empty($edit->settings['expand']) ? $edit->settings['expand'] : 't', |
| 0c87a920 WW |
1881 | '#options' => array('t' => t('enabled'), 'f' => t('disabled')), |
| 1882 | '#description' => t('The toolbar start expanded or collapsed.'), | |
| 1883 | ); | |
| 1884 | ||
| 1885 | $form['appearance']['width'] = array( | |
| 1886 | '#type' => 'textfield', | |
| 1887 | '#title' => t('Width'), | |
| d7fbc905 | 1888 | '#default_value' => !empty($edit->settings['width']) ? $edit->settings['width'] : '100%', |
| 0c87a920 WW |
1889 | '#description' => t("Width in pixels or percent. Ex: 400 or 100%"), |
| 1890 | '#size' => 40, | |
| 1891 | '#maxlength' => 128, | |
| 1892 | ); | |
| 1893 | ||
| 1894 | $form['appearance']['lang'] = array( | |
| 1895 | '#type' => 'select', | |
| 1896 | '#title' => t('Language'), | |
| d7fbc905 | 1897 | '#default_value' => !empty($edit->settings['lang']) ? $edit->settings['lang'] : 'en', |
| 0c87a920 WW |
1898 | '#options' => $lang_options, |
| 1899 | '#description' => t('The language for the FCKeditor interface.') | |
| 1900 | ); | |
| 1901 | ||
| 1902 | $form['appearance']['auto_lang'] = array( | |
| 1903 | '#type' => 'select', | |
| 1904 | '#title' => t('Auto-detect language'), | |
| d7fbc905 | 1905 | '#default_value' => !empty($edit->settings['auto_lang']) ? $edit->settings['auto_lang'] : 't', |
| 0c87a920 WW |
1906 | '#options' => array('t' => t('true'), 'f' => t('false')), |
| 1907 | '#description' => t('Use auto detect user language feature.') | |
| 1908 | ); | |
| 1909 | ||
| 8de1e54a WW |
1910 | /* |
| 1911 | $form['appearance']['appearance_conf'] = array( | |
| 1912 | '#type' => 'select', | |
| 1913 | '#title' => t('Ignore this section, use default settings defined in config files'), | |
| 1914 | '#default_value' => $edit->settings['appearance_conf'] ? $edit->settings['appearance_conf'] : 'f', | |
| 1915 | '#options' => array('f' => t('false'), 't' => t('true')), | |
| 1916 | '#description' => t('Although it is less handy, defining settings only in config files (<code>fckconfig.js</code> and <code>fckeditor.config.js</code>) will slightly leverage your traffic and improve load time of your site. <br/>Warning: if set to true, all changes made in <code>Editor appearance</code> will have no affect on FCKeditor\'s behaviour.'), | |
| 1917 | ); | |
| 1918 | */ | |
| 0c87a920 WW |
1919 | |
| 1920 | $form['output'] = array( | |
| 1921 | '#type' => 'fieldset', | |
| 1922 | '#title' => t('Cleanup and output'), | |
| 1923 | '#collapsible' => TRUE, | |
| 1924 | '#collapsed' => TRUE, | |
| 1925 | ); | |
| 1926 | ||
| 1927 | $form['output']['enter_mode'] = array( | |
| 1928 | '#type' => 'select', | |
| 1929 | '#title' => t('Enter mode'), | |
| d7fbc905 | 1930 | '#default_value' => !empty($edit->settings['enter_mode']) ? $edit->settings['enter_mode'] : 'p', |
| 0c87a920 WW |
1931 | '#options' => array('p' => '<p>', 'br' => '<br>', 'div' => '<div>'), |
| 1932 | '#description' => t('Set which tag FCKeditor should use when [Enter] key is pressed.') | |
| 1933 | ); | |
| 1934 | ||
| 1935 | $form['output']['shift_enter_mode'] = array( | |
| 1936 | '#type' => 'select', | |
| 1937 | '#title' => t('Shift + Enter mode'), | |
| d7fbc905 | 1938 | '#default_value' => !empty($edit->settings['shift_enter_mode']) ? $edit->settings['shift_enter_mode'] : 'br', |
| 0c87a920 WW |
1939 | '#options' => array('p' => '<p>', 'br' => '<br>', 'div' => '<div>'), |
| 1940 | '#description' => t('Set which tag FCKeditor should use when [Shift] + [Enter] is pressed.') | |
| 1941 | ); | |
| 1942 | ||
| 1943 | $form['output']['font_format'] = array( | |
| 1944 | '#type' => 'textfield', | |
| 1945 | '#title' => t('Font formats'), | |
| d7fbc905 | 1946 | '#default_value' => !empty($edit->settings['font_format']) ? $edit->settings['font_format'] : 'p;div;pre;address;h1;h2;h3;h4;h5;h6', |
| 0c87a920 WW |
1947 | '#size' => 40, |
| 1948 | '#maxlength' => 250, | |
| 1949 | '#description' => t('Semicolon separated list of HTML font formats. Allowed values are: p;div;pre;address;h1;h2;h3;h4;h5;h6'), | |
| 1950 | ); | |
| 1951 | ||
| 1952 | $form['output']['format_source'] = array( | |
| 1953 | '#type' => 'select', | |
| 1954 | '#title' => t('Apply source formatting'), | |
| d7fbc905 | 1955 | '#default_value' => !empty($edit->settings['format_source']) ? $edit->settings['format_source'] : 't', |
| 1507d7d9 | 1956 | '#options' => array('t' => t('true'), 'f' => ('false')), |
| 0c87a920 WW |
1957 | '#description' => t('When set to "true" the editor will format the XHTML when switching from WYSIWYG view to Source view, by inserting line breaks on some tags endings and indenting paragraphs, tables and lists.'), |
| 1958 | ); | |
| 1959 | ||
| 1960 | $form['output']['format_output'] = array( | |
| 1961 | '#type' => 'select', | |
| 1962 | '#title' => t('Format output'), | |
| d7fbc905 | 1963 | '#default_value' => !empty($edit->settings['format_output']) ? $edit->settings['format_output'] : 't', |
| 1507d7d9 | 1964 | '#options' => array('t' => t('true'), 'f' => t('false')), |
| 0c87a920 WW |
1965 | '#description' => t('When set to "true" the editor will format the XHTML output by inserting line breaks on some tags endings and indenting paragraphs, tables and lists.'), |
| 1966 | ); | |
| 1967 | ||
| 8de1e54a WW |
1968 | /* |
| 1969 | $form['output']['output_conf'] = array( | |
| 1970 | '#type' => 'select', | |
| 1971 | '#title' => t('Ignore this section, use default settings defined in config files'), | |
| 1972 | '#default_value' => $edit->settings['output_conf'] ? $edit->settings['output_conf'] : 'f', | |
| 1973 | '#options' => array('f' => t('false'), 't' => t('true')), | |
| 1974 | '#description' => t('Although it is less handy, defining settings only in config files (<code>fckconfig.js</code> and <code>fckeditor.config.js</code>) will slightly leverage your traffic and improve load time of your site. <br/>Warning: if set to true, all changes made in <code>Cleanup and output</code> will have no affect on FCKeditor\'s behaviour.'), | |
| 1975 | ); | |
| 1976 | */ | |
| 0c87a920 WW |
1977 | |
| 1978 | $form['css'] = array( | |
| 1979 | '#type' => 'fieldset', | |
| 1980 | '#title' => t('CSS'), | |
| 1981 | '#collapsible' => TRUE, | |
| 1982 | '#collapsed' => TRUE | |
| 1983 | ); | |
| 1984 | ||
| 1985 | $form['css']['css_mode'] = array( | |
| 1986 | '#type' => 'select', | |
| 1987 | '#title' => t('Editor CSS'), | |
| d7fbc905 | 1988 | '#default_value' => !empty($edit->settings['css_mode']) ? $edit->settings['css_mode'] : 'theme', |
| 0c87a920 WW |
1989 | '#options' => array('theme' => t('use theme css'), 'self' => t('define css'), 'none' => t('FCKeditor default')), |
| 1990 | '#description' => t('Defines the CSS to be used in the editor area.<br />use theme css - load style.css from current site theme.<br/>define css - enter path for css file below.<br />FCKeditor default - uses default CSS from editor.') | |
| 1991 | ); | |
| 1992 | ||
| 1993 | $form['css']['css_path'] = array( | |
| 1994 | '#type' => 'textfield', | |
| 1995 | '#title' => t('CSS path'), | |
| d7fbc905 | 1996 | '#default_value' => !empty($edit->settings['css_path']) ? $edit->settings['css_path'] : "", |
| 0c87a920 WW |
1997 | '#size' => 40, |
| 1998 | '#maxlength' => 255, | |
| 0ee41c0b | 1999 | '#description' => t('Enter path to CSS file (<em>example: css/editor.css</em>) or a list of css files seperated by a comma (<em>example: /themes/garland/style.css,http://example.com/style.css</em>).<br />Macros: %h (host name: !host), %t (path to theme: !theme)<br />Be sure to select "define css" above.', array('!host' => base_path(), '!theme' => base_path() . path_to_theme() .'/')) |
| 0c87a920 WW |
2000 | ); |
| 2001 | ||
| 2002 | $form['css']['css_style'] = array( | |
| 8de1e54a WW |
2003 | '#type' => 'select', |
| 2004 | '#title' => t('Predefined styles'), | |
| d7fbc905 | 2005 | '#default_value' => !empty($edit->settings['css_style']) ? $edit->settings['css_style'] : 'theme', |
| 8de1e54a WW |
2006 | '#options' => array('theme' => t('use theme fckstyles.xml'), 'self' => t('define path to fckstyles.xml'), 'default' => t('FCKeditor default')), |
| 2007 | '#description' => t('Define the location of <code>fckstyles.xml</code> file. It is used by the "Style" dropdown list available in the Default toolbar.<br />Copy !fckstyles.xml inside your theme directory (<code>!theme</code>) and adjust it to your needs.', array('!fckstyles.xml' => drupal_get_path('module', 'fckeditor') .'/fckeditor/fckstyles.xml', '!theme' => path_to_theme() .'/fckstyles.xml')) | |
| 0c87a920 WW |
2008 | ); |
| 2009 | ||
| 8de1e54a WW |
2010 | $form['css']['styles_path'] = array( |
| 2011 | '#type' => 'textfield', | |
| 2012 | '#title' => t('Predefined styles path'), | |
| d7fbc905 | 2013 | '#default_value' => !empty($edit->settings['styles_path']) ? $edit->settings['styles_path'] : "", |
| 8de1e54a WW |
2014 | '#size' => 40, |
| 2015 | '#maxlength' => 255, | |
| 0ee41c0b | 2016 | '#description' => t('Enter path to XML file with predefined styles (<em>example: /fckstyles.xml</em>).<br />Macros: %h (host name: !host), %t (path to theme: !theme), %m (path to FCKeditor module: !module)<br />Be sure to select "define path to fckstyles.xml" above.', array('!host' => base_path(), '!theme' => base_path() . path_to_theme() .'/', '!module' => drupal_get_path('module', 'fckeditor'))) |
| 0c87a920 | 2017 | ); |
| 8de1e54a | 2018 | |
| d3cf16a0 WW |
2019 | $form['fckeditor_upload_settings'] = array( |
| 2020 | '#type' => 'fieldset', | |
| 2021 | '#title' => t('File browser settings'), | |
| 2022 | '#collapsible' => TRUE, | |
| 2023 | '#collapsed' => TRUE, | |
| 7d26d749 | 2024 | '#description' => t('Set file browser settings. A file browser will allow you to explore the files contained on the server and embed them as links, images or flash movies. Besides the built-in FCKeditor file browser, you can also use a contributed module like !imce or !ib. The quick upload setting controls whether images, flash movies and files can be uploaded using the Upload tab of the respective dialogs. Please note that these options require manual configuration, check !readme for more information.<br />', |
| 8de1e54a WW |
2025 | array( |
| 2026 | '!imce' => l(t('IMCE'), 'http://drupal.org/project/imce'), | |
| 7d26d749 | 2027 | '!ib' => l(t('Image Browser'), 'http://drupal.org/project/imagebrowser'), |
| 8de1e54a WW |
2028 | '!readme' => l('readme.txt', 'admin/help/fckeditor'), |
| 2029 | ) | |
| 2030 | ) | |
| d3cf16a0 | 2031 | ); |
| 924d15ba WW |
2032 | |
| 2033 | $filebrowsers = array( | |
| 2034 | 'none' => t('None'), | |
| 2035 | 'builtin' => t('Built-in filebrowser'), | |
| d3cf16a0 | 2036 | ); |
| 924d15ba WW |
2037 | |
| 2038 | if (module_exists('imce')) { | |
| 2039 | $filebrowsers['imce'] = t('IMCE'); | |
| d3cf16a0 | 2040 | } |
| cc735e40 WW |
2041 | |
| 2042 | if (module_exists('imagebrowser')) { | |
| 2043 | $filebrowsers['ib'] = t('Image Browser'); | |
| 2044 | } | |
| 2045 | ||
| 924d15ba | 2046 | $form['fckeditor_upload_settings']['filebrowser'] = array( |
| 8de1e54a | 2047 | '#type' => 'select', |
| 924d15ba WW |
2048 | '#options' => $filebrowsers, |
| 2049 | '#title' => t('File browser type'), | |
| 2050 | '#default_value' => !empty($edit->settings['filebrowser']) ? $edit->settings['filebrowser'] : 'none', | |
| 2051 | '#description' => t('Select the file browser that you would like to use to upload files, images and flash movies.'), | |
| 2052 | ); | |
| 2053 | ||
| 2054 | $form['fckeditor_upload_settings']['quickupload'] = array( | |
| 8de1e54a WW |
2055 | '#type' => 'select', |
| 2056 | '#options' => array('f' => t('false'), 't' => t('true')), | |
| 924d15ba WW |
2057 | '#title' => t('Allow quick uploads'), |
| 2058 | '#default_value' => !empty($edit->settings['quickupload']) ? $edit->settings['quickupload'] : 'f', | |
| cc735e40 | 2059 | '#description' => t('The quick upload functionality can be disabled and enabled independently of the file browser. It will always use the settings below. To enable quick uploads you must follow the same configuration procedure as when enabling the built-in file browser.'), |
| 924d15ba WW |
2060 | ); |
| 2061 | ||
| 2062 | $current_user_files_path = empty($edit->settings['UserFilesPath']) ? "" : strtr($edit->settings['UserFilesPath'], array("%f" => file_directory_path(), "%u" => "UID", "%b" => base_path())); | |
| 2063 | $current_user_files_absolute_path = empty($edit->settings['UserFilesAbsolutePath']) ? "" : strtr($edit->settings['UserFilesAbsolutePath'], array("%f" => file_directory_path(), "%u" => "UID", "%b" => base_path(), "%d" => $_SERVER['DOCUMENT_ROOT'])); | |
| 8de1e54a | 2064 | |
| 924d15ba | 2065 | $form['fckeditor_upload_settings']['UserFilesPath'] = array( |
| 8de1e54a WW |
2066 | '#type' => 'textfield', |
| 2067 | '#title' => t('Path to uploaded files'), | |
| d7fbc905 | 2068 | '#default_value' => !empty($edit->settings['UserFilesPath']) ? $edit->settings['UserFilesPath'] : "%b%f/", |
| 8de1e54a WW |
2069 | '#size' => 40, |
| 2070 | '#maxlength' => 255, | |
| 2071 | '#description' => t('Path to uploaded files relative to the document root.<br />Available wildcard characters:<br/><strong>%b</strong> - base URL path of the Drupal installation (!base).<br/><strong>%f</strong> - Drupal file system path where the files are stored (!files).<br /><strong>%u</strong> - User ID.<br />Current path: !path', array('!path' => $current_user_files_path, '!files' => file_directory_path(), '!base' => base_path())), | |
| 924d15ba | 2072 | ); |
| 5b62271f | 2073 | |
| 924d15ba | 2074 | $form['fckeditor_upload_settings']['UserFilesAbsolutePath'] = array( |
| 8de1e54a WW |
2075 | '#type' => 'textfield', |
| 2076 | '#title' => t('Absolute path to uploaded files'), | |
| d7fbc905 | 2077 | '#default_value' => !empty($edit->settings['UserFilesAbsolutePath']) ? $edit->settings['UserFilesAbsolutePath'] : "%d%b%f/", |
| 8de1e54a WW |
2078 | '#size' => 40, |
| 2079 | '#maxlength' => 255, | |
| 2080 | '#description' => t('The path to the local directory (in the server) which points to the path defined above. If empty, FCKeditor will try to discover the right path.<br />Available wildcard characters:<br/><strong>%d</strong> - server path to document root (!root).<br /><strong>%b</strong> - base URL path of the Drupal installation (!base).<br/><strong>%f</strong> - Drupal file system path where the files are stored (!files).<br /><strong>%u</strong> - User ID.<br />Current path: !path', array('!path' => $current_user_files_absolute_path, '!files' => file_directory_path(), '!base' => base_path(), '!root' => $_SERVER['DOCUMENT_ROOT'])), | |
| 924d15ba | 2081 | ); |
| 5b62271f WW |
2082 | |
| 2083 | if (variable_get('file_downloads', '') == FILE_DOWNLOADS_PRIVATE) { | |
| bbb4a78f | 2084 | $form['fckeditor_upload_settings']['UserFilesPath']['#description'] = t('Setting relative path to uploaded files has been disabled because private downloads are enabled and this path is calculated automatically. To change the location of uploaded files in the private file system, edit the <a href="!url">FCKeditor Global Profile</a>.', array('!url' => url('admin/settings/fckeditor/editg'))); |
| cc67ac84 | 2085 | $form['fckeditor_upload_settings']['UserFilesPath']['#disabled'] = TRUE; |
| bbb4a78f | 2086 | $form['fckeditor_upload_settings']['UserFilesAbsolutePath']['#description'] = t('Setting path to uploaded files has been disabled because private downloads are enabled and this path is calculated automatically.To change the location of uploaded files in the private file system, edit the <a href="!url">FCKeditor Global Profile</a>.', array('!global' => url('admin/settings/fckeditor/editg'))); |
| cc67ac84 | 2087 | $form['fckeditor_upload_settings']['UserFilesAbsolutePath']['#disabled'] = TRUE; |
| 5b62271f WW |
2088 | } |
| 2089 | ||
| 8de1e54a | 2090 | $form['advanced'] = array( |
| 0c87a920 | 2091 | '#type' => 'fieldset', |
| 8de1e54a | 2092 | '#title' => t('Advanced options'), |
| 0c87a920 WW |
2093 | '#collapsible' => TRUE, |
| 2094 | '#collapsed' => TRUE, | |
| 0c87a920 | 2095 | ); |
| 8de1e54a WW |
2096 | $form['advanced']['js_conf'] = array( |
| 2097 | '#type' => 'textarea', | |
| 2098 | '#title' => t('Custom javascript configuration'), | |
| d7fbc905 | 2099 | '#default_value' => !empty($edit->settings['js_conf']) ? $edit->settings['js_conf'] : "", |
| 8de1e54a WW |
2100 | '#cols' => 60, |
| 2101 | '#rows' => 5, | |
| 2102 | '#description' => t('Warning: to change FCKeditor configuration globally, you should modify the config file: <code>!fckeditor_config</code>.<br/>Sometimes it is required to change the FCKeditor configuration for selected profile. Use this box to define settings that are uniqe for this profile.<br/>Available options are listed in the !docs.<br/>Warning: if you make something wrong here, FCKeditor may fail to load.<br/>For example to disable some advanced tabs in dialog windows in FCKeditor, add the following: !example', | |
| 2103 | array( | |
| 2104 | '!fckeditor_config' => drupal_get_path('module', 'fckeditor') ."/fckeditor.config.js", | |
| 2105 | '!docs' => l(t("FCKeditor documentation"), "http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide/Configuration/Configuration_Options"), | |
| 2106 | "!example" => "<pre>LinkDlgHideTarget = true ; | |
| 2107 | LinkDlgHideAdvanced = true ; | |
| 2108 | ImageDlgHideLink = true ; | |
| 2109 | ImageDlgHideAdvanced = true ; | |
| 2110 | FlashDlgHideAdvanced = true ;</pre>") | |
| 2111 | )); | |
| 0c87a920 | 2112 | |
| a8e394de WW |
2113 | $form['submit'] = array( |
| 2114 | '#type' => 'submit', | |
| 2115 | '#value' => $btn | |
| 2116 | ); | |
| 0c87a920 WW |
2117 | |
| 2118 | return $form; | |
| 2119 | } | |
| 2120 | ||
| 2121 | /** | |
| e44c2389 | 2122 | * Search the field id for matches in array of matches |
| 2123 | * | |
| 2124 | * @param $search | |
| 2125 | * A string representing a form field id | |
| 2126 | * @ param $array | |
| 2127 | * An $array with strings to match the $search parameter against | |
| 2128 | * | |
| 2129 | * @return | |
| 2130 | * TRUE on match, FALSE on no match | |
| 23824481 | 2131 | */ |
| 2132 | function fckeditor_idsearch($search, $array) { | |
| 2133 | foreach ($array as $key => $value) { | |
| 8de1e54a | 2134 | if (!empty($value) && preg_match('/^'. str_replace('*', '.*', addslashes($value)) .'$/i', $search)) { |
| 23824481 | 2135 | // on any first match we know we're done here so return positive |
| cc67ac84 | 2136 | return TRUE; |
| f3d88ca0 | 2137 | } |
| f3d88ca0 | 2138 | } |
| cc67ac84 | 2139 | return FALSE; |
| f3d88ca0 | 2140 | } |
| 04b827fa DS |
2141 | |
| 2142 | /** | |
| e44c2389 | 2143 | * Test if client can render the FCKeditor |
| 0c87a920 WW |
2144 | * Use built-in test method in fckeditor.php |
| 2145 | * If fckeditor.php is not found, return false (probably in such case fckeditor is not installed correctly) | |
| e44c2389 | 2146 | * |
| 2147 | * @return | |
| 2148 | * TRUE if the browser is reasonably capable | |
| 04b827fa DS |
2149 | */ |
| 2150 | function fckeditor_is_compatible_client() { | |
| 231f8c3f WW |
2151 | $fckeditor_main_file = drupal_get_path('module', 'fckeditor') .'/fckeditor/fckeditor.php'; |
| 2152 | if (!function_exists('version_compare') || version_compare(phpversion(), '5', '<')) { | |
| 2153 | $fckeditor_target_file = drupal_get_path('module', 'fckeditor') .'/fckeditor/fckeditor_php4.php'; | |
| 2154 | } | |
| 2155 | else { | |
| 2156 | $fckeditor_target_file = drupal_get_path('module', 'fckeditor') .'/fckeditor/fckeditor_php5.php'; | |
| 2157 | } | |
| c8fbe8d0 | 2158 | |
| 231f8c3f WW |
2159 | if (file_exists($fckeditor_target_file)) { |
| 2160 | include_once $fckeditor_target_file; | |
| 2161 | //FCKeditor 2.6.1+ | |
| 0c87a920 WW |
2162 | if (function_exists('FCKeditor_IsCompatibleBrowser')) { |
| 2163 | return FCKeditor_IsCompatibleBrowser(); | |
| 2164 | } | |
| c8fbe8d0 | 2165 | else if (class_exists('FCKeditor')) { |
| 231f8c3f WW |
2166 | //FCKeditor 2.6 with definition of FCKeditor_IsCompatibleBrowser() in fckeditor.php |
| 2167 | if (filesize($fckeditor_main_file) > 1500) { | |
| 2168 | include_once $fckeditor_main_file; | |
| 2169 | } | |
| 2170 | //FCKeditor 2.5.1 and earlier | |
| c8fbe8d0 | 2171 | $fck = new FCKeditor('fake'); |
| 0c87a920 WW |
2172 | return $fck->IsCompatible(); |
| 2173 | } | |
| 2174 | } | |
| 2175 | ||
| cc67ac84 | 2176 | return FALSE; |
| 0c87a920 WW |
2177 | } |
| 2178 | ||
| 8de1e54a | 2179 | function fckeditor_user_get_setting($user, $profile, $setting) { |
| 0c87a920 WW |
2180 | $default = array( |
| 2181 | 'default' => 't', | |
| 2182 | 'show_toggle' => 't', | |
| 2183 | 'popup' => 'f', | |
| 2184 | 'skin' => 'default', | |
| 2185 | 'toolbar' => 'default', | |
| 2186 | 'expand' => 't', | |
| 2187 | 'width' => '100%', | |
| 2188 | 'lang' => 'en', | |
| 2189 | 'auto_lang' => 't', | |
| 2190 | ); | |
| 2191 | $settings = $profile->settings; | |
| 2192 | ||
| 2193 | if ($settings['allow_user_conf']) { | |
| 8de1e54a | 2194 | $status = isset($user->{"fckeditor_". $setting}) ? $user->{"fckeditor_". $setting} : (isset($settings[$setting]) ? $settings[$setting] : $default[$setting]); |
| 04b827fa | 2195 | } |
| 0c87a920 WW |
2196 | else { |
| 2197 | $status = isset($settings[$setting]) ? $settings[$setting] : $default[$setting]; | |
| 04b827fa | 2198 | } |
| 0c87a920 WW |
2199 | |
| 2200 | return $status; | |
| 2201 | } | |
| 2202 | ||
| 8bdf4d22 WW |
2203 | function fckeditor_user_get_profile($user) { |
| 2204 | static $profile_name; | |
| 2205 | ||
| 2206 | // Since fckeditor_profile_load() makes a db hit, only call it when we're pretty sure | |
| 2207 | // we're gonna render fckeditor. | |
| 2208 | if (!isset($profile_name[$user->uid])) { | |
| 2209 | $sorted_roles = fckeditor_sorted_roles(); | |
| 2210 | foreach ($sorted_roles as $rid => $name) { | |
| 2211 | if (isset($user->roles[$rid])) { | |
| 2212 | break; | |
| 2213 | } | |
| 2214 | } | |
| 2215 | ||
| db7eae46 | 2216 | if (isset($rid) && isset($user->roles[$rid])) { |
| 8bdf4d22 WW |
2217 | $profile_name[$user->uid] = db_result(db_query("SELECT s.name FROM {fckeditor_settings} s INNER JOIN {fckeditor_role} r ON r.name = s.name WHERE r.rid='%s'", $rid)); |
| 2218 | } | |
| 2219 | else if ($user->uid == "1") { | |
| 45c06da2 | 2220 | $profile_name[$user->uid] = db_result(db_query_range("SELECT s.name FROM {fckeditor_settings} s INNER JOIN {fckeditor_role} r ON r.name = s.name ORDER BY r.rid DESC", 1)); |
| 8bdf4d22 | 2221 | } |
| 0c87a920 | 2222 | } |
| d3cf16a0 | 2223 | |
| 8bdf4d22 WW |
2224 | if (isset($profile_name[$user->uid]) && $profile_name[$user->uid]) { |
| 2225 | $profile = fckeditor_profile_load($profile_name[$user->uid]); | |
| 2226 | return $profile; | |
| 0c87a920 | 2227 | } |
| d3cf16a0 | 2228 | |
| cc67ac84 | 2229 | return FALSE; |
| 0c87a920 WW |
2230 | } |
| 2231 | ||
| 2232 | function fckeditor_init() { | |
| 2233 | drupal_add_css(drupal_get_path('module', 'fckeditor') .'/fckeditor.css'); | |
| fbb0fa65 | 2234 | } |
| cc0fc71b WW |
2235 | |
| 2236 | function fckeditor_ask_delete_confirmation($is_global, $profile = "") { | |
| 2237 | if (!$is_global) { | |
| 2238 | $delete_link = l(t('Yes, delete!'), 'admin/settings/fckeditor/deleteconfirmed/'. urlencode($profile)); | |
| 2239 | $profile_name = t('!profile profile', array('!profile' => $profile)); | |
| 2240 | } | |
| 2241 | else { | |
| 2242 | $delete_link = l(t('Yes, delete!'), 'admin/settings/fckeditor/deletegconfirmed'); | |
| 2243 | $profile_name = t('Global Profile'); | |
| 2244 | } | |
| 2245 | ||
| 2246 | drupal_set_title(t('Confirm profile deletion')); | |
| 2247 | drupal_set_message(t("You're about to delete the FCKeditor profile, read the question below carefully."), "warning"); | |
| 2248 | ||
| 2249 | return t("<p>Are you sure that you want to delete the !profile?</p><p>!yes !no</p>", | |
| 2250 | array('!profile' => $profile_name, | |
| 2251 | '!yes' => $delete_link, | |
| cc67ac84 | 2252 | '!no' => l(t('Cancel'), 'admin/settings/fckeditor', array('attributes' => array('style' => 'margin-left:40px'))), |
| cc0fc71b WW |
2253 | )); |
| 2254 | } | |
| b202a8cf WW |
2255 | |
| 2256 | /** | |
| 2257 | * Implementation of hook_file_download(). | |
| 2258 | * Support for private downloads. | |
| 0a4de7b0 | 2259 | * FCKeditor does not implement any kind of potection on private files. |
| b202a8cf WW |
2260 | */ |
| 2261 | function fckeditor_file_download($file) { | |
| 0a4de7b0 WW |
2262 | if ($path = file_create_path($file)) { |
| 2263 | $result = db_query("SELECT f.* FROM {files} f WHERE filepath = '%s'", $path); | |
| 01139d56 | 2264 | if (db_fetch_object($result)) { |
| 0a4de7b0 WW |
2265 | return NULL; |
| 2266 | } | |
| 2267 | ||
| 2268 | //No info in DB? Probably a file uploaded with FCKeditor | |
| 2269 | $global_profile = fckeditor_profile_load("FCKeditor Global Profile"); | |
| 2270 | $global_conf = $global_profile->settings; | |
| 2271 | ||
| 2272 | //Assume that files inside of fckeditor directory belong to the FCKeditor. If private directory is set, let the decision about protection to the user. | |
| bbb4a78f | 2273 | $private_dir = isset($global_profile->settings['private_dir']) ? $global_profile->settings['private_dir'] : "/"; |
| 0a4de7b0 WW |
2274 | |
| 2275 | //If path to the file points to the FCKeditor private directory, allow downloading | |
| 2276 | if (strpos($path, file_directory_path() ."/". trim($private_dir, "/\\")) === 0) { | |
| 2277 | $ctype = ($info = @getimagesize($path)) ? $info['mime'] : (function_exists('mime_content_type') ? mime_content_type($path) : 'application/x-download'); | |
| 2278 | return array('Content-type: '. $ctype); | |
| b202a8cf WW |
2279 | } |
| 2280 | } | |
| dedd64a9 | 2281 | } |