codysnider /
tt-rss
| 1 | <?php |
||||||
| 2 | class Af_Unburn extends Plugin { |
||||||
| 3 | private $host; |
||||||
| 4 | |||||||
| 5 | public function about() { |
||||||
| 6 | return array(1.0, |
||||||
| 7 | "Resolves feedburner and similar feed redirector URLs (requires CURL)", |
||||||
| 8 | "fox"); |
||||||
| 9 | } |
||||||
| 10 | |||||||
| 11 | public function flags() { |
||||||
| 12 | return array("needs_curl" => true); |
||||||
| 13 | } |
||||||
| 14 | |||||||
| 15 | public function init($host) { |
||||||
| 16 | $this->host = $host; |
||||||
| 17 | |||||||
| 18 | $host->add_hook($host::HOOK_ARTICLE_FILTER, $this); |
||||||
| 19 | } |
||||||
| 20 | |||||||
| 21 | public 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 | |||||||
| 28 | if ((strpos($article["link"], "feedproxy.google.com") !== false || |
||||||
| 29 | strpos($article["link"], "/~r/") !== false || |
||||||
| 30 | strpos($article["link"], "feedsportal.com") !== false)) { |
||||||
| 31 | |||||||
| 32 | $ch = curl_init($article["link"]); |
||||||
| 33 | |||||||
| 34 | curl_setopt($ch, CURLOPT_TIMEOUT, 5); |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 35 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
||||||
| 36 | curl_setopt($ch, CURLOPT_HEADER, true); |
||||||
| 37 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
||||||
| 38 | curl_setopt($ch, CURLOPT_NOBODY, true); |
||||||
| 39 | curl_setopt($ch, CURLOPT_USERAGENT, SELF_USER_AGENT); |
||||||
| 40 | |||||||
| 41 | if (defined('_CURL_HTTP_PROXY')) { |
||||||
| 42 | curl_setopt($ch, CURLOPT_PROXY, _CURL_HTTP_PROXY); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 43 | } |
||||||
| 44 | |||||||
| 45 | @curl_exec($ch); |
||||||
|
0 ignored issues
–
show
It seems like you do not handle an error condition for
curl_exec(). This can introduce security issues, and is generally not recommended.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
It seems like
$ch can also be of type false; however, parameter $ch of curl_exec() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 46 | |||||||
| 47 | $real_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); |
||||||
|
0 ignored issues
–
show
It seems like
$ch can also be of type false; however, parameter $ch of curl_getinfo() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 48 | |||||||
| 49 | curl_close($ch); |
||||||
|
0 ignored issues
–
show
It seems like
$ch can also be of type false; however, parameter $ch of curl_close() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 50 | |||||||
| 51 | if ($real_url) { |
||||||
| 52 | /* remove the rest of it */ |
||||||
| 53 | |||||||
| 54 | $query = parse_url($real_url, PHP_URL_QUERY); |
||||||
| 55 | |||||||
| 56 | if ($query && strpos($query, "utm_source") !== false) { |
||||||
| 57 | $args = array(); |
||||||
| 58 | parse_str($query, $args); |
||||||
| 59 | |||||||
| 60 | foreach (array("utm_source", "utm_medium", "utm_campaign") as $param) { |
||||||
| 61 | if (isset($args[$param])) { |
||||||
| 62 | unset($args[$param]); |
||||||
| 63 | } |
||||||
| 64 | } |
||||||
| 65 | |||||||
| 66 | $new_query = http_build_query($args); |
||||||
| 67 | |||||||
| 68 | if ($new_query != $query) { |
||||||
| 69 | $real_url = str_replace("?$query", "?$new_query", $real_url); |
||||||
| 70 | } |
||||||
| 71 | } |
||||||
| 72 | |||||||
| 73 | $real_url = preg_replace("/\?$/", "", $real_url); |
||||||
| 74 | |||||||
| 75 | $article["plugin_data"] = "unburn,$owner_uid:".$article["plugin_data"]; |
||||||
| 76 | $article["link"] = $real_url; |
||||||
| 77 | } |
||||||
| 78 | } |
||||||
| 79 | |||||||
| 80 | return $article; |
||||||
| 81 | } |
||||||
| 82 | |||||||
| 83 | public function api_version() { |
||||||
| 84 | return 2; |
||||||
| 85 | } |
||||||
| 86 | |||||||
| 87 | } |
||||||
| 88 |