| 1 |
<?php
|
| 2 |
// $Id: bbcode.module,v 1.49 2008/01/18 15:17:02 naudefj Exp $
|
| 3 |
|
| 4 |
function bbcode_help($section) {
|
| 5 |
if ($section == 'admin/modules#description')
|
| 6 |
return t('Allow the use of BBCode in your posts.');
|
| 7 |
}
|
| 8 |
|
| 9 |
function bbcode_filter_tips($delta, $format, $long = false) {
|
| 10 |
if ($long) {
|
| 11 |
include_once(drupal_get_path('module', 'bbcode') .'/bbcode-help.inc');
|
| 12 |
return _bbcode_filter_tip();
|
| 13 |
}
|
| 14 |
else {
|
| 15 |
# D5: $output = t('You can use !BBCode tags in the text.', array('!BBCode' => l(t('BBCode'), "filter/tips/$format", NULL, NULL, 'filter-bbcode-' . $delta)));
|
| 16 |
$output = t('You can use !BBCode tags in the text.', array('!BBCode' => l(t('BBCode'), "filter/tips/$format", array('fragment' => 'filter-bbcode-' . $delta))));
|
| 17 |
if (variable_get("bbcode_make_links_$format", FALSE)) {
|
| 18 |
$output .= ' '. t('URLs will automatically be converted to links.');
|
| 19 |
}
|
| 20 |
return $output;
|
| 21 |
}
|
| 22 |
}
|
| 23 |
|
| 24 |
function bbcode_filter($op, $delta = 0, $format = -1, $text = '') {
|
| 25 |
switch ($op) {
|
| 26 |
case 'list':
|
| 27 |
return array(0 => t('BBCode'));
|
| 28 |
|
| 29 |
case 'description':
|
| 30 |
return t('Converts BBCode to HTML.');
|
| 31 |
|
| 32 |
case 'process':
|
| 33 |
include_once(drupal_get_path('module', 'bbcode') .'/bbcode-filter.inc');
|
| 34 |
if (variable_get("bbcode_debug_$format", 0)) {
|
| 35 |
$timing_start = explode(' ', microtime());
|
| 36 |
$ret = _bbcode_filter_process($text, $format);
|
| 37 |
$timing_stop = explode(' ', microtime());
|
| 38 |
$elapsed = $timing_stop[1] - $timing_start[1];
|
| 39 |
$elapsed += $timing_stop[0] - $timing_start[0];
|
| 40 |
$ret .= '<hr />'. l('BBCode', "filter/tips/$format") .' parsed on '.date('r').'<br />Execution time: '.$elapsed.' seconds.<hr />';
|
| 41 |
return $ret;
|
| 42 |
}
|
| 43 |
else
|
| 44 |
return _bbcode_filter_process($text, $format);
|
| 45 |
|
| 46 |
case 'settings':
|
| 47 |
$form = array();
|
| 48 |
$form['bbcode_filter'] = array(
|
| 49 |
'#type' => 'fieldset',
|
| 50 |
'#title' => t('BBCode filter'),
|
| 51 |
'#collapsible' => TRUE,
|
| 52 |
'#collapsed' => FALSE);
|
| 53 |
$form['bbcode_filter']["bbcode_make_links_$format"] = array(
|
| 54 |
'#type' => 'select',
|
| 55 |
'#title' => t('Convert addresses to links'),
|
| 56 |
'#default_value' => variable_get("bbcode_make_links_$format", 1),
|
| 57 |
'#options' => array(t('Disabled'), t('Enabled')),
|
| 58 |
'#description' => t('Turn web and e-mail addresses into clickable links. This is useful if content authors do not explicitly mark addresses as links with [url] and [email] tags.'));
|
| 59 |
$form['bbcode_filter']["bbcode_filter_nofollow_$format"] = array(
|
| 60 |
'#type' => 'select',
|
| 61 |
'#title' => t('Spam link deterrent'),
|
| 62 |
'#default_value' => variable_get("bbcode_filter_nofollow_$format", 0),
|
| 63 |
'#options' => array(t('Disabled'), t('Enabled')),
|
| 64 |
'#description' => t('If enabled, BBCode will add rel="nofollow" to all links, as a measure to reduce the effectiveness of spam links. Note: this will also prevent valid links from being followed by search engines, therefore it is likely most effective when enabled for anonymous users.'));
|
| 65 |
$form['bbcode_filter']["bbcode_encode_mailto_$format"] = array(
|
| 66 |
'#type' => 'select',
|
| 67 |
'#title' => t('Email address encoding'),
|
| 68 |
'#default_value' => variable_get("bbcode_encode_mailto_$format", 1),
|
| 69 |
'#options' => array(t('Disabled'), t('Enabled')),
|
| 70 |
'#description' => t('Whether to encode email addresses with javascript. With this method you will have clickable mailto links, but it will be a bit harder for spam robots to collect them.'));
|
| 71 |
$form['bbcode_filter']["bbcode_paragraph_breaks_$format"] = array(
|
| 72 |
'#type' => 'select',
|
| 73 |
'#title' => t('Smart paragraph and line breaks'),
|
| 74 |
'#default_value' => variable_get("bbcode_paragraph_breaks_$format", 2),
|
| 75 |
'#options' => array(t('Disabled'), t('Line breaks only'), t('Line and paragraph breaks')),
|
| 76 |
'#description' => t('Add line and paragraph breaks to text, excluding text in preformatted code blocks. If you disable this option, you need to enable Drupal\'s "Line break converter". Don\'t use both together!'));
|
| 77 |
$form['bbcode_filter']["bbcode_debug_$format"] = array(
|
| 78 |
'#type' => 'select',
|
| 79 |
'#title' => t('Print debugging info'),
|
| 80 |
'#default_value' => variable_get("bbcode_debug_$format", 0),
|
| 81 |
'#options' => array(t('Disabled'), t('Enabled')),
|
| 82 |
'#description' => t('Print BBCode parse date and execution time. This option should be disabled on production sites. You may need to clear the cache after changing this option.'));
|
| 83 |
return $form;
|
| 84 |
|
| 85 |
default:
|
| 86 |
return $text;
|
| 87 |
}
|
| 88 |
}
|
| 89 |
|
| 90 |
/* hook_quicktags_alter
|
| 91 |
* Alter icons if the quicktags module is enabled
|
| 92 |
*/
|
| 93 |
function bbcode_quicktags_alter($items) {
|
| 94 |
$path = base_path() . drupal_get_path('module','quicktags') .'/';
|
| 95 |
$items['ed_italic'] = array(
|
| 96 |
'name' => 'italic',
|
| 97 |
'prefix' => '[i]',
|
| 98 |
'suffix' => '[/i]',
|
| 99 |
'accesskey' => 'i',
|
| 100 |
'weight' => 10,
|
| 101 |
'icon' => $path .'ed_italic.png',
|
| 102 |
);
|
| 103 |
$items['ed_bold'] = array(
|
| 104 |
'name' => 'bold',
|
| 105 |
'prefix' => '[b]',
|
| 106 |
'suffix' => '[/b]',
|
| 107 |
'accesskey' => 'b',
|
| 108 |
'weight' => 20,
|
| 109 |
'icon' => $path .'ed_bold.png',
|
| 110 |
);
|
| 111 |
$items['ed_code'] = array(
|
| 112 |
'name' => 'code',
|
| 113 |
'prefix' =>'[code]',
|
| 114 |
'suffix' => '[/code]',
|
| 115 |
'accesskey' => 'c',
|
| 116 |
'weight' => 30,
|
| 117 |
'icon' => $path .'ed_code.png',
|
| 118 |
);
|
| 119 |
$items['ed_block'] = array(
|
| 120 |
'name' => 'quote',
|
| 121 |
'prefix' =>'[quote]',
|
| 122 |
'suffix' => '[/quote]',
|
| 123 |
'accesskey' => 'q',
|
| 124 |
'weight' => 40,
|
| 125 |
'icon' => $path .'ed_block.png',
|
| 126 |
);
|
| 127 |
$items['ed_link'] = array(
|
| 128 |
'name' => 'link',
|
| 129 |
'prefix' =>'[url=http://]',
|
| 130 |
'suffix' => '[/url]',
|
| 131 |
'accesskey' => 'l',
|
| 132 |
'weight' => 50,
|
| 133 |
'icon' => $path .'ed_link.png',
|
| 134 |
);
|
| 135 |
return $items;
|
| 136 |
}
|
| 137 |
|