Changeset 38225

Show
Ignore:
Timestamp:
04/04/08 11:23:00 (3 months ago)
Author:
ketsugi
Message:

Almost done with the UI, just gotta do pagination :)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • acronyms/trunk/acronyms.php

    r37989 r38225  
    182182      { 
    183183      } 
    184        
     184 
    185185      /** 
    186186       * Adds the Management page to WordPress 
     
    194194      } 
    195195       
    196       /** 
    197        * Manage Acronyms page 
    198        *  
    199        * @return void 
    200        **/ 
    201       function manage_acronyms () 
    202       { 
     196      function management_handler () { 
    203197            $title = __('Acronyms'); 
    204198            $parent_file = 'edit.php?page=acronyms.php'; 
     
    207201            wp_reset_vars(array('action', 'acronym')); 
    208202 
    209             if ( isset($_POST['deleteit']) ) 
     203            if ( isset($_GET['deleteit']) ) 
    210204                  $action = 'delete'; 
    211             else $action = $_POST['action']; 
     205            else $action = $_GET['action']; 
    212206 
    213207            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; 
    220216                        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; 
    227225                        break; 
    228226              case 'delete': 
    229                         check_admin_referer('bulk-acronyms'); 
     227                        check_admin_referer('delete-acronym'); 
    230228 
    231229            if ( !current_user_can('manage_categories') ) 
    232230                  wp_die(__('Cheatin’ uh?')); 
    233231 
    234                 $acronyms = $_POST['delete_acronyms']; 
     232                $acronyms = $_GET['delete_acronyms']; 
    235233            foreach( (array) $acronyms as $acronym ) { 
    236234                  Acronyms::delete ( $acronym ); 
     
    240238                   $message = 6; 
    241239            else $message = 2; 
    242  
     240            wp_redirect('edit.php?page=acronyms.php&message=' . $message); 
     241            exit; 
    243242                    break; 
    244243            } 
    245  
     244      } 
     245 
     246 
     247      /** 
     248       * Manage Acronyms page 
     249       *  
     250       * @return void 
     251       **/ 
     252      function manage_acronyms () 
     253      { 
     254            $message = $_GET['message']; 
    246255            $messages[1] = __('Acronym added.'); 
    247256            $messages[2] = __('Acronym deleted.'); 
     
    260269?> 
    261270<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> 
    265277            <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'])); ?>" /> 
    267279                  <input type="submit" value="<?php _e( 'Search acronyms' ); ?>" class="button" /> 
    268280            </p> 
     
    272284    <div class="alignleft"> 
    273285      <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'); ?> 
    275287            </div> 
    276288    <br class="clear" /> 
    277289  </div> 
    278290  <br class="clear" /> 
    279 <?php Acronyms::show_acronym_list($_POST['s']) ?> 
     291<?php Acronyms::show_acronym_list($_GET['s']) ?> 
    280292  </form> 
    281293</div><?php 
     
    310322      } 
    311323 
     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       */ 
    312328      function show_acronym_list ( $s ) 
    313329      { 
     
    354370                  $heading = __('Edit Acronym'); 
    355371                  $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'
    359375            } else { 
    360376                  $heading = __('Add Acronym'); 
    361377                  $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'; 
    364380                  $nonce_action = 'add-acronym'; 
    365381            } 
     
    369385<div id="ajax-response"></div> 
    370386<?php echo $form ?> 
    371 <input type="hidden" name="page" value="acronyms.php" /> 
     387<input type="hidden" name="page" value="acronyms.php"/> 
    372388<input type="hidden" name="action" value="<?php echo $action ?>" /> 
    373389<?php wp_original_referer_field(true, 'previous'); wp_nonce_field($nonce_action); ?> 
    374390      <table class="form-table"> 
    375391            <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> 
    377393                  <td><label for="fulltext"><?php _e('Full') ?></label>: <input name="fulltext" id="fulltext" type="text" value="<?php echo attribute_escape($fulltext); ?>" size="80" /></td> 
    378394            </tr> 
     
    389405      function update ( $acronym, $fulltext ) 
    390406      { 
    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            } 
    395415      } 
    396416 
     
    411431} /* END CLASS acronyms */ 
    412432 
     433add_action( 'admin_init', array( 'Acronyms', 'management_handler' ) ); 
    413434add_action( 'activate_acronyms.php', array( 'Acronyms', 'install' ) ); 
    414435add_action( 'deactivate_acronyms.php', array( 'Acronyms', 'uninstall' ) ); 
    415436if (1 == get_option( 'acronym_content' ) ) 
    416437      add_filter( 'the_content', array( 'Acronyms', 'acronym_replace' ) ); 
    417 if (1 == get_option( 'acronym_comments' ) )     
     438if (1 == get_option( 'acronym_comments' ) ) 
    418439      add_filter( 'comment_text', array( 'Acronyms', 'acronym_replace' ) ); 
    419440add_action( 'admin_menu', array( 'Acronyms', 'add_pages' ) );