Skip to content
Snippets Groups Projects
Select Git revision
  • optimize-images
  • 5.0
  • master default protected
  • 4.1
4 results

index.php

Blame
  • Forked from Digital Experience Group / UNL_Search
    196 commits behind the upstream repository.
    index.php 5.00 KiB
    <?php
    
    require_once dirname(__FILE__).'/../config.sample.php';
    
    UNL_Templates::setCachingService(new UNL_Templates_CachingService_Null());
    
    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->addScript('http://www.google.com/jsapi' . (empty(UNL_Search::$jsapiKey) ? '' : '?key=' . UNL_Search::$jsapiKey));
    $page->head .= '
    <link rel="stylesheet" href="http://www.google.com/cse/style/look/default.css" type="text/css" />
    <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
        && $_GET['u'] !== 'http://www.unl.edu/'
        && 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" class="google-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="./" method="get">
          <fieldset>
          <div class="grid10 first">
              <label for="q">Search</label>
              <input class="search-query" type="text" name="q" id="search_q" title="search" />';
    if (!empty($local_results)) {
        $page->maincontentarea .= '<input type="hidden" name="u" value="'.htmlentities($_GET['u'], ENT_QUOTES).'" />';
    }
    $page->maincontentarea .= '
          </div>
          <div class="grid2">
              <input class="search-button" title="search" type="submit" value="Search" />
          </div>
          </fieldset>
      </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="grid8 first">
        '.$local_results.'
        <h3 class="sec_header">UNL Web</h3>
        <div id="unl_results" class="google-results"></div>
    </div>
    <div class="grid4">
        <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;
    
    ?>