Changeset 38225
- Timestamp:
- 04/04/08 11:23:00 (3 months ago)
- Files:
-
- acronyms/trunk/acronyms.php (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
acronyms/trunk/acronyms.php
r37989 r38225 182 182 { 183 183 } 184 184 185 185 /** 186 186 * Adds the Management page to WordPress … … 194 194 } 195 195 196 /** 197 * Manage Acronyms page 198 * 199 * @return void 200 **/ 201 function manage_acronyms () 202 { 196 function management_handler () { 203 197 $title = __('Acronyms'); 204 198 $parent_file = 'edit.php?page=acronyms.php'; … … 207 201 wp_reset_vars(array('action', 'acronym')); 208 202 209 if ( isset($_ POST['deleteit']) )203 if ( isset($_GET['deleteit']) ) 210 204 $action = 'delete'; 211 else $action = $_ POST['action'];205 else $action = $_GET['action']; 212 206 213 207 switch ($action) { 214 case 'add': 215 check_admin_referer('add-acronym'); 216 $acronym = $_POST['acronym']; 217 $fulltext = $_POST['fulltext']; 218 Acronyms::update ( $acronym, $fulltext ); 219 $message = 1; 208 case 'add-acronym': 209 check_admin_referer('add-acronym');; 210 $acronym = $_GET['acronym']; 211 $fulltext = $_GET['fulltext']; 212 if ( Acronyms::update ( $acronym, $fulltext ) ) $message = 1; 213 else $message = 4; 214 wp_redirect('edit.php?page=acronyms.php&message=' . $message); 215 exit; 220 216 break; 221 case 'edit': 222 $acronym = $_POST['acronym']; 223 $fulltext = $_POST['fulltext']; 224 check_admin_referer('edit-acronym_' . $acronym); 225 Acronyms::update ( $acronym, $fulltext ); 226 $message = 3; 217 case 'edit-acronym': 218 $acronym = $_GET['acronym']; 219 $fulltext = $_GET['fulltext']; 220 check_admin_referer('edit-acronym'); 221 if ( Acronyms::update ( $acronym, $fulltext ) ) $message = 3; 222 else $message = 5; 223 wp_redirect('edit.php?page=acronyms.php&message=' . $message); 224 exit; 227 225 break; 228 226 case 'delete': 229 check_admin_referer(' bulk-acronyms');227 check_admin_referer('delete-acronym'); 230 228 231 229 if ( !current_user_can('manage_categories') ) 232 230 wp_die(__('Cheatin’ uh?')); 233 231 234 $acronyms = $_ POST['delete_acronyms'];232 $acronyms = $_GET['delete_acronyms']; 235 233 foreach( (array) $acronyms as $acronym ) { 236 234 Acronyms::delete ( $acronym ); … … 240 238 $message = 6; 241 239 else $message = 2; 242 240 wp_redirect('edit.php?page=acronyms.php&message=' . $message); 241 exit; 243 242 break; 244 243 } 245 244 } 245 246 247 /** 248 * Manage Acronyms page 249 * 250 * @return void 251 **/ 252 function manage_acronyms () 253 { 254 $message = $_GET['message']; 246 255 $messages[1] = __('Acronym added.'); 247 256 $messages[2] = __('Acronym deleted.'); … … 260 269 ?> 261 270 <div class="wrap"> 262 <form id="posts-filter" action="" method="post"> 263 <input type="hidden" name="page" value="acronyms.php" /> 264 <h2><?php _e('Manage Acronyms') ?> (<a href="#addacronym"><?php _e('add new')?></a>)</h2> 271 <form id="posts-filter" action="" method="get"> 272 <input type="hidden" name="page" value="acronyms.php"/> 273 <h2><?php 274 _e('Manage Acronyms'); 275 if( 'edit' != $_GET['action'] ) echo ' (<a href="#addacronym">' . __('add new') . '</a>)' 276 ?></h2> 265 277 <p id="post-search"> 266 <input type="text" id="post-search-input" name="s" value="<?php echo attribute_escape(stripslashes($_ POST['s'])); ?>" />278 <input type="text" id="post-search-input" name="s" value="<?php echo attribute_escape(stripslashes($_GET['s'])); ?>" /> 267 279 <input type="submit" value="<?php _e( 'Search acronyms' ); ?>" class="button" /> 268 280 </p> … … 272 284 <div class="alignleft"> 273 285 <input type="submit" value="<?php _e('Delete') ?>" name="deleteit" class="button-secondary delete" /> 274 <?php wp_nonce_field(' bulk-acronyms'); ?>286 <?php wp_nonce_field('delete-acronym'); ?> 275 287 </div> 276 288 <br class="clear" /> 277 289 </div> 278 290 <br class="clear" /> 279 <?php Acronyms::show_acronym_list($_ POST['s']) ?>291 <?php Acronyms::show_acronym_list($_GET['s']) ?> 280 292 </form> 281 293 </div><?php … … 310 322 } 311 323 324 /* string show_acronym_list ( string $s, int $num_of_acronyms, int $page_num ) 325 * 326 * Displays the list of acronyms, filtered by search term $s and showing page # $page_num based on $num_of_acronyms per page 327 */ 312 328 function show_acronym_list ( $s ) 313 329 { … … 354 370 $heading = __('Edit Acronym'); 355 371 $submit_text = __('Edit Acronym'); 356 $form = '<form name="editacronym" id="editacronym" method=" post" action="" class="validate">';357 $action = 'edit ';358 $nonce_action = 'edit-acronym _' . $acronym;372 $form = '<form name="editacronym" id="editacronym" method="get" action="" class="validate">'; 373 $action = 'edit-acronym'; 374 $nonce_action = 'edit-acronym'; 359 375 } else { 360 376 $heading = __('Add Acronym'); 361 377 $submit_text = __('Add Acronym'); 362 $form = '<form name="addacronym" id="addacronym" method=" post" action="" class="add:the-list: validate">';363 $action = 'add ';378 $form = '<form name="addacronym" id="addacronym" method="get" action="" class="add:the-list: validate">'; 379 $action = 'add-acronym'; 364 380 $nonce_action = 'add-acronym'; 365 381 } … … 369 385 <div id="ajax-response"></div> 370 386 <?php echo $form ?> 371 <input type="hidden" name="page" value="acronyms.php" />387 <input type="hidden" name="page" value="acronyms.php"/> 372 388 <input type="hidden" name="action" value="<?php echo $action ?>" /> 373 389 <?php wp_original_referer_field(true, 'previous'); wp_nonce_field($nonce_action); ?> 374 390 <table class="form-table"> 375 391 <tr class="form-field form-required"> 376 <td><label for="acronym"><?php _e('Acronym') ?></label>: <input name="acronym" id="acronym" type="text" value="<?php echo attribute_escape($acronym); ?>" size="20" <?php if ( 'edit' == $action ) echo ' disabled="disabled"'; ?>/></td>392 <td><label for="acronym"><?php _e('Acronym') ?></label>: <input name="acronym" id="acronym" type="text" value="<?php echo attribute_escape($acronym); ?>" size="20" <?php if ( 'edit' == $action ) echo 'readonly="readonly"'; ?>/></td> 377 393 <td><label for="fulltext"><?php _e('Full') ?></label>: <input name="fulltext" id="fulltext" type="text" value="<?php echo attribute_escape($fulltext); ?>" size="80" /></td> 378 394 </tr> … … 389 405 function update ( $acronym, $fulltext ) 390 406 { 391 $acronyms = get_option( 'acronym_acronyms' ); 392 $acronyms[$acronym] = $fulltext; 393 ksort($acronyms); 394 update_option( 'acronym_acronyms', $acronyms ); 407 if ( empty( $acronym ) || empty( $fulltext ) ) return false; 408 else { 409 $acronyms = get_option( 'acronym_acronyms' ); 410 $acronyms[$acronym] = $fulltext; 411 uksort( $acronyms, "strcmp"); 412 update_option( 'acronym_acronyms', $acronyms ); 413 return true; 414 } 395 415 } 396 416 … … 411 431 } /* END CLASS acronyms */ 412 432 433 add_action( 'admin_init', array( 'Acronyms', 'management_handler' ) ); 413 434 add_action( 'activate_acronyms.php', array( 'Acronyms', 'install' ) ); 414 435 add_action( 'deactivate_acronyms.php', array( 'Acronyms', 'uninstall' ) ); 415 436 if (1 == get_option( 'acronym_content' ) ) 416 437 add_filter( 'the_content', array( 'Acronyms', 'acronym_replace' ) ); 417 if (1 == get_option( 'acronym_comments' ) ) 438 if (1 == get_option( 'acronym_comments' ) ) 418 439 add_filter( 'comment_text', array( 'Acronyms', 'acronym_replace' ) ); 419 440 add_action( 'admin_menu', array( 'Acronyms', 'add_pages' ) );
