init.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. class Af_Unburn extends Plugin {
  3. private $link;
  4. private $host;
  5. function about() {
  6. return array(1.0,
  7. "Resolves feedburner and similar feed redirector URLs (requires CURL)",
  8. "fox");
  9. }
  10. function init($host) {
  11. $this->link = $host->get_link();
  12. $this->host = $host;
  13. $host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
  14. }
  15. function hook_article_filter($article) {
  16. $owner_uid = $article["owner_uid"];
  17. if (!function_exists("curl_init"))
  18. return $article;
  19. if ((strpos($article["link"], "feedproxy.google.com") !== FALSE ||
  20. strpos($article["link"], "/~r/") !== FALSE ||
  21. strpos($article["link"], "feedsportal.com") !== FALSE)) {
  22. if (strpos($article["plugin_data"], "unburn,$owner_uid:") === FALSE) {
  23. if (ini_get("safe_mode")) {
  24. $ch = curl_init(geturl($article["link"]));
  25. } else {
  26. $ch = curl_init($article["link"]);
  27. }
  28. curl_setopt($ch, CURLOPT_TIMEOUT, 5);
  29. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  30. curl_setopt($ch, CURLOPT_HEADER, true);
  31. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, !ini_get("safe_mode"));
  32. curl_setopt($ch, CURLOPT_USERAGENT, SELF_USER_AGENT);
  33. $contents = @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. } else if (isset($article["stored"]["link"])) {
  55. $article["link"] = $article["stored"]["link"];
  56. }
  57. }
  58. return $article;
  59. }
  60. function geturl($url){
  61. (function_exists('curl_init')) ? '' : die('cURL Must be installed for geturl function to work. Ask your host to enable it or uncomment extension=php_curl.dll in php.ini');
  62. $curl = curl_init();
  63. $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
  64. $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
  65. $header[] = "Cache-Control: max-age=0";
  66. $header[] = "Connection: keep-alive";
  67. $header[] = "Keep-Alive: 300";
  68. $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
  69. $header[] = "Accept-Language: en-us,en;q=0.5";
  70. $header[] = "Pragma: ";
  71. curl_setopt($curl, CURLOPT_URL, $url);
  72. curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0 Firefox/5.0');
  73. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  74. curl_setopt($curl, CURLOPT_HEADER, true);
  75. curl_setopt($curl, CURLOPT_REFERER, $url);
  76. curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
  77. curl_setopt($curl, CURLOPT_AUTOREFERER, true);
  78. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  79. //curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); //CURLOPT_FOLLOWLOCATION Disabled...
  80. curl_setopt($curl, CURLOPT_TIMEOUT, 60);
  81. $html = curl_exec($curl);
  82. $status = curl_getinfo($curl);
  83. curl_close($curl);
  84. if($status['http_code']!=200){
  85. if($status['http_code'] == 301 || $status['http_code'] == 302) {
  86. list($header) = explode("\r\n\r\n", $html, 2);
  87. $matches = array();
  88. preg_match("/(Location:|URI:)[^(\n)]*/", $header, $matches);
  89. $url = trim(str_replace($matches[1],"",$matches[0]));
  90. $url_parsed = parse_url($url);
  91. return (isset($url_parsed))? geturl($url, $referer):'';
  92. }
  93. $oline='';
  94. foreach($status as $key=>$eline){$oline.='['.$key.']'.$eline.' ';}
  95. $line =$oline." \r\n ".$url."\r\n-----------------\r\n";
  96. $handle = @fopen('./curl.error.log', 'a');
  97. fwrite($handle, $line);
  98. return FALSE;
  99. }
  100. return $url;
  101. }
  102. }
  103. ?>