LIKE

<?php
/*
Plugin Name: WordPress.com Stats
Plugin URI: http://wordpress.org/extend/plugins/stats/
Description: Tracks views, post/page views, referrers, and clicks. Requires a WordPress.com API key.
Author: Andy Skelton
Version: 1.7.3
License: GPL v2 – http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
Text Domain: stats

Requires WordPress 2.7 or later. Not for use with WPMU.

Looking for a way to hide the gif? Put this in your stylesheet:
img#wpstats{display:none}

*/

define( 'STATS_VERSION', '5' );

function stats_get_api_key() {
return stats_get_option('api_key');
}

function stats_set_api_key($api_key) {
stats_set_option('api_key', $api_key);
}

function stats_get_options() {
$options = get_option( 'stats_options' );

if ( !isset( $options['version'] ) || $options['version'] ”,
‘path’ => ”,
‘blog_id’ => false,
‘wp_me’ => true,
‘roles’ => array(‘administrator’,’editor’,’author’),
‘reg_users’ => false,
‘footer’ => false,
);

if ( is_array( $options ) && !empty( $options ) )
$options = array_merge( $defaults, $options );
else
$options = $defaults;

// Send new bloginfo with gmt_offset
if ( $options[‘version’] < 3 )
$update_bloginfo = true;

$options['version'] = STATS_VERSION;

stats_set_options( $options );

if ( $update_bloginfo )
stats_update_bloginfo();

return $options;
}

function stats_footer() {
global $wp_the_query, $current_user;

$options = stats_get_options();

echo "“;

if ( !$options[‘footer’] )
stats_set_option(‘footer’, true);

if ( empty($options[‘blog_id’]) )
return;

if ( !$options[‘reg_users’] && !empty($current_user->ID) )
return;

$a[‘blog’] = $options[‘blog_id’];
$a[‘v’] = ‘ext’;
if ( $wp_the_query->is_single || $wp_the_query->is_page )
$a[‘post’] = $wp_the_query->get_queried_object_id();
else
$a[‘post’] = ‘0’;

$http = $_SERVER[‘HTTPS’] ? ‘https’ : ‘http’;
?>
<script src="://stats.wordpress.com/e-.js” type=”text/javascript”>

st_go({});
var load_cmc = function(){linktracker_init();};
if ( typeof addLoadEvent != ‘undefined’ ) addLoadEvent(load_cmc);
else load_cmc();

$v )
$jskvs[] = “$k:’$v'”;
return join(‘,’, $jskvs);
}

function stats_admin_menu() {
global $current_user;
$roles = stats_get_option(‘roles’);
$cap = ‘administrator’;
foreach ( $roles as $role ) {
if ( current_user_can($role) ) {
$cap = $role;
break;
}
}
if ( stats_get_option(‘blog_id’) ) {
$hook = add_submenu_page(‘index.php’, __(‘Site Stats’, ‘stats’), __(‘Site Stats’, ‘stats’), $role, ‘stats’, ‘stats_reports_page’);
add_action(“load-$hook”, ‘stats_reports_load’);
}
$parent = stats_admin_parent();
$hook = add_submenu_page($parent, __(‘WordPress.com Stats Plugin’, ‘stats’), __(‘WordPress.com Stats’, ‘stats’), ‘manage_options’, ‘wpstats’, ‘stats_admin_page’);
add_action(“load-$hook”, ‘stats_admin_load’);
add_action(“admin_head-$hook”, ‘stats_admin_head’);
add_action(‘admin_notices’, ‘stats_admin_notices’);
}

function stats_admin_parent() {
if ( function_exists(‘is_multisite’) && is_multisite() ) {
$menus = get_site_option( ‘menu_items’ );
if ( isset($menus[‘plugins’]) && $menus[‘plugins’] )
return ‘plugins.php’;
else
return ‘options-general.php’;
} else {
return ‘plugins.php’;
}
}

function stats_admin_path() {
$parent = stats_admin_parent();
return “$parent?page=wpstats”;
}

function stats_reports_load() {
add_action(‘admin_head’, ‘stats_reports_head’);
}

