summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tinymce.module144
1 files changed, 124 insertions, 20 deletions
diff --git a/tinymce.module b/tinymce.module
index ce8d2cd..bc52d10 100644
--- a/tinymce.module
+++ b/tinymce.module
@@ -83,12 +83,22 @@ function tinymce_elements() {
}
/**
+ * Implementation of hook_form_alter()
+ */
+function tinymce_form_alter(&$form, &$form_state) {
+ // disable 'teaser' textarea
+ unset($form['body_field']['teaser_js']);
+ $form['body_field']['teaser_include'] = array();
+}
+
+/**
* Attach tinymce to a textarea
*/
function tinymce_process_textarea($element) {
static $is_running = FALSE;
global $user;
static $profile_name;
+
//$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);
@@ -100,6 +110,7 @@ function tinymce_process_textarea($element) {
return $element;
}
}
+
$profile = tinymce_profile_load($profile_name);
$init = tinymce_config($profile);
$init['elements'] = 'edit-'. $textarea_name;
@@ -107,7 +118,7 @@ function tinymce_process_textarea($element) {
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) {
return $element;
@@ -214,7 +225,6 @@ EOD;
// if tinymce filemanager is installed
drupal_add_js($tinymce_mod_path .'/tinymce/jscripts/tiny_mce/plugins/filemanager/jscripts/mcfilemanager.js');
}
-
// TinyMCE Compressor 1.0.9 and greater
if (file_exists($tinymce_mod_path .'/tinymce/jscripts/tiny_mce/tiny_mce_gzip.js')) {
drupal_add_js($tinymce_mod_path .'/tinymce/jscripts/tiny_mce/tiny_mce_gzip.js');
@@ -235,11 +245,6 @@ EOD;
// Load a TinyMCE init for each textarea.
if ($init) drupal_add_js($tinymce_invoke, 'inline');
- //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;
- }
// Set resizable to false to avoid drupal.js resizable function from taking control of the textarea
$element['#resizable'] = FALSE;
}
@@ -306,12 +311,13 @@ function tinymce_user($type, &$edit, &$user, $category = NULL) {
* request life cycle. It can be ignored.
*/
function theme_tinymce_theme($init, $textarea_name, $theme_name, $is_running) {
- /* uncomment to debug this
+ // uncomment to debug this
- print_r($init);
+/* print_r($init);
print_r($textarea_name);
print_r($theme_name);
- print_r($is_running);*/
+ print_r($is_running);
+*/
switch ($textarea_name) {
// Disable tinymce for these textareas
case 'log': // book and page log
@@ -432,12 +438,34 @@ function _tinymce_get_buttons($skip_metadata = TRUE) {
// Find out the buttons a plugin has.
foreach ($plugin as $k => $v) {
if (strstr($k, 'theme_advanced_buttons')) {
- if (!isset($metadata[$name]['button']))
+ if (!isset($metadata[$name]['buttons']))
$metadata[$name]['buttons'] = $plugin[$k];
else
$metadata[$name]['buttons'] = array_merge((array) $metadata[$name]['button'], $plugin[$k]);
}
}
+
+ // add list of default buttons
+ // source: http://wiki.moxiecode.com/index.php/TinyMCE:Control_reference
+ $name = 'default';
+ $buttons = array(
+ "bold", "italic", "underline", "strikethrough",
+ "justifyleft", "justifycenter", "justifyright", "justifyfull",
+ "bullist", "numlist",
+ "outdent", "indent",
+ "cut", "copy", "paste",
+ "undo", "redo",
+ "link", "unlink",
+ "image", "cleanup", "help", "code", "hr",
+ "removeformat", "formatselect", "fontselect", "fontsizeselect", "styleselect",
+ "sub", "sup",
+ "forecolor", "backcolor", "forecolorpicker", "backcolorpicker",
+ "charmap", "visualaid",
+ "anchor", "newdocument", "blockquote"
+ );
+ foreach ($buttons as $button) {
+ $metadata['default']['buttons'][] = $button;
+ }
}
return $metadata;
}
@@ -464,8 +492,10 @@ function tinymce_config($profile) {
// Is tinymce on by default?
$status = tinymce_user_get_status($user, $profile);
+ $status = 'true';
$init['mode'] = $status == 'true' ? 'exact' : 'none';
+// $init['mode'] = "textareas";
$init['theme'] = $settings['theme'] ? $settings['theme'] : 'advanced';
$init['relative_urls'] = 'false';
$init['document_base_url'] = "$host";
@@ -552,17 +582,82 @@ function tinymce_config($profile) {
if (!isset($init['theme_advanced_buttons2'])) $init['theme_advanced_buttons2'] = array();
if (!isset($init['theme_advanced_buttons3'])) $init['theme_advanced_buttons3'] = array();
+ // bweh - this isn't right!
+ // some buttons should go in a specific order:
+
+ // row 1
+ // - cut
+ // - copy
+ // - paste
+ // - pasteword
+ // - separator
+ // - undo
+ // - redo
+ // - separator
+ // - bold
+ // - italic
+ // - underline
+ // - separator
+
+ // row 2
+ // - formatselect
+ // - fontselect
+ // - fontsizeselect
+ // - separator
+ // - justifyleft
+ // - justifycenter
+ // - justifyright
+ // - justifyfull
+ // - separator
+ // - numlist
+ // - bullist
+ // - indent
+ // - outdent
+
+ $buttons = array_merge($init['theme_advanced_buttons1'], $init['theme_advanced_buttons2'], $init['theme_advanced_buttons3']);
+ $init['theme_advanced_buttons1'] = array();
+ $init['theme_advanced_buttons2'] = array();
+ $init['theme_advanced_buttons3'] = array();
+
+ $row[] = array( array('newdocument', 'save'), array('bold', 'italic', 'underline'), array('undo', 'redo'), array('cut', 'copy', 'paste', 'pasteword'), array('link', 'unlink'), array('image', 'charmap'), array('code') );
+ $row[] = array( array('formatselect', 'fontselect', 'fontsizeselect'), array('justifyleft', 'justifycenter', 'justifyright', 'justifyfull'), array('numlist', 'bullist', 'indent', 'outdent') );
+
+ foreach ($row as $r_index=>$r) {
+ $row_buttons = array();
+ foreach ($r as $rg_index=>$rowgroup) {
+
+ $selected = array_intersect($rowgroup, $buttons);
+
+ if (count($selected)>0) {
+ if (count($row_buttons)>0) {
+ $row_buttons[] = "separator";
+ }
+ $row_buttons = array_merge($row_buttons, $selected);
+ }
+
+ $buttons = array_diff($buttons, $selected);
+ }
+ $init['theme_advanced_buttons' . ($r_index+1)] = $row_buttons;
+ }
+
+ if (count($buttons)>0) {
+ // some buttons are left -> append them to row 3
+ $init['theme_advanced_buttons3'] = array_merge($init['theme_advanced_buttons3'], $buttons);
+ }
+
$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'][] = 'separator';
$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'][] = 'separator';
$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'];
@@ -602,9 +697,12 @@ function tinymce_profile_load($name = '') {
if (!$profiles) {
$roles = user_roles();
- $result = db_query('SELECT * FROM {tinymce_settings}');
+
+ $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)) {
@@ -616,6 +714,7 @@ function tinymce_profile_load($name = '') {
}
}
+
return ($name ? $profiles[$name] : $profiles);
}
@@ -632,20 +731,25 @@ function tinymce_profile_load($name = '') {
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;
- }
- }
+ // This piece of code sometimes fires on textareas that are just
+ // plain HTML; so I disabled it. I want my, I want my, I want my MCE....
+
+// // 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 {