index.php 5.21 KB
Newer Older
1
2
<?php

Brett Bieber's avatar
Brett Bieber committed
3
require_once dirname(__FILE__).'/../config.sample.php';
4

5
6
UNL_Templates::setCachingService(new UNL_Templates_CachingService_Null());

7
UNL_Templates::$options['version'] = 3.1;
8

9
10
11
12
13
14
15
$template = 'Fixed';

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

16
$page = UNL_Templates::factory('Fixed');
17
$page->doctitle = '<title>UNL | Search</title>';
18
19
20
21
22
23
$page->pagetitle = '';
$page->breadcrumbs = '
<ul>
    <li><a href="http://www.unl.edu/" title="University of Nebraska&ndash;Lincoln">UNL</a></li>
    <li>Search</li>
</ul>';
24
$local_results = '';
Brett Bieber's avatar
Brett Bieber committed
25
26
$apiKey = UNL_Search::getJSAPIKey();
$page->addScript('http://www.google.com/jsapi' . (empty($apiKey) ? '' : '?key=' . $apiKey));
27
$page->head .= '
28
<link rel="stylesheet" href="http://www.google.com/cse/style/look/default.css" type="text/css" />
29
<link rel="stylesheet" type="text/css" href="http://directory.unl.edu/css/result_lists.css" />
30
<link rel="stylesheet" type="text/css" href="searchCSS.css" />
31
';
32
if ($template == 'Mobile') {
Brett Bieber's avatar
Brett Bieber committed
33
34
    $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>';
35
} else {
Brett Bieber's avatar
Brett Bieber committed
36
    $page->head .='<script type="text/javascript">var mobileSearch = false;</script>';
37
}
38
39
$page->addScript('searchFunc.js');

40
if (isset($_GET['u']) //u is referring site
41
    && $_GET['u'] !== 'http://www.unl.edu/'
42
43
44
    && preg_match('/^https?/', $_GET['u'])
    && filter_var($_GET['u'], FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED)
    && $scanned = @file_get_contents($_GET['u'])) {
45
    // Add local site search results
46
    $scanned = new UNL_Templates_Scanner($scanned);
47
    if (isset($scanned->navlinks)) { //we're scrapping the navigation and other content from the originatting site.
48
49
50
51
        require_once 'HTMLPurifier.auto.php';
        $config = HTMLPurifier_Config::createDefault();
        $config->set('Cache.SerializerPath', '/tmp');
        $purifier = new HTMLPurifier($config);
52

53
54
        $page->head        .= '<link rel="home" href="'.htmlentities($_GET['u'], ENT_QUOTES).'" />';
        $page->breadcrumbs  = $purifier->purify(UNL_Search::removeRelativePaths($scanned->breadcrumbs, $_GET['u']));
55
        $page->titlegraphic = $purifier->purify(str_replace(array('<h1>', '</h1>'), '',$scanned->titlegraphic));
56
57
58
59
60
61
62
        $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);
        }
63
64
65
        if (!empty($scanned->footercontent)) {
            $page->footercontent = $purifier->purify($scanned->footercontent);
        }
66
    }
67

68
69
    if (isset($_GET['cx'])) {
        // Use their custom search engine instead of the linked one.
Brett Bieber's avatar
Brett Bieber committed
70
        $context = '"'.htmlentities($_GET['cx'], ENT_QUOTES).'"';
71
72
73
74
    } else {
        // Auto-build a custom search engine
        $context = '{crefUrl :"http://www1.unl.edu/search/linkedcse/?u='.$_GET['u'].'"}';
    }
75
    $page->addScriptDeclaration('
Brett Bieber's avatar
Brett Bieber committed
76
        UNL_Search.do_local_search = true;
77
        UNL_Search.local_search_context = '.$context.';
Brett Bieber's avatar
Brett Bieber committed
78
    ');
79
80
    $local_results = '
    <h3 class="sec_header">Local Results</h3>
81
    <div id="local_results" class="google-results"></div>';
82
83
84
85
} else {
    // Default search for no referring site.
    $page->titlegraphic = '<h1>UNL Search</h1>';
    $page->addScriptDeclaration('UNL_Search.do_local_search = false;');
Brett Bieber's avatar
Brett Bieber committed
86
87
88
89
90
    $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');
91

92
93
94
95
96
}


$page->maincontentarea = '
<div id="searchform">
97
  <form action="./" method="get">
98
99
100
101
      <fieldset>
      <div class="grid10 first">
          <label for="q">Search</label>
          <input class="search-query" type="text" name="q" id="search_q" title="search" />';
102
103
104
105
if (!empty($local_results)) {
    $page->maincontentarea .= '<input type="hidden" name="u" value="'.htmlentities($_GET['u'], ENT_QUOTES).'" />';
}
$page->maincontentarea .= '
106
107
108
109
110
      </div>
      <div class="grid2">
          <input class="search-button" title="search" type="submit" value="Search" />
      </div>
      </fieldset>
111
112
113
114
115
116
117
118
  </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>
119
<div class="grid8 first">
120
121
    '.$local_results.'
    <h3 class="sec_header">UNL Web</h3>
122
    <div id="unl_results" class="google-results"></div>
123
</div>
124
<div class="grid4">
125
126
127
128
    <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>
129
130
131
';
echo $page;

132
?>