summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWendy2007-02-07 12:18:21 (GMT)
committer Wendy2007-02-07 12:18:21 (GMT)
commit37e7f108dac4e1ef878c94ee0fa80603d54319e9 (patch)
treea598a23a68594c4fea2f0627e3886e75f79806a1
parentbd9ad03f4a975c54eaaa9353a1bc2798eaf48809 (diff)
*** empty log message ***
-rw-r--r--INSTALL.txt258
-rw-r--r--plugin_reg.php106
-rw-r--r--tinymce.install49
-rw-r--r--tinymce.module1161
4 files changed, 1497 insertions, 77 deletions
diff --git a/INSTALL.txt b/INSTALL.txt
new file mode 100644
index 0000000..df71dff
--- /dev/null
+++ b/INSTALL.txt
@@ -0,0 +1,258 @@
+********************************************************************
+ D R U P A L M O D U L E
+********************************************************************
+Name: TinyMCE module
+
+Maintainers: Theodore Serbinski <stanson AT gmail DOT com> and
+ Matt Westgate <drupal AT asitis DOT org> and
+ Jeff Robbins <robbins AT jjeff DOT com>
+ Richard Bennett <richard.b AT gritechnologies DOT com>
+
+
+
+Dependancies:
+ This module requires the third-party TinyMCE editor and a
+ Javascript-enabled web browser. Currently it is known to work
+ with Internet Explorer, Mozilla and Firefox and degrade gracefully
+ for Safari and Konqueror users. A browser compatibility chart is here:
+
+ http://tinymce.moxiecode.com/tinymce/docs/compatiblity_chart.html
+
+
+INSTALLATION:
+********************************************************************
+
+NOTE: During this installation process you'll be asked to also
+ install the official TinyMCE package from
+ tinymce.moxiecode.com.
+
+
+1. Place the entire tinymce directory into your Drupal modules/
+ directory.
+
+
+2. Download TinyMCE 2.0 from
+
+ http://tinymce.moxiecode.com/
+
+ Remember to uncompress the file and make sure the folder is named
+ 'tinymce'.
+
+
+3. Place the entire 'tinymce' engine folder inside your modules/tinymce
+ directory. So the TinyMCE engine will live in modules/tinymce/tinymce
+
+
+4. Enable this module by navigating to:
+
+ administer > modules
+
+ *note - all database tables will be automatically created during this step
+
+
+5. Setup role based tinymce profiles via
+
+ administer > settings > tinymce
+
+
+6. To boost the performance of TinyMCE, download the "TinyMCE compressor" from:
+
+ http://tinymce.moxiecode.com/download.php
+
+ Place the tiny_mce_gzip.php file in
+
+ modules/tinymce/tinymce/jscripts/tiny_mce
+
+
+7. To use AJAX spell checking, download the spellchecker plugin:
+ (note: this requires TinyMCE 2.0.6+)
+
+ http://tinymce.moxiecode.com/download.php
+
+ Extract this file to
+
+ modules/tinymce/tinymce/jscripts/tiny_mce/plugins/
+
+ Then edit config.php in plugins/spellchecker/:
+
+ Uncomment this line and comment out all other require_once's:
+
+ require_once("classes/TinyGoogleSpell.class.php"); // Google web service
+
+ Set this to true:
+
+ $spellCheckerConfig['enabled'] = true;
+
+ Enable spellchecker in TinyMCE settings page, under "buttons and plugins"
+
+
+
+Create new content as a role that has TinyMCE permissions and see TinyMCE in
+action!
+
+
+README:
+********************************************************************
+Once TinyMCE is enabled, the default behavior is that all textareas
+will use TinyMCE for all users. The admin can change these defaults
+at
+
+ administer > settings > tinymce
+
+The admin can choose what theme TinyMCE should be the default and
+user's can override this by editing their account (if they've been
+given permissions to do so). User's also have the option of disabling
+TinyMCE completely.
+
+The admin can also define which pages TinyMCE should be used on.
+This cannot be changed on a per user basis.
+
+
+PLUGINS FOR TINYMCE:
+********************************************************************
+Adding plugins to TinyMCE is very easy. By default, all TinyMCE
+plugins are disabled, but can easily be enabled by going to:
+
+ Administer > settings > tinymce
+
+And then editing a profile (make sure you create one first!) and going
+to the Buttons & Plugins section. To enable a button or a plugin,
+simply check a box and TinyMCE will automatically be updated. To find
+out more info on what a specific button or plugin does, click the
+corresponding link (note not all buttons have help text).
+
+If you wish to add more plugins to TinyMCE, simply extract these
+plugins to the folder: tinymce\jscripts\tiny_mce\plugins
+
+Then open up plugin_reg.php, found in the TinyMCE module folder.
+
+Add the following lines:
+
+ $plugins['plugin_name'] = array();
+ $plugins['plugin_name']['theme_advanced_buttons3'] = array('icon_name');
+ // note, you can choose which row of buttons to use by changing
+ // the 3 to either 1 or 2
+ $plugins['plugin_name']['plugin_property'] = array('property_value');
+
+Be sure to set the 'plugin_name' to the name of the plugin (generally
+the plugin folder name) and set the 'icon_name' and other properties
+(properties are optional). See plugin_reg.php for more examples.
+
+To add Drupal specific plugins, TinyMCE comes bundled with plugins
+in the main module directory. These plugins include:
+
+ - drupalimage: works in conjunction with the img_assist Drupal
+ module
+
+ NOTE: If you want to use img_assist with TinyMCE, you don't have to
+ install a plugin. Just enable the img_assist module and click
+ the photo icon that appears below each textarea.
+
+Follow the directions in the README.txt for these plugins to enable them.
+
+
+CAVEATS
+********************************************************************
+By default, Drupal uses the 'Filtered HTML' input format for adding
+content to the site and this can create conflicts with TinyMCE. It's
+best when using this editor to use an input format that has all
+filters disabled. What I usually do is create an input format called
+'Rich-text editing' and set that as the default format for roles which
+use TinyMCE exclusively. To modify your input formats go to:
+
+ Administer > input formats > configure > configure filters
+
+
+TWEAKING THE TINYMCE THEME
+********************************************************************
+
+Developers have complete control over when and how tinymce is enabled
+for each textarea inside Drupal by creating a custom Drupal theme
+function. The following example assumes you're using a phptemplate based theme.
+
+Put the following function in your themes template.php file:
+
+/**
+ * Customize a TinyMCE theme.
+ *
+ * @param init
+ * An array of settings TinyMCE should invoke a theme. You may override any
+ * of the TinyMCE settings. Details here:
+ *
+ * http://tinymce.moxiecode.com/wrapper.php?url=tinymce/docs/using.htm
+ *
+ * @param textarea_name
+ * The name of the textarea TinyMCE wants to enable.
+ *
+ * @param theme_name
+ * The default tinymce theme name to be enabled for this textarea. The
+ * sitewide default is 'simple', but the user may also override this.
+ *
+ * @param is_running
+ * A boolean flag that identifies id TinyMCE is currently running for this
+ * request life cycle. It can be ignored.
+ */
+function theme_tinymce_theme($init, $textarea_name, $theme_name, $is_running) {
+ switch ($textarea_name) {
+ // Disable tinymce for these textareas
+ case 'log': // book and page log
+ case 'img_assist_pages':
+ case 'caption': // signature
+ case 'pages':
+ case 'access_pages': //TinyMCE profile settings.
+ case 'user_mail_welcome_body': // user config settings
+ case 'user_mail_approval_body': // user config settings
+ case 'user_mail_pass_body': // user config settings
+ case 'synonyms': // taxonomy terms
+ case 'description': // taxonomy terms
+ unset($init);
+ break;
+
+ // Force the 'simple' theme for some of the smaller textareas.
+ case 'signature':
+ case 'site_mission':
+ case 'site_footer':
+ case 'site_offline_message':
+ case 'page_help':
+ case 'user_registration_help':
+ case 'user_picture_guidelines':
+ $init['theme'] = 'simple';
+ foreach ($init as $k => $v) {
+ if (strstr($k, 'theme_advanced_')) unset($init[$k]);
+ }
+ break;
+ }
+
+ /* Example, add some extra features when using the advanced theme.
+
+ // If $init is available, we can extend it
+ if (isset($init)) {
+ switch ($theme_name) {
+ case 'advanced':
+ $init['extended_valid_elements'] = array('a[href|target|name|title|onclick]');
+ break;
+ }
+ }
+
+ */
+
+ // Always return $init
+ return $init;
+}
+
+If you study the above function you can see that tinymce can be completely
+disabled or you can even switch themes for a given textarea.
+
+See the TinyMCE manual for details on the parameters that can be
+sent to TinyMCE:
+
+http://tinymce.moxiecode.com/documentation.php
+
+
+TINYMCE KEYBOARD SHORTCUTS
+********************************************************************
+Ctrl+Z Undo
+Ctrl+Y Redo
+Ctrl+B Bold
+Ctrl+I Italic
+Ctrl+U Underline
diff --git a/plugin_reg.php b/plugin_reg.php
new file mode 100644
index 0000000..893e13d
--- /dev/null
+++ b/plugin_reg.php
@@ -0,0 +1,106 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Registers TinyMCE plugins for the Drupal TinyMCE module. Note these settings
+ * can be overridden by each Drupal theme.
+ */
+
+function _tinymce_plugins() {
+
+/**
+ * A couple of notes about adding plugins.
+ *
+ * 1) Don't use any of the *_add or *_add_before hooks for theme button placement.
+ * Stick with theme_advanced_buttons1, theme_advanced_buttons2,
+ * theme_advanced_buttons3 only.
+ *
+ * 2) You can change the order of the buttons by moving the plugins around in
+ * this code. You can also change the order of the button array for each plugin.
+ */
+
+$plugins['advhr'] = array();
+$plugins['advhr']['theme_advanced_buttons3'] = array('advhr');
+$plugins['advhr']['extended_valid_elements'] = array('hr[class|width|size|noshade]');
+
+$plugins['advimage'] = array();
+$plugins['advimage']['extended_valid_elements'] = array('img[class|src|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name]');
+
+$plugins['advlink'] = array();
+$plugins['advlink']['extended_valid_elements'] = array('a[name|href|target|title|onclick]');
+
+$plugins['autosave'] = array();
+
+$plugins['contextmenu'] = array();
+
+// Note this isn't a true plugin, rather it's buttons made available by the advanced theme.
+$plugins['default'] = array();
+$plugins['default']['theme_advanced_buttons1'] = array('bold', 'italic', 'underline', 'strikethrough', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'bullist', 'numlist', 'outdent', 'indent', 'undo', 'redo', 'link', 'unlink', 'anchor');
+$plugins['default']['theme_advanced_buttons2'] = array('image', 'cleanup', 'forecolor', 'backcolor', 'sup', 'sub', 'code', 'hr');
+$plugins['default']['theme_advanced_buttons3'] = array('cut', 'copy', 'paste', 'visualaid', 'removeformat', 'charmap', 'help');
+
+$plugins['directionality'] = array();
+$plugins['directionality']['theme_advanced_buttons3'] = array('ltr', 'rtl');
+
+$plugins['emotions'] = array();
+$plugins['emotions']['theme_advanced_buttons3'] = array('emotions');
+
+$plugins['filemanager'] = array();
+
+$plugins['flash'] = array();
+$plugins['flash']['theme_advanced_buttons3'] = array('flash');
+$plugins['flash']['extended_valid_elements'] = array('img[class|src|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name|obj|param|embed]');
+
+// Note this isn't a true plugin, rather it's buttons made available by the advanced theme.
+$plugins['font'] = array();
+$plugins['font']['theme_advanced_buttons1'] = array('formatselect', 'fontselect', 'fontsizeselect', 'styleselect');
+$plugins['font']['extended_valid_elements'] = array('font[face|size|color|style],span[class|align|style]');
+
+$plugins['fullscreen'] = array();
+$plugins['fullscreen']['theme_advanced_buttons3'] = array('fullscreen');
+
+$plugins['iespell'] = array();
+$plugins['iespell']['theme_advanced_buttons3'] = array('iespell');
+
+$plugins['imagemanager'] = array();
+
+$plugins['inlinepopups'] = array();
+
+$plugins['insertdatetime'] = array();
+$plugins['insertdatetime']['theme_advanced_buttons2'] = array('insertdate', 'inserttime');
+$plugins['insertdatetime']['plugin_insertdate_dateFormat'] = array('%Y-%m-%d');
+$plugins['insertdatetime']['plugin_insertdate_timeFormat'] = array('%H:%M:%S');
+
+$plugins['layer'] = array();
+$plugins['layer']['theme_advanced_buttons3'] = array('insertlayer', 'moveforward', 'movebackward', 'absolute');
+
+$plugins['paste'] = array();
+$plugins['paste']['theme_advanced_buttons3'] = array('pastetext', 'pasteword', 'selectall');
+
+$plugins['preview'] = array();
+$plugins['preview']['theme_advanced_buttons2'] = array('preview');
+
+$plugins['print'] = array();
+$plugins['print']['theme_advanced_buttons3'] = array('print');
+
+$plugins['searchreplace'] = array();
+$plugins['searchreplace']['theme_advanced_buttons2'] = array('search', 'replace');
+
+
+if (is_dir(drupal_get_path('module', 'tinymce') . '/tinymce/jscripts/tiny_mce/plugins/spellchecker/')) {
+ $plugins['spellchecker'] = array();
+ $plugins['spellchecker']['theme_advanced_buttons3'] = array('spellchecker');
+}
+
+$plugins['style'] = array();
+$plugins['style']['theme_advanced_buttons3'] = array('styleprops');
+
+$plugins['table'] = array();
+$plugins['table']['theme_advanced_buttons3'] = array('tablecontrols');
+
+$plugins['zoom'] = array();
+$plugins['zoom']['theme_advanced_buttons2'] = array('zoom');
+
+return $plugins;
+}
diff --git a/tinymce.install b/tinymce.install
new file mode 100644
index 0000000..0680899
--- /dev/null
+++ b/tinymce.install
@@ -0,0 +1,49 @@
+<?php
+// $Id$
+
+/**
+ * Implementation of hook_install()
+ *
+ * This will automatically install the database tables for the TinyMCE module for both the MySQL and PostgreSQL databases.
+ *
+ * If you are using another database, you will have to install the tables by hand, using the queries below as a reference.
+ *
+ * Note that the curly braces around table names are a drupal-specific feature to allow for automatic database table prefixing,
+ * and will need to be removed.
+ */
+function tinymce_install() {
+ switch ($GLOBALS['db_type']) {
+ case 'mysql':
+ case 'mysqli':
+ db_query("CREATE TABLE {tinymce_settings} (
+ name varchar(128) NOT NULL default '',
+ settings text NOT NULL default '',
+ PRIMARY KEY (name)
+ ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
+
+ db_query("CREATE TABLE {tinymce_role} (
+ name varchar(128) NOT NULL default '',
+ rid tinyint(3) unsigned NOT NULL default '0',
+ PRIMARY KEY (name,rid)
+ ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
+ break;
+
+ case 'pgsql':
+ db_query("CREATE TABLE {tinymce_settings} (
+ name varchar(128) NOT NULL default '',
+ settings text NOT NULL default '',
+ PRIMARY KEY (name)
+ );");
+
+ db_query("CREATE TABLE {tinymce_role} (
+ name varchar(128) NOT NULL default '',
+ rid smallint NOT NULL default '0',
+ PRIMARY KEY (name,rid)
+ );");
+ break;
+ }
+}
+
+function tinymce_update_1() {
+ return _system_update_utf8(array('tinymce_settings', 'tinymce_role'));
+}
diff --git a/tinymce.module b/tinymce.module
index ca4129f..d1a0e2c 100644
--- a/tinymce.module
+++ b/tinymce.module
@@ -1,116 +1,1123 @@
<?php
// $Id$
+// A collaborative project by Matt Westgate <drupal at asitis dot org>,
+// Richard Bennett <richard.b@ at ritechnologies dot com> and Jeff Robbins <robbins at jjeff dot com>
+/**
+ * @file
+ * Integrate the TinyMCE editor (http://tinymce.moxiecode.com/) into Drupal.
+ */
+
+/**
+ * Implementation of hook_menu().
+ */
+function tinymce_menu($may_cache) {
+ $items = array();
+ if ($may_cache) {
+ $items[] = array('path' => 'admin/settings/tinymce', 'title' => t('tinymce'),
+ 'callback' => 'tinymce_admin',
+ 'access' => user_access('administer tinymce'));
+ }
+ return $items;
+}
+
+/**
+ * Implementation of hook_help().
+ */
function tinymce_help($section) {
switch ($section) {
- case 'admin/help#tinymce':
- $output = '<p>'. t('The most popular WYSIWYG editor for advance content.') .'</p>';
- $output .= t("<p><ul>"
- ."<li>Editor mode: full, compact and simple.</li>"
- ."</ul>"
- ."</p>");
- return $output;
case 'admin/modules#description':
- return t('Enable WYSIWYG Editor to your site.');
+ return t('The TinyMCE Javascript HTML WYSIWYG editor.');
+ case 'admin/settings/tinymce#pages':
+ return "node/*\nuser/*\ncomment/*";
+ case 'admin/settings/tinymce':
+ case 'admin/help#tinymce' :
+ return t('<p style="font-size:x-small">$Revision$ $Date$</p>' .
+ '<p>TinyMCE adds what-you-see-is-what-you-get (WYSIWYG) html editing to textareas. This editor can be enabled/disabled without reloading the page by clicking a link below each textarea.</p>
+ <p>Profiles can be defined based on user roles. A TinyMCE profile can define which pages receive this TinyMCE capability, what buttons or themes are enabled for the editor, how the editor is displayed, and a few other editor functions.</p>
+ <p>Lastly, only users with the <code>access tinymce</code> <a href="%url">permission</a> will be able to use TinyMCE.</p>', array('%url' => url('admin/access'))
+ );
}
}
+/**
+ * Implementation of hook_perm().
+ */
function tinymce_perm() {
$array = array('administer tinymce', 'access tinymce');
- $array[] = 'enable tinymce file manager';
+ $tinymce_mod_path = drupal_get_path('module', 'tinymce');
+
+ if (is_dir($tinymce_mod_path . '/tinymce/jscripts/tiny_mce/plugins/imagemanager/')) {
+ $array[] = 'access tinymce imagemanager';
+ }
+ if (is_dir($tinymce_mod_path . '/tinymce/jscripts/tiny_mce/plugins/filemanager/')) {
+ $array[] = 'access tinymce filemanager';
+ }
return $array;
}
-function tinymce_menu($may_cache) {
+/**
+ * Implementation of hook_elements().
+ */
+function tinymce_elements() {
+ $type = array();
- $items = array();
+ if (user_access('access tinymce')) {
+ // Set resizable to false to avoid drupal.js resizable function from taking control of the textarea
+ $type['textarea'] = array('#process' => array('tinymce_process_textarea' => array()), '#resizable' => FALSE);
+ }
+
+ return $type;
+}
+
+/**
+ * Attach tinymce to a textarea
+ */
+function tinymce_process_textarea($element) {
+ static $is_running = FALSE;
+ global $user;
+ static $profile_name;
- $items[] = array(
- 'path' => 'admin/settings/tinymce',
- 'title' => t('TinyMCE'),
- 'description' => t('Tinymce settings.'),
- 'callback' => 'drupal_get_form',
- 'callback arguments' => array('tinymce_admin_settings'),
- 'access' => user_access('administer tinymce'),
- 'type' => MENU_NORMAL_ITEM);
+ //$element is an array of attributes for the textarea but there is no just 'name' value, so we extract this from the #id field
+ $textarea_name = substr($element['#id'], strpos($element['#id'], '-') + 1);
+
+ // Since tinymce_config() makes a db hit, only call it when we're pretty sure
+ // we're gonna render tinymce.
+ if (!$profile_name) {
+ $profile_name = db_result(db_query('SELECT s.name FROM {tinymce_settings} s INNER JOIN {tinymce_role} r ON r.name = s.name WHERE r.rid IN (%s)', implode(',', array_keys($user->roles))));
+ }
+ $profile = tinymce_profile_load($profile_name);
+ $init = tinymce_config($profile);
+ $init['elements'] = 'edit-'. $textarea_name;
+
+ if (_tinymce_page_match($profile)) {
+ // Merge user-defined TinyMCE settings.
+ $init = (array) theme('tinymce_theme', $init, $textarea_name, $init['theme'], $is_running);
+
+ // If $init array is empty no need to execute rest of code since there are no textareas to theme with TinyMCE
+ if (count($init) < 1) {
+ // we set this textarea to use drupal resizable since tinymce won't be controling this textarea
+ $element['#resizable'] = TRUE;
+ return $element;
+ }
+
+ $settings = array();
+ foreach ($init as $k => $v) {
+ $v = is_array($v) ? implode(',', $v) : $v;
+ // Don't wrap the JS init in quotes for boolean values or functions.
+ if (strtolower($v) != 'true' && strtolower($v) != 'false' && $v[0] != '{') {
+ $v = '"'. $v. '"';
+ }
+ $settings[] = $k. ' : '. $v;
+ }
+ $tinymce_settings = implode(",\n ", $settings);
+
+ $enable = t('enable rich-text');
+ $disable = t('disable rich-text');
+
+$tinymce_invoke = <<<EOD
+<script type="text/javascript">
+ tinyMCE.init({
+ $tinymce_settings
+ });
+</script>
+EOD;
+
+$js_toggle = <<<EOD
+<script type="text/javascript">
+ function mceToggle(id, linkid) {
+ element = document.getElementById(id);
+ link = document.getElementById(linkid);
+ img_assist = document.getElementById('img_assist-link-'+ id);
+
+ if (tinyMCE.getEditorId(element.id) == null) {
+ tinyMCE.addMCEControl(element, element.id);
+ element.togg = 'on';
+ link.innerHTML = '$disable';
+ link.href = "javascript:mceToggle('" +id+ "', '" +linkid+ "');";
+ if (img_assist)
+ img_assist.innerHTML = '';
+ link.blur();
+ }
+ else {
+ tinyMCE.removeMCEControl(tinyMCE.getEditorId(element.id));
+ element.togg = 'off';
+ link.innerHTML = '$enable';
+ link.href = "javascript:mceToggle('" +id+ "', '" +linkid+ "');";
+ if (img_assist)
+ img_assist.innerHTML = img_assist_default_link;
+ link.blur();
+ }
+ }
+</script>
+EOD;
+
+$status = tinymce_user_get_status($user, $profile);
+
+// note we test for string == true because we save our settings as strings
+$link_text = $status == 'true' ? $disable : $enable;
+$img_assist_link = ($status == 'true') ? 'yes' : 'no';
+$no_wysiwyg = t('Your current web browser does not support WYSIWYG editing.');
+$wysiwyg_link = <<<EOD
+<script type="text/javascript">
+ img_assist = document.getElementById('img_assist-link-edit-$textarea_name');
+ if (img_assist) {
+ var img_assist_default_link = img_assist.innerHTML;
+ if ('$img_assist_link' == 'yes') {
+ img_assist.innerHTML = tinyMCE.getEditorId('edit-$textarea_name') == null ? '' : img_assist_default_link;
+ }
+ else {
+ img_assist.innerHTML = tinyMCE.getEditorId('edit-$textarea_name') == null ? img_assist_default_link : '';
+ }
+ }
+ if (typeof(document.execCommand) == 'undefined') {
+ img_assist.innerHTML = img_assist_default_link;
+ document.write('<div style="font-size:x-small">$no_wysiwyg</div>');
+ }
+ else {
+ document.write("<div><a href=\"javascript:mceToggle('edit-$textarea_name', 'wysiwyg4$textarea_name');\" id=\"wysiwyg4$textarea_name\">$link_text</a></div>");
+ }
+</script>
+EOD;
+
+ // We only load the TinyMCE js file once per request
+ if (!$is_running) {
+ $is_running = TRUE;
+ $tinymce_mod_path = drupal_get_path('module', 'tinymce');
- return $items;
+ if (is_dir($tinymce_mod_path . '/tinymce/jscripts/tiny_mce/plugins/imagemanager/') && user_access('access tinymce imagemanager') ) {
+ // if tinymce imagemanager is installed
+ drupal_add_js($tinymce_mod_path . '/tinymce/jscripts/tiny_mce/plugins/imagemanager/jscripts/mcimagemanager.js');
+ }
+
+ if (is_dir($tinymce_mod_path . '/tinymce/jscripts/tiny_mce/plugins/filemanager/') && user_access('access tinymce filemanager') ) {
+ // if tinymce filemanager is installed
+ drupal_add_js($tinymce_mod_path . '/tinymce/jscripts/tiny_mce/plugins/filemanager/jscripts/mcfilemanager.js');
+ }
+
+ // TinyMCE Compressor
+ if (file_exists($tinymce_mod_path . '/tinymce/jscripts/tiny_mce/tiny_mce_gzip.php')) {
+ drupal_add_js($tinymce_mod_path . '/tinymce/jscripts/tiny_mce/tiny_mce_gzip.php');
+ }
+ else {
+ // For some crazy reason IE will only load this JS file if the absolute reference is given to it.
+ drupal_add_js($tinymce_mod_path . '/tinymce/jscripts/tiny_mce/tiny_mce.js');
+ }
+ drupal_set_html_head($js_toggle);
+ // We have to do this becuase of some unfocused CSS in certain themes. See http://drupal.org/node/18879 for details
+ drupal_set_html_head('<style type="text/css" media="all">.mceEditor img { display: inline; }</style>');
+ }
+ // Load a TinyMCE init for each textarea.
+ if ($init) drupal_set_html_head($tinymce_invoke);
+
+ //settings are saved as strings, not booleans
+ if ($profile->settings['show_toggle'] == 'true') {
+ // Make sure to append to #suffix so it isn't completely overwritten
+ $element['#suffix'] .= $wysiwyg_link;
+ }
+ }
+ else {
+ $element['#resizable'] = TRUE;
+ }
+
+ return $element;
+}
+
+/**
+ * Implementation of hook_user().
+ */
+function tinymce_user($type, &$edit, &$user, $category = NULL) {
+ if ($type == 'form' && $category == 'account' && user_access('access tinymce')) {
+ $profile = tinymce_user_get_profile($user);
+
+ // because the settings are saved as strings we need to test for the string 'true'
+ if ($profile->settings['user_choose'] == 'true') {
+ $form['tinymce'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('TinyMCE rich-text settings'),
+ '#weight' => 10,
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE
+ );
+
+ $form['tinymce']['tinymce_status'] = array(
+ '#type' => 'select',
+ '#title' => t('Default state'),
+ '#default_value' => isset($user->tinymce_status) ? $user->tinymce_status : (isset($profile->settings['default']) ? $profile->settings['default'] : 'false'),
+ '#options' => array('false' => 'false', 'true' => 'true'),
+ '#description' => t('Should rich-text editing be enabled or disabled by default in textarea fields?')
+ );
+
+ return array('tinymce' => $form);
+ }
+ }
+ if ($type == 'validate') {
+ return array('tinymce_status' => $edit['tinymce_status']);
+ }
+}
+
+/**
+ * @addtogroup themeable
+ * @{
+ */
+
+/**
+ * Customize a TinyMCE theme.
+ *
+ * @param init
+ * An array of settings TinyMCE should invoke a theme. You may override any
+ * of the TinyMCE settings. Details here:
+ *
+ * http://tinymce.moxiecode.com/wrapper.php?url=tinymce/docs/using.htm
+ *
+ * @param textarea_name
+ * The name of the textarea TinyMCE wants to enable.
+ *
+ * @param theme_name
+ * The default tinymce theme name to be enabled for this textarea. The
+ * sitewide default is 'simple', but the user may also override this.
+ *
+ * @param is_running
+ * A boolean flag that identifies id TinyMCE is currently running for this
+ * request life cycle. It can be ignored.
+ */
+function theme_tinymce_theme($init, $textarea_name, $theme_name, $is_running) {
+ switch ($textarea_name) {
+ // Disable tinymce for these textareas
+ case 'log': // book and page log
+ case 'img_assist_pages':
+ case 'caption': // signature
+ case 'pages':
+ case 'access_pages': //TinyMCE profile settings.
+ case 'user_mail_welcome_body': // user config settings
+ case 'user_mail_approval_body': // user config settings
+ case 'user_mail_pass_body': // user config settings
+ case 'synonyms': // taxonomy terms
+ case 'description': // taxonomy terms
+ unset($init);
+ break;
+
+ // Force the 'simple' theme for some of the smaller textareas.
+ case 'signature':
+ case 'site_mission':
+ case 'site_footer':
+ case 'site_offline_message':
+ case 'page_help':
+ case 'user_registration_help':
+ case 'user_picture_guidelines':
+ $init['theme'] = 'simple';
+ foreach ($init as $k => $v) {
+ if (strstr($k, 'theme_advanced_')) unset($init[$k]);
+ }
+ break;
+ }
+
+ /* Example, add some extra features when using the advanced theme.
+
+ // If $init is available, we can extend it
+ if (isset($init)) {
+ switch ($theme_name) {
+ case 'advanced':
+ $init['extended_valid_elements'] = array('a[href|target|name|title|onclick]');
+ break;
+ }
+ }
+
+ */
+
+ // Always return $init
+ return $init;
+}
+
+/** @} End of addtogroup themeable */
+
+/**
+ * Grab the themes available to TinyMCE.
+ *
+ * TinyMCE themes control the functionality and buttons that are available to a
+ * user. Themes are only looked for within the default TinyMCE theme directory.
+ *
+ * NOTE: This function is not used in this release. We are only using advanced theme.
+ *
+ * @return
+ * An array of theme names.
+ */
+function _tinymce_get_themes() {
+ static $themes = array();
+
+ if (!$themes) {
+ $theme_loc = drupal_get_path('module', 'tinymce') .'/tinymce/jscripts/tiny_mce/themes/';
+ if (is_dir($theme_loc) && $dh = opendir($theme_loc)) {
+ while (($file = readdir($dh)) !== false) {
+ if (!in_array($file, array('.', '..', 'CVS')) && is_dir($theme_loc . $file)) {
+ $themes[$file] = $file;
+ }
+ }
+ closedir($dh);
+ asort($themes);
+ }
+ }
+
+ return $themes;
+}
+
+/**
+ * Return plugin metadata from the plugin registry.
+ *
+ * We also scrape each plugin's *.js file for the human friendly name and help
+ * text URL of each plugin.
+ *
+ * @return
+ * An array for each plugin.
+ */
+function _tinymce_get_buttons($skip_metadata = TRUE) {
+ include_once(drupal_get_path('module', 'tinymce'). '/plugin_reg.php');
+ $plugins = _tinymce_plugins();
+
+ if ($skip_metadata == FALSE && is_array($plugins)) {
+ foreach ($plugins as $name => $plugin) {
+ $file = drupal_get_path('module', 'tinymce'). '/tinymce/jscripts/tiny_mce/plugins/'. $name .'/editor_plugin_src.js';
+ // Grab the plugin metadata by scanning the *.js file.
+ if (file_exists($file)) {
+ $lines = file($file);
+ $has_longname = FALSE;
+ $has_infourl = FALSE;
+ foreach ($lines as $line) {
+ if ($has_longname && $has_infourl) break;
+ if (strstr($line, 'longname')) {
+ $start = strpos($line, "'") + 1;
+ $end = strrpos($line, "'") - $start;
+ $metadata[$name]['longname'] = substr($line, $start, $end);
+ $has_longname = TRUE;
+ }
+ elseif (strstr($line, 'infourl')) {
+ $start = strpos($line, "'") + 1;
+ $end = strrpos($line, "'") - $start;
+ $metadata[$name]['infourl'] = substr($line, $start, $end);
+ $has_infourl = TRUE;
+ }
+ }
+ }
+
+ // Find out the buttons a plugin has.
+ foreach ($plugin as $k => $v) {
+ if (strstr($k, 'theme_advanced_buttons')) {
+ $metadata[$name]['buttons'] = array_merge((array) $metadata[$name]['buttons'], $plugin[$k]);
+ }
+ }
+ }
+ return $metadata;
+ }
+
+ return $plugins;
+}
+/********************************************************************
+ * Module Functions :: Public
+ ********************************************************************/
+
+/**
+ * Controller for tinymce administrative settings.
+ */
+function tinymce_admin($arg = NULL) {
+
+ $edit = $_POST['edit'];
+ $op = $_POST['op'];
+
+ $op = $arg && !$op ? $arg : $op;
+
+ switch ($op) {
+ case 'add':
+ $breadcrumb[] = array('path' => 'admin', 'title' => t('administer'));
+ $breadcrumb[] = array('path' => 'admin/settings/tinymce', 'title' => t('tinymce'));
+ $breadcrumb[] = array('path' => 'admin/settings/tinymce/add', 'title' => t('Add new TinyMCE profile'));
+ menu_set_location($breadcrumb);
+ $output = tinymce_profile_form($edit);
+ break;
+
+ case 'edit':
+ drupal_set_title(t('Edit tinymce profile'));
+ $output = tinymce_profile_form(tinymce_profile_load(urldecode(arg(4))));
+ break;
+
+ case 'delete':
+ tinymce_profile_delete(urldecode(arg(4)));
+ drupal_set_message(t('Deleted profile'));
+ drupal_goto('admin/settings/tinymce');
+ break;
+
+ case t('Create profile');
+ case t('Update profile');
+ if (tinymce_profile_validate($edit)) {
+ tinymce_profile_save($edit);
+ $edit['old_name'] ? drupal_set_message(t('Your TinyMCE profile has been updated.')) : drupal_set_message(t('Your TinyMCE profile has been created.'));
+ drupal_goto('admin/settings/tinymce');
+ }
+ else {
+ $output = tinymce_profile_form($edit);
+ }
+ break;
+
+ default:
+ drupal_set_title(t('TinyMCE settings'));
+ //Check if TinyMCE is installed.
+ $tinymce_loc = drupal_get_path('module', 'tinymce') .'/tinymce/';
+ if (!is_dir($tinymce_loc)) {
+ drupal_set_message(t('Could not find the TinyMCE engine installed at <strong>%tinymce-directory</strong>. Please <a href="http://tinymce.moxiecode.com/">download TinyMCE</a>, uncompress it and copy the folder into %tinymce-path.', array('%tinymce-path' => drupal_get_path('module', 'tinymce'), '%tinymce-directory' => $tinymce_loc)), 'error');
+ }
+ $output = tinymce_profile_overview();
+ }
+
+ return $output;
}
-function tinymce_admin_settings() {
- // only administrators can access this function
- // Generate the form - settings applying to all patterns first
+/**
+ * Return an array of initial tinymce config options from the current role.
+ */
+function tinymce_config($profile) {
+ global $user;
+
+ // Drupal theme path.
+ $themepath = path_to_theme() . '/';
+ $host = base_path();
+
+ $settings = $profile->settings;
+
+ // Build a default list of TinyMCE settings.
+
+ // Is tinymce on by default?
+ $status = tinymce_user_get_status($user, $profile);
+
+ $init['mode'] = $status == 'true' ? 'exact' : 'none';
+ $init['theme'] = $settings['theme'] ? $settings['theme'] : 'advanced';
+ $init['relative_urls'] = 'false';
+ $init['document_base_url'] = "$host";
+ $init['language'] = $settings['language'] ? $settings['language'] : 'en';
+ $init['safari_warning'] = $settings['safari_message'] ? $settings['safari_message'] : 'false';
+ $init['entity_encoding'] = 'raw';
+ $init['verify_html'] = $settings['verify_html'] ? $settings['verify_html'] : 'false';
+ $init['preformatted'] = $settings['preformatted'] ? $settings['preformatted'] : 'false';
+ $init['convert_fonts_to_styles'] = $settings['convert_fonts_to_styles'] ? $settings['convert_fonts_to_styles'] : 'false';
+
+ $tinymce_mod_path = drupal_get_path('module', 'tinymce');
+ if (is_dir($tinymce_mod_path . '/tinymce/jscripts/tiny_mce/plugins/imagemanager/') && user_access('access tinymce imagemanager')) {
+ // we probably need more security than this
+ $init['file_browser_callback'] = "mcImageManager.filebrowserCallBack";
+ }
+ if (is_dir($tinymce_mod_path . '/tinymce/jscripts/tiny_mce/plugins/filemanager/') && user_access('access tinymce filemanager')) {
+ // we probably need more security than this
+ $init['file_browser_callback'] = "mcImageManager.filebrowserCallBack";
+ }
- $form['tinymce_settings'] = array(
- '#type' => 'fieldset',
- '#weight' => -20,
- '#title' => t('Basic settings'),
- '#collapsible' => TRUE,
- '#collapsed' => FALSE
+ if ($init['theme'] == 'advanced') {
+ $init['plugins'] = array();
+ $init['theme_advanced_toolbar_location'] = $settings['toolbar_loc'] ? $settings['toolbar_loc'] : 'bottom';
+ $init['theme_advanced_toolbar_align'] = $settings['toolbar_align'] ? $settings['toolbar_align'] : 'left';
+ $init['theme_advanced_path_location'] = $settings['path_loc'] ? $settings['path_loc'] : 'bottom';
+ $init['theme_advanced_resizing'] = $settings['resizing'] ? $settings['resizing'] : 'true';
+ $init['theme_advanced_blockformats'] = $settings['block_formats'] ? $settings['block_formats'] : 'p,address,pre,h1,h2,h3,h4,h5,h6';
+
+ if (is_array($settings['buttons'])) {
+ // This gives us the $plugins variable.
+ $plugins = _tinymce_get_buttons();
+
+ // Find the enabled buttons and the mce row they belong on. Also map the
+ // plugin metadata for each button.
+ $plugin_tracker = array();
+ foreach ($plugins as $rname => $rplugin) { // Plugin name
+ foreach ($rplugin as $mce_key => $mce_value) { // TinyMCE key
+ foreach ($mce_value as $k => $v) { // Buttons
+ if ($settings['buttons'][$rname . '-' . $v]) {
+ // Font isn't a true plugin, rather it's buttons made available by the advanced theme
+ if (!in_array($rname, $plugin_tracker) && $rname != 'font') $plugin_tracker[] = $rname;
+ $init[$mce_key][] = $v;
+ }
+ }
+ }
+ // Some advanced plugins only have an $rname and no buttons
+ if ($settings['buttons'][$rname]) {
+ if (!in_array($rname, $plugin_tracker)) $plugin_tracker[] = $rname;
+ }
+ }
+
+ // Add the rest of the TinyMCE config options to the $init array for each button.
+ if (is_array($plugin_tracker)) {
+ foreach ($plugin_tracker as $pname) {
+ if ($pname != 'default') $init['plugins'][] = $pname;
+ foreach ($plugins[$pname] as $mce_key => $mce_value) {
+ // Don't overwrite buttons or extended_valid_elements
+ if ($mce_key == 'extended_valid_elements') {
+ // $mce_value is an array for extended_valid_elements so just grab the first element in the array (never more than one)
+ $init[$mce_key][] = $mce_value[0];
+ }
+ else if (!strstr($mce_key, 'theme_advanced_buttons')) {
+ $init[$mce_key] = $mce_value;
+ }
+ }
+ }
+ }
+
+ // Cleanup
+ foreach ($init as $mce_key => $mce_value) {
+ if (is_array($mce_value)) $mce_value = array_unique($mce_value);
+ $init[$mce_key] = $mce_value;
+ }
+
+ // Shuffle buttons around so that row 1 always has the most buttons,
+ // followed by row 2, etc. Note: These rows need to be set to NULL otherwise
+ // TinyMCE loads it's own buttons inherited from the theme.
+ if (!$init['theme_advanced_buttons1']) $init['theme_advanced_buttons1'] = array();
+ if (!$init['theme_advanced_buttons2']) $init['theme_advanced_buttons2'] = array();
+ if (!$init['theme_advanced_buttons3']) $init['theme_advanced_buttons3'] = array();
+
+ $min_btns = 5; // Minimum number of buttons per row.
+ $num1 = count($init['theme_advanced_buttons1']);
+ $num2 = count($init['theme_advanced_buttons2']);
+ $num3 = count($init['theme_advanced_buttons3']);
+
+ if ($num3 < $min_btns) {
+ $init['theme_advanced_buttons2'] = array_merge($init['theme_advanced_buttons2'], $init['theme_advanced_buttons3']);
+ $init['theme_advanced_buttons3'] = array();
+ $num2 = count($init['theme_advanced_buttons2']);
+ }
+ if ($num2 < $min_btns) {
+ $init['theme_advanced_buttons1'] = array_merge($init['theme_advanced_buttons1'], $init['theme_advanced_buttons2']);
+ // Squish the rows together, since row 2 is empty
+ $init['theme_advanced_buttons2'] = $init['theme_advanced_buttons3'];
+ $init['theme_advanced_buttons3'] = array();
+ $num1 = count($init['theme_advanced_buttons1']);
+ }
+ if ($num1 < $min_btns) {
+ $init['theme_advanced_buttons1'] = array_merge($init['theme_advanced_buttons1'], $init['theme_advanced_buttons2']);
+ // Squish the rows together, since row 2 is empty
+ $init['theme_advanced_buttons2'] = $init['theme_advanced_buttons3'];
+ $init['theme_advanced_buttons3'] = array();
+ }
+
+ }
+ }
+
+ if ($settings['css_classes']) $init['theme_advanced_styles'] = $settings['css_classes'];
+
+ if ($settings['css_setting'] == 'theme') {
+ $css = $themepath . 'style.css';
+ if (file_exists($css)) {
+ $init['content_css'] = $host . $css;
+ }
+ }
+ else if ($settings['css_setting'] == 'self') {
+ $init['content_css'] = str_replace(array('%h', '%t'), array($host, $themepath), $settings['css_path']);
+ }
+
+ return $init;
+}
+
+/**
+ * Remove a profile from the database.
+ */
+function tinymce_profile_delete($name) {
+ db_query("DELETE FROM {tinymce_settings} WHERE name = '%s'", $name);
+ db_query("DELETE FROM {tinymce_role} WHERE name = '%s'", $name);
+}
+
+/**
+ * Return an HTML form for profile configuration.
+ */
+function tinymce_profile_form($edit) {
+ $edit = (object) $edit;
+
+ // Only display the roles that currently don't have a tinymce profile. One
+ // profile per role.
+ $orig_roles = user_roles(FALSE, 'access tinymce');
+ $roles = $orig_roles;
+ if (arg(3) == 'add') {
+ $result = db_query('SELECT DISTINCT(rid) FROM {tinymce_role}');
+ while ($data = db_fetch_object($result)) {
+ if (!in_array($data->rid, array_keys((array) $edit->rids)) && !form_get_errors()){
+ unset($roles[$data->rid]);
+ }
+ }
+ if (!$orig_roles) {
+ drupal_set_message(t('You must <a href="%access-control-url">assign</a> at least one role with the \'access tinymce\' permission before creating a profile.', array('%access-control-url' => url('admin/access'))), 'error');
+ }
+ else if (!$roles) {
+ drupal_set_message(t('You will not be allowed to create a new profile since all user roles have already been assigned profiles. Either remove an existing tinymce profile from at least one role or assign another role the \'access tinymce\' permission.'), 'error');
+ }
+ else if (count($orig_roles) != count($roles)) {
+ drupal_set_message(t('Not all user roles are shown since they already have tinymce profiles. You must first unassign profiles in order to add them to a new one.'));
+ }
+ $btn = t('Create profile');
+ }
+ else {
+ $form['old_name'] = array('#type' => 'hidden', '#value' => $edit->name);
+ $btn = t('Update profile');
+ }
+
+ $form['basic'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Basic setup'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE
);
-
- $form['tinymce_settings']['editor_mode'] = array(
- '#type' => 'radios',
- '#title' => t('Editor Mode'),
- '#default_value' => variable_get('editor_mode', 0),
- '#options' => array(t('Full'), t('Compact'), t('Simple')),
- '#description' => t("FULL: enable all TinyMCE features. COMPACT: enable most used features. SIMPLE: just enable simple editor.<hr>")
+
+ $form['basic']['name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Profile name'),
+ '#default_value' => $edit->name,
+ '#size' => 40,
+ '#maxlength' => 128,
+ '#description' => t('Enter a name for this profile. This name is only visible within the tinymce administration page.'),
+ '#required' => TRUE
);
- $form['tinymce_settings']['editor_element'] = array(
- '#type' => 'radios',
- '#title' => t('Enable TinyMCE for'),
- '#default_value' => variable_get('editor_element', 0),
- '#options' => array(t('Edit-body only'), t('Edit-comment only'), t('Both')),
- '#description' => t("If you want TinyMCE available for textarea of edit-body and comment then you should select <b>Both</b> option.")
+ $form['basic']['rids'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Roles allowed to use this profile'),
+ '#default_value' => array_keys((array) $edit->rids),
+ '#options' => $roles,
+ '#description' => t('Check at least one role. Only roles with \'access tinymce\' permission will be shown here.'),
+ '#required' => TRUE
);
- $form['tinymce_settings']['editor_node_type'] = array(
- '#type' => 'textfield',
- '#title' => t('Enable TinyMCE for this node types'),
- '#default_value' => variable_get('editor_node_type', 'page,story,blog'),
- '#description' => t("Node type in case-sensitive name, i.e: page,story,data_product,blog")
+ $form['basic']['default'] = array(
+ '#type' => 'select',
+ '#title' => t('Default state'),
+ '#default_value' => $edit->settings['default'] ? $edit->settings['default'] : 'false',
+ '#options' => array('false' => 'false', 'true' => 'true'),
+ '#description' => t('Default editor state for users in this profile. Users will be able to override this state if the next option is enabled.'),
);
-
- return system_settings_form($form);
-}
-
-function tinymce_form_alter($form_id, &$form) {
- $editor_node_type = variable_get("editor_node_type", 'page,story,blog');
- $form_type = $form['type']['#value'];
- if (!preg_match("/\b$form_type\b/i", $editor_node_type)) return;
+ $form['basic']['user_choose'] = array(
+ '#type' => 'select',
+ '#title' => t('Allow users to choose default'),
+ '#default_value' => $edit->settings['user_choose'] ? $edit->settings['user_choose'] : 'false',
+ '#options' => array('false' => 'false', 'true' => 'true'),
+ '#description' => t('If allowed, users will be able to choose their own TinyMCE default state by visiting their profile page.'),
+ );
+
+ $form['basic']['show_toggle'] = array(
+ '#type' => 'select',
+ '#title' => t('Show disable/enable rich text editor toggle'),
+ '#default_value' => $edit->settings['show_toggle'] ? $edit->settings['show_toggle'] : 'true',
+ '#options' => array('false' => 'false', 'true' => 'true'),
+ '#description' => t('Whether or not to show the disable/enable rich text editor toggle below the textarea. If false, editor defaults to the global default or user default (see above).'),
+ );
+
+ // This line upgrades previous versions of TinyMCE for user who previously selected a theme other than advanced.
+ if ($edit->settings['theme'] != 'advanced') $edit->settings['theme'] = 'advanced';
+
+ $form['basic']['theme'] = array(
+ '#type' => 'hidden',
+ '#value' => $edit->settings['theme'] ? $edit->settings['theme'] : 'advanced'
+ );
+
+ $form['basic']['language'] = array(
+ '#type' => 'select',
+ '#title' => t('Language'),
+ '#default_value' => $edit->settings['language'] ? $edit->settings['language'] : 'en',
+ '#options' => drupal_map_assoc(array('ar', 'ca', 'cs', 'cy', 'da', 'de', 'el', 'en', 'es', 'fa', 'fi', 'fr', 'fr_ca', 'he', 'hu', 'is', 'it', 'ja', 'ko', 'nb', 'nl', 'nn', 'pl', 'pt', 'pt_br', 'ru', 'ru_KOI8-R', 'ru_UTF-8', 'sk', 'sv', 'th', 'zh_cn', 'zh_tw', 'zh_tw_utf8')),
+ '#description' => t('The language for the TinyMCE interface. Language codes based on the <a href="http://www.loc.gov/standards/iso639-2/englangn.html">ISO-639-2</a> format.')
+ );
- if ($form_id == 'comment_form' || (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) && user_access('access tinymce')) {
- $queries = array("textarea#body", "textarea#comment");
- tinymce_add_javascript();
+ $form['basic']['safari_message'] = array(
+ '#type' => 'select',
+ '#title' => t('Safari browser warning'),
+ '#default_value' => $edit->settings['safari_message'] ? $edit->settings['safari_message'] : 'false',
+ '#options' => array('false' => 'false', 'true' => 'true'),
+ '#description' => t('TinyMCE support for the Safari web browser is experimental and a warning message is displayed when that browser is detected. You can disable this message here.')
+ );
+
+ $form['visibility'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Visibility'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE
+ );
+
+ $access = user_access('use PHP for block visibility');
+
+ // If the visibility is set to PHP mode but the user doesn't have this block permission, don't allow them to edit nor see this PHP code
+ if ($edit->settings['access'] == 2 && !$access) {
+ $form['visibility'] = array();
+ $form['visibility']['access'] = array(
+ '#type' => 'value',
+ '#value' => 2
+ );
+ $form['visibility']['access_pages'] = array(
+ '#type' => 'value',
+ '#value' => $edit->settings['access_pages']
+ );
}
-}
+ else {
+ $options = array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.'));
+ $description = t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '%blog' for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => theme('placeholder', 'blog'), '%blog-wildcard' => theme('placeholder', 'blog/*'), '%front' => theme('placeholder', '<front>')));
+
+ if ($access) {
+ $options[] = t('Show if the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).');
+ $description .= t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array('%php' => theme('placeholder', '<?php ?>')));
+ }
+ $form['visibility']['access'] = array(
+ '#type' => 'radios',
+ '#title' => t('Show tinymce on specific pages'),
+ '#default_value' => isset($edit->settings['access']) ? $edit->settings['access'] : 1,
+ '#options' => $options
+ );
+ $form['visibility']['access_pages'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Pages'),
+ '#default_value' => isset($edit->settings['access_pages']) ? $edit->settings['access_pages'] : tinymce_help('admin/settings/tinymce#pages'),
+ '#description' => $description
+ );
+ }
+
+ $form['buttons'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Buttons and plugins'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ '#tree' => TRUE,
+ '#theme' => 'tinymce_profile_form_buttons'
+ );
+
+ $metadata = _tinymce_get_buttons(FALSE);
+ // Generate the button list.
+ foreach($metadata as $name => $meta) {
+ if (is_array($meta['buttons'])) {
+ foreach ($meta['buttons'] as $button) {
+ if ($name != 'default') {
+ $img_src = drupal_get_path('module', 'tinymce'). "/tinymce/jscripts/tiny_mce/plugins/$name/images/$name.gif";
+
+ //correct for plugins that have more than one button
+ if (!file_exists($img_src)) {
+ $img_src = drupal_get_path('module', 'tinymce'). "/tinymce/jscripts/tiny_mce/plugins/$name/images/$button.gif";
+ }
+ }
+ else {
+ $img_src = drupal_get_path('module', 'tinymce'). "/tinymce/jscripts/tiny_mce/themes/advanced/images/$button.gif";
+ }
+
+ $b = file_exists($img_src) ? '<img src="'. base_path() . $img_src .'" title="'. $button .'" style="border: 1px solid grey; vertical-align: middle;" />' : $button;
+
+ if ($name == 'default') {
+ $title = $b;
+ }
+ else {
+ $title = $metadata[$name]['longname'] ? $metadata[$name]['longname'] : $name;
+ if ($metadata[$name]['infourl']) {
+ $title = '<a href="'. $metadata[$name]['infourl'] .'" target="_blank">'. $title .'</a>';
+ }
+ $title = $b . ' &#8211; '. $title;
+ }
+ $form_value = $edit->settings['buttons'][$name . '-' . $button];
+ $form['buttons'][$name . '-' . $button] = array('#type' => 'checkbox', '#title' => $title, '#default_value' => $form_value);
+ }
+ }
+ else {
+ $title = $metadata[$name]['longname'] ? $metadata[$name]['longname'] : $name;
+ if ($metadata[$name]['infourl']) {
+ $title = '<a href="'. $metadata[$name]['infourl'] .'" target="_blank">'. $title .'</a>';
+ }
+ $form_value = $edit->settings['buttons'][$name];
+ $form['buttons'][$name] = array('#type' => 'checkbox', '#title' => $title, '#default_value' => $form_value);
+ }
+ }
+
+ $form['appearance'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Editor appearance'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE
+ );
+
+ $form['appearance']['toolbar_loc'] = array(
+ '#type' => 'select',
+ '#title' => t('Toolbar location'),
+ '#default_value' => $edit->settings['toolbar_loc'],
+ '#options' => array('bottom' => 'bottom', 'top' => 'top'),
+ '#description' => t('Show toolbar at the top or bottom of the editor area?')
+ );
+
+ $form['appearance']['toolbar_align'] = array(
+ '#type' => 'select',
+ '#title' => t('Toolbar alignment'),
+ '#default_value' => $edit->settings['toolbar_align'],
+ '#options' => array('center' => 'center', 'left' => 'left', 'right' => 'right'),
+ '#description' => t('Align tool icons left, center, or right within the toolbar.')
+ );
+
+ $form['appearance']['path_loc'] = array(
+ '#type' => 'select',
+ '#title' => t('Path location'),
+ '#default_value' => $edit->settings['path_loc'] ? $edit->settings['path_loc'] : 'bottom',
+ '#options' => array('none' => 'none', 'top' => 'top', 'bottom' => 'bottom'),
+ '#description' => t('Path to html elements (i.e. "body>table>tr>td"). Show at top, bottom, or not at all.')
+ );
+
+ $form['appearance']['resizing'] = array(
+ '#type' => 'select',
+ '#title' => t('Enable resizing button'),
+ '#default_value' => isset($edit->settings['resizing']) ? $edit->settings['resizing'] : 'true',
+ '#options' => array('false' => 'false', 'true' => 'true'),
+ '#description' => t(' This option gives you the ability to enable/disable the resizing button. If enabled the <strong>Path location toolbar</strong> must be set to "top" or "bottom" in order to display the resize icon.')
+ );
+
+ $form['appearance']['block_formats'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Block formats'),
+ '#default_value' => $edit->settings['block_formats'] ? $edit->settings['block_formats'] : 'p,address,pre,h1,h2,h3,h4,h5,h6',
+ '#size' => 40,
+ '#maxlength' => 250,
+ '#description' => t('Comma separated list of HTML block formats. You can only remove elements, not add.')
+ );
-function tinymce_add_javascript() {
- $editor_mode = variable_get("editor_mode", 0);
- $editor_element = variable_get("editor_element", 0);
+ $form['output'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Cleanup and output'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE
+ );
- drupal_add_js(drupal_get_path('module', 'tinymce') . '/includes/jscripts/tiny_mce/tiny_mce.js');
- //drupal_add_js(drupal_get_path('module', 'tinymce') . '/imce/imce_set.js');
+ $form['output']['verify_html'] = array(
+ '#type' => 'select',
+ '#title' => t('Verify HTML'),
+ '#default_value' => $edit->settings['verify_html'],
+ '#options' => array('true' => 'true', 'false' => 'false'),
+ '#description' => t('Should the HTML contents be verified or not? Verifying will strip &lt;head&gt tags, so choose false if you will be editing full page HTML.')
+ );
- if ($editor_mode==0) { drupal_add_js(drupal_get_path('module', 'tinymce') . '/themes/tinymce_full.js'); }
- elseif ($editor_mode==1) { drupal_add_js(drupal_get_path('module', 'tinymce') . '/themes/tinymce_compact.js'); }
- else { drupal_add_js(drupal_get_path('module', 'tinymce') . '/themes/tinymce_simple.js'); }
+ $form['output']['preformatted'] = array(
+ '#type' => 'select',
+ '#title' => t('Preformatted'),
+ '#default_value' => $edit->settings['preformatted'],
+ '#options' => array('false' => 'false', 'true' => 'true'),
+ '#description' => t('If this option is set to true, the editor will insert TAB characters on tab and preserve other whitespace characters just like a PRE HTML element does.')
+ );
- //tinyMCE.configs[i]['file_browser_callback'] = 'imceImageBrowser';
- if ($editor_element==0) {$tinymce_elements = 'edit-body';}
- elseif ($editor_element==1) {$tinymce_elements = 'edit-comment';}
- else {$tinymce_elements = 'edit-body,edit-comment';}
+ $form['output']['convert_fonts_to_styles'] = array(
+ '#type' => 'select',
+ '#title' => t('Convert &lt;font&gt; tags to styles'),
+ '#default_value' => $edit->settings['convert_fonts_to_styles'],
+ '#options' => array('true' => 'true', 'false' => 'false'),
+ '#description' => t('If you set this option to true, font size, font family, font color and font background color will be replaced by inline styles.')
+ );
+
+ $form['css'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('CSS'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE
+ );
+ $form['css']['css_setting'] = array(
+ '#type' => 'select',
+ '#title' => t('Editor CSS'),
+ '#default_value' => $edit->settings['css_setting'] ? $edit->settings['css_setting'] : 'theme',
+ '#options' => array('theme' => 'use theme css', 'self' => 'define css', 'none' => 'tinyMCE default'),
+ '#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 />tinyMCE default - uses default CSS from editor.')
+ );
- drupal_add_js("
- if ('undefined' != typeof(window.tinyMCE)) {
- for (var i=0; i<tinyMCE.configs.length; i++) {
- tinyMCE.configs[i]['elements'] = '$tinymce_elements';
+ $form['css']['css_path'] = array(
+ '#type' => 'textfield',
+ '#title' => t('CSS path'),
+ '#default_value' => $edit->settings['css_path'],
+ '#size' => 40,
+ '#maxlength' => 255,
+ '#description' => t('Enter path to CSS file (example: "css/editor.css").<br />Macros: %h (host name: http://www.example.com/), %t (path to theme: theme/yourtheme/)<br />Be sure to select "define css" above.')
+ );
+
+ $form['css']['css_classes'] = array(
+ '#type' => 'textfield',
+ '#title' => t('CSS classes'),
+ '#default_value' => $edit->settings['css_classes'],
+ '#size' => 40,
+ '#maxlength' => 255,
+ '#description' => t('Adds CSS classes to the "styles" droplist. Format is: &lt;title&gt;=&lt;class&gt;;<br/> Example: Header 1=header1;Header 2=header2;Header 3=header3 (note: no trailing \';\')<br />Leave blank to automatically import list of CSS classes from style sheet.')
+ );
+
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => $btn
+ );
+
+ $output .= drupal_get_form('tinymce_profile_form', $form);
+
+ return $output;
+}
+
+/**
+ * Layout for the buttons in the tinymce profile form
+ */
+function theme_tinymce_profile_form_buttons($form) {
+ $buttons = array();
+
+ // Flatten forms array
+ foreach (element_children($form) as $key) {
+ $buttons[] = form_render($form[$key]);
+ }
+
+ //split checkboxes into rows with 3 columns
+ $total = count($buttons);
+ $rows = array();
+ for ($i = 0; $i < $total; $i++) {
+ $row = array();
+ $row[] = array('data' => $buttons[$i]);
+ $row[] = array('data' => $buttons[++$i]);
+ $row[] = array('data' => $buttons[++$i]);
+ $rows[] = $row;
+ }
+
+ $output = theme('table', array(), $rows, array('width' => '100%'));
+
+ return $output;
+}
+
+/**
+ * Load all profiles. Just load one profile if $name is passed in.
+ */
+function tinymce_profile_load($name = '') {
+ static $profiles = array();
+
+ if (!$profiles) {
+ $roles = user_roles();
+ $result = db_query('SELECT * FROM {tinymce_settings}');
+ while ($data = db_fetch_object($result)) {
+ $data->settings = unserialize($data->settings);
+ $result2 = db_query("SELECT rid FROM {tinymce_role} WHERE name = '%s'", $data->name);
+ $role = array();
+ while ($r = db_fetch_object($result2)) {
+ $role[$r->rid] = $roles[$r->rid];
}
+ $data->rids = $role;
+
+ $profiles[$data->name] = $data;
+ }
+ }
+
+ return ($name ? $profiles[$name] : $profiles);
+}
+
+/**
+ * Controller for tinymce profiles.
+ */
+function tinymce_profile_overview() {
+ $output = '';
+
+ $profiles = tinymce_profile_load();
+ if ($profiles) {
+ $roles = user_roles();
+ $header = array(t('Profile'), t('Roles'), t('Operations'));
+ foreach ($profiles as $p) {
+ $rows[] = array(array('data' => $p->name, 'valign' => 'top'), array('data' => implode("<br />\n", $p->rids)), array('data' => l(t('edit'), 'admin/settings/tinymce/edit/'. urlencode($p->name)) . ' '. l(t('delete'), 'admin/settings/tinymce/delete/'. urlencode($p->name)), 'valign' => 'top'));
}
- "
- , 'inline');
+ $output .= theme('table', $header, $rows);
+ $output .= t('<p><a href="%create-profile-url">Create new profile</a></p>', array('%create-profile-url' => url('admin/settings/tinymce/add')));
+ }
+ else {
+ drupal_set_message(t('No profiles found. Click here to <a href="%create-profile-url">create a new profile</a>.', array('%create-profile-url' => url('admin/settings/tinymce/add'))));
+ }
+
+ return $output;
+}
+
+/**
+ * Save a profile to the database.
+ */
+function tinymce_profile_save($edit) {
+ db_query("DELETE FROM {tinymce_settings} WHERE name = '%s' or name = '%s'", $edit['name'], $edit['old_name']);
+ db_query("DELETE FROM {tinymce_role} WHERE name = '%s' or name = '%s'", $edit['name'], $edit['old_name']);
+ db_query("INSERT INTO {tinymce_settings} (name, settings) VALUES ('%s', '%s')", $edit['name'], serialize($edit));
+ foreach ($edit['rids'] as $rid => $value) {
+ db_query("INSERT INTO {tinymce_role} (name, rid) VALUES ('%s', %d)", $edit['name'], $rid);
+ }
+
+ // if users can't set their own defaults, make sure to remove $user->tinymce_status so their default doesn't override the main default
+ if ($edit['user_choose'] == 'false') {
+ global $user;
+ user_save($user, array('tinymce_status' => NULL));
+ }
+}
+
+/**
+ * Profile validation.
+ */
+function tinymce_profile_validate($edit) {
+ $errors = array();
+
+ if (!$edit['name']) {
+ $errors['name'] = t('You must give a profile name.');
+ }
+
+ if (!$edit['rids']) {
+ $errors['rids'] = t('You must select at least one role.');
+ }
+
+ foreach ($errors as $name => $message) {
+ form_set_error($name, $message);
+ }
+
+ return count($errors) == 0;
+}
+
+/********************************************************************
+ * Module Functions :: Private
+ ********************************************************************/
+
+/**
+ * Determine if TinyMCE has permission to be used on the current page.
+ *
+ * @return
+ * TRUE if can render, FALSE if not allowed.
+ */
+function _tinymce_page_match($edit) {
+ $page_match = FALSE;
+
+ // Kill TinyMCE if we're editing a textarea with PHP in it!
+ // PHP input formats are #2 in the filters table.
+ if (is_numeric(arg(1)) && arg(2) == 'edit') {
+ $node = node_load(arg(1));
+ if ($node->format == 2) {
+ return FALSE;
+ }
+ }
+
+ if ($edit->settings['access_pages']) {
+ // If the PHP option wasn't selected
+ if ($edit->settings['access'] < 2) {
+ $path = drupal_get_path_alias($_GET['q']);
+ $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($edit->settings['access_pages'], '/')) .')$/';
+ $page_match = !($edit->settings['access'] xor preg_match($regexp, $path));
+ }
+ else {
+ $page_match = drupal_eval($edit->settings['access_pages']);
+ }
+ }
+ // No pages were specified to block so show on all
+ else {
+ $page_match = TRUE;
+ }
+
+ return $page_match;
+}
+
+function tinymce_user_get_profile($account) {
+ $profile_name = db_result(db_query('SELECT s.name FROM {tinymce_settings} s INNER JOIN {tinymce_role} r ON r.name = s.name WHERE r.rid IN (%s)', implode(',', array_keys($account->roles))));
+ if ($profile_name){
+ return tinymce_profile_load($profile_name);
+ }
+ else {
+ return FALSE;
+ }
+}
+
+function tinymce_user_get_status($user, $profile){
+ $settings = $profile->settings;
+
+ if ($settings['user_choose']) {
+ $status = isset($user->tinymce_status) ? $user->tinymce_status : (isset($settings['default']) ? $settings['default'] : 'false');
+ }
+ else {
+ $status = isset($settings['default']) ? $settings['default'] : 'false';
+ }
+
+ return $status;
}