0,0 → 1,145 |
<?php |
|
/** |
* A footnote list contains {@link #Footnote Footnotes} |
* |
* @author Thomas 'PointedEars' Lahn <php@PointedEars.de> |
*/ |
class FootnoteList |
{ |
/** |
* The footnotes of this list |
* |
* @var Array |
*/ |
protected $footnotes; |
|
/** |
* Last used number sign for a footnote |
* |
* @var int |
*/ |
protected $lastNumberSign; |
|
public function __construct() |
{ |
$this->clear(); |
} |
|
/** |
* Clears the footnote list |
*/ |
public function clear() |
{ |
$this->footnotes = array(); |
$this->lastNumberSign = 0; |
} |
|
/** |
* Adds a footnote to the list (unless already specified) |
* |
* @param string $name |
* Name of the footnote |
* @param string $sign |
* Sign of the footnote. If empty, the next available number is used. |
* @param string $text |
* Text for the footnote |
* @return string |
* The code for printing the footnote reference. |
*/ |
public function add($name, $sign = '', $text = '') |
{ |
$footnotes =& $this->footnotes; |
|
if (!isset($footnotes[$name])) |
{ |
if (!$sign) |
{ |
$sign = ++$this->lastNumberSign; |
} |
|
$footnotes[$name] = new Footnote($sign, $text); |
} |
|
return $footnotes[$name]->printRef(); |
} |
|
/** |
* Prints the list of footnotes |
*/ |
public function printMe() |
{ |
$footnotes =& $this->footnotes; |
|
foreach ($footnotes as $name => &$footnote) |
{ |
/* TODO */ |
$footnote->printMe(); |
} |
} |
|
/** |
* Prints the list of footnotes and clears the list in memory |
*/ |
public function flush() |
{ |
$this->printMe(); |
$this->clear(); |
} |
} |
|
/** |
* A footnote to be used in a {@link #FootnoteList "footnote list"} |
* |
* @author Thomas 'PointedEars' Lahn <php@PointedEars.de> |
*/ |
class Footnote |
{ |
/** |
* The sign used for referring to this footnote |
* |
* @var string |
*/ |
protected $sign = ''; |
|
/** |
* The text for this footnote |
* |
* @var string |
*/ |
protected $text = ''; |
|
/** |
* Creates a footnote |
* |
* @param string $sign |
* The sign that should be used for referring to this footnote |
* @param string $text |
* The text for this footnote |
*/ |
public function __construct($sign, $text) |
{ |
$this->sign = $sign; |
$this->text = $text; |
} |
|
/** |
* Returns the reference for this footnote |
* |
* @return string |
*/ |
public function printRef() |
{ |
return "<sup>$sign</sup>"; |
} |
|
/** |
* Prints this footnote in a footnote list |
*/ |
public function printMe() |
{ |
/* TODO */ |
} |
} |
|
?> |