diff --git a/code/PackagistShortCode.php b/code/PackagistShortCode.php index def229e..9ec35bc 100644 --- a/code/PackagistShortCode.php +++ b/code/PackagistShortCode.php @@ -1,7 +1,9 @@ Packagist package undefined

'; } @@ -15,9 +17,9 @@ public static function parse($arguments, $content=null, $parser=null) { $obj->Package=$arguments['package']; //Add the button config - if(array_key_exists('mode', $arguments) && ($arguments['mode']=='total' || $arguments['mode']=='monthly' || $arguments['mode']=='daily')) { + if (array_key_exists('mode', $arguments) && ($arguments['mode']=='total' || $arguments['mode']=='monthly' || $arguments['mode']=='daily')) { $obj->DisplayMode=$arguments['mode']; - }else { + } else { $obj->DisplayMode='total'; } @@ -27,18 +29,18 @@ public static function parse($arguments, $content=null, $parser=null) { $cacheKey=md5('packagistshortcode_'.$arguments['package']); $cache=SS_Cache::factory('PackagistShortCode'); $cachedData=$cache->load($cacheKey); - if($cachedData==null) { + if ($cachedData==null) { $response=self::getFromAPI($arguments['package']); //Verify a 200, if not say the repo errored out and cache false - if(empty($response) || $response===false || !property_exists($response, 'package')) { + if (empty($response) || $response===false || !property_exists($response, 'package')) { $cachedData=array('total'=>'N/A', 'monthly'=>'N/A', 'daily'=>'N/A'); - }else { - if($config->UseShortHandNumbers==true) { + } else { + if ($config->UseShortHandNumbers==true) { $totalDownloads=self::shortHandNumber($response->package->downloads->total); $monthlyDownloads=self::shortHandNumber($response->package->downloads->monthly); $dailyDownloads=self::shortHandNumber($response->package->downloads->daily); - }else { + } else { $totalDownloads=number_format($response->package->downloads->total); $monthlyDownloads=number_format($response->package->downloads->monthly); $dailyDownloads=number_format($response->package->downloads->daily); @@ -47,15 +49,15 @@ public static function parse($arguments, $content=null, $parser=null) { $cachedData=array('total'=>$totalDownloads, 'monthly'=>$monthlyDownloads, 'daily'=>$dailyDownloads); } - //Cache response to file system + //Cache response to file system $cache->save(serialize($cachedData), $cacheKey); - }else { + } else { $cachedData=unserialize($cachedData); } - $obj->TotalDownloads=$cachedData['total']; - $obj->MonthlyDownloads=$cachedData['monthly']; + $obj->TotalDownloads=$cachedData['total']; + $obj->MonthlyDownloads=$cachedData['monthly']; $obj->DailyDownloads=$cachedData['daily']; @@ -66,44 +68,45 @@ public static function parse($arguments, $content=null, $parser=null) { return $ssViewer->process($obj); } - /** - * Loads the data from the github api - * @param {string} $url URL to load + /** + * Loads the data from the github api + * @param {string} $url URL to load * @return {stdObject} Returns the JSON Response from the GitHub API * - * @see http://developer.github.com/v3/repos/#get - */ - final protected static function getFromAPI($repo) { - if(function_exists('curl_init') && $ch=curl_init()) { - curl_setopt($ch, CURLOPT_URL, 'https://packagist.org/packages/'.$repo.'.json'); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + * @see http://developer.github.com/v3/repos/#get + */ + final protected static function getFromAPI($repo) + { + if (function_exists('curl_init') && $ch=curl_init()) { + curl_setopt($ch, CURLOPT_URL, 'https://packagist.org/packages/'.$repo.'.json'); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - $contents=json_decode(curl_exec($ch)); + $contents=json_decode(curl_exec($ch)); curl_close($ch); - return $contents; - }else { - user_error('CURL is not available', E_USER_ERROR); - } + return $contents; + } else { + user_error('CURL is not available', E_USER_ERROR); + } } - /** + /** * Gets the short hand of the given number so 1000 becomes 1k, 2000 becomes 2k, and 1000000 becomes 1m etc - * @param {int} $number Number to convert - * @return {string} Short hand of the given number + * @param {int} $number Number to convert + * @return {string} Short hand of the given number */ - protected static function shortHandNumber($number) { - if($number>=1000000000) { - return round($number/1000000000, 1).'B'; - }else if($number>=1000000) { - return round($number/1000000, 1).'M'; - }else if($number>=1000) { - return round($number/1000, 1).'K'; - } - - return $number; - } + protected static function shortHandNumber($number) + { + if ($number>=1000000000) { + return round($number/1000000000, 1).'B'; + } elseif ($number>=1000000) { + return round($number/1000000, 1).'M'; + } elseif ($number>=1000) { + return round($number/1000, 1).'K'; + } + + return $number; + } } -?> \ No newline at end of file