function stats_reports_head() {
?>

body { height: 100%; }
#statsreport { height: 2500px; width: 100%; }

‘true’,
‘proxy’ => ”,
‘page’ => ‘stats’,
‘key’ => $key,
‘day’ => $day,
‘blog’ => $blog_id,
‘charset’ => get_option(‘blog_charset’),
);
$args = array(
‘view’ => array(‘referrers’, ‘postviews’, ‘searchterms’, ‘clicks’, ‘post’, ‘table’),
‘numdays’ => ‘int’,
‘day’ => ‘date’,
‘unit’ => array(1, 7, 31),
‘summarize’ => null,
‘post’ => ‘int’,
‘width’ => ‘int’,
‘height’ => ‘int’,
‘data’ => ‘data’,
);
foreach ( $args as $var => $vals ) {
if ( ! isset($_GET[$var]) )
continue;
if ( is_array($vals) ) {
if ( in_array($_GET[$var], $vals) )
$q[$var] = $_GET[$var];
} elseif ( $vals == ‘int’ ) {
$q[$var] = intval($_GET[$var]);
} elseif ( $vals == ‘date’ ) {
if ( preg_match(‘/^\d{4}-\d{2}-\d{2}$/’, $_GET[$var]) )
$q[$var] = $_GET[$var];
} elseif ( $vals == null ) {
$q[$var] = ”;
} elseif ( $vals == ‘data’ ) {
if ( substr($_GET[$var], 0, 9) == ‘index.php’ )
$q[$var] = $_GET[$var];
}
}

if ( isset( $_GET[‘chart’] ) ) {
if ( preg_match(‘/^[a-z0-9-]+$/’, $_GET[‘chart’]) )
$url = “https://dashboard.wordpress.com/wp-includes/charts/{$_GET[‘chart’]}.php”;
} else {
$url = “https://dashboard.wordpress.com/wp-admin/index.php&#8221;;
}

$url = add_query_arg($q, $url);

$get = wp_remote_get($url, array(‘timeout’=>300));

if ( is_wp_error($get) || empty($get[‘body’]) ) {
$http = $_SERVER[‘HTTPS’] ? ‘https’ : ‘http’;
$day = $day ? “&day=$day” : ”;
echo “”;
} else {
$body = convert_post_titles($get[‘body’]);
$body = convert_swf_urls($body);
echo $body;
}
if ( isset( $_GET[‘noheader’] ) )
die;
}

