Plugin Directory

Changeset 707957


Ignore:
Timestamp:
05/04/2013 06:06:44 PM (13 years ago)
Author:
rewish
Message:

WP Hatena Notation 2.0.3 Released

Location:
wp-hatena-notation/trunk
Files:
6 edited

Legend:

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

    r706689 r707957  
    3131
    3232    /**
     33     * Enable wpautop filter
     34     * @var bool
     35     */
     36    protected $wpautop = false;
     37
     38    /**
    3339     * Constructor
    3440     *
     
    4955        add_action('admin_init', array($this, 'onAdminInit'));
    5056        add_action('the_post', array($this, 'onThePost'));
     57        add_filter('the_content', array($this, 'onTheContent'));
     58
     59        // Remove wpautop
     60        if ($this->option('Renderer.linebreak_method') !== 'wordpress') {
     61            $this->wpautop = remove_filter('the_content', 'wpautop');
     62        }
    5163    }
    5264
     
    6981     *
    7082     * @param string $content
    71      * @param mixed $post Optional, Post ID or Post object
    7283     * @return string
    7384     */
    74     public function render($content, $post = null) {
    75         if ($post) {
    76             $post = get_post($post);
    77             if (!$this->Config->isEnabled($post->ID)) {
    78                 return $content;
    79             }
    80         }
     85    public function render($content) {
    8186        return $this->Renderer->render(HatenaSyntax::parse($content));
    8287    }
     
    8590     * Enabled post?
    8691     *
    87      * @param $post_id
     92     * @param WP_Post $post
    8893     * @return bool
    8994     */
    90     public function enabled($post_id, $enabled = 1) {
     95    public function enabled($post, $enabled = 1) {
     96        $post = get_post($post);
     97
    9198        if (count(func_get_args()) === 2) {
    92             return $this->Config->saveEnabled($post_id, $enabled);
     99            return $this->Config->saveEnabled($post->ID, $enabled);
    93100        }
    94         return $this->Config->isEnabled($post_id);
     101
     102        return $this->Config->isEnabled($post->ID);
    95103    }
    96104
     
    121129    public function onThePost($post) {
    122130        global $page, $pages;
    123         $content = preg_replace('/<!--more(.*?)?-->/', '====', $pages[$page - 1]);
    124         $pages[$page - 1] = $this->render($content, $post);
     131
     132        if ($this->enabled($post)) {
     133            $content = preg_replace('/<!--more(.*?)?-->/', '====', $pages[$page - 1]);
     134            $pages[$page - 1] = $this->render($content);
     135        }
     136    }
     137
     138    /**
     139     * Hook on the_content
     140     *
     141     * @param string $content
     142     * @return string
     143     */
     144    public function onTheContent($content) {
     145        $post = get_post();
     146
     147        if (!$this->wpautop || $this->enabled($post)) {
     148            return $content;
     149        }
     150
     151        return wpautop($content);
    125152    }
    126153}
  • wp-hatena-notation/trunk/WP/Hatena/Notation/Migration.php

    r707817 r707957  
    7777        }
    7878
    79         $context->option('Config.per_post_default', true);
     79        $context->option('Config.per_post', true);
    8080    }
    8181
  • wp-hatena-notation/trunk/WP/Hatena/Notation/Options.php

    r706689 r707957  
    4444        $this->options['Renderer'] += array(
    4545            'headerlevel' => 3,
    46             'linebreak_method' => 'wordpress',
     46            'linebreak_method' => 'wpautop',
    4747            'link_target_blank' => true,
    4848            'title_expires' => 90,
  • wp-hatena-notation/trunk/readme.txt

    r707817 r707957  
    4242== Changelog ==
    4343
     44= 2.0.3 =
     45* 改行の扱いで「何もしない」以外を選んだ場合`wpautop`フィルタを無効化
     46
    4447= 2.0.2 =
    4548* HTMLが全てエスケープされる不具合を修正
    46 * マイグレーション時に「はてな記法を使用」のデフォルトが不使用になる不具合を修正
    4749
    4850= 2.0.1 =
  • wp-hatena-notation/trunk/views/options.php

    r706689 r707957  
    4747                    <td>
    4848                        <select name="<?php echo $this->fieldName('Renderer.linebreak_method'); ?>">
     49                            <option value="wpautop"<?php if ($options->Renderer->linebreak_method === 'wpautop'): ?> selected="selected"<?php endif; ?>>wpautop関数を適用(推奨)</option>
    4950                            <option value="wordpress"<?php if ($options->Renderer->linebreak_method === 'wordpress'): ?> selected="selected"<?php endif; ?>>何もしない(WordPressの改行ルールに従う)</option>
    50                             <option value="wpautop"<?php if ($options->Renderer->linebreak_method === 'wpautop'): ?> selected="selected"<?php endif; ?>>wpautop関数を適用</option>
    51                             <option value="plugin"<?php if ($options->Renderer->linebreak_method === 'plugin'): ?> selected="selected"<?php endif; ?>>改行を全てpとして扱う</option>
     51                            <option value="plugin"<?php if ($options->Renderer->linebreak_method === 'plugin'): ?> selected="selected"<?php endif; ?>>改行を全てpとして扱う(廃止予定)</option>
    5252                        </select>
    5353                        <p class="description"><code>&lt;p&gt;</code>や<code>&lt;br&gt;</code>を挿入する方法を指定します。</p>
  • wp-hatena-notation/trunk/wp-hatena-notation.php

    r707803 r707957  
    44Plugin URI: https://github.com/rewish/wp-hatena-notation
    55Description: あなたのWordPressに「はてな記法」を導入します。
    6 Version: 2.0.2
     6Version: 2.0.3
    77Author: rewish
    88Author URI: https://github.com/rewish
Note: See TracChangeset for help on using the changeset viewer.