PluginProbe
MyBookTable Bookstore by Stormhill Media / trunk
MyBookTable Bookstore by Stormhill Media vtrunk
3.6.5 trunk
mybooktable / includes / extras / universalbuybutton.php

universalbuybutton.php in MyBookTable Bookstore by Stormhill Media trunk, at includes/extras/universalbuybutton.php

71 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
4 /*---------------------------------------------------------*/
5 /* Universal Buy Button */
6 /*---------------------------------------------------------*/
7
8 function mbt_universal_buybutton_init() {
9 add_filter('mbt_stores', 'mbt_add_universal_buybutton');
10 add_action('wp_head', 'mbt_add_universal_buybutton_css');
11 add_filter('mbt_buybutton_editor', 'mbt_universal_buybutton_editor', 10, 4);
12 add_filter('mbt_format_buybutton', 'mbt_universal_buybutton_button', 10, 3);
13 }
14 add_action('mbt_init', 'mbt_universal_buybutton_init');
15
16 function mbt_add_universal_buybutton($stores) {
17 $stores['universal'] = array('name' => 'Universal Buy Button');
18 return $stores;
19 }
20
21 function mbt_universal_buybutton_editor($output, $data, $id, $store) {
22 if($data['store'] == 'universal') {
23 $output = '<input name="'.$id.'[store]" type="hidden" value="'.$data['store'].'">';
24 $output .= __('Button Text:','mybooktable').' <input type="text" name="'.$id.'[text]" value="'.(empty($data['text']) ? '' : $data['text']).'"><br>';
25 $output .= __('Button URL:','mybooktable').' <input type="text" name="'.$id.'[url]" value="'.(empty($data['url']) ? '' : htmlspecialchars($data['url'])).'"><br>';
26 $editor_desc = (empty($store['editor_desc']) ? __('Paste in the product URL for this item.', 'mybooktable').' <a href="'.admin_url('admin.php?page=mbt_help&mbt_video_tutorial=buy_buttons').'" target="_blank">'.__('Learn more about adding Buy Button links.', 'mybooktable').'</a>' : $store['editor_desc']);
27 $output .= '<p>'.$editor_desc.'</p>';
28 }
29 return $output;
30 }
31
32 function mbt_universal_buybutton_button($output, $data, $store) {
33 if($data['store'] == 'universal') {
34 if(empty($data['url'])) {
35 $output = '';
36 } else {
37 $buybutton_url = wp_parse_url($data['url']);
38 $site_url = wp_parse_url(get_site_url());
39 $internal = (isset($buybutton_url['host']) and isset($site_url['host']) and ($buybutton_url['host'] == $site_url['host']));
40
41 if(!empty($data['display']) and $data['display'] == 'text') {
42 $output = '<li><a class="mbt-universal-text-buybutton" href="'.htmlspecialchars($data['url']).'" '.($internal ? '' : 'target="_blank" ').'rel="nofollow">'.$data['text'].'</a></li>';
43 } else {
44 $output = '<div class="mbt-book-buybutton"><a class="mbt-universal-buybutton" href="'.htmlspecialchars($data['url']).'" '.($internal ? '' : 'target="_blank" ').' rel="nofollow">'.$data['text'].'</a></div>';
45 }
46 }
47 }
48 return $output;
49 }
50
51 function mbt_add_universal_buybutton_css() {
52 $book_button_size = mbt_get_setting('book_button_size');
53 $listing_button_size = mbt_get_setting('listing_button_size');
54 $widget_button_size = mbt_get_setting('widget_button_size');
55 echo('<style type="text/css">');
56 echo('.mbt-book-buybuttons .mbt-universal-buybutton { margin: 0; display: inline-block; box-sizing: border-box; }');
57 //Book Button Size
58 if($book_button_size == 'small') { echo('.mbt-book .mbt-book-buybuttons .mbt-universal-buybutton { font-size: 13px; line-height: 13px; padding: 5px 8px; width: 144px; min-height: 25px; }'); }
59 else if($book_button_size == 'medium') { echo('.mbt-book .mbt-book-buybuttons .mbt-universal-buybutton { font-size: 15px; line-height: 16px; padding: 6px 12px; width: 172px; min-height: 30px; }'); }
60 else { echo('.mbt-book .mbt-book-buybuttons .mbt-universal-buybutton { font-size: 18px; line-height: 20px; padding: 6px 15px; width: 201px; min-height: 35px; }'); }
61 //Listing Button Size
62 if($listing_button_size == 'small') { echo('.mbt-book-archive .mbt-book .mbt-book-buybuttons .mbt-universal-buybutton { font-size: 13px; line-height: 13px; padding: 5px 8px; width: 144px; min-height: 25px; }'); }
63 else if($listing_button_size == 'medium') { echo('.mbt-book-archive .mbt-book .mbt-book-buybuttons .mbt-universal-buybutton { font-size: 15px; line-height: 16px; padding: 6px 12px; width: 172px; min-height: 30px; }'); }
64 else { echo('.mbt-book-archive .mbt-book .mbt-book-buybuttons .mbt-universal-buybutton { font-size: 18px; line-height: 20px; padding: 6px 15px; width: 201px; min-height: 35px; }'); }
65 //Widget Button Size
66 if($widget_button_size == 'small') { echo('.mbt-featured-book-widget .mbt-book-buybuttons .mbt-universal-buybutton { font-size: 13px; line-height: 13px; padding: 5px 8px; width: 144px; min-height: 25px; }'); }
67 else if($widget_button_size == 'medium') { echo('.mbt-featured-book-widget .mbt-book-buybuttons .mbt-universal-buybutton { font-size: 15px; line-height: 16px; padding: 6px 12px; width: 172px; min-height: 30px; }'); }
68 else { echo('.mbt-featured-book-widget .mbt-book-buybuttons .mbt-universal-buybutton { font-size: 18px; line-height: 20px; padding: 6px 15px; width: 201px; min-height: 35px; }'); }
69 echo('</style>');
70 }
71