<?php
/************************************************************************/
/* Maximus CMS: Web Portal System                                       */
/* ==============================                                       */
/*                                                                      */
/* Copyright (c) 2002 - 2006                                            */
/* http://www.php-maximus.fr                                            */
/* dev@php-maximus.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.       */
/************************************************************************/
/* Based on PHP-NUKE: Web Portal System                                 */
/************************************************************************/
if (!defined('ADMIN_ALLOW') && !defined('ADMIN_MAX')) {
	die ("Access Denied");
}
if ($acces == 1) {
if($admintest && $adminsecu)  {

    if($view == 4) { $ingroups = implode("-",$groups); }
    if($view < 4) { $ingroups = ""; }

		if ($headline != 0) {
			$row = $db->sql_fetchrow($db->sql_query("select sitename, headlinesurl from ".$prefix."_headlines where hid='$headline'"));
			$title = stripslashes($row['sitename']);
			$url = stripslashes($row['headlinesurl']);
		}
		$row2 = $db->sql_fetchrow($db->sql_query("SELECT weight FROM ".TABLE_BLOCKS." WHERE bposition='$bposition' ORDER BY weight DESC"));
		$weight = $db->XMFnum($row2['weight']);
		$weight++;
		$title = stripslashes(FixQuotes($title));
		$content = stripslashes(FixQuotes($content));
		$bkey = "";
		$btime = "";
		if ($blockfile != "") {
			$url = "";
			if ($title == "") {
				$title = ereg_replace("block-","",$blockfile);
				$title = ereg_replace(".php","",$title);
				$title = ereg_replace("_"," ",$title);
			}
		}
		if ($url != "") {
			$btime = time();
			if (!ereg("http://",$url)) {
				$url = "http://$url";
			}
			$rdf = parse_url($url);
			$fp = fsockopen($rdf['host'], 80, $errno, $errstr, 15);
			if (!$fp) {
				rssfail();
				exit;
			}
			if ($fp) {
				fputs($fp, "GET " . $rdf['path'] . "?" . $rdf['query'] . " HTTP/1.0\r\n");
				fputs($fp, "HOST: " . $rdf['host'] . "\r\n\r\n");
				$string = "";
				while(!feof($fp)) {
					$pagetext = fgets($fp,228);
					$string .= chop($pagetext);
				}
				fputs($fp,"Connection: close\r\n\r\n");
				fclose($fp);
				$items = explode("</item>",$string);
				$content = "<font class=\"content\">";
				for ($i=0;$i<10;$i++) {
					$link = ereg_replace(".*<link>","",$items[$i]);
					$link = ereg_replace("</link>.*","",$link);
					$title2 = ereg_replace(".*<title>","",$items[$i]);
					$title2 = ereg_replace("</title>.*","",$title2);
					if ($items[$i] == "" AND $cont != 1) {
						$content = "";
					} else {
						if (strcmp($link,$title2) AND $items[$i] != "") {
							$cont = 1;
							$content .= "<strong><big>&middot;</big></strong>&nbsp;<a href=\"$link\" target=\"new\">$title2</a><br />\n";
						}
					}
				}
			}
		}
		$content = FixQuotes($content);
		if (($content == "") AND ($blockfile == "")) {
			rssfail();
		} else {
			if ($expire == "") {
				$expire = 0;
			}
			if ($expire != 0) {
				$expire = time() + ($expire * 86400);
			}
			$db->sql_query("insert into ".TABLE_BLOCKS." values (NULL, '$bkey', '$title', '$content', '$url', 'l', '$weight', '$active', '$refresh', '$btime', '$blanguage', '$blockfile', '$view', '$ingroups', '$expire', '$action', '$subscription')");

			redirect_url("".$admin_file.".php?op=BlocksManager");
		}

}
}else {
	echo "Access Denied";
}