You are here

function _biblio_filter_replace_callback in Bibliography Module 7

Same name and namespace in other branches
  1. 5 biblio.module \_biblio_filter_replace_callback()
  2. 6.2 biblio.module \_biblio_filter_replace_callback()
  3. 6 biblio.module \_biblio_filter_replace_callback()
  4. 7.2 biblio.module \_biblio_filter_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 _biblio_filter_replace_callback()
_biblio_filter_reference_process in ./biblio.module
1 string reference to '_biblio_filter_replace_callback'
_biblio_filter_reference_process in ./biblio.module

File

./biblio.module, line 2235
Bibliography Module for Drupal.

Code

function _biblio_filter_replace_callback($matches, $op = '') {
  static $n = 0;
  static $store_matches = array();
  $str = '';
  if ($op == 'output footer') {
    if ($n > 0) {
      $str = '<hr /><h3>' . t('References') . '</h3>';
      $str .= '<div class="references"><ol>';
      for ($m = 1; $m <= $n; $m++) {
        $str .= '<li id="reference' . $m . '"><a name="ref' . $m . '">' . _biblio_citekey_print($store_matches[$m - 1]) . " </a></li>\n\n";
      }
      $str .= '</ol></div>';
    }
    $n = 0;
    $store_matches = array();
    return $str;
  }

  // Default op: act as called by preg_replace_callback()
  $ref = array_search($matches[1], $store_matches);
  if ($ref === FALSE) {
    $n++;

    // $stores_matches[$matches[1]] = $n;.
    array_push($store_matches, $matches[1]);
    $ref = $n;
  }
  else {
    $ref++;
  }
  $allowed_tags = array();
  $title = filter_xss($matches[1], biblio_get_allowed_tags());

  // Html attribute cannot contain quotes.
  $title = str_replace('"', "&quot;", $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 '<sup class="see_reference" title="'. $title .'"><a href="#reference'. $n .'">'. $n .'</a></sup>';
  // $text = '<span><a href="#reference'. $n .'">['. $n .']</a> </span>';
  // $text = '<span>['. $n .']</span>';
  // $text .= '<span class="hovertip">'._biblio_citekey_print($title) .'</span>';.
  $text = '<span hovertip="reference' . $ref . '"><a href="#ref' . $ref . '">[' . $ref . ']</a></span>';
  if (module_exists('hovertip')) {
    $text = '<span hovertip="reference' . $ref . '"><a href="#ref' . $ref . '">[' . $ref . ']</a></span>';
    $text .= '<span id="reference' . $ref . '" class="hovertip">' . _biblio_citekey_print($title) . '</span>';
  }
  else {
    $text = '<a href="#ref' . $ref . '" title="Reference ' . $ref . '">[' . $ref . ']</a>';
  }
  return $text;
}