Plugin Directory

Changeset 1652087


Ignore:
Timestamp:
05/06/2017 03:37:32 PM (9 years ago)
Author:
yutuo
Message:

Up to 1.1.0

Location:
wp-switch-util/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • wp-switch-util/trunk/README.md

    r1422163 r1652087  
    1414* Disable the admin bar
    1515* Enable the link manager
    16 
     16* Disable auto p
     17* Only registered user access
    1718
    1819这个插件实现了以下功能:
     
    2728* 启用友情链接
    2829* 禁用自动添加<p>标签
     30* 仅登陆用户可访问
    2931
    3032#### Installation
     
    4446
    4547#### Changelog
     48
     49**1.1.0**
     50
     51* Add feature "Only registered user access"
     52* 添加仅登陆用户可访问功能
    4653
    4754**0.3.1**
  • wp-switch-util/trunk/inc/wp_switch_util_setting.php

    r1365102 r1652087  
    11<?php
    2 if ($_POST[WPSwitchUtilConfig::CONFIG_OPTIONS_KEY]) {
     2if (isset($_POST) && array_key_exists(WPSwitchUtilConfig::CONFIG_OPTIONS_KEY, $_POST)) {
    33    $postOptions = $_POST[WPSwitchUtilConfig::CONFIG_OPTIONS_KEY];
    44    $this->options = $postOptions;
     
    2020                    <td>
    2121                        <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' : '' ?>/>
    2323                        <?php echo __('Cache Days:', 'wp_su') ?>
    2424                        <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"/>
    2626                        <?php echo __('If you set 0, it\'s will no referce.', 'wp_su') ?>
    2727                    </td>
     
    3131                    <td>
    3232                        <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' : '' ?>/>
    3434                        <?php echo __('Length:', 'wp_su') ?>
    3535                        <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>
    3745                    </td>
    3846                </tr>
     
    4149                    <td>
    4250                        <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' : '' ?>/>
    4452                    </select></td>
    4553                </tr>
     
    4856                    <td>
    4957                        <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' : '' ?>/>
    5159                    </select></td>
    5260                </tr>
     
    5563                    <td>
    5664                        <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' : '' ?>/>
    5866                    </td>
    5967                </tr>
     
    6270                    <td>
    6371                        <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' : '' ?>/>
    6573                    </td>
    6674                </tr>
     
    6977                    <td>
    7078                        <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' : '' ?>/>
    7280                    </td>
    7381                </tr>
     
    7684                    <td>
    7785                        <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' : '' ?>/>
    7987                    </td>
    8088                </tr>
     
    8391                    <td>
    8492                        <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' : '' ?>/>
    8694                    </td>
    8795                </tr>
     
    9098                    <td>
    9199                        <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' : '' ?>/>
    93108                    </td>
    94109                </tr>
     
    104119            document.getElementById('wpSuCacheDay').disabled = !document.getElementById('wpSuCacheAvatar').checked;
    105120            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;         
    106123        }
    107124        document.getElementById('wpSuCacheAvatar').onclick = setDisable;
  • wp-switch-util/trunk/lang/wp_su-zh_CN.po

    r1365102 r1652087  
    22msgstr ""
    33"Project-Id-Version: WP Switch Util\n"
    4 "POT-Creation-Date: 2016-03-06 18:11+0900\n"
    5 "PO-Revision-Date: 2016-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"
    66"Last-Translator: \n"
    77"Language-Team: \n"
     
    1111"Content-Transfer-Encoding: 8bit\n"
    1212"Plural-Forms: nplurals=1; plural=0;\n"
    13 "X-Generator: Poedit 1.8.6\n"
     13"X-Generator: Poedit 2.0.1\n"
    1414"X-Poedit-Basepath: ..\n"
    1515"X-Poedit-WPHeader: wp_switch_util.php\n"
     
    2121"X-Poedit-SearchPathExcluded-0: *.js\n"
    2222
    23 #: inc/wp_switch_util_setting.php:10 wp_switch_util.php:72
     23#: inc/wp_switch_util_setting.php:10 wp_switch_util.php:106
    2424msgid "Wp Switch Util"
    2525msgstr ""
     
    6161msgstr "长度:"
    6262
    63 #: inc/wp_switch_util_setting.php:40
     63#: inc/wp_switch_util_setting.php:38
     64msgid "MDB5 Type"
     65msgstr "要转换的类型"
     66
     67#: inc/wp_switch_util_setting.php:41
     68msgid "Post"
     69msgstr "文章"
     70
     71#: inc/wp_switch_util_setting.php:44
     72msgid "Page"
     73msgstr "页面"
     74
     75#: inc/wp_switch_util_setting.php:48
    6476msgid "Disable Change The Word"
    6577msgstr "不转换半角到全角"
    6678
    67 #: inc/wp_switch_util_setting.php:47
     79#: inc/wp_switch_util_setting.php:55
    6880msgid "Disable Auto Save"
    6981msgstr "禁用自动保存"
    7082
    71 #: inc/wp_switch_util_setting.php:54
     83#: inc/wp_switch_util_setting.php:62
    7284msgid "Disable hirstroy"
    7385msgstr "禁用历史版本"
    7486
    75 #: inc/wp_switch_util_setting.php:61
     87#: inc/wp_switch_util_setting.php:69
    7688msgid "Disable pingback in site"
    7789msgstr "禁止站内Pingback"
    7890
    79 #: inc/wp_switch_util_setting.php:68
     91#: inc/wp_switch_util_setting.php:76
    8092msgid "Don't display the admin bar"
    8193msgstr "不显示admin bar"
    8294
    83 #: inc/wp_switch_util_setting.php:75
     95#: inc/wp_switch_util_setting.php:83
    8496msgid "Enable the link manager"
    8597msgstr "启用友情链接"
    8698
    87 #: inc/wp_switch_util_setting.php:82
     99#: inc/wp_switch_util_setting.php:90
    88100msgid "Disable auto p at content"
    89101msgstr "禁用文章自动添加&lt;p&gt;标签"
    90102
    91 #: inc/wp_switch_util_setting.php:89
     103#: inc/wp_switch_util_setting.php:97
    92104msgid "Disable auto p at comment"
    93105msgstr "禁用评论自动添加&lt;p&gt;标签"
    94106
    95 #: inc/wp_switch_util_setting.php:98
     107#: inc/wp_switch_util_setting.php:104
     108msgid "Registered user only"
     109msgstr "仅注册用户可以访问"
     110
     111#: inc/wp_switch_util_setting.php:113
    96112msgid "Save Changes"
    97113msgstr "保存修改"
    98114
    99 #: wp_switch_util.php:82
     115#: wp_switch_util.php:116
    100116msgid "Settings"
    101117msgstr "设置"
     118
     119#: wp_switch_util.php:237
     120msgid ""
     121"Only registered and logged in users are allowed to view this site. Please "
     122"log in now."
     123msgstr "仅注册并登陆后的用户可以访问本站,请登陆。"
    102124
    103125#. Plugin Name of the plugin/theme
  • wp-switch-util/trunk/readme.txt

    r1422163 r1652087  
    2424* Enable the link manager
    2525* Disable auto p
     26* Only registered user access
    2627
    2728这个插件实现了以下功能:
     
    3536* 不显示admin bar
    3637* 启用友情链接
     38* 禁用自动添加<p>标签
     39* 仅登陆用户可访问
    3740
    3841== Installation ==
     
    5861
    5962== Changelog ==
     63
     64= 1.1.0 =
     65
     66* Add feature "Only registered user access"
     67* 添加仅登陆用户可访问功能
    6068
    6169= 0.3.1 =
  • wp-switch-util/trunk/wp_switch_util.php

    r1422163 r1652087  
    55 * Plugin URI: http://yutuo.net/archives/f685d2dbbb176e86.html
    66 * Description: This plugin can: cache the avatar, format you url, disable the histroy, disable auto save, disable admin bar
    7  * Version: 0.3.1
     7 * Version: 1.1.0
    88 * Author: yutuo
    99 * Author URI: http://yutuo.net
     
    2323        'mdb5url' => '0',
    2424        'mdb5length' => '16',
     25        'mdb5typepost' => '1',
     26        'mdb5typepage' => '0',
    2527        'changeword' => '0',
    2628        'autosave' => '0',
     
    3133        'autopcontent' => '0',
    3234        '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',
    3355    );
    3456}
     
    4466
    4567    /** 构造函数 */
    46     function WPSwitchUtil()
     68    function __construct()
    4769    {
    4870        $this->pluginDir = dirname(plugin_basename(__FILE__));
     
    5072        $this->options = get_option(WPSwitchUtilConfig::CONFIG_OPTIONS_KEY);
    5173    }
     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    }
    5283
    5384    /** 启用 */
     
    6293        delete_option(WPSwitchUtilConfig::CONFIG_OPTIONS_KEY);
    6394    }
     95
    6496
    6597    /** 初始化 */
     
    125157    {
    126158        $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        }
    134173    }
    135174
     
    172211        return false;
    173212    }
    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   
    175240    /** 应用插件 */
    176241    function apply()
     
    191256        }
    192257        // 头像缓存
    193         if (array_key_exists('cacheavatar', $this->options) && $this->options['cacheavatar'] == '1') {
     258        if ($this->getOption('cacheavatar') == '1') {
    194259            add_filter('get_avatar', array($this, 'cacheAvatar'), 10, 4);
    195260        }
    196261        // MDB5的URL
    197         if (array_key_exists('mdb5url', $this->options) && $this->options['mdb5url'] == '1') {
     262        if ($this->getOption('mdb5url') == '1') {
    198263            add_filter('name_save_pre', array($this, 'mdb5Url'));
    199264        }
    200265        // 不转换半角到全角
    201         if (array_key_exists('changeword', $this->options) && $this->options['changeword'] == '1') {
     266        if ($this->getOption('changeword') == '1') {
    202267            $this->changeWord();
    203268        }
    204269        // 禁止自动保存
    205         if (array_key_exists('autosave', $this->options) && $this->options['autosave'] == '1') {
     270        if ($this->getOption('autosave') == '1') {
    206271            add_action('wp_print_scripts', array($this, 'disableAutoSave'));
    207272        }
    208273        // 禁止历史版本
    209         if (array_key_exists('hirstroy', $this->options) && $this->options['hirstroy'] == '1') {
     274        if ($this->getOption('hirstroy') == '1') {
    210275            remove_action('post_updated', 'wp_save_post_revision');
    211276        }
    212277        // 阻止站内文章Pingback
    213         if (array_key_exists('pingback', $this->options) && $this->options['pingback'] == '1') {
     278        if ($this->getOption('pingback') == '1') {
    214279            add_action('pre_ping', array($this, 'disablePingbackSelf'));
    215280        }
    216281        // 不显示AdminBar
    217         if (array_key_exists('adminbar', $this->options) && $this->options['adminbar'] == '1') {
     282        if ($this->getOption('adminbar') == '1') {
    218283            add_filter('show_admin_bar', array($this, 'hideAdminBar'));
    219284        }
    220285        // 启用友情链接
    221         if (array_key_exists('linkmanager', $this->options) && $this->options['linkmanager'] == '1') {
     286        if ($this->getOption('linkmanager') == '1') {
    222287            add_filter('pre_option_link_manager_enabled', '__return_true');
    223288        }
    224         // 禁用文章自动添加<p>
    225         if (array_key_exists('autopcontent', $this->options) && $this->options['autopcontent'] == '1') {
     289        // 禁用文章自动添加
     290        if ($this->getOption('autopcontent') == '1') {
    226291            remove_filter('the_content', 'wpautop');
    227292        }
    228         // 禁用评论自动添加<p>
    229         if (array_key_exists('autopcomment', $this->options) && $this->options['autopcomment'] == '1') {
     293        // 禁用评论自动添加
     294        if ($this->getOption('autopcomment') == '1') {
    230295            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'));
    231301        }
    232302    }
Note: See TracChangeset for help on using the changeset viewer.