function _footnotes_replace_callback in Footnotes 6
Same name and namespace in other branches
- 5.2 footnotes.module \_footnotes_replace_callback()
- 5 footnotes.module \_footnotes_replace_callback()
- 6.2 footnotes.module \_footnotes_replace_callback()
- 7.3 footnotes.module \_footnotes_replace_callback()
- 7.2 footnotes.module \_footnotes_replace_callback()
Helper function called from preg_replace_callback() above
Uses static vars to temporarily store footnotes found. In my understanding, this is not threadsafe?!
1 call to _footnotes_replace_callback()
- footnotes_filter in ./
footnotes.module - Implementation of hook_filter().
1 string reference to '_footnotes_replace_callback'
- footnotes_filter in ./
footnotes.module - Implementation of hook_filter().
File
- ./
footnotes.module, line 159 - The Footnotes module is a filter that can be used to insert automatically numbered footnotes into Drupal texts.
Code
function _footnotes_replace_callback($matches, $op = '') {
static $n = 0;
static $store_matches = array();
$str = '';
if ($op == 'output footer') {
if ($n > 0) {
$str = '<ol class="footnotes">';
for ($m = 1; $m <= $n; $m++) {
$text = $store_matches[$m - 1][0];
$randstr = $store_matches[$m - 1][1];
$str .= '<li><a class="footnote" name="footnote' . $m . '_' . $randstr . '" href="#footnoteref' . $m . '_' . $randstr . '">' . $m . '.</a> ';
$str .= $text . "</li>\n";
}
$str .= "</ol>\n";
}
$n = 0;
$store_matches = array();
return $str;
}
//default op: act as called by preg_replace_callback()
//Random string used to ensure footnote id's are unique, even
//when contents of multiple nodes reside on same page. (fixes http://drupal.org/node/194558)
$randstr = _footnotes_helper_randstr();
array_push($store_matches, array(
$matches[1],
$randstr,
));
$n++;
$allowed_tags = array();
$title = filter_xss($matches[1], $allowed_tags);
//html attribute cannot contain quotes
$title = str_replace('"', """, $title);
//remove newlines. Browsers don't support them anyway and they'll confuse line break converter in filter.module
$title = str_replace("\n", " ", $title);
$title = str_replace("\r", "", $title);
return '<a class="see_footnote" id="footnoteref' . $n . '_' . $randstr . '" title="' . $title . '" href="#footnote' . $n . '_' . $randstr . '">' . $n . '</a>';
}