init.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. class Af_Unburn extends Plugin {
  3. private $host;
  4. function about() {
  5. return array(1.0,
  6. "Resolves feedburner and similar feed redirector URLs (requires CURL)",
  7. "fox");
  8. }
  9. function flags() {
  10. return array("needs_curl" => true);
  11. }
  12. function init($host) {
  13. $this->host = $host;
  14. $host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
  15. }
  16. function hook_article_filter($article) {
  17. $owner_uid = $article["owner_uid"];
  18. if (defined('NO_CURL') || !function_exists("curl_init") || ini_get("open_basedir"))
  19. return $article;
  20. if ((strpos($article["link"], "feedproxy.google.com") !== FALSE ||
  21. strpos($article["link"], "/~r/") !== FALSE ||
  22. strpos($article["link"], "feedsportal.com") !== FALSE)) {
  23. $ch = curl_init($article["link"]);
  24. curl_setopt($ch, CURLOPT_TIMEOUT, 5);
  25. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  26. curl_setopt($ch, CURLOPT_HEADER, true);
  27. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  28. curl_setopt($ch, CURLOPT_NOBODY, true);
  29. curl_setopt($ch, CURLOPT_USERAGENT, SELF_USER_AGENT);
  30. if (defined('_CURL_HTTP_PROXY')) {
  31. curl_setopt($ch, CURLOPT_PROXY, _CURL_HTTP_PROXY);
  32. }
  33. @curl_exec($ch);
  34. $real_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
  35. curl_close($ch);
  36. if ($real_url) {
  37. /* remove the rest of it */
  38. $query = parse_url($real_url, PHP_URL_QUERY);
  39. if ($query && strpos($query, "utm_source") !== FALSE) {
  40. $args = array();
  41. parse_str($query, $args);
  42. foreach (array("utm_source", "utm_medium", "utm_campaign") as $param) {
  43. if (isset($args[$param])) unset($args[$param]);
  44. }
  45. $new_query = http_build_query($args);
  46. if ($new_query != $query) {
  47. $real_url = str_replace("?$query", "?$new_query", $real_url);
  48. }
  49. }
  50. $real_url = preg_replace("/\?$/", "", $real_url);
  51. $article["plugin_data"] = "unburn,$owner_uid:" . $article["plugin_data"];
  52. $article["link"] = $real_url;
  53. }
  54. }
  55. return $article;
  56. }
  57. function api_version() {
  58. return 2;
  59. }
  60. }