* @version 0.0.1 * @copyright Copyright (c) 2009, tknzk.com All rights reserved. * @license BSD License * */ class HatenaBookmarkCount { const DEBUG = false; const HATENA_API_URL = 'http://api.b.st-hatena.com'; const VERSION = '0.0.1'; /** * Delay Time Micro seconds * * @var int */ private $delay; /** * Default constructor * * @return void * @param int $delay * */ public function __construct($delay = null) { if($delay !== null) { $this->setDelay($delay); } } /** * Get Hatena Bookmark Count * * @access public * @param string $urls * @return array * @static */ public function entrycount($urls) { if(is_array($urls)) { $i = 0; foreach($urls as $url) { $apiurl = self::HATENA_API_URL . '/entry.count?' . 'url=' . urlencode($url) . ''; //$response = file_get_contents($apiurl); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $apiurl); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($curl); curl_close($curl); $json = json_decode($response,true); if($json) { $ret[$i]['url'] = $url; $ret[$i]['count'] = $json; } if($i > 1) { if($this->delay !== null) { usleep($this->delay); } } $i++; } return $ret; }else{ $ret = array(); $apiurl = self::HATENA_API_URL . '/entry.count?' . 'url=' . urlencode($urls) . ''; //$response = file_get_contents($apiurl); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $apiurl); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($curl); curl_close($curl); $json = json_decode($response,true); if($json) { $ret = array(); $ret['url'] = $urls; $ret['count'] = $json; } return $ret; } } /** * Set Delay micro seconds * * @return void * @pram string */ public function setDelay($delay) { $this->delay = (string) $delay; } }