You are here

function footnotes_is_footnotes_later in Footnotes 5

Same name and namespace in other branches
  1. 8.2 footnotes.module \footnotes_is_footnotes_later()
  2. 5.2 footnotes.module \footnotes_is_footnotes_later()
  3. 6.2 footnotes.module \footnotes_is_footnotes_later()
  4. 6 footnotes.module \footnotes_is_footnotes_later()
  5. 7.3 footnotes.module \footnotes_is_footnotes_later()
  6. 7.2 footnotes.module \footnotes_is_footnotes_later()

Helper for other filters, check if Footnotes is present in your filter chain.

Other filters may leverage the Footnotes functionality in a simple way: by outputting markup with <fn>...</fn> tags within.

This creates a dependency, the Footnotes filter must be present later in "Input format". By calling this helper function the other filters that depend on Footnotes may check whether Footnotes is present later in the chain of filters in the current Input format.

If this function returns true, the caller may depend on Footnotes. Function returns false if caller may not depend on Footnotes.

Example usage: <code> filter_example_filter( $op, $delta = 0, $format = -1, $text = '') { ... //When caller wishes to depend on html footnotes, last argument may be omitted if( footnotes_is_footnotes_later( $format, 'filter_example_filter', $delta ) ) { //output markup which may include <fn> tags } else { // must make do without footnotes features } ... } </code>

Note: You should also put "dependencies = footnotes" in your module.info file.

Parameters

$format: The input format caller is being run as part of ($format of hook_filter(...))

$caller: Name of calling module

$caller_delta: Delta of the filter within calling module ($delta of hook_filter(...))

$footnotes_delta: Delta of the filter within footnotes module

Return value

True if Footnotes is present after $caller in Input format $format

File

./footnotes.module, line 302
The Footnotes module is a filter that can be used to insert automatically numbered footnotes into Drupal texts.

Code

function footnotes_is_footnotes_later($format, $caller, $caller_delta = 0, $footnotes_delta = 0) {

  //Determine caller's weight in the current input format
  $result = db_query("SELECT weight FROM filters WHERE module='%s' AND format=%d AND delta=%d;", $caller, $format, $caller_delta);
  $caller_weight = db_fetch_object($result);
  $caller_weight = $caller_weight->weight;

  //See if Footnotes is present in the input format and if weight is higher
  $result = db_query("SELECT weight FROM filters WHERE module='%s' AND format=%d AND delta=%d;", 'footnotes', $format, $footnotes_delta);
  $fn_weight = db_fetch_object($result);
  if ($fn_weight) {
    $fn_weight = $fn_weight->weight;
  }
  else {

    //Footnotes is not present at all in input format $format
    return FALSE;
  }
  if ($fn_weight > $caller_weight) {

    //Footnotes is after caller in input format $format
    return TRUE;
  }
  else {

    //Footnotes is before caller in input format $format
    return FALSE;

    //TODO: What is correct interpretation when weight is equal?
  }
}