| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Bloglovin Button |
| 4 |
Plugin URI: https://wordpress.org/plugins/bloglovin-button/ |
| 5 |
Version: 1.3.9 |
| 6 |
Author: pipdig |
| 7 |
Description: Easily add the Bloglovin Button to your WordPress blog. |
| 8 |
Text Domain: bloglovin-button |
| 9 |
Author URI: https://www.pipdig.co/ |
| 10 |
License: GPLv2 or later |
| 11 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html |
| 12 |
|
| 13 |
This program is free software; you can redistribute it and/or modify |
| 14 |
it under the terms of the GNU General Public License as published by |
| 15 |
the Free Software Foundation; either version 2 of the License, or |
| 16 |
(at your option) any later version. |
| 17 |
|
| 18 |
This program is distributed in the hope that it will be useful, |
| 19 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
GNU General Public License for more details. |
| 22 |
*/ |
| 23 |
|
| 24 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 25 |
|
| 26 |
class bloglovin_button_widget extends WP_Widget { |
| 27 |
|
| 28 |
public function __construct() { |
| 29 |
$widget_ops = array('classname' => 'bloglovin_button_widget', 'description' => __("Display the official Bloglovin' button.", 'bloglovin-button') ); |
| 30 |
parent::__construct('bloglovin_button_widget', __("Bloglovin' Button", 'bloglovin-button'), $widget_ops); |
| 31 |
} |
| 32 |
|
| 33 |
function widget($args, $instance) { |
| 34 |
// PART 1: Extracting the arguments + getting the values |
| 35 |
extract($args, EXTR_SKIP); |
| 36 |
$title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']); |
| 37 |
$links = get_option('pipdig_links'); |
| 38 |
if (isset($instance['bloglovin_url'])) { |
| 39 |
$bloglovin_url = esc_url($instance['bloglovin_url']); |
| 40 |
} elseif (isset($links['bloglovin'])) { // pull from p3 if available |
| 41 |
$bloglovin_url = esc_url($links['bloglovin']); |
| 42 |
} else { |
| 43 |
$bloglovin_url = ''; |
| 44 |
} |
| 45 |
$style_select = empty($instance['style_select']) ? '' : $instance['style_select']; |
| 46 |
|
| 47 |
// Before widget code, if any |
| 48 |
echo (isset($before_widget)?$before_widget:''); |
| 49 |
|
| 50 |
// PART 2: The title and the text output |
| 51 |
if (!empty($title)) { |
| 52 |
echo $before_title . $title . $after_title; |
| 53 |
} |
| 54 |
|
| 55 |
switch ($style_select) { |
| 56 |
case '1': |
| 57 |
$counter = 'true'; |
| 58 |
$button = 'button'; |
| 59 |
break; |
| 60 |
case '2': |
| 61 |
$counter = 'false'; |
| 62 |
$button = 'button'; |
| 63 |
break; |
| 64 |
case '3': |
| 65 |
$counter = 'false'; |
| 66 |
$button = ''; |
| 67 |
break; |
| 68 |
} |
| 69 |
|
| 70 |
if (!empty($bloglovin_url)) { |
| 71 |
if ($url = parse_url($bloglovin_url)) { |
| 72 |
$bloglovin_url = 'https://'.$url['host'].$url['path']; |
| 73 |
$bloglovin_url = rtrim($bloglovin_url,"/"); |
| 74 |
} |
| 75 |
?> |
| 76 |
<a data-blsdk-counter="<?php echo $counter; ?>" data-blsdk-type="<?php echo $button; ?>" target="_blank" href="<?php echo $bloglovin_url; ?>" class="blsdk-follow">Follow</a> |
| 77 |
<script defer>(function(d, s, id) {var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) return;js = d.createElement(s);js.id = id;js.src = "https://www.bloglovin.com/widget/js/loader.js?v=1";fjs.parentNode.insertBefore(js, fjs);}(document, "script", "bloglovin-sdk"))</script> |
| 78 |
<?php |
| 79 |
} else { |
| 80 |
_e("Setup not complete. Please add your Bloglovin' URL to the Bloglovin' Button in the dashboard.", 'bloglovin-button'); |
| 81 |
} |
| 82 |
// After widget code, if any |
| 83 |
echo (isset($after_widget)?$after_widget:''); |
| 84 |
} |
| 85 |
|
| 86 |
public function form( $instance ) { |
| 87 |
|
| 88 |
// PART 1: Extract the data from the instance variable |
| 89 |
$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) ); |
| 90 |
$title = $instance['title']; |
| 91 |
if (isset($instance['bloglovin_url'])) { |
| 92 |
$bloglovin_url = esc_url($instance['bloglovin_url']); |
| 93 |
} |
| 94 |
$links = get_option('pipdig_links'); |
| 95 |
if (isset($instance['bloglovin_url'])) { |
| 96 |
$bloglovin_url = esc_url($instance['bloglovin_url']); |
| 97 |
} elseif (isset($links['bloglovin'])) { // pull from p3 if available |
| 98 |
$bloglovin_url = esc_url($links['bloglovin']); |
| 99 |
} else { |
| 100 |
$bloglovin_url = ''; |
| 101 |
} |
| 102 |
$style_select = ( isset( $instance['style_select'] ) && is_numeric( $instance['style_select'] ) ) ? (int) $instance['style_select'] : 1; |
| 103 |
|
| 104 |
|
| 105 |
// PART 2-3: Display the fields |
| 106 |
?> |
| 107 |
<p> |
| 108 |
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Widget Title:', 'bloglovin-button'); ?></label> |
| 109 |
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /> |
| 110 |
</p> |
| 111 |
|
| 112 |
<p> |
| 113 |
<label for="<?php echo $this->get_field_id('bloglovin_url'); ?>"><?php _e("Bloglovin' URL:", 'bloglovin-button'); ?></label> |
| 114 |
<input class="widefat" id="<?php echo $this->get_field_id('bloglovin_url'); ?>" name="<?php echo $this->get_field_name('bloglovin_url'); ?>" type="url" value="<?php echo esc_url($bloglovin_url); ?>" required /> |
| 115 |
</p> |
| 116 |
|
| 117 |
<p style="font-size: 90%"><?php _e("You should use your full Bloglovin' URL. For example:", 'bloglovin-button'); ?><br /><em>https://www.bloglovin.com/blogs/inthefrow-4177899</em></p> |
| 118 |
|
| 119 |
<p> |
| 120 |
<legend><h4><?php _e('Button style:', 'bloglovin-button'); ?></h4></legend> |
| 121 |
|
| 122 |
<input type="radio" id="<?php echo ($this->get_field_id( 'style_select' ) . '-1') ?>" name="<?php echo ($this->get_field_name( 'style_select' )) ?>" value="1" <?php checked( $style_select == 1, true) ?>> |
| 123 |
<label for="<?php echo ($this->get_field_id( 'style_select' ) . '-1' ) ?>"><img src="<?php echo plugins_url( 'img/button_with_count.png', __FILE__ ) ?>" style="position:relative;top:5px;" /></label> |
| 124 |
<br /><br /> |
| 125 |
<input type="radio" id="<?php echo ($this->get_field_id( 'style_select' ) . '-2') ?>" name="<?php echo ($this->get_field_name( 'style_select' )) ?>" value="2" <?php checked( $style_select == 2, true) ?>> |
| 126 |
<label for="<?php echo ($this->get_field_id( 'style_select' ) . '-2' ) ?>"><img src="<?php echo plugins_url( 'img/button_no_count.png', __FILE__ ) ?>" style="position:relative;top:5px;" /></label> |
| 127 |
<br /><br /> |
| 128 |
<input type="radio" id="<?php echo ($this->get_field_id( 'style_select' ) . '-3') ?>" name="<?php echo ($this->get_field_name( 'style_select' )) ?>" value="3" <?php checked( $style_select == 3, true) ?>> |
| 129 |
<label for="<?php echo ($this->get_field_id( 'style_select' ) . '-3' ) ?>"><img src="<?php echo plugins_url( 'img/bloglovin-button-full.png', __FILE__ ) ?>" style="position:relative;top:5px;" /></label> |
| 130 |
</p> |
| 131 |
|
| 132 |
<p><?php _e("You can also add your Bloglovin' button to any post/page by using the shortcode [bloglovin_button]", 'bloglovin-button'); ?></p> |
| 133 |
<?php |
| 134 |
|
| 135 |
} |
| 136 |
|
| 137 |
function update($new_instance, $old_instance) { |
| 138 |
if (!is_customize_preview()) { |
| 139 |
update_option('pipdig_bloglovin_btn_url', $new_instance['bloglovin_url']); |
| 140 |
} |
| 141 |
$instance = $old_instance; |
| 142 |
$instance['title'] = sanitize_text_field($new_instance['title']); |
| 143 |
$instance['bloglovin_url'] = esc_url($new_instance['bloglovin_url']); |
| 144 |
$instance['style_select'] = ( isset( $new_instance['style_select'] ) && $new_instance['style_select'] > 0 && $new_instance['style_select'] < 4 ) ? (int) $new_instance['style_select'] : 0; // 4 is total radio +1 |
| 145 |
|
| 146 |
return $instance; |
| 147 |
} |
| 148 |
|
| 149 |
} |
| 150 |
|
| 151 |
function bloglovin_button_register_widgets() { |
| 152 |
register_widget('bloglovin_button_widget'); |
| 153 |
} |
| 154 |
add_action('widgets_init', 'bloglovin_button_register_widgets'); |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
function bloglovin_button_shortcode( $atts ) { |
| 159 |
extract( shortcode_atts( |
| 160 |
array( |
| 161 |
'email' => '', |
| 162 |
), $atts ) |
| 163 |
); |
| 164 |
|
| 165 |
if (get_option('pipdig_bloglovin_btn_url')) { |
| 166 |
$bloglovin_url = get_option('pipdig_bloglovin_btn_url'); |
| 167 |
} else { |
| 168 |
$links = get_option('pipdig_links'); |
| 169 |
if (isset($links['bloglovin'])) { // pull from p3 if available |
| 170 |
$bloglovin_url = $links['bloglovin']; |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
$output = ''; |
| 175 |
|
| 176 |
if (empty($bloglovin_url)) { |
| 177 |
return $output; |
| 178 |
} |
| 179 |
|
| 180 |
if ($email == 'true') { |
| 181 |
$output = '<div style="text-align:center;max-width:320px;margin:0 auto"><a title="'.__('Follow on Bloglovin', 'bloglovin-button').'" class="blsdk-follow" href="'.esc_url($bloglovin_url).'" target="_blank" rel="nofollow" data-blsdk-type="" data-blsdk-counter="false">'.__('Follow on Bloglovin', 'bloglovin-button').'</a><scr'.'ipt defer>(function(d, s, id) {var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) return;js = d.createElement(s);js.id = id;js.src = "https://www.bloglovin.com/widget/js/loader.js?v=1";fjs.parentNode.insertBefore(js, fjs);}(document, "script", "bloglovin-sdk"))</scr'.'ipt>'; |
| 182 |
} else { |
| 183 |
$output = ' |
| 184 |
<a title="'.esc_attr(__('Follow on Bloglovin', 'bloglovin-button')).'" target="_blank" class="bl_button_shortcode nopin" rel="nofollow" href="'.esc_url($bloglovin_url).'"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAARQAAAAqCAMAAABFqVQiAAAA7VBMVEUAAAD///8FBQVeXl4aGhr19fX4+PgP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1SuO9lsJupCACjOp8+whpa3YHG0iG+5S1wzmukmzHS9CHqHYdy2j7YcMDd2U374GAqUUknCkVylebc4xSOAtTpDKcyRI55ZbBE2v6Ifycs6jD2QDQRyw8UvoFQ3yBTOnEnVWUJdZ02EihHuQr90hcI06cXSBuWzYT614Xc0k45L8LayG/0QxQmhKUxjYQvewiqB4h68lesmQynDlQE2p37Cx4GddOXcodAb2ddDoQHZuAwhGIWytbQ/CfAG8Epbq+A3xkaYz6ZL1K4WwJdCyftvw/zemJrOgcWHO5Ekql8kQmDgzK+hiKPQP4BSOykKz/MKPx6wEFRRKGs/T8SHTKXHwlRw9JG7piBI+I77brzgCyF+QlPqwRDEdRRKP6Dr8lNTYTd7dD3ieI8K2bjPYmchATjLH0CBIOnLoYTU9Tqfz68HKTxpnkKJbfNY+icffdpg5+vobLZrwWJDOAFyEsgT2izpOcZxy0WTQlkO2ljVAFwJDjDYWn83m70NipCZEJugV1N633SHAtJMfT0U+9MbPX1MElTAqmGuEAITk101aRwzJV94a0WSKu9lCsWQBUQz9QXpjqpK1c1P7XPS+lD6EApEK18J5fYqkPDT50iTDBTsC1RLqTQAJoSK/a0yM+TIc6RFJiK+Xx6sxa2C/cEFmB05RyhHCxQxLcGD1xdB6duQTKIKrrVFfgeeeMRLylR44i0KC4myUZk6Z0mxLbJ+Eslt5y1jFK52r9bBHUnwTXyxcRE6Go8cQYNhDwzYNMNP/ItDbHjMEqlkdU3NiKWmIOr2UB3qZZWcvR9fg341rMr0aPFYpKt3wQW6tHXAPoMS1lSnWvTBhrFOVN0w6rIoP/T9CZTGer0enPn7fwjv/0u+Q3EQ7v5TjFsRmbvcf8v0h0ji9x8C2mXIsM07FavIDwzLxu8/LjYJP3xgfwLXc++fN+nW/gAAAABJRU5ErkJggg==" style="width: 120px; height: auto" class="nopin" data-pin-nopin="true" alt="'.esc_attr(__('Follow on Bloglovin', 'bloglovin-button')).'" /></a> |
| 185 |
'; |
| 186 |
} |
| 187 |
|
| 188 |
return $output; |
| 189 |
} |
| 190 |
add_shortcode( 'bloglovin_button', 'bloglovin_button_shortcode' ); |