PluginProbe
Bandsintown Events / 1.4.0
Bandsintown Events v1.4.0
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.0, at bandsintown.php

362 lines 11.2 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.0
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_action('widgets_init', array($this, 'bandsintown_widget_init'));
38
39 $this->options = get_option('bitp_options', []);
40 }
41
42 function bandsintown_widget_init()
43 {
44 return register_widget('Bandsintown_JS_Widget');
45 }
46
47 function bandsintown_tour_dates()
48 {
49 wp_enqueue_script('bit-tour-dates', 'https://widgetv3.bandsintown.com/main.min.js');
50 }
51
52 // Admin menu management.
53 function admin_menu()
54 {
55 add_options_page(
56 'Bandsintown Events',
57 'Bandsintown Events',
58 'manage_options',
59 'bandsintown-settings',
60 array($this, 'settings')
61 );
62 }
63
64 // Manage plugin settings
65 function settings()
66 {
67 ?>
68 <div>
69 <div class="wrap" id="bandsintown_wrap">
70 <h2>Bandsintown Events</h2>
71 <form action="options.php" method="post">
72 <?php
73 settings_fields('plugin_options');
74 do_settings_sections('bitp');
75 ?>
76 <input name="Submit" type="submit" class="button-primary" tabindex="1" value="<?php esc_attr_e('Save Settings'); ?>" />
77 </form>
78 </div>
79 </div>
80 <?php
81 }
82
83 // Register_settings
84 function plugin_admin_init()
85 { // whitelist options
86 register_setting('plugin_options', 'bitp_options', array(
87 'type' => 'array',
88 'sanitize_callback' => array($this, 'options_validate'),
89 'default' => get_default_setting_inputs()
90 ));
91 add_settings_section('settings_section', 'General Settings', array($this, 'main_description'), 'bitp');
92 add_settings_field('artist', '', array($this, 'settings_inputs'), 'bitp', 'settings_section');
93 }
94
95 // Settings Description
96 function main_description()
97 {
98 //
99 }
100
101 // The Settings Inputs
102 function settings_inputs()
103 {
104 $options = get_option('bitp_options');
105 $artist = esc_attr($options['artist']);
106 $text_color = esc_attr($options['text_color']);
107 $background_color = esc_attr($options['background_color']);
108 $display_limit = esc_attr($options['display_limit']);
109 $css = esc_attr($options['custom_css']);
110
111 echo "
112 <script type='text/javascript' src='https://widgetv3.bandsintown.com/main.min.js'></script>
113 <tr>
114 <p><label for='bitp_options[artist]'><strong>Artist</strong></label><br>
115 <input id='bitp_options_artist' name='bitp_options[artist]' type='text' value='$artist' /><br>
116
117 <p>
118 You can use this section to create your own custom CSS rules and
119 override the look and feel of the widget output.
120 </p>
121
122 <p>
123 <strong>Text color:</strong>
124 <input name='bitp_options[text_color]' tabindex='1' value='" . ($text_color ?? '#000000') . "' />
125 </p>
126
127 <p>
128 <strong>Background color:</strong>
129 <input name='bitp_options[background_color]' tabindex='2' value='" . ($background_color ?? '#FFFFFF') . "' />
130 </p>
131
132 <p>
133 <strong>Display</strong>
134 <input name='bitp_options[display_limit]' tabindex='5' value='" . ($display_limit ?? '15') . "' />
135 Events
136 </p>
137
138 <p>
139 <strong>Custom CSS:</strong>
140 <br>
141 <textarea name='bitp_options[custom_css]' style='width: 100%; height: 150px' tabindex='1'> $css </textarea>
142 </p>
143 ";
144
145 //render & output preview template tag
146 $this->template_tag($options);
147 }
148
149 // Validation
150 function options_validate($input)
151 {
152 $valid_input = array();
153 $valid_options = shortcode_atts(get_all_widget_setting_inputs(true), get_option('bitp_options'));
154 foreach ($input as $key => $value) {
155 $kebab_key = str_replace('_', '-', $key);
156 if (is_bool($value)) {
157 $value = ($value) ? 'true' : 'false';
158 }
159 $input_value = $value ?: ($valid_options[$kebab_key] ?? '');
160 $valid_input[$key] = sanitize_text_field($input_value);
161 }
162 return $valid_input;
163 }
164
165 // [bandsintown_events] shortcode
166 function shortcode($atts)
167 {
168 $options = get_option('bitp_options');
169 $widget_atts = array_merge([
170 'artist-name' => htmlentities($options['artist']),
171 'text-color' => esc_attr($options['text_color']),
172 'background-color' => esc_attr($options['background_color']),
173 'event-ticket-cta-bg-color' => esc_attr($options['button_and_link_color']),
174 'sold-out-button-background-color' => esc_attr($options['button_and_link_color']),
175 'display-limit' => esc_attr($options['display_limit']),
176 'event-ticket-cta-text-color' => esc_attr($options['link_text_color']),
177 'sold-out-button-text-color' => esc_attr($options['link_text_color']),
178 'event-rsvp-cta-border-color' => esc_attr($options['button_and_link_color']),
179 'event-rsvp-cta-text-color' => esc_attr($options['button_and_link_color'])
180 ], $atts);
181 $output = $this->template_tag($widget_atts, false);
182 return $output;
183 }
184
185 // actual processing of the template tag
186 function template_tag($params = array(), $echo = true)
187 {
188 if (!is_array($params)) {
189 $str = $params;
190 $params = array();
191 parse_str($str, $params);
192 }
193 if (empty($params['artist-name']) && !empty($this->options['artist'])) {
194 $params['artist-name'] = $this->options['artist'];
195 }
196 //fill in any missing values from the settings
197 $default_atts = get_required_shortcode_post_meta();
198 $default_atts['event-rsvp-only-show-icon'] = 'false'; // default to false for backwards compatibility
199 //$default_atts = get_all_widget_setting_inputs(true);
200 $widget_atts = array_merge($default_atts, $params);
201 //$widget_atts = shortcode_atts($default_atts, $params);
202 $enforced_attributes = get_enforced_attributes_widget_settings();
203 // Merge with enforced_attributes
204 foreach ($enforced_attributes as $key => $value) {
205 $widget_atts[$key] = $value;
206 }
207 $output = '<div class="bandsintown-widget-container" style="max-width: 100%;">';
208 $output .= " <a class='bit-widget-initializer' ";
209 foreach ($widget_atts as $key => $value) {
210 //$value = $tag_atts[$key] ?? $value;
211 // Skip display-limit if value is 0 (meaning "All events")
212 // Bandsintown widget will show all events when this attribute is not set
213 if ($key === 'display-limit' && ($value === 0 || $value === '0')) {
214 continue; // Skip this attribute
215 }
216 $output .= "
217 data-" . $key . "='" . esc_attr($value) . "'";
218 }
219 $output .= " ></a></div>";
220
221 $options = get_option('bitp_options');
222
223 if (!empty($options['custom_css'])) {
224 $output .= '<style type="text/css">' . esc_html($options['custom_css']) . '</style>';
225 }
226 if ($echo) {
227 echo $output;
228 } else {
229 return $output;
230 }
231 }
232 } // end Bandsintown_JS_Plugin
233
234 //
235 // Bandsintown Widget
236 //
237 class Bandsintown_JS_Widget extends WP_Widget
238 {
239
240 function __construct()
241 {
242 parent::__construct(false, $name = 'Bandsintown Events');
243 }
244
245 function widget($args, $instance)
246 {
247 extract($args);
248 $title = apply_filters('widget_title', $instance['title']);
249 echo $before_widget;
250 if ($title)
251 echo $before_title . $title . $after_title;
252 the_bandsintown_events(array(
253 'artist' => $instance['artist'],
254 'display_limit' => $instance['display_limit'],
255 'force_narrow_layout' => true
256 ));
257
258 echo $after_widget;
259 }
260
261 function update($new_instance, $old_instance)
262 {
263 $instance = $new_instance;
264 $instance['title'] = strip_tags($new_instance['title']);
265 $instance['artist'] = strip_tags(stripslashes($new_instance['artist']));
266 $instance['display_limit'] = strip_tags(stripslashes($new_instance['display_limit']));
267 return $instance;
268 }
269
270 function form($instance)
271 {
272 if (empty($instance['artist'])) {
273 $options = get_option('bitp_options');
274 $instance['artist'] = $options['artist'];
275 }
276 include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'widget-form.php';
277 }
278 } // end Bandsintown JS Widget
279
280
281 // Block Editor Support
282 function bandsintown_register_block()
283 {
284 // Check if block editor is available
285 if (!function_exists('register_block_type')) {
286 return;
287 }
288
289 // Register the block script
290 wp_register_script(
291 'bandsintown-block-editor',
292 plugins_url('blocks/bandsintown-block.js', __FILE__),
293 array('wp-blocks', 'wp-element', 'wp-block-editor', 'wp-components', 'wp-i18n'),
294 filemtime(plugin_dir_path(__FILE__) . 'blocks/bandsintown-block.js'),
295 false
296 );
297
298 // Register the block styles
299 wp_register_style(
300 'bandsintown-block-style',
301 plugins_url('blocks/bandsintown-block.css', __FILE__),
302 array(),
303 filemtime(plugin_dir_path(__FILE__) . 'blocks/bandsintown-block.css')
304 );
305
306 // Enqueue block styles for both editor and frontend
307 wp_enqueue_style('bandsintown-block-style');
308
309 // Get default settings
310 $options = get_option('bitp_options', []);
311
312 $options = array_merge(array(
313 'artist' => '',
314 'text_color' => '#000',
315 'background_color' => '#fff',
316 'display_limit' => '15',
317 'custom_css' => ''
318 ), $options);
319
320
321 // Localize default settings for JavaScript
322 wp_localize_script('bandsintown-block-editor', 'bandsintownBlock', array(
323 'defaultSettings' => array(
324 'artist' => '', //$options['artist']
325 'textColor' => $options['text_color'],
326 'backgroundColor' => $options['background_color'],
327 'displayLimit' => intval($options['display_limit']),
328 'customCSS' => $options['custom_css']
329 ),
330 'defaultPanelAttributes' => get_widget_json_panel_attributes($options),
331 'defaultWPAttributes' => get_widget_json_wp_default_data(),
332 'widgetAttributes' => get_widget_json_all_attributes(),
333 'requiredShortcodePostMeta' => get_required_shortcode_post_meta(),
334 'enforcedAttributes' => get_enforced_attributes_widget_settings(),
335 'widgetSrc' => get_widget_src(),
336 'pluginUrl' => plugins_url('', __FILE__),
337 'iconUrl' => plugins_url('favicon.png', __FILE__),
338 ));
339
340 // Register the block type
341 register_block_type('bandsintown/events-block', array(
342 'editor_script' => 'bandsintown-block-editor',
343 'editor_style' => 'bandsintown-block-style',
344 'style' => 'bandsintown-block-style',
345 'render_callback' => 'drx_render_bandsintown_block',
346 //'attributes' => get_option('bitp_options', [])
347 ));
348 }
349
350 // Hook into init to register block
351 add_action('init', 'bandsintown_register_block');
352
353 global $bitp;
354 $bitp = new Bandsintown_JS_Plugin();
355
356 // template tag wrapper
357 function the_bandsintown_events($params = array(), $echo = true)
358 {
359 global $bitp;
360 return $bitp->template_tag($params, $echo);
361 }
362