Dataoke.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace Heanup\App\Api\Model;
  3. use QL\QueryList;
  4. use function GuzzleHttp\Psr7\parse_query;
  5. class Dataoke
  6. {
  7. public static function parse($content)
  8. {
  9. $ql = QueryList::html($content);
  10. $rt = $ql->find("a")->attrs('href');
  11. $data = $rt->all();
  12. $data = array_unique($data);
  13. foreach ($data as $k => $url) {
  14. if (strstr($url, "tao.php") === false) {
  15. continue;
  16. }
  17. $query = parse_url($url);
  18. $t = parse_query($query['query']);
  19. $q = [];
  20. if ($t['cid']) {
  21. $q['cid'] = $t['cid'];
  22. }
  23. if ($t['pid']) {
  24. $q['pid'] = $t['pid'];
  25. }
  26. if ($t['bids']) {
  27. $q['bids'] = $t['bids'];
  28. }
  29. if ($t['original_id']){
  30. $q['original_id'] = $t['original_id'];
  31. }
  32. if ($t['kw']) {
  33. unset($q['kw']);
  34. if (count($q) > 0) {
  35. $s = "?" . http_build_query($q);
  36. } else {
  37. $s = "";
  38. }
  39. $new_url = "/kw/" . $t['kw'] . ".html" . $s;
  40. $content = str_replace('"' . $url . '"', '"' . $new_url . '"', $content);
  41. } else {
  42. if ($t['cid']) {
  43. unset($q['cid']);
  44. if (count($q) > 0) {
  45. $s = "?" . http_build_query($q);
  46. } else {
  47. $s = "";
  48. }
  49. if ($t['page']){
  50. $new_url = "/category/".$t['cid']."/page_" . $t['page'] . ".html".$s;
  51. $content = str_replace('"' . $url . '"', '"' . $new_url . '"', $content);
  52. $url=htmlentities($url);
  53. $content = str_replace('"' . $url . '"', '"' . $new_url . '"', $content);
  54. }else{
  55. $new_url = "/category/" . $t['cid'] . "/index.html".$s;
  56. }
  57. $content = str_replace('"' . $url . '"', '"' . $new_url . '"', $content);
  58. } else {
  59. if ($t['id']) {
  60. $new_url = "/product/" . $t['id'] . ".html";
  61. $content = str_replace('"' . $url . '"', '"' . $new_url . '"', $content);
  62. }
  63. }
  64. }
  65. ///index.php?r=index
  66. // if ($url=="/index.php?r=index"){
  67. // $content = str_replace($url, "/" , $content);
  68. // }
  69. }
  70. $content = str_replace('"/tao.php?r=p"', '"/pages/fengqiang.html"', $content);
  71. $content = str_replace('"/tao.php?r=nine"', '"/pages/nine.html"', $content);
  72. $content = str_replace('"/tao.php?r=ddq"', '"/pages/dongdong.html"', $content);
  73. $content = str_replace('"/tao.php?r=l"', '"/pages/haohuo.html"', $content);
  74. $content = str_replace('"/tao.php?r=index/index&u=1350274"', '"/"', $content);
  75. $content = str_replace('href="/tao.php?r=index/index"', 'href="/"', $content);
  76. $content = str_replace('https://cmsstatic.ffquan.cn//js/new_home.js', "/static/new_home.js", $content);
  77. // $content=str_replace('index.php', "tao.php", $content);
  78. return $content;
  79. }
  80. }