Plugin Directory

Changeset 2778948


Ignore:
Timestamp:
09/01/2022 04:48:33 PM (4 years ago)
Author:
outerbridge
Message:

Various fixes. Tested and stable up to WP6.0

Location:
password-generator/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • password-generator/trunk/outerbridge-password-generator.php

    r1663097 r2778948  
    22/*
    33Plugin Name: Password Generator
    4 Plugin URI: http2://outerbridge.co.uk/
     4Plugin URI: https://outerbridge.co.uk/
    55Description: Password Generator is a plugin written by Outerbridge which adds a widget to WordPress which generates various length random passwords (with or without special characters).
    66Author: Outerbridge
    7 Version: 1.6
     7Version: 1.7
    88Author URI: https://outerbridge.co.uk/
    99Tags: password generator, special characters, strong password
     
    1414/**
    1515 *
     16 * v1.7 220901 Various fixes. Tested and stable up to WP6.0
     17 *
    1618 * v1.6 170523 Made translatable
    17  *
    1819 * v1.5 170503 Updated to remove old style constructor and general tidy up
    1920 * v1.4 150818 Updated WP_Widget functionality for WP4.3
     
    2627 */
    2728
    28 class obr_password_generator extends WP_Widget{
     29class obr_password_generator extends WP_Widget {
    2930    // version
    30     public $obr_password_generator = '1.6';
     31    public $obr_password_generator = '1.7';
    3132   
    3233    //contructor
    33     function __construct(){
    34         parent::__construct('obr_pass_gen', __('Outerbridge Password Generator', 'password-generator'), array('classname' => 'oouterbridge_pass_gen_widget', 'description' => __('Create strong passwords quickly and easily using this widget.  Various password lengths available as well as the option to use symbols as well as alphanumerics.', 'password-generator')));
    35         register_activation_hook(__FILE__, array($this, 'obr_install'));       
    36         register_deactivation_hook(__FILE__, array($this, 'obr_uninstall'));       
    37         add_action('wp_loaded', array($this, 'obr_plugin_update_check'));
    38         add_action('wp_head', array($this, 'obr_header'));
     34    function __construct() {
     35        parent::__construct( 'obr_pass_gen', __( 'Outerbridge Password Generator', 'password-generator' ), array( 'classname' => 'oouterbridge_pass_gen_widget', 'description' => __( 'Create strong passwords quickly and easily using this widget.  Various password lengths available as well as the option to use symbols as well as alphanumerics.', 'password-generator' ) ) );
     36        register_activation_hook( __FILE__, array( $this, 'obr_install' ) );       
     37        register_deactivation_hook( __FILE__, array( $this, 'obr_uninstall' ) );       
     38        add_action( 'wp_loaded', array( $this, 'obr_plugin_update_check' ) );
     39        add_action( 'wp_head', array( $this, 'obr_header' ) );
    3940    }
    4041   
    4142    // functions
    42     function widget($args, $instance){
    43         extract($args);
    44         $title = apply_filters('widget_title', $instance['title']);
     43    function widget( $args, $instance ) {
     44        extract( $args );
     45        $title = '';
     46        if ( isset( $instance[ 'title' ] ) ) {
     47            $title = apply_filters( 'widget_title', $instance[ 'title' ] );
     48        }
    4549        echo $before_widget;
    46         if ($title){
    47             echo $before_title,$title,$after_title;
     50        if ( strlen( $title ) > 0 ) {
     51            echo $before_title, $title, $after_title;
    4852        } else {
    49             echo $before_title,__('Password Generator', 'password-generator'),$after_title;
    50         }
    51         if (isset($_POST['pg_length'])){
     53            echo $before_title, __( 'Password Generator', 'password-generator' ), $after_title;
     54        }
     55        if ( isset( $_POST[ 'pg_length' ] ) ) {
    5256            $formposted = true;
    53             $pg_length = strip_tags(stripslashes($_POST['pg_length']));
    54             if ($pg_length > 20 || $pg_length < 8){
     57            $pg_length = strip_tags( stripslashes( $_POST[ 'pg_length' ] ) );
     58            if ( $pg_length > 20 || $pg_length < 8 ) {
    5559                $pg_length = 14;
    5660            }
    5761            $chk_symbols = '';
    58             if (isset($_POST['chk_symbols'])){
    59                 $chk_symbols = strip_tags(stripslashes($_POST['chk_symbols']));
     62            if ( isset( $_POST[ 'chk_symbols' ] ) ) {
     63                $chk_symbols = strip_tags( stripslashes( $_POST[ 'chk_symbols' ] ) );
    6064            }
    6165        } else {
     
    6569        }
    6670        echo '<form action="';
    67         $path = $_SERVER['REQUEST_URI'];
    68         if (strlen($path)){
     71        $path = $_SERVER[ 'REQUEST_URI' ];
     72        if ( strlen( $path ) ) {
    6973            echo $path;
    7074        } else {
     
    7377        echo '" method="POST">';
    7478        echo '<ul><li>';
    75         _e('Password length?', 'password-generator');
     79        _e( 'Password length?', 'password-generator' );
    7680        echo '<select name="pg_length" title="';
    77         _e('Password length?', 'password-generator');
     81        _e( 'Password length?', 'password-generator' );
    7882        echo '"><optgroup label="';
    79         _e('Recommended Lengths', 'password-generator');
     83        _e( 'Recommended Lengths', 'password-generator' );
    8084        echo '">';
    81         for ($i = 14; $i <= 20; $i++){
     85        for ( $i = 14; $i <= 20; $i++ ) {
    8286            echo '<option';
    83             if ($i == $pg_length){
     87            if ( $i == $pg_length ) {
    8488                echo ' selected="selected"';
    8589            }
    86             echo ' value="',$i,'">',$i,'</option>';
     90            echo ' value="', $i, '">', $i, '</option>';
    8791        }
    8892        echo '</optgroup>';
    8993        echo '<optgroup label="';
    90         _e('Shorter Lengths', 'password-generator');
     94        _e( 'Shorter Lengths', 'password-generator' );
    9195        echo '">';
    92         for ($i = 8; $i <= 13; $i++){
     96        for ( $i = 8; $i <= 13; $i++ ) {
    9397            echo '<option';
    94             if ($i == $pg_length){
     98            if ( $i == $pg_length ) {
    9599                echo ' selected="selected"';
    96100            }
    97             echo ' value="',$i,'">',$i,'</option>';
     101            echo ' value="', $i, '">', $i, '</option>';
    98102        }   
    99103        echo '</optgroup></select></li>';
    100104        echo '<li><label for="chk_symbols">';
    101         _e('Include symbols?', 'password-generator');
     105        _e( 'Include symbols?', 'password-generator' );
    102106        echo '</label><input name="chk_symbols"';
    103         if ($chk_symbols){
     107        if ( $chk_symbols ) {
    104108            echo ' checked="checked"';
    105109        }
    106110        echo 'type="checkbox" title="';
    107         _e('Include symbols?', 'password-generator');
     111        _e( 'Include symbols?', 'password-generator' );
    108112        echo '" /></li></ul>';
    109113        echo '<input type="submit" value="';
    110         _e('Generate password', 'password-generator');
     114        _e( 'Generate password', 'password-generator' );
    111115        echo '" name="submit" /><br />';
    112         if ($formposted){
     116        if ( $formposted ) {
    113117            echo '<p>';
    114             printf(__('New Password: %s', 'password-generator'), '<strong>'.$this->obr_generate_password($pg_length, $chk_symbols).'</strong>');
     118            printf( __( 'New Password: %s', 'password-generator' ), '<strong>' . $this->obr_generate_password( $pg_length, $chk_symbols ) . '</strong>' );
    115119            echo '</p>';
    116120        }
     
    119123    }
    120124
    121     function obr_generate_password($length, $symbols){
     125    function obr_generate_password( $length, $symbols ) {
    122126        $random_chars = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    123         if ($symbols){
     127        if ( $symbols ) {
    124128            $random_chars .= "+-=_*!@#$%+-=_*!@#$%+-=_*!@#$%+-=_*!@#$%";
    125129        }
    126130        $getstring = "";
    127131        $password = "";
    128         while(strlen($password) < $length){
    129             $addstring = substr($random_chars, mt_rand(0, strlen($random_chars) - 1), 1);
     132        while( strlen( $password ) < $length ) {
     133            $addstring = substr( $random_chars, mt_rand( 0, strlen( $random_chars ) - 1 ), 1 );
    130134            // Avoid duplicates
    131             if (strlen($getstring) > 0){
    132                 if (!strstr($password, $getstring)){
     135            if ( strlen( $getstring ) > 0 ) {
     136                if ( !strstr( $password, $getstring ) ) {
    133137                    //append to the password
    134138                    $password .= $addstring;
     
    143147    function obr_header(){
    144148        echo "\n<!-- ";
    145         printf(__('Using Outerbridge Password Generator.  Find out more at %s', 'password-generator'), 'https://outerbridge.co.uk/');
     149        printf( __( 'Using Outerbridge Password Generator.  Find out more at %s', 'password-generator' ), 'https://outerbridge.co.uk/' );
    146150        echo "-->\n";
    147151    }
    148152
    149     function update($new_instance, $old_instance){
     153    function update( $new_instance, $old_instance ) {
    150154        $instance = $old_instance;
    151         $instance['title'] = strip_tags(stripslashes($new_instance['title']));
     155        $instance[ 'title' ] = strip_tags( stripslashes( $new_instance[ 'title' ] ) );
    152156        return $instance;
    153157    }
    154158   
    155     function form($instance){
    156         $instance = wp_parse_args((array) $instance, array('title'=>'Password Generator'));
    157         $title = htmlspecialchars($instance['title']);
    158         echo '<p style="text-align:right;"><label for="'.$this->get_field_name('title').'">'.__('Title:', 'password-generator').' <input style="width: 250px;" id="'.$this->get_field_id('title').'" name="'.$this->get_field_name('title').'" type="text" value="'.$title.'" /></label></p>';
    159     }
    160 
    161     function obr_install(){
    162         add_option('obr_password_generator', $this->obr_password_generator);
     159    function form( $instance ) {
     160        $instance = wp_parse_args( (array) $instance, array( 'title'=>'Password Generator' ) );
     161        $title = htmlspecialchars( $instance[ 'title' ] );
     162        echo '<p style="text-align:right;"><label for="' . $this->get_field_name( 'title' ) . '">' . __( 'Title:', 'password-generator' ) . ' <input style="width: 250px;" id="' . $this->get_field_id( 'title' ) . '" name="' . $this->get_field_name( 'title' ) . '" type="text" value="' . $title . '" /></label></p>';
     163    }
     164
     165    function obr_install() {
     166        add_option( 'obr_password_generator', $this->obr_password_generator );
    163167        $this->obr_plugin_update_check();
    164168    }
    165169
    166     function obr_uninstall(){
    167         delete_option('obr_password_generator');
    168     }
    169 
    170     function obr_plugin_update_check(){
    171         $installed_ver = get_option('obr_password_generator');
    172         if($installed_ver != $this->obr_password_generator){
     170    function obr_uninstall() {
     171        delete_option( 'obr_password_generator' );
     172    }
     173
     174    function obr_plugin_update_check() {
     175        $installed_ver = get_option( 'obr_password_generator' );
     176        if( $installed_ver != $this->obr_password_generator ) {
    173177            $charset_collate = '';
    174             if (!empty($wpdb->charset)){
     178            if ( !empty( $wpdb->charset ) ) {
    175179                $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
    176180            }
    177             if (!empty($wpdb->collate)){
     181            if ( !empty( $wpdb->collate ) ) {
    178182                $charset_collate .= " COLLATE $wpdb->collate";
    179183            }
    180184            $mysql = "";
    181             require_once(ABSPATH.'wp-admin/includes/upgrade.php');
    182             dbDelta($mysql);
     185            require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
     186            dbDelta( $mysql );
    183187
    184188            echo '<div id="message" class="updated fade"><p><strong>';
    185             printf(__('Outerbridge Password Generator updated to version %s', 'password-generator'), $this->obr_password_generator);
     189            printf( __( 'Outerbridge Password Generator updated to version %s', 'password-generator' ), $this->obr_password_generator );
    186190            echo '</strong></p></div>';
    187             update_option('obr_password_generator', $this->obr_password_generator);
     191            update_option( 'obr_password_generator', $this->obr_password_generator );
    188192        }
    189193    }
    190194}
    191195
    192 function obr_password_generator_init(){
    193     register_widget('obr_password_generator');
     196function obr_password_generator_init() {
     197    register_widget( 'obr_password_generator' );
    194198}
    195 add_action('widgets_init', 'obr_password_generator_init');
    196 
     199add_action( 'widgets_init', 'obr_password_generator_init' );
     200
  • password-generator/trunk/readme.txt

    r2585893 r2778948  
    1 === Outerbridge Password Generator ===
     1=== Password Generator ===
    22Contributors: outerbridge
    33Author URI: https://outerbridge.co.uk/
    44Tags: password generator, special characters, strong password
    55Requires at least: 4.7
    6 Tested up to: 5.8
     6Tested up to: 6.0
    77Stable tag: trunk
    88
     
    4646== Changelog ==
    4747
     48= 1.7 =
     49- (01 Sep 2022) Various fixes. Tested and stable up to WP6.0
     50
    4851= 1.6 =
    4952- (23 May 2017) Made translatable
     
    7477
    7578
     79= 1.7 =
     80- Various fixes. Tested and stable up to WP6.0
     81
    7682= 1.6 =
    7783- Made translatable
Note: See TracChangeset for help on using the changeset viewer.