Changeset 1652087
- Timestamp:
- 05/06/2017 03:37:32 PM (9 years ago)
- Location:
- wp-switch-util/trunk
- Files:
-
- 6 edited
-
README.md (modified) (3 diffs)
-
inc/wp_switch_util_setting.php (modified) (12 diffs)
-
lang/wp_su-zh_CN.mo (modified) (previous)
-
lang/wp_su-zh_CN.po (modified) (4 diffs)
-
readme.txt (modified) (3 diffs)
-
wp_switch_util.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-switch-util/trunk/README.md
r1422163 r1652087 14 14 * Disable the admin bar 15 15 * Enable the link manager 16 16 * Disable auto p 17 * Only registered user access 17 18 18 19 这个插件实现了以下功能: … … 27 28 * 启用友情链接 28 29 * 禁用自动添加<p>标签 30 * 仅登陆用户可访问 29 31 30 32 #### Installation … … 44 46 45 47 #### Changelog 48 49 **1.1.0** 50 51 * Add feature "Only registered user access" 52 * 添加仅登陆用户可访问功能 46 53 47 54 **0.3.1** -
wp-switch-util/trunk/inc/wp_switch_util_setting.php
r1365102 r1652087 1 1 <?php 2 if ( $_POST[WPSwitchUtilConfig::CONFIG_OPTIONS_KEY]) {2 if (isset($_POST) && array_key_exists(WPSwitchUtilConfig::CONFIG_OPTIONS_KEY, $_POST)) { 3 3 $postOptions = $_POST[WPSwitchUtilConfig::CONFIG_OPTIONS_KEY]; 4 4 $this->options = $postOptions; … … 20 20 <td> 21 21 <input type="checkbox" name="wp_su_options[cacheavatar]" id="wpSuCacheAvatar" value="1" 22 <?php echo ($this-> options['cacheavatar']== '1') ? 'checked' : '' ?>/>22 <?php echo ($this->getOption('cacheavatar') == '1') ? 'checked' : '' ?>/> 23 23 <?php echo __('Cache Days:', 'wp_su') ?> 24 24 <input type="number" name="wp_su_options[cacheday]" id="wpSuCacheDay" min="0" max="999" 25 value="<?php echo $this-> options['cacheday']; ?>" required="required"/>25 value="<?php echo $this->getOption('cacheday'); ?>" required="required"/> 26 26 <?php echo __('If you set 0, it\'s will no referce.', 'wp_su') ?> 27 27 </td> … … 31 31 <td> 32 32 <input type="checkbox" name="wp_su_options[mdb5url]" id="wpSuMdb5Url" value="1" 33 <?php echo ($this-> options['mdb5url']== '1') ? 'checked' : '' ?>/>33 <?php echo ($this->getOption('mdb5url') == '1') ? 'checked' : '' ?>/> 34 34 <?php echo __('Length:', 'wp_su') ?> 35 35 <input type="number" name="wp_su_options[mdb5length]" id="wpSuMdb5Length" min="16" max="32" 36 value="<?php echo $this->options['mdb5length']; ?>" required="required"/> 36 value="<?php echo $this->getOption('mdb5length'); ?>" required="required"/> 37 38 <label><?php echo __('MDB5 Type', 'wp_su') ?></label> 39 <input type="checkbox" name="wp_su_options[mdb5typepost]" id="wpSuMdb5TypePost" value="1" 40 <?php echo ($this->getOption('mdb5typepost') == '1') ? 'checked' : '' ?>/> 41 <label for="wpSuMdb5TypePost"><?php echo __('Post', 'wp_su') ?></label> 42 <input type="checkbox" name="wp_su_options[mdb5typepage]" id="wpSuMdb5TypePage" value="1" 43 <?php echo ($this->getOption('mdb5typepage') == '1') ? 'checked' : '' ?>/> 44 <label for="wpSuMdb5TypePage"><?php echo __('Page', 'wp_su') ?></label> 37 45 </td> 38 46 </tr> … … 41 49 <td> 42 50 <input type="checkbox" name="wp_su_options[changeword]" id="wpSuChangeWord" value="1" 43 <?php echo ($this-> options['changeword']== '1') ? 'checked' : '' ?>/>51 <?php echo ($this->getOption('changeword') == '1') ? 'checked' : '' ?>/> 44 52 </select></td> 45 53 </tr> … … 48 56 <td> 49 57 <input type="checkbox" name="wp_su_options[autosave]" id="wpSuAutoSave" value="1" 50 <?php echo ($this-> options['autosave']== '1') ? 'checked' : '' ?>/>58 <?php echo ($this->getOption('autosave') == '1') ? 'checked' : '' ?>/> 51 59 </select></td> 52 60 </tr> … … 55 63 <td> 56 64 <input type="checkbox" name="wp_su_options[hirstroy]" id="wpSuHirstroy" value="1" 57 <?php echo ($this-> options['hirstroy']== '1') ? 'checked' : '' ?>/>65 <?php echo ($this->getOption('hirstroy') == '1') ? 'checked' : '' ?>/> 58 66 </td> 59 67 </tr> … … 62 70 <td> 63 71 <input type="checkbox" name="wp_su_options[pingback]" id="wpSuPingback" value="1" 64 <?php echo ($this-> options['pingback']== '1') ? 'checked' : '' ?>/>72 <?php echo ($this->getOption('pingback') == '1') ? 'checked' : '' ?>/> 65 73 </td> 66 74 </tr> … … 69 77 <td> 70 78 <input type="checkbox" name="wp_su_options[adminbar]" id="wpSuAdminBar" value="1" 71 <?php echo ($this-> options['adminbar']== '1') ? 'checked' : '' ?>/>79 <?php echo ($this->getOption('adminbar') == '1') ? 'checked' : '' ?>/> 72 80 </td> 73 81 </tr> … … 76 84 <td> 77 85 <input type="checkbox" name="wp_su_options[linkmanager]" id="wpSuLinkManager" value="1" 78 <?php echo ($this-> options['linkmanager']== '1') ? 'checked' : '' ?>/>86 <?php echo ($this->getOption('linkmanager') == '1') ? 'checked' : '' ?>/> 79 87 </td> 80 88 </tr> … … 83 91 <td> 84 92 <input type="checkbox" name="wp_su_options[autopcontent]" id="wpAutoPContent" value="1" 85 <?php echo ($this-> options['autopcontent']== '1') ? 'checked' : '' ?>/>93 <?php echo ($this->getOption('autopcontent') == '1') ? 'checked' : '' ?>/> 86 94 </td> 87 95 </tr> … … 90 98 <td> 91 99 <input type="checkbox" name="wp_su_options[autopcomment]" id="wpAutoPComment" value="1" 92 <?php echo ($this->options['autopcomment'] == '1') ? 'checked' : '' ?>/> 100 <?php echo ($this->getOption('autopcomment') == '1') ? 'checked' : '' ?>/> 101 </td> 102 </tr> 103 <tr> 104 <th scope="row"><?php echo __('Registered user only', 'wp_su') ?></th> 105 <td> 106 <input type="checkbox" name="wp_su_options[reguseronly]" id="wpRegUserOnly" value="1" 107 <?php echo ($this->getOption('reguseronly') == '1') ? 'checked' : '' ?>/> 93 108 </td> 94 109 </tr> … … 104 119 document.getElementById('wpSuCacheDay').disabled = !document.getElementById('wpSuCacheAvatar').checked; 105 120 document.getElementById('wpSuMdb5Length').disabled = !document.getElementById('wpSuMdb5Url').checked; 121 document.getElementById('wpSuMdb5TypePost').disabled = !document.getElementById('wpSuMdb5Url').checked; 122 document.getElementById('wpSuMdb5TypePage').disabled = !document.getElementById('wpSuMdb5Url').checked; 106 123 } 107 124 document.getElementById('wpSuCacheAvatar').onclick = setDisable; -
wp-switch-util/trunk/lang/wp_su-zh_CN.po
r1365102 r1652087 2 2 msgstr "" 3 3 "Project-Id-Version: WP Switch Util\n" 4 "POT-Creation-Date: 201 6-03-06 18:11+0900\n"5 "PO-Revision-Date: 201 6-03-06 18:38+0900\n"4 "POT-Creation-Date: 2017-05-07 00:21+0900\n" 5 "PO-Revision-Date: 2017-05-07 00:22+0900\n" 6 6 "Last-Translator: \n" 7 7 "Language-Team: \n" … … 11 11 "Content-Transfer-Encoding: 8bit\n" 12 12 "Plural-Forms: nplurals=1; plural=0;\n" 13 "X-Generator: Poedit 1.8.6\n"13 "X-Generator: Poedit 2.0.1\n" 14 14 "X-Poedit-Basepath: ..\n" 15 15 "X-Poedit-WPHeader: wp_switch_util.php\n" … … 21 21 "X-Poedit-SearchPathExcluded-0: *.js\n" 22 22 23 #: inc/wp_switch_util_setting.php:10 wp_switch_util.php: 7223 #: inc/wp_switch_util_setting.php:10 wp_switch_util.php:106 24 24 msgid "Wp Switch Util" 25 25 msgstr "" … … 61 61 msgstr "长度:" 62 62 63 #: inc/wp_switch_util_setting.php:40 63 #: inc/wp_switch_util_setting.php:38 64 msgid "MDB5 Type" 65 msgstr "要转换的类型" 66 67 #: inc/wp_switch_util_setting.php:41 68 msgid "Post" 69 msgstr "文章" 70 71 #: inc/wp_switch_util_setting.php:44 72 msgid "Page" 73 msgstr "页面" 74 75 #: inc/wp_switch_util_setting.php:48 64 76 msgid "Disable Change The Word" 65 77 msgstr "不转换半角到全角" 66 78 67 #: inc/wp_switch_util_setting.php: 4779 #: inc/wp_switch_util_setting.php:55 68 80 msgid "Disable Auto Save" 69 81 msgstr "禁用自动保存" 70 82 71 #: inc/wp_switch_util_setting.php: 5483 #: inc/wp_switch_util_setting.php:62 72 84 msgid "Disable hirstroy" 73 85 msgstr "禁用历史版本" 74 86 75 #: inc/wp_switch_util_setting.php:6 187 #: inc/wp_switch_util_setting.php:69 76 88 msgid "Disable pingback in site" 77 89 msgstr "禁止站内Pingback" 78 90 79 #: inc/wp_switch_util_setting.php: 6891 #: inc/wp_switch_util_setting.php:76 80 92 msgid "Don't display the admin bar" 81 93 msgstr "不显示admin bar" 82 94 83 #: inc/wp_switch_util_setting.php: 7595 #: inc/wp_switch_util_setting.php:83 84 96 msgid "Enable the link manager" 85 97 msgstr "启用友情链接" 86 98 87 #: inc/wp_switch_util_setting.php: 8299 #: inc/wp_switch_util_setting.php:90 88 100 msgid "Disable auto p at content" 89 101 msgstr "禁用文章自动添加<p>标签" 90 102 91 #: inc/wp_switch_util_setting.php: 89103 #: inc/wp_switch_util_setting.php:97 92 104 msgid "Disable auto p at comment" 93 105 msgstr "禁用评论自动添加<p>标签" 94 106 95 #: inc/wp_switch_util_setting.php:98 107 #: inc/wp_switch_util_setting.php:104 108 msgid "Registered user only" 109 msgstr "仅注册用户可以访问" 110 111 #: inc/wp_switch_util_setting.php:113 96 112 msgid "Save Changes" 97 113 msgstr "保存修改" 98 114 99 #: wp_switch_util.php: 82115 #: wp_switch_util.php:116 100 116 msgid "Settings" 101 117 msgstr "设置" 118 119 #: wp_switch_util.php:237 120 msgid "" 121 "Only registered and logged in users are allowed to view this site. Please " 122 "log in now." 123 msgstr "仅注册并登陆后的用户可以访问本站,请登陆。" 102 124 103 125 #. Plugin Name of the plugin/theme -
wp-switch-util/trunk/readme.txt
r1422163 r1652087 24 24 * Enable the link manager 25 25 * Disable auto p 26 * Only registered user access 26 27 27 28 这个插件实现了以下功能: … … 35 36 * 不显示admin bar 36 37 * 启用友情链接 38 * 禁用自动添加<p>标签 39 * 仅登陆用户可访问 37 40 38 41 == Installation == … … 58 61 59 62 == Changelog == 63 64 = 1.1.0 = 65 66 * Add feature "Only registered user access" 67 * 添加仅登陆用户可访问功能 60 68 61 69 = 0.3.1 = -
wp-switch-util/trunk/wp_switch_util.php
r1422163 r1652087 5 5 * Plugin URI: http://yutuo.net/archives/f685d2dbbb176e86.html 6 6 * Description: This plugin can: cache the avatar, format you url, disable the histroy, disable auto save, disable admin bar 7 * Version: 0.3.17 * Version: 1.1.0 8 8 * Author: yutuo 9 9 * Author URI: http://yutuo.net … … 23 23 'mdb5url' => '0', 24 24 'mdb5length' => '16', 25 'mdb5typepost' => '1', 26 'mdb5typepage' => '0', 25 27 'changeword' => '0', 26 28 'autosave' => '0', … … 31 33 'autopcontent' => '0', 32 34 'autopcomment' => '0', 35 'reguseronly' => '0', 36 ); 37 38 /** 注册用户页面 */ 39 static $REG_USER_ONLY_PAGES = array( 40 'cacheavatar' => '0', 41 'cacheday' => '15', 42 'mdb5url' => '0', 43 'mdb5length' => '16', 44 'mdb5typepost' => '1', 45 'mdb5typepage' => '0', 46 'changeword' => '0', 47 'autosave' => '0', 48 'hirstroy' => '0', 49 'pingback' => '0', 50 'adminbar' => '0', 51 'linkmanager' => '0', 52 'autopcontent' => '0', 53 'autopcomment' => '0', 54 'reguseronly' => '0', 33 55 ); 34 56 } … … 44 66 45 67 /** 构造函数 */ 46 function WPSwitchUtil()68 function __construct() 47 69 { 48 70 $this->pluginDir = dirname(plugin_basename(__FILE__)); … … 50 72 $this->options = get_option(WPSwitchUtilConfig::CONFIG_OPTIONS_KEY); 51 73 } 74 75 /** 读取设置值,没有设置值时,读取初始值 */ 76 function getOption($key) { 77 if (array_key_exists($key, $this->options)) { 78 return $this->options[$key]; 79 } else { 80 return WPSwitchUtilConfig::$DEFAULT_OPTION[$key]; 81 } 82 } 52 83 53 84 /** 启用 */ … … 62 93 delete_option(WPSwitchUtilConfig::CONFIG_OPTIONS_KEY); 63 94 } 95 64 96 65 97 /** 初始化 */ … … 125 157 { 126 158 $post_title = $_POST['post_title']; 127 $str = mb_convert_encoding($post_title, 'UTF-8'); 128 $md5_str = md5($str); 129 130 $length = array_key_exists('mdb5length', $this->options) ? intval($this->options['mdb5length']) : 16; 131 132 $md5_str = substr($md5_str, intval((32 - $length) / 2), $length); 133 return $md5_str; 159 $post_type = $_POST['post_type']; 160 $setting_key = 'mdb5type' . $post_type; 161 162 if (array_key_exists($setting_key, $this->options) && $this->options[$setting_key] == '1') { 163 $str = mb_convert_encoding($post_title, 'UTF-8'); 164 $md5_str = md5($str); 165 166 $length = array_key_exists('mdb5length', $this->options) ? intval($this->options['mdb5length']) : 16; 167 168 $md5_str = substr($md5_str, intval((32 - $length) / 2), $length); 169 return $md5_str; 170 } else { 171 return $postname; 172 } 134 173 } 135 174 … … 172 211 return false; 173 212 } 174 213 214 /** 仅注册用户可以访问 */ 215 function regUserOnly() { 216 if (current_user_can('read')) { 217 return; 218 } 219 220 if (in_array(basename($_SERVER['PHP_SELF']), WPSwitchUtilConfig::$REG_USER_ONLY_PAGES)) { 221 return; 222 } 223 224 auth_redirect(); 225 } 226 227 public function loginFormMessage() { 228 if ('wp-login.php' != basename($_SERVER['PHP_SELF']) || !empty($_POST) || (!empty($_GET) && empty($_GET['redirect_to']))) { 229 return; 230 } 231 232 $redirectTo = $_GET['redirect_to']; 233 if (strpos($redirectTo, get_admin_url()) === 0) { 234 return; 235 } 236 global $error; 237 $error = __('Only registered and logged in users are allowed to view this site. Please log in now.', 'wp_su'); 238 } 239 175 240 /** 应用插件 */ 176 241 function apply() … … 191 256 } 192 257 // 头像缓存 193 if (array_key_exists('cacheavatar', $this->options) && $this->options['cacheavatar']== '1') {258 if ($this->getOption('cacheavatar') == '1') { 194 259 add_filter('get_avatar', array($this, 'cacheAvatar'), 10, 4); 195 260 } 196 261 // MDB5的URL 197 if (array_key_exists('mdb5url', $this->options) && $this->options['mdb5url']== '1') {262 if ($this->getOption('mdb5url') == '1') { 198 263 add_filter('name_save_pre', array($this, 'mdb5Url')); 199 264 } 200 265 // 不转换半角到全角 201 if (array_key_exists('changeword', $this->options) && $this->options['changeword']== '1') {266 if ($this->getOption('changeword') == '1') { 202 267 $this->changeWord(); 203 268 } 204 269 // 禁止自动保存 205 if (array_key_exists('autosave', $this->options) && $this->options['autosave']== '1') {270 if ($this->getOption('autosave') == '1') { 206 271 add_action('wp_print_scripts', array($this, 'disableAutoSave')); 207 272 } 208 273 // 禁止历史版本 209 if (array_key_exists('hirstroy', $this->options) && $this->options['hirstroy']== '1') {274 if ($this->getOption('hirstroy') == '1') { 210 275 remove_action('post_updated', 'wp_save_post_revision'); 211 276 } 212 277 // 阻止站内文章Pingback 213 if (array_key_exists('pingback', $this->options) && $this->options['pingback']== '1') {278 if ($this->getOption('pingback') == '1') { 214 279 add_action('pre_ping', array($this, 'disablePingbackSelf')); 215 280 } 216 281 // 不显示AdminBar 217 if (array_key_exists('adminbar', $this->options) && $this->options['adminbar']== '1') {282 if ($this->getOption('adminbar') == '1') { 218 283 add_filter('show_admin_bar', array($this, 'hideAdminBar')); 219 284 } 220 285 // 启用友情链接 221 if (array_key_exists('linkmanager', $this->options) && $this->options['linkmanager']== '1') {286 if ($this->getOption('linkmanager') == '1') { 222 287 add_filter('pre_option_link_manager_enabled', '__return_true'); 223 288 } 224 // 禁用文章自动添加 <p>225 if (array_key_exists('autopcontent', $this->options) && $this->options['autopcontent']== '1') {289 // 禁用文章自动添加 290 if ($this->getOption('autopcontent') == '1') { 226 291 remove_filter('the_content', 'wpautop'); 227 292 } 228 // 禁用评论自动添加 <p>229 if (array_key_exists('autopcomment', $this->options) && $this->options['autopcomment']== '1') {293 // 禁用评论自动添加 294 if ($this->getOption('autopcomment') == '1') { 230 295 remove_filter('comment_text', 'wpautop'); 296 } 297 // 仅注册用户可以访问 298 if ($this->getOption('reguseronly') == '1') { 299 add_action('wp', array($this, 'regUserOnly')); 300 add_action('init', array($this, 'loginFormMessage')); 231 301 } 232 302 }
Note: See TracChangeset
for help on using the changeset viewer.