]>
Commit | Line | Data |
---|---|---|
9b725068 AD |
1 | <?php |
2 | class Af_Unburn extends Plugin { | |
9b725068 AD |
3 | private $host; |
4 | ||
5 | function about() { | |
6 | return array(1.0, | |
6368785e | 7 | "Resolves feedburner and similar feed redirector URLs (requires CURL)", |
9b725068 AD |
8 | "fox"); |
9 | } | |
10 | ||
11 | function init($host) { | |
9b725068 AD |
12 | $this->host = $host; |
13 | ||
14 | $host->add_hook($host::HOOK_ARTICLE_FILTER, $this); | |
15 | } | |
16 | ||
17 | function hook_article_filter($article) { | |
18 | $owner_uid = $article["owner_uid"]; | |
19 | ||
20 | if (!function_exists("curl_init")) | |
21 | return $article; | |
22 | ||
eb161344 | 23 | if ((strpos($article["link"], "feedproxy.google.com") !== FALSE || |
a90952ec | 24 | strpos($article["link"], "/~r/") !== FALSE || |
e02555c1 | 25 | strpos($article["link"], "feedsportal.com") !== FALSE)) { |
9b725068 | 26 | |
e02555c1 | 27 | if (strpos($article["plugin_data"], "unburn,$owner_uid:") === FALSE) { |
9b725068 | 28 | |
438a3ecb | 29 | if (ini_get("safe_mode") || ini_get("open_basedir")) { |
81153e6b AD |
30 | $ch = curl_init(geturl($article["link"])); |
31 | } else { | |
32 | $ch = curl_init($article["link"]); | |
33 | } | |
34 | ||
e02555c1 AD |
35 | curl_setopt($ch, CURLOPT_TIMEOUT, 5); |
36 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
37 | curl_setopt($ch, CURLOPT_HEADER, true); | |
438a3ecb | 38 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, !ini_get("safe_mode") && !ini_get("open_basedir")); |
e02555c1 | 39 | curl_setopt($ch, CURLOPT_USERAGENT, SELF_USER_AGENT); |
9b725068 | 40 | |
05f14a7d AD |
41 | if (defined('_CURL_HTTP_PROXY')) { |
42 | curl_setopt($ch, CURLOPT_PROXY, _CURL_HTTP_PROXY); | |
43 | } | |
44 | ||
e02555c1 | 45 | $contents = @curl_exec($ch); |
9b725068 | 46 | |
e02555c1 | 47 | $real_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); |
8c685908 | 48 | |
e02555c1 | 49 | curl_close($ch); |
8c685908 | 50 | |
e02555c1 AD |
51 | if ($real_url) { |
52 | /* remove the rest of it */ | |
8c685908 | 53 | |
e02555c1 | 54 | $query = parse_url($real_url, PHP_URL_QUERY); |
8c685908 | 55 | |
e02555c1 AD |
56 | if ($query && strpos($query, "utm_source") !== FALSE) { |
57 | $args = array(); | |
58 | parse_str($query, $args); | |
59 | ||
60 | foreach (array("utm_source", "utm_medium", "utm_campaign") as $param) { | |
61 | if (isset($args[$param])) unset($args[$param]); | |
62 | } | |
8c685908 | 63 | |
e02555c1 | 64 | $new_query = http_build_query($args); |
8c685908 | 65 | |
e02555c1 AD |
66 | if ($new_query != $query) { |
67 | $real_url = str_replace("?$query", "?$new_query", $real_url); | |
68 | } | |
8c685908 | 69 | } |
8c685908 | 70 | |
e02555c1 | 71 | $real_url = preg_replace("/\?$/", "", $real_url); |
1e6463fd | 72 | |
e02555c1 AD |
73 | $article["plugin_data"] = "unburn,$owner_uid:" . $article["plugin_data"]; |
74 | $article["link"] = $real_url; | |
75 | } | |
76 | } else if (isset($article["stored"]["link"])) { | |
77 | $article["link"] = $article["stored"]["link"]; | |
9b725068 AD |
78 | } |
79 | } | |
80 | ||
81 | return $article; | |
82 | } | |
81153e6b | 83 | |
e2b0054b AD |
84 | function geturl($url){ |
85 | ||
86 | (function_exists('curl_init')) ? '' : die('cURL Must be installed for geturl function to work. Ask your host to enable it or uncomment extension=php_curl.dll in php.ini'); | |
87 | ||
88 | $curl = curl_init(); | |
89 | $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,"; | |
90 | $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"; | |
91 | $header[] = "Cache-Control: max-age=0"; | |
92 | $header[] = "Connection: keep-alive"; | |
93 | $header[] = "Keep-Alive: 300"; | |
94 | $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"; | |
95 | $header[] = "Accept-Language: en-us,en;q=0.5"; | |
96 | $header[] = "Pragma: "; | |
97 | ||
98 | curl_setopt($curl, CURLOPT_URL, $url); | |
99 | curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0 Firefox/5.0'); | |
100 | curl_setopt($curl, CURLOPT_HTTPHEADER, $header); | |
101 | curl_setopt($curl, CURLOPT_HEADER, true); | |
102 | curl_setopt($curl, CURLOPT_REFERER, $url); | |
103 | curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate'); | |
104 | curl_setopt($curl, CURLOPT_AUTOREFERER, true); | |
105 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
106 | //curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); //CURLOPT_FOLLOWLOCATION Disabled... | |
107 | curl_setopt($curl, CURLOPT_TIMEOUT, 60); | |
108 | ||
109 | $html = curl_exec($curl); | |
110 | ||
111 | $status = curl_getinfo($curl); | |
112 | curl_close($curl); | |
113 | ||
114 | if($status['http_code']!=200){ | |
115 | if($status['http_code'] == 301 || $status['http_code'] == 302) { | |
116 | list($header) = explode("\r\n\r\n", $html, 2); | |
117 | $matches = array(); | |
118 | preg_match("/(Location:|URI:)[^(\n)]*/", $header, $matches); | |
119 | $url = trim(str_replace($matches[1],"",$matches[0])); | |
120 | $url_parsed = parse_url($url); | |
6f7798b6 | 121 | return (isset($url_parsed))? geturl($url):''; |
e2b0054b AD |
122 | } |
123 | $oline=''; | |
124 | foreach($status as $key=>$eline){$oline.='['.$key.']'.$eline.' ';} | |
125 | $line =$oline." \r\n ".$url."\r\n-----------------\r\n"; | |
126 | $handle = @fopen('./curl.error.log', 'a'); | |
127 | fwrite($handle, $line); | |
128 | return FALSE; | |
129 | } | |
130 | return $url; | |
131 | } | |
106a3de9 AD |
132 | |
133 | function api_version() { | |
134 | return 2; | |
135 | } | |
136 | ||
9b725068 AD |
137 | } |
138 | ?> |