Plugin Directory

Changeset 1354181


Ignore:
Timestamp:
02/19/2016 02:39:21 PM (10 years ago)
Author:
yutuo
Message:

0.1.0

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

Legend:

Unmodified
Added
Removed
  • wp-switch-util/trunk

    • Property svn:ignore
      •  

        old new  
        11.git
         2.idea
  • wp-switch-util/trunk/README.md

    r1352649 r1354181  
    2727#### Installation
    2828
     29**Installation**
     30
    29311. Upload the plugin files to the `/wp-content/plugins/wp-switch-util` directory, or install the plugin through the WordPress plugins screen directly.
    30322. Activate the plugin through the 'Plugins' screen in WordPress
    31333. Use the Settings->Wp Switch Util screen to configure the plugin
    3234
    33 --
     35**安装方法**
    3436
    35371. 上传本插件文件到`/wp-content/plugins/wp-switch-util`目录,或者通过Wordpress插件安装画面自动安装。
     
    4042#### Changelog
    4143
    42 = 0.0.3 =
     44**0.1.0**
     45
     46* Fixed the bug that can't disable revision.
     47* 解决版本更新的问题
     48
     49**0.0.3**
    4350
    4451* Fixed the bug that can't disable auto save.
    45 
    46 --
    47 
    4852* 解决自动保存的BUG
    4953
    50 = 0.0.2 =
     54**0.0.2**
    5155
    5256* Upgrade the bug that the plugin can't cache avatar on HTTPS protocol.
    5357* Change the folder that avatar is cached to `/cache/avatar`.
    54 
    55 --
    56 
    5758* 解决HTTPS协议下不能缓存头像的问题。
    5859* 修改缓存头像目录到`/cache/avatar`。
    5960
    60 = 0.0.1 =
     61**0.0.1**
    6162
    6263* New.
  • wp-switch-util/trunk/readme.txt

    r1352649 r1354181  
    2222* Disable pingback in site
    2323* Disable the admin bar
    24 
    25 ------------------------
    2624
    2725这个插件实现了以下功能:
     
    5856== Changelog ==
    5957
     58= 0.1.0 =
     59
     60* Fixed the bug that can't disable revision.
     61* 解决版本更新的问题
     62
    6063= 0.0.3 =
    6164
    6265* Fixed the bug that can't disable auto save.
    63 
    64 --
    65 
    6666* 解决自动保存的BUG
    6767
     
    7070* Upgrade the bug that the plugin can't cache avatar on HTTPS protocol.
    7171* Change the folder that avatar is cached to `/cache/avatar`.
    72 
    73 --
    74 
    7572* 解决HTTPS协议下不能缓存头像的问题。
    7673* 修改缓存头像目录到`/cache/avatar`。
  • wp-switch-util/trunk/wp_switch_util.php

    r1352649 r1354181  
    11<?php
     2
    23/**
    3 Plugin Name: WP Switch Util
    4 Plugin URI: http://yutuo.net/archives/f685d2dbbb176e86.html
    5 Description: This plugin can: cache the avatar, format you url, disable the histroy, disable auto save, disable admin bar
    6 Version: 0.0.3
    7 Author: yutuo
    8 Author URI: http://yutuo.net
    9 Text Domain: wp_su
    10 Domain Path: /wp-switch-util
    11 License: GPL v3 - http://www.gnu.org/licenses/gpl.html
    12 */
    13 class WPSwitchUtilConfig {
     4 * Plugin Name: WP Switch Util
     5 * Plugin URI: http://yutuo.net/archives/f685d2dbbb176e86.html
     6 * Description: This plugin can: cache the avatar, format you url, disable the histroy, disable auto save, disable admin bar
     7 * Version: 0.1.0
     8 * Author: yutuo
     9 * Author URI: http://yutuo.net
     10 * Text Domain: wp_su
     11 * Domain Path: /wp-switch-util
     12 * License: GPL v3 - http://www.gnu.org/licenses/gpl.html
     13 */
     14class WPSwitchUtilConfig
     15{
    1416    /** 保存的KEY */
    1517    const CONFIG_OPTIONS_KEY = 'wp_su_options';
    1618
    1719    /** 默认设置 */
    18     static $DEFAULT_OPTION = array (
    19             'cacheavatar' => '0',
    20             'cacheday' => '15',
    21             'mdb5url' => '0',
    22             'mdb5length' => '16',   
    23             'changeword' => '0',
    24             'autosave' => '0',
    25             'hirstroy' => '0',
    26             'pingback' => '0',
    27             'adminbar' => '0',
     20    static $DEFAULT_OPTION = array(
     21        'cacheavatar' => '0',
     22        'cacheday' => '15',
     23        'mdb5url' => '0',
     24        'mdb5length' => '16',
     25        'changeword' => '0',
     26        'autosave' => '0',
     27        'hirstroy' => '0',
     28        'pingback' => '0',
     29        'adminbar' => '0',
    2830    );
    2931}
    3032
    31 class WPSwitchUtil {
     33class WPSwitchUtil
     34{
    3235    /** 本Plugin文件夹实际目录 */
    3336    var $pluginDir;
     
    3639    /** 设置 */
    3740    var $options;
     41
    3842    /** 构造函数 */
    39     function WPSwitchUtil() {
     43    function WPSwitchUtil()
     44    {
    4045        $this->pluginDir = dirname(plugin_basename(__FILE__));
    4146        $this->currentUrl = get_option('siteurl') . '/wp-content/plugins/' . basename(dirname(__FILE__));
    4247        $this->options = get_option(WPSwitchUtilConfig::CONFIG_OPTIONS_KEY);
    4348    }
     49
    4450    /** 启用 */
    45     function activate() {
     51    function activate()
     52    {
    4653        update_option(WPSwitchUtilConfig::CONFIG_OPTIONS_KEY, WPSwitchUtilConfig::$DEFAULT_OPTION);
    4754    }
     55
    4856    /** 停用 */
    49     function deActivate() {
     57    function deActivate()
     58    {
    5059        delete_option(WPSwitchUtilConfig::CONFIG_OPTIONS_KEY);
    5160    }
     61
    5262    /** 初始化 */
    53     function init() {
     63    function init()
     64    {
    5465        load_plugin_textdomain('wp_su', false, $this->pluginDir . '/lang');
    5566    }
     67
    5668    /** 在设置菜单添加链接 */
    57     function menuLink() {
     69    function menuLink()
     70    {
    5871        add_options_page('Wp Switch Util Settings', __('Wp Switch Util', 'wp_su'), 'manage_options', 'wpSwitchUtil',
    59                         array ($this, 'optionPage'));
    60     }
     72            array($this, 'optionPage'));
     73    }
     74
    6175    /** 插件设置链接 */
    62     function actionLink($links, $file) {
     76    function actionLink($links, $file)
     77    {
    6378        if ($file != plugin_basename(__FILE__)) {
    6479            return $links;
     
    6883        return $links;
    6984    }
     85
    7086    /** 插件设置页面 */
    71     function optionPage() {
     87    function optionPage()
     88    {
    7289        $current_path = dirname(__FILE__) . '/inc/wp_switch_util_setting.php';
    7390        include $current_path;
    7491    }
     92
    7593    /** 头像缓存 */
    76     function cacheAvatar($avatar, $id_or_email, $size, $default) {
     94    function cacheAvatar($avatar, $id_or_email, $size, $default)
     95    {
    7796        // URL目录地址
    78         $current_path = content_url() . '/cache/avatar/';   
     97        $current_path = content_url() . '/cache/avatar/';
    7998        // 保存目录
    8099        $out_folder = WP_CONTENT_DIR . '/cache/avatar/';
     
    98117        return $avatar;
    99118    }
     119
    100120    /** MDB5的URL */
    101     function mdb5Url($postname) {
     121    function mdb5Url($postname)
     122    {
    102123        $post_title = $_POST['post_title'];
    103124        $str = mb_convert_encoding($post_title, 'UTF-8');
     
    109130        return $md5_str;
    110131    }
     132
    111133    /** 不转换半角到全角 */
    112     function changeWord() {
     134    function changeWord()
     135    {
    113136        $filters_to_remove = array(
    114137            'comment_author', 'term_name', 'link_name', 'link_description', 'link_notes', 'bloginfo', 'wp_title', 'widget_title',
     
    118141        );
    119142
    120         foreach ($filters_to_remove as $a_filter){
     143        foreach ($filters_to_remove as $a_filter) {
    121144            remove_filter($a_filter, 'wptexturize');
    122145        }
    123146    }
     147
    124148    /** 禁止自动保存 */
    125     function disableAutoSave() {
     149    function disableAutoSave()
     150    {
    126151        wp_deregister_script('autosave');
    127152    }
    128     /** 阻止站内文章Pingback */
    129     function disablePingbackSelf(&$links) {
    130         $home = get_option('home');
    131         foreach ($links as $l => $link) {
    132             if (0 === strpos($link, $home)) {
    133                 unset($links[$l]);
    134             }
    135         }
    136            
    137     }
     153
     154    /** 阻止站内文章Pingback */
     155    function disablePingbackSelf(&$links)
     156    {
     157        $home = get_option('home');
     158        foreach ($links as $l => $link) {
     159            if (0 === strpos($link, $home)) {
     160                unset($links[$l]);
     161            }
     162        }
     163
     164    }
     165
    138166    /** 不显示AdminBar */
    139     function hideAdminBar() {
     167    function hideAdminBar()
     168    {
    140169        return false;
    141170    }
     171
    142172    /** 应用插件 */
    143     function apply() {
     173    function apply()
     174    {
    144175        // 启用
    145         register_activation_hook(__FILE__, array ($this, 'activate'));
     176        register_activation_hook(__FILE__, array($this, 'activate'));
    146177        // 停用
    147         register_deactivation_hook(__FILE__, array ($this, 'deActivate'));
     178        register_deactivation_hook(__FILE__, array($this, 'deActivate'));
    148179        // 初始化
    149         add_action('init', array ($this, 'init'));
     180        add_action('init', array($this, 'init'));
    150181        // 管理页面
    151         add_action('admin_menu', array ($this, 'menuLink'));
     182        add_action('admin_menu', array($this, 'menuLink'));
    152183        // 插件链接
    153         add_action('plugin_action_links', array ($this, 'actionLink'), 10, 2);
     184        add_action('plugin_action_links', array($this, 'actionLink'), 10, 2);
    154185
    155186        if (!is_array($this->options)) {
     
    162193        // MDB5的URL
    163194        if (array_key_exists('mdb5url', $this->options) && $this->options['mdb5url'] == '1') {
    164             add_filter('name_save_pre', array ($this, 'mdb5Url'));
     195            add_filter('name_save_pre', array($this, 'mdb5Url'));
    165196        }
    166197        // 不转换半角到全角
     
    170201        // 禁止自动保存
    171202        if (array_key_exists('autosave', $this->options) && $this->options['autosave'] == '1') {
    172             add_action('wp_print_scripts', array ($this, 'disableAutoSave'));
     203            add_action('wp_print_scripts', array($this, 'disableAutoSave'));
    173204        }
    174205        // 禁止历史版本
    175206        if (array_key_exists('hirstroy', $this->options) && $this->options['hirstroy'] == '1') {
    176             remove_action('pre_post_update', 'wp_save_post_revision');
     207            remove_action('post_updated', 'wp_save_post_revision');
    177208        }
    178209        // 阻止站内文章Pingback
    179         if (array_key_exists('pingback', $this->options) && $this->options['pingback'] == '1') {
    180             add_action('pre_ping', array ($this, 'disablePingbackSelf'));   
     210        if (array_key_exists('pingback', $this->options) && $this->options['pingback'] == '1') {
     211            add_action('pre_ping', array($this, 'disablePingbackSelf'));
    181212        }
    182213        // 不显示AdminBar
    183214        if (array_key_exists('adminbar', $this->options) && $this->options['adminbar'] == '1') {
    184             add_filter('show_admin_bar', array ($this, 'hideAdminBar'));
    185         }
    186     }
    187 
    188     function getImageFilesToDisk($url, $out_folder, $save_day) {
     215            add_filter('show_admin_bar', array($this, 'hideAdminBar'));
     216        }
     217    }
     218
     219    function getImageFilesToDisk($url, $out_folder, $save_day)
     220    {
    189221        $url = str_replace('&amp;', '&', $url);
    190222        // 图片文件名取得 
     
    192224            return '';
    193225        }
    194        
     226
    195227        $pre_file_name = $match[1];
    196228        $size = $match[2];
    197229        $level = $match[3];
    198         $file_name = $pre_file_name . '.png';       
     230        $file_name = $pre_file_name . '.png';
    199231        $out_folder = $out_folder . $size . '/';
    200232        if (!file_exists($out_folder)) {
     
    217249    }
    218250
    219     function getDftImageFilesToDisk($out_folder, $size) {
     251    function getDftImageFilesToDisk($out_folder, $size)
     252    {
    220253        $url = "http://www.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=${size}&d=monsterid&r=G";
    221254        $file_name = 'ad516503a11cd5ca435acc9bb6523536.png';
     
    234267    }
    235268
    236     function curl_file_get_contents($durl) {
     269    function curl_file_get_contents($durl)
     270    {
    237271        $ch = curl_init();
    238272        curl_setopt($ch, CURLOPT_URL, $durl);
    239273        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
    240274        curl_setopt($ch, CURLOPT_USERAGENT, _USERAGENT_);
    241         curl_setopt($ch, CURLOPT_REFERER,_REFERER_);
     275        curl_setopt($ch, CURLOPT_REFERER, _REFERER_);
    242276        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    243277        $r = curl_exec($ch);
Note: See TracChangeset for help on using the changeset viewer.