From 39b151c3c9840a4e6420dc24260ec745d890141f Mon Sep 17 00:00:00 2001 From: Lwangaman Date: Thu, 21 May 2020 21:42:37 +0000 Subject: [PATCH] better handling of bible quotes cache by prefixing transients, added option in settings page to flush bible quotes cache --- bibleget-io.php | 26 ++++++++++++++++++++++++-- css/admin.css | 30 ++++++++++++++++++++++++++++++ js/admin.js | 42 ++++++++++++++++++++++++++++++++++++++++++ options.php | 31 ++++++++++++++++++++----------- readme.txt | 11 +++++++++-- 5 files changed, 125 insertions(+), 15 deletions(-) diff --git a/bibleget-io.php b/bibleget-io.php index eaeb557..f9efabf 100644 --- a/bibleget-io.php +++ b/bibleget-io.php @@ -1,7 +1,7 @@ options + WHERE `option_name` LIKE '%transient_%".TRANSIENT_PREFIX."%' + "; + //We shouldn't have to do a $wpdb->prepare here because there is no kind of user input anywhere + if($wpdb->query( $sql ) !== false){ + echo 'cacheflushed'; + } + else{ + echo 'cacheNotFlushed'; + } + wp_die(); +} + +add_action('wp_ajax_flush_bible_quotes_cache', 'flushBibleQuotesCache'); + function searchByKeyword(){ $keyword = $_POST['keyword']; $version = $_POST['version']; diff --git a/css/admin.css b/css/admin.css index 1185426..93001f7 100644 --- a/css/admin.css +++ b/css/admin.css @@ -72,6 +72,30 @@ form input[type=color] { left: 0; } +#bibleget-settings-contents .flexcontainer { + display: flex; + justify-content: space-evenly; + padding: 15px; + margin: 15px; + border: 1px solid lightgray; + border-radius: 6px; +} + +#bibleget-settings-contents .flexcontainer .flexitem { + flex-grow: 1; + margin: 15px; + border-right: 1px solid gray; +} + +#bibleget-settings-contents .flexcontainer .flexitem:last-child { + border-right: 0px; +} + +#bibleget-settings-contents .flexcontainer .flexitem button { + display: block; + margin: 0px auto; +} + #bibleget_ajax_spinner { position: absolute; background-color: rgba(0, 0, 0, 0.7); @@ -180,3 +204,9 @@ form input[type=color] { #biblegetForceRefreshGFapiResults:hover,#biblegetGFapiKeyRetest:hover { text-decoration: underline; } + +#versionselect { + overflow-y: hidden; + max-width: 100%; + width: 30em; +} diff --git a/js/admin.js b/js/admin.js index 43fc7a2..1bf7a74 100644 --- a/js/admin.js +++ b/js/admin.js @@ -81,6 +81,48 @@ jQuery(document).ready(function($) { }); }); + jQuery('#bibleget-cache-flush-btn').on('click', function(){ + jQuery.ajax({ + type: 'POST', + url: bibleGetOptionsFromServer.ajax_url, + data: { action: 'flush_bible_quotes_cache' }, + beforeSend : function() { + jQuery('#bibleget_ajax_spinner').show(); + }, + complete : function() { + jQuery('#bibleget_ajax_spinner').hide(); + }, + success : function(returndata) { + if (returndata == 'cacheflushed') { + jQuery( + "#bibleget-settings-notification") + .append( + 'Bible quotes cache emptied successfully') + .fadeIn("slow"); + } else { + jQuery("#bibleget-settings-notification").append( + 'There was an error while attempting to flush the Bible quotes cache... Perhaps try again?') + .fadeIn("slow"); + } + jQuery(".bibleget-settings-notification-dismiss") + .click(function() { + jQuery("#bibleget-settings-notification").fadeOut("slow"); + }); + + }, + error: function(xhr, ajaxOptions, thrownError){ + jQuery("#bibleget-settings-notification") + .fadeIn("slow") + .append('Emptying of Bible quotes cache was not successful... ERROR: ' + xhr.responseText); + jQuery(".bibleget-settings-notification-dismiss") + .click(function() { + jQuery("#bibleget-settings-notification").fadeOut("slow"); + }); + + } + }); + }); + if(typeof gfontsBatch !== 'undefined' && typeof gfontsBatch === 'object' && gfontsBatch.hasOwnProperty('job') && gfontsBatch.job.hasOwnProperty('gfontsPreviewJob') && gfontsBatch.job.gfontsPreviewJob === true && gfontsBatch.job.hasOwnProperty('gfontsWeblist') && typeof gfontsBatch.job.gfontsWeblist == 'object' && gfontsBatch.job.gfontsWeblist.hasOwnProperty('items') ){ //console.log('We have a gfontsPreviewJob to do! gfontsBatch: '); //console.log(gfontsBatch); diff --git a/options.php b/options.php index 71eb082..9c7bf5a 100644 --- a/options.php +++ b/options.php @@ -428,7 +428,7 @@ public function admin_print_scripts($hook) if ($this->gfontsAPIkeyCheckResult == "SUCCESS") { //We only want the transient to be set from the bibleget settings page, so we wait until now // instead of doing it in the gfontsAPIkeyCheck (which is called on any admin interface) - set_transient(TRANSIENT_PREFIX.md5($this->options['googlefontsapi_key']), $this->gfontsAPIkeyCheckResult, 90 * 24 * HOUR_IN_SECONDS); // 90 giorni + set_transient(md5($this->options['googlefontsapi_key']), $this->gfontsAPIkeyCheckResult, 90 * 24 * HOUR_IN_SECONDS); // 90 giorni $plugin_path = ""; // bibleGetWriteLog("about to initialize creation of admin page..."); @@ -543,8 +543,16 @@ public function create_admin_page() echo "
" . implode(", ", $this->biblebookslangs) . "
"; ?> -

