PluginProbe
Bandsintown Events / trunk
Bandsintown Events vtrunk
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 trunk, at bandsintown.php

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