Commit b7e7d601 authored by Kevin Abel's avatar Kevin Abel
Browse files

Load the default (UNL) template regions on local site scrape failure

parent 96075f72
......@@ -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'])) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment