Newer
Older
$config_file = __DIR__ . '/../config.sample.php';
if (file_exists(__DIR__ . '/../config.inc.php')) {
$config_file = __DIR__ . '/../config.inc.php';
}
function renderTemplate($file, $params = array())
{
extract($params);
include $file;
}
$isEmbed = isset($_GET['embed']) && $_GET['embed'];
UNL_Templates::setCachingService(new UNL_Templates_CachingService_Null());
UNL_Templates::$options['version'] = 4.0;
if (UNL_Search::$mode === 'debug') {
$page = UNL_Templates::factory('Local');
$page->addScript('js/search.js');
} else {
$page = UNL_Templates::factory('Fixed');
$page->addScript('js/search.min.js');
}
if (!$isEmbed) {
$page->doctitle = '<title>Search | University of Nebraska–Lincoln</title>';
$page->pagetitle = '';
ob_start();
renderTemplate('templates/breadcrumbs.tpl.php');
$page->breadcrumbs = ob_get_clean();
}
$inlineJS = '';
$params = array(
'autoload' => json_encode(array('modules' => array(
array(
'name' => 'search',
'version' => '1.0',
'callback' => 'searchInit',
'style' => '//www.google.com/cse/style/look/v2/default.css'
),
))),
);
if (!empty($apiKey)) {
$params['key'] = $apiKey;
Seth Meranda
committed
}
$page->addScript('//www.google.com/jsapi?' . http_build_query($params));
$page->addStyleSheet('css/search.css');
//u is referring site
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 (isset($_GET['cx'])) {
// Use their custom search engine instead of the linked one.
$context = $_GET['cx'];
} else {
// Auto-build a custom search engine
$context = array('crefUrl' => UNL_Search::getLinkedCSEUrl($_GET['u']));
$context = json_encode($context);
$inlineJS .= "var LOCAL_SEARCH_CONTEXT = {$context};\n";
ob_start();
renderTemplate('templates/google-results.tpl.php', array(
'title' => $page->titlegraphic,
'id' => 'local_results',
));
$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');
if (isset($_GET['q'])) {
$q = json_encode($_GET['q']);
$inlineJS .= "var INITIAL_QUERY = {$q};\n";
$page->addScriptDeclaration($inlineJS);
ob_start();
if (!$isEmbed) {
renderTemplate('templates/search-form.tpl.php', array('local_results' => $local_results));
}
renderTemplate('templates/search-results.tpl.php', array(
'isEmbed' => $isEmbed,
'local_results' => $local_results
));
$maincontent = ob_get_clean();
if (!$isEmbed) {
$page->maincontentarea = $maincontent;
echo $page;
} else {
if (UNL_Search::$mode === 'debug') {
$template = 'templates/embed-debug.tpl.php';
} else {
$template = 'templates/embed.tpl.php';
}
renderTemplate($template, array(
'head' => $page->head,
'maincontent' => $maincontent
));