Changeset 2870

Show
Ignore:
Timestamp:
11/24/08 08:28:58 (7 weeks ago)
Author:
MattRead
Message:

first pass at seperating adminhandler into a managable mess

Location:
branches/adminhandler/htdocs/system/classes
Files:
17 added
1 modified

Legend:

Unmodified
Added
Removed
  • branches/adminhandler/htdocs/system/classes/adminhandler.php

    r2867 r2870  
    8484        $this->theme->page = $page; 
    8585        $this->theme->admin_title = ucwords($page) . ( $type != '' ? ' ' . ucwords($type) : '' ); 
    86         switch( $_SERVER['REQUEST_METHOD'] ) { 
    87             case 'POST': 
    88                 // Let plugins try to handle the page 
    89                 Plugins::act('admin_theme_post_' . $page, $this, $this->theme); 
    90                 // Handle POSTs to the admin pages 
    91                 $fn = 'post_' . $page; 
    92                 if ( method_exists( $this, $fn ) ) { 
    93                     $this->$fn(); 
    94                 } 
    95                 else { 
    96                     $classname = get_class( $this ); 
    97                     echo sprintf( _t( '%1$s->%2$s() does not exist.' ), $classname, $fn ); 
    98                     exit; 
    99                 } 
    100                 break; 
    101             default: 
    102                 // Let plugins try to handle the page 
    103                 Plugins::act('admin_theme_get_' . $page, $this, $this->theme); 
    104                 // Handle GETs of the admin pages 
    105                 $fn = 'get_' . $page; 
    106                 if ( method_exists( $this, $fn ) ) { 
    107                     $this->$fn(); 
    108                     exit; 
    109                 } 
    110                 // If a get_ function doesn't exist, just load the template and display it 
    111                 if ( $this->theme->template_exists( $page ) ) { 
    112                     $this->display( $page ); 
    113                 } 
    114                 else { 
    115                     // The requested console page doesn't exist 
    116                     header( 'HTTP/1.0 404 Not Found' ); 
    117                     $this->header(); 
    118                     _e( 'Whooops!' ); 
    119                     $this->footer(); 
    120                 } 
    121                 break; 
     86         
     87        $request_method = strtolower($_SERVER['REQUEST_METHOD']); 
     88        $admin_page = $page . 'AdminPage'; 
     89        Plugins::act("admin_theme_{$request_method}_{$page}", $this, $this->theme); 
     90        if ( class_exists($admin_page) ) { 
     91            $admin_page = new $admin_page( $request_method, $this, $this->theme ); 
     92            $fn = 'act_request_' . strtolower($request_method); 
     93            $admin_page->$fn(); 
     94        } 
     95        else { 
     96            header( 'HTTP/1.1 404 Not Found', true, 404 ); 
     97            _e('Page Not Found'); 
    12298        } 
    12399    } 
     
    129105    { 
    130106        $context = $this->handler_vars['context']; 
    131         if ( method_exists( $this, 'ajax_' . $context ) ) { 
    132             call_user_func( array( $this, 'ajax_' . $context ), $this->handler_vars ); 
     107        $request_method = strtolower($_SERVER['REQUEST_METHOD']); 
     108        $admin_page = $context . 'AdminPage'; 
     109         
     110        if ( class_exists($admin_page) ) { 
     111            $admin_page = new $admin_page( $request_method, $this ); 
     112            $fn = 'act_ajax_' . strtolower($request_method); 
     113            $admin_page->$fn( $this->handler_vars ); 
    133114        } 
    134115        else { 
    135             header( 'HTTP/1.1 403 Forbidden', true, 403 ); 
    136             die(); 
    137         } 
    138     } 
    139  
    140     /** 
    141      * Handles get requests from the options admin page 
    142      */ 
    143     public function get_options() 
    144     { 
    145         $this->post_options(); 
    146     } 
    147  
    148     /** 
    149      * Handles posts requests from the options admin page 
    150      */ 
    151     public function post_options() 
    152     { 
    153         $option_items = array(); 
    154         $timezones = DateTimeZone::listIdentifiers(); 
    155         $timezones = array_merge( array( ''=>'' ), array_combine( array_values( $timezones ), array_values( $timezones ) ) ); 
    156  
    157         $option_items[_t('Name & Tagline')] = array( 
    158             'title' => array( 
    159                 'label' => _t('Site Name'), 
    160                 'type' => 'text', 
    161                 'helptext' => '', 
    162                 ), 
    163             'tagline' => array( 
    164                 'label' => _t('Site Tagline'), 
    165                 'type' => 'text', 
    166                 'helptext' => '', 
    167                 ), 
    168             ); 
    169  
    170         $option_items[_t('Publishing')] = array( 
    171             'pagination' => array( 
    172                 'label' => _t('Items per Page'), 
    173                 'type' => 'text', 
    174                 'helptext' => '', 
    175                 ), 
    176             'atom_entries' => array( 
    177                 'label' => _t('Entries to show in Atom feed'), 
    178                 'type' => 'text', 
    179                 'helptext' => '', 
    180                 ), 
    181             'comments_require_id' => array( 
    182                 'label' => _t('Require Comment Author Info'), 
    183                 'type' => 'checkbox', 
    184                 'helptext' => '', 
    185                 ), 
    186             ); 
    187  
    188         $option_items[_t('Time & Date')] = array( 
    189             /*'presets' => array( 
    190                 'label' => _t('Presets'), 
    191                 'type' => 'select', 
    192                 'selectarray' => array( 
    193                     'europe' => _t('Europe') 
    194                     ), 
    195                 'helptext' => '', 
    196                 ),*/ 
    197             'timezone' => array( 
    198                 'label' => _t('Time Zone'), 
    199                 'type' => 'select', 
    200                 'selectarray' => $timezones, 
    201                 'helptext' => 'Current Date Time: ' . HabariDateTime::date_create()->format(), 
    202                 ), 
    203             'dateformat' => array( 
    204                 'label' => _t('Date Format'), 
    205                 'type' => 'text', 
    206                 'helptext' => 'Current Date: ' . HabariDateTime::date_create()->date 
    207                 ), 
    208             'timeformat' => array( 
    209                 'label' => _t('Time Format'), 
    210                 'type' => 'text', 
    211                 'helptext' => 'Current Time: ' . HabariDateTime::date_create()->time, 
    212                 ) 
    213             ); 
    214  
    215         $option_items[_t('Language')] = array( 
    216             'locale' => array( 
    217                 'label' => _t( 'Locale' ), 
    218                 'type' => 'select', 
    219                 'selectarray' => array_merge( array( '' => 'default' ), array_combine( Locale::list_all(), Locale::list_all() ) ), 
    220                 'helptext' => 'International language code', 
    221             ), 
    222             'system_locale' => array( 
    223                 'label' => _t('System Locale'), 
    224                 'type' => 'text', 
    225                 'helptext' => 'The appropriate locale code for your server', 
    226             ), 
    227         ); 
    228  
    229         $option_items[_t('Logging')] = array( 
    230             'log_backtraces' => array( 
    231                 'label' => _t( 'Log Backtraces' ), 
    232                 'type' => 'checkbox', 
    233                 'helptext' => _t( 'Logs error backtraces to the log tables\' data column. Can drastically increase log size!' ), 
    234             ), 
    235         ); 
    236  
    237             /*$option_items[_t('Presentation')] = array( 
    238             'encoding' => array( 
    239                 'label' => _t('Encoding'), 
    240                 'type' => 'select', 
    241                 'selectarray' => array( 
    242                     'UTF-8' => 'UTF-8' 
    243                     ), 
    244                 'helptext' => '', 
    245                 ), 
    246             );*/ 
    247  
    248         $option_items = Plugins::filter( 'admin_option_items', $option_items ); 
    249  
    250         $form = new FormUI('Admin Options'); 
    251         $tab_index = 3; 
    252         foreach ( $option_items as $name => $option_fields ) { 
    253             $fieldset = $form->append( 'wrapper', Utils::slugify( $name ), $name ); 
    254             $fieldset->class = 'container settings'; 
    255             $fieldset->append( 'static', $name, '<h2>' . htmlentities( $name, ENT_COMPAT, 'UTF-8' ) . '</h2>' ); 
    256             foreach ( $option_fields as $option_name => $option ) { 
    257                 $field = $fieldset->append( $option['type'], $option_name, $option_name, $option['label'] ); 
    258                 $field->template = 'optionscontrol_' . $option['type']; 
    259                 $field->class = 'item clear'; 
    260                 if ( $option['type'] == 'select' && isset( $option['selectarray'] ) ) { 
    261                     $field->options = $option['selectarray']; 
    262                 } 
    263                 $field->tabindex = $tab_index; 
    264                 $tab_index++; 
    265                 $field->helptext = $option['helptext']; 
    266                 if ( isset( $option['helptext'] ) ) { 
    267                     $field->helptext = $option['helptext']; 
    268                 } 
    269                 else { 
    270                     $field->helptext = ''; 
    271                 } 
    272                 // @todo: do something with helptext 
    273         } 
    274             } 
    275  
    276         /* @todo: filter for additional options from plugins 
    277          * We could either use existing config forms and simply extract 
    278          * the form controls, or we could create something different 
    279          */ 
    280  
    281         $submit = $form->append( 'submit', 'apply', _t('Apply'), 'admincontrol_submit' ); 
    282         $submit->tabindex = $tab_index; 
    283         $form->on_success( array( $this, 'form_options_success' ) ); 
    284  
    285         $this->theme->form = $form->get(); 
    286         $this->theme->option_names = array_keys( $option_items ); 
    287         $this->theme->display( 'options' ); 
    288         } 
    289  
    290     /** 
    291      * Display a message when the site options are saved, and save those options 
    292      * 
    293      * @param FormUI $form The successfully submitted form 
    294      */ 
    295     public function form_options_success($form) 
    296     { 
    297         Session::notice( _t( 'Successfully updated options' ) ); 
    298         $form->save(); 
    299         Utils::redirect(); 
    300     } 
    301  
    302     /** 
    303      * Handles post requests from the dashboard. 
    304      */ 
    305     public function post_dashboard() 
    306     { 
    307         $this->get_dashboard(); 
    308     } 
    309  
    310     /** 
    311      * Handles get requests for the dashboard 
    312      * @todo update check should probably be cron'd and cached, not re-checked every load 
    313      */ 
    314     public function get_dashboard() 
    315     { 
    316         // Not sure how best to determine this yet, maybe set an option on install, maybe do this: 
    317         $firstpostdate = DB::get_value('SELECT min(pubdate) FROM {posts} WHERE status = ?', array(Post::status('published'))); 
    318         if ( intval( $firstpostdate ) !== 0 ) $firstpostdate = time() - $firstpostdate; 
    319         $this->theme->active_time = array( 
    320             'years' => floor($firstpostdate / 31556736), 
    321             'months' => floor(($firstpostdate % 31556736) / 2629728), 
    322             'days' => round(($firstpostdate % 2629728) / 86400), 
    323         ); 
    324  
    325         // if the active plugin list has changed, expire the updates cache 
    326         if ( Cache::has( 'dashboard_updates' ) && ( Cache::get( 'dashboard_updates_plugins' ) != Options::get( 'active_plugins' ) ) ) { 
    327             Cache::expire( 'dashboard_updates' ); 
    328         } 
    329  
    330         /* 
    331          * Check for updates to core and any hooked plugins 
    332          * cache the output so we don't make a request every load but can still display updates 
    333          */ 
    334         if ( Cache::has( 'dashboard_updates' ) ) { 
    335             $this->theme->updates = Cache::get( 'dashboard_updates' ); 
    336         } 
    337         else { 
    338             $updates = Update::check(); 
    339  
    340             if ( !Error::is_error( $updates ) ) { 
    341                 Cache::set( 'dashboard_updates', $updates ); 
    342                 $this->theme->updates = $updates; 
    343  
    344                 // cache the set of plugins we just used to check for 
    345                 Cache::set( 'dashboard_updates_plugins', Options::get( 'active_plugins' ) ); 
    346             } 
    347             else { 
    348                 $this->theme->updates = array(); 
    349             } 
    350         } 
    351  
    352         $this->theme->stats = array( 
    353             'author_count' => Users::get( array( 'count' => 1 ) ), 
    354             'page_count' => Posts::get( array( 'count' => 1, 'content_type' => Post::type('page'), 'status' => Post::status('published') ) ), 
    355             'entry_count' => Posts::get( array( 'count' => 1, 'content_type' => Post::type('entry'), 'status' => Post::status('published') ) ), 
    356             'comment_count' => Comments::count_total( Comment::STATUS_APPROVED, FALSE ), 
    357             'tag_count' => DB::get_value('SELECT count(id) FROM {tags}'), 
    358             'page_draft_count' => Posts::get( array( 'count' => 1, 'content_type' => Post::type('page'), 'status' => Post::status('draft'), 'user_id' => User::identify()->id ) ), 
    359             'entry_draft_count' => Posts::get( array( 'count' => 1, 'content_type' => Post::type('entry'), 'status' => Post::status('draft'), 'user_id' => User::identify()->id ) ), 
    360             'unapproved_comment_count' => Comments::count_total( Comment::STATUS_UNAPPROVED, FALSE ), 
    361             'user_entry_scheduled_count' => Posts::get( array( 'count' => 1, 'content_type' => Post::type( 'entry'), 'status' => Post::status( 'scheduled' ), 'user_id' => User::identify()->id ) ), 
    362         ); 
    363  
    364         $this->fetch_dashboard_modules(); 
    365  
    366         // check for first run 
    367         $u = User::identify(); 
    368         if ( ! isset( $u->info->experience_level ) ) { 
    369             $this->theme->first_run = true; 
    370             $u->info->experience_level = 'user'; 
    371             $u->info->commit(); 
    372         } 
    373         else { 
    374             $this->theme->first_run = false; 
    375         } 
    376  
    377         $this->display( 'dashboard' ); 
    378     } 
    379  
    380     /** 
    381      * Fetches active modules for display on the dashboard 
    382      */ 
    383     public function fetch_dashboard_modules() 
    384     { 
    385  
    386         if ( count( Modules::get_all() ) == 0 ) { 
    387             $this->theme->modules = array(); 
    388             return; 
    389         } 
    390  
    391         // get the active module list 
    392         $modules = Modules::get_active(); 
    393  
    394         // append the 'Add Item' module 
    395         $modules['nosort'] = _t('Add Item'); 
    396  
    397         // register the 'Add Item' filter 
    398         Plugins::register( array( $this, 'filter_dash_module_add_item' ), 'filter', 'dash_module_add_item'); 
    399  
    400         foreach( $modules as $id => $module_name ) { 
    401             $slug = Utils::slugify( (string) $module_name, '_' ); 
    402             $module = array( 
    403                 'name' => $module_name, 
    404                 'title' => $module_name, 
    405                 'content' => '', 
    406                 'options' => '' 
    407                 ); 
    408  
    409             $module = Plugins::filter( 'dash_module_' .$slug, $module, $id, $this->theme ); 
    410  
    411             $modules[$id] = $module; 
    412         } 
    413  
    414         $this->theme->modules = $modules; 
    415     } 
    416  
    417     /** 
    418      * Handles post requests from the publish page. 
    419      */ 
    420     public function post_publish() 
    421     { 
    422         $form = $this->form_publish( new Post(), false ); 
    423  
    424         // check to see if we are updating or creating a new post 
    425         if ( $form->post_id->value != 0 ) { 
    426             $post = Post::get( array( 'id' => $form->post_id->value, 'status' => Post::status( 'any' ) ) ); 
    427             $post->title = $form->title->value; 
    428             if ( $form->newslug->value == '' ) { 
    429                 Session::notice( _e('A post slug cannot be empty. Keeping old slug.') ); 
    430             } 
    431             elseif ( $form->newslug->value != $form->slug->value ) { 
    432                 $post->slug = $form->newslug->value; 
    433             } 
    434             $post->tags = $form->tags->value; 
    435  
    436             $post->content = $form->content->value; 
    437             $post->content_type = $form->content_type->value; 
    438             // if not previously published and the user wants to publish now, change the pubdate to the current date/time 
    439             // if the post pubdate is <= the current date/time. 
    440             if ( ( $post->status != Post::status( 'published' ) ) 
    441                 && ( $form->status->value == Post::status( 'published' ) ) 
    442                 && ( HabariDateTime::date_create( $form->pubdate->value )->int <= HabariDateTime::date_create()->int ) 
    443                 ) { 
    444                 $post->pubdate = HabariDateTime::date_create(); 
    445             } 
    446             // else let the user change the publication date. 
    447             //  If previously published and the new date is in the future, the post will be unpublished and scheduled. Any other status, and the post will just get the new pubdate. 
    448             // This will result in the post being scheduled for future publication if the date/time is in the future and the new status is published. 
    449             else { 
    450                 $post->pubdate = HabariDateTime::date_create( $form->pubdate->value ); 
    451             } 
    452  
    453             $post->status = $form->status->value; 
    454         } 
    455         else { 
    456             $postdata = array( 
    457                 'slug' => $form->newslug->value, 
    458                 'title' => $form->title->value, 
    459                 'tags' => $form->tags->value, 
    460                 'content' => $form->content->value, 
    461                 'user_id' => User::identify()->id, 
    462                 'pubdate' => HabariDateTime::date_create($form->pubdate->value), 
    463                 'status' => $form->status->value, 
    464                 'content_type' => $form->content_type->value, 
    465             ); 
    466  
    467             $post = Post::create( $postdata ); 
    468         } 
    469  
    470         if( $post->pubdate->int > HabariDateTime::date_create()->int && $post->status == Post::status( 'published' ) ) { 
    471             $post->status = Post::status( 'scheduled' ); 
    472         } 
    473  
    474         $post->info->comments_disabled = !$form->comments_enabled->value; 
    475  
    476         Plugins::act('publish_post', $post, $form); 
    477  
    478         $post->update( $form->minor_edit->value ); 
    479  
    480         Session::notice( sprintf( _t( 'The post %1$s has been saved as %2$s.' ), sprintf('<a href="%1$s">\'%2$s\'</a>', $post->permalink, $post->title), Post::status_name( $post->status ) ) ); 
    481         Utils::redirect( URL::get( 'admin', 'page=publish&id=' . $post->id ) ); 
    482     } 
    483  
    484     public function get_publish( $template = 'publish') 
    485     { 
    486         $extract = $this->handler_vars->filter_keys('id', 'content_type'); 
    487         foreach($extract as $key => $value) { 
    488             $$key = $value; 
    489         } 
    490  
    491         if ( isset( $id ) ) { 
    492             $post = Post::get( array( 'id' => $id, 'status' => Post::status( 'any' ) ) ); 
    493             $this->theme->post = $post; 
    494             $this->theme->newpost = false; 
    495         } 
    496         else { 
    497             $post = new Post(); 
    498             $this->theme->post = $post; 
    499             $post->content_type = Post::type( ( isset( $content_type ) ) ? $content_type : 'entry' ); 
    500             $this->theme->newpost = true; 
    501         } 
    502  
    503         $this->theme->admin_page = sprintf(_t('Publish %s'), ucwords(Post::type_name($post->content_type))); 
    504  
    505         $statuses = Post::list_post_statuses( false ); 
    506         $this->theme->statuses = $statuses; 
    507  
    508         $this->theme->form = $this->form_publish($post, $this->theme->newpost ); 
    509  
    510         $this->theme->wsse = Utils::WSSE(); 
    511  
    512         $this->display( $template ); 
    513     } 
    514  
    515     public function form_publish($post, $newpost = true) 
    516     { 
    517         $form = new FormUI('create-content'); 
    518         $form->set_option( 'form_action', URL::get('admin', 'page=publish' ) ); 
    519         $form->class[] = 'create'; 
    520  
    521         if( isset( $this->handler_vars['id'] ) ) { 
    522             $post_links = $form->append('wrapper', 'post_links'); 
    523             $post_links->append('static', 'post_permalink', '<a href="'.$post->permalink.( $post->statusname == 'draft' ? '?preview=1' : '' ).'" class="viewpost" onclick="$(this).attr(\'target\', \'preview\');">'.( $post->statusname == 'draft' ? _t('Preview Post') : _t('View Post') ).'</a>'); 
    524             $post_links->class ='container'; 
    525         } 
    526  
    527         // Create the Title field 
    528         $form->append('text', 'title', 'null:null', _t('Title'), 'admincontrol_text'); 
    529         $form->title->class = 'important'; 
    530         $form->title->tabindex = 1; 
    531         $form->title->value = $post->title; 
    532         $this->theme->admin_page = sprintf(_t('Publish %s'), ucwords(Post::type_name($post->content_type))); 
    533         // Create the silos 
    534         if ( count( Plugins::get_by_interface( 'MediaSilo' ) ) ) { 
    535             $form->append('silos', 'silos'); 
    536             $form->silos->silos = Media::dir(); 
    537         } 
    538  
    539         // Create the Content field 
    540         $form->append('textarea', 'content', 'null:null', _t('Content'), 'admincontrol_textarea'); 
    541         $form->content->class[] = 'resizable'; 
    542         $form->content->tabindex = 2; 
    543         $form->content->value = $post->content; 
    544         $form->content->raw = true; 
    545  
    546         // Create the tags field 
    547         $form->append('text', 'tags', 'null:null', _t('Tags, separated by, commas'), 'admincontrol_text'); 
    548         $form->tags->tabindex = 3; 
    549         $form->tags->value = implode(', ', $post->tags); 
    550  
    551         // Create the splitter 
    552         $publish_controls = $form->append('tabs', 'publish_controls'); 
    553  
    554         // Create the publishing controls 
    555         // pass "false" to list_post_statuses() so that we don't include internal post statuses 
    556         $statuses = Post::list_post_statuses( false ); 
    557         unset( $statuses[array_search( 'any', $statuses )] ); 
    558         $statuses = Plugins::filter( 'admin_publish_list_post_statuses', $statuses ); 
    559  
    560         $settings = $publish_controls->append('fieldset', 'settings', _t('Settings')); 
    561  
    562         $settings->append('select', 'status', 'null:null', _t('Content State'), array_flip($statuses), 'tabcontrol_select'); 
    563         $settings->status->value = $post->status; 
    564  
    565         if ( $newpost ) { 
    566             // hide the field 
    567             $settings->append('hidden', 'minor_edit', 'null:null'); 
    568             $settings->minor_edit->value = false; 
    569         } 
    570         else { 
    571             $settings->append('checkbox', 'minor_edit', 'null:null', _t('Minor Edit'), 'tabcontrol_checkbox'); 
    572             $settings->minor_edit->value = true; 
    573         } 
    574  
    575         $settings->append('checkbox', 'comments_enabled', 'null:null', _t('Comments Allowed'), 'tabcontrol_checkbox'); 
    576         $settings->comments_enabled->value = $post->info->comments_disabled ? false : true; 
    577  
    578         $settings->append('text', 'pubdate', 'null:null', _t('Publication Time'), 'tabcontrol_text'); 
    579         $settings->pubdate->value = $post->pubdate->format('Y-m-d H:i:s'); 
    580  
    581         $settings->append('text', 'newslug', 'null:null', _t('Content Address'), 'tabcontrol_text'); 
    582         $settings->newslug->value = $post->slug; 
    583  
    584         // Create the button area 
    585         $buttons = $form->append('fieldset', 'buttons'); 
    586         $buttons->template = 'admincontrol_buttons'; 
    587         $buttons->class[] = 'container'; 
    588         $buttons->class[] = 'buttons'; 
    589         $buttons->class[] = 'publish'; 
    590  
    591         // Create the Save button 
    592         $buttons->append('submit', 'save', _t('Save'), 'admincontrol_submit'); 
    593         $buttons->save->tabindex = 4; 
    594  
    595         // Add required hidden controls 
    596         $form->append('hidden', 'content_type', 'null:null'); 
    597         $form->content_type->value = $post->content_type; 
    598         $form->append('hidden', 'post_id', 'null:null'); 
    599         $form->post_id->id = 'id'; 
    600         if ( $newpost ) { 
    601             $form->post_id->value= 0; 
    602         } else { 
    603             $form->post_id->value= $this->handler_vars['id']; 
    604         } 
    605         $form->append('hidden', 'slug', 'null:null'); 
    606         $form->slug->value = $post->slug; 
    607  
    608         // Let plugins alter this form 
    609         Plugins::act('form_publish', $form, $post); 
    610  
    611         // Put the form into the theme 
    612         $this->theme->form = $form->get(); 
    613         return $form; 
    614     } 
    615  
    616     /** 
    617      * Deletes a post from the database. 
    618      */ 
    619     public function post_delete_post() 
    620     { 
    621         $extract = $this->handler_vars->filter_keys('id', 'nonce', 'timestamp', 'PasswordDigest'); 
    622         foreach($extract as $key => $value) { 
    623             $$key = $value; 
    624         } 
    625  
    626         $okay = TRUE; 
    627         if ( empty( $id ) || empty( $nonce ) || empty( $timestamp ) || empty( $PasswordDigest ) ) { 
    628             $okay = FALSE; 
    629         } 
    630         $wsse = Utils::WSSE( $nonce, $timestamp ); 
    631         if ( $digest != $wsse['digest'] ) { 
    632             $okay = FALSE; 
    633         } 
    634         if ( !$okay )   { 
    635             Utils::redirect( URL::get( 'admin', 'page=posts&type='. Post::status( 'any' ) ) ); 
    636         } 
    637         $post = Post::get( array( 'id' => $id, 'status' => Post::status( 'any' ) ) ); 
    638         $post->delete(); 
    639         Session::notice( sprintf( _t( 'Deleted the %1$s titled "%2$s".' ), Post::type_name( $post->content_type ), $post->title ) ); 
    640         Utils::redirect( URL::get( 'admin', 'page=posts&type=' . Post::status( 'any' ) ) ); 
    641     } 
    642  
    643     public function get_user() 
    644     { 
    645         // Get author list 
    646         $author_list = Users::get_all(); 
    647         $authors[0] = _t('nobody'); 
    648         foreach ( $author_list as $author ) { 
    649             $authors[ $author->id ]= $author->displayname; 
    650         } 
    651         $this->theme->authors = $authors; 
    652  
    653         $this->theme->currentuser = User::identify(); 
    654  
    655         $this->theme->wsse = Utils::WSSE(); 
    656  
    657         $this->theme->display('user'); 
    658  
    659     } 
    660  
    661     /** 
    662      * Handles post requests from the user profile page. 
    663      */ 
    664     public function post_user() 
    665     { 
    666         $extract = $this->handler_vars->filter_keys('nonce', 'timestamp', 'PasswordDigest'); 
    667         foreach($extract as $key => $value) { 
    668             $$key = $value; 
    669         } 
    670  
    671         $wsse = Utils::WSSE( $nonce, $timestamp ); 
    672         if ( $PasswordDigest != $wsse['digest'] ) { 
    673             Utils::redirect( URL::get( 'admin', 'page=users' ) ); 
    674         } 
    675  
    676         // Keep track of whether we actually need to update any fields 
    677         $update = FALSE; 
    678         $results = array( 'page' => 'user' ); 
    679         $currentuser = User::identify(); 
    680  
    681         $fields = array( 'user_id' => 'id', 'delete' => NULL, 'username' => 'username', 'displayname' => 'displayname', 'email' => 'email', 'imageurl' => 'imageurl', 'pass1' => NULL, 'locale_tz' => 'locale_tz', 'locale_date_format' => 'locale_date_format', 'locale_time_format' => 'locale_time_format' ); 
    682         $fields = Plugins::filter( 'adminhandler_post_user_fields', $fields ); 
    683         $posted_fields = $this->handler_vars->filter_keys( array_keys( $fields ) ); 
    684  
    685         // Editing someone else's profile? If so, load that user's profile 
    686         if ( isset($user_id) && ($currentuser->id != $user_id) ) { 
    687             $user = User::get_by_id( $user_id ); 
    688             $results['user']= $user->username; 
    689         } 
    690         else { 
    691             $user = $currentuser; 
    692         } 
    693  
    694         foreach ( $posted_fields as $posted_field => $posted_value ) { 
    695             switch ( $posted_field ) { 
    696                 case 'delete': // Deleting a user 
    697                         if ( isset( $user_id ) && ( $currentuser->id != intval( $user_id ) ) ) { 
    698                             $username = $user->username; 
    699                             $posts = Posts::get( array( 'user_id' => $user_id, 'nolimit' => 1 ) ); 
    700                             if ( isset( $reassign ) && ( 1 === intval( $reassign ) ) ) { 
    701                                 // we're going to re-assign all of this user's posts 
    702                                 $newauthor = isset( $author ) ? intval( $author ) : 1; 
    703                                 Posts::reassign( $newauthor, $posts ); 
    704                             } 
    705                             else { 
    706                                 // delete posts 
    707                                 foreach ( $posts as $post ) { 
    708                                     $post->delete(); 
    709                                 } 
    710                             } 
    711                             $user->delete(); 
    712                             Session::notice( sprintf( _t( '%s has been deleted' ), $username ) ); 
    713                         } 
    714                     // redirect to main user list 
    715             &n