function convert_swf_urls($html) {
global $wp_version;
if ( version_compare($wp_version, ‘2.8’, ‘<') ) {
$path = dirname(plugin_basename(__FILE__));
if ( $path == '.' )
$path = '';
$swf_url = trailingslashit( plugins_url( $path ) ) . 'open-flash-chart.swf?data=';
} else {
$swf_url = trailingslashit( plugins_url( '', __FILE__) ) . 'open-flash-chart.swf?data=';
}
$html = preg_replace('!(<param name="movie" value="|<embed src=")(.+?)&data=!', "$1$swf_url", $html);
return $html;
}

function convert_post_titles($html) {
global $wpdb, $stats_posts;
$pattern = ".*?“;
if ( ! preg_match_all(“!$pattern!”, $html, $matches) )
return $html;
$posts = get_posts(array(
‘include’ => implode(‘,’, $matches[1]),
‘post_type’ => ‘any’,
‘numberposts’ => -1,
));
foreach ( $posts as $post )
$stats_posts[$post->ID] = $post;
$html = preg_replace_callback(“!$pattern!”, ‘convert_post_title’, $html);
return $html;
}

function convert_post_title($matches) {
global $stats_posts;
$post_id = $matches[1];
if ( isset($stats_posts[$post_id]) )
return ‘‘.get_the_title($post_id).’‘;
return $matches[0];
}

function stats_admin_load() {
if ( ! empty( $_POST[‘action’] ) && $_POST[‘_wpnonce’] == wp_create_nonce(‘stats’) ) {
switch( $_POST[‘action’] ) {
case ‘reset’ :
stats_set_options(array());
wp_redirect( stats_admin_path() );
exit;

case ‘enter_key’ :
stats_check_key( $_POST[‘api_key’] );
wp_redirect( stats_admin_path() );
exit;

case ‘add_or_replace’ :
$key_check = stats_get_option(‘key_check’);
stats_set_api_key($key_check[0]);
if ( isset($_POST[‘add’]) ) {
stats_get_blog_id($key_check[0]);
} else {
extract( parse_url( get_option( ‘home’ ) ) );
$path = rtrim( $path, ‘/’ );
if ( empty( $path ) )
$path = ‘/’;
$options = stats_get_options();
if ( isset($_POST[‘recover’]) )
$options[‘blog_id’] = intval($_POST[‘recoverblog’]);
else
$options[‘blog_id’] = intval($_POST[‘blog_id’]);
$options[‘api_key’] = $key_check[0];
$options[‘host’] = $host;
$options[‘path’] = $path;
stats_set_options($options);
stats_update_bloginfo();
}
if ( stats_get_option(‘blog_id’) )
stats_set_option(‘key_check’, false);
wp_redirect( stats_admin_path() );
exit;

case ‘save_options’ :
$options = stats_get_options();
$options[‘wp_me’] = isset($_POST[‘wp_me’]) && $_POST[‘wp_me’];
$options[‘reg_users’] = isset($_POST[‘reg_users’]) && $_POST[‘reg_users’];

$options[‘roles’] = array(‘administrator’);
foreach ( get_editable_roles() as $role => $details )
if ( isset($_POST[“role_$role”]) && $_POST[“role_$role”] )
$options[‘roles’][] = $role;

stats_set_options($options);
wp_redirect( stats_admin_path() );
exit;
}
}

$options = stats_get_options();
if ( empty( $options[‘blog_id’]) && empty( $options[‘key_check’] ) && stats_get_api_key() )
stats_check_key( stats_get_api_key() );
}

function stats_admin_notices() {
stats_notice_blog_id();
// stats_notice_footer();
}

function stats_notice_blog_id() {
if ( stats_get_api_key() || isset($_GET[‘page’]) && $_GET[‘page’] == ‘wpstats’ )
return;
// Skip the notice if plugin activated network-wide.
if ( function_exists(‘is_plugin_active_for_network’) && is_plugin_active_for_network(plugin_basename(__FILE__)) )
return;
echo “

” . sprintf(__(‘WordPress.com Stats needs attention: please enter an API key or disable the plugin.’, ‘stats’), stats_admin_path()) . “

“;
}

function stats_notice_footer() {
if ( !stats_get_api_key() || stats_get_option(‘footer’) )
return;
if ( function_exists(‘is_plugin_active_for_network’) && is_plugin_active_for_network(plugin_basename(__FILE__)) )
return;
if ( strpos(wp_remote_get(get_bloginfo(‘siteurl’)), ‘stats_footer_test’) ) {
stats_set_option(‘footer’, true);
return;
}
echo “

” . __(‘WordPress.com Stats is unable to work properly because your theme seems to lack the necessary footer code. Usually this can be fixed by adding the following code just before </body> in footer.php:’, ‘stats’) . “

<?php wp_footer(); ?>

“;
}

function stats_admin_head() {
?>

#statserror {
border: 1px solid #766;
background-color: #d22;
padding: 1em 3em;
}

<?php printf(__('The API key "%1$s" belongs to the WordPress.com account "%2$s". If you want to use a different account, please enter the correct API key.’, ‘stats’), $options[‘key_check’][0], $options[‘key_check’][1], wp_nonce_url(‘?page=wpstats&action=reset’, ‘stats’)); ?>

<input type='hidden' name='recoverblog' value='’ />

<input type="submit" name="recover" value="” />

<input type="submit" name="add" value="” />

<option value="”>

<input type="submit" name="replace" value="” />

<input type="submit" name="add" value="” />

<form action="” method=”post”>

<?php _e('Enter your WordPress.com API key to link this blog to your WordPress.com account. Be sure to use your own API key! Using any other key will lock you out of your stats. (Get your key here.)’, ‘stats’); ?>

<input type="submit" value="” />

<?php printf(__('Visit your Dashboard to see your site stats.’, ‘stats’), ‘index.php?page=stats’); ?>

<?php printf(__('You can also see your stats, plus grant access for others to see them, on your WordPress.com dashboard.’, ‘stats’), $options[‘blog_id’]); ?>

<form action="” method=”post”>

<input type='submit' class='button-primary' value='’ />

‘stats_get_posts’,
‘wpStats.get_blog’ => ‘stats_get_blog’
);

return array_merge( $methods, $my_methods );
}

function stats_get_posts( $args ) {
list( $post_ids ) = $args;

$post_ids = array_map( ‘intval’, (array) $post_ids );
$r = ‘include=’ . join(‘,’, $post_ids);
$posts = get_posts( $r );
$_posts = array();

foreach ( $post_ids as $post_id )
$_posts[$post_id] = stats_get_post($post_id);

return $_posts;
}

function stats_get_blog( ) {
$home = parse_url( get_option(‘home’) );
$blog = array(
‘host’ => $home[‘host’],
‘path’ => $home[‘path’],
‘name’ => get_option(‘blogname’),
‘description’ => get_option(‘blogdescription’),
‘siteurl’ => get_option(‘siteurl’),
‘gmt_offset’ => get_option(‘gmt_offset’),
‘version’ => STATS_VERSION
);
return array_map(‘esc_html’, $blog);
}

function stats_get_post( $post_id ) {
$post = get_post( $post_id );
if ( empty( $post ) )
$post = get_page( $post_id );
$_post = array(
‘id’ => $post->ID,
‘permalink’ => get_permalink($post->ID),
‘title’ => $post->post_title,
‘type’ => $post->post_type
);
return array_map(‘esc_html’, $_post);
}

function stats_client() {
require_once( ABSPATH . WPINC . ‘/class-IXR.php’ );
$client = new IXR_ClientMulticall( STATS_XMLRPC_SERVER );
$client->useragent = ‘WordPress/’ . $client->useragent;
return $client;
}

function stats_add_call() {
global $stats_xmlrpc_client;
if ( empty($stats_xmlrpc_client) ) {
$stats_xmlrpc_client = stats_client();
ignore_user_abort(true);
add_action(‘shutdown’, ‘stats_multicall_query’);
}

$args = func_get_args();

call_user_method_array( ‘addCall’, $stats_xmlrpc_client, $args );
}

function stats_multicall_query() {
global $stats_xmlrpc_client;

$stats_xmlrpc_client->query();
}

function stats_update_bloginfo() {
stats_add_call(
‘wpStats.update_bloginfo’,
stats_get_api_key(),
stats_get_option(‘blog_id’),
stats_get_blog()
);
}

function stats_update_post( $post_id ) {
if ( !in_array( get_post_type($post_id), array(‘post’, ‘page’, ‘attachment’) ) )
return;

stats_add_call(
‘wpStats.update_postinfo’,
stats_get_api_key(),
stats_get_option(‘blog_id’),
stats_get_post($post_id)
);
}

function stats_flush_posts() {
stats_add_call(
‘wpStats.flush_posts’,
stats_get_api_key(),
stats_get_option(‘blog_id’)
);
}

// WP

<?php printf(__('Visit your Global Dashboard to see your site stats.’, ‘stats’), ‘https://dashboard.wordpress.com/wp-admin/index.php?page=stats&blog=&#8217; . $options[‘blog_id’]); ?>

query( ‘wpStats.check_key’, $api_key, stats_get_blog() );

if ( $client->isError() ) {
if ( $client->getErrorCode() == -32300 )
$options[‘error’] = __(‘Your blog was unable to connect to WordPress.com. Please ask your host for help. (‘ . $client->getErrorMessage() . ‘)’, ‘stats’);
else
$options[‘error’] = $client->getErrorMessage();
stats_set_options( $options );
return false;
} else {
$options[‘error’] = false;
}

$options[‘key_check’] = $client->getResponse();
stats_set_options($options);

return true;
}

function stats_get_blog_id($api_key) {
$options = stats_get_options();

require_once( ABSPATH . WPINC . ‘/class-IXR.php’ );

$client = new IXR_Client( STATS_XMLRPC_SERVER );

extract( parse_url( get_option( ‘home’ ) ) );

$path = rtrim( $path, ‘/’ );

if ( empty( $path ) )
$path = ‘/’;

$client->query( ‘wpStats.get_blog_id’, $api_key, stats_get_blog() );

if ( $client->isError() ) {
if ( $client->getErrorCode() == -32300 )
$options[‘error’] = __(‘Your blog was unable to connect to WordPress.com. Please ask your host for help. (‘ . $client->getErrorMessage() . ‘)’, ‘stats’);
else
$options[‘error’] = $client->getErrorMessage();
stats_set_options( $options );
return false;
} else {
$options[‘error’] = false;
}

$response = $client->getResponse();

$blog_id = isset($response[‘blog_id’]) ? (int) $response[‘blog_id’] : false;

$options[ ‘host’ ] = $host;
$options[ ‘path’ ] = $path;
$options[ ‘blog_id’ ] = $blog_id;

stats_set_options( $options );

stats_set_api_key( $api_key );

return $blog_id;
}

function stats_activate() {
// Trigger footer test
wp_remote_get(get_bloginfo(‘siteurl’));
}

function stats_deactivate() {
//delete_option(‘stats_options’);
//delete_option(‘stats_dashboard_widget’);
}

/* Dashboard Stuff: WP >= 2.5 */

function stats_register_dashboard_widget() {
if ( ( !$blog_id = stats_get_option(‘blog_id’) ) || !stats_get_api_key() || !current_user_can( ‘manage_options’ ) )
return;

// wp_dashboard_empty: we load in the content after the page load via JS
wp_register_sidebar_widget( ‘dashboard_stats’, __(‘Stats’, ‘stats’), ‘wp_dashboard_empty’, array(
‘width’ => ‘full’
) );
wp_register_widget_control( ‘dashboard_stats’, __(‘Stats’, ‘stats’), ‘stats_register_dashboard_widget_control’, array(), array(
‘widget_id’ => ‘dashboard_stats’,
) );

add_action( ‘admin_head’, ‘stats_dashboard_head’ );
}

function stats_dashboard_widget_options() {
$defaults = array( ‘chart’ => 1, ‘top’ => 1, ‘search’ => 7, ‘active’ => 7 );
if ( ( !$options = get_option( ‘stats_dashboard_widget’ ) ) || !is_array($options) )
$options = array();

// Ignore obsolete option values
$intervals = array(1, 7, 31, 90, 365);
foreach ( array(‘top’, ‘search’, ‘active’) as $key )
if ( isset($options[$key]) && !in_array($options[$key], $intervals) )
unset($options[$key]);

return array_merge( $defaults, $options );
}

function stats_register_dashboard_widget_control() {
$periods = array( ‘1’ => __(‘day’, ‘stats’), ‘7’ => __(‘week’, ‘stats’), ’31’ => __(‘month’, ‘stats’) );
$intervals = array( ‘1’ => __(‘the past day’, ‘stats’), ‘7’ => __(‘the past week’, ‘stats’), ’31’ => __(‘the past month’, ‘stats’), ’90’ => __(‘the past quarter’, ‘stats’), ‘365’ => __(‘the past year’, ‘stats’) );
$options = stats_dashboard_widget_options();

$defaults = array(
‘top’ => 1,
‘search’ => 7,
‘active’ => 7,
);

if ( ‘post’ == strtolower($_SERVER[‘REQUEST_METHOD’]) && isset( $_POST[‘widget_id’] ) && ‘dashboard_stats’ == $_POST[‘widget_id’] ) {
if ( isset($periods[$_POST[‘chart’]]) )
$options[‘chart’] = $_POST[‘chart’];
foreach ( array( ‘top’, ‘search’, ‘active’ ) as $key ) {
if ( isset($intervals[$_POST[$key]]) )
$options[$key] = $_POST[$key];
else
$options[$key] = $defaults[$key];
}
update_option( ‘stats_dashboard_widget’, $options );
}
?>

$label ) : ?>
<option value="”>

.

$label ) : ?>
<option value="”>

.

$label ) : ?>
<option value="”>

.

$label ) : ?>
<option value="”>

.

/* */

/* <![CDATA[ */
#dashboard_stats .dashboard-widget-content {
padding-top: 25px;
}
#stats-info h4 {
font-size: 1em;
margin: 0 0 .3em;
}
<?php if ( version_compare( '2.7-z', $GLOBALS['wp_version'], '
#dashboard_stats {
overflow-x: hidden;
}
#dashboard_stats #stats-graph {
margin: 0;
}
#stats-info {
border-top: 1px solid #ccc;
}
#stats-info .stats-section {
width: 50%;
float: left;
}
#stats-info .stats-section-inner {
margin: 1em 0;
}
#stats-info div#active {
border-top: 1px solid #ccc;
}
#stats-info p {
margin: 0 0 .25em;
color: #999;
}
#stats-info div#top-search p {
color: #333;
}
#stats-info p a {
display: block;
}

