Changeset 1504811
- Timestamp:
- 09/29/2016 02:48:48 AM (10 years ago)
- Location:
- easy-random-quotes
- Files:
-
- 12 added
- 2 edited
-
tags/1.7 (added)
-
tags/1.7/kl-easyrandomquotes.php (added)
-
tags/1.7/lang (added)
-
tags/1.7/lang/easy-random-quotes.pot (added)
-
tags/1.7/readme.txt (added)
-
tags/1.7/uninstall.php (added)
-
tags/1.8 (added)
-
tags/1.8/kl-easyrandomquotes.php (added)
-
tags/1.8/lang (added)
-
tags/1.8/lang/easy-random-quotes.pot (added)
-
tags/1.8/readme.txt (added)
-
tags/1.8/uninstall.php (added)
-
trunk/kl-easyrandomquotes.php (modified) (14 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
easy-random-quotes/trunk/kl-easyrandomquotes.php
r691529 r1504811 5 5 * Description: Insert quotes and pull them randomly into your pages and posts (via shortcodes) or your template (via template tags). 6 6 * Author: Kailey Lampert 7 * Version: 1. 77 * Version: 1.8 8 8 * Author URI: http://kaileylampert.com/ 9 9 * License: GPLv2 or later … … 16 16 class kl_easyrandomquotes { 17 17 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 23 32 add_shortcode( 'erq', 'erq_shortcode' ); 24 33 } 25 34 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 */ 33 69 function update() { 34 70 … … 36 72 $newquote = wp_filter_post_kses( $_POST['erq_newquote'] ); 37 73 38 $theQuotes = get_option( 'kl-easyrandomquotes', array() ); //get existing39 40 74 if ( ! empty( $newquote ) ) { 41 75 76 $theQuotes = get_option( 'kl-easyrandomquotes', array() ); //get existing 77 42 78 $theQuotes[] = $newquote; //add new 43 79 44 80 check_admin_referer( 'easyrandomquotes-update_add' ); 81 45 82 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' ) ); 47 85 48 86 } 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' ) ); 50 88 } 51 89 … … 57 95 $newquotes = array_map( 'wp_filter_post_kses', $newquotes ); 58 96 59 global $erq_count;60 97 $erq_count = count( $newquotes ); 61 98 62 99 $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 64 102 foreach ( $newquotes as $newquote ) { 65 103 $theQuotes[] = $newquote; … … 69 107 70 108 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 ) ); 78 111 79 112 } // end if add … … 81 114 if ( isset( $_POST[ 'erq_quote' ] ) ) { 82 115 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(); 85 118 $theQuotes = get_option( 'kl-easyrandomquotes', array() ); 86 119 87 120 // update each quote 88 foreach ( $ids as $id => $quote ) {89 $theQuotes[ $id ] = wp_filter_post_kses( $quote ); // update each part with new quote90 } 91 92 // delete all checke cquotes93 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 ] ); 95 128 } 96 129 97 130 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' ) ); 100 134 } 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' ) ); 102 136 } 103 137 … … 106 140 if ( isset( $_POST[ 'clear' ] ) ) { 107 141 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 112 150 } 113 151 … … 116 154 } // end update() 117 155 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(); 119 166 echo '<div class="wrap">'; 120 167 … … 140 187 wp_nonce_field( 'easyrandomquotes-update_edit' ); 141 188 142 $tblrows = '<tr><t hclass="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>'; 145 192 146 193 echo '<table class="widefat page"><thead>' . $tblrows . '</thead><tfoot>' . $tblrows . '</tfoot><tbody>'; … … 149 196 150 197 if ( ! empty( $theQuotes ) ) { 151 foreach ( $theQuotes as $id=>$quote ) {198 foreach ( $theQuotes as $id=>$quote ) { 152 199 echo '<tr>'; 153 200 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>'; 155 202 echo '<td>[erq id=' . $id . ']</td>'; 156 203 echo '</tr>'; 157 204 } 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 } 159 208 160 209 echo '</tbody></table>'; … … 170 219 }// end page() 171 220 172 221 /** 222 * 223 */ 173 224 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; 176 227 177 228 $string1 = sprintf( __( 'Specific quote: %s' , 'easy-random-quotes' ), '<code>[erq id=2]</code>' ); … … 190 241 191 242 $screen->add_help_tab( array( 192 'id' => 'erq_help',193 'title' => 'Help',243 'id' => 'erq_help', 244 'title' => 'Help', 194 245 'content' => $content, 195 246 ) ); … … 199 250 } 200 251 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 */ 203 256 function 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']; 207 262 208 263 $id = explode( ',', $id ); … … 210 265 $id = array_pop( $id ); 211 266 212 $theQuotes = get_option( 'kl-easyrandomquotes', array() ); //get exsisting267 $theQuotes = get_option( 'kl-easyrandomquotes', array() ); //get exsisting 213 268 $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 } 216 272 } 217 273 218 /* widget */219 function kl_easyrandomquotes_load_widget() {220 register_widget( 'kl_easyrandomquotes_widget' );221 }222 223 274 class kl_easyrandomquotes_widget extends WP_Widget { 224 275 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 ); 227 284 $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 */ 231 291 function widget( $args, $instance ) { 232 292 extract( $args ); 233 293 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>'; 236 298 echo $after_widget; 237 299 } 238 300 301 /** 302 * 303 */ 239 304 function update( $new_instance, $old_instance ) { 240 305 $instance = $old_instance; 241 $instance['title'] = esc_attr( $new_instance['title'] );306 $instance['title'] = esc_attr( $new_instance['title'] ); 242 307 $instance['hide_title'] = (bool) $new_instance['hide_title'] ? 1 : 0; 243 308 return $instance; 244 309 } 245 310 311 /** 312 * 313 */ 246 314 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 ); 248 319 $instance = wp_parse_args( (array) $instance, $defaults ); 249 320 ?> 250 <p style="width:63%;float:left;">321 <p> 251 322 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'easy-random-quotes' );?> 252 323 <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']; ?>" /> 253 324 </label> 254 325 </p> 255 <p style="width:33%;float:right;padding-top:20px;height:20px;">326 <p> 256 327 <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'] ); ?> /> 257 328 <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 5 5 Requires at least: 2.8 6 6 Tested up to: 3.5.1 7 Stable tag: trunk7 Stable tag: 1.8 8 8 9 9 Insert quotes and pull them randomly into your pages and posts (via shortcodes) or your template (via template tags). … … 36 36 == Changelog == 37 37 38 = 1.8 = 39 * maintenance 40 38 41 = 1.7 = 39 42 * New: Random quotes from a given list of ids: [erq id='2,4,6']
Note: See TracChangeset
for help on using the changeset viewer.