php.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /* ------------------------------------------------------------------------------------
  3. * Goosle - The fast, privacy oriented search tool that just works.
  4. *
  5. * COPYRIGHT NOTICE
  6. * Copyright 2023-2024 Arnan de Gans. All Rights Reserved.
  7. *
  8. * COPYRIGHT NOTICES AND ALL THE COMMENTS SHOULD REMAIN INTACT.
  9. * By using this code you agree to indemnify Arnan de Gans from any
  10. * liability that might arise from its use.
  11. ------------------------------------------------------------------------------------ */
  12. class PHPnetRequest extends EngineRequest {
  13. public function get_request_url() {
  14. $query = str_replace('%22', '\"', $this->query);
  15. $query = str_replace('php ', '', $query);
  16. $query = str_replace('_', '-', $query);
  17. // Is there no query left? Bail!
  18. if(empty($query)) return false;
  19. $url = 'https://www.php.net/manual/function.'.urlencode($query);
  20. unset($query);
  21. return $url;
  22. }
  23. public function get_request_headers() {
  24. return array(
  25. 'Accept' => 'text/html, application/xhtml+xml, application/xml;q=0.8, */*;q=0.7'
  26. );
  27. }
  28. public function parse_results($response) {
  29. $engine_result = array();
  30. $xpath = get_xpath($response);
  31. // No response
  32. if(!$xpath) return $engine_result;
  33. // Scrape the results
  34. $scrape = $xpath->query("//div/section/div[@class='refentry']");
  35. // No results
  36. if(count($scrape) == 0) return $engine_result;
  37. $query = str_replace('%22', '', $this->query);
  38. $query = str_replace('php ', '', $query);
  39. $query = str_replace('_', '-', $query);
  40. foreach($scrape as $result) {
  41. $title = $xpath->query(".//div/h1[@class='refname']")[0]->textContent;
  42. if(is_null($title)) return $engine_result;
  43. $php_versions = $xpath->query(".//div/p[@class='verinfo']")[0]->textContent;
  44. $purpose = $xpath->query(".//div/p[@class='refpurpose']")[0]->textContent;
  45. $usage = $xpath->query(".//div[@class='refsect1 description']/div[@class='methodsynopsis dc-description']")[0]->textContent;
  46. $summary = $xpath->query(".//div[@class='refsect1 description']/p[@class='para rdfs-comment']")[0]->textContent;
  47. $engine_result = array (
  48. // Required
  49. 'title' => "Function: ".sanitize($title),
  50. 'text' => "<p><em><small>".sanitize($php_versions)."</small></em></p><p>".sanitize($purpose)."</p><p>".highlight_string("<?php ".sanitize($usage)." ?>", 1)."</p><p>".$summary."</p>",
  51. 'source' => "https://www.php.net/manual/function.".urlencode($query)
  52. );
  53. }
  54. unset($response, $xpath, $scrape);
  55. return $engine_result;
  56. }
  57. }
  58. ?>