Skip to content

Commit

Permalink
add prefix to transients so we can target them if necessary; remove l…
Browse files Browse the repository at this point in the history
…eft float and size from options page
  • Loading branch information
Lwangaman authored and Lwangaman committed May 21, 2020
1 parent 6d336d8 commit 7e730d0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
25 changes: 14 additions & 11 deletions bibleget-io.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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']));
}
}

Expand Down Expand Up @@ -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 '<div class="bibleget-quote-div">' . $output . '</div>';
$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 = '<span style="color:Red;font-weight:bold;">' . __("Bible Quote failure... Temporary error from the BibleGet server. Please try again in a few minutes", "bibleget-io") . '</span>';
}
Expand Down Expand Up @@ -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 '<div class="bibleget-quote-div">' . $output . '</div>';
$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 = '<span style="color:Red;font-weight:bold;">' . __("Bible Quote failure... Temporary error from the BibleGet server. Please try again in a few minutes", "bibleget-io") . '</span>';
}
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ h2#bibleget-h2:before {
margin-right: 0.3em;
}

#page-wrap>div.leftfloat {
float: left;
width: 45%;
}

.page-clear {
clear: both;
}
Expand Down
12 changes: 6 additions & 6 deletions options.php
Original file line number Diff line number Diff line change
Expand Up @@ -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...");
Expand Down Expand Up @@ -638,7 +638,7 @@ public function favorite_version_callback()
public function googlefontsapikey_callback()
{

echo '<label for="googlefontsapi_key">' . __("Google Fonts API Key", "bibleget-io") . ' <input type="text" id="googlefontsapi_key" name="bibleget_settings[googlefontsapi_key]" value="' . $this->gfontsAPIkey . '" style="width:100%;" /></label>';
echo '<label for="googlefontsapi_key">' . __("Google Fonts API Key", "bibleget-io") . ' <input type="text" id="googlefontsapi_key" name="bibleget_settings[googlefontsapi_key]" value="' . $this->gfontsAPIkey . '" size="50" /></label>';
if ($this->gfontsAPIkeyCheckResult) {
switch ($this->gfontsAPIkeyCheckResult) {
case "SUCCESS":
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 7e730d0

Please sign in to comment.