diff --git a/api.php b/api.php index 8d8428f..66c4fe6 100644 --- a/api.php +++ b/api.php @@ -1,13 +1,13 @@ \ No newline at end of file diff --git a/config.php b/config.php index 0262221..19e84a0 100755 --- a/config.php +++ b/config.php @@ -9,20 +9,31 @@ $config_google_language = "en"; /* - Format: "ip:port" - - For a TOR connection you would use these settings: - $config_proxy = "127.0.0.1:9050"; - $config_proxy_type = 5; - */ - $config_proxy = null; + To send requests trough a proxy uncomment CURLOPT_PROXY and CURLOPT_PROXYTYPE: - /* - 1 -> HTTP - 2 -> SOCKS4 - 3 -> SOCKS4a (resolves URL hostname) - 4 -> SOCKS5 - 5 -> SOCKS5 (resolves URL hostname) + CURLOPT_PROXYTYPE options: + + CURLPROXY_HTTP + CURLPROXY_SOCKS4 + CURLPROXY_SOCKS4A + CURLPROXY_SOCKS5 + CURLPROXY_SOCKS5_HOSTNAME + + As an example, for a TOR connection you would use these settings: + CURLOPT_PROXY => "127.0.0.1:9050", + CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5, + + !!! ONLY CHANGE THE OTHER OPTIONS IF YOU KNOW WHAT YOU ARE DOING !!! */ - $config_proxy_type = 1; + $config_curl_settings = array( + // CURLOPT_PROXY => "ip:port", + // CURLOPT_PROXYTYPE => CURLPROXY_HTTP, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_HEADER => false, + CURLOPT_FOLLOWLOCATION => false, + CURLOPT_ENCODING => "", + CURLOPT_USERAGENT => $config_user_agent, + CURLOPT_SSL_VERIFYHOST => 0, + CURLOPT_VERBOSE => 1 + ); ?> \ No newline at end of file diff --git a/fetch.php b/fetch.php deleted file mode 100644 index 39f42fa..0000000 --- a/fetch.php +++ /dev/null @@ -1,228 +0,0 @@ - true, - CURLOPT_HEADER => false, - CURLOPT_FOLLOWLOCATION => false, - CURLOPT_ENCODING => "", - CURLOPT_USERAGENT => $config_user_agent, - CURLOPT_SSL_VERIFYHOST => 0, - CURLOPT_VERBOSE => 1 - ); - - function get_base_url($url) - { - $split_url = explode("/", $url); - $base_url = $split_url[0] . "//" . $split_url[2] . "/"; - return $base_url; - } - - function special_search($query) - { - $query_lower = strtolower($query); - - // Check for currency convesion - if (strpos($query_lower, "to")) - convert_currency($query); - - // Check for definition - else if (strpos($query_lower, "mean")) - define_word($query); - } - - function convert_currency($query) - { - - global $curl_settings , $proxy_type , $config_proxy; - - $split_query = explode(" ", $query); - - if (count($split_query) >= 4) - { - $amount_to_convert = floatval($split_query[0]); - - if ($amount_to_convert != 0) - { - $base_currency = strtoupper($split_query[1]); - $currency_to_convert = strtoupper($split_query[3]); - - $ch = curl_init("https://cdn.moneyconvert.net/api/latest.json"); - if ($config_proxy != null) - { - curl_setopt($ch, CURLOPT_PROXY, $config_proxy); - curl_setopt($ch, CURLOPT_PROXYTYPE, $proxy_type); - } - curl_setopt_array($ch, $curl_settings); - $response = curl_exec($ch); - $json_response = json_decode($response, true); - - $rates = $json_response["rates"]; - - if (array_key_exists($base_currency, $rates) && array_key_exists($currency_to_convert, $rates)) - { - $base_currency_response = $rates[$base_currency]; - $currency_to_convert_response = $rates[$currency_to_convert]; - - $conversion_result = ($currency_to_convert_response / $base_currency_response) * $amount_to_convert; - - echo "
"; - echo "$amount_to_convert $base_currency = $conversion_result $currency_to_convert"; - echo "
"; - } - } - } - } - - function define_word($query) - { - global $curl_settings , $proxy_type , $config_proxy; - - $split_query = explode(" ", $query); - - if (count($split_query) >= 2) - { - $reversed_split_q = array_reverse($split_query); - $word_to_define = $reversed_split_q[1]; - - $ch = curl_init("https://api.dictionaryapi.dev/api/v2/entries/en/$word_to_define"); - if ($config_proxy != null) - { - curl_setopt($ch, CURLOPT_PROXY, $config_proxy); - curl_setopt($ch, CURLOPT_PROXYTYPE, $proxy_type); - } - curl_setopt_array($ch, $curl_settings); - $response = curl_exec($ch); - $json_response = json_decode($response, true); - - if (!array_key_exists("title", $json_response)) - { - $definition = $json_response[0]["meanings"][0]["definitions"][0]["definition"]; - - echo "";
- echo "$word_to_define meaning
";
- echo "
" . $definition . "
";
- echo "
"; + echo "$amount_to_convert $base_currency = $conversion_result $currency_to_convert"; + echo "
"; + } + } + } + } +?> \ No newline at end of file diff --git a/results/definition.php b/results/definition.php new file mode 100644 index 0000000..81d20ee --- /dev/null +++ b/results/definition.php @@ -0,0 +1,29 @@ += 2) + { + $reversed_split_q = array_reverse($split_query); + $word_to_define = $reversed_split_q[1]; + + $ch = curl_init("https://api.dictionaryapi.dev/api/v2/entries/en/$word_to_define"); + curl_setopt_array($ch, $config_curl_settings); + $response = curl_exec($ch); + $json_response = json_decode($response, true); + + if (!array_key_exists("title", $json_response)) + { + $definition = $json_response[0]["meanings"][0]["definitions"][0]["definition"]; + + echo "";
+ echo "$word_to_define meaning
";
+ echo "
" . $definition . "
";
+ echo "
Fetched the results in $end_time seconds
"; - if ($_SESSION["type"] != "img") + if ($type == 0) // text search { - special_search($query); + check_for_special_search($query); foreach($results as $result) { $title = $result["title"]; $url = $result["url"]; $base_url = $result["base_url"]; + $description = $result["description"]; echo "