Plugin Directory

Changeset 2660486


Ignore:
Timestamp:
01/20/2022 03:56:24 AM (4 years ago)
Author:
winrid
Message:

3.10.4 - Support for manually syncing back to WordPress. Improvements also made to comment content synced.

Location:
fastcomments
Files:
56 added
6 edited

Legend:

Unmodified
Added
Removed
  • fastcomments/trunk/README.txt

    r2658501 r2660486  
    44Requires at least: 4.6
    55Tested up to: 5.8
    6 Stable tag: 3.10.3
     6Stable tag: 3.10.4
    77Requires PHP: 5.2.4
    88License: GPLv2 or later
     
    8585
    8686== Changelog ==
     87
     88= 3.10.4 =
     89* Support for syncing all of your Comment data from FastComments back to WordPress has been added.
    8790
    8891= 3.10.3 =
  • fastcomments/trunk/admin/fastcomments-admin-view.php

    r2613148 r2660486  
    2222        </a>
    2323        <a href="https://fastcomments.com/auth/my-account/integrations/v1/setup?token=<?php echo get_option("fastcomments_token") ?>&hasAccount=true" target="_blank">
     24            <img src="<?php echo plugin_dir_url( dirname( __FILE__ ) ); ?>/admin/images/sync-status.png" alt="Check Integration Status" title="Check Integration Status"/>
     25            <div>Check Integration Status</div>
     26        </a>
     27        <a href="<?php echo admin_url('admin.php?page=fastcomments&sub_page=manual-sync'); ?>">
    2428            <img src="<?php echo plugin_dir_url( dirname( __FILE__ ) ); ?>/admin/images/sync.png" alt="Manually Run Sync" title="Manually Run Sync"/>
    25             <div>Manually Run Sync</div>
     29            <div>Manually Sync</div>
    2630        </a>
    2731        <a href="<?php echo admin_url('admin.php?page=fastcomments&sub_page=support'); ?>">
  • fastcomments/trunk/admin/fastcomments-admin.php

    r2613148 r2660486  
    7373    );
    7474
    75     $fastcomments_my_account_node_args = array(
     75    $fastcomments_manual_sync_node_args = array(
     76        'parent' => 'fastcomments',
     77        'id' => 'manual-sync',
     78        'title' => 'Manual Sync',
     79        'href' => admin_url('admin.php?page=fastcomments&sub_page=manual-sync'),
     80    );
     81
     82    $fastcomments_support_node_args = array(
    7683        'parent' => 'fastcomments',
    7784        'id' => 'fastcomments_support',
     
    8895
    8996    $wp_admin_bar->add_node($fastcomments_node_args);
     97    $wp_admin_bar->add_node($fastcomments_my_account_node_args);
    9098    $wp_admin_bar->add_node($fastcomments_moderate_node_args);
    9199    $wp_admin_bar->add_node($fastcomments_analytics_node_args);
    92100    $wp_admin_bar->add_node($fastcomments_customize_node_args);
    93     $wp_admin_bar->add_node($fastcomments_my_account_node_args);
     101    $wp_admin_bar->add_node($fastcomments_manual_sync_node_args);
     102    $wp_admin_bar->add_node($fastcomments_support_node_args);
    94103    $wp_admin_bar->add_node($fastcomments_configure_node_args);
    95104}
     
    115124        $subPage = isset($_GET['sub_page']) ? $_GET['sub_page'] : 'n/a';
    116125        switch ($subPage) {
     126            case 'manual-sync':
     127                require_once plugin_dir_path(__FILE__) . 'fastcomments-admin-manual-sync-view.php';
     128                break;
    117129            case 'support':
    118130                global $diagnostic_info;
  • fastcomments/trunk/core/FastCommentsWordPressIntegration.php

    r2613148 r2660486  
    272272    }
    273273
    274     public function fc_to_wp_comment($fc_comment) {
     274    public function fc_to_wp_comment($fc_comment, $skipWPCheck) {
    275275        /*
    276276            We intentionally don't send these fields, as they don't apply to us so they won't ever change on our side.
     
    288288            if (isset($fc_comment->meta->wpPostId)) {
    289289                $post_id = $fc_comment->meta->wpPostId;
     290            } else if ($skipWPCheck && isset($fc_comment->urlId)) {
     291                $post_id = (int)$fc_comment->urlId;
    290292            }
    291293            if (isset($fc_comment->meta->wpUserId)) {
    292294                $user_id = $fc_comment->meta->wpUserId;
    293295            }
    294         }
    295 
    296         if (!$post_id) {
     296        } else if ($skipWPCheck && isset($fc_comment->urlId)) {
     297            $post_id = (int)$fc_comment->urlId;
     298        }
     299
     300        if (!$skipWPCheck && !$post_id) {
    297301            return null; // don't try to set post id to a url... this is probably not a comment from the WP integration.
    298302        }
     
    321325        $wp_comment['comment_date'] = $date_formatted;
    322326        $wp_comment['comment_date_gmt'] = $date_formatted_gmt;
    323         $wp_comment['comment_content'] = $fc_comment->comment;
     327        $wp_comment['comment_content'] = $fc_comment->commentHTML;
    324328        $wp_comment['comment_karma'] = $fc_comment->votes;
    325329        $wp_comment['comment_approved'] = $fc_comment->approved ? 1 : 0;
     
    401405                        }
    402406
    403                         $new_wp_comment = $this->fc_to_wp_comment($eventData->comment);
     407                        $new_wp_comment = $this->fc_to_wp_comment($eventData->comment, false);
    404408                        if ($new_wp_comment) {
    405409                            $comment_id_or_false = wp_insert_comment($new_wp_comment);
     
    419423                        $fcId = $eventData->comment->_id;
    420424                        $this->log('debug', "Updating comment $fcId");
    421                         $wp_comment = $this->fc_to_wp_comment($eventData->comment);
     425                        $wp_comment = $this->fc_to_wp_comment($eventData->comment, false);
    422426                        if ($wp_comment) {
    423427                            wp_update_comment($wp_comment);
     
    512516    }
    513517}
    514 
  • fastcomments/trunk/fastcomments-wordpress-plugin.php

    r2658501 r2660486  
    44Plugin URI: https://fastcomments.com
    55Description: Live Comments, Fast. A comment system that will delight your users and developers.
    6 Version: 3.10.3
     6Version: 3.10.4
    77Author: winrid @ FastComments
    88License: GPL-2.0+
     
    1414}
    1515
    16 $FASTCOMMENTS_VERSION = 3.101;
     16$FASTCOMMENTS_VERSION = 3.104;
    1717
    1818require_once plugin_dir_path(__FILE__) . 'admin/fastcomments-admin.php';
  • fastcomments/trunk/public/fastcomments-public.php

    r2613148 r2660486  
    2222                'methods' => 'PUT',
    2323                'callback' => array($this, 'handle_set_sso_enabled_request'),
     24                'permission_callback' => function () {
     25                    return current_user_can('activate_plugins');
     26                }
     27            ));
     28            register_rest_route('fastcomments/v1', '/api/sync-to-wp', array(
     29                'methods' => 'PUT',
     30                'callback' => array($this, 'handle_sync_to_wp_request'),
    2431                'permission_callback' => function () {
    2532                    return current_user_can('activate_plugins');
     
    6168
    6269        return new WP_REST_Response(array('status' => 'success'), 200);
     70    }
     71
     72    public function handle_sync_to_wp_request(WP_REST_Request $request) {
     73        $includeCount = $request->get_param('includeCount');
     74        $skip = $request->get_param('skip');
     75        require_once plugin_dir_path(__FILE__) . '../core/FastCommentsWordPressIntegration.php';
     76        $fastcomments = new FastCommentsWordPressIntegration();
     77        $token = $fastcomments->getSettingValue('fastcomments_token');
     78        $request_url = "https://fastcomments.com/integrations/v1/comments?token=$token";
     79        if ($includeCount) {
     80            $request_url .= '&includeCount=true';
     81        }
     82        if ($skip) {
     83            $request_url .= "&skip=$skip";
     84        }
     85        $get_comments_response_raw = $fastcomments->makeHTTPRequest('GET', $request_url, null);
     86        $get_comments_response = json_decode($get_comments_response_raw->responseBody);
     87        if ($get_comments_response->status === 'success') {
     88            $count = count($get_comments_response->comments);
     89            if ($count > 0) {
     90                foreach ($get_comments_response->comments as $comment) {
     91                    $wp_comment = $fastcomments->fc_to_wp_comment($comment, true);
     92                    if(!wp_update_comment($wp_comment)) {
     93                        wp_insert_comment($wp_comment);
     94                    }
     95                }
     96                return new WP_REST_Response(array('status' => 'success', 'hasMore' => $get_comments_response->hasMore, 'totalCount' => $includeCount ? $get_comments_response->totalCount : null, 'count' => $count), 200);
     97            } else {
     98                return new WP_REST_Response(array('status' => 'success'), 200);
     99            }
     100        } else {
     101            return new WP_REST_Response(array('status' => 'failed'), 500);
     102        }
    63103    }
    64104
Note: See TracChangeset for help on using the changeset viewer.