You are here

public function LikeBtn::syncVotes in Like Button 7

Same name and namespace in other branches
  1. 8.2 likebtn.php \LikeBtn::syncVotes()

Comment sync function.

1 call to LikeBtn::syncVotes()
LikeBtn::runSyncVotes in ./likebtn.php
Running votes synchronization.

File

./likebtn.php, line 92
LikeBtn like button.

Class

LikeBtn

Code

public function syncVotes($email = '', $api_key = '', $site_id = '') {
  $sync_result = TRUE;
  $last_sync_time = number_format(variable_get('likebtn_last_sync_time', 0), 0, '', '');
  $updated_after = '';
  if (variable_get('likebtn_last_successfull_sync_time', 0)) {
    $updated_after = variable_get('likebtn_last_successfull_sync_time') - LIKEBTN_LAST_SUCCESSFULL_SYNC_TIME_OFFSET;
  }
  $url = "output=json&last_sync_time=" . $last_sync_time;
  if ($updated_after) {
    $url .= '&updated_after=' . $updated_after;
  }

  // Retrieve first page.
  $response = $this
    ->apiRequest('stat', $url, $email, $api_key, $site_id);
  if (!$this
    ->updateVotes($response)) {
    $sync_result = FALSE;
  }

  // Retrieve all pages.
  if (isset($response['response']['total']) && isset($response['response']['page_size'])) {
    $total_pages = ceil((int) $response['response']['total'] / (int) $response['response']['page_size']);
    for ($page = 2; $page <= $total_pages; $page++) {
      $response = $this
        ->apiRequest('stat', $url . '&page=' . $page, $email, $api_key, $site_id);
      if (!$this
        ->updateVotes($response)) {
        $sync_result = FALSE;
      }
    }
  }
  if ($sync_result) {
    variable_set('likebtn_last_successfull_sync_time', $last_sync_time);
  }
}