unl_wysiwyg.module 4.21 KB
Newer Older
1
2
3
4
5
6
7
8
<?php

/**
 * Implements of hook_element_info_alter().
 */
function unl_wysiwyg_element_info_alter(&$type) {
  // Change text format processing on elements to our version.
  if (isset($type['text_format'])) {
9
    $type['text_format']['#process'][] = 'unl_wysiwyg_filter_process_format';
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  }
}

/**
 * Callback for processing the text_format element
 */
function unl_wysiwyg_filter_process_format($element) {
  // Only remove the plain_text and filtered_html options on the node edit form. They need to be available on comment forms, etc.
  if (isset($element['#entity_type']) && $element['#entity_type'] == 'node') {
    unset($element['format']['format']['#options']['plain_text']);
    unset($element['format']['format']['#options'][1]); // On production the machine names are integers
    unset($element['format']['format']['#options']['filtered_html']);
    unset($element['format']['format']['#options'][11]);
    $element['format']['format']['#title'] = 'Editor: ';
  }
  return $element;
}

/**
 * Implementation of hook_wysiwyg_editor_settings_alter().
 */
function unl_wysiwyg_wysiwyg_editor_settings_alter(&$settings, $context) {
  switch($context['editor']['name']) {
    case 'tinymce':
      // Set custom settings
      $settings['theme'] = 'advanced';
      $settings['skin'] = 'unl';
      $settings['forced_root_block'] = false;
      $settings['plugins'] .= ',pdw,inlinepopups';

      // Process a default order for the buttons
      $enabled_buttons = preg_split('/,/', $settings['theme_advanced_buttons1']);
42
      $default_buttons = array('formatselect', '|', 'bold', 'italic', 'strikethrough', '|', 'bullist', 'numlist', 'blockquote', '|', 'justifyleft', 'justifycenter','justifyright','|','link', 'unlink', 'image', 'media', '|', 'pastetext', 'pasteword', 'removeformat', '|', 'pdw_toggle',
43
                               'PAGEBREAK', 'styleselect', 'forecolor', 'backcolor', '|', 'underline', '|', 'justifyfull', '|', 'sup', 'sub', 'charmap', '|', 'indent', 'outdent', '|', 'anchor', '|', 'unlGrid', 'unlZenBox', 'unlTooltip', '|', 'undo', 'redo', '|', 'search', 'replace', '|', 'fullscreen', );
44
      foreach ($default_buttons as $button) {
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
        if (in_array($button, $enabled_buttons)) {
          unset($enabled_buttons[array_search($button, $enabled_buttons)]);
        }
        elseif ($button != '|' && $button != 'PAGEBREAK' && $button != 'pdw_toggle') {
          unset($default_buttons[array_search($button, $default_buttons)]);
        }
      }

      // Don't show the button for the codeprotect plugin if the php filter module is disabled
      if (!module_exists('php')) {
        unset($enabled_buttons[array_search('codeprotect', $enabled_buttons)]);
      }

      // Define the final button settings
      $default_buttons_list = preg_split('/,PAGEBREAK,/', implode(',', $default_buttons));
      $settings['theme_advanced_buttons1'] = $default_buttons_list[0];
      $settings['theme_advanced_buttons2'] = $default_buttons_list[1];
      $settings['theme_advanced_buttons3'] = (count($enabled_buttons) > 0) ? implode(',', $enabled_buttons) : NULL;
      $settings['pdw_toggle_on'] = '1';
      $settings['pdw_toggle_toolbars'] = (count($enabled_buttons) > 0) ? '2,3' : '2';
      break;
  }
}

/**
 * Implementation of hook_wywiwyg_plugin() found in wysiwyg.api.php
 */
function unl_wysiwyg_wysiwyg_plugin($editor) {
  switch ($editor) {
    case 'tinymce':
      return array(
        'unl' => array(
          'url' => 'http://github.unl.edu/iim/TinyMCE',
78
          'path' => base_path() . '/sites/all/libraries/tinymcs/jscripts/tiny_mce/plugins/unl',
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
          'internal' => TRUE,
          'load' => TRUE,
          'buttons' => array(
            'unlZenBox' => 'UNL Zenbox',
            'unlGrid' => 'UNL Grid',
            'unlTooltip' => 'UNL Tooltip',
          ),
        ),
        'codeprotect' => array(
          'title' => t('CodeProtect'),
          'url' => 'http://sourceforge.net/tracker/?func=detail&aid=2859676&group_id=103281&atid=738747',
          'path' => wysiwyg_get_path('tinymce_plugins') . '/codeprotect',
          'filename' => 'editor_plugin.js',
          'buttons' => array(
            'codeprotect' => t('CodeProtect'),
          ),
          'load' => TRUE,
          'internal' => FALSE,
        ),
      );
      break;
  }
}