Plugin Directory

Changeset 619608


Ignore:
Timestamp:
10/31/2012 08:47:52 PM (13 years ago)
Author:
jascott
Message:

Updated import-comments

Location:
kickpress/trunk
Files:
3 edited

Legend:

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

    r618659 r619608  
    25652565            }
    25662566           
    2567             unset( $comments, $comment);
     2567            unset( $comments, $comment );
    25682568           
    25692569            ksort( $nodes );
     
    25872587    }
    25882588   
    2589     public function export_comments_debug( $comments ) {
     2589    private function export_comment_node( $comment ) {
     2590        $node = (object) array(
     2591            'id'      => $comment->comment_ID,
     2592            'post_id' => $comment->comment_post_ID,
     2593            'date'    => date( DATE_RSS, strtotime( $comment->comment_date ) )
     2594        );
     2595       
     2596        if ( isset( $comment->comment_modified ) )
     2597            $node->modified = date( DATE_RSS,
     2598                strtotime( $comment->comment_modified ) );
     2599       
     2600        $node->author = (object) array(
     2601            'name'  => $comment->comment_author,
     2602            'email' => $comment->comment_author_email,
     2603            'url'   => $comment->comment_author_url
     2604        );
     2605       
     2606        if ( isset( $comment->comment_title ) )
     2607            $node->title = $comment->comment_title;
     2608               
     2609        $node->content  = $comment->comment_content;
     2610        $node->comments = array();
     2611       
     2612        if ( ! empty( $comment->comments ) ) {
     2613            foreach ( $comment->comments as $child_comment ) {
     2614                $node->comments[] = $this->export_comment_node( $child_comment );
     2615            }
     2616        }
     2617       
     2618        return $node;
     2619    }
     2620   
     2621    private function export_comments_debug( $comments ) {
    25902622        header( 'Content-Type: text/plain' );
    2591        
     2623        //die( rawurlencode( '[{"id":"191","post_id":"1340","date":"Wed, 31 Oct 2012 13:27:19 +0000","modified":"Wed, 31 Oct 2012 13:27:19 +0000","author":{"name":"Andrew Scott","email":"ascott@rbc.org","url":"http:\/\/rubberchickenfarm.com"},"content":"Bookmark: Privacy Policy","status":"trash"}]' ) );
    25922624        print_r( $comments );
    25932625    }
     
    25972629       
    25982630        foreach ( $comments as $comment ) {
    2599             $json_array[] = $this->export_comment_node_json( $comment );
     2631            $json_array[] = $this->export_comment_node( $comment );
    26002632        }
    26012633       
     
    26102642        if ( isset( $_GET['callback'] ) )
    26112643            echo ');';
    2612     }
    2613    
    2614     private function export_comment_node_json( $comment ) {
    2615         $json_object = (object) array(
    2616             'id'      => $comment->comment_ID,
    2617             'post_id' => $comment->comment_post_ID,
    2618             'date'    => date( DATE_RSS, strtotime( $comment->comment_date ) ),
    2619             'author'  => (object) array(
    2620                 'name'  => $comment->comment_author,
    2621                 'email' => $comment->comment_author_email,
    2622                 'url'   => $comment->comment_author_url
    2623             )
    2624         );
    2625        
    2626         if ( isset( $comment->comment_title ) )
    2627             $json_object->title = $comment->comment_title;
    2628                
    2629         $json_object->content = $comment->comment_content;
    2630        
    2631         if ( isset( $comment->comment_modified ) )
    2632             $json_object->modified = date( DATE_RSS, strtotime( $comment->comment_modified ) );
    2633        
    2634         if ( ! empty( $comment->comments ) ) {
    2635             $json_object->comments = array();
    2636            
    2637             foreach ( $comment->comments as $child_comment ) {
    2638                 $json_object->comments[] = $this->export_comment_node_json( $child_comment );
    2639             }
    2640         }
    2641        
    2642         return $json_object;
    26432644    }
    26442645   
     
    26512652       
    26522653        foreach ( $comments as $comment ) {
    2653             $node = $this->export_comment_node_xml( $comment );
     2654            $node = $this->export_comment_node( $comment );
     2655            $node = $this->export_comment_node_xml( $node );
    26542656            $root->appendChild( $doc->importNode( $node, true ) );
    26552657        }
     
    26602662    }
    26612663   
    2662     public function export_comment_node_xml( $comment ) {
     2664    private function export_comment_node_xml( $node ) {
    26632665        $doc = new DOMDocument( '1.0', 'UTF-8' );
    26642666        $doc->preserveWhiteSpace = true;
     
    26662668       
    26672669        $root = $doc->appendChild( $doc->createElement( 'comment' ) );
    2668         $root->setAttribute( 'id', $comment->comment_ID );
    2669         $root->setAttribute( 'post_id', $comment->comment_post_ID );
     2670        $root->setAttribute( 'id', $node->id );
     2671        $root->setAttribute( 'post_id', $node->post_id );
    26702672       
    26712673        /* if ( 0 < $comment->comment_parent )
    2672             $root->setAttribute( 'parent-id', $comment->comment_parent ); */
    2673        
    2674         $root->appendChild( $doc->createElement( 'date',
    2675             date( DATE_RSS, strtotime( $comment->comment_date ) ) ) );
     2674            $root->setAttribute( 'parent_id', $comment->comment_parent ); */
     2675       
     2676        $root->appendChild( $doc->createElement( 'date', $node->date ) );
    26762677       
    26772678        if ( isset( $comment->comment_modified ) )
    2678             $root->appendChild( $doc->createElement( 'modified',
    2679                 date( DATE_RSS, strtotime( $comment->comment_modified ) ) ) );
     2679            $root->appendChild( $doc->createElement( 'modified', $node->modified ) );
    26802680       
    26812681        $author = $root->appendChild( $doc->createElement( 'author' ) );
    2682         $author->appendChild( $doc->createElement( 'name',  $comment->comment_author ) );
    2683         $author->appendChild( $doc->createElement( 'email', $comment->comment_author_email ) );
    2684         $author->appendChild( $doc->createElement( 'url',   $comment->comment_author_url ) );
    2685        
    2686         if ( isset( $comment->comment_title ) ) {
     2682        $author->appendChild( $doc->createElement( 'name',  $node->author->name ) );
     2683        $author->appendChild( $doc->createElement( 'email', $node->author->email ) );
     2684        $author->appendChild( $doc->createElement( 'url',   $node->author->url ) );
     2685       
     2686        if ( isset( $node->title ) ) {
    26872687            $title = $root->appendChild( $doc->createElement( 'title' ) );
    2688             $title->appendChild( $doc->createCDATASection( $comment->comment_title ) );
     2688            $title->appendChild( $doc->createCDATASection( $node->title ) );
    26892689        }
    26902690       
    26912691        $content = $root->appendChild( $doc->createElement( 'content' ) );
    2692         $content->appendChild( $doc->createCDATASection( $comment->comment_content ) );
    2693        
    2694         if ( ! empty( $comment->comments ) ) {
     2692        $content->appendChild( $doc->createCDATASection( $node->content ) );
     2693       
     2694        if ( ! empty( $node->comments ) ) {
    26952695            $children = $root->appendChild( $doc->createElement( 'comments' ) );
    26962696           
    2697             foreach ( $comment->comments as $child_comment ) {
     2697            foreach ( $node->comments as $child_comment ) {
    26982698                $node = $this->export_comment_node_xml( $child_comment );
    26992699                $children->appendChild( $doc->importNode( $node, true ) );
     
    27142714       
    27152715        if ( 'xml' == $format ) {
    2716             $comments = $this->import_comments_xml( $_REQUEST['data'] );
     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            );
    27172733        } else {
    2718             $comments = $this->import_comments_json( $_REQUEST['data'] );
    2719         }
    2720        
    2721         if ( is_array( $comments ) ) {
     2734            $new_comments = $this->import_comments_json( $_REQUEST['data'] );
     2735        }
     2736       
     2737        $comments = array();
     2738       
     2739        foreach ( $new_comments as &$comment ) {
     2740            if ( empty( $comment->modified ) )
     2741                $comment->modified = $comment->date;
     2742           
     2743            $comments[$comment->id]['new'] =& $comment;
     2744        }
     2745       
     2746        unset ( $comment );
     2747       
     2748        if ( in_array( $action_key, array( 'bookmarks', 'notes' ) ) ) {
     2749            $old_comments = call_user_func( "kickpress_get_{$action_key}" );
     2750           
     2751            foreach ( $old_comments as &$comment ) {
     2752                $comment = $this->export_comment_node( $comment );
     2753                $comments[$comment->id]['old'] =& $comment;
     2754            }
     2755           
     2756            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           
    27222773            if ( 'bookmarks' == $action_key ) {
    2723                 foreach ( $comments as $comment ) {
    2724                     kickpress_insert_bookmark( $comment->post_id );
    2725                 }
     2774                $this->import_bookmark( $comment['new'] );
    27262775            } elseif ( 'notes' == $action_key ) {
    2727                 foreach ( $comments as $comment ) {
    2728                     if ( isset( $comment->id ) && 0 < $comment->id ) {
    2729                         $mod_date = get_comment_meta( $comment->id, '_modified', true );
    2730                        
    2731                         $old_comment = get_comment( $comment->id );
    2732                         $old_comment->comment_modified = empty( $mod_date )
    2733                                      ? $old_comment->comment_date : $mod_date;
    2734                        
    2735                         $save_time = strtotime( $old_comment->comment_modified );
    2736                         $edit_time = strtotime( $comment->modified );
    2737                        
    2738                         if ( $save_time < $edit_time ) {
    2739                             $modified = date( 'Y-m-d H:i:s', $edit_time );
    2740                            
    2741                             kickpress_update_private_comment( $comment->id, array(
    2742                                 'comment_title'    => $comment->title,
    2743                                 'comment_content'  => $comment->content,
    2744                                 'comment_modified' => $modified
    2745                             ) );
    2746                         }
    2747                     } else {
    2748                         kickpress_insert_note( $comment->post_id,
    2749                             $comment->title, $comment->content );
    2750                     }
    2751                 }
    2752             }
    2753         }
     2776                $this->import_note( $comment['new'] );
     2777            }
     2778        }
     2779       
     2780        exit;
    27542781    }
    27552782   
     
    27752802                ),
    27762803                'title'    => trim( (string) $node->title ),
    2777                 'content'  => trim( (string) $node->content )
     2804                'content'  => trim( (string) $node->content ),
     2805                'status'   => (string) $node->status
    27782806            );
    27792807        }
     
    27812809        return $comments;
    27822810    }
     2811   
     2812    private function import_bookmark( $bookmark ) {
     2813        if ( 'trash' == $bookmark->status ) {
     2814            kickpress_delete_bookmark( $bookmark->post_id );
     2815        } else {
     2816            kickpress_insert_bookmark( $bookmark->post_id );
     2817        }
     2818    }
     2819   
     2820    private function import_note( $note ) {
     2821        $offset = get_option( 'gmt_offset' ) * 3600;
     2822       
     2823        if ( 'trash' == $note->status ) {
     2824            kickpress_delete_note( $note->id );
     2825        } elseif ( 0 == $note->id ) {
     2826            $time = strtotime( $note->date ) + $offset;
     2827            $date = gmdate( 'Y-m-d H:i:s', $time );
     2828           
     2829            // using low-level form to force date
     2830            kickpress_insert_private_comment( $note->post_id, array(
     2831                'comment_date'    => $date,
     2832                'comment_title'   => $note->title,
     2833                'comment_content' => $note->content,
     2834                'comment_type'    => 'note'
     2835            ) );
     2836        } else {
     2837            $time = strtotime( $note->modified ) + $offset;
     2838            $date = gmdate( 'Y-m-d H:i:s', $time );
     2839           
     2840            // using low-level form to force modified date
     2841            kickpress_update_private_comment( $note->id, array(
     2842                'comment_modified' => $date,
     2843                'comment_title'    => $note->title,
     2844                'comment_content'  => $note->content,
     2845                'comment_type'     => 'note'
     2846            ) );
     2847        }
     2848    }
     2849   
    27832850    /* Theme/Template Elements */
    27842851
  • kickpress/trunk/kickpress-bookmarks.php

    r599114 r619608  
    136136        $comment_agent        = substr( $_SERVER['HTTP_USER_AGENT'], 0, 254 );
    137137       
    138         $comment_date     = current_time( 'mysql' );
    139         $comment_date_gmt = current_time( 'mysql', 1 );
     138        if ( ! isset ( $comment_date ) )
     139            $comment_date = current_time( 'mysql' );
     140       
     141        $comment_date_gmt = get_gmt_from_date( $comment_date );
    140142       
    141143        $comment_data = compact(
  • kickpress/trunk/kickpress-oauth.php

    r619230 r619608  
    553553            exit;
    554554        }
    555        
     555               
    556556        if ( is_null( $args ) ) $args = self::get_args();
    557557       
Note: See TracChangeset for help on using the changeset viewer.