Mark Ghosh Author: Ajay D'Souza Author URI: http://ajaydsouza.com/ */ if (!defined('ABSPATH')) die("Aren't you supposed to come here via WP-Admin?"); define('ALD_TPTN_DIR', dirname(__FILE__)); define('TPTN_LOCAL_NAME', 'tptn'); // Pre-2.6 compatibility if ( ! defined( 'WP_CONTENT_URL' ) ) define( 'WP_CONTENT_URL', get_option( 'siteurl' ) . '/wp-content' ); if ( ! defined( 'WP_CONTENT_DIR' ) ) define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); if ( ! defined( 'WP_PLUGIN_URL' ) ) define( 'WP_PLUGIN_URL', WP_CONTENT_URL. '/plugins' ); if ( ! defined( 'WP_PLUGIN_DIR' ) ) define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' ); // Guess the location $tptn_path = WP_PLUGIN_DIR.'/'.plugin_basename(dirname(__FILE__)); $tptn_url = WP_PLUGIN_URL.'/'.plugin_basename(dirname(__FILE__)); if (!function_exists('add_action')) { $wp_root = '../../..'; if (file_exists($wp_root.'/wp-load.php')) { require_once($wp_root.'/wp-load.php'); } else { require_once($wp_root.'/wp-config.php'); } } global $tptn_db_version; $tptn_db_version = "2.8"; function ald_tptn_init() { //* Begin Localization Code */ $tc_localizationName = TPTN_LOCAL_NAME; $tc_comments_locale = get_locale(); $tc_comments_mofile = ALD_TPTN_DIR . "/languages/" . $tc_localizationName . "-". $tc_comments_locale.".mo"; load_textdomain($tc_localizationName, $tc_comments_mofile); //* End Localization Code */ } add_action('init', 'ald_tptn_init'); /********************************************************************* * Main Function (Do not edit) * ********************************************************************/ // Update post views add_filter('the_content','tptn_add_viewed_count'); function tptn_add_viewed_count($content) { global $post, $wpdb, $single,$tptn_url,$tptn_path; $table_name = $wpdb->prefix . "top_ten"; $tptn_settings = tptn_read_options(); $current_user = wp_get_current_user(); $post_author = ( $current_user->ID == $post->post_author ? true : false ); if((is_single() || is_page())) { if (!(($post_author)&&(!$tptn_settings['track_authors']))) { $id = intval($post->ID); $output = ''; return $content.$output; } else { return $content; } } else { return $content; } } // Function to add count to content function tptn_pc_content($content) { global $single, $post,$tptn_url,$tptn_path; $tptn_settings = tptn_read_options(); $id = intval($post->ID); if((is_single())&&($tptn_settings['add_to_content'])) { $output = ''; return $content.$output; } elseif((is_page())&&($tptn_settings['count_on_pages'])) { $output = ''; return $content.$output; } else { return $content; } } add_filter('the_content', 'tptn_pc_content'); // Function to manually display count function echo_tptn_post_count() { global $post,$tptn_url,$tptn_path; $id = intval($post->ID); $output = ''; echo $output; } // Function to return popular posts function tptn_pop_posts( $daily = false , $widget = false ) { global $wpdb, $siteurl, $tableposts, $id; if ($daily) $table_name = $wpdb->prefix . "top_ten_daily"; else $table_name = $wpdb->prefix . "top_ten"; $tptn_settings = tptn_read_options(); $limit = $tptn_settings['limit']*5; $exclude_categories = explode(',',$tptn_settings['exclude_categories']); if (!$daily) { $sql = "SELECT postnumber, cntaccess as sumCount, ID, post_type, post_status, post_content "; $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 sumCount DESC LIMIT $limit"; } else { $daily_range = $tptn_settings[daily_range] - 1; $current_time = gmdate( 'Y-m-d', ( time() + ( get_option( 'gmt_offset' ) * 3600 ) ) ); $current_date = strtotime ( '-'.$daily_range. ' DAY' , strtotime ( $current_time ) ); $current_date = date ( 'Y-m-j' , $current_date ); $sql = "SELECT postnumber, SUM(cntaccess) as sumCount, dp_date, ID, post_type, post_status, post_content "; $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 $limit"; } $results = $wpdb->get_results($sql); $counter = 0; $output = ''; if (!$widget) { if (!$daily) { $output .= '