| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Bandsintown Events |
| 4 |
Plugin URI: https://wordpress.org/plugins/bandsintown/ |
| 5 |
Description: Bandsintown's Events plugin makes it easy for artists to showcase their upcoming events anywhere on their WordPress-powered blog or website. Easily display an automatically updated list of your events to your fans using the widget, shortcode or template tag. |
| 6 |
Author: Bandsintown.com |
| 7 |
Author URI: https://www.bandsintown.com |
| 8 |
License: GPL v2 or later |
| 9 |
License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 10 |
Version: 1.4.2 |
| 11 |
*/ |
| 12 |
|
| 13 |
// Prevent direct access |
| 14 |
if (!defined('ABSPATH')) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
// Include helper functions |
| 19 |
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'common.php'; |
| 20 |
|
| 21 |
|
| 22 |
// Bandsintown Events Plugin |
| 23 |
class Bandsintown_JS_Plugin |
| 24 |
{ |
| 25 |
protected $options; |
| 26 |
function __construct() |
| 27 |
{ |
| 28 |
if (is_admin()) { |
| 29 |
// disable unnecessary settings sections in admin for now |
| 30 |
add_action('admin_menu', array($this, 'admin_menu')); |
| 31 |
add_action('admin_init', array($this, 'plugin_admin_init')); |
| 32 |
} else { |
| 33 |
add_action('wp_enqueue_scripts', array($this, 'bandsintown_tour_dates')); |
| 34 |
} |
| 35 |
|
| 36 |
add_shortcode('bandsintown_events', array($this, 'shortcode')); |
| 37 |
add_shortcode('bandsintown_widget', array($this, 'shortcode_widget')); |
| 38 |
add_action('widgets_init', array($this, 'bandsintown_widget_init')); |
| 39 |
|
| 40 |
$this->options = get_option('bitp_options', []); |
| 41 |
} |
| 42 |
|
| 43 |
function bandsintown_widget_init() |
| 44 |
{ |
| 45 |
return register_widget('Bandsintown_JS_Widget'); |
| 46 |
} |
| 47 |
|
| 48 |
function bandsintown_tour_dates() |
| 49 |
{ |
| 50 |
//wp_enqueue_script('bit-tour-dates', 'https://widget.bandsintown.com/main.min.js'); |
| 51 |
//wp_enqueue_script('bit-tour-dates', 'https://widgetv3.bandsintown.com/main.min.js'); |
| 52 |
} |
| 53 |
|
| 54 |
// Admin menu management. |
| 55 |
function admin_menu() |
| 56 |
{ |
| 57 |
add_options_page( |
| 58 |
'Bandsintown Events', |
| 59 |
'Bandsintown Events', |
| 60 |
'manage_options', |
| 61 |
'bandsintown-settings', |
| 62 |
array($this, 'settings') |
| 63 |
); |
| 64 |
} |
| 65 |
|
| 66 |
// Manage plugin settings |
| 67 |
function settings() |
| 68 |
{ |
| 69 |
?> |
| 70 |
<div> |
| 71 |
<div class="wrap" id="bandsintown_wrap"> |
| 72 |
<h2>Bandsintown Events</h2> |
| 73 |
<form action="options.php" method="post"> |
| 74 |
<?php |
| 75 |
settings_fields('plugin_options'); |
| 76 |
do_settings_sections('bitp'); |
| 77 |
?> |
| 78 |
<input name="Submit" type="submit" class="button-primary" tabindex="1" value="<?php esc_attr_e('Save Settings'); ?>" /> |
| 79 |
</form> |
| 80 |
</div> |
| 81 |
</div> |
| 82 |
<?php |
| 83 |
} |
| 84 |
|
| 85 |
// Register_settings |
| 86 |
function plugin_admin_init() |
| 87 |
{ // whitelist options |
| 88 |
register_setting('plugin_options', 'bitp_options', array( |
| 89 |
'type' => 'array', |
| 90 |
'sanitize_callback' => array($this, 'options_validate'), |
| 91 |
'default' => get_default_setting_inputs() |
| 92 |
)); |
| 93 |
add_settings_section('settings_section', 'General Settings', array($this, 'main_description'), 'bitp'); |
| 94 |
add_settings_field('artist', '', array($this, 'settings_inputs'), 'bitp', 'settings_section'); |
| 95 |
} |
| 96 |
|
| 97 |
// Settings Description |
| 98 |
function main_description() |
| 99 |
{ |
| 100 |
// |
| 101 |
} |
| 102 |
|
| 103 |
// The Settings Inputs |
| 104 |
function settings_inputs() |
| 105 |
{ |
| 106 |
$options = get_option('bitp_options'); |
| 107 |
$artist = esc_attr($options['artist']); |
| 108 |
$text_color = esc_attr($options['text_color']); |
| 109 |
$background_color = esc_attr($options['background_color']); |
| 110 |
$display_limit = esc_attr($options['display_limit']); |
| 111 |
$css = esc_attr($options['custom_css']); |
| 112 |
|
| 113 |
echo " |
| 114 |
<script type='text/javascript' src='https://widgetv3.bandsintown.com/main.min.js'></script> |
| 115 |
<tr> |
| 116 |
<p><label for='bitp_options[artist]'><strong>Artist</strong></label><br> |
| 117 |
<input id='bitp_options_artist' name='bitp_options[artist]' type='text' value='$artist' /><br> |
| 118 |
|
| 119 |
<p> |
| 120 |
You can use this section to create your own custom CSS rules and |
| 121 |
override the look and feel of the widget output. |
| 122 |
</p> |
| 123 |
|
| 124 |
<p> |
| 125 |
<strong>Text color:</strong> |
| 126 |
<input name='bitp_options[text_color]' tabindex='1' value='" . ($text_color ?? '#000000') . "' /> |
| 127 |
</p> |
| 128 |
|
| 129 |
<p> |
| 130 |
<strong>Background color:</strong> |
| 131 |
<input name='bitp_options[background_color]' tabindex='2' value='" . ($background_color ?? '#FFFFFF') . "' /> |
| 132 |
</p> |
| 133 |
|
| 134 |
<p> |
| 135 |
<strong>Display</strong> |
| 136 |
<input name='bitp_options[display_limit]' tabindex='5' value='" . ($display_limit ?? '15') . "' /> |
| 137 |
Events |
| 138 |
</p> |
| 139 |
|
| 140 |
<p> |
| 141 |
<strong>Custom CSS:</strong> |
| 142 |
<br> |
| 143 |
<textarea name='bitp_options[custom_css]' style='width: 100%; height: 150px' tabindex='1'> $css </textarea> |
| 144 |
</p> |
| 145 |
"; |
| 146 |
|
| 147 |
//render & output preview template tag |
| 148 |
$this->template_tag($options); |
| 149 |
} |
| 150 |
|
| 151 |
// Validation |
| 152 |
function options_validate($input) |
| 153 |
{ |
| 154 |
$valid_input = array(); |
| 155 |
$valid_options = shortcode_atts(get_all_widget_setting_inputs(true), get_option('bitp_options')); |
| 156 |
foreach ($input as $key => $value) { |
| 157 |
$kebab_key = str_replace('_', '-', $key); |
| 158 |
if (is_bool($value)) { |
| 159 |
$value = ($value) ? 'true' : 'false'; |
| 160 |
} |
| 161 |
$input_value = $value ?: ($valid_options[$kebab_key] ?? ''); |
| 162 |
$valid_input[$key] = sanitize_text_field($input_value); |
| 163 |
} |
| 164 |
return $valid_input; |
| 165 |
} |
| 166 |
|
| 167 |
// [bandsintown_events] |
| 168 |
function shortcode($atts) |
| 169 |
{ |
| 170 |
$default_atts = array( |
| 171 |
'artist' => '', |
| 172 |
'artist-name' => '', |
| 173 |
'text-color' => '#000000', |
| 174 |
'link-color' => '#2F95DE', |
| 175 |
'link-text-color' => '#FFFFFF', |
| 176 |
'background-color' => '#FFFFFF', |
| 177 |
'popup-background-color' => '#FFFFFF', |
| 178 |
'separator-color' => '', |
| 179 |
'font' => '', |
| 180 |
'widget-width' => '', |
| 181 |
'display-logo' => '', |
| 182 |
'display-track-button' => '', |
| 183 |
'display-local-dates' => 'false', |
| 184 |
'display-past-dates' => 'true', |
| 185 |
'display-lineup' => '', |
| 186 |
'display-details' => '', |
| 187 |
'display-limit' => '15', |
| 188 |
'language' => '', |
| 189 |
'auto-style' => 'false', |
| 190 |
'div-id' => '', |
| 191 |
'facebook-page-id' => '', |
| 192 |
'afill-code' => '', |
| 193 |
'app-id' => '' |
| 194 |
); |
| 195 |
|
| 196 |
$sc_atts = shortcode_atts($default_atts, $atts); |
| 197 |
|
| 198 |
// Get the artist name from the shortcode attributes |
| 199 |
$artist_name = $sc_atts['artist-name']; |
| 200 |
if (!empty($sc_atts['artist'])) { |
| 201 |
$artist_name = $sc_atts['artist']; |
| 202 |
} |
| 203 |
|
| 204 |
// Default to the artist name from the settings if it's not set in the shortcode |
| 205 |
if (empty($artist_name)) { |
| 206 |
$artist_name = $this->options['artist']; |
| 207 |
} |
| 208 |
|
| 209 |
$sc_atts['artist-name'] = htmlentities($artist_name); |
| 210 |
unset($sc_atts['artist']); |
| 211 |
|
| 212 |
// Use the values from the settings if they are not set in the shortcode |
| 213 |
$has_default_background_color = $sc_atts['background-color'] == $default_atts['background-color']; |
| 214 |
$has_default_display_limit = $sc_atts['display-limit'] == $default_atts['display-limit']; |
| 215 |
$has_default_link_color = $sc_atts['link-color'] == $default_atts['link-color']; |
| 216 |
$has_default_link_text_color = $sc_atts['link-text-color'] == $default_atts['link-text-color']; |
| 217 |
$has_default_text_color = $sc_atts['text-color'] == $default_atts['text-color']; |
| 218 |
|
| 219 |
if ($has_default_background_color && !empty($this->options['background_color'])) { |
| 220 |
$sc_atts['background-color'] = $this->options['background_color']; |
| 221 |
} |
| 222 |
|
| 223 |
if ($has_default_display_limit && !empty($this->options['display_limit'])) { |
| 224 |
$sc_atts['display-limit'] = $this->options['display_limit']; |
| 225 |
} |
| 226 |
|
| 227 |
if ($has_default_link_color && !empty($this->options['button_and_link_color'])) { |
| 228 |
$sc_atts['link-color'] = $this->options['button_and_link_color']; |
| 229 |
} |
| 230 |
|
| 231 |
if ($has_default_link_text_color && !empty($this->options['link_text_color'])) { |
| 232 |
$sc_atts['link-text-color'] = $this->options['link_text_color']; |
| 233 |
} |
| 234 |
|
| 235 |
if ($has_default_text_color && !empty($this->options['text_color'])) { |
| 236 |
$sc_atts['text-color'] = $this->options['text_color']; |
| 237 |
} |
| 238 |
|
| 239 |
// These atts should be omitted altogether if they are blank |
| 240 |
foreach ( |
| 241 |
array( |
| 242 |
'separator-color', |
| 243 |
'font', |
| 244 |
'widget-width', |
| 245 |
'display-logo', |
| 246 |
'display-lineup', |
| 247 |
'display-details', |
| 248 |
'display-track-button', |
| 249 |
'language', |
| 250 |
'div-id', |
| 251 |
'facebook-page-id', |
| 252 |
'afill-code', |
| 253 |
'app-id' |
| 254 |
) as $a |
| 255 |
) { |
| 256 |
if (empty($sc_atts[$a])) { |
| 257 |
unset($sc_atts[$a]); |
| 258 |
} |
| 259 |
} |
| 260 |
|
| 261 |
$data_atts = ""; |
| 262 |
|
| 263 |
foreach ($sc_atts as $att => $value) { |
| 264 |
$data_atts .= 'data-' . $att . '=' . '"' . esc_attr($value) . '" '; |
| 265 |
} |
| 266 |
|
| 267 |
$options = get_option('bitp_options'); |
| 268 |
$output = '<script type="text/javascript" src="https://widget.bandsintown.com/main.min.js?ver=7.0"></script>'; |
| 269 |
$output .= '<a class="bit-widget-initializer bandsintown-events" ' . $data_atts . '></a>'; |
| 270 |
if (!empty($options['custom_css'])) { |
| 271 |
$output .= '<style type="text/css">' . esc_html($options['custom_css']) . '</style>'; |
| 272 |
} |
| 273 |
|
| 274 |
return $output; |
| 275 |
} |
| 276 |
// [bandsintown_widget] |
| 277 |
function shortcode_widget($atts) |
| 278 |
{ |
| 279 |
$options = get_option('bitp_options'); |
| 280 |
$widget_atts = array_merge([ |
| 281 |
'artist-name' => htmlentities($options['artist']), |
| 282 |
'text-color' => esc_attr($options['text_color']), |
| 283 |
'background-color' => esc_attr($options['background_color']), |
| 284 |
'event-ticket-cta-bg-color' => esc_attr($options['button_and_link_color']), |
| 285 |
'sold-out-button-background-color' => esc_attr($options['button_and_link_color']), |
| 286 |
'display-limit' => esc_attr($options['display_limit']), |
| 287 |
'event-ticket-cta-text-color' => esc_attr($options['link_text_color']), |
| 288 |
'sold-out-button-text-color' => esc_attr($options['link_text_color']), |
| 289 |
'event-rsvp-cta-border-color' => esc_attr($options['button_and_link_color']), |
| 290 |
'event-rsvp-cta-text-color' => esc_attr($options['button_and_link_color']) |
| 291 |
], $atts); |
| 292 |
$output = $this->template_tag($widget_atts, false); |
| 293 |
return $output; |
| 294 |
} |
| 295 |
|
| 296 |
function template_tag_old($params = array(), $echo = true) |
| 297 |
{ |
| 298 |
if (!is_array($params)) { |
| 299 |
$str = $params; |
| 300 |
$params = array(); |
| 301 |
parse_str($str, $params); |
| 302 |
} |
| 303 |
|
| 304 |
if (empty($params['artist'])) { |
| 305 |
$params['artist'] = $this->options['artist']; |
| 306 |
} |
| 307 |
|
| 308 |
if (empty($params['display_limit'])) { |
| 309 |
$params['display_limit'] = $this->options['display_limit']; |
| 310 |
} |
| 311 |
|
| 312 |
$output = '<a class="bit-widget-initializer bandsintown-events" ' |
| 313 |
. ' data-artist-name=' . htmlentities($params['artist']) . ' ' |
| 314 |
. ' data-text-color=' . esc_attr($this->options['text_color']) . ' ' |
| 315 |
. ' data-link-color="' . esc_attr($this->options['button_and_link_color']) . '" ' |
| 316 |
. ' data-background-color="' . esc_attr($this->options['background_color']) . '" ' |
| 317 |
. ' data-display-limit="' . esc_attr($params['display_limit']) . '" ' |
| 318 |
. ' data-link-text-color="' . esc_attr($this->options['link_text_color']) . '" ' |
| 319 |
. ' data-display-local-dates="false" ' |
| 320 |
. ' data-display-past-dates="true" ' |
| 321 |
. ' data-auto-style="false" ' |
| 322 |
. ' data-popup-background-color="#FFFFFF"></a>'; |
| 323 |
|
| 324 |
$options = get_option('bitp_options'); |
| 325 |
|
| 326 |
if (!empty($options['custom_css'])) { |
| 327 |
$output .= '<style type="text/css">' . esc_html($options['custom_css']) . '</style>'; |
| 328 |
} |
| 329 |
|
| 330 |
if ($echo) { |
| 331 |
echo $output; |
| 332 |
} else { |
| 333 |
return $output; |
| 334 |
} |
| 335 |
} |
| 336 |
// actual processing of the template tag |
| 337 |
function template_tag($params = array(), $echo = true) |
| 338 |
{ |
| 339 |
if (!is_array($params)) { |
| 340 |
$str = $params; |
| 341 |
$params = array(); |
| 342 |
parse_str($str, $params); |
| 343 |
} |
| 344 |
if (empty($params['artist-name']) && !empty($this->options['artist'])) { |
| 345 |
$params['artist-name'] = $this->options['artist']; |
| 346 |
} |
| 347 |
//fill in any missing values from the settings |
| 348 |
$default_atts = get_required_shortcode_post_meta(); |
| 349 |
$default_atts['event-rsvp-only-show-icon'] = 'false'; // default to false for backwards compatibility |
| 350 |
//$default_atts = get_all_widget_setting_inputs(true); |
| 351 |
$widget_atts = array_merge($default_atts, $params); |
| 352 |
//$widget_atts = shortcode_atts($default_atts, $params); |
| 353 |
$enforced_attributes = get_enforced_attributes_widget_settings(); |
| 354 |
// Merge with enforced_attributes |
| 355 |
foreach ($enforced_attributes as $key => $value) { |
| 356 |
$widget_atts[$key] = $value; |
| 357 |
} |
| 358 |
$output = '<script type="text/javascript" src="' . esc_url(get_widget_src()) . '"></script>'; |
| 359 |
$output .= '<div class="bandsintown-widget-container" style="max-width: 100%;">'; |
| 360 |
$output .= " <a class='bit-widget-initializer bandsintown-widget' "; |
| 361 |
foreach ($widget_atts as $key => $value) { |
| 362 |
//$value = $tag_atts[$key] ?? $value; |
| 363 |
// Skip display-limit if value is 0 (meaning "All events") |
| 364 |
// Bandsintown widget will show all events when this attribute is not set |
| 365 |
if ($key === 'display-limit' && ($value === 0 || $value === '0')) { |
| 366 |
continue; // Skip this attribute |
| 367 |
} |
| 368 |
$output .= " |
| 369 |
data-" . $key . "='" . esc_attr($value) . "'"; |
| 370 |
} |
| 371 |
$output .= " ></a></div>"; |
| 372 |
|
| 373 |
$options = get_option('bitp_options'); |
| 374 |
|
| 375 |
if (!empty($options['custom_css'])) { |
| 376 |
$output .= '<style type="text/css">' . esc_html($options['custom_css']) . '</style>'; |
| 377 |
} |
| 378 |
if ($echo) { |
| 379 |
echo $output; |
| 380 |
} else { |
| 381 |
return $output; |
| 382 |
} |
| 383 |
} |
| 384 |
} // end Bandsintown_JS_Plugin |
| 385 |
|
| 386 |
// |
| 387 |
// Bandsintown Widget |
| 388 |
// |
| 389 |
class Bandsintown_JS_Widget extends WP_Widget |
| 390 |
{ |
| 391 |
|
| 392 |
function __construct() |
| 393 |
{ |
| 394 |
parent::__construct(false, $name = 'Bandsintown Events'); |
| 395 |
} |
| 396 |
|
| 397 |
function widget($args, $instance) |
| 398 |
{ |
| 399 |
extract($args); |
| 400 |
$title = apply_filters('widget_title', $instance['title']); |
| 401 |
echo $before_widget; |
| 402 |
if ($title) |
| 403 |
echo $before_title . $title . $after_title; |
| 404 |
the_bandsintown_events(array( |
| 405 |
'artist' => $instance['artist'], |
| 406 |
'display_limit' => $instance['display_limit'], |
| 407 |
'force_narrow_layout' => true |
| 408 |
)); |
| 409 |
|
| 410 |
echo $after_widget; |
| 411 |
} |
| 412 |
|
| 413 |
function update($new_instance, $old_instance) |
| 414 |
{ |
| 415 |
$instance = $new_instance; |
| 416 |
$instance['title'] = strip_tags($new_instance['title']); |
| 417 |
$instance['artist'] = strip_tags(stripslashes($new_instance['artist'])); |
| 418 |
$instance['display_limit'] = strip_tags(stripslashes($new_instance['display_limit'])); |
| 419 |
return $instance; |
| 420 |
} |
| 421 |
|
| 422 |
function form($instance) |
| 423 |
{ |
| 424 |
if (empty($instance['artist'])) { |
| 425 |
$options = get_option('bitp_options'); |
| 426 |
$instance['artist'] = $options['artist']; |
| 427 |
} |
| 428 |
include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'widget-form.php'; |
| 429 |
} |
| 430 |
} // end Bandsintown JS Widget |
| 431 |
|
| 432 |
|
| 433 |
// Block Editor Support |
| 434 |
function bandsintown_register_block() |
| 435 |
{ |
| 436 |
// Check if block editor is available |
| 437 |
if (!function_exists('register_block_type')) { |
| 438 |
return; |
| 439 |
} |
| 440 |
|
| 441 |
// Register the block script |
| 442 |
wp_register_script( |
| 443 |
'bandsintown-block-editor', |
| 444 |
plugins_url('blocks/bandsintown-block.js', __FILE__), |
| 445 |
array('wp-blocks', 'wp-element', 'wp-block-editor', 'wp-components', 'wp-i18n'), |
| 446 |
filemtime(plugin_dir_path(__FILE__) . 'blocks/bandsintown-block.js'), |
| 447 |
false |
| 448 |
); |
| 449 |
|
| 450 |
// Register the block styles |
| 451 |
wp_register_style( |
| 452 |
'bandsintown-block-style', |
| 453 |
plugins_url('blocks/bandsintown-block.css', __FILE__), |
| 454 |
array(), |
| 455 |
filemtime(plugin_dir_path(__FILE__) . 'blocks/bandsintown-block.css') |
| 456 |
); |
| 457 |
|
| 458 |
// Enqueue block styles for both editor and frontend |
| 459 |
wp_enqueue_style('bandsintown-block-style'); |
| 460 |
|
| 461 |
// Get default settings |
| 462 |
$options = get_option('bitp_options', []); |
| 463 |
|
| 464 |
$options = array_merge(array( |
| 465 |
'artist' => '', |
| 466 |
'text_color' => '#000', |
| 467 |
'background_color' => '#fff', |
| 468 |
'display_limit' => '15', |
| 469 |
'custom_css' => '' |
| 470 |
), $options); |
| 471 |
|
| 472 |
|
| 473 |
// Localize default settings for JavaScript |
| 474 |
wp_localize_script('bandsintown-block-editor', 'bandsintownBlock', array( |
| 475 |
'defaultSettings' => array( |
| 476 |
'artist' => '', //$options['artist'] |
| 477 |
'textColor' => $options['text_color'], |
| 478 |
'backgroundColor' => $options['background_color'], |
| 479 |
'displayLimit' => intval($options['display_limit']), |
| 480 |
'customCSS' => $options['custom_css'] |
| 481 |
), |
| 482 |
'defaultPanelAttributes' => get_widget_json_panel_attributes($options), |
| 483 |
'defaultWPAttributes' => get_widget_json_wp_default_data(), |
| 484 |
'widgetAttributes' => get_widget_json_all_attributes(), |
| 485 |
'requiredShortcodePostMeta' => get_required_shortcode_post_meta(), |
| 486 |
'enforcedAttributes' => get_enforced_attributes_widget_settings(), |
| 487 |
'widgetSrc' => get_widget_src(), |
| 488 |
'pluginUrl' => plugins_url('', __FILE__), |
| 489 |
'iconUrl' => plugins_url('favicon.png', __FILE__), |
| 490 |
)); |
| 491 |
|
| 492 |
// Register the block type |
| 493 |
register_block_type('bandsintown/events-block', array( |
| 494 |
'editor_script' => 'bandsintown-block-editor', |
| 495 |
'editor_style' => 'bandsintown-block-style', |
| 496 |
'style' => 'bandsintown-block-style', |
| 497 |
'render_callback' => 'drx_render_bandsintown_block', |
| 498 |
//'attributes' => get_option('bitp_options', []) |
| 499 |
)); |
| 500 |
} |
| 501 |
|
| 502 |
// Hook into init to register block |
| 503 |
add_action('init', 'bandsintown_register_block'); |
| 504 |
|
| 505 |
global $bitp; |
| 506 |
$bitp = new Bandsintown_JS_Plugin(); |
| 507 |
|
| 508 |
// template tag wrapper |
| 509 |
function the_bandsintown_events($params = array(), $echo = true) |
| 510 |
{ |
| 511 |
global $bitp; |
| 512 |
return $bitp->template_tag_old($params, $echo); |
| 513 |
} |
| 514 |
|