php.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. // Format query/url for php.net
  15. $query = str_replace('_', '-', $this->search->query_terms[1]);
  16. $url = 'https://www.php.net/manual/function.'.urlencode($query).'.php';
  17. unset($query);
  18. return $url;
  19. }
  20. public function get_request_headers() {
  21. return array(
  22. 'Accept' => 'text/html, application/xhtml+xml, application/xml;q=0.8, */*;q=0.7'
  23. );
  24. }
  25. public function parse_results($response) {
  26. $engine_result = array();
  27. $xpath = get_xpath($response);
  28. // No response
  29. if(!$xpath) {
  30. if($this->opts->querylog == 'on') querylog(get_class($this), 's', $this->url, 'No response', 0);
  31. return $engine_result;
  32. }
  33. // Scrape the results
  34. $scrape = $xpath->query("//div[@class='refentry']");
  35. // No results
  36. if(count($scrape) == 0) {
  37. if($this->opts->querylog == 'on') querylog(get_class($this), 's', $this->url, 'No results', 0);
  38. return $engine_result;
  39. }
  40. $query = str_replace('_', '-', $this->search->query_terms[1]);
  41. // Process scrape
  42. $title = $xpath->evaluate(".//div/h1[@class='refname']", $scrape[0]);
  43. if($title->length == 0) return $engine_result;
  44. $php_versions = $xpath->evaluate(".//div/p[@class='verinfo']", $scrape[0]);
  45. $purpose = $xpath->evaluate(".//div/p[@class='refpurpose']", $scrape[0]);
  46. $usage = $xpath->evaluate(".//div[@class='refsect1 description']/div[@class='methodsynopsis dc-description']", $scrape[0]);
  47. $summary = $xpath->evaluate(".//div[@class='refsect1 description']/p[@class='para rdfs-comment']", $scrape[0]);
  48. $title = sanitize($title[0]->textContent);
  49. $php_versions = ($php_versions->length > 0) ? sanitize($php_versions[0]->textContent) : "";
  50. $purpose = ($purpose->length > 0) ? sanitize($purpose[0]->textContent) : "";
  51. $usage = ($usage->length > 0) ? sanitize($usage[0]->textContent) : "";
  52. $summary = ($summary->length > 0) ? sanitize($summary[0]->textContent) : "";
  53. // Clean up string
  54. $usage = preg_replace(array('/\s{2,}/', '/[\t\n]/'), ' ', $usage);
  55. // Return result
  56. $engine_result = array (
  57. // Required
  58. 'title' => "Function: ".$title,
  59. 'text' => "<p><em><small>".$php_versions."</small></em></p><p>".$purpose."</p><p>".highlight_string("<?php ".htmlspecialchars_decode($usage)." ?>", 1)."</p><p>".$summary."</p>",
  60. 'source' => "https://www.php.net/manual/function.".urlencode($query).".php",
  61. 'note' => "Description may be incomplete. Always check the documentation page for more information."
  62. );
  63. if($this->opts->querylog == 'on') querylog(get_class($this), 's', $this->url, 1, 1);
  64. unset($response, $xpath, $scrape);
  65. return $engine_result;
  66. }
  67. }
  68. ?>