Plugin Directory

Changeset 621437


Ignore:
Timestamp:
11/05/2012 09:37:50 PM (13 years ago)
Author:
jascott
Message:

OAuth updates

Location:
kickpress/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • kickpress/trunk/kickpress-api.php

    r619608 r621437  
    17521752        ) );
    17531753       
     1754        $uri = implode( '/', array(
     1755            get_bloginfo( 'url' ),
     1756            kickpress_get_api_trigger(),
     1757            sprintf( "%s[%s]/",
     1758                $this->params['action'],
     1759                $this->params['action_key']
     1760            )
     1761        ) );
     1762       
    17541763        $query = 'POST' == $method ? $_POST : $_GET;
    17551764       
     
    27132722        $post_type = $this->params['post_type'];
    27142723       
    2715         if ( 'xml' == $format ) {
    2716             $new_comments = $this->import_comments_xml( $_REQUEST['data'] );
    2717         } elseif ( 'debug' == $format ) {
    2718             $new_comments = array (
    2719                 (object) array(
    2720                     'id'       => '191',
    2721                     'post_id'  => '1340',
    2722                     'date'     => 'Wed, 31 Oct 2012 13:27:19 +0000',
    2723                     'modified' => 'Wed, 31 Oct 2012 13:27:19 +0000',
    2724                     'author'   => (object) array(
    2725                         'name'  => 'Andrew Scott',
    2726                         'email' => 'ascott@rbc.org',
    2727                         'url'   => 'http://rubberchickenfarm.com'
    2728                     ),
    2729                     'content'  => 'Bookmark: Privacy Policy',
    2730                     'status'   => 'deleted'
    2731                 )
    2732             );
    2733         } else {
    2734             $new_comments = $this->import_comments_json( $_REQUEST['data'] );
    2735         }
     2724        $func = array( $this, "import_comments_{$format}" );
     2725        $args = $_REQUEST['data'];
     2726       
     2727        if ( is_callable( $func ) )
     2728            $new_comments = call_user_func( $func, $args );
     2729        else return;
    27362730       
    27372731        $comments = array();
     
    27412735                $comment->modified = $comment->date;
    27422736           
    2743             $comments[$comment->id]['new'] =& $comment;
     2737            if ( 0 < $comment->id )
     2738                $comments[$comment->id]['new'] =& $comment;
     2739            else
     2740                $comments['new'][] =& $comment;
    27442741        }
    27452742       
     
    27552752           
    27562753            unset( $comment );
    2757         }
    2758        
    2759         foreach ( $comments as $comment_id => $comment ) {
    2760             if ( ! isset( $comment['new'] ) ) {
    2761                 // no new comment, skip ahead
    2762                 continue;
    2763             } elseif ( ! isset( $comment['old'] ) ) {
    2764                 // insert comment
    2765             } else {
    2766                 $old_mod_date = strtotime( $comment['old']->modified );
    2767                 $new_mod_date = strtotime( $comment['new']->modified );
    2768                 if ( $new_mod_date <= $old_mod_date )
    2769                     // keep old comment, skip ahead
    2770                     continue;
    2771             }
    2772            
    2773             if ( 'bookmarks' == $action_key ) {
    2774                 $this->import_bookmark( $comment['new'] );
    2775             } elseif ( 'notes' == $action_key ) {
    2776                 $this->import_note( $comment['new'] );
     2754           
     2755            $type = substr( $action_key, 0, -1 );
     2756            $func = array( $this, "import_{$type}" );
     2757           
     2758            if ( is_callable( $func ) ) {
     2759                foreach ( $comments['new'] as $comment ) {
     2760                    call_user_func( $func, $comment );
     2761                }
     2762               
     2763                unset( $comments['new'] );
     2764               
     2765                foreach ( $comments as $comment_id => $comment ) {
     2766                    if ( ! isset( $comment['new'] ) ) {
     2767                        // no new comment, skip ahead
     2768                        continue;
     2769                    } elseif ( ! isset( $comment['old'] ) ) {
     2770                        // no old comment, continue
     2771                    } else {
     2772                        $old_mod_date = strtotime( $comment['old']->modified );
     2773                        $new_mod_date = strtotime( $comment['new']->modified );
     2774                        if ( $new_mod_date <= $old_mod_date )
     2775                            // keep old comment, skip ahead
     2776                            continue;
     2777                    }
     2778                   
     2779                    call_user_func( $func, $comment['new'] );
     2780                }
    27772781            }
    27782782        }
     
    27922796        foreach ( $sxe->comment as $node ) {
    27932797            $comments[] = (object) array(
    2794                 'id'       => (string) $node['id'],
    2795                 'post_id'  => (string) $node['post_id'],
    2796                 'date'     => (string) $node->date,
    2797                 'modified' => (string) $node->modified,
    2798                 'author'   => (object) array(
     2798                'id'        => (string) $node['id'],
     2799                'mobile_id' => (string) $node['mobile_id'],
     2800                'post_id'   => (string) $node['post_id'],
     2801                'date'      => (string) $node->date,
     2802                'modified'  => (string) $node->modified,
     2803                'author'    => (object) array(
    27992804                    'name'  => (string) $node->author->name,
    28002805                    'email' => (string) $node->author->email,
    28012806                    'url'   => (string) $node->author->url
    28022807                ),
    2803                 'title'    => trim( (string) $node->title ),
    2804                 'content'  => trim( (string) $node->content ),
    2805                 'status'   => (string) $node->status
     2808                'title'     => trim( (string) $node->title ),
     2809                'content'   => trim( (string) $node->content ),
     2810                'status'    => (string) $node->status
    28062811            );
    28072812        }
    28082813       
    28092814        return $comments;
     2815    }
     2816   
     2817    private function import_comments_debug( $text ) {
     2818        return array (
     2819            (object) array(
     2820                'id'        => '191',
     2821                'mobile_id' => '17',
     2822                'post_id'   => '1340',
     2823                'date'      => 'Wed, 31 Oct 2012 13:27:19 +0000',
     2824                'modified'  => 'Wed, 31 Oct 2012 13:27:19 +0000',
     2825                'author'    => (object) array(
     2826                    'name'  => 'Andrew Scott',
     2827                    'email' => 'ascott@rbc.org',
     2828                    'url'   => 'http://rubberchickenfarm.com'
     2829                ),
     2830                'content'   => 'Bookmark: Privacy Policy',
     2831                'status'    => 'trash'
     2832            )
     2833        );
    28102834    }
    28112835   
     
    28132837        if ( 'trash' == $bookmark->status ) {
    28142838            kickpress_delete_bookmark( $bookmark->post_id );
     2839           
     2840            // populate action result
    28152841        } else {
    28162842            kickpress_insert_bookmark( $bookmark->post_id );
     2843           
     2844            // populate action result
    28172845        }
    28182846    }
     
    28232851        if ( 'trash' == $note->status ) {
    28242852            kickpress_delete_note( $note->id );
     2853           
     2854            // populate action result
    28252855        } elseif ( 0 == $note->id ) {
    28262856            $time = strtotime( $note->date ) + $offset;
     
    28342864                'comment_type'    => 'note'
    28352865            ) );
     2866           
     2867            // populate action result
    28362868        } else {
    28372869            $time = strtotime( $note->modified ) + $offset;
     
    28452877                'comment_type'     => 'note'
    28462878            ) );
     2879           
     2880            // populate action result
    28472881        }
    28482882    }
  • kickpress/trunk/kickpress-oauth.php

    r619608 r621437  
    530530        }
    531531       
    532         $auth = @trim( $_SERVER['HTTP_AUTHORIZATION'] );
     532        $auth = @trim( stripslashes( $_SERVER['HTTP_AUTHORIZATION'] ) );
    533533       
    534534        if ( stripos( $auth, 'OAuth' ) === 0 ) {
     
    611611                        }
    612612                    }
    613                
     613                   
    614614                    if ( ! empty( $token ) && ! empty( $token_secret ) ) {
    615615                        $provider->set_token( $token, $token_secret );
    616616                        $consumer->set_token( $token, $token_secret );
    617617                    } else {
    618                         return new WP_Error( 'invalid_request',
    619                             'Failed to validate oauth token' );
     618                        /* return new WP_Error( 'invalid_request',
     619                            'Failed to validate oauth token' ); */
    620620                    }
    621621                }
     
    699699            ) );
    700700           
    701             // var_dump( $oauth_signature, $proof_signature );
    702            
    703701            return $oauth_signature == $proof_signature;
    704702        }
Note: See TracChangeset for help on using the changeset viewer.