Changeset 2577451
- Timestamp:
- 08/03/2021 09:40:18 PM (5 years ago)
- Location:
- fastcomments
- Files:
-
- 34 added
- 11 edited
-
tags/3.9.2 (added)
-
tags/3.9.2/.gitignore (added)
-
tags/3.9.2/LICENSE (added)
-
tags/3.9.2/README.md (added)
-
tags/3.9.2/README.txt (added)
-
tags/3.9.2/admin (added)
-
tags/3.9.2/admin/fastcomments-admin-setup-view.js (added)
-
tags/3.9.2/admin/fastcomments-admin-setup-view.php (added)
-
tags/3.9.2/admin/fastcomments-admin-sso-view.css (added)
-
tags/3.9.2/admin/fastcomments-admin-sso-view.js (added)
-
tags/3.9.2/admin/fastcomments-admin-sso-view.php (added)
-
tags/3.9.2/admin/fastcomments-admin-support-view.php (added)
-
tags/3.9.2/admin/fastcomments-admin-view.php (added)
-
tags/3.9.2/admin/fastcomments-admin.css (added)
-
tags/3.9.2/admin/fastcomments-admin.php (added)
-
tags/3.9.2/admin/images (added)
-
tags/3.9.2/admin/images/api.png (added)
-
tags/3.9.2/admin/images/crown.png (added)
-
tags/3.9.2/admin/images/css.png (added)
-
tags/3.9.2/admin/images/debugging.png (added)
-
tags/3.9.2/admin/images/download.png (added)
-
tags/3.9.2/admin/images/home.png (added)
-
tags/3.9.2/admin/images/logo-50.png (added)
-
tags/3.9.2/admin/images/logo.png (added)
-
tags/3.9.2/admin/images/support.png (added)
-
tags/3.9.2/admin/images/sync.png (added)
-
tags/3.9.2/core (added)
-
tags/3.9.2/core/FastCommentsIntegrationCore.php (added)
-
tags/3.9.2/core/FastCommentsWordPressIntegration.php (added)
-
tags/3.9.2/fastcomments-wordpress-plugin.php (added)
-
tags/3.9.2/public (added)
-
tags/3.9.2/public/fastcomments-public.php (added)
-
tags/3.9.2/public/fastcomments-widget-view.php (added)
-
tags/3.9.2/uninstall.php (added)
-
trunk/README.txt (modified) (2 diffs)
-
trunk/admin/fastcomments-admin-setup-view.js (modified) (2 diffs)
-
trunk/admin/fastcomments-admin-setup-view.php (modified) (1 diff)
-
trunk/admin/fastcomments-admin-sso-view.js (modified) (2 diffs)
-
trunk/admin/fastcomments-admin-sso-view.php (modified) (1 diff)
-
trunk/admin/fastcomments-admin.php (modified) (3 diffs)
-
trunk/core/FastCommentsIntegrationCore.php (modified) (1 diff)
-
trunk/core/FastCommentsWordPressIntegration.php (modified) (11 diffs)
-
trunk/fastcomments-wordpress-plugin.php (modified) (2 diffs)
-
trunk/public/fastcomments-public.php (modified) (5 diffs)
-
trunk/public/fastcomments-widget-view.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
fastcomments/trunk/README.txt
r2576818 r2577451 4 4 Requires at least: 4.6 5 5 Tested up to: 5.8 6 Stable tag: 3.9. 16 Stable tag: 3.9.2 7 7 Requires PHP: 5.2.4 8 8 License: GPLv2 or later … … 85 85 == Changelog == 86 86 87 = 3.9.2 = 88 * Stability improvements and sync-related bugfixes. Initial setup made more intuitive in some areas. 89 87 90 = 3.9.1 = 88 91 * Initial sync has been sped up and some bugs fixed. -
fastcomments/trunk/admin/fastcomments-admin-setup-view.js
r2576755 r2577451 9 9 xhrFields: { 10 10 withCredentials: true 11 }, 12 beforeSend: function (xhr) { 13 xhr.setRequestHeader('X-WP-Nonce', window.FC_DATA.nonce); 11 14 } 12 15 }) … … 28 31 xhrFields: { 29 32 withCredentials: true 33 }, 34 beforeSend: function (xhr) { 35 xhr.setRequestHeader('X-WP-Nonce', window.FC_DATA.nonce); 30 36 } 31 37 }) -
fastcomments/trunk/admin/fastcomments-admin-setup-view.php
r2576755 r2577451 37 37 <?php } ?> 38 38 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') )); ?> 41 44 </div> -
fastcomments/trunk/admin/fastcomments-admin-sso-view.js
r2576755 r2577451 65 65 } 66 66 }, 67 error: onError 67 error: onError, 68 beforeSend: function (xhr) { 69 xhr.setRequestHeader('X-WP-Nonce', window.FC_DATA.nonce); 70 } 68 71 }); 69 72 }); … … 135 138 } 136 139 }, 137 error: onError 140 error: onError, 141 beforeSend: function (xhr) { 142 xhr.setRequestHeader('X-WP-Nonce', window.FC_DATA.nonce); 143 } 138 144 }); 139 145 }); -
fastcomments/trunk/admin/fastcomments-admin-sso-view.php
r2576755 r2577451 89 89 <?php } ?> 90 90 <?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') )); ?> 93 96 </div> -
fastcomments/trunk/admin/fastcomments-admin.php
r2576755 r2577451 110 110 function fc_render_admin_index() 111 111 { 112 wp_enqueue_style("fastcomments-admin", plugin_dir_url(__FILE__) . 'fastcomments-admin.css'); 112 113 if (get_option("fastcomments_setup")) { 113 114 global $wp_version; 114 switch ($_GET['sub_page']) { 115 $subPage = isset($_GET['sub_page']) ? $_GET['sub_page'] : 'n/a'; 116 switch ($subPage) { 115 117 case 'support': 116 118 global $diagnostic_info; … … 119 121 'tenant_id' => get_option('fastcomments_tenant_id'), 120 122 'setup' => get_option('fastcomments_setup'), 121 'sync_token' => get_option('fastcomments_ connection_token'),123 'sync_token' => get_option('fastcomments_token'), 122 124 'sso_secret' => get_option('fastcomments_sso_key') 123 125 ), … … 146 148 function fc_render_admin_support() 147 149 { 150 wp_enqueue_style("fastcomments-admin", plugin_dir_url(__FILE__) . 'fastcomments-admin.css'); 148 151 require_once plugin_dir_path(__FILE__) . 'fastcomments-admin-support-view.php'; 149 152 } 150 153 151 wp_enqueue_style("fastcomments-admin", plugin_dir_url(__FILE__) . 'fastcomments-admin.css');152 154 add_filter('plugin_action_links', 'fc_plugin_action_links', 10, 2); 153 155 add_action('admin_menu', 'fc_contruct_admin_menu'); -
fastcomments/trunk/core/FastCommentsIntegrationCore.php
r2576818 r2577451 103 103 $this->setSettingValue('fastcomments_sso_enabled', true); 104 104 } else { 105 $this->log('error', $apiSecretResponse->reason); 105 106 throw new RuntimeException("API did not return success response when trying to get the key!"); 106 107 } -
fastcomments/trunk/core/FastCommentsWordPressIntegration.php
r2576755 r2577451 62 62 $id_map_table_name = $wpdb->prefix . "fastcomments_comment_ids"; 63 63 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"); 68 65 69 66 delete_option('fc_fastcomments_comment_ids_version'); … … 98 95 99 96 public function createUUID() { 100 return uniqid( );97 return uniqid("", true); 101 98 } 102 99 … … 118 115 $id_map_table_name = $wpdb->prefix . "fastcomments_comment_ids"; 119 116 $existing_wp_id = $this->getWPCommentId($fcId); 120 if ($existing_wp_id !== null) {117 if ($existing_wp_id === null) { 121 118 $insert_result = $wpdb->insert( 122 119 $id_map_table_name, … … 139 136 $this->log('debug', "getWPCommentId $fcId"); 140 137 $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) { 142 139 return $id_row->wp_id; 143 140 } … … 219 216 220 217 // 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); 223 220 224 221 225 222 $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; 227 224 228 225 $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']; 230 228 $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; 231 231 $wp_comment['comment_author'] = $fc_comment->commenterName; 232 232 $wp_comment['comment_author_email'] = $fc_comment->commenterEmail; … … 235 235 $wp_comment['comment_content'] = $fc_comment->comment; 236 236 $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; 238 238 $wp_comment['comment_parent'] = $wp_parent_id; 239 239 … … 275 275 276 276 public function handleEvents($events) { 277 $this->log('debug', "BEGIN handleEvents"); 277 278 foreach ($events as $event) { 278 279 try { … … 285 286 case 'new-comment': 286 287 $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 } 291 299 } 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"); 294 301 } 295 302 break; … … 298 305 $this->log('debug', "Updating comment $fcId"); 299 306 $wp_comment = $this->fc_to_wp_comment($eventData->comment); 300 $wp_id = $this->getWPCommentId($fcId);301 $wp_comment['comment_ID'] = $wp_id;302 307 wp_update_comment($wp_comment); 303 308 break; … … 305 310 $this->log('debug', "Deleting comment $fcId"); 306 311 $wp_id = $this->getWPCommentId($eventData->comment->_id); 307 if ( $wp_id != null) {312 if (is_numeric($wp_id)) { 308 313 wp_trash_comment($wp_id); 309 314 } … … 341 346 } 342 347 } 348 $this->log('debug', "END handleEvents"); 343 349 } 344 350 -
fastcomments/trunk/fastcomments-wordpress-plugin.php
r2576818 r2577451 4 4 Plugin URI: https://fastcomments.com 5 5 Description: Live Comments, Fast. A comment system that will delight your users and developers. 6 Version: 3.9. 16 Version: 3.9.2 7 7 Author: winrid @ FastComments 8 8 License: GPL-2.0+ … … 14 14 } 15 15 16 $FASTCOMMENTS_VERSION = 3.91; 17 16 $FASTCOMMENTS_VERSION = 3.92; 18 17 19 18 require_once plugin_dir_path(__FILE__) . 'admin/fastcomments-admin.php'; -
fastcomments/trunk/public/fastcomments-public.php
r2576755 r2577451 8 8 'methods' => 'GET', 9 9 'callback' => array($this, 'handle_get_config_status_request'), 10 'permission s_callback' => function() {11 return current_user_can(' manage_options');10 'permission_callback' => function () { 11 return current_user_can('activate_plugins'); 12 12 } 13 13 )); … … 15 15 'methods' => 'GET', 16 16 'callback' => array($this, 'handle_tick_request'), 17 'permission s_callback' => function() {18 return current_user_can(' manage_options');17 'permission_callback' => function () { 18 return current_user_can('activate_plugins'); 19 19 } 20 20 )); … … 22 22 'methods' => 'PUT', 23 23 'callback' => array($this, 'handle_set_sso_enabled_request'), 24 'permission s_callback' => function() {25 return current_user_can(' manage_options');24 'permission_callback' => function () { 25 return current_user_can('activate_plugins'); 26 26 } 27 27 )); … … 63 63 } 64 64 65 public static function get_config_for_post($post) 66 { 65 public static function get_config_for_post($post) { 67 66 $ssoKey = get_option('fastcomments_sso_key'); 68 67 $isSSOEnabled = $ssoKey && get_option('fastcomments_sso_enabled'); … … 76 75 } 77 76 78 private static function getSSOConfig($ssoKey) 79 { 77 private static function getSSOConfig($ssoKey) { 80 78 $timestamp = time() * 1000; 81 79 -
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 ); ?>2 1 <div id="fastcomments-widget"></div> 3 2 <?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 } 32 42 ?>
Note: See TracChangeset
for help on using the changeset viewer.