PluginProbe
AudioIgniter Music Player / 1.1.0
AudioIgniter Music Player v1.1.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.1.0, at audioigniter.php

1,094 lines 35.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: 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.1.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.1.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-admin', 'ai_scripts', array(
202 'messages' => array(
203 'confirm_clear_tracks' => esc_html__( 'Do you really want to remove all tracks? (This will not delete your audio files).', 'audioigniter' ),
204 'media_title_upload' => esc_html__( 'Select or upload audio media', 'audioigniter' ),
205 'media_title_upload_cover' => esc_html__( 'Select a cover image', 'audioigniter' ),
206 ),
207 ) );
208 }
209
210 /**
211 * Enqueues frontend scripts and styles.
212 *
213 * @since 1.0.0
214 */
215 public function enqueue_scripts() {
216 wp_enqueue_style( 'audioigniter' );
217 wp_enqueue_script( 'audioigniter' );
218 }
219
220 /**
221 * Enqueues admin scripts and styles.
222 *
223 * @since 1.0.0
224 */
225 public function enqueue_admin_scripts( $hook ) {
226 $screen = get_current_screen();
227
228 if ( 'post' === $screen->base && $screen->post_type === $this->post_type ) {
229 wp_enqueue_media();
230 wp_enqueue_style( 'audioigniter-admin' );
231 wp_enqueue_script( 'audioigniter-admin' );
232 }
233 }
234
235 /**
236 * Post types registration.
237 *
238 * @since 1.0.0
239 */
240 public function register_post_types() {
241 $labels = array(
242 'name' => esc_html_x( 'Playlists', 'post type general name', 'audioigniter' ),
243 'singular_name' => esc_html_x( 'Playlist', 'post type singular name', 'audioigniter' ),
244 'menu_name' => esc_html_x( 'Playlists', 'admin menu', 'audioigniter' ),
245 'name_admin_bar' => esc_html_x( 'Playlist', 'add new on admin bar', 'audioigniter' ),
246 'add_new' => esc_html__( 'Add New Playlist', 'audioigniter' ),
247 'add_new_item' => esc_html__( 'Add New Playlist', 'audioigniter' ),
248 'edit_item' => esc_html__( 'Edit Playlist', 'audioigniter' ),
249 'new_item' => esc_html__( 'New Playlist', 'audioigniter' ),
250 'view_item' => esc_html__( 'View Playlist', 'audioigniter' ),
251 'search_items' => esc_html__( 'Search Playlists', 'audioigniter' ),
252 'not_found' => esc_html__( 'No playlists found', 'audioigniter' ),
253 'not_found_in_trash' => esc_html__( 'No playlists found in the trash', 'audioigniter' ),
254 );
255
256 $args = array(
257 'labels' => $labels,
258 'singular_label' => esc_html_x( 'Playlist', 'post type singular name', 'audioigniter' ),
259 'public' => false,
260 'show_ui' => true,
261 'capability_type' => 'post',
262 'hierarchical' => false,
263 'has_archive' => false,
264 'supports' => array( 'title' ),
265 'menu_icon' => 'dashicons-controls-volumeon',
266 );
267
268 register_post_type( $this->post_type, $args );
269 }
270
271
272 /**
273 * Registers metaboxes for the ai_playlist post type.
274 *
275 * @since 1.0.0
276 */
277 public function add_meta_boxes() {
278 add_meta_box( 'ai-meta-box-tracks', esc_html__( 'Tracks', 'audioigniter' ), array( $this, 'metabox_tracks' ), $this->post_type, 'normal', 'high' );
279 add_meta_box( 'ai-meta-box-settings', esc_html__( 'Settings', 'audioigniter' ), array( $this, 'metabox_settings' ), $this->post_type, 'normal', 'high' );
280 add_meta_box( 'ai-meta-box-shortcode', esc_html__( 'Shortcode', 'audioigniter' ), array( $this, 'metabox_shortcode' ), $this->post_type, 'normal', 'high' );
281 }
282
283 /**
284 * Echoes the Tracks metabox markup.
285 *
286 * @since 1.0.0
287 *
288 * @param WP_Post $object
289 * @param array $box
290 */
291 public function metabox_tracks( $object, $box ) {
292 $tracks = $this->get_post_meta( $object->ID, '_audioigniter_tracks', array() );
293
294 wp_nonce_field( basename( __FILE__ ), $object->post_type . '_nonce' );
295 ?>
296
297 <?php $this->metabox_tracks_header(); ?>
298
299 <div class="ai-container">
300 <?php $this->metabox_tracks_field_controls(); ?>
301
302 <?php $container_classes = apply_filters( 'audioigniter_metabox_tracks_container_classes', array( 'ai-fields-container' ) ); ?>
303
304 <div class="<?php echo esc_attr( implode( ' ', $container_classes ) ); ?>">
305 <?php
306 if ( ! empty( $tracks ) ) {
307 foreach ( $tracks as $track ) {
308 $this->metabox_tracks_repeatable_track_field( $track );
309 }
310 } else {
311 $this->metabox_tracks_repeatable_track_field();
312 }
313 ?>
314 </div>
315
316 <?php $this->metabox_tracks_field_controls(); ?>
317 </div>
318
319 <?php $this->metabox_tracks_footer(); ?>
320
321 <input type="hidden" name="ai_nonce" id="ai_nonce" value="<?php echo esc_attr( wp_create_nonce( self::plugin_basename() ) ); ?>"/>
322 <?php
323 }
324
325
326 /**
327 * Echoes the Tracks metabox header.
328 *
329 * @since 1.0.0
330 */
331 protected function metabox_tracks_header() {
332 ?>
333 <div class="ai-header ai-brand-module">
334 <div class="ai-row">
335 <div class="ai-col-left">
336 <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">
337 <img
338 src="<?php echo esc_url( $this->plugin_url() . 'assets/images/logo.svg' ); ?>"
339 alt="<?php esc_attr_e( 'AudioIgniter Logo', 'audioigniter' ); ?>"
340 >
341 </a>
342 </div>
343
344 <?php if ( apply_filters( 'audioigniter_metabox_tracks_show_upgrade_button', true ) ) : ?>
345 <div class="ai-col-right">
346 <div class="ai-brand-module-actions">
347 <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">
348 <?php esc_html_e( 'Upgrade to Pro', 'audioigniter' ); ?>
349 </a>
350 </div>
351 </div>
352 <?php endif; ?>
353 </div>
354 </div>
355 <?php
356 }
357
358 /**
359 * Echoes the Tracks metabox footer.
360 *
361 * @since 1.0.0
362 */
363 protected function metabox_tracks_footer() {
364 ?>
365 <div class="ai-footer ai-brand-module">
366 <div class="ai-row">
367 <div class="ai-col-left">
368 <ul class="ai-list-inline">
369 <?php
370 $links = apply_filters( 'audioigniter_metabox_tracks_footer_links', array(
371 'support' => array(
372 'title' => __( 'Support', 'audioigniter' ),
373 'url' => 'https://wordpress.org/support/plugin/audioigniter',
374 ),
375 'documentation' => array(
376 'title' => __( 'Documentation', 'audioigniter' ),
377 'url' => 'https://www.cssigniter.com/docs/audioigniter/',
378 ),
379 'rate_plugin' => array(
380 'title' => __( 'Rate this plugin', 'audioigniter' ),
381 'url' => 'https://wordpress.org/support/view/plugin-reviews/audioigniter',
382 ),
383 ) );
384
385 foreach ( $links as $link ) {
386 if ( empty( $link['url'] ) || empty( $link['title'] ) ) {
387 continue;
388 }
389
390 echo sprintf( '<li><a href="%s" target="_blank">%s</a></li>',
391 esc_url( $link['url'] ),
392 esc_html( $link['title'] )
393 );
394 }
395 ?>
396 </ul>
397 </div>
398
399 <div class="ai-col-right">
400 <?php
401 $url = 'https://www.cssigniter.com/ignite/plugins/audioigniter?utm_source=dashboard&utm_medium=link&utm_content=audioigniter&utm_campaign=footer-link';
402 $copy = sprintf( __( 'Thank you for creating with <a href="%s" target="_blank">AudioIgniter</a>', 'audioigniter' ),
403 esc_url( $url )
404 );
405 ?>
406 <div class="ai-brand-module-actions">
407 <p class="ai-note"><?php echo wp_kses( $copy, array( 'a' => array( 'href' => true, 'target' => true ) ) ); ?></p>
408 </div>
409 </div>
410 </div>
411 </div>
412 <?php
413 }
414
415 protected function metabox_tracks_repeatable_track_field( $track = array() ) {
416 $track = wp_parse_args( $track, self::get_default_track_values() );
417
418 $cover_id = $track['cover_id'];
419 $title = $track['title'];
420 $artist = $track['artist'];
421 $track_url = $track['track_url'];
422 $buy_link = $track['buy_link'];
423
424 $cover_url = wp_get_attachment_image_src( intval( $cover_id ), 'thumbnail' );
425 if ( ! empty( $cover_url[0] ) ) {
426 $cover_url = $cover_url[0];
427 $cover_data = wp_prepare_attachment_for_js( intval( $cover_id ) );
428 } else {
429 $cover_url = '';
430 $cover_data = '';
431 }
432
433 $uid = uniqid();
434
435 $field_classes = apply_filters( 'audioigniter_metabox_track_classes', array( 'ai-field-repeatable' ), $track_url );
436 ?>
437 <div class="<?php echo esc_attr( implode( ' ', $field_classes ) ); ?>" data-uid="<?php echo esc_attr( $uid ); ?>">
438 <div class="ai-field-head">
439
440 <?php do_action( 'audioigniter_metabox_tracks_repeatable_track_field_before_title' ); ?>
441
442 <span class="ai-field-title"><?php echo wp_kses( $title, array() ); ?></span>
443
444 <button type="button" class="ai-field-toggle button-link">
445 <span class="screen-reader-text">
446 <?php esc_html_e( 'Toggle track visibility', 'audioigniter' ); ?>
447 </span>
448 <span class="toggle-indicator"></span>
449 </button>
450 </div>
451
452 <div class="ai-field-container">
453 <div class="ai-field-cover">
454 <a href="#" class="ai-field-upload-cover <?php echo ! empty( $cover_url ) ? 'ai-has-cover' : ''; ?>">
455 <span class="ai-remove-cover">
456 <span class="screen-reader-text">
457 <?php esc_html_e( 'Remove Cover Image', 'audioigniter' ); ?>
458 </span>
459 <span class="dashicons dashicons-no-alt"></span>
460 </span>
461
462 <?php if ( ! empty( $cover_url ) ) : ?>
463 <img src="<?php echo esc_url( $cover_url ); ?>" alt="<?php echo esc_attr( $cover_data['alt'] ); ?>">
464 <?php else : ?>
465 <img src="#" alt="">
466 <?php endif; ?>
467
468 <div class="ai-field-cover-placeholder">
469 <span class="ai-cover-prompt">
470 <?php esc_html_e( 'Upload Cover', 'audioigniter' ); ?>
471 </span>
472 </div>
473 </a>
474
475 <input
476 type="hidden"
477 id="ai_playlist_tracks-<?php echo esc_attr( $uid ); ?>-cover_id"
478 name="ai_playlist_tracks[<?php echo esc_attr( $uid ); ?>][cover_id]"
479 value="<?php echo esc_attr( $cover_id ); ?>"
480 />
481 </div>
482
483 <div class="ai-field-split">
484 <div class="ai-form-field">
485 <label
486 for="ai_playlist_tracks-<?php echo esc_attr( $uid ); ?>-title"
487 class="screen-reader-text">
488 <?php esc_html_e( 'Title', 'audioigniter' ); ?>
489 </label>
490 <input
491 type="text"
492 id="ai_playlist_tracks-<?php echo esc_attr( $uid ); ?>-title"
493 class="ai-track-title"
494 name="ai_playlist_tracks[<?php echo esc_attr( $uid ); ?>][title]"
495 placeholder="<?php esc_attr_e( 'Title', 'audioigniter' ); ?>"
496 value="<?php echo esc_attr( $title ); ?>"
497 />
498 </div>
499 <div class="ai-form-field">
500 <label
501 for="ai_playlist_tracks-<?php echo esc_attr( $uid ); ?>-artist"
502 class="screen-reader-text">
503 <?php esc_html_e( 'Artist', 'audioigniter' ); ?>
504 </label>
505 <input
506 type="text"
507 id="ai_playlist_tracks-<?php echo esc_attr( $uid ); ?>-artist"
508 class="ai-track-artist"
509 name="ai_playlist_tracks[<?php echo esc_attr( $uid ); ?>][artist]"
510 placeholder="<?php esc_attr_e( 'Artist', 'audioigniter' ); ?>"
511 value="<?php echo esc_attr( $artist ); ?>"
512 />
513 </div>
514 </div>
515
516 <div class="ai-field-split">
517 <div class="ai-form-field">
518 <label
519 for="ai_playlist_tracks-<?php echo esc_attr( $uid ); ?>-track_url"
520 class="screen-reader-text">
521 <?php esc_html_e( 'Audio file or radio stream', 'audioigniter' ); ?>
522 </label>
523
524 <div class="ai-form-field-addon">
525 <input
526 type="text"
527 id="ai_playlist_tracks-<?php echo esc_attr( $uid ); ?>-track_url"
528 class="ai-track-url"
529 name="ai_playlist_tracks[<?php echo esc_attr( $uid ); ?>][track_url]"
530 placeholder="<?php esc_attr_e( 'Audio file or radio stream', 'audioigniter' ); ?>"
531 value="<?php echo esc_url( $track_url ); ?>"
532 />
533 <button type="button" class="button ai-upload">
534 <?php esc_html_e( 'Upload', 'audioigniter' ); ?>
535 </button>
536
537 <?php do_action( 'audioigniter_metabox_tracks_repeatable_track_field_after_track_upload_button' ); ?>
538 </div>
539 </div>
540 <div class="ai-form-field">
541 <label
542 for="ai_playlist_tracks-<?php echo esc_attr( $uid ); ?>-buy_link"
543 class="screen-reader-text">
544 <?php esc_html_e( 'Buy link', 'audioigniter' ); ?>
545 </label>
546 <input
547 type="text"
548 id="ai_playlist_tracks-<?php echo esc_attr( $uid ); ?>-buy_link"
549 class="ai-track-buy-link"
550 name="ai_playlist_tracks[<?php echo esc_attr( $uid ); ?>][buy_link]"
551 placeholder="<?php esc_attr_e( 'Buy link', 'audioigniter' ); ?>"
552 value="<?php echo esc_url( $buy_link ); ?>"
553 />
554 </div>
555
556 <button type="button" class="button ai-remove-field">
557 <span class="dashicons dashicons-dismiss"></span>
558 <?php esc_html_e( 'Remove Track', 'audioigniter' ); ?>
559 </button>
560 </div>
561 </div>
562 </div>
563 <?php
564 }
565
566 protected function metabox_tracks_field_controls() {
567 ?>
568 <div class="ai-field-controls-wrap">
569 <div class="ai-field-controls">
570 <button type="button" class="button ai-add-field">
571 <span class="dashicons dashicons-plus-alt"></span>
572 <?php esc_html_e( 'Add Track', 'audioigniter' ); ?>
573 </button>
574
575 <?php do_action( 'audioigniter_metabox_tracks_field_controls' ); ?>
576
577 <button type="button" class="button ai-remove-all-fields">
578 <span class="dashicons dashicons-dismiss"></span>
579 <?php esc_html_e( 'Clear Playlist', 'audioigniter' ); ?>
580 </button>
581 </div>
582
583 <div class="ai-field-controls-visibility">
584 <a href="#" class="ai-fields-expand-all">
585 <?php esc_html_e( 'Expand All', 'audioigniter' ); ?>
586 </a>
587 <a href="#" class="ai-fields-collapse-all">
588 <?php esc_html_e( 'Collapse All', 'audioigniter' ); ?>
589 </a>
590 </div>
591 </div>
592 <?php
593 }
594
595 /**
596 * Echoes the Settings metabox markup.
597 *
598 * @since 1.0.0
599 *
600 * @param WP_Post $object
601 * @param array $box
602 */
603 function metabox_settings( $object, $box ) {
604 $numbers = $this->get_post_meta( $object->ID, '_audioigniter_show_numbers', 1 );
605 $numbers_reverse = $this->get_post_meta( $object->ID, '_audioigniter_show_numbers_reverse', 0 );
606 $thumb = $this->get_post_meta( $object->ID, '_audioigniter_show_covers', 1 );
607 $active_thumb = $this->get_post_meta( $object->ID, '_audioigniter_show_active_cover', 1 );
608 $artist = $this->get_post_meta( $object->ID, '_audioigniter_show_artist', 1 );
609 $buy_links = $this->get_post_meta( $object->ID, '_audioigniter_show_buy_links', 1 );
610 $buy_links_new_target = $this->get_post_meta( $object->ID, '_audioigniter_buy_links_new_target', 1 );
611 $cycle_tracks = $this->get_post_meta( $object->ID, '_audioigniter_cycle_tracks', 0 );
612 $track_listing = $this->get_post_meta( $object->ID, '_audioigniter_show_track_listing', 1 );
613 $credit = $this->get_post_meta( $object->ID, '_audioigniter_show_credit', 0 );
614 $limit_tracklisting_height = $this->get_post_meta( $object->ID, '_audioigniter_limit_tracklisting_height', 1 );
615 $tracklisting_height = $this->get_post_meta( $object->ID, '_audioigniter_tracklisting_height', 185 );
616 $max_width = $this->get_post_meta( $object->ID, '_audioigniter_max_width' );
617
618 wp_nonce_field( basename( __FILE__ ), $object->post_type . '_nonce' );
619 ?>
620 <div class="ai-module ai-module-settings">
621 <div class="ai-form-field">
622 <input
623 type="checkbox"
624 class="ai-checkbox"
625 id="_audioigniter_show_track_listing"
626 name="_audioigniter_show_track_listing"
627 value="1" <?php checked( $track_listing, true ); ?>
628 />
629
630 <label for="_audioigniter_show_track_listing">
631 <?php esc_html_e( 'Show track listing', 'audioigniter' ); ?>
632 </label>
633 </div>
634
635 <div class="ai-form-field">
636 <input
637 type="checkbox"
638 class="ai-checkbox"
639 id="_audioigniter_show_numbers"
640 name="_audioigniter_show_numbers"
641 value="1" <?php checked( $numbers, true ); ?>
642 />
643
644 <label for="_audioigniter_show_numbers">
645 <?php esc_html_e( 'Show track numbers in tracklist', 'audioigniter' ); ?>
646 </label>
647 </div>
648
649 <div class="ai-form-field">
650 <input
651 type="checkbox"
652 class="ai-checkbox"
653 id="_audioigniter_show_numbers_revese"
654 name="_audioigniter_show_numbers_reverse"
655 value="1" <?php checked( $numbers_reverse, true ); ?>
656 />
657
658 <label for="_audioigniter_show_numbers_revese">
659 <?php esc_html_e( 'Show numbers in reverse order', 'audioigniter' ); ?>
660 </label>
661
662 <p class="ai-field-help">
663 <?php esc_html_e( 'For this to work, the "Show track numbers in tracklist" option above must be enabled.', 'audioigniter' ); ?>
664 </p>
665 </div>
666
667 <div class="ai-form-field">
668 <input
669 type="checkbox"
670 class="ai-checkbox"
671 id="_audioigniter_show_covers"
672 name="_audioigniter_show_covers"
673 value="1" <?php checked( $thumb, true ); ?>
674 />
675
676 <label for="_audioigniter_show_covers">
677 <?php esc_html_e( 'Show track covers in tracklist', 'audioigniter' ); ?>
678 </label>
679 </div>
680
681 <div class="ai-form-field">
682 <input
683 type="checkbox"
684 class="ai-checkbox"
685 id="_audioigniter_show_active_cover"
686 name="_audioigniter_show_active_cover"
687 value="1" <?php checked( $active_thumb, true ); ?>
688 />
689
690 <label for="_audioigniter_show_active_cover">
691 <?php esc_html_e( "Show active track's cover", 'audioigniter' ); ?>
692 </label>
693 </div>
694
695 <div class="ai-form-field">
696 <input
697 type="checkbox"
698 class="ai-checkbox"
699 id="_audioigniter_show_artist"
700 name="_audioigniter_show_artist"
701 value="1" <?php checked( $artist, true ); ?>
702 />
703
704 <label for="_audioigniter_show_artist">
705 <?php esc_html_e( 'Show artist names', 'audioigniter' ); ?>
706 </label>
707 </div>
708
709 <div class="ai-form-field">
710 <input
711 type="checkbox"
712 class="ai-checkbox"
713 id="_audioigniter_show_buy_links"
714 name="_audioigniter_show_buy_links"
715 value="1" <?php checked( $buy_links, true ); ?>
716 />
717
718 <label for="_audioigniter_show_buy_links">
719 <?php esc_html_e( 'Show track buy links', 'audioigniter' ); ?>
720 </label>
721 </div>
722
723 <div class="ai-form-field">
724 <input
725 type="checkbox"
726 class="ai-checkbox"
727 id="_audioigniter_buy_links_new_target"
728 name="_audioigniter_buy_links_new_target"
729 value="1" <?php checked( $buy_links_new_target, true ); ?>
730 />
731
732 <label for="_audioigniter_buy_links_new_target">
733 <?php esc_html_e( 'Open buy links in new window', 'audioigniter' ); ?>
734 </label>
735 </div>
736
737 <div class="ai-form-field">
738 <input
739 type="checkbox"
740 class="ai-checkbox"
741 id="_audioigniter_cycle_tracks"
742 name="_audioigniter_cycle_tracks"
743 value="1" <?php checked( $cycle_tracks, true ); ?>
744 />
745
746 <label for="_audioigniter_cycle_tracks">
747 <?php esc_html_e( 'Repeat tracklist enabled by default', 'audioigniter' ); ?>
748 </label>
749
750 <p class="ai-field-help">
751 <?php esc_html_e( 'Note that users still have the option to turn it on or off in the player regardless of this option.', 'audioigniter' ); ?>
752 </p>
753 </div>
754
755 <div class="ai-form-field">
756 <input
757 type="checkbox"
758 class="ai-checkbox"
759 id="_audioigniter_show_credit"
760 name="_audioigniter_show_credit"
761 value="1" <?php checked( $credit, true ); ?>
762 />
763
764 <label for="_audioigniter_show_credit">
765 <?php esc_html_e( 'Show "Powered by AudioIgniter" link', 'audioigniter' ); ?>
766 </label>
767
768 <p class="ai-field-help">
769 <?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' ); ?>
770 </p>
771 </div>
772
773 <div class="ai-form-field">
774 <input
775 type="checkbox"
776 class="ai-checkbox"
777 id="_audioigniter_limit_tracklisting_height"
778 name="_audioigniter_limit_tracklisting_height"
779 value="1" <?php checked( $limit_tracklisting_height, true ); ?>
780 />
781
782 <label for="_audioigniter_limit_tracklisting_height">
783 <?php esc_html_e( 'Limit track listing height', 'audioigniter' ); ?>
784 </label>
785 </div>
786
787 <div class="ai-form-field">
788 <label for="_audioigniter_tracklisting_height">
789 <?php esc_html_e( 'Track listing height', 'audioigniter' ); ?>
790 </label>
791
792 <input
793 type="number"
794 min="10"
795 step="5"
796 id="_audioigniter_tracklisting_height"
797 class="ai-track-title"
798 name="_audioigniter_tracklisting_height"
799 placeholder="<?php esc_attr_e( 'Track listing height', 'audioigniter' ); ?>"
800 value="<?php echo esc_attr( $tracklisting_height ); ?>"
801 />
802
803 <p class="ai-field-help">
804 <?php esc_html_e( 'Set a number of pixels', 'audioigniter' ); ?>
805 </p>
806 </div>
807
808 <div class="ai-form-field">
809 <label for="_audioigniter_max_width">
810 <?php esc_html_e( 'Maximum player width', 'audioigniter' ); ?>
811 </label>
812
813 <input
814 type="number"
815 id="_audioigniter_max_width"
816 class="ai-track-title"
817 name="_audioigniter_max_width"
818 placeholder="<?php esc_attr_e( 'Automatic width', 'audioigniter' ); ?>"
819 value="<?php echo esc_attr( $max_width ); ?>"
820 />
821
822 <p class="ai-field-help">
823 <?php esc_html_e( 'Set a number of pixels, or leave empty to automatically cover 100% of the available area (recommended).', 'audioigniter' ); ?>
824 </p>
825 </div>
826 </div>
827 <?php
828 }
829
830 /**
831 * Echoes the Shortcode metabox markup.
832 *
833 * @since 1.0.0
834 *
835 * @param WP_Post $object
836 * @param array $box
837 */
838 public function metabox_shortcode( $object, $box ) {
839 ?>
840 <div class="ai-module ai-module-shortcode">
841 <div class="ai-form-field">
842 <label for="ai_shortcode">
843 <?php esc_html_e( 'Grab the shortcode', 'audioigniter' ); ?>
844 </label>
845
846 <input
847 type="text"
848 class="code"
849 id="ai_shortcode"
850 name="ai_shortcode"
851 value="<?php echo esc_attr( sprintf( '[ai_playlist id="%s"]', $object->ID ) ); ?>"
852 />
853
854 </div>
855 </div>
856 <?php
857 }
858
859 public function save_post( $post_id ) {
860 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return false; }
861 if ( isset( $_POST['post_view'] ) && $_POST['post_view'] === 'list' ) { return false; }
862 if ( ! isset( $_POST['post_type'] ) || $_POST['post_type'] !== $this->post_type ) { return false; }
863 if ( ! isset( $_POST[ $this->post_type . '_nonce' ] ) || ! wp_verify_nonce( $_POST[ $this->post_type . '_nonce' ], basename( __FILE__ ) ) ) { return false; }
864 $post_type_obj = get_post_type_object( $this->post_type );
865 if ( ! current_user_can( $post_type_obj->cap->edit_post, $post_id ) ) { return false; }
866
867 update_post_meta( $post_id, '_audioigniter_tracks', $this->sanitizer->metabox_playlist( $_POST['ai_playlist_tracks'], $post_id ) );
868
869 update_post_meta( $post_id, '_audioigniter_show_numbers', $this->sanitizer->checkbox_ref( $_POST['_audioigniter_show_numbers'] ) );
870 update_post_meta( $post_id, '_audioigniter_show_numbers_reverse', $this->sanitizer->checkbox_ref( $_POST['_audioigniter_show_numbers_reverse'] ) );
871 update_post_meta( $post_id, '_audioigniter_show_covers', $this->sanitizer->checkbox_ref( $_POST['_audioigniter_show_covers'] ) );
872 update_post_meta( $post_id, '_audioigniter_show_active_cover', $this->sanitizer->checkbox_ref( $_POST['_audioigniter_show_active_cover'] ) );
873 update_post_meta( $post_id, '_audioigniter_show_artist', $this->sanitizer->checkbox_ref( $_POST['_audioigniter_show_artist'] ) );
874 update_post_meta( $post_id, '_audioigniter_show_buy_links', $this->sanitizer->checkbox_ref( $_POST['_audioigniter_show_buy_links'] ) );
875 update_post_meta( $post_id, '_audioigniter_buy_links_new_target', $this->sanitizer->checkbox_ref( $_POST['_audioigniter_buy_links_new_target'] ) );
876 update_post_meta( $post_id, '_audioigniter_cycle_tracks', $this->sanitizer->checkbox_ref( $_POST['_audioigniter_cycle_tracks'] ) );
877 update_post_meta( $post_id, '_audioigniter_show_track_listing', $this->sanitizer->checkbox_ref( $_POST['_audioigniter_show_track_listing'] ) );
878 update_post_meta( $post_id, '_audioigniter_show_credit', $this->sanitizer->checkbox_ref( $_POST['_audioigniter_show_credit'] ) );
879 update_post_meta( $post_id, '_audioigniter_limit_tracklisting_height', $this->sanitizer->checkbox_ref( $_POST['_audioigniter_limit_tracklisting_height'] ) );
880 update_post_meta( $post_id, '_audioigniter_tracklisting_height', intval( $_POST['_audioigniter_tracklisting_height'] ) );
881 update_post_meta( $post_id, '_audioigniter_max_width', $this->sanitizer->intval_or_empty( $_POST['_audioigniter_max_width'] ) );
882 }
883
884 public static function get_default_track_values() {
885 return apply_filters( 'audioigniter_default_track_values', array(
886 'cover_id' => '',
887 'title' => '',
888 'artist' => '',
889 'track_url' => '',
890 'buy_link' => '',
891 ) );
892 }
893
894 public function register_image_sizes() {
895 add_image_size( 'audioigniter_cover', 560, 560, true );
896 }
897
898 public function register_widgets() {
899 $widgets = apply_filters( 'audioigniter_register_widgets', array() );
900
901 foreach ( $widgets as $class => $file ) {
902 require_once( $file );
903 register_widget( $class );
904 }
905 }
906
907 public function register_shortcodes() {
908 add_shortcode( 'ai_playlist', array( $this, 'shortcode_ai_playlist' ) );
909 }
910
911 public function shortcode_ai_playlist( $atts, $content = null, $tag ) {
912 $atts = shortcode_atts( array(
913 'id' => '',
914 ), $atts, $tag );
915
916 $id = $atts['id'];
917
918 if ( empty( $id ) ) {
919 return '';
920 }
921
922 $id = intval( $id );
923 $post = get_post( $id );
924
925 if ( empty( $post ) || $post->post_type !== $this->post_type ) {
926 return '';
927 }
928
929 $params = apply_filters( 'audioigniter_shortcode_data_attributes_array', array(
930 'data-tracks-url' => add_query_arg( array( 'audioigniter_playlist_id' => $id ), home_url( '/' ) ),
931 'data-display-track-no' => $this->convert_bool_string( $this->get_post_meta( $id, '_audioigniter_show_numbers', 1 ) ),
932 'data-reverse-track-order' => $this->convert_bool_string( $this->get_post_meta( $id, '_audioigniter_show_numbers_reverse', 0 ) ),
933 'data-display-tracklist-covers' => $this->convert_bool_string( $this->get_post_meta( $id, '_audioigniter_show_covers', 1 ) ),
934 'data-display-active-cover' => $this->convert_bool_string( $this->get_post_meta( $id, '_audioigniter_show_active_cover', 1 ) ),
935 'data-display-artist-names' => $this->convert_bool_string( $this->get_post_meta( $id, '_audioigniter_show_artist', 1 ) ),
936 'data-display-buy-buttons' => $this->convert_bool_string( $this->get_post_meta( $id, '_audioigniter_show_buy_links', 1 ) ),
937 'data-buy-buttons-target' => $this->convert_bool_string( $this->get_post_meta( $id, '_audioigniter_buy_links_new_target', 1 ) ),
938 'data-cycle-tracks' => $this->convert_bool_string( $this->get_post_meta( $id, '_audioigniter_cycle_tracks', 0 ) ),
939 'data-display-credits' => $this->convert_bool_string( $this->get_post_meta( $id, '_audioigniter_show_credit', 1 ) ),
940 'data-display-tracklist' => $this->convert_bool_string( $this->get_post_meta( $id, '_audioigniter_show_track_listing', 1 ) ),
941 'data-limit-tracklist-height' => $this->convert_bool_string( $this->get_post_meta( $id, '_audioigniter_limit_tracklisting_height', 1 ) ),
942 'data-tracklist-height' => intval( $this->get_post_meta( $id, '_audioigniter_tracklisting_height', 185 ) ),
943 'data-max-width' => $this->get_post_meta( $id, '_audioigniter_max_width' ),
944 ), $id, $post );
945
946 $params = array_filter( $params );
947 $params = $this->sanitizer->html_data_attributes_array( $params );
948
949 $data = '';
950 foreach ( $params as $attribute => $value ) {
951 $data .= sprintf( '%s="%s" ', sanitize_key( $attribute ), esc_attr( $value ) );
952 }
953
954 $output = sprintf( '<div id="audioigniter-%s" class="audioigniter-root" %s></div>',
955 esc_attr( $id ),
956 $data
957 );
958
959 return $output;
960 }
961
962 public function convert_bool_string( $value ) {
963 if ( $value ) {
964 return 'true';
965 }
966
967 return 'false';
968 }
969
970 public function register_playlist_endpoint() {
971 add_rewrite_tag( '%audioigniter_playlist_id%', '([0-9]+)' );
972 add_rewrite_rule( '^audioigniter/playlist/([0-9]+)/?', 'index.php?audioigniter_playlist_id=$matches[1]', 'bottom' );
973 }
974
975 public function handle_playlist_endpoint() {
976 global $wp_query;
977
978 $playlist_id = $wp_query->get( 'audioigniter_playlist_id' );
979
980 if ( empty( $playlist_id ) ) {
981 return;
982 }
983
984 $playlist_id = intval( $playlist_id );
985 $post = get_post( $playlist_id );
986
987 if ( empty( $post ) || $post->post_type !== $this->post_type ) {
988 wp_send_json_error( __( "ID doesn't match a playlist", 'audioigniter' ) );
989 }
990
991 $response = array();
992 $tracks = $this->get_post_meta( $playlist_id, '_audioigniter_tracks', array() );
993
994 foreach ( $tracks as $track ) {
995 $tmp = array();
996
997 $tmp['title'] = $track['title'];
998 $tmp['subtitle'] = $track['artist'];
999 $tmp['audio'] = $track['track_url'];
1000 $tmp['buyUrl'] = $track['buy_link'];
1001
1002 $cover_url = wp_get_attachment_image_src( intval( $track['cover_id'] ), 'audioigniter_cover' );
1003 if ( ! empty( $cover_url[0] ) ) {
1004 $cover_url = $cover_url[0];
1005 } else {
1006 $cover_url = '';
1007 }
1008
1009 $tmp['cover'] = $cover_url;
1010
1011 $response[] = $tmp;
1012 }
1013
1014 wp_send_json( $response );
1015 }
1016
1017
1018 public function get_all_playlists( $orderby = 'date', $order = 'DESC' ) {
1019 $q = new WP_Query( array(
1020 'post_type' => $this->post_type,
1021 'posts_per_page' => - 1,
1022 'orderby' => $orderby,
1023 'order' => $order,
1024 ) );
1025
1026 return $q->posts;
1027 }
1028
1029 public function get_post_meta( $post_id, $key, $default = '' ) {
1030 $keys = get_post_custom_keys( $post_id );
1031
1032 $value = $default;
1033
1034 if ( is_array( $keys ) && in_array( $key, $keys, true ) ) {
1035 $value = get_post_meta( $post_id, $key, true );
1036 }
1037
1038 return $value;
1039 }
1040
1041 public function plugin_activated() {
1042 if ( ! current_user_can( 'activate_plugins' ) ) {
1043 return;
1044 }
1045
1046 $this->register_post_types();
1047
1048 do_action( 'audioigniter_activated' );
1049
1050 flush_rewrite_rules();
1051 }
1052
1053 public function plugin_deactivated() {
1054 if ( ! current_user_can( 'activate_plugins' ) ) {
1055 return;
1056 }
1057
1058 unregister_post_type( $this->post_type );
1059
1060 do_action( 'audioigniter_deactivated' );
1061
1062 flush_rewrite_rules();
1063 }
1064
1065 public static function plugin_basename() {
1066 return plugin_basename( __FILE__ );
1067 }
1068
1069 public function plugin_url() {
1070 return self::$plugin_url;
1071 }
1072
1073 public function plugin_path() {
1074 return self::$plugin_path;
1075 }
1076 }
1077
1078
1079 /**
1080 * Main instance of AudioIgniter.
1081 *
1082 * Returns the working instance of AudioIgniter. No need for globals.
1083 *
1084 * @since 1.0.0
1085 * @return AudioIgniter
1086 */
1087 function AudioIgniter() {
1088 return AudioIgniter::instance();
1089 }
1090
1091 add_action( 'plugins_loaded', array( AudioIgniter(), 'plugin_setup' ) );
1092 register_activation_hook( __FILE__, array( AudioIgniter(), 'plugin_activated' ) );
1093 register_deactivation_hook( __FILE__, array( AudioIgniter(), 'plugin_deactivated' ) );
1094