From 02fb23c6298f47b6e28c3c058db343a4f49477c3 Mon Sep 17 00:00:00 2001
From: Brett Bieber <brett.bieber@gmail.com>
Date: Wed, 28 Sep 2011 14:31:18 +0000
Subject: [PATCH] All multiple API keys to be set

---
 config.sample.php  |  5 ++++-
 src/UNL/Search.php | 23 +++++++++++++++++++++--
 www/index.php      |  3 ++-
 3 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/config.sample.php b/config.sample.php
index c5d4ee2..e6959a9 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 c72f30a..5b0ad20 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 1f7e584..4d1aa52 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" />
-- 
GitLab