Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Update | 29 comments | Create New Account
Click here to return to the 'Update' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Update
Authored by: tokek on May 20, '05 06:32:12PM
Updated version:

<?
/*
Add Mozilla-like keyword functionality to Safari's search bar.

Author: sapporo@land.ru (inspired by a hint from nimatoad at
http://www.macosxhints.com/article.php?story=20030514035516436)

TO DO: german umlauts don't show up the way they should at the
target site

There's another method of redirecting Safari searches by editing
/etc -> hosts (as proposed here:
http://www.macosxhints.com/article.php?story=20030509004243460),
but this seemed to be the easiest one. You'll have to modifiy
Safari.app after you update it (and pray they didn't change the
way searching works).

*/
/*
Originally from:
	http://www.macosxhints.com/article.php?story=20030519070642235

Some of the changes made:
	+ parameter-less keywords (eg. "bbc" goes to BBC News)
	+ Parse strings into any specified character encoding (UTF-8 when unspecified)
	+ more use of array lookups, fewer while loops, preg matching
	+ uses stripslashes to undo the effects of automatic addslashes.
-- 20050520 Tokek
*/


// add your own keywords here

$keywords = array(
	"az"   => array("http://www.amazon.com/exec/obidos/external-search?mode=blended&keyword=%query%"),
	"azj"  => array("http://www.amazon.co.jp/exec/obidos/external-search?mode=blended&keyword=%query%"),
	"c"    => array("http://www.%query%.com/"),
	"en"   => array("http://www.google.com/search?ie=UTF-8&oe=UTF-8&lr=lang_en&q=%query%"),
	"f"    => array("http://froogle.google.com/froogle?q=%query%"),
	"g"    => array("http://www.google.com/search?ie=UTF-8&oe=UTF-8&q=%query%"),
	"gi"   => array("http://images.google.com/images?ie=UTF-8&oe=UTF-8&safe=off&q=%query%"),
	"gj"   => array("http://www.google.com/search?ie=UTF-8&oe=UTF-8&lr=lang_ja&hl=ja&q=%query%"),
	"gij"  => array("http://images.google.com/images?ie=UTF-8&oe=UTF-8&safe=off&lr=lang_ja&hl=ja&q=%query%"),
	"gji"  => array("http://images.google.com/images?ie=UTF-8&oe=UTF-8&safe=off&lr=lang_ja&hl=ja&q=%query%"),
	"m"    => array("http://www.google.com/search?ie=UTF-8&oe=UTF-8&q=%query%+site:macosxhints.com"),
	"q"    => array("http://www.google.com/search?ie=UTF-8&oe=UTF-8&q=%22%query%%22"),
	"wj"   => array("http://ja.wikipedia.org/wiki/%query%"),
	"d"    => array("http://dictionary.reference.com/search?q=%query%", "ISO-8859-1"),
	"w"    => array("http://en.wikipedia.org/w/wiki.phtml?search=%query%&go=Go", "ISO-8859-1"),
	"goo"  => array("http://dictionary.goo.ne.jp/search.php?MT=%query%&kind=jn&mode=0", "EUC-JP"),
);



// shortword - self-made neologism meaning parameter-less custom keyword
$shortwords = array(
	"g"    => "http://www.google.com/",
	"ym"   => "http://mail.yahoo.com/",
	"gm"   => "http://gmail.google.com/gmail",
	"goo"   => "http://dictionary.goo.ne.jp/",
	"bbc"   => "http://news.bbc.co.uk/",
);


// the original search term
// remove slashes that were automatically added
$q = urldecode(stripslashes($_GET['q']));

// show help screen
if ("help" == $q) {

	echo "<html><body><center><h2>Search help:</h2><table>";
	while (list ($key, $location) = each ($keywords)) {
		echo "<tr><td>$key </td><td>$location</td></tr>\n";
	}
	echo "</table><p>Cmd+Option+F for the searchbox.";
	echo "<p>http://www.macosxhints.com/article.php?story=20030519070642235";
	echo "<p><a href='mailto:sapporo@land.ru'>sapporo@land.ru</a></body></html>";
	exit;
}

// E3 80 80 is ideographic space character (U+3000) in UTF-8 byte sequence
if (preg_match("/^([a-z]+)(\xE3\x80\x80|\s)(.*)/", $q, $matches)) {
	$key = $matches[1];
	$query = $matches[3];
	list($location, $charset) = $keywords[$key];
	if ($location != "") {
		if ($charset != "") {
			$query = mb_convert_encoding($query, $charset, "UTF-8");
		}
		header("Location: $val".str_replace("%query%", urlencode($query), $location));
		exit;
	}
}
else {
	// search for matching shortword and redirect upon success
	$location = $shortwords[$q];
	if ($location != "") {
		header("Location: $location");
		exit;
	}
}

// default to google.com
header("Location: http://www.google.com/search?&ie=UTF-8&oe=UTF-8&q=".urlencode($q));

?>



[ Reply to This | # ]