#stats-graph {
width: 50%;
float: left;
}
#stats-info {
width: 49%;
float: left;
}
#stats-info div {
margin: 0 0 1em 30px;
}
#stats-info div#active {
margin-bottom: 0;
}
#stats-info p {
margin: 0;
color: #999;
}

/* ]]> */

false, ‘days’ => false, ‘limit’ => 3, ‘post_id’ => false, ‘summarize’ => ” );

$args = wp_parse_args( $args, $defaults );
$args[‘table’] = $table;
$args[‘blog_id’] = $blog_id;
$args[‘api_key’] = $key;

$stats_csv_url = add_query_arg( $args, ‘http://stats.wordpress.com/csv.php&#8217; );

$key = md5( $stats_csv_url );

// Get cache
$stats_cache = get_option( ‘stats_cache’ );
if ( !$stats_cache || !is_array($stats_cache) )
$stats_cache = array();

// Return or expire this key
if ( isset($stats_cache[$key]) ) {
$time = key($stats_cache[$key]);
if ( time() – $time $label )
$row[$label] = $stats[$s][$col];
$stats_rows[] = $row;
}
} while(0);

// Expire old keys
foreach ( $stats_cache as $k => $cache )
if ( !is_array($cache) || 300 $stats_rows );
update_option( ‘stats_cache’, $stats_cache );

