Changeset 1021652
- Timestamp:
- 11/07/2014 06:40:03 PM (11 years ago)
- Location:
- social-metrics-tracker
- Files:
-
- 83 added
- 1 deleted
- 6 edited
-
tags/1.3.0 (added)
-
tags/1.3.0/MetricsUpdater.class.php (added)
-
tags/1.3.0/SocialMetricsSettings.class.php (added)
-
tags/1.3.0/SocialMetricsTrackerWidget.class.php (added)
-
tags/1.3.0/css (added)
-
tags/1.3.0/css/social_metrics.css (added)
-
tags/1.3.0/data-sources (added)
-
tags/1.3.0/data-sources/FacebookUpdater.class.php (added)
-
tags/1.3.0/data-sources/GooglePlusUpdater.class.php (added)
-
tags/1.3.0/data-sources/HTTPResourceUpdater.class.php (added)
-
tags/1.3.0/data-sources/LinkedInUpdater.class.php (added)
-
tags/1.3.0/data-sources/PinterestUpdater.class.php (added)
-
tags/1.3.0/data-sources/StumbleUponUpdater.class.php (added)
-
tags/1.3.0/data-sources/TwitterUpdater.class.php (added)
-
tags/1.3.0/data-sources/WordPressCircuitBreaker.class.php (added)
-
tags/1.3.0/data-sources/google_analytics.php (added)
-
tags/1.3.0/lib (added)
-
tags/1.3.0/lib/Google (added)
-
tags/1.3.0/lib/Google/Auth (added)
-
tags/1.3.0/lib/Google/Auth/Abstract.php (added)
-
tags/1.3.0/lib/Google/Auth/AssertionCredentials.php (added)
-
tags/1.3.0/lib/Google/Auth/Exception.php (added)
-
tags/1.3.0/lib/Google/Auth/LoginTicket.php (added)
-
tags/1.3.0/lib/Google/Auth/OAuth2.php (added)
-
tags/1.3.0/lib/Google/Auth/Simple.php (added)
-
tags/1.3.0/lib/Google/Cache (added)
-
tags/1.3.0/lib/Google/Cache/Abstract.php (added)
-
tags/1.3.0/lib/Google/Cache/Apc.php (added)
-
tags/1.3.0/lib/Google/Cache/Exception.php (added)
-
tags/1.3.0/lib/Google/Cache/File.php (added)
-
tags/1.3.0/lib/Google/Cache/Memcache.php (added)
-
tags/1.3.0/lib/Google/Cache/Null.php (added)
-
tags/1.3.0/lib/Google/Client.php (added)
-
tags/1.3.0/lib/Google/Collection.php (added)
-
tags/1.3.0/lib/Google/Config.php (added)
-
tags/1.3.0/lib/Google/Exception.php (added)
-
tags/1.3.0/lib/Google/Http (added)
-
tags/1.3.0/lib/Google/Http/Batch.php (added)
-
tags/1.3.0/lib/Google/Http/CacheParser.php (added)
-
tags/1.3.0/lib/Google/Http/MediaFileUpload.php (added)
-
tags/1.3.0/lib/Google/Http/REST.php (added)
-
tags/1.3.0/lib/Google/Http/Request.php (added)
-
tags/1.3.0/lib/Google/IO (added)
-
tags/1.3.0/lib/Google/IO/Abstract.php (added)
-
tags/1.3.0/lib/Google/IO/Curl.php (added)
-
tags/1.3.0/lib/Google/IO/Exception.php (added)
-
tags/1.3.0/lib/Google/IO/Stream.php (added)
-
tags/1.3.0/lib/Google/IO/cacerts.pem (added)
-
tags/1.3.0/lib/Google/Model.php (added)
-
tags/1.3.0/lib/Google/Service (added)
-
tags/1.3.0/lib/Google/Service.php (added)
-
tags/1.3.0/lib/Google/Service/Analytics.php (added)
-
tags/1.3.0/lib/Google/Service/Exception.php (added)
-
tags/1.3.0/lib/Google/Service/Resource.php (added)
-
tags/1.3.0/lib/Google/Signer (added)
-
tags/1.3.0/lib/Google/Signer/Abstract.php (added)
-
tags/1.3.0/lib/Google/Signer/P12.php (added)
-
tags/1.3.0/lib/Google/Utils (added)
-
tags/1.3.0/lib/Google/Utils.php (added)
-
tags/1.3.0/lib/Google/Utils/URITemplate.php (added)
-
tags/1.3.0/lib/Google/Verifier (added)
-
tags/1.3.0/lib/Google/Verifier/Abstract.php (added)
-
tags/1.3.0/lib/Google/Verifier/Pem.php (added)
-
tags/1.3.0/lib/class-wp-list-table.php (added)
-
tags/1.3.0/lib/wp-settings-framework.php (added)
-
tags/1.3.0/readme.txt (added)
-
tags/1.3.0/settings (added)
-
tags/1.3.0/settings/smt-gapi.php (added)
-
tags/1.3.0/settings/smt-general.php (added)
-
tags/1.3.0/smt-dashboard-debug.php (added)
-
tags/1.3.0/smt-dashboard.php (added)
-
tags/1.3.0/smt-export.php (added)
-
tags/1.3.0/social-metrics-tracker.php (added)
-
tags/1.3.0/uninstall.php (added)
-
trunk/MetricsUpdater.class.php (modified) (11 diffs)
-
trunk/SocialMetricsSettings.class.php (modified) (8 diffs)
-
trunk/data-sources/FacebookUpdater.class.php (added)
-
trunk/data-sources/GooglePlusUpdater.class.php (added)
-
trunk/data-sources/HTTPResourceUpdater.class.php (added)
-
trunk/data-sources/LinkedInUpdater.class.php (added)
-
trunk/data-sources/PinterestUpdater.class.php (added)
-
trunk/data-sources/StumbleUponUpdater.class.php (added)
-
trunk/data-sources/TwitterUpdater.class.php (added)
-
trunk/data-sources/WordPressCircuitBreaker.class.php (added)
-
trunk/data-sources/google_analytics.php (modified) (14 diffs)
-
trunk/data-sources/sharedcount.com.php (deleted)
-
trunk/readme.txt (modified) (9 diffs)
-
trunk/smt-dashboard.php (modified) (6 diffs)
-
trunk/social-metrics-tracker.php (modified) (9 diffs)
-
trunk/uninstall.php (added)
Legend:
- Unmodified
- Added
- Removed
-
social-metrics-tracker/trunk/MetricsUpdater.class.php
r1008254 r1021652 10 10 ***************************************************/ 11 11 12 require_once('data-sources/HTTPResourceUpdater.class.php'); 13 require_once('data-sources/FacebookUpdater.class.php'); 14 require_once('data-sources/TwitterUpdater.class.php'); 15 require_once('data-sources/LinkedInUpdater.class.php'); 16 require_once('data-sources/GooglePlusUpdater.class.php'); 17 require_once('data-sources/PinterestUpdater.class.php'); 18 require_once('data-sources/StumbleUponUpdater.class.php'); 19 12 20 class MetricsUpdater { 13 21 … … 21 29 $this->options = ($options) ? $options : get_option('smt_settings'); 22 30 23 // Import adapters for 3rd party services24 if (class_exists('SharedCountUpdater')) {25 $this->SharedCountUpdater = new SharedCountUpdater();26 }27 28 // If analytics are being tracked, pull update29 if (class_exists('GoogleAnalyticsUpdater')) {30 $this->GoogleAnalyticsUpdater = new GoogleAnalyticsUpdater();31 }32 33 31 // Check post on each page load 34 32 add_action( 'wp_head', array($this, 'checkThisPost')); … … 38 36 add_action( 'social_metrics_update_single_post', array( $this, 'updatePostStats' ), 10, 1 ); 39 37 38 // Manual data update for a post 39 if (is_admin() && isset($_REQUEST['smt_sync_now']) && $_REQUEST['smt_sync_now']) { 40 add_action ( 'wp_loaded', array($this, 'manualUpdate') ); 41 } else if (is_admin() && isset($_REQUEST['smt_sync_done']) && $_REQUEST['smt_sync_done']) { 42 add_action ( 'admin_notices', array($this, 'manualUpdateNotice') ); 43 } 44 40 45 } // end constructor 46 47 public function setupDataSources() { 48 if (isset($this->dataSourcesReady) && $this->dataSourcesReady) return; 49 50 if (class_exists('GoogleAnalyticsUpdater')) { 51 if (!$this->GoogleAnalyticsUpdater) $this->GoogleAnalyticsUpdater = new GoogleAnalyticsUpdater(); 52 } 53 54 // Import adapters for 3rd party services 55 if (!isset($this->FacebookUpdater)) $this->FacebookUpdater = new FacebookUpdater(); 56 if (!isset($this->TwitterUpdater)) $this->TwitterUpdater = new TwitterUpdater(); 57 if (!isset($this->LinkedInUpdater)) $this->LinkedInUpdater = new LinkedInUpdater(); 58 if (!isset($this->GooglePlusUpdater)) $this->GooglePlusUpdater = new GooglePlusUpdater(); 59 if (!isset($this->PinterestUpdater)) $this->PinterestUpdater = new PinterestUpdater(); 60 if (!isset($this->StumbleUponUpdater)) $this->StumbleUponUpdater = new StumbleUponUpdater(); 61 62 return $this->dataSourcesReady = true; 63 } 64 65 // Manual data update for a post 66 public function manualUpdate() { 67 68 $post_id = intval( $_REQUEST['smt_sync_now'] ); 69 if (!$post_id) return false; 70 71 if (get_post_meta($post_id, 'socialcount_LAST_UPDATED', true) > time()-300) { 72 $message = "You must wait at least 5 minutes before performing another update on this post. "; 73 printf( '<div class="error"> <p> %s </p> </div>', $message); 74 } else { 75 $this->updatePostStats($_REQUEST['smt_sync_now']); 76 header("Location: ".add_query_arg(array('smt_sync_done' => $post_id), remove_query_arg('smt_sync_now'))); 77 } 78 79 } 80 81 // Display a notice that we updated a post 82 public function manualUpdateNotice() { 83 $post_id = intval( $_REQUEST['smt_sync_done'] ); 84 if (!$post_id) return false; 85 86 $title = get_the_title($post_id); 87 $message = "<b>$title</b> was updated successfully! <a href=\"".remove_query_arg('smt_sync_done')."\">Dismiss</a> "; 88 printf( '<div class="updated"> <p> %s </p> </div>', $message); 89 } 41 90 42 91 /** … … 103 152 public function updatePostStats($post_id) { 104 153 154 $this->setupDataSources(); 155 105 156 // Data validation 157 $post_id = intval($post_id); 106 158 if ($post_id <= 0) return false; 107 159 … … 112 164 do_action('social_metrics_data_sync', $post_id, $permalink); 113 165 166 // Social Network data 167 $this->FacebookUpdater->sync($post_id, $permalink); 168 $this->TwitterUpdater->sync($post_id, $permalink); 169 $this->LinkedInUpdater->sync($post_id, $permalink); 170 $this->GooglePlusUpdater->sync($post_id, $permalink); 171 $this->PinterestUpdater->sync($post_id, $permalink); 172 $this->StumbleUponUpdater->sync($post_id, $permalink); 173 174 // Calculate new socialcount_TOTAL 175 $all = array ( 176 $this->FacebookUpdater->get_total(), 177 $this->TwitterUpdater->get_total(), 178 $this->LinkedInUpdater->get_total(), 179 $this->GooglePlusUpdater->get_total(), 180 $this->PinterestUpdater->get_total(), 181 $this->StumbleUponUpdater->get_total() 182 ); 183 184 update_post_meta($post_id, 'socialcount_TOTAL', array_sum($all)); 185 114 186 // Last updated time 115 187 update_post_meta($post_id, "socialcount_LAST_UPDATED", time()); 188 116 189 117 190 // Get comment count from DB … … 292 365 * 293 366 */ 294 public static function scheduleFullDataSync() { 367 public function scheduleFullDataSync($verbose = false) { 368 369 update_option( 'smt_last_full_sync', time() ); 295 370 296 371 // We are going to stagger the updates so we do not overload the Wordpress cron. … … 298 373 $interval = 5; // in seconds 299 374 375 $num = 0; 376 377 $post_types = $this->get_post_types(); 378 300 379 // Get posts that have not ever been updated. 301 380 // In case the function does not finish, we want to start with posts that have NO data yet. 302 $querydata = query_posts(array( 381 $q = new WP_Query(); 382 383 $q->query(array( 384 'post_type' => $post_types, 303 385 'order' =>'DESC', 304 386 'orderby' =>'post_date', … … 314 396 )); 315 397 316 foreach ($q uerydata as $querydatum) {317 wp_schedule_single_event( $nextTime, 'social_metrics_update_single_post', array( $ querydatum->ID ) );398 foreach ($q->posts as $post ) { 399 wp_schedule_single_event( $nextTime, 'social_metrics_update_single_post', array( $post->ID ) ); 318 400 $nextTime = $nextTime + $interval; 401 $num++; 402 403 if ($verbose) { 404 print('<li>Scheduled '.$post->post_type.': '.$post->post_title.'</li>'); 405 flush(); 406 } 319 407 } 320 408 321 409 // Get posts which HAVE been updated 322 $querydata = query_posts(array( 410 $q = new WP_Query(); 411 412 $q->query(array( 413 'post_type' => $post_types, 323 414 'order' =>'DESC', 324 415 'orderby' =>'post_date', … … 334 425 )); 335 426 336 foreach ($q uerydata as $querydatum) {337 wp_schedule_single_event( $nextTime, 'social_metrics_update_single_post', array( $ querydatum->ID ) );427 foreach ($q->posts as $post ) { 428 wp_schedule_single_event( $nextTime, 'social_metrics_update_single_post', array( $post->ID ) ); 338 429 $nextTime = $nextTime + ($interval * 2); 339 } 340 341 return true; 430 $num++; 431 432 if ($verbose) { 433 print('<li>Scheduled '.$post->post_type.': '.$post->post_title.'</li>'); 434 flush(); 435 } 436 } 437 438 return $num; 342 439 } // end scheduleFullDataSync() 343 440 … … 363 460 } // end removeAllQueuedUpdates() 364 461 365 public static function printQueueLength() {462 public static function getQueueLength() { 366 463 $queue = array(); 367 464 $cron = _get_cron_array(); … … 376 473 } 377 474 378 $count = count($queue); 475 return count($queue); 476 } 477 478 public static function printQueueLength() { 479 $count = MetricsUpdater::getQueueLength(); 379 480 if ($count >= 1) { 380 481 $label = ($count >=2) ? ' items' : ' item'; 381 printf( '<div class="updated"> <p> %s </p> </div>', ' Currently updating <b>'.$count . $label.'</b> with the most recent social and analytics data...');482 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...'); 382 483 } 383 484 } // end printQueueLength() -
social-metrics-tracker/trunk/SocialMetricsSettings.class.php
r1001451 r1021652 22 22 23 23 break; 24 24 25 25 default: 26 26 $this->section = 'general'; … … 59 59 // Render the Google API config page 60 60 // 61 // Beware: Messy PHP code within..... 61 // Beware: Messy PHP code within..... 62 62 function gapi_section() { 63 63 … … 80 80 // Display a different HTML block per each wizard step 81 81 switch ($this->gapi->step) { 82 /*************************************************/ 83 case 1: 84 /*************************************************/ 82 /*************************************************/ 83 case 1: 84 /*************************************************/ 85 85 ?> 86 86 <form method="POST" action="admin.php?page=social-metrics-tracker-settings§ion=gapi"> … … 141 141 </form> 142 142 143 <?php 144 /*************************************************/ 145 break; case 2: 146 /*************************************************/ 143 <?php 144 /*************************************************/ 145 break; case 2: 146 /*************************************************/ 147 147 ?> 148 148 … … 163 163 </div> 164 164 165 <?php 166 /*************************************************/ 167 break; case 3: 168 /*************************************************/ 165 <?php 166 /*************************************************/ 167 break; case 3: 168 /*************************************************/ 169 169 ?> 170 170 … … 190 190 191 191 <p class="description">With <b>shared credentials</b>, all blogs on this WP Multisite network will automatically use the Google Analytics profile you set up to sync data and you will only need to complete this setup wizard once. With <b>different credentials</b>, each blog will need to complete this wizard but each blog will be able to link to a seperate Gooogle Analytics account.</p> 192 192 193 193 <?php endif; ?> 194 194 … … 202 202 </form> 203 203 204 <?php 205 /*************************************************/ 206 break; case 4: 207 /*************************************************/ 204 <?php 205 /*************************************************/ 206 break; case 4: 207 /*************************************************/ 208 208 ?> 209 209 … … 219 219 <p>If you wish to disable data sync, navigate back to any of the previous setup steps and data syncing will stop.</p> 220 220 221 <?php 222 /*************************************************/ 223 break; default: 224 /*************************************************/ 221 <?php 222 /*************************************************/ 223 break; default: 224 /*************************************************/ 225 225 ?> 226 226 <h2>Something isn't working right...</h2> 227 <?php 228 /*************************************************/ 229 break; 230 /*************************************************/ 227 <?php 228 /*************************************************/ 229 break; 230 /*************************************************/ 231 231 232 232 } // end switch -
social-metrics-tracker/trunk/data-sources/google_analytics.php
r1001451 r1021652 42 42 $this->update_gapi_data(); 43 43 44 } 44 } 45 45 46 46 } … … 83 83 if ($value > 0) { 84 84 update_post_meta($post_id, 'ga_pageviews', $value); 85 } 86 87 } 88 89 // Turns multisite mode on or off. ***Changing this disrupts all saved data. 85 } 86 87 } 88 89 // Turns multisite mode on or off. ***Changing this disrupts all saved data. 90 90 public function set_multisite_mode($bool) { 91 91 if (is_multisite()) { … … 125 125 } 126 126 127 // Get function 127 // Get function 128 128 public function get_gapi_keys() { 129 129 $values['gapi_client_id'] = isset($this->data['gapi_client_id']) ? $this->data['gapi_client_id'] : null; … … 139 139 } 140 140 141 // Returns true if can sync, false if not. 141 // Returns true if can sync, false if not. 142 142 public function can_sync() { 143 143 return (isset($this->data['gapi_profile_id']) && strlen($this->data['gapi_profile_id']) > 0 && isset($this->data['gapi_token'])); … … 148 148 $this->connect(); 149 149 $this->gapi->setScopes(array('https://www.googleapis.com/auth/analytics.readonly')); 150 $this->gapi->setAccessType('offline'); 150 $this->gapi->setAccessType('offline'); 151 151 $this->gapi->setApprovalPrompt('force'); 152 152 return $this->gapi->createAuthUrl(); … … 232 232 $this->data['data_is_flowing'] = true; 233 233 $this->update_gapi_data(); // save to DB 234 234 235 235 return true; 236 236 … … 242 242 } 243 243 244 // Get the number of pageviews for a given URL. 244 // Get the number of pageviews for a given URL. 245 245 public function get_pageviews($full_url) { 246 246 … … 268 268 'ga:pageviews', 269 269 $options 270 ); 270 ); 271 271 272 272 $single_result = $result->getRows(); … … 276 276 277 277 } catch (Exception $e) { 278 // There was an error querying the Google Analytics service. 278 // There was an error querying the Google Analytics service. 279 279 280 280 $this->data['data_is_flowing'] = false; … … 289 289 public function go_to_step($num) { 290 290 switch ($num) { 291 case 1: 291 case 1: 292 292 // Remove API Keys 293 293 unset($this->data['gapi_client_id']); … … 301 301 302 302 // Fall through to next case 303 303 304 304 case 3: 305 305 // Remove selected profile … … 318 318 319 319 320 // Return an array with all of the profile IDs associated with the current Analytics account. 320 // Return an array with all of the profile IDs associated with the current Analytics account. 321 321 public function get_profile_list() { 322 322 $profiles = array(); … … 328 328 $result = $this->analytics->management_webproperties->listManagementWebproperties($account->id); 329 329 $webProperties = $result->items; 330 330 331 331 foreach ($webProperties as $webProperty) { 332 332 … … 334 334 $items = $result->items; 335 335 foreach ($items as $item) array_push($profiles, array('id'=> $item->id,'name'=> $item->name, 'parent'=>$account->name)); 336 336 337 337 } 338 338 } -
social-metrics-tracker/trunk/readme.txt
r1009290 r1021652 5 5 Requires at least: 3.5 6 6 Tested up to: 4.0 7 Stable tag: 1. 2.57 Stable tag: 1.3.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 20 20 = Get stats from these social networks: = 21 21 22 Facebook, Twitter, LinkedIn, Digg, Delicious,StumbleUpon, Pinterest, and Google+22 Facebook, Twitter, LinkedIn, StumbleUpon, Pinterest, and Google+ 23 23 24 24 = Focus your writing topics: = … … 41 41 If you do not see any statistics on the Social Metrics dashboard, make sure that you have some posts published and that wp-cron.php is working correctly. This plugin relies on the WordPress Cron system to fetch data updates. This plugin will not work on local or development servers where URLs are not publicly accessible. 42 42 43 = Un-installation = 44 45 When you un-install this plugin through the WordPress dashboard, it will remove all traces of any social data collected by the plugin. If you wish to keep the data, manually delete the plugin files instead of using the WordPress dashboard; this will bypass the uninstall.php script which deletes the data. 46 43 47 44 48 == Frequently Asked Questions == … … 46 50 = Where is social network data gathered from? = 47 51 48 Share counts and interactions are downloaded from the http://www.sharedcount.com/ API 52 The information is retrieved directly from the public APIs that each social network provides. This plugin will make requests to these APIs periodically in order to display the latest possible data. 49 53 50 54 = What social networks are measured? = 51 55 52 Data is collected from the following social networks: Facebook, Twitter, Reddit, LinkedIn, Digg, Delicious, StumbleUpon, Pinterest, and Google+56 Data is collected from the following social networks: Facebook, Twitter, LinkedIn, StumbleUpon, Pinterest, and Google+ 53 57 54 58 = What information is sent from my blog to other services? = … … 70 74 = Who created this? = 71 75 72 This plugin was created by the Chapman University web marketing team. Our use for the plugin is to track posts on social networks to see which stories students, alumni, and faculty are most interested in sharing.76 This plugin was created by Ben Cole, as a member of the Chapman University web marketing team. Our use for the plugin is to track posts on social networks to see which stories students, alumni, and faculty are most interested in sharing. 73 77 74 78 … … 81 85 == Changelog == 82 86 87 = 1.3.0 = 88 * Data is now synced directly from social network APIs instead of relying on the sharedcount.com API 89 * Removed Digg.com, and Delicious.com because they no longer provide data. 90 * Removed Reddit.com because it was not previously working, but will re-add in a future version. 91 * Added uninstall.php to delete all traces of this plugin if un-installed through WordPress. 92 * Fixed plugin activation error on blogs with a large number of posts. 93 * IMPORANT: As of January 1, 2015, versions of this plugin below 1.3 will no longer work. You MUST upgrade to version 1.3 or higher before this date. 94 83 95 = 1.2.5 = 84 Fixed a bug where social scores were not being updated.96 * Fixed a bug where social scores were not being updated. 85 97 86 98 = 1.2.4 = 87 Important bug fix for ranking of posts.99 * Important bug fix for ranking of posts. 88 100 89 101 = 1.2.3 = … … 115 127 116 128 = 1.0.1 = 117 * Added colors and labels to the graph for each of the ninesocial networks.129 * Added colors and labels to the graph for each of the social networks. 118 130 * Bar graph expands on hover to show detail of the breakdown. 119 131 … … 123 135 124 136 == Upgrade Notice == 137 138 = 1.3 = 139 Major update which changes the way social data is collected 125 140 126 141 = 1.2.5 = … … 167 182 Here is a listing of all of the available data fields which you can access in that way: 168 183 169 socialcount_TOTAL, socialcount_facebook, socialcount_twitter, socialcount_googleplus, socialcount_linkedin, socialcount_pinterest, socialcount_ diggs, socialcount_delicious, socialcount_reddit, socialcount_stumbleupon, socialcount_LAST_UPDATED184 socialcount_TOTAL, socialcount_facebook, socialcount_twitter, socialcount_googleplus, socialcount_linkedin, socialcount_pinterest, socialcount_stumbleupon, socialcount_LAST_UPDATED 170 185 171 186 **Extending the plugin** -
social-metrics-tracker/trunk/smt-dashboard.php
r1001451 r1021652 16 16 $this->smt = $smt; 17 17 18 $this->gapi = new GoogleAnalyticsUpdater(); 18 $this->gapi = new GoogleAnalyticsUpdater(); 19 19 20 20 $this->services = array( 21 'facebook' => 'Facebook', 22 'twitter' => 'Twitter', 23 'googleplus' => 'Google Plus', 24 'linkedin' => 'LinkedIn', 25 'pinterest' => 'Pinterest', 26 'diggs' => 'Digg.com', 27 'delicious' => 'Delicious', 28 'reddit' => 'Reddit', 21 'facebook' => 'Facebook', 22 'twitter' => 'Twitter', 23 'googleplus' => 'Google Plus', 24 'linkedin' => 'LinkedIn', 25 'pinterest' => 'Pinterest', 26 'diggs' => 'Digg.com', 27 'delicious' => 'Delicious', 28 'reddit' => 'Reddit', 29 29 'stumbleupon'=> 'Stumble Upon' 30 30 ); … … 166 166 */ 167 167 function handle_dashboard_sorting($query) { 168 168 169 169 // get order 170 170 // this should be taken care of by default but something is interfering 171 171 // If no order, default is DESC 172 172 $query->set( 'order', ! empty( $_REQUEST[ 'order' ] ) ? $_REQUEST[ 'order' ] : 'DESC' ); 173 173 174 174 // get orderby 175 175 // If no sort, then get default option 176 176 $orderby = ! empty( $_REQUEST[ 'orderby' ] ) ? $_REQUEST[ 'orderby' ] : $this->smt->options[ 'smt_options_default_sort_column' ]; 177 177 178 178 // tweak query based on orderby 179 179 switch( $orderby ) { 180 180 181 181 case 'aggregate': 182 182 183 183 $query->set( 'orderby', 'meta_value_num' ); 184 184 $query->set( 'meta_key', 'social_aggregate_score' ); 185 185 break; 186 186 187 187 case 'comments': 188 189 $query->set( 'orderby', 'comment_count' ); 188 189 $query->set( 'orderby', 'comment_count' ); 190 190 break; 191 191 192 192 case 'post_date': 193 194 $query->set( 'orderby', 'post_date' ); 193 194 $query->set( 'orderby', 'post_date' ); 195 195 break; 196 196 197 197 case 'social': 198 198 199 199 $query->set( 'orderby', 'meta_value_num' ); 200 $query->set( 'meta_key', 'socialcount_TOTAL' ); 200 $query->set( 'meta_key', 'socialcount_TOTAL' ); 201 201 break; 202 202 203 203 case 'views': 204 204 205 205 $query->set( 'orderby', 'meta_value_num' ); 206 206 $query->set( 'meta_key', 'ga_pageviews' ); 207 207 208 208 break; 209 209 210 210 } 211 211 … … 234 234 // Filter our query results 235 235 add_filter( 'posts_where', array($this, 'date_range_filter') ); 236 add_filter( 'pre_get_posts', array($this, 'handle_dashboard_sorting') ); 236 add_filter( 'pre_get_posts', array($this, 'handle_dashboard_sorting') ); 237 237 238 238 $querydata = new WP_Query(array( … … 314 314 <option value="0"<?php if ($range == 0) echo 'selected="selected"'; ?>>Items published anytime</option> 315 315 </select> 316 316 317 317 <?php do_action( 'smt_dashboard_query_options' ); // Allows developers to add additional sort options ?> 318 318 319 319 <input type="submit" name="filter" id="submit_filter" class="button" value="Filter"> 320 321 322 <a href="<?php echo add_query_arg(array('smt_full_sync' => 1)); ?>" class="button" onClick="return confirm('Are you sure? This will schedule ALL your posts to be updated and may take a long time if you have a lot of posts.')">Schedule full sync</a> 320 323 321 324 <?php … … 338 341 */ 339 342 function smt_render_dashboard_view($smt){ 343 344 $last_full_sync = get_option( "smt_last_full_sync" ); 345 340 346 ?> 341 347 <div class="wrap"> 342 348 <h2>Social Metrics Tracker</h2> 343 <?php 344 if(!is_array($smt->options)) { 345 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>." ); 346 die(); 347 } 348 349 ?> 349 350 351 <?php if (isset($_REQUEST['smt_full_sync'])) : ?> 352 353 <h3>Now scheduling a full data update...</h3> 354 <p>This process must check all posts in your database and may take a short while...</p> 355 <p>If you have custom post types that you would like to track or exclude please go to the configuration page!</p> 356 <?php flush(); ?> 357 <?php $metricsUpdater = new MetricsUpdater(); ?> 358 <?php $num = $metricsUpdater->scheduleFullDataSync(true); ?> 359 <p>... all done! </p> 360 <?php flush(); ?> 361 <p><b><?php echo $num; ?> items</b> were scheduled to be udpated.</p> 362 <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> 363 <p><a href="<?php echo remove_query_arg('smt_full_sync'); ?>">Return to Social Metrics dashboard</a></p> 364 365 <?php return; endif; ?> 366 350 367 351 368 <form id="social-metrics-tracker" method="get" action="admin.php?page=social-metrics-tracker"> 352 <!-- For plugins, we also need to ensure that the form posts back to our current page -->353 369 <input type="hidden" name="page" value="<?php echo $_REQUEST['page'] ?>" /> 354 370 <input type="hidden" name="orderby" value="<?php echo (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : $smt->options['smt_options_default_sort_column']; ?>" /> 355 371 <input type="hidden" name="order" value="<?php echo (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'DESC'; ?>" /> 356 372 373 <?php if (!$last_full_sync) : ?> 374 <div class="update-nag" style="margin-bottom:30px;"> 375 <h3> Setup Instructions </h3> 376 <p>You need to perform a one time full-sync. </p> 377 <p>We will schedule it now, and it will run in the background.</p> 378 <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> 379 <p><a href="<?php echo add_query_arg(array('smt_full_sync' => 1)); ?>" class="button">Schedule full sync</a></p> 380 </div> 381 <?php endif; ?> 382 357 383 <?php 358 384 //Create an instance of our package class... … … 362 388 $SocialMetricsTable->prepare_items(); 363 389 $SocialMetricsTable->display(); 364 365 390 ?> 391 366 392 </form> 367 393 368 394 <?php MetricsUpdater::printQueueLength(); ?> 395 369 396 370 397 </div> -
social-metrics-tracker/trunk/social-metrics-tracker.php
r1009290 r1021652 4 4 Plugin URI: https://github.com/ChapmanU/wp-social-metrics-tracker 5 5 Description: Collect and display social network shares, likes, tweets, and view counts of posts. 6 Version: 1. 2.56 Version: 1.3.0 7 7 Author: Ben Cole, Chapman University 8 8 Author URI: http://www.bencole.net … … 26 26 // Class Dependancies 27 27 require_once('MetricsUpdater.class.php'); 28 require_once('data-sources/sharedcount.com.php');29 28 require_once('data-sources/google_analytics.php'); 30 29 include_once('SocialMetricsSettings.class.php'); … … 33 32 class SocialMetricsTracker { 34 33 35 p rivate $version = '1.2.5'; // for db upgrade comparison34 public $version = '1.3.0'; // for db upgrade comparison 36 35 public $updater; 37 36 public $options; … … 42 41 register_activation_hook( __FILE__, array($this, 'activate') ); 43 42 register_deactivation_hook( __FILE__, array($this, 'deactivate') ); 44 register_uninstall_hook( __FILE__, array('SocialMetricsTracker', 'uninstall') );45 43 46 44 if (is_admin()) { … … 71 69 } 72 70 73 // Manual data update for a post74 if (is_admin() && $this->updater && isset($_REQUEST['smt_sync_now']) && $_REQUEST['smt_sync_now']) {75 $this->updater->updatePostStats($_REQUEST['smt_sync_now']);76 header("Location: ".remove_query_arg('smt_sync_now'));77 }78 79 71 // Data export tool 80 72 if (is_admin() && isset($_GET['smt_download_export_file']) && $_GET['smt_download_export_file'] && $_GET['page'] == 'social-metrics-tracker-export') { … … 210 202 update_option( "smt_version", $this->version ); 211 203 212 // Do upgrade tasks 204 // IF migrating from version below 1.3 205 if ($installed_version !== false && version_compare($installed_version, '1.3', '<')) { 206 update_option( 'smt_last_full_sync', 1 ); 207 } 213 208 214 209 } … … 216 211 217 212 public function activate() { 213 218 214 // Add default settings 219 220 215 if (get_option('smt_settings') === false) { 221 216 … … 231 226 } 232 227 233 234 if ($this->is_development_server()) {235 // Do not schedule update236 } else {237 // Sync all data238 MetricsUpdater::scheduleFullDataSync();239 }240 241 228 $this->version_check(); 242 229 … … 250 237 } 251 238 252 public static function uninstall() {253 254 // Delete options255 delete_option('smt_settings');256 257 }258 259 239 } // END SocialMetricsTracker 260 240
Note: See TracChangeset
for help on using the changeset viewer.