Subversion Repositories PHPX

Rev

Rev 7 | Rev 10 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7 Rev 8
Line 56... Line 56...
56
      if (!$sign)
56
      if (!$sign)
57
      {
57
      {
58
        $sign = ++$this->lastNumberSign;
58
        $sign = ++$this->lastNumberSign;
59
      }
59
      }
60
   
60
     
61
      $footnotes[$name] = new Footnote($sign, $text);
61
      $footnotes[$name] = new Footnote($name, $sign, $text);
62
    }
62
    }
63
   
63
   
64
    return $footnotes[$name]->printRef();
64
    return $footnotes[$name]->getRef();
65
  }
65
  }
66
 
66
 
67
  /**
67
  /**
68
   * Prints the list of footnotes
68
   * Prints the list of footnotes
69
   */
69
   */
70
  public function printMe()
70
  public function printMe()
71
  {
71
  {
72
    $footnotes =& $this->footnotes;
72
    $footnotes =& $this->footnotes;
73
   
73
   
-
 
74
    function cmp($a, $b)
-
 
75
    {
-
 
76
      if ($a->sign < $b->sign)
-
 
77
      {
-
 
78
        return -1;
-
 
79
      }
-
 
80
      else if ($a->sign > $b->sign)
-
 
81
      {
-
 
82
        return 1;
-
 
83
      }
-
 
84
      else
-
 
85
      {
-
 
86
        return 0;
-
 
87
      }
-
 
88
    }
-
 
89
   
-
 
90
    uasort($footnotes, 'cmp');
-
 
91
   
-
 
92
    ?><table class="footnotes">
-
 
93
    <?php
-
 
94
   
74
    foreach ($footnotes as $name => &$footnote)
95
    foreach ($footnotes as $name => &$footnote)
75
    {
96
    {
76
      /* TODO */
-
 
77
      $footnote->printMe();
97
      $footnote->printMe();
78
    }
98
    }
-
 
99
   
-
 
100
    ?></table><?php
79
  }
101
  }
80
 
102
 
81
  /**
103
  /**
82
   * Prints the list of footnotes and clears the list in memory
104
   * Prints the list of footnotes and clears the list in memory
83
   */
105
   */
Line 94... Line 116...
94
 * @author Thomas 'PointedEars' Lahn &lt;php@PointedEars.de&gt;
116
 * @author Thomas 'PointedEars' Lahn &lt;php@PointedEars.de&gt;
95
 */
117
 */
96
class Footnote
118
class Footnote
97
{
119
{
98
  /**
120
  /**
-
 
121
   * The name of this footnote
-
 
122
   *
-
 
123
   * @var string
-
 
124
   */
-
 
125
  protected $name = '';
-
 
126
 
-
 
127
  /**
99
   * The sign used for referring to this footnote
128
   * The sign used for referring to this footnote
100
   *
129
   *
101
   * @var string
130
   * @var string
102
   */
131
   */
103
  protected $sign = '';
132
  protected $sign = '';
Line 108... Line 137...
108
   * @var string
137
   * @var string
109
   */
138
   */
110
  protected $text = '';
139
  protected $text = '';
111
 
140
 
112
  /**
141
  /**
-
 
142
   * The number of times this footnote has been referred
-
 
143
   *
-
 
144
   * @var int
-
 
145
   */
-
 
146
  protected $references = 0;
-
 
147
 
-
 
148
  /**
113
   * Creates a footnote
149
   * Creates a footnote
114
   *
150
   *
-
 
151
   * @param string $name
-
 
152
   *   The name of this footnote
115
   * @param string $sign
153
   * @param string $sign
116
   *   The sign that should be used for referring to this footnote
154
   *   The sign that should be used for referring to this footnote
117
   * @param string $text
155
   * @param string $text
118
   *   The text for this footnote
156
   *   The text for this footnote
119
   */
157
   */
120
  public function __construct($sign, $text)
158
  public function __construct($name, $sign, $text)
121
  {
159
  {
-
 
160
    $this->name = $name;
122
    $this->sign = $sign;
161
    $this->sign = $sign;
123
    $this->text = $text;
162
    $this->text = $text;
124
  }
163
  }
125
 
164
126
  /**
165
  /**
-
 
166
   * Universal getter
-
 
167
   *
-
 
168
   * @param string $name
-
 
169
   *   Name of the property to be read-accessed.  Currently only 'sign'
-
 
170
   *   is supported.
-
 
171
   * @throws Exception if a non-existing property is accessed
-
 
172
   * @return mixed
-
 
173
   *   Property value
-
 
174
   */
-
 
175
  public function __get($name)
-
 
176
  {
-
 
177
    if ($name === 'sign')
-
 
178
    {
-
 
179
      return $this->sign;
-
 
180
    }
-
 
181
    else
-
 
182
    {
-
 
183
      throw new Exception('No such property ' . get_class($this) . "::\$$name");
-
 
184
    }
-
 
185
  }
-
 
186
 
-
 
187
  /**
127
   * Returns the reference for this footnote
188
   * Returns the reference for this footnote
128
   *
189
   *
129
   * @return string
190
   * @return string
130
   */
191
   */
131
  public function printRef()
192
  public function getRef()
132
  {
193
  {
-
 
194
    $s = $this->name;
-
 
195
   
-
 
196
    $ret = "<sup><a href='#footnote-{$s}'"
-
 
197
      . ($this->references === 0
-
 
198
        ? " name='fn-{$s}-ref' id='fn-{$s}-ref'"
-
 
199
        : '')
-
 
200
      . " class='footnote'>{$this->sign}</a></sup>";
-
 
201
-
 
202
    ++$this->references;
-
 
203
                         
133
    return "<sup>$sign</sup>";
204
    return $ret;
134
  }
205
  }
135
 
206
 
136
  /**
207
  /**
137
   * Prints this footnote in a footnote list
208
   * Prints this footnote in a footnote list
138
   */
209
   */
139
  public function printMe()
210
  public function printMe()
140
  {
211
  {
-
 
212
    $s = $this->name;
-
 
213
   
-
 
214
    echo "  <tr>
-
 
215
        <th><sup><a name='footnote-{$s}' id='footnote-{$s}' class='footnote'
-
 
216
          >{$this->sign}</a></sup><a href='#fn-{$s}-ref' name='footnote-{$s}'
-
 
217
          id='footnote-{$s}' class='backref'>&#8593;</a></th>
-
 
218
        <td>{$this->text}</td>
141
    /* TODO */
219
      </tr>
-
 
220
    ";
142
  }
221
  }
143
}
222
}
144
223
145
?>
224
?>
146
225