]> git.wh0rd.org - tt-rss.git/blame - plugins/af_unburn/init.php
digest: fix counter vertical offset
[tt-rss.git] / plugins / af_unburn / init.php
CommitLineData
9b725068
AD
1<?php
2class Af_Unburn extends Plugin {
3
4 private $link;
5 private $host;
6
7 function about() {
8 return array(1.0,
9 "Resolve feedburner URLs (requires CURL)",
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
26 if (strpos($article["link"], "feedproxy.google.com") !== FALSE &&
27 strpos($article["guid"], "unburn,$owner_uid:") === FALSE) {
28
29 $ch = curl_init($article["link"]);
30 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
31 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
32 curl_setopt($ch, CURLOPT_HEADER, true);
33 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
34
35 $contents = @curl_exec($ch);
36
37 $real_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
38
8c685908
AD
39 curl_close($ch);
40
9b725068 41 if ($real_url) {
8c685908
AD
42 /* remove the rest of it */
43
44 $query = parse_url($real_url, PHP_URL_QUERY);
45
46 if ($query && strpos($query, "utm_source") !== FALSE) {
47 $args = array();
48 parse_str($query, $args);
49
50 foreach (array("utm_source", "utm_medium", "utm_campaign") as $param) {
51 if (isset($args[$param])) unset($args[$param]);
52 }
53
54 $new_query = http_build_query($args);
55
56 if ($new_query != $query) {
57 $real_url = str_replace("?$query", "?$new_query", $real_url);
58 }
59 }
60
9b725068
AD
61 $article["guid"] = "unburn,$owner_uid:" . $article["guid"];
62 $article["link"] = $real_url;
63 }
64 }
65
66 return $article;
67 }
68}
69?>