| 1 |
<?php
|
| 2 |
// $Id: pearwiki_filter.module,v 1.12 2009/08/22 06:41:37 adamgriffiths Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* An input filter which uses the PEAR Text_Wiki package for rendering
|
| 7 |
* different wiki syntax styles.
|
| 8 |
*/
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Implementation of hook_help().
|
| 12 |
* Note this module uses advanced help
|
| 13 |
*/
|
| 14 |
function pearwiki_filter_help($path, $arg) {
|
| 15 |
$output = '';
|
| 16 |
$module= 'pearwiki_filter';
|
| 17 |
$topic= 'index';
|
| 18 |
switch ($path) {
|
| 19 |
case 'admin/help#' . $module :
|
| 20 |
$link = theme('advanced_help_topic', $module, $topic);
|
| 21 |
if($link){
|
| 22 |
$output = advanced_help_view_topic($module, $topic);
|
| 23 |
}else{
|
| 24 |
$output .= t("<p>Full help documentation requires the Advanced Help module
|
| 25 |
is installed. See README.txt for more information.</p>");
|
| 26 |
}
|
| 27 |
break;
|
| 28 |
}
|
| 29 |
|
| 30 |
return $output;
|
| 31 |
}
|
| 32 |
|
| 33 |
function pearwiki_filter_get_help_popup_link($topic='index'){
|
| 34 |
//TODO return an alternative location if advanced help is not installed.
|
| 35 |
$output = '';
|
| 36 |
$module= 'pearwiki_filter';
|
| 37 |
$link = theme('advanced_help_topic', $module, $topic);
|
| 38 |
if($link){
|
| 39 |
$output = '' . $link . '';
|
| 40 |
}else{
|
| 41 |
$output .= l(t('(help page)'),'admin/help/' . $module);
|
| 42 |
}
|
| 43 |
return $output;
|
| 44 |
}
|
| 45 |
/*
|
| 46 |
* Setup functions
|
| 47 |
*/
|
| 48 |
|
| 49 |
/**
|
| 50 |
* Implementation of hook_filter().
|
| 51 |
*/
|
| 52 |
function pearwiki_filter_filter($op, $delta = 0, $format = -1, $text = '') {
|
| 53 |
switch ($op) {
|
| 54 |
case 'list':
|
| 55 |
return array(t('PEAR Wiki Filter'));
|
| 56 |
|
| 57 |
case 'description':
|
| 58 |
return t('Filter which uses PEAR Wiki parsers.') . pearwiki_filter_get_help_popup_link() ;
|
| 59 |
|
| 60 |
case 'process':
|
| 61 |
return pearwiki_filter_process($text, $format);
|
| 62 |
|
| 63 |
case 'settings':
|
| 64 |
return pearwiki_filter_filter_settings($format);
|
| 65 |
|
| 66 |
case 'no cache':
|
| 67 |
return FALSE;
|
| 68 |
|
| 69 |
default:
|
| 70 |
return $text;
|
| 71 |
}
|
| 72 |
}
|
| 73 |
|
| 74 |
/**
|
| 75 |
* Implementation of hook_filter_tips().
|
| 76 |
*/
|
| 77 |
function pearwiki_filter_filter_tips($delta, $format, $long = FALSE) {
|
| 78 |
$output = '';
|
| 79 |
|
| 80 |
$formatname = pearwiki_filter_syntax($format);
|
| 81 |
$helpfunction = 'pearwiki_filter_'. strtolower($formatname) .'_help';
|
| 82 |
// Try the syntax specific helper function first.
|
| 83 |
if (function_exists($helpfunction)) {
|
| 84 |
$output = $helpfunction('tips', $long, $format);
|
| 85 |
$url = $helpfunction('syntax_url');
|
| 86 |
}
|
| 87 |
if ($output) {
|
| 88 |
// Output was produced by format specific function.
|
| 89 |
}
|
| 90 |
elseif ($url) {
|
| 91 |
// No output was produced, but an url to the wiki syntax was provided.
|
| 92 |
$output = '<p>'. t('You can use <a href="!url">%wiki syntax</a>. It is possible that not all formatting options are supported at the moment.', array('!url' => $url, '%wiki' => $formatname)) .'</p>';
|
| 93 |
}
|
| 94 |
else {
|
| 95 |
// Default help text.
|
| 96 |
$output = '<p>'. t('You can use %wiki syntax.It is possible that not all formatting options are supported at the moment.', array('%wiki' => $formatname)) .'</p>';
|
| 97 |
$output .= pearwiki_filter_interwiki_help_tip($format, $long);
|
| 98 |
}
|
| 99 |
return $output;
|
| 100 |
}
|
| 101 |
|
| 102 |
/**
|
| 103 |
* Callback for settings formular
|
| 104 |
*/
|
| 105 |
function pearwiki_filter_filter_settings($format) {
|
| 106 |
$form = array();
|
| 107 |
$form['pearwiki_filter'] = array(
|
| 108 |
'#type' => 'fieldset',
|
| 109 |
'#title' => t('PEAR Wiki filter'),
|
| 110 |
'#collapsible' => TRUE,
|
| 111 |
);
|
| 112 |
$form['pearwiki_filter']['pearwiki_filter_pear_path_'. $format] = array(
|
| 113 |
'#type' => 'textfield',
|
| 114 |
'#title' => t('Path of PEAR packages'),
|
| 115 |
'#default_value' => pearwiki_filter_pear_path($format),
|
| 116 |
'#description' => t('Specify the base path of the Text_Wiki PEAR package.') . pearwiki_filter_get_help_popup_link('locating_pear_packages'),
|
| 117 |
);
|
| 118 |
$parsers = array();
|
| 119 |
foreach (pearwiki_filter_parsers($format) as $parser) {
|
| 120 |
$url = '';
|
| 121 |
$name = '';
|
| 122 |
$helpfunction = 'pearwiki_filter_'. strtolower($parser) .'_help';
|
| 123 |
if (function_exists($helpfunction)) {
|
| 124 |
$url = $helpfunction('syntax_url');
|
| 125 |
$name = $helpfunction('name');
|
| 126 |
}
|
| 127 |
if (!$name)
|
| 128 |
$name = $parser;
|
| 129 |
if ($url) {
|
| 130 |
$parsers[$parser] = '<a href="'. $url .'">'. $name .'</a>';
|
| 131 |
}
|
| 132 |
else {
|
| 133 |
$parsers[$parser] = $name;
|
| 134 |
}
|
| 135 |
}
|
| 136 |
if (count($parsers)) {
|
| 137 |
$form['pearwiki_filter']['pearwiki_filter_syntax_'. $format] = array(
|
| 138 |
'#type' => 'radios',
|
| 139 |
'#title' => t('Format'),
|
| 140 |
'#default_value' => pearwiki_filter_syntax($format),
|
| 141 |
'#options' => $parsers,
|
| 142 |
'#description' => t('Select the Wikiformat to use. Click on a name to view an overview of the syntax.'),
|
| 143 |
);
|
| 144 |
}
|
| 145 |
else {
|
| 146 |
$form['pearwiki_filter']['pearwiki_filter_syntax_'. $format] = array(
|
| 147 |
'#value' => '<p class="error">'.
|
| 148 |
t('PEAR Text/Wiki installation not found. Looked in directory %dir.<br/>'.
|
| 149 |
'There should be a <em>Text</em> directory with a file <em>Wiki.php</em> in it.' . pearwiki_filter_get_help_popup_link('locating_pear_packages'),
|
| 150 |
array('%dir' => pearwiki_filter_pear_path($format))) .'</p>',
|
| 151 |
);
|
| 152 |
}
|
| 153 |
// Compatibility options
|
| 154 |
// ---------------------
|
| 155 |
$form['pearwiki_filter']['compatibility'] = array(
|
| 156 |
'#type' => 'fieldset',
|
| 157 |
'#title' => 'Compatibility',
|
| 158 |
'#description' => t('The following options control ... .')
|
| 159 |
);
|
| 160 |
$form['pearwiki_filter']['compatibility']['pearwiki_filter_allow_html_'. $format] = array(
|
| 161 |
'#type' => 'checkbox',
|
| 162 |
'#title' => t('Allow HTML?'),
|
| 163 |
'#default_value' => pearwiki_filter_allow_html($format),
|
| 164 |
'#description' => t('Allow HTML tags to be used.'),
|
| 165 |
);
|
| 166 |
$form['pearwiki_filter']['compatibility']['pearwiki_filter_ignore_tags_'. $format] = array(
|
| 167 |
'#type' => 'textfield',
|
| 168 |
'#title' => t('Ignore tags'),
|
| 169 |
'#default_value' => pearwiki_filter_ignore_tags($format),
|
| 170 |
'#description' => t('Tags which are fully ignored (the tag, attributes and content is untouched). Use this for compatibility with other filters. Specify a space-separated list of tagnames.<br/>Example: If you specify <em>code</em> than the filter ignores <code type="php"> ... </code> which can then be processed by other filters like the <a href="http://drupal.tschannen.net/wiki/geshi_filter">GeSHi filter</a>. This can introduce a security risk through XSS scripting. Make sure the ignored text will be processed by another filter.')
|
| 171 |
);
|
| 172 |
$form['pearwiki_filter']['compatibility']['pearwiki_filter_ignore_regexp_'. $format] = array(
|
| 173 |
'#type' => 'textfield',
|
| 174 |
'#title' => t('Ignore regexp'),
|
| 175 |
'#default_value' => pearwiki_filter_ignore_regexp($format),
|
| 176 |
'#description' => t('A regular expression where the match is ignored (the full match is untouched). Use this for compatibility with other filters. This can introduce a security risk through XSS scripting. Make sure the ignored text will be processed by another filter.')
|
| 177 |
);
|
| 178 |
// Wikilink options
|
| 179 |
// ----------------
|
| 180 |
$form['pearwiki_filter']['wikilinks'] = array(
|
| 181 |
'#type' => 'fieldset',
|
| 182 |
'#title' => 'Wikilinks',
|
| 183 |
'#description' => t('The following options control the behavior when wikilinks are used. It is recommended to use one of the additional modules, but only check one. The modules need to be enabled in order to check them.')
|
| 184 |
);
|
| 185 |
$form['pearwiki_filter']['wikilinks']['pearwiki_filter_use_wiki_links_'. $format] = array(
|
| 186 |
'#type' => 'checkbox',
|
| 187 |
'#title' => t('Use wiki links?'),
|
| 188 |
'#default_value' => pearwiki_filter_use_wiki_links($format),
|
| 189 |
'#description' => t('Are wiki links activated? If this option is not activated, wikilinks will not be parsed.')
|
| 190 |
);
|
| 191 |
$form['pearwiki_filter']['wikilinks']['pearwiki_filter_space_replacement_'. $format] = array(
|
| 192 |
'#type' => 'textfield',
|
| 193 |
'#title' => t('Replacement for Spaces'),
|
| 194 |
'#default_value' => pearwiki_filter_space_replacement($format),
|
| 195 |
'#description' => t('Set the replacement character for spaces in wikilinks. If left emtpy, no replacement will be made. Set the value to the same as in the autopath module, so a title of a node becomes a wikilink. This option is ignored for the <em>Mediawiki</em> format since the parser alredy replaces spaces with underscores.')
|
| 196 |
);
|
| 197 |
$form['pearwiki_filter']['wikilinks']['pearwiki_filter_wikilink_base_'. $format] = array(
|
| 198 |
'#type' => 'textfield',
|
| 199 |
'#title' => t('Base path for wikilinks'),
|
| 200 |
'#default_value' => pearwiki_filter_wikilink_base($format),
|
| 201 |
'#description' => t('If none of the next three options is used, this path will be prepended to wikilinks.')
|
| 202 |
);
|
| 203 |
$form['pearwiki_filter']['wikilinks']['pearwiki_filter_use_wikitools_'. $format] = array(
|
| 204 |
'#type' => 'checkbox',
|
| 205 |
'#title' => l(t('Use wikitools?'), 'http://drupal.org/project/wikitools'),
|
| 206 |
'#default_value' => pearwiki_filter_use_wikitools($format),
|
| 207 |
'#description' => t('Use wikitools to create links. When enabled, all links are passed to the wikitools module for handling and have the wikipath prepended which is specified in the wikitools settings. The module wikitools has to be enabled.'),
|
| 208 |
);
|
| 209 |
if (!module_exists('wikitools')) {
|
| 210 |
$form['pearwiki_filter']['wikilinks']['pearwiki_filter_use_wikitools_'. $format]['#default_value'] = FALSE;
|
| 211 |
$form['pearwiki_filter']['wikilinks']['pearwiki_filter_use_wikitools_'. $format]['#disabled'] = TRUE;
|
| 212 |
}
|
| 213 |
$form['pearwiki_filter']['wikilinks']['pearwiki_filter_use_liquid_'. $format] = array(
|
| 214 |
'#type' => 'checkbox',
|
| 215 |
'#title' => l(t('Use liquid?'), 'http://drupal.org/project/liquid'),
|
| 216 |
'#default_value' => pearwiki_filter_use_wikitools($format),
|
| 217 |
'#description' => t('Use liquid to create links. When enabled, all wikilinks are of the form \'wiki/Page Title\'. The module liquid has to be enabled.'),
|
| 218 |
);
|
| 219 |
if (!module_exists('liquid')) {
|
| 220 |
$form['pearwiki_filter']['wikilinks']['pearwiki_filter_use_liquid_'. $format]['#default_value'] = FALSE;
|
| 221 |
$form['pearwiki_filter']['wikilinks']['pearwiki_filter_use_liquid_'. $format]['#disabled'] = TRUE;
|
| 222 |
}
|
| 223 |
$form['pearwiki_filter']['wikilinks']['pearwiki_filter_use_freelinking_'. $format] = array(
|
| 224 |
'#type' => 'checkbox',
|
| 225 |
'#title' => l(t('Use freelinking?'), 'http://drupal.org/project/freelinking'),
|
| 226 |
'#default_value' => pearwiki_filter_use_freelinking($format),
|
| 227 |
'#description' => t('Use freelinking to create links. When enabled, all links are passed to the freelinking module for handling, thus they have the form \'freelinking/Page Title\'. The module freelinking has to be enabled, but you don\'t have to activate the freelinking filter for this format.'),
|
| 228 |
);
|
| 229 |
if (!module_exists('freelinking')) {
|
| 230 |
$form['pearwiki_filter']['wikilinks']['pearwiki_filter_use_freelinking_'. $format]['#default_value'] = FALSE;
|
| 231 |
$form['pearwiki_filter']['wikilinks']['pearwiki_filter_use_freelinking_'. $format]['#disabled'] = TRUE;
|
| 232 |
}
|
| 233 |
$form['pearwiki_filter']['wikilinks']['pearwiki_filter_interwiki_mapping_'. $format] = array(
|
| 234 |
'#type' => 'textarea',
|
| 235 |
'#title' => t('Interwiki Mapping'),
|
| 236 |
'#default_value' => pearwiki_filter_interwiki_mapping_text($format),
|
| 237 |
'#description' => t('A list of interwiki mappings Each line denotes one mapping. The format is: <em>title</em> | <em>interwiki name</em> | <em>mapping url</em>. <br /><path> is a special mapping url which will be transformed into a Drupal path for the current site.')
|
| 238 |
);
|
| 239 |
// Image options
|
| 240 |
// -------------
|
| 241 |
$form['pearwiki_filter']['images'] = array(
|
| 242 |
'#type' => 'fieldset',
|
| 243 |
'#title' => 'Images',
|
| 244 |
'#description' => t('The following options control the behavior when image links are used.')
|
| 245 |
);
|
| 246 |
$form['pearwiki_filter']['images']['pearwiki_filter_image_base_'. $format] = array(
|
| 247 |
'#type' => 'textfield',
|
| 248 |
'#title' => t('Base path for images'),
|
| 249 |
'#default_value' => pearwiki_filter_image_base($format),
|
| 250 |
'#description' => t('Base path for images. Images will be looked for in this directory.')
|
| 251 |
);
|
| 252 |
$form['pearwiki_filter']['images']['pearwiki_filter_use_image_'. $format] = array(
|
| 253 |
'#type' => 'checkbox',
|
| 254 |
'#title' => l(t('Use image module?'), 'http://drupal.org/project/image'),
|
| 255 |
'#default_value' => pearwiki_filter_use_image($format),
|
| 256 |
'#description' => t('Use image module to link images. When enabled, the title of the image name will be searched for in the uploaded image nodes. The module image has to be enabled.'),
|
| 257 |
);
|
| 258 |
if (!module_exists('image')) {
|
| 259 |
$form['pearwiki_filter']['images']['pearwiki_filter_use_image_'. $format]['#default_value'] = FALSE;
|
| 260 |
$form['pearwiki_filter']['images']['pearwiki_filter_use_image_'. $format]['#disabled'] = TRUE;
|
| 261 |
}
|
| 262 |
return $form;
|
| 263 |
}
|
| 264 |
|
| 265 |
/*
|
| 266 |
* Settings
|
| 267 |
*/
|
| 268 |
|
| 269 |
/**
|
| 270 |
* Wiki syntax to use for $format.
|
| 271 |
*/
|
| 272 |
function pearwiki_filter_syntax($format, $value = NULL) {
|
| 273 |
if (is_null($value)) {
|
| 274 |
return variable_get('pearwiki_filter_syntax_'. $format, 'Mediawiki');
|
| 275 |
}
|
| 276 |
variable_set('pearwiki_filter_syntax_'. $format, $value);
|
| 277 |
}
|
| 278 |
|
| 279 |
/**
|
| 280 |
* Location of override directory for $format
|
| 281 |
*/
|
| 282 |
function pearwiki_filter_pear_override_directory($format, $value = NULL) {
|
| 283 |
if (is_null($value)) {
|
| 284 |
return variable_get('pearwiki_filter_override_path_'. $format, getcwd() .'/'. drupal_get_path('module', 'pearwiki_filter') .'/pear_override');
|
| 285 |
}
|
| 286 |
variable_set('pearwiki_filter_override_path_'. $format, $value);
|
| 287 |
}
|
| 288 |
|
| 289 |
/**
|
| 290 |
* Location of PEAR packages for $format.
|
| 291 |
*/
|
| 292 |
function pearwiki_filter_pear_path($format, $value = NULL) {
|
| 293 |
if (is_null($value)) {
|
| 294 |
return variable_get('pearwiki_filter_pear_path_'. $format, getcwd() .'/'. drupal_get_path('module', 'pearwiki_filter') .'/');
|
| 295 |
}
|
| 296 |
variable_set('pearwiki_filter_pear_path_'. $format, $value);
|
| 297 |
}
|
| 298 |
|
| 299 |
/**
|
| 300 |
* Is basic HTML allowed?
|
| 301 |
*/
|
| 302 |
function pearwiki_filter_allow_html($format, $value = NULL) {
|
| 303 |
if (is_null($value)) {
|
| 304 |
return variable_get('pearwiki_filter_allow_html_'. $format, TRUE);
|
| 305 |
}
|
| 306 |
variable_set('pearwiki_filter_allow_html_'. $format, $value);
|
| 307 |
}
|
| 308 |
|
| 309 |
/**
|
| 310 |
* Space-separated list of tag names which are ignored while rendering.
|
| 311 |
*/
|
| 312 |
function pearwiki_filter_ignore_tags($format, $value = NULL) {
|
| 313 |
if (is_null($value)) {
|
| 314 |
return variable_get('pearwiki_filter_ignore_tags_'. $format, '');
|
| 315 |
}
|
| 316 |
variable_set('pearwiki_filter_ignore_tags_'. $format, $value);
|
| 317 |
}
|
| 318 |
|
| 319 |
/**
|
| 320 |
* Regular expression whose match is ignored while rendering.
|
| 321 |
*/
|
| 322 |
function pearwiki_filter_ignore_regexp($format, $value = NULL) {
|
| 323 |
if (is_null($value)) {
|
| 324 |
return variable_get('pearwiki_filter_ignore_regexp_'. $format, '');
|
| 325 |
}
|
| 326 |
variable_set('pearwiki_filter_ignore_regexp_'. $format, $value);
|
| 327 |
}
|
| 328 |
|
| 329 |
/**
|
| 330 |
* Are wikilinks transformed into links?
|
| 331 |
*/
|
| 332 |
function pearwiki_filter_use_wiki_links($format, $value = NULL) {
|
| 333 |
if (is_null($value)) {
|
| 334 |
return variable_get('pearwiki_filter_use_wiki_links_'. $format, TRUE);
|
| 335 |
}
|
| 336 |
variable_set('pearwiki_filter_use_wiki_links_'. $format, $value);
|
| 337 |
}
|
| 338 |
|
| 339 |
/**
|
| 340 |
* Base path for wikilinks.
|
| 341 |
*/
|
| 342 |
function pearwiki_filter_wikilink_base($format, $value = NULL) {
|
| 343 |
if (is_null($value)) {
|
| 344 |
return variable_get('pearwiki_filter_wikilink_base_'. $format, 'wiki/');
|
| 345 |
}
|
| 346 |
variable_set('pearwiki_filter_wikilink_base_'. $format, $value);
|
| 347 |
}
|
| 348 |
|
| 349 |
/**
|
| 350 |
* Is freelinking used for wikilinks?
|
| 351 |
*/
|
| 352 |
function pearwiki_filter_use_freelinking($format, $value = NULL) {
|
| 353 |
if (is_null($value)) {
|
| 354 |
return variable_get('pearwiki_filter_use_freelinking_'. $format, FALSE);
|
| 355 |
}
|
| 356 |
variable_set('pearwiki_filter_use_freelinking_'. $format, $value);
|
| 357 |
}
|
| 358 |
|
| 359 |
/**
|
| 360 |
* Is wikitools used for wikilinks?
|
| 361 |
*/
|
| 362 |
function pearwiki_filter_use_wikitools($format, $value = NULL) {
|
| 363 |
if (is_null($value)) {
|
| 364 |
return variable_get('pearwiki_filter_use_wikitools_'. $format, FALSE);
|
| 365 |
}
|
| 366 |
variable_set('pearwiki_filter_use_wikitools_'. $format, $value);
|
| 367 |
}
|
| 368 |
|
| 369 |
/**
|
| 370 |
* Is liquid used for wikilinks?
|
| 371 |
*/
|
| 372 |
function pearwiki_filter_use_liquid($format, $value = NULL) {
|
| 373 |
if (is_null($value)) {
|
| 374 |
return variable_get('pearwiki_filter_use_liquid_'. $format, FALSE);
|
| 375 |
}
|
| 376 |
variable_set('pearwiki_filter_use_liquid_'. $format, $value);
|
| 377 |
}
|
| 378 |
|
| 379 |
|
| 380 |
/**
|
| 381 |
* Unprocessed text for interwiki mappings.
|
| 382 |
*/
|
| 383 |
function pearwiki_filter_interwiki_mapping_text($format, $value = NULL) {
|
| 384 |
if (is_null($value)) {
|
| 385 |
return variable_get('pearwiki_filter_interwiki_mapping_'. $format, t('Local drupal path') ." | path | <path>\ngroups.drupal.org | gdo | http://groups.drupal.org/freelinking/%s\nWikipedia | wp | http://en.wikipedia.org/wiki/%s\n");
|
| 386 |
}
|
| 387 |
variable_set('pearwiki_filter_interwiki_mapping_'. $format, $value);
|
| 388 |
}
|
| 389 |
|
| 390 |
/**
|
| 391 |
* Information about interwiki mappings.
|
| 392 |
* @param $op
|
| 393 |
* when 'url' is passed, returns an array with interwiki ids as key and url mapping as values
|
| 394 |
* when 'array' is passed, returns an array with interwiki ids as key and an associative array with 'id', 'title' and 'url' as values.
|
| 395 |
*/
|
| 396 |
function pearwiki_filter_interwiki_mappings($format, $op = 'url') {
|
| 397 |
$mappings = array();
|
| 398 |
$lines = explode("\n", pearwiki_filter_interwiki_mapping_text($format));
|
| 399 |
foreach ($lines as $line) {
|
| 400 |
if ($line) {
|
| 401 |
list($title, $id, $url) = explode('|', $line, 3);
|
| 402 |
if (trim($url) == '<path>') {
|
| 403 |
$url = str_replace('__QUERY_POSITION__', '%s', url('__QUERY_POSITION__'));
|
| 404 |
}
|
| 405 |
if ($op == 'url') {
|
| 406 |
$mappings[trim($id)] = trim($url);
|
| 407 |
}
|
| 408 |
elseif ($op == 'array') {
|
| 409 |
$mappings[trim($id)] = array(
|
| 410 |
'id' => trim($id),
|
| 411 |
'title' => trim($title),
|
| 412 |
'url' => trim($url)
|
| 413 |
);
|
| 414 |
}
|
| 415 |
}
|
| 416 |
}
|
| 417 |
return $mappings;
|
| 418 |
}
|
| 419 |
|
| 420 |
/**
|
| 421 |
* Replacement for spaces in wiki links.
|
| 422 |
* Mediawiki ignores this option and always replaces with an underscore
|
| 423 |
*/
|
| 424 |
function pearwiki_filter_space_replacement($format, $value = NULL) {
|
| 425 |
if (is_null($value)) {
|
| 426 |
return variable_get('pearwiki_filter_space_replacement_'. $format, variable_get('pathauto_separator', ''));
|
| 427 |
}
|
| 428 |
variable_set('pearwiki_filter_space_replacement_'. $format, $value);
|
| 429 |
}
|
| 430 |
|
| 431 |
/**
|
| 432 |
* Base path for image lookup.
|
| 433 |
*/
|
| 434 |
function pearwiki_filter_image_base($format, $value = NULL) {
|
| 435 |
if (is_null($value)) {
|
| 436 |
return variable_get('pearwiki_filter_image_base_'. $format, 'files/');
|
| 437 |
}
|
| 438 |
variable_set('pearwiki_filter_image_base_'. $format, $value);
|
| 439 |
}
|
| 440 |
|
| 441 |
/**
|
| 442 |
* Base path for image lookup.
|
| 443 |
*/
|
| 444 |
function pearwiki_filter_use_image($format, $value = NULL) {
|
| 445 |
if (is_null($value)) {
|
| 446 |
return variable_get('pearwiki_filter_use_image_'. $format, TRUE);
|
| 447 |
}
|
| 448 |
variable_set('pearwiki_filter_use_image_'. $format, $value);
|
| 449 |
}
|
| 450 |
|
| 451 |
/**
|
| 452 |
* List of available parsers.
|
| 453 |
*/
|
| 454 |
function pearwiki_filter_parsers($format) {
|
| 455 |
$result = array();
|
| 456 |
$dirname = realpath(pearwiki_filter_pear_path($format)) .'/Text/Wiki';
|
| 457 |
if (is_dir($dirname)) {
|
| 458 |
$handle = opendir($dirname);
|
| 459 |
while ($file = readdir($handle)) {
|
| 460 |
if ($file != 'Render.php' && $file != 'Parse.php' && is_file($dirname .'/'. $file)) {
|
| 461 |
$result[basename($file, '.php')] = basename($file, '.php');
|
| 462 |
}
|
| 463 |
}
|
| 464 |
closedir($handle);
|
| 465 |
}
|
| 466 |
return $result;
|
| 467 |
}
|
| 468 |
|
| 469 |
/*
|
| 470 |
* Operations
|
| 471 |
*/
|
| 472 |
|
| 473 |
/**
|
| 474 |
* Parse 'text' and apply the wiki-formatting.
|
| 475 |
*/
|
| 476 |
function pearwiki_filter_process($text, $format) {
|
| 477 |
global $pearwiki_current_format;
|
| 478 |
|
| 479 |
// Global option for custom implementation of Text_Wiki rules which
|
| 480 |
// need the options of the current format.
|
| 481 |
$pearwiki_current_format = $format;
|
| 482 |
|
| 483 |
// load PEAR files if necessary
|
| 484 |
ini_set('include_path', realpath(pearwiki_filter_pear_path($format)) . PATH_SEPARATOR . ini_get('include_path'));
|
| 485 |
if (!class_exists('Text_Wiki')) {
|
| 486 |
@include_once 'Text/Wiki.php';
|
| 487 |
}
|
| 488 |
if (!class_exists('Text_Wiki')) {
|
| 489 |
// loading of PEAR failed
|
| 490 |
drupal_set_message(t('Loading of <em>Text_Wiki</em> class from PEAR failed. Check your <a href="@url">filter settings</a>.', array('@url' => url('admin/settings/filters/'. $format .'/configure'))), 'error');
|
| 491 |
return '<pre>'. check_plain($text) .'</pre>';
|
| 492 |
}
|
| 493 |
|
| 494 |
$formatname = pearwiki_filter_syntax($format);
|
| 495 |
$wiki =& Text_Wiki::singleton($formatname);
|
| 496 |
|
| 497 |
// add path used to insert or overwrite parse/render rules
|
| 498 |
$wiki->addPath('parse', realpath(pearwiki_filter_pear_override_directory($format)) .'/parse');
|
| 499 |
$wiki->addPath('render', realpath(pearwiki_filter_pear_override_directory($format)) .'/render');
|
| 500 |
|
| 501 |
// general parse setup
|
| 502 |
if (pearwiki_filter_ignore_regexp($format)) {
|
| 503 |
$wiki->insertRule('ignoreregexp', 'delimiter');
|
| 504 |
}
|
| 505 |
if (pearwiki_filter_ignore_tags($format)) {
|
| 506 |
$wiki->insertRule('ignoretag', 'delimiter');
|
| 507 |
}
|
| 508 |
if (pearwiki_filter_allow_html($format)) {
|
| 509 |
$wiki->insertRule('ignorehtml', 'delimiter');
|
| 510 |
}
|
| 511 |
if (!pearwiki_filter_use_wiki_links($format)) {
|
| 512 |
$wiki->disableRule('wikilink');
|
| 513 |
}
|
| 514 |
|
| 515 |
// General render setup
|
| 516 |
// Todo: this is at the moment directly called from the wikilink render rule
|
| 517 |
// $wiki->setRenderConf('xhtml', 'wikilink', 'exists_callback', 'pearwiki_filter_page_path');
|
| 518 |
$wiki->setRenderConf('xhtml', 'wikilink', 'view_url', base_path());
|
| 519 |
$wiki->setRenderConf('xhtml', 'wikilink', 'new_url', base_path());
|
| 520 |
$wiki->setRenderConf('xhtml', 'wikilink', 'css', NULL);
|
| 521 |
$wiki->setRenderConf('xhtml', 'wikilink', 'css_new', NULL);
|
| 522 |
$wiki->setRenderConf('xhtml', 'wikilink', 'style_new', NULL);
|
| 523 |
$wiki->setRenderConf('xhtml', 'wikilink', 'new_text', NULL);
|
| 524 |
$wiki->setRenderConf('xhtml', 'wikilink', 'target', NULL);
|
| 525 |
$wiki->setRenderConf('xhtml', 'interwiki', 'target', NULL);
|
| 526 |
$wiki->setRenderConf('xhtml', 'interwiki', 'sites', pearwiki_filter_interwiki_mappings($format));
|
| 527 |
$wiki->setRenderConf('xhtml', 'url', 'target', NULL);
|
| 528 |
$wiki->setRenderConf('xhtml', 'image', 'base', pearwiki_filter_image_base($format));
|
| 529 |
|
| 530 |
// Load format dependent options
|
| 531 |
$setupfunction = 'pearwiki_filter_'. strtolower($formatname) .'_config';
|
| 532 |
if (function_exists($setupfunction)) {
|
| 533 |
$setupfunction($wiki, $format);
|
| 534 |
}
|
| 535 |
|
| 536 |
$wiki->parse($text);
|
| 537 |
|
| 538 |
// Note: for the format config the X of Xhtml has to be in uppercase in the CVS Version of 12/20/06
|
| 539 |
// if this options is not set, special characters like ä,ö,ü dont work properly although the default encoding allow them
|
| 540 |
$wiki->setFormatConf('Xhtml', 'translate', HTML_SPECIALCHARS);
|
| 541 |
|
| 542 |
$output = $wiki->render();
|
| 543 |
|
| 544 |
if (pearwiki_filter_allow_html($format)) {
|
| 545 |
$output = filter_xss_admin($output);
|
| 546 |
}
|
| 547 |
return $output;
|
| 548 |
}
|
| 549 |
|
| 550 |
/**
|
| 551 |
* Callback to get drupal path for a page title.
|
| 552 |
*/
|
| 553 |
function pearwiki_filter_page_path($page) {
|
| 554 |
global $pearwiki_current_format;
|
| 555 |
|
| 556 |
$space_replacement = pearwiki_filter_space_replacement($pearwiki_current_format);
|
| 557 |
if ($space_replacement) {
|
| 558 |
$page = str_replace(' ', $space_replacement, $page);
|
| 559 |
}
|
| 560 |
|
| 561 |
$path = '';
|
| 562 |
|
| 563 |
// When wikitools is enabled, just create a wikitools link.
|
| 564 |
if (pearwiki_filter_use_wikitools($pearwiki_current_format) && module_exists('wikitools')) {
|
| 565 |
$path = wikitools_wikilink_drupal_path($page);
|
| 566 |
}
|
| 567 |
elseif (pearwiki_filter_use_freelinking($pearwiki_current_format)) {
|
| 568 |
// When freelinking is enabled, just create a freelinking link.
|
| 569 |
$path = 'freelinking/'. urlencode($page);
|
| 570 |
}
|
| 571 |
elseif (pearwiki_filter_use_liquid($pearwiki_current_format)) {
|
| 572 |
// When liquid is enabled, create a link to liquid.
|
| 573 |
$path = 'wiki/'. urlencode($page);
|
| 574 |
}
|
| 575 |
else {
|
| 576 |
// Try to find the node and link to it directly.
|
| 577 |
$node = db_fetch_object(db_query("SELECT nid FROM {node} WHERE LOWER(title)=LOWER('%s')", $page));
|
| 578 |
if ($node) {
|
| 579 |
$path = 'node/'. $node->nid;
|
| 580 |
}
|
| 581 |
else {
|
| 582 |
// The page was not found.
|
| 583 |
$path = pearwiki_filter_wikilink_base($pearwiki_current_format) . urlencode($page);
|
| 584 |
}
|
| 585 |
}
|
| 586 |
return (variable_get('clean_url', 0) ? '' : '?q=') . $path;
|
| 587 |
}
|
| 588 |
|
| 589 |
/*
|
| 590 |
* Format sepcific helper functions
|
| 591 |
*/
|
| 592 |
|
| 593 |
function pearwiki_filter_interwiki_help_tip($format, $long = FALSE) {
|
| 594 |
$output = '';
|
| 595 |
$mappings = pearwiki_filter_interwiki_mappings($format, 'array');
|
| 596 |
if (count($mappings)) {
|
| 597 |
if ($long) {
|
| 598 |
$output .= '<p>'. t('You can use the following interwiki links:') .'</p>';
|
| 599 |
$output .= '<ul>';
|
| 600 |
foreach ($mappings as $key => $info) {
|
| 601 |
$output .= '<li>'. $key .': '. $info['title'] . t(' - mapped to %url', array('%url' => $info['url'])) .'</li>';
|
| 602 |
}
|
| 603 |
$output .= '</ul>';
|
| 604 |
}
|
| 605 |
else {
|
| 606 |
$output .= t('You can use the following interwiki links: ');
|
| 607 |
$output .= implode(', ', array_keys($mappings));
|
| 608 |
}
|
| 609 |
}
|
| 610 |
return $output;
|
| 611 |
}
|
| 612 |
|
| 613 |
// Mediawiki specific functions
|
| 614 |
// ----------------------------
|
| 615 |
|
| 616 |
function pearwiki_filter_mediawiki_help($op, $long = FALSE, $format = 0) {
|
| 617 |
switch ($op) {
|
| 618 |
case 'name':
|
| 619 |
return 'Mediawiki';
|
| 620 |
|
| 621 |
case 'syntax_url':
|
| 622 |
return 'http://meta.wikimedia.org/wiki/Cheatsheet';
|
| 623 |
|
| 624 |
case 'tips':
|
| 625 |
$output = '';
|
| 626 |
if ($long) {
|
| 627 |
$output .= '<p>'. t('You can use <a href="http://meta.wikimedia.org/wiki/Cheatsheet"><em>Mediawiki</em> syntax</a>. It is possible that not all formatting options are supported at the moment.') .'</p>';
|
| 628 |
$output .= '<p>'. t('You can link to internal content by using the title of a node. Use [[Node Title]] to link to the node with the corrseponding name. An alternate title can be specified like this: [[Node Title|Link title]]') .'</p>';
|
| 629 |
$output .= '<p>'. t('External links are detected automatically. So just type http://example.com for the link. If you want a different title, use the following syntax: [http://example.com some link title].') .'</p>';
|
| 630 |
$interwiki_help = pearwiki_filter_interwiki_help_tip($format, TRUE);
|
| 631 |
if ($interwiki_help) {
|
| 632 |
$output .= '<p>'. t('You can use interwiki links. Type [[site:Page Title]] to link to a page on a different site.');
|
| 633 |
$output .= ' '. substr($interwiki_help, 3);
|
| 634 |
$output .= '<p>'. t('Images are included with [[Image:filename]].');
|
| 635 |
if (pearwiki_filter_use_image($format)) {
|
| 636 |
$output .= t(' You can link to uploaded image nodes with [[Image:node title]].') .'<br/>';
|
| 637 |
}
|
| 638 |
$output .= t('Special image formatting can be done via [[Image:name|alignment|size|caption]] where any of additional information is optional. <em>alignment</em> is one of <em>left</em>, <em>center</em> or <em>right</em>. Size is in the format <em>80px</em> or <em>80x70px</em>. The caption is arbitrary text. See the <a href="@url">wikipedia help</a> for the full syntax, but be aware that frames and description text is not supported.', array('@url' => 'http://en.wikipedia.org/wiki/Wikipedia:Extended_image_syntax')) .'</p>';
|
| 639 |
}
|
| 640 |
}
|
| 641 |
else {
|
| 642 |
$output .= '<p>'. t('You can use <a href="http://meta.wikimedia.org/wiki/Cheatsheet"><em>Mediawiki</em> syntax</a>. It is possible that not all formatting options are supported at the moment.') .'<br/>';
|
| 643 |
$output .= t('Links to other pages: [[Page Title]] or [[path/to/page|Title]].') .'<br/>';
|
| 644 |
$output .= t('External links: http://example.com or [http://example.com some link title].') .'<br/>';
|
| 645 |
$interwiki_help = pearwiki_filter_interwiki_help_tip($format, FALSE);
|
| 646 |
if ($interwiki_help) {
|
| 647 |
$output .= t('Interwiki links: [[site:Page Title]].') .'<br/>';
|
| 648 |
$output .= $interwiki_help .'<br/>';
|
| 649 |
}
|
| 650 |
$output .= t('Images are included with [[Image:name]]. <a href="@url">(wikipedia help)</a>', array('@url' => 'http://en.wikipedia.org/wiki/Wikipedia:Extended_image_syntax'));
|
| 651 |
$output .= '</p>';
|
| 652 |
}
|
| 653 |
return $output;
|
| 654 |
}
|
| 655 |
}
|
| 656 |
|
| 657 |
function pearwiki_filter_mediawiki_config(&$wiki, $format) {
|
| 658 |
$wiki->addPath('parse', realpath(pearwiki_filter_pear_override_directory($format)) .'/parse_mediawiki');
|
| 659 |
$wiki->insertRule('image', 'break');
|
| 660 |
$wiki->insertRule('interwiki', 'image');
|
| 661 |
}
|
| 662 |
|
| 663 |
// TikiWiki specific functions
|
| 664 |
// ---------------------------
|
| 665 |
|
| 666 |
function pearwiki_filter_tiki_help($op, $long = FALSE, $format = 0) {
|
| 667 |
switch ($op) {
|
| 668 |
case 'name':
|
| 669 |
return 'TikiWiki';
|
| 670 |
|
| 671 |
case 'syntax_url':
|
| 672 |
return 'http://tikiwiki.org/tiki-index.php?page=WikiSyntax';
|
| 673 |
|
| 674 |
case 'tips':
|
| 675 |
$output = '';
|
| 676 |
$output .= '<p>'. t('You can use <a href="http://tikiwiki.org/tiki-index.php?page=WikiSyntax"><em>TikiWiki</em> syntax</a>. It is possible that not all formatting options are supported at the moment.') .'</p>';
|
| 677 |
$output .= '<p>'. t('You can link to internal content by using the page title or the path. A link to a node can either be made using ((Node Title)) or ((node/3)) using the corresponding node id.') .'</p>';
|
| 678 |
$output .= '<p>'. t('External links are detected automatically. If you want a description, use the following syntax: [http://example.com some|link title].') .'</p>';
|
| 679 |
return $output;
|
| 680 |
}
|
| 681 |
}
|
| 682 |
|
| 683 |
function pearwiki_filter_tiki_config(&$wiki, $format) {
|
| 684 |
}
|
| 685 |
|
| 686 |
// DokuWiki specific functions
|
| 687 |
// ---------------------------
|
| 688 |
|
| 689 |
function pearwiki_filter_doku_help($op, $long = FALSE, $format = 0) {
|
| 690 |
switch ($op) {
|
| 691 |
case 'name':
|
| 692 |
return 'DokuWiki';
|
| 693 |
|
| 694 |
case 'syntax_url':
|
| 695 |
return 'http://wiki.splitbrain.org/wiki:syntax';
|
| 696 |
|
| 697 |
case 'tips':
|
| 698 |
return '';
|
| 699 |
}
|
| 700 |
}
|
| 701 |
|
| 702 |
function pearwiki_filter_doku_config(&$wiki, $format) {
|
| 703 |
}
|
| 704 |
|
| 705 |
// Creole specific functions
|
| 706 |
// -------------------------
|
| 707 |
|
| 708 |
function pearwiki_filter_creole_help($op, $long = FALSE, $format = 0) {
|
| 709 |
switch ($op) {
|
| 710 |
case 'name':
|
| 711 |
return 'Creole';
|
| 712 |
case 'syntax_url':
|
| 713 |
return 'http://www.wikicreole.org/wiki/EditPageHelp';
|
| 714 |
case 'tips':
|
| 715 |
return '';
|
| 716 |
}
|
| 717 |
}
|
| 718 |
|
| 719 |
function pearwiki_filter_creole_config(&$wiki, $format) {
|
| 720 |
}
|
| 721 |
|
| 722 |
// CoWiki specific functions
|
| 723 |
// -------------------------
|
| 724 |
|
| 725 |
function pearwiki_filter_cowiki_help($op, $long = FALSE, $format = 0) {
|
| 726 |
switch ($op) {
|
| 727 |
case 'name':
|
| 728 |
return 'CoWiki';
|
| 729 |
case 'syntax_url':
|
| 730 |
return 'http://cowiki.org/';
|
| 731 |
case 'tips':
|
| 732 |
return 'This Wikitype is discontinued. You should not use this format.';
|
| 733 |
}
|
| 734 |
}
|
| 735 |
|
| 736 |
// BBCode specific functions
|
| 737 |
// -------------------------
|
| 738 |
|
| 739 |
function pearwiki_filter_bbcode_help($op, $long = FALSE, $format = 0) {
|
| 740 |
switch ($op) {
|
| 741 |
case 'name':
|
| 742 |
return 'BBCode';
|
| 743 |
case 'syntax_url':
|
| 744 |
return 'http://en.wikipedia.org/wiki/BBCode';
|
| 745 |
case 'tips':
|
| 746 |
return '';
|
| 747 |
}
|
| 748 |
}
|
| 749 |
|
| 750 |
// Default syntax specific functions
|
| 751 |
// ---------------------------------
|
| 752 |
|
| 753 |
function pearwiki_filter_default_help($op, $long = FALSE, $format = 0) {
|
| 754 |
switch ($op) {
|
| 755 |
case 'name':
|
| 756 |
return 'Default';
|
| 757 |
case 'syntax_url':
|
| 758 |
return 'http://wiki.ciaweb.net/yawiki/index.php?area=Text_Wiki&page=SamplePage';
|
| 759 |
case 'tips':
|
| 760 |
return '';
|
| 761 |
}
|
| 762 |
}
|
| 763 |
|
| 764 |
function pearwiki_filter_default_config(&$wiki, $format) {
|
| 765 |
}
|
| 766 |
|