Plugin Directory

Changeset 1021652


Ignore:
Timestamp:
11/07/2014 06:40:03 PM (11 years ago)
Author:
bcole808
Message:

Release of v1.3.0

Location:
social-metrics-tracker
Files:
83 added
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • social-metrics-tracker/trunk/MetricsUpdater.class.php

    r1008254 r1021652  
    1010***************************************************/
    1111
     12require_once('data-sources/HTTPResourceUpdater.class.php');
     13require_once('data-sources/FacebookUpdater.class.php');
     14require_once('data-sources/TwitterUpdater.class.php');
     15require_once('data-sources/LinkedInUpdater.class.php');
     16require_once('data-sources/GooglePlusUpdater.class.php');
     17require_once('data-sources/PinterestUpdater.class.php');
     18require_once('data-sources/StumbleUponUpdater.class.php');
     19
    1220class MetricsUpdater {
    1321
     
    2129        $this->options = ($options) ? $options : get_option('smt_settings');
    2230
    23         // Import adapters for 3rd party services
    24         if (class_exists('SharedCountUpdater')) {
    25             $this->SharedCountUpdater = new SharedCountUpdater();
    26         }
    27 
    28         // If analytics are being tracked, pull update
    29         if (class_exists('GoogleAnalyticsUpdater')) {
    30             $this->GoogleAnalyticsUpdater = new GoogleAnalyticsUpdater();
    31         }
    32 
    3331        // Check post on each page load
    3432        add_action( 'wp_head', array($this, 'checkThisPost'));
     
    3836        add_action( 'social_metrics_update_single_post', array( $this, 'updatePostStats' ), 10, 1 );
    3937
     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
    4045    } // 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! &nbsp;<a href=\"".remove_query_arg('smt_sync_done')."\">Dismiss</a> ";
     88        printf( '<div class="updated"> <p> %s </p> </div>', $message);
     89    }
    4190
    4291    /**
     
    103152    public function updatePostStats($post_id) {
    104153
     154        $this->setupDataSources();
     155
    105156        // Data validation
     157        $post_id = intval($post_id);
    106158        if ($post_id <= 0) return false;
    107159
     
    112164        do_action('social_metrics_data_sync', $post_id, $permalink);
    113165
     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
    114186        // Last updated time
    115187        update_post_meta($post_id, "socialcount_LAST_UPDATED", time());
     188
    116189
    117190        // Get comment count from DB
     
    292365    *
    293366    */
    294     public static function scheduleFullDataSync() {
     367    public function scheduleFullDataSync($verbose = false) {
     368
     369        update_option( 'smt_last_full_sync', time() );
    295370
    296371        // We are going to stagger the updates so we do not overload the Wordpress cron.
     
    298373        $interval = 5; // in seconds
    299374
     375        $num = 0;
     376
     377        $post_types = $this->get_post_types();
     378
    300379        // Get posts that have not ever been updated.
    301380        // 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,
    303385            'order'         =>'DESC',
    304386            'orderby'       =>'post_date',
     
    314396        ));
    315397
    316         foreach ($querydata 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 ) );
    318400            $nextTime = $nextTime + $interval;
     401            $num++;
     402
     403            if ($verbose) {
     404                print('<li>Scheduled '.$post->post_type.': '.$post->post_title.'</li>');
     405                flush();
     406            }
    319407        }
    320408
    321409        // 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,
    323414            'order'         =>'DESC',
    324415            'orderby'       =>'post_date',
     
    334425        ));
    335426
    336         foreach ($querydata 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 ) );
    338429            $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;
    342439    } // end scheduleFullDataSync()
    343440
     
    363460    } // end removeAllQueuedUpdates()
    364461
    365     public static function printQueueLength() {
     462    public static function getQueueLength() {
    366463        $queue = array();
    367464        $cron = _get_cron_array();
     
    376473        }
    377474
    378         $count = count($queue);
     475        return count($queue);
     476    }
     477
     478    public static function printQueueLength() {
     479        $count = MetricsUpdater::getQueueLength();
    379480        if ($count >= 1) {
    380481            $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...');
    382483        }
    383484    } // end printQueueLength()
  • social-metrics-tracker/trunk/SocialMetricsSettings.class.php

    r1001451 r1021652  
    2222
    2323                break;
    24            
     24
    2525            default:
    2626                $this->section = 'general';
     
    5959    // Render the Google API config page
    6060    //
    61     // Beware: Messy PHP code within..... 
     61    // Beware: Messy PHP code within.....
    6262    function gapi_section() {
    6363
     
    8080        // Display a different HTML block per each wizard step
    8181        switch ($this->gapi->step) {
    82             /*************************************************/ 
    83             case 1: 
    84             /*************************************************/ 
     82            /*************************************************/
     83            case 1:
     84            /*************************************************/
    8585            ?>
    8686            <form method="POST" action="admin.php?page=social-metrics-tracker-settings&section=gapi">
     
    141141            </form>
    142142
    143             <?php 
    144             /*************************************************/ 
    145             break; case 2: 
    146             /*************************************************/ 
     143            <?php
     144            /*************************************************/
     145            break; case 2:
     146            /*************************************************/
    147147            ?>
    148148
     
    163163            </div>
    164164
    165             <?php 
    166             /*************************************************/ 
    167             break; case 3: 
    168             /*************************************************/ 
     165            <?php
     166            /*************************************************/
     167            break; case 3:
     168            /*************************************************/
    169169            ?>
    170170
     
    190190
    191191                        <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
    193193                        <?php endif; ?>
    194194
     
    202202            </form>
    203203
    204             <?php 
    205             /*************************************************/ 
    206             break; case 4: 
    207             /*************************************************/ 
     204            <?php
     205            /*************************************************/
     206            break; case 4:
     207            /*************************************************/
    208208            ?>
    209209
     
    219219            <p>If you wish to disable data sync, navigate back to any of the previous setup steps and data syncing will stop.</p>
    220220
    221             <?php 
    222             /*************************************************/ 
    223             break; default: 
    224             /*************************************************/ 
     221            <?php
     222            /*************************************************/
     223            break; default:
     224            /*************************************************/
    225225            ?>
    226226            <h2>Something isn't working right...</h2>
    227             <?php 
    228             /*************************************************/ 
    229             break; 
    230             /*************************************************/ 
     227            <?php
     228            /*************************************************/
     229            break;
     230            /*************************************************/
    231231
    232232        } // end switch
  • social-metrics-tracker/trunk/data-sources/google_analytics.php

    r1001451 r1021652  
    4242            $this->update_gapi_data();
    4343
    44         } 
     44        }
    4545
    4646    }
     
    8383        if ($value > 0) {
    8484            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.
    9090    public function set_multisite_mode($bool) {
    9191        if (is_multisite()) {
     
    125125    }
    126126
    127     // Get function 
     127    // Get function
    128128    public function get_gapi_keys() {
    129129        $values['gapi_client_id']       = isset($this->data['gapi_client_id'])     ? $this->data['gapi_client_id']     : null;
     
    139139    }
    140140
    141     // Returns true if can sync, false if not. 
     141    // Returns true if can sync, false if not.
    142142    public function can_sync() {
    143143        return (isset($this->data['gapi_profile_id']) && strlen($this->data['gapi_profile_id']) > 0 && isset($this->data['gapi_token']));
     
    148148        $this->connect();
    149149        $this->gapi->setScopes(array('https://www.googleapis.com/auth/analytics.readonly'));
    150         $this->gapi->setAccessType('offline'); 
     150        $this->gapi->setAccessType('offline');
    151151        $this->gapi->setApprovalPrompt('force');
    152152        return $this->gapi->createAuthUrl();
     
    232232            $this->data['data_is_flowing'] = true;
    233233            $this->update_gapi_data(); // save to DB
    234                    
     234
    235235            return true;
    236236
     
    242242    }
    243243
    244     // Get the number of pageviews for a given URL. 
     244    // Get the number of pageviews for a given URL.
    245245    public function get_pageviews($full_url) {
    246246
     
    268268                'ga:pageviews',
    269269                $options
    270             ); 
     270            );
    271271
    272272            $single_result = $result->getRows();
     
    276276
    277277        } catch (Exception $e) {
    278             // There was an error querying the Google Analytics service. 
     278            // There was an error querying the Google Analytics service.
    279279
    280280            $this->data['data_is_flowing'] = false;
     
    289289    public function go_to_step($num) {
    290290        switch ($num) {
    291             case 1: 
     291            case 1:
    292292                // Remove API Keys
    293293                unset($this->data['gapi_client_id']);
     
    301301
    302302                // Fall through to next case
    303            
     303
    304304            case 3:
    305305                // Remove selected profile
     
    318318
    319319
    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.
    321321    public function get_profile_list() {
    322322        $profiles = array();
     
    328328            $result = $this->analytics->management_webproperties->listManagementWebproperties($account->id);
    329329            $webProperties = $result->items;
    330              
     330
    331331            foreach ($webProperties as $webProperty) {
    332332
     
    334334                $items = $result->items;
    335335                foreach ($items as $item) array_push($profiles, array('id'=> $item->id,'name'=> $item->name, 'parent'=>$account->name));
    336                  
     336
    337337            }
    338338        }
  • social-metrics-tracker/trunk/readme.txt

    r1009290 r1021652  
    55Requires at least: 3.5
    66Tested up to: 4.0
    7 Stable tag: 1.2.5
     7Stable tag: 1.3.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    2020= Get stats from these social networks: =
    2121
    22 Facebook, Twitter, LinkedIn, Digg, Delicious, StumbleUpon, Pinterest, and Google+
     22Facebook, Twitter, LinkedIn, StumbleUpon, Pinterest, and Google+
    2323
    2424= Focus your writing topics: =
     
    4141If 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.
    4242
     43= Un-installation =
     44
     45When 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
    4347
    4448== Frequently Asked Questions ==
     
    4650= Where is social network data gathered from? =
    4751
    48 Share counts and interactions are downloaded from the http://www.sharedcount.com/ API
     52The 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.
    4953
    5054= What social networks are measured? =
    5155
    52 Data is collected from the following social networks: Facebook, Twitter, Reddit, LinkedIn, Digg, Delicious, StumbleUpon, Pinterest, and Google+
     56Data is collected from the following social networks: Facebook, Twitter, LinkedIn, StumbleUpon, Pinterest, and Google+
    5357
    5458= What information is sent from my blog to other services? =
     
    7074= Who created this? =
    7175
    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.
     76This 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.
    7377
    7478
     
    8185== Changelog ==
    8286
     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
    8395= 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.
    8597
    8698= 1.2.4 =
    87 Important bug fix for ranking of posts.
     99* Important bug fix for ranking of posts.
    88100
    89101= 1.2.3 =
     
    115127
    116128= 1.0.1 =
    117 * Added colors and labels to the graph for each of the nine social networks.
     129* Added colors and labels to the graph for each of the social networks.
    118130* Bar graph expands on hover to show detail of the breakdown.
    119131
     
    123135
    124136== Upgrade Notice ==
     137
     138= 1.3 =
     139Major update which changes the way social data is collected
    125140
    126141= 1.2.5 =
     
    167182Here is a listing of all of the available data fields which you can access in that way:
    168183
    169 socialcount_TOTAL, socialcount_facebook, socialcount_twitter, socialcount_googleplus, socialcount_linkedin, socialcount_pinterest, socialcount_diggs, socialcount_delicious, socialcount_reddit, socialcount_stumbleupon, socialcount_LAST_UPDATED
     184socialcount_TOTAL, socialcount_facebook, socialcount_twitter, socialcount_googleplus, socialcount_linkedin, socialcount_pinterest, socialcount_stumbleupon, socialcount_LAST_UPDATED
    170185
    171186**Extending the plugin**
  • social-metrics-tracker/trunk/smt-dashboard.php

    r1001451 r1021652  
    1616        $this->smt = $smt;
    1717
    18         $this->gapi = new GoogleAnalyticsUpdater(); 
     18        $this->gapi = new GoogleAnalyticsUpdater();
    1919
    2020        $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',
    2929            'stumbleupon'=> 'Stumble Upon'
    3030        );
     
    166166     */
    167167    function handle_dashboard_sorting($query) {
    168        
     168
    169169        // get order
    170170        // this should be taken care of by default but something is interfering
    171171        // If no order, default is DESC
    172172        $query->set( 'order', ! empty( $_REQUEST[ 'order' ] ) ? $_REQUEST[ 'order' ] : 'DESC' );
    173        
     173
    174174        // get orderby
    175175        // If no sort, then get default option
    176176        $orderby = ! empty( $_REQUEST[ 'orderby' ] ) ? $_REQUEST[ 'orderby' ] : $this->smt->options[ 'smt_options_default_sort_column' ];
    177                
     177
    178178        // tweak query based on orderby
    179179        switch( $orderby ) {
    180        
     180
    181181            case 'aggregate':
    182            
     182
    183183                $query->set( 'orderby', 'meta_value_num' );
    184184                $query->set( 'meta_key', 'social_aggregate_score' );
    185185                break;
    186                
     186
    187187            case 'comments':
    188            
    189                 $query->set( 'orderby', 'comment_count' );             
     188
     189                $query->set( 'orderby', 'comment_count' );
    190190                break;
    191                
     191
    192192            case 'post_date':
    193            
    194                 $query->set( 'orderby', 'post_date' );         
     193
     194                $query->set( 'orderby', 'post_date' );
    195195                break;
    196                
     196
    197197            case 'social':
    198            
     198
    199199                $query->set( 'orderby', 'meta_value_num' );
    200                 $query->set( 'meta_key', 'socialcount_TOTAL' );             
     200                $query->set( 'meta_key', 'socialcount_TOTAL' );
    201201                break;
    202                
     202
    203203            case 'views':
    204            
     204
    205205                $query->set( 'orderby', 'meta_value_num' );
    206206                $query->set( 'meta_key', 'ga_pageviews' );
    207                
     207
    208208                break;
    209        
     209
    210210        }
    211211
     
    234234        // Filter our query results
    235235        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') );
    237237
    238238        $querydata = new WP_Query(array(
     
    314314                        <option value="0"<?php if ($range == 0) echo 'selected="selected"'; ?>>Items published anytime</option>
    315315                    </select>
    316                    
     316
    317317                    <?php do_action( 'smt_dashboard_query_options' ); // Allows developers to add additional sort options ?>
    318318
    319319                    <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>
    320323
    321324            <?php
     
    338341 */
    339342function smt_render_dashboard_view($smt){
     343
     344    $last_full_sync = get_option( "smt_last_full_sync" );
     345
    340346    ?>
    341347    <div class="wrap">
    342348        <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
    350367
    351368        <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 -->
    353369            <input type="hidden" name="page" value="<?php echo $_REQUEST['page'] ?>" />
    354370            <input type="hidden" name="orderby" value="<?php echo (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : $smt->options['smt_options_default_sort_column']; ?>" />
    355371            <input type="hidden" name="order" value="<?php echo (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'DESC'; ?>" />
    356372
     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
    357383            <?php
    358384            //Create an instance of our package class...
     
    362388            $SocialMetricsTable->prepare_items();
    363389            $SocialMetricsTable->display();
    364 
    365390            ?>
     391
    366392        </form>
    367393
    368394        <?php MetricsUpdater::printQueueLength(); ?>
     395
    369396
    370397    </div>
  • social-metrics-tracker/trunk/social-metrics-tracker.php

    r1009290 r1021652  
    44Plugin URI: https://github.com/ChapmanU/wp-social-metrics-tracker
    55Description: Collect and display social network shares, likes, tweets, and view counts of posts.
    6 Version: 1.2.5
     6Version: 1.3.0
    77Author: Ben Cole, Chapman University
    88Author URI: http://www.bencole.net
     
    2626// Class Dependancies
    2727require_once('MetricsUpdater.class.php');
    28 require_once('data-sources/sharedcount.com.php');
    2928require_once('data-sources/google_analytics.php');
    3029include_once('SocialMetricsSettings.class.php');
     
    3332class SocialMetricsTracker {
    3433
    35     private $version = '1.2.5'; // for db upgrade comparison
     34    public $version = '1.3.0'; // for db upgrade comparison
    3635    public $updater;
    3736    public $options;
     
    4241        register_activation_hook( __FILE__, array($this, 'activate') );
    4342        register_deactivation_hook( __FILE__, array($this, 'deactivate') );
    44         register_uninstall_hook( __FILE__, array('SocialMetricsTracker', 'uninstall') );
    4543
    4644        if (is_admin()) {
     
    7169        }
    7270
    73         // Manual data update for a post
    74         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 
    7971        // Data export tool
    8072        if (is_admin() && isset($_GET['smt_download_export_file']) && $_GET['smt_download_export_file'] && $_GET['page'] == 'social-metrics-tracker-export') {
     
    210202            update_option( "smt_version", $this->version );
    211203
    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            }
    213208
    214209        }
     
    216211
    217212    public function activate() {
     213
    218214        // Add default settings
    219 
    220215        if (get_option('smt_settings') === false) {
    221216
     
    231226        }
    232227
    233 
    234         if ($this->is_development_server()) {
    235             // Do not schedule update
    236         } else {
    237             // Sync all data
    238             MetricsUpdater::scheduleFullDataSync();
    239         }
    240 
    241228        $this->version_check();
    242229
     
    250237    }
    251238
    252     public static function uninstall() {
    253 
    254         // Delete options
    255         delete_option('smt_settings');
    256 
    257     }
    258 
    259239} // END SocialMetricsTracker
    260240
Note: See TracChangeset for help on using the changeset viewer.