]>
git.wh0rd.org - tt-rss.git/blob - plugins/af_unburn/init.php
2 class Af_Unburn
extends Plugin
{
7 "Resolves feedburner and similar feed redirector URLs (requires CURL)",
11 function init($host) {
14 $host->add_hook($host::HOOK_ARTICLE_FILTER
, $this);
17 function hook_article_filter($article) {
18 $owner_uid = $article["owner_uid"];
20 if (defined('NO_CURL') ||
!function_exists("curl_init") ||
ini_get("open_basedir"))
23 if ((strpos($article["link"], "feedproxy.google.com") !== FALSE ||
24 strpos($article["link"], "/~r/") !== FALSE ||
25 strpos($article["link"], "feedsportal.com") !== FALSE)) {
27 $ch = curl_init($article["link"]);
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_NOBODY
, true);
34 curl_setopt($ch, CURLOPT_USERAGENT
, SELF_USER_AGENT
);
36 if (defined('_CURL_HTTP_PROXY')) {
37 curl_setopt($ch, CURLOPT_PROXY
, _CURL_HTTP_PROXY
);
42 $real_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL
);
47 /* remove the rest of it */
49 $query = parse_url($real_url, PHP_URL_QUERY
);
51 if ($query && strpos($query, "utm_source") !== FALSE) {
53 parse_str($query, $args);
55 foreach (array("utm_source", "utm_medium", "utm_campaign") as $param) {
56 if (isset($args[$param])) unset($args[$param]);
59 $new_query = http_build_query($args);
61 if ($new_query != $query) {
62 $real_url = str_replace("?$query", "?$new_query", $real_url);
66 $real_url = preg_replace("/\?$/", "", $real_url);
68 $article["plugin_data"] = "unburn,$owner_uid:" . $article["plugin_data"];
69 $article["link"] = $real_url;
76 function api_version() {