0 || self::$footnote_numberless_nth > 0);
}
static function reset(){
self::$footnote_nth = 0;
self::$footnote_numberless_nth = 0;
self::$footnotes = array();
self::$footnotes_numberless = array();
}
static function add_ref($atts, $content) {
$opts = get_option('afn_opts');
$a = shortcode_atts( array(
'type' => 'numeric',
), $atts );
switch($a['type']){
case "numeric":
self::$footnote_nth++;
self::$footnotes[] = $content;
return ''.self::$footnote_nth.'';
break;
case "numberless": case "non-numeric": default:
self::$footnote_numberless_nth ++;
self::$footnotes_numberless[] = $content;
return ''.$opts['var_footnotesymbol'].'';
break;
}
}
static function refs_shortcode($atts){
$opts = get_option('afn_opts');
if(isset($opts['var_reftitle']) && trim($opts['var_reftitle']) != ""){
$defaultTitle = $opts['var_reftitle'];
}
else{
$defaultTitle = __('References', 'advanced_footnotes');
}
$a = shortcode_atts( array(
'title' => $defaultTitle,
), $atts );
if($a['title'] === 'false' || $a['title'] === ''){
$a['title'] = false;
}
return self::print_refs(false, $a['title']);
}
static function print_refs($print = true, $title = false){
$opts = get_option('afn_opts');
$html = '
';
if($print){
echo $html;
}
return $html;
}
static function get_refs(){
$refs = array();
foreach(self::$footnotes_numberless as $nth => $footnote){
$num = $nth+1;
$idprefix = 'article-footnote-numberless-';
$hrefprefix = '#article-footnote-hook-';
$refs['numberless'][] = array(
'classes' => 'afn-footnotes-ref reference non-numeric',
'num' => $num,
'idprefix' => $idprefix,
'id' => $idprefix.$num,
'hrefprefix' => $hrefprefix,
'href' => $hrefprefix.$num,
'content' => $footnote,
);
}
foreach(self::$footnotes as $nth => $footnote){
$num = $nth+1;
$idprefix = 'article-footnote-';
$hrefprefix = '#article-footnote-hook-';
$refs['numeric'][] = array(
'classes' => 'afn-footnotes-ref reference numeric',
'num' => $num,
'idprefix' => $idprefix,
'id' => $idprefix.$num,
'hrefprefix' => $hrefprefix,
'href' => $hrefprefix.$num,
'content' => $footnote,
);
}
return $refs;
}
}
add_shortcode('footnote', array('advanced_footnotes', 'add_ref'));
add_shortcode('footnotes', array('advanced_footnotes', 'refs_shortcode'));
add_action( 'wp_head', array('advanced_footnotes', 'reset'));
function advanced_footnotes_mce_scripts($plugin_array){
$plugin_array["advanced_footnotes"] = plugin_dir_url(__FILE__) . 'assets/js/tinymce.advanced-footnotes.js';
return $plugin_array;
}
add_filter("mce_external_plugins", "advanced_footnotes_mce_scripts");
function advanced_footnotes_user_includes() {
global $advanced_footnotes_data;
$opts = get_option('afn_opts');
if(isset($opts['include_js'])){
wp_enqueue_script( 'advanced_footnotes_js', plugin_dir_url( __FILE__ ) . 'assets/js/advanced-footnotes.js', array("jquery"), $advanced_footnotes_data[0], false );
}
if(isset($opts['include_css'])){
wp_enqueue_style('advanced_footnotes_css', plugin_dir_url( __FILE__ ).'assets/css/advanced-footnotes.css', array(), $advanced_footnotes_data[0] );
}
}
add_action('wp_enqueue_scripts', 'advanced_footnotes_user_includes');
function advanced_footnotes_admin_includes() {
global $advanced_footnotes_data;
wp_enqueue_script( 'advanced_footnotes_js_admin', plugin_dir_url( __FILE__ ) . 'assets/js/advanced-footnotes-admin.js', array("jquery"), $advanced_footnotes_data[0], false );
}
add_action( 'admin_enqueue_scripts', 'advanced_footnotes_admin_includes' );
function advanced_footnotes_register_button($buttons){
array_push($buttons, "footnote");
return $buttons;
}
add_filter("mce_buttons", "advanced_footnotes_register_button");
function advanced_footnotes_user_head(){
$opts = get_option('afn_opts');
if(isset($opts['customcss']) && trim($opts['customcss'] != "")){
echo ''."\r\n";
}
if(!isset($opts['var_disablejsopts'])){
$meta = array();
if(isset($opts['var_scrollgap'])){
$meta['scrollGap'] = intval($opts['var_scrollgap']);
}
if(isset($opts['var_scrollspeed'])){
$meta['scrollSpeed'] = intval($opts['var_scrollspeed']);
}
if(count($meta) > 0){
echo "\r\n";
}
}
}
add_action('wp_head','advanced_footnotes_user_head');
function advanced_footnotes_install(){
if(!get_option('afn_opts')) {
$op = array(
'include_css' => "on",
'include_js' => "on",
'var_reftitle' => __('References', 'advanced_footnotes'),
'var_disablejsopts' => "on",
'var_scrollgap' => "0",
'var_scrollspeed' => "350",
);
add_option('afn_opts', $op);
}
}
register_activation_hook(__FILE__, 'advanced_footnotes_install');
function advanced_footnotes_restore(){
delete_option('afn_opts');
advanced_footnotes_install();
}
include(plugin_dir_path( __FILE__ ).'options.php');
?>