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

Brett Bieber's avatar
Brett Bieber committed
3
4
5
6
7
8
$config_file = __DIR__ . '/../config.sample.php';

if (file_exists(__DIR__ . '/../config.inc.php')) {
    $config_file = __DIR__ . '/../config.inc.php';
}
require_once $config_file;
9

10
11
UNL_Templates::setCachingService(new UNL_Templates_CachingService_Null());

12
UNL_Templates::$options['version'] = 3.1;
13

14
15
16
17
18
19
20
$template = 'Fixed';

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

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

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

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

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

97
98
99
100
101
}


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

133
?>