Add a feed
if ($loggedin=="yes") { ?>
if ($do != "yes") { ?>
//=== SearchPage "Add" Button ===
if ($_GET['add'] != "") {
//DB CONFIG
$host = "localhost";
$user = "merlin";
$pass = "Vita_Merlini";
$db = "ntugo_mynt";
//CONNECT
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect to database. Please contact the webmaster.");
//SELECT DB
mysql_select_db($db) or die ("Unable to select database (connection was OK). Please contact the webmaster.");
//CHECK FEEDDIR FOR FEED
$query = "SELECT * FROM mynt_feeddir WHERE FeedURL = '$add'";
$result = mysql_query($query) or die(mysql_error());
if (mysql_num_rows($result) > 0)
{
while ($row = mysql_fetch_assoc($result)) {
$ntsp_feed_url = $row['FeedURL'] ;
$ntsp_feed_name = $row['FeedName'] ;
$ntsp_feed_tags = $row['Tags'] ;
}
}
//CLOSE CONNECTION
mysql_close($connection);
}
//===========================
//=== API ===
if ($_GET['apiadd'] != "") {
$ntsp_feed_url = $_GET['apiadd'];
$ntsp_feed_name = $_GET['apititle'];
$ntsp_feed_tags = $_GET['apitags'];
}
//==========
?>
} ?>
if ($do=="yes") {
//Grab form data
$newfeed_url = $_POST['newfeed_url'];
$newfeed_name = $_POST['newfeed_name'];
$newfeed_name = addSlashes($newfeed_name);
$newfeed_tags = addSlashes($newfeed_tags);
$newfeed_tags = $_POST['newfeed_tags'];
$newfeed_user = $_SESSION["web_user"];
//Is the feed URL valid?
// Include SimplePie
include_once('./simplepie.inc');
include_once('./idn/idna_convert.class.php');
// Create a new instance of the SimplePie object
$feed = new SimplePie();
// Use the URL that was passed to the page in SimplePie
$feed->set_feed_url($newfeed_url);
$feed->set_cache_duration (600);
// XML dump
$feed->enable_xml_dump(isset($_GET['xmldump']) ? true : false);
// Initialize the whole SimplePie object. Read the feed, process it, parse it, cache it, and
// all that other good stuff. The feed's information will not be available to SimplePie before
// this is called.
$success = $feed->init();
// We'll make sure that the right content type and character encoding gets set automatically.
// This function will grab the proper character encoding, as well as set the content type to text/html.
$feed->handle_content_type();
if (!$success) {
echo "The URL you entered is not a valid feed.
Go back and try again.";
$regerror=="1";
exit();
}
//Check for blank fields
if ($newfeed_url=="" OR $newfeed_name==""){
echo "A regired field was left blank.
Go back and try again.";
$regerror=="1";
exit();
}
//Is the feed in the FeedDir?
//DB CONFIG
$host = "localhost";
$user = "merlin";
$pass = "VitaMerlini";
$db = "ntugo_mynt";
//CONNECT
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect to database. Please contact the webmaster.");
//SELECT DB
mysql_select_db($db) or die ("Unable to select database (connection was OK). Please contact the webmaster.");
//CHECK FEEDDIR FOR FEED
$query = "SELECT * FROM mynt_feeddir WHERE FeedURL = '$newfeed_url'";
$result = mysql_query($query) or die(mysql_error());
if (mysql_num_rows($result) > 0)
{
$indir="yes";
}
//CLOSE CONNECTION
mysql_close($connection);
//Is the user already subscribed to the feed?
//DB CONFIG
$host = "localhost";
$user = "merlin";
$pass = "VitaMerlini";
$db = "ntugo_mynt";
//CONNECT
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect to database. Please contact the webmaster.");
//SELECT DB
mysql_select_db($db) or die ("Unable to select database (connection was OK). Please contact the webmaster.");
//CHECK FEEDDIR FOR FEED
$query = "SELECT * FROM mynt_feeds WHERE FeedURL = '$newfeed_url' AND User = '$newfeed_user'";
$result = mysql_query($query) or die(mysql_error());
if (mysql_num_rows($result) > 0)
{
echo "You are already subscribed to that feed!
Back to your feeds.";
$regerror=="1";
exit();
}
//CLOSE CONNECTION
mysql_close($connection);
//Add the feed!
if ($regerror != "1") {
//DB CONFIG
$host = "localhost";
$user = "merlin";
$pass = "VitaMerlini";
$db = "ntugo_mynt";
//CONNECT
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect to database. Please contact the webmaster.");
//SELECT DB
mysql_select_db($db) or die ("Unable to select database (connection was OK). Please contact the webmaster.");
//INSERT THE FEED
$query = "INSERT INTO mynt_feeds (FeedURL, FeedName, User, Tags) VALUES('$newfeed_url', '$newfeed_name', '$newfeed_user', '$newfeed_tags')";
$result = mysql_query($query) or die(mysql_error());
if ($indir == "yes") {
$query = "UPDATE mynt_feeddir SET SubscriberCount = SubscriberCount +1 WHERE FeedURL = '$newfeed_url'";
$result = mysql_query($query) or die(mysql_error());
}
if ($indir != "yes") {
$query = "INSERT INTO mynt_feeddir (FeedURL, FeedName, Tags, SubscriberCount) VALUES('$newfeed_url', '$newfeed_name', '$newfeed_tags', 1)";
$result = mysql_query($query) or die(mysql_error());
}
//CLOSE CONNECTION
mysql_close($connection);
echo "Feed added.
Go back to your feeds or
add another.";
}
}
?>
}
else {
//=== If not logged in ===
?>
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
?>
You must be logged in to access this page.
}
//=====================
?>