Plugin Directory

Changeset 599114


Ignore:
Timestamp:
09/14/2012 09:59:45 PM (14 years ago)
Author:
jascott
Message:

General upkeep

Location:
kickpress/trunk
Files:
6 edited

Legend:

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

    r595539 r599114  
    3838            'callback'         => '',
    3939            'label'            => 'OAuth 1.0a',
     40            'capability'       => ''
     41        ),
     42        'register'       => array(
     43            'slug'             => 'register',
     44            'method'           => 'register',
     45            'callback'         => '',
     46            'label'            => 'Register User',
    4047            'capability'       => ''
    4148        ),
     
    6168            'capability'       => 'read'
    6269        ),
    63         'export-comments'         => array(
     70        'export-comments' => array(
    6471            'slug'             => 'export-comments',
    6572            'method'           => 'export_comments',
    6673            'callback'         => '',
    6774            'label'            => 'Export Comments',
     75            'capability'       => 'read'
     76        ),
     77        'import-comments' => array(
     78            'slug'             => 'import-comments',
     79            'method'           => 'import_comments',
     80            'callback'         => '',
     81            'label'            => 'Import Comments',
    6882            'capability'       => 'read'
    6983        ),
     
    208222
    209223        $default_params = array(
    210             'post_type'          => null,
    211             'action'             => null
     224            'post_type' => null,
     225            'action'    => null
    212226        );
    213227
     
    229243        // Initialize custom post type options
    230244        $this->init_post_type_options();
     245    }
     246
     247    public function __get( $key ) {
     248        return @$this->params[$key];
     249    }
     250   
     251    public function __isset( $key ) {
     252        return isset( $this->params[$key] );
    231253    }
    232254
     
    886908            $post = array_shift( get_posts( array(
    887909                'post_type' => $this->params['post_type'],
    888                 'name' => $this->params['post_name']
     910                'name'      => $this->params['post_name']
    889911            ) ) );
    890912           
     
    894916        if ( is_null( $action ) ) $action = $this->params['action'];
    895917       
    896         if ( $current_action = $this->get_current_action($action) ) {
     918        if ( $current_action = $this->get_current_action( $action ) ) {
    897919            extract( $current_action );
    898920           
     
    900922
    901923            if ( $post_type = get_post_type_object( $this->params['post_type'] ) ) {
    902                 if ( isset($post_type->cap->$capability) )
     924                if ( isset( $post_type->cap->$capability ) )
    903925                    $capability = $post_type->cap->$capability;
    904926            }
    905927
    906928            $this->params['callback'] = $callback;
    907 
     929           
    908930            // Validate that the user has permission to perform this action
    909931            if ( ! empty( $capability ) && ! current_user_can( $capability ) ) {
     
    969991       
    970992        switch ( $format ) {
    971             case 'xml':
    972                 $doc = new DOMDocument();
    973                 $doc->formatOutput = true;
    974                 $doc->appendChild( $root = $doc->createElement( 'result' ) );
    975                
    976                 $root->appendChild( $doc->createElement( 'status', $this->action_results['status'] ) );
    977                 $root->appendChild( $messages = $doc->createElement( 'messages' ) );
    978                 $root->appendChild( $data = $doc->createElement( 'data' ) );
    979                
    980                 foreach ( $this->action_results['messages'] as $type => $message ) {
    981                     $messages->appendChild( $doc->createElement( $type, $message ) );
    982                 }
    983                
    984                 // TODO write data XML
    985                
    986                 return $doc->saveXML();
    987             case 'json':
    988             default:
    989                 $output = json_encode( $this->action_results );
    990                
    991                 if ( isset( $_REQUEST['callback'] ) )
    992                     $output .= $_REQUEST['callback'] . '(' . $output . ');';
    993                
    994                 return $output;
     993        case 'xml':
     994            $doc = new DOMDocument();
     995            $doc->formatOutput = true;
     996            $doc->appendChild( $root = $doc->createElement( 'result' ) );
     997           
     998            $root->appendChild( $doc->createElement( 'status', $this->action_results['status'] ) );
     999            $root->appendChild( $messages = $doc->createElement( 'messages' ) );
     1000            $root->appendChild( $data = $doc->createElement( 'data' ) );
     1001           
     1002            foreach ( $this->action_results['messages'] as $type => $message ) {
     1003                $messages->appendChild( $doc->createElement( $type, $message ) );
     1004            }
     1005           
     1006            // TODO write data XML
     1007           
     1008            return $doc->saveXML();
     1009        case 'json':
     1010        default:
     1011            $output = json_encode( $this->action_results );
     1012           
     1013            if ( isset( $_REQUEST['callback'] ) )
     1014                $output .= $_REQUEST['callback'] . '(' . $output . ');';
     1015           
     1016            return $output;
    9951017        }
    9961018    }
     
    13801402       
    13811403        switch ( $proxy ) {
    1382             case 'facebook':
    1383                 $this->login_facebook();
    1384                 break;
    1385             case 'twitter':
    1386                 $this->login_twitter();
    1387                 break;
    1388             default:
    1389                 $this->action_results['status'] = 'failure';
    1390                 $this->action_results['messages'][] = 'Unknown login proxy.';
    1391                 $this->action_results['data'][] = $proxy;
    1392                 break;
    1393         }
    1394     }
    1395    
    1396     public function login_facebook() {
     1404        case 'facebook':
     1405            $this->login_facebook();
     1406            break;
     1407        case 'twitter':
     1408            $this->login_twitter();
     1409            break;
     1410        default:
     1411            $this->action_results['status'] = 'failure';
     1412            $this->action_results['messages'][] = 'Unknown login proxy.';
     1413            $this->action_results['data'][] = $proxy;
     1414            break;
     1415        }
     1416    }
     1417   
     1418    private function login_facebook() {
    13971419        global $kickpress_plugin_options;
    13981420       
     
    15201542    }
    15211543   
    1522     public function login_twitter() {
     1544    private function login_twitter() {
    15231545        $log_file = dirname( __FILE__ ) . '/kickpress-twitter.log';
    15241546       
     
    17221744       
    17231745        switch ( strtolower( $this->params['action_key'] ) ) {
    1724             case 'request-token':
    1725                 kickpress_oauth_provider::request_token( $args );
    1726                 break;
    1727             case 'access-token':
    1728                 kickpress_oauth_provider::access_token( $args );
    1729                 break;
    1730             case 'authorize':
     1746        case 'request-token':
     1747            kickpress_oauth_provider::request_token( $args );
     1748            break;
     1749        case 'access-token':
     1750            kickpress_oauth_provider::access_token( $args );
     1751            break;
     1752        case 'authorize':
     1753            kickpress_oauth_provider::authorize( $args );
     1754            break;
     1755        case 'register':
     1756            global $wpdb;
     1757           
     1758            if ( kickpress_is_remote_app() ) {
     1759                add_filter( 'wpmu_signup_user_notification', '__return_false' );
     1760               
     1761                $user_login = $_REQUEST['login'];
     1762                $user_email = $_REQUEST['email'];
     1763               
     1764                if ( empty( $user_email ) )
     1765                    die( 'Email address may not be empty' );
     1766               
     1767                if ( empty( $user_login ) ) $user_login = $user_email;
     1768               
     1769                $user_data = wpmu_validate_user_signup( $user_login, $user_email );
     1770                // unset( $user_data['errors']->errors['user_email_used'] );
     1771               
     1772                if ( is_wp_error( $user_data ) )
     1773                    die( json_encode( $user_data['errors'] ) );
     1774               
     1775                // change password
     1776                $user_password = $_REQUEST['password'];
     1777               
     1778                if ( empty( $user_password ) )
     1779                    die( 'Password may not be empty' );
     1780               
     1781                $user_login = apply_filters( 'pre_user_login',
     1782                    sanitize_user( stripslashes( $user_login ), true ) );
     1783               
     1784                wpmu_signup_user( $user_login, $user_email, array(
     1785                    'add_to_blog' => $wpdb->blogid,
     1786                    'new_role'    => 'subscriber'
     1787                ) );
     1788               
     1789                $key = $wpdb->get_var( $wpdb->prepare(
     1790                    "SELECT activation_key " .
     1791                    "FROM {$wpdb->signups} " .
     1792                    "WHERE user_login = %s " .
     1793                    "AND user_email = %s",
     1794                    $user_login,
     1795                    $user_email
     1796                ) );
     1797               
     1798                // action hook handles first/last name?
     1799                $user_data = wpmu_activate_signup( $key );
     1800               
     1801                if ( is_wp_error( $user_data ) )
     1802                    die( $user_data->get_error_message() );
     1803               
     1804                wp_set_current_user( $user_data['user_id'] );
     1805               
    17311806                kickpress_oauth_provider::authorize( $args );
    1732                 break;
     1807            }
     1808           
     1809            break;
    17331810        }
    17341811       
     
    24452522   
    24462523    public function export_comments() {
    2447         $format = isset( $this->params['action_key'] )
    2448                 ? $this->params['action_key'] : 'json';
    2449        
    2450         if ( empty( $this->params['id'] ) ) exit;
    2451        
    2452         $comments = get_comments( array(
    2453             'post_id' => $this->params['id']
    2454         ) );
    2455        
    2456         $trees = array();
    2457         $nodes = array();
    2458        
    2459         foreach ( $comments as &$comment ) {
    2460             $nodes[$comment->comment_ID] =& $comment;
    2461             $nodes[$comment->comment_ID]->comments = array();
    2462         }
    2463        
    2464         ksort( $nodes );
    2465        
    2466         foreach ( $nodes as &$node ) {
    2467             if ( 0 == $node->comment_parent ) $trees[$node->comment_ID] =& $node;
    2468             else $nodes[$node->comment_parent]->comments[$node->comment_ID] =& $node;
     2524        $action = $this->params['action'];
     2525        $action_key = $this->params['action_key'];
     2526        $format = isset( $this->params['format'] )
     2527                ? $this->params['format'] : 'json';
     2528       
     2529        $post_id   = $this->params['id'];
     2530        $post_type = $this->params['post_type'];
     2531       
     2532        if ( in_array( $action_key, array( 'bookmarks', 'notes' ) ) ) {
     2533            $comments = call_user_func( 'kickpress_get_' . $action_key );
     2534        } else {
     2535            if ( empty( $post_id ) ) exit;
     2536           
     2537            $comments = get_comments( array(
     2538                'post_id' => $post_id
     2539            ) );
     2540           
     2541            $trees = array();
     2542            $nodes = array();
     2543           
     2544            foreach ( $comments as &$comment ) {
     2545                $nodes[$comment->comment_ID] =& $comment;
     2546                $nodes[$comment->comment_ID]->comments = array();
     2547            }
     2548           
     2549            unset( $comments, $comment);
     2550           
     2551            ksort( $nodes );
     2552           
     2553            foreach ( $nodes as &$node ) {
     2554                if ( 0 == $node->comment_parent ) $trees[$node->comment_ID] =& $node;
     2555                else $nodes[$node->comment_parent]->comments[$node->comment_ID] =& $node;
     2556            }
     2557           
     2558            $comments = $trees;
    24692559        }
    24702560       
     
    24742564       
    24752565        if ( method_exists( $this, $method ) )
    2476             call_user_func( array( $this, $method ), $trees );
     2566            call_user_func( array( $this, $method ), $comments );
    24772567       
    24782568        exit;
     
    24862576   
    24872577    private function export_comments_json( $comments ) {
     2578        $json_array = array();
     2579       
    24882580        foreach ( $comments as $comment ) {
    24892581            $json_array[] = $this->export_comment_node_json( $comment );
     
    25052597        $json_object = (object) array(
    25062598            'id'      => $comment->comment_ID,
     2599            'post_id' => $comment->comment_post_ID,
    25072600            'date'    => date( DATE_RSS, strtotime( $comment->comment_date ) ),
    25082601            'author'  => (object) array(
     
    25102603                'email' => $comment->comment_author_email,
    25112604                'url'   => $comment->comment_author_url
    2512             ),
    2513             'content' => $comment->comment_content
     2605            )
    25142606        );
     2607       
     2608        if ( isset( $comment->comment_title ) )
     2609            $json_object->title = $comment->comment_title;
     2610               
     2611        $json_object->content = $comment->comment_content;
     2612       
     2613        if ( isset( $comment->comment_modified ) )
     2614            $json_object->modified = date( DATE_RSS, strtotime( $comment->comment_modified ) );
    25152615       
    25162616        if ( ! empty( $comment->comments ) ) {
     
    25302630        $doc->formatOutput = true;
    25312631       
    2532         $root = $doc->appendChild( $doc->createElement( 'post' ) );
    2533         $root->setAttribute( 'id', $this->params['id'] );
    2534        
    2535         $list = $root->appendChild( $doc->createElement( 'comments' ) );
     2632        $root = $doc->appendChild( $doc->createElement( 'comments' ) );
    25362633       
    25372634        foreach ( $comments as $comment ) {
    25382635            $node = $this->export_comment_node_xml( $comment );
    2539             $list->appendChild( $doc->importNode( $node, true ) );
     2636            $root->appendChild( $doc->importNode( $node, true ) );
    25402637        }
    25412638       
     
    25522649        $root = $doc->appendChild( $doc->createElement( 'comment' ) );
    25532650        $root->setAttribute( 'id', $comment->comment_ID );
     2651        $root->setAttribute( 'post_id', $comment->comment_post_ID );
    25542652       
    25552653        /* if ( 0 < $comment->comment_parent )
    25562654            $root->setAttribute( 'parent-id', $comment->comment_parent ); */
    25572655       
    2558         $root->appendChild( $doc->createElement( 'date', date( DATE_RSS, strtotime( $comment->comment_date ) ) ) );
     2656        $root->appendChild( $doc->createElement( 'date',
     2657            date( DATE_RSS, strtotime( $comment->comment_date ) ) ) );
     2658       
     2659        if ( isset( $comment->comment_modified ) )
     2660            $root->appendChild( $doc->createElement( 'modified',
     2661                date( DATE_RSS, strtotime( $comment->comment_modified ) ) ) );
    25592662       
    25602663        $author = $root->appendChild( $doc->createElement( 'author' ) );
     
    25632666        $author->appendChild( $doc->createElement( 'url',   $comment->comment_author_url ) );
    25642667       
     2668        if ( isset( $comment->comment_title ) ) {
     2669            $title = $root->appendChild( $doc->createElement( 'title' ) );
     2670            $title->appendChild( $doc->createCDATASection( $comment->comment_title ) );
     2671        }
     2672       
    25652673        $content = $root->appendChild( $doc->createElement( 'content' ) );
    25662674        $content->appendChild( $doc->createCDATASection( $comment->comment_content ) );
     
    25782686    }
    25792687
     2688    public function import_comments() {
     2689        $action = $this->params['action'];
     2690        $action_key = $this->params['action_key'];
     2691        $format = isset( $this->params['format'] )
     2692                ? $this->params['format'] : 'json';
     2693       
     2694        $post_id   = $this->params['id'];
     2695        $post_type = $this->params['post_type'];
     2696       
     2697        if ( 'xml' == $format ) {
     2698            $comments = $this->import_comments_xml( $_REQUEST['data'] );
     2699        } else {
     2700            $comments = $this->import_comments_json( $_REQUEST['data'] );
     2701        }
     2702       
     2703        if ( is_array( $comments ) ) {
     2704            if ( 'bookmarks' == $action_key ) {
     2705                foreach ( $comments as $comment ) {
     2706                    kickpress_insert_bookmark( $comment->post_id );
     2707                }
     2708            } elseif ( 'notes' == $action_key ) {
     2709                foreach ( $comments as $comment ) {
     2710                    if ( isset( $comment->id ) && 0 < $comment->id ) {
     2711                        $mod_date = get_comment_meta( $comment->id, '_modified', true );
     2712                       
     2713                        $old_comment = get_comment( $comment->id );
     2714                        $old_comment->comment_modified = empty( $mod_date )
     2715                                     ? $old_comment->comment_date : $mod_date;
     2716                       
     2717                        $save_time = strtotime( $old_comment->comment_modified );
     2718                        $edit_time = strtotime( $comment->modified );
     2719                       
     2720                        if ( $save_time < $edit_time ) {
     2721                            $modified = date( 'Y-m-d H:i:s', $edit_time );
     2722                           
     2723                            kickpress_update_private_comment( $comment->id, array(
     2724                                'comment_title'    => $comment->title,
     2725                                'comment_content'  => $comment->content,
     2726                                'comment_modified' => $modified
     2727                            ) );
     2728                        }
     2729                    } else {
     2730                        kickpress_insert_note( $comment->post_id,
     2731                            $comment->title, $comment->content );
     2732                    }
     2733                }
     2734            }
     2735        }
     2736    }
     2737   
     2738    private function import_comments_json( $json ) {
     2739        return json_decode( stripslashes( $json ) );
     2740    }
     2741   
     2742    private function import_comments_xml( $xml ) {
     2743        $sxe = simplexml_load_string( stripslashes( $xml ) );
     2744       
     2745        $comments = array();
     2746       
     2747        foreach ( $sxe->comment as $node ) {
     2748            $comments[] = (object) array(
     2749                'id'       => (string) $node['id'],
     2750                'post_id'  => (string) $node['post_id'],
     2751                'date'     => (string) $node->date,
     2752                'modified' => (string) $node->modified,
     2753                'author'   => (object) array(
     2754                    'name'  => (string) $node->author->name,
     2755                    'email' => (string) $node->author->email,
     2756                    'url'   => (string) $node->author->url
     2757                ),
     2758                'title'    => trim( (string) $node->title ),
     2759                'content'  => trim( (string) $node->content )
     2760            );
     2761        }
     2762       
     2763        return $comments;
     2764    }
    25802765    /* Theme/Template Elements */
    25812766
  • kickpress/trunk/kickpress-bookmarks.php

    r559958 r599114  
    4141   
    4242    foreach ( $comments as $comment ) {
    43         $comment_title = get_comment_meta( $comment->comment_ID, '_title', true );
    44         if ( ! empty( $comment_title ) ) $comment->comment_title = $comment_title;
     43        $title = get_comment_meta( $comment->comment_ID, '_title', true );
     44        if ( ! empty( $title ) ) $comment->comment_title = $title;
     45       
     46        $modified     = get_comment_meta( $comment->comment_ID, '_modified',     true );
     47        $modified_gmt = get_comment_meta( $comment->comment_ID, '_modified_gmt', true );
     48       
     49        if ( ! empty( $modified ) && ! empty( $modified_gmt ) ) {
     50            $comment->comment_modified     = $modified;
     51            $comment->comment_modified_gmt = $modified_gmt;
     52        } else {
     53            $comment->comment_modified     = $comment->comment_date;
     54            $comment->comment_modified_gmt = $comment->comment_date_gmt;
     55        }
    4556    }
    4657   
     
    102113function kickpress_insert_private_comment( $post_id, $data = array() ) {
    103114    if ( is_user_logged_in() && $post = get_post( $post_id ) ) {
    104         extract( $data );
     115        extract( $data, EXTR_SKIP );
    105116       
    106117        $comment_post_ID  = $post->ID;
     
    144155        );
    145156       
    146         if ( isset( $comment_ID ) && $comment_ID > 0 ) {
    147             $comment_data['comment_ID'] = $comment_ID;
    148             wp_update_comment( $comment_data );
    149         } else {
    150             $comment_ID = wp_insert_comment( $comment_data );
    151             $comment_data['comment_ID'] = $comment_ID;
    152         }
     157        $comment_ID = wp_insert_comment( $comment_data );
    153158       
    154159        if ( isset( $comment_title ) )
    155160            update_comment_meta( $comment_ID, '_title', $comment_title );
     161    }
     162}
     163
     164function kickpress_update_private_comment( $comment_id, $data = array() ) {
     165    if ( is_user_logged_in() && $comment = get_comment( $comment_id ) ) {
     166        if ( get_current_user_id() == $comment->user_id ) {
     167            extract( $data, EXTR_SKIP );
     168           
     169            $comment_ID = $comment_id;
     170           
     171            $comment_data = compact(
     172                'comment_ID',
     173                'comment_content'
     174            );
     175           
     176            wp_update_comment( $comment_data );
     177           
     178            if ( isset( $comment_title ) )
     179                update_comment_meta( $comment_ID, '_title', $comment_title );
     180           
     181            if ( ! isset( $comment_modified ) )
     182                $comment_modified = current_time( 'mysql' );
     183           
     184            $comment_modified_gmt = get_gmt_from_date( $comment_modified );
     185           
     186            update_comment_meta( $comment_ID, '_modified',     $comment_modified );
     187            update_comment_meta( $comment_ID, '_modified_gmt', $comment_modified_gmt );
     188        }
    156189    }
    157190}
     
    200233
    201234function kickpress_update_note( $comment_id, $title, $content ) {
    202    
    203     if ( is_user_logged_in() && $note = get_comment( $comment_id ) ) {
    204         kickpress_insert_private_comment( $note->comment_post_ID, array(
    205             'comment_ID'      => $comment_id,
     235    if ( is_user_logged_in() && $comment = get_comment( $comment_id ) ) {
     236        kickpress_update_private_comment( $comment_id, array(
     237            'comment_title'   => $title,
    206238            'comment_content' => $content,
    207239            'comment_type'    => 'note'
  • kickpress/trunk/kickpress-functions.php

    r595539 r599114  
    432432   
    433433    if ( $log = @fopen( $file, 'a' ) ) {
    434         fwrite( $log, date( 'c' ) . "\t" . $data . PHP_EOL );
     434        $line = sprintf(
     435            "%s\t%s\t%s",
     436            date( 'c' ),
     437            KICKPRESS_DEBUG_TOKEN,
     438            $data
     439        );
     440       
     441        fwrite( $log, $line . PHP_EOL );
    435442        fflush( $log );
    436443        fclose( $log );
  • kickpress/trunk/kickpress-oauth.php

    r595581 r599114  
    119119       
    120120        foreach ( $vars as $key => $value ) {
     121            if ( ! is_string( $value ) ) continue;
     122           
    121123            $item = $quotes . rawurlencode( $value ) . $quotes;
    122124           
     
    199201        $query = self::normalize_params( $query );
    200202       
    201         $key = self::normalize_params( array(
     203        /* $key = self::normalize_params( array(
    202204            $this->_consumer_secret,
    203205            $this->_token_secret
     
    205207            'sorted' => false,
    206208            'keyed'  => false
    207         ) );
     209        ) ); */
     210       
     211        $key = sprintf( "%s&%s", $this->consumer_secret, $this->token_secret );
    208212       
    209213        $msg = self::normalize_params( array(
     
    415419        if ( is_null( $args ) ) $args = self::get_args();
    416420       
     421        if ( kickpress_is_remote_app() && ! is_user_logged_in() ) {
     422            $user = wp_authenticate( $_REQUEST['login'], $_REQUEST['password'] );
     423           
     424            if ( is_a( $user, 'WP_User' ) )
     425                wp_set_current_user( $user->ID );
     426            else
     427                die( 'Invalid username/password' );
     428        }
     429       
    417430        if ( $user_id = get_current_user_id() ) {
    418431            $token = $args['query']['oauth_token'];
     
    426439                   
    427440                    $authorize = strtolower( $query['authorize'] );
    428                     unset($query['authorize']);
     441                    unset( $query['authorize'] );
    429442                   
    430443                    // Check for prior authorization
     
    443456                    }
    444457                   
    445                     $url = $oauth->oauth_callback . '?' . http_build_query( $query );
     458                    if ( kickpress_is_remote_app() ) {
     459                        unset( $query['login'], $query['password'] );
     460                        die( self::normalize_params( $query ) );
     461                    }
     462                   
     463                    $url = $oauth->oauth_callback . '?'
     464                         . http_build_query( $query );
    446465                   
    447466                    header( 'Location: ' . $url );
     
    479498        self::$_action = 'authenticate';
    480499       
    481         if ( isset( $_SERVER['HTTP_AUTHORIZATION'] ) ) {
     500        $auth = @trim( $_SERVER['HTTP_AUTHORIZATION'] );
     501       
     502        if ( stripos( $auth, 'OAuth' ) === 0 ) {
    482503            $consumer = self::validate_consumer( $args );
    483504           
    484             if ( ! is_wp_error( $consumer ) )
    485                 wp_set_current_user( $consumer->user_id );
     505            if ( ! is_wp_error( $consumer ) ) {
     506                define( 'REMOTE_APP_TOKEN', $consumer->consumer_key );
     507               
     508                if ( 0 < $consumer->user_id )
     509                    wp_set_current_user( $consumer->user_id );
     510            }
    486511        }
    487512    }
     
    534559                        }
    535560                    } elseif ( 'authenticate' == self::$_action ) {
    536                         $meta = kickpress_user_meta_query( 0,
    537                             'kickpress\_oauth\_access\_token\_%',
    538                             array( 'oauth_token' => $token ) );
    539                        
    540                         if ( $meta = array_shift( $meta ) ) {
    541                             $token        = $meta->oauth_token;
    542                             $token_secret = $meta->oauth_secret;
     561                        if ( ! empty( $token ) ) {
     562                            $meta = kickpress_user_meta_query( 0,
     563                                'kickpress\_oauth\_access\_token\_%',
     564                                array( 'oauth_token' => $token ) );
    543565                           
    544                             $consumer->set_user_id( $meta->user_id );
    545                             $consumer->set_blog_id( $meta->blog_id );
     566                            if ( $meta = @array_shift( $meta ) ) {
     567                                $token        = $meta->oauth_token;
     568                                $token_secret = $meta->oauth_secret;
     569                               
     570                                $consumer->set_user_id( $meta->user_id );
     571                                $consumer->set_blog_id( $meta->blog_id );
     572                            }
    546573                        }
    547574                    }
     
    551578                        $consumer->set_token( $token, $token_secret );
    552579                    } else {
    553                         return new WP_Error( 'oauth_error',
    554                             'Failed to validate oauth token' );
     580                        /* return new WP_Error( 'oauth_error',
     581                            'Failed to validate oauth token' ); */
    555582                    }
    556583                }
     
    621648        if ( empty( $uri ) ) return false;
    622649       
     650        $uri = str_replace( array( '%5B', '%5D' ), array( '[', ']' ), $uri );
     651       
    623652        if ( $oauth = $this->parse_signature( $signature ) ) {
    624653            $oauth_signature = $oauth['oauth_signature'];
     
    632661            ) );
    633662           
     663            // var_dump( $oauth_signature, $proof_signature );
     664           
    634665            return $oauth_signature == $proof_signature;
    635666        }
  • kickpress/trunk/kickpress-redirects.php

    r595581 r599114  
    159159
    160160        if ( count($query_parts) ) {
    161             // Check whether or not the first parameter is not in the filter array,
     161            // Check whether or not the first parameter is in the filter array,
    162162            // if it is not, we will evaluate if it is a valid post_name to
    163163            // determine if it needs to be loaded as a post
    164164            $first_index = 0;
    165165            $first_param = $query_parts[0];
    166 
    167             // Determine if the return format is passed as part of an action: toggle-term[category].json/featured/
    168             if ( strpos( $first_param, '.' ) !== false ) {
    169                 list( $first_param, $format ) = explode( '.', $first_param );
     166           
     167            // Determine if the return format is passed as part of an action
     168            // eg: toggle-term[category].json/featured/
     169            if ( ( $pos = strrpos( $first_param, '.' ) ) !== false ) {
     170                $format      = substr( $first_param, $pos + 1 );
     171                $first_param = substr( $first_param, 0, $pos );
    170172            } elseif ( isset( $_REQUEST['format'] ) ) {
    171173                if ( ( $pos = strpos( $_REQUEST['format'], '/' ) ) !== false )
     
    176178                $format = null;
    177179            }
    178 
    179             if ( $param_is_array = strpos( $first_param, '[' ) ) {
    180                 $first_param_key = substr( $first_param, $param_is_array + 1, -1 );
    181                 $first_param     = substr( $first_param, 0, $param_is_array );
     180           
     181            if ( ( $pos = strpos( $first_param, '[' ) ) !== false ) {
     182                $first_param_key = substr( $first_param, $pos + 1, -1 );
     183                $first_param     = substr( $first_param, 0, $pos );
     184            } else {
     185                $first_param_key = null;
    182186            }
    183187           
     
    192196                $query_string['action'] = $action;
    193197
    194                 if ( !empty( $format ) )
     198                if ( ! empty( $format ) )
    195199                    $query_string['format'] = $format;
    196200
     
    198202                $kickpress_api->params['format'] = $format;
    199203               
    200                 if ( isset( $first_param_key ) )
     204                if ( ! empty( $first_param_key ) )
    201205                    $kickpress_api->params['action_key'] = $first_param_key;
    202206
     
    213217                $kickpress_api->params['view'] = $view;
    214218                $kickpress_api->params['view_alias'] = $first_param;
     219                $kickpress_api->params['format'] = $format;
    215220            }
    216221
     
    220225               
    221226                foreach ( $query_parts as $query_part_index => $query_part_value ) {
    222                     if ( $query_part_index < $first_index )
    223                         continue;
     227                    if ( $query_part_index < $first_index ) continue;
    224228
    225229                    // Overwrite the defaults if needed with the query string
    226230                    $eval_decoded = urldecode( $query_part_value );
    227231                   
    228                     /* if ( preg_match_all( '/\[(.+)\]/Ui', $eval_decoded, $keys ) && preg_match( '/^[^\[]+/i', $eval_decoded, $names ) ) {
    229                         $new_query_value = array();
    230                         $ptr_query_value =& $new_query_value;
    231                        
    232                         foreach ( $keys[1] as $key ) {
    233                             $ptr_query_value[$key] = null;
    234                             $ptr_query_value =& $ptr_query_value[$key];
    235                         }
    236                        
    237                         echo '<pre>' . print_r( $new_query_value, true ) . '</pre>';
    238                     } */
    239                    
    240232                    // evaluate if an array existes in the query string like: term[category]
    241                     if ( $is_array = strpos( $eval_decoded, '[' ) )
    242                         $eval_query_part = substr( $eval_decoded, 0, $is_array );
     233                    if ( ( $pos = strpos( $eval_decoded, '[' ) ) !== false )
     234                        $eval_query_part = substr( $eval_decoded, 0, $pos );
    243235                    else
    244236                        $eval_query_part = $eval_decoded;
    245237                   
    246238                    // Rebuild the query string with key=value&key=value pairs
    247                     if ( in_array( $eval_query_part, $filter_array ) && isset( $query_parts[$query_part_index + 1] ) ) {
     239                    if ( in_array( $eval_query_part, $filter_array ) &&
     240                        isset( $query_parts[$query_part_index + 1] ) ) {
    248241                        if ( 'search' == $query_part_value ) {
    249242                            $_GET['s'] = $query_parts[$query_part_index + 1];
  • kickpress/trunk/kickpress.php

    r589549 r599114  
    2525        Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA   02110-1301  USA
    2626*/
     27
     28define( 'KICKPRESS_DEBUG_TOKEN',
     29    md5( uniqid( rand(), true ) ) );
     30
     31if ( isset( $_SERVER['HTTP_AUTHORIZATION'] ) )
     32    remove_action('init', 'wp_cron');
    2733
    2834// Global plugin settings
     
    98104require_once(WP_PLUGIN_DIR.'/kickpress/kickpress-application.php');
    99105require_once(WP_PLUGIN_DIR.'/kickpress/kickpress-oauth.php');
    100 require_once(WP_PLUGIN_DIR.'/kickpress/kickpress-curation.php');
     106// require_once(WP_PLUGIN_DIR.'/kickpress/kickpress-curation.php');
    101107
    102108/** Register the kickpress shortcodes */
Note: See TracChangeset for help on using the changeset viewer.