]>
git.wh0rd.org - tt-rss.git/blob - plugins/af_unburn/init.php
2 class Af_Unburn
extends Plugin
{
9 "Resolves feedburner and similar feed redirector URLs (requires CURL)",
13 function init($host) {
14 $this->link
= $host->get_link();
17 $host->add_hook($host::HOOK_ARTICLE_FILTER
, $this);
20 function hook_article_filter($article) {
21 $owner_uid = $article["owner_uid"];
23 if (!function_exists("curl_init"))
26 if ((strpos($article["link"], "feedproxy.google.com") !== FALSE ||
27 strpos($article["link"], "/~r/") !== FALSE ||
28 strpos($article["link"], "feedsportal.com") !== FALSE) &&
29 strpos($article["plugin_data"], "unburn,$owner_uid:") === FALSE) {
31 $ch = curl_init($article["link"]);
32 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT
, 5);
33 curl_setopt($ch, CURLOPT_RETURNTRANSFER
, true);
34 curl_setopt($ch, CURLOPT_HEADER
, true);
35 curl_setopt($ch, CURLOPT_FOLLOWLOCATION
, true);
37 $contents = @curl_exec
($ch);
39 $real_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL
);
44 /* remove the rest of it */
46 $query = parse_url($real_url, PHP_URL_QUERY
);
48 if ($query && strpos($query, "utm_source") !== FALSE) {
50 parse_str($query, $args);
52 foreach (array("utm_source", "utm_medium", "utm_campaign") as $param) {
53 if (isset($args[$param])) unset($args[$param]);
56 $new_query = http_build_query($args);
58 if ($new_query != $query) {
59 $real_url = str_replace("?$query", "?$new_query", $real_url);
63 $real_url = preg_replace("/\?$/", "", $real_url);
65 $article["plugin_data"] = "unburn,$owner_uid:" . $article["plugin_data"];
66 $article["link"] = $real_url;