get_charset_collate();
if($amdbible_current_db_version=='2.0'){
//The following update will delete any changes made to plans and will have to be recreated and/or edited.
$table_name = $wpdb->prefix . "amdbible_plans_info";
$sql = "DROP TABLE IF EXISTS $table_name;";
$wpdb->query($sql);
$sql = "CREATE TABLE $table_name (
id int(8) unsigned AUTO_INCREMENT NOT NULL COMMENT 'Bible Reading Plan',
cx tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT 'Plan uses Complex Passages',
n varchar(50) NOT NULL COMMENT 'Name of Reading Plan',
d text NOT NULL COMMENT 'Description of Reading Plan',
PRIMARY KEY (id)
) $charset_collate;";
$wpdb->query($sql);
$table_name = $wpdb->prefix . "amdbible_plans";
$sql = "DROP TABLE IF EXISTS $table_name;";
$wpdb->query($sql);
$sql = "CREATE TABLE $table_name (
id int(8) unsigned AUTO_INCREMENT NOT NULL,
p tinyint(1) unsigned NOT NULL COMMENT 'Bible Reading Plan',
d smallint(2) unsigned NOT NULL COMMENT 'Day of the year 1 to 366',
sv int(8) unsigned zerofill NOT NULL COMMENT 'Start Verse',
ev int(8) unsigned zerofill NOT NULL COMMENT 'End Verse',
cx text COMMENT 'Complex Passage Array Serialized',
PRIMARY KEY (id),
UNIQUE KEY p_and_d (p,d)
) $charset_collate;";
$wpdb->query($sql);
define('AMDBIBLE_INSTALL', TRUE);
require_once(plugin_dir_path( __FILE__ )."insert-plans.php");
} else if($amdbible_current_db_version < $amdbible_db_version){
$table_name = $wpdb->prefix . "amdbible_key_eng";
$sql = "CREATE TABLE $table_name (
b int(11) NOT NULL COMMENT 'Book Num',
n text NOT NULL COMMENT 'Name',
t varchar(2) NOT NULL COMMENT 'Which Testament this book is in',
g tinyint(3) unsigned NOT NULL COMMENT 'A genre ID to identify the type of book this is',
PRIMARY KEY (b)
) $charset_collate;";
dbDelta( $sql );
$table_name = $wpdb->prefix . "amdbible_key_abbr_eng";
$sql = "CREATE TABLE $table_name (
id smallint(5) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Abbreviation ID',
a varchar(255) NOT NULL,
b smallint(5) unsigned NOT NULL COMMENT 'ID of book that is abbreviated',
p tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Whether an abbreviation is the primary one for the book',
PRIMARY KEY (id)
) $charset_collate;";
dbDelta( $sql );
$table_name = $wpdb->prefix . "amdbible_key_genre_eng";
$sql = "CREATE TABLE $table_name (
g tinyint(3) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Genre ID',
n varchar(255) NOT NULL COMMENT 'Name of genre',
PRIMARY KEY (g)
) $charset_collate;";
dbDelta( $sql );
$table_name = $wpdb->prefix . "amdbible_kjv";
$sql = "CREATE TABLE $table_name (
id int(8) unsigned zerofill NOT NULL,
b int(11) NOT NULL COMMENT 'Book Num',
c int(11) NOT NULL COMMENT 'Chapter Num',
v int(11) NOT NULL COMMENT 'Verse Num',
t text NOT NULL COMMENT 'Text',
PRIMARY KEY (id)
) $charset_collate;";
dbDelta( $sql );
$table_name = $wpdb->prefix . "amdbible_plans_info";
$sql = "CREATE TABLE $table_name (
id int(8) unsigned AUTO_INCREMENT NOT NULL COMMENT 'Bible Reading Plan',
cx tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT 'Plan uses Complex Passages',
n varchar(50) NOT NULL COMMENT 'Name of Reading Plan',
d text NOT NULL COMMENT 'Description of Reading Plan',
PRIMARY KEY (id)
) $charset_collate;";
dbDelta( $sql );
$table_name = $wpdb->prefix . "amdbible_plans";
$sql = "CREATE TABLE $table_name (
id int(8) unsigned AUTO_INCREMENT NOT NULL,
p tinyint(1) unsigned NOT NULL COMMENT 'Bible Reading Plan',
d smallint(2) unsigned NOT NULL COMMENT 'Day of the year 1 to 366',
sv int(8) unsigned zerofill NOT NULL COMMENT 'Start Verse',
ev int(8) unsigned zerofill NOT NULL COMMENT 'End Verse',
cx text COMMENT 'Complex Passage Array Serialized',
PRIMARY KEY (id),
UNIQUE KEY p_and_d (p,d)
) $charset_collate;";
dbDelta( $sql );
$table_name = $wpdb->prefix . "amdbible_devos";
$sql = "CREATE TABLE $table_name (
id int(8) unsigned AUTO_INCREMENT NOT NULL,
d varchar(5) NOT NULL COMMENT 'Date of Devotion',
ap varchar(2) NOT NULL COMMENT 'Morning or Evening',
v varchar(50) NOT NULL COMMENT 'Verse for Devotion',
t varchar(255) NOT NULL COMMENT 'Title of Devotion',
c text NOT NULL COMMENT 'Devotion Content',
PRIMARY KEY (id)
) $charset_collate;";
dbDelta( $sql );
define('AMDBIBLE_INSTALL', TRUE);
require_once(plugin_dir_path( __FILE__ )."insert-keys.php");
if(file_exists(plugin_dir_path( __FILE__ )."insert-kjv.php")){
require_once(plugin_dir_path( __FILE__ )."insert-kjv.php");
} else {
require_once(plugin_dir_path( __FILE__ )."insert-kjv-empty.php");
}
require_once(plugin_dir_path( __FILE__ )."insert-plans.php");
if(file_exists(plugin_dir_path( __FILE__ )."insert-devos.php")){
require_once(plugin_dir_path( __FILE__ )."insert-devos.php");
} else {
require_once(plugin_dir_path( __FILE__ )."insert-devos-empty.php");
}
}
update_option( 'amdbible_db_version', $amdbible_db_version );
}
//create tables upon plugin activation
register_activation_hook( __FILE__, 'amdbible_install' );
/**
* Deactivate plugin.
*/
function amdbible_deactivate() {
/*
* These removal items were moved to uninstall instead of deactivate to keep user settings and changes to database
*/
}
//delete custom tables upon plugin deactivation
register_deactivation_hook( __FILE__, 'amdbible_deactivate' );
/**
*
* Add Admin Menu and Page
*
*/
add_action( 'admin_menu', 'amdbible_admin_page' );
function amdbible_admin_page(){
$page_title = 'AMD Bible Reading Settings';
$menu_title = 'AMD Settings';
$capability = 'manage_options';
$menu_slug = 'amd-bible-reading';
$function = 'amdbible_settings_page';
$icon_url = 'dashicons-book-alt';
$position = 79;
add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position);
add_action( 'admin_init', 'amdbible_settings' );
}
add_action('admin_menu', 'amdbible_admin_plan_editor');
function amdbible_admin_plan_editor(){
$parent_slug='amd-bible-reading';
$page_title='AMD Bible Reading Plan Editor';
$menu_title='Plan Editor';
$capability='manage_options';
$menu_slug='amdbible-plan-editor';
$function='amdbible_plan_editor_page';
add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function );
}
add_action('admin_menu', 'amdbible_admin_library');
function amdbible_admin_library(){
$parent_slug='amd-bible-reading';
$page_title='AMD Library';
$menu_title='AMD Library';
$capability='manage_options';
$menu_slug='amdbible-library';
$function='amdbible_library_page';
add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function );
}
add_action('admin_menu', 'amdbible_about');
function amdbible_about(){
$parent_slug='amd-bible-reading';
$page_title='About AMD Bible Reading Plugin';
$menu_title='About AMD';
$capability='manage_options';
$menu_slug='amdbible-about';
$function='amdbible_about_page';
add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function );
}
function amdbible_validate_int($input){
//no user permissions are needed to check input
if(ctype_digit($input)){
return $input;
} else {
return '';
}
}
function amdbible_validate_bool($input){
//no user permissions are needed to check input
if($input){
return '1';
} else{
return '0';
}
}
function amdbible_validate_color($input){
//no user permissions are needed to check input
if(preg_match('/^#([a-f0-9]{3}){1,2}$/i',$input)){
return $input;
} else {
return '#000000';
}
}
function amdbible_admin_scripts($hook){
//only render style script on the AMD Settings page.
if('toplevel_page_amd-bible-reading' != $hook){
return;
}
wp_enqueue_style('wp-color-picker');
wp_enqueue_script('amdbible_script_handle',plugins_url('amdbible-script.js',__FILE__),array('wp-color-picker'),false,true);
}
add_action('admin_enqueue_scripts','amdbible_admin_scripts');
function amdbible_settings() {
//register_setting( $option_group, $option_name [, $sanitize_callback ] ); //for format help
register_setting( 'amd-settings-group', 'amdbible_plan_chosen', 'amdbible_validate_int' );
register_setting( 'amd-settings-group', 'amdbible_full_reading_page', 'amdbible_validate_int' );
register_setting( 'amd-settings-group', 'amdbible_stand_cx_ref', 'amdbible_validate_bool' );
register_setting( 'amd-settings-group', 'amdbible_delete_db', 'amdbible_validate_bool' );
register_setting( 'amd-settings-group', 'amdbible_ch_number_color', 'amdbible_validate_color' );
register_setting( 'amd-settings-group', 'amdbible_ver_number_color', 'amdbible_validate_color' );
register_setting( 'amd-settings-group', 'amdbible_use_local_kjv', 'amdbible_validate_bool' );
register_setting( 'amd-settings-group', 'amdbible_use_local_devos', 'amdbible_validate_bool' );
add_settings_section('amd-plan-option','Currently Selected Reading Plan','amdbible_plan_options','amd-bible-reading');
//add_settings_field( $id , $title , $callback , $page [, $section [, $args ] ] ); //for format help
add_settings_field('plan_options','Selected Plan','amdbible_reading_plan','amd-bible-reading','amd-plan-option');
add_settings_field('full_reading_page','Select Page for default Full Reading Plan','amdbible_full_reading_page','amd-bible-reading','amd-plan-option');
add_settings_field('stand_ref','Standardize CX References','amdbible_stand_ref','amd-bible-reading','amd-plan-option');
add_settings_field('amd_delete','Delete Database Data','amdbible_delete','amd-bible-reading','amd-plan-option');
add_settings_field('amd_ch_num_color','Chapter Number Color','amdbible_ch_num_color','amd-bible-reading','amd-plan-option');
add_settings_field('amd_ver_num_color','Verse Number Color','amdbible_ver_num_color','amd-bible-reading','amd-plan-option');
add_settings_field('use_local_kjv','Use local Bible database','amdbible_use_local_kjv','amd-bible-reading','amd-plan-option');
add_settings_field('use_local_devos','Use local devotional database','amdbible_use_local_devos','amd-bible-reading','amd-plan-option');
}
function amdbible_plan_options(){
//no user permissions are needed here. read predefined data only.
global $wpdb;
$amdbible_plans = $wpdb->get_results( "SELECT id,n,d FROM {$wpdb->prefix}amdbible_plans_info" );
foreach($amdbible_plans as $reading_plan){
if(get_option('amdbible_plan_chosen',1)==$reading_plan->id){
$current_plan['id'] = $reading_plan->id;
$current_plan['n'] = $reading_plan->n;
$current_plan['d'] = $reading_plan->d;
}
}
echo $current_plan['n'].'
'.$current_plan['d'].'
CAUTION: By checking this box and uninstalling the plugin, all plugin related options and database information will be removed. Check this box for a complete removal.
'; } function amdbible_ch_num_color(){ // check user capabilities if ( ! current_user_can( 'manage_options' ) ) { return; } echo ''; } function amdbible_ver_num_color(){ // check user capabilities if ( ! current_user_can( 'manage_options' ) ) { return; } echo ''; } function amdbible_use_local_kjv(){ // check user capabilities if ( ! current_user_can( 'manage_options' ) ) { return; } echo 'Check this after installing the KJV Bible on the AMD Library settings page. This will make your site run faster and independantly of external sites.
'; } function amdbible_use_local_devos(){ // check user capabilities if ( ! current_user_can( 'manage_options' ) ) { return; } echo 'Check this after installing the devotional on the AMD Library settings page. This will make your site run faster and independantly of external sites.
'; } function amdbible_full_reading_page(){ // check user capabilities if ( ! current_user_can( 'manage_options' ) ) { return; } $pageID = get_option('amdbible_full_reading_page',0); ?>Rate this plugin | Help and Support | Donate
Currently Selected Plan:
Continue Reading (page and plan set in AMD Settings)
'; } else { echo 'Full Reading Page not set in Settings
'; } } function amdbible_dashboard_devotional() { echo wpautop(do_shortcode("[amd_bible_devo]")); } function amdbible_about_page(){ // check user capabilities if ( ! current_user_can( 'manage_options' ) ) { return; } $page = 'amd-bible-reading'; $settings_page = add_query_arg(compact('page'), admin_url('admin.php')); $page = 'amdbible-plan-editor'; $amdbible_plan_editor = add_query_arg(compact('page'), admin_url('admin.php')); $post_type = 'page'; $new_page = add_query_arg(compact('post_type'),admin_url('post-new.php')); $widgets = admin_url('widgets.php'); ?>Rate this plugin | Help and Support | Donate
I have built this plugin to be the very best King James Version (KJV) Bible Daily Reading Plugin for WordPress. I have set forth to make this plugin very simple and easy to use. This plugin will generate one widget, "Daily Bible Snippet", and provides support for four shortcodes [amd_bible_devo]; [amd_bible_daily]; [amd_bible_rand]; and [amd_bible].
There are a few recommended steps to ensure that the plugin works correctly with your site.
Navigate to AMD Settings, and set the 'Selected Plan' option. This will set the reading plan for the [amd_bible_daily] shortcode and the widget
Navigate to AMD Settings, and set your preference for the 'Standardize CX References' option. Leaving this option checked will force Complex References to become formatted before displaying on the front-end using the [amd_bible_daily] shortcode or widget.
Add a New Page, Name the page and enter the [amd_bible_daily] shortcode into the content and publish the page. There are 14 attributes that can be used to control how the passage is displayed. The defaults very depending on the inline attribute. Please see the below section for default and accepted values:
| NAME | ACCEPTED VALUES | DEFAULT | DEFAULT when inline=true |
|---|---|---|---|
| inline | boolean | false | (set to true) |
| limit | integer (0=unlimited) | 0 | 0 |
| limit_type | string 'words' or 'verses' | '' | '' |
| show_book | boolean | true | false |
| show_chapter | boolean | true | false |
| show_verse | boolean | true | false |
| reference_before | boolean | true | false |
| reference_after | boolean | false | true |
| form_before | boolean | true | false |
| form_after | boolean | true | false |
| plan | integer | (Set in AMD Settings) | |
| day | integer 1-366 | (curent day) can be overridden by variable in URL takes precedence over date variable in shortcode. | |
| date | a date string | (current_date) can be overridden by variable in URL. | |
| date_format | string (valid date format) | 'D., M. j, Y' | |
| no_reading_text | string | There is no reading scheduled for this day. Use this day to catch up or read ahead." | |
Navigate to Appearance -> Widgets, and add the Daily Bible Snippet Widget to your selected sidebar. There are 8 options with the Widget.
1) Select the Reading Plan to use for the widget instance.
2) Scripture starts with Reference inline? When this option is checked, the scripture will begin with the reference. This is helpful if using a custom widget title.
3) Use Reference for Title? When this option is checked, The title will default to the Reference for the daily scripture passage(s).
4) Title: this input will be used as the title given that the reference is not used by the previous option.
5) Limit Type: this will define how the passage is limited. The options are 'words' or 'verses'. If limit type is set to words, the last verse will most likely be interrupted, but the content will be more of a standard length.
6) Limit: using the limit type in the previous option this option defines how many items to display.
7) Full Reading Page: select the page created in the previous setup step. This will show the full daily bible reading utilizing the [amd_bible_daily] shortcode.
8) Read More Text: this input controls what text is displayed with the page linked in the previous setting. make sure to save your settings.
Note: Some themes support sidebars differently and there are also plugins that will control where and how sidebars will display. I recommend SMK Sidebar Generator and Widget Visibility Time Scheduler
I have found Charles Spurgeon Devotionals to be very encouraging and uplifting and have decided to include them in this plugin by utilizing another shortcode [amd_bible_devo]. The steps to adding this into your content is very simple and can be done on any post or page. Simply add the [amd_bible_devo] shortcode into your content at the desired location. At this time there is no option to display a different devotion than the one that is current for the specific time of day and date.
Random verses can now be displayed using the new shortcode [amd_bible_rand]. There are four main attributes that can be utilized to determine where the random verse is selected from:
ot - (boolean) when set to true this will show verses from the old testament only
nt - (boolean) when set to true this will show verses from the new testament only
book - (numeric or string: book name, or book abbreviation) when set verses will originate from selected book
chapter - (numeric) when set along with book attribute, this will determine from which chapter the verses will originate
most_read - (boolean) when set to true this will show verses from a list of the top read 100 Bible verses from a study conducted by biblegateway.com
essential - (boolean) when set to true this will show verses from a list of Bible verses essential to the Christian life. These verses cover the following topics: Victorious Life, Romans Road, Assurance, Baptism, Believe in Christ, Bible, Biblical Inspiration, Christ's Sacrifice, Dedication, Friendship, Forgiveness of Sins, Guidance, Hell, Home, Law, Local Church, One Way of Salvation, Others, Peace, Prinsiples, Problem Solving, Procrastination, Salvation without Works, Second Coming, Vicoty over Satan, Witnessing
Bible verses and passages can now be displayed anywhere shortcodes are accepted using the shortcode [amd_bible]Your Reference[/amd_bible]. Replace 'Your Reference' with any simple or complex Bible Reference. (See reference examples below.) There are eight attributes that can be used to control how the passage is displayed. The defaults very depending on the inline attribute. Please see the below section for default and accepted values:
| NAME | ACCEPTED VALUES | DEFAULT | DEFAULT when inline=false |
|---|---|---|---|
| inline | boolean | true | (set to false) |
| limit | integer (0=unlimited) | 0 | 0 |
| limit_type | string 'words' or 'verses' | '' | '' |
| show_book | boolean | false | true |
| show_chapter | boolean | false | true |
| show_verse | boolean | false | true |
| reference_before | boolean | false | true |
| reference_after | boolean | true | false |
Examples of shortcodes:
[amd_bible]Psalm 1[/amd_bible][amd_bible inline='false']Psalm 1-3[/amd_bible][amd_bible show_book=true show_chapt=true show_verse= true reference_before=true reference_after=false]Psalm 1:1, 3-5; 2-4:2[/amd_bible]Note: It is possible to use a shortcode in a widget with Shortcode Widget
Complex and Custom Reading Plans are Here! It is now possible to edit existing Bible Reading Plans and even add new plans. Navigate to AMD Settings -> Plan Editor, and either create a new plan or choose an existing plan to edit. New plans cannot have the same names as existing plans. After creating the plan please add the plan details before selecting the plan in AMD Settings as the chosen plan. This will prevent your widget and shortcodes from displaying no passages. Plans can either use complex references or simple references (leaving complex references unchecked). With simple references there will be two input fields for each date, starting reference and ending reference. Only simple, single verse references can be used in this format. To easily indicate the end of the chapter verse '999' can be used, for instance 'Gensesis 4:999' will show up to all of the verses in chapter 4 of Genesis. Book abbreviations can be used such as "Gen" for Genesis. With complex references, you have an additional option to upload a CSV file to easily and quickly insert your custom reading plan from your favorite source. CSV files must be comma delimitted with no headers and column 1 being the day of year, column 2 being the corresponding complex reference (or starting reference if simple plan, and column 3 being the ending reference). Complex references can consist of varying diversities. See examples:
Gen. 1-3Gen 1:1-10Genesis 1:1-5, 7, 10; 21King 1, 3, 4:5-9; 5First Kings 2II Kings 1; John 4John 1:1, 2:4-10JudeBe sure to Save Changes before navigating away from the plan editor page or your changes will be lost. CAUTION! changing a plan from a simple to complex or vice versa and saving valid data will erase the alternate settings. You could easily erase an entire plan this way.
In order to restore all data to original installation, you will need to delete the plugin and all associated data and reinstall. To do this before uninstalling or deactivating the plugin, you will need to check the "Delete Database Data" option. This will erase any custom reading plans you may have created.
AMD stands for A Master Designs. A Master Designs was birthed by a dream I had to fully support myself in the ministry serving the Lord as Paul was a tent maker. Currently this dream has yet to reach fruition but is a work in progress. If I can be of any assistance to you please let me know. My skills involve graphic design, web development, PC support and repair, and overall tech guru. For more information, please visit my website at A Master Designs. A Master Designing for THE MASTER!
The King James Version of the Bible in the appropriate CSV file format is available at http://amasterdesigns.com/amdbible_kjv/
Spurgeon's Morning and Evening Daily Devotional in the appropriate CSV file format is available at http://amasterdesigns.com/amdbible_devos/
"; } $content .= "".$no_reading_text.""; if(!$inline){ $content .= "
"; } } if(!is_null($passages)){ foreach($passages as $verse){ if($limit && $count >= $limit){ break; $snippet = true; } if($verse->c != $c){ if($verse->b != $b){ if($b !== null){ if(!$inline){ $content .= ""; } } if($show_book){ if($inline){ $content .= "".sanitize_text_field(amdbible_bk_name($verse->b))." "; } else { $content .= "".sanitize_text_field(amdbible_bk_name($verse->b))."
"; } } } if($show_chapt){ if($inline){ $content .= "Chapter ".intval($verse->c).". "; } else { $content .= "".intval($verse->c).""; } } else { if(!$inline){ $content .= "
"; } } } if($show_verse_num){ $content .= "".intval($verse->v)." "; } if($limit && $limit_type == 'words'){ $words_in_verse = str_word_count($verse->t); $count = $count+$words_in_verse; if($count > $limit){ $trim = $words_in_verse - ($count - $limit); $words = str_word_count($verse->t, 2); $pos = array_keys($words); $verse->t = substr($verse->t, 0, $pos[$trim]); } } $content .= "".sanitize_text_field($verse->t)." "; $b = $verse->b; $c = $verse->c; $v = $verse->v; if($limit && $limit_type == 'verses'){ $count++; } } } if($snippet){ $content .= ". . ."; } if(!$inline){ $content .= "
Sorry, devotional for this day is not loaded.
EOD; } else { $title = esc_html($devo->t); $verse = esc_html($devo->v); //html markup is allowed in content $content = $devo->c; $txt = <<$content
EOD; } return $txt; } add_shortcode( 'amd_bible_devo', 'amdbible_shortcode_devo' ); /** * Display the Bible Reading Plan in place of shortcode * * @param array $atts Shortcode attributes. * * @return string content to be displayed in place of shortcode */ function amdbible_shortcode_daily( $atts ) { $args = shortcode_atts( array( 'plan' => null, 'limit' => 0, 'limit_type' => null, 'show_book' => null, 'show_chapt' => null, 'show_verse' => null, 'inline' => false, 'reference_before' => null, 'reference_after' => null, 'form_before' => null, 'form_after' => null, 'date' => null, // * 'day' => null, // * 'date_format' => "D., M. j, Y", 'no_reading_text' => "There is no reading scheduled for this day. Use this day to catch up or read ahead." ), $atts ); if(is_null($args['limit_type'])){ $args['limit_type'] = (filter_var($args['inline'] ,FILTER_VALIDATE_BOOLEAN)) ? 'words' : 'verses'; } if(is_null($args['show_book'])){ $args['show_book'] = (filter_var($args['inline'] ,FILTER_VALIDATE_BOOLEAN)) ? false : true; } if(is_null($args['show_verse'])){ $args['show_verse'] = (filter_var($args['inline'] ,FILTER_VALIDATE_BOOLEAN)) ? false : true; } if(is_null($args['show_chapt'])){ $args['show_chapt'] = (filter_var($args['inline'] ,FILTER_VALIDATE_BOOLEAN)) ? false : true; } if(is_null($args['reference_before'])){ $args['reference_before'] = (filter_var($args['inline'] ,FILTER_VALIDATE_BOOLEAN)) ? false : true; } if(is_null($args['reference_after'])){ $args['reference_after'] = (filter_var($args['inline'] ,FILTER_VALIDATE_BOOLEAN)) ? true : false; } if(is_null($args['form_before'])){ $args['form_before'] = (filter_var($args['inline'] ,FILTER_VALIDATE_BOOLEAN)) ? false : true; } if(is_null($args['form_after'])){ $args['form_after'] = (filter_var($args['inline'] ,FILTER_VALIDATE_BOOLEAN)) ? false : true; } $limit = filter_var($args['limit'] ,FILTER_VALIDATE_INT); $limit_type = esc_attr($args['limit_type']); if($limit_type!='words'&&$limit_type!='verses'){ $limit_type = null; } $show_book = filter_var($args['show_book'] ,FILTER_VALIDATE_BOOLEAN); $show_chapt = filter_var($args['show_chapt'] ,FILTER_VALIDATE_BOOLEAN); $show_verse = filter_var($args['show_verse'] ,FILTER_VALIDATE_BOOLEAN); $inline = filter_var($args['inline'] ,FILTER_VALIDATE_BOOLEAN); $reference_before = filter_var($args['reference_before'],FILTER_VALIDATE_BOOLEAN); $reference_after = filter_var($args['reference_after'] ,FILTER_VALIDATE_BOOLEAN); $form_before = filter_var($args['form_before'] ,FILTER_VALIDATE_BOOLEAN); $form_after = filter_var($args['form_after'] ,FILTER_VALIDATE_BOOLEAN); $day = filter_var($args['day'] ,FILTER_VALIDATE_INT); if((1 >= $day) || ($day >= 366)){ $day = null; } $attr_date = $args['date']; if(is_null($attr_date) || !strtotime($attr_date)){ $attr_date = null; } $date_format = $args['date_format']; $no_reading_text = esc_attr($args['no_reading_text']); $txt = ""; //accept a parameter of d for day of the year value between 1 and 366 if(isset($_GET["d"]) && $_GET["d"] && $_GET["d"]>=1 && $_GET["d"]<=366){ $doy = intval($_GET["d"]); $diff = $doy-date('z')-1; if($diff>=0){$diff = "+".$diff;} $date = strtotime("$diff days"); //accept the a parameter of date where format is yyyy-mm-dd } else if(isset($_GET["date"]) && $_GET["date"] && $_GET["date"]==date("Y-m-d",strtotime($_GET["date"]))){ $date = strtotime($_GET["date"]); } else if(!is_null($day)){ $diff = $day-date('z')-1; if($diff>=0){$diff = "+".$diff;} $date = strtotime("$diff days"); } else if(!is_null($attr_date)){ $date = strtotime($attr_date); //esle set the date to current day } else { $date = time(); } //offset day of year by 1 to conform with 1-366 instead of 0-365 $day = date('z',$date)+1; $plan = amdbible_get_plan($args['plan']); $data = amdbible_daily_passage($day,$plan); if($data===false){ //Data returned empty or false so there is no need // to continue and print empty passage. return false; } $passages = $data["complete"]; $references = ""; if(!get_option('amdbible_stand_cx_ref',1) && isset($plan['cx']) && $plan['cx']){ //check for standardize-cx_ref option $references = amdbible_cx_reference($day,$plan); } else { foreach($data["passages"] as $passage){ if(!empty($references)){ $references .= '; '; } $references .= amdbible_reference($passage["sv"],$passage["ev"]); } } $references = esc_html($references); if($form_before){ $txt .= amdbible_date_form($date); } if($reference_before){ if($inline){ $txt .= "".date($date_format,$date).". ".$references." KJV — "; } else { $txt .= "".date($date_format,$date)." — ".$references." KJV
"; } } $txt .= amdbible_format_passage($passages,$limit,$limit_type,$show_book,$show_chapt,$show_verse,$inline,$no_reading_text); if($reference_after){ if($inline){ $txt .= " — ".$references." KJV reading for ".date($date_format,$date).""; } else { $txt .= "".$references." KJV reading for ".date($date_format,$date)."
"; } } if($form_after){ $txt .= amdbible_date_form($date); } return $txt; } add_shortcode( 'amd_bible_daily', 'amdbible_shortcode_daily' ); function amdbible_shortcode_passage( $atts, $content = null ) { $txt = ""; $args = shortcode_atts( array( 'limit' => 0, 'limit_type' => null, 'show_book' => null, 'show_chapt' => null, 'show_verse' => null, 'inline' => true, 'reference_before' => null, 'reference_after' => null, ), $atts ); if(is_null($args['limit_type'])){ $args['limit_type'] = (filter_var($args['inline'] ,FILTER_VALIDATE_BOOLEAN)) ? 'words' : 'verses'; } if(is_null($args['show_book'])){ $args['show_book'] = (filter_var($args['inline'] ,FILTER_VALIDATE_BOOLEAN)) ? false : true; } if(is_null($args['show_verse'])){ $args['show_verse'] = (filter_var($args['inline'] ,FILTER_VALIDATE_BOOLEAN)) ? false : true; } if(is_null($args['show_chapt'])){ $args['show_chapt'] = (filter_var($args['inline'] ,FILTER_VALIDATE_BOOLEAN)) ? false : true; } if(is_null($args['reference_before'])){ $args['reference_before'] = (filter_var($args['inline'] ,FILTER_VALIDATE_BOOLEAN)) ? false : true; } if(is_null($args['reference_after'])){ $args['reference_after'] = (filter_var($args['inline'] ,FILTER_VALIDATE_BOOLEAN)) ? true : false; } $limit = filter_var($args['limit'] ,FILTER_VALIDATE_INT); $limit_type = esc_attr($args['limit_type']); if($limit_type!='words'&&$limit_type!='verses'){ $limit_type = null; } $show_book = filter_var($args['show_book'] ,FILTER_VALIDATE_BOOLEAN); $show_chapt = filter_var($args['show_chapt'] ,FILTER_VALIDATE_BOOLEAN); $show_verse = filter_var($args['show_verse'] ,FILTER_VALIDATE_BOOLEAN); $inline = filter_var($args['inline'] ,FILTER_VALIDATE_BOOLEAN); $reference_before = filter_var($args['reference_before'],FILTER_VALIDATE_BOOLEAN); $reference_after = filter_var($args['reference_after'] ,FILTER_VALIDATE_BOOLEAN); /* The following code snippet is not yet supported and will be reviewed in a later revision if(empty($content) && isset($_GET['amdPassage'])){ $content = $_GET['amdPassage']; $limit_type = (is_null($limit_type)) ? 'verses' : $limit_type; if($limit_type=='verses'){ $limit = 500; } else { $limit = 12500; } } */ if(!empty($content)){ $decoded_ref = amdbible_cx_reference_decode($content); if($decoded_ref[0]===false){ return $content; } $data = amdbible_get_passage($decoded_ref); if($data===false){ //Data returned empty or false so there is no need // to continue and print empty passage. return false; } $passages = $data["complete"]; $references = ""; if(!get_option('amdbible_stand_cx_ref',1)){ //check for standardize-cx_ref option $references = $content; } else { foreach($data["passages"] as $passage){ if(!empty($references)){ $references .= '; '; } $references .= amdbible_reference($passage["sv"],$passage["ev"]); } } if($reference_before){ if($inline){ $txt .= "".$references." KJV — "; } else { $txt .= "".$references." KJV
"; } } $txt .= amdbible_format_passage($passages,$limit,$limit_type,$show_book,$show_chapt,$show_verse,$inline); if($reference_after){ if($inline){ $txt .= " — ".$references." KJV"; } else { $txt .= "".$references." KJV
"; } } } else { return; } return $txt; } add_shortcode( 'amd_bible', 'amdbible_shortcode_passage' ); function amdbible_randomn_passage( $atts ){ $txt = ""; global $books; global $wpdb; $args = shortcode_atts( array( 'limit' => 0, 'limit_type' => null, 'show_book' => null, 'show_chapt' => null, 'show_verse' => null, //'inline' => true, //possibly change this if expanded to allow randomn chapter. 'reference_before' => null, 'reference_after' => null, 'ot'=>null, 'nt'=>null, 'book'=>null, 'chapter'=>null, //'show_type'=>null, //possibly change this if expanded to allow randomn chapter. 'most_read'=>false, 'essential'=>false, 'start_para'=>false, 'end_para'=>false, ), $atts ); $args['inline'] = true; //possibly change this if expanded to allow randomn chapter. if(is_null($args['limit_type'])){ $args['limit_type'] = (filter_var($args['inline'] ,FILTER_VALIDATE_BOOLEAN)) ? 'words' : 'verses'; } if(is_null($args['show_book'])){ $args['show_book'] = (filter_var($args['inline'] ,FILTER_VALIDATE_BOOLEAN)) ? false : true; } if(is_null($args['show_verse'])){ $args['show_verse'] = (filter_var($args['inline'] ,FILTER_VALIDATE_BOOLEAN)) ? false : true; } if(is_null($args['show_chapt'])){ $args['show_chapt'] = (filter_var($args['inline'] ,FILTER_VALIDATE_BOOLEAN)) ? false : true; } if(is_null($args['reference_before'])){ $args['reference_before'] = (filter_var($args['inline'] ,FILTER_VALIDATE_BOOLEAN)) ? false : true; } if(is_null($args['reference_after'])){ $args['reference_after'] = (filter_var($args['inline'] ,FILTER_VALIDATE_BOOLEAN)) ? true : false; } $limit = filter_var($args['limit'] ,FILTER_VALIDATE_INT); $limit_type = esc_attr($args['limit_type']); if($limit_type!='words'&&$limit_type!='verses'){ $limit_type = null; } $show_book = filter_var($args['show_book'] ,FILTER_VALIDATE_BOOLEAN); $show_chapt = filter_var($args['show_chapt'] ,FILTER_VALIDATE_BOOLEAN); $show_verse = filter_var($args['show_verse'] ,FILTER_VALIDATE_BOOLEAN); $inline = filter_var($args['inline'] ,FILTER_VALIDATE_BOOLEAN); $reference_before = filter_var($args['reference_before'],FILTER_VALIDATE_BOOLEAN); $reference_after = filter_var($args['reference_after'] ,FILTER_VALIDATE_BOOLEAN); $most_read = filter_var($args['most_read'] ,FILTER_VALIDATE_BOOLEAN); $essential = filter_var($args['essential'] ,FILTER_VALIDATE_BOOLEAN); $start_para = filter_var($args['start_para'] ,FILTER_VALIDATE_BOOLEAN); $end_para = filter_var($args['end_para'] ,FILTER_VALIDATE_BOOLEAN); $most_read_list = array( array('43003016','43003016'), array('24029011','24029011'), array('45008028','45008028'), array('50004013','50004013'), array('01001001','01001001'), array('20003005','20003005'), array('20003006','20003006'), array('45012002','45012002'), array('50004006','50004006'), array('40028019','40028019'), array('49002008','49002008'), array('48005022','48005022'), array('45012001','45012001'), array('43010010','43010010'), array('44018010','44018010'), array('44018009','44018009'), array('44018011','44018011'), array('48002020','48002020'), array('62001009','62001009'), array('45003023','45003023'), array('43014006','43014006'), array('40028020','40028020'), array('45005008','45005008'), array('50004008','50004008'), array('50004007','50004007'), array('07001009','07001009'), array('23040031','23040031'), array('49002009','49002009'), array('45006023','45006023'), array('48005023','48005023'), array('23053005','23053005'), array('60003015','60003015'), array('55003016','55003016'), array('40006033','40006033'), array('58012002','58012002'), array('60005007','60005007'), array('49002010','49002010'), array('46010013','46010013'), array('40011028','40011028'), array('58011001','58011001'), array('47005017','47005017'), array('58013005','58013005'), array('47012009','47012009'), array('45010009','45010009'), array('23041010','23041010'), array('01001026','01001026'), array('40011029','40011029'), array('43016033','43016033'), array('44001008','44001008'), array('55001007','55001007'), array('23053004','23053004'), array('47005021','47005021'), array('45015013','45015013'), array('43011025','43011025'), array('58011006','58011006'), array('43005024','43005024'), array('59001002','59001002'), array('23053006','23053006'), array('44002038','44002038'), array('49003020','49003020'), array('40011030','40011030'), array('01001027','01001027'), array('51003012','51003012'), array('58012001','58012001'), array('59005016','59005016'), array('44017011','44017011'), array('50004019','50004019'), array('43001001','43001001'), array('46006019','46006019'), array('62003016','62003016'), array('19133001','19133001'), array('43014027','43014027'), array('58004012','58004012'), array('43015013','43015013'), array('33006008','33006008'), array('45010017','45010017'), array('43001012','43001012'), array('59001012','59001012'), array('59001003','59001003'), array('45008038','45008038'), array('45008039','45008039'), array('58010025','58010025'), array('61001004','61001004'), array('50001006','50001006'), array('19133003','19133003'), array('58004016','58004016'), array('19037004','19037004'), array('43003017','43003017'), array('44004012','44004012'), array('23026003','23026003'), array('60002024','60002024'), array('06001008','06001008'), array('40028018','40028018'), array('51003023','51003023'), array('40022037','40022037'), array('19133002','19133002'), array('40005016','40005016'), array('23055008','23055008'), array('58004015','58004015'), array('43013035','43013035'), ); $essential_list = array( array('46006019','46006020'), array('48002020','48002020'), array('60002002','60002002'), array('43014013','43014013'), array('62003022','62003022'), array('41016015','41016015'), array('45003010','45003010'), array('45005008','45005008'), array('45003023','45003023'), array('45006023','45006023'), array('45010009','45010010'), array('45010013','45010013'), array('43003036','43003036'), array('58013005','58013005'), array('43010028','43010028'), array('62005011','62005013'), array('45006003','45006005'), array('43001012','43001012'), array('44016031','44016031'), array('43003016','43003016'), array('06001008','06001008'), array('55002015','55002015'), array('19119011','19119011'), array('40005018','40005018'), array('55003016','55003017'), array('23053006','23053006'), array('56002014','56002014'), array('47005021','47005021'), array('45006011','45006013'), array('45012001','45012002'), array('42009023','42009023'), array('20017017','20017017'), array('20018024','20018024'), array('19119063','19119063'), array('19103012','19103012'), array('62001009','62001009'), array('49001007','49001007'), array('20028013','20028013'), array('19119133','19119133'), array('20003005','20003006'), array('66020015','66020015'), array('53001008','53001009'), array('20022006','20022006'), array('49005022','49005025'), array('46007003','46007003'), array('45003020','45003020'), array('59002010','59002010'), array('48003024','48003024'), array('44002041','44002041'), array('58010025','58010025'), array('46011026','46011026'), array('23043011','23043011'), array('44004012','44004012'), array('43014006','43014006'), array('47012015','47012015'), array('50002001','50002004'), array('23026003','23026003'), array('50004006','50004007'), array('46010031','46010031'), array('51003023','51003023'), array('51003017','51003017'), array('40005023','40005024'), array('40018015','40018015'), array('44024016','44024016'), array('20027001','20027001'), array('47006002','47006002'), array('20029001','20029001'), array('49002008','49002009'), array('56003005','56003005'), array('55001009','55001009'), array('52004016','52004018'), array('56002011','56002013'), array('46010013','46010013'), array('59004007','59004007'), array('53003003','53003003'), array('40004019','40004019'), array('40028019','40028020'), ); if($most_read && $essential){ $list = array_merge($essential_list,$most_read_list); $rand_key = array_rand($list); $sv_ev = $list[$rand_key]; $sv = $sv_ev[0]; $ev = $sv_ev[1]; $reference = amdbible_reference($sv,$ev); $data = array("complete"=>array(),"passages"=>array()); } else if($most_read){ $rand_key = array_rand($most_read_list); $sv_ev = $most_read_list[$rand_key]; $sv = $sv_ev[0]; $ev = $sv_ev[1]; $reference = amdbible_reference($sv,$ev); $data = array("complete"=>array(),"passages"=>array()); } else if($essential){ $rand_key = array_rand($essential_list); $sv_ev = $essential_list[$rand_key]; $sv = $sv_ev[0]; $ev = $sv_ev[1]; $reference = amdbible_reference($sv,$ev); $data = array("complete"=>array(),"passages"=>array()); } else { $book = $args['book']; $chapter = 0; if(!is_null($args['book'])){ if(is_numeric($book) && $book>=1 && $book<=66){ $book = str_pad(filter_var($book ,FILTER_VALIDATE_INT),2,'0',STR_PAD_LEFT); } else if(isset($books[$book])){ $book = str_pad($books[$book],2,'0',STR_PAD_LEFT); } else { $book = null; } } /* $show_type = esc_attr($args['show_type']); if($show_type!='chapter'){ $show_type = 'verse'; } */ //possibly change this if expanded to allow randomn chapter. if(is_null($book)){ $OT = filter_var($args['ot'] ,FILTER_VALIDATE_BOOLEAN); $NT = filter_var($args['nt'] ,FILTER_VALIDATE_BOOLEAN); if(($OT && $NT) || (!$OT && !$NT)){ // ALL $filter = "BETWEEN 01001001 AND 66999999"; } else if($OT){ // O.T. $filter = "BETWEEN 01001001 AND 39999999"; } else { // N.T. $filter = "BETWEEN 40001001 AND 66999999"; } } else { if(!is_null($args['chapter']) && is_numeric($args['chapter'])){ $chapter = str_pad(filter_var($args['chapter'] ,FILTER_VALIDATE_INT),3,'0',STR_PAD_LEFT); $filter = "BETWEEN ".$book.$chapter."001 AND ".$book.$chapter."999"; } else { $filter = "BETWEEN ".$book."001001 AND ".$book."999999"; } } $query = " SELECT id FROM {$wpdb->prefix}amdbible_kjv WHERE id $filter ORDER BY RAND() LIMIT 1 "; $sv = $wpdb->get_var($query); $reference = amdbible_reference($sv); $data = array("complete"=>array(),"passages"=>array()); $ev = $sv; } $passage = amdbible_passage($sv,$ev); $data["passages"][] = array( "sv"=>$sv, "ev"=>$ev, "passage"=>$passage ); $data["complete"] = $passage; $passages = $data["complete"]; $references = ""; if(!get_option('amdbible_stand_cx_ref',1)){ //check for standardize-cx_ref option $references = $content; } else { foreach($data["passages"] as $passage){ if(!empty($references)){ $references .= '; '; } $references .= amdbible_reference($passage["sv"],$passage["ev"]); } } if($reference_before){ if($inline){ $txt .= "".$references." KJV — "; if($start_para){ $txt .= ""; } } else { $txt .= "
".$references." KJV
"; } } $txt .= amdbible_format_passage($passages,$limit,$limit_type,$show_book,$show_chapt,$show_verse,$inline); if($reference_after){ if($inline){ $txt .= " — ".$references." KJV"; if($end_para){ $txt .= ""; } } else { $txt .= "".$references." KJV
"; } } return $txt; } add_shortcode( 'amd_bible_rand', 'amdbible_randomn_passage' ); add_action( 'widgets_init', function(){ register_widget( 'amdbible_widget' ); }); /** * Adds My_Widget widget. */ class amdbible_widget extends WP_Widget { /** * Register widget with WordPress. */ function __construct() { parent::__construct( 'amdbible_widget', // Base ID __('Daily Bible Snippet', 'text_domain'), // Name array( 'description' => __( 'Widget to Display Snippet of Daily Bible Reading', 'text_domain' ), ) // Args ); } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget( $args, $instance ) { //get the current daily passage $day = date('z',time())+1; if(isset($instance['plan'])){ $plan = $instance['plan']; } else { $plan = amdbible_get_plan(); } $passages = amdbible_daily_passage($day,$plan); $references = ""; if(!get_option('amdbible_stand_cx_ref',1) && isset($plan['cx']) && $plan['cx']){ //check for standardize-cx_ref option $references = amdbible_cx_reference($day,$plan); } else { foreach($passages["passages"] as $passage){ $references .= amdbible_reference($passage["sv"],$passage["ev"])." "; } } if(isset($instance['ref_title'])){ $ref_title = $instance['ref_title']; } else { $ref_title = '0'; } if($ref_title=='1'){ $instance['title'] = $references; } //start outputting content echo $args['before_widget']; if ( ! empty( $instance['title'] ) ) { echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title']; } //check and get variables if(isset($instance['limit'])){ $limit = $instance['limit']; } else { $limit = 50; } if(isset($instance['limit_type'])){ $limit_type = $instance['limit_type']; } else { $limit_type = 'words'; } if(isset($instance['read_more_text'])){ $read_more_text = $instance['read_more_text']; } else { $read_more_text = __( 'Read More', 'text_domain' ); } if(isset($instance['ref_start']) && $instance['ref_start']=='1'){ echo "".$references.": "; } echo amdbible_format_passage($passages["complete"],$limit,$limit_type,false,false,false); if(isset($instance['full_page'])){ echo '',$read_more_text,''; } echo $args['after_widget']; } /** * Back-end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. */ public function form( $instance ) { // Check values if(isset($instance['plan'])){ $plan = $instance['plan']; } else { $plan = amdbible_get_plan(); } if(isset($instance['ref_start'])){ $ref_start = esc_attr($instance['ref_start']); } else { $ref_start = '0'; } if(isset($instance['ref_title'])){ $ref_title = esc_attr($instance['ref_title']); } else { $ref_title = '0'; } if(isset($instance['title'])){ $title = esc_attr($instance['title']); } else { $title = __( 'New title', 'text_domain' ); } if(isset($instance['limit_type'])){ $limit_type = esc_attr($instance['limit_type']); } else { $limit_type = 'words'; } if(isset($instance['limit'])){ $limit = esc_attr($instance['limit']); } else { $limit = __( '50', 'text_domain' ); } if(isset($instance['full_page'])){ $full_page = esc_attr($instance['full_page']); } else { $full_page = ''; } if(isset($instance['read_more_text'])){ $read_more_text = esc_attr($instance['read_more_text']); } else { $read_more_text = __( 'Continue Reading', 'text_domain' ); } ?>
/>
/>