/[drupal]/contributions/modules/citation_filter/citation_filter.module
ViewVC logotype

Diff of /contributions/modules/citation_filter/citation_filter.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1, Mon Dec 10 01:51:01 2007 UTC revision 1.2, Sat Dec 15 20:13:10 2007 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id$  // $Id: citation_filter.module,v 1.1 2007/12/10 01:51:01 cwgordon7 Exp $
3    
4  /**  /**
5   * Implementation of hook_filter.   * Implementation of hook_filter.
# Line 30  function citation_filter_filter($op, $de Line 30  function citation_filter_filter($op, $de
30  }  }
31    
32  /**  /**
33   * Helper function for hook_filter.   * Helper function for citation_filter_filter.
34   */   */
35  function citation_filter_replace($text, $format) {  function citation_filter_replace($text, $format) {
36    $sup = variable_get("citation_filter_superscript_$format", TRUE);    $sup = variable_get("citation_filter_superscript_$format", TRUE);
# Line 40  function citation_filter_replace($text, Line 40  function citation_filter_replace($text,
40    $references = array();    $references = array();
41    $tmp = $text;    $tmp = $text;
42    $refnum = 1;    $refnum = 1;
43      $links = array();
44    while ($pos !== FALSE) {    while ($pos !== FALSE) {
45      $pos = stripos($tmp, '[ref:');      $pos = stripos($tmp, '[ref:');
46      if ($pos !== FALSE) {      if ($pos !== FALSE) {
47        $return .= substr($tmp, 0, $pos);        $return .= substr($tmp, 0, $pos);
48        $class = '#citation-'. $refnum;  
49        if ($sup) {        $ref = substr($tmp, $pos + 5, (strpos($tmp, ']') - 5) - $pos);
50          $return .= '<sup><a href="'. $class .'" rel="nofollow">['. $refnum .']</a></sup>';        $pos2 = strpos($ref, '|');
51          if ($pos2) {
52            $link = substr($ref, 0, $pos2);
53          }
54          else {
55            $link = $ref;
56          }
57    
58          $keys = array_keys($links);
59          if (!in_array($link, $keys)) {
60            $links[$link] = $refnum;
61            $class = '#citation-'. $refnum;
62            if ($sup) {
63              $return .= '<sup><a href="'. $class .'" rel="nofollow">['. $refnum .']</a></sup>';
64            }
65            else {
66              $return .= '<a href="'. $class .'" rel="nofollow">['. $refnum .']</a>';
67            }
68            $refnum++;
69        }        }
70        else {        else {
71          $return .= '<a href="'. $class .'" rel="nofollow">['. $refnum .']</a>';          $tmprefnum = $links[$link];
72            $class = '#citation-'. $tmprefnum;
73            if ($sup) {
74              $return .= '<sup><a href="'. $class .'" rel="nofollow">['. $tmprefnum .']</a></sup>';
75            }
76            else {
77              $return .= '<a href="'. $class .'" rel="nofollow">['. $tmprefnum .']</a>';
78            }
79        }        }
80        $refnum++;  
81        $tmp = substr($tmp, $pos + 1);        $tmp = substr($tmp, $pos + 1);
82        $end = stripos($tmp, ']');        $end = stripos($tmp, ']');
83        $references[] = substr($tmp, 0, $end);        $references[] = substr($tmp, 0, $end);
84        $tmp = substr($tmp, $end + 1);        $tmp = substr($tmp, $end + 1);
85      }      }
86    }    }
87      $return .= $tmp;
88    return array('text' => $return, 'refs' => $references);    return array('text' => $return, 'refs' => $references);
89  }  }
90    
91  /**  /**
92   * Helper function for hook_filter.   * Helper function for citation_filter_filter.
93   */   */
94  function citation_filter_append($refs, $format) {  function citation_filter_append($refs, $format) {
95    $sup = variable_get("citation_filter_superscript_$format", TRUE);    $sup = variable_get("citation_filter_superscript_$format", TRUE);
96    $refnum = 1;    $refnum = 1;
97    $return = '<br />'. variable_get("citation_filter_title_$format", t('<h3>References</h3>'));    $return = '<br />'. variable_get("citation_filter_title_$format", t('<h3>References</h3>'));
98      $links[] = array();
99    foreach ($refs as $ref) {    foreach ($refs as $ref) {
100      $pos = strpos($ref, '|');      $pos = strpos($ref, '|');
101      if ($pos) {      if ($pos) {
# Line 79  function citation_filter_append($refs, $ Line 107  function citation_filter_append($refs, $
107        $link = $ref;        $link = $ref;
108        $title = $ref;        $title = $ref;
109      }      }
110      $class = '#citation-'. $refnum;      // Only add citation if doesn't already exist.
111      if ($sup) {      if (!in_array($link, $links)) {
112        $return .= '<br /><sup><a href="'. $class .'" name="'. substr($class, 1) .'" rel="nofollow">['. $refnum .']</a></sup>'. l($title, $link);        $links[] = $link;
113      }        $class = '#citation-'. $refnum;
114      else {        if ($sup) {
115        $return .= '<br /><a href="'. $class .'" name="'. substr($class, 1) .'" rel="nofollow">['. $refnum .']</a>'. l($title, $link);          $return .= '<br /><sup><a href="'. $class .'" name="'. substr($class, 1) .'" rel="nofollow">['. $refnum .']</a></sup>'. l($title, $link);
116          }
117          else {
118            $return .= '<br /><a href="'. $class .'" name="'. substr($class, 1) .'" rel="nofollow">['. $refnum .']</a>'. l($title, $link);
119          }
120      }      }
121      $refnum++;      $refnum++;
122    }    }
# Line 92  function citation_filter_append($refs, $ Line 124  function citation_filter_append($refs, $
124  }  }
125    
126  /**  /**
127   * Helper function for hook_filter.   * Return settings form for citation filter.
128   */   */
129  function citation_filter_settings($format) {  function citation_filter_settings($format) {
130    $form['citation_filter'] = array(    $form['citation_filter'] = array(
131      '#type' => 'fieldset',      '#type' => 'fieldset',
132      '#title' => t('HTML filter'),      '#title' => t('Citation filter'),
133      '#collapsible' => TRUE,      '#collapsible' => TRUE,
134    );    );
135    $form['citation_filter']["citation_filter_superscript_$format"] = array(    $form['citation_filter']["citation_filter_superscript_$format"] = array(
# Line 118  function citation_filter_settings($forma Line 150  function citation_filter_settings($forma
150  /**  /**
151   * Implementation of hook_filter_tips.   * Implementation of hook_filter_tips.
152   */   */
153  function citation_filter_filter_tips($delta, $format, $long = false) {  function citation_filter_filter_tips($delta, $format, $long = FALSE) {
154    if ($long) {    if ($long) {
155      return t('You may post references in the form of [ref:link] or [ref:linkdestination|linktitle]. It will be replaced by a reference in the form of [1], with a reference at the bottom of the page in the form of [1]ClickableCitation.');      return t('You may post references in the form of [ref:link] or [ref:linkdestination|linktitle]. It will be replaced by a reference in the form of [1], with a reference at the bottom of the page in the form of [1]ClickableCitation.');
156    }    }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.2