diff --git a/include/twitteroauth.php b/include/twitteroauth.php index ee1214b..57e0dae 100644 --- a/include/twitteroauth.php +++ b/include/twitteroauth.php @@ -219,6 +219,8 @@ function http($url, $method, $postfields = NULL) { if (!empty($postfields)) { $url = "{$url}?{$postfields}"; } + case 'GET': + curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-PHX: true')); } curl_setopt($ci, CURLOPT_URL, $url); diff --git a/twip.php b/twip.php index 175e08f..fe75092 100644 --- a/twip.php +++ b/twip.php @@ -49,6 +49,36 @@ public function json_x86_encode($in){ return preg_replace('/id":"(\d+)"/', 'id":\1', $in); } + public function status2rss($status){ + if(is_string($status)){ + $statuses = $this->json_x86_decode($status); + } + $title = ($this->screen_name) ? ($this->screen_name.' in Twitter') : 'RSS for Twitter'; + $link = ($this->screen_name) ? ('https://twitter.com/' . $this->screen_name) : $this->request_uri; + $now = date("D, d M Y H:i:s T"); + $output = " + + + <![CDATA[".$title."]]> + + request_uri."]]> + $now + $now + "; + foreach ($statuses as $line){ + $output .= "<![CDATA[".$line->user->screen_name.": ".$line->text."]]> + user->screen_name."/statuses/".$line->id_str."]]> + user->screen_name."/statuses/".$line->id_str."]]> + ".date("r", strtotime($line->created_at))." + text)."]]> + user->screen_name."]]> + source."]]> + "; + } + $output .= "\n"; + return $output; + } + public function parse_entities($status, $type){ if($type == 'json'){ $j = is_string($status) ? $this->json_x86_decode($status) : $status; @@ -69,7 +99,11 @@ public function parse_entities($status, $type){ $this->replace_tco_json($j->status->retweeted_status); } } - return is_string($status) ? $this->json_x86_encode($j) : $j; + if($this->rss){ + $status = $this->status2rss($status); + } else { + return is_string($status) ? $this->json_x86_encode($j) : $j; + } } return $status; } @@ -174,6 +208,12 @@ private function override_mode($imageproxy = FALSE){ return; } $this->parameters = $this->get_parameters(); + if(preg_match('/^[^?]+\.rss/', $this->request_uri)){ + $this->rss = true; + $this->request_uri = preg_replace('/(^[^?]+)\.rss/', '\1.json', $this->request_uri); + } else { + $this->rss = false; + } $this->uri_fixer(); $this->connection = new TwitterOAuth($this->oauth_key, $this->oauth_secret, $this->access_token['oauth_token'], $this->access_token['oauth_token_secret']); @@ -196,6 +236,15 @@ private function override_mode($imageproxy = FALSE){ $this->request_uri = str_replace("api.twitter.com", "upload.twitter.com", $this->request_uri); } + $this->screen_name = ''; + $parsed = parse_url($this->request_uri); + if (array_key_exists('query', $parsed)) { + parse_str($parsed['query'], $params); + if (array_key_exists('screen_name', $params)) { + $this->screen_name = $params['screen_name']; + } + } + switch($this->method){ case 'POST': echo $this->parse_entities($this->connection->post($this->request_uri,$this->parameters), $type); @@ -266,11 +315,14 @@ private function uri_fixer(){ 'pc=true' => 'pc=false', //change pc=true to pc=false '&earned=true' => '', //remove "&earned=true" '/1.1/mentions.json' => '/1.1/mentions_timeline.json', //backward compat for API 1.0 + '/1.1/statuses/mentions.json' => '/1.1/statuses/mentions_timeline.json', //backward compat for API 1.0 'i/search.json' => 'search.json', //fix search issue on twitter for iPhone ); $api = str_replace(array_keys($replacement), array_values($replacement), $api); + $api = preg_replace('/user_timeline\/(.*)\.json/', 'user_timeline.json?screen_name=\1&count=200', $api); + if((strpos($api,'search.') === 0)){ $this->request_uri = sprintf("%s%s", $this->parent_search_api, $api);