Skip to content

Instantly share code, notes, and snippets.

@nicbou

nicbou/search.php

Created Jul 4, 2020
Embed
What would you like to do?
Trly.gd
<?php
//Disable magic quotes, hassle-free
if (get_magic_quotes_gpc()) {
$process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
while (list($key, $val) = each($process)) {
foreach ($val as $k => $v) {
unset($process[$key][$k]);
if (is_array($v)) {
$process[$key][stripslashes($k)] = $v;
$process[] = &$process[$key][stripslashes($k)];
} else {
$process[$key][stripslashes($k)] = stripslashes($v);
}
}
}
unset($process);
}
//Search
if(isset($_GET['q'])){
$query = $_GET['q'];
$searchword = preg_split('/:/',$query,2);
$searchkey = $searchword[0];
if (sizeof($searchword)>1){
$query = $searchword[1];
switch (strtolower($searchkey)) {
case "b":
case "bing":
$url = "http://www.bing.com/search?q=";
break;
case "commons":
$url = "http://commons.wikimedia.org/w/index.php?title=Special:Search&search=";
break;
case "d":
case "dict":
$url = "http://dictionary.reference.com/search?q=";
break;
case "finance":
$url = "http://www.google.com/finance?q=";
break;
case "gmail":
if (strtolower($query) == "compose" || strtolower($query) == "new"){
$url = "https://mail.google.com/mail/#compose";
$query = "";
break;
}
else if($query == "inbox"){
$url = "https://mail.google.com/mail/#inbox";
break;
}
$url = "https://mail.google.com/mail/#search/";
break;
case "finance":
$url = "http://www.google.com/finance?q=";
break;
case "here":
$url = "https://maps.here.com/search/";
break;
case "i":
case "images":
$url = "http://images.google.com/images?q=";
break;
case "imdb":
$url = "http://www.imdb.com/find?q=";
break;
case "*":
case "lucky":
$url = "http://www.google.com/search?btnI=I'm+Feeling+Lucky&q=";
break;
case "m":
case "gmaps":
$url = "http://maps.google.com/maps?q=";
break;
case "reddit":
$query = completeURL($query);
$url = "http://www.reddit.com/search?q=";
break;
case "screenshot":
$url = "http://kwout.com/grab?address=";
break;
case "thes":
$url = "http://thesaurus.reference.com/search?q=";
break;
case "twitter":
$url = "http://twitter.com/search?q=";
break;
case "udict":
$url = "http://www.urbandictionary.com/define.php?term=";
break;
case "whois":
$query = completeURL($query);
$url = "http://www.whois.net/whois/";
break;
case "w":
case "wiki":
case "wikipedia":
$url = "http://www.wikipedia.org/search-redirect.php?language=en&search=";
break;
case "wa":
case "walpha":
case "wolfram":
$url = "http://www.wolframalpha.com/input/?i=";
break;
case "yt":
case "youtube":
$url = "http://www.youtube.com/results?search_query=";
break;
default:
if (preg_match("/^([a-z]{2})2([a-z]{2})$/",strtolower($searchkey))) {
$url = "http://translate.google.com/translate_t?sl=" . substr($searchkey,0,2) . "&tl=" . substr($searchkey,3,2) . "&text=";
}
else if (preg_match("/^(wiki)([a-z]{2})$/",strtolower($searchkey))) {
$url = "http://www.wikipedia.org/search-redirect.php?language=" . substr($searchkey,4,2) . "&search=";
}
//Wikipedia with language
else if (preg_match("/^(wiki)([a-z]{2})$/",strtolower($searchkey))) {
$url = "http://www.wikipedia.org/search-redirect.php?language=" . substr($searchkey,4,2) . "&search=";
}
else if (preg_match("/^(w)([a-z]{2})$/",strtolower($searchkey))) {
$url = "http://www.wikipedia.org/search-redirect.php?language=" . substr($searchkey,1,2) . "&search=";
}
//Google Translate
else if (preg_match("/^([a-z]{3})2([a-z]{3})$/",strtolower($searchkey))) {
$url = "http://finance.yahoo.com/currency-converter/#from=" . substr($searchkey,0,3) . ";to=" . substr($searchkey,4,3) . ";amt=";
}
//Google with language
else if (preg_match("/^(google)([a-z]{2})$/",strtolower($searchkey))) {
$url = "http://google.com/search?hl=" . substr($searchkey,6,2) . "&sl=" . substr($searchkey,6,2) . "&q=";
}
else if (preg_match("/^(g)([a-z]{2})$/",strtolower($searchkey))) {
$url = "http://google.com/search?hl=" . substr($searchkey,6,2) . "&sl=" . substr($searchkey,1,2) . "&q=";
}
else {
$url = "http://google.com/search?q=";
$query = $_GET['q'];
}
}
}
else {
//I'm feeling lucky
if (substr($query,0,1)=='*') {
$url = "http://www.google.com/search?btnI=I'm+Feeling+Lucky&q=";
}
//Help
else if ($query == '#help'){
$url = "help.php";
$query = "";
}
//Keywords
else if ($query == '#keywords'){
$url = "keywords.php";
$query = "";
}
//Google search
else{
$url = "http://google.com/search?q=";
}
}
$newURL = $url . urlencode(utf8_encode($query));
header ("Location: $newURL");
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.