| 1 |
<?php |
<?php |
| 2 |
// $Id$ |
// $Id: freelinking.module,v 1.32.2.11.2.2.2.16 2009/11/09 03:31:30 grayside Exp $ |
| 3 |
/** |
/** |
| 4 |
* Freelinking 3 |
* Freelinking 3 |
| 5 |
* Provides flexibe linking of content, wiki-style |
* Provides flexibe linking of content, wiki-style |
| 43 |
case 'process': |
case 'process': |
| 44 |
$freelinking = freelinking_get_plugins(); |
$freelinking = freelinking_get_plugins(); |
| 45 |
$defaultplugin = variable_get('freelinking_default', 'nodetitle'); |
$defaultplugin = variable_get('freelinking_default', 'nodetitle'); |
| 46 |
$markdown = variable_get('freelinking_markdown_mode', FALSE); |
$syntax = variable_get('freelinking_match_syntax', 'double_bracket'); |
| 47 |
|
$regex = _freelinking_match_pattern(); |
| 48 |
|
|
| 49 |
// Loop through every freelink format |
// Loop through every freelink format |
| 50 |
// Space at text start prevents match failure at start. |
// Space at text start prevents match failure at start. |
| 51 |
preg_match_all(_freelinking_match_pattern(), ' ' . $text, |
preg_match_all($regex[$syntax], ' ' . $text, $matches, PREG_SET_ORDER); |
|
$matches, PREG_SET_ORDER); |
|
| 52 |
|
|
| 53 |
foreach($matches as $match) { |
foreach($matches as $match) { |
| 54 |
$current_plugin = ''; |
$current_plugin = ''; |
| 57 |
$match[0] = preg_replace('/^[^\\\\]/', '', $match[0]); |
$match[0] = preg_replace('/^[^\\\\]/', '', $match[0]); |
| 58 |
|
|
| 59 |
// in markdown mode, the first match is part of the target. |
// in markdown mode, the first match is part of the target. |
| 60 |
if ($markdown) { |
if ($syntax == 'markdown') { |
| 61 |
$match[1] .= '|' . $match[2]; |
$match[1] .= '|' . $match[2]; |
| 62 |
} |
} |
| 63 |
|
|
| 238 |
'#description' => t('Default plugin to use when not specified in text. "Nodetitle" mimics previous versions of Freelinking.'), |
'#description' => t('Default plugin to use when not specified in text. "Nodetitle" mimics previous versions of Freelinking.'), |
| 239 |
); |
); |
| 240 |
|
|
| 241 |
$form['freelinking_markdown_mode'] = array( |
|
| 242 |
'#title' => t('Markdown Syntax Mode'), |
$syntax['double_bracket'] = t('Standard') . ' - [[plugin:target|Title]]'; |
| 243 |
'#type' => 'checkbox', |
$syntax['single_bracket'] = t('Single Bracket') . ' - [plugin:target|Title]'; |
| 244 |
'#default_value' => variable_get('freelinking_markdown_mode', FALSE), |
$syntax['markdown'] = 'Markdown - [Title](plugin:target)'; |
| 245 |
'#description' => t('Use Markdown syntax [Title](plugin:url) in place of Freelinking syntax [[plugin:url|Title]]'), |
|
| 246 |
|
$form['freelinking_match_syntax'] = array( |
| 247 |
|
'#title' => t('Match Syntax Mode'), |
| 248 |
|
'#type' => 'select', |
| 249 |
|
'#default_value' => variable_get('freelinking_match_syntax', 'double_bracket'), |
| 250 |
|
'#options' => $syntax, |
| 251 |
|
'#description' => t('What syntax to use in identifying freelinks.'), |
| 252 |
); |
); |
| 253 |
|
|
| 254 |
$form['freelinking_wrapper'] = array( |
$form['freelinking_wrapper'] = array( |
| 276 |
* Implementation of hook_filter_tips() |
* Implementation of hook_filter_tips() |
| 277 |
*/ |
*/ |
| 278 |
function freelinking_filter_tips($delta, $format, $long = FALSE) { |
function freelinking_filter_tips($delta, $format, $long = FALSE) { |
| 279 |
if(variable_get('freelinking_markdown_mode', FALSE)) { |
$syntax = variable_get('freelinking_syntax_mode', 'double_bracket'); |
| 280 |
|
if ($syntax == 'double_bracket') { |
| 281 |
|
$pattern = '<tt>[[indicator:target|Title]]</tt>'; |
| 282 |
|
} |
| 283 |
|
else if ($syntax == 'markdown') { |
| 284 |
$pattern = '<tt>[Title](indicator:target)</tt>'; |
$pattern = '<tt>[Title](indicator:target)</tt>'; |
| 285 |
} |
} |
| 286 |
else { |
else { |
| 287 |
$pattern = '<tt>[[indicator:target|Title]]</tt>'; |
$pattern = '<tt>[indicator:target|Title]</tt>'; |
| 288 |
} |
} |
| 289 |
$text .= t('Freelinking helps you easily create HTML links. Links take the form of !pattern.', |
$text .= t('Freelinking helps you easily create HTML links. Links take the form of !pattern.', |
| 290 |
array('!pattern' => $pattern)); |
array('!pattern' => $pattern)); |
| 414 |
} |
} |
| 415 |
$separator = preg_quote($separator); |
$separator = preg_quote($separator); |
| 416 |
|
|
| 417 |
// Markdown mode: use inline markdown link syntax |
$option['double_bracket'] = |
| 418 |
if (variable_get('freelinking_markdown_mode', FALSE)) { |
'/[^\\\\]\[\[(.+' . $separator . '?.+)]]/Uu'; |
| 419 |
return '/[^\\\\]\[([^\[.]*)\]\((.+' . $separator . '.+)\)/Uu'; |
$option['single_bracket'] = |
| 420 |
} |
'/[^\\\\]\[(.+' . $separator . '?.+)]/Uu'; |
| 421 |
// Otherwise, use freelink/wiki style |
$option['markdown'] = |
| 422 |
return '/[^\\\\]\[\[(.+' . $separator . '?.+)]]/Uu'; |
'/[^\\\\]\[([^\[.]*)\]\((.+' . $separator . '.+)\)/Uu'; |
| 423 |
|
|
| 424 |
|
return $option; |
| 425 |
} |
} |
| 426 |
|
|
| 427 |
// vim: tw=300 nowrap syn=php |
// vim: tw=300 nowrap syn=php |