--- footnotes.module-r1.12 2008-07-24 19:46:13.000000000 -0400 +++ footnotes.module-themed 2008-07-24 19:47:17.000000000 -0400 @@ -216,16 +216,9 @@ function _footnotes_replace_callback( $m if( $op == 'output footer' ) { if (count($store_matches) > 0) { - $str = '
    '; - // loop through the stored footnotes - foreach ($store_matches as $fn_attr) { - list($text,$value,$value_id,$randstr) = $fn_attr; - $str .= '
  1. ' . $value . '. '; - $str .= $text . "
  2. \n"; - } - $str .= "
\n"; + // Only if there are stored fn matches, pass the array of fns to be themed + // as a list + $str = theme('footnote_list',$store_matches); } $n = 0; $store_matches = array(); @@ -265,21 +258,27 @@ function _footnotes_replace_callback( $m // Remove illegal characters from $value so it can be used as an HTML id attribute. $value_id = preg_replace('|[^\w\-]|', '', $value); - // Store the footnote text, the footnote value label, and randstr - array_push( $store_matches, array( $matches[2], $value, $value_id, $randstr) ); - - $allowed_tags = array(); - $title = filter_xss($matches[2], $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 '' . $value . ''; + + // Create a footnote item as an array. + $fn = array( + 'value' => $value, + 'text' => $matches[2], + 'fn_id' => 'footnote' . $value_id . '_' . $randstr, + 'ref_id' => 'footnoteref' . $value_id . '_' . $randstr + ); + + // Store the footnote item. + array_push( $store_matches, $fn ); + + // Return the item themed into a footnote link. + return theme('footnote_link',$fn); + } + + + /** * Helper function called from preg_replace_callback() above * @@ -327,6 +326,69 @@ function _footnotes_helper_randstr() { } /** + * Implementation of hook_theme() + */ +function footnotes_theme( ) { + return array( + 'footnote_link' => array( + 'arguments' => array('fn' => NULL) + ), + 'footnote_list' => array( + 'arguments' => array('footnotes' => NULL) + ) + ); +} + +/** + * Themed output of a footnote link appearing in the text body + * + * Accepts a single associative array, containing values on the following keys: + * text - the raw unprocessed text extracted from within the [fn] tag + * value - the raw unprocessed footnote number or other identifying label + * fn_id - the globally unique identifier for the in-body footnote link + * anchor, used to allow links from the list to the body + * ref_id - the globally unique identifier for the footnote's anchor in the + * footnote listing, used to allow links to the list from the body + */ +function theme_footnote_link($fn) { + $allowed_tags = array(); + $title = filter_xss($fn['text'], $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 '' . + $fn['value'] . ''; +} + +/** + * Themed output of the footnotes list appearing at at [footnotes] + * + * Accepts an array containing an ordered listing of associative arrays, each + * containing values on the following keys: + * text - the raw unprocessed text extracted from within the [fn] tag + * value - the raw unprocessed footnote number or other identifying label + * fn_id - the globally unique identifier for the in-body footnote link + * anchor, used to allow links from the list to the body + * ref_id - the globally unique identifier for the footnote's anchor in the + * footnote listing, used to allow links to the list from the body + */ +function theme_footnote_list($footnotes) { + $str = '
    '; + // loop through the footnotes + foreach ($footnotes as $fn) { + $str .= '
  1. ' . $fn['value'] . '. '; + $str .= $fn['text'] . "
  2. \n"; + } + $str .= "
\n"; + return $str; +} + + +/** * Implementation of hook_init() * * Add special css for Footnotes module.