PluginProbe
AudioIgniter Music Player / 1.6.1
AudioIgniter Music Player v1.6.1
2.0.4 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.3.0 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.9.0 2.0.0 2.0.1 2.0.2 All 26 releases
audioigniter / audioigniter.php

audioigniter.php in AudioIgniter Music Player 1.6.1, at audioigniter.php

1,339 lines 44.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: AudioIgniter
4 * Plugin URI: https://www.cssigniter.com/plugins/audioigniter/
5 * Description: AudioIgniter lets you create music playlists and embed them in your WordPress posts, pages or custom post types and serve your audio content in style!
6 * Author: The CSSIgniter Team
7 * Author URI: https://www.cssigniter.com
8 * Version: 1.6.1
9 * Text Domain: audioigniter
10 * Domain Path: languages
11 *
12 * AudioIgniter is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 2 of the License, or
15 * any later version.
16 *
17 * AudioIgniter Downloads is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with AudioIgniter. If not, see <http://www.gnu.org/licenses/>.
24 *
25 */
26
27 if ( ! defined( 'ABSPATH' ) ) {
28 exit;
29 }
30
31
32 class AudioIgniter {
33
34 /**
35 * AudioIgniter version.
36 *
37 * @var string
38 * @since 1.0.0
39 */
40 public static $version = '1.6.1';
41
42 /**
43 * Instance of this class.
44 *
45 * @var AudioIgniter
46 * @since 1.0.0
47 */
48 protected static $instance = null;
49
50 /**
51 * Sanitizer instance.
52 *
53 * @var AudioIgniter_Sanitizer
54 * @since 1.0.0
55 */
56 public $sanitizer = null;
57
58 /**
59 * The URL directory path (with trailing slash) of the main plugin file.
60 *
61 * @var string
62 * @since 1.0.0
63 */
64 protected static $plugin_url = '';
65
66 /**
67 * The filesystem directory path (with trailing slash) of the main plugin file.
68 *
69 * @var string
70 * @since 1.0.0
71 */
72 protected static $plugin_path = '';
73
74
75 /**
76 * Playlist post type name.
77 *
78 * @var string
79 * @since 1.0.0
80 */
81 public $post_type = 'ai_playlist';
82
83
84
85 /**
86 * AudioIgniter Instance.
87 *
88 * Instantiates or reuses an instance of AudioIgniter.
89 *
90 * @since 1.0.0
91 * @static
92 * @see AudioIgniter()
93 * @return AudioIgniter - Single instance.
94 */
95 public static function instance() {
96 if ( is_null( self::$instance ) ) {
97 self::$instance = new self();
98 }
99 return self::$instance;
100 }
101
102
103 /**
104 * AudioIgniter constructor. Intentionally left empty so that instances can be created without
105 * re-loading of resources (e.g. scripts/styles), or re-registering hooks.
106 * http://wordpress.stackexchange.com/questions/70055/best-way-to-initiate-a-class-in-a-wp-plugin
107 * https://gist.github.com/toscho/3804204
108 *
109 * @since 1.0.0
110 */
111 public function __construct() {}
112
113 /**
114 * Kickstarts plugin loading.
115 *
116 * @since 1.0.0
117 */
118 public function plugin_setup() {
119 self::$plugin_url = plugin_dir_url( __FILE__ );
120 self::$plugin_path = plugin_dir_path( __FILE__ );
121
122 load_plugin_textdomain( 'audioigniter', false, dirname( self::plugin_basename() ) . '/languages' );
123
124 include_once( 'class-audioigniter-sanitizer.php' );
125 $this->sanitizer = new AudioIgniter_Sanitizer();
126
127 // Initialization needed in every request.
128 $this->init();
129
130 // Initialization needed in admin requests.
131 $this->admin_init();
132
133 // Initialization needed in frontend requests.
134 $this->frontend_init();
135
136 do_action( 'audioigniter_loaded' );
137 }
138
139 /**
140 * Registers actions that need to be run on both admin and frontend
141 *
142 * @since 1.0.0
143 */
144 protected function init() {
145 add_action( 'init', array( $this, 'register_post_types' ) );
146 add_action( 'init', array( $this, 'register_scripts' ) );
147 add_action( 'init', array( $this, 'register_playlist_endpoint' ) );
148 add_action( 'init', array( $this, 'register_image_sizes' ) );
149 add_action( 'init', array( $this, 'register_shortcodes' ) );
150 add_action( 'widgets_init', array( $this, 'register_widgets' ) );
151
152 do_action( 'audioigniter_init' );
153 }
154
155
156 /**
157 * Registers actions that need to be run on admin only.
158 *
159 * @since 1.0.0
160 */
161 protected function admin_init() {
162 if ( ! is_admin() ) {
163 return;
164 }
165
166 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
167 add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
168 add_action( 'save_post', array( $this, 'save_post' ) );
169
170 do_action( 'audioigniter_admin_init' );
171 }
172
173 /**
174 * Registers actions that need to be run on frontend only.
175 *
176 * @since 1.0.0
177 */
178 protected function frontend_init() {
179 if ( is_admin() ) {
180 return;
181 }
182
183 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
184 add_action( 'template_redirect', array( $this, 'handle_playlist_endpoint' ) );
185
186 do_action( 'audioigniter_frontend_init' );
187 }
188
189 /**
190 * Register (but not enqueue) all scripts and styles to be used throughout the plugin.
191 *
192 * @since 1.0.0
193 */
194 public function register_scripts() {
195 wp_register_style( 'audioigniter', $this->plugin_url() . 'player/build/style.css', array(), self::$version );
196 wp_register_style( 'audioigniter-admin', $this->plugin_url() . 'assets/css/admin-styles.css', array(), self::$version );
197
198 wp_register_script( 'audioigniter', $this->plugin_url() . 'player/build/app.js', array(), self::$version, true );
199 wp_register_script( 'audioigniter-admin', $this->plugin_url() . 'assets/js/audioigniter.js', array(), self::$version, true );
200
201 wp_localize_script( 'audioigniter', 'aiStrings', apply_filters( 'audioigniter_aiStrings', array(
202 /* translators: %s is the track's title. */
203 'play_title' => esc_html__( 'Play %s', 'audioigniter' ),
204 /* translators: %s is the track's title. */
205 'pause_title' => esc_html__( 'Pause %s', 'audioigniter' ),
206 'previous' => esc_html__( 'Previous track', 'audioigniter' ),
207 'next' => esc_html__( 'Next track', 'audioigniter' ),
208 'toggle_list_repeat' => esc_html__( 'Toggle track listing repeat', 'audioigniter' ),
209 'toggle_track_repeat' => esc_html__( 'Toggle track repeat' ),
210 'toggle_list_visible' => esc_html__( 'Toggle track listing visibility', 'audioigniter' ),
211 'buy_track' => esc_html__( 'Buy this track', 'audioigniter' ),
212 'download_track' => esc_html__( 'Download this track', 'audioigniter' ),
213 'volume_up' => esc_html__( 'Volume Up', 'audioigniter' ),
214 'volume_down' => esc_html__( 'Volume Down', 'audioigniter' ),
215 'open_track_lyrics' => esc_html__( 'Open track lyrics', 'audioigniter' ),
216 'set_playback_rate' => esc_html__( 'Set playback rate', 'audioigniter' ),
217 'skip_forward' => esc_html__( 'Skip forward', 'audioigniter' ),
218 'skip_backward' => esc_html__( 'Skip backward', 'audioigniter' ),
219 ) ) );
220
221 wp_localize_script( 'audioigniter-admin', 'ai_scripts', array(
222 'messages' => array(
223 'confirm_clear_tracks' => esc_html__( 'Do you really want to remove all tracks? (This will not delete your audio files).', 'audioigniter' ),
224 'media_title_upload' => esc_html__( 'Select or upload audio media', 'audioigniter' ),
225 'media_title_upload_cover' => esc_html__( 'Select a cover image', 'audioigniter' ),
226 ),
227 ) );
228 }
229
230 /**
231 * Enqueues frontend scripts and styles.
232 *
233 * @since 1.0.0
234 */
235 public function enqueue_scripts() {
236 wp_enqueue_style( 'audioigniter' );
237 wp_enqueue_script( 'audioigniter' );
238 }
239
240 /**
241 * Enqueues admin scripts and styles.
242 *
243 * @since 1.0.0
244 */
245 public function enqueue_admin_scripts( $hook ) {
246 $screen = get_current_screen();
247
248 if ( 'post' === $screen->base && $screen->post_type === $this->post_type ) {
249 wp_enqueue_media();
250 wp_enqueue_style( 'audioigniter-admin' );
251 wp_enqueue_script( 'audioigniter-admin' );
252 }
253 }
254
255 /**
256 * Post types registration.
257 *
258 * @since 1.0.0
259 */
260 public function register_post_types() {
261 $labels = array(
262 'name' => esc_html_x( 'Playlists', 'post type general name', 'audioigniter' ),
263 'singular_name' => esc_html_x( 'Playlist', 'post type singular name', 'audioigniter' ),
264 'menu_name' => esc_html_x( 'Playlists', 'admin menu', 'audioigniter' ),
265 'name_admin_bar' => esc_html_x( 'Playlist', 'add new on admin bar', 'audioigniter' ),
266 'add_new' => esc_html__( 'Add New Playlist', 'audioigniter' ),
267 'add_new_item' => esc_html__( 'Add New Playlist', 'audioigniter' ),
268 'edit_item' => esc_html__( 'Edit Playlist', 'audioigniter' ),
269 'new_item' => esc_html__( 'New Playlist', 'audioigniter' ),
270 'view_item' => esc_html__( 'View Playlist', 'audioigniter' ),
271 'search_items' => esc_html__( 'Search Playlists', 'audioigniter' ),
272 'not_found' => esc_html__( 'No playlists found', 'audioigniter' ),
273 'not_found_in_trash' => esc_html__( 'No playlists found in the trash', 'audioigniter' ),
274 );
275
276 $args = array(
277 'labels' => $labels,
278 'singular_label' => esc_html_x( 'Playlist', 'post type singular name', 'audioigniter' ),
279 'public' => false,
280 'show_ui' => true,
281 'capability_type' => 'post',
282 'hierarchical' => false,
283 'has_archive' => false,
284 'supports' => array( 'title' ),
285 'menu_icon' => 'dashicons-controls-volumeon',
286 );
287
288 register_post_type( $this->post_type, $args );
289 }
290
291
292 /**
293 * Registers metaboxes for the ai_playlist post type.
294 *
295 * @since 1.0.0
296 */
297 public function add_meta_boxes() {
298 add_meta_box( 'ai-meta-box-tracks', esc_html__( 'Tracks', 'audioigniter' ), array( $this, 'metabox_tracks' ), $this->post_type, 'normal', 'high' );
299 add_meta_box( 'ai-meta-box-settings', esc_html__( 'Settings', 'audioigniter' ), array( $this, 'metabox_settings' ), $this->post_type, 'normal', 'high' );
300 add_meta_box( 'ai-meta-box-shortcode', esc_html__( 'Shortcode', 'audioigniter' ), array( $this, 'metabox_shortcode' ), $this->post_type, 'normal', 'high' );
301 }
302
303 /**
304 * Echoes the Tracks metabox markup.
305 *
306 * @since 1.0.0
307 *
308 * @param WP_Post $object
309 * @param array $box
310 */
311 public function metabox_tracks( $object, $box ) {
312 $tracks = $this->get_post_meta( $object->ID, '_audioigniter_tracks', array() );
313
314 wp_nonce_field( basename( __FILE__ ), $object->post_type . '_nonce' );
315 ?>
316
317 <?php $this->metabox_tracks_header(); ?>
318
319 <div class="ai-container">
320 <?php $this->metabox_tracks_field_controls(); ?>
321
322 <?php $container_classes = apply_filters( 'audioigniter_metabox_tracks_container_classes', array( 'ai-fields-container' ) ); ?>
323
324 <div class="<?php echo esc_attr( implode( ' ', $container_classes ) ); ?>">
325 <?php
326 if ( ! empty( $tracks ) ) {
327 foreach ( $tracks as $track ) {
328 $this->metabox_tracks_repeatable_track_field( $track );
329 }
330 } else {
331 $this->metabox_tracks_repeatable_track_field();
332 }
333 ?>
334 </div>
335
336 <?php $this->metabox_tracks_field_controls(); ?>
337 </div>
338
339 <?php $this->metabox_tracks_footer(); ?>
340
341 <input type="hidden" name="ai_nonce" id="ai_nonce" value="<?php echo esc_attr( wp_create_nonce( self::plugin_basename() ) ); ?>"/>
342 <?php
343 }
344
345
346 /**
347 * Echoes the Tracks metabox header.
348 *
349 * @since 1.0.0
350 */
351 protected function metabox_tracks_header() {
352 ?>
353 <div class="ai-header ai-brand-module">
354 <div class="ai-row">
355 <div class="ai-col-left">
356 <a href="https://www.cssigniter.com/plugins/audioigniter?utm_source=dashboard&utm_medium=link&utm_content=audioigniter&utm_campaign=logo" target="_blank" class="ai-logo">
357 <img
358 src="<?php echo esc_url( $this->plugin_url() . 'assets/images/logo.svg' ); ?>"
359 alt="<?php esc_attr_e( 'AudioIgniter Logo', 'audioigniter' ); ?>"
360 >
361 </a>
362 </div>
363
364 <?php if ( apply_filters( 'audioigniter_metabox_tracks_show_upgrade_button', true ) ) : ?>
365 <div class="ai-col-right">
366 <div class="ai-brand-module-actions">
367 <a href="https://www.cssigniter.com/plugins/audioigniter?utm_source=dashboard&utm_medium=link&utm_content=audioigniter&utm_campaign=upgrade-pro" class="ai-btn ai-btn-green" target="_blank">
368 <?php esc_html_e( 'Upgrade to Pro', 'audioigniter' ); ?>
369 </a>
370 </div>
371 </div>
372 <?php endif; ?>
373 </div>
374 </div>
375 <?php
376 }
377
378 /**
379 * Echoes the Tracks metabox footer.
380 *
381 * @since 1.0.0
382 */
383 protected function metabox_tracks_footer() {
384 ?>
385 <div class="ai-footer ai-brand-module">
386 <div class="ai-row">
387 <div class="ai-col-left">
388 <ul class="ai-list-inline">
389 <?php
390 $links = apply_filters( 'audioigniter_metabox_tracks_footer_links', array(
391 'support' => array(
392 'title' => __( 'Support', 'audioigniter' ),
393 'url' => 'https://wordpress.org/support/plugin/audioigniter',
394 ),
395 'documentation' => array(
396 'title' => __( 'Documentation', 'audioigniter' ),
397 'url' => 'https://www.cssigniter.com/docs/audioigniter/',
398 ),
399 'rate_plugin' => array(
400 'title' => __( 'Rate this plugin', 'audioigniter' ),
401 'url' => 'https://wordpress.org/support/view/plugin-reviews/audioigniter',
402 ),
403 ) );
404
405 foreach ( $links as $link ) {
406 if ( empty( $link['url'] ) || empty( $link['title'] ) ) {
407 continue;
408 }
409
410 echo sprintf( '<li><a href="%s" target="_blank">%s</a></li>',
411 esc_url( $link['url'] ),
412 esc_html( $link['title'] )
413 );
414 }
415 ?>
416 </ul>
417 </div>
418
419 <div class="ai-col-right">
420 <?php
421 $url = 'https://www.cssigniter.com/plugins/audioigniter?utm_source=dashboard&utm_medium=link&utm_content=audioigniter&utm_campaign=footer-link';
422 /* translators: %s is a URL. */
423 $copy = sprintf( __( 'Thank you for creating with <a href="%s" target="_blank">AudioIgniter</a>', 'audioigniter' ),
424 esc_url( $url )
425 );
426 ?>
427 <div class="ai-brand-module-actions">
428 <p class="ai-note"><?php echo wp_kses( $copy, array( 'a' => array( 'href' => true, 'target' => true ) ) ); ?></p>
429 </div>
430 </div>
431 </div>
432 </div>
433 <?php
434 }
435
436 protected function metabox_tracks_repeatable_track_field( $track = array() ) {
437 $track = wp_parse_args( $track, self::get_default_track_values() );
438
439 $cover_id = $track['cover_id'];
440 $title = $track['title'];
441 $artist = $track['artist'];
442 $track_url = $track['track_url'];
443 $buy_link = $track['buy_link'];
444 $download_url = $track['download_url'];
445
446 $cover_url = wp_get_attachment_image_src( intval( $cover_id ), 'thumbnail' );
447 if ( ! empty( $cover_url[0] ) ) {
448 $cover_url = $cover_url[0];
449 $cover_data = wp_prepare_attachment_for_js( intval( $cover_id ) );
450 } else {
451 $cover_url = '';
452 $cover_data = '';
453 }
454
455 $uid = uniqid();
456
457 $field_classes = apply_filters( 'audioigniter_metabox_track_classes', array( 'ai-field-repeatable' ), $track_url );
458 ?>
459 <div class="<?php echo esc_attr( implode( ' ', $field_classes ) ); ?>" data-uid="<?php echo esc_attr( $uid ); ?>">
460 <div class="ai-field-head">
461
462 <?php do_action( 'audioigniter_metabox_tracks_repeatable_track_field_before_title' ); ?>
463
464 <span class="ai-field-title"><?php echo wp_kses( $title, array() ); ?></span>
465
466 <button type="button" class="ai-field-toggle button-link">
467 <span class="screen-reader-text">
468 <?php esc_html_e( 'Toggle track visibility', 'audioigniter' ); ?>
469 </span>
470 <span class="toggle-indicator"></span>
471 </button>
472 </div>
473
474 <div class="ai-field-container">
475 <div class="ai-field-cover">
476 <a href="#" class="ai-field-upload-cover <?php echo ! empty( $cover_url ) ? 'ai-has-cover' : ''; ?>">
477 <span class="ai-remove-cover">
478 <span class="screen-reader-text">
479 <?php esc_html_e( 'Remove Cover Image', 'audioigniter' ); ?>
480 </span>
481 <span class="dashicons dashicons-no-alt"></span>
482 </span>
483
484 <?php if ( ! empty( $cover_url ) ) : ?>
485 <img src="<?php echo esc_url( $cover_url ); ?>" alt="<?php echo esc_attr( $cover_data['alt'] ); ?>">
486 <?php else : ?>
487 <img src="#" alt="">
488 <?php endif; ?>
489
490 <div class="ai-field-cover-placeholder">
491 <span class="ai-cover-prompt">
492 <?php esc_html_e( 'Upload Cover', 'audioigniter' ); ?>
493 </span>
494 </div>
495 </a>
496
497 <input
498 type="hidden"
499 id="ai_playlist_tracks-<?php echo esc_attr( $uid ); ?>-cover_id"
500 name="ai_playlist_tracks[<?php echo esc_attr( $uid ); ?>][cover_id]"
501 value="<?php echo esc_attr( $cover_id ); ?>"
502 />
503 </div>
504
505 <div class="ai-field-split">
506 <div class="ai-form-field">
507 <label
508 for="ai_playlist_tracks-<?php echo esc_attr( $uid ); ?>-title"
509 class="screen-reader-text">
510 <?php esc_html_e( 'Title', 'audioigniter' ); ?>
511 </label>
512 <input
513 type="text"
514 id="ai_playlist_tracks-<?php echo esc_attr( $uid ); ?>-title"
515 class="ai-track-title"
516 name="ai_playlist_tracks[<?php echo esc_attr( $uid ); ?>][title]"
517 placeholder="<?php esc_attr_e( 'Title', 'audioigniter' ); ?>"
518 value="<?php echo esc_attr( $title ); ?>"
519 />
520 </div>
521 <div class="ai-form-field">
522 <label
523 for="ai_playlist_tracks-<?php echo esc_attr( $uid ); ?>-artist"
524 class="screen-reader-text">
525 <?php esc_html_e( 'Artist', 'audioigniter' ); ?>
526 </label>
527 <input
528 type="text"
529 id="ai_playlist_tracks-<?php echo esc_attr( $uid ); ?>-artist"
530 class="ai-track-artist"
531 name="ai_playlist_tracks[<?php echo esc_attr( $uid ); ?>][artist]"
532 placeholder="<?php esc_attr_e( 'Artist', 'audioigniter' ); ?>"
533 value="<?php echo esc_attr( $artist ); ?>"
534 />
535 </div>
536
537 <div class="ai-form-field">
538 <label
539 for="ai_playlist_tracks-<?php echo esc_attr( $uid ); ?>-buy_link"
540 class="screen-reader-text">
541 <?php esc_html_e( 'Buy link', 'audioigniter' ); ?>
542 </label>
543 <input
544 type="text"
545 id="ai_playlist_tracks-<?php echo esc_attr( $uid ); ?>-buy_link"
546 class="ai-track-buy-link"
547 name="ai_playlist_tracks[<?php echo esc_attr( $uid ); ?>][buy_link]"
548 placeholder="<?php esc_attr_e( 'Buy link', 'audioigniter' ); ?>"
549 value="<?php echo esc_url( $buy_link ); ?>"
550 />
551 </div>
552
553 <?php do_action( 'audioigniter_metabox_tracks_repeatable_track_fields_column_1', $track, $uid ); ?>
554 </div>
555
556 <div class="ai-field-split">
557 <div class="ai-form-field">
558 <label
559 for="ai_playlist_tracks-<?php echo esc_attr( $uid ); ?>-track_url"
560 class="screen-reader-text">
561 <?php esc_html_e( 'Audio file or radio stream', 'audioigniter' ); ?>
562 </label>
563
564 <div class="ai-form-field-addon">
565 <input
566 type="text"
567 id="ai_playlist_tracks-<?php echo esc_attr( $uid ); ?>-track_url"
568 class="ai-track-url"
569 name="ai_playlist_tracks[<?php echo esc_attr( $uid ); ?>][track_url]"
570 placeholder="<?php esc_attr_e( 'Audio file or radio stream', 'audioigniter' ); ?>"
571 value="<?php echo esc_url( $track_url ); ?>"
572 />
573 <button type="button" class="button ai-upload">
574 <?php esc_html_e( 'Upload', 'audioigniter' ); ?>
575 </button>
576
577 <?php do_action( 'audioigniter_metabox_tracks_repeatable_track_field_after_track_upload_button' ); ?>
578 </div>
579 </div>
580
581 <div class="ai-form-field">
582 <label
583 for="ai_playlist_tracks-<?php echo esc_attr( $uid ); ?>-download_url"
584 class="screen-reader-text">
585 <?php esc_html_e( 'Download URL', 'audioigniter' ); ?>
586 </label>
587 <input
588 type="text"
589 id="ai_playlist_tracks-<?php echo esc_attr( $uid ); ?>-download_url"
590 class="ai-track-download-url"
591 name="ai_playlist_tracks[<?php echo esc_attr( $uid ); ?>][download_url]"
592 placeholder="<?php esc_attr_e( 'Download URL', 'audioigniter' ); ?>"
593 value="<?php echo esc_url( $download_url ); ?>"
594 />
595 </div>
596
597 <?php do_action( 'audioigniter_metabox_tracks_repeatable_track_fields_column_2', $track, $uid ); ?>
598
599 <button type="button" class="button ai-remove-field">
600 <span class="dashicons dashicons-dismiss"></span>
601 <?php esc_html_e( 'Remove Track', 'audioigniter' ); ?>
602 </button>
603 </div>
604
605 </div>
606 </div>
607 <?php
608 }
609
610 protected function metabox_tracks_field_controls() {
611 ?>
612 <div class="ai-field-controls-wrap">
613 <div class="ai-field-controls">
614 <button type="button" class="button ai-add-field">
615 <span class="dashicons dashicons-plus-alt"></span>
616 <?php esc_html_e( 'Add Track', 'audioigniter' ); ?>
617 </button>
618
619 <?php do_action( 'audioigniter_metabox_tracks_field_controls' ); ?>
620
621 <button type="button" class="button ai-remove-all-fields">
622 <span class="dashicons dashicons-dismiss"></span>
623 <?php esc_html_e( 'Clear Playlist', 'audioigniter' ); ?>
624 </button>
625 </div>
626
627 <div class="ai-field-controls-visibility">
628 <a href="#" class="ai-fields-expand-all">
629 <?php esc_html_e( 'Expand All', 'audioigniter' ); ?>
630 </a>
631 <a href="#" class="ai-fields-collapse-all">
632 <?php esc_html_e( 'Collapse All', 'audioigniter' ); ?>
633 </a>
634 </div>
635 </div>
636 <?php
637 }
638
639 /**
640 * Echoes the Settings metabox markup.
641 *
642 * @version 1.4.0
643 * @since 1.0.0
644 *
645 * @param WP_Post $object
646 * @param array $box
647 */
648 public function metabox_settings( $object, $box ) {
649 $type = $this->get_post_meta( $object->ID, '_audioigniter_player_type', 'full' );
650 $numbers = $this->get_post_meta( $object->ID, '_audioigniter_show_numbers', 1 );
651 $numbers_reverse = $this->get_post_meta( $object->ID, '_audioigniter_show_numbers_reverse', 0 );
652 $thumb = $this->get_post_meta( $object->ID, '_audioigniter_show_covers', 1 );
653 $active_thumb = $this->get_post_meta( $object->ID, '_audioigniter_show_active_cover', 1 );
654 $artist = $this->get_post_meta( $object->ID, '_audioigniter_show_artist', 1 );
655 $buy_links = $this->get_post_meta( $object->ID, '_audioigniter_show_buy_links', 1 );
656 $buy_links_new_target = $this->get_post_meta( $object->ID, '_audioigniter_buy_links_new_target', 1 );
657 $cycle_tracks = $this->get_post_meta( $object->ID, '_audioigniter_cycle_tracks', 0 );
658 $track_listing = $this->get_post_meta( $object->ID, '_audioigniter_show_track_listing', 1 );
659 $track_listing_allow_toggle = $this->get_post_meta( $object->ID, '_audioigniter_allow_track_listing_toggle', 1 );
660 $track_listing_allow_loop = $this->get_post_meta( $object->ID, '_audioigniter_allow_track_listing_loop', 1 );
661 $credit = $this->get_post_meta( $object->ID, '_audioigniter_show_credit', 0 );
662 $limit_tracklisting_height = $this->get_post_meta( $object->ID, '_audioigniter_limit_tracklisting_height', 1 );
663 $tracklisting_height = $this->get_post_meta( $object->ID, '_audioigniter_tracklisting_height', 185 );
664 $volume = $this->get_post_meta( $object->ID, '_audioigniter_volume', 100 );
665 $max_width = $this->get_post_meta( $object->ID, '_audioigniter_max_width' );
666
667 wp_nonce_field( basename( __FILE__ ), $object->post_type . '_nonce' );
668 ?>
669 <div class="ai-module ai-module-settings">
670 <div class="ai-form-field-group">
671 <h3 class="ai-form-field-group-title"><?php esc_html_e( 'Player &amp; Track listing', 'audioigniter' ); ?></h3>
672
673 <div class="ai-form-field">
674 <div class="ai-player-type-message ai-info-box"></div>
675 <label for="_audioigniter_player_type">
676 <?php esc_html_e( 'Player Type', 'audioigniter' ); ?>
677 </label>
678
679 <select
680 class="widefat ai-form-select-player-type"
681 id="_audioigniter_player_type"
682 name="_audioigniter_player_type"
683 >
684 <?php foreach ( $this->get_player_types() as $player_key => $player_type ) : ?>
685 <option
686 value="<?php echo esc_attr( $player_key ); ?>"
687 data-no-support="<?php echo esc_attr( implode( ', ', $player_type['no-support'] ) ); ?>"
688 data-info="<?php echo esc_attr( $player_type['info'] ); ?>"
689 <?php selected( $type, $player_key ); ?>
690 >
691 <?php echo wp_kses( $player_type['label'], 'strip' ); ?>
692 </option>
693 <?php endforeach; ?>
694 </select>
695 </div>
696
697 <div class="ai-form-field">
698 <input
699 type="checkbox"
700 class="ai-checkbox"
701 id="_audioigniter_show_track_listing"
702 name="_audioigniter_show_track_listing"
703 value="1" <?php checked( $track_listing, true ); ?>
704 />
705
706 <label for="_audioigniter_show_track_listing">
707 <?php esc_html_e( 'Show track listing by default', 'audioigniter' ); ?>
708 </label>
709 </div>
710
711 <div class="ai-form-field">
712 <input
713 type="checkbox"
714 class="ai-checkbox"
715 id="_audioigniter_allow_track_listing_toggle"
716 name="_audioigniter_allow_track_listing_toggle"
717 value="1" <?php checked( $track_listing_allow_toggle, true ); ?>
718 />
719
720 <label for="_audioigniter_allow_track_listing_toggle">
721 <?php esc_html_e( 'Show track listing visibility toggle button', 'audioigniter' ); ?>
722 </label>
723 </div>
724
725 <div class="ai-form-field">
726 <input
727 type="checkbox"
728 class="ai-checkbox"
729 id="_audioigniter_show_numbers_revese"
730 name="_audioigniter_show_numbers_reverse"
731 value="1" <?php checked( $numbers_reverse, true ); ?>
732 />
733
734 <label for="_audioigniter_show_numbers_revese">
735 <?php esc_html_e( 'Reverse track order', 'audioigniter' ); ?>
736 </label>
737 </div>
738
739 <div class="ai-form-field">
740 <label for="_audioigniter_volume">
741 <?php esc_html_e( 'Starting volume', 'audioigniter' ); ?>
742 </label>
743
744 <input
745 type="number"
746 min="0"
747 max="100"
748 step="10"
749 id="_audioigniter_volume"
750 class="ai-track-title"
751 name="_audioigniter_volume"
752 placeholder="<?php esc_attr_e( '0-100', 'audioigniter' ); ?>"
753 value="<?php echo esc_attr( $volume ); ?>"
754 />
755
756 <p class="ai-field-help">
757 <?php esc_html_e( 'Enter a value between 0 and 100 in increments of 10', 'audioigniter' ); ?>
758 </p>
759 </div>
760
761 <div class="ai-form-field">
762 <input
763 type="checkbox"
764 class="ai-checkbox"
765 id="_audioigniter_limit_tracklisting_height"
766 name="_audioigniter_limit_tracklisting_height"
767 value="1" <?php checked( $limit_tracklisting_height, true ); ?>
768 />
769
770 <label for="_audioigniter_limit_tracklisting_height">
771 <?php esc_html_e( 'Limit track listing height', 'audioigniter' ); ?>
772 </label>
773 </div>
774
775 <div class="ai-form-field">
776 <label for="_audioigniter_tracklisting_height">
777 <?php esc_html_e( 'Track listing height', 'audioigniter' ); ?>
778 </label>
779
780 <input
781 type="number"
782 min="10"
783 step="5"
784 id="_audioigniter_tracklisting_height"
785 class="ai-track-title"
786 name="_audioigniter_tracklisting_height"
787 placeholder="<?php esc_attr_e( 'Track listing height', 'audioigniter' ); ?>"
788 value="<?php echo esc_attr( $tracklisting_height ); ?>"
789 />
790
791 <p class="ai-field-help">
792 <?php esc_html_e( 'Set a number of pixels', 'audioigniter' ); ?>
793 </p>
794 </div>
795
796 <div class="ai-form-field">
797 <label for="_audioigniter_max_width">
798 <?php esc_html_e( 'Maximum player width', 'audioigniter' ); ?>
799 </label>
800
801 <input
802 type="number"
803 id="_audioigniter_max_width"
804 class="ai-track-title"
805 name="_audioigniter_max_width"
806 placeholder="<?php esc_attr_e( 'Automatic width', 'audioigniter' ); ?>"
807 value="<?php echo esc_attr( $max_width ); ?>"
808 />
809
810 <p class="ai-field-help">
811 <?php esc_html_e( 'Set a number of pixels, or leave empty to automatically cover 100% of the available area (recommended).', 'audioigniter' ); ?>
812 </p>
813 </div>
814
815 <?php do_action( 'audioigniter_metabox_settings_group_player_track_listing_fields', $object, $box ); ?>
816 </div>
817
818 <div class="ai-form-field-group">
819 <h3 class="ai-form-field-group-title"><?php esc_html_e( 'Tracks', 'audioigniter' ); ?></h3>
820
821 <div class="ai-form-field">
822 <input
823 type="checkbox"
824 class="ai-checkbox"
825 id="_audioigniter_show_numbers"
826 name="_audioigniter_show_numbers"
827 value="1" <?php checked( $numbers, true ); ?>
828 />
829
830 <label for="_audioigniter_show_numbers">
831 <?php esc_html_e( 'Show track numbers in tracklist', 'audioigniter' ); ?>
832 </label>
833 </div>
834
835 <div class="ai-form-field">
836 <input
837 type="checkbox"
838 class="ai-checkbox"
839 id="_audioigniter_show_covers"
840 name="_audioigniter_show_covers"
841 value="1" <?php checked( $thumb, true ); ?>
842 />
843
844 <label for="_audioigniter_show_covers">
845 <?php esc_html_e( 'Show track covers in tracklist', 'audioigniter' ); ?>
846 </label>
847 </div>
848
849 <div class="ai-form-field">
850 <input
851 type="checkbox"
852 class="ai-checkbox"
853 id="_audioigniter_show_active_cover"
854 name="_audioigniter_show_active_cover"
855 value="1" <?php checked( $active_thumb, true ); ?>
856 />
857
858 <label for="_audioigniter_show_active_cover">
859 <?php esc_html_e( "Show active track's cover", 'audioigniter' ); ?>
860 </label>
861 </div>
862
863 <div class="ai-form-field">
864 <input
865 type="checkbox"
866 class="ai-checkbox"
867 id="_audioigniter_show_artist"
868 name="_audioigniter_show_artist"
869 value="1" <?php checked( $artist, true ); ?>
870 />
871
872 <label for="_audioigniter_show_artist">
873 <?php esc_html_e( 'Show artist names', 'audioigniter' ); ?>
874 </label>
875 </div>
876
877 <div class="ai-form-field">
878 <input
879 type="checkbox"
880 class="ai-checkbox"
881 id="_audioigniter_show_buy_links"
882 name="_audioigniter_show_buy_links"
883 value="1" <?php checked( $buy_links, true ); ?>
884 />
885
886 <label for="_audioigniter_show_buy_links">
887 <?php esc_html_e( 'Show track extra buttons (buy link, download button etc)', 'audioigniter' ); ?>
888 </label>
889 </div>
890
891 <div class="ai-form-field">
892 <input
893 type="checkbox"
894 class="ai-checkbox"
895 id="_audioigniter_buy_links_new_target"
896 name="_audioigniter_buy_links_new_target"
897 value="1" <?php checked( $buy_links_new_target, true ); ?>
898 />
899
900 <label for="_audioigniter_buy_links_new_target">
901 <?php esc_html_e( 'Open buy links in new window', 'audioigniter' ); ?>
902 </label>
903 </div>
904
905 <?php do_action( 'audioigniter_metabox_settings_group_tracks_fields', $object, $box ); ?>
906 </div>
907
908 <div class="ai-form-field-group">
909 <h3 class="ai-form-field-group-title"><?php esc_html_e( 'Track &amp; Track listing repeat', 'audioigniter' ); ?></h3>
910
911 <div class="ai-form-field">
912 <input
913 type="checkbox"
914 class="ai-checkbox"
915 id="_audioigniter_cycle_tracks"
916 name="_audioigniter_cycle_tracks"
917 value="1" <?php checked( $cycle_tracks, true ); ?>
918 />
919
920 <label for="_audioigniter_cycle_tracks">
921 <?php esc_html_e( 'Repeat track listing enabled by default', 'audioigniter' ); ?>
922 </label>
923 </div>
924
925 <div class="ai-form-field">
926 <input
927 type="checkbox"
928 class="ai-checkbox"
929 id="_audioigniter_allow_track_listing_loop"
930 name="_audioigniter_allow_track_listing_loop"
931 value="1" <?php checked( $track_listing_allow_loop, true ); ?>
932 />
933
934 <label for="_audioigniter_allow_track_listing_loop">
935 <?php esc_html_e( 'Show track listing repeat toggle button', 'audioigniter' ); ?>
936 </label>
937 </div>
938
939 <?php do_action( 'audioigniter_metabox_settings_group_player_track_track_listing_repeat_fields', $object, $box ); ?>
940 </div>
941
942 <div class="ai-form-field">
943 <input
944 type="checkbox"
945 class="ai-checkbox"
946 id="_audioigniter_show_credit"
947 name="_audioigniter_show_credit"
948 value="1" <?php checked( $credit, true ); ?>
949 />
950
951 <label for="_audioigniter_show_credit">
952 <?php esc_html_e( 'Show "Powered by AudioIgniter" link', 'audioigniter' ); ?>
953 </label>
954
955 <p class="ai-field-help">
956 <?php esc_html_e( "We've put a great deal of effort into building this plugin. If you feel like it, let others know about it by enabling this option.", 'audioigniter' ); ?>
957 </p>
958 </div>
959 </div>
960 <?php
961 }
962
963 /**
964 * Echoes the Shortcode metabox markup.
965 *
966 * @since 1.0.0
967 *
968 * @param WP_Post $object
969 * @param array $box
970 */
971 public function metabox_shortcode( $object, $box ) {
972 ?>
973 <div class="ai-module ai-module-shortcode">
974 <div class="ai-form-field">
975 <label for="ai_shortcode">
976 <?php esc_html_e( 'Grab the shortcode', 'audioigniter' ); ?>
977 </label>
978
979 <input
980 type="text"
981 class="code"
982 id="ai_shortcode"
983 name="ai_shortcode"
984 value="<?php echo esc_attr( sprintf( '[ai_playlist id="%s"]', $object->ID ) ); ?>"
985 />
986
987 </div>
988 </div>
989 <?php
990 }
991
992 /**
993 * Returns the available player types and their data.
994 *
995 * @version 1.4.0
996 * @since 1.4.0
997 *
998 * @return array
999 */
1000 public function get_player_types() {
1001 // Each player type has a number of settings that it might not support
1002 // E.g. "Simple Player" does not support track listing visibility, covers
1003 // and others. Provide every setting that's not supported based on the `name`
1004 // attribute of each setting input (input, select, textarea), *without
1005 // the _audioigniter_ prefix* in the `no-support` array.
1006 // To allow support for every setting simply set `no-support` to an empty array.
1007
1008 $player_types = array(
1009 'full' => array(
1010 'label' => __( 'Full Player', 'audioigniter' ),
1011 'no-support' => array(),
1012 'info' => '',
1013 ),
1014 'simple' => array(
1015 'label' => __( 'Simple Player', 'audioigniter' ),
1016 'no-support' => array(
1017 'show_track_listing',
1018 'show_covers',
1019 'show_active_cover',
1020 'limit_tracklisting_height',
1021 'tracklisting_height',
1022 'allow_track_listing_loop',
1023 'allow_track_listing_toggle',
1024 'skip_amount',
1025 ),
1026 'info' => '',
1027 ),
1028 );
1029
1030 return apply_filters( 'audioigniter_player_types', $player_types );
1031 }
1032
1033 public function save_post( $post_id ) {
1034 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return false; }
1035 if ( isset( $_POST['post_view'] ) && 'list' === $_POST['post_view'] ) { return false; }
1036 if ( ! isset( $_POST['post_type'] ) || $_POST['post_type'] !== $this->post_type ) { return false; }
1037 if ( ! isset( $_POST[ $this->post_type . '_nonce' ] ) || ! wp_verify_nonce( $_POST[ $this->post_type . '_nonce' ], basename( __FILE__ ) ) ) { return false; }
1038 $post_type_obj = get_post_type_object( $this->post_type );
1039 if ( ! current_user_can( $post_type_obj->cap->edit_post, $post_id ) ) { return false; }
1040
1041 update_post_meta( $post_id, '_audioigniter_tracks', $this->sanitizer->metabox_playlist( $_POST['ai_playlist_tracks'], $post_id ) );
1042
1043 update_post_meta( $post_id, '_audioigniter_show_numbers', $this->sanitizer->checkbox_ref( $_POST['_audioigniter_show_numbers'] ) );
1044 update_post_meta( $post_id, '_audioigniter_show_numbers_reverse', $this->sanitizer->checkbox_ref( $_POST['_audioigniter_show_numbers_reverse'] ) );
1045 update_post_meta( $post_id, '_audioigniter_show_covers', $this->sanitizer->checkbox_ref( $_POST['_audioigniter_show_covers'] ) );
1046 update_post_meta( $post_id, '_audioigniter_show_active_cover', $this->sanitizer->checkbox_ref( $_POST['_audioigniter_show_active_cover'] ) );
1047 update_post_meta( $post_id, '_audioigniter_show_artist', $this->sanitizer->checkbox_ref( $_POST['_audioigniter_show_artist'] ) );
1048 update_post_meta( $post_id, '_audioigniter_show_buy_links', $this->sanitizer->checkbox_ref( $_POST['_audioigniter_show_buy_links'] ) );
1049 update_post_meta( $post_id, '_audioigniter_buy_links_new_target', $this->sanitizer->checkbox_ref( $_POST['_audioigniter_buy_links_new_target'] ) );
1050 update_post_meta( $post_id, '_audioigniter_cycle_tracks', $this->sanitizer->checkbox_ref( $_POST['_audioigniter_cycle_tracks'] ) );
1051 update_post_meta( $post_id, '_audioigniter_show_track_listing', $this->sanitizer->checkbox_ref( $_POST['_audioigniter_show_track_listing'] ) );
1052 update_post_meta( $post_id, '_audioigniter_allow_track_listing_toggle', $this->sanitizer->checkbox_ref( $_POST['_audioigniter_allow_track_listing_toggle'] ) );
1053 update_post_meta( $post_id, '_audioigniter_allow_track_listing_loop', $this->sanitizer->checkbox_ref( $_POST['_audioigniter_allow_track_listing_loop'] ) );
1054 update_post_meta( $post_id, '_audioigniter_player_type', $this->sanitizer->player_type( $_POST['_audioigniter_player_type'] ) );
1055 update_post_meta( $post_id, '_audioigniter_show_credit', $this->sanitizer->checkbox_ref( $_POST['_audioigniter_show_credit'] ) );
1056 update_post_meta( $post_id, '_audioigniter_limit_tracklisting_height', $this->sanitizer->checkbox_ref( $_POST['_audioigniter_limit_tracklisting_height'] ) );
1057 update_post_meta( $post_id, '_audioigniter_tracklisting_height', intval( $_POST['_audioigniter_tracklisting_height'] ) );
1058 update_post_meta( $post_id, '_audioigniter_volume', intval( $_POST['_audioigniter_volume'] ) );
1059 update_post_meta( $post_id, '_audioigniter_max_width', $this->sanitizer->intval_or_empty( $_POST['_audioigniter_max_width'] ) );
1060
1061 /**
1062 * @since 1.4.0
1063 */
1064 do_action( 'audioigniter_save_post', $post_id );
1065 }
1066
1067 public static function get_default_track_values() {
1068 return apply_filters( 'audioigniter_default_track_values', array(
1069 'cover_id' => '',
1070 'title' => '',
1071 'artist' => '',
1072 'track_url' => '',
1073 'buy_link' => '',
1074 'download_url' => '',
1075 ) );
1076 }
1077
1078 public function register_image_sizes() {
1079 add_image_size( 'audioigniter_cover', 560, 560, true );
1080 }
1081
1082 public function register_widgets() {
1083 $widgets = apply_filters( 'audioigniter_register_widgets', array() );
1084
1085 foreach ( $widgets as $class => $file ) {
1086 require_once( $file );
1087 register_widget( $class );
1088 }
1089 }
1090
1091 public function register_shortcodes() {
1092 add_shortcode( 'ai_playlist', array( $this, 'shortcode_ai_playlist' ) );
1093 }
1094
1095 /**
1096 * Checks whether passed post object or ID is an AudioIgniter playlist.
1097 *
1098 * @version 1.4.0
1099 * @since 1.4.0
1100 *
1101 * @param int|WP_Post $post Post ID or post object.
1102 *
1103 * @return bool
1104 */
1105 public function is_playlist( $post ) {
1106 $post = get_post( $post );
1107
1108 if ( is_wp_error( $post ) || empty( $post ) || is_null( $post ) || $post->post_type !== $this->post_type ) {
1109 return false;
1110 }
1111
1112 return true;
1113 }
1114
1115 /**
1116 * Returns a data attributes array for the given playlist.
1117 *
1118 * @version 1.4.0
1119 * @since 1.4.0
1120 *
1121 * @param int $post_id Post ID.
1122 *
1123 * @return array
1124 */
1125 public function get_playlist_data_attributes_array( $post_id ) {
1126 $post_id = intval( $post_id );
1127
1128 if ( ! $this->is_playlist( $post_id ) ) {
1129 return array();
1130 }
1131
1132 $attrs = array(
1133 'data-player-type' => $this->get_post_meta( $post_id, '_audioigniter_player_type', 'full' ),
1134 'data-tracks-url' => add_query_arg( array( 'audioigniter_playlist_id' => $post_id ), home_url( '/' ) ),
1135 'data-display-track-no' => $this->convert_bool_string( $this->get_post_meta( $post_id, '_audioigniter_show_numbers', 1 ) ),
1136 'data-reverse-track-order' => $this->convert_bool_string( $this->get_post_meta( $post_id, '_audioigniter_show_numbers_reverse', 0 ) ),
1137 'data-display-tracklist-covers' => $this->convert_bool_string( $this->get_post_meta( $post_id, '_audioigniter_show_covers', 1 ) ),
1138 'data-display-active-cover' => $this->convert_bool_string( $this->get_post_meta( $post_id, '_audioigniter_show_active_cover', 1 ) ),
1139 'data-display-artist-names' => $this->convert_bool_string( $this->get_post_meta( $post_id, '_audioigniter_show_artist', 1 ) ),
1140 'data-display-buy-buttons' => $this->convert_bool_string( $this->get_post_meta( $post_id, '_audioigniter_show_buy_links', 1 ) ),
1141 'data-buy-buttons-target' => $this->convert_bool_string( $this->get_post_meta( $post_id, '_audioigniter_buy_links_new_target', 1 ) ),
1142 'data-cycle-tracks' => $this->convert_bool_string( $this->get_post_meta( $post_id, '_audioigniter_cycle_tracks', 0 ) ),
1143 'data-display-credits' => $this->convert_bool_string( $this->get_post_meta( $post_id, '_audioigniter_show_credit', 1 ) ),
1144 'data-display-tracklist' => $this->convert_bool_string( $this->get_post_meta( $post_id, '_audioigniter_show_track_listing', 1 ) ),
1145 'data-allow-tracklist-toggle' => $this->convert_bool_string( $this->get_post_meta( $post_id, '_audioigniter_allow_track_listing_toggle', 1 ) ),
1146 'data-allow-tracklist-loop' => $this->convert_bool_string( $this->get_post_meta( $post_id, '_audioigniter_allow_track_listing_loop', 1 ) ),
1147 'data-limit-tracklist-height' => $this->convert_bool_string( $this->get_post_meta( $post_id, '_audioigniter_limit_tracklisting_height', 1 ) ),
1148 'data-volume' => intval( $this->get_post_meta( $post_id, '_audioigniter_volume', 100 ) ),
1149 'data-tracklist-height' => intval( $this->get_post_meta( $post_id, '_audioigniter_tracklisting_height', 185 ) ),
1150 'data-max-width' => $this->get_post_meta( $post_id, '_audioigniter_max_width' ),
1151 );
1152
1153 return apply_filters( 'audioigniter_get_playlist_data_attributes_array', $attrs, $post_id );
1154 }
1155
1156 /**
1157 * Returns the output of the [ai_playlist] shortcode.
1158 *
1159 * @version 1.4.0
1160 * @since 1.0.0
1161 *
1162 * @param array $atts The shortcode attributes.
1163 * @param string|null $content Content, when used with a shortcode closing tag.
1164 * @param string $tag The shortcode name used to reach this function.
1165 *
1166 * @return string
1167 */
1168 public function shortcode_ai_playlist( $atts, $content = null, $tag ) {
1169 $atts = shortcode_atts( array(
1170 'id' => '',
1171 ), $atts, $tag );
1172
1173 $id = intval( $atts['id'] );
1174
1175 if ( ! $this->is_playlist( $id ) ) {
1176 return '';
1177 }
1178
1179 $post = get_post( $id );
1180
1181 $params = apply_filters( 'audioigniter_shortcode_data_attributes_array', $this->get_playlist_data_attributes_array( $id ), $id, $post );
1182 $params = array_filter( $params, array( $this->sanitizer, 'array_filter_empty_null' ) );
1183 $params = $this->sanitizer->html_data_attributes_array( $params );
1184
1185 // Returning a truthy value from the filter, will short-circuit execution of the shortcode.
1186 if ( false !== apply_filters( 'audioigniter_shortcode_shortcircuit', false, $id, $post, $params ) ) {
1187 return '';
1188 }
1189
1190 $data = '';
1191 foreach ( $params as $attribute => $value ) {
1192 $data .= sprintf( '%s="%s" ', sanitize_key( $attribute ), esc_attr( $value ) );
1193 }
1194
1195 $output = sprintf( '<div id="audioigniter-%s" class="audioigniter-root" %s></div>',
1196 esc_attr( $id ),
1197 $data
1198 );
1199
1200 return $output;
1201 }
1202
1203 public function convert_bool_string( $value ) {
1204 if ( $value ) {
1205 return 'true';
1206 }
1207
1208 return 'false';
1209 }
1210
1211 public function register_playlist_endpoint() {
1212 add_rewrite_tag( '%audioigniter_playlist_id%', '([0-9]+)' );
1213 add_rewrite_rule( '^audioigniter/playlist/([0-9]+)/?', 'index.php?audioigniter_playlist_id=$matches[1]', 'bottom' );
1214 }
1215
1216 public function handle_playlist_endpoint() {
1217 global $wp_query;
1218
1219 $playlist_id = $wp_query->get( 'audioigniter_playlist_id' );
1220
1221 if ( empty( $playlist_id ) ) {
1222 return;
1223 }
1224
1225 $playlist_id = intval( $playlist_id );
1226 $post = get_post( $playlist_id );
1227
1228 if ( empty( $post ) || $post->post_type !== $this->post_type ) {
1229 wp_send_json_error( __( "ID doesn't match a playlist", 'audioigniter' ) );
1230 }
1231
1232 $response = array();
1233 $tracks = $this->get_post_meta( $playlist_id, '_audioigniter_tracks', array() );
1234
1235 foreach ( $tracks as $track ) {
1236 $track = wp_parse_args( $track, self::get_default_track_values() );
1237 $track_response = array();
1238
1239 $track_response['title'] = $track['title'];
1240 $track_response['subtitle'] = $track['artist'];
1241 $track_response['audio'] = $track['track_url'];
1242 $track_response['buyUrl'] = $track['buy_link'];
1243 $track_response['downloadUrl'] = $track['download_url'];
1244
1245 $cover_url = wp_get_attachment_image_src( intval( $track['cover_id'] ), 'audioigniter_cover' );
1246 if ( ! empty( $cover_url[0] ) ) {
1247 $cover_url = $cover_url[0];
1248 } else {
1249 $cover_url = '';
1250 }
1251
1252 $track_response['cover'] = $cover_url;
1253
1254 $track_response = apply_filters( 'audioigniter_playlist_endpoint_track', $track_response, $track, $playlist_id, $post );
1255
1256 $response[] = $track_response;
1257 }
1258
1259 wp_send_json( $response );
1260 }
1261
1262
1263 public function get_all_playlists( $orderby = 'date', $order = 'DESC' ) {
1264 $q = new WP_Query( array(
1265 'post_type' => $this->post_type,
1266 'posts_per_page' => - 1,
1267 'orderby' => $orderby,
1268 'order' => $order,
1269 ) );
1270
1271 return $q->posts;
1272 }
1273
1274 public function get_post_meta( $post_id, $key, $default = '' ) {
1275 $keys = get_post_custom_keys( $post_id );
1276
1277 $value = $default;
1278
1279 if ( is_array( $keys ) && in_array( $key, $keys, true ) ) {
1280 $value = get_post_meta( $post_id, $key, true );
1281 }
1282
1283 return $value;
1284 }
1285
1286 public function plugin_activated() {
1287 if ( ! current_user_can( 'activate_plugins' ) ) {
1288 return;
1289 }
1290
1291 $this->register_post_types();
1292
1293 do_action( 'audioigniter_activated' );
1294
1295 flush_rewrite_rules();
1296 }
1297
1298 public function plugin_deactivated() {
1299 if ( ! current_user_can( 'activate_plugins' ) ) {
1300 return;
1301 }
1302
1303 unregister_post_type( $this->post_type );
1304
1305 do_action( 'audioigniter_deactivated' );
1306
1307 flush_rewrite_rules();
1308 }
1309
1310 public static function plugin_basename() {
1311 return plugin_basename( __FILE__ );
1312 }
1313
1314 public function plugin_url() {
1315 return self::$plugin_url;
1316 }
1317
1318 public function plugin_path() {
1319 return self::$plugin_path;
1320 }
1321 }
1322
1323
1324 /**
1325 * Main instance of AudioIgniter.
1326 *
1327 * Returns the working instance of AudioIgniter. No need for globals.
1328 *
1329 * @since 1.0.0
1330 * @return AudioIgniter
1331 */
1332 function AudioIgniter() {
1333 return AudioIgniter::instance();
1334 }
1335
1336 add_action( 'plugins_loaded', array( AudioIgniter(), 'plugin_setup' ) );
1337 register_activation_hook( __FILE__, array( AudioIgniter(), 'plugin_activated' ) );
1338 register_deactivation_hook( __FILE__, array( AudioIgniter(), 'plugin_deactivated' ) );
1339