public function widget($args, $instance) { global $ss_podcasting; $cache = array(); if (!$this->is_preview()) { $cache = wp_cache_get('widget_single_episode', 'widget'); } if (!is_array($cache)) { $cache = array(); } if (!isset($args['widget_id'])) { $args['widget_id'] = $this->id; } if (isset($cache[$args['widget_id']])) { echo $cache[$args['widget_id']]; return; } ob_start(); $episode_id = $instance['episode_id']; if (0 == $episode_id) { $ssp_episodes = ssp_episodes(1); if (0 < count($ssp_episodes)) { foreach ($ssp_episodes as $episode) { $episode_id = $episode->ID; break; } } } if (!$episode_id) { return; } $title = $instance['title'] ? $instance['title'] : get_the_title($episode_id); /** This filter is documented in wp-includes/default-widgets.php */ $title = apply_filters('widget_title', $title, $instance, $this->id_base); $show_title = isset($instance['show_title']) ? $instance['show_title'] : false; $show_excerpt = isset($instance['show_excerpt']) ? $instance['show_excerpt'] : false; $show_content = isset($instance['show_content']) ? $instance['show_content'] : false; $show_player = isset($instance['show_player']) ? $instance['show_player'] : false; $show_details = isset($instance['show_details']) ? $instance['show_details'] : false; $content_items = array(); if ($show_title) { $content_items[] = 'title'; } if ($show_excerpt) { $content_items[] = 'excerpt'; } if ($show_content) { $content_items[] = 'content'; } if ($show_player) { $content_items[] = 'player'; } if ($show_details) { $content_items[] = 'details'; } // Get episode markup $html = $ss_podcasting->podcast_episode($episode_id, $content_items, 'widget'); if (!$html) { return; } echo $args['before_widget']; if ($title) { echo $args['before_title'] . $title . $args['after_title']; } echo $html; echo $args['after_widget']; if (!$this->is_preview()) { $cache[$args['widget_id']] = ob_get_flush(); wp_cache_set('widget_single_episode', $cache, 'widget'); } else { ob_end_flush(); } }
} ?> <?php if ($new_feed_url) { ?> <itunes:new-feed-url><?php echo esc_url($new_feed_url); ?> </itunes:new-feed-url> <?php } // Add RSS2 headers do_action('rss2_head'); // Get post IDs of all podcast episodes $num_posts = intval(apply_filters('ssp_feed_number_of_posts', get_option('posts_per_rss', 10))); $args = ssp_episodes($num_posts, $podcast_series, true, 'feed'); $qry = new WP_Query($args); if ($qry->have_posts()) { while ($qry->have_posts()) { $qry->the_post(); // Audio file $audio_file = $ss_podcasting->get_enclosure(get_the_ID()); if (get_option('permalink_structure')) { $enclosure = $ss_podcasting->get_episode_download_link(get_the_ID()); } else { $enclosure = $audio_file; } // If there is no enclosure then go no further if (!isset($enclosure) || !$enclosure) { continue; }
/** * Adding podcast episodes to 'At a glance' dashboard widget * @param array $items Existing items * @return array Updated items */ public function glance_items($items = array()) { $num_posts = count(ssp_episodes(-1, '', false, 'glance')); $post_type_object = get_post_type_object($this->token); $text = _n('%s Episode', '%s Episodes', $num_posts, 'ss-podcasting'); $text = sprintf($text, number_format_i18n($num_posts)); if ($post_type_object && current_user_can($post_type_object->cap->edit_posts)) { $items[] = sprintf('<a class="%1$s-count" href="edit.php?post_type=%1$s">%2$s</a>', $this->token, $text) . "\n"; } else { $items[] = sprintf('<span class="%1$s-count">%2$s</span>', $this->token, $text) . "\n"; } return $items; }
public function widget($args, $instance) { $cache = array(); if (!$this->is_preview()) { $cache = wp_cache_get('widget_recent_episodes', 'widget'); } if (!is_array($cache)) { $cache = array(); } if (!isset($args['widget_id'])) { $args['widget_id'] = $this->id; } if (isset($cache[$args['widget_id']])) { echo $cache[$args['widget_id']]; return; } ob_start(); $title = !empty($instance['title']) ? $instance['title'] : __('Recent Episodes', 'ss-podcasting'); /** This filter is documented in wp-includes/default-widgets.php */ $title = apply_filters('widget_title', $title, $instance, $this->id_base); $number = !empty($instance['number']) ? absint($instance['number']) : 5; if (!$number) { $number = 5; } $show_date = isset($instance['show_date']) ? $instance['show_date'] : false; $query_args = ssp_episodes($number, '', true, 'widget'); $qry = new WP_Query(apply_filters('ssp_widget_recent_episodes_args', $query_args)); if ($qry->have_posts()) { ?> <?php echo $args['before_widget']; ?> <?php if ($title) { echo $args['before_title'] . $title . $args['after_title']; } ?> <ul> <?php while ($qry->have_posts()) { $qry->the_post(); ?> <li> <a href="<?php the_permalink(); ?> "><?php get_the_title() ? the_title() : the_ID(); ?> </a> <?php if ($show_date) { ?> <span class="post-date"><?php echo get_the_date(); ?> </span> <?php } ?> </li> <?php } ?> </ul> <?php echo $args['after_widget']; // Reset the global $the_post as this query will have stomped on it wp_reset_postdata(); } if (!$this->is_preview()) { $cache[$args['widget_id']] = ob_get_flush(); wp_cache_set('widget_recent_episodes', $cache, 'widget'); } else { ob_end_flush(); } }
public function widget($args, $instance) { $cache = array(); if (!$this->is_preview()) { $cache = wp_cache_get('widget_podcast_series', 'widget'); } if (!is_array($cache)) { $cache = array(); } if (!isset($args['widget_id'])) { $args['widget_id'] = $this->id; } if (isset($cache[$args['widget_id']])) { echo $cache[$args['widget_id']]; return; } ob_start(); $series_id = $instance['series_id']; if (!$series_id) { return; } $series = get_term($series_id, 'series'); if (!$series || is_wp_error($series)) { return; } $title = $instance['title'] ? $instance['title'] : $series->name; /** This filter is documented in wp-includes/default-widgets.php */ $title = apply_filters('widget_title', $title, $instance, $this->id_base); $show_title = isset($instance['show_title']) ? $instance['show_title'] : false; $show_desc = isset($instance['show_desc']) ? $instance['show_desc'] : false; $show_date = isset($instance['show_date']) ? $instance['show_date'] : false; $query_args = ssp_episodes(999, $series->slug, true, 'widget'); $qry = new WP_Query(apply_filters('ssp_widget_series_episodes_args', $query_args)); if ($qry->have_posts()) { ?> <?php echo $args['before_widget']; ?> <?php if ($title) { echo $args['before_title'] . $title . $args['after_title']; } ?> <?php if ($show_title) { ?> <h3><?php echo $series->name; ?> </h3> <?php } ?> <?php if ($show_desc) { ?> <p><?php echo $series->description; ?> </p> <?php } ?> <ul> <?php while ($qry->have_posts()) { $qry->the_post(); ?> <li> <a href="<?php the_permalink(); ?> "><?php get_the_title() ? the_title() : the_ID(); ?> </a> <?php if ($show_date) { ?> <span class="post-date"><?php echo get_the_date(); ?> </span> <?php } ?> </li> <?php } ?> </ul> <?php echo $args['after_widget']; // Reset the global $the_post as this query will have stomped on it wp_reset_postdata(); } if (!$this->is_preview()) { $cache[$args['widget_id']] = ob_get_flush(); wp_cache_set('widget_podcast_series', $cache, 'widget'); } else { ob_end_flush(); } }
/** * Get podcast * @param string/array $args Arguments to be passed to the query. * @return array/boolean Array if true, boolean if false. */ public function get_podcast($args = '') { $defaults = array('title' => '', 'content' => 'series', 'series' => ''); $args = wp_parse_args($args, $defaults); $args = apply_filters('ssp_get_podcast_args', $args); $podcast_post_types = get_option('ss_podcasting_use_post_types', array()); $podcast_post_types[] = 'podcast'; if ('episodes' == $args['content']) { // Get selected series $podcast_series = ''; if (isset($args['series']) && $args['series']) { $podcast_series = $args['series']; } // Get query args $query_args = apply_filters('ssp_get_podcast_query_args', ssp_episodes(-1, $podcast_series, true, '')); // The Query $query = get_posts($query_args); // The Display if (!is_wp_error($query) && is_array($query) && count($query) > 0) { foreach ($query as $k => $v) { // Get the URL $query[$k]->url = get_permalink($v->ID); } } else { $query = false; } } else { $terms = get_terms('series'); if (count($terms) > 0) { foreach ($terms as $term) { $query[$term->term_id] = new stdClass(); $query[$term->term_id]->title = $term->name; $query[$term->term_id]->url = get_term_link($term); $query_args = apply_filters('ssp_get_podcast_series_query_args', ssp_episodes(-1, $term->slug, true, '')); $posts = get_posts($query_args); $count = count($posts); $query[$term->term_id]->count = $count; } } } $query['content'] = $args['content']; return $query; }
/** * Load content for stats page * @access public * @since 1.0.0 * @return void */ public function stats_page() { global $wp_version, $wpdb; $metabox_title = 'h2'; if (version_compare($wp_version, '4.4', '<')) { $metabox_title = 'h3'; } $title_tail = $no_stats_filler = ''; switch ($this->filter) { case 'series': if ('all' != $this->series) { $series_obj = get_term_by('slug', $this->series, 'series'); $series_name = $series_obj->name; if ($series_name) { $title_tail = sprintf(__('for Series: %s', 'seriously-simple-stats'), '<u>' . $series_name . '</u>'); $no_stats_filler = __('for this series', 'seriously-simple-stats'); } } break; case 'episode': if ('all' != $this->episode) { $episode_name = get_the_title($this->episode); if ($episode_name) { $title_tail = sprintf(__('for Episode: %s', 'seriously-simple-stats'), '<u>' . $episode_name . '</u>'); $no_stats_filler = __('for this episode', 'seriously-simple-stats'); } } break; } $page_title = sprintf(__('Podcast Stats %s', 'seriously-simple-stats'), $title_tail); $html = '<div class="wrap" id="podcast_settings">' . "\n"; $html .= '<h1>' . $page_title . '</h1>' . "\n"; $html .= '<div class="metabox-holder">' . "\n"; // Count total entries for episode selection $count_entries_sql = "SELECT COUNT(id) FROM {$this->_table}"; if ($this->episode_id_where) { $count_stats_episode_id_where = 'WHERE ' . $this->episode_id_where; $count_entries_sql = $count_entries_sql . " {$count_stats_episode_id_where}"; } $total_entries = $wpdb->get_var($count_entries_sql); if (!$total_entries) { $html .= '<div class="" id="no-stats-container">' . "\n"; $html .= '<div class="inside no-activity">' . "\n"; $html .= '<p class="smiley"></p>' . "\n"; $html .= '<p>' . sprintf(__('No stats %s yet!', 'seriously-simple-stats'), $no_stats_filler) . '</p>' . "\n"; $html .= '</div>' . "\n"; $html .= '</div>' . "\n"; } else { $html .= '<div class="postbox" id="content-filter-container">' . "\n"; $html .= '<div class="inside">' . "\n"; $html .= '<form action="" method="get" name="ssp-stats-content-filter">' . "\n"; $html .= '<strong>' . "\n"; foreach ($_GET as $param => $value) { if (in_array($param, array('post_type', 'page', 'start', 'end'))) { $html .= '<input type="hidden" name="' . esc_attr($param) . '" value="' . esc_attr($value) . '" />'; } } switch ($this->filter) { case 'episode': $series_class = 'hidden'; $episode_class = ''; break; case 'series': $series_class = ''; $episode_class = 'hidden'; break; default: $series_class = 'hidden'; $episode_class = 'hidden'; break; } $html .= __('View stats for', 'seriously-simple-stats') . "\n"; $html .= ' <select name="filter" id="content-filter-select">' . "\n"; $html .= '<option value="" ' . selected('', $this->filter, false) . '>' . __('All episodes', 'seriously-simple-stats') . '</option>' . "\n"; $html .= '<option value="series" ' . selected('series', $this->filter, false) . '>' . __('An individual series', 'seriously-simple-stats') . '</option>' . "\n"; $html .= '<option value="episode" ' . selected('episode', $this->filter, false) . '>' . __('An individual episode', 'seriously-simple-stats') . '</option>' . "\n"; $html .= '</select>' . "\n"; // Series selection $html .= '<span id="by-series-selection" class="' . esc_attr($series_class) . '">' . "\n"; $series = get_terms('series'); $html .= '»' . "\n"; $html .= '<select name="series">' . "\n"; foreach ($series as $s) { $html .= '<option value="' . esc_attr($s->slug) . '" ' . selected($this->series, $s->slug, false) . '>' . esc_html($s->name) . '</option>' . "\n"; } $html .= '</select>' . "\n"; $html .= '</span>' . "\n"; // Episode selection $html .= '<span id="by-episode-selection" class="' . esc_attr($episode_class) . '">' . "\n"; $episodes_args = ssp_episodes(-1, '', true, 'stats'); $episodes_args['orderby'] = 'title'; $episodes_args['order'] = 'ASC'; $episodes = get_posts($episodes_args); $html .= '»' . "\n"; $html .= '<select name="episode">' . "\n"; foreach ($episodes as $episode) { $html .= '<option value="' . esc_attr($episode->ID) . '" ' . selected($this->episode, $episode->ID, false) . '>' . esc_html($episode->post_title) . '</option>' . "\n"; } $html .= '</select>' . "\n"; $html .= '</span>' . "\n"; $html .= '<input type="submit" id="content-filter-button" class="hidden button" value="' . __('Apply', 'seriously-simple-stats') . '" />' . "\n"; $html .= '</strong>' . "\n"; $html .= '</form>' . "\n"; $html .= '</div>' . "\n"; $html .= '</div>' . "\n"; $html .= '<div class="postbox">' . "\n"; $html .= '<' . $metabox_title . ' class="hndle ui-sortable-handle">' . "\n"; $html .= '<span>' . __('At a Glance', 'seriously-simple-stats') . '</span>' . "\n"; $html .= '</' . $metabox_title . '>' . "\n"; $html .= '<div class="inside">' . "\n"; $episode_id_where = ''; if ($this->episode_id_where) { $episode_id_where = 'AND ' . $this->episode_id_where; } // Listens today $start_of_day = strtotime(date('Y-m-d 00:00:00', $this->current_time)); $listens_today = $wpdb->get_var($wpdb->prepare("SELECT COUNT(id) FROM {$this->_table} WHERE date BETWEEN %d AND %d {$episode_id_where}", $start_of_day, $this->current_time)); $html .= $this->daily_stat($listens_today, __('Listens today', 'seriously-simple-stats')); // Listens this week $one_week_ago = strtotime('-1 week', $this->current_time); $listens_this_week = $wpdb->get_var($wpdb->prepare("SELECT COUNT(id) FROM {$this->_table} WHERE date BETWEEN %d AND %d {$episode_id_where}", $one_week_ago, $this->current_time)); $html .= $this->daily_stat($listens_this_week, __('Listens this week', 'seriously-simple-stats')); // Listens last week $two_weeks_ago = strtotime('-1 week', $one_week_ago); $listens_last_week = $wpdb->get_var($wpdb->prepare("SELECT COUNT(id) FROM {$this->_table} WHERE date BETWEEN %d AND %d {$episode_id_where}", $two_weeks_ago, $one_week_ago)); $html .= $this->daily_stat($listens_last_week, __('Listens last week', 'seriously-simple-stats')); // Change from last week if (!$listens_last_week) { $week_diff = '-'; } else { $week_diff = round($listens_this_week / $listens_last_week * 100, 1); if ($week_diff < 100) { $week_diff = '-' . (100 - $week_diff) . '%'; } elseif ($week_diff > 100) { $week_diff = '+' . ($week_diff - 100) . '%'; } else { $week_diff = '0%'; } } $html .= $this->daily_stat($week_diff, __('Change from last week', 'seriously-simple-stats')); $html .= '<br class="clear" />'; $html .= '</div>' . "\n"; $html .= '</div>' . "\n"; $html .= '<div class="postbox" id="daily-listens-container">' . "\n"; // Date range selection $start_date_select = '<input type="text" id="start-date-filter_display" class="ssp-datepicker" placeholder="' . __('Start date', 'seriously-simple-stats') . '" value="' . esc_attr(date('j F, Y', $this->start_date)) . '" /><input type="hidden" id="start-date-filter" name="start" value="' . esc_attr(date('d-m-Y', $this->start_date)) . '" />'; $end_date_select = '<input type="text" id="end-date-filter_display" class="ssp-datepicker" placeholder="' . __('End date', 'seriously-simple-stats') . '" value="' . esc_attr(date('j F, Y', $this->end_date)) . '" /><input type="hidden" id="end-date-filter" name="end" value="' . esc_attr(date('d-m-Y', $this->end_date)) . '" />'; $date_select_submit = '<input id="date_select_submit" class="hidden button" type="submit" value="' . __('Apply', 'seriously-simple-stats') . '" />'; $date_select_hidden = ''; foreach ($_GET as $param => $value) { if (in_array($param, array('post_type', 'page', 'filter', 'episode', 'series'))) { $date_select_hidden .= '<input type="hidden" name="' . esc_attr($param) . '" value="' . esc_attr($value) . '" />'; } } $html .= '<' . $metabox_title . ' class="hndle ui-sortable-handle">' . "\n"; $html .= '<form action="" method="get" name="ssp-stats-date-filter" class="hasDatepicker">' . "\n"; $html .= $date_select_hidden; $html .= '<span>' . sprintf(__('Stats for %s to %s %s', 'seriously-simple-stats'), $start_date_select, $end_date_select, $date_select_submit) . '</span>' . "\n"; $html .= '</form>' . "\n"; $html .= '</' . $metabox_title . '>' . "\n"; $html .= '<div class="inside">' . "\n"; $html .= '<' . $metabox_title . ' class="hndle ui-sortable-handle">' . "\n"; $html .= '<span>' . __('Daily Listens', 'seriously-simple-stats') . '</span>' . "\n"; $html .= '</' . $metabox_title . '>' . "\n"; $html .= '<div id="daily_listens"></div>' . "\n"; $html .= '<' . $metabox_title . ' class="hndle ui-sortable-handle">' . "\n"; $html .= '<span>' . __('Listening Sources', 'seriously-simple-stats') . '</span>' . "\n"; $html .= '</' . $metabox_title . '>' . "\n"; $html .= '<div id="listening-sources"></div>' . "\n"; $html .= '</div>' . "\n"; $html .= '</div>' . "\n"; $html .= '<div class="postbox" id="top-ten-container">' . "\n"; $html .= '<' . $metabox_title . ' class="hndle ui-sortable-handle">' . "\n"; $html .= '<span>' . __('Top Ten Episodes of All Time', 'seriously-simple-stats') . '</span>' . "\n"; $html .= '</' . $metabox_title . '>' . "\n"; $html .= '<div class="inside">' . "\n"; $sql = "SELECT COUNT(id) AS listens, post_id FROM {$this->_table} GROUP BY post_id ORDER BY listens DESC LIMIT 10"; $results = $wpdb->get_results($sql); $html .= '<ul>' . "\n"; $li_class = 'alternate'; foreach ($results as $result) { $episode = get_post($result->post_id); $episode_link = admin_url('post.php?post=' . $episode->ID . '&action=edit'); $html .= '<li class="' . esc_attr($li_class) . '"><span class="first-col top-ten-count">' . sprintf(_n('%d %slisten%s', '%d %slistens%s', $result->listens, 'seriously-simple-stats'), $result->listens, '<span>', '</span>') . '</span> <span class="top-ten-title"><a href="' . $episode_link . '">' . esc_html($episode->post_title) . '</a></span></li>' . "\n"; if ('' == $li_class) { $li_class = 'alternate'; } else { $li_class = ''; } } $html .= '</ul>' . "\n"; $html .= '</div>' . "\n"; $html .= '</div>' . "\n"; } $html .= '</div>' . "\n"; $html .= '</div>' . "\n"; $wpdb->flush(); echo $html; }