| 1 |
<?php |
<?php |
| 2 |
// $Id: bbcode_wysiwyg.module,v 1.4.4.7 2008/04/29 04:03:50 jrbeeman Exp $ |
// $Id: bbcode_wysiwyg.module,v 1.4.4.8 2008/04/29 04:09:59 jrbeeman Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* Implementation of hook_perm(). |
* Implementation of hook_perm(). |
| 83 |
/** |
/** |
| 84 |
* Provide javascript settings |
* Provide javascript settings |
| 85 |
*/ |
*/ |
| 86 |
function bbcode_wysiwyg_js_settings($is_node, $element) { |
function bbcode_wysiwyg_js_settings($element) { |
| 87 |
$buttons = variable_get('bbcode_wysiwyg_buttons_enabled', array()); |
$buttons_enabled = variable_get('bbcode_wysiwyg_buttons_enabled', array()); |
| 88 |
|
$buttons = array(); |
| 89 |
|
$shortcuts = array( |
| 90 |
|
'bold' => 66, |
| 91 |
|
'italic' => 73, |
| 92 |
|
'quote' => 81, |
| 93 |
|
'link' => 76, |
| 94 |
|
'break' => 82, |
| 95 |
|
'image' => 77, |
| 96 |
|
'center' => 67, |
| 97 |
|
); |
| 98 |
$open_tags = array(); |
$open_tags = array(); |
| 99 |
foreach ($buttons as $key => $value) { |
foreach ($buttons_enabled as $key => $value) { |
| 100 |
$open_tags[$key] = FALSE; |
$open_tags[$key] = FALSE; |
| 101 |
|
if ($buttons_enabled[$key]) { |
| 102 |
|
$buttons[$key] = $shortcuts[$key]; |
| 103 |
|
} |
| 104 |
} |
} |
| 105 |
return array( |
return array( |
| 106 |
'bbcode_wysiwyg' => array( |
'bbcode_wysiwyg' => array( |
| 107 |
'enterLinkURL' => t('Please enter the URL to link to'), |
'enterLinkURL' => t('Please enter the URL to link to'), |
| 108 |
'enterImageURL' => t('Please enter the address of the image to include'), |
'enterImageURL' => t('Please enter the address of the image to include'), |
|
'isNode' => $is_node, |
|
| 109 |
'attachTo' => $element, |
'attachTo' => $element, |
| 110 |
'buttons' => $buttons, |
'buttons' => $buttons, |
| 111 |
'openTags' => $open_tags, |
'openTags' => $open_tags, |
|
'keydown_ctrl' => FALSE, |
|
|
'keydown_shift' => FALSE, |
|
| 112 |
), |
), |
| 113 |
); |
); |
| 114 |
} |
} |
| 117 |
/** |
/** |
| 118 |
* Quick method for adding necessary bbcode javascript and css from any method |
* Quick method for adding necessary bbcode javascript and css from any method |
| 119 |
*/ |
*/ |
| 120 |
function bbcode_wysiwyg_add($is_node, $attach_to) { |
function bbcode_wysiwyg_add($attach_to) { |
| 121 |
drupal_add_js(bbcode_wysiwyg_js_settings($is_node, $attach_to), 'setting'); |
drupal_add_js(bbcode_wysiwyg_js_settings($attach_to), 'setting'); |
| 122 |
drupal_add_js(drupal_get_path('module', 'bbcode_wysiwyg') .'/bbcode_wysiwyg.js'); |
drupal_add_js(drupal_get_path('module', 'bbcode_wysiwyg') .'/bbcode_wysiwyg.js'); |
| 123 |
drupal_add_css(drupal_get_path('module', 'bbcode_wysiwyg') .'/bbcode_wysiwyg.css'); |
drupal_add_css(drupal_get_path('module', 'bbcode_wysiwyg') .'/bbcode_wysiwyg.css'); |
| 124 |
} |
} |
| 129 |
*/ |
*/ |
| 130 |
function bbcode_wysiwyg_form_alter($form_id, &$form) { |
function bbcode_wysiwyg_form_alter($form_id, &$form) { |
| 131 |
$show = FALSE; |
$show = FALSE; |
|
$is_node = FALSE; |
|
| 132 |
$attach_to = ''; |
$attach_to = ''; |
| 133 |
$other_forms = variable_get('bbcode_wysiwyg_other_forms', array()); |
$other_forms = variable_get('bbcode_wysiwyg_other_forms', array()); |
| 134 |
$node_forms = variable_get('bbcode_wysiwyg_node_forms', array()); |
$node_forms = variable_get('bbcode_wysiwyg_node_forms', array()); |
| 135 |
|
|
| 136 |
if ($form['#id'] == 'node-form' && $node_forms[$form['type']['#value']]) { |
if ($form['#id'] == 'node-form' && $node_forms[$form['type']['#value']]) { |
| 137 |
$show = TRUE; |
$show = TRUE; |
|
$is_node = TRUE; |
|
| 138 |
$attach_to = 'edit-body'; |
$attach_to = 'edit-body'; |
| 139 |
} |
} |
| 140 |
else if ($other_forms[$form_id]) { |
else if ($other_forms[$form_id]) { |
| 143 |
} |
} |
| 144 |
|
|
| 145 |
if ($show && user_access('access bbcode formatting bar')) { |
if ($show && user_access('access bbcode formatting bar')) { |
| 146 |
bbcode_wysiwyg_add($is_node, $attach_to); |
bbcode_wysiwyg_add($attach_to); |
| 147 |
} |
} |
| 148 |
} |
} |
| 149 |
|
|