Subversion Repositories PHPX

Compare Revisions

Last modification

Ignore whitespace Rev 24 → Rev 25

/trunk/footnotes.class.php
12,7 → 12,7
*
* @var Array
*/
protected $footnotes;
protected $_footnotes;
/**
* Last used number sign for a footnote
19,28 → 19,39
*
* @var int
*/
protected $lastNumberSign;
protected $_lastNumberSign;
protected $defaultPrefix;
protected $defaultSuffix;
protected $_defaultPrefix;
protected $_defaultSuffix;
protected $makeTooltip;
protected $_makeTooltip;
public function __construct($defaultPrefix = '', $defaultSuffix = '', $makeTooltip = false)
{
$this->clear();
$this->defaultPrefix = $defaultPrefix;
$this->defaultSuffix = $defaultSuffix;
$this->makeTooltip = $makeTooltip;
$this->_defaultPrefix = $defaultPrefix;
$this->_defaultSuffix = $defaultSuffix;
$this->_makeTooltip = $makeTooltip;
}
public function __get($name)
{
if (property_exists($this, "_$name"))
{
return $this->{"_$name"};
}
 
throw new InvalidArgumentException(
'No such property ' . get_class($this) . "::\$$name");
}
/**
* Clears the footnote list
*/
public function clear()
{
$this->footnotes = array();
$this->lastNumberSign = 0;
$this->_footnotes = array();
$this->_lastNumberSign = 0;
}
/**
57,22 → 68,22
*/
public function add($name, $sign = '', $text = '', $tooltip = null)
{
$footnotes =& $this->footnotes;
$footnotes =& $this->_footnotes;
if (!isset($footnotes[$name]))
{
if (!$sign)
{
$sign = ++$this->lastNumberSign;
$sign = ++$this->_lastNumberSign;
}
else if (is_int($sign))
{
$this->lastNumberSign = $sign;
$this->_lastNumberSign = $sign;
}
$footnotes[$name] = new Footnote($name, $sign, $text,
$this->defaultSuffix, $this->defaultPrefix,
$this->makeTooltip ? ($tooltip !== null ? $tooltip : $text) : '');
$this->_defaultSuffix, $this->_defaultPrefix,
$this->_makeTooltip ? ($tooltip !== null ? $tooltip : $text) : '');
}
return $footnotes[$name]->getRef();
83,26 → 94,35
*/
public function printMe()
{
$footnotes =& $this->footnotes;
$footnotes =& $this->_footnotes;
function cmp($a, $b)
{
if ($a->sign < $b->sign)
uasort($footnotes, function ($a, $b) {
/* Sort numbered footnotes first */
if (is_int($a->sign) && !is_int($b->sign))
{
return -1;
}
else if ($a->sign > $b->sign)
 
if (is_int($b->sign) && !is_int($a->sign))
{
return 1;
}
else
/* Sort footnotes either numerically or alphabetically */
/* TODO: Sort "1b" before "12a" */
if ($a->sign < $b->sign)
{
return 0;
return -1;
}
}
if ($a->sign > $b->sign)
{
return 1;
}
return 0;
});
uasort($footnotes, 'cmp');
?><table class="footnotes">
<?php
136,7 → 156,7
*
* @var string
*/
protected $name = '';
protected $_name = '';
/**
* The sign used for referring to this footnote
143,7 → 163,7
*
* @var string
*/
protected $sign = '';
protected $_sign = '';
/**
* The text for this footnote
150,11 → 170,11
*
* @var string
*/
protected $text = '';
protected $_text = '';
protected $prefix = '';
protected $suffix = '';
protected $tooltip = '';
protected $_prefix = '';
protected $_suffix = '';
protected $_tooltip = '';
/**
* The number of times this footnote has been referred
161,7 → 181,7
*
* @var int
*/
protected $references = 0;
protected $_references = 0;
/**
* Creates a footnote
180,12 → 200,12
public function __construct($name, $sign, $text, $suffix = '', $prefix = '',
$tooltip = '')
{
$this->name = $name;
$this->sign = $sign;
$this->text = $text;
$this->suffix = $suffix;
$this->prefix = $prefix;
$this->tooltip = $tooltip;
$this->_name = $name;
$this->_sign = (is_numeric($sign) ? (int) $sign : $sign);
$this->_text = $text;
$this->_suffix = $suffix;
$this->_prefix = $prefix;
$this->_tooltip = $tooltip;
}
 
/**
200,15 → 220,13
*/
public function __get($name)
{
if ($name === 'sign')
if (property_exists($this, "_$name"))
{
return $this->sign;
return $this->{"_$name"};
}
else
{
throw new InvalidArgumentException(
'No such property ' . get_class($this) . "::\$$name");
}
 
throw new InvalidArgumentException(
'No such property ' . get_class($this) . "::\$$name");
}
/**
218,23 → 236,23
*/
public function getRef()
{
$s = $this->name;
$s = $this->_name;
$ret = "<sup><a href='#footnote-{$s}'"
. ($this->references === 0
. ($this->_references === 0
? " name='fn-{$s}-ref' id='fn-{$s}-ref'"
: '')
. ' class="footnote"'
. ($this->tooltip
. ($this->_tooltip
? ' title="'
. preg_replace('/"/', '&quot;',
trim(reduceWhitespace(strip_tags($this->tooltip))))
trim(reduceWhitespace(strip_tags($this->_tooltip))))
. '"'
: '')
. ">{$this->prefix}{$this->sign}{$this->suffix}"
. ">{$this->_prefix}{$this->_sign}{$this->_suffix}"
. '</a></sup>';
 
++$this->references;
++$this->_references;
return $ret;
}
244,13 → 262,13
*/
public function printMe()
{
$s = $this->name;
$s = $this->_name;
echo " <tr>
<th><sup><a name='footnote-{$s}' id='footnote-{$s}' class='footnote'
>{$this->sign}</a></sup><a
>{$this->_sign}</a></sup><a
href='#fn-{$s}-ref' class='backref'>&#8593;</a></th>
<td>{$this->text}</td>
<td>{$this->_text}</td>
</tr>
";
}