Plugin Directory

Changeset 2577451


Ignore:
Timestamp:
08/03/2021 09:40:18 PM (5 years ago)
Author:
winrid
Message:

3.9.2 - Stability improvements and sync-related bugfixes. Initial setup made more intuitive in some areas.

Location:
fastcomments
Files:
34 added
11 edited

Legend:

Unmodified
Added
Removed
  • fastcomments/trunk/README.txt

    r2576818 r2577451  
    44Requires at least: 4.6
    55Tested up to: 5.8
    6 Stable tag: 3.9.1
     6Stable tag: 3.9.2
    77Requires PHP: 5.2.4
    88License: GPLv2 or later
     
    8585== Changelog ==
    8686
     87= 3.9.2 =
     88* Stability improvements and sync-related bugfixes. Initial setup made more intuitive in some areas.
     89
    8790= 3.9.1 =
    8891* Initial sync has been sped up and some bugs fixed.
  • fastcomments/trunk/admin/fastcomments-admin-setup-view.js

    r2576755 r2577451  
    99            xhrFields: {
    1010               withCredentials: true
     11            },
     12            beforeSend: function (xhr) {
     13                xhr.setRequestHeader('X-WP-Nonce', window.FC_DATA.nonce);
    1114            }
    1215        })
     
    2831            xhrFields: {
    2932               withCredentials: true
     33            },
     34            beforeSend: function (xhr) {
     35                xhr.setRequestHeader('X-WP-Nonce', window.FC_DATA.nonce);
    3036            }
    3137        })
  • fastcomments/trunk/admin/fastcomments-admin-setup-view.php

    r2576755 r2577451  
    3737    <?php } ?>
    3838
    39     <?php wp_enqueue_script( 'fastcomments_admin_setup_view', plugin_dir_url( __FILE__ ) . 'fastcomments-admin-setup-view.js', array(), $FASTCOMMENTS_VERSION ); ?>
    40     <?php wp_localize_script('fastcomments_admin_setup_view', 'FC_DATA', array( 'siteUrl' => get_site_url() )); ?>
     39    <?php
     40        global $FASTCOMMENTS_VERSION;
     41        wp_enqueue_script( 'fastcomments_admin_setup_view', plugin_dir_url( __FILE__ ) . 'fastcomments-admin-setup-view.js', array(), $FASTCOMMENTS_VERSION);
     42    ?>
     43    <?php wp_localize_script('fastcomments_admin_setup_view', 'FC_DATA', array( 'siteUrl' => get_site_url(), 'nonce' => wp_create_nonce('wp_rest') )); ?>
    4144</div>
  • fastcomments/trunk/admin/fastcomments-admin-sso-view.js

    r2576755 r2577451  
    6565                        }
    6666                    },
    67                     error: onError
     67                    error: onError,
     68                    beforeSend: function (xhr) {
     69                        xhr.setRequestHeader('X-WP-Nonce', window.FC_DATA.nonce);
     70                    }
    6871                });
    6972            });
     
    135138                        }
    136139                    },
    137                     error: onError
     140                    error: onError,
     141                    beforeSend: function (xhr) {
     142                        xhr.setRequestHeader('X-WP-Nonce', window.FC_DATA.nonce);
     143                    }
    138144                });
    139145            });
  • fastcomments/trunk/admin/fastcomments-admin-sso-view.php

    r2576755 r2577451  
    8989        <?php } ?>
    9090    <?php } ?>
    91     <?php wp_enqueue_script('fastcomments_admin_sso_view', plugin_dir_url(__FILE__) . 'fastcomments-admin-sso-view.js', array(), $FASTCOMMENTS_VERSION); ?>
    92     <?php wp_localize_script('fastcomments_admin_sso_view', 'FC_DATA', array( 'siteUrl' => get_site_url() )); ?>
     91    <?php
     92        global $FASTCOMMENTS_VERSION;
     93        wp_enqueue_script('fastcomments_admin_sso_view', plugin_dir_url(__FILE__) . 'fastcomments-admin-sso-view.js', array(), $FASTCOMMENTS_VERSION);
     94    ?>
     95    <?php wp_localize_script('fastcomments_admin_sso_view', 'FC_DATA', array( 'siteUrl' => get_site_url(), 'nonce' => wp_create_nonce('wp_rest') )); ?>
    9396</div>
  • fastcomments/trunk/admin/fastcomments-admin.php

    r2576755 r2577451  
    110110function fc_render_admin_index()
    111111{
     112    wp_enqueue_style("fastcomments-admin", plugin_dir_url(__FILE__) . 'fastcomments-admin.css');
    112113    if (get_option("fastcomments_setup")) {
    113114        global $wp_version;
    114         switch ($_GET['sub_page']) {
     115        $subPage = isset($_GET['sub_page']) ? $_GET['sub_page'] : 'n/a';
     116        switch ($subPage) {
    115117            case 'support':
    116118                global $diagnostic_info;
     
    119121                        'tenant_id' => get_option('fastcomments_tenant_id'),
    120122                        'setup' => get_option('fastcomments_setup'),
    121                         'sync_token' => get_option('fastcomments_connection_token'),
     123                        'sync_token' => get_option('fastcomments_token'),
    122124                        'sso_secret' => get_option('fastcomments_sso_key')
    123125                    ),
     
    146148function fc_render_admin_support()
    147149{
     150    wp_enqueue_style("fastcomments-admin", plugin_dir_url(__FILE__) . 'fastcomments-admin.css');
    148151    require_once plugin_dir_path(__FILE__) . 'fastcomments-admin-support-view.php';
    149152}
    150153
    151 wp_enqueue_style("fastcomments-admin", plugin_dir_url(__FILE__) . 'fastcomments-admin.css');
    152154add_filter('plugin_action_links', 'fc_plugin_action_links', 10, 2);
    153155add_action('admin_menu', 'fc_contruct_admin_menu');
  • fastcomments/trunk/core/FastCommentsIntegrationCore.php

    r2576818 r2577451  
    103103            $this->setSettingValue('fastcomments_sso_enabled', true);
    104104        } else {
     105            $this->log('error', $apiSecretResponse->reason);
    105106            throw new RuntimeException("API did not return success response when trying to get the key!");
    106107        }
  • fastcomments/trunk/core/FastCommentsWordPressIntegration.php

    r2576755 r2577451  
    6262        $id_map_table_name = $wpdb->prefix . "fastcomments_comment_ids";
    6363
    64         $drop_id_map_table_sql = "DROP TABLE $id_map_table_name";
    65 
    66         require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    67         dbDelta($drop_id_map_table_sql);
     64        $wpdb->query("DROP TABLE IF EXISTS $id_map_table_name");
    6865
    6966        delete_option('fc_fastcomments_comment_ids_version');
     
    9895
    9996    public function createUUID() {
    100         return uniqid();
     97        return uniqid("", true);
    10198    }
    10299
     
    118115        $id_map_table_name = $wpdb->prefix . "fastcomments_comment_ids";
    119116        $existing_wp_id = $this->getWPCommentId($fcId);
    120         if ($existing_wp_id !== null) {
     117        if ($existing_wp_id === null) {
    121118            $insert_result = $wpdb->insert(
    122119                $id_map_table_name,
     
    139136        $this->log('debug', "getWPCommentId $fcId");
    140137        $id_row = $wpdb->get_row("SELECT wp_id FROM $id_map_table_name WHERE id = \"$fcId\"");
    141         if ($id_row !== false) {
     138        if ($id_row) {
    142139            return $id_row->wp_id;
    143140        }
     
    219216
    220217        // wordpress timestamp format is Y-m-d H:i:s (mysql date column type)
    221         $date = date_create($fc_comment->date);
    222         $date_formatted = date_format($date, 'YYYY-MM-DD HH:mm:ss');
     218        $timestamp = strtotime($fc_comment->date);
     219        $date_formatted = date('Y-m-d H:i:s', $timestamp);
    223220
    224221
    225222        $wp_id = $this->getWPCommentId($fc_comment->_id);
    226         $wp_parent_id = $fc_comment->parentId ? $this->getWPCommentId($fc_comment->parentId) : null;
     223        $wp_parent_id = isset($fc_comment->parentId) && $fc_comment->parentId ? $this->getWPCommentId($fc_comment->parentId) : 0;
    227224
    228225        $wp_comment['comment_ID'] = is_numeric($wp_id) ? $wp_id : null;
    229         $wp_comment['comment_post_ID'] = $fc_comment->urlId;
     226        $wp_comment['comment_post_ID'] = (int) $fc_comment->urlId;
     227        $finalpostId = $wp_comment['comment_post_ID'];
    230228        $wp_comment['comment_post_url'] = $fc_comment->url;
     229        // TODO fix user ids potentially getting lost via 1. Create comment in WP 2. Sync to FC 3. Update Comment Text in FC 4. Sync back to WP.
     230//        $wp_comment['comment_user_ID'] = 0;
    231231        $wp_comment['comment_author'] = $fc_comment->commenterName;
    232232        $wp_comment['comment_author_email'] = $fc_comment->commenterEmail;
     
    235235        $wp_comment['comment_content'] = $fc_comment->comment;
    236236        $wp_comment['comment_karma'] = $fc_comment->votes;
    237         $wp_comment['comment_approved'] = $fc_comment->approved && $fc_comment ? 1 : 0;
     237        $wp_comment['comment_approved'] = $fc_comment->approved ? 1 : 0;
    238238        $wp_comment['comment_parent'] = $wp_parent_id;
    239239
     
    275275
    276276    public function handleEvents($events) {
     277        $this->log('debug', "BEGIN handleEvents");
    277278        foreach ($events as $event) {
    278279            try {
     
    285286                    case 'new-comment':
    286287                        $fcId = $eventData->comment->_id;
    287                         $this->log('debug', "Incoming comment $fcId");
    288                         $comment_id_or_false = wp_insert_comment($this->fc_to_wp_comment($eventData->comment));
    289                         if ($comment_id_or_false) {
    290                             $this->addCommentIDMapEntry($fcId, $comment_id_or_false);
     288                        $wp_id = $this->getWPCommentId($fcId);
     289                        $existingComment = isset($wp_id) ? get_comment($wp_id) : null;
     290                        if (!$existingComment) {
     291                            $this->log('debug', "Incoming comment $fcId");
     292                            $comment_id_or_false = wp_insert_comment($this->fc_to_wp_comment($eventData->comment));
     293                            if ($comment_id_or_false) {
     294                                $this->addCommentIDMapEntry($fcId, $comment_id_or_false);
     295                            } else {
     296                                $debug_data = $event->data;
     297                                $this->log('error', "Failed to save comment: $debug_data");
     298                            }
    291299                        } else {
    292                             $debug_data = $event->data;
    293                             $this->log('error', "Failed to save comment: $debug_data");
     300                            $this->log('debug', "Incoming comment $fcId ignored, already maps to comment $wp_id");
    294301                        }
    295302                        break;
     
    298305                        $this->log('debug', "Updating comment $fcId");
    299306                        $wp_comment = $this->fc_to_wp_comment($eventData->comment);
    300                         $wp_id = $this->getWPCommentId($fcId);
    301                         $wp_comment['comment_ID'] = $wp_id;
    302307                        wp_update_comment($wp_comment);
    303308                        break;
     
    305310                        $this->log('debug', "Deleting comment $fcId");
    306311                        $wp_id = $this->getWPCommentId($eventData->comment->_id);
    307                         if ($wp_id != null) {
     312                        if (is_numeric($wp_id)) {
    308313                            wp_trash_comment($wp_id);
    309314                        }
     
    341346            }
    342347        }
     348        $this->log('debug', "END handleEvents");
    343349    }
    344350
  • fastcomments/trunk/fastcomments-wordpress-plugin.php

    r2576818 r2577451  
    44Plugin URI: https://fastcomments.com
    55Description: Live Comments, Fast. A comment system that will delight your users and developers.
    6 Version: 3.9.1
     6Version: 3.9.2
    77Author: winrid @ FastComments
    88License: GPL-2.0+
     
    1414}
    1515
    16 $FASTCOMMENTS_VERSION = 3.91;
    17 
     16$FASTCOMMENTS_VERSION = 3.92;
    1817
    1918require_once plugin_dir_path(__FILE__) . 'admin/fastcomments-admin.php';
  • fastcomments/trunk/public/fastcomments-public.php

    r2576755 r2577451  
    88                'methods' => 'GET',
    99                'callback' => array($this, 'handle_get_config_status_request'),
    10                 'permissions_callback' => function() {
    11                     return current_user_can('manage_options');
     10                'permission_callback' => function () {
     11                    return current_user_can('activate_plugins');
    1212                }
    1313            ));
     
    1515                'methods' => 'GET',
    1616                'callback' => array($this, 'handle_tick_request'),
    17                 'permissions_callback' => function() {
    18                     return current_user_can('manage_options');
     17                'permission_callback' => function () {
     18                    return current_user_can('activate_plugins');
    1919                }
    2020            ));
     
    2222                'methods' => 'PUT',
    2323                'callback' => array($this, 'handle_set_sso_enabled_request'),
    24                 'permissions_callback' => function() {
    25                     return current_user_can('manage_options');
     24                'permission_callback' => function () {
     25                    return current_user_can('activate_plugins');
    2626                }
    2727            ));
     
    6363    }
    6464
    65     public static function get_config_for_post($post)
    66     {
     65    public static function get_config_for_post($post) {
    6766        $ssoKey = get_option('fastcomments_sso_key');
    6867        $isSSOEnabled = $ssoKey && get_option('fastcomments_sso_enabled');
     
    7675    }
    7776
    78     private static function getSSOConfig($ssoKey)
    79     {
     77    private static function getSSOConfig($ssoKey) {
    8078        $timestamp = time() * 1000;
    8179
  • fastcomments/trunk/public/fastcomments-widget-view.php

    r2576755 r2577451  
    1 <?php wp_enqueue_script( 'fastcomments_widget_embed', 'https://cdn.fastcomments.com/js/embed-v2.min.js', array(), $FASTCOMMENTS_VERSION, false ); ?>
    21<div id="fastcomments-widget"></div>
    32<?php
    4 global $post;
    5 $config = FastCommentsPublic::get_config_for_post($post);
    6 $jsonFcConfig = json_encode($config);
    7 $urlId = $config['urlId'];
    8 // These "fcInitializedById" checks are for plugins that try to load the comments more than once for the same url id.
    9 // The repeated attempt to load is to handle plugins that make our embed script async.
    10 $script = "
    11     (function() {
    12         if (!window.fcInitializedById) {
    13             window.fcInitializedById = {};
    14         }
    15         if (window.fcInitializedById['$urlId']) {
    16             return;
    17         }
    18         window.fcInitializedById['$urlId'] = true;
    19         var attempts = 0;
    20         function attemptToLoad() {
    21             attempts++;
    22             if (window.FastCommentsUI) {
    23                 window.FastCommentsUI(document.getElementById('fastcomments-widget'), $jsonFcConfig);
    24                 return;
    25             }
    26             setTimeout(attemptToLoad, attempts > 50 ? 500 : 50);
    27         }
    28         attemptToLoad();
    29     })();
    30 ";
    31 wp_add_inline_script('fastcomments_widget_embed', $script);
     3    if (!get_option('fastcomments_tenant_id') && current_user_can('activate_plugins')) {
     4        ?>
     5            <div style="text-align: center">
     6                <div style="margin-bottom: 20px">FastComments is not yet setup!</div>
     7                <a class="button button-primary" href="<?php echo esc_url(get_admin_url(null, 'admin.php?page=fastcomments')) ?>">Complete FastComments Setup</a>
     8            </div>
     9        <?php
     10    } else {
     11        global $FASTCOMMENTS_VERSION;
     12        wp_enqueue_script( 'fastcomments_widget_embed', 'https://cdn.fastcomments.com/js/embed-v2.min.js', array(), $FASTCOMMENTS_VERSION, false );
     13        global $post;
     14        $config = FastCommentsPublic::get_config_for_post($post);
     15        $jsonFcConfig = json_encode($config);
     16        $urlId = $config['urlId'];
     17        // These "fcInitializedById" checks are for plugins that try to load the comments more than once for the same url id.
     18        // The repeated attempt to load is to handle plugins that make our embed script async.
     19        $script = "
     20            (function() {
     21                if (!window.fcInitializedById) {
     22                    window.fcInitializedById = {};
     23                }
     24                if (window.fcInitializedById['$urlId']) {
     25                    return;
     26                }
     27                window.fcInitializedById['$urlId'] = true;
     28                var attempts = 0;
     29                function attemptToLoad() {
     30                    attempts++;
     31                    if (window.FastCommentsUI) {
     32                        window.FastCommentsUI(document.getElementById('fastcomments-widget'), $jsonFcConfig);
     33                        return;
     34                    }
     35                    setTimeout(attemptToLoad, attempts > 50 ? 500 : 50);
     36                }
     37                attemptToLoad();
     38            })();
     39        ";
     40        wp_add_inline_script('fastcomments_widget_embed', $script);
     41    }
    3242?>
Note: See TracChangeset for help on using the changeset viewer.