You are here

public function SharrreCounterController::getCounter in Share Message 8

Get the counter for Google Plus and Stumbleupon.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The current HTTP request from which we get the counter.

Return value

\Symfony\Component\HttpFoundation\JsonResponse A JSON response containing the counter.

1 string reference to 'SharrreCounterController::getCounter'
sharemessage.routing.yml in ./sharemessage.routing.yml
sharemessage.routing.yml

File

src/Controller/SharrreCounterController.php, line 31

Class

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

Namespace

Drupal\sharemessage\Controller

Code

public function getCounter(Request $request) {

  // Sharrre by Julien Hany.
  $json = [
    'url' => $request
      ->get('url'),
    'count' => 0,
  ];
  $url = urlencode($json['url']);
  $type = $request
    ->get('type');
  if (filter_var($json['url'], FILTER_VALIDATE_URL)) {
    if ($type == 'googlePlus') {
      $json['count'] = $this
        ->getCounterGooglePlus($url);
    }
    elseif ($type == 'stumbleupon') {
      $json['count'] = $this
        ->getCounterStumbleupon($url);
    }
  }
  return new JsonResponse($json);
}