* @package Kernel
* @version $Id$
*/
?>
cache_folder = "../" . $this->cache_folder;
$this->cache_time = VCDConfig::getRSSCacheTimeout();
$this->site_rss = SettingsServices::getSettingsByKey('RSS_SITE');
$this->user_rss = SettingsServices::getSettingsByKey('RSS_USERS');
$this->baseurl = SettingsServices::getSettingsByKey('SITE_HOME');
$pObj = UserServices::getPropertyByKey('RSS');
if ($pObj instanceof userPropertiesObj) {
$this->rssUsers = UserServices::getAllUsersWithProperty($pObj->getpropertyID());
}
}
/**
* Get paths to all users with RSS enabled on their movie list
*
* @return string
*/
public function getRSSUsers() {
if (($this->user_rss) && (sizeof($this->rssUsers) > 0)) {
$xml = "rss_encoding}\"?>\n";
$xml .= "";
$xml .= "".$this->baseurl."";
$xml .= "";
foreach ($this->rssUsers as $user) {
$xml .= "";
$xml .= "".$user->getUsername()."";
$xml .= "".$user->getFullname()."";
$xml .= "".$this->baseurl."rss/?rss=".$user->getUsername()."";
$xml .= "";
}
$xml .= "";
$xml .= "";
return $xml;
} else {
$xml = "rss_encoding}\"?>\n";
$xml .= "No users sharing RSS feeds";
return $xml;
}
}
/**
* Get single RSS feed by user name
*
* @param string $user_name
* @return string
*/
public function getRSSbyUser($user_name) {
if ($this->site_rss && $this->user_rss && $this->isValidUser($user_name)) {
// Check for cached feed if cache is enabled.
$usecache = false;
if ($this->use_cache && strcmp($this->cache_folder, "") != 0) {
$usecache = true;
$cache_file = $this->cache_folder . 'vcddbrss_' . md5($user_name);
$timedif = @(time() - filemtime($cache_file));
if ($timedif < $this->cache_time) {
// cached file is fresh enough, return cached array
$xml = unserialize(join('', file($cache_file)));
return $xml;
}
}
$builddate = date("r", time());
$xml = "rss_encoding}\"?>\n";
$xml .= "rss_version."\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n";
$xml .= "\n";
$xml .= "".htmlspecialchars(SettingsServices::getSettingsByKey('SITE_NAME'), ENT_QUOTES)." (".$user_name.")\n";
$xml .= "".$this->baseurl."\n";
$xml .= "VCD-db movie list\n";
$xml .= "en-us\n";
$xml .= "{$builddate}\n";
$xml .= "VCD-db ".VCDDB_VERSION."\n";
$xml .= "\n".$this->baseurl."images/logo.gif\nVCD-db\n{$this->baseurl}\n\n";
$uobj = UserServices::getUserByUsername($user_name);
$movies = MovieServices::getLatestVcdsByUserID($uobj->getUserID(),10, true);
if (sizeof($movies) > 0) {
foreach ($movies as $smallMovie) {
$movie = MovieServices::getVcdByID($smallMovie->getID());
$arr = $movie->getRSSData();
$xml .= "- \n";
$xml .= "".htmlspecialchars($movie->getTitle(),ENT_QUOTES)."\n";
if (VCDConfig::isUsingFriendlyUrls()) {
$xml .= "".$this->baseurl."movie/".$movie->getID()."\n";
} else {
$xml .= "".$this->baseurl."?page=cd&vcd_id=".$movie->getID()."\n";
}
$xml .= "".htmlspecialchars($arr['description'],ENT_QUOTES)."\n";
$xml .= "".htmlspecialchars($arr['creator'],ENT_QUOTES)."\n";
$xml .= "".htmlspecialchars(date('c', $arr['date']),ENT_QUOTES)."\n";
$xml .= "
\n";
}
}
$xml .= "\n";
$xml .= "\n";
// Check if we need to write the results to cache because the existing one was to old.
if ($usecache) {
$serialized = serialize($xml);
if ($f = @fopen($cache_file, 'w')) {
fwrite ($f, $serialized, strlen($serialized));
fclose($f);
}
}
return $xml;
} else {
$xml = "rss_encoding}\"?>\n";
$xml .= "Invalid username";
return $xml;
}
}
/**
* Get the sites RSS feed
*
* @return string
*/
public function getSiteRss() {
if ($this->site_rss) {
// Check for cached feed if cache is enabled.
$usecache = false;
if ($this->use_cache && strcmp($this->cache_folder, "") != 0) {
$usecache = true;
$cache_file = $this->cache_folder . 'vcddbrss_' . md5($this->baseurl);
$timedif = @(time() - filemtime($cache_file));
if ($timedif < $this->cache_time) {
// cached file is fresh enough, return cached array
$xml = unserialize(join('', file($cache_file)));
return $xml;
}
}
$sInfo = VCDConnection::getServerInfo();
$db_env = DB_TYPE . " - " . $sInfo['description'];
$builddate = date("r", time());
$xml = "rss_encoding}\"?>\n";
$xml .= "rss_version."\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n";
$xml .= "\n";
$xml .= "".htmlspecialchars(SettingsServices::getSettingsByKey('SITE_NAME'),ENT_QUOTES)."\n";
$xml .= "".$this->baseurl."\n";
$xml .= "VCD-db Movie List\n";
$xml .= "en-us\n";
$xml .= "{$builddate}\n";
$xml .= "VCD-db ".VCDDB_VERSION." ({$db_env})\n";
$xml .= "\n".$this->baseurl."images/logo.gif\nVCD-db\n{$this->baseurl}\n\n";
$movies = MovieServices::getTopTenList();
if (sizeof($movies) > 0) {
foreach ($movies as $smallMovie) {
$movie = MovieServices::getVcdByID($smallMovie->getID());
$arr = $movie->getRSSData();
$xml .= "- \n";
$xml .= "".htmlspecialchars($movie->getTitle(),ENT_QUOTES)."\n";
if (VCDConfig::isUsingFriendlyUrls()) {
$xml .= "".$this->baseurl."movie/".$movie->getID()."\n";
} else {
$xml .= "".$this->baseurl."?page=cd&vcd_id=".$movie->getID()."\n";
}
$xml .= "".htmlspecialchars($arr['description'],ENT_QUOTES)."\n";
$xml .= "".htmlspecialchars($arr['creator'],ENT_QUOTES)."\n";
$xml .= "".htmlspecialchars(date('c', $arr['date']),ENT_QUOTES)."\n";
$xml .= "
\n";
}
}
$xml .= "\n";
$xml .= "\n";
// Check if we need to write the results to cache because the existing one was to old.
if ($usecache) {
$serialized = serialize($xml);
if ($f = @fopen($cache_file, 'w')) {
fwrite ($f, $serialized, strlen($serialized));
fclose($f);
}
}
return $xml;
} else {
$xml = "rss_encoding}\"?>\n";
$xml .= "";
$xml .= "RSS disabled by administrator";
$xml .= "";
return $xml;
}
}
public function getRemoteVcddbFeed($name, $url) {
try {
// Check for cached feed if cache is enabled.
$this->cache_folder = CACHE_FOLDER;
$xmlLoaded = false;
if ($this->use_cache && strcmp($this->cache_folder, "") != 0) {
$cache_file = $this->cache_folder . 'vcddbrss_' . md5($url);
$timedif = @(time() - filemtime($cache_file));
if ($timedif < $this->cache_time) {
// cached file is fresh enough
$xml = unserialize(join('', file($cache_file)));
$xmlLoaded = true;
}
}
if ($xmlLoaded) {
$xml = simplexml_load_string($xml);
} else {
$xml = @simplexml_load_file($url);
}
if (!is_object($xml)) {
return null;
}
// Check if we need to write the results to cache because the existing one was to old.
if ($this->use_cache && !$xmlLoaded) {
$serialized = serialize($xml->asXML());
if ($f = @fopen($cache_file, 'w')) {
fwrite ($f, $serialized, strlen($serialized));
fclose($f);
}
}
return $xml;
} catch (Exception $ex) {
throw $ex;
}
}
/**
* Check if requested user name is valid
*
* @param string $username
* @return bool
*/
private function isValidUser($username) {
foreach ($this->rssUsers as $user) {
if (strcmp($user->getUserName(), $username) == 0) {
return true;
}
}
return false;
}
}
?>