PluginProbe
Bandsintown Events / 1.4.4
Bandsintown Events v1.4.4
1.4.5 1.4.4 1.4.3 1.4.2 1.4.1 trunk 0.2.0 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 All 28 releases
bandsintown / bandsintown.php

bandsintown.php in Bandsintown Events 1.4.4, at bandsintown.php

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