<?php
/**
*
* @author Benjamin Gillissen <hide@address.com>
*
* **************************************************************
Copyright (C) 2009 Benjamin Gillissen
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details at:
http://www.gnu.org/copyleft/gpl.html
* **************************************************************
*/
class ajx_tt_imdb extends ajax {
public static function tt_imdb($id, $dest){
parent::$CB = __FUNCTION__;
$cachetype = configs::get('newzbinv2', 'cachetype');
$class = 'nb_cache_'.$cachetype;
$cache = new $class();
if ( FALSE === $cache->iscached('imdb', $id) ){
$p = CORE::getdeps(PATH_LIBS, 'imdb', NULL, NULL, 'pl');
if ( FALSE === $p ){
parent::addAssign("tooltip_imdb_".$dest, "innerHTML", "imDB Perl script not found in libs !");
return parent::getReply();
}
if ( FALSE === is_executable($p) ){
parent::addAssign("tooltip_imdb_".$dest, "innerHTML", "imDB Perl script is not executable !");
return parent::getReply();
}
$cmd=escapeshellcmd("$p -D $id");
$o = shell_exec($cmd);
if ( empty($o) ){
parent::addAssign("tooltip_imdb_".$dest, "innerHTML", "imDB Perl script returned nothing for `$cmd`.");
return parent::getReply();
}
$cache->import_imdb($id, $o);
}
$infos = Array('Title', 'Year', 'Director', 'Plot', 'UserRating', 'MovieRating', 'Runtime', 'Writers', 'Cast', 'Genres', 'Countries');
$match = "#";
foreach($infos as $k => $val){ $match .= "($val:)([\w\W]+?)"; }
$match .= "#";
$o = $cache->read_imdb($id);
$tot = preg_match_all($match, $o, $result);
if ( $tot !== 0 ){
foreach($infos as $k => $val){ $data[$val] = $result[($k+1)*2][0]; }
$data['rating'] = 10 * $data['UserRating'];
$tpl = new template();
if ( FALSE === $tpl->load_file('pages/search/tooltip_imdb.tpl') ){
parent::addAssign("tooltip_imdb_".$dest, "innerHTML", $o);
return parent::getReply();
}
$tpl->setdata($data);
parent::addAssign("tooltip_imdb_".$dest, "innerHTML", $tpl->parse(TRUE) );
} else {
parent::addAssign("tooltip_imdb_".$dest, "innerHTML", "Error parsing imDB Perl script result for `$id`.");
}
unset($cache);
parent::addScript("tooltip_update('imdb', '$dest')");
return parent::getReply();
}
public static function imdbdata_old($id, $dest){
parent::$CB = __FUNCTION__;
$cache = new file_cache('nb_imdb');
if ( $cache->isexpired($id) ){
$p = CORE::getdeps(PATH_LIBS, 'imdb', NULL, NULL, 'pl');
if ( FALSE === $p ){
parent::addAssign("tooltip_imdb_".$dest, "innerHTML", "imDB Perl script not found in libs !");
return parent::getReply();
}
if ( FALSE === is_executable($p) ){
parent::addAssign("tooltip_imdb_".$dest, "innerHTML", "imDB Perl script is not executable !");
return parent::getReply();
}
$cmd=escapeshellcmd("$p -D $id");
$o = shell_exec($cmd);
if ( empty($o) ){
parent::addAssign("tooltip_imdb_".$dest, "innerHTML", "imDB Perl script returned nothing for `$cmd`.");
return parent::getReply();
}
$cache->import_data($id);
}
$infos = Array('Title', 'Year', 'Director', 'Plot', 'UserRating', 'MovieRating', 'Runtime', 'Writers', 'Cast', 'Genres', 'Countries');
$match = "#";
foreach($infos as $k => $val){ $match .= "($val:)([\w\W]+?)"; }
$match .= "#";
$o = $cache->readfile($cache->getpath($id));
$tot = preg_match_all($match, $o, $result);
if ( $tot !== 0 ){
foreach($infos as $k => $val){ $data[$val] = $result[($k+1)*2][0]; }
$data['rating'] = 10 * $data['UserRating'];
$tpl = new template();
if ( FALSE === $tpl->load_file('pages/search/tooltip_imdb.tpl') ){
parent::addAssign("tooltip_imdb_".$dest, "innerHTML", $o);
return parent::getReply();
}
$tpl->setdata($data);
parent::addAssign("tooltip_imdb_".$dest, "innerHTML", $tpl->parse(TRUE) );
} else {
parent::addAssign("tooltip_imdb_".$dest, "innerHTML", "Error parsing imDB Perl script result for `$cmd`.");
}
unset($cache);
return parent::getReply();
}
}