Subversion Repositories PHPX

Rev

Rev 8 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
7 PointedEar 1
<?php
2
 
3
/**
4
 * A footnote list contains {@link #Footnote Footnotes}
5
 *
6
 * @author Thomas 'PointedEars' Lahn &lt;php@PointedEars.de&gt;
7
 */
8
class FootnoteList
9
{
10
  /**
11
   * The footnotes of this list
12
   *
13
   * @var Array
14
   */
15
  protected $footnotes;
16
 
17
  /**
18
   * Last used number sign for a footnote
19
   *
20
   * @var int
21
   */
22
  protected $lastNumberSign;
23
 
24
  public function __construct()
25
  {
26
    $this->clear();
27
  }
28
 
29
  /**
30
   * Clears the footnote list
31
   */
32
  public function clear()
33
  {
34
    $this->footnotes = array();
35
    $this->lastNumberSign = 0;
36
  }
37
 
38
  /**
39
   * Adds a footnote to the list (unless already specified)
40
   *
41
   * @param string $name
42
   *   Name of the footnote
43
   * @param string $sign
44
   *   Sign of the footnote.  If empty, the next available number is used.
45
   * @param string $text
46
   *   Text for the footnote
47
   * @return string
48
   *   The code for printing the footnote reference.
49
   */
50
  public function add($name, $sign = '', $text = '')
51
  {
52
    $footnotes =& $this->footnotes;
53
 
54
    if (!isset($footnotes[$name]))
55
    {
56
      if (!$sign)
57
      {
58
        $sign = ++$this->lastNumberSign;
59
      }
60
 
61
      $footnotes[$name] = new Footnote($sign, $text);
62
    }
63
 
64
    return $footnotes[$name]->printRef();
65
  }
66
 
67
  /**
68
   * Prints the list of footnotes
69
   */
70
  public function printMe()
71
  {
72
    $footnotes =& $this->footnotes;
73
 
74
    foreach ($footnotes as $name => &$footnote)
75
    {
76
      /* TODO */
77
      $footnote->printMe();
78
    }
79
  }
80
 
81
  /**
82
   * Prints the list of footnotes and clears the list in memory
83
   */
84
  public function flush()
85
  {
86
    $this->printMe();
87
    $this->clear();
88
  }
89
}
90
 
91
/**
92
 * A footnote to be used in a {@link #FootnoteList "footnote list"}
93
 *
94
 * @author Thomas 'PointedEars' Lahn &lt;php@PointedEars.de&gt;
95
 */
96
class Footnote
97
{
98
  /**
99
   * The sign used for referring to this footnote
100
   *
101
   * @var string
102
   */
103
  protected $sign = '';
104
 
105
  /**
106
   * The text for this footnote
107
   *
108
   * @var string
109
   */
110
  protected $text = '';
111
 
112
  /**
113
   * Creates a footnote
114
   *
115
   * @param string $sign
116
   *   The sign that should be used for referring to this footnote
117
   * @param string $text
118
   *   The text for this footnote
119
   */
120
  public function __construct($sign, $text)
121
  {
122
    $this->sign = $sign;
123
    $this->text = $text;
124
  }
125
 
126
  /**
127
   * Returns the reference for this footnote
128
   *
129
   * @return string
130
   */
131
  public function printRef()
132
  {
133
    return "<sup>$sign</sup>";
134
  }
135
 
136
  /**
137
   * Prints this footnote in a footnote list
138
   */
139
  public function printMe()
140
  {
141
    /* TODO */
142
  }
143
}
144
 
145
?>