Suggestion for mass manual import
-
First patch:
--- g-crossposting.php 2014-09-16 17:31:32.000000000 -0700 +++ g-crossposting-patch.php 2014-09-16 17:35:03.000000000 -0700 @@ -143,6 +143,26 @@ } /** + * checks Google+ for all activities and posts them + */ +function g_crossposting_update_all() { + // first check if all settings are in place + if (! g_crossposting_is_enabled()) { + return; + } + + // get all activities + $all_activities = array(); + $all_activities = g_crossposting_get_all_activities(); + if ($all_activities == null) { + return; + } + + // post new activities on blog + g_crossposting_post_new($all_activities); +} + +/** * checks Google+ for new activities and posts them */ function g_crossposting_update() { @@ -173,7 +193,7 @@ // basic validation showed that we might have valid connection settings // now do an actual connect to see if we are able to connect - if (g_crossposting_api_activities_list($options['gplusid'], $options['apikey'], 1) == null) { + if (g_crossposting_api_activities_list($options['gplusid'], $options['apikey'], 1, "") == null) { // either settings are wrong or gplus is offline return FALSE; @@ -214,9 +234,9 @@ * * @return array with activities or null */ -function g_crossposting_api_activities_list($p_gplusid, $p_apikey, $p_maxactivities) { +function g_crossposting_api_activities_list($p_gplusid, $p_apikey, $p_maxactivities, $p_pagetoken) { // get list of latest p_maxactivities activities - $ch = curl_init("https://www.googleapis.com/plus/v1/people/{$p_gplusid}/activities/public?alt=json&maxResults={$p_maxactivities}&key={$p_apikey}"); + $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}"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $activities = curl_exec($ch); curl_close($ch); @@ -232,6 +252,42 @@ } /** + * returns all activities + * + * @return array of all activities found on Google+ + */ + +function g_crossposting_get_all_activities() { + // load options + $options = g_crossposting_get_settings(); + + // go through all activities + $all_activities = array(); + $nextPageToken = null; + do + { + $activities = g_crossposting_api_activities_list($options['gplusid'], + $options['apikey'], $options['maxactivities'], $nextPageToken); + if ($activities == null) { + return null; + } + + $nextPageToken = $activities->nextPageToken; + foreach ($activities->items as $activity) + { + $all_activities[] = $activity; + } + } + while($nextPageToken != null); + + if (count($all_activities) > 0) { + return $all_activities; + } else { + return null; + } +} + +/** * returns new activities not yet posted on blog * * @return array of new activities or null if no new activities were @@ -505,3 +561,4 @@ return FALSE; } +
Second patch:
--- admin.php 2014-09-16 17:31:32.000000000 -0700 +++ admin-patch.php 2014-09-16 17:32:29.000000000 -0700 @@ -20,7 +20,8 @@ // provide admins a hook to trigger manual import of activities if (array_key_exists('g_crossposting_manual_import', $_GET)) { - g_crossposting_update(); + //g_crossposting_update(); + g_crossposting_update_all(); g_crossposting_add_error('g_crossposting_err_import', __('Manual import of Google+ activities done.', 'g-crossposting')); } @@ -295,3 +296,4 @@ echo '</div>'; } +
Viewing 15 replies - 1 through 15 (of 15 total)
Viewing 15 replies - 1 through 15 (of 15 total)
- The topic ‘Suggestion for mass manual import’ is closed to new replies.