From f458f9dabbb7e41cd5e2e5de173d344f0d5870af Mon Sep 17 00:00:00 2001 From: Kodie Grantham Date: Tue, 25 Jul 2017 11:30:20 -0500 Subject: [PATCH] Added url_params config option --- config.php | 7 +++++++ share_count.php | 25 ++++++++++++++----------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/config.php b/config.php index e800551..c4f991b 100644 --- a/config.php +++ b/config.php @@ -17,4 +17,11 @@ class Config { public $format = 'json'; // 'json', 'jsonp' or 'xml' public $callback = 'processShares'; // default jsonp callback function name + /* added URL parameters for services */ + public $url_params = array( + 'facebook' => array( + 'app_access_token' => '' + ) + ); + } diff --git a/share_count.php b/share_count.php index 8f42039..fb45cfa 100644 --- a/share_count.php +++ b/share_count.php @@ -108,18 +108,21 @@ public function getShares($url = '', $services = '') { ); if ($services) { - if (!is_array($services)) { - $services = explode(',', $services); - } - - foreach($services as $service) { - $provider = $shareLinks[$service]; - @$this->getCount($service, $provider[0] . $this->url, $provider[1]); - } + if (!is_array($services)) { $services = explode(',', $services); } } else { - foreach($shareLinks as $service=>$provider) { - @$this->getCount($service, $provider[0] . $this->url, $provider[1]); - } + $services = array_keys($shareLinks); + } + + foreach($services as $service) { + $provider = $shareLinks[$service]; + $url_params = ''; + + if (array_key_exists($service, $this->config->url_params)) { + $url_params = '&' . http_build_query($this->config->url_params[$service]); + } + + $url = $provider[0] . $this->url . $url_params; + @$this->getCount($service, $url, $provider[1]); } switch($this->format) {