init.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 (!function_exists("curl_init"))
  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. if (strpos($article["plugin_data"], "unburn,$owner_uid:") === FALSE) {
  21. if (ini_get("safe_mode") || ini_get("open_basedir")) {
  22. $ch = curl_init(geturl($article["link"]));
  23. } else {
  24. $ch = curl_init($article["link"]);
  25. }
  26. curl_setopt($ch, CURLOPT_TIMEOUT, 5);
  27. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  28. curl_setopt($ch, CURLOPT_HEADER, true);
  29. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, !ini_get("safe_mode") && !ini_get("open_basedir"));
  30. curl_setopt($ch, CURLOPT_USERAGENT, SELF_USER_AGENT);
  31. $contents = @curl_exec($ch);
  32. $real_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
  33. curl_close($ch);
  34. if ($real_url) {
  35. /* remove the rest of it */
  36. $query = parse_url($real_url, PHP_URL_QUERY);
  37. if ($query && strpos($query, "utm_source") !== FALSE) {
  38. $args = array();
  39. parse_str($query, $args);
  40. foreach (array("utm_source", "utm_medium", "utm_campaign") as $param) {
  41. if (isset($args[$param])) unset($args[$param]);
  42. }
  43. $new_query = http_build_query($args);
  44. if ($new_query != $query) {
  45. $real_url = str_replace("?$query", "?$new_query", $real_url);
  46. }
  47. }
  48. $real_url = preg_replace("/\?$/", "", $real_url);
  49. $article["plugin_data"] = "unburn,$owner_uid:" . $article["plugin_data"];
  50. $article["link"] = $real_url;
  51. }
  52. } else if (isset($article["stored"]["link"])) {
  53. $article["link"] = $article["stored"]["link"];
  54. }
  55. }
  56. return $article;
  57. }
  58. function geturl($url){
  59. (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');
  60. $curl = curl_init();
  61. $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
  62. $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
  63. $header[] = "Cache-Control: max-age=0";
  64. $header[] = "Connection: keep-alive";
  65. $header[] = "Keep-Alive: 300";
  66. $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
  67. $header[] = "Accept-Language: en-us,en;q=0.5";
  68. $header[] = "Pragma: ";
  69. curl_setopt($curl, CURLOPT_URL, $url);
  70. curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0 Firefox/5.0');
  71. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  72. curl_setopt($curl, CURLOPT_HEADER, true);
  73. curl_setopt($curl, CURLOPT_REFERER, $url);
  74. curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
  75. curl_setopt($curl, CURLOPT_AUTOREFERER, true);
  76. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  77. //curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); //CURLOPT_FOLLOWLOCATION Disabled...
  78. curl_setopt($curl, CURLOPT_TIMEOUT, 60);
  79. $html = curl_exec($curl);
  80. $status = curl_getinfo($curl);
  81. curl_close($curl);
  82. if($status['http_code']!=200){
  83. if($status['http_code'] == 301 || $status['http_code'] == 302) {
  84. list($header) = explode("\r\n\r\n", $html, 2);
  85. $matches = array();
  86. preg_match("/(Location:|URI:)[^(\n)]*/", $header, $matches);
  87. $url = trim(str_replace($matches[1],"",$matches[0]));
  88. $url_parsed = parse_url($url);
  89. return (isset($url_parsed))? geturl($url, $referer):'';
  90. }
  91. $oline='';
  92. foreach($status as $key=>$eline){$oline.='['.$key.']'.$eline.' ';}
  93. $line =$oline." \r\n ".$url."\r\n-----------------\r\n";
  94. $handle = @fopen('./curl.error.log', 'a');
  95. fwrite($handle, $line);
  96. return FALSE;
  97. }
  98. return $url;
  99. }
  100. }
  101. ?>