<?php

/************************************************************************/
/* PHP-NUKE: Web Portal System                                          */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2001 by Francisco Burzi (fbc@mandrakesoft.com)         */
/* http://phpnuke.org                                                   */
/*                                                                      */
/* 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.       */
/************************************************************************/

if(!defined('BLOCK_FILE')){
   Header("Location: ../index.php");
   die();
}

global $db;

/************************************************************************/
/* Anime News Network Newsfeed Block                                    */
/* version 1.0                                                          */
/* Written by Daniel DeLorme & W. Allen Divers                          */
/*                                                                      */
/* To use this block you need to be subscribed to the ANN Newsfeed:     */
/*   https://www.animenewsnetwork.com/newsfeed/                         */
/*                                                                      */
/* Replace [u] by your newsfeed username and [p] by your newsfeed       */
/* password (the getnews password, not the login password)              */
/* Place this module in your blocks directory of your PHP-Nuke install  */
/* From there, simply add this block through your admin menu, set       */
/* refresh for one hour, give it a nice name and then edit the username */
/* and password to your specifications.                                 */
/************************************************************************/


// open database
// Fetch the stored news
$result = $db->sql_query("SELECT * FROM ANN_news");
$ANN_news = $db->sql_fetchrow($result);
if (!$ANN_news)
{	@$db->sql_query("CREATE TABLE ANN_news (last_query INT UNSIGNED NOT NULL, news TEXT NOT NULL)");
	@$db->sql_query("INSERT INTO ANN_news VALUES (0, ' ')");
}

// If the news were last updated more than one hour ago, re-update them
if ($ANN_news['last_query'] < time() - 3600 or trim($annNews['news']) == "")
{
	// Fetch the news from ANN
	// You need to put your own username and password here
	// CAREFUL: it should look like ?u=qwe&p=123 , NOT like ?u=[qwe]&p=[123]
	$a = file("https://www.animenewsnetwork.com/newsfeed/getnews.php?u=[u]&p=[p]");
	$n = addslashes(trim(implode("",$a)));

	// Save the news to the database
	$query = "UPDATE ANN_news SET last_query=UNIX_TIMESTAMP()";
	if ($n)
	{	$query .= ", news='$n'";
		$ANN_news['news'] = stripslashes($n);
	}
	$db->sql_query($query);
}

// Display the news
$content = 'News provided by <A HREF="https://www.animenewsnetwork.com">AnimeNewsNetwork.com</a>'.$ANN_news['news'];

?>
