public function deactivate()
 {
     // Remove Queued Updates
     MetricsUpdater::removeAllQueuedUpdates();
 }
 public static function printQueueLength()
 {
     $count = MetricsUpdater::getQueueLength();
     if ($count >= 1) {
         $label = $count >= 2 ? ' items' : ' item';
         printf('<div class="updated"> <p> %s </p> </div>', '<b>' . $count . $label . '</b> scheduled to be synced with social networks the next time WP Cron is run...');
     }
 }
function smt_render_dashboard_view($smt)
{
    $last_full_sync = get_option("smt_last_full_sync");
    if (isset($_REQUEST['smt_test_http_now'])) {
        $smt->debugger->testHTTPResourceUpdaters();
    }
    $offline_updaters = $smt->debugger->getOfflineHTTPResourceUpdaters();
    ?>
	<div class="wrap">

		<h2>Social Metrics Tracker</h2>


		<?php 
    if (isset($_REQUEST['smt_full_sync'])) {
        ?>
		<h3>Now scheduling a full data update...</h3>
		<p>This process must check all posts in your database and may take a short while...</p>
		<p>If you have custom post types that you would like to track or exclude please go to the configuration page!</p>
		<?php 
        $num = $smt->updater->scheduleFullDataSync(true);
        ?>
		<p>Your server will work on retrieving share stats from social networks in the background. You should not need to run this again as the plugin will automatically keep items up-to-date as visitors browse and share your content. </p>
		<?php 
        return;
    }
    ?>


		<form id="social-metrics-tracker" method="get" action="admin.php?page=social-metrics-tracker">
			<input type="hidden" name="page" value="<?php 
    echo $_REQUEST['page'];
    ?>
" />
			<input type="hidden" name="orderby" value="<?php 
    echo !empty($_REQUEST['orderby']) ? $_REQUEST['orderby'] : $smt->options['smt_options_default_sort_column'];
    ?>
" />
			<input type="hidden" name="order" value="<?php 
    echo !empty($_REQUEST['order']) ? $_REQUEST['order'] : 'DESC';
    ?>
" />


			<?php 
    if (!$last_full_sync) {
        ?>
			<div class="update-nag" style="margin-bottom:30px;">
				<h3> Setup Instructions </h3>
				<p>You need to perform a one time full-sync. </p>
				<p>We will schedule it now, and it will run in the background.</p>
				<p>In general, social stats can take a little while to appear. This plugin will keep numbers up to date by periodically checking for new stats as visitors view your posts. Even after social shares occur, it can take a few hours for them to appear here. If you have custom post types, please visit the configuration page first. </p>
				<p><a href="<?php 
        echo add_query_arg(array('smt_full_sync' => 1));
        ?>
" class="button">Schedule full sync</a></p>
			</div>
			<?php 
    }
    ?>


			<?php 
    if (!$smt->is_development_server() && $last_full_sync) {
        ?>

				<?php 
        if (count($offline_updaters) == 0) {
            ?>
				<button id="smt-connection-status-toggle" class="smt-connection-item online">Data is being synced in the background</button>
				<?php 
        } else {
            ?>
				<button id="smt-connection-status-toggle" class="smt-connection-item offline">Temporary connectivity issue detected. Click for details.</button>
				<?php 
        }
        ?>

				<div id="smt-connection-status" style="<?php 
        echo isset($_REQUEST['smt_test_http_now']) ? '' : 'display:none;';
        ?>
">
					<?php 
        foreach ($smt->updater->getSources() as $h) {
            ?>
					<?php 
            $status = $h->wpcb->getStatusDetail();
            ?>
					<div class="smt-connection-item <?php 
            echo $status['working'] ? 'online' : 'offline';
            ?>
">
						<?php 
            echo $h->name;
            ?>
						<?php 
            if (!$status['working']) {
                ?>
						 - <?php 
                echo $status['fail_count'];
                ?>
 failures - <?php 
                echo $status['error_message'];
                ?>
 
						 <a href="javascript:void(0);" onClick="jQuery('#smt-error-details-<?php 
                echo $h->slug;
                ?>
').slideToggle();">[Show debug info]</a>
						 <div id="smt-error-details-<?php 
                echo $h->slug;
                ?>
" style="display:none;">
						 	<p><b>Debug information: </b>This is a record of the most recent attempt your blog server made at connecting to the social network to retrieve stats. <span style="color:red;">Warning: The debug info below may contain your private access_token for Facebook, if you have configured that under Connection Settings (it would be part of 'request_uri' below). It will also contain a URL back to one of your blog posts (see "request_uri" below). If you post this publicly on the support forums, be sure to delete any private information before posting!</span>. </p>
						 	<textarea class="smt-debug-box"><?php 
                echo htmlspecialchars(print_r($status['error_detail'], true));
                ?>
</textarea>
						 </div>
						 <br /><small>Will automatically retry <?php 
                echo date("M j, g:i a", $status['next_query_at']);
                ?>
.</small>
						<?php 
            }
            ?>

						<br />
						<small>Last checked <?php 
            echo date("M j, g:i a", $status['last_query_at']);
            ?>
</small>
					</div>
					<?php 
        }
        ?>

					<?php 
        if (count($offline_updaters) > 0 && !isset($_REQUEST['smt_test_http_now'])) {
            ?>
					<p><a class="button" href="<?php 
            echo add_query_arg(array('smt_test_http_now' => 1));
            ?>
">Re-check all connections right now.</a></p>
					<p><small>If any of the services listed above are displaying errors, they will be automatically excluded when checking for new data. If errors do not resolve themselves within one day, there might be a problem with the servers ability to connect to social network APIs to retrieve data. Clicking "re-check now" will test all connections by attempting to fetch the share count for the url "http://www.wikipedia.org" and will verify that all social networks report at least one share for that URL.</small></p>
					<?php 
        }
        ?>

				</div>

			<?php 
    }
    ?>


			<?php 
    //Create an instance of our package class...
    $SocialMetricsTable = new SocialMetricsTable($smt);
    //Fetch, prepare, sort, and filter our data...
    $SocialMetricsTable->prepare_items();
    $SocialMetricsTable->display();
    ?>

			<p align="center">Please <a href="https://wordpress.org/support/view/plugin-reviews/social-metrics-tracker">rate the Social Metrics Tracker</a> plugin if you have found it useful, or <a href="https://wordpress.org/support/plugin/social-metrics-tracker">visit the support forum</a> for help.</p>

		</form>

		<?php 
    MetricsUpdater::printQueueLength();
    ?>

	</div>
	<?php 
}
function smt_render_dashboard_debug_view($options)
{
    //Create an instance of our package class...
    $testListTable = new SocialMetricsDebugTable();
    //Fetch, prepare, sort, and filter our data...
    $testListTable->prepare_items();
    ?>
	<div class="wrap">

		<div id="icon-users" class="icon32"><br/></div>
		<h2>Advanced Relevancy Rank Dashboard</h2>

		<?php 
    if (!is_array($options)) {
        printf('<div class="error"> <p> %s </p> </div>', "Before you can view data, you must <a class='login' href='options-general.php?page=social-metrics-tracker-settings'>configure the Social Metrics Tracker</a>.");
        die;
    }
    if (isset($_GET['smc_recalculate_all_ranks'])) {
        printf('<div class="updated"> <p> %s </p> </div>', 'Now updating all social relevancy ranks... Do not navigate away from this page until it is complete! <a href="admin.php?page=social-metrics-tracker-debug">Return to report view</a>');
        $data_updater = new MetricsUpdater();
        $data_updater->recalculateAllScores(true);
        die;
    }
    ?>

		<!-- Forms are NOT created automatically, so you need to wrap the table in one to use features like bulk actions -->
		<form id="social-metrics-tracker" method="get" action="admin.php?page=social-metrics-tracker-debug">
			<!-- For plugins, we also need to ensure that the form posts back to our current page -->
			<input type="hidden" name="page" value="<?php 
    echo $_REQUEST['page'];
    ?>
" />
			<input type="hidden" name="orderby" value="<?php 
    echo !empty($_REQUEST['orderby']) ? $_REQUEST['orderby'] : $options['smt_options_default_sort_column'];
    ?>
" />
			<input type="hidden" name="order" value="<?php 
    echo !empty($_REQUEST['order']) ? $_REQUEST['order'] : 'DESC';
    ?>
" />

			<!-- Now we can render the completed list table -->
			<?php 
    $testListTable->display();
    ?>
		</form>

	</div>
	<?php 
}
// Google Analytics Views
$wpdb->query("DELETE FROM {$wpdb->prefix}postmeta WHERE meta_key = 'ga_pageviews'");
// Social Metrics
$wpdb->query("DELETE FROM {$wpdb->prefix}postmeta WHERE meta_key = 'socialcount_TOTAL'");
$wpdb->query("DELETE FROM {$wpdb->prefix}postmeta WHERE meta_key = 'socialcount_LAST_UPDATED'");
$wpdb->query("DELETE FROM {$wpdb->prefix}postmeta WHERE meta_key = 'socialcount_alt_data_LAST_UPDATED'");
$wpdb->query("DELETE FROM {$wpdb->prefix}postmeta WHERE meta_key = 'socialcount_facebook'");
$wpdb->query("DELETE FROM {$wpdb->prefix}postmeta WHERE meta_key = 'socialcount_twitter'");
$wpdb->query("DELETE FROM {$wpdb->prefix}postmeta WHERE meta_key = 'socialcount_googleplus'");
$wpdb->query("DELETE FROM {$wpdb->prefix}postmeta WHERE meta_key = 'socialcount_linkedin'");
$wpdb->query("DELETE FROM {$wpdb->prefix}postmeta WHERE meta_key = 'socialcount_pinterest'");
$wpdb->query("DELETE FROM {$wpdb->prefix}postmeta WHERE meta_key = 'socialcount_diggs'");
$wpdb->query("DELETE FROM {$wpdb->prefix}postmeta WHERE meta_key = 'socialcount_delicious'");
$wpdb->query("DELETE FROM {$wpdb->prefix}postmeta WHERE meta_key = 'socialcount_reddit'");
$wpdb->query("DELETE FROM {$wpdb->prefix}postmeta WHERE meta_key = 'socialcount_stumbleupon'");
$wpdb->query("DELETE FROM {$wpdb->prefix}postmeta WHERE meta_key = 'socialcount_xing'");
$wpdb->query("DELETE FROM {$wpdb->prefix}postmeta WHERE meta_key = 'socialcount_flattr'");
$wpdb->query("DELETE FROM {$wpdb->prefix}postmeta WHERE meta_key = 'facebook_shares'");
$wpdb->query("DELETE FROM {$wpdb->prefix}postmeta WHERE meta_key = 'facebook_comments'");
$wpdb->query("DELETE FROM {$wpdb->prefix}postmeta WHERE meta_key = 'facebook_likes'");
// Compound score numbers
$wpdb->query("DELETE FROM {$wpdb->prefix}postmeta WHERE meta_key = 'social_aggregate_score'");
$wpdb->query("DELETE FROM {$wpdb->prefix}postmeta WHERE meta_key = 'social_aggregate_score_detail'");
$wpdb->query("DELETE FROM {$wpdb->prefix}postmeta WHERE meta_key = 'social_aggregate_score_decayed'");
$wpdb->query("DELETE FROM {$wpdb->prefix}postmeta WHERE meta_key = 'social_aggregate_score_decayed_last_updated'");
// Social Metrics alternate source URLs
$wpdb->query("DELETE FROM {$wpdb->prefix}postmeta WHERE meta_key = 'socialcount_url_data'");
// Remove all scheduled cron tasks
include_once 'MetricsUpdater.class.php';
MetricsUpdater::removeAllQueuedUpdates();