Changeset 2613148
- Timestamp:
- 10/12/2021 04:28:16 PM (4 years ago)
- Location:
- fastcomments
- Files:
-
- 40 added
- 10 edited
-
tags/3.9.10 (added)
-
tags/3.9.10/.gitignore (added)
-
tags/3.9.10/LICENSE (added)
-
tags/3.9.10/README.md (added)
-
tags/3.9.10/README.txt (added)
-
tags/3.9.10/admin (added)
-
tags/3.9.10/admin/fastcomments-admin-advanced-settings-view.js (added)
-
tags/3.9.10/admin/fastcomments-admin-advanced-settings-view.php (added)
-
tags/3.9.10/admin/fastcomments-admin-setup-view.js (added)
-
tags/3.9.10/admin/fastcomments-admin-setup-view.php (added)
-
tags/3.9.10/admin/fastcomments-admin-sso-view.css (added)
-
tags/3.9.10/admin/fastcomments-admin-sso-view.js (added)
-
tags/3.9.10/admin/fastcomments-admin-sso-view.php (added)
-
tags/3.9.10/admin/fastcomments-admin-support-view.php (added)
-
tags/3.9.10/admin/fastcomments-admin-view.php (added)
-
tags/3.9.10/admin/fastcomments-admin.css (added)
-
tags/3.9.10/admin/fastcomments-admin.php (added)
-
tags/3.9.10/admin/images (added)
-
tags/3.9.10/admin/images/api.png (added)
-
tags/3.9.10/admin/images/crown.png (added)
-
tags/3.9.10/admin/images/css.png (added)
-
tags/3.9.10/admin/images/debugging.png (added)
-
tags/3.9.10/admin/images/download.png (added)
-
tags/3.9.10/admin/images/home.png (added)
-
tags/3.9.10/admin/images/logo-50.png (added)
-
tags/3.9.10/admin/images/logo.png (added)
-
tags/3.9.10/admin/images/settings.png (added)
-
tags/3.9.10/admin/images/support.png (added)
-
tags/3.9.10/admin/images/sync.png (added)
-
tags/3.9.10/core (added)
-
tags/3.9.10/core/FastCommentsIntegrationCore.php (added)
-
tags/3.9.10/core/FastCommentsWordPressIntegration.php (added)
-
tags/3.9.10/fastcomments-wordpress-plugin.php (added)
-
tags/3.9.10/public (added)
-
tags/3.9.10/public/fastcomments-public.php (added)
-
tags/3.9.10/public/fastcomments-widget-view.php (added)
-
tags/3.9.10/uninstall.php (added)
-
trunk/README.txt (modified) (2 diffs)
-
trunk/admin/fastcomments-admin-advanced-settings-view.js (added)
-
trunk/admin/fastcomments-admin-advanced-settings-view.php (added)
-
trunk/admin/fastcomments-admin-sso-view.js (modified) (3 diffs)
-
trunk/admin/fastcomments-admin-sso-view.php (modified) (2 diffs)
-
trunk/admin/fastcomments-admin-view.php (modified) (1 diff)
-
trunk/admin/fastcomments-admin.php (modified) (1 diff)
-
trunk/admin/images/settings.png (added)
-
trunk/core/FastCommentsIntegrationCore.php (modified) (4 diffs)
-
trunk/core/FastCommentsWordPressIntegration.php (modified) (15 diffs)
-
trunk/fastcomments-wordpress-plugin.php (modified) (2 diffs)
-
trunk/public/fastcomments-public.php (modified) (3 diffs)
-
trunk/uninstall.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
fastcomments/trunk/README.txt
r2588650 r2613148 4 4 Requires at least: 4.6 5 5 Tested up to: 5.8 6 Stable tag: 3.9. 96 Stable tag: 3.9.10 7 7 Requires PHP: 5.2.4 8 8 License: GPLv2 or later … … 84 84 85 85 == Changelog == 86 87 = 3.9.10 = 88 * When using SSO, Admins and Moderators now have the appropriate tags shown on with comments. Additionally, configuration has been added for the FastComments log level. 86 89 87 90 = 3.9.9 = -
fastcomments/trunk/admin/fastcomments-admin-sso-view.js
r2577451 r2613148 1 1 (function () { 2 function addNoticeDismissalEventListeners() { 3 const noticeDismissButtons = document.querySelectorAll('.notice-dismiss'); 4 5 noticeDismissButtons.forEach(function (dismissNoticeButton) { 6 dismissNoticeButton.addEventListener('click', function () { 7 dismissNoticeButton.parentNode.classList.add('hidden'); 8 }); 9 }); 10 } 11 2 12 (function disableSSOFlow() { 3 13 const disableButton = document.getElementById('fc-sso-disable'); … … 6 16 const noticeSSODisabledSuccess = document.getElementById('sso-disabled-success'); 7 17 const noticeSSODisabledFailure = document.getElementById('sso-disabled-failure'); 18 19 addNoticeDismissalEventListeners(); 8 20 9 21 if (disableButton) { … … 80 92 const noticeSSOEnabledFailure = document.getElementById('sso-enabled-failure'); 81 93 94 addNoticeDismissalEventListeners(); 95 82 96 if (enableButton) { 83 97 jQuery('#dialog-enable-sso').dialog({ -
fastcomments/trunk/admin/fastcomments-admin-sso-view.php
r2577451 r2613148 17 17 <?php if (get_option('users_can_register')) { ?> 18 18 <div class="notice notice-success is-dismissible hidden" id="sso-disabled-success"> 19 <p><strong>SSO Disabled! <a href="<?php echo get_admin_url(null, " ?page=fastcomments&sub_page=sso", null) ?>">Refresh</a>.</strong></p>19 <p><strong>SSO Disabled! <a href="<?php echo get_admin_url(null, "admin.php?page=fastcomments&sub_page=sso", null) ?>">Refresh</a>.</strong></p> 20 20 <button type="button" class="notice-dismiss"> 21 21 <span class="screen-reader-text">Dismiss this notice.</span> … … 51 51 <?php } else { ?> 52 52 <div class="notice notice-success is-dismissible hidden" id="sso-enabled-success"> 53 <p><strong>SSO Enabled! <a href="<?php echo get_admin_url(null, " ?page=fastcomments&sub_page=sso", null) ?>">Refresh</a>.</strong></p>53 <p><strong>SSO Enabled! <a href="<?php echo get_admin_url(null, "admin.php?page=fastcomments&sub_page=sso", null) ?>">Refresh</a>.</strong></p> 54 54 <button type="button" class="notice-dismiss"> 55 55 <span class="screen-reader-text">Dismiss this notice.</span> -
fastcomments/trunk/admin/fastcomments-admin-view.php
r2576755 r2613148 33 33 <div>SSO Settings</div> 34 34 </a> 35 <a href="<?php echo admin_url('admin.php?page=fastcomments&sub_page=advanced-settings'); ?>"> 36 <img src="<?php echo plugin_dir_url( dirname( __FILE__ ) ); ?>/admin/images/settings.png" alt="Advanced Settings" title="Advanced Settings"/> 37 <div>Advanced Settings</div> 38 </a> 35 39 </div> 36 40 </div> -
fastcomments/trunk/admin/fastcomments-admin.php
r2577451 r2613148 138 138 require_once plugin_dir_path(__FILE__) . 'fastcomments-admin-sso-view.php'; 139 139 break; 140 case 'advanced-settings': 141 require_once plugin_dir_path(__FILE__) . 'fastcomments-admin-advanced-settings-view.php'; 142 break; 140 143 default: 141 144 require_once plugin_dir_path(__FILE__) . 'fastcomments-admin-view.php'; -
fastcomments/trunk/core/FastCommentsIntegrationCore.php
r2588650 r2613148 168 168 $lastFetchDate = $this->getSettingValue('fastcomments_stream_last_fetch_timestamp'); 169 169 $lastFetchDateToSend = $lastFetchDate ? $lastFetchDate : 0; 170 $this->log('debug', "Polling next commands for fromDateTime=[$lastFetchDateToSend]."); 170 171 $rawIntegrationStreamResponse = $this->makeHTTPRequest('GET', "$this->baseUrl/commands?token=$token&fromDateTime=$lastFetchDateToSend", null); 171 172 $this->log('debug', 'Stream response status: ' . $rawIntegrationStreamResponse->responseStatusCode); … … 193 194 194 195 public function commandFetchEvents($token) { 196 $this->log('debug', "BEGIN commandFetchEvents"); 195 197 $fromDateTime = $this->getSettingValue('fastcomments_stream_last_fetch_timestamp'); 196 198 $hasMore = true; 197 199 $startedAt = time(); 198 while ($hasMore && time() - $startedAt < 30 * 1000) { 199 $this->log('debug', 'Send events command loop...'); 200 while ($hasMore && time() - $startedAt < 30) { 200 201 $fromDateTimeToSend = $fromDateTime ? $fromDateTime : 0; 202 $this->log('debug', "Send events command loop... Fetching events fromDateTime=[$fromDateTimeToSend]"); 201 203 $rawIntegrationEventsResponse = $this->makeHTTPRequest('GET', "$this->baseUrl/events?token=$token&fromDateTime=$fromDateTimeToSend", null); 202 204 $response = json_decode($rawIntegrationEventsResponse->responseBody); 203 205 if ($response->status === 'success') { 204 206 $count = count($response->events); 205 $this->log('info', "Got events count=[$count] ");207 $this->log('info', "Got events count=[$count] hasMore=[$response->hasMore]"); 206 208 if ($response->events && count($response->events) > 0) { 207 209 $this->handleEvents($response->events); 208 $fromDateTime = strtotime($response->events[count($response->events) - 1]->createdAt) ;210 $fromDateTime = strtotime($response->events[count($response->events) - 1]->createdAt) * 1000; 209 211 } 210 $hasMore = $response->hasMore;212 $hasMore = !!$response->hasMore; 211 213 $this->setSettingValue('fastcomments_stream_last_fetch_timestamp', $fromDateTime); 212 214 } else { … … 215 217 } 216 218 } 219 $this->log('debug', "END commandFetchEvents"); 217 220 } 218 221 … … 294 297 $response = json_decode($httpResponse->responseBody); 295 298 if ($response->status === 'success') { 299 foreach ($response->commentIds as $wpId => $fcId) { 300 update_comment_meta((int) $wpId, 'fastcomments_id', $fcId); 301 } 296 302 $countRemaining = $countRemainingIfSuccessful; 297 303 $fromDateTime = $lastCommentFromDateTime; -
fastcomments/trunk/core/FastCommentsWordPressIntegration.php
r2588650 r2613148 11 11 private function ensure_plugin_dependencies() { 12 12 global $wpdb; 13 require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 13 14 14 15 $charset_collate = $wpdb->get_charset_collate(); … … 22 23 ) $charset_collate;"; 23 24 24 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');25 25 dbDelta($create_id_map_table_sql); 26 update_option('fc_fastcomments_comment_ids_version', '1.0'); 26 27 $event_ids_table_name = $wpdb->prefix . "fastcomments_event_ids"; // TODO AUTO REMOVE OLD EVENT MARKERS 28 29 $create_event_ids_table_sql = "CREATE TABLE $event_ids_table_name ( 30 id varchar(100) NOT NULL, 31 PRIMARY KEY (id) 32 ) $charset_collate;"; 33 34 dbDelta($create_event_ids_table_sql); 35 36 update_option('fc_fastcomments_comment_ids_version', '2.0'); 27 37 28 38 global $FASTCOMMENTS_VERSION; … … 32 42 if (!$timestamp) { 33 43 wp_schedule_event(time() + 86400, 'daily', 'fastcomments_cron_hook'); 44 } 45 46 if (!get_option('fastcomments_log_level')) { 47 update_option('fastcomments_log_level', 'warn'); 34 48 } 35 49 } … … 58 72 59 73 public function deactivate() { 60 global $wpdb;61 62 $id_map_table_name = $wpdb->prefix . "fastcomments_comment_ids";63 64 $wpdb->query("DROP TABLE IF EXISTS $id_map_table_name");65 66 74 delete_option('fc_fastcomments_comment_ids_version'); 67 75 delete_option('fastcomments_token'); … … 76 84 delete_option('fastcomments_stream_last_send_id'); 77 85 delete_option('fastcomments_comment_sent_count'); 86 delete_option('fastcomments_log_level'); 78 87 79 88 $timestamp = wp_next_scheduled('fastcomments_cron'); … … 81 90 } 82 91 92 // note - if the user uninstalls and re-installs - duplicate data my occur as we cleanup the tables to prevent duplicates. 93 public function uninstall() { 94 global $wpdb; 95 96 $id_map_table_name = $wpdb->prefix . "fastcomments_comment_ids"; 97 98 $was_drop_successful = $wpdb->query("DROP TABLE IF EXISTS $id_map_table_name"); 99 100 if (!$was_drop_successful) { 101 $this->log('warn', "Dropping of $id_map_table_name was not successful!"); 102 } 103 104 $event_ids_table_name = $wpdb->prefix . "fastcomments_event_ids"; 105 106 $was_drop_successful = $wpdb->query("DROP TABLE IF EXISTS $event_ids_table_name"); 107 108 if (!$was_drop_successful) { 109 $this->log('warn', "Dropping of $event_ids_table_name was not successful!"); 110 } 111 112 // TODO cleanup comment meta items where key = fastcomments_id etc (there is an index on key) 113 } 114 115 private static $logLevels = array( 116 'debug' => 0, // log everything 117 'info' => 1, // log info, warnings, and errors 118 'warn' => 2, // only log warnings, errors 119 'error' => 3, // only log errors 120 'disabled' => 10 // don't log 121 ); 122 83 123 public function log($level, $message) { 84 switch ($level) { 85 case 'debug': 86 error_log("DEBUG:::" . $message); 87 break; 88 case 'info': 89 error_log("INFO:::" . $message); 90 break; 91 case 'error': 92 error_log("ERROR:::" . $message); 93 break; 124 $lowestLogLevel = $this->getSettingValue('fastcomments_log_level'); 125 // handle no log level defined for backwards compat. 126 if (!$lowestLogLevel || FastCommentsWordPressIntegration::$logLevels[$lowestLogLevel] <= FastCommentsWordPressIntegration::$logLevels[$level]) { 127 switch ($level) { 128 case 'debug': 129 error_log("DEBUG:::" . $message); 130 break; 131 case 'info': 132 error_log("INFO:::" . $message); 133 break; 134 case 'warn': 135 error_log("WARN:::" . $message); 136 break; 137 case 'error': 138 error_log("ERROR:::" . $message); 139 break; 140 } 94 141 } 95 142 } … … 109 156 public function setSettingValue($settingName, $settingValue) { 110 157 update_option($settingName, $settingValue); 158 } 159 160 private function setEventHandled($eventId) { 161 global $wpdb; 162 $event_ids_table_name = $wpdb->prefix . "fastcomments_event_ids"; 163 $insert_result = $wpdb->insert( 164 $event_ids_table_name, 165 array( 166 'id' => $eventId, 167 ) 168 ); 169 if ($insert_result === false) { 170 $this->log('error', "Was not able to mark event $eventId as handled."); 171 } 172 } 173 174 private function isEventHandled($eventId) { 175 global $wpdb; 176 $event_ids_table_name = $wpdb->prefix . "fastcomments_event_ids"; 177 $id_row = $wpdb->get_row("SELECT id FROM $event_ids_table_name WHERE id = \"$eventId\""); 178 if ($id_row) { 179 return true; 180 } 181 return false; 111 182 } 112 183 … … 127 198 $this->log('error', "Was not able to map $fcId to $wpId"); 128 199 } 200 } else if ($existing_wp_id === $wpId) { 201 $this->log('debug', "Skipped mapping $fcId to $wpId - mapping already exists."); 129 202 } else { 130 $this->log('debug', "Skipped mapping $fcId to $wpId - mapping already exists."); 131 } 203 $this->log('warn', "Skipped mapping $fcId to $wpId - ALREADY MAPPED TO $existing_wp_id!"); 204 } 205 } 206 207 private function removeCommentIDMapEntry($fcId, $wpId) { 208 global $wpdb; 209 $id_map_table_name = $wpdb->prefix . "fastcomments_comment_ids"; 210 $id_row = $wpdb->get_row("DELETE FROM $id_map_table_name WHERE id = \"$fcId\" AND wp_id = $wpId LIMIT 1"); 211 if ($id_row) { 212 return $id_row->wp_id; 213 } 214 return null; 132 215 } 133 216 … … 135 218 global $wpdb; 136 219 $id_map_table_name = $wpdb->prefix . "fastcomments_comment_ids"; 137 $this->log('debug', "getWPCommentId $fcId");138 220 $id_row = $wpdb->get_row("SELECT wp_id FROM $id_map_table_name WHERE id = \"$fcId\""); 139 221 if ($id_row) { … … 292 374 foreach ($events as $event) { 293 375 try { 376 $this->log('debug', "BEGIN handleEvents EVENT $event->_id"); 377 378 if ($this->isEventHandled($event->_id)) { 379 $this->log('debug', "END handleEvents EVENT $event->_id SUCCESS - ALREADY HANDLED."); 380 continue; 381 } 382 294 383 /** @type {FastCommentsEventStreamItemData} * */ 295 384 $eventData = json_decode($event->data); … … 302 391 $wp_id = $this->getWPCommentId($fcId); 303 392 $existingComment = isset($wp_id) ? get_comment($wp_id) : null; 304 if (!$existingComment) { 305 $this->log('debug', "Incoming comment $fcId"); 306 $new_wp_comment = $this->fc_to_wp_comment($eventData->comment); 307 if ($new_wp_comment) { 308 $comment_id_or_false = wp_insert_comment($new_wp_comment); 309 if ($comment_id_or_false) { 310 $this->addCommentIDMapEntry($fcId, $comment_id_or_false); 311 add_comment_meta($comment_id_or_false, 'fastcomments_id', $eventData->comment->_id, true); 312 } else { 313 $debug_data = $event->data; 314 $this->log('error', "Failed to save comment: $debug_data"); 315 } 393 $this->log('debug', "Incoming comment $fcId"); 394 if ($existingComment) { 395 $this->log('debug', "Incoming comment $fcId will overwrite existing $wp_id"); 396 wp_delete_comment($wp_id, true); 397 } 398 if ($wp_id) { 399 $this->removeCommentIDMapEntry($fcId, $wp_id); 400 $this->log('debug', "Removing stale $fcId -> $wp_id mapping."); 401 } 402 403 $new_wp_comment = $this->fc_to_wp_comment($eventData->comment); 404 if ($new_wp_comment) { 405 $comment_id_or_false = wp_insert_comment($new_wp_comment); 406 if ($comment_id_or_false) { 407 $this->addCommentIDMapEntry($fcId, $comment_id_or_false); 408 update_comment_meta($comment_id_or_false, 'fastcomments_id', $eventData->comment->_id); 409 $this->log('debug', "Saved $fcId (wp id $comment_id_or_false)"); 316 410 } else { 317 $this->log('debug', "Skipping sync of $fcId - is not from the WP integration."); 411 $debug_data = $event->data; 412 $this->log('error', "Failed to save comment: $debug_data"); 318 413 } 319 414 } else { 320 $this->log('debug', " Incoming comment $fcId ignored, already maps to comment $wp_id");415 $this->log('debug', "Skipping sync of $fcId - is not from the WP integration."); 321 416 } 322 417 break; … … 327 422 if ($wp_comment) { 328 423 wp_update_comment($wp_comment); 329 add_comment_meta($wp_comment['comment_ID'], 'fastcomments_id', $eventData->comment->_id, true);424 update_comment_meta($wp_comment['comment_ID'], 'fastcomments_id', $eventData->comment->_id, true); 330 425 } else { 331 426 $this->log('debug', "Skipping sync of $fcId - is not from the WP integration."); … … 333 428 break; 334 429 case 'deleted-comment': 430 $fcId = $eventData->comment->_id; 335 431 $this->log('debug', "Deleting comment $fcId"); 336 $wp_id = $this->getWPCommentId($ eventData->comment->_id);432 $wp_id = $this->getWPCommentId($fcId); 337 433 if (is_numeric($wp_id)) { 338 wp_trash_comment($wp_id); 434 $was_successful = wp_trash_comment($wp_id); 435 if (!$was_successful) { 436 $this->log('debug', "Attempted to delete $fcId ($wp_id) - but it was not successful!"); 437 } else { 438 $this->removeCommentIDMapEntry($fcId, $wp_id); 439 } 440 } else { 441 $this->log('debug', "Attempted to delete $fcId - but it was not found."); 339 442 } 340 443 break; … … 367 470 break; 368 471 } 472 $this->setEventHandled($event->_id); 473 $this->log('debug', "END handleEvents EVENT $event->_id SUCCESS"); 369 474 } catch (Exception $e) { 475 $this->log('debug', "END handleEvents EVENT $event->_id FAILURE"); 370 476 $this->log('error', $e->getMessage()); 371 477 } … … 376 482 private function getCommentQueryWhere($afterId) { 377 483 // This query ensures a stable sort for pagination and allows us to paginate while not seeing the same comment twice. 378 return "comment_ID > $afterId ";484 return "comment_ID > $afterId AND comment_approved != \"trash\""; 379 485 } 380 486 -
fastcomments/trunk/fastcomments-wordpress-plugin.php
r2588650 r2613148 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. 96 Version: 3.9.10 7 7 Author: winrid @ FastComments 8 8 License: GPL-2.0+ … … 14 14 } 15 15 16 $FASTCOMMENTS_VERSION = 3.9 9;16 $FASTCOMMENTS_VERSION = 3.910; 17 17 18 18 require_once plugin_dir_path(__FILE__) . 'admin/fastcomments-admin.php'; -
fastcomments/trunk/public/fastcomments-public.php
r2588650 r2613148 54 54 require_once plugin_dir_path(__FILE__) . '../core/FastCommentsWordPressIntegration.php'; 55 55 $fastcomments = new FastCommentsWordPressIntegration(); 56 if ($should_set_enabled ) {56 if ($should_set_enabled === true || $should_set_enabled === 'true') { 57 57 $fastcomments->enableSSO(); 58 58 } else { … … 88 88 $result['timestamp'] = $timestamp; 89 89 90 $is_admin = current_user_can('administrator'); 91 $is_moderator = current_user_can('moderate_comments'); 92 90 93 $sso_user = array(); 91 94 if ($wp_user) { … … 95 98 $sso_user['avatar'] = get_avatar_url($wp_user->ID, 95); 96 99 $sso_user['optedInNotifications'] = true; 97 // TODO pass isAdmin/isModerator flags 100 $sso_user['isAdmin'] = $is_admin; 101 $sso_user['isModerator'] = $is_moderator; 98 102 } 99 103 -
fastcomments/trunk/uninstall.php
r2576755 r2613148 15 15 delete_option( 'fastcomments_sso_enabled' ); 16 16 delete_option( 'fastcomments_setup' ); 17 delete_option( 'fastcomments_log_level' ); 17 18 18 19 $fastcomments = new FastCommentsWordPressIntegration();
Note: See TracChangeset
for help on using the changeset viewer.