]>
Commit | Line | Data |
---|---|---|
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 flags() { | |
12 | return array("needs_curl" => true); | |
13 | } | |
14 | ||
15 | function init($host) { | |
16 | $this->host = $host; | |
17 | ||
18 | $host->add_hook($host::HOOK_ARTICLE_FILTER, $this); | |
19 | } | |
20 | ||
21 | function hook_article_filter($article) { | |
22 | $owner_uid = $article["owner_uid"]; | |
23 | ||
24 | if (defined('NO_CURL') || !function_exists("curl_init") || ini_get("open_basedir")) | |
25 | return $article; | |
26 | ||
27 | if ((strpos($article["link"], "feedproxy.google.com") !== FALSE || | |
28 | strpos($article["link"], "/~r/") !== FALSE || | |
29 | strpos($article["link"], "feedsportal.com") !== FALSE)) { | |
30 | ||
31 | $ch = curl_init($article["link"]); | |
32 | ||
33 | curl_setopt($ch, CURLOPT_TIMEOUT, 5); | |
34 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
35 | curl_setopt($ch, CURLOPT_HEADER, true); | |
36 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
37 | curl_setopt($ch, CURLOPT_NOBODY, true); | |
38 | curl_setopt($ch, CURLOPT_USERAGENT, SELF_USER_AGENT); | |
39 | ||
40 | if (defined('_CURL_HTTP_PROXY')) { | |
41 | curl_setopt($ch, CURLOPT_PROXY, _CURL_HTTP_PROXY); | |
42 | } | |
43 | ||
44 | @curl_exec($ch); | |
45 | ||
46 | $real_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); | |
47 | ||
48 | curl_close($ch); | |
49 | ||
50 | if ($real_url) { | |
51 | /* remove the rest of it */ | |
52 | ||
53 | $query = parse_url($real_url, PHP_URL_QUERY); | |
54 | ||
55 | if ($query && strpos($query, "utm_source") !== FALSE) { | |
56 | $args = array(); | |
57 | parse_str($query, $args); | |
58 | ||
59 | foreach (array("utm_source", "utm_medium", "utm_campaign") as $param) { | |
60 | if (isset($args[$param])) unset($args[$param]); | |
61 | } | |
62 | ||
63 | $new_query = http_build_query($args); | |
64 | ||
65 | if ($new_query != $query) { | |
66 | $real_url = str_replace("?$query", "?$new_query", $real_url); | |
67 | } | |
68 | } | |
69 | ||
70 | $real_url = preg_replace("/\?$/", "", $real_url); | |
71 | ||
72 | $article["plugin_data"] = "unburn,$owner_uid:" . $article["plugin_data"]; | |
73 | $article["link"] = $real_url; | |
74 | } | |
75 | } | |
76 | ||
77 | return $article; | |
78 | } | |
79 | ||
80 | function api_version() { | |
81 | return 2; | |
82 | } | |
83 | ||
84 | } |