Plugin Directory

Changeset 996346


Ignore:
Timestamp:
09/24/2014 09:46:54 PM (12 years ago)
Author:
sebstein
Message:
  • get rid of PHP warning during mass import that $activities->nextPageToken is undefined
  • during mass all import, always request 100 items per page
  • remove legacy duplicate check via last_activity_id
  • only include parameters in G+ API call, which are actually set
File:
1 edited

Legend:

Unmodified
Added
Removed
  • g-crossposting/trunk/g-crossposting.php

    r995586 r996346  
    217217function g_crossposting_api_activities_list($p_gplusid, $p_apikey, $p_maxactivities, $p_pagetoken) {
    218218    // get list of latest p_maxactivities activities
    219     $ch = curl_init("https://www.googleapis.com/plus/v1/people/{$p_gplusid}/activities/public?alt=json&maxResults={$p_maxactivities}&key={$p_apikey}&pageToken={$p_pagetoken}");
     219    $query = "https://www.googleapis.com/plus/v1/people/{$p_gplusid}/activities/public?alt=json&key={$p_apikey}";
     220
     221    if (isset($p_maxactivities)) {
     222        $query = $query."&maxResults={$p_maxactivities}";
     223    }
     224
     225    if (isset($p_pagetoken)) {
     226        $query = $query."&pageToken={$p_pagetoken}";
     227    }
     228
     229    $ch = curl_init($query);
    220230    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    221231    $activities = curl_exec($ch);
    222232    curl_close($ch);
     233
    223234    $activities = json_decode($activities);
    224235
     
    241252    // load options
    242253    $options = g_crossposting_get_settings();
    243     $last_activity_id = get_option('g_crossposting_last_activity_id', null);
    244254
    245255    // get activities from Google+
     
    250260    }
    251261
    252     // go through activities to see if we got some not posted yet
    253     // stop as soon as we found the last posted one
    254     $new_activities = array();
    255     foreach ($activities->items as $activity) {
    256         if ($last_activity_id == null || $activity->id != $last_activity_id) {
    257             $new_activities[] = $activity;
    258         } else {
    259             // found an activity already imported
    260             // abort, because the list is sorted by time with newest first
    261             break;
    262         }
    263     }
    264 
    265     if (count($new_activities) > 0) {
    266         return $new_activities;
     262    if (isset($activities->items) && count($activities->items) > 0) {
     263        return $activities->items;
    267264    } else {
    268265        return null;
     
    279276    $posts_updated = 0;
    280277    foreach ($activities as $activity) {
    281         // store ID of latest activity so that we know what was posted already
    282         if ($latest_activity_id == null) {
    283             $latest_activity_id = $activity->id;
    284             update_option('g_crossposting_last_activity_id' , $latest_activity_id);
    285         }
    286 
    287278        // no activity ID or one of being null must be wrong
    288         if (! isset($activity->id) || $activity->id == null) {
     279        if (! isset($activity->id)) {
    289280            continue;
    290281        }
     
    548539    {
    549540        $activities = g_crossposting_api_activities_list($options['gplusid'],
    550                             $options['apikey'], $options['maxactivities'], $nextPageToken);
     541                                                            $options['apikey'], 100, $nextPageToken);
    551542        if ($activities == null) {
    552543            return null;
    553544        }
    554545
    555         $nextPageToken = $activities->nextPageToken;
    556         foreach ($activities->items as $activity)
    557         {
    558             $all_activities[] = $activity;
    559         }
     546        if (isset($activities->nextPageToken)) {
     547            $nextPageToken = $activities->nextPageToken;
     548        } else {
     549            $nextPageToken = null;
     550        }
     551
     552        $all_activities = array_merge($all_activities, $activities->items);
    560553    }
    561554    while($nextPageToken != null);
Note: See TracChangeset for help on using the changeset viewer.