summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo Chatzimichos <tampakrap@gentoo.org>2010-10-27 11:13:08 +0300
committerTheo Chatzimichos <tampakrap@gentoo.org>2010-10-27 11:13:08 +0300
commite7fac954e7932db9a62c717ba0acf078401fbe96 (patch)
tree9ef7cb9a42ea18a659b5d8857e6a7a282d0c9463 /plugins/stats
parentsmall fixes in update script (diff)
downloadblogs-gentoo-e7fac954e7932db9a62c717ba0acf078401fbe96.tar.gz
blogs-gentoo-e7fac954e7932db9a62c717ba0acf078401fbe96.tar.bz2
blogs-gentoo-e7fac954e7932db9a62c717ba0acf078401fbe96.zip
Add the following plugins:
- aksimet - clean archives reloaded - google intergration toolkit - openid - smart youtube - wp stats - wp-syntax - wp-security scan
Diffstat (limited to 'plugins/stats')
-rw-r--r--plugins/stats/languages/stats.pot305
-rw-r--r--plugins/stats/open-flash-chart.swfbin0 -> 64600 bytes
-rw-r--r--plugins/stats/readme.txt170
-rw-r--r--plugins/stats/screenshot-1.pngbin0 -> 158914 bytes
-rw-r--r--plugins/stats/screenshot-2.pngbin0 -> 48212 bytes
-rw-r--r--plugins/stats/screenshot-3.pngbin0 -> 26118 bytes
-rw-r--r--plugins/stats/stats.php1246
7 files changed, 1721 insertions, 0 deletions
diff --git a/plugins/stats/languages/stats.pot b/plugins/stats/languages/stats.pot
new file mode 100644
index 00000000..c4c2ec47
--- /dev/null
+++ b/plugins/stats/languages/stats.pot
@@ -0,0 +1,305 @@
+# Translation of the WordPress plugin WordPress.com Stats 1.7.5 by Automattic.
+# Copyright (C) 2010 Automattic
+# This file is distributed under the same license as the WordPress.com Stats package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, 2010.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: WordPress.com Stats 1.7.5\n"
+"Report-Msgid-Bugs-To: http://wordpress.org/tag/stats\n"
+"POT-Creation-Date: 2010-10-04 12:09-0700\n"
+"PO-Revision-Date: 2010-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: stats.php:142
+msgid "Site Stats"
+msgstr ""
+
+#: stats.php:146
+msgid "WordPress.com Stats Plugin"
+msgstr ""
+
+#. #-#-#-#-# stats.pot (WordPress.com Stats 1.7.5) #-#-#-#-#
+#. Plugin Name of the plugin/theme
+#: stats.php:146 stats.php:391
+msgid "WordPress.com Stats"
+msgstr ""
+
+#: stats.php:360
+#, php-format
+msgid ""
+"<a href=\"%s\">WordPress.com Stats</a> needs attention: please enter an API "
+"key or disable the plugin."
+msgstr ""
+
+#: stats.php:372
+msgid ""
+"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 &lt;/body&gt; in footer.php:"
+msgstr ""
+
+#: stats.php:395
+msgid "Error from last API Key attempt:"
+msgstr ""
+
+#: stats.php:401
+#, php-format
+msgid ""
+"The API key \"%1$s\" belongs to the WordPress.com account \"%2$s\". If you "
+"want to use a different account, please <a href=\"%3$s\">enter the correct "
+"API key</a>."
+msgstr ""
+
+#: stats.php:402
+msgid ""
+"Note: the API key you use determines who will be registered as the \"owner\" "
+"of this blog in the WordPress.com database. Please choose your key "
+"accordingly. Do not use a temporary key."
+msgstr ""
+
+#: stats.php:418
+msgid "Recommended Action"
+msgstr ""
+
+#: stats.php:421
+msgid ""
+"It looks like you have installed Stats on a blog with this URL before. You "
+"can recover the stats history from that blog here."
+msgstr ""
+
+#: stats.php:422
+msgid "Recover stats"
+msgstr ""
+
+#: stats.php:424
+msgid ""
+"It looks like this blog has never had stats before. There is no record of "
+"its URL in the WordPress.com database."
+msgstr ""
+
+#: stats.php:425
+msgid "Add this blog to my WordPress.com account"
+msgstr ""
+
+#: stats.php:428
+msgid "Recover other stats"
+msgstr ""
+
+#: stats.php:429
+msgid ""
+"Have you relocated this blog from a different URL? You may opt to have this "
+"blog take over the stats history from any other self-hosted blog associated "
+"with your WordPress.com account. This is appropriate if this blog had a "
+"different URL in the past. The WordPress.com database will rename its "
+"records to match this blog's URL."
+msgstr ""
+
+#: stats.php:432
+msgid "Select a blog"
+msgstr ""
+
+#: stats.php:437
+msgid "Take over stats history"
+msgstr ""
+
+#: stats.php:445
+msgid "Add blog to WordPress.com account"
+msgstr ""
+
+#: stats.php:446
+msgid ""
+"This blog will be added to your WordPress.com account. You will be able to "
+"allow other WordPress.com users to see your stats if you like."
+msgstr ""
+
+#: stats.php:447
+msgid "Add blog to WordPress.com"
+msgstr ""
+
+#: stats.php:452
+msgid ""
+"The WordPress.com Stats Plugin is not working because it needs to be linked "
+"to a WordPress.com account."
+msgstr ""
+
+#: stats.php:456
+#, php-format
+msgid ""
+"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. (<a href=\"%s\">Get your key here.</a>)"
+msgstr ""
+
+#: stats.php:457
+msgid "API Key:"
+msgstr ""
+
+#: stats.php:459
+msgid "Save &raquo;"
+msgstr ""
+
+#: stats.php:462
+#, php-format
+msgid "Visit <a href=\"%s\">your Dashboard</a> to see your site stats."
+msgstr ""
+
+#: stats.php:463
+#, php-format
+msgid ""
+"You can also see your stats, plus grant access for others to see them, on <a "
+"href=\"https://dashboard.wordpress.com/wp-admin/index.php?page=stats&blog=%s"
+"\">your WordPress.com dashboard</a>."
+msgstr ""
+
+#: stats.php:464
+msgid "Options"
+msgstr ""
+
+#: stats.php:469
+msgid "Registered users"
+msgstr ""
+
+#: stats.php:470
+msgid "Count the page views of registered users who are logged in."
+msgstr ""
+
+#: stats.php:471
+msgid "Shortlinks"
+msgstr ""
+
+#: stats.php:472
+msgid ""
+"Publish WP.me <a href='http://wp.me/sf2B5-shorten'>shortlinks</a> as "
+"metadata. This is a free service from WordPress.com."
+msgstr ""
+
+#: stats.php:474
+msgid "Report visibility"
+msgstr ""
+
+#: stats.php:476
+msgid "Select the roles that will be able to view stats reports."
+msgstr ""
+
+#: stats.php:483
+msgid "Save options"
+msgstr ""
+
+#: stats.php:608
+msgid "WordPress.com Site Stats"
+msgstr ""
+
+#: stats.php:609
+#, php-format
+msgid "Visit <a href=\"%s\">your Global Dashboard</a> to see your site stats."
+msgstr ""
+
+#: stats.php:625 stats.php:658
+msgid ""
+"Your blog was unable to connect to WordPress.com. Please ask your host for "
+"help. ("
+msgstr ""
+
+#: stats.php:699 stats.php:702
+msgid "Stats"
+msgstr ""
+
+#: stats.php:724
+msgid "day"
+msgstr ""
+
+#: stats.php:724
+msgid "week"
+msgstr ""
+
+#: stats.php:724
+msgid "month"
+msgstr ""
+
+#: stats.php:725
+msgid "the past day"
+msgstr ""
+
+#: stats.php:725
+msgid "the past week"
+msgstr ""
+
+#: stats.php:725
+msgid "the past month"
+msgstr ""
+
+#: stats.php:725
+msgid "the past quarter"
+msgstr ""
+
+#: stats.php:725
+msgid "the past year"
+msgstr ""
+
+#: stats.php:747
+msgid "Chart stats by"
+msgstr ""
+
+#: stats.php:756
+msgid "Show top posts over"
+msgstr ""
+
+#: stats.php:765
+msgid "Show top search terms over"
+msgstr ""
+
+#: stats.php:774
+msgid "Show most active posts over"
+msgstr ""
+
+#. translators: Stats dashboard widget postviews list: "$post_title $views Views"
+#: stats.php:1025
+#, php-format
+msgid "%1$s %2$s Views"
+msgstr ""
+
+#. translators: Stats dashboard widget postviews list: "$post_title, $views Views"
+#: stats.php:1029
+#, php-format
+msgid "%1$s, %2$s views"
+msgstr ""
+
+#: stats.php:1048
+msgid "Top Posts"
+msgstr ""
+
+#: stats.php:1061
+msgid "Top Searches"
+msgstr ""
+
+#: stats.php:1067
+msgid "Most Active"
+msgstr ""
+
+#: stats.php:1081
+msgid "View All"
+msgstr ""
+
+#: stats.php:1182
+msgid "Get Shortlink"
+msgstr ""
+
+#. Plugin URI of the plugin/theme
+msgid "http://wordpress.org/extend/plugins/stats/"
+msgstr ""
+
+#. Description of the plugin/theme
+msgid ""
+"Tracks views, post/page views, referrers, and clicks. Requires a WordPress."
+"com API key."
+msgstr ""
+
+#. Author of the plugin/theme
+msgid "Automattic"
+msgstr ""
diff --git a/plugins/stats/open-flash-chart.swf b/plugins/stats/open-flash-chart.swf
new file mode 100644
index 00000000..85b590a2
--- /dev/null
+++ b/plugins/stats/open-flash-chart.swf
Binary files differ
diff --git a/plugins/stats/readme.txt b/plugins/stats/readme.txt
new file mode 100644
index 00000000..9fb74299
--- /dev/null
+++ b/plugins/stats/readme.txt
@@ -0,0 +1,170 @@
+=== WordPress.com Stats ===
+Contributors: automattic, skeltoac, mdawaffe
+Tags: stats, statistics
+Requires at least: 2.7
+Tested up to: 3.0.1
+Stable tag: 1.7.5
+
+You can have simple, concise stats with no additional load on your server by plugging into WordPress.com's stat system.
+
+== Description ==
+
+There are hundreds of plugins and services which can provide statistics about your visitors. However I found that even though something like Google Analytics provides an incredible depth of information, it can be overwhelming and doesn't really highlight what's most interesting to me as a writer. That's why Automattic created its own stats system, to focus on just the most popular metrics a blogger wants to track and provide them in a clear and concise interface.
+
+Installing this stats plugin is much like installing Akismet, all you need is to put in your [API Key](http://wordpress.com/api-keys/ "You can get a free API key from WordPress.com") and the rest is automatic.
+
+Once it's running it'll begin collecting information about your pageviews, which posts and pages are the most popular, where your traffic is coming from, and what people click on when they leave. It'll also add a link to your dashboard which allows you to see all your stats on a single page. Less is more.
+
+Finally, because all of the processing and collection runs on our servers and not yours, it doesn't cause any additional load on your hosting account. In fact, it's one of the fastest stats system, hosted or not hosted, that you can use.
+
+== Screenshots ==
+
+1. Your stats are displayed in a frame on your own blog's dashboard. There are graphs and several sections of charts below. You will need to be logged in at WordPress.com to see the stats. If you see a login box here, use your WordPress.com login.
+
+2. Each post has its own graph.
+
+3. You can add other WordPress.com users to the list of people allowed to see your stats.
+
+== Installation ==
+
+The automatic plugin installer should work for most people. Manual installation is easy and takes fewer than five minutes.
+
+1. Create a `stats` directory in your `plugins` directory. Typically that's `wp-content/plugins/stats/`.
+2. Into this new directory upload `stats.php` and `open-flash-chart.swf`.
+3. Activate the plugin through the 'Plugins' menu in WordPress.
+4. It will ask you to enter your WordPress.com API key, do so.
+5. Sit back and wait a few minutes for your stats to come rolling in.
+
+== Frequently Asked Questions ==
+
+= Can I keep using existing stat systems like Mint, Google Analytics, and Statcounter? =
+
+Of course, nothing we do conflicts with any of those systems. We're just (hopefully) faster.
+
+= How long before I start seeing stats? =
+
+It may take as long as 20 minutes the first time you use it. After that they should update every 3 minutes or so.
+
+= Does it count my own hits? =
+
+It does not count the hits of logged in users.
+
+= What if the stats don't start showing up? Do I need anything special in my theme? =
+
+Yes, your theme must have a call to `<?php wp_footer(); ?>` at the very bottom right before the `</body>` tag.
+
+= Can I hide the smiley? =
+
+Sure, just use `display:none`. Try this code in your stylesheet:
+
+`img#wpstats{display:none}`
+
+= Is it compatible with WP-Cache? =
+
+The plugin collects stats via a javascript call, so as long as the JS call is on the page stats will be collected just fine, whether the page is cached or not.
+
+= Can I use the same API key on multiple blogs? =
+
+Just like with Akismet, you're welcome to use the same API key on multiple blogs. If you view your stats directly on WordPress.com, you can easily switch between all of your blogs' stats reports.
+
+= How do I add a Top Posts widget to my blog? =
+
+We opened our database for developers to retrieve stats. The API is at `http://stats.wordpress.com/csv.php` and the plugin includes a handy function, `stats_get_csv()`, which you can use to get your most popular posts. Here is code you can add to your theme based on the work of <a href="http://www.binarymoon.co.uk/2010/03/ultimate-add-popular-posts-wordpress-blog-1-line-code/">Ben Gillbanks</a>:
+
+`<?php if ( function_exists('stats_get_csv') && $top_posts = stats_get_csv('postviews', 'days=7&limit=8') ) : ?>
+ <h3>Currently Hot</h3>
+ <ol>
+<?php foreach ( $top_posts as $p ) : ?>
+ <li><a href="<?php echo $p['post_permalink']; ?>"><?php echo $p['post_title']; ?></a></li>
+<?php endforeach; ?>
+ </ol>
+<?php endif; ?>`
+
+== Changelog ==
+
+= 1.7.5 =
+* Fix deprecated function call_user_method_array (props Galeforce99)
+* Move data deletion to uninstall hook (props viper007bond)
+* Change "Get your key here" link to apikey.wordpress.com
+
+= 1.7.4 =
+* Reinstate deactivation hook
+
+= 1.7.3 =
+* Add domain to gettext calls and load_plugin_textdomain (props nbachiyski)
+* Add POT file and Text Domain
+* Change some escaping functions (props nbachiyski)
+* Remove delete_option from deactivation hook
+
+= 1.7.2 =
+* Remove footer test pending investigation of errors.
+
+= 1.7.1 =
+* Add real-time test to check footer immediately prior to displaying notice. Should help automatic upgraders.
+
+= 1.7 =
+* Remove support for hard-coded API key as $stats_wpcom_api_key
+* Update admin screen after API key entry to add Recommended Action and clarify instructions
+* Add option to disable wp.me shortlinks
+* Add option to select roles with stats report visibility
+* Add option to enable tracking logged-in users
+* When activated for entire network, do not show admin notice about missing API keys
+* When plugins.php disabled, move stats admin page to options-general.php
+* Add check for footer code and display a helpful notice if not detected
+
+= 1.6.3 =
+* Add support for shortlink API in WordPress 3.0
+* Add CSV usage example to readme
+* Remove .htaccess
+* Remove all-time stats from dashboard widget
+
+= 1.6.2 =
+* Fix infinite loop when shortlink function dec2sixtwo called with a negative number. Thanks to Andrew Mattie for identifying this bug.
+* Fix unescaped Top Searches section in dashboard module. Thanks to Kobi for the report.
+
+= 1.6.1 =
+* Fix attachment titles in post stats list.
+* Fix chart not appearing due to .htaccess directive installed by some users. Thanks to Sean at growingmoneyblog.com for access to his affected system.
+
+= 1.6 =
+* Add shortlink generator. Now wp.me shortlinks are available on the Edit Post screen from a button next to View Post.
+
+= 1.5.4 =
+* Work around core API change in plugins_url. Different code for 2.7. Fixes missing charts in 2.7.*. No changes for 2.8+.
+
+= 1.5.3 =
+* Restore backward compatibility for WordPress 2.7. Fixes "Call to undefined function plugin_dir_url()..."
+
+= 1.5.2 =
+* Fix dashboard chart missing due to omitted line of code.
+
+= 1.5.1 =
+* Include <a href="http://teethgrinder.co.uk/open-flash-chart/">Open Flash Chart</a> SWF. Faster and more reliable than proxying it. Should fix missing graph for many users.
+* Move change log out of source code.
+* Fixed an XMLRPC encoding issue that resulted in "malformed" error when entering API key. Thanks to Oscar Reixa for helping.
+
+= 1.5 =
+* Kill iframes.
+* Use blog's role/cap system to allow local users to view reports. (No more switcher.)
+* Thanks to Stefanos Kofopoulos for helping to debug encoding issues.
+
+= 1.4 =
+* Added gmt_offset setting to blog definition. (Stats in your time zone.)
+
+= 1.3.8 =
+* Fixed "Missing API Key" error appearing in place of more helpful errors. Hat tip: Walt Ritscher.
+
+= 1.3.7 =
+* If blog dashboard is https, stats iframe should be https.
+
+= 1.3.6 =
+* fopen v wp_remote_fopen CSV fix from A. Piccinelli
+
+= 1.3.5 =
+* Compatibility with WordPress 2.7
+
+= 1.3.4 =
+* Compatibility with WordPress 2.7
+
+= 1.3.3 =
+* wpStats.update_postinfo no longer triggered by revision saves (post_type test)
diff --git a/plugins/stats/screenshot-1.png b/plugins/stats/screenshot-1.png
new file mode 100644
index 00000000..3cc8f68a
--- /dev/null
+++ b/plugins/stats/screenshot-1.png
Binary files differ
diff --git a/plugins/stats/screenshot-2.png b/plugins/stats/screenshot-2.png
new file mode 100644
index 00000000..c461db2a
--- /dev/null
+++ b/plugins/stats/screenshot-2.png
Binary files differ
diff --git a/plugins/stats/screenshot-3.png b/plugins/stats/screenshot-3.png
new file mode 100644
index 00000000..7580ba3f
--- /dev/null
+++ b/plugins/stats/screenshot-3.png
Binary files differ
diff --git a/plugins/stats/stats.php b/plugins/stats/stats.php
new file mode 100644
index 00000000..631be3e3
--- /dev/null
+++ b/plugins/stats/stats.php
@@ -0,0 +1,1246 @@
+<?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: Automattic
+Version: 1.7.5
+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'] < STATS_VERSION )
+ $options = stats_upgrade_options( $options );
+
+ return $options;
+}
+
+function stats_get_option( $option ) {
+ $options = stats_get_options();
+
+ if ( isset( $options[$option] ) )
+ return $options[$option];
+
+ return null;
+}
+
+function stats_set_option( $option, $value ) {
+ $options = stats_get_options();
+
+ $options[$option] = $value;
+
+ stats_set_options($options);
+}
+
+function stats_set_options($options) {
+ update_option( 'stats_options', $options );
+}
+
+function stats_upgrade_options( $options ) {
+ $defaults = array(
+ 'host' => '',
+ '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 "<!--stats_footer_test-->";
+
+ 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="<?php echo $http; ?>://stats.wordpress.com/e-<?php echo gmdate('YW'); ?>.js" type="text/javascript"></script>
+<script type="text/javascript">
+st_go({<?php echo stats_array($a); ?>});
+var load_cmc = function(){linktracker_init(<?php echo "{$a['blog']},{$a['post']},2"; ?>);};
+if ( typeof addLoadEvent != 'undefined' ) addLoadEvent(load_cmc);
+else load_cmc();
+</script>
+<?php
+}
+
+function stats_array($kvs) {
+ $kvs = apply_filters('stats_array', $kvs);
+ $kvs = array_map('addslashes', $kvs);
+ foreach ( $kvs as $k => $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() {
+?>
+<style type="text/css">
+ body { height: 100%; }
+ #statsreport { height: 2500px; width: 100%; }
+</style>
+<?php
+}
+
+function stats_reports_page() {
+ if ( isset( $_GET['dashboard'] ) )
+ return stats_dashboard_widget_content();
+ $blog_id = stats_get_option('blog_id');
+ $key = stats_get_api_key();
+ $day = isset( $_GET['day'] ) && preg_match( '/^\d{4}-\d{2}-\d{2}$/', $_GET['day'] ) ? $_GET['day'] : false;
+ $q = array(
+ 'noheader' => '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";
+ }
+
+ $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 ? "&amp;day=$day" : '';
+ echo "<iframe id='statsreport' frameborder='0' src='$http://dashboard.wordpress.com/wp-admin/index.php?page=estats&amp;blog=$blog_id&amp;noheader=true$day'></iframe>";
+ } 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 = "<span class='post-(\d+)-link'>.*?</span>";
+ 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 '<a href="'.get_permalink($post_id).'" target="_blank">'.get_the_title($post_id).'</a>';
+ 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 "<div class='updated' style='background-color:#f66;'><p>" . sprintf(__('<a href="%s">WordPress.com Stats</a> needs attention: please enter an API key or disable the plugin.', 'stats'), stats_admin_path()) . "</p></div>";
+}
+
+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 "<div class='updated' style='background-color:#f66;'><p>" . __('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 &lt;/body&gt; in footer.php:', 'stats') . "</p><p><code>&lt;?php wp_footer(); ?&gt;</code></p></div>";
+}
+
+function stats_admin_head() {
+ ?>
+ <style type="text/css">
+ #statserror {
+ border: 1px solid #766;
+ background-color: #d22;
+ padding: 1em 3em;
+ }
+ </style>
+ <?php
+}
+
+function stats_admin_page() {
+ $options = stats_get_options();
+ ?>
+ <div class="wrap">
+ <h2><?php _e('WordPress.com Stats', 'stats'); ?></h2>
+ <div class="narrow">
+<?php if ( !empty($options['error']) ) : ?>
+ <div id='statserror'>
+ <h3><?php _e('Error from last API Key attempt:', 'stats'); ?></h3>
+ <p><?php echo $options['error']; ?></p>
+ </div>
+<?php $options['error'] = false; stats_set_options($options); endif; ?>
+
+<?php if ( empty($options['blog_id']) && !empty($options['key_check']) ) : ?>
+ <p><?php printf(__('The API key "%1$s" belongs to the WordPress.com account "%2$s". If you want to use a different account, please <a href="%3$s">enter the correct API key</a>.', 'stats'), $options['key_check'][0], $options['key_check'][1], wp_nonce_url('?page=wpstats&action=reset', 'stats')); ?></p>
+ <p><?php _e('Note: the API key you use determines who will be registered as the "owner" of this blog in the WordPress.com database. Please choose your key accordingly. Do not use a temporary key.', 'stats'); ?></p>
+
+<?php if ( !empty($options['key_check'][2]) ) : ?>
+ <form method="post">
+ <?php wp_nonce_field('stats'); ?>
+ <input type="hidden" name="action" value="add_or_replace" />
+<?php
+ $domainpath = preg_replace('|.*://|', '', get_bloginfo('siteurl'));
+ foreach ( $options['key_check'][2] as $blog ) {
+ if ( trailingslashit("{$blog[domain]}{$blog[path]}") == trailingslashit($domainpath) )
+ break;
+ else
+ unset($blog);
+ }
+?>
+
+ <h3><?php _e('Recommended Action', 'stats'); ?></h3>
+<?php if ( isset($blog) ) : ?>
+ <input type='hidden' name='recoverblog' value='<?php echo $blog['userblog_id']; ?>' />
+ <p><?php _e('It looks like you have installed Stats on a blog with this URL before. You can recover the stats history from that blog here.', 'stats'); ?></p>
+ <p><input type="submit" name="recover" value="<?php echo js_escape(__('Recover stats', 'stats')); ?>" /></p>
+<?php else : ?>
+ <p><?php _e('It looks like this blog has never had stats before. There is no record of its URL in the WordPress.com database.', 'stats'); ?></p>
+ <p><input type="submit" name="add" value="<?php echo js_escape(__('Add this blog to my WordPress.com account', 'stats')); ?>" /></p>
+<?php endif; ?>
+
+ <h3><?php _e('Recover other stats', 'stats'); ?></h3>
+ <p><?php _e("Have you relocated this blog from a different URL? You may opt to have this blog take over the stats history from any other self-hosted blog associated with your WordPress.com account. This is appropriate if this blog had a different URL in the past. The WordPress.com database will rename its records to match this blog's URL.", 'stats'); ?></p>
+ <p>
+ <select name="blog_id">
+ <option selected="selected" value="0"><?php _e('Select a blog', 'stats'); ?></option>
+<?php foreach ( $options['key_check'][2] as $blog ) : ?>
+ <option value="<?php echo $blog['userblog_id']; ?>"><?php echo $blog['domain'] . $blog['path']; ?></option>
+<?php endforeach; ?>
+ </select>
+ <input type="submit" name="replace" value="<?php echo js_escape(__('Take over stats history', 'stats')); ?>" />
+ </p>
+ </form>
+
+<?php else : ?>
+ <form method="post">
+ <?php wp_nonce_field('stats'); ?>
+ <input type="hidden" name="action" value="add_or_replace" />
+ <h3><?php _e('Add blog to WordPress.com account', 'stats'); ?></h3>
+ <p><?php _e("This blog will be added to your WordPress.com account. You will be able to allow other WordPress.com users to see your stats if you like.", 'stats'); ?></p>
+ <p><input type="submit" name="add" value="<?php echo esc_attr(__('Add blog to WordPress.com', 'stats')); ?>" /></p>
+ </form>
+<?php endif; ?>
+
+<?php elseif ( empty( $options['blog_id'] ) ) : ?>
+ <p><?php _e('The WordPress.com Stats Plugin is not working because it needs to be linked to a WordPress.com account.', 'stats'); ?></p>
+
+ <form action="<?php echo stats_admin_path() ?>" method="post">
+ <?php wp_nonce_field('stats'); ?>
+ <p><?php printf(__('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. (<a href="%s">Get your key here.</a>)', 'stats'), 'https://apikey.wordpress.com/'); ?></p>
+ <label for="api_key"><?php _e('API Key:', 'stats'); ?> <input type="text" name="api_key" id="api_key" value="" /></label>
+ <input type="hidden" name="action" value="enter_key" />
+ <p class="submit"><input type="submit" value="<?php _e('Save &raquo;', 'stats'); ?>" /></p>
+ </form>
+<?php else : ?>
+ <p><?php printf(__('Visit <a href="%s">your Dashboard</a> to see your site stats.', 'stats'), 'index.php?page=stats'); ?></p>
+ <p><?php printf(__('You can also see your stats, plus grant access for others to see them, on <a href="https://dashboard.wordpress.com/wp-admin/index.php?page=stats&blog=%s">your WordPress.com dashboard</a>.', 'stats'), $options['blog_id']); ?></p>
+ <h3><?php _e('Options', 'stats'); ?></h3>
+ <form action="<?php echo stats_admin_path() ?>" method="post">
+ <input type='hidden' name='action' value='save_options' />
+ <?php wp_nonce_field('stats'); ?>
+ <table id="menu" class="form-table">
+ <tr valign="top"><th scope="row"><label for="wp_me"><?php _e( 'Registered users' , 'stats'); ?></label></th>
+ <td><label><input type='checkbox'<?php checked($options['reg_users']); ?> name='reg_users' id='reg_users' /> <?php _e("Count the page views of registered users who are logged in.", 'stats'); ?></label></td>
+ <tr valign="top"><th scope="row"><label for="wp_me"><?php _e( 'Shortlinks' , 'stats'); ?></label></th>
+ <td><label><input type='checkbox'<?php checked($options['wp_me']); ?> name='wp_me' id='wp_me' /> <?php _e("Publish WP.me <a href='http://wp.me/sf2B5-shorten'>shortlinks</a> as metadata. This is a free service from WordPress.com.", 'stats'); ?></label></td>
+ </tr>
+ <tr valign="top"><th scope="row"><?php _e( 'Report visibility' , 'stats'); ?></th>
+ <td>
+ <?php _e('Select the roles that will be able to view stats reports.', 'stats'); ?><br/>
+<?php $stats_roles = stats_get_option('roles');
+ foreach ( get_editable_roles() as $role => $details ) : ?>
+ <label><input type='checkbox' <?php if ( $role == 'administrator' ) echo "disabled='disabled' "; ?>name='role_<?php echo $role; ?>'<?php checked($role == 'administrator' || in_array($role, $stats_roles)); ?> /> <?php echo translate_user_role($details['name']); ?></label><br/>
+<?php endforeach; ?>
+ </tr>
+ </table>
+ <p class="submit"><input type='submit' class='button-primary' value='<?php echo esc_attr(__('Save options', 'stats')); ?>' /></p>
+ </form>
+<?php endif; ?>
+
+ </div>
+ </div>
+
+ <?php
+ stats_set_options( $options );
+}
+
+function stats_xmlrpc_methods( $methods ) {
+ $my_methods = array(
+ 'wpStats.get_posts' => '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_func_array( array( $stats_xmlrpc_client, 'addCall' ), $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 < 2.5
+function stats_activity() {
+ if ( did_action( 'rightnow_end' ) )
+ return;
+
+ $options = stats_get_options();
+
+ if ( $options['blog_id'] ) {
+ ?>
+ <h3><?php _e('WordPress.com Site Stats', 'stats'); ?></h3>
+ <p><?php printf(__('Visit <a href="%s">your Global Dashboard</a> to see your site stats.', 'stats'), 'https://dashboard.wordpress.com/wp-admin/index.php?page=stats&blog=' . $options['blog_id']); ?></p>
+ <?php
+ }
+}
+
+function stats_check_key($api_key) {
+ $options = stats_get_options();
+
+ require_once( ABSPATH . WPINC . '/class-IXR.php' );
+
+ $client = new IXR_Client( STATS_XMLRPC_SERVER );
+
+ $client->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_uninstall() {
+ 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 );
+ }
+?>
+ <p>
+ <label for="chart"><?php _e( 'Chart stats by' , 'stats'); ?></label>
+ <select id="chart" name="chart">
+<?php foreach ( $periods as $val => $label ) : ?>
+ <option value="<?php echo $val; ?>"<?php selected( $val, $options['chart'] ); ?>><?php echo esc_html( $label ); ?></option>
+<?php endforeach; ?>
+ </select>.
+ </p>
+
+ <p>
+ <label for="top"><?php _e( 'Show top posts over' , 'stats'); ?></label>
+ <select id="top" name="top">
+<?php foreach ( $intervals as $val => $label ) : ?>
+ <option value="<?php echo $val; ?>"<?php selected( $val, $options['top'] ); ?>><?php echo esc_html( $label ); ?></option>
+<?php endforeach; ?>
+ </select>.
+ </p>
+
+ <p>
+ <label for="search"><?php _e( 'Show top search terms over' , 'stats'); ?></label>
+ <select id="search" name="search">
+<?php foreach ( $intervals as $val => $label ) : ?>
+ <option value="<?php echo $val; ?>"<?php selected( $val, $options['search'] ); ?>><?php echo esc_html( $label ); ?></option>
+<?php endforeach; ?>
+ </select>.
+ </p>
+
+ <p>
+ <label for="active"><?php _e( 'Show most active posts over' , 'stats'); ?></label>
+ <select id="active" name="active">
+<?php foreach ( $intervals as $val => $label ) : ?>
+ <option value="<?php echo $val; ?>"<?php selected( $val, $options['active'] ); ?>><?php echo esc_html( $label ); ?></option>
+<?php endforeach; ?>
+ </select>.
+ </p>
+
+<?php
+}
+
+function stats_add_dashboard_widget( $widgets ) {
+ global $wp_registered_widgets;
+ if ( !isset($wp_registered_widgets['dashboard_stats']) || !current_user_can( 'manage_options' ) )
+ return $widgets;
+
+ array_splice( $widgets, 2, 0, 'dashboard_stats' );
+ return $widgets;
+}
+
+// Javascript and CSS for dashboard widget
+function stats_dashboard_head() { ?>
+<script type="text/javascript">
+/* <![CDATA[ */
+jQuery( function($) {
+ var dashStats = $('#dashboard_stats.postbox div.inside');
+ if ( dashStats.find( '.dashboard-widget-control-form' ).size() ) {
+ return;
+ }
+
+ if ( !dashStats.size() ) {
+ dashStats = $('#dashboard_stats div.dashboard-widget-content');
+ var h = parseInt( dashStats.parent().height() ) - parseInt( dashStats.prev().height() );
+ var args = 'width=' + dashStats.width() + '&height=' + h.toString();
+ } else {
+ var args = 'width=' + ( dashStats.prev().width() * 2 ).toString();
+ }
+
+ dashStats.not( '.dashboard-widget-control' ).load('index.php?page=stats&noheader&dashboard&' + args );
+} );
+/* ]]> */
+</script>
+<style type="text/css">
+/* <![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;
+}
+<?php else : ?>
+#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;
+}
+<?php endif; ?>
+/* ]]> */
+</style>
+<?php
+}
+
+function stats_get_csv( $table, $args = null ) {
+ $blog_id = stats_get_option('blog_id');
+ $key = stats_get_api_key();
+
+ if ( !$blog_id || !$key )
+ return array();
+
+ $defaults = array( 'end' => 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' );
+
+ $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 < 300 )
+ return $stats_cache[$key][$time];
+ unset( $stats_cache[$key] );
+ }
+
+ $stats_rows = array();
+ do {
+ if ( !$stats = stats_get_remote_csv( $stats_csv_url ) )
+ break;
+
+ $labels = array_shift( $stats );
+
+ if ( 0 === stripos( $labels[0], 'error' ) )
+ break;
+
+ $stats_rows = array();
+ for ( $s = 0; isset($stats[$s]); $s++ ) {
+ $row = array();
+ foreach ( $labels as $col => $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 < time() - key($cache) )
+ unset($stats_cache[$k]);
+
+ // Set cache
+ $stats_cache[$key] = array( time() => $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 < 230 )
+ $height = 230;
+
+ $_width = $width - 5;
+ $_height = $height - ( $GLOBALS['is_winIE'] ? 16 : 5 ); // hack!
+
+ $options = stats_dashboard_widget_options();
+
+ $q = array(
+ 'noheader' => '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';
+
+ $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 "<iframe id='stats-graph' class='stats-section' frameborder='0' style='width: {$width}px; height: {$height}px; overflow: hidden' src='$src'></iframe>";
+ } else {
+ $body = convert_swf_urls($get['body']);
+ echo $body;
+ }
+
+ $post_ids = array();
+
+ if ( version_compare( '2.7-z', $GLOBALS['wp_version'], '<=' ) ) {
+ $csv_args = array( 'top' => '&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']);
+
+?>
+<div id="stats-info">
+ <div id="top-posts" class='stats-section'>
+ <div class="stats-section-inner">
+ <h4 class="heading"><?php _e( 'Top Posts' , 'stats'); ?></h4>
+ <?php foreach ( $top_posts as $post ) : if ( !get_post( $post['post_id'] ) ) continue; ?>
+ <p><?php printf(
+ $printf,
+ '<a href="' . get_permalink( $post['post_id'] ) . '">' . get_the_title( $post['post_id'] ) . '</a>',
+// '<a href="' . $post['post_permalink'] . '">' . $post['post_title'] . '</a>',
+ number_format_i18n( $post['views'] )
+ ); ?></p>
+ <?php endforeach; ?>
+ </div>
+ </div>
+ <div id="top-search" class='stats-section'>
+ <div class="stats-section-inner">
+ <h4 class="heading"><?php _e( 'Top Searches' , 'stats'); ?></h4>
+ <p><?php echo join( ',&nbsp; ', $searches );?></p>
+ </div>
+ </div>
+ <div id="active" class='stats-section'>
+ <div class="stats-section-inner">
+ <h4 class="heading"><?php _e( 'Most Active' , 'stats'); ?></h4>
+ <?php foreach ( $active_posts as $post ) : if ( !get_post( $post['post_id'] ) ) continue; ?>
+ <p><?php printf(
+ $printf,
+ '<a href="' . get_permalink( $post['post_id'] ) . '">' . get_the_title( $post['post_id'] ) . '</a>',
+// '<a href="' . $post['post_permalink'] . '">' . $post['post_title'] . '</a>',
+ number_format_i18n( $post['views'] )
+ ); ?></p>
+ <?php endforeach; ?>
+ </div>
+ </div>
+</div>
+<br class="clear" />
+<p class="textright">
+ <a class="button" href="index.php?page=stats"><?php _e( 'View All' , 'stats'); ?></a>
+</p>
+<?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 ) {
+ $out = '-';
+ $num = abs($num);
+ }
+
+ for ( $t = floor( log10( $num ) / log10( 62 ) ); $t >= 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/' . 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) <= 8 && false === strpos($post->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/' . $type . wpme_dec2sixtwo($blog_id) . '-' . $id;
+}
+
+function wpme_shortlink_wp_head() {
+ global $wp_query;
+
+ $shortlink = wpme_get_shortlink(0, 'query');
+ echo '<link rel="shortlink" href="' . $shortlink . '" />';
+}
+
+function wpme_shortlink_header() {
+ global $wp_query;
+
+ if ( headers_sent() )
+ return;
+
+ $shortlink = wpme_get_shortlink(0, 'query');
+
+ header('Link: <' . $shortlink . '>; rel=shortlink');
+}
+
+function wpme_get_shortlink_html($html, $post_id) {
+ $url = wpme_get_shortlink($post_id);
+ $html .= '<input id="shortlink" type="hidden" value="' . $url . '" /><a href="#" class="button" onclick="prompt(&#39;URL:&#39;, jQuery(\'#shortlink\').val()); return false;">' . __('Get Shortlink', 'stats') . '</a>';
+ 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_action('wp_head', 'wpme_shortlink_wp_head');
+ add_action('wp', 'wpme_shortlink_header');
+ add_filter( 'get_sample_permalink_html', 'wpme_get_shortlink_html', 10, 2 );
+ } else {
+ // Register a shortlink handler 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_uninstall_hook(__FILE__, 'stats_uninstall');
+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' );