Skip to content

Commit

Permalink
font-family dropdown previews the font
Browse files Browse the repository at this point in the history
  • Loading branch information
Lwangaman authored and Lwangaman committed Jun 11, 2017
1 parent 126a948 commit da18e7b
Show file tree
Hide file tree
Showing 9 changed files with 244 additions and 93 deletions.
69 changes: 41 additions & 28 deletions bibleget-io.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/*
* Plugin Name: BibleGet I/O
* Version: 4.3
* Version: 4.5
* 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].
* Author: John Romano D'Orazio
Expand All @@ -26,7 +26,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
define ( "BIBLEGETPLUGINVERSION", "v4_4" );
define ( "BIBLEGETPLUGINVERSION", "v4_5" );

if (! defined ( 'ABSPATH' )) {
header ( 'Status: 403 Forbidden' );
Expand Down Expand Up @@ -641,15 +641,15 @@ function bibleGetCheckQuery($thisquery, $indexes, $thisbook = "") {
/* Mighty fine and dandy helper function I created! */
function bibleGetToProperCase($txt) {
// echo "<div style=\"border:3px solid Yellow;\">txt = $txt</div>";
preg_match ( "/\p{L}/u", $txt, $mList, PREG_OFFSET_CAPTURE );
$idx = intval ( $mList [0] [1] );
preg_match( "/\p{L}/u", $txt, $mList, PREG_OFFSET_CAPTURE );
$idx = intval( $mList[0][1] );
// echo "<div style=\"border:3px solid Purple;\">idx = $idx</div>";
$chr = mb_substr ( $txt, $idx, 1, 'UTF-8' );
$chr = mb_substr( $txt, $idx, 1, 'UTF-8' );
// echo "<div style=\"border:3px solid Pink;\">chr = $chr</div>";
if (preg_match ( "/\p{L&}/u", $chr )) {
$post = mb_substr ( $txt, $idx + 1, mb_strlen ( $txt ), 'UTF-8' );
if (preg_match( "/\p{L&}/u", $chr )) {
$post = mb_substr( $txt, $idx + 1, mb_strlen ( $txt ), 'UTF-8' );
// echo "<div style=\"border:3px solid Black;\">post = $post</div>";
return mb_substr ( $txt, 0, $idx, 'UTF-8' ) . mb_strtoupper ( $chr, 'UTF-8' ) . mb_strtolower ( $post, 'UTF-8' );
return mb_substr( $txt, 0, $idx, 'UTF-8' ) . mb_strtoupper ( $chr, 'UTF-8' ) . mb_strtolower ( $post, 'UTF-8' );
} else {
return $txt;
}
Expand Down Expand Up @@ -678,7 +678,7 @@ function bibleGetIsValidBook($book) {
if (get_option ( "bibleget_biblebooks0" ) === false) {
bibleGetSetOptions ();
}
for($i = 0; $i < 73; $i ++) {
for($i = 0; $i < 73; $i++) {
$usrprop = "bibleget_biblebooks" . $i;
$jsbook = json_decode ( get_option ( $usrprop ), true );
array_push ( $biblebooks, $jsbook );
Expand All @@ -704,7 +704,7 @@ function bibleGetGetMetaData($request) {
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2 );
//echo "<div>" . plugins_url ( 'DST_Root_CA.cer',__FILE__ ) . "</div>";
//curl_setopt($ch, CURLOPT_CAINFO, plugin_dir_path ( __FILE__ ) . "DST_Root_CA.cer"); //seems to work.. ???
//curl_setopt($ch, CURLOPT_CAINFO, plugin_dir_path ( __FILE__ ) . "ca/DST_Root_CA.cer"); //seems to work.. ???
//curl_setopt($ch, CURLOPT_CAINFO, plugin_dir_path ( __FILE__ ) . "DST_Root_CA.pem");

}
Expand All @@ -723,13 +723,41 @@ function bibleGetGetMetaData($request) {
}

$response = curl_exec ( $ch );
if (curl_errno ( $ch )) {
if (curl_errno ( $ch ) && (curl_errno($ch) === 77 || curl_errno($ch) === 60) && $url == "https://query.bibleget.io/metadata.php?query=" . $request . "&return=json" ) {
//error 60: SSL certificate problem: unable to get local issuer certificate
//error 77: error setting certificate verify locations CAPath: none
//curl.cainfo needs to be set in php.ini to point to the curl pem bundle available at https://curl.haxx.se/ca/cacert.pem
//until that's fixed on the server environment let's resort to a simple http request
$url = "http://query.bibleget.io/metadata.php?query=" . $request . "&return=json";
curl_setopt( $ch, CURLOPT_URL, $url );
$response = curl_exec ( $ch );
if (curl_errno ( $ch )) {
$optionsurl = admin_url ( "options-general.php?page=bibleget-settings-admin" );
/* translators: do not change the placeholders or the html markup, though you can translate the anchor title */
$notices [] = "BIBLEGET PLUGIN ERROR: " . sprintf ( __ ( "There was a problem communicating with the BibleGet server. <a href=\"%s\" title=\"update metadata now\">Metadata needs to be manually updated</a>." ), $optionsurl ) . " (" . bibleGetCurrentPageUrl () . ")";
update_option ( 'bibleget_error_admin_notices', $notices );
return false;
}
else {
$info = curl_getinfo ( $ch );
// echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url'];
if ($info ["http_code"] != 200) {
$optionsurl = admin_url ( "options-general.php?page=bibleget-settings-admin" );
/* translators: do not change the placeholders or the html markup, though you can translate the anchor title */
$notices [] = "BIBLEGET PLUGIN ERROR: " . sprintf ( __ ( "There may have been a problem communicating with the BibleGet server. <a href=\"%s\" title=\"update metadata now\">Metadata needs to be manually updated</a>." ), $optionsurl ) . " (" . bibleGetCurrentPageUrl () . ")";
update_option ( 'bibleget_error_admin_notices', $notices );
return false;
}
}
}
elseif (curl_errno ( $ch )){
$optionsurl = admin_url ( "options-general.php?page=bibleget-settings-admin" );
/* translators: do not change the placeholders or the html markup, though you can translate the anchor title */
$notices [] = "BIBLEGET PLUGIN ERROR: " . sprintf ( __ ( "There was a problem communicating with the BibleGet server. <a href=\"%s\" title=\"update metadata now\">Metadata needs to be manually updated</a>." ), $optionsurl ) . " (" . bibleGetCurrentPageUrl () . ")";
update_option ( 'bibleget_error_admin_notices', $notices );
return false;
} else {
}
else {
$info = curl_getinfo ( $ch );
// echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url'];
if ($info ["http_code"] != 200) {
Expand Down Expand Up @@ -1272,19 +1300,4 @@ function bibleGetCurrentPageUrl() {
return $pageURL;
}

/**
* Function bibleGetSaveCss_action
* Handles ajax requests for the modification of the custom css file
*/
add_action ( 'wp_ajax_bibleGetSaveCss_action', 'bibleGetSaveCss_action' );
function bibleGetSaveCss_action() {
global $wpdb; // this is how you get access to the database

$whatever = intval ( $_POST ['whatever'] );

$whatever += 10;

echo $whatever;

wp_die (); // this is required to terminate immediately and return a proper response
}

Binary file added ca/DST_Root_CA.cer
Binary file not shown.
20 changes: 20 additions & 0 deletions ca/DST_Root_CA.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-----BEGIN CERTIFICATE-----
MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/
MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT
DkRTVCBSb290IENBIFgzMB4XDTAwMDkzMDIxMTIxOVoXDTIxMDkzMDE0MDExNVow
PzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD
Ew5EU1QgUm9vdCBDQSBYMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
AN+v6ZdQCINXtMxiZfaQguzH0yxrMMpb7NnDfcdAwRgUi+DoM3ZJKuM/IUmTrE4O
rz5Iy2Xu/NMhD2XSKtkyj4zl93ewEnu1lcCJo6m67XMuegwGMoOifooUMM0RoOEq
OLl5CjH9UL2AZd+3UWODyOKIYepLYYHsUmu5ouJLGiifSKOeDNoJjj4XLh7dIN9b
xiqKqy69cK3FCxolkHRyxXtqqzTWMIn/5WgTe1QLyNau7Fqckh49ZLOMxt+/yUFw
7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40dutolucbY38EVAjqr2m7xPi71XAicPNaD
aeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNV
HQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMSnsaR7LHH62+FLkHX/xBVghYkQMA0GCSqG
SIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69
ikugdB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXr
AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz
R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5
JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo
Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ
-----END CERTIFICATE-----
Binary file added ca/LETSENCRYPT.cer
Binary file not shown.
27 changes: 27 additions & 0 deletions ca/LETSENCRYPT.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-----BEGIN CERTIFICATE-----
MIIEkjCCA3qgAwIBAgIQCgFBQgAAAVOFc2oLheynCDANBgkqhkiG9w0BAQsFADA/
MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT
DkRTVCBSb290IENBIFgzMB4XDTE2MDMxNzE2NDA0NloXDTIxMDMxNzE2NDA0Nlow
SjELMAkGA1UEBhMCVVMxFjAUBgNVBAoTDUxldCdzIEVuY3J5cHQxIzAhBgNVBAMT
GkxldCdzIEVuY3J5cHQgQXV0aG9yaXR5IFgzMIIBIjANBgkqhkiG9w0BAQEFAAOC
AQ8AMIIBCgKCAQEAnNMM8FrlLke3cl03g7NoYzDq1zUmGSXhvb418XCSL7e4S0EF
q6meNQhY7LEqxGiHC6PjdeTm86dicbp5gWAf15Gan/PQeGdxyGkOlZHP/uaZ6WA8
SMx+yk13EiSdRxta67nsHjcAHJyse6cF6s5K671B5TaYucv9bTyWaN8jKkKQDIZ0
Z8h/pZq4UmEUEz9l6YKHy9v6Dlb2honzhT+Xhq+w3Brvaw2VFn3EK6BlspkENnWA
a6xK8xuQSXgvopZPKiAlKQTGdMDQMc2PMTiVFrqoM7hD8bEfwzB/onkxEz0tNvjj
/PIzark5McWvxI0NHWQWM6r6hCm21AvA2H3DkwIDAQABo4IBfTCCAXkwEgYDVR0T
AQH/BAgwBgEB/wIBADAOBgNVHQ8BAf8EBAMCAYYwfwYIKwYBBQUHAQEEczBxMDIG
CCsGAQUFBzABhiZodHRwOi8vaXNyZy50cnVzdGlkLm9jc3AuaWRlbnRydXN0LmNv
bTA7BggrBgEFBQcwAoYvaHR0cDovL2FwcHMuaWRlbnRydXN0LmNvbS9yb290cy9k
c3Ryb290Y2F4My5wN2MwHwYDVR0jBBgwFoAUxKexpHsscfrb4UuQdf/EFWCFiRAw
VAYDVR0gBE0wSzAIBgZngQwBAgEwPwYLKwYBBAGC3xMBAQEwMDAuBggrBgEFBQcC
ARYiaHR0cDovL2Nwcy5yb290LXgxLmxldHNlbmNyeXB0Lm9yZzA8BgNVHR8ENTAz
MDGgL6AthitodHRwOi8vY3JsLmlkZW50cnVzdC5jb20vRFNUUk9PVENBWDNDUkwu
Y3JsMB0GA1UdDgQWBBSoSmpjBH3duubRObemRWXv86jsoTANBgkqhkiG9w0BAQsF
AAOCAQEA3TPXEfNjWDjdGBX7CVW+dla5cEilaUcne8IkCJLxWh9KEik3JHRRHGJo
uM2VcGfl96S8TihRzZvoroed6ti6WqEBmtzw3Wodatg+VyOeph4EYpr/1wXKtx8/
wApIvJSwtmVi4MFU5aMqrSDE6ea73Mj2tcMyo5jMd6jmeWUHK8so/joWUoHOUgwu
X4Po1QYz+3dszkDqMp4fklxBwXRsW10KXzPMTZ+sOPAveyxindmjkW8lGy+QsRlG
PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6
KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==
-----END CERTIFICATE-----
170 changes: 119 additions & 51 deletions custom_controls.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,131 @@ class BibleGet_Customize_StyleBar_Control extends WP_Customize_Control {
public $type = 'stylebar';
public function enqueue() {
wp_enqueue_script ( 'bibleget-stylebar-control', // Give the script a unique ID
plugins_url ( 'js/stylebar-control.js', __FILE__ ), // Define the path to the JS file
array (
'jquery'
), // Define dependencies
'', // Define a version (optional)
true ) // Specify whether to put in footer (leave this true)
;
plugins_url ( 'js/stylebar-control.js', __FILE__ ), // Define the path to the JS file
array ( 'jquery' ), // Define dependencies
'', // Define a version (optional)
true ); // Specify whether to put in footer (leave this true)
}
public function render_content() {
$styles = explode ( ",", esc_attr ( $this->value () ) );
?>
<input type="hidden" <?php $this->link(); ?>
value="<?php echo esc_attr( $this->value() ); ?>" />
$styles = explode ( ",", esc_attr ( $this->value() ) );
?>
<input type="hidden" <?php $this->link(); ?> value="<?php echo esc_attr( $this->value() ); ?>" />
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<?php
if (! empty ( $this->description )) :
?>
<?php if (! empty ( $this->description )) : ?>
<span class="description customize-control-description"><?php echo esc_html( $this->description ); ?></span>
<?php endif; ?>
<div class="bibleget-buttonset button-group button-large">
<?php foreach ( $this->choices as $value => $label ) : ?>
<?php
$labelstyles = "";
switch ($value) {
case 'bold' :
$labelstyles .= "font-weight:bold;";
break;
case 'italic' :
$labelstyles .= "font-style:italic;";
break;
case 'underline' :
$labelstyles .= "text-decoration:underline;";
break;
case 'strikethrough' :
$labelstyles .= "text-decoration:line-through;";
break;
case 'superscript' :
$labelstyles .= "font-size:0.7em;vertical-align:baseline;position:relative;top:-0.6em;";
break;
case 'subscript' :
$labelstyles .= "font-size:0.7em;vertical-align:baseline;position:relative;top:0.6em;";
break;
}
?>
<label
class="button <?php echo in_array( $value, $styles ) ? "button-primary" : "button-secondary" ;?>">
<span style="display:block;<?php echo $labelstyles; ?>"><?php echo esc_html( $label ); ?></span>
<input class="ui-helper-hidden-accessible" type="checkbox"
value="<?php echo esc_attr( $value ); ?>"
<?php checked( in_array( $value, $styles ) ); ?>
style="height: 0px; width: 0px;" />
</label>
<?php endforeach; ?>

</div>
<?php foreach ( $this->choices as $value => $label ) : ?>
<?php
$labelstyles = "";
switch ($value) {
case 'bold' :
$labelstyles .= "font-weight:bold;";
break;
case 'italic' :
$labelstyles .= "font-style:italic;";
break;
case 'underline' :
$labelstyles .= "text-decoration:underline;";
break;
case 'strikethrough' :
$labelstyles .= "text-decoration:line-through;";
break;
case 'superscript' :
$labelstyles .= "font-size:0.7em;vertical-align:baseline;position:relative;top:-0.6em;";
break;
case 'subscript' :
$labelstyles .= "font-size:0.7em;vertical-align:baseline;position:relative;top:0.6em;";
break;
}
?>
<label class="button <?php echo in_array( $value, $styles ) ? "button-primary" : "button-secondary" ;?>">
<span style="display:block;<?php echo $labelstyles; ?>"><?php echo esc_html( $label ); ?></span>
<input class="ui-helper-hidden-accessible" type="checkbox" value="<?php echo esc_attr( $value ); ?>" <?php checked( in_array( $value, $styles ) ); ?> style="height: 0px; width: 0px;" />
</label>
<?php endforeach; ?>

</div>
<?php
} // end public function render_content
} // end class BibleGet_Customize_StyleBar_Control

class BibleGet_Customize_FontSelect_Control extends WP_Customize_Control {
private $safe_fonts = false;
public $type = 'fontselect';

public function __construct($manager, $id, $args = array() ){
$this->safe_fonts = array(
array("font-family" => "Arial", "fallback" => "Helvetica", "generic-family" => "sans-serif"),
array("font-family" => "Arial Black", "fallback" => "Gadget", "generic-family" => "sans-serif"),
array("font-family" => "Book Antiqua", "fallback" => "Palatino", "generic-family" => "serif"),
array("font-family" => "Courier New", "fallback" => "Courier", "generic-family" => "monospace"),
array("font-family" => "Georgia", "generic-family" => "serif"),
array("font-family" => "Impact", "fallback" => "Charcoal", "generic-family" => "sans-serif"),
array("font-family" => "Lucida Console", "fallback" => "Monaco", "generic-family" => "monospace"),
array("font-family" => "Lucida Sans Unicode", "fallback" => "Lucida Grande", "generic-family" => "sans-serif"),
array("font-family" => "Palatino Linotype", "fallback" => "Palatino", "generic-family" => "serif"),
array("font-family" => "Tahoma", "fallback" => "Geneva", "generic-family" => "sans-serif"),
array("font-family" => "Times New Roman", "fallback" => "Times", "generic-family" => "serif"),
array("font-family" => "Trebuchet MS", "fallback" => "Helvetica", "generic-family" => "sans-serif"),
array("font-family" => "Verdana", "fallback" => "Geneva", "generic-family" => "sans-serif")
);
parent::__construct( $manager, $id, $args );
}

public function get_font_index($fontfamily){
foreach($this->safe_fonts as $index => $font){
if($font["font-family"] == $fontfamily){ return $index; }
}
return false;
}
}
}
/*
public function enqueue() {
wp_enqueue_script ( 'bibleget-fontselect-control', // Give the script a unique ID
plugins_url ( 'js/fontselect-control.js', __FILE__ ), // Define the path to the JS file
array ( 'jquery' ), // Define dependencies
'', // Define a version (optional)
true ); // Specify whether to put in footer (leave this true)
}
*/
public function render_content() {
?>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<?php if (! empty ( $this->description )) : ?>
<span class="description customize-control-description"><?php echo esc_html( $this->description ); ?></span>
<?php endif; ?>
<?php
if(!empty($this->safe_fonts) ){
$fidx = $this->get_font_index($this->value());
$style = '';
$flbk = '';

if($fidx!==false){
if(isset($this->safe_fonts[$fidx]["fallback"])){
$flbk = '&apos;'.$this->safe_fonts[$fidx]["fallback"].'&apos;,';
}
$style = ' style="font-family:&apos;'.$this->safe_fonts[$fidx]["font-family"].'&apos;,'.$flbk.'&apos;'.$this->safe_fonts[$fidx]["generic-family"].'&apos;;padding:0px;margin:0px;text-align:left;"';
}

?>
<select <?php $this->link(); echo $style; ?>>
<?php
foreach ( $this->safe_fonts as $index => $font ) :
$flbk = '';
if(isset($font["fallback"])){
$flbk = '&apos;'.$font["fallback"].'&apos;,';
}
$style = ' style="font-family:&apos;'.$font["font-family"].'&apos;,'.$flbk.'&apos;'.$font["generic-family"].'&apos;;padding:0px;margin:0px;text-align:left;"';
$selected = $this->value() == $font["font-family"] ? " SELECTED" : "";
echo '<optgroup'.$style.'><option value="'.$font["font-family"].'" style="padding:0px;margin:0px;text-align:left;"'.$selected.'>'.$font["font-family"].'</option></optgroup>';
endforeach;
}// end if not empty this->safe_fonts
?>
</select>
<?php
} // end public function render_content
} // end class BibleGet_Customize_FontSelect_Control

} // end if class exists WP_Customize_Control
4 changes: 2 additions & 2 deletions js/stylebar-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ wp.customize.controlConstructor['stylebar'] = wp.customize.Control.extend({
ready : function() {
'use strict';

var control = this, checkboxes = jQuery('input:checkbox',
control.container);
var control = this,
checkboxes = jQuery('input:checkbox', control.container);

// console.log("stylebar control constructor extension script is
// ready");
Expand Down
Loading

0 comments on commit da18e7b

Please sign in to comment.