Location: PHPKode > projects > VideoDB > videodb/lookup.php
<?php
/**
 * IMDB lookup popup
 *
 * Popup to search at IMDB
 *
 * @package videoDB
 * @author  Andreas Gohr    <hide@address.com>
 * @author  Andreas Goetz   <hide@address.com>
 * @version $Id: lookup.php,v 2.27 2008/01/08 18:04:20 andig2 Exp $
 */
 
require_once './core/functions.php';
require_once './engines/engines.php';
require_once './engines/imdb.php';

/**
 * Update item list asynchronously
 *
 * @author  Andreas Goetz   <hide@address.com>
 */ 
function ajax_render()
{
    global $smarty, $result;

    // 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',  null, null, false);

    header('X-JSON: '.json_encode(array('count' => count($result))));
    echo $content;
    
    exit;
}

// filter relevant search engines
$engines = $config['engine'];

if ($searchtype == 'image')
{
    // limit to engines capable of image search
    $engines = array_intersect_assoc($engines, array('amazonxml'=>1, 'amazona2s'=>1, 'google'=>1));   // function PHP>=4.3.0
}
else
{
    // Google is not capable of movie searches
    unset($engines['google']);
}

// 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 = 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 'amazonxml':
                    // amazonxml
                    require_once('engines/'.$engine.'.php');
                    
                    $smarty->assign('catalog', array('books','music','classical','dvd','vhs'));
                    if (empty($catalog)) $catalog = 'dvd';    // default amazonxml searchmode
                    $smarty->assign('selectedcatalog', $catalog);
                    
                    $smarty->assign('area', array('US','UK','DE','JP'));
                    if (empty($area)) $area = 'US';                 // default amazonxml search area
                    $smarty->assign('selectedarea', $area);

                    if (!empty($find))
                    {
                        $result     = engineSearch($find, $engine, $catalog, $area);  // catalog and are are only used by amazonxml
                        $searchurl  = amazonxmlSearchUrl($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);
                    }
}

#dump($result);
#if ($result[0]['details']) dump($result);

// process asynchronous refresh
if ($ajax_render)
{
    $smarty->assign('imdbresults', $result);
    ajax_render();
}

// prepare templates
tpl_language();
tpl_header();

$smarty->assign('engines',  engineGetLookup($find, $searchtype, $engine));
$smarty->assign('engine',   $engine);
$smarty->assign('searchurl',    $searchurl);
$smarty->assign('searchtype',   $searchtype);

$smarty->assign('find', $find);
$smarty->assign('q_find', formvar($find));
$smarty->assign('imdbresults', $result);
$smarty->assign('http_error', $CLIENTERROR);

// display templates
smarty_display('lookup.tpl');

?>
Return current item: VideoDB