- +
+
+

+ +
+
+

+ +
+
@@ -632,6 +640,7 @@ public function favorite_version_callback() echo ''; } echo ''; + echo '
'.__("In order to select multiple items, hold down CTRL key (Command key on Mac) while clicking items.","bibleget-io").''; echo ''; } @@ -662,14 +671,14 @@ public function googlefontsapikey_callback() $gfontsAPIkeyTimeLeft = (count($timeLeft) > 0) ? "[" . implode(", ", $timeLeft) . "]" : ""; /* translators: refers to the outcome of the validity check of the Google Fonts API key */ - echo '' . __("VALID", "bibleget-io") . ''; + echo '' . __("VALID", "bibleget-io") . '
'; echo ' ' . sprintf(__("Google Fonts API refresh scheduled in: %s", "bibleget-io"), $gfontsAPIkeyTimeLeft); echo ' ' . sprintf(__("OR %s Click here %s to force refresh the list of fonts from the Google Fonts API", "bibleget-io"), '', ''); echo ''; break; case "CURL_ERROR": /* translators: refers to the outcome of the validity check of the Google Fonts API key */ - echo '' . __("CURL ERROR WHEN SENDING REQUEST", "bibleget-io") . ''; + echo '' . __("CURL ERROR WHEN SENDING REQUEST", "bibleget-io") . '
'; foreach ($this->gfontsAPI_errors as $er) { if ($er == 403) { echo '
'; @@ -683,11 +692,11 @@ public function googlefontsapikey_callback() break; case "JSON_ERROR": /* translators: refers to the outcome of the validity check of the Google Fonts API key */ - echo '' . __("NO VALID JSON RESPONSE", "bibleget-io") . ''; + echo '' . __("NO VALID JSON RESPONSE", "bibleget-io") . '
'; break; case "REQUEST_NOT_SENT": /* translators: refers to the outcome of the validity check of the Google Fonts API key */ - echo '' . __("SERVER UNABLE TO MAKE REQUESTS", "bibleget-io") . ''; + echo '' . __("SERVER UNABLE TO MAKE REQUESTS", "bibleget-io") . '
'; break; } } else { @@ -717,7 +726,7 @@ public function gfontsAPIkeyCheck() $this->gfontsAPIkey = $this->options['googlefontsapi_key']; //has this key been tested in the past 3 months at least? - if (false === ($result = get_transient(TRANSIENT_PREFIX.md5($this->options['googlefontsapi_key'])))) { + if (false === ($result = get_transient(md5($this->options['googlefontsapi_key'])))) { //We will make a secure connection to the Google Fonts API endpoint $curl_version = curl_version(); @@ -778,7 +787,7 @@ public function gfontsAPIkeyCheck() //we have a previously saved api key which has been tested //$result is not false global $wpdb; - $transientKey = TRANSIENT_PREFIX.md5($this->options['googlefontsapi_key']); + $transientKey = md5($this->options['googlefontsapi_key']); $transient_timeout = $wpdb->get_col(" SELECT option_value FROM $wpdb->options @@ -979,8 +988,8 @@ public function bibleGetForceRefreshGFontsResults() { check_ajax_referer('refresh_gfonts_results_nonce', 'security', TRUE); //no need for an "if", it will die if not valid if (isset($_POST["gfontsApiKey"]) && $_POST["gfontsApiKey"] != "") { - if (get_transient(TRANSIENT_PREFIX.md5($_POST["gfontsApiKey"]))) { - delete_transient(TRANSIENT_PREFIX.md5($_POST["gfontsApiKey"])); + if (get_transient(md5($_POST["gfontsApiKey"]))) { + delete_transient(md5($_POST["gfontsApiKey"])); echo 'TRANSIENT_DELETED'; wp_die(); } diff --git a/readme.txt b/readme.txt index addb0c1..653862b 100644 --- a/readme.txt +++ b/readme.txt @@ -2,9 +2,9 @@ Contributors: Lwangaman Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=HDS7XQKGFHJ58 Tags: bible,shortcode,quote,citation,verses,bibbia,citazione,versetti,biblia,cita,versiculos,versets,citation -Requires at least: 3.3 +Requires at least: 5.0 Tested up to: 5.4.1 -Stable tag: 5.6 +Stable tag: 5.7 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -94,6 +94,10 @@ If you receive a 504 http status error it means that the connection with the Goo == Changelog == += 5.7 = +* better handling of bible quotes cache by prefixing the transients +* added option to flush bible quotes cache from settings page + = 5.6 = * turn off PHP error reporting! @@ -261,6 +265,9 @@ If you receive a 504 http status error it means that the connection with the Goo == Upgrade Notice == += 5.7 = +Versions prior to 5.1 must be updated. v5.4 adds a Gutenberg block + = 5.6 = Versions prior to 5.1 must be updated. v5.4 adds a Gutenberg block