Пример #1
0
<?php

/*
Plugin Name: WebKit Table of Contents
Plugin URI: http://webkit.org
Description: Builds a table of contents with navigation anchors from headings
Version: 1.0
Author: Jonathan Davis
*/
WebKitTableOfContents::init();
class WebKitTableOfContents
{
    private static $editing = false;
    private static $toc = array();
    private static $attr_regex = '\\{((?:[ ]*[#.][-_:a-zA-Z0-9]+){1,})[ ]*\\}';
    public function init()
    {
        add_filter('wp_insert_post_data', array('WebKitTableOfContents', 'wp_insert_post_data'), 20, 2);
        add_action('wp_insert_post', array('WebKitTableOfContents', 'wp_insert_post'));
    }
    public static function hasIndex()
    {
        $toc = get_post_meta(get_the_ID(), 'toc', true);
        array_walk($toc, array('WebKitTableOfContents', 'filterIndex'));
        return !empty(self::$toc) && count(self::$toc) > 2;
    }
    public static function filterIndex($value, $key)
    {
        list($level, $anchor) = explode('::', $key);
        if ($level < 3) {
            self::$toc[$key] = $value;