Plugin Directory

Changeset 978380


Ignore:
Timestamp:
09/04/2014 05:24:47 AM (12 years ago)
Author:
Webnist
Message:

version 0.3 Adding basic authentication.

Location:
ichigen-san/trunk
Files:
3 added
4 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • ichigen-san/trunk/ichigen-san.php

    r603714 r978380  
    22/*
    33Plugin Name: Ichigen San
    4 Plugin URI: http://plugins.webnist.jp
    5 Description:
     4Plugin URI: http://wordpress.org/plugins/ichigen-san/
     5Description: Because you can not be viewed unless you log When you activate this plug-in, You can start a private blog. Furthermore, you can also be used for communication between the acquaintance.
    66Author: Webnist
    7 Version: 0.1
    8 Author URI: http://webni.st
     7Version: 0.3
     8Author URI: http://profiles.wordpress.org/webnist
     9License: GPLv2 or later
     10Text Domain: ichigen-san
     11Domain Path: /languages/
    912*/
    10 
    11 if ( !defined( 'ICHIGEN_SAN_DOMAIN' ) )
    12     define( 'ICHIGEN_SAN_DOMAIN', 'ichigen-san' );
    1313
    1414if ( !defined( 'ICHIGEN_SAN_PLUGIN_URL' ) )
     
    1818    define( 'ICHIGEN_SAN_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . dirname( plugin_basename( __FILE__ ) ) );
    1919
    20 new Ichigen_San();
    21 
    22 class Ichigen_San {
    23 
    24     private $version = '0.1';
    25     private $base_dir;
    26     private $plugin_dir;
    27     private $plugin_url;
    28     private $menu_slug = 'ichigen-san';
     20class IchigenSan {
    2921
    3022    public function __construct() {
    31         $this->base_dir = dirname( plugin_basename( __FILE__ ) );
    32         $this->plugin_dir = WP_PLUGIN_DIR . '/' . $this->base_dir;
    33         $this->plugin_url = WP_PLUGIN_URL . '/' . $this->base_dir;
    34         $this->menu_slug = 'ichigen-san';
    35 
    36         load_plugin_textdomain( ICHIGEN_SAN_DOMAIN, false, $this->base_dir . '/languages/' );
    37         add_action( 'template_redirect', array( &$this, 'redirect_ichigen_san' ) );
     23        $data = get_file_data(
     24            __FILE__,
     25            array(
     26                'ver'    => 'Version',
     27                'domain' => 'Text Domain',
     28                'langs'  => 'Domain Path'
     29            )
     30        );
     31
     32        $this->plugin_basename = dirname( plugin_basename(__FILE__) );
     33        $this->version         = $data['ver'];
     34        $this->domain          = $data['domain'];
     35        $this->langs           = $data['langs'];
     36        $this->enabling        = get_option( 'ichigen_san_enabling', 0 );
     37        $this->basic_user      = get_option( 'ichigen_san_basic_user' );
     38        $this->basic_pass      = get_option( 'ichigen_san_basic_pass' );
     39
     40        load_plugin_textdomain( $this->domain, false, $this->plugin_basename . $this->langs );
     41        add_action( 'template_redirect', array( &$this, 'template_redirect' ) );
    3842        if ( is_admin() ) {
    3943            add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
    40             add_action( 'admin_print_styles', array( &$this, 'admin_styles' ) );
    41             //add_action( 'admin_enqueue_scripts', array( &$this, 'admin_javascript' ) );
    4244            add_action( 'admin_init', array( &$this, 'add_general_custom_fields' ) );
    4345            add_filter( 'admin_init', array( &$this, 'add_custom_whitelist_options_fields' ) );
     46            add_action( 'admin_print_scripts-settings_page_' . $this->plugin_basename, array( &$this, 'admin_print_scripts' ) );
    4447        }
    4548    }
    4649
     50    public function admin_print_scripts() {
     51        wp_enqueue_script( 'admin_ichigen_san', ICHIGEN_SAN_PLUGIN_URL . '/js/ichigen-san.js', array( 'jquery' ), $this->version, true );
     52    }
     53
    4754    public function admin_menu() {
    48         add_menu_page( __( 'Set Ichigen San', ICHIGEN_SAN_DOMAIN ), __( 'Set Ichigen San', ICHIGEN_SAN_DOMAIN ), 'add_users', $this->menu_slug, array( &$this, 'add_admin_edit_page' ) );
     55        add_options_page( __( 'Set Ichigen San', $this->domain ), __( 'Set Ichigen San', $this->domain ), 'add_users', $this->plugin_basename, array( &$this, 'add_admin_edit_page' ), ICHIGEN_SAN_PLUGIN_URL . '/images/icon/menu.png' );
    4956    }
    5057
    5158    public function add_admin_edit_page() {
    52         $title = __( 'Set Ichigen San', ICHIGEN_SAN_DOMAIN ); ?>
    53         <div class="wrap">
    54         <?php screen_icon(); ?>
    55         <h2><?php echo esc_html( $title ); ?></h2>
    56         <form method="post" action="options.php">
    57         <?php settings_fields( $this->menu_slug ); ?>
    58         <?php do_settings_sections( $this->menu_slug ); ?>
    59         <table class="form-table">
    60         <?php do_settings_fields( $this->menu_slug, 'default' ); ?>
    61         </table>
    62         <?php submit_button(); ?>
    63         </form>
    64         </div>
    65     <?php }
     59        $title = __( 'Set Ichigen San', $this->domain );
     60        echo '<div class="wrap">' . "\n";
     61        screen_icon();
     62        echo '<h2>' . esc_html( $title ) . '</h2>' . "\n";
     63        echo '<form method="post" action="options.php">' . "\n";
     64        settings_fields( $this->plugin_basename  );
     65        do_settings_sections( $this->plugin_basename  );
     66        submit_button();
     67        echo '<h2>' . esc_html__( 'Setting initialization', $this->domain ) . '</h2>' . "\n";
     68        submit_button( __( 'Initialization', $this->domain ), 'primary', 'ichigen-san-initialization' );
     69        echo '</form>' . "\n";
     70        echo '</div>' . "\n";
     71    }
    6672
    6773    public function add_general_custom_fields() {
    68         add_settings_field( 'enabling', __( 'Enabling Ichogen San', ICHIGEN_SAN_DOMAIN ), array( &$this, 'enabling_field' ), $this->menu_slug, 'default' );
    69     }
    70 
    71     public function enabling_field( $args ) {
    72         extract( $args );
    73         $value = get_option( 'ichigen_san_enabling' );
    74 ?>
    75         <label><input type="checkbox" name="ichigen_san_enabling" value="1" id="ichigen_san_enabling"<?php checked( 1, $value ); ?> /><?php _e( 'Enabling', ICHIGEN_SAN_DOMAIN ); ?></label>
    76     <?php
     74        global $wp_version;
     75
     76        add_settings_section(
     77            'general',
     78            __( 'General', $this->domain ),
     79            '',
     80            $this->domain
     81        );
     82        add_settings_field(
     83            'enabling',
     84            __( 'Enabling Ichogen San', $this->domain ),
     85            array( &$this, 'select_field' ),
     86            $this->plugin_basename ,
     87            'general',
     88            array(
     89                'name'   => 'ichigen_san_enabling',
     90                'value'  => $this->enabling,
     91                'option' => array(
     92                    __( 'Disabled', $this->domain ) => 0,
     93                    __( 'Login screen', $this->domain ) => 1,
     94                    __( 'Basic authentication', $this->domain ) => 2,
     95                ),
     96            )
     97        );
     98        add_settings_field(
     99            'basic-user',
     100            __( 'Basic User', $this->domain ),
     101            array( &$this, 'text_field' ),
     102            $this->plugin_basename ,
     103            'general',
     104            array(
     105                'name'  => 'ichigen_san_basic_user',
     106                'value' => $this->basic_user,
     107            )
     108        );
     109        add_settings_field(
     110            'basic-pass',
     111            __( 'Basic Password', $this->domain ),
     112            array( &$this, 'text_field' ),
     113            $this->plugin_basename ,
     114            'general',
     115            array(
     116                'name'  => 'ichigen_san_basic_pass',
     117                'value' => $this->basic_pass,
     118                'type'  => 'password',
     119            )
     120        );
     121    }
     122    public function text_field( $args ) {
     123        extract( $args );
     124        $desc   = ! empty( $desc ) ? $desc : '';
     125        $type   = empty( $type ) ? 'text' : esc_attr( $type );
     126        $value  = ( 'password' == $type ) ? '' : $value;
     127        $output = '<input type="' . $type . '" name="' . $name .'" id="' . $name .'" value="' . $value .'" />' . "\n";
     128        if ( $desc )
     129            $output .= '<p class="description">' . $desc . '</p>' . "\n";
     130
     131        echo $output;
     132    }
     133
     134    public function textarea_field( $args ) {
     135        extract( $args );
     136        $desc   = ! empty( $desc ) ? $desc : '';
     137        $output = '<textarea name="' . $name .'" rows="10" cols="50" id="' . $name .'" class="large-text code">' . $value . '</textarea>' . "\n";
     138        if ( $desc )
     139            $output .= '<p class="description">' . $desc . '</p>' . "\n";
     140        echo $output;
     141    }
     142
     143    public function check_field( $args ) {
     144        extract( $args );
     145        $desc   = ! empty( $desc ) ? $desc : '';
     146        $output = '<label for="' . $name . '">' . "\n";
     147        $output = '<input name="' . $name . '" type="checkbox" id="' . $name . '" value="1"' . checked( $value, 1, false ) . '>' . "\n";
     148        if ( $desc )
     149            $output .= $desc . "\n";
     150        $output  .= '</label>' . "\n";
     151
     152        echo $output;
     153    }
     154
     155    public function select_field( $args ) {
     156        extract( $args );
     157        $desc   = ! empty( $desc ) ? $desc : '';
     158        $output = '<select name="' . $name . '" id="' . $name . '">' . "\n";
     159            foreach ( $option as $key => $val ) {
     160                $output .= '<option value="' . $val . '"' . selected( $value, $val, false ) . '>' . $key . '</option>' . "\n";
     161            }
     162        $output .= '</select>' . "\n";
     163            if ( $desc )
     164            $output .= $desc . "\n";
     165
     166        echo $output;
    77167    }
    78168
    79169    public function add_custom_whitelist_options_fields() {
    80         register_setting( $this->menu_slug, 'ichigen_san_enabling' );
    81     }
    82 
    83     public function admin_styles() {
    84         wp_enqueue_style( 'admin_ichigen_san_style', $this->plugin_url . '/css/admin-style.css' );
    85     }
    86 
    87     public function redirect_ichigen_san() {
    88         if ( !is_user_logged_in() && get_option( 'ichigen_san_enabling' ) ) {
     170        register_setting( $this->plugin_basename , 'ichigen_san_enabling', 'intval' );
     171        register_setting( $this->plugin_basename , 'ichigen_san_basic_user', 'esc_attr' );
     172        register_setting( $this->plugin_basename , 'ichigen_san_basic_pass', array( &$this, 'register_setting_basic_pass_check' ) );
     173        register_setting( $this->plugin_basename , 'ichigen-san-convert', array( &$this, 'register_setting_convert' ) );
     174        register_setting( $this->plugin_basename , 'ichigen-san-initialization', array( &$this, 'register_setting_initialization' ) );
     175    }
     176
     177    public function register_setting_basic_pass_check( $value ) {
     178        if ( empty( $value ) && ! empty( $this->basic_pass ) ) {
     179            $value = $this->basic_pass;
     180        } else {
     181            $value = wp_hash_password( $value );
     182        }
     183
     184        return $value;
     185    }
     186
     187    public function register_setting_initialization( $value ) {
     188        if ( __( 'Initialization', $this->domain ) != $value )
     189            return $value;
     190
     191        delete_option( 'ichigen_san_enabling' );
     192        delete_option( 'ichigen_san_basic_user' );
     193        delete_option( 'ichigen_san_basic_pass' );
     194        return $value;
     195    }
     196
     197    public function template_redirect() {
     198        if ( !is_user_logged_in() && $this->enabling == 1 ) {
    89199            auth_redirect();
     200        } elseif ( !is_user_logged_in() && $this->enabling == 2 ) {
     201            nocache_headers();
     202            // Check the BASIC authentication user and password
     203            $user = isset($_SERVER["PHP_AUTH_USER"]) ? $_SERVER["PHP_AUTH_USER"] : '';
     204            $pwd  = isset($_SERVER["PHP_AUTH_PW"]) ? $_SERVER["PHP_AUTH_PW"] : '';
     205            if ( $this->basic_user && $this->basic_pass ) {
     206                if ( $user == $this->basic_user && wp_check_password( $pwd, $this->basic_pass ) ) {
     207                    return;
     208                }
     209            }
     210            // Check the user/password for WordPress
     211            if ( !is_wp_error(wp_authenticate($user, $pwd)) ) {
     212                return;
     213            }
     214
     215            // BASIC authentication is required
     216            header('WWW-Authenticate: Basic realm="Please Enter Your Password"');
     217            header('HTTP/1.0 401 Unauthorized');
     218            echo 'Authorization Required';
     219            die();
     220        } else {
     221            return;
    90222        }
    91223    }
    92 
    93224}
     225new IchigenSan();
  • ichigen-san/trunk/languages/ichigen-san-ja.po

    r607358 r978380  
     1# Copyright (C) 2014 Ichigen San
     2# This file is distributed under the same license as the Ichigen San package.
    13msgid ""
    24msgstr ""
    3 "Project-Id-Version: Ichigen San\n"
    4 "Report-Msgid-Bugs-To: \n"
    5 "POT-Creation-Date: 2012-09-11 19:29+0900\n"
    6 "PO-Revision-Date: 2012-09-11 19:29+0900\n"
    7 "Last-Translator: Webnist <webnist@webnist.org>\n"
    8 "Language-Team: Webnist <webnist@webnist.org>\n"
     5"Project-Id-Version: Ichigen San 0.3\n"
     6"Report-Msgid-Bugs-To: http://wordpress.org/tag/ichigen-san\n"
     7"POT-Creation-Date: 2014-09-04 04:23:43+00:00\n"
    98"MIME-Version: 1.0\n"
    109"Content-Type: text/plain; charset=UTF-8\n"
    1110"Content-Transfer-Encoding: 8bit\n"
    12 "X-Poedit-KeywordsList: __;_e\n"
    13 "X-Poedit-Basepath: ../\n"
     11"PO-Revision-Date: 2014-09-04 13:26+0900\n"
     12"Last-Translator: Webnist <webnist@webnist.org>\n"
     13"Language-Team: LANGUAGE <LL@li.org>\n"
     14"X-Generator: Poedit 1.6.3\n"
    1415"Plural-Forms: nplurals=1; plural=0;\n"
    15 "X-Poedit-SourceCharset: UTF-8\n"
    16 "X-Poedit-SearchPath-0: .\n"
     16"Language: ja\n"
    1717
    18 #: ichigen-san.php:48 ichigen-san.php:52
     18#: ichigen-san.php:55 ichigen-san.php:59
    1919msgid "Set Ichigen San"
    2020msgstr "一見さん設定"
    2121
    22 #: ichigen-san.php:68
     22#: ichigen-san.php:67
     23msgid "Setting initialization"
     24msgstr "設定の初期化"
     25
     26#: ichigen-san.php:68 ichigen-san.php:188
     27msgid "Initialization"
     28msgstr "初期化"
     29
     30#: ichigen-san.php:78
     31msgid "General"
     32msgstr "一般設定"
     33
     34#: ichigen-san.php:84
    2335msgid "Enabling Ichogen San"
    24 msgstr "一見さんを有効化する"
     36msgstr "一見さんの有効設定"
    2537
    26 #: ichigen-san.php:75
    27 msgid "Enabling"
    28 msgstr "有効化"
     38#: ichigen-san.php:92
     39msgid "Disabled"
     40msgstr ""
     41
     42#: ichigen-san.php:93
     43msgid "Login screen"
     44msgstr ""
     45
     46#: ichigen-san.php:94
     47msgid "Basic authentication"
     48msgstr ""
     49
     50#: ichigen-san.php:100
     51msgid "Basic User"
     52msgstr ""
     53
     54#: ichigen-san.php:111
     55msgid "Basic Password"
     56msgstr ""
     57
     58#. Plugin Name of the plugin/theme
     59msgid "Ichigen San"
     60msgstr ""
     61
     62#. Plugin URI of the plugin/theme
     63msgid "http://wordpress.org/plugins/ichigen-san/"
     64msgstr "http://wordpress.org/plugins/ichigen-san/"
     65
     66#. Description of the plugin/theme
     67msgid ""
     68"Because you can not be viewed unless you log When you activate this plug-in, "
     69"You can start a private blog. Furthermore, you can also be used for "
     70"communication between the acquaintance."
     71msgstr ""
     72"このプラグインを有効化するとログインしなければ閲覧することが出来ないため、プ"
     73"ライベートなブログを開始できます。また、知り合い同士のコミュニケーションの為"
     74"に使用することもできます。"
     75
     76#. Author of the plugin/theme
     77msgid "Webnist"
     78msgstr "Webnist"
     79
     80#. Author URI of the plugin/theme
     81msgid "http://profiles.wordpress.org/webnist"
     82msgstr "http://profiles.wordpress.org/webnist"
  • ichigen-san/trunk/readme-ja.txt

    r603714 r978380  
    1 === Plugin Name ===
     1=== Ichigen San ===
    22Contributors: Webnist, megumithemes
    3 Donate link: 
     3Donate link:
    44Tags: Private, Maintenance
    55Requires at least: 3.4
    6 Tested up to: 3.4
    7 Stable tag: 0.1
     6Tested up to: 3.9.2
     7Stable tag: 0.3
     8License: GPLv2 or later
    89
    9 プラーベート用やメンテナンス用
     10プラーベート用
    1011
    1112== Description ==
     
    1718このプラグインを使用すれば煩わしい、BASIC認証ともさよならできます。
    1819
     20ごめんなさい、今回のバージョンで BASIC認証をサポートしました。
     21
    1922プラグインの由来について。
    2023日本には”Ichigen-San Okotowari”という文化があります。
     
    25282. プラグインメニューより有効化。
    2629
     30== Upgrade Notice ==
     31BASIC認証を選択できるようになりました。
     32
     33== Changelog ==
     34
     35= 0.3 =
     36* BASIC認証を選択できるようになりました。
     37* オプションページを、設定の中に移動
     38
     39= 0.1 =
     40* 最初のバージョン
  • ichigen-san/trunk/readme.txt

    r603714 r978380  
    1 === Plugin Name ===
     1=== Ichigen San ===
    22Contributors: Webnist, megumithemes
    3 Donate link: 
     3Donate link:
    44Tags: Private, Maintenance
    55Requires at least: 3.4
    6 Tested up to: 3.4
    7 Stable tag: 0.1
     6Tested up to: 3.9.2
     7Stable tag: 0.3
     8License: GPLv2 or later
    89
    9 Private publishing and maintenance
     10Private publishing
    1011
    1112== Description ==
     
    1718Troublesome if you use this plugin, you can also authenticate goodbye BASIC.
    1819
     20Sorry, this version was support BASIC authentication.
     21
    1922About the origin of the plug-in.
    2023There is a culture of "Ichigen-San Okotowari" in Japan.
     
    2225
    2326== Installation ==
    24 1. Upload the entire `ichigen-san` folder to the `/wp-content/plugins/` directory.
    25 2. Activate the plugin through the 'Plugins' menu in WordPress.
     27A plug-in installation screen is displayed on the WordPress admin panel.
     28It installs it in `wp-content/plugins`.
     29The plug-in is made effective.
     30Open \'Settings\' -> \'Set Ichigen San\' menu.
    2631
     32== Upgrade Notice ==
     33Adding basic authentication.
     34
     35== Changelog ==
     36
     37= 0.3 =
     38* Adding basic authentication.
     39* Go to Settings menu options page
     40
     41= 0.1 =
     42* First version
Note: See TracChangeset for help on using the changeset viewer.