From 7cb4d6e476597bbfb71fc4e20e7cf9bf51c0d617 Mon Sep 17 00:00:00 2001
From: Kevin Abel <kevin.abel.0@gmail.com>
Date: Thu, 17 Apr 2014 17:06:10 -0500
Subject: [PATCH] Add methods to UNL_Search class to support more config

Also pulls bootstrap logic into class methods.
---
 src/UNL/Search.php | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/src/UNL/Search.php b/src/UNL/Search.php
index 5b0ad20..1f718e6 100644
--- a/src/UNL/Search.php
+++ b/src/UNL/Search.php
@@ -7,6 +7,10 @@ class UNL_Search
      * @var array
      */
     public static $jsapiKeys = array();
+    
+    public static $mode = 'production';
+    
+    public static $linkedCSEServer = 'http://www1.unl.edu/search/linkedcse/';
 
     function __construct()
     {
@@ -49,13 +53,36 @@ class UNL_Search
         }
         return $html;
     }
+    
+    /**
+     * Returns a UNL_Templates_Scanner of the given URL or false on failure
+     *
+     * @param string $referrer
+     * @return boolean|UNL_Templates_Scanner
+     */
+    public static function getScannedPage($referrer)
+    {
+        if ($referrer == 'http://www.unl.edu' ||
+            !preg_match('/^https?/', $referrer) ||
+            !filter_var($referrer, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED)
+        ) {
+            return false;
+        }
+        
+        $scanned = @file_get_contents($referrer);
+        if (!$scanned) {
+            return false;
+        }
+        
+        return new UNL_Templates_Scanner($scanned);
+    }
 
     /**
      * Return an API key
      *
      * @return string
      */
-    function getJSAPIKey()
+    public static function getJSAPIKey()
     {
         if (empty(self::$jsapiKeys)) {
             return '';
@@ -65,4 +92,8 @@ class UNL_Search
         return self::$jsapiKeys[0];
     }
 
+    public static function getLinkedCSEUrl($referrer)
+    {
+        return self::$linkedCSEServer . '?u=' . urlencode($referrer);
+    }
 }
-- 
GitLab