Changeset 619608
- Timestamp:
- 10/31/2012 08:47:52 PM (13 years ago)
- Location:
- kickpress/trunk
- Files:
-
- 3 edited
-
kickpress-api.php (modified) (10 diffs)
-
kickpress-bookmarks.php (modified) (1 diff)
-
kickpress-oauth.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
kickpress/trunk/kickpress-api.php
r618659 r619608 2565 2565 } 2566 2566 2567 unset( $comments, $comment );2567 unset( $comments, $comment ); 2568 2568 2569 2569 ksort( $nodes ); … … 2587 2587 } 2588 2588 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 ) { 2590 2622 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"}]' ) ); 2592 2624 print_r( $comments ); 2593 2625 } … … 2597 2629 2598 2630 foreach ( $comments as $comment ) { 2599 $json_array[] = $this->export_comment_node _json( $comment );2631 $json_array[] = $this->export_comment_node( $comment ); 2600 2632 } 2601 2633 … … 2610 2642 if ( isset( $_GET['callback'] ) ) 2611 2643 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_url2623 )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;2643 2644 } 2644 2645 … … 2651 2652 2652 2653 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 ); 2654 2656 $root->appendChild( $doc->importNode( $node, true ) ); 2655 2657 } … … 2660 2662 } 2661 2663 2662 p ublic function export_comment_node_xml( $comment) {2664 private function export_comment_node_xml( $node ) { 2663 2665 $doc = new DOMDocument( '1.0', 'UTF-8' ); 2664 2666 $doc->preserveWhiteSpace = true; … … 2666 2668 2667 2669 $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 ); 2670 2672 2671 2673 /* 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 ) ); 2676 2677 2677 2678 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 ) ); 2680 2680 2681 2681 $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 ) ) { 2687 2687 $title = $root->appendChild( $doc->createElement( 'title' ) ); 2688 $title->appendChild( $doc->createCDATASection( $ comment->comment_title ) );2688 $title->appendChild( $doc->createCDATASection( $node->title ) ); 2689 2689 } 2690 2690 2691 2691 $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 ) ) { 2695 2695 $children = $root->appendChild( $doc->createElement( 'comments' ) ); 2696 2696 2697 foreach ( $ comment->comments as $child_comment ) {2697 foreach ( $node->comments as $child_comment ) { 2698 2698 $node = $this->export_comment_node_xml( $child_comment ); 2699 2699 $children->appendChild( $doc->importNode( $node, true ) ); … … 2714 2714 2715 2715 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 ); 2717 2733 } 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 2722 2773 if ( 'bookmarks' == $action_key ) { 2723 foreach ( $comments as $comment ) { 2724 kickpress_insert_bookmark( $comment->post_id ); 2725 } 2774 $this->import_bookmark( $comment['new'] ); 2726 2775 } 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; 2754 2781 } 2755 2782 … … 2775 2802 ), 2776 2803 'title' => trim( (string) $node->title ), 2777 'content' => trim( (string) $node->content ) 2804 'content' => trim( (string) $node->content ), 2805 'status' => (string) $node->status 2778 2806 ); 2779 2807 } … … 2781 2809 return $comments; 2782 2810 } 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 2783 2850 /* Theme/Template Elements */ 2784 2851 -
kickpress/trunk/kickpress-bookmarks.php
r599114 r619608 136 136 $comment_agent = substr( $_SERVER['HTTP_USER_AGENT'], 0, 254 ); 137 137 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 ); 140 142 141 143 $comment_data = compact( -
kickpress/trunk/kickpress-oauth.php
r619230 r619608 553 553 exit; 554 554 } 555 555 556 556 if ( is_null( $args ) ) $args = self::get_args(); 557 557
Note: See TracChangeset
for help on using the changeset viewer.