php.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. // Format query/url for php.net
  16. $query = str_replace('php ', '', $query);
  17. $query = str_replace('_', '-', $query);
  18. // Is there no query left? Bail!
  19. if(empty($query)) return false;
  20. $url = 'https://www.php.net/manual/function.'.urlencode($query).'.php';
  21. unset($query);
  22. return $url;
  23. }
  24. public function get_request_headers() {
  25. return array(
  26. 'Accept' => 'text/html, application/xhtml+xml, application/xml;q=0.8, */*;q=0.7'
  27. );
  28. }
  29. public function parse_results($response) {
  30. $engine_result = array();
  31. $xpath = get_xpath($response);
  32. // No response
  33. if(!$xpath) return $engine_result;
  34. // Scrape the results
  35. $scrape = $xpath->query("//div/section/div[@class='refentry']");
  36. // No results
  37. if(count($scrape) == 0) return $engine_result;
  38. $query = str_replace('%22', '', $this->query);
  39. $query = str_replace('php ', '', $query);
  40. $query = str_replace('_', '-', $query);
  41. foreach($scrape as $result) {
  42. $title = $xpath->query(".//div/h1[@class='refname']")[0]->textContent;
  43. if(is_null($title)) return $engine_result;
  44. $php_versions = $xpath->query(".//div/p[@class='verinfo']")[0]->textContent;
  45. $purpose = $xpath->query(".//div/p[@class='refpurpose']")[0]->textContent;
  46. $usage = $xpath->query(".//div[@class='refsect1 description']/div[@class='methodsynopsis dc-description']")[0]->textContent;
  47. $summary = $xpath->query(".//div[@class='refsect1 description']/p[@class='para rdfs-comment']")[0]->textContent;
  48. $engine_result = array (
  49. // Required
  50. 'title' => "Function: ".sanitize($title),
  51. '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>",
  52. 'source' => "https://www.php.net/manual/function.".urlencode($query).".php"
  53. );
  54. }
  55. unset($response, $xpath, $scrape);
  56. return $engine_result;
  57. }
  58. }
  59. ?>