/** * Display a playlist. * * @since 1.0.0 * @todo Add an arg to specify a template path that doesn't exist in the /cue directory. * * @param mixed $post A post ID, WP_Post object or post slug. * @param array $args */ function cue_playlist($post, $args = array()) { if (is_string($post) && !is_numeric($post)) { // Get a playlist by its slug. $post = get_page_by_path($post, OBJECT, 'cue_playlist'); } else { $post = get_post($post); } if (!$post || 'cue_playlist' !== get_post_type($post)) { return; } $tracks = get_cue_playlist_tracks($post); if (empty($tracks)) { return; } if (!isset($args['enqueue']) || $args['enqueue']) { Cue::enqueue_assets(); } $template_names = array("playlist-{$post->ID}.php", "playlist-{$post->post_name}.php", "playlist.php"); // Prepend custom templates. if (!empty($args['template'])) { $add_templates = array_filter((array) $args['template']); $template_names = array_merge($add_templates, $template_names); } $template_loader = new Cue_Template_Loader(); $template = $template_loader->locate_template($template_names); $classes = array('cue-playlist'); $classes[] = isset($args['show_playlist']) && false == $args['show_playlist'] ? 'is-playlist-hidden' : ''; $classes = implode(' ', array_filter($classes)); echo '<div class="cue-playlist-container">'; do_action('cue_before_playlist', $post, $tracks, $args); include $template; do_action('cue_after_playlist', $post, $tracks, $args); echo '</div>'; }
/** * Add a cue * * @param mixed $_mixed An cue instance or a string representing the text * @param string $_start A timecode * @param string $_stop A timecode */ public function addCue($_mixed, $_start = null, $_stop = null) { $fileFormat = self::getFormat($this); // if $_mixed is a Cue if (is_subclass_of($_mixed, __NAMESPACE__ . '\\Cue')) { $cueFormat = Cue::getFormat($_mixed); if ($cueFormat !== $fileFormat) { throw new \Exception("Can't add a {$cueFormat} cue in a {$fileFormat} file."); } $_mixed->setLineEnding($this->lineEnding); $this->cues[] = $_mixed; } else { $cueClass = self::getExpectedCueClass($this); $cue = new $cueClass($_start, $_stop, $_mixed); $cue->setLineEnding($this->lineEnding); $this->cues[] = $cue; } return $this; }