From b7e7d601a0fd6bc073d5feed8d56e7a0dde19897 Mon Sep 17 00:00:00 2001
From: Kevin Abel <kevin.abel.0@gmail.com>
Date: Wed, 23 Apr 2014 10:23:07 -0500
Subject: [PATCH] Load the default (UNL) template regions on local site scrape
 failure

---
 www/index.php | 54 +++++++++++++++++++++++++++++++--------------------
 1 file changed, 33 insertions(+), 21 deletions(-)

diff --git a/www/index.php b/www/index.php
index c9dcf2a..1b70b34 100644
--- a/www/index.php
+++ b/www/index.php
@@ -13,6 +13,16 @@ function renderTemplate($file, $params = array())
     include $file;
 }
 
+function loadDefaultSections($page)
+{
+    $page->titlegraphic = 'UNL Search';
+    $page->breadcrumbs   = str_replace('Department', 'Search', $page->breadcrumbs);
+    $page->navlinks      = file_get_contents('http://www.unl.edu/ucomm/sharedcode/navigation.html');
+    $page->leftcollinks  = file_get_contents('http://www.unl.edu/ucomm/sharedcode/relatedLinks.html');
+    $page->contactinfo   = preg_replace('#<h3>.*</h3>#', '', file_get_contents('http://www.unl.edu/ucomm/sharedcode/footerContactInfo.html'));
+    $page->footercontent = file_get_contents('http://www.unl.edu/ucomm/sharedcode/footer.html');
+}
+
 $isEmbed = isset($_GET['embed']) && $_GET['embed'];
 
 UNL_Templates::setCachingService(new UNL_Templates_CachingService_Null());
@@ -58,21 +68,28 @@ $page->addStyleSheet('css/search.css');
 if (isset($_GET['u']) && $scanned = UNL_Search::getScannedPage($_GET['u'])) { 
     // Add local site search results
     // we're scrapping the navigation and other content from the originatting site.
-    if (!$isEmbed && isset($scanned->titlegraphic)) { 
-        require_once 'HTMLPurifier.auto.php';
-        $config = HTMLPurifier_Config::createDefault();
-        $config->set('Cache.SerializerPath', '/tmp');
-        $purifier = new HTMLPurifier($config);
-
-        $page->head        .= '<link rel="home" href="'.htmlentities($_GET['u'], ENT_QUOTES).'" />';
-        $page->breadcrumbs  = $purifier->purify(UNL_Search::removeRelativePaths($scanned->breadcrumbs, $_GET['u']));
-        $page->titlegraphic = $purifier->purify(str_replace(array('<h1>', '</h1>'), '',$scanned->titlegraphic));
-        $page->navlinks     = $purifier->purify(UNL_Search::removeRelativePaths($scanned->navlinks, $_GET['u']));
-        if (!empty($scanned->contactinfo)) {
-            $page->contactinfo = $purifier->purify(preg_replace('#<h3>.*</h3>#', '', $scanned->contactinfo));
-        }
-        if (!empty($scanned->footercontent)) {
-            $page->footercontent = $purifier->purify($scanned->footercontent);
+    if (!$isEmbed) {
+        if (isset($scanned->titlegraphic)) { 
+            require_once 'HTMLPurifier.auto.php';
+            $config = HTMLPurifier_Config::createDefault();
+            $config->set('Cache.SerializerPath', '/tmp');
+            $purifier = new HTMLPurifier($config);
+    
+            $page->head        .= '<link rel="home" href="'.htmlentities($_GET['u'], ENT_QUOTES).'" />';
+            $page->breadcrumbs  = $purifier->purify(UNL_Search::removeRelativePaths($scanned->breadcrumbs, $_GET['u']));
+            $page->titlegraphic = $purifier->purify(str_replace(array('<h1>', '</h1>'), '',$scanned->titlegraphic));
+            $page->navlinks     = $purifier->purify(UNL_Search::removeRelativePaths($scanned->navlinks, $_GET['u']));
+            if (!empty($scanned->leftcollinks)) {
+                $page->leftcollinks = $purifier->purify($scanned->leftcollinks);
+            }
+            if (!empty($scanned->contactinfo)) {
+                $page->contactinfo = $purifier->purify(preg_replace('#<h3>.*</h3>#', '', $scanned->contactinfo));
+            }
+            if (!empty($scanned->footercontent)) {
+                $page->footercontent = $purifier->purify($scanned->footercontent);
+            }
+        } else {
+            loadDefaultSections($page);
         }
     }
 
@@ -94,12 +111,7 @@ if (isset($_GET['u']) && $scanned = UNL_Search::getScannedPage($_GET['u'])) {
     $local_results = ob_get_clean();
 } elseif (!$isEmbed) {
     // Default search for no referring site.
-    $page->titlegraphic = 'UNL Search';
-    $page->breadcrumbs   = str_replace('Department', 'Search', $page->breadcrumbs);
-    $page->navlinks      = file_get_contents('http://www.unl.edu/ucomm/sharedcode/navigation.html');
-    $page->leftcollinks  = file_get_contents('http://www.unl.edu/ucomm/sharedcode/relatedLinks.html');
-    $page->contactinfo   = preg_replace('#<h3>.*</h3>#', '', file_get_contents('http://www.unl.edu/ucomm/sharedcode/footerContactInfo.html'));
-    $page->footercontent = file_get_contents('http://www.unl.edu/ucomm/sharedcode/footer.html');
+    loadDefaultSections($page);
 }
 
 if (isset($_GET['q'])) {
-- 
GitLab