| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 3 |
|
| 4 |
function mbt_templates_init() { |
| 5 |
//register image sizes |
| 6 |
list($width, $height) = apply_filters('mbt_book_image_size', array(800, 800)); |
| 7 |
add_image_size('mbt_book_image', $width, $height, false); |
| 8 |
list($width, $height) = apply_filters('mbt_endorsement_image_size', array(1000, 400)); |
| 9 |
add_image_size('mbt_endorsement_image', $width, $height, false); |
| 10 |
|
| 11 |
add_action('mbt_get_storefront_content_sections', 'mbt_get_storefront_content_sections'); |
| 12 |
add_action('mbt_get_singlecolumn_content_sections', 'mbt_get_singlecolumn_content_sections'); |
| 13 |
|
| 14 |
if(!is_admin()) { |
| 15 |
//enqueue frontend styling |
| 16 |
add_action('wp_enqueue_scripts', 'mbt_enqueue_resources'); |
| 17 |
add_action('wp_head', 'mbt_add_custom_css'); |
| 18 |
|
| 19 |
//enable frontend ajax |
| 20 |
add_action('wp_head', 'mbt_enable_frontend_ajax'); |
| 21 |
|
| 22 |
//modify the post query |
| 23 |
add_action('pre_get_posts', 'mbt_pre_get_posts', 20); |
| 24 |
|
| 25 |
//override page template |
| 26 |
add_filter('template_include', 'mbt_load_book_templates'); |
| 27 |
|
| 28 |
//add body tag |
| 29 |
add_filter('body_class', 'mbt_body_class'); |
| 30 |
|
| 31 |
//general hooks |
| 32 |
add_action('mbt_content_wrapper_start', 'mbt_do_wrapper_start'); |
| 33 |
add_action('mbt_content_wrapper_end', 'mbt_do_wrapper_end'); |
| 34 |
add_action('mbt_book_excerpt', 'mbt_do_book_excerpt'); |
| 35 |
|
| 36 |
//book archive hooks |
| 37 |
add_action('mbt_book_archive_content', 'mbt_do_book_archive_content'); |
| 38 |
add_action('mbt_before_book_archive', 'mbt_do_before_book_archive', 0); |
| 39 |
add_action('mbt_after_book_archive', 'mbt_do_after_book_archive', 100); |
| 40 |
add_action('mbt_book_archive_header', 'mbt_do_book_archive_header'); |
| 41 |
add_action('mbt_book_archive_header_image', 'mbt_do_book_archive_header_image'); |
| 42 |
add_action('mbt_book_archive_header_title', 'mbt_do_book_archive_header_title'); |
| 43 |
add_action('mbt_book_archive_header_description', 'mbt_do_book_archive_header_description'); |
| 44 |
add_action('mbt_book_archive_loop', 'mbt_do_book_archive_loop'); |
| 45 |
add_action('mbt_book_archive_no_results', 'mbt_do_book_archive_no_results'); |
| 46 |
add_action('mbt_after_book_archive_loop', 'mbt_the_book_archive_pagination'); |
| 47 |
|
| 48 |
//single book hooks |
| 49 |
add_action('mbt_single_book_storefront_content', 'mbt_do_single_book_storefront_content'); |
| 50 |
add_action('mbt_before_single_book_storefront', 'mbt_do_before_single_book_storefront', 0); |
| 51 |
add_action('mbt_after_single_book_storefront', 'mbt_do_after_single_book_storefront', 100); |
| 52 |
add_action('mbt_single_book_storefront_summary', 'mbt_do_single_book_storefront_summary'); |
| 53 |
add_action('mbt_single_book_storefront_images', 'mbt_do_single_book_storefront_images'); |
| 54 |
add_action('mbt_single_book_storefront_title', 'mbt_do_single_book_storefront_title'); |
| 55 |
add_action('mbt_single_book_storefront_price', 'mbt_do_single_book_storefront_price'); |
| 56 |
add_action('mbt_single_book_storefront_meta', 'mbt_do_single_book_storefront_meta'); |
| 57 |
add_action('mbt_single_book_storefront_blurb', 'mbt_do_single_book_storefront_blurb'); |
| 58 |
add_action('mbt_single_book_storefront_buybuttons', 'mbt_do_single_book_storefront_buybuttons'); |
| 59 |
add_action('mbt_single_book_storefront_overview', 'mbt_do_single_book_storefront_overview'); |
| 60 |
add_filter('mbt_book_section_title', 'mbt_single_book_storefront_book_reviews_section_title', 10, 3); |
| 61 |
|
| 62 |
add_action('mbt_single_book_singlecolumn_content', 'mbt_do_single_book_singlecolumn_content'); |
| 63 |
add_action('mbt_before_single_book_singlecolumn', 'mbt_do_before_single_book_singlecolumn', 0); |
| 64 |
add_action('mbt_after_single_book_singlecolumn', 'mbt_do_after_single_book_singlecolumn', 100); |
| 65 |
add_action('mbt_single_book_singlecolumn_summary', 'mbt_do_single_book_singlecolumn_summary'); |
| 66 |
add_action('mbt_single_book_singlecolumn_title', 'mbt_do_single_book_singlecolumn_title'); |
| 67 |
add_action('mbt_single_book_singlecolumn_blurb', 'mbt_do_single_book_singlecolumn_blurb'); |
| 68 |
add_action('mbt_single_book_singlecolumn_overview', 'mbt_do_single_book_singlecolumn_overview'); |
| 69 |
add_action('mbt_single_book_singlecolumn_meta', 'mbt_do_single_book_singlecolumn_meta'); |
| 70 |
|
| 71 |
if(!mbt_get_setting('hide_domc_notice')) { add_action('mbt_after_single_book', 'mbt_the_domc_notice', 90); } |
| 72 |
|
| 73 |
//book excerpt hooks |
| 74 |
add_action('mbt_book_excerpt_content', 'mbt_do_book_excerpt_content'); |
| 75 |
add_action('mbt_before_book_excerpt', 'mbt_do_before_book_excerpt', 0); |
| 76 |
add_action('mbt_after_book_excerpt', 'mbt_do_after_book_excerpt', 100); |
| 77 |
add_action('mbt_book_excerpt_images', 'mbt_do_book_excerpt_images'); |
| 78 |
add_action('mbt_book_excerpt_title', 'mbt_do_book_excerpt_title'); |
| 79 |
add_action('mbt_book_excerpt_price', 'mbt_do_book_excerpt_price'); |
| 80 |
add_action('mbt_book_excerpt_meta', 'mbt_do_book_excerpt_meta'); |
| 81 |
add_action('mbt_book_excerpt_blurb', 'mbt_do_book_excerpt_blurb'); |
| 82 |
add_action('mbt_book_excerpt_buybuttons', 'mbt_do_book_excerpt_buybuttons'); |
| 83 |
} |
| 84 |
} |
| 85 |
add_action('mbt_init', 'mbt_templates_init'); |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
/*---------------------------------------------------------*/ |
| 90 |
/* Template Overload Functions */ |
| 91 |
/*---------------------------------------------------------*/ |
| 92 |
|
| 93 |
function mbt_load_book_templates($template) { |
| 94 |
global $post; |
| 95 |
|
| 96 |
if(mbt_is_booktable_page() or is_post_type_archive('mbt_book') or is_tax('mbt_author') or is_tax('mbt_genre') or is_tax('mbt_series') or is_tax('mbt_tag')) { |
| 97 |
$template = mbt_locate_template('archive-book.php'); |
| 98 |
} else if(is_singular('mbt_book')) { |
| 99 |
$template = mbt_locate_template('single-book-'.mbt_get_book_display_mode($post->ID).'.php'); |
| 100 |
} |
| 101 |
|
| 102 |
return $template; |
| 103 |
} |
| 104 |
|
| 105 |
function mbt_pre_get_posts($query) { |
| 106 |
if(!is_admin() and $query->is_main_query()) { |
| 107 |
if(mbt_get_setting('booktable_page') and ($booktable_page = get_post(mbt_get_setting('booktable_page')))) { |
| 108 |
if($query->is_post_type_archive('mbt_book')) { |
| 109 |
$paged = $query->get('paged'); |
| 110 |
$query->init(); |
| 111 |
$query->set('page_id', $booktable_page->ID); |
| 112 |
$query->set('paged', $paged); |
| 113 |
$query->parse_query(); |
| 114 |
} |
| 115 |
if($query->is_page() and ($query->get('page_id') == $booktable_page->ID or $query->get('pagename') == $booktable_page->post_name)) { |
| 116 |
global $mbt_is_booktable_page; |
| 117 |
$mbt_is_booktable_page = true; |
| 118 |
$query->set('paged', $query->get('paged') ? $query->get('paged') : get_query_var('page')); |
| 119 |
add_action('mbt_before_book_archive', 'mbt_do_before_booktable_page'); |
| 120 |
add_action('mbt_after_book_archive', 'mbt_do_after_booktable_page'); |
| 121 |
} |
| 122 |
} |
| 123 |
if($query->is_post_type_archive('mbt_book') or $query->is_tax('mbt_author') or $query->is_tax('mbt_genre') or $query->is_tax('mbt_tag')) { |
| 124 |
$query->set('orderby', 'menu_order'); |
| 125 |
$query->set('posts_per_page', mbt_get_posts_per_page()); |
| 126 |
} |
| 127 |
if($query->is_tax('mbt_series')) { |
| 128 |
$query->set('orderby', 'meta_value_num'); |
| 129 |
$query->set('meta_key', 'mbt_series_order'); |
| 130 |
$query->set('order', 'ASC'); |
| 131 |
$query->set('posts_per_page', mbt_get_posts_per_page()); |
| 132 |
} |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
function mbt_enqueue_resources() { |
| 137 |
wp_enqueue_style('mbt-style', plugins_url('css/frontend-style.css', dirname(__FILE__)), array(), MBT_VERSION); |
| 138 |
$plugin_style_css = mbt_current_style_url('style.css'); |
| 139 |
if(!empty($plugin_style_css)) { wp_enqueue_style('mbt-style-pack', $plugin_style_css, array(), MBT_VERSION); } |
| 140 |
if(mbt_is_mbt_page()) { mbt_enqueue_frontend_scripts(); } |
| 141 |
} |
| 142 |
|
| 143 |
function mbt_enqueue_frontend_scripts() { |
| 144 |
global $mbt_enqueue_frontend_scripts_enqueued; |
| 145 |
if(!empty($mbt_enqueue_frontend_scripts_enqueued)) { return; } |
| 146 |
add_action('wp_footer', 'mbt_enqueue_scripts'); |
| 147 |
$mbt_enqueue_frontend_scripts_enqueued = true; |
| 148 |
} |
| 149 |
|
| 150 |
function mbt_enqueue_scripts() { |
| 151 |
wp_enqueue_script('jquery-ui-accordion'); |
| 152 |
wp_enqueue_script('mbt-frontend-js', plugins_url('js/frontend.js', dirname(__FILE__)), array('jquery', 'jquery-ui-accordion'), MBT_VERSION, true); |
| 153 |
wp_enqueue_script('mbt-shadowbox', plugins_url('js/lib/jquery.colorbox.min.js', dirname(__FILE__)), array('jquery'), MBT_VERSION, true); |
| 154 |
|
| 155 |
// Scroll fix: uses native window.scrollTo to bypass theme JS conflicts (e.g. Divi) |
| 156 |
// Registered after mbt-frontend-js so it loads last and owns the capture phase |
| 157 |
$scroll_deps = array( 'mbt-frontend-js' ); |
| 158 |
if ( wp_script_is( 'mbtpro3-frontend-js', 'registered' ) ) { |
| 159 |
$scroll_deps[] = 'mbtpro3-frontend-js'; |
| 160 |
} |
| 161 |
wp_enqueue_script( 'mbt-scroll-fix', plugins_url( 'js/scroll-fix.js', dirname(__FILE__) ), $scroll_deps, MBT_VERSION, true ); |
| 162 |
wp_print_scripts( 'mbt-scroll-fix' ); |
| 163 |
} |
| 164 |
|
| 165 |
function mbt_get_template_folders() { |
| 166 |
return apply_filters('mbt_template_folders', array()); |
| 167 |
} |
| 168 |
|
| 169 |
function mbt_add_default_template_folder($folders) { |
| 170 |
$folders[] = plugin_dir_path(dirname(__FILE__)).'templates/'; |
| 171 |
return $folders; |
| 172 |
} |
| 173 |
add_filter('mbt_template_folders', 'mbt_add_default_template_folder', 100); |
| 174 |
|
| 175 |
function mbt_add_theme_template_folders($folders) { |
| 176 |
$folders[] = get_stylesheet_directory().'/mybooktable/'; |
| 177 |
$folders[] = get_template_directory().'/mybooktable/'; |
| 178 |
return $folders; |
| 179 |
} |
| 180 |
add_filter('mbt_template_folders', 'mbt_add_theme_template_folders', 50); |
| 181 |
|
| 182 |
function mbt_locate_template($name) { |
| 183 |
$locatedtemplate = ''; |
| 184 |
$template_folders = mbt_get_template_folders(); |
| 185 |
foreach($template_folders as $folder) { |
| 186 |
$locatedtemplate = $folder.$name; |
| 187 |
if(file_exists($locatedtemplate)) { break; } |
| 188 |
} |
| 189 |
return $locatedtemplate; |
| 190 |
} |
| 191 |
|
| 192 |
function mbt_include_template($name) { |
| 193 |
$locatedtemplate = mbt_locate_template($name); |
| 194 |
if(file_exists($locatedtemplate)) { include($locatedtemplate); } |
| 195 |
} |
| 196 |
|
| 197 |
function mbt_add_custom_css() { |
| 198 |
$image_size = mbt_get_setting('image_size'); |
| 199 |
$book_button_size = mbt_get_setting('book_button_size'); |
| 200 |
$listing_button_size = mbt_get_setting('listing_button_size'); |
| 201 |
$widget_button_size = mbt_get_setting('widget_button_size'); |
| 202 |
?> |
| 203 |
<style type="text/css"> |
| 204 |
<?php |
| 205 |
//Book Button Size |
| 206 |
if($book_button_size == 'small') { |
| 207 |
echo(wp_kses_post('.mbt-book .mbt-book-buybuttons .mbt-book-buybutton img { width: 144px; height: 25px; } .mbt-book .mbt-book-buybuttons .mbt-book-buybutton { padding: 3px 6px 0px 0px; }')); |
| 208 |
} |
| 209 |
else if($book_button_size == 'medium') { |
| 210 |
echo(wp_kses_post('.mbt-book .mbt-book-buybuttons .mbt-book-buybutton img { width: 172px; height: 30px; } .mbt-book .mbt-book-buybuttons .mbt-book-buybutton { padding: 4px 8px 0px 0px; }')); |
| 211 |
} else { |
| 212 |
echo(wp_kses_post('.mbt-book .mbt-book-buybuttons .mbt-book-buybutton img { width: 201px; height: 35px; } .mbt-book .mbt-book-buybuttons .mbt-book-buybutton { padding: 5px 10px 0px 0px; }')); |
| 213 |
} |
| 214 |
//Listing Button Size |
| 215 |
if($listing_button_size == 'small') { |
| 216 |
echo(wp_kses_post('.mbt-book-archive .mbt-book .mbt-book-buybuttons .mbt-book-buybutton img { width: 144px; height: 25px; } .mbt-book-archive .mbt-book .mbt-book-buybuttons .mbt-book-buybutton { padding: 3px 6px 0px 0px; }')); |
| 217 |
} else if($listing_button_size == 'medium') { echo(wp_kses_post('.mbt-book-archive .mbt-book .mbt-book-buybuttons .mbt-book-buybutton img { width: 172px; height: 30px; } .mbt-book-archive .mbt-book .mbt-book-buybuttons .mbt-book-buybutton { padding: 4px 8px 0px 0px; }')); |
| 218 |
} else { |
| 219 |
echo(wp_kses_post('.mbt-book-archive .mbt-book .mbt-book-buybuttons .mbt-book-buybutton img { width: 201px; height: 35px; } .mbt-book-archive .mbt-book .mbt-book-buybuttons .mbt-book-buybutton { padding: 5px 10px 0px 0px; }')); |
| 220 |
} |
| 221 |
//Widget Button Size |
| 222 |
if($widget_button_size == 'small') { |
| 223 |
echo(wp_kses_post('.mbt-featured-book-widget .mbt-book-buybuttons .mbt-book-buybutton img { width: 144px; height: 25px; } .mbt-featured-book-widget .mbt-book-buybuttons .mbt-book-buybutton { padding: 3px 6px 0px 0px; }')); |
| 224 |
} else if($widget_button_size == 'medium') { |
| 225 |
echo(wp_kses_post('.mbt-featured-book-widget .mbt-book-buybuttons .mbt-book-buybutton img { width: 172px; height: 30px; } .mbt-featured-book-widget .mbt-book-buybuttons .mbt-book-buybutton { padding: 4px 8px 0px 0px; }')); |
| 226 |
} else { |
| 227 |
echo('.mbt-featured-book-widget .mbt-book-buybuttons .mbt-book-buybutton img { width: 201px; height: 35px; } .mbt-featured-book-widget .mbt-book-buybuttons .mbt-book-buybutton { padding: 5px 10px 0px 0px; }'); |
| 228 |
} |
| 229 |
?> |
| 230 |
</style> |
| 231 |
<?php |
| 232 |
} |
| 233 |
|
| 234 |
function mbt_body_class($classes) { |
| 235 |
if(mbt_is_mbt_page()) { |
| 236 |
$classes[] = 'mybooktable'; |
| 237 |
} |
| 238 |
return $classes; |
| 239 |
} |
| 240 |
|
| 241 |
/*---------------------------------------------------------*/ |
| 242 |
/* Template Context Functions */ |
| 243 |
/*---------------------------------------------------------*/ |
| 244 |
|
| 245 |
function mbt_init_template_context_data() { |
| 246 |
global $mbt_template_context_data; |
| 247 |
if(empty($mbt_template_context_data)) { |
| 248 |
$mbt_template_context_data = array( |
| 249 |
'context' => array(), |
| 250 |
'display_mode' => array(), |
| 251 |
); |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
function mbt_start_template_context($context) { |
| 256 |
global $mbt_template_context_data; |
| 257 |
mbt_init_template_context_data(); |
| 258 |
array_push($mbt_template_context_data['context'], $context); |
| 259 |
} |
| 260 |
|
| 261 |
function mbt_end_template_context() { |
| 262 |
global $mbt_template_context_data; |
| 263 |
mbt_init_template_context_data(); |
| 264 |
array_pop($mbt_template_context_data['context']); |
| 265 |
} |
| 266 |
|
| 267 |
function mbt_has_template_context($context) { |
| 268 |
global $mbt_template_context_data; |
| 269 |
mbt_init_template_context_data(); |
| 270 |
return in_array($context, $mbt_template_context_data['context']); |
| 271 |
} |
| 272 |
|
| 273 |
function mbt_start_template_display_mode($display_mode) { |
| 274 |
global $mbt_template_context_data; |
| 275 |
mbt_init_template_context_data(); |
| 276 |
array_push($mbt_template_context_data['display_mode'], $display_mode); |
| 277 |
} |
| 278 |
|
| 279 |
function mbt_end_template_display_mode() { |
| 280 |
global $mbt_template_context_data; |
| 281 |
mbt_init_template_context_data(); |
| 282 |
array_pop($mbt_template_context_data['display_mode']); |
| 283 |
} |
| 284 |
|
| 285 |
function mbt_get_template_display_mode() { |
| 286 |
global $mbt_template_context_data; |
| 287 |
mbt_init_template_context_data(); |
| 288 |
return end($mbt_template_context_data['display_mode']); |
| 289 |
} |
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
/*---------------------------------------------------------*/ |
| 294 |
/* General Template Functions */ |
| 295 |
/*---------------------------------------------------------*/ |
| 296 |
function mbt_do_wrapper_start() { |
| 297 |
mbt_include_template("wrapper-start.php"); |
| 298 |
} |
| 299 |
function mbt_do_wrapper_end() { |
| 300 |
mbt_include_template("wrapper-end.php"); |
| 301 |
} |
| 302 |
function mbt_do_book_excerpt() { |
| 303 |
mbt_include_template("excerpt-book.php"); |
| 304 |
} |
| 305 |
function mbt_do_before_booktable_page() { |
| 306 |
global $wp_query; |
| 307 |
if($wp_query->is_main_query()) { |
| 308 |
mbt_push_query( |
| 309 |
'booktable_page', |
| 310 |
new WP_Query(array('post_type' => 'mbt_book', 'paged' => $wp_query->get('paged'), 'orderby' => 'menu_order', 'posts_per_page' => mbt_get_posts_per_page())) |
| 311 |
); |
| 312 |
} |
| 313 |
} |
| 314 |
function mbt_do_after_booktable_page() { |
| 315 |
mbt_pop_query('booktable_page'); |
| 316 |
} |
| 317 |
function mbt_enable_frontend_ajax() { |
| 318 |
?> |
| 319 |
<script type="text/javascript"> |
| 320 |
window.ajaxurl = "<?php echo(esc_url(admin_url('admin-ajax.php'))); ?>"; |
| 321 |
</script> |
| 322 |
<?php |
| 323 |
} |
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
/*---------------------------------------------------------*/ |
| 328 |
/* Book Archive Template Functions */ |
| 329 |
/*---------------------------------------------------------*/ |
| 330 |
function mbt_do_book_archive_content() { |
| 331 |
mbt_include_template("archive-book/content.php"); |
| 332 |
} |
| 333 |
function mbt_do_before_book_archive() { |
| 334 |
mbt_include_template("archive-book/before.php"); |
| 335 |
} |
| 336 |
function mbt_do_after_book_archive() { |
| 337 |
mbt_include_template("archive-book/after.php"); |
| 338 |
} |
| 339 |
function mbt_do_book_archive_header() { |
| 340 |
mbt_include_template("archive-book/header.php"); |
| 341 |
} |
| 342 |
function mbt_do_book_archive_header_image() { |
| 343 |
mbt_include_template("archive-book/header/image.php"); |
| 344 |
} |
| 345 |
function mbt_do_book_archive_header_title() { |
| 346 |
mbt_include_template("archive-book/header/title.php"); |
| 347 |
} |
| 348 |
function mbt_do_book_archive_header_description() { |
| 349 |
mbt_include_template("archive-book/header/description.php"); |
| 350 |
} |
| 351 |
function mbt_do_book_archive_loop() { |
| 352 |
mbt_include_template("archive-book/loop.php"); |
| 353 |
} |
| 354 |
function mbt_do_book_archive_no_results() { |
| 355 |
mbt_include_template("archive-book/no-results.php"); |
| 356 |
} |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
/*---------------------------------------------------------*/ |
| 361 |
/* Single Book Template Functions */ |
| 362 |
/*---------------------------------------------------------*/ |
| 363 |
|
| 364 |
/* storefront mode */ |
| 365 |
|
| 366 |
function mbt_do_single_book_storefront_content() { |
| 367 |
mbt_include_template("single-book-storefront/content.php"); |
| 368 |
} |
| 369 |
function mbt_do_before_single_book_storefront() { |
| 370 |
mbt_include_template("single-book-storefront/before.php"); |
| 371 |
} |
| 372 |
function mbt_do_after_single_book_storefront() { |
| 373 |
mbt_include_template("single-book-storefront/after.php"); |
| 374 |
} |
| 375 |
function mbt_do_single_book_storefront_images() { |
| 376 |
mbt_include_template("single-book-storefront/images.php"); |
| 377 |
} |
| 378 |
function mbt_do_single_book_storefront_title() { |
| 379 |
mbt_include_template("single-book-storefront/title.php"); |
| 380 |
} |
| 381 |
function mbt_do_single_book_storefront_price() { |
| 382 |
mbt_include_template("single-book-storefront/price.php"); |
| 383 |
} |
| 384 |
function mbt_do_single_book_storefront_meta() { |
| 385 |
mbt_include_template("single-book-storefront/meta.php"); |
| 386 |
} |
| 387 |
function mbt_do_single_book_storefront_blurb() { |
| 388 |
mbt_include_template("single-book-storefront/blurb.php"); |
| 389 |
} |
| 390 |
function mbt_do_single_book_storefront_buybuttons() { |
| 391 |
mbt_include_template("single-book-storefront/buybuttons.php"); |
| 392 |
} |
| 393 |
function mbt_do_single_book_storefront_overview() { |
| 394 |
mbt_include_template("single-book-storefront/overview.php"); |
| 395 |
} |
| 396 |
function mbt_do_single_book_storefront_summary() { |
| 397 |
mbt_include_template("single-book-storefront/summary.php"); |
| 398 |
} |
| 399 |
function mbt_single_book_storefront_book_reviews_section_title($title, $post_id, $section_id) { |
| 400 |
if(mbt_get_book_display_mode($post_id) == 'storefront' and $section_id == 'reviews') { $title = ''; } |
| 401 |
return $title; |
| 402 |
} |
| 403 |
function mbt_get_storefront_content_sections($sections) { |
| 404 |
$sections['summary'] = array('name'=> 'Summary', 'priority' => 10, 'action' => 'mbt_single_book_storefront_summary'); |
| 405 |
$sections['video_sample'] = array('name'=> 'Video Sample', 'priority' => 20, 'function' => 'mbt_do_standard_book_video_sample_section'); |
| 406 |
$sections['overview'] = array('name'=> 'Overview', 'priority' => 30, 'action' => 'mbt_single_book_storefront_overview'); |
| 407 |
$sections['endorsements'] = array('name'=> 'Endorsements', 'priority' => 40, 'function' => 'mbt_do_standard_book_endorsements_section'); |
| 408 |
$sections['bookclub'] = array('name'=> 'Book Club Resources', 'priority' => 50, 'function' => 'mbt_do_standard_book_bookclub_section'); |
| 409 |
$sections['audiobook'] = array('name'=> 'Audio Book Resources', 'priority' => 55, 'function' => 'mbt_do_standard_book_audiobook_section'); |
| 410 |
if(mbt_get_setting('show_about_author')) { $sections['about_author'] = array('name'=> 'About Author', 'priority' => 100, 'function' => 'mbt_do_standard_book_about_author_section'); } |
| 411 |
if(mbt_get_setting('show_series')) { $sections['series'] = array('name'=> 'Books in Series', 'priority' => 110, 'function' => 'mbt_do_standard_book_series_section'); } |
| 412 |
$sections['kindle_instant_preview'] = array('name'=> 'Kindle Instant Preview', 'priority' => 120, 'function' => 'mbt_do_standard_kindle_instant_preview_section'); |
| 413 |
if(mbt_get_setting('show_find_bookstore')) { $sections['find_bookstore'] = array('name'=> 'Find Bookstores', 'priority' => 130, 'function' => 'mbt_do_standard_find_bookstore_section'); } |
| 414 |
$sections['reviews'] = array('name'=> 'Reviews', 'priority' => 140, 'function' => 'mbt_do_standard_reviews_section'); |
| 415 |
return $sections; |
| 416 |
} |
| 417 |
|
| 418 |
/* singlecolumn mode */ |
| 419 |
|
| 420 |
function mbt_do_single_book_singlecolumn_content() { |
| 421 |
mbt_include_template("single-book-singlecolumn/content.php"); |
| 422 |
} |
| 423 |
function mbt_do_before_single_book_singlecolumn() { |
| 424 |
mbt_include_template("single-book-singlecolumn/before.php"); |
| 425 |
} |
| 426 |
function mbt_do_after_single_book_singlecolumn() { |
| 427 |
mbt_include_template("single-book-singlecolumn/after.php"); |
| 428 |
} |
| 429 |
function mbt_do_single_book_singlecolumn_title() { |
| 430 |
mbt_include_template("single-book-singlecolumn/title.php"); |
| 431 |
} |
| 432 |
function mbt_do_single_book_singlecolumn_blurb() { |
| 433 |
mbt_include_template("single-book-singlecolumn/blurb.php"); |
| 434 |
} |
| 435 |
function mbt_do_single_book_singlecolumn_meta() { |
| 436 |
mbt_include_template("single-book-singlecolumn/meta.php"); |
| 437 |
} |
| 438 |
function mbt_do_single_book_singlecolumn_overview() { |
| 439 |
mbt_include_template("single-book-singlecolumn/overview.php"); |
| 440 |
} |
| 441 |
function mbt_do_single_book_singlecolumn_summary() { |
| 442 |
mbt_include_template("single-book-singlecolumn/summary.php"); |
| 443 |
} |
| 444 |
function mbt_get_singlecolumn_content_sections($sections) { |
| 445 |
$sections['summary'] = array('name'=> 'Summary', 'priority' => 10, 'action' => 'mbt_single_book_singlecolumn_summary'); |
| 446 |
$sections['video_sample'] = array('name'=> 'Video Sample', 'priority' => 20, 'function' => 'mbt_do_standard_book_video_sample_section'); |
| 447 |
$sections['overview'] = array('name'=> 'Overview', 'priority' => 30, 'action' => 'mbt_single_book_singlecolumn_overview'); |
| 448 |
$sections['meta'] = array('name'=> 'Details', 'priority' => 40, 'action' => 'mbt_single_book_singlecolumn_meta'); |
| 449 |
$sections['endorsements'] = array('name'=> 'Endorsements', 'priority' => 50, 'function' => 'mbt_do_standard_book_endorsements_section'); |
| 450 |
$sections['bookclub'] = array('name'=> 'Book Club Resources', 'priority' => 60, 'function' => 'mbt_do_standard_book_bookclub_section'); |
| 451 |
$sections['audiobook'] = array('name'=> 'Audio Book Resources', 'priority' => 65, 'function' => 'mbt_do_standard_book_audiobook_section'); |
| 452 |
$sections['purchase'] = array('name'=> 'Buy Buttons', 'priority' => 70, 'function' => 'mbt_do_standard_book_purchase_section'); |
| 453 |
if(mbt_get_setting('enable_socialmedia_single_book')) { $sections['socialmedia'] = array('name'=> 'Social Media', 'priority' => 80, 'function' => 'mbt_do_standard_book_socialmedia_section'); } |
| 454 |
if(mbt_get_setting('show_about_author')) { $sections['about_author'] = array('name'=> 'About Author', 'priority' => 100, 'function' => 'mbt_do_standard_book_about_author_section'); } |
| 455 |
if(mbt_get_setting('show_series')) { $sections['series'] = array('name'=> 'Books in Series', 'priority' => 110, 'function' => 'mbt_do_standard_book_series_section'); } |
| 456 |
$sections['preview'] = array('name'=> 'Preview', 'priority' => 125, 'function' => 'mbt_do_standard_book_preview_section'); |
| 457 |
if(mbt_get_setting('show_find_bookstore')) { $sections['find_bookstore'] = array('name'=> 'Find Bookstores', 'priority' => 130, 'function' => 'mbt_do_standard_find_bookstore_section'); } |
| 458 |
$sections['reviews'] = array('name'=> 'Reviews', 'priority' => 140, 'function' => 'mbt_do_standard_reviews_section'); |
| 459 |
return $sections; |
| 460 |
} |
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
/*---------------------------------------------------------*/ |
| 465 |
/* Book Excerpt Template Functions */ |
| 466 |
/*---------------------------------------------------------*/ |
| 467 |
function mbt_do_book_excerpt_content() { |
| 468 |
mbt_include_template("excerpt-book/content.php"); |
| 469 |
} |
| 470 |
function mbt_do_before_book_excerpt() { |
| 471 |
mbt_include_template("excerpt-book/before.php"); |
| 472 |
} |
| 473 |
function mbt_do_after_book_excerpt() { |
| 474 |
mbt_include_template("excerpt-book/after.php"); |
| 475 |
} |
| 476 |
function mbt_do_book_excerpt_images() { |
| 477 |
mbt_include_template("excerpt-book/images.php"); |
| 478 |
} |
| 479 |
function mbt_do_book_excerpt_title() { |
| 480 |
mbt_include_template("excerpt-book/title.php"); |
| 481 |
} |
| 482 |
function mbt_do_book_excerpt_price() { |
| 483 |
mbt_include_template("excerpt-book/price.php"); |
| 484 |
} |
| 485 |
function mbt_do_book_excerpt_meta() { |
| 486 |
mbt_include_template("excerpt-book/meta.php"); |
| 487 |
} |
| 488 |
function mbt_do_book_excerpt_blurb() { |
| 489 |
mbt_include_template("excerpt-book/blurb.php"); |
| 490 |
} |
| 491 |
function mbt_do_book_excerpt_buybuttons() { |
| 492 |
mbt_include_template("excerpt-book/buybuttons.php"); |
| 493 |
} |
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
/*---------------------------------------------------------*/ |
| 498 |
/* Book Archive Functions */ |
| 499 |
/*---------------------------------------------------------*/ |
| 500 |
|
| 501 |
function mbt_get_book_archive_image() { |
| 502 |
$query_obj = get_queried_object(); |
| 503 |
if(empty($query_obj) or empty($query_obj->taxonomy)) { return ''; } |
| 504 |
$img = mbt_get_taxonomy_image($query_obj->taxonomy, $query_obj->term_id); |
| 505 |
return apply_filters('mbt_get_book_archive_image', empty($img) ? '' : '<img class="mbt-book-archive-image" src="'.$img.'">'); |
| 506 |
} |
| 507 |
function mbt_the_book_archive_image() { |
| 508 |
echo(wp_kses_post(mbt_get_book_archive_image())); |
| 509 |
} |
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
function mbt_get_book_archive_title($before = '', $after = '') { |
| 514 |
$output = ''; |
| 515 |
|
| 516 |
if(is_tax('mbt_author') or is_tax('mbt_genre') or is_tax('mbt_series') or is_tax('mbt_tag')) { |
| 517 |
$output = get_queried_object()->name; |
| 518 |
} else if(mbt_is_booktable_page()) { |
| 519 |
$booktable_page = get_post(mbt_get_setting('booktable_page')); |
| 520 |
$output = $booktable_page->post_title; |
| 521 |
} else if(is_post_type_archive('mbt_book')) { |
| 522 |
if(mbt_get_setting('booktable_page') and ($booktable_page = get_post(mbt_get_setting('booktable_page')))) { |
| 523 |
$output = $booktable_page->post_title; |
| 524 |
} else { |
| 525 |
$output = mbt_get_product_name(); |
| 526 |
} |
| 527 |
} |
| 528 |
|
| 529 |
return apply_filters('mbt_get_book_archive_title', empty($output) ? '' : $before.$output.$after, $before, $after); |
| 530 |
} |
| 531 |
function mbt_the_book_archive_title($before = '', $after = '') { |
| 532 |
echo(wp_kses_post(mbt_get_book_archive_title($before, $after))); |
| 533 |
} |
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
function mbt_get_book_archive_description($before = '', $after = '') { |
| 538 |
$output = ''; |
| 539 |
|
| 540 |
if(is_tax('mbt_author') or is_tax('mbt_genre') or is_tax('mbt_series') or is_tax('mbt_tag')) { |
| 541 |
$output = do_shortcode(apply_filters('term_description', get_queried_object()->description)); |
| 542 |
} else if(mbt_is_booktable_page()) { |
| 543 |
if(function_exists('st_remove_st_add_link')) { st_remove_st_add_link(''); } |
| 544 |
mbt_push_query('book_archive_description', new WP_Query(array('page_id' => mbt_get_setting('booktable_page')))); |
| 545 |
global $post; |
| 546 |
$output = $post ? apply_filters('the_content', $post->post_content) : ''; |
| 547 |
mbt_pop_query('book_archive_description'); |
| 548 |
} else if(is_post_type_archive('mbt_book')) { |
| 549 |
if(mbt_get_setting('booktable_page')) { |
| 550 |
if(function_exists('st_remove_st_add_link')) { st_remove_st_add_link(''); } |
| 551 |
mbt_push_query('book_archive_description', new WP_Query(array('page_id' => mbt_get_setting('booktable_page')))); |
| 552 |
global $post; |
| 553 |
$output = $post ? apply_filters('the_content', $post->post_content) : ''; |
| 554 |
mbt_pop_query('book_archive_description'); |
| 555 |
} |
| 556 |
} |
| 557 |
|
| 558 |
return apply_filters('mbt_get_book_archive_description', empty($output) ? '' : $before.$output.$after, $before, $after); |
| 559 |
} |
| 560 |
function mbt_the_book_archive_description($before = '', $after = '') { |
| 561 |
echo(wp_kses_post(mbt_get_book_archive_description($before, $after))); |
| 562 |
} |
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
function mbt_get_book_archive_pagination() { |
| 567 |
global $wp_query; |
| 568 |
|
| 569 |
$posts_per_page = intval($wp_query->get('posts_per_page')); |
| 570 |
$paged = max(1, absint($wp_query->get('paged'))); |
| 571 |
$total_pages = max(1, absint($wp_query->max_num_pages)); |
| 572 |
if($total_pages < 2) { return; } |
| 573 |
|
| 574 |
$pages_to_show = 7; |
| 575 |
$pages_to_show_minus_1 = $pages_to_show - 1; |
| 576 |
$half_page_start = floor($pages_to_show_minus_1/2); |
| 577 |
$half_page_end = ceil($pages_to_show_minus_1/2); |
| 578 |
$start_page = max(1, $paged - $half_page_start); |
| 579 |
|
| 580 |
$end_page = $paged + $half_page_end; |
| 581 |
|
| 582 |
if(($end_page - $start_page) != $pages_to_show_minus_1) { |
| 583 |
$end_page = $start_page + $pages_to_show_minus_1; |
| 584 |
} |
| 585 |
|
| 586 |
if($end_page > $total_pages) { |
| 587 |
$start_page = max(1, $total_pages - $pages_to_show_minus_1); |
| 588 |
$end_page = $total_pages; |
| 589 |
} |
| 590 |
|
| 591 |
$prev_text = apply_filters('mbt_book_archive_pagination_previous', '← '.__('Back', 'mybooktable')); |
| 592 |
$next_text = apply_filters('mbt_book_archive_pagination_next', __('More Books', 'mybooktable').' →'); |
| 593 |
|
| 594 |
$output = '<nav class="mbt-book-archive-pagination">'; |
| 595 |
|
| 596 |
if($paged > 1) { $output .= '<a href="'.get_pagenum_link($paged - 1).'" class="mbt-book-archive-pagination-previous">'.$prev_text.'</a>'; } |
| 597 |
if($start_page >= 2 && $pages_to_show < $total_pages) { $output .= '<span class="mbt-book-archive-pagination-delimiter">'.apply_filters('mbt_book_archive_pagination_delimiter', '…').'</span>'; } |
| 598 |
|
| 599 |
foreach(range($start_page, $end_page) as $i) { |
| 600 |
if($i == $paged) { |
| 601 |
$output .= '<span class="mbt-book-archive-pagination-page current">'.apply_filters('mbt_book_archive_pagination_page', strval($i)).'</span>'; |
| 602 |
} else { |
| 603 |
$output .= '<a href="'.get_pagenum_link($i).'" class="mbt-book-archive-pagination-page">'.apply_filters('mbt_book_archive_pagination_page', strval($i)).'</a>'; |
| 604 |
} |
| 605 |
} |
| 606 |
|
| 607 |
if($end_page < $total_pages) { $output .= '<span class="mbt-book-archive-pagination-delimiter">'.apply_filters('mbt_book_archive_pagination_delimiter', '…').'</span>'; } |
| 608 |
if($paged < $total_pages) { $output .= '<a href="'.get_pagenum_link($paged + 1).'" class="mbt-book-archive-pagination-next">'.$next_text.'</a>'; } |
| 609 |
|
| 610 |
$output .= "</nav>"; |
| 611 |
|
| 612 |
return apply_filters('mbt_get_book_archive_pagination', $output); |
| 613 |
} |
| 614 |
function mbt_the_book_archive_pagination() { |
| 615 |
echo(wp_kses_post(mbt_get_book_archive_pagination())); |
| 616 |
} |
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
/*---------------------------------------------------------*/ |
| 621 |
/* General Book Functions */ |
| 622 |
/*---------------------------------------------------------*/ |
| 623 |
|
| 624 |
function mbt_do_book_content_sections($display_mode) { |
| 625 |
$sections = mbt_get_sorted_content_sections($display_mode); |
| 626 |
echo('<div class="mbt-book-sections">'); |
| 627 |
foreach($sections as $section) { |
| 628 |
if(!empty($section['action'])) { |
| 629 |
do_action($section['action']); |
| 630 |
} else if(!empty($section['function'])) { |
| 631 |
call_user_func($section['function']); |
| 632 |
} |
| 633 |
} |
| 634 |
echo('</div>'); |
| 635 |
} |
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
// Book Class |
| 640 |
function mbt_get_book_class($post_id) { |
| 641 |
$context = mbt_has_template_context('excerpt') ? 'excerpt' : (mbt_has_template_context('single') ? 'single' : ''); |
| 642 |
$display_mode = $context == 'single' ? mbt_get_template_display_mode() : ''; |
| 643 |
return apply_filters('mbt_get_book_class', 'mbt-book'.(empty($context) ? '' : ' mbt-book-'.$context).(empty($display_mode) ? '' : ' mbt-display-mode-'.$display_mode), $post_id); |
| 644 |
} |
| 645 |
function mbt_the_book_class() { |
| 646 |
global $post; |
| 647 |
echo(esc_attr(mbt_get_book_class($post->ID))); |
| 648 |
} |
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
// Book Image |
| 653 |
function mbt_get_placeholder_image_src() { |
| 654 |
return apply_filters('mbt_get_placeholder_image_src', array(plugins_url('images/book-placeholder.jpg', dirname(__FILE__)), 400, 472)); |
| 655 |
} |
| 656 |
function mbt_get_large_placeholder_image_src() { |
| 657 |
return apply_filters('mbt_get_large_placeholder_image_src', array(plugins_url('images/book-placeholder-large.jpg', dirname(__FILE__)), 1000, 1178)); |
| 658 |
} |
| 659 |
function mbt_get_book_image_src($post_id) { |
| 660 |
//prevent Jetpack Photon from breaking image width/height by disabling their image downsize |
| 661 |
add_filter('jetpack_photon_override_image_downsize', '__return_true'); |
| 662 |
$image = wp_get_attachment_image_src(get_post_meta($post_id, 'mbt_book_image_id', true), 'mbt_book_image'); |
| 663 |
remove_filter('jetpack_photon_override_image_downsize', '__return_true'); |
| 664 |
return apply_filters('mbt_get_book_image_src', $image ? $image : mbt_get_placeholder_image_src(), $post_id); |
| 665 |
} |
| 666 |
function mbt_get_book_image_srcset($post_id) { |
| 667 |
//prevent Jetpack Photon from breaking image width/height by disabling their image downsize |
| 668 |
add_filter('jetpack_photon_override_image_downsize', '__return_true'); |
| 669 |
$srcset = function_exists('wp_get_attachment_image_srcset') ? wp_get_attachment_image_srcset(get_post_meta($post_id, 'mbt_book_image_id', true), 'mbt_book_image') : ''; |
| 670 |
if(!$srcset) { |
| 671 |
list($src, $width, $height) = mbt_get_book_image_src($post_id); |
| 672 |
$srcset = $src ? $src.' '.$width.'w' : ''; |
| 673 |
|
| 674 |
//build extra srcset for placeholder image |
| 675 |
$placeholder = mbt_get_placeholder_image_src(); |
| 676 |
if($src == $placeholder[0]) { |
| 677 |
$placeholder_large = mbt_get_large_placeholder_image_src(); |
| 678 |
$srcset = $placeholder[0].' '.$placeholder[1].'w, '.$placeholder_large[0].' '.$placeholder_large[1].'w'; |
| 679 |
} |
| 680 |
} |
| 681 |
remove_filter('jetpack_photon_override_image_downsize', '__return_true'); |
| 682 |
return apply_filters('mbt_get_book_image_srcset', $srcset, $post_id); |
| 683 |
} |
| 684 |
function mbt_get_book_image($post_id, $attrs = '') { |
| 685 |
list($src, $width, $height) = mbt_get_book_image_src($post_id); |
| 686 |
$srcset = mbt_get_book_image_srcset($post_id); |
| 687 |
|
| 688 |
$image_size = mbt_get_setting('image_size'); |
| 689 |
if($image_size == 'small') { $sizes = '15vw'; } |
| 690 |
else if($image_size == 'large') { $sizes = '35vw'; } |
| 691 |
else { $sizes = '25vw'; } |
| 692 |
|
| 693 |
$attrs = wp_parse_args($attrs, array('alt' => wp_strip_all_tags(get_the_title($post_id)), 'class' => '', 'sizes' => $sizes)); |
| 694 |
$attrs['class'] .= ' mbt-book-image'; |
| 695 |
$attrs['src'] = esc_url($src); |
| 696 |
$attrs['srcset'] = wp_kses_post($srcset); |
| 697 |
|
| 698 |
$attributes = array(); |
| 699 |
foreach($attrs as $attr => $value) { |
| 700 |
$attributes[] = $attr.'="'.$value.'"'; |
| 701 |
} |
| 702 |
|
| 703 |
return apply_filters('mbt_get_book_image', '<img itemprop="image" '.implode(' ', $attributes).'>', $post_id, $attrs); |
| 704 |
} |
| 705 |
function mbt_the_book_image($attrs = '') { |
| 706 |
global $post; |
| 707 |
echo(wp_kses_post(mbt_get_book_image($post->ID, $attrs))); |
| 708 |
} |
| 709 |
|
| 710 |
function mbt_get_book_images($post_id, $include_link = false) { |
| 711 |
$image_size_class = ''; |
| 712 |
$image_size = mbt_get_setting('image_size'); |
| 713 |
if($image_size == 'small') { $image_size_class = 'mbt-book-images-small'; } |
| 714 |
else if($image_size == 'large') { $image_size_class = 'mbt-book-images-large'; } |
| 715 |
|
| 716 |
$output = ''; |
| 717 |
$output .= '<div class="mbt-book-images '.$image_size_class.'">'; |
| 718 |
$output .= $include_link ? '<a href="'.get_permalink($post_id).'">'.mbt_get_book_image($post_id).'</a>' : mbt_get_book_image($post_id); |
| 719 |
$output .= '</div>'; |
| 720 |
|
| 721 |
return apply_filters('mbt_get_book_images', $output, $post_id, $include_link); |
| 722 |
} |
| 723 |
|
| 724 |
function mbt_the_book_images($include_link = false) { |
| 725 |
global $post; |
| 726 |
echo(wp_kses_post(mbt_get_book_images($post->ID, $include_link))); |
| 727 |
} |
| 728 |
|
| 729 |
// Book Price Display |
| 730 |
function mbt_get_book_price($post_id) { |
| 731 |
$price = get_post_meta($post_id, 'mbt_price', true); |
| 732 |
if(preg_match("/^[0-9.]+$/", $price)) { $price = "$".number_format((double)$price, 2); } |
| 733 |
|
| 734 |
$sale_price = get_post_meta($post_id, 'mbt_sale_price', true); |
| 735 |
if(preg_match("/^[0-9.]+$/", $sale_price)) { $sale_price = "$".number_format((double)$sale_price, 2); } |
| 736 |
|
| 737 |
$ebook_price = get_post_meta($post_id, 'mbt_ebook_price', true); |
| 738 |
if(preg_match("/^[0-9.]+$/", $ebook_price)) { $ebook_price = "$".number_format((double)$ebook_price, 2); } |
| 739 |
|
| 740 |
$audiobook_price = get_post_meta($post_id, 'mbt_audiobook_price', true); |
| 741 |
if(preg_match("/^[0-9.]+$/", $audiobook_price)) { $audiobook_price = "$".number_format((double)$audiobook_price, 2); } |
| 742 |
|
| 743 |
$output = ''; |
| 744 |
if(!empty($sale_price) and !empty($price)) { |
| 745 |
$output = '<span itemprop="offers" itemscope itemtype="https://schema.org/Offer"><span itemprop="price" class="mbt-old-price">'.$price.'</span><link itemprop="availability" href="https://schema.org/Discontinued"/></span>'; |
| 746 |
$output .= '<span itemprop="offers" itemscope itemtype="https://schema.org/Offer"><span itemprop="price" class="mbt-new-price">'.$sale_price.'</span><link itemprop="availability" href="https://schema.org/InStock"/></span>'; |
| 747 |
} else if(!empty($price)) { |
| 748 |
$output = '<span itemprop="offers" itemscope itemtype="https://schema.org/Offer"><span itemprop="price">'.$price.'</span><link itemprop="availability" href="https://schema.org/InStock"/></span>'; |
| 749 |
} |
| 750 |
|
| 751 |
if(!empty($ebook_price)) { |
| 752 |
$output .= '<span class="mbt-alt-price"><span class="mbt-price-title">'.__('eBook', 'mybooktable').':</span> <span itemprop="offers" itemscope itemtype="https://schema.org/Offer"><span itemprop="price">'.$ebook_price.'</span><link itemprop="availability" href="https://schema.org/InStock"/></span></span>'; |
| 753 |
} |
| 754 |
if(!empty($audiobook_price)) { |
| 755 |
$output .= '<span class="mbt-alt-price"><span class="mbt-price-title">'.__('Audiobook', 'mybooktable').':</span> <span itemprop="offers" itemscope itemtype="https://schema.org/Offer"><span itemprop="price">'.$audiobook_price.'</span><link itemprop="availability" href="https://schema.org/InStock"/></span></span>'; |
| 756 |
} |
| 757 |
|
| 758 |
if(!empty($output)) { $output = '<div class="mbt-book-price">'.$output.'</div>'; } |
| 759 |
|
| 760 |
return apply_filters('mbt_get_book_price', $output, $post_id); |
| 761 |
} |
| 762 |
function mbt_the_book_price() { |
| 763 |
global $post; |
| 764 |
echo(wp_kses_post(mbt_get_book_price($post->ID))); |
| 765 |
} |
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
// Book Samples |
| 770 |
function mbt_get_book_sample($post_id) { |
| 771 |
$output = ''; |
| 772 |
$sample_chapter = get_post_meta($post_id, 'mbt_sample_url', true); |
| 773 |
$audio_sample = get_post_meta($post_id, 'mbt_sample_audio', true); |
| 774 |
$audio_type = wp_check_filetype($audio_sample, wp_get_mime_types()); |
| 775 |
$output .= empty($sample_chapter) ? '' : '<div class="mbt-book-sample mbt-book-sample-chapter"><a target="_blank" href="'.$sample_chapter.'">'.__('View Book Sample', 'mybooktable').'</a></div>'; |
| 776 |
$output .= empty($audio_sample) ? '' : '<div class="mbt-book-sample mbt-book-sample-audio"><audio controls><source src="'.$audio_sample.'" type="'.$audio_type['type'].'">Your browser does not support the audio element.</audio></div>'; |
| 777 |
return apply_filters('mbt_get_book_sample', $output, $post_id); |
| 778 |
} |
| 779 |
|
| 780 |
function mbt_the_book_sample() { |
| 781 |
global $post; |
| 782 |
echo(wp_kses_post(mbt_get_book_sample($post->ID))); |
| 783 |
} |
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
// Video Sample |
| 788 |
function mbt_get_book_video_sample($post_id) { |
| 789 |
global $wp_embed; |
| 790 |
$output = ''; |
| 791 |
$url = get_post_meta($post_id, 'mbt_sample_video', true); |
| 792 |
if(!empty($url)) { $output .= '<div class="mbt-book-video-sample">'.$wp_embed->shortcode(array('width'=>500, 'height'=>500), $url).'<div style="clear:both;"></div></div>'; } |
| 793 |
return apply_filters('mbt_get_book_video_sample', $output, $post_id); |
| 794 |
} |
| 795 |
function mbt_the_book_video_sample() { |
| 796 |
global $post; |
| 797 |
echo(wp_kses_post(mbt_get_book_video_sample($post->ID))); |
| 798 |
} |
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
// Book Buy Buttons |
| 803 |
function mbt_get_buybuttons($post_id, $excerpt=false, $force_shadowbox=null) { |
| 804 |
$output = ''; |
| 805 |
$stores = mbt_get_stores(); |
| 806 |
|
| 807 |
$using_shadowbox = (((($excerpt and mbt_get_setting('buybutton_shadowbox') == 'listings') or mbt_get_setting('buybutton_shadowbox') == 'all') and $force_shadowbox !== false) or $force_shadowbox === true); |
| 808 |
|
| 809 |
$buybuttons = mbt_query_buybuttons($post_id, array('display' => 'button')); |
| 810 |
if(!empty($buybuttons)) { |
| 811 |
foreach($buybuttons as $buybutton) { |
| 812 |
if(empty($stores[$buybutton['store']])) { continue; } |
| 813 |
$output .= mbt_format_buybutton($buybutton, $stores[$buybutton['store']]); |
| 814 |
} |
| 815 |
} |
| 816 |
|
| 817 |
if(!$excerpt or $using_shadowbox) { |
| 818 |
$textbuybuttons_output = ''; |
| 819 |
$textbuybuttons = mbt_query_buybuttons($post_id, array('display' => 'text')); |
| 820 |
if(!empty($textbuybuttons)) { |
| 821 |
$textbuybuttons_output .= '<div class="mbt-book-buybuttons-textonly">'; |
| 822 |
$textbuybuttons_output .= '<h3>'.__('Other book sellers', 'mybooktable').':</h3>'; |
| 823 |
$textbuybuttons_output .= '<ul>'; |
| 824 |
foreach($textbuybuttons as $buybutton) { |
| 825 |
if(empty($stores[$buybutton['store']])) { continue; } |
| 826 |
$textbuybuttons_output .= mbt_format_buybutton($buybutton, $stores[$buybutton['store']]); |
| 827 |
} |
| 828 |
$textbuybuttons_output .= '</ul>'; |
| 829 |
$textbuybuttons_output .= '</div>'; |
| 830 |
} |
| 831 |
$output .= apply_filters('mbt_textbuybuttons_output', $textbuybuttons_output); |
| 832 |
} |
| 833 |
|
| 834 |
$output = apply_filters('mbt_buybuttons_output', $output); |
| 835 |
|
| 836 |
if(!empty($output) and $using_shadowbox) { |
| 837 |
$book_button_size = mbt_get_setting('book_button_size'); |
| 838 |
if($book_button_size == 'small') { $buybuttons_width = 2+150*2; } |
| 839 |
else if($book_button_size == 'medium') { $buybuttons_width = 2+180*2; } |
| 840 |
else { $buybuttons_width = 2+211*2; } |
| 841 |
|
| 842 |
$shadowbox_content = apply_filters('mbt_buybuttons_shadowbox_title', '<div class="mbt-shadowbox-title">'.__('Buy This Book Online', 'mybooktable').'</div>'); |
| 843 |
$shadowbox_content .= apply_filters('mbt_buybuttons_shadowbox_buybuttons', '<div class="'.mbt_get_book_class('shadowbox').'"><div class="mbt-book-buybuttons" style="width:'.$buybuttons_width.'px">'.$output.'</div></div>', $output, $buybuttons_width); |
| 844 |
$shadowbox_content .= apply_filters('mbt_buybuttons_shadowbox_book_image', mbt_get_book_image($post_id)); |
| 845 |
$shadowbox_content .= '<div style="clear:both"></div>'; |
| 846 |
if(mbt_get_setting('show_find_bookstore_buybuttons_shadowbox')) { $shadowbox_content .= apply_filters('mbt_buybuttons_shadowbox_find_bookstore', mbt_get_find_bookstore_form($post_id)); } |
| 847 |
$shadowbox_content = apply_filters('mbt_buybuttons_shadowbox_content', $shadowbox_content); |
| 848 |
|
| 849 |
$shadowbox_output = '<div class="mbt-shadowbox-hidden" style="display:none"><div class="mbt-shadowbox mbt-buybuttons-shadowbox" id="mbt_buybutton_shadowbox_'.$post_id.'">'; |
| 850 |
$shadowbox_output .= $shadowbox_content; |
| 851 |
$shadowbox_output .= '</div></div>'; |
| 852 |
|
| 853 |
$shadowbox_button_output = '<div class="mbt-book-buybutton">'; |
| 854 |
$shadowbox_button_output .= ' <div data-href="#mbt_buybutton_shadowbox_'.$post_id.'" class="mbt-shadowbox-buybutton mbt-shadowbox-inline">'; |
| 855 |
$shadowbox_button_output .= ' <img src="'.mbt_image_url('shadowbox_button.png').'" border="0" alt="'.__('Buy now!', 'mybooktable').'"/>'; |
| 856 |
$shadowbox_button_output .= ' </div>'; |
| 857 |
$shadowbox_button_output .= '</div>'; |
| 858 |
$shadowbox_button_output = apply_filters('mbt_format_buybutton', $shadowbox_button_output, array('display'=>'button', 'store'=>'shadowbox', 'url'=>''), array('name' => 'Shadow Box')); |
| 859 |
|
| 860 |
$output = $shadowbox_output.$shadowbox_button_output; |
| 861 |
} |
| 862 |
|
| 863 |
if(!empty($output)) { $output = '<div class="mbt-book-buybuttons">'.$output.'<div style="clear:both;"></div></div>'; } |
| 864 |
|
| 865 |
return apply_filters('mbt_get_buybuttons', $output, $post_id, $excerpt, $force_shadowbox); |
| 866 |
} |
| 867 |
function mbt_the_buybuttons($excerpt=false, $force_shadowbox=null) { |
| 868 |
global $post; |
| 869 |
echo(wp_kses_post(mbt_get_buybuttons($post->ID, $excerpt, $force_shadowbox))); |
| 870 |
} |
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
// Book Blurb |
| 875 |
function mbt_get_book_blurb($post_id, $read_more = false) { |
| 876 |
$post = get_post($post_id); |
| 877 |
$output = do_shortcode(wpautop($post->post_excerpt)); |
| 878 |
if($read_more) { $output .= apply_filters('mbt_read_more', ' <a href="'.get_permalink($post_id).'" class="mbt-read-more">'.apply_filters('mbt_read_more_text',__('More info', 'mybooktable').' →' ).'</a>'); } |
| 879 |
return apply_filters('mbt_get_book_blurb', $output, $post_id, $read_more); |
| 880 |
} |
| 881 |
function mbt_the_book_blurb($read_more = false) { |
| 882 |
global $post; |
| 883 |
echo(wp_kses_post(mbt_get_book_blurb($post->ID, $read_more))); |
| 884 |
} |
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
// General Book Metadata Display |
| 889 |
function mbt_get_book_metadata($post_id, $field_id, $field_title) { |
| 890 |
$value = get_post_meta($post_id, $field_id, true); |
| 891 |
return empty($value) ? '' : '<span class="mbt-meta-item mbt-meta-length"><span class="mbt-meta-title">'.esc_html($field_title).':</span> '.esc_html($value).'</span><br>'; |
| 892 |
} |
| 893 |
function mbt_the_book_metadata($field_id, $field_title) { |
| 894 |
global $post; |
| 895 |
echo(wp_kses_post(mbt_get_book_metadata($post->ID, $field_id, $field_title))); |
| 896 |
} |
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
// Book Publisher |
| 901 |
function mbt_get_book_publisher($post_id) { |
| 902 |
$publisher_name = get_post_meta($post_id, 'mbt_publisher_name', true); |
| 903 |
$publisher_url = get_post_meta($post_id, 'mbt_publisher_url', true); |
| 904 |
if(empty($publisher_name)) { return ''; } |
| 905 |
if(empty($publisher_url)) { |
| 906 |
$publisher_string = '<span class="mbt-publisher">'.esc_html($publisher_name).'</span>'; |
| 907 |
} else { |
| 908 |
$publisher_string = '<a href="'.esc_url($publisher_url).'" target="_blank" rel="nofollow" class="mbt-publisher">'.esc_html($publisher_name).'</a>'; |
| 909 |
} |
| 910 |
$output = '<span class="mbt-meta-item mbt-meta-publisher"><span class="mbt-meta-title">'.__('Publisher', 'mybooktable').':</span> '.$publisher_string.'</span><br>'; |
| 911 |
return apply_filters('mbt_get_book_publisher', $output, $post_id); |
| 912 |
} |
| 913 |
function mbt_the_book_publisher() { |
| 914 |
global $post; |
| 915 |
echo(wp_kses_post(mbt_get_book_publisher($post->ID))); |
| 916 |
} |
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
function mbt_get_book_unique_id($post_id) { |
| 921 |
$output = ''; |
| 922 |
if(get_post_meta($post_id, 'mbt_show_unique_id', true) !== 'no') { |
| 923 |
$unique_id = get_post_meta($post_id, 'mbt_unique_id_asin', true); |
| 924 |
$output .= empty($unique_id) ? '' : '<span class="mbt-meta-item mbt-meta-asin"><span class="mbt-meta-title">ASIN:</span> <span>'.esc_html($unique_id).'</span></span><br>'; |
| 925 |
$unique_id = get_post_meta($post_id, 'mbt_unique_id_isbn', true); |
| 926 |
$output .= empty($unique_id) ? '' : '<span class="mbt-meta-item mbt-meta-isbn"><span class="mbt-meta-title">ISBN:</span> <span itemprop="isbn">'.$unique_id.'</span></span><br>'; |
| 927 |
} |
| 928 |
return apply_filters('mbt_get_book_unique_id', $output, $post_id); |
| 929 |
} |
| 930 |
function mbt_the_book_unique_id() { |
| 931 |
global $post; |
| 932 |
echo(wp_kses_post(mbt_get_book_unique_id($post->ID))); |
| 933 |
} |
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
// Taxonomy Lists |
| 938 |
function mbt_get_book_series($post_id) { |
| 939 |
$series = NULL; |
| 940 |
|
| 941 |
$terms = get_the_terms($post_id, 'mbt_series'); |
| 942 |
if(!empty($terms) and !is_wp_error($terms)) { |
| 943 |
foreach($terms as $term) { |
| 944 |
if(empty($series) or $series->term_id == $term->parent) { $series = $term; } |
| 945 |
} |
| 946 |
} |
| 947 |
|
| 948 |
return $series; |
| 949 |
} |
| 950 |
function mbt_get_book_series_list($post_id) { |
| 951 |
$output = ''; |
| 952 |
$series = mbt_get_book_series($post_id); |
| 953 |
|
| 954 |
while(!empty($series) and !is_wp_error($series)) { |
| 955 |
$output = '<a itemprop="keywords" href="'.esc_url(get_term_link($series, 'mbt_series')).'">'.esc_html($series->name).'</a>'.(empty($output) ? '' : ', '.$output); |
| 956 |
$series = get_term_by('id', $series->parent, 'mbt_series'); |
| 957 |
} |
| 958 |
|
| 959 |
if(!empty($output)) { |
| 960 |
$post = get_post($post_id); |
| 961 |
$series_order = get_post_meta($post->ID, 'mbt_series_order', true); |
| 962 |
$output = '<span class="mbt-meta-item mbt-meta-series"><span class="mbt-meta-title">'.__('Series', 'mybooktable').':</span> '.$output.((!is_string($series_order) or strlen($series_order) < 1) ? '' : ', Book '.$series_order).'</span><br>'; |
| 963 |
} |
| 964 |
|
| 965 |
return apply_filters('mbt_get_book_series_list', $output, $post_id); |
| 966 |
} |
| 967 |
function mbt_get_the_term_list($post_id, $tax, $name, $name_plural, $type) { |
| 968 |
$terms = get_the_terms($post_id, $tax); |
| 969 |
if(is_wp_error($terms) or empty($terms)){ return ''; } |
| 970 |
|
| 971 |
if($tax == 'mbt_author') { |
| 972 |
$sortfunc = function($a, $b) { |
| 973 |
$a = mbt_get_author_priority($a->term_id); |
| 974 |
$b = mbt_get_author_priority($b->term_id); |
| 975 |
return ($a > $b) ? -1 : (($a < $b) ? 1 : 0); |
| 976 |
}; |
| 977 |
usort($terms, $sortfunc); |
| 978 |
} |
| 979 |
|
| 980 |
foreach($terms as $term) { |
| 981 |
$link = get_term_link($term, $tax); |
| 982 |
$itemprop = ($type === 'author' or $type === 'genre') ? ' itemprop="'.$type.'"' : ''; |
| 983 |
$term_links[] = '<a'.$itemprop.' href="'.esc_url($link).'">'.esc_html($term->name).'</a>'; |
| 984 |
} |
| 985 |
|
| 986 |
return '<span class="mbt-meta-item mbt-meta-'.$tax.'"><span class="mbt-meta-title">'.(count($terms) > 1 ? $name_plural : $name).':</span> '.join(', ', $term_links).'</span><br>'; |
| 987 |
} |
| 988 |
function mbt_the_book_series_list() { |
| 989 |
global $post; |
| 990 |
echo(wp_kses_post(mbt_get_book_series_list($post->ID))); |
| 991 |
} |
| 992 |
function mbt_get_book_authors_list($post_id) { |
| 993 |
return apply_filters('mbt_get_book_authors_list', mbt_get_the_term_list($post_id, 'mbt_author', __('Author', 'mybooktable'), __('Authors', 'mybooktable'), 'author'), $post_id); |
| 994 |
} |
| 995 |
function mbt_the_book_authors_list() { |
| 996 |
global $post; |
| 997 |
echo(wp_kses_post(mbt_get_book_authors_list($post->ID))); |
| 998 |
} |
| 999 |
function mbt_get_book_genres_list($post_id) { |
| 1000 |
return apply_filters('mbt_get_book_genres_list', mbt_get_the_term_list($post_id, 'mbt_genre', __('Genre', 'mybooktable'), __('Genres', 'mybooktable'), 'genre'), $post_id); |
| 1001 |
} |
| 1002 |
function mbt_the_book_genres_list() { |
| 1003 |
global $post; |
| 1004 |
echo(wp_kses_post(mbt_get_book_genres_list($post->ID))); |
| 1005 |
} |
| 1006 |
function mbt_get_book_tags_list($post_id) { |
| 1007 |
return apply_filters('mbt_get_book_tags_list', mbt_get_the_term_list($post_id, 'mbt_tag', __('Tag', 'mybooktable'), __('Tags', 'mybooktable'), 'tag'), $post_id); |
| 1008 |
} |
| 1009 |
function mbt_the_book_tags_list() { |
| 1010 |
global $post; |
| 1011 |
echo(wp_kses_post(mbt_get_book_tags_list($post->ID))); |
| 1012 |
} |
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
// DOMC Notice |
| 1017 |
function mbt_the_domc_notice() { |
| 1018 |
echo(wp_kses_post('<div class="mbt-affiliate-disclaimer">'.mbt_get_setting('domc_notice_text').'</div>')); |
| 1019 |
} |
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
// Series Books Display |
| 1024 |
function mbt_get_book_series_books($post_id) { |
| 1025 |
$output = ''; |
| 1026 |
$series = mbt_get_book_series($post_id); |
| 1027 |
if(!empty($series)) { |
| 1028 |
$series_books = new WP_Query(array('mbt_series' => $series->slug, 'order' => 'ASC', 'orderby' => 'meta_value_num', 'meta_key' => 'mbt_series_order', 'post__not_in' => array($post_id), 'posts_per_page' => -1)); |
| 1029 |
if(!empty($series_books->posts)) { |
| 1030 |
$output .= '<div class="mbt-book-series">'; |
| 1031 |
foreach($series_books->posts as $series_book) { |
| 1032 |
list($src, $width, $height) = mbt_get_book_image_src($series_book->ID); |
| 1033 |
$output .= '<div class="mbt-series-book">'; |
| 1034 |
$output .= '<div class="mbt-series-book-images"><a href="'.get_permalink($series_book->ID).'"><img src="'.$src.'"></a></div>'; |
| 1035 |
$output .= '<div class="mbt-series-book-title"><a href="'.esc_url(get_permalink($series_book->ID)).'">'.esc_html($series_book->post_title).'</a></div>'; |
| 1036 |
$output .= '</div>'; |
| 1037 |
} |
| 1038 |
$output .= '<div style="clear:both"></div>'; |
| 1039 |
$output .= '</div>'; |
| 1040 |
} |
| 1041 |
} |
| 1042 |
return apply_filters('mbt_get_book_series_books', $output, $post_id); |
| 1043 |
} |
| 1044 |
function mbt_the_book_series_books() { |
| 1045 |
global $post; |
| 1046 |
echo(wp_kses_post(mbt_get_book_series_books($post->ID))); |
| 1047 |
} |
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
// Kindle Instant Preview |
| 1052 |
function mbt_get_kindle_instant_preview($post_id) { |
| 1053 |
$show_instant_preview = get_post_meta($post_id, 'mbt_show_instant_preview', true); |
| 1054 |
if($show_instant_preview === "no") { return ''; } |
| 1055 |
|
| 1056 |
$output = ''; |
| 1057 |
$asin = get_post_meta($post_id, 'mbt_unique_id_asin', true); |
| 1058 |
if(!empty($asin)) { |
| 1059 |
$url = 'https://read.amazon.com/kp/card?asin='.$asin.'&preview=inline&linkCode=kpe&ref_=cm_sw_r_kb_dp_Ol2Ywb1Y4HHHK'; |
| 1060 |
$output = '<iframe class="mbt_kindle_instant_preview" src="'.$url.'" frameborder="0"></iframe>'; |
| 1061 |
} |
| 1062 |
return apply_filters('mbt_get_kindle_instant_preview', $output, $post_id); |
| 1063 |
} |
| 1064 |
function mbt_the_kindle_instant_preview() { |
| 1065 |
global $post; |
| 1066 |
echo(wp_kses_post(mbt_get_kindle_instant_preview($post->ID))); |
| 1067 |
} |
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
// Star Rating |
| 1072 |
function mbt_get_book_star_rating($post_id) { |
| 1073 |
$output = ''; |
| 1074 |
$star_rating = intval(get_post_meta($post_id, 'mbt_star_rating', true)); |
| 1075 |
if($star_rating > 0) { |
| 1076 |
$output .= '<span class="mbt-meta-item mbt-meta-star-rating"><span class="mbt-meta-title">'.__('Rating', 'mybooktable').':</span> <div class="mbt-star-rating">'; |
| 1077 |
for($i=0; $i < 5; $i++) { |
| 1078 |
$output .= '<span class="mbt-star '.($i < $star_rating ? 'mbt-star-filled' : '').'"></span>'; |
| 1079 |
} |
| 1080 |
$output .= '</div></span><br>'; |
| 1081 |
} |
| 1082 |
return apply_filters('mbt_get_book_star_rating', $output, $post_id); |
| 1083 |
} |
| 1084 |
function mbt_the_book_star_rating() { |
| 1085 |
global $post; |
| 1086 |
echo(wp_kses_post(mbt_get_book_star_rating($post->ID))); |
| 1087 |
} |
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
// Find Bookstore |
| 1092 |
function mbt_get_find_bookstore_form($post_id) { |
| 1093 |
$key = mbt_get_setting('google_api_key'); |
| 1094 |
if(empty($key)) { return ''; } |
| 1095 |
wp_enqueue_script('mbt-google-maps', 'https://maps.googleapis.com/maps/api/js?key='.$key.'&v=3.exp', array(), MBT_VERSION, true); |
| 1096 |
$output = ''; |
| 1097 |
$output .= '<div class="mbt-find-bookstore">'; |
| 1098 |
$output .= '<form class="mbt-find-bookstore-form" action="//maps.google.com/maps">'; |
| 1099 |
$output .= ' <input type="text" class="mbt-city" placeholder="'.__('City', 'mybooktable').'" name="city" size="20">'; |
| 1100 |
$output .= ' <input type="text" class="mbt-zip" placeholder="'.__('Zip', 'mybooktable').'" name="zip" size="5" maxlength="5">'; |
| 1101 |
$output .= ' <input type="submit" name="submit" value="'.__('Find Store', 'mybooktable').'">'; |
| 1102 |
$output .= '</form>'; |
| 1103 |
$output .= '<div style="clear:both"></div>'; |
| 1104 |
$output .= '</div>'; |
| 1105 |
return apply_filters('mbt_get_find_bookstore_form', $output, $post_id); |
| 1106 |
} |
| 1107 |
function mbt_the_find_bookstore_form() { |
| 1108 |
global $post; |
| 1109 |
echo(wp_kses_post(mbt_get_find_bookstore_form($post->ID))); |
| 1110 |
} |
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
// Reviews |
| 1115 |
function mbt_get_reviews($post_id) { |
| 1116 |
$output = ''; |
| 1117 |
$reviews_types = mbt_get_reviews_types(); |
| 1118 |
$current_reviews = mbt_get_setting('reviews_type'); |
| 1119 |
if(!empty($reviews_types[$current_reviews]['callback'])) { |
| 1120 |
$unique_id = get_post_meta($post_id, 'mbt_unique_id_asin', true).get_post_meta($post_id, 'mbt_unique_id_isbn', true); |
| 1121 |
$cache_id = 'mbt_'.$current_reviews.'_reviews_'.$post_id.'_'.$unique_id; |
| 1122 |
if(false === ($output = get_transient($cache_id))) { |
| 1123 |
$output = call_user_func_array($reviews_types[$current_reviews]['callback'], array()); |
| 1124 |
set_transient($cache_id, $output, HOUR_IN_SECONDS); |
| 1125 |
} |
| 1126 |
} |
| 1127 |
return apply_filters('mbt_get_reviews', $output, $post_id); |
| 1128 |
} |
| 1129 |
function mbt_the_reviews() { |
| 1130 |
global $post; |
| 1131 |
echo(wp_kses_post(mbt_get_reviews($post->ID))); |
| 1132 |
} |
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
// Endorsements |
| 1137 |
function mbt_get_book_endorsements($post_id) { |
| 1138 |
$endorsements = get_post_meta($post_id, 'mbt_endorsements', true); |
| 1139 |
$output = ''; |
| 1140 |
if(!empty($endorsements)) { |
| 1141 |
$output .= '<div class="mbt-book-endorsements">'; |
| 1142 |
foreach($endorsements as $endorsement) { |
| 1143 |
if(empty($endorsement['content'])) { continue; } |
| 1144 |
$name_url = $endorsement['name_url']; |
| 1145 |
if(!empty($name_url) and substr($name_url, 0, 4) !== 'http') { $name_url = 'https://'.$name_url; } |
| 1146 |
$output .= '<div class="mbt-endorsement">'; |
| 1147 |
$image = wp_get_attachment_image_src($endorsement['image_id'], 'mbt_endorsement_image'); |
| 1148 |
$srcset = function_exists('wp_get_attachment_image_srcset') ? wp_get_attachment_image_srcset($endorsement['image_id'], 'mbt_endorsement_image') : ''; |
| 1149 |
if(!empty($image)) { $output .= '<div class="mbt-endorsement-image"><img src="'.esc_url($image[0]).'"'.(empty($srcset) ? '' : ' srcset="'.esc_attr($srcset).'"').'></div>'; } |
| 1150 |
$output .= ' <div class="mbt-endorsement-content">'; |
| 1151 |
$output .= wp_kses_post($endorsement['content']); |
| 1152 |
$output .= empty($endorsement['name']) ? '' : '<div class="mbt-endorsement-name">– '.(empty($name_url) ? '' : '<a href="'.esc_url($name_url).'" target="_blank">').esc_html($endorsement['name']).(empty($name_url) ? '' : '</a>').'</div>'; |
| 1153 |
$output .= ' </div>'; |
| 1154 |
$output .= ' <div style="clear:both"></div>'; |
| 1155 |
$output .= '</div>'; |
| 1156 |
} |
| 1157 |
$output .= '<div style="clear:both"></div>'; |
| 1158 |
$output .= '</div>'; |
| 1159 |
} |
| 1160 |
return apply_filters('mbt_get_book_endorsements', $output, $post_id); |
| 1161 |
} |
| 1162 |
function mbt_the_book_endorsements() { |
| 1163 |
global $post; |
| 1164 |
echo(wp_kses_post(mbt_get_book_endorsements($post->ID))); |
| 1165 |
} |
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
// About Author |
| 1170 |
function mbt_get_book_about_author($post_id) { |
| 1171 |
$output = ''; |
| 1172 |
|
| 1173 |
$terms = get_the_terms($post_id, 'mbt_author'); |
| 1174 |
if(is_wp_error($terms) or empty($terms)) { return ''; } |
| 1175 |
|
| 1176 |
//sort by priority |
| 1177 |
$sortfunc = function($a, $b) { |
| 1178 |
$a = mbt_get_author_priority($a->term_id); |
| 1179 |
$b = mbt_get_author_priority($b->term_id); |
| 1180 |
return ($a > $b) ? -1 : (($a < $b) ? 1 : 0); |
| 1181 |
}; |
| 1182 |
usort($terms, $sortfunc); |
| 1183 |
|
| 1184 |
//select first author with description and highest priority |
| 1185 |
$author = reset($terms); |
| 1186 |
foreach($terms as $term) { |
| 1187 |
if(mbt_get_author_priority($term->term_id) < mbt_get_author_priority($author->term_id)) { break; } |
| 1188 |
if(!empty($term->description)) { $author = $term; break; } |
| 1189 |
} |
| 1190 |
if(empty($author->description)) { return ''; } |
| 1191 |
|
| 1192 |
$image = mbt_get_taxonomy_image('mbt_author', $author->term_id); |
| 1193 |
|
| 1194 |
$output .= '<div class="mbt-book-about-author">'; |
| 1195 |
if(!empty($image)) { |
| 1196 |
$output .= ' <div class="mbt-book-about-author-image"><img src="'.esc_url($image).'"></div>'; |
| 1197 |
$output .= ' <div class="mbt-book-about-author-right">'; |
| 1198 |
} |
| 1199 |
$output .= ' <div class="mbt-book-about-author-name">'.$author->name.'</div>'; |
| 1200 |
$output .= ' <div class="mbt-book-about-author-desc">'.wp_kses_post(wpautop($author->description)).'</div>'; |
| 1201 |
if(!empty($image)) { |
| 1202 |
$output .= ' </div>'; |
| 1203 |
$output .= ' <div style="clear:both"></div>'; |
| 1204 |
} |
| 1205 |
$output .= '</div>'; |
| 1206 |
|
| 1207 |
return apply_filters('mbt_get_book_about_author', $output, $post_id); |
| 1208 |
} |
| 1209 |
function mbt_the_book_about_author() { |
| 1210 |
global $post; |
| 1211 |
echo(wp_kses_post(mbt_get_book_about_author($post->ID))); |
| 1212 |
} |
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
// Book Teaser |
| 1217 |
function mbt_get_book_teaser($post_id) { |
| 1218 |
$output = ''; |
| 1219 |
$teaser = get_post_meta($post_id, 'mbt_book_teaser', true); |
| 1220 |
if($teaser) { |
| 1221 |
$output .= '<h2 class="mbt-book-teaser">'.esc_html($teaser).'</h2>'; |
| 1222 |
} |
| 1223 |
return apply_filters('mbt_get_book_teaser', $output, $post_id); |
| 1224 |
} |
| 1225 |
function mbt_the_book_teaser() { |
| 1226 |
global $post; |
| 1227 |
echo(wp_kses_post(mbt_get_book_teaser($post->ID))); |
| 1228 |
} |
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
// Call to Action Button |
| 1233 |
function mbt_get_book_cta_button($post_id, $button_text='') { |
| 1234 |
$output = ''; |
| 1235 |
$buybuttons = mbt_query_buybuttons($post_id); |
| 1236 |
if(!empty($buybuttons)) { |
| 1237 |
$text = apply_filters('mbt_book_cta_button_text', empty($button_text) ? __('Order Now!', 'mybooktable') : $button_text); |
| 1238 |
$output .= '<a href="#mbt-book-purchase-anchor" class="mbt-book-purchase-button mbt-primary-button">'.$text.'</a>'; |
| 1239 |
} |
| 1240 |
return apply_filters('mbt_get_book_cta_button', $output, $post_id, $button_text); |
| 1241 |
} |
| 1242 |
function mbt_the_book_cta_button($button_text='') { |
| 1243 |
global $post; |
| 1244 |
echo(wp_kses_post(mbt_get_book_cta_button($post->ID, $button_text))); |
| 1245 |
} |
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
// Book Club Resources |
| 1250 |
function mbt_get_book_bookclub_resources($post_id) { |
| 1251 |
global $wp_embed; |
| 1252 |
|
| 1253 |
$links = get_post_meta($post_id, 'mbt_bookclub_links', true); |
| 1254 |
$video = get_post_meta($post_id, 'mbt_bookclub_video', true); |
| 1255 |
$output = ''; |
| 1256 |
if(!empty($links) or !empty($video)) { |
| 1257 |
$output .= '<div class="mbt-book-bookclub-resources">'; |
| 1258 |
if(!empty($video)) { $output .= '<div class="mbt-book-bookclub-video">'.$wp_embed->shortcode(array('width'=>400, 'height'=>400), $video).'</div>'; } |
| 1259 |
$links_output = ''; |
| 1260 |
if(!empty($links) and is_array($links)) { |
| 1261 |
foreach($links as $link) { |
| 1262 |
if(empty($link['url'])) { continue; } |
| 1263 |
$links_output .= '<li><a target="_blank" href="'.esc_url($link['url']).'">'.(empty($link['text']) ? 'Download Resource' : esc_html($link['text'])).'</a></li>'; |
| 1264 |
} |
| 1265 |
} |
| 1266 |
if(!empty($links_output)) { $output .= '<ul class="mbt-book-bookclub-links">'.$links_output.'</ul>'; } |
| 1267 |
$output .= '</div>'; |
| 1268 |
} |
| 1269 |
return apply_filters('mbt_get_book_bookclub_resources', $output, $post_id); |
| 1270 |
} |
| 1271 |
function mbt_the_book_bookclub_resources() { |
| 1272 |
global $post; |
| 1273 |
echo(wp_kses_post(mbt_get_book_bookclub_resources($post->ID))); |
| 1274 |
} |
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
// Audio Book Resources |
| 1279 |
function mbt_get_book_audiobook_resources($post_id) { |
| 1280 |
global $wp_embed; |
| 1281 |
|
| 1282 |
$links = get_post_meta($post_id, 'mbt_audiobook_links', true); |
| 1283 |
$output = ''; |
| 1284 |
if(!empty($links) or !empty($video)) { |
| 1285 |
$output .= '<div class="mbt-book-audiobook-resources">'; |
| 1286 |
$links_output = ''; |
| 1287 |
if(!empty($links) and is_array($links)) { |
| 1288 |
foreach($links as $link) { |
| 1289 |
if(empty($link['url'])) { continue; } |
| 1290 |
$links_output .= '<li><a target="_blank" href="'.esc_url($link['url']).'">'.(empty($link['text']) ? 'Download Resource' : esc_html($link['text'])).'</a></li>'; |
| 1291 |
} |
| 1292 |
} |
| 1293 |
if(!empty($links_output)) { $output .= '<ul class="mbt-book-audiobook-links">'.$links_output.'</ul>'; } |
| 1294 |
$output .= '</div>'; |
| 1295 |
} |
| 1296 |
return apply_filters('mbt_get_book_audiobook_resources', $output, $post_id); |
| 1297 |
} |
| 1298 |
function mbt_the_book_audiobook_resources() { |
| 1299 |
global $post; |
| 1300 |
echo(wp_kses_post(mbt_get_book_audiobook_resources($post->ID))); |
| 1301 |
} |
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
// Book Overview Image |
| 1306 |
function mbt_get_book_overview_image($post_id) { |
| 1307 |
$output = ''; |
| 1308 |
$image_id = get_post_meta($post_id, 'mbt_overview_image', true); |
| 1309 |
if(empty($image_id)) { $image_id = get_post_meta($post_id, 'mbt_book_image_id', true); } |
| 1310 |
$image = wp_get_attachment_image_src($image_id, 'mbt_endorsement_image'); |
| 1311 |
$srcset = function_exists('wp_get_attachment_image_srcset') ? wp_get_attachment_image_srcset($image_id, 'mbt_endorsement_image') : ''; |
| 1312 |
if(!empty($image)) { $output .= '<div class="mbt-book-overview-image"><img src="'.esc_url($image[0]).'"'.(empty($srcset) ? '' : ' srcset="'.esc_attr($srcset).'"').'></div>'; } |
| 1313 |
return apply_filters('mbt_get_book_overview_image', $output, $post_id); |
| 1314 |
} |
| 1315 |
function mbt_the_book_overview_image() { |
| 1316 |
global $post; |
| 1317 |
echo(wp_kses_post(mbt_get_book_overview_image($post->ID))); |
| 1318 |
} |
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
// Book Preview |
| 1323 |
function mbt_get_book_preview($post_id) { |
| 1324 |
$output = ''; |
| 1325 |
$output .= mbt_get_kindle_instant_preview($post_id); |
| 1326 |
$output .= mbt_get_book_sample($post_id); |
| 1327 |
return apply_filters('mbt_get_book_preview', $output, $post_id); |
| 1328 |
} |
| 1329 |
function mbt_the_book_preview() { |
| 1330 |
global $post; |
| 1331 |
echo(wp_kses_post(mbt_get_book_preview($post->ID))); |
| 1332 |
} |
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
/*---------------------------------------------------------*/ |
| 1337 |
/* Social Media Functions */ |
| 1338 |
/*---------------------------------------------------------*/ |
| 1339 |
// add the facebook script |
| 1340 |
/* |
| 1341 |
function add_facebook_script_after_body(){ |
| 1342 |
if(mbt_get_setting('enable_socialmedia_book_excerpt')) { |
| 1343 |
echo '<div id="fb-root"></div><script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v9.0" nonce="dY2mHxBB"></script>'; |
| 1344 |
} |
| 1345 |
} |
| 1346 |
*/ |
| 1347 |
//add_action('wp_footer', 'add_facebook_script_after_body'); |
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
//wp_enqueue_script('jquery','/wp-includes/js/jquery/jquery.js','','',true); |
| 1352 |
|
| 1353 |
// Social Media Badges |
| 1354 |
function mbt_get_book_socialmedia_badges($post_id) { |
| 1355 |
$url = urlencode(get_permalink($post_id)); |
| 1356 |
$output = ''; |
| 1357 |
|
| 1358 |
//$output .= '<div class="mbt-book-socialmedia-badges">'; |
| 1359 |
//$output .= '<iframe src="https://www.facebook.com/plugins/like.php?href='.$url.'&layout=box_count" class="mbt-fblike" style="width: 51px; height: 61px; margin: 0px; border: none; overflow: hidden;" scrolling="no" frameborder="0" allowtransparency="true"></iframe>'; |
| 1360 |
$output = '<div style="float: right;" class="fb-like" data-href="'.get_permalink().'" data-width="" data-layout="box_count" data-action="like" data-size="large" data-share="true"></div>'; |
| 1361 |
//$output .= '</div>'; |
| 1362 |
|
| 1363 |
return apply_filters('mbt_get_book_socialmedia_badges', $output, $post_id); |
| 1364 |
} |
| 1365 |
|
| 1366 |
function mbt_the_book_socialmedia_badges() { |
| 1367 |
global $post; |
| 1368 |
echo(wp_kses_post(mbt_get_book_socialmedia_badges($post->ID))); |
| 1369 |
} |
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
// Social Media Bar |
| 1374 |
function mbt_get_book_socialmedia_bar($post_id) { |
| 1375 |
$url = urlencode(get_permalink($post_id)); |
| 1376 |
$output = ''; |
| 1377 |
|
| 1378 |
$output .= '<div class="mbt-book-socialmedia-bar">'; |
| 1379 |
if(function_exists('st_makeEntries')) { |
| 1380 |
$output .= st_makeEntries(); |
| 1381 |
} else { |
| 1382 |
$output .= '<iframe src="https://www.facebook.com/plugins/like.php?href='.$url.'&layout=button_count" class="mbt-fblike" style="width: 75px; height: 20px; margin: 0px; border: none; overflow: hidden;" scrolling="no" frameborder="0" allowtransparency="true"></iframe>'; |
| 1383 |
//$output = '<div class="fb-like" data-href="'.get_permalink().'" data-width="" data-layout="box_count" data-action="like" data-size="large" data-share="true"></div>'; |
| 1384 |
$output .= '<iframe src="https://platform.twitter.com/widgets/tweet_button.html?url='.$url.'&count=horizontal&size=m" class="mbt-twittershare" style="height: 20px; width: 100px; margin: 0px; border: none; overflow: hidden;" allowtransparency="true" frameborder="0" scrolling="no"></iframe>'; |
| 1385 |
} |
| 1386 |
$output .= '</div>'; |
| 1387 |
|
| 1388 |
return apply_filters('mbt_get_book_socialmedia_bar', $output, $post_id); |
| 1389 |
} |
| 1390 |
function mbt_the_book_socialmedia_bar() { |
| 1391 |
global $post; |
| 1392 |
echo(wp_kses_post(mbt_get_book_socialmedia_bar($post->ID))); |
| 1393 |
} |
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
// Social Media Buttons |
| 1398 |
function mbt_get_book_socialmedia_buttons($post_id) { |
| 1399 |
$encoded_permalink = urlencode(get_permalink($post_id)); |
| 1400 |
$output = ''; |
| 1401 |
|
| 1402 |
$output .= '<div class="mbt-book-socialmedia-buttons">'; |
| 1403 |
$output .= ' <a href="https://www.facebook.com/sharer/sharer.php?u='.$encoded_permalink.'" target="_blank" class="mbt-book-socialmedia-button mbt-book-socialmedia-facebook">Facebook</a>'; |
| 1404 |
$output .= ' <a href="https://twitter.com/intent/tweet?text='.urlencode(__('Check out this book!', 'mybooktable')).'&url='.$encoded_permalink.'&original_referer='.$encoded_permalink.'" target="_blank" class="mbt-book-socialmedia-button mbt-book-socialmedia-twitter">Twitter</a>'; |
| 1405 |
$output .= ' <a href="https://plus.google.com/share?url='.$encoded_permalink.'" target="_blank" class="mbt-book-socialmedia-button mbt-book-socialmedia-googleplus">Google+</a>'; |
| 1406 |
$output .= '</div>'; |
| 1407 |
|
| 1408 |
return apply_filters('mbt_get_book_socialmedia_buttons', $output, $post_id); |
| 1409 |
} |
| 1410 |
function mbt_the_book_socialmedia_buttons() { |
| 1411 |
global $post; |
| 1412 |
echo(wp_kses_post(mbt_get_book_socialmedia_buttons($post->ID))); |
| 1413 |
} |
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
/*---------------------------------------------------------*/ |
| 1418 |
/* Standard Book Sections */ |
| 1419 |
/*---------------------------------------------------------*/ |
| 1420 |
|
| 1421 |
function mbt_do_standard_book_video_sample_section() { |
| 1422 |
global $post; |
| 1423 |
echo(wp_kses_post(mbt_render_book_section($post->ID, 'video-sample', mbt_get_book_video_sample($post->ID)))); |
| 1424 |
} |
| 1425 |
|
| 1426 |
function mbt_do_standard_book_endorsements_section() { |
| 1427 |
global $post; |
| 1428 |
echo(wp_kses_post(mbt_render_book_section($post->ID, 'endorsements', mbt_get_book_endorsements($post->ID)), __('Endorsements', 'mybooktable'))); |
| 1429 |
} |
| 1430 |
|
| 1431 |
function mbt_do_standard_book_about_author_section() { |
| 1432 |
global $post; |
| 1433 |
echo(wp_kses_post(mbt_render_book_section($post->ID, 'about-author', mbt_get_book_about_author($post->ID)), __('About the Author', 'mybooktable'))); |
| 1434 |
} |
| 1435 |
|
| 1436 |
function mbt_do_standard_book_bookclub_section() { |
| 1437 |
global $post; |
| 1438 |
$title = get_post_meta($post->ID, 'mbt_bookclub_title', true); |
| 1439 |
$title = empty($title) ? __('Book Club Resources', 'mybooktable') : $title; |
| 1440 |
echo(wp_kses_post(mbt_render_book_section($post->ID, 'bookclub', mbt_get_book_bookclub_resources($post->ID), $title))); |
| 1441 |
} |
| 1442 |
|
| 1443 |
function mbt_do_standard_book_audiobook_section() { |
| 1444 |
global $post; |
| 1445 |
$title = get_post_meta($post->ID, 'mbt_audiobook_title', true); |
| 1446 |
$title = empty($title) ? __('Audio Book Resources', 'mybooktable') : $title; |
| 1447 |
echo(wp_kses_post(mbt_render_book_section($post->ID, 'audiobook', mbt_get_book_audiobook_resources($post->ID), $title))); |
| 1448 |
} |
| 1449 |
|
| 1450 |
function mbt_do_standard_book_purchase_section() { |
| 1451 |
global $post; |
| 1452 |
echo(wp_kses_post(mbt_render_book_section($post->ID, 'purchase', mbt_get_buybuttons($post->ID, false, false), __('Order Now', 'mybooktable')))); |
| 1453 |
} |
| 1454 |
|
| 1455 |
function mbt_do_standard_book_socialmedia_section() { |
| 1456 |
global $post; |
| 1457 |
echo(wp_kses_post(mbt_render_book_section($post->ID, 'socialmedia', mbt_get_book_socialmedia_buttons($post->ID), __('Share', 'mybooktable')))); |
| 1458 |
} |
| 1459 |
|
| 1460 |
function mbt_do_standard_book_series_section() { |
| 1461 |
global $post; |
| 1462 |
$series = mbt_get_book_series($post->ID); |
| 1463 |
/* translators: %1$s: the product name, %2$s: series name */ |
| 1464 |
$title = empty($series) ? '' : sprintf(__('Other %1$s in the "%2$s"', 'mybooktable'), mbt_get_product_name(), $series->name); |
| 1465 |
echo(wp_kses_post(mbt_render_book_section($post->ID, 'series', mbt_get_book_series_books($post->ID), $title))); |
| 1466 |
} |
| 1467 |
|
| 1468 |
function mbt_do_standard_book_preview_section() { |
| 1469 |
global $post; |
| 1470 |
echo(wp_kses_post(mbt_render_book_section($post->ID, 'preview', mbt_get_book_preview($post->ID), __('Preview', 'mybooktable')))); |
| 1471 |
} |
| 1472 |
|
| 1473 |
function mbt_do_standard_kindle_instant_preview_section() { |
| 1474 |
global $post; |
| 1475 |
echo(wp_kses_post(mbt_render_book_section($post->ID, 'kindle-instant-preview', mbt_get_kindle_instant_preview($post->ID), __('Look Inside', 'mybooktable')))); |
| 1476 |
} |
| 1477 |
|
| 1478 |
function mbt_do_standard_find_bookstore_section() { |
| 1479 |
global $post; |
| 1480 |
echo(wp_kses_post(mbt_render_book_section($post->ID, 'find-bookstore', mbt_get_find_bookstore_form($post->ID), __('Find A Local Bookstore', 'mybooktable')))); |
| 1481 |
} |
| 1482 |
|
| 1483 |
function mbt_do_standard_reviews_section() { |
| 1484 |
global $post; |
| 1485 |
echo(wp_kses_post(mbt_render_book_section($post->ID, 'reviews', mbt_get_reviews($post->ID), __('Reviews', 'mybooktable')))); |
| 1486 |
} |