You are here

protected function SharrreCounterController::getCounterGooglePlus in Share Message 8

Get the counter for Google Plus.

Source http://www.helmutgranda.com/2011/11/01/get-a-url-google-count-via-php/

Parameters

string $url: Requested URL.

Return value

int Returns the counter for Google Plus.

1 call to SharrreCounterController::getCounterGooglePlus()
SharrreCounterController::getCounter in src/Controller/SharrreCounterController.php
Get the counter for Google Plus and Stumbleupon.

File

src/Controller/SharrreCounterController.php, line 59

Class

SharrreCounterController
Route controller class for the Sharrre - Google Plus and Stumbleupon counter.

Namespace

Drupal\sharemessage\Controller

Code

protected function getCounterGooglePlus($url) {
  $contents = $this
    ->parse('https://plusone.google.com/u/0/_/+1/fastbutton?url=' . $url . '&count=true');
  preg_match('/window\\.__SSR = {c: ([\\d]+)/', $contents, $matches);

  // If the counter is set, remove the extra strings around it and save it in
  // the JSON array.
  if (isset($matches[0])) {
    return (int) str_replace('window.__SSR = {c: ', '', $matches[0]);
  }
}