Plugin Directory

Changeset 800973


Ignore:
Timestamp:
11/08/2013 07:03:32 AM (12 years ago)
Author:
rewish
Message:

Version 2.1.0 Released

Location:
wp-hatena-notation/trunk
Files:
3 added
1 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • wp-hatena-notation/trunk/WP/Hatena/Notation.php

    r707957 r800973  
    44 */
    55require_once dirname(__FILE__) . '/Notation/Exception.php';
     6
    67require_once dirname(__FILE__) . '/Notation/Domain.php';
    78require_once dirname(__FILE__) . '/Notation/Options.php';
    8 require_once dirname(__FILE__) . '/Notation/Config.php';
     9require_once dirname(__FILE__) . '/Notation/PostSetting.php';
     10require_once dirname(__FILE__) . '/Notation/Cache.php';
     11
    912require_once dirname(__FILE__) . '/Notation/Renderer.php';
    1013require_once dirname(__FILE__) . '/Notation/LinkTitle.php';
     14
    1115require_once dirname(__FILE__) . '/Notation/Migration.php';
    1216
     
    1923
    2024    /**
    21      * Config instance
    22      * @var WP_Hatena_Notation_Config
    23      */
    24     protected $Config;
     25     * PostSetting instance
     26     * @var WP_Hatena_Notation_PostSetting
     27     */
     28    protected $PostSetting;
    2529
    2630    /**
     
    3135
    3236    /**
     37     * Cache instance
     38     * @var WP_Hatena_Notation_Cache
     39     */
     40    protected $Cache;
     41
     42    /**
    3343     * Enable wpautop filter
    3444     * @var bool
     
    3848    /**
    3949     * Constructor
    40      *
    41      * @param string $domain
    42      */
    43     public function __construct($domain) {
    44         $this->Options = new WP_Hatena_Notation_Options($domain);
    45         $this->Config = new WP_Hatena_Notation_Config($domain, $this->option('Config'));
     50     */
     51    public function __construct() {
     52        $this->Options = new WP_Hatena_Notation_Options();
     53        $this->PostSetting = new WP_Hatena_Notation_PostSetting($this->option('PostSetting'));
    4654        $this->Renderer = new WP_Hatena_Notation_Renderer($this->option('Renderer'));
     55        $this->Cache = new WP_Hatena_Notation_Cache();
    4756
    4857        $this->registerHooks();
     
    5362     */
    5463    protected function registerHooks() {
    55         add_action('admin_init', array($this, 'onAdminInit'));
     64        if (is_admin()) {
     65            add_action('admin_init', array($this, 'onAdminInit'));
     66            add_action('save_post', array($this, 'onSavePost'));
     67        }
     68
    5669        add_action('the_post', array($this, 'onThePost'));
    5770        add_filter('the_content', array($this, 'onTheContent'));
     
    8497     */
    8598    public function render($content) {
     99        $content = preg_replace('/<!--more(.*?)?-->/', '====', $content);
    86100        return $this->Renderer->render(HatenaSyntax::parse($content));
    87101    }
    88102
    89103    /**
     104     * Cached content
     105     *
     106     * @param WP_Post $post
     107     * @param string $content
     108     * @return string
     109     */
     110    public function cachedContent($post, $content) {
     111        $cachedContent = $this->Cache->get($post, 'content');
     112
     113        if (!$cachedContent) {
     114            $cachedContent = $this->render($content);
     115            $this->Cache->set($post, 'content', $cachedContent);
     116        }
     117
     118        return $cachedContent;
     119    }
     120
     121    /**
    90122     * Enabled post?
    91123     *
    92124     * @param WP_Post $post
     125     * @param integer $enabled
    93126     * @return bool
    94127     */
     
    97130
    98131        if (count(func_get_args()) === 2) {
    99             return $this->Config->saveEnabled($post->ID, $enabled);
    100         }
    101 
    102         return $this->Config->isEnabled($post->ID);
     132            return $this->PostSetting->saveEnabled($post->ID, $enabled);
     133        }
     134
     135        return $this->PostSetting->isEnabled($post->ID);
    103136    }
    104137
     
    114147
    115148    /**
     149     * Is enabled cache?
     150     *
     151     * @return bool
     152     */
     153    public function isEnabledCache() {
     154        return !!$this->Options->get('Renderer.cache');
     155    }
     156
     157    /**
    116158     * Hook on admin_init
    117159     */
    118160    public function onAdminInit() {
    119161        WP_Hatena_Notation_Migration::migrate($this);
     162    }
     163
     164    /**
     165     * Hook on save_post
     166     *
     167     * @param integer $postID
     168     */
     169    public function onSavePost($postID) {
     170        if ($this->enabled($postID) && $this->isEnabledCache()) {
     171            $post = get_post($postID);
     172            $this->Cache->set($post, 'content', $this->render($post->post_content));
     173        }
    120174    }
    121175
     
    130184        global $page, $pages;
    131185
    132         if ($this->enabled($post)) {
    133             $content = preg_replace('/<!--more(.*?)?-->/', '====', $pages[$page - 1]);
    134             $pages[$page - 1] = $this->render($content);
     186        if (!$this->enabled($post)) {
     187            return;
     188        }
     189
     190        if ($this->isEnabledCache()) {
     191            $pages[$page - 1] = $this->cachedContent($post, $pages[$page - 1]);
     192        } else {
     193            $pages[$page - 1] = $this->render($pages[$page - 1]);
    135194        }
    136195    }
  • wp-hatena-notation/trunk/WP/Hatena/Notation/Domain.php

    r706689 r800973  
    88     * @var string
    99     */
    10     protected $name;
     10    protected $domain = WP_HATENA_NOTATION_DOMAIN;
    1111
    1212    /**
    13      * Constructor
     13     * Get ID
    1414     *
    15      * @param string $name
     15     * @param string $key
     16     * @return string
    1617     */
    17     public function __construct($name) {
    18         $this->name = $name;
     18    public function id($key) {
     19        return $this->domain . '_' . $key;
    1920    }
    2021
    2122    /**
    22      * Field name
     23     * Get nonce key
     24     *
     25     * @return string
     26     */
     27    public function nonceKey() {
     28        return $this->domain . '_nonce';
     29    }
     30
     31    /**
     32     * Get field name
    2333     *
    2434     * @param  string $key
     
    2636     */
    2737    public function fieldName($key) {
    28         return $this->name . '[' . implode('][', explode('.', $key)) . ']';
     38        return $this->domain . '[' . implode('][', explode('.', $key)) . ']';
     39    }
     40
     41    /**
     42     * Get meta key
     43     *
     44     * @param string $key
     45     * @return string
     46     */
     47    public function metaKey($key) {
     48        return '_' . $this->id($key);
    2949    }
    3050}
  • wp-hatena-notation/trunk/WP/Hatena/Notation/LinkTitle.php

    r707792 r800973  
    1717
    1818    /**
    19      * Title titless
     19     * Title titles
    2020     * @var array
    2121     */
  • wp-hatena-notation/trunk/WP/Hatena/Notation/Migration.php

    r727156 r800973  
    44class WP_Hatena_Notation_Migration {
    55    /**
    6      * Migration version number
    7      */
    8     const VERSION = '2.0.0';
    9 
    10     /**
    116     * Migration version name
    127     */
    13     const VERSION_NAME = 'hatena-notation-migrations';
    14 
    15     /**
    16      * Legacy option name
    17      * @constant string
    18      */
    19     const LEGACY_OPTION_NAME = 'hatena_notation';
    20 
    21     /**
    22      * Legacy link title table name
    23      * @constant string
    24      */
    25     const LEGACY_LINK_TITLE_TABLE_NAME = 'hatena_notation';
     8    const VERSION_NAME = 'wp-hatena-notation-migration-version';
    269
    2710    /**
     
    3316        $version = get_option(self::VERSION_NAME, '1.4');
    3417        $versions = self::getVersions();
    35         $migrated = false;
     18        $latestVersion = 0;
    3619
    3720        foreach ($versions as $info) {
    38             if ($version <= $info['version']) {
    39                 require_once $info['path'];
    40                 call_user_func(array($info['class'], 'migrate'), $context);
    41                 $migrated = true;
     21            if ($version > $info['version']) {
     22                continue;
     23            }
     24
     25            require_once $info['path'];
     26            call_user_func(array($info['class'], 'migrate'), $context);
     27
     28            if ($latestVersion < $info['version']) {
     29                $latestVersion = $info['version'];
    4230            }
    4331        }
    4432
    45         if ($migrated) {
    46             update_option(self::VERSION_NAME, self::VERSION);
     33        if ($latestVersion > $version) {
     34            update_option(self::VERSION_NAME, $latestVersion);
    4735        }
    4836    }
  • wp-hatena-notation/trunk/WP/Hatena/Notation/Options.php

    r707957 r800973  
    2424    /**
    2525     * Constructor
    26      *
    27      * @param string $name Option name
    2826     */
    29     public function __construct($name) {
    30         parent::__construct($name);
     27    public function __construct() {
    3128        $this->setUp();
    3229        $this->registerHooks();
     
    3734     */
    3835    public function setUp() {
    39         $this->options = get_option($this->name, array()) + array(
     36        $this->options = get_option($this->domain, array()) + array(
    4037            'Renderer' => array(),
    41             'Config' => array()
     38            'PostSetting' => array()
    4239        );
    4340
    4441        $this->options['Renderer'] += array(
     42            'cache' => false,
    4543            'headerlevel' => 3,
    4644            'linebreak_method' => 'wpautop',
     
    5351        );
    5452
    55         $this->options['Config'] += array(
     53        $this->options['PostSetting'] += array(
    5654            'per_user' => false,
    5755            'per_user_default' => true,
     
    8381        }
    8482
    85         update_option($this->name, $this->options);
     83        update_option($this->domain, $this->options);
    8684    }
    8785
     
    9088     *
    9189     * @param string $key
     90     * @return mixed
    9291     */
    9392    public function get($key = null) {
     
    115114     *
    116115     * @param string $key
     116     * @return string
    117117     */
    118118    public function toJSON($key) {
     
    124124     */
    125125    public function addOptionsPage() {
    126         add_options_page(self::PAGE_TITLE, self::MENU_TITLE, 'manage_options', $this->name, array($this, 'renderOptionsPage'));
     126        add_options_page(self::PAGE_TITLE, self::MENU_TITLE, 'manage_options', $this->domain, array($this, 'renderOptionsPage'));
    127127    }
    128128
     
    134134
    135135        $options = (object)$this->get();
    136         $options->Renderer = (object)$options->Renderer;
    137         $options->Config = (object)$options->Config;
     136
     137        foreach ($options as &$option) {
     138            $option = (object)$option;
     139        }
    138140
    139141        $highlightCSS = $wp_hatena_notation->fileURL('css/highlight.css');
  • wp-hatena-notation/trunk/readme.txt

    r727151 r800973  
    4242== Changelog ==
    4343
     44= 2.1.0 =
     45* はてな記法解析結果のキャッシュ機能を追加
     46
    4447= 2.0.4 =
    4548* 互換性維持のため`wphn_render()`を追加
  • wp-hatena-notation/trunk/views/meta_box.php

    r706689 r800973  
    1 <?php wp_nonce_field($this->name, $this->nonceKey()); ?>
     1<?php wp_nonce_field($this->domain, $this->nonceKey()); ?>
    22
    33<input type="hidden" name="<?php echo $this->fieldName('Post.enabled'); ?>" value="0">
    4 <input id="<?php echo $this->name; ?>_enabled" type="checkbox" name="<?php echo $this->fieldName('Post.enabled'); ?>" value="1"<?php if ($enabled): ?> checked="checked"<?php endif; ?>>
    5 <label for="<?php echo $this->name; ?>_enabled">はてな記法を使用</label>
     4<input id="<?php echo $this->id('enabled'); ?>" type="checkbox" name="<?php echo $this->fieldName('Post.enabled'); ?>" value="1"<?php if ($enabled): ?> checked="checked"<?php endif; ?>>
     5<label for="<?php echo $this->id('enabled'); ?>">はてな記法を使用</label>
  • wp-hatena-notation/trunk/views/options.php

    r707957 r800973  
    77            <?php wp_nonce_field('update-options'); ?>
    88            <input type="hidden" name="action" value="update">
    9             <input type="hidden" name="page_options" value="<?php echo $this->name; ?>">
     9            <input type="hidden" name="page_options" value="<?php echo $this->domain; ?>">
    1010        </div>
    1111
     
    1313        <table class="form-table">
    1414            <tbody>
     15                <tr>
     16                    <th>パフォーマンス</th>
     17                    <td>
     18                        <label>
     19                            <input type="hidden" name="<?php echo $this->fieldName('Renderer.cache'); ?>" value="0">
     20                            <input type="checkbox" name="<?php echo $this->fieldName('Renderer.cache'); ?>" value="1"<?php if ($options->Renderer->cache): ?> checked="checked"<?php endif; ?>>
     21                            記事のレンダリング結果をキャッシュ
     22                        </label>
     23                    </td>
     24                </tr>
     25
    1526                <tr>
    1627                    <th>見出し記法基準レベル</th>
     
    7283
    7384                <tr>
    74                     <th style="padding-bottom:2px;" rowspan="3">スーパーpre記法の色分け方法</th>
     85                    <th style="padding-bottom:2px;" rowspan="2">スーパーpre記法の色分け方法</th>
    7586                    <td style="padding-bottom:2px;">
    7687                        <select id="wp_hatena_notation_superpre_method" name="<?php echo $this->fieldName('Renderer.superpre_method'); ?>">
     
    99110                <th rowspan="2">記事ごとの設定</th>
    100111                <td>
    101                     <input type="hidden" name="<?php echo $this->fieldName('Config.per_post'); ?>" value="0">
    102                     <input id="wp_hatena_notation_per_post" type="checkbox" name="<?php echo $this->fieldName('Config.per_post'); ?>" value="1"<?php if ($options->Config->per_post): ?> checked="checked"<?php endif; ?>>
     112                    <input type="hidden" name="<?php echo $this->fieldName('PostSetting.per_post'); ?>" value="0">
     113                    <input id="wp_hatena_notation_per_post" type="checkbox" name="<?php echo $this->fieldName('PostSetting.per_post'); ?>" value="1"<?php if ($options->PostSetting->per_post): ?> checked="checked"<?php endif; ?>>
    103114                    <label for="wp_hatena_notation_per_post">使用/不使用の切り替えを許可する</label>
    104115                    <div id="wp_hatena_notation_per_post_default_wrap">
    105                         ┗<input type="hidden" name="<?php echo $this->fieldName('Config.per_post_default'); ?>" value="0">
    106                         <input id="wp_hatena_notation_per_post_default" type="checkbox" name="<?php echo $this->fieldName('Config.per_post_default'); ?>" value="1"<?php if ($options->Config->per_post_default): ?> checked="checked"<?php endif; ?>>
     116                        ┗<input type="hidden" name="<?php echo $this->fieldName('PostSetting.per_post_default'); ?>" value="0">
     117                        <input id="wp_hatena_notation_per_post_default" type="checkbox" name="<?php echo $this->fieldName('PostSetting.per_post_default'); ?>" value="1"<?php if ($options->PostSetting->per_post_default): ?> checked="checked"<?php endif; ?>>
    107118                        <label for="wp_hatena_notation_per_post_default">初期状態で「はてな記法を使用」にチェックを入れる</label>
    108119                    </div>
    109120                </td>
    110                 <td></td>
    111121            </tr>
    112122        </table>
  • wp-hatena-notation/trunk/wp-hatena-notation.php

    r727151 r800973  
    44Plugin URI: https://github.com/rewish/wp-hatena-notation
    55Description: WordPressに「はてな記法」を導入します。
    6 Version: 2.0.4
     6Version: 2.1.0
    77Author: rewish
    88Author URI: https://github.com/rewish
    99*/
     10define('WP_HATENA_NOTATION_DOMAIN', 'wp-hatena-notation');
     11
    1012define('WP_HATENA_NOTATION_DIR',      WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . basename(dirname(__FILE__)));
    1113define('WP_HATENA_NOTATION_FILE',     WP_HATENA_NOTATION_DIR . DIRECTORY_SEPARATOR . basename(__FILE__));
     
    1618
    1719// Global instance
    18 $wp_hatena_notation = new WP_Hatena_Notation('wp-hatena-notation');
     20$wp_hatena_notation = new WP_Hatena_Notation();
    1921
    2022// Function to maintain compatibility with 1.x
Note: See TracChangeset for help on using the changeset viewer.