PluginProbe
AudioIgniter Music Player / 1.5.0
AudioIgniter Music Player v1.5.0
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.5.0, at audioigniter.php

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