";
echo "
";
echo "
Share magnet result ";
echo "
Tap or click on the field below to copy the magnet result to your clipboard.
";
- echo "
Sharing: ".stripslashes($result['name'])." ";
- echo "
Copy magnet link
";
+ echo "
Sharing: ".stripslashes($result['title'])." ";
+ echo "
siteurl)."/results.php?s=".$share_url."\" />Copy magnet link
";
echo "
";
echo "
Close
";
echo "
";
@@ -292,12 +300,18 @@ echo '';
}
echo "";
- echo "
Goosle does not index, offer or distribute torrent files. ";
+
+ // Pagination navigation
+ if($opts->cache_type !== 'off' && $goosle_results['number_of_results'] > $opts->search_results_per_page) {
+ echo "";
+ }
+
+ echo "
Goosle does not index, offer or distribute torrent files.
";
}
// No results found
- if(array_key_exists('error', $results)) {
- foreach($results['error'] as $error) {
+ if(array_key_exists('error', $goosle_results)) {
+ foreach($goosle_results['error'] as $error) {
echo "
".$error['message']."
";
}
}
diff --git a/engines/search-news.php b/engines/search-news.php
index c8d9a84..b3167ec 100644
--- a/engines/search-news.php
+++ b/engines/search-news.php
@@ -12,32 +12,34 @@
class NewsSearch extends EngineRequest {
protected $requests, $special_request;
- public function __construct($opts, $mh) {
+ public function __construct($search, $opts, $mh) {
$this->requests = array();
- if($opts->enable_qwantnews == 'on') {
- require ABSPATH.'engines/news/qwant-news.php';
- $this->requests[] = new QwantNewsRequest($opts, $mh);
- }
-
- if($opts->enable_yahoonews == 'on') {
- require ABSPATH.'engines/news/yahoo-news.php';
- $this->requests[] = new YahooNewsRequest($opts, $mh);
- }
-
- if($opts->enable_bravenews == 'on') {
- require ABSPATH.'engines/news/brave-news.php';
- $this->requests[] = new BraveNewsRequest($opts, $mh);
- }
-
- if($opts->enable_hackernews == 'on') {
- require ABSPATH.'engines/news/hackernews.php';
- $this->requests[] = new HackernewsRequest($opts, $mh);
+ if($opts->enable_news_search == 'on') {
+ if($opts->enable_qwantnews == 'on') {
+ require ABSPATH.'engines/news/qwant-news.php';
+ $this->requests[] = new QwantNewsRequest($search, $opts, $mh);
+ }
+
+ if($opts->enable_yahoonews == 'on') {
+ require ABSPATH.'engines/news/yahoo-news.php';
+ $this->requests[] = new YahooNewsRequest($search, $opts, $mh);
+ }
+
+ if($opts->enable_bravenews == 'on') {
+ require ABSPATH.'engines/news/brave-news.php';
+ $this->requests[] = new BraveNewsRequest($search, $opts, $mh);
+ }
+
+ if($opts->enable_hackernews == 'on') {
+ require ABSPATH.'engines/news/hackernews.php';
+ $this->requests[] = new HackernewsRequest($search, $opts, $mh);
+ }
}
}
public function parse_results($response) {
- $results = array();
+ $goosle_results = array();
if(count($this->requests) !== 0) {
foreach($this->requests as $request) {
@@ -45,72 +47,63 @@ class NewsSearch extends EngineRequest {
$engine_result = $request->get_results();
if(!empty($engine_result)) {
- if(array_key_exists('did_you_mean', $engine_result)) {
- $results['did_you_mean'] = $engine_result['did_you_mean'];
- }
-
- if(array_key_exists('search_specific', $engine_result)) {
- $results['search_specific'][] = $engine_result['search_specific'];
- }
-
- if(array_key_exists('search', $engine_result)) {
- // Count results per source
- $results['sources'][$engine_result['source']] = $engine_result['amount'];
-
+ if(isset($engine_result['search'])) {
+ $how_many_results = 0;
+ $time = time();
+
// Merge duplicates and apply relevance scoring
foreach($engine_result['search'] as $result) {
- if(array_key_exists('search', $results)) {
- $result_urls = array_column($results['search'], 'url', 'id');
+ if(isset($goosle_results['search'])) {
+ $result_urls = array_column($goosle_results['search'], 'url', 'id');
$found_id = array_search($result['url'], $result_urls); // Return the result ID, or false if not found
} else {
$found_id = false;
}
+ $how_many_results++;
$social_media_multiplier = (is_social_media($result['url'])) ? ($request->opts->social_media_relevance / 10) : 1;
$goosle_rank = floor($result['engine_rank'] * floatval($social_media_multiplier));
if($found_id !== false) {
// Duplicate result from another engine
- $results['search'][$found_id]['goosle_rank'] += $goosle_rank;
- $results['search'][$found_id]['combo_source'][] = $engine_result['source'];
+ $goosle_results['search'][$found_id]['goosle_rank'] += $goosle_rank;
+ $goosle_results['search'][$found_id]['combo_source'][] = $engine_result['source'];
} else {
// First find, rank and add to results
- // Replace anything but alphanumeric with a space
- $query_terms = explode(' ', preg_replace('/\s{2,}|[^a-z0-9]+/', ' ', strtolower($request->query)));
- $match_rank = match_count($result['title'], $query_terms);
- $match_rank += match_count($result['description'], $query_terms);
- $match_rank += match_count($result['url'], $query_terms);
+ $match_rank = match_count($result['title'], $request->search->query_terms);
+ $match_rank += match_count($result['description'], $request->search->query_terms);
+ $match_rank += match_count($result['url'], $request->search->query_terms);
- if($result['date_added'] > $request->opts->result_range) {
- $time_rank = time() - $result['date_added'];
- if($time_rank > 7776001) { // More than 3 months old
- $match_rank += 1;
- } elseif($time_rank > 3888001 && $time_rank < 7776000) {
- $match_rank += 2;
- } elseif($time_rank > 1209600 && $time_rank < 3888000) {
- $match_rank += 4;
- } elseif($time_rank > 604801 && $time_rank < 1209600) {
- $match_rank += 6;
- } elseif($time_rank > 86401 && $time_rank < 604800) {
- $match_rank += 8;
- } elseif($time_rank > 43201 && $time_rank < 86400) {
- $match_rank += 10;
- } elseif($time_rank > 32601 && $time_rank < 43200) {
- $match_rank += 12;
- } else { // Less than 6 hours old
- $match_rank += 14;
- }
+ $time_rank = $time - $result['timestamp'];
+ if($time_rank > 21600) { // Less than 6 hours old
+ $match_rank += 8;
+ } elseif($time_rank > 86400 && $time_rank < 21600) { // About a day old
+ $match_rank += 6;
+ } elseif($time_rank > 604800 && $time_rank < 86400) { // Less than a week old, but more than a day
+ $match_rank += 4;
+ } elseif($time_rank > 2592000 && $time_rank < 604800) { // Less than a month old, but more than a week
+ $match_rank += 4;
+ } elseif($time_rank > 31536000 && $time_rank < 2592000) { // Less than a year old, but more than a month
+ $match_rank += 2;
+ } else { // More than a year old
+ $match_rank += 1;
}
$result['goosle_rank'] = $goosle_rank + $match_rank;
$result['combo_source'][] = $engine_result['source'];
$result['id'] = md5($result['url']);
- $results['search'][$result['id']] = $result;
+ // Add result to final results
+ $goosle_results['search'][$result['id']] = $result;
}
unset($result, $result_urls, $found_id, $social_media_multiplier, $goosle_rank, $match_rank, $time_rank, $query_terms);
}
+
+ // Count results per source
+ $goosle_results['sources'][$engine_result['source']] = $how_many_results;
+
+ unset($how_many_results, $time);
}
}
} else {
@@ -118,84 +111,109 @@ class NewsSearch extends EngineRequest {
$http_code_info = ($request_result['http_code'] > 200 && $request_result['http_code'] < 600) ? " -
What's this ?" : '';
$github_issue_url = "https://github.com/adegans/Goosle/discussions/new?category=general&".http_build_query(array('title' => get_class($request)." failed with error ".$request_result['http_code'], 'body' => "```\nEngine: ".get_class($request)."\nError Code: ".$request_result['http_code']."\nRequest url: ".$request_result['url']."\n```", 'labels' => 'request-error'));
- $results['error'][] = array(
+ $goosle_results['error'][] = array(
'message' => "
Ohno! A search query ran into some trouble. Usually you can try again in a few seconds to get a result!
Engine: ".get_class($request)."
Error code: ".$request_result['http_code'].$http_code_info."
Request url: ".$request_result['url']."
Need help? Find
similar issues , or
ask your own question ."
);
}
unset($request);
}
+
+ if(array_key_exists('search', $goosle_results)) {
+ // Re-order results based on rank
+ $keys = array_column($goosle_results['search'], 'goosle_rank');
+ array_multisort($keys, SORT_DESC, $goosle_results['search']);
+
+ // Count all results
+ $goosle_results['number_of_results'] = count($goosle_results['search']);
+
+ unset($keys);
+ } else {
+ // Add error if there are no search results
+ $goosle_results['error'][] = array(
+ 'message' => "No results found. Please try with more specific or different keywords!"
+ );
+ }
} else {
- $results['error'][] = array(
- 'message' => "
Configuration issue! It appears that all Web Search engines are disabled. Please enable at least one in your config.php file.
Need help? Find
similar issues ."
+ $goosle_results['error'][] = array(
+ 'message' => "It appears that all News Search engines are disabled or that searching for news is disabled."
);
}
- if(array_key_exists('search', $results)) {
- // Re-order results based on rank
- $keys = array_column($results['search'], 'goosle_rank');
- array_multisort($keys, SORT_DESC, $results['search']);
-
- unset($keys);
- } else {
- // Add error if there are no search results
- $results['error'][] = array(
- 'message' => "No results found. Please try with more specific or different keywords!"
- );
- }
-
- return $results;
+ return $goosle_results;
}
- public static function print_results($results, $opts) {
+ public static function print_results($goosle_results, $search, $opts) {
/*
// Uncomment for debugging
echo '
Settings: ';
print_r($opts);
echo ' ';
+echo "
Search data: ";
+print_r($search);
+echo " ";
echo '
Search results: ';
-print_r($results);
+print_r($goosle_results);
echo ' ';
*/
- if(array_key_exists('search', $results)) {
+ if(array_key_exists('search', $goosle_results)) {
+ // Pagination offset
+ if($opts->cache_type !== 'off') {
+ $offset = ((($search->page - 1) * $opts->search_results_per_page) + 1);
+ $goosle_results['search'] = array_slice($goosle_results['search'], $offset, $opts->search_results_per_page);
+ }
+
echo "
";
+
+ // Pagination navigation
+ if($opts->cache_type !== 'off' && $goosle_results['number_of_results'] > $opts->search_results_per_page) {
+ echo "";
+ }
}
// Some error occured
- if(array_key_exists('error', $results)) {
- foreach($results['error'] as $error) {
+ if(array_key_exists('error', $goosle_results)) {
+ foreach($goosle_results['error'] as $error) {
echo "
".$error['message']."
";
}
}
- unset($results);
+ unset($goosle_results);
}
}
?>
\ No newline at end of file
diff --git a/engines/search/brave.php b/engines/search/brave.php
index a3ec2cb..9c46959 100644
--- a/engines/search/brave.php
+++ b/engines/search/brave.php
@@ -11,27 +11,14 @@
------------------------------------------------------------------------------------ */
class BraveRequest extends EngineRequest {
public function get_request_url() {
- $query = str_replace('%22', '\"', $this->query);
-
- // Safe search ignore (not supported)
- if(preg_match('/(safe:)(on|off)/i', $query, $matches)) {
- $query = trim(str_replace($matches[0], '', $query));
- }
- unset($matches);
-
- // Is there no query left? Bail!
- if(empty($query)) return false;
-
$url = 'https://search.brave.com/search?'.http_build_query(array(
- 'q' => $query, // Search query
+ 'q' => $this->search->query, // Search query
'offset' => 0, // Start on 'page' 1 of results (0 = 1)
'show_local' => 0, // Localize results (0 = no localization)
'spellcheck' => 0, // No spellcheck on your query
'source' => 'web' // Where are you searching from? (Web)
));
- unset($query);
-
return $url;
}
@@ -88,10 +75,8 @@ class BraveRequest extends EngineRequest {
}
// Base info
- $number_of_results = count($engine_temp);
- if($number_of_results > 0) {
+ if(!empty($engine_temp)) {
$engine_result['source'] = 'Brave';
- $engine_result['amount'] = $number_of_results;
$engine_result['search'] = $engine_temp;
}
diff --git a/engines/search/duckduckgo.php b/engines/search/duckduckgo.php
index 18ee530..cc5e48d 100644
--- a/engines/search/duckduckgo.php
+++ b/engines/search/duckduckgo.php
@@ -11,29 +11,21 @@
------------------------------------------------------------------------------------ */
class DuckDuckGoRequest extends EngineRequest {
public function get_request_url() {
- $query = str_replace('%22', '\"', $this->query);
-
// Safe search override
- $safe = '-1';
- if(preg_match('/(safe:)(on|off)/i', $query, $matches)) {
- if($matches[2] == 'on') $safe = '1';
- if($matches[2] == 'off') $safe = '-2';
- $query = trim(str_replace($matches[0], '', $query));
+ if($this->search->safe == 0) {
+ $safe = '-2';
+ } else if($this->search->safe == 2) {
+ $safe = '1';
+ } else {
+ $safe = '-1';
}
- unset($matches);
-
- // Is there no query left? Bail!
- if(empty($query)) return false;
// Set locale
$language = (preg_match('/[a-z]{2}-[a-z]{2}/i', $this->opts->duckduckgo_language) && strlen($this->opts->duckduckgo_language) == 5) ? strtolower($this->opts->duckduckgo_language) : 'en_gb';
- // Is there no query left? Bail!
- if(empty($query)) return false;
-
// All parameters and values: https://duckduckgo.com/duckduckgo-help-pages/settings/params/
$url = 'https://html.duckduckgo.com/html/?'.http_build_query(array(
- 'q' => $query, // Search query
+ 'q' => $this->search->query, // Search query
'kp' => $safe, // Safe search (1 = on, -1 = moderate, -2 = off
'kl' => $language, // Language region
'kz' => '-1', // Instant answers (1 = on, -1 = off)
@@ -48,7 +40,7 @@ class DuckDuckGoRequest extends EngineRequest {
'k1' => '-1' // Ads (1 = on, -1 = off)
));
- unset($query, $safe, $language);
+ unset($safe, $language);
return $url;
}
@@ -115,10 +107,8 @@ class DuckDuckGoRequest extends EngineRequest {
}
// Base info
- $number_of_results = count($engine_temp);
- if($number_of_results > 0) {
+ if(!empty($engine_temp)) {
$engine_result['source'] = 'DuckDuckGo';
- $engine_result['amount'] = $number_of_results;
$engine_result['search'] = $engine_temp;
}
diff --git a/engines/search/google.php b/engines/search/google.php
index c759105..0c196aa 100644
--- a/engines/search/google.php
+++ b/engines/search/google.php
@@ -11,24 +11,10 @@
------------------------------------------------------------------------------------ */
class GoogleRequest extends EngineRequest {
public function get_request_url() {
- $query = str_replace('%22', '\"', $this->query);
-
- // Safe search override
- $safe = '1';
- if(preg_match('/(safe:)(on|off)/i', $query, $matches)) {
- if($matches[2] == 'on') $safe = '2';
- if($matches[2] == 'off') $safe = '0';
- $query = trim(str_replace($matches[0], '', $query));
- }
- unset($matches);
-
- // Is there no query left? Bail!
- if(empty($query)) return false;
-
// Including the preferred language variable breaks the page result, and with that the crawler!
$url = 'https://www.google.com/search?'.http_build_query(array(
- 'q' => $query, // Search query
- 'safe' => $safe, // Safe search (0 = off, 1 = moderate, 2 = on/strict)
+ 'q' => $this->search->query, // Search query
+ 'safe' => $this->search->safe, // Safe search (0 = off, 1 = moderate, 2 = on/strict)
'num' => 30, // Number of results per page
'pws' => 0, // Personalized search results (0 = off)
'udm' => 14, // A view for simpler/non-ai results
@@ -37,8 +23,6 @@ class GoogleRequest extends EngineRequest {
'sclient' => 'web' // Where are you searching from
));
- unset($query, $safe);
-
return $url;
}
@@ -105,10 +89,8 @@ class GoogleRequest extends EngineRequest {
}
// Base info
- $number_of_results = count($engine_temp);
- if($number_of_results > 0) {
+ if(!empty($engine_temp)) {
$engine_result['source'] = 'Google';
- $engine_result['amount'] = $number_of_results;
$engine_result['search'] = $engine_temp;
}
diff --git a/engines/search/qwant.php b/engines/search/qwant.php
index c49f3ce..c80091c 100644
--- a/engines/search/qwant.php
+++ b/engines/search/qwant.php
@@ -11,34 +11,20 @@
------------------------------------------------------------------------------------ */
class QwantRequest extends EngineRequest {
public function get_request_url() {
- $query = str_replace('%22', '\"', $this->query);
-
- // Safe search override
- $safe = '1'; // Moderate results
- if(preg_match('/(safe:)(on|off)/i', $query, $matches)) {
- if($matches[2] == 'on') $safe = '2';
- if($matches[2] == 'off') $safe = '0';
- $query = trim(str_replace($matches[0], '', $query));
- }
- unset($matches);
-
// Set locale
$language = (preg_match('/[a-z]{2}_[a-z]{2}/i', $this->opts->qwant_language) && strlen($this->opts->qwant_language) == 5) ? strtolower($this->opts->qwant_language) : 'en_gb';
- // Is there no query left? Bail!
- if(empty($query)) return false;
-
// Based on https://github.com/locness3/qwant-api-docs and variables from qwant website
$url = 'https://api.qwant.com/v3/search/web?'.http_build_query(array(
- 'q' => $query, // Search query
+ 'q' => $this->search->query, // Search query
't' => 'web', // Type of search, web search
- 'safesearch' => $safe, // Safe search filter (0 = off, 1 = normal, 2 = strict)
+ 'safesearch' => $this->search->safe, // Safe search filter (0 = off, 1 = normal, 2 = strict)
'locale' => $language, // In which language should the search be done
'count' => 10, // How many results? (Maximum 10)
'device' => 'desktop' // What kind of device are we searching from?
));
- unset($query, $safe, $language);
+ unset($query, $language);
return $url;
}
@@ -89,10 +75,8 @@ class QwantRequest extends EngineRequest {
}
// Base info
- $number_of_results = count($engine_temp);
- if($number_of_results > 0) {
+ if(!empty($engine_temp)) {
$engine_result['source'] = 'Qwant';
- $engine_result['amount'] = $number_of_results;
$engine_result['search'] = $engine_temp;
}
diff --git a/engines/search/wikipedia.php b/engines/search/wikipedia.php
index 95fc92d..04e86e5 100644
--- a/engines/search/wikipedia.php
+++ b/engines/search/wikipedia.php
@@ -11,30 +11,19 @@
------------------------------------------------------------------------------------ */
class WikiRequest extends EngineRequest {
public function get_request_url() {
- $query = str_replace('%22', '\"', $this->query);
-
- // Safe search ignore
- if(preg_match('/(safe:)(on|off)/i', $query, $matches)) {
- $query = trim(str_replace($matches[0], '', $query));
- }
- unset($matches);
-
// Set locale
$language = (strlen($this->opts->wikipedia_language) == 2) ? strtolower($this->opts->wikipedia_language) : 'en';
- // Is there no query left? Bail!
- if(empty($query)) return false;
-
// Variables based on https://www.mediawiki.org/wiki/API:Search
$url = 'https://'.$language.'.wikipedia.org/w/api.php?'.http_build_query(array(
- 'srsearch' => $query, // Search query
+ 'srsearch' => $this->search->query, // Search query
'action' => 'query', // Search type (via a query?)
'list' => 'search', // Full text search
'format' => 'json', // Return format (Must be json)
'srlimit' => 10 // How many search results to get, ideally as few as possible since it's just static wiki pages (max 500)
));
- unset($query, $language);
+ unset($language);
return $url;
}
@@ -79,10 +68,8 @@ class WikiRequest extends EngineRequest {
}
// Base info
- $number_of_results = count($engine_temp);
- if($number_of_results > 0) {
+ if(!empty($engine_temp)) {
$engine_result['source'] = 'Wikipedia';
- $engine_result['amount'] = $number_of_results;
$engine_result['search'] = $engine_temp;
}
diff --git a/engines/special/currency.php b/engines/special/currency.php
index 122a337..2994325 100644
--- a/engines/special/currency.php
+++ b/engines/special/currency.php
@@ -43,11 +43,10 @@ class CurrencyRequest extends EngineRequest {
// [2] = (to|in)
// [3] = TO CURRENCY
- $query_terms = explode(' ', $this->query);
- $amount = floatval($query_terms[0]);
- $amount_currency = strtoupper($query_terms[1]);
- $conversion_currency = strtoupper($query_terms[3]);
- $last_update = date('M d, Y H:i:s', timezone_offset(strtotime(sanitize($json_response['lastupdate'])), $this->opts->timezone));
+ $amount = floatval($this->search->query_terms[0]);
+ $amount_currency = strtoupper($this->search->query_terms[1]);
+ $conversion_currency = strtoupper($this->search->query_terms[3]);
+ $last_update = the_date('M d, Y H:i', strtotime(sanitize($json_response['lastupdate'])));
// Unknown/misspelled currencies
if(!array_key_exists($amount_currency, $json_response['rates']) || !array_key_exists($conversion_currency, $json_response['rates'])) {
@@ -58,13 +57,14 @@ class CurrencyRequest extends EngineRequest {
$conversion = round(($json_response['rates'][$conversion_currency] / $json_response['rates'][$amount_currency]) * $amount, 2);
$one_to_n = round(($json_response['rates'][$conversion_currency] / $json_response['rates'][$amount_currency]) * 1, 2);
+ // Return result
$engine_result = array(
'title' => "Currency conversion: ".$amount." ".$amount_currency." = ".$conversion." ".$conversion_currency,
- 'text' => "
1 $amount_currency = $one_to_n $conversion_currency
Updated: $last_update (GMT/UTC+0)
",
+ 'text' => "
1 ".$amount_currency." = ".$one_to_n." ".$conversion_currency."
Updated: ".$last_update."
",
'source' => "https://moneyconvert.net/"
);
- unset($response, $json_response, $query_terms, $amount, $amount_currency, $conversion, $one_to_n, $conversion_currency, $last_update);
+ unset($response, $json_response, $amount, $amount_currency, $conversion, $one_to_n, $conversion_currency, $last_update);
return $engine_result;
}
diff --git a/engines/special/definition.php b/engines/special/definition.php
index d16ac84..717991a 100644
--- a/engines/special/definition.php
+++ b/engines/special/definition.php
@@ -11,18 +11,9 @@
------------------------------------------------------------------------------------ */
class DefinitionRequest extends EngineRequest {
public function get_request_url() {
- $query = str_replace('%22', '\"', $this->query);
- $query_terms = explode(' ', $query);
-
- // [0] = (define|d|mean|meaning)
+ // [0] = (define|meaning)
// [1] = WORD
-
- // Is there no query left? Bail!
- if(empty($query)) return false;
-
- $url = 'https://api.dictionaryapi.dev/api/v2/entries/en/'.$query_terms[1];
-
- unset($query, $query_terms);
+ $url = 'https://api.dictionaryapi.dev/api/v2/entries/en/'.$this->search->query_terms[1];
return $url;
}
@@ -46,10 +37,12 @@ class DefinitionRequest extends EngineRequest {
if(empty($json_response)) return $engine_result;
// No results
- if(!array_key_exists('title', $json_response)) return $engine_result;
+ if(isset($json_response['title']) && $json_response['title'] == 'No Definitions Found') return $engine_result;
- // Grab first result if there are multiple
- $result = $json_response[0];
+ $result = $json_response[0]; // Always grab the first result
+
+ // Incomplete listing? Bail!
+ if(!array_key_exists('word', $result)) return $engine_result;
// Find a phonetic spelling
if(isset($result['phonetic'])) {
@@ -81,6 +74,7 @@ class DefinitionRequest extends EngineRequest {
unset($meaning);
}
+ // Return result
$engine_result = array(
'title' => "Definition for: ".sanitize($result['word'])."
[".sanitize($phonetic)."] ",
'text' => $formatted_response,
diff --git a/engines/special/ipify.php b/engines/special/ipify.php
index 964db75..95fac79 100644
--- a/engines/special/ipify.php
+++ b/engines/special/ipify.php
@@ -34,10 +34,12 @@ class ipRequest extends EngineRequest {
// No response
if(empty($json_response)) return $engine_result;
+ // Return result
$engine_result = array(
'title' => "Your IP Address: ".$_SERVER["REMOTE_ADDR"],
- 'text' => "
All requests via Goosle use this as your IP Address: ".sanitize($json_response['ip'])."Goosle is not a proxy server. This test does NOT guarantee any degree of privacy. Any site that you visit through Goosle Search Results will see your actual IP Address.
",
- 'source' => "https://www.ipify.org/"
+ 'text' => "
All requests via Goosle use this as your IP Address: ".sanitize($json_response['ip'])."
",
+ 'source' => "https://www.ipify.org/",
+ 'note' => "Goosle is not a proxy server. Any website that you visit through Goosle Search Results will see your actual IP Address."
);
unset($response, $json_response);
diff --git a/engines/special/php.php b/engines/special/php.php
index d6723c7..00087cb 100644
--- a/engines/special/php.php
+++ b/engines/special/php.php
@@ -11,14 +11,8 @@
------------------------------------------------------------------------------------ */
class PHPnetRequest extends EngineRequest {
public function get_request_url() {
- $query = str_replace('%22', '\"', $this->query);
-
// Format query/url for php.net
- $query = str_replace('php ', '', $query);
- $query = str_replace('_', '-', $query);
-
- // Is there no query left? Bail!
- if(empty($query)) return false;
+ $query = str_replace('_', '-', $this->search->query_terms[1]);
$url = 'https://www.php.net/manual/function.'.urlencode($query).'.php';
@@ -41,31 +35,39 @@ class PHPnetRequest extends EngineRequest {
if(!$xpath) return $engine_result;
// Scrape the results
- $scrape = $xpath->query("//div/section/div[@class='refentry']");
+ $scrape = $xpath->query("//div[@class='refentry']");
// No results
if(count($scrape) == 0) return $engine_result;
- $query = str_replace('%22', '', $this->query);
- $query = str_replace('php ', '', $query);
- $query = str_replace('_', '-', $query);
+ $query = str_replace('_', '-', $this->search->query_terms[1]);
- foreach($scrape as $result) {
- $title = $xpath->query(".//div/h1[@class='refname']")[0]->textContent;
- if(is_null($title)) return $engine_result;
+ // Process scrape
+ $title = $xpath->evaluate(".//div/h1[@class='refname']", $scrape[0]);
+ if($title->length == 0) return $engine_result;
- $php_versions = $xpath->query(".//div/p[@class='verinfo']")[0]->textContent;
- $purpose = $xpath->query(".//div/p[@class='refpurpose']")[0]->textContent;
- $usage = $xpath->query(".//div[@class='refsect1 description']/div[@class='methodsynopsis dc-description']")[0]->textContent;
- $summary = $xpath->query(".//div[@class='refsect1 description']/p[@class='para rdfs-comment']")[0]->textContent;
+ $php_versions = $xpath->evaluate(".//div/p[@class='verinfo']", $scrape[0]);
+ $purpose = $xpath->evaluate(".//div/p[@class='refpurpose']", $scrape[0]);
+ $usage = $xpath->evaluate(".//div[@class='refsect1 description']/div[@class='methodsynopsis dc-description']", $scrape[0]);
+ $summary = $xpath->evaluate(".//div[@class='refsect1 description']/p[@class='para rdfs-comment']", $scrape[0]);
- $engine_result = array (
- // Required
- 'title' => "Function: ".sanitize($title),
- 'text' => "
".sanitize($php_versions)."
".sanitize($purpose)."
".highlight_string("", 1)."
".$summary."
",
- 'source' => "https://www.php.net/manual/function.".urlencode($query).".php"
- );
- }
+ $title = sanitize($title[0]->textContent);
+ $php_versions = ($php_versions->length > 0) ? sanitize($php_versions[0]->textContent) : "";
+ $purpose = ($purpose->length > 0) ? sanitize($purpose[0]->textContent) : "";
+ $usage = ($usage->length > 0) ? sanitize($usage[0]->textContent) : "";
+ $summary = ($summary->length > 0) ? sanitize($summary[0]->textContent) : "";
+
+ // Clean up string
+ $usage = preg_replace(array('/\s{2,}/', '/[\t\n]/'), ' ', $usage);
+
+ // Return result
+ $engine_result = array (
+ // Required
+ 'title' => "Function: ".$title,
+ 'text' => "
".$php_versions."
".$purpose."
".highlight_string("", 1)."
".$summary."
",
+ 'source' => "https://www.php.net/manual/function.".urlencode($query).".php",
+ 'note' => "Description may be incomplete. Always check the documentation page for more information."
+ );
unset($response, $xpath, $scrape);
return $engine_result;
diff --git a/engines/special/wordpress.php b/engines/special/wordpress.php
new file mode 100644
index 0000000..521dba7
--- /dev/null
+++ b/engines/special/wordpress.php
@@ -0,0 +1,92 @@
+search->query_terms[1] == 'hook') {
+ // https://developer.wordpress.org/reference/hooks/HOOK_OR_FILTER_NAME/
+ $type = 'hooks';
+ $query = $this->search->query_terms[2];
+ } else {
+ // https://developer.wordpress.org/reference/functions/FUNCTION_NAME/
+ $type = 'functions';
+ $query = $this->search->query_terms[1];
+ }
+
+
+
+ $url = 'https://developer.wordpress.org/reference/'.$type.'/.'.urlencode($query).'/';
+
+ unset($query, $type);
+
+ return $url;
+ }
+
+ public function get_request_headers() {
+ return array(
+ 'Accept' => 'text/html, application/xhtml+xml, application/xml;q=0.8, */*;q=0.7'
+ );
+ }
+
+ public function parse_results($response) {
+ $engine_result = array();
+ $xpath = get_xpath($response);
+
+ // No response
+ if(!$xpath) return $engine_result;
+
+ // Scrape the results
+ $scrape = $xpath->query("//div/main/article");
+
+ // No results
+ if(count($scrape) == 0) return $engine_result;
+
+ if($this->search->query_terms[1] == 'hook') {
+ $type = 'hooks';
+ $query = $this->search->query_terms[2];
+ } else {
+ $type = 'functions';
+ $query = $this->search->query_terms[1];
+ }
+
+ // Process scrape
+ $usage = $xpath->evaluate(".//h1[@class='wp-block-wporg-code-reference-title']", $scrape[0]);
+ if($usage->length == 0) return $engine_result;
+
+ $purpose = $xpath->evaluate(".//section[@class='wp-block-wporg-code-reference-summary']", $scrape[0]);
+ $description = $xpath->evaluate(".//section[contains(@class, 'wp-block-wporg-code-reference-explanation')]/p[1]", $scrape[0]);
+ if($description->length == 0) $description = $xpath->evaluate(".//section[contains(@class, 'wp-block-wporg-code-reference-description')]/p[1]", $scrape[0]);
+ $introduced = $xpath->evaluate(".//section[@class='wp-block-wporg-code-reference-changelog']//tbody", $scrape[0]);
+
+ $title = sanitize($query);
+ $purpose = ($purpose->length > 0) ? sanitize($purpose[0]->textContent) : "";
+ $description = ($description->length > 0) ? sanitize($description[0]->textContent) : "";
+ $usage = ($usage->length > 0) ? sanitize($usage[0]->textContent) : "";
+ $introduced = ($introduced->length > 0) ? sanitize($introduced[0]->lastChild->firstElementChild->textContent) : "(Unknown)";
+
+ // Clean up string
+ $usage = preg_replace(array('/\s{2,}/', '/[\t\n]/'), ' ', $usage);
+
+ // Return result
+ $engine_result = array (
+ // Required
+ 'title' => ucfirst($type).": ".$title,
+ 'text' => "
Since WordPress ".$introduced."
".$purpose."
".highlight_string("", 1)."
".$description."
",
+ 'source' => "https://developer.wordpress.org/reference/".$type."/".urlencode($query)."/",
+ 'note' => "Description may be incomplete. Always check the documentation page for more information."
+ );
+ unset($response, $xpath, $scrape);
+
+ return $engine_result;
+ }
+}
+?>
diff --git a/error.php b/error.php
new file mode 100644
index 0000000..18c7224
--- /dev/null
+++ b/error.php
@@ -0,0 +1,50 @@
+
+
+
+
+
Goosle Search
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
You can't use G oosle without an authorization key!
+
Contact the website administrator for more information.
+
+
+
\ No newline at end of file
diff --git a/functions/oauth.php b/functions/oauth.php
index 89d5f82..9953a3c 100644
--- a/functions/oauth.php
+++ b/functions/oauth.php
@@ -123,10 +123,10 @@ if(verify_hash($opts->hash_auth, $opts->hash, $auth)) {
-Goosle