return $stats_rows;
}

function stats_get_remote_csv( $url ) {
$url = clean_url( $url, null, ‘url’ );

// Yay!
if ( ini_get(‘allow_url_fopen’) ) {
$fp = @fopen($url, ‘r’);
if ( $fp ) {
//stream_set_timeout($fp, $timeout); // Requires php 4.3
$data = array();
while ( $remote_read = fgetcsv($fp, 1000) )
$data[] = $remote_read;
fclose($fp);
return $data;
}
}

// Boo – we need to use wp_remote_fopen for maximium compatibility
if ( !$csv = wp_remote_fopen( $url ) )
return false;

return stats_str_getcsv( $csv );
}

// rather than parsing the csv and its special cases, we create a new file and do fgetcsv on it.
function stats_str_getcsv( $csv ) {
if ( !$temp = tmpfile() ) // tmpfile() automatically unlinks
return false;

$data = array();

fwrite($temp, $csv, strlen($csv));
fseek($temp, 0);
while ( false !== $row = fgetcsv($temp, 1000) )
$data[] = $row;
fclose($temp);

return $data;
}

function stats_dashboard_widget_content() {
$blog_id = stats_get_option(‘blog_id’);
if ( ( !$width = (int) ( $_GET[‘width’] / 2 ) ) || $width < 250 )
$width = 370;
if ( ( !$height = (int) $_GET['height'] – 36 ) || $height ‘true’,
‘proxy’ => ”,
‘page’ => ‘stats’,
‘blog’ => $blog_id,
‘key’ => stats_get_api_key(),
‘chart’ => ”,
‘unit’ => $options[‘chart’],
‘width’ => $_width,
‘height’ => $_height,
);

$url = ‘https://dashboard.wordpress.com/wp-admin/index.php&#8217;;

$url = add_query_arg($q, $url);

$get = wp_remote_get($url, array(‘timeout’=>300));

if ( is_wp_error($get) || empty($get[‘body’]) ) {
$http = $_SERVER[‘HTTPS’] ? ‘https’ : ‘http’;
$src = clean_url( “$http://dashboard.wordpress.com/wp-admin/index.php?page=estats&blog=$blog_id&noheader=true&chart&unit=$options[chart]&width=$_width&height=$_height” );
echo “”;
} else {
$body = convert_swf_urls($get[‘body’]);
echo $body;
}

$post_ids = array();

if ( version_compare( ‘2.7-z’, $GLOBALS[‘wp_version’], ‘ ‘&limit=8’, ‘active’ => ‘&limit=5’, ‘search’ => ‘&limit=5’ );
/* translators: Stats dashboard widget postviews list: “$post_title $views Views” */
$printf = __( ‘%1$s %2$s Views’ , ‘stats’);
} else {
$csv_args = array( ‘top’ => ”, ‘active’ => ”, ‘search’ => ” );
/* translators: Stats dashboard widget postviews list: “$post_title, $views Views” */
$printf = __( ‘%1$s, %2$s views’ , ‘stats’);
}

foreach ( $top_posts = stats_get_csv( ‘postviews’, “days=$options[top]$csv_args[top]” ) as $post )
$post_ids[] = $post[‘post_id’];
foreach ( $active_posts = stats_get_csv( ‘postviews’, “days=$options[active]$csv_args[active]” ) as $post )
$post_ids[] = $post[‘post_id’];

// cache
get_posts( array( ‘include’ => join( ‘,’, array_unique($post_ids) ) ) );

$searches = array();
foreach ( $search_terms = stats_get_csv( ‘searchterms’, “days=$options[search]$csv_args[search]” ) as $search_term )
$searches[] = esc_html($search_term[‘searchterm’]);

?>

<?php printf(
$printf,
'‘ . get_the_title( $post[‘post_id’] ) . ‘‘,
// ‘‘ . $post[‘post_title’] . ‘‘,
number_format_i18n( $post[‘views’] )
); ?>

<?php printf(
$printf,
'‘ . get_the_title( $post[‘post_id’] ) . ‘‘,
// ‘‘ . $post[‘post_title’] . ‘‘,
number_format_i18n( $post[‘views’] )
); ?>


<?php
exit;
}

if ( !function_exists('number_format_i18n') ) {
function number_format_i18n( $number, $decimals = null ) { return number_format( $number, $decimals ); }
}

if ( !function_exists('wpme_dec2sixtwo') ) {
function wpme_dec2sixtwo( $num ) {
$index = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$out = "";

if ( $num = 0; $t– ) {
$a = floor( $num / pow( 62, $t ) );
$out = $out . substr( $index, $a, 1 );
$num = $num – ( $a * pow( 62, $t ) );
}

return $out;
}
}

if ( ! function_exists(‘wpme_get_shortlink’) ) :
function wpme_get_shortlink( $id = 0, $context = ‘post’, $allow_slugs = true ) {
global $wp_query;

$blog_id = stats_get_option(‘blog_id’);

if ( ‘query’ == $context ) {
if ( is_singular() ) {
$id = $wp_query->get_queried_object_id();
$context = ‘post’;
} elseif ( is_front_page() ) {
$context = ‘blog’;
} else {
return ”;
}
}

if ( ‘blog’ == $context ) {
if ( empty($id) )
$id = $blog_id;
return ‘http://wp.me/&#8217; . wpme_dec2sixtwo($id);
}

$post = get_post($id);

if ( empty($post) )
return ”;

$post_id = $post->ID;
$type = ”;

if ( $allow_slugs && ‘publish’ == $post->post_status && ‘post’ == $post->post_type && strlen($post->post_name) post_name, ‘%’)
&& false === strpos($post->post_name, ‘-‘) ) {
$id = $post->post_name;
$type = ‘s’;
} else {
$id = wpme_dec2sixtwo($post_id);
if ( ‘page’ == $post->post_type )
$type = ‘P’;
elseif ( ‘post’ == $post->post_type )
$type = ‘p’;
elseif ( ‘attachment’ == $post->post_type )
$type = ‘a’;
}

if ( empty($type) )
return ”;

return ‘http://wp.me/&#8217; . $type . wpme_dec2sixtwo($blog_id) . ‘-‘ . $id;
}

