summaryrefslogtreecommitdiffstats
path: root/tinymce.module
blob: ca4129fc364ecfa25729085d667dc34bb735e26b (plain)
1
2
3
4
5
6
7
8
9
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
42
43
44
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
// $Id$

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.');
  }
}

function tinymce_perm() {
  $array = array('administer tinymce', 'access tinymce');
  $array[] = 'enable tinymce file manager';
  
  return $array;
}

function tinymce_menu($may_cache) {

  $items = array();
  
  $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);
      
  return $items;
}

function tinymce_admin_settings() {
  // only administrators can access this function
  // Generate the form - settings applying to all patterns first
  
  $form['tinymce_settings'] = array(
    '#type' => 'fieldset',
    '#weight' => -20,
    '#title' => t('Basic settings'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE
  );
    
  $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['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['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")
  );
    
  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;  
  
  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();
  }
}

function tinymce_add_javascript() {
  $editor_mode  = variable_get("editor_mode", 0); 
  $editor_element  = variable_get("editor_element", 0); 
  
  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');
  
  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'); }
  
  //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';}
  
  
  drupal_add_js("
    if ('undefined' != typeof(window.tinyMCE)) {
      for (var i=0; i<tinyMCE.configs.length; i++) {
        tinyMCE.configs[i]['elements'] = '$tinymce_elements';
      }
    }
  "
  , 'inline');
}