diff --git a/config.sample.php b/config.sample.php index c5d4ee2273b67f880489fd92bde585f9c8cfd112..e6959a99df0df11544bafa62af403bc8c6ad50bb 100644 --- a/config.sample.php +++ b/config.sample.php @@ -13,4 +13,7 @@ require_once 'UNL/Autoload.php'; */ // the following key is only "valid" for http://ucommabel.unl.edu/workspace/UNL_Search/www/ -// UNL_Search::$jsapiKey = 'ABQIAAAAGAtSvF89-VbesSJ07TEeoBTpxXZziuBpIcFFfJO7Mm8wj1oQWRRwVSIfGRIEAC9DlOSQX7rAAWHjhA'; +// UNL_Search::$jsapiKeys[] = 'ABQIAAAAGAtSvF89-VbesSJ07TEeoBTpxXZziuBpIcFFfJO7Mm8wj1oQWRRwVSIfGRIEAC9DlOSQX7rAAWHjhA'; + + + diff --git a/src/UNL/Search.php b/src/UNL/Search.php index c72f30aeaf0e1cdbc555065649fbb50c90204896..5b0ad20bde5743ca8ebf51ec595416556786765e 100644 --- a/src/UNL/Search.php +++ b/src/UNL/Search.php @@ -1,7 +1,12 @@ <?php class UNL_Search { - public static $jsapiKey = ''; + /** + * Array of Google JS API keys to use + * + * @var array + */ + public static $jsapiKeys = array(); function __construct() { @@ -45,5 +50,19 @@ class UNL_Search return $html; } + /** + * Return an API key + * + * @return string + */ + function getJSAPIKey() + { + if (empty(self::$jsapiKeys)) { + return ''; + } + + shuffle(self::$jsapiKeys); + return self::$jsapiKeys[0]; + } + } -?> \ No newline at end of file diff --git a/www/index.php b/www/index.php index 1f7e5844450d6a743aeff894750127d233eb5da9..4d1aa52295812b1078a67d974156d92ecc0fc5bf 100644 --- a/www/index.php +++ b/www/index.php @@ -16,7 +16,8 @@ if (isset($_GET['format']) $page = UNL_Templates::factory($template); $page->doctitle = '<title>UNL | Search</title>'; $local_results = ''; -$page->addScript('http://www.google.com/jsapi' . (empty(UNL_Search::$jsapiKey) ? '' : '?key=' . UNL_Search::$jsapiKey)); +$apiKey = UNL_Search::getJSAPIKey(); +$page->addScript('http://www.google.com/jsapi' . (empty($apiKey) ? '' : '?key=' . $apiKey)); $page->head .= ' <link rel="stylesheet" href="http://www.google.com/cse/style/look/default.css" type="text/css" /> <link rel="stylesheet" type="text/css" href="http://directory.unl.edu/css/result_lists.css" />