Log in with username/password: lyceum/lyceum

Changeset 1055

Show
Ignore:
Timestamp:
08/12/07 18:47:01 (1 year ago)
Author:
jjb
Message:

Cleaning up post.php redirect logic. Code is now much more parallel with WordPress?, and also easier to ascertain behavior regarding tokens, while debugging token errors.

#748, #729

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/lib/functions.php

    r1023 r1055  
    344344} 
    345345 
     346function remove_token_arg($url){ 
     347   return preg_replace('/&?token=[^&]+/', '', $url); 
     348} 
     349 
     350function get_url_arg_pairs($url) { 
     351   $args = parse_url($url, PHP_URL_QUERY); 
     352   $arr  = array();   
     353   foreach (explode('&', $args) as $i) { 
     354      list($name,$value) = explode('=', $i, 2); 
     355      $arr[$name] = $value; 
     356   }   
     357   return $arr; 
     358} 
     359 
    346360?> 
  • trunk/src/lyceum/wp-admin/post.php

    r1054 r1055  
    123123    
    124124   if ($_POST['save']) { 
    125       $location = 'post.php?token='.formtoken('post.php','edit',$post_ID)."&action=edit&post=$post_ID";//might not be ideal for all cases -jjb 
    126       // $location = wp_get_referer(); 
     125      $location = wp_get_referer(); 
    127126   } elseif ($_POST['updatemeta']) { 
    128       $location = 'post.php?token='.formtoken('post.php','edit',$post_ID)."&action=edit&post=$post_ID&message=2#postcustom";//might not be ideal for all cases -jjb 
    129       // $location = wp_get_referer() . '&message=2#postcustom'; 
     127      $location = wp_get_referer() . '&message=2#postcustom'; 
    130128   } elseif ($_POST['deletemeta']) { 
    131       $location = 'post.php?token='.formtoken('post.php','edit',$post_ID)."&action=edit&post=$post_ID&message=3#postcustom";//might not be ideal for all cases -jjb 
    132       // $location = wp_get_referer() . '&message=3#postcustom'; 
    133    } elseif ($_POST['submit']) { 
    134       $location = 'post.php?message=1'; 
    135    // } elseif (!empty($referredby) && $referredby != $referer) { 
    136    //    $location = $_POST['referredby']; 
    137    //    if ( $_POST['referredby'] == 'redo' ) 
    138    //       $location = get_permalink( $post_ID ); 
     129      $location = wp_get_referer() . '&message=3#postcustom'; 
     130   } elseif (!empty($referredby) && $referredby != $referer) { 
     131      $location = $_POST['referredby']; 
     132      if ( $_POST['referredby'] == 'redo' ) 
     133         $location = get_permalink( $post_ID ); 
    139134   } elseif ($action == 'editattachment') { 
    140135      $location = 'attachments.php'; 
     
    142137      $location = 'post.php'; 
    143138   } 
     139 
     140   $location = remove_token_arg($location); 
     141   $matches=array(); 
     142   preg_match('/(.*)?\/([^\/]*\.php)/', parse_url($location, PHP_URL_PATH), $matches); 
     143   $file = $matches[2]; 
     144   $args = get_url_arg_pairs($location); 
     145 
     146   if ('post.php' == $file && 'edit' == $args['action']) 
     147      $location .= '&token=' . formtoken('post.php','edit',$post_ID); 
    144148 
    145149   wp_redirect($location); // Send user on their way while we keep working 
Log in with username/password: lyceum/lyceum