[Instructions]
 */
define('FOOTNOTES_START', '[footnotes]');
class footnotes_class {
	var $refs = false;
	var $id = 'noid';
	function __construct($id) {
		if ($id)
			$this->id = $id;
	}
	function note($n, $s) {
		$lang = lang_load('plugin:footnotes');
		$back = $lang ['plugin'] ['footnotes'] ['back'];
		
		$id = $this->id;
		$this->refs = true;
		return '
' . trim($s) . " ↩" . '';
	}
	function footnotes($matches) {
		$lang = lang_load('plugin:footnotes');
		$footnotes = $lang ['plugin'] ['footnotes'] ['footnotes'];
		$str = '';
		return $str;
	}
	function references($matches) {
		$lang = lang_load('plugin:footnotes');
		$footnote = $lang ['plugin'] ['footnotes'] ['footnote'];
		$n = $matches [1];
		$id = $this->id;
		$href_rel = "{$id}-rel-{$n}";
		$href_note = "{$id}-fn-{$n}";
		return "{$n}";
	}
	function headings($matches) {
		$i = 7 - strlen($matches [1]);
		return "{$matches[2]}";
	}
}
function plugin_footnotes_filter($text) {
	global $smarty;
	$footnotes_obj = new footnotes_class($id = $smarty->getTemplateVars('id'));
	// *STRONG* emphasis
	$text = preg_replace('|(?\w)|xs', '$1', $text);
	// _emphasis_ (italic)
	$text = preg_replace('|(?\w)|xs', '$1', $text);
	// heading
	/*
	 * $text = preg_replace_callback(
	 * '(?\w)|xs'
	 * //'/\n(#{1,6})([^#]+)# * /',
	 * array(&$footnotes_obj, 'headings'),
	 * $text);
	 *
	 */
	$text = preg_replace_callback('|\n' . preg_quote(FOOTNOTES_START) . '\s*(.*)|sm', array(
		&$footnotes_obj,
		'footnotes'
	), $text);
	// no [footnotes] references at the bottom of the page: stops
	if (!$footnotes_obj->refs)
		return $text;
	$text = preg_replace_callback('|\[\^([0-9]+)\]|', array(
		&$footnotes_obj,
		'references'
	), $text);
	return $text;
}
add_filter('the_content', 'plugin_footnotes_filter', 0);
?>