public function oauthRequest($params = array()) { $method = $params[0]; $additional_params = isset($params[1]) ? $params[1] : array(); $sha1_method = new OAuthSignatureMethod_HMAC_SHA1(); $consumer = new OAuthConsumer($this->oauth['app_consumer_key'], $this->oauth['app_consumer_secret']); $token = new OAuthConsumer($this->oauth['user_access_token'], $this->oauth['user_access_token_secret']); $request = OAuthRequest::from_consumer_and_token($consumer, $token, 'GET', 'http://api.twitter.com/1/' . $method . '.json', $additional_params); $request->sign_request($sha1_method, $consumer, $token); return FileFetcher::get($request->to_url()); }
/** * [@param Cache_Lite $Cache_Lite] * @return void */ public function buildCache($Cache_Lite = null) { PubwichLog::log(2, sprintf(Pubwich::_('Rebuilding the cache for %s service'), get_class($this))); $url = $this->getURL(); if (!$Cache_Lite) { $Cache_Lite = new Cache_Lite($this->cache_options); $Cache_Lite->get($this->cache_id); } $content = FileFetcher::get($url, $this->http_headers); if ($content !== false) { $cacheWrite = $Cache_Lite->save($content); if (PEAR::isError($cacheWrite)) { /*var_dump( $cacheWrite->getMessage() );*/ } libxml_use_internal_errors(true); $this->data = call_user_func($this->callback_function, $content); } else { $this->data = false; } }
/** * @param SimpleXMLElement $album * [@param bool $rebuildCache] * @return void */ public function fetchAlbum($album, $rebuildCache = false) { $Cache_Lite = new Cache_Lite(parent::getCacheOptions()); $id = $this->buildAlbumId($album); if (!$rebuildCache && ($data = $Cache_Lite->get($id))) { $this->albumdata[$id] = simplexml_load_string($data); } else { $Cache_Lite->get($id); PubwichLog::log(2, Pubwich::_('Rebuilding cache for a Last.fm album')); $url = sprintf("http://ws.audioscrobbler.com/2.0/?method=album.getinfo&api_key=%s&artist=%s&album=%s", $this->key, urlencode($album->artist), urlencode($album->name)); $data = FileFetcher::get($url); $cacheWrite = $Cache_Lite->save($data); if (PEAR::isError($cacheWrite)) { //var_dump( $cacheWrite ); } $this->albumdata[$id] = simplexml_load_string($data); } }
/** * @param SimpleXMLElement $album * [@param bool $rebuildCache] * @return void */ public function fetchPhotoGeoData($photo, $rebuildCache = false) { $Cache_Lite = new Cache_Lite(parent::getCacheOptions()); $id = $photo["id"]; if (!$rebuildCache && ($data = $Cache_Lite->get($id))) { $this->photogeodata["{$id}"] = simplexml_load_string($data); } else { $Cache_Lite->get($id); PubwichLog::log(2, Pubwich::_('Rebuilding geo cache for a Flickr Photo')); $url = sprintf('http://api.flickr.com/services/rest/?method=flickr.photos.geo.getLocation&api_key=%s&photo_id=%s', $this->apikey, $id); $fdata = FileFetcher::get($url); $cacheWrite = $Cache_Lite->save($fdata); if (PEAR::isError($cacheWrite)) { //var_dump( $cacheWrite ); } $pdata = simplexml_load_string($fdata); $this->photogeodata["{$id}"] = $pdata; } }
/** * [@param Cache_Lite $Cache_Lite] * @return void */ public function buildCache($Cache_Lite = null) { PubwichLog::log(2, sprintf(Pubwich::_('Rebuilding the cache for %s service'), get_class($this))); $url = $this->getURL(); if (!$Cache_Lite) { // create cache object $Cache_Lite = new Cache_Lite($this->cache_options); $Cache_Lite->get($this->cache_id); } if (!isset($this->callback_getdata) || !$this->callback_getdata) { $content = FileFetcher::get($url, $this->http_headers); } else { $content = call_user_func($this->callback_getdata[0], $this->callback_getdata[1]); } if ($content !== false) { $cacheWrite = $Cache_Lite->save($content); libxml_use_internal_errors(true); $this->data = $content; if (is_string($this->data)) { $this->data = call_user_func($this->callback_function, $this->data); } } else { $this->data = false; } }