init.php 1.9 KB

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