summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo Chatzimichos <tampakrap@gentoo.org>2013-08-01 09:06:18 +0200
committerTheo Chatzimichos <tampakrap@gentoo.org>2013-08-01 09:06:18 +0200
commit2d6f7d9cd4baee8c303942220506ef756208145f (patch)
treef6d15538aa8453dbae321c4815b0b101a4c3b404 /plugins/jetpack/class.jetpack-heartbeat.php
parentUpdate jetpack, akismet and wordpress-importer (diff)
downloadblogs-gentoo-2d6f7d9cd4baee8c303942220506ef756208145f.tar.gz
blogs-gentoo-2d6f7d9cd4baee8c303942220506ef756208145f.tar.bz2
blogs-gentoo-2d6f7d9cd4baee8c303942220506ef756208145f.zip
forgot to include new files of jetpack
Diffstat (limited to 'plugins/jetpack/class.jetpack-heartbeat.php')
-rw-r--r--plugins/jetpack/class.jetpack-heartbeat.php131
1 files changed, 131 insertions, 0 deletions
diff --git a/plugins/jetpack/class.jetpack-heartbeat.php b/plugins/jetpack/class.jetpack-heartbeat.php
new file mode 100644
index 00000000..40daf2a9
--- /dev/null
+++ b/plugins/jetpack/class.jetpack-heartbeat.php
@@ -0,0 +1,131 @@
+<?php
+
+class Jetpack_Heartbeat {
+
+ /**
+ * Jetpack object
+ *
+ * @since 2.3.3
+ * @var Jetpack
+ */
+ var $jetpack = null;
+
+ /**
+ * Holds the singleton instance of this class
+ *
+ * @since 2.3.3
+ * @var Jetpack_Heartbeat
+ */
+ static $instance = false;
+
+ private $cron_name = 'jetpack_heartbeat';
+
+ /**
+ * Singleton
+ *
+ * @since 2.3.3
+ * @static
+ * @return Jetpack_Heartbeat
+ */
+ public static function init() {
+ if ( ! self::$instance ) {
+ self::$instance = new Jetpack_Heartbeat;
+ }
+
+ return self::$instance;
+ }
+
+ /**
+ * Constructor for singleton
+ *
+ * @since 2.3.3
+ * @return Jetpack_Heartbeat
+ */
+ private function __construct() {
+ $this->jetpack = Jetpack::init();
+
+ // Add weekly interval for wp-cron
+ add_filter('cron_schedules', array( $this, 'add_cron_intervals' ) );
+
+ // Schedule the task
+ add_action( $this->cron_name, array( $this, 'cron_exec' ) );
+
+ if (!wp_next_scheduled( $this->cron_name ) ) {
+ wp_schedule_event( time(), 'jetpack_weekly', $this->cron_name );
+ }
+ }
+
+ /**
+ * Method that gets executed on the wp-cron call
+ *
+ * @since 2.3.3
+ * @global string $wp_version
+ */
+ public function cron_exec() {
+
+ /*
+ * Check for an identity crisis
+ *
+ * If one exists:
+ * - Bump stat for ID crisis
+ * - Email site admin about potential ID crisis
+ */
+
+
+
+ /**
+ * Setup an array of items that will eventually be stringified
+ * and sent off to the Jetpack API
+ *
+ * Associative array with format group => values
+ * - values should be an array that will be imploded to a string
+ */
+
+ $jetpack = $this->jetpack;
+
+ $jetpack->stat( 'active-modules', implode( ',', $this->jetpack->get_active_modules() ) );
+ $jetpack->stat( 'active', JETPACK__VERSION );
+ $jetpack->stat( 'wp-version', get_bloginfo( 'version' ) );
+ $jetpack->stat( 'php-version', PHP_VERSION );
+ $jetpack->stat( 'ssl', $jetpack->permit_ssl() );
+ $jetpack->stat( 'language', get_bloginfo( 'language' ) );
+ $jetpack->stat( 'charset', get_bloginfo( 'charset' ) );
+ $jetpack->stat( 'qty-posts', wp_count_posts()->publish );
+ $jetpack->stat( 'qty-pages', wp_count_posts( 'page' )->publish );
+ $jetpack->stat( 'qty-comments', wp_count_comments()->approved );
+ $jetpack->stat( 'is-multisite', is_multisite() ? 'multisite' : 'singlesite' );
+
+ // Only check a few plugins, to see if they're currently active.
+ $plugins_to_check = array(
+ 'vaultpress/vaultpress.php',
+ 'akismet/akismet.php',
+ 'wp-super-cache/wp-cache.php',
+ );
+ $plugins = array_intersect( $plugins_to_check, get_option( 'active_plugins', array() ) );
+ foreach( $plugins as $plugin ) {
+ $jetpack->stat( 'plugins', $plugin );
+ }
+
+ $jetpack->do_stats( 'server_side' );
+ }
+
+ /**
+ * Adds additional Jetpack specific intervals to wp-cron
+ *
+ * @since 2.3.3
+ * @return array
+ */
+ public function add_cron_intervals( $schedules ) {
+ $schedules['jetpack_weekly'] = array(
+ 'interval' => WEEK_IN_SECONDS,
+ 'display' => __('Jetpack weekly')
+ );
+ return $schedules;
+ }
+
+ public function deactivate() {
+ $timestamp = wp_next_scheduled( $this->cron_name );
+ wp_unschedule_event($timestamp, $this->cron_name );
+ }
+
+}// end class