Skip to content
Snippets Groups Projects
Forked from Digital Experience Group / UNL_Search
218 commits behind the upstream repository.
index.php 4.61 KiB
<?php

require_once dirname(__FILE__).'/../config.sample.php';

UNL_Templates::$options['version'] = 3;

$template = 'Fixed';

if (isset($_GET['format'])
    && $_GET['format'] == 'mobile') {
    $template = 'Mobile';
}

$page = UNL_Templates::factory($template);
$page->doctitle = '<title>UNL | Search</title>';
$local_results = '';
$page->head .= '
<script src="http://www.google.com/jsapi?key=ABQIAAAAfxH7RKwDLHYhDD9dSUZe-RTELkNjcWhKXky6vQZrvQAPA5Uw6xR-eQp2X1fKnLG-UqeKQ_7mwv5CcQ" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="http://directory.unl.edu/css/peoplefinder_default.css" />
<link rel="stylesheet" type="text/css" href="searchCSS.css" />
';
if ($template == 'Mobile') {
    $page->head .='<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" >
    <script type="text/javascript">var mobileSearch = true;</script>';
} else {
    $page->head .='<script type="text/javascript">var mobileSearch = false;</script>';
}
$page->addScript('searchFunc.js');

if (isset($_GET['u']) //u is referring site
    && preg_match('/^https?/', $_GET['u'])
    && filter_var($_GET['u'], FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED)
    && $scanned = @file_get_contents($_GET['u'])) {
    // Add local site search results
    $scanned = new UNL_Templates_Scanner($scanned);
    if (isset($scanned->navlinks)) { //we're scrapping the navigation and other content from the originatting site.
        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($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($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 = '"'.htmlentities($_GET['cx'], ENT_QUOTES).'"';
    } else {
        // Auto-build a custom search engine
        $context = '{crefUrl :"http://www1.unl.edu/search/linkedcse/?u='.$_GET['u'].'"}';
    }
    $page->addScriptDeclaration('
        UNL_Search.do_local_search = true;
        UNL_Search.local_search_context = '.$context.';
    ');
    $local_results = '
    <h3 class="sec_header">Local Results</h3>
    <div id="local_results"></div>';
} else {
    // Default search for no referring site.
    $page->titlegraphic = '<h1>UNL Search</h1>';
    $page->addScriptDeclaration('UNL_Search.do_local_search = false;');
    $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   = file_get_contents('http://www.unl.edu/ucomm/sharedcode/footerContactInfo.html');
    $page->footercontent = file_get_contents('http://www.unl.edu/ucomm/sharedcode/footer.html');

}


$page->maincontentarea = '
<div id="searchform">
  <form action="http://www1.unl.edu/search/" method="get">
      <label for="q">Search</label>
    <input type="text" name="q" id="q" />';
if (!empty($local_results)) {
    $page->maincontentarea .= '<input type="hidden" name="u" value="'.htmlentities($_GET['u'], ENT_QUOTES).'" />';
}
$page->maincontentarea .= '
    <input type="submit" value="Search" />
  </form>
  <noscript>
    <form action="http://www.googlesyndicatedsearch.com/u/UNL1" method="get">
        <input style="width:90%" type="text" name="q" />
        <input type="submit" value="Search" />
    </form>
  </noscript>
</div>
<div class="three_col left">
    '.$local_results.'
    <h3 class="sec_header">UNL Web</h3>
    <div id="unl_results"></div>
</div>
<div class="col right">
    <h3 class="sec_header">UNL Directory</h3>
    <div id="ppl_results"></div>
    <a href="http://www1.unl.edu/wdn/wiki/About_Peoplefinder">About the UNL Directory</a>
</div>
';
echo $page;

?>