From 7e730d0e8162869b90fe6b97e963f7cbec26d5e8 Mon Sep 17 00:00:00 2001 From: Lwangaman Date: Thu, 21 May 2020 20:05:12 +0000 Subject: [PATCH] add prefix to transients so we can target them if necessary; remove left float and size from options page --- bibleget-io.php | 25 ++++++++++++++----------- css/admin.css | 5 ----- options.php | 12 ++++++------ 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/bibleget-io.php b/bibleget-io.php index bbc0fb5..eaeb557 100644 --- a/bibleget-io.php +++ b/bibleget-io.php @@ -3,7 +3,7 @@ * Plugin Name: BibleGet I/O * Version: 5.6 * Plugin URI: https://www.bibleget.io/ - * Description: Easily insert Bible quotes from a choice of Bible versions into your articles or pages with the shortcode [bibleget]. + * Description: Easily insert Bible quotes from a choice of Bible versions into your articles or pages with the "Bible quote" block or with the shortcode [bibleget]. * Author: John Romano D'Orazio * Author URI: https://www.johnromanodorazio.com/ * Text Domain: bibleget-io @@ -37,6 +37,8 @@ exit(); } +define("TRANSIENT_PREFIX","bibleget_"); + //error_reporting(E_ALL); //ini_set('display_errors', 'on'); require_once(plugin_dir_path(__FILE__) . "options.php"); @@ -112,8 +114,8 @@ function BibleGet_on_uninstall() //Check if we have a Google Fonts API key transient, if so remove it $BibleGetOptions = get_option('bibleget_settings'); if (isset($BibleGetOptions['googlefontsapi_key']) && $BibleGetOptions['googlefontsapi_key'] != "") { - if (get_transient(md5($BibleGetOptions['googlefontsapi_key']))) { - delete_transient(md5($BibleGetOptions['googlefontsapi_key'])); + if (get_transient(TRANSIENT_PREFIX.md5($BibleGetOptions['googlefontsapi_key']))) { + delete_transient(TRANSIENT_PREFIX.md5($BibleGetOptions['googlefontsapi_key'])); } } @@ -244,13 +246,13 @@ function bibleget_shortcode($atts = [], $content = null, $tag = '') // bibleGetWriteLog("value of finalquery = ".$finalquery); if ($finalquery != "") { - if (false === ($output = get_transient(md5($finalquery)))) { + if (false === ($output = get_transient(TRANSIENT_PREFIX.md5($finalquery)))) { // $output = $finalquery; // return '
' . $output . '
'; $output = bibleGetQueryServer($finalquery); if ($output) { $output = str_replace(PHP_EOL, '', $output); - set_transient(md5($finalquery), $output, 7 * 24 * HOUR_IN_SECONDS); + set_transient(TRANSIENT_PREFIX.md5($finalquery), $output, 7 * 24 * HOUR_IN_SECONDS); } else { $output = '' . __("Bible Quote failure... Temporary error from the BibleGet server. Please try again in a few minutes", "bibleget-io") . ''; } @@ -427,13 +429,13 @@ function bibleGet_renderGutenbergBlock($atts) // bibleGetWriteLog("value of finalquery = ".$finalquery); if ($finalquery != "") { - if (false === ($output = get_transient(md5($finalquery)))) { + if (false === ($output = get_transient(TRANSIENT_PREFIX.md5($finalquery)))) { // $output = $finalquery; // return '
' . $output . '
'; $output = bibleGetQueryServer($finalquery); if ($output) { $output = str_replace(PHP_EOL, '', $output); - set_transient(md5($finalquery), $output, 7 * 24 * HOUR_IN_SECONDS); + set_transient(TRANSIENT_PREFIX.md5($finalquery), $output, 7 * 24 * HOUR_IN_SECONDS); } else { $output = '' . __("Bible Quote failure... Temporary error from the BibleGet server. Please try again in a few minutes", "bibleget-io") . ''; } @@ -534,16 +536,17 @@ function bibleGet_renderGutenbergBlock($atts) if ($currentLangIdx === false) { $currentLangIdx = array_search("English", $biblebookslangs); } - $lclabbrev = $jsbook[$currentLangIdx][1]; $lclbook = $jsbook[$currentLangIdx][0]; + $lclabbrev = $jsbook[$currentLangIdx][1]; $bookChapterText = $bookChapterEl->textContent; - if (preg_match("/^([1-3]{0,1}((\p{L}\p{M}*)+))/u", $bookChapterText, $res)) { + //Remove book name from the string (check includes any possible spaces in the book name) + if (preg_match('/^([1-3I]{0,3}[\s]{0,1}((\p{L}\p{M}*)+))/u', $bookChapterText, $res)) { $bookChapterText = str_replace($res[0], "", $bookChapterText); } if($atts['usebookabbreviation'] === true){ //use abbreviated form in wp lang - $bookChapterEl->textContent = $lclabbrev . $bookChapterText; + $bookChapterEl->textContent = $lclabbrev . $bookChapterText; } else{ //use full form in wp lang @@ -557,7 +560,7 @@ function bibleGet_renderGutenbergBlock($atts) foreach ($bookChapterEls as $bookChapterEl) { $bookAbbrev = $xPath->query('following-sibling::input[@class="bookAbbrev"]', $bookChapterEl)->item(0)->getAttribute("value"); $bookChapterText = $bookChapterEl->textContent; - if (preg_match("/^([1-3]{0,1}((\p{L}\p{M}*)+))/u", $bookChapterText, $res)) { + if (preg_match('/^([1-3I]{0,3}[\s]{0,1}((\p{L}\p{M}*)+))/u', $bookChapterText, $res)) { $bookChapterText = str_replace($res[0], "", $bookChapterText); } $bookChapterEl->textContent = $bookAbbrev . $bookChapterText; diff --git a/css/admin.css b/css/admin.css index 3e6bf0e..1185426 100644 --- a/css/admin.css +++ b/css/admin.css @@ -7,11 +7,6 @@ h2#bibleget-h2:before { margin-right: 0.3em; } -#page-wrap>div.leftfloat { - float: left; - width: 45%; -} - .page-clear { clear: both; } diff --git a/options.php b/options.php index 8a2e2b0..d75a682 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(md5($this->options['googlefontsapi_key']), $this->gfontsAPIkeyCheckResult, 90 * 24 * HOUR_IN_SECONDS); // 90 giorni + set_transient(TRANSIENT_PREFIX.md5($this->options['googlefontsapi_key']), $this->gfontsAPIkeyCheckResult, 90 * 24 * HOUR_IN_SECONDS); // 90 giorni $plugin_path = ""; // bibleGetWriteLog("about to initialize creation of admin page..."); @@ -638,7 +638,7 @@ public function favorite_version_callback() public function googlefontsapikey_callback() { - echo ''; + echo ''; if ($this->gfontsAPIkeyCheckResult) { switch ($this->gfontsAPIkeyCheckResult) { case "SUCCESS": @@ -717,7 +717,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(md5($this->options['googlefontsapi_key'])))) { + if (false === ($result = get_transient(TRANSIENT_PREFIX.md5($this->options['googlefontsapi_key'])))) { //We will make a secure connection to the Google Fonts API endpoint $curl_version = curl_version(); @@ -778,7 +778,7 @@ public function gfontsAPIkeyCheck() //we have a previously saved api key which has been tested //$result is not false global $wpdb; - $transientKey = md5($this->options['googlefontsapi_key']); + $transientKey = TRANSIENT_PREFIX.md5($this->options['googlefontsapi_key']); $transient_timeout = $wpdb->get_col(" SELECT option_value FROM $wpdb->options @@ -979,8 +979,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(md5($_POST["gfontsApiKey"]))) { - delete_transient(md5($_POST["gfontsApiKey"])); + if (get_transient(TRANSIENT_PREFIX.md5($_POST["gfontsApiKey"]))) { + delete_transient(TRANSIENT_PREFIX.md5($_POST["gfontsApiKey"])); echo 'TRANSIENT_DELETED'; wp_die(); }