]> git.wh0rd.org - tt-rss.git/blame - plugins/af_unburn/init.php
Fetch only the headers in order to get the real article URL.
[tt-rss.git] / plugins / af_unburn / init.php
CommitLineData
9b725068
AD
1<?php
2class 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
aa03bac4 20 if (defined('NO_CURL') || !function_exists("curl_init") || ini_get("open_basedir"))
9b725068
AD
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
4c467026 27 $ch = curl_init($article["link"]);
81153e6b 28
e02555c1
AD
29 curl_setopt($ch, CURLOPT_TIMEOUT, 5);
30 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
31 curl_setopt($ch, CURLOPT_HEADER, true);
4c467026 32 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
fb59c879 33 curl_setopt($ch, CURLOPT_NOBODY, true);
e02555c1 34 curl_setopt($ch, CURLOPT_USERAGENT, SELF_USER_AGENT);
9b725068 35
05f14a7d
AD
36 if (defined('_CURL_HTTP_PROXY')) {
37 curl_setopt($ch, CURLOPT_PROXY, _CURL_HTTP_PROXY);
38 }
39
129d6263 40 @curl_exec($ch);
9b725068 41
e02555c1 42 $real_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
8c685908 43
e02555c1 44 curl_close($ch);
8c685908 45
e02555c1
AD
46 if ($real_url) {
47 /* remove the rest of it */
8c685908 48
e02555c1 49 $query = parse_url($real_url, PHP_URL_QUERY);
8c685908 50
e02555c1
AD
51 if ($query && strpos($query, "utm_source") !== FALSE) {
52 $args = array();
53 parse_str($query, $args);
54
55 foreach (array("utm_source", "utm_medium", "utm_campaign") as $param) {
56 if (isset($args[$param])) unset($args[$param]);
57 }
8c685908 58
e02555c1 59 $new_query = http_build_query($args);
8c685908 60
e02555c1
AD
61 if ($new_query != $query) {
62 $real_url = str_replace("?$query", "?$new_query", $real_url);
63 }
8c685908 64 }
8c685908 65
e02555c1 66 $real_url = preg_replace("/\?$/", "", $real_url);
1e6463fd 67
e02555c1
AD
68 $article["plugin_data"] = "unburn,$owner_uid:" . $article["plugin_data"];
69 $article["link"] = $real_url;
70 }
9b725068
AD
71 }
72
73 return $article;
74 }
81153e6b 75
106a3de9
AD
76 function api_version() {
77 return 2;
78 }
79
9b725068
AD
80}
81?>