]> git.wh0rd.org - tt-rss.git/blob - plugins/af_unburn/init.php
263997dbf330a70c17c3758093a836f6f8efe2db
[tt-rss.git] / plugins / af_unburn / init.php
1 <?php
2 class Af_Unburn extends Plugin {
3 private $host;
4
5 function about() {
6 return array(1.0,
7 "Resolves feedburner and similar feed redirector URLs (requires CURL)",
8 "fox");
9 }
10
11 function init($host) {
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 (defined('NO_CURL') || !function_exists("curl_init") || ini_get("open_basedir"))
21 return $article;
22
23 if ((strpos($article["link"], "feedproxy.google.com") !== FALSE ||
24 strpos($article["link"], "/~r/") !== FALSE ||
25 strpos($article["link"], "feedsportal.com") !== FALSE)) {
26
27 $ch = curl_init($article["link"]);
28
29 curl_setopt($ch, CURLOPT_TIMEOUT, 5);
30 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
31 curl_setopt($ch, CURLOPT_HEADER, true);
32 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
33 curl_setopt($ch, CURLOPT_USERAGENT, SELF_USER_AGENT);
34
35 if (defined('_CURL_HTTP_PROXY')) {
36 curl_setopt($ch, CURLOPT_PROXY, _CURL_HTTP_PROXY);
37 }
38
39 @curl_exec($ch);
40
41 $real_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
42
43 curl_close($ch);
44
45 if ($real_url) {
46 /* remove the rest of it */
47
48 $query = parse_url($real_url, PHP_URL_QUERY);
49
50 if ($query && strpos($query, "utm_source") !== FALSE) {
51 $args = array();
52 parse_str($query, $args);
53
54 foreach (array("utm_source", "utm_medium", "utm_campaign") as $param) {
55 if (isset($args[$param])) unset($args[$param]);
56 }
57
58 $new_query = http_build_query($args);
59
60 if ($new_query != $query) {
61 $real_url = str_replace("?$query", "?$new_query", $real_url);
62 }
63 }
64
65 $real_url = preg_replace("/\?$/", "", $real_url);
66
67 $article["plugin_data"] = "unburn,$owner_uid:" . $article["plugin_data"];
68 $article["link"] = $real_url;
69 }
70 }
71
72 return $article;
73 }
74
75 function api_version() {
76 return 2;
77 }
78
79 }
80 ?>