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