2 class Af_Unburn extends Plugin {
7 "Resolves feedburner and similar feed redirector URLs (requires CURL)",
11 function init($host) {
14 $host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
17 function hook_article_filter($article) {
18 $owner_uid = $article["owner_uid"];
20 if (!function_exists("curl_init"))
23 if ((strpos($article["link"], "feedproxy.google.com") !== FALSE ||
24 strpos($article["link"], "/~r/") !== FALSE ||
25 strpos($article["link"], "feedsportal.com") !== FALSE)) {
27 if (strpos($article["plugin_data"], "unburn,$owner_uid:") === FALSE) {
29 if (ini_get("safe_mode") || ini_get("open_basedir")) {
30 $ch = curl_init(geturl($article["link"]));
32 $ch = curl_init($article["link"]);
35 curl_setopt($ch, CURLOPT_TIMEOUT, 5);
36 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
37 curl_setopt($ch, CURLOPT_HEADER, true);
38 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, !ini_get("safe_mode") && !ini_get("open_basedir"));
39 curl_setopt($ch, CURLOPT_USERAGENT, SELF_USER_AGENT);
41 $contents = @curl_exec($ch);
43 $real_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
48 /* remove the rest of it */
50 $query = parse_url($real_url, PHP_URL_QUERY);
52 if ($query && strpos($query, "utm_source") !== FALSE) {
54 parse_str($query, $args);
56 foreach (array("utm_source", "utm_medium", "utm_campaign") as $param) {
57 if (isset($args[$param])) unset($args[$param]);
60 $new_query = http_build_query($args);
62 if ($new_query != $query) {
63 $real_url = str_replace("?$query", "?$new_query", $real_url);
67 $real_url = preg_replace("/\?$/", "", $real_url);
69 $article["plugin_data"] = "unburn,$owner_uid:" . $article["plugin_data"];
70 $article["link"] = $real_url;
72 } else if (isset($article["stored"]["link"])) {
73 $article["link"] = $article["stored"]["link"];
80 function geturl($url){
82 (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');
85 $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
86 $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
87 $header[] = "Cache-Control: max-age=0";
88 $header[] = "Connection: keep-alive";
89 $header[] = "Keep-Alive: 300";
90 $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
91 $header[] = "Accept-Language: en-us,en;q=0.5";
92 $header[] = "Pragma: ";
94 curl_setopt($curl, CURLOPT_URL, $url);
95 curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0 Firefox/5.0');
96 curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
97 curl_setopt($curl, CURLOPT_HEADER, true);
98 curl_setopt($curl, CURLOPT_REFERER, $url);
99 curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
100 curl_setopt($curl, CURLOPT_AUTOREFERER, true);
101 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
102 //curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); //CURLOPT_FOLLOWLOCATION Disabled...
103 curl_setopt($curl, CURLOPT_TIMEOUT, 60);
105 $html = curl_exec($curl);
107 $status = curl_getinfo($curl);
110 if($status['http_code']!=200){
111 if($status['http_code'] == 301 || $status['http_code'] == 302) {
112 list($header) = explode("\r\n\r\n", $html, 2);
114 preg_match("/(Location:|URI:)[^(\n)]*/", $header, $matches);
115 $url = trim(str_replace($matches[1],"",$matches[0]));
116 $url_parsed = parse_url($url);
117 return (isset($url_parsed))? geturl($url, $referer):'';
120 foreach($status as $key=>$eline){$oline.='['.$key.']'.$eline.' ';}
121 $line =$oline." \r\n ".$url."\r\n-----------------\r\n";
122 $handle = @fopen('./curl.error.log', 'a');
123 fwrite($handle, $line);
129 function api_version() {