Changeset 800973
- Timestamp:
- 11/08/2013 07:03:32 AM (12 years ago)
- Location:
- wp-hatena-notation/trunk
- Files:
-
- 3 added
- 1 deleted
- 9 edited
-
WP/Hatena/Notation.php (modified) (9 diffs)
-
WP/Hatena/Notation/Cache.php (added)
-
WP/Hatena/Notation/Config.php (deleted)
-
WP/Hatena/Notation/Domain.php (modified) (2 diffs)
-
WP/Hatena/Notation/LinkTitle.php (modified) (1 diff)
-
WP/Hatena/Notation/Migration.php (modified) (2 diffs)
-
WP/Hatena/Notation/Migration/2_1_0.php (added)
-
WP/Hatena/Notation/Options.php (modified) (8 diffs)
-
WP/Hatena/Notation/PostSetting.php (added)
-
readme.txt (modified) (1 diff)
-
views/meta_box.php (modified) (1 diff)
-
views/options.php (modified) (4 diffs)
-
wp-hatena-notation.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-hatena-notation/trunk/WP/Hatena/Notation.php
r707957 r800973 4 4 */ 5 5 require_once dirname(__FILE__) . '/Notation/Exception.php'; 6 6 7 require_once dirname(__FILE__) . '/Notation/Domain.php'; 7 8 require_once dirname(__FILE__) . '/Notation/Options.php'; 8 require_once dirname(__FILE__) . '/Notation/Config.php'; 9 require_once dirname(__FILE__) . '/Notation/PostSetting.php'; 10 require_once dirname(__FILE__) . '/Notation/Cache.php'; 11 9 12 require_once dirname(__FILE__) . '/Notation/Renderer.php'; 10 13 require_once dirname(__FILE__) . '/Notation/LinkTitle.php'; 14 11 15 require_once dirname(__FILE__) . '/Notation/Migration.php'; 12 16 … … 19 23 20 24 /** 21 * Config instance22 * @var WP_Hatena_Notation_ Config23 */ 24 protected $ Config;25 * PostSetting instance 26 * @var WP_Hatena_Notation_PostSetting 27 */ 28 protected $PostSetting; 25 29 26 30 /** … … 31 35 32 36 /** 37 * Cache instance 38 * @var WP_Hatena_Notation_Cache 39 */ 40 protected $Cache; 41 42 /** 33 43 * Enable wpautop filter 34 44 * @var bool … … 38 48 /** 39 49 * 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')); 46 54 $this->Renderer = new WP_Hatena_Notation_Renderer($this->option('Renderer')); 55 $this->Cache = new WP_Hatena_Notation_Cache(); 47 56 48 57 $this->registerHooks(); … … 53 62 */ 54 63 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 56 69 add_action('the_post', array($this, 'onThePost')); 57 70 add_filter('the_content', array($this, 'onTheContent')); … … 84 97 */ 85 98 public function render($content) { 99 $content = preg_replace('/<!--more(.*?)?-->/', '====', $content); 86 100 return $this->Renderer->render(HatenaSyntax::parse($content)); 87 101 } 88 102 89 103 /** 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 /** 90 122 * Enabled post? 91 123 * 92 124 * @param WP_Post $post 125 * @param integer $enabled 93 126 * @return bool 94 127 */ … … 97 130 98 131 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); 103 136 } 104 137 … … 114 147 115 148 /** 149 * Is enabled cache? 150 * 151 * @return bool 152 */ 153 public function isEnabledCache() { 154 return !!$this->Options->get('Renderer.cache'); 155 } 156 157 /** 116 158 * Hook on admin_init 117 159 */ 118 160 public function onAdminInit() { 119 161 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 } 120 174 } 121 175 … … 130 184 global $page, $pages; 131 185 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]); 135 194 } 136 195 } -
wp-hatena-notation/trunk/WP/Hatena/Notation/Domain.php
r706689 r800973 8 8 * @var string 9 9 */ 10 protected $ name;10 protected $domain = WP_HATENA_NOTATION_DOMAIN; 11 11 12 12 /** 13 * Constructor13 * Get ID 14 14 * 15 * @param string $name 15 * @param string $key 16 * @return string 16 17 */ 17 public function __construct($name) {18 $this->name = $name;18 public function id($key) { 19 return $this->domain . '_' . $key; 19 20 } 20 21 21 22 /** 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 23 33 * 24 34 * @param string $key … … 26 36 */ 27 37 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); 29 49 } 30 50 } -
wp-hatena-notation/trunk/WP/Hatena/Notation/LinkTitle.php
r707792 r800973 17 17 18 18 /** 19 * Title titles s19 * Title titles 20 20 * @var array 21 21 */ -
wp-hatena-notation/trunk/WP/Hatena/Notation/Migration.php
r727156 r800973 4 4 class WP_Hatena_Notation_Migration { 5 5 /** 6 * Migration version number7 */8 const VERSION = '2.0.0';9 10 /**11 6 * Migration version name 12 7 */ 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'; 26 9 27 10 /** … … 33 16 $version = get_option(self::VERSION_NAME, '1.4'); 34 17 $versions = self::getVersions(); 35 $ migrated = false;18 $latestVersion = 0; 36 19 37 20 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']; 42 30 } 43 31 } 44 32 45 if ($ migrated) {46 update_option(self::VERSION_NAME, self::VERSION);33 if ($latestVersion > $version) { 34 update_option(self::VERSION_NAME, $latestVersion); 47 35 } 48 36 } -
wp-hatena-notation/trunk/WP/Hatena/Notation/Options.php
r707957 r800973 24 24 /** 25 25 * Constructor 26 *27 * @param string $name Option name28 26 */ 29 public function __construct($name) { 30 parent::__construct($name); 27 public function __construct() { 31 28 $this->setUp(); 32 29 $this->registerHooks(); … … 37 34 */ 38 35 public function setUp() { 39 $this->options = get_option($this-> name, array()) + array(36 $this->options = get_option($this->domain, array()) + array( 40 37 'Renderer' => array(), 41 ' Config' => array()38 'PostSetting' => array() 42 39 ); 43 40 44 41 $this->options['Renderer'] += array( 42 'cache' => false, 45 43 'headerlevel' => 3, 46 44 'linebreak_method' => 'wpautop', … … 53 51 ); 54 52 55 $this->options[' Config'] += array(53 $this->options['PostSetting'] += array( 56 54 'per_user' => false, 57 55 'per_user_default' => true, … … 83 81 } 84 82 85 update_option($this-> name, $this->options);83 update_option($this->domain, $this->options); 86 84 } 87 85 … … 90 88 * 91 89 * @param string $key 90 * @return mixed 92 91 */ 93 92 public function get($key = null) { … … 115 114 * 116 115 * @param string $key 116 * @return string 117 117 */ 118 118 public function toJSON($key) { … … 124 124 */ 125 125 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')); 127 127 } 128 128 … … 134 134 135 135 $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 } 138 140 139 141 $highlightCSS = $wp_hatena_notation->fileURL('css/highlight.css'); -
wp-hatena-notation/trunk/readme.txt
r727151 r800973 42 42 == Changelog == 43 43 44 = 2.1.0 = 45 * はてな記法解析結果のキャッシュ機能を追加 46 44 47 = 2.0.4 = 45 48 * 互換性維持のため`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()); ?> 2 2 3 3 <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 7 7 <?php wp_nonce_field('update-options'); ?> 8 8 <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; ?>"> 10 10 </div> 11 11 … … 13 13 <table class="form-table"> 14 14 <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 15 26 <tr> 16 27 <th>見出し記法基準レベル</th> … … 72 83 73 84 <tr> 74 <th style="padding-bottom:2px;" rowspan=" 3">スーパーpre記法の色分け方法</th>85 <th style="padding-bottom:2px;" rowspan="2">スーパーpre記法の色分け方法</th> 75 86 <td style="padding-bottom:2px;"> 76 87 <select id="wp_hatena_notation_superpre_method" name="<?php echo $this->fieldName('Renderer.superpre_method'); ?>"> … … 99 110 <th rowspan="2">記事ごとの設定</th> 100 111 <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; ?>> 103 114 <label for="wp_hatena_notation_per_post">使用/不使用の切り替えを許可する</label> 104 115 <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; ?>> 107 118 <label for="wp_hatena_notation_per_post_default">初期状態で「はてな記法を使用」にチェックを入れる</label> 108 119 </div> 109 120 </td> 110 <td></td>111 121 </tr> 112 122 </table> -
wp-hatena-notation/trunk/wp-hatena-notation.php
r727151 r800973 4 4 Plugin URI: https://github.com/rewish/wp-hatena-notation 5 5 Description: WordPressに「はてな記法」を導入します。 6 Version: 2. 0.46 Version: 2.1.0 7 7 Author: rewish 8 8 Author URI: https://github.com/rewish 9 9 */ 10 define('WP_HATENA_NOTATION_DOMAIN', 'wp-hatena-notation'); 11 10 12 define('WP_HATENA_NOTATION_DIR', WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . basename(dirname(__FILE__))); 11 13 define('WP_HATENA_NOTATION_FILE', WP_HATENA_NOTATION_DIR . DIRECTORY_SEPARATOR . basename(__FILE__)); … … 16 18 17 19 // Global instance 18 $wp_hatena_notation = new WP_Hatena_Notation( 'wp-hatena-notation');20 $wp_hatena_notation = new WP_Hatena_Notation(); 19 21 20 22 // Function to maintain compatibility with 1.x
Note: See TracChangeset
for help on using the changeset viewer.