posts; $tptn_settings = tptn_read_options(); if($_POST['tptn_save']){ $tptn_settings[title] = ($_POST['title']); $tptn_settings[title_daily] = ($_POST['title_daily']); $tptn_settings[daily_range] = ($_POST['daily_range']); $tptn_settings[limit] = ($_POST['limit']); $tptn_settings[count_disp_form] = ($_POST['count_disp_form']); $tptn_settings[add_to_content] = (($_POST['add_to_content']) ? true : false); $tptn_settings[exclude_pages] = (($_POST['exclude_pages']) ? true : false); $tptn_settings[count_on_pages] = (($_POST['count_on_pages']) ? true : false); $tptn_settings[track_authors] = (($_POST['track_authors']) ? true : false); $tptn_settings[pv_in_admin] = (($_POST['pv_in_admin']) ? true : false); $tptn_settings[disp_list_count] = (($_POST['disp_list_count']) ? true : false); $tptn_settings[d_use_js] = (($_POST['d_use_js']) ? true : false); $tptn_settings[show_credit] = (($_POST['show_credit']) ? true : false); update_option('ald_tptn_settings', $tptn_settings); $str = '

'. __('Options saved successfully.',TPTN_LOCAL_NAME) .'

'; echo $str; } if ($_POST['tptn_default']){ delete_option('ald_tptn_settings'); $tptn_settings = tptn_default_options(); update_option('ald_tptn_settings', $tptn_settings); $str = '

'. __('Options set to Default.',TPTN_LOCAL_NAME) .'

'; echo $str; } ?>

Top 10

Top 10 . ()

%totalcount% to display the total count and %dailycount% to display the daily count. e.g. the default options displays (Visited 123 times, 23 visits today)',TPTN_LOCAL_NAME); ?>

'; echo '

'; if (!$daily) _e('Popular Posts',TPTN_LOCAL_NAME); else _e('Daily Popular Posts',TPTN_LOCAL_NAME); echo '

'; echo '
'; echo tptn_pop_display($daily,$paged,$limit); echo '
'; } /* Add menu item in WP-Admin */ function tptn_adminmenu() { if (function_exists('current_user_can')) { // In WordPress 2.x if (current_user_can('manage_options')) { $tptn_is_admin = true; } } else { // In WordPress 1.x global $user_ID; if (user_can_edit_user($user_ID, 0)) { $tptn_is_admin = true; } } if ((function_exists('add_options_page'))&&($tptn_is_admin)) { add_options_page(__("Top 10", TPTN_LOCAL_NAME), __("Top 10", TPTN_LOCAL_NAME), 9, 'tptn_options', 'tptn_options'); add_posts_page(__("Popular Posts", TPTN_LOCAL_NAME), __("Top 10", TPTN_LOCAL_NAME), 9, 'tptn_manage', 'tptn_manage'); } } add_action('admin_menu', 'tptn_adminmenu'); /* Create a Dashboard Widget */ function tptn_pop_display($daily = false, $page = 0, $limit = 10) { global $wpdb, $siteurl, $tableposts, $id; $table_name = $wpdb->prefix . "top_ten"; if ($daily) $table_name .= "_daily"; // If we're viewing daily posts, set this to true $tptn_settings = tptn_read_options(); if (!($limit)) $limit = $tptn_settings['limit']; if (!($page)) $page = 0; // Default page value. if(!$daily) { $sql = "SELECT postnumber, cntaccess , ID, post_type "; $sql .= "FROM $table_name INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ; if ($tptn_settings['exclude_pages']) $sql .= "AND post_type = 'post' "; $sql .= "AND post_status = 'publish' "; $sql .= "ORDER BY cntaccess DESC"; } else { $daily_range = $tptn_settings[daily_range]. ' DAY'; $current_date = $wpdb->get_var("SELECT DATE_ADD(DATE_SUB(CURDATE(), INTERVAL $daily_range), INTERVAL 1 DAY) "); $sql = "SELECT postnumber, SUM(cntaccess) as sumCount, dp_date, ID, post_type, post_status "; $sql .= "FROM $table_name INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ; if ($tptn_settings['exclude_pages']) $sql .= "AND post_type = 'post' "; $sql .= "AND post_status = 'publish' AND dp_date >= '$current_date' "; $sql .= "GROUP BY postnumber "; $sql .= "ORDER BY sumCount DESC"; } $results = $wpdb->get_results($sql); $numrows = 0; if ($results) { foreach ($results as $result) { $numrows++; } } $pages = intval($numrows/$limit); // Number of results pages. // $pages now contains int of pages, unless there is a remainder from division. if ($numrows % $limit) {$pages++;} // has remainder so add one page $current = ($page/$limit) + 1; // Current page number. if (($pages < 1) || ($pages == 0)) {$total = 1;} // If $pages is less than one or equal to 0, total pages is 1. else { $total = $pages;} // Else total pages is $pages value. $first = $page + 1; // The first result. if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {$last = $page + $limit;} //If not last results page, last result equals $page plus $limit. else{$last = $numrows;} // If last results page, last result equals total number of results. if(!$daily) { $sql = "SELECT postnumber, cntaccess , ID, post_type "; $sql .= "FROM $table_name INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ; if ($tptn_settings['exclude_pages']) $sql .= "AND post_type = 'post' "; $sql .= "AND post_status = 'publish' "; $sql .= "ORDER BY cntaccess DESC LIMIT $page, $limit"; } else { $sql = "SELECT postnumber, SUM(cntaccess) as sumCount, dp_date, ID, post_type, post_status "; $sql .= "FROM $table_name INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ; if ($tptn_settings['exclude_pages']) $sql .= "AND post_type = 'post' "; $sql .= "AND post_status = 'publish' AND dp_date >= '$current_date' "; $sql .= "GROUP BY postnumber "; $sql .= "ORDER BY sumCount DESC LIMIT $page, $limit"; } $results = $wpdb->get_results($sql); $output = ''; return $output; } // Dashboard for Popular Posts function tptn_pop_dashboard() { echo tptn_pop_display(false,0,10); } // Dashboard for Daily Popular Posts function tptn_pop_daily_dashboard() { echo tptn_pop_display(true,0,10); } function tptn_pop_dashboard_setup() { if (function_exists('wp_add_dashboard_widget')) { wp_add_dashboard_widget( 'tptn_pop_dashboard', __( 'Popular Posts',TPTN_LOCAL_NAME ), 'tptn_pop_dashboard' ); wp_add_dashboard_widget( 'tptn_pop_daily_dashboard', __( 'Daily Popular',TPTN_LOCAL_NAME ), 'tptn_pop_daily_dashboard' ); } } add_action('wp_dashboard_setup', 'tptn_pop_dashboard_setup'); /* Display page views on the Edit Posts / Pages screen */ // Add an extra column function tptn_column($cols) { $tptn_settings = tptn_read_options(); if ($tptn_settings[pv_in_admin]) $cols['tptn'] = __('Total / Today\'s Views',TPTN_LOCAL_NAME); return $cols; } // Display page views for each column function tptn_value($column_name, $id) { $tptn_settings = tptn_read_options(); if (($column_name == 'tptn')&&($tptn_settings[pv_in_admin])) { global $wpdb; $table_name = $wpdb->prefix . "top_ten"; $resultscount = $wpdb->get_row("select postnumber, cntaccess from $table_name WHERE postnumber = $id"); $cntaccess = number_format((($resultscount) ? $resultscount->cntaccess : 0)); $cntaccess .= ' / '; // Now process daily count $table_name = $wpdb->prefix . "top_ten_daily"; $daily_range = $tptn_settings[daily_range]. ' DAY'; $current_date = $wpdb->get_var("SELECT DATE_ADD(DATE_SUB(CURDATE(), INTERVAL $daily_range), INTERVAL 1 DAY) "); $resultscount = $wpdb->get_row("SELECT postnumber, SUM(cntaccess) as sumCount FROM $table_name WHERE postnumber = $id AND dp_date >= '$current_date' GROUP BY postnumber "); $cntaccess .= number_format((($resultscount) ? $resultscount->sumCount : 0)); echo $cntaccess; } } // Output CSS for width of new column function tptn_css() { ?>