]>
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, | |
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 | ||
eb161344 AD |
26 | if ((strpos($article["link"], "feedproxy.google.com") !== FALSE || |
27 | strpos($article["link"], "feedsportal.com") !== FALSE) && | |
9b725068 AD |
28 | strpos($article["guid"], "unburn,$owner_uid:") === FALSE) { |
29 | ||
30 | $ch = curl_init($article["link"]); | |
31 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); | |
32 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
33 | curl_setopt($ch, CURLOPT_HEADER, true); | |
34 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
35 | ||
36 | $contents = @curl_exec($ch); | |
37 | ||
38 | $real_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); | |
39 | ||
8c685908 AD |
40 | curl_close($ch); |
41 | ||
9b725068 | 42 | if ($real_url) { |
8c685908 AD |
43 | /* remove the rest of it */ |
44 | ||
45 | $query = parse_url($real_url, PHP_URL_QUERY); | |
46 | ||
47 | if ($query && strpos($query, "utm_source") !== FALSE) { | |
48 | $args = array(); | |
49 | parse_str($query, $args); | |
50 | ||
51 | foreach (array("utm_source", "utm_medium", "utm_campaign") as $param) { | |
52 | if (isset($args[$param])) unset($args[$param]); | |
53 | } | |
54 | ||
55 | $new_query = http_build_query($args); | |
56 | ||
57 | if ($new_query != $query) { | |
58 | $real_url = str_replace("?$query", "?$new_query", $real_url); | |
59 | } | |
60 | } | |
61 | ||
9b725068 AD |
62 | $article["guid"] = "unburn,$owner_uid:" . $article["guid"]; |
63 | $article["link"] = $real_url; | |
64 | } | |
65 | } | |
66 | ||
67 | return $article; | |
68 | } | |
69 | } | |
70 | ?> |