function wpme_shortlink_wp_head() {
global $wp_query;

$shortlink = wpme_get_shortlink(0, ‘query’);
echo ”;
}

function wpme_shortlink_header() {
global $wp_query;

if ( headers_sent() )
return;

$shortlink = wpme_get_shortlink(0, ‘query’);

header(‘Link: ; rel=shortlink’);
}

function wpme_get_shortlink_html($html, $post_id) {
$url = wpme_get_shortlink($post_id);
$html .= ‘‘ . __(‘Get Shortlink’, ‘stats’) . ‘‘;
return $html;
}

function wpme_get_shortlink_handler($shortlink, $id, $context, $allow_slugs) {
return wpme_get_shortlink($id, $context, $allow_slugs);
}

if ( stats_get_option(‘wp_me’) ) {
if ( ! function_exists(‘wp_get_shortlink’) ) {
// Register these only for WP = 3.0.
add_filter(‘get_shortlink’, ‘wpme_get_shortlink_handler’, 10, 4);
}
}

endif;

if ( !function_exists( ‘esc_html’ ) ):
function esc_html( $string ) {
return wp_specialchars( $string );
}
endif;

function stats_load_translations() {
load_plugin_textdomain( ‘stats’, null, basename( dirname( __FILE__ ) ) . ‘/languages’ );
}

add_action( ‘wp_dashboard_setup’, ‘stats_register_dashboard_widget’ );
add_filter( ‘wp_dashboard_widgets’, ‘stats_add_dashboard_widget’ );

// Boooooooooooring init stuff
register_activation_hook(__FILE__, ‘stats_activate’);
register_deactivation_hook(__FILE__, ‘stats_deactivate’);
add_action( ‘admin_menu’, ‘stats_admin_menu’ );
add_action( ‘activity_box_end’, ‘stats_activity’, 1 ); // WP < 2.5
add_action( 'init', 'stats_load_translations' );

// Plant the tracking code in the footer
add_action( 'wp_footer', 'stats_footer', 101 );

// Tell HQ about changed settings
add_action( 'update_option_home', 'stats_update_bloginfo' );
add_action( 'update_option_siteurl', 'stats_update_bloginfo' );
add_action( 'update_option_blogname', 'stats_update_bloginfo' );
add_action( 'update_option_blogdescription', 'stats_update_bloginfo' );
add_action( 'update_option_timezone_string', 'stats_update_bloginfo' );
add_action( 'add_option_timezone_string', 'stats_update_bloginfo' );
add_action( 'update_option_gmt_offset', 'stats_update_bloginfo' );

// Tell HQ about changed posts
add_action( 'save_post', 'stats_update_post', 10, 1 );

// Tell HQ to drop all post info for this blog
add_action( 'update_option_permalink_structure', 'stats_flush_posts' );

// Teach the XMLRPC server how to dance properly
add_filter( 'xmlrpc_methods', 'stats_xmlrpc_methods' );

define( 'STATS_XMLRPC_SERVER', 'http://wordpress.com/xmlrpc.php&#039; );

1 Comment (+add yours?)

  1. werner1964
    Jan 03, 2012 @ 12:56:38

    Blue heaven post up in respect to clasic cars, concours can but dizzy round cessfully within the deplete if ego in the singular break, because negativeness aiel liking sit on thereabouts them. argus car rentals

    Reply

Leave a comment