Plugin Directory

Changeset 1504811


Ignore:
Timestamp:
09/29/2016 02:48:48 AM (10 years ago)
Author:
trepmal
Message:

tag 1.8 maintenance release

Location:
easy-random-quotes
Files:
12 added
2 edited

Legend:

Unmodified
Added
Removed
  • easy-random-quotes/trunk/kl-easyrandomquotes.php

    r691529 r1504811  
    55 * Description: Insert quotes and pull them randomly into your pages and posts (via shortcodes) or your template (via template tags).
    66 * Author: Kailey Lampert
    7  * Version: 1.7
     7 * Version: 1.8
    88 * Author URI: http://kaileylampert.com/
    99 * License: GPLv2 or later
     
    1616class kl_easyrandomquotes {
    1717
    18     function kl_easyrandomquotes( ) {
    19         add_action( 'admin_menu', array( &$this, 'menu' ) );
    20         add_action( 'contextual_help', array( &$this, 'help'), 10, 3 );
    21 
    22         add_action( 'widgets_init', 'kl_easyrandomquotes_load_widget' );
     18    /**
     19     *
     20     */
     21    private $page_name;
     22
     23    /**
     24     *
     25     */
     26    function __construct() {
     27        add_action( 'widgets_init',    array( $this, 'kl_easyrandomquotes_load_widget' ) );
     28
     29        add_action( 'admin_menu',      array( $this, 'menu' ) );
     30        add_action( 'contextual_help', array( $this, 'help'), 10, 3 );
     31
    2332        add_shortcode( 'erq', 'erq_shortcode' );
    2433    }
    2534
    26     function menu( ) {
    27         global $erq_page;
    28         $erq_page = add_submenu_page( 'options-general.php', __( 'Easy Random Quotes', 'easy-random-quotes' ), __( 'Easy Random Quotes', 'easy-random-quotes' ), 'administrator', __FILE__, array( &$this, 'page' ) );
    29         add_action( 'admin_head-'.$erq_page, array( &$this, 'update') );
    30 
    31     }
    32 
     35    /**
     36     *
     37     */
     38    function kl_easyrandomquotes_load_widget() {
     39        register_widget( 'kl_easyrandomquotes_widget' );
     40    }
     41
     42    /**
     43     *
     44     */
     45    function menu() {
     46        $this->page_name = add_options_page(
     47            __( 'Easy Random Quotes', 'easy-random-quotes' ),
     48            __( 'Easy Random Quotes', 'easy-random-quotes' ),
     49            'manage_options',
     50            __FILE__,
     51            array( $this, 'page' )
     52        );
     53
     54        add_action( 'admin_head-'.$this->page_name, array( $this, 'verify_nonce' ) );
     55
     56    }
     57
     58    function verify_nonce() {
     59        if ( isset( $_POST['erq_add'] ) || isset( $_POST['erq_import'] ) ) {
     60            check_admin_referer( 'easyrandomquotes-update_add' );
     61        }
     62        if ( isset( $_POST['erq_quote'] ) ) {
     63            check_admin_referer( 'easyrandomquotes-update_edit' );
     64        }
     65    }
     66    /**
     67     *
     68     */
    3369    function update() {
    3470
     
    3672            $newquote = wp_filter_post_kses( $_POST['erq_newquote'] );
    3773
    38             $theQuotes = get_option( 'kl-easyrandomquotes', array() ); //get existing
    39 
    4074            if ( ! empty( $newquote ) ) {
    4175
     76                $theQuotes = get_option( 'kl-easyrandomquotes', array() ); //get existing
     77
    4278                $theQuotes[] = $newquote; //add new
    4379
    4480                check_admin_referer( 'easyrandomquotes-update_add' );
     81
    4582                update_option( 'kl-easyrandomquotes', $theQuotes ); //successfully updated
    46                 add_action( 'admin_notices', create_function('$a', 'echo "<div class=\"updated\"><p>" . __( "New quote was added" , "easy-random-quotes" ) . "</p></div>";') );
     83
     84                $this->alert_message( __( 'New quote was added' , 'easy-random-quotes' ) );
    4785
    4886            } else {
    49                 add_action( 'admin_notices', create_function('$a', 'echo "<div class=\"updated\"><p>" . __( "Nothing added" , "easy-random-quotes" ) . "</p></div>";') );
     87                $this->alert_message( __( 'Nothing added' , 'easy-random-quotes' ) );
    5088            }
    5189
     
    5795            $newquotes = array_map( 'wp_filter_post_kses', $newquotes );
    5896
    59             global $erq_count;
    6097            $erq_count = count( $newquotes );
    6198
    6299            $theQuotes = get_option( 'kl-easyrandomquotes', array() );
    63             //array_merge messes up the keys, and using the '+' method will skip certain items
     100
     101            // array_merge messes up the keys, and using the '+' method will skip certain items
    64102            foreach ( $newquotes as $newquote ) {
    65103                $theQuotes[] = $newquote;
     
    69107
    70108            update_option( 'kl-easyrandomquotes', $theQuotes ); //successfully updated
    71             add_action( 'admin_notices', 'erq_import_success' );
    72             function erq_import_success() {
    73                 global $erq_count;
    74                 ?><div class="updated"><p><?php
    75                     printf( __( '%d new quotes were added', 'easy-random-quotes' ), $erq_count );
    76                 ?></p></div><?php
    77             }
     109
     110            $this->alert_message( sprintf( __( '%d new quotes were added', 'easy-random-quotes' ), $erq_count ) );
    78111
    79112        } // end if add
     
    81114        if ( isset( $_POST[ 'erq_quote' ] ) ) {
    82115
    83             $ids = $_POST[ 'erq_quote' ];
    84             $dels = isset( $_POST[ 'erq_del' ] ) ? $_POST[ 'erq_del' ] : array();
     116            $ids       = $_POST[ 'erq_quote' ];
     117            $dels      = isset( $_POST[ 'erq_del' ] ) ? $_POST[ 'erq_del' ] : array();
    85118            $theQuotes =  get_option( 'kl-easyrandomquotes', array() );
    86119
    87120            // update each quote
    88             foreach( $ids as $id => $quote ) {
    89                 $theQuotes[ $id ] = wp_filter_post_kses( $quote ); //update each part with new quote
    90             }
    91 
    92             // delete all checkec quotes
    93             foreach( $dels as $id => $quote ) {
    94                 unset( $theQuotes[ $id ] ); //delete selected...
     121            foreach ( $ids as $id => $quote ) {
     122                $theQuotes[ $id ] = wp_filter_post_kses( $quote ); // update each part with new quote
     123            }
     124
     125            // delete all checked quotes
     126            foreach ( $dels as $id => $quote ) {
     127                unset( $theQuotes[ $id ] );
    95128            }
    96129
    97130            check_admin_referer( 'easyrandomquotes-update_edit' );
    98             if ( update_option( 'kl-easyrandomquotes',$theQuotes ) ) { //if option was successfully update with new values
    99                 add_action( 'admin_notices', create_function('$a', 'echo "<div class=\"updated\"><p>" . __( "Quote was edited/deleted" , "easy-random-quotes" ) . "</p></div>";') );
     131
     132            if ( update_option( 'kl-easyrandomquotes',$theQuotes ) ) {
     133                $this->alert_message( __( 'Quote was edited/deleted' , 'easy-random-quotes' ) );
    100134            } else {
    101                 add_action( 'admin_notices', create_function('$a', 'echo "<div class=\"updated\"><p>" . __( "Nothing changed" , "easy-random-quotes" ) . "</p></div>";') );
     135                $this->alert_message( __( 'Nothing changed' , 'easy-random-quotes' ) );
    102136            }
    103137
     
    106140        if ( isset( $_POST[ 'clear' ] ) ) {
    107141
    108             if ( !isset( $_POST[ 'confirm' ])) {
    109                 add_action( 'admin_notices', create_function('$a', 'echo "<div class=\"updated\"><p>" . __( "You must confirm for a reset" , "easy-random-quotes" ) . "</p></div>";') );
    110             } elseif (delete_option( 'kl-easyrandomquotes' )) {
    111                 add_action( 'admin_notices', create_function('$a', 'echo "<div class=\"updated\"><p>" . __( "All quotes deleted" , "easy-random-quotes" ) . "</p></div>";') );
     142            if ( ! isset( $_POST[ 'confirm' ] ) ) {
     143
     144                $this->alert_message( __( 'You must confirm for a reset' , 'easy-random-quotes' ) );
     145
     146            } elseif ( delete_option( 'kl-easyrandomquotes' ) ) {
     147
     148                $this->alert_message( __( 'All quotes deleted' , 'easy-random-quotes' ) );
     149
    112150            }
    113151
     
    116154    } // end update()
    117155
    118     function page( ) {
     156
     157    function alert_message( $message, $type='updated' ) {
     158        echo '<div class="' . esc_attr( $type ) . '"><p>' . $message . '</p></div>';
     159    }
     160
     161    /**
     162     *
     163     */
     164    function page() {
     165        $this->update();
    119166        echo '<div class="wrap">';
    120167
     
    140187            wp_nonce_field( 'easyrandomquotes-update_edit' );
    141188
    142             $tblrows = '<tr><th class="manage-column column-cb check-column" id="cb"><input type="checkbox" /></th>
    143                             <th class="manage-column">' . __( 'The quote' , 'easy-random-quotes' ) . '</th>
    144                             <th class="manage-column">' . __( 'Short code (for posts/pages)' , 'easy-random-quotes' ) . '</th></tr>';
     189            $tblrows = '<tr><td class="manage-column column-cb check-column" id="cb"><input type="checkbox" /></th>
     190                            <th scope="col" id="quote" class="manage-column column-quote">' . __( 'The quote' , 'easy-random-quotes' ) . '</th>
     191                            <th scope="col" id="shortcode" class="manage-column column-shortcode">' . __( 'Short code (for posts/pages)' , 'easy-random-quotes' ) . '</th></tr>';
    145192
    146193            echo '<table class="widefat page"><thead>' . $tblrows . '</thead><tfoot>' . $tblrows . '</tfoot><tbody>';
     
    149196
    150197            if ( ! empty( $theQuotes ) ) {
    151                 foreach( $theQuotes as $id=>$quote ) {
     198                foreach ( $theQuotes as $id=>$quote ) {
    152199                    echo '<tr>';
    153200                    echo '<th class="check-column"><input type="checkbox" name="erq_del[' . $id . ']" /></th>';
    154                     echo '<td><textarea name="erq_quote[' . $id . ']" rows="6" cols="60">' . stripslashes( $quote ) . '</textarea></td>';
     201                    echo '<td><textarea name="erq_quote[' . $id . ']" rows="6" cols="60">' . esc_textarea( stripslashes( $quote ) ) . '</textarea></td>';
    155202                    echo '<td>[erq id=' . $id . ']</td>';
    156203                    echo '</tr>';
    157204                }
    158             } else { echo '<tr><th colspan="3">' . __( 'No quotes' , 'easy-random-quotes' ) . '</th></tr>'; }
     205            } else {
     206                echo '<tr><th colspan="3">' . __( 'No quotes' , 'easy-random-quotes' ) . '</th></tr>';
     207            }
    159208
    160209            echo '</tbody></table>';
     
    170219    }// end page()
    171220
    172 
     221    /**
     222     *
     223     */
    173224    function help( $contextual_help, $screen_id, $screen ) {
    174         global $erq_page;
    175         if ( $screen_id != $erq_page ) return;
     225
     226        if ( $screen_id != $this->page_name ) return;
    176227
    177228        $string1 = sprintf( __( 'Specific quote: %s' , 'easy-random-quotes' ), '<code>[erq id=2]</code>' );
     
    190241
    191242        $screen->add_help_tab( array(
    192             'id' => 'erq_help',
    193             'title' => 'Help',
     243            'id'      => 'erq_help',
     244            'title'   => 'Help',
    194245            'content' => $content,
    195246        ) );
     
    199250}
    200251
    201 //shortcode/template tag
    202 //outside of class to make it more accessible
     252/**
     253 * shortcode/template tag
     254 * outside of class to make it more accessible
     255 */
    203256function erq_shortcode( $atts=array() ) {
    204     extract( shortcode_atts( array(
    205             'id' => 'rand'
    206     ), $atts ) );
     257    $atts = shortcode_atts( array(
     258        'id' => 'rand',
     259    ), $atts );
     260
     261    $id = $atts['id'];
    207262
    208263    $id = explode( ',', $id );
     
    210265    $id = array_pop( $id );
    211266
    212     $theQuotes = get_option( 'kl-easyrandomquotes', array() );  //get exsisting
     267    $theQuotes = get_option( 'kl-easyrandomquotes', array() ); //get exsisting
    213268    $use = ( 'rand' == $id ) ? array_rand( $theQuotes ) : $id;
    214     if ( isset( $theQuotes[ $use ] ) )
    215     return stripslashes( $theQuotes[ $use ] );
     269    if ( isset( $theQuotes[ $use ] ) ) {
     270        return stripslashes( $theQuotes[ $use ] );
     271    }
    216272}
    217273
    218 /* widget */
    219 function kl_easyrandomquotes_load_widget() {
    220     register_widget( 'kl_easyrandomquotes_widget' );
    221 }
    222 
    223274class kl_easyrandomquotes_widget extends WP_Widget {
    224275
    225     function kl_easyrandomquotes_widget() {
    226         $widget_ops = array( 'classname' => 'kl-erq', 'description' => __( 'Displays random quotes', 'easy-random-quotes' ) );
     276    /**
     277     *
     278     */
     279    function __construct() {
     280        $widget_ops = array(
     281            'classname'   => 'kl-erq',
     282            'description' => __( 'Displays random quotes', 'easy-random-quotes' )
     283        );
    227284        $control_ops = array();
    228         $this->WP_Widget( 'kl-erq', __( 'Easy Random Quotes', 'easy-random-quotes' ), $widget_ops, $control_ops );
    229     }
    230 
     285        parent::__construct( 'kl-erq', __( 'Easy Random Quotes', 'easy-random-quotes' ), $widget_ops, $control_ops );
     286    }
     287
     288    /**
     289     *
     290     */
    231291    function widget( $args, $instance ) {
    232292        extract( $args );
    233293        echo $before_widget;
    234         if ( $instance[ 'title' ] ) echo $before_title . apply_filters( 'widget_title', $instance[ 'title' ] ) . $after_title;
    235         echo '<p>' . erq_shortcode( ) . '</p>';
     294        if ( ! $instance[ 'hide_title' ] ) {
     295            echo $before_title . apply_filters( 'widget_title', $instance[ 'title' ] ) . $after_title;
     296        }
     297        echo '<p>' . erq_shortcode() . '</p>';
    236298        echo $after_widget;
    237299    }
    238300
     301    /**
     302     *
     303     */
    239304    function update( $new_instance, $old_instance ) {
    240305        $instance = $old_instance;
    241         $instance['title'] = esc_attr( $new_instance['title'] );
     306        $instance['title']      = esc_attr( $new_instance['title'] );
    242307        $instance['hide_title'] = (bool) $new_instance['hide_title'] ? 1 : 0;
    243308        return $instance;
    244309    }
    245310
     311    /**
     312     *
     313     */
    246314    function form( $instance ) {
    247         $defaults = array( 'title' => __( 'A Random Thought', 'easy-random-quotes' ), 'hide_title' => 0 );
     315        $defaults = array(
     316            'title'      => __( 'A Random Thought', 'easy-random-quotes' ),
     317            'hide_title' => 0
     318        );
    248319        $instance = wp_parse_args( (array) $instance, $defaults );
    249320        ?>
    250         <p style="width:63%;float:left;">
     321        <p>
    251322            <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'easy-random-quotes' );?>
    252323                <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $instance['title']; ?>" />
    253324            </label>
    254325        </p>
    255         <p style="width:33%;float:right;padding-top:20px;height:20px;">
     326        <p>
    256327            <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('hide_title'); ?>" name="<?php echo $this->get_field_name('hide_title'); ?>"<?php checked( $instance['hide_title'] ); ?> />
    257328            <label for="<?php echo $this->get_field_id('hide_title'); ?>"><?php _e('Hide Title?', 'easy-random-quotes' );?></label>
  • easy-random-quotes/trunk/readme.txt

    r691529 r1504811  
    55Requires at least: 2.8
    66Tested up to: 3.5.1
    7 Stable tag: trunk
     7Stable tag: 1.8
    88
    99Insert quotes and pull them randomly into your pages and posts (via shortcodes) or your template (via template tags).
     
    3636== Changelog ==
    3737
     38= 1.8 =
     39* maintenance
     40
    3841= 1.7 =
    3942* New: Random quotes from a given list of ids: [erq id='2,4,6']
Note: See TracChangeset for help on using the changeset viewer.