-
Notifications
You must be signed in to change notification settings - Fork 42
/
lookup.php
115 lines (93 loc) · 3.21 KB
/
lookup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/**
* IMDB lookup popup
*
* Popup to search at IMDB
*
* @package videoDB
* @author Andreas Gohr <[email protected]>
* @author Andreas Goetz <[email protected]>
* @version $Id: lookup.php,v 2.33 2010/04/04 10:33:56 andig2 Exp $
*/
require_once './core/functions.php';
require_once './engines/engines.php';
require_once './engines/imdb.php';
/**
* Update item list asynchronously
*
* @author Andreas Goetz <[email protected]>
*/
function ajax_render()
{
global $smarty, $result, $config;
// add some delay for debugging
if ($config['debug'] && $_SERVER['SERVER_ADDR'] == '127.0.0.1') usleep(rand(200,1000)*1000);
// load languages and config into Smarty
tpl_language();
$content = $smarty->fetch('lookup_ajax.tpl');
header('X-JSON: '.json_encode(array('count' => count($result))));
exit($content);
}
/**
* input
*/
$engine = req_string('engine');
$find = req_string('find');
$catalog = req_string('catalog');
$searchaka = req_int('searchaka');
$searchtype = req_string('searchtype');
$ajax_render = req_int('ajax_render');
$CLIENTERROR = null;
// determine default engine (first in list)
if (empty($engine)) $engine = engineGetDefault();
// result array
$result = array();
// Undo url encoding. At this point we cannot be sure which encoding is present- either ISO from URL or UTF-8 from form subimssion. Make sure we have unicode again.
$find = html_entity_decode_all(urldecode($find));
if (!is_utf8($find)) $find = utf8_encode($find);
switch ($engine)
{
case 'amazona2s':
// amazona2s
$smarty->assign('catalog', array('Books','Classical','DigitalMusic','DVD','Electronics','Magazines','Music','MusicTracks','UnboxVideo','VHS','Video','VideoGames'));
if (empty($catalog)) $catalog = 'DVD';
$smarty->assign('selectedcatalog', $catalog);
if (!empty($find))
{
$result = engineSearch($find, $engine, $catalog);
$searchurl = engineGetSearchUrl($find, $engine);
}
break;
case 'imdb':
// imdb
$smarty->assign('searchaka', $searchaka);
if (!empty($find))
{
$result = engineSearch($find, $engine, $searchaka);
$searchurl = engineGetSearchUrl($find, $engine);
}
break;
default:
// tvcom, amazon, google
if (!empty($find))
{
$result = engineSearch($find, $engine);
$searchurl = engineGetSearchUrl($find, $engine);
}
}
$smarty->assign('searchtype', $searchtype);
$smarty->assign('imdbresults', $result);
// process asynchronous refresh
if ($ajax_render)
{
ajax_render();
}
// prepare templates
tpl_language();
tpl_header();
// prepare template with selected and available engines
tpl_lookup($find, $engine, $searchtype);
$smarty->assign('searchurl', $searchurl);
$smarty->assign('http_error', $CLIENTERROR);
// display templates
smarty_display('lookup.tpl');