From 8a857992cab1d07b1aa056ec754d65832c685c2d Mon Sep 17 00:00:00 2001 From: Matt Sims Date: Thu, 18 May 2017 20:53:21 +0100 Subject: [PATCH 01/15] Only generate charts on stats page. --- includes/class-ssp-stats.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/includes/class-ssp-stats.php b/includes/class-ssp-stats.php index c4b226f..4c47b82 100755 --- a/includes/class-ssp-stats.php +++ b/includes/class-ssp-stats.php @@ -739,14 +739,17 @@ private function daily_stat ( $number = '', $description = '' ) { * @since 1.0.0 * @return void */ - public function chart_data () { + public function chart_data ( $hook = '' ) { - $output = ''; + if( 'podcast_page_podcast_stats' == $hook ) { + + $output = ''; - $output .= $this->daily_listens_chart(); - $output .= $this->referrers_chart(); + $output .= $this->daily_listens_chart(); + $output .= $this->referrers_chart(); - echo $output; + echo $output; + } } /** From 409ffbce6540e12055325a37be90ce9c79857cbd Mon Sep 17 00:00:00 2001 From: JTrial <31481033+JTrial@users.noreply.github.com> Date: Mon, 11 Sep 2017 00:02:28 +0200 Subject: [PATCH 02/15] New Features - Dashboard widget added to display the past months listens - Android device listens are counted towards stats - Past three months stats are shown for all episodes --- assets/css/admin.css | 2 +- includes/class-ssp-stats.php | 458 ++++++++++++++++++++++++++++++++++- 2 files changed, 455 insertions(+), 5 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index 3208ac8..e013e91 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -1 +1 @@ -#podcast-episode-stats .episode-stat-data:before{font:normal 20px/1 'dashicons';color:#888;speak:none;display:inline-block;padding:0 2px 0 0;top:0;left:-1px;position:relative;vertical-align:top;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-decoration:none !important}#podcast-episode-stats .episode-stat-data.total-downloads:before{content:"\f521"}#podcast-episode-stats .episode-stat-data.total-listeners:before{content:'\f307'}#podcast-episode-stats .episode-stat-data.sources{font-weight:bold;margin-bottom:0}#podcast-episode-stats .episode-stat-data.sources:before{content:'\f319'}#podcast-episode-stats ul.sources-list{text-indent:10px;margin-top:2px}#podcast-episode-stats ul.sources-list li{font-style:italic}#podcast-episode-stats ul.sources-list li:before{font:normal 100%/1 'dashicons';color:#888;speak:none;display:inline-block;padding:0 2px 0 0;top:0;left:-1px;position:relative;vertical-align:middle;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-decoration:none !important}#podcast-episode-stats ul.sources-list li.itunes:before,#podcast-episode-stats ul.sources-list li.stitcher:before,#podcast-episode-stats ul.sources-list li.overcast:before,#podcast-episode-stats ul.sources-list li.pocketcasts:before{content:'\f482'}#podcast-episode-stats ul.sources-list li.direct:before{content:'\f316'}#podcast-episode-stats ul.sources-list li.new_window:before{content:"\f504"}#podcast-episode-stats ul.sources-list li.player:before{content:"\f522"}#podcast-episode-stats ul.sources-list li.unknown:before{content:'\f223'}#podcast-episode-stats .no-activity{overflow:hidden;padding:0 0 12px;text-align:center}#podcast-episode-stats .no-activity p{color:#999;font-size:16px}#podcast-episode-stats .no-activity p.smiley{margin-top:0}#podcast-episode-stats .no-activity p.smiley:before{content:"\f328";font:normal 120px/1 dashicons;speak:none;display:block;margin:0 5px 0 0;padding:0;text-indent:0;text-align:center;position:relative;-webkit-font-smoothing:antialiased;text-decoration:none !important}#podcast_settings .clear{clear:both;float:none}#podcast_settings .hndle{cursor:default !important}#podcast_settings #no-stats-container .no-activity{overflow:hidden;padding:0 0 12px;text-align:center}#podcast_settings #no-stats-container .no-activity p{color:#999;font-size:16px}#podcast_settings #no-stats-container .no-activity p.smiley{margin-top:0}#podcast_settings #no-stats-container .no-activity p.smiley:before{content:"\f328";font:normal 120px/1 dashicons;speak:none;display:block;margin:0 5px 0 0;padding:0;text-indent:0;text-align:center;position:relative;-webkit-font-smoothing:antialiased;text-decoration:none !important}#podcast_settings #content-filter-container .inside{padding-bottom:0}#podcast_settings #content-filter-container #content-filter-button{margin-left:5px}#podcast_settings .overview-stat{width:25%;float:left;text-align:center}#podcast_settings .overview-stat .stat-total{font-size:400%;line-height:1;margin-bottom:10px;font-weight:bold}#podcast_settings .overview-stat .stat-description{font-style:italic}#podcast_settings #top-ten-container .inside{margin:0;padding:0}#podcast_settings #top-ten-container .inside ul{list-style:none;margin:0}#podcast_settings #top-ten-container .inside ul li{margin:0;padding:10px}#podcast_settings #top-ten-container .inside ul li.headers{font-weight:bold}#podcast_settings #top-ten-container .inside ul li .first-col{display:inline-block;width:100px}#podcast_settings #top-ten-container .inside ul li .first-col.top-ten-count{font-size:150%}#podcast_settings #top-ten-container .inside ul li .first-col.top-ten-count span{font-size:60%}#podcast_settings #top-ten-container .inside ul li .top-ten-title{font-size:135%} \ No newline at end of file +#podcast-episode-stats .episode-stat-data:before{font:normal 20px/1 'dashicons';color:#888;speak:none;display:inline-block;padding:0 2px 0 0;top:0;left:-1px;position:relative;vertical-align:top;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-decoration:none !important}#podcast-episode-stats .episode-stat-data.total-downloads:before{content:"\f521"}#podcast-episode-stats .episode-stat-data.total-listeners:before{content:'\f307'}#podcast-episode-stats .episode-stat-data.sources{font-weight:bold;margin-bottom:0}#podcast-episode-stats .episode-stat-data.sources:before{content:'\f319'}#podcast-episode-stats ul.sources-list{text-indent:10px;margin-top:2px}#podcast-episode-stats ul.sources-list li{font-style:italic}#podcast-episode-stats ul.sources-list li:before{font:normal 100%/1 'dashicons';color:#888;speak:none;display:inline-block;padding:0 2px 0 0;top:0;left:-1px;position:relative;vertical-align:middle;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-decoration:none !important}#podcast-episode-stats ul.sources-list li.itunes:before,#podcast-episode-stats ul.sources-list li.stitcher:before,#podcast-episode-stats ul.sources-list li.overcast:before,#podcast-episode-stats ul.sources-list li.pocketcasts:before{content:'\f482'}#podcast-episode-stats ul.sources-list li.direct:before{content:'\f316'}#podcast-episode-stats ul.sources-list li.new_window:before{content:"\f504"}#podcast-episode-stats ul.sources-list li.player:before{content:"\f522"}#podcast-episode-stats ul.sources-list li.unknown:before{content:'\f223'}#podcast-episode-stats .no-activity{overflow:hidden;padding:0 0 12px;text-align:center}#podcast-episode-stats .no-activity p{color:#999;font-size:16px}#podcast-episode-stats .no-activity p.smiley{margin-top:0}#podcast-episode-stats .no-activity p.smiley:before{content:"\f328";font:normal 120px/1 dashicons;speak:none;display:block;margin:0 5px 0 0;padding:0;text-indent:0;text-align:center;position:relative;-webkit-font-smoothing:antialiased;text-decoration:none !important}#podcast_settings .clear{clear:both;float:none}#podcast_settings .hndle{cursor:default !important}#podcast_settings #no-stats-container .no-activity{overflow:hidden;padding:0 0 12px;text-align:center}#podcast_settings #no-stats-container .no-activity p{color:#999;font-size:16px}#podcast_settings #no-stats-container .no-activity p.smiley{margin-top:0}#podcast_settings #no-stats-container .no-activity p.smiley:before{content:"\f328";font:normal 120px/1 dashicons;speak:none;display:block;margin:0 5px 0 0;padding:0;text-indent:0;text-align:center;position:relative;-webkit-font-smoothing:antialiased;text-decoration:none !important}#podcast_settings #content-filter-container .inside{padding-bottom:0}#podcast_settings #content-filter-container #content-filter-button{margin-left:5px}#podcast_settings .overview-stat{width:25%;float:left;text-align:center}#podcast_settings .overview-stat .stat-total{font-size:400%;line-height:1;margin-bottom:10px;font-weight:bold}#podcast_settings .overview-stat .stat-description{font-style:italic}#podcast_settings #top-ten-container .inside{margin:0;padding:0}#podcast_settings #top-ten-container .inside ul{list-style:none;margin:0}#podcast_settings #top-ten-container .inside ul li{margin:0;padding:10px}#podcast_settings #top-ten-container .inside ul li.headers{font-weight:bold}#podcast_settings #top-ten-container .inside ul li .first-col{display:inline-block;width:100px}#podcast_settings #top-ten-container .inside ul li .first-col.top-ten-count{font-size:150%}#podcast_settings #top-ten-container .inside ul li .first-col.top-ten-count span{font-size:60%}#podcast_settings #top-ten-container .inside ul li .top-ten-title{font-size:135%} .dashboard_widget_podcast_settings .overview-stat{ width: 33% !important; } .ssps_last_30_days_graph_text{ text-align: right; } td.ssp_stats_3m_total { background-color: #f3f3f3; } \ No newline at end of file diff --git a/includes/class-ssp-stats.php b/includes/class-ssp-stats.php index c4b226f..a9cd230 100755 --- a/includes/class-ssp-stats.php +++ b/includes/class-ssp-stats.php @@ -227,6 +227,10 @@ public function __construct ( $file = '', $version = '1.0.0', $db_version = '1.0 // Handle localisation add_action( 'plugins_loaded', array( $this, 'load_localisation' ) ); + + // Add dashboard widget + add_action( 'wp_dashboard_setup', array( $this, 'add_dashboard_widget' ), 1 ); + } // End __construct () public function load_episode_ids () { @@ -297,6 +301,8 @@ public function track_download ( $file = '', $episode = 0, $referrer = '' ) { $referrer = 'overcast'; } elseif ( stripos( $user_agent, 'Pocket Casts' ) !== false ) { $referrer = 'pocketcasts'; + } elseif( stripos( $user_agent, 'Android' ) !== false || stripos( $user_agent, 'PodcastAddict' ) !== false || stripos( $user_agent, 'Player FM' ) !== false || stripos( $user_agent, 'Google-Play' ) !== false ){ + $referrer = 'android'; } // Get episode ID for database insert @@ -425,6 +431,8 @@ public function stats_meta_box_content ( $post ) { case 'player': ++$player; break; + case 'android': + ++$android; default: ++$unknown; break; @@ -457,6 +465,9 @@ public function stats_meta_box_content ( $post ) { if( $player ) { $html .= '
  • ' . __( 'Audio player', 'seriously-simple-stats' ) . ': ' . $player . '
  • '; } + if( $android ){ + $html .= '
  • ' . __( 'Android App', 'seriously-simple-stats' ) . ': ' . $android . '
  • '; + } if( $unknown ) { $html .= '
  • ' . __( 'Other', 'seriously-simple-stats' ) . ': ' . $unknown . '
  • '; } @@ -713,6 +724,294 @@ public function stats_page () { $html .= '' . "\n"; $html .= '' . "\n"; + + //Displays all episodes, 25 per page + $html .= '
    ' . "\n"; + $html .= '<' . $metabox_title . ' class="hndle ui-sortable-handle">' . "\n"; + + $html .= '' . __( 'All Episodes for the Last Three Months', 'seriously-simple-stats' ) . '' . "\n"; + $html .= '' . "\n"; + $html .= '
    ' . "\n"; + + + $referrer_data = array(); + $all_episodes_stats = array(); + + $referrer_labels = array( + 'download' => __( 'Direct download', 'seriously-simple-stats' ), + 'player' => __( 'Audio player', 'seriously-simple-stats' ), + 'new_window' => __( 'Played in new window', 'seriously-simple-stats' ), + 'itunes' => __( 'iTunes', 'seriously-simple-stats' ), + 'stitcher' => __( 'Stitcher', 'seriously-simple-stats' ), + 'overcast' => __( 'Overcast', 'seriously-simple-stats' ), + 'pocketcasts' => __( 'Pocket Casts', 'seriously-simple-stats' ), + 'other' => __( 'Other', 'seriously-simple-stats' ), + 'android' => __('Android App', 'seriously-simple-stats') + ); + + $this->start_date = strtotime( current_time('Y-m-d').' -2 MONTH' ); + + $sql = "SELECT COUNT(id) AS listens, post_id FROM $this->_table GROUP BY post_id"; + + if( isset( $_GET['orderby'] ) ){ + + if( $_GET['orderby'] == 'date' ){ + + $order = isset( $_GET['order'] ) ? sanitize_text_field( $_GET['order'] ) : "desc"; + + $sql .= " ORDER BY date ".$order; + + } + + } else { + + $sql .= " ORDER BY `date` DESC"; + + } + + $results = $wpdb->get_results( $sql ); + + $total_posts = count( $results ); + + if( is_array( $results ) ){ + + foreach( $results as $result ){ + + // Define the previous three months array keys + $total_listens_array = array( + intval( current_time( 'm' ) ) => 0, + intval( date( 'm', strtotime( current_time('Y-m-d').' -1 MONTH' ) ) ) => 0, + intval( date( 'm', strtotime( current_time('Y-m-d').' -2 MONTH' ) ) ) => 0 + ); + + $post = get_post( intval( $result->post_id ) ); + + $sql = "SELECT `date` FROM $this->_table WHERE `post_id` = '".$result->post_id."' AND `date` >= ".$this->start_date; + + $episode_results = $wpdb->get_results( $sql ); + + $listens = 0; + + $pretty_referrer_data = array(); + + foreach( $episode_results as $ref ) { + + //Increase the count of listens per month + ++$total_listens_array[intval( date('m', intval( $ref->date ) ) )]; + $listens++; + + } + + //Allows for sorting based on listens for a specific month + if( isset( $_GET['month_num'])){ + $total_listens = $total_listens_array[intval( $_GET['month_num'] )]; + } else{ + $total_listens = $listens; + } + + $all_episodes_stats[] = apply_filters( 'ssp_stats_three_months_all_episodes', array( + 'episode_name' => $post->post_title, + 'date' => date( 'Y-m-d', strtotime( $post->post_date ) ), + 'slug' => admin_url('post.php?post='.$post->ID.'&action=edit'), + 'listens' => $listens, + 'listens_array' => $total_listens_array, + 'order_listens' => $total_listens + ) ); + + } + + } + + //24 because we're counting an array + $total_per_page = apply_filters( 'ssp_stats_three_months_per_page', 24 ); + + $month_num_cur = current_time('m'); + $month_num_prev = date('m', strtotime( current_time("Y-m-d")." -1 MONTH" ) ); + $month_num_prior = date('m', strtotime( current_time("Y-m-d")." -2 MONTH" ) ); + + //Set default page sorting URLs for the table headers + $episode_name_url = admin_url("edit.php?post_type=podcast&page=podcast_stats&orderby=title&order=desc#last-three-months-container"); + + $published_url = admin_url("edit.php?post_type=podcast&page=podcast_stats&orderby=date&order=desc#last-three-months-container"); + + $listens_m_1 = admin_url("edit.php?post_type=podcast&page=podcast_stats&orderby=listens&month_num=".$month_num_cur."&order=desc#last-three-months-container"); + + $listens_m_2 = admin_url("edit.php?post_type=podcast&page=podcast_stats&orderby=listens&month_num=".$month_num_prev."&order=desc#last-three-months-container"); + + $listens_m_3 = admin_url("edit.php?post_type=podcast&page=podcast_stats&orderby=listens&month_num=".$month_num_prior."&order=desc#last-three-months-container"); + + $listens = admin_url("edit.php?post_type=podcast&page=podcast_stats&orderby=listens&order=desc#last-three-months-container"); + + if( isset( $_GET['orderby'] ) ){ + + //Get or set the order + if( isset( $_GET['order'] ) ){ + if( $_GET['order'] == 'asc' ){ + $order = 'desc'; + } else { + $order = 'asc'; + } + } else { + $order = 'desc'; + } + + //Get the current page number + if( isset( $_GET['pagenum'] ) ){ + $page_num = "&pagenum=".intval( $_GET['pagenum'] ); + } else { + $page_num = ""; + } + + if( $_GET['orderby'] == 'title' ){ + + //Order according to title of episode + $episode_name_url = admin_url("edit.php?post_type=podcast&page=podcast_stats&orderby=title&order=$order".$page_num."#last-three-months-container"); + + } else if( $_GET['orderby'] == 'listens' ){ + + //Order according to total listens or per month + $listens = admin_url("edit.php?post_type=podcast&page=podcast_stats&orderby=listens&order=$order".$page_num."#last-three-months-container"); + + $listens_m_1 = admin_url("edit.php?post_type=podcast&page=podcast_stats&orderby=listens&month_num=".$month_num_cur."&order=$order".$page_num."#last-three-months-container"); + + $listens_m_2 = admin_url("edit.php?post_type=podcast&page=podcast_stats&orderby=listens&month_num=".$month_num_prev."&order=$order".$page_num."#last-three-months-container"); + + $listens_m_3 = admin_url("edit.php?post_type=podcast&page=podcast_stats&orderby=listens&month_num=".$month_num_prior."&order=$order".$page_num."#last-three-months-container"); + + } else if( $_GET['orderby'] == 'date' ){ + //Order according to published date of episode + $published_url = admin_url("edit.php?post_type=podcast&page=podcast_stats&orderby=date&order=$order".$page_num."#last-three-months-container"); + + } + + } + + $html .= ""; + $html .= " "; + $html .= " "; + $html .= " "; + $html .= " "; + $html .= " "; + $html .= " "; + $html .= " "; + $html .= " "; + $html .= " "; + $html .= " "; + + if( !empty( $all_episodes_stats ) && is_array( $all_episodes_stats ) ){ + + //Sorting by total listens + if( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'listens' ){ + + if( isset( $_GET['order'] ) ){ + + if( $_GET['order'] == 'asc' ){ + $order_flag = SORT_ASC; + } else { + $order_flag = SORT_DESC; + } + + } else { + $order_flag = SORT_DESC; + } + + $listen_sorting = array(); + foreach( $all_episodes_stats as $listen ){ + $listen_sorting[] = $listen['order_listens']; + } + + array_multisort( $listen_sorting, SORT_NUMERIC, $order_flag, $all_episodes_stats ); + + } + + if( isset( $_GET['pagenum'] ) ){ + + $pagenum = intval( $_GET['pagenum'] ); + + if( $pagenum <= 1){ + $current_cursor = 0; + } else { + $current_cursor = ($pagenum - 1)* $total_per_page; + } + + $next_cursor = $total_per_page * $pagenum; + + $all_episodes_stats = array_slice( $all_episodes_stats, $current_cursor, $total_per_page , true ); + + } else { + + $all_episodes_stats = array_slice( $all_episodes_stats, 0, $total_per_page, true ); + + } + + //Display the data + foreach( $all_episodes_stats as $ep ){ + + $html .= ""; + $html .= " "; + $html .= " "; + if( isset( $ep['listens_array'] ) ){ + foreach( $ep['listens_array'] as $listen ){ + //Each months total listens + $html .= ""; + } + } + //Total Listen Count + $html .= " "; + $html .= ""; + + } + + } + + $html .= "
    ".__('Episode Name', 'seriously-simple-stats')."".__('Publish Date', 'seriously-simple-stats')."".current_time('F')."".date('F', strtotime( current_time("Y-m-d")." -1 MONTH" ) )."".date('F', strtotime( current_time("Y-m-d")." -2 MONTH" ) )."".__('Total', 'seriously-simple-stats')."
    ".$ep['episode_name']."".$ep['date']."".$listen."".$ep['listens']."
    "; + + //Only show page links if there's more than 25 episodes in the table + $pagination_html = ""; + if( $total_posts >= $total_per_page ){ + + if( isset( $_GET['pagenum'] ) ){ + $pagenum = intval( $_GET['pagenum'] ); + } else { + $pagenum = 1; + } + + $total_pages = ceil($total_posts/$total_per_page); + + $pagination_html .= "
    "; + $pagination_html .= '
    '; + $pagination_html .= ' '.$total_posts.' '.__('items', 'seriously-simple-stats').''; + + $prev_page = ( $pagenum <= 1 ) ? 1 : $pagenum - 1; + + $order_by = isset( $_GET['orderby'] ) ? '&orderby='.sanitize_text_field( $_GET['orderby'] ) : ""; + + $order = isset( $_GET['order'] ) ? '&order='.sanitize_text_field( $_GET['order'] ) : ""; + + $month_num = isset( $_GET['month_num'] ) ? '&month_num='.sanitize_text_field( $_GET['month_num'] ) : ""; + + $pagination_html .= " "; + if( $pagenum != 1 ){ + $pagination_html .= ' '.__('Previous page', 'seriously-simple-stats').''; + } + + $pagination_html .= ' '.$pagenum.' of '.$total_pages.' '; + + $next_page = $pagenum + 1; + + if( $next_page <= $total_pages ){ + $pagination_html .= ' '.__('Next page', 'seriously-simple-stats').''; + } + $pagination_html .= "  "; + $pagination_html .= "
    "; + $pagination_html .= "
    "; + } + + $html .= $pagination_html; + + $html .= '
    ' . "\n"; + $html .= '
    ' . "\n"; + } $html .= '' . "\n"; @@ -791,6 +1090,55 @@ private function daily_listens_chart () { return $this->generate_chart( 'LineChart', '', $columns, $data, 'daily_listens' ); } + /** + * Return data for weekly Listens chart + * @access private + * @since 1.0.0 + * @param integer $start_date Start date of chart data + * @param integer $end_date End date of chart data + * @return string Javascript for chart generation + */ + private function weekly_listens_chart () { + + global $wpdb; + + $columns = array( + __( 'Week', 'seriously-simple-stats' ) => 'date', + __( 'Listens', 'seriously-simple-stats' ) => 'number', + ); + + $episode_id_where = ''; + if( $this->episode_id_where ) { + $episode_id_where = 'AND ' . $this->episode_id_where; + } + + // $this->start_date = strtotime( current_time('mysql')." - 2 MONTH" ); + + $sql = $wpdb->prepare( "SELECT date FROM $this->_table WHERE date BETWEEN %d AND %d $episode_id_where", $this->start_date, $this->end_date ); + $results = $wpdb->get_results( $sql ); + + $date_data = array(); + foreach( $results as $timestamp ) { + $date = date( 'Y-m-d', $timestamp->date ); + + if( isset( $date_data[ $date ] ) ) { + ++$date_data[ $date ]; + } else { + $date_data[ $date ] = 1; + } + } + ksort( $date_data ); + + $data = array(); + + foreach( $date_data as $date => $listens ){ + $data[] = array( $date, $listens ); + } + + return $this->generate_chart( 'LineChart', '', $columns, $data, 'weekly_listens', '100%' ); + + } + /** * Return data for Referrers chart * @access private @@ -844,6 +1192,7 @@ private function referrers_chart () { 'overcast' => __( 'Overcast', 'seriously-simple-stats' ), 'pocketcasts' => __( 'Pocket Casts', 'seriously-simple-stats' ), 'other' => __( 'Other', 'seriously-simple-stats' ), + 'android' => __('Android App', 'seriously-simple-stats') ); $data = array(); @@ -885,18 +1234,28 @@ private function generate_chart ( $type = '', $title = '', $columns = array(), $ } $column_data = ''; + $column_date = 0; foreach( $columns as $column_label => $column_type ) { $column_data .= "data.addColumn('$column_type', '$column_label');" . "\n"; + //Added to ensure a unix timestamp is created for this column types data + if( $column_type === 'date' ){ + $column_date++; + } } $chart_data = ''; + foreach( $data as $data_set ) { $chart_data .= "["; foreach( $data_set as $item ) { if( is_numeric( $item ) ) { $chart_data .= "$item,"; } else { - $chart_data .= "'$item',"; + if( $column_date > 0 ){ + $chart_data .= "new Date('$item'),"; + } else { + $chart_data .= "'$item',"; + } } } $chart_data .= "]," . "\n"; @@ -906,6 +1265,7 @@ private function generate_chart ( $type = '', $title = '', $columns = array(), $ $chartid = uniqid() . '_' . mt_rand( 0, 9999 ); $options = ''; + switch( $type ) { case 'LineChart': $options .= "legend: 'none'," . "\n"; @@ -944,8 +1304,10 @@ function draw_chart_() { }; // Instantiate and draw the chart - var chart = new google.visualization.( document.getElementById( '' ) ); - chart.draw( data, options ); + if( jQuery( '#'+'' ).length > 0 ){ + var chart = new google.visualization.( document.getElementById( '' ) ); + chart.draw( data, options ); + } // chart.draw( data, google.charts.Line.convertOptions(options) ); } @@ -963,7 +1325,8 @@ function draw_chart_() { */ public function admin_enqueue_scripts ( $hook = '' ) { - if( 'podcast_page_podcast_stats' == $hook ) { + //index.php added to accommodate dashboard widget chart + if( 'podcast_page_podcast_stats' == $hook || 'index.php' == $hook ) { // Include Google Charts scripts wp_enqueue_script( 'google-charts', "//www.google.com/jsapi?autoload={ @@ -1092,4 +1455,91 @@ private function _log_version_number () { update_option( $this->_token . '_version', $this->_version ); } // End _log_version_number () + + /** + * Adds a widget to the dashboard to show relevant stats + * @access public + * @since 1.2 + * @return void + */ + public function add_dashboard_widget(){ + + add_meta_box( 'ssp_stats_dashboard_widget', __('Seriously Simple Stats - Overview', 'seriously-simple-stats' ), array( $this, 'dashboard_widget_callback' ), 'dashboard', 'normal', 'high' ); + + } + + /** + * Callback for the dashboard widget + * @access public + * @since 1.2 + * @return string + */ + public function dashboard_widget_callback(){ + + global $wpdb; + + $html = ""; + + $html .= "
    "; + + // 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 .= '
    ' . "\n"; + $html .= '
    ' . "\n"; + $html .= '

    ' . "\n"; + $html .= '

    ' . sprintf( __( 'No stats %s yet!', 'seriously-simple-stats' ), $no_stats_filler ) . '

    ' . "\n"; + $html .= '
    ' . "\n"; + $html .= '
    ' . "\n"; + } else { + + $html .= "

    ".__('Last 30 Days', 'seriously-simple-stats')." ".__('View All Data', 'seriously-simple-stats').""."

    "; + + $html .= "
    "; + + $this->start_date = strtotime( current_time( 'Y-m-d H:i:s' ) . ' -30 DAY' ); + + $html .= $this->weekly_listens_chart(); + + $html .= '
    ' . "\n"; + $html .= '
    ' . "\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' ) ); + + $html .= '
    '; + + $html .= '
    ' . "\n"; + $html .= '
    ' . "\n"; + + } + + $html .= "
    "; + + echo $html; + + } } From 817784d5daefa7546bda9c189cd9840c4d46f47a Mon Sep 17 00:00:00 2001 From: JTrial <31481033+JTrial@users.noreply.github.com> Date: Mon, 11 Sep 2017 00:09:41 +0200 Subject: [PATCH 03/15] Ability to order by title --- includes/class-ssp-stats.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/includes/class-ssp-stats.php b/includes/class-ssp-stats.php index a9cd230..6416669 100755 --- a/includes/class-ssp-stats.php +++ b/includes/class-ssp-stats.php @@ -901,7 +901,7 @@ public function stats_page () { if( !empty( $all_episodes_stats ) && is_array( $all_episodes_stats ) ){ //Sorting by total listens - if( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'listens' ){ + if( isset( $_GET['orderby'] ) && ( $_GET['orderby'] == 'listens' || $_GET['orderby'] == 'title' ) ){ if( isset( $_GET['order'] ) ){ @@ -916,11 +916,18 @@ public function stats_page () { } $listen_sorting = array(); + + if( $_GET['orderby'] == 'listens' ){ + $order_type = 'order_listens'; + } else { + $order_type = 'episode_name'; + } + foreach( $all_episodes_stats as $listen ){ - $listen_sorting[] = $listen['order_listens']; + $listen_sorting[] = $listen[$order_type]; } - array_multisort( $listen_sorting, SORT_NUMERIC, $order_flag, $all_episodes_stats ); + array_multisort( $listen_sorting, $order_flag, $all_episodes_stats ); } From 9cf5ef28b611fba7b7dbfbf3b1af938b52262e11 Mon Sep 17 00:00:00 2001 From: JTrial <31481033+JTrial@users.noreply.github.com> Date: Tue, 12 Sep 2017 23:50:54 +0200 Subject: [PATCH 04/15] Separated newly added services --- includes/class-ssp-stats.php | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/includes/class-ssp-stats.php b/includes/class-ssp-stats.php index 6416669..d6fb72a 100755 --- a/includes/class-ssp-stats.php +++ b/includes/class-ssp-stats.php @@ -301,8 +301,14 @@ public function track_download ( $file = '', $episode = 0, $referrer = '' ) { $referrer = 'overcast'; } elseif ( stripos( $user_agent, 'Pocket Casts' ) !== false ) { $referrer = 'pocketcasts'; - } elseif( stripos( $user_agent, 'Android' ) !== false || stripos( $user_agent, 'PodcastAddict' ) !== false || stripos( $user_agent, 'Player FM' ) !== false || stripos( $user_agent, 'Google-Play' ) !== false ){ + } elseif( stripos( $user_agent, 'Android' ) !== false ){ $referrer = 'android'; + } elseif( stripos( $user_agent, 'PodcastAddict' ) !== false ){ + $referrer = 'podcast_addict'; + } elseif( stripos( $user_agent, 'Player FM' ) !== false ){ + $referrer = 'playerfm'; + } elseif( stripos( $user_agent, 'Google-Play' ) !== false ){ + $referrer = 'google_play'; } // Get episode ID for database insert @@ -433,6 +439,12 @@ public function stats_meta_box_content ( $post ) { break; case 'android': ++$android; + case 'podcast_addict': + ++$podcast_addict; + case 'playerfm': + ++$playerfm; + case 'google_play': + ++$google_play; default: ++$unknown; break; @@ -468,6 +480,15 @@ public function stats_meta_box_content ( $post ) { if( $android ){ $html .= '
  • ' . __( 'Android App', 'seriously-simple-stats' ) . ': ' . $android . '
  • '; } + if( $podcast_addict ){ + $html .= '
  • ' . __( 'Podcast Addict', 'seriously-simple-stats' ) . ': ' . $podcast_addict . '
  • '; + } + if( $playerfm ){ + $html .= '
  • ' . __( 'Player FM', 'seriously-simple-stats' ) . ': ' . $playerfm . '
  • '; + } + if( $google_play ){ + $html .= '
  • ' . __( 'Google Play', 'seriously-simple-stats' ) . ': ' . $google_play . '
  • '; + } if( $unknown ) { $html .= '
  • ' . __( 'Other', 'seriously-simple-stats' ) . ': ' . $unknown . '
  • '; } @@ -746,7 +767,10 @@ public function stats_page () { 'overcast' => __( 'Overcast', 'seriously-simple-stats' ), 'pocketcasts' => __( 'Pocket Casts', 'seriously-simple-stats' ), 'other' => __( 'Other', 'seriously-simple-stats' ), - 'android' => __('Android App', 'seriously-simple-stats') + 'android' => __('Android App', 'seriously-simple-stats'), + 'podcast_addict' => __( 'Podcast Addict', 'seriously-simple-stats' ), + 'playerfm' => __( 'Player FM', 'seriously-simple-stats' ), + 'google_play' => __( 'Google Play', 'seriously-simple-stats' ) ); $this->start_date = strtotime( current_time('Y-m-d').' -2 MONTH' ); @@ -1199,7 +1223,10 @@ private function referrers_chart () { 'overcast' => __( 'Overcast', 'seriously-simple-stats' ), 'pocketcasts' => __( 'Pocket Casts', 'seriously-simple-stats' ), 'other' => __( 'Other', 'seriously-simple-stats' ), - 'android' => __('Android App', 'seriously-simple-stats') + 'android' => __('Android App', 'seriously-simple-stats'), + 'podcast_addict' => __( 'Podcast Addict', 'seriously-simple-stats' ), + 'playerfm' => __( 'Player FM', 'seriously-simple-stats' ), + 'google_play' => __( 'Google Play', 'seriously-simple-stats' ) ); $data = array(); From d9c773c04c5ba03c188885ed9054d129b626f057 Mon Sep 17 00:00:00 2001 From: JTrial <31481033+JTrial@users.noreply.github.com> Date: Wed, 27 Sep 2017 15:15:17 +0200 Subject: [PATCH 05/15] Updated Changes - Dashboard widget graph width adjusted - Dashboard widget graph labels set to only show the month and day - Last three months stats has been moved above the top 10 episodes of all time - Published date moved to show before the episode name - Ordering removed from the Last Three Months table - Unused variables removed - Android/Google Play stats are set to still record, but not display on any graphs --- assets/css/admin.css | 2 +- includes/class-ssp-stats.php | 331 ++++++++++++----------------------- 2 files changed, 116 insertions(+), 217 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index e013e91..9ff56ad 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -1 +1 @@ -#podcast-episode-stats .episode-stat-data:before{font:normal 20px/1 'dashicons';color:#888;speak:none;display:inline-block;padding:0 2px 0 0;top:0;left:-1px;position:relative;vertical-align:top;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-decoration:none !important}#podcast-episode-stats .episode-stat-data.total-downloads:before{content:"\f521"}#podcast-episode-stats .episode-stat-data.total-listeners:before{content:'\f307'}#podcast-episode-stats .episode-stat-data.sources{font-weight:bold;margin-bottom:0}#podcast-episode-stats .episode-stat-data.sources:before{content:'\f319'}#podcast-episode-stats ul.sources-list{text-indent:10px;margin-top:2px}#podcast-episode-stats ul.sources-list li{font-style:italic}#podcast-episode-stats ul.sources-list li:before{font:normal 100%/1 'dashicons';color:#888;speak:none;display:inline-block;padding:0 2px 0 0;top:0;left:-1px;position:relative;vertical-align:middle;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-decoration:none !important}#podcast-episode-stats ul.sources-list li.itunes:before,#podcast-episode-stats ul.sources-list li.stitcher:before,#podcast-episode-stats ul.sources-list li.overcast:before,#podcast-episode-stats ul.sources-list li.pocketcasts:before{content:'\f482'}#podcast-episode-stats ul.sources-list li.direct:before{content:'\f316'}#podcast-episode-stats ul.sources-list li.new_window:before{content:"\f504"}#podcast-episode-stats ul.sources-list li.player:before{content:"\f522"}#podcast-episode-stats ul.sources-list li.unknown:before{content:'\f223'}#podcast-episode-stats .no-activity{overflow:hidden;padding:0 0 12px;text-align:center}#podcast-episode-stats .no-activity p{color:#999;font-size:16px}#podcast-episode-stats .no-activity p.smiley{margin-top:0}#podcast-episode-stats .no-activity p.smiley:before{content:"\f328";font:normal 120px/1 dashicons;speak:none;display:block;margin:0 5px 0 0;padding:0;text-indent:0;text-align:center;position:relative;-webkit-font-smoothing:antialiased;text-decoration:none !important}#podcast_settings .clear{clear:both;float:none}#podcast_settings .hndle{cursor:default !important}#podcast_settings #no-stats-container .no-activity{overflow:hidden;padding:0 0 12px;text-align:center}#podcast_settings #no-stats-container .no-activity p{color:#999;font-size:16px}#podcast_settings #no-stats-container .no-activity p.smiley{margin-top:0}#podcast_settings #no-stats-container .no-activity p.smiley:before{content:"\f328";font:normal 120px/1 dashicons;speak:none;display:block;margin:0 5px 0 0;padding:0;text-indent:0;text-align:center;position:relative;-webkit-font-smoothing:antialiased;text-decoration:none !important}#podcast_settings #content-filter-container .inside{padding-bottom:0}#podcast_settings #content-filter-container #content-filter-button{margin-left:5px}#podcast_settings .overview-stat{width:25%;float:left;text-align:center}#podcast_settings .overview-stat .stat-total{font-size:400%;line-height:1;margin-bottom:10px;font-weight:bold}#podcast_settings .overview-stat .stat-description{font-style:italic}#podcast_settings #top-ten-container .inside{margin:0;padding:0}#podcast_settings #top-ten-container .inside ul{list-style:none;margin:0}#podcast_settings #top-ten-container .inside ul li{margin:0;padding:10px}#podcast_settings #top-ten-container .inside ul li.headers{font-weight:bold}#podcast_settings #top-ten-container .inside ul li .first-col{display:inline-block;width:100px}#podcast_settings #top-ten-container .inside ul li .first-col.top-ten-count{font-size:150%}#podcast_settings #top-ten-container .inside ul li .first-col.top-ten-count span{font-size:60%}#podcast_settings #top-ten-container .inside ul li .top-ten-title{font-size:135%} .dashboard_widget_podcast_settings .overview-stat{ width: 33% !important; } .ssps_last_30_days_graph_text{ text-align: right; } td.ssp_stats_3m_total { background-color: #f3f3f3; } \ No newline at end of file +#podcast-episode-stats .episode-stat-data:before{font:normal 20px/1 'dashicons';color:#888;speak:none;display:inline-block;padding:0 2px 0 0;top:0;left:-1px;position:relative;vertical-align:top;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-decoration:none !important}#podcast-episode-stats .episode-stat-data.total-downloads:before{content:"\f521"}#podcast-episode-stats .episode-stat-data.total-listeners:before{content:'\f307'}#podcast-episode-stats .episode-stat-data.sources{font-weight:bold;margin-bottom:0}#podcast-episode-stats .episode-stat-data.sources:before{content:'\f319'}#podcast-episode-stats ul.sources-list{text-indent:10px;margin-top:2px}#podcast-episode-stats ul.sources-list li{font-style:italic}#podcast-episode-stats ul.sources-list li:before{font:normal 100%/1 'dashicons';color:#888;speak:none;display:inline-block;padding:0 2px 0 0;top:0;left:-1px;position:relative;vertical-align:middle;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-decoration:none !important}#podcast-episode-stats ul.sources-list li.itunes:before,#podcast-episode-stats ul.sources-list li.stitcher:before,#podcast-episode-stats ul.sources-list li.overcast:before,#podcast-episode-stats ul.sources-list li.pocketcasts:before{content:'\f482'}#podcast-episode-stats ul.sources-list li.direct:before{content:'\f316'}#podcast-episode-stats ul.sources-list li.new_window:before{content:"\f504"}#podcast-episode-stats ul.sources-list li.player:before{content:"\f522"}#podcast-episode-stats ul.sources-list li.unknown:before{content:'\f223'}#podcast-episode-stats .no-activity{overflow:hidden;padding:0 0 12px;text-align:center}#podcast-episode-stats .no-activity p{color:#999;font-size:16px}#podcast-episode-stats .no-activity p.smiley{margin-top:0}#podcast-episode-stats .no-activity p.smiley:before{content:"\f328";font:normal 120px/1 dashicons;speak:none;display:block;margin:0 5px 0 0;padding:0;text-indent:0;text-align:center;position:relative;-webkit-font-smoothing:antialiased;text-decoration:none !important}#podcast_settings .clear{clear:both;float:none}#podcast_settings .hndle{cursor:default !important}#podcast_settings #no-stats-container .no-activity{overflow:hidden;padding:0 0 12px;text-align:center}#podcast_settings #no-stats-container .no-activity p{color:#999;font-size:16px}#podcast_settings #no-stats-container .no-activity p.smiley{margin-top:0}#podcast_settings #no-stats-container .no-activity p.smiley:before{content:"\f328";font:normal 120px/1 dashicons;speak:none;display:block;margin:0 5px 0 0;padding:0;text-indent:0;text-align:center;position:relative;-webkit-font-smoothing:antialiased;text-decoration:none !important}#podcast_settings #content-filter-container .inside{padding-bottom:0}#podcast_settings #content-filter-container #content-filter-button{margin-left:5px}#podcast_settings .overview-stat{width:25%;float:left;text-align:center}#podcast_settings .overview-stat .stat-total{font-size:400%;line-height:1;margin-bottom:10px;font-weight:bold}#podcast_settings .overview-stat .stat-description{font-style:italic}#podcast_settings #top-ten-container .inside{margin:0;padding:0}#podcast_settings #top-ten-container .inside ul{list-style:none;margin:0}#podcast_settings #top-ten-container .inside ul li{margin:0;padding:10px}#podcast_settings #top-ten-container .inside ul li.headers{font-weight:bold}#podcast_settings #top-ten-container .inside ul li .first-col{display:inline-block;width:100px}#podcast_settings #top-ten-container .inside ul li .first-col.top-ten-count{font-size:150%}#podcast_settings #top-ten-container .inside ul li .first-col.top-ten-count span{font-size:60%}#podcast_settings #top-ten-container .inside ul li .top-ten-title{font-size:135%} .dashboard_widget_podcast_settings .overview-stat{ width: 33% !important; } .ssps_last_30_days_graph_text{ text-align: right; } td.ssp_stats_3m_total { border-left: 1px solid #cdcdcd; } .dashboard_widget_podcast_settings .stat-total { font-size: 300% !important; } \ No newline at end of file diff --git a/includes/class-ssp-stats.php b/includes/class-ssp-stats.php index d6fb72a..c48ac66 100755 --- a/includes/class-ssp-stats.php +++ b/includes/class-ssp-stats.php @@ -288,27 +288,35 @@ public function track_download ( $file = '', $episode = 0, $referrer = '' ) { // Check for specific podcasting services in user agent // The iOS Podcasts app makes a HEAD request with user agent Podcasts/2.4 and then a GET request with user agent AppleCoreMedia - // This conditional will prevent double tracking from that app - if( stripos( $user_agent, 'podcasts/' ) !== false ) { - return; - } - - if ( stripos( $user_agent, 'itunes' ) !== false || stripos( $user_agent, 'AppleCoreMedia' ) !== false ) { - $referrer = 'itunes'; - } elseif ( stripos( $user_agent, 'stitcher' ) !== false ) { - $referrer = 'stitcher'; - } elseif ( stripos( $user_agent, 'overcast' ) !== false ) { - $referrer = 'overcast'; - } elseif ( stripos( $user_agent, 'Pocket Casts' ) !== false ) { - $referrer = 'pocketcasts'; - } elseif( stripos( $user_agent, 'Android' ) !== false ){ - $referrer = 'android'; - } elseif( stripos( $user_agent, 'PodcastAddict' ) !== false ){ - $referrer = 'podcast_addict'; - } elseif( stripos( $user_agent, 'Player FM' ) !== false ){ - $referrer = 'playerfm'; - } elseif( stripos( $user_agent, 'Google-Play' ) !== false ){ - $referrer = 'google_play'; + + switch( $user_agent ){ + case stripos( $user_agent, 'podcasts/' ) !== false: + // This conditional will prevent double tracking from that app + break; + case ( stripos( $user_agent, 'itunes' ) !== false || stripos( $user_agent, 'AppleCoreMedia' ) !== false ): + $referrer = 'itunes'; + break; + case stripos( $user_agent, 'stitcher' ) !== false: + $referrer = 'stitcher'; + break; + case stripos( $user_agent, 'overcast' ) !== false: + $referrer = 'overcast'; + break; + case stripos( $user_agent, 'Pocket Casts' ) !== false: + $referrer = 'pocketcasts'; + break; + case stripos( $user_agent, 'Android' ) !== false: + $referrer = 'android'; + break; + case stripos( $user_agent, 'PodcastAddict' ) !== false: + $referrer = 'podcast_addict'; + break; + case stripos( $user_agent, 'Player FM' ) !== false: + $referrer = 'playerfm'; + break; + case stripos( $user_agent, 'Google-Play' ) !== false: + $referrer = 'google_play'; + break; } // Get episode ID for database insert @@ -410,7 +418,7 @@ public function stats_meta_box_content ( $post ) { $html .= '

    ' . __( 'Total listens', 'seriously-simple-stats' ) . ': ' . $total_downloads . '

    '; $users = array(); - $itunes = $stitcher = $overcast = $pocketcasts = $direct = $new_window = $player = $unknown = 0; + $itunes = $stitcher = $overcast = $pocketcasts = $direct = $new_window = $player = $android = $podcast_addict = $playerfm = $google_play = $unknown = 0; foreach( $stats as $stat ) { $listeners[ $stat->ip_address ] = $stat->ip_address; @@ -477,18 +485,20 @@ public function stats_meta_box_content ( $post ) { if( $player ) { $html .= '
  • ' . __( 'Audio player', 'seriously-simple-stats' ) . ': ' . $player . '
  • '; } - if( $android ){ - $html .= '
  • ' . __( 'Android App', 'seriously-simple-stats' ) . ': ' . $android . '
  • '; - } + // Hidden but keeping for possible future use as per instruction + // if( $android ){ + // $html .= '
  • ' . __( 'Android App', 'seriously-simple-stats' ) . ': ' . $android . '
  • '; + // } if( $podcast_addict ){ $html .= '
  • ' . __( 'Podcast Addict', 'seriously-simple-stats' ) . ': ' . $podcast_addict . '
  • '; } if( $playerfm ){ $html .= '
  • ' . __( 'Player FM', 'seriously-simple-stats' ) . ': ' . $playerfm . '
  • '; } - if( $google_play ){ - $html .= '
  • ' . __( 'Google Play', 'seriously-simple-stats' ) . ': ' . $google_play . '
  • '; - } + // Hidden but keeping for possible future use as per instruction + // if( $google_play ){ + // $html .= '
  • ' . __( 'Google Play', 'seriously-simple-stats' ) . ': ' . $google_play . '
  • '; + // } if( $unknown ) { $html .= '
  • ' . __( 'Other', 'seriously-simple-stats' ) . ': ' . $unknown . '
  • '; } @@ -720,79 +730,20 @@ public function stats_page () { $html .= '' . "\n"; $html .= '' . "\n"; - $html .= '
    ' . "\n"; - $html .= '<' . $metabox_title . ' class="hndle ui-sortable-handle">' . "\n"; - $html .= '' . __( 'Top Ten Episodes of All Time', 'seriously-simple-stats' ) . '' . "\n"; - $html .= '' . "\n"; - $html .= '
    ' . "\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 .= '
      ' . "\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 .= '
    • ' . sprintf( _n( '%d %slisten%s', '%d %slistens%s', $result->listens, 'seriously-simple-stats' ), $result->listens, '', '' ) . ' ' . esc_html( $episode->post_title ) . '
    • ' . "\n"; - if( '' == $li_class ) { - $li_class = 'alternate'; - } else { - $li_class = ''; - } - } - $html .= '
    ' . "\n"; - - $html .= '
    ' . "\n"; - $html .= '
    ' . "\n"; - //Displays all episodes, 25 per page $html .= '
    ' . "\n"; $html .= '<' . $metabox_title . ' class="hndle ui-sortable-handle">' . "\n"; - - $html .= '' . __( 'All Episodes for the Last Three Months', 'seriously-simple-stats' ) . '' . "\n"; + + $html .= '' . __( 'All Episodes for the Last Three Months', 'seriously-simple-stats' ) . '' . "\n"; $html .= '' . "\n"; $html .= '
    ' . "\n"; - - $referrer_data = array(); $all_episodes_stats = array(); - $referrer_labels = array( - 'download' => __( 'Direct download', 'seriously-simple-stats' ), - 'player' => __( 'Audio player', 'seriously-simple-stats' ), - 'new_window' => __( 'Played in new window', 'seriously-simple-stats' ), - 'itunes' => __( 'iTunes', 'seriously-simple-stats' ), - 'stitcher' => __( 'Stitcher', 'seriously-simple-stats' ), - 'overcast' => __( 'Overcast', 'seriously-simple-stats' ), - 'pocketcasts' => __( 'Pocket Casts', 'seriously-simple-stats' ), - 'other' => __( 'Other', 'seriously-simple-stats' ), - 'android' => __('Android App', 'seriously-simple-stats'), - 'podcast_addict' => __( 'Podcast Addict', 'seriously-simple-stats' ), - 'playerfm' => __( 'Player FM', 'seriously-simple-stats' ), - 'google_play' => __( 'Google Play', 'seriously-simple-stats' ) - ); - $this->start_date = strtotime( current_time('Y-m-d').' -2 MONTH' ); $sql = "SELECT COUNT(id) AS listens, post_id FROM $this->_table GROUP BY post_id"; - if( isset( $_GET['orderby'] ) ){ - - if( $_GET['orderby'] == 'date' ){ - - $order = isset( $_GET['order'] ) ? sanitize_text_field( $_GET['order'] ) : "desc"; - - $sql .= " ORDER BY date ".$order; - - } - - } else { - - $sql .= " ORDER BY `date` DESC"; - - } - $results = $wpdb->get_results( $sql ); $total_posts = count( $results ); @@ -816,8 +767,6 @@ public function stats_page () { $listens = 0; - $pretty_referrer_data = array(); - foreach( $episode_results as $ref ) { //Increase the count of listens per month @@ -826,20 +775,12 @@ public function stats_page () { } - //Allows for sorting based on listens for a specific month - if( isset( $_GET['month_num'])){ - $total_listens = $total_listens_array[intval( $_GET['month_num'] )]; - } else{ - $total_listens = $listens; - } - $all_episodes_stats[] = apply_filters( 'ssp_stats_three_months_all_episodes', array( 'episode_name' => $post->post_title, - 'date' => date( 'Y-m-d', strtotime( $post->post_date ) ), + 'date' => date( 'm-d-Y', strtotime( $post->post_date ) ), 'slug' => admin_url('post.php?post='.$post->ID.'&action=edit'), 'listens' => $listens, 'listens_array' => $total_listens_array, - 'order_listens' => $total_listens ) ); } @@ -853,107 +794,33 @@ public function stats_page () { $month_num_prev = date('m', strtotime( current_time("Y-m-d")." -1 MONTH" ) ); $month_num_prior = date('m', strtotime( current_time("Y-m-d")." -2 MONTH" ) ); - //Set default page sorting URLs for the table headers - $episode_name_url = admin_url("edit.php?post_type=podcast&page=podcast_stats&orderby=title&order=desc#last-three-months-container"); - - $published_url = admin_url("edit.php?post_type=podcast&page=podcast_stats&orderby=date&order=desc#last-three-months-container"); - - $listens_m_1 = admin_url("edit.php?post_type=podcast&page=podcast_stats&orderby=listens&month_num=".$month_num_cur."&order=desc#last-three-months-container"); - - $listens_m_2 = admin_url("edit.php?post_type=podcast&page=podcast_stats&orderby=listens&month_num=".$month_num_prev."&order=desc#last-three-months-container"); - - $listens_m_3 = admin_url("edit.php?post_type=podcast&page=podcast_stats&orderby=listens&month_num=".$month_num_prior."&order=desc#last-three-months-container"); - - $listens = admin_url("edit.php?post_type=podcast&page=podcast_stats&orderby=listens&order=desc#last-three-months-container"); - - if( isset( $_GET['orderby'] ) ){ - - //Get or set the order - if( isset( $_GET['order'] ) ){ - if( $_GET['order'] == 'asc' ){ - $order = 'desc'; - } else { - $order = 'asc'; - } - } else { - $order = 'desc'; - } - - //Get the current page number - if( isset( $_GET['pagenum'] ) ){ - $page_num = "&pagenum=".intval( $_GET['pagenum'] ); - } else { - $page_num = ""; - } - - if( $_GET['orderby'] == 'title' ){ - - //Order according to title of episode - $episode_name_url = admin_url("edit.php?post_type=podcast&page=podcast_stats&orderby=title&order=$order".$page_num."#last-three-months-container"); - - } else if( $_GET['orderby'] == 'listens' ){ - - //Order according to total listens or per month - $listens = admin_url("edit.php?post_type=podcast&page=podcast_stats&orderby=listens&order=$order".$page_num."#last-three-months-container"); - - $listens_m_1 = admin_url("edit.php?post_type=podcast&page=podcast_stats&orderby=listens&month_num=".$month_num_cur."&order=$order".$page_num."#last-three-months-container"); - - $listens_m_2 = admin_url("edit.php?post_type=podcast&page=podcast_stats&orderby=listens&month_num=".$month_num_prev."&order=$order".$page_num."#last-three-months-container"); - - $listens_m_3 = admin_url("edit.php?post_type=podcast&page=podcast_stats&orderby=listens&month_num=".$month_num_prior."&order=$order".$page_num."#last-three-months-container"); - - } else if( $_GET['orderby'] == 'date' ){ - //Order according to published date of episode - $published_url = admin_url("edit.php?post_type=podcast&page=podcast_stats&orderby=date&order=$order".$page_num."#last-three-months-container"); - - } - + //Get the current page number + if( isset( $_GET['pagenum'] ) ){ + $page_num = "&pagenum=".intval( $_GET['pagenum'] ); + } else { + $page_num = ""; } - $html .= ""; - $html .= " "; - $html .= " "; - $html .= " "; - $html .= " "; - $html .= " "; - $html .= " "; - $html .= " "; - $html .= " "; - $html .= " "; - $html .= " "; + $html .= "
    ".__('Episode Name', 'seriously-simple-stats')."".__('Publish Date', 'seriously-simple-stats')."".current_time('F')."".date('F', strtotime( current_time("Y-m-d")." -1 MONTH" ) )."".date('F', strtotime( current_time("Y-m-d")." -2 MONTH" ) )."".__('Total', 'seriously-simple-stats')."
    " . "\n"; + $html .= " " . "\n"; + $html .= " " . "\n"; + $html .= " " . "\n"; + $html .= " " . "\n"; + $html .= " " . "\n"; + $html .= " " . "\n"; + $html .= " " . "\n"; + $html .= " " . "\n"; + $html .= " " . "\n"; + $html .= " " . "\n"; if( !empty( $all_episodes_stats ) && is_array( $all_episodes_stats ) ){ - //Sorting by total listens - if( isset( $_GET['orderby'] ) && ( $_GET['orderby'] == 'listens' || $_GET['orderby'] == 'title' ) ){ - - if( isset( $_GET['order'] ) ){ - - if( $_GET['order'] == 'asc' ){ - $order_flag = SORT_ASC; - } else { - $order_flag = SORT_DESC; - } - - } else { - $order_flag = SORT_DESC; - } - - $listen_sorting = array(); - - if( $_GET['orderby'] == 'listens' ){ - $order_type = 'order_listens'; - } else { - $order_type = 'episode_name'; - } - - foreach( $all_episodes_stats as $listen ){ - $listen_sorting[] = $listen[$order_type]; - } - - array_multisort( $listen_sorting, $order_flag, $all_episodes_stats ); - + //Sort list by episode name + foreach( $all_episodes_stats as $listen ){ + $listen_sorting[] = $listen['episode_name']; } + + array_multisort( $listen_sorting, SORT_DESC, $all_episodes_stats ); if( isset( $_GET['pagenum'] ) ){ @@ -965,8 +832,6 @@ public function stats_page () { $current_cursor = ($pagenum - 1)* $total_per_page; } - $next_cursor = $total_per_page * $pagenum; - $all_episodes_stats = array_slice( $all_episodes_stats, $current_cursor, $total_per_page , true ); } else { @@ -978,18 +843,18 @@ public function stats_page () { //Display the data foreach( $all_episodes_stats as $ep ){ - $html .= ""; - $html .= " "; - $html .= " "; + $html .= "" . "\n"; + $html .= " " . "\n"; + $html .= " " . "\n"; if( isset( $ep['listens_array'] ) ){ foreach( $ep['listens_array'] as $listen ){ //Each months total listens - $html .= ""; + $html .= "" . "\n"; } } //Total Listen Count - $html .= " "; - $html .= ""; + $html .= " " . "\n"; + $html .= "" . "\n"; } @@ -1009,9 +874,9 @@ public function stats_page () { $total_pages = ceil($total_posts/$total_per_page); - $pagination_html .= "
    "; - $pagination_html .= '
    '; - $pagination_html .= ' '.$total_posts.' '.__('items', 'seriously-simple-stats').''; + $pagination_html .= "
    " . "\n"; + $pagination_html .= '
    ' . "\n"; + $pagination_html .= ' '.$total_posts.' '.__('items', 'seriously-simple-stats').'' . "\n"; $prev_page = ( $pagenum <= 1 ) ? 1 : $pagenum - 1; @@ -1033,9 +898,9 @@ public function stats_page () { if( $next_page <= $total_pages ){ $pagination_html .= ' '.__('Next page', 'seriously-simple-stats').''; } - $pagination_html .= "  "; - $pagination_html .= "
    "; - $pagination_html .= "
    "; + $pagination_html .= "  " . "\n"; + $pagination_html .= "
    " . "\n"; + $pagination_html .= "
    " . "\n"; } $html .= $pagination_html; @@ -1043,6 +908,32 @@ public function stats_page () { $html .= '' . "\n"; $html .= '' . "\n"; + $html .= '
    ' . "\n"; + $html .= '<' . $metabox_title . ' class="hndle ui-sortable-handle">' . "\n"; + $html .= '' . __( 'Top Ten Episodes of All Time', 'seriously-simple-stats' ) . '' . "\n"; + $html .= '' . "\n"; + $html .= '
    ' . "\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 .= '
      ' . "\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 .= '
    • ' . sprintf( _n( '%d %slisten%s', '%d %slistens%s', $result->listens, 'seriously-simple-stats' ), $result->listens, '', '' ) . ' ' . esc_html( $episode->post_title ) . '
    • ' . "\n"; + if( '' == $li_class ) { + $li_class = 'alternate'; + } else { + $li_class = ''; + } + } + $html .= '
    ' . "\n"; + + $html .= '
    ' . "\n"; + $html .= '
    ' . "\n"; + } $html .= '' . "\n"; @@ -1143,8 +1034,6 @@ private function weekly_listens_chart () { $episode_id_where = 'AND ' . $this->episode_id_where; } - // $this->start_date = strtotime( current_time('mysql')." - 2 MONTH" ); - $sql = $wpdb->prepare( "SELECT date FROM $this->_table WHERE date BETWEEN %d AND %d $episode_id_where", $this->start_date, $this->end_date ); $results = $wpdb->get_results( $sql ); @@ -1158,6 +1047,7 @@ private function weekly_listens_chart () { $date_data[ $date ] = 1; } } + ksort( $date_data ); $data = array(); @@ -1166,7 +1056,7 @@ private function weekly_listens_chart () { $data[] = array( $date, $listens ); } - return $this->generate_chart( 'LineChart', '', $columns, $data, 'weekly_listens', '100%' ); + return $this->generate_chart( 'LineChart', '', $columns, $data, 'weekly_listens', 250 ); } @@ -1223,10 +1113,10 @@ private function referrers_chart () { 'overcast' => __( 'Overcast', 'seriously-simple-stats' ), 'pocketcasts' => __( 'Pocket Casts', 'seriously-simple-stats' ), 'other' => __( 'Other', 'seriously-simple-stats' ), - 'android' => __('Android App', 'seriously-simple-stats'), + // 'android' => __('Android App', 'seriously-simple-stats'), //Removed but kept for potential future use 'podcast_addict' => __( 'Podcast Addict', 'seriously-simple-stats' ), 'playerfm' => __( 'Player FM', 'seriously-simple-stats' ), - 'google_play' => __( 'Google Play', 'seriously-simple-stats' ) + // 'google_play' => __( 'Google Play', 'seriously-simple-stats' ) //Removed but kept for potential future use ); $data = array(); @@ -1238,7 +1128,12 @@ private function referrers_chart () { $ref_label = $referrer_labels[ $ref ]; } else { // Allow 'Unknown' label as a backup, even though this probably won't ever get used - $ref_label = __( 'Unknown', 'seriously-simple-stats' ); + if( $ref == 'android' || $ref == 'google_play' ){ + // Ignoring this count in the mean time until we can track these counts correctly + continue; + } else { + $ref_label = __( 'Unknown', 'seriously-simple-stats' ); + } } $data[] = array( $ref_label, $listens ); @@ -1300,10 +1195,14 @@ private function generate_chart ( $type = '', $title = '', $columns = array(), $ $options = ''; + if( $column_date > 0 ){ + $options .= "hAxis:{ format: 'MMM d' }, chartArea:{ width: '100%', top: '25' }, ". "\n"; + } + switch( $type ) { case 'LineChart': $options .= "legend: 'none'," . "\n"; - $options .= "vAxis: { minValue: 0 }" . "\n"; + $options .= "vAxis: { minValue: 0 } " . "\n"; break; case 'PieChart': $options .= "is3D: true" . "\n"; From fc7054951ce6d5e83bf0cfb9bc704643656ab653 Mon Sep 17 00:00:00 2001 From: JTrial <31481033+JTrial@users.noreply.github.com> Date: Wed, 27 Sep 2017 23:42:23 +0200 Subject: [PATCH 06/15] Additional Changes - Y-axis label visible in the dashboard graph - Lifetime listens displayed for the last three months table --- includes/class-ssp-stats.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/includes/class-ssp-stats.php b/includes/class-ssp-stats.php index c48ac66..0439f89 100755 --- a/includes/class-ssp-stats.php +++ b/includes/class-ssp-stats.php @@ -734,7 +734,7 @@ public function stats_page () { $html .= '
    ' . "\n"; $html .= '<' . $metabox_title . ' class="hndle ui-sortable-handle">' . "\n"; - $html .= '' . __( 'All Episodes for the Last Three Months', 'seriously-simple-stats' ) . '' . "\n"; + $html .= '' . __( 'All Episodes for the Last Three Months', 'seriously-simple-stats' ) . '' . "\n"; $html .= '' . "\n"; $html .= '
    ' . "\n"; @@ -761,25 +761,23 @@ public function stats_page () { $post = get_post( intval( $result->post_id ) ); - $sql = "SELECT `date` FROM $this->_table WHERE `post_id` = '".$result->post_id."' AND `date` >= ".$this->start_date; + $sql = "SELECT `date` FROM $this->_table WHERE `post_id` = '".$result->post_id."'"; $episode_results = $wpdb->get_results( $sql ); - $listens = 0; + $lifetime_count = count( $episode_results ); foreach( $episode_results as $ref ) { - //Increase the count of listens per month - ++$total_listens_array[intval( date('m', intval( $ref->date ) ) )]; - $listens++; - + if( isset( $total_listens_array[intval( date('m', intval( $ref->date ) ) )] ) ) + ++$total_listens_array[intval( date('m', intval( $ref->date ) ) )]; } $all_episodes_stats[] = apply_filters( 'ssp_stats_three_months_all_episodes', array( 'episode_name' => $post->post_title, 'date' => date( 'm-d-Y', strtotime( $post->post_date ) ), 'slug' => admin_url('post.php?post='.$post->ID.'&action=edit'), - 'listens' => $listens, + 'listens' => $lifetime_count, 'listens_array' => $total_listens_array, ) ); @@ -1196,7 +1194,7 @@ private function generate_chart ( $type = '', $title = '', $columns = array(), $ $options = ''; if( $column_date > 0 ){ - $options .= "hAxis:{ format: 'MMM d' }, chartArea:{ width: '100%', top: '25' }, ". "\n"; + $options .= "hAxis:{ format: 'MMM d' }, chartArea:{ width: '80%', top: '25' }, ". "\n"; } switch( $type ) { From 6cfff26a5f61f5cddcbb79387085b6befd92ae5c Mon Sep 17 00:00:00 2001 From: JTrial <31481033+JTrial@users.noreply.github.com> Date: Tue, 10 Oct 2017 11:52:32 +0200 Subject: [PATCH 07/15] Code Refactor - Switch statement removed to use an if condition instead --- includes/class-ssp-stats.php | 51 ++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/includes/class-ssp-stats.php b/includes/class-ssp-stats.php index 0439f89..5f4c640 100755 --- a/includes/class-ssp-stats.php +++ b/includes/class-ssp-stats.php @@ -284,41 +284,34 @@ public function track_download ( $file = '', $episode = 0, $referrer = '' ) { $CrawlerDetect = new CrawlerDetect(); if( $CrawlerDetect->isCrawler( $user_agent ) ) { return; - } + } // Check for specific podcasting services in user agent // The iOS Podcasts app makes a HEAD request with user agent Podcasts/2.4 and then a GET request with user agent AppleCoreMedia - switch( $user_agent ){ - case stripos( $user_agent, 'podcasts/' ) !== false: - // This conditional will prevent double tracking from that app - break; - case ( stripos( $user_agent, 'itunes' ) !== false || stripos( $user_agent, 'AppleCoreMedia' ) !== false ): - $referrer = 'itunes'; - break; - case stripos( $user_agent, 'stitcher' ) !== false: - $referrer = 'stitcher'; - break; - case stripos( $user_agent, 'overcast' ) !== false: - $referrer = 'overcast'; - break; - case stripos( $user_agent, 'Pocket Casts' ) !== false: - $referrer = 'pocketcasts'; - break; - case stripos( $user_agent, 'Android' ) !== false: - $referrer = 'android'; - break; - case stripos( $user_agent, 'PodcastAddict' ) !== false: - $referrer = 'podcast_addict'; - break; - case stripos( $user_agent, 'Player FM' ) !== false: - $referrer = 'playerfm'; - break; - case stripos( $user_agent, 'Google-Play' ) !== false: - $referrer = 'google_play'; - break; + if( stripos( $user_agent, 'podcasts/' ) !== false ){ + // This conditional will prevent double tracking from that app + return; } + if ( stripos( $user_agent, 'itunes' ) !== false || stripos( $user_agent, 'AppleCoreMedia' ) !== false ){ + $referrer = 'itunes'; + } else if ( stripos( $user_agent, 'stitcher' ) !== false ) { + $referrer = 'stitcher'; + } else if ( stripos( $user_agent, 'overcast' ) !== false ) { + $referrer = 'overcast'; + } else if ( stripos( $user_agent, 'Pocket Casts' ) !== false ) { + $referrer = 'pocketcasts'; + } else if ( stripos( $user_agent, 'Android' ) !== false ) { + $referrer = 'android'; + } else if ( stripos( $user_agent, 'PodcastAddict' ) !== false ) { + $referrer = 'podcast_addict'; + } else if ( stripos( $user_agent, 'Player FM' ) !== false ) { + $referrer = 'playerfm'; + } else if ( stripos( $user_agent, 'Google-Play' ) !== false ) { + $referrer = 'google_play'; + } + // Get episode ID for database insert $episode_id = $episode->ID; From 7475959761f11f51555458e96b71f6f4d7485a07 Mon Sep 17 00:00:00 2001 From: JTrial <31481033+JTrial@users.noreply.github.com> Date: Tue, 10 Oct 2017 23:33:04 +0200 Subject: [PATCH 08/15] Undefined variable removed - Removed as using this in the dashboard doesn't serve a purpose. Would only apply when filtering by a series etc. --- includes/class-ssp-stats.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-ssp-stats.php b/includes/class-ssp-stats.php index 5f4c640..d63a243 100755 --- a/includes/class-ssp-stats.php +++ b/includes/class-ssp-stats.php @@ -1418,7 +1418,7 @@ public function dashboard_widget_callback(){ $html .= '
    ' . "\n"; $html .= '
    ' . "\n"; $html .= '

    ' . "\n"; - $html .= '

    ' . sprintf( __( 'No stats %s yet!', 'seriously-simple-stats' ), $no_stats_filler ) . '

    ' . "\n"; + $html .= '

    ' . __( 'No stats yet!', 'seriously-simple-stats' ) . '

    ' . "\n"; $html .= '
    ' . "\n"; $html .= '
    ' . "\n"; } else { From 393b0508faaeed0d68616ca3dbfd4933f21ff6c5 Mon Sep 17 00:00:00 2001 From: Jonathan Bossenger Date: Wed, 11 Oct 2017 11:10:14 +0200 Subject: [PATCH 09/15] Version bump to 1.2.0 Updated changelog and contributors Added SSP_STATS_VERSION constant Added .distignore file for packaging --- .distignore | 2 ++ readme.txt | 13 ++++++++++--- seriously-simple-stats.php | 8 +++++--- 3 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 .distignore diff --git a/.distignore b/.distignore new file mode 100644 index 0000000..60b028c --- /dev/null +++ b/.distignore @@ -0,0 +1,2 @@ +.git +.gitignore \ No newline at end of file diff --git a/readme.txt b/readme.txt index 68b1bc9..077d4d3 100644 --- a/readme.txt +++ b/readme.txt @@ -1,9 +1,9 @@ === Seriously Simple Stats === -Contributors: hlashbrooke +Contributors: PodcastMotor, psykro, simondowdles, hlashbrooke, seriouspodcaster Tags: seriously simple podcasting, stats, statistics, listeners, analytics, podcast, podcasting, ssp, free, add-ons, extensions, addons Requires at least: 4.4 -Tested up to: 4.6 -Stable tag: 1.1 +Tested up to: 4.8.2 +Stable tag: 1.2.0 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -78,6 +78,13 @@ Yes. This plugin uses the [Crawler Detect](https://github.com/JayBizzle/Crawler- == Changelog == += 1.2.0 = +* 2017-10-11 +* [FIX] Only generate charts on stats page (props [mattsims](https://github.com/mattsims)) +* [NEW] Added stats widget to WordPress dashboard +* [NEW] Added new listening sources (PodcastAddict, Player FM, Google-Play) +* [NEW] Added new stats view for all episodes for the past three months + = 1.1 = * 2016-09-07 * [NEW] Including Crawler Detect library to prevent crawlers/bots from bring recorded as actual listens diff --git a/seriously-simple-stats.php b/seriously-simple-stats.php index 58e4015..10bd9d9 100644 --- a/seriously-simple-stats.php +++ b/seriously-simple-stats.php @@ -1,7 +1,7 @@ Date: Wed, 11 Oct 2017 11:14:22 +0200 Subject: [PATCH 10/15] Cleanup of some unused variables Updated commented out sections --- includes/class-ssp-stats.php | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/includes/class-ssp-stats.php b/includes/class-ssp-stats.php index b3f6cdd..623ad9c 100755 --- a/includes/class-ssp-stats.php +++ b/includes/class-ssp-stats.php @@ -409,8 +409,7 @@ public function stats_meta_box_content ( $post ) { if( $total_downloads ) { $html .= '

    ' . __( 'Total listens', 'seriously-simple-stats' ) . ': ' . $total_downloads . '

    '; - - $users = array(); + $itunes = $stitcher = $overcast = $pocketcasts = $direct = $new_window = $player = $android = $podcast_addict = $playerfm = $google_play = $unknown = 0; foreach( $stats as $stat ) { @@ -478,20 +477,20 @@ public function stats_meta_box_content ( $post ) { if( $player ) { $html .= '
  • ' . __( 'Audio player', 'seriously-simple-stats' ) . ': ' . $player . '
  • '; } - // Hidden but keeping for possible future use as per instruction - // if( $android ){ - // $html .= '
  • ' . __( 'Android App', 'seriously-simple-stats' ) . ': ' . $android . '
  • '; - // } + // Commented out for now, could be included in the future + /*if( $android ){ + $html .= '
  • ' . __( 'Android App', 'seriously-simple-stats' ) . ': ' . $android . '
  • '; + }*/ if( $podcast_addict ){ $html .= '
  • ' . __( 'Podcast Addict', 'seriously-simple-stats' ) . ': ' . $podcast_addict . '
  • '; } if( $playerfm ){ $html .= '
  • ' . __( 'Player FM', 'seriously-simple-stats' ) . ': ' . $playerfm . '
  • '; } - // Hidden but keeping for possible future use as per instruction - // if( $google_play ){ - // $html .= '
  • ' . __( 'Google Play', 'seriously-simple-stats' ) . ': ' . $google_play . '
  • '; - // } + // Commented out for now, could be used in the future + /*if( $google_play ){ + $html .= '
  • ' . __( 'Google Play', 'seriously-simple-stats' ) . ': ' . $google_play . '
  • '; + }*/ if( $unknown ) { $html .= '
  • ' . __( 'Other', 'seriously-simple-stats' ) . ': ' . $unknown . '
  • '; } @@ -780,18 +779,7 @@ public function stats_page () { //24 because we're counting an array $total_per_page = apply_filters( 'ssp_stats_three_months_per_page', 24 ); - - $month_num_cur = current_time('m'); - $month_num_prev = date('m', strtotime( current_time("Y-m-d")." -1 MONTH" ) ); - $month_num_prior = date('m', strtotime( current_time("Y-m-d")." -2 MONTH" ) ); - - //Get the current page number - if( isset( $_GET['pagenum'] ) ){ - $page_num = "&pagenum=".intval( $_GET['pagenum'] ); - } else { - $page_num = ""; - } - + $html .= "
    ".__('Publish Date', 'seriously-simple-stats')."".__('Episode Name', 'seriously-simple-stats')."".current_time('F')."".date('F', strtotime( current_time("Y-m-d")." -1 MONTH" ) )."".date('F', strtotime( current_time("Y-m-d")." -2 MONTH" ) )."".__('Lifetime', 'seriously-simple-stats')."
    ".$ep['episode_name']."".$ep['date']."
    ".$ep['date']."".$ep['episode_name']."".$listen."".$listen."".$ep['listens']."
    ".$ep['listens']."
    " . "\n"; $html .= " " . "\n"; $html .= " " . "\n"; @@ -1107,10 +1095,10 @@ private function referrers_chart () { 'overcast' => __( 'Overcast', 'seriously-simple-stats' ), 'pocketcasts' => __( 'Pocket Casts', 'seriously-simple-stats' ), 'other' => __( 'Other', 'seriously-simple-stats' ), - // 'android' => __('Android App', 'seriously-simple-stats'), //Removed but kept for potential future use + // 'android' => __('Android App', 'seriously-simple-stats'), //Commented out for now 'podcast_addict' => __( 'Podcast Addict', 'seriously-simple-stats' ), 'playerfm' => __( 'Player FM', 'seriously-simple-stats' ), - // 'google_play' => __( 'Google Play', 'seriously-simple-stats' ) //Removed but kept for potential future use + // 'google_play' => __( 'Google Play', 'seriously-simple-stats' ) //Commented out for now ); $data = array(); From bb4b953701174cce912725a838fa019545cf1871 Mon Sep 17 00:00:00 2001 From: Jonathan Bossenger Date: Wed, 11 Oct 2017 11:24:52 +0200 Subject: [PATCH 11/15] Updating Author info --- seriously-simple-stats.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/seriously-simple-stats.php b/seriously-simple-stats.php index 10bd9d9..b74549b 100644 --- a/seriously-simple-stats.php +++ b/seriously-simple-stats.php @@ -4,10 +4,10 @@ * Version: 1.2.0 * Plugin URI: https://wordpress.org/plugins/seriously-simple-stats * Description: Integrated analytics and stats tracking for Seriously Simple Podcasting. - * Author: Hugh Lashbrooke - * Author URI: https://hughlashbrooke.com/ + * Author: PodcastMotor + * Author URI: https://www.podcastmotor.com/ * Requires at least: 4.4 - * Tested up to: 4.6 + * Tested up to: 4.8.2 * * Text Domain: seriously-simple-stats * Domain Path: /languages @@ -15,6 +15,10 @@ * @package WordPress * @author Hugh Lashbrooke * @since 1.0.0 + * + * @author PodcastMotor + * @since 1.2.0 + * */ if ( ! defined( 'ABSPATH' ) ) { From d42708dad77d27861a5a2e0774c4d10349883b97 Mon Sep 17 00:00:00 2001 From: Jonathan Bossenger Date: Wed, 11 Oct 2017 11:27:41 +0200 Subject: [PATCH 12/15] Code formatting for Google chart api --- includes/class-ssp-stats.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/includes/class-ssp-stats.php b/includes/class-ssp-stats.php index 623ad9c..49a8b11 100755 --- a/includes/class-ssp-stats.php +++ b/includes/class-ssp-stats.php @@ -1244,13 +1244,7 @@ public function admin_enqueue_scripts ( $hook = '' ) { if( 'podcast_page_podcast_stats' == $hook || 'index.php' == $hook ) { // Include Google Charts scripts - wp_enqueue_script( 'google-charts', "//www.google.com/jsapi?autoload={ - 'modules':[{ - 'name':'visualization', - 'version':'1', - 'packages':['corechart'] - }] - }", array(), $this->_version, false ); + wp_enqueue_script( 'google-charts', "//www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1','packages':['corechart']}]}", array(), $this->_version, false ); // Load custom scripts wp_register_script( $this->_token . '-admin', esc_url( $this->assets_url ) . 'js/admin' . $this->script_suffix . '.js', array( 'jquery' ), $this->_version ); From c9ef0f0e81db51faca17f7115f776451dabb3749 Mon Sep 17 00:00:00 2001 From: Jonathan Bossenger Date: Wed, 11 Oct 2017 12:22:10 +0200 Subject: [PATCH 13/15] Removing $hook check on chart_data function --- includes/class-ssp-stats.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/includes/class-ssp-stats.php b/includes/class-ssp-stats.php index 49a8b11..59d8926 100755 --- a/includes/class-ssp-stats.php +++ b/includes/class-ssp-stats.php @@ -939,17 +939,14 @@ private function daily_stat ( $number = '', $description = '' ) { * @since 1.0.0 * @return void */ - public function chart_data ( $hook = '' ) { + public function chart_data ( ) { - if( 'podcast_page_podcast_stats' == $hook ) { + $output = ''; - $output = ''; + $output .= $this->daily_listens_chart(); + $output .= $this->referrers_chart(); - $output .= $this->daily_listens_chart(); - $output .= $this->referrers_chart(); - - echo $output; - } + echo $output; } /** From ec67a368fc7baefa5206666db5bd42cf94fdd57c Mon Sep 17 00:00:00 2001 From: Jonathan Bossenger Date: Wed, 11 Oct 2017 12:28:02 +0200 Subject: [PATCH 14/15] Adding .gitignore and .distignore --- .distignore | 3 ++- .gitignore | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 .gitignore diff --git a/.distignore b/.distignore index 60b028c..adbbe77 100644 --- a/.distignore +++ b/.distignore @@ -1,2 +1,3 @@ .git -.gitignore \ No newline at end of file +.gitignore +.idea \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..962e2a6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea +*.iml +.gitignore \ No newline at end of file From edeb0c7988fd56aa0e418545d7690c2f25c0d0e6 Mon Sep 17 00:00:00 2001 From: Jonathan Bossenger Date: Wed, 11 Oct 2017 13:09:11 +0200 Subject: [PATCH 15/15] Removed item in changelog --- readme.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/readme.txt b/readme.txt index 077d4d3..239a040 100644 --- a/readme.txt +++ b/readme.txt @@ -80,7 +80,6 @@ Yes. This plugin uses the [Crawler Detect](https://github.com/JayBizzle/Crawler- = 1.2.0 = * 2017-10-11 -* [FIX] Only generate charts on stats page (props [mattsims](https://github.com/mattsims)) * [NEW] Added stats widget to WordPress dashboard * [NEW] Added new listening sources (PodcastAddict, Player FM, Google-Play) * [NEW] Added new stats view for all episodes for the past three months