$news_nextid = 1; // AUTOUPDATE
$shownewsdivs = true;
$news_content_exists = false;
// FROM PHP.net
if (!function_exists('file_put_contents')) {
if (!defined('FILE_APPEND')) {
define('FILE_APPEND', 8);
}
if (!defined('FILE_USE_INCLUDE_PATH')) {
define('FILE_USE_INCLUDE_PATH', 1);
}
function file_put_contents($filename, $data, $flags = 0) {
$mode = $flags & FILE_APPEND ? 'ab' : 'wb';
$fh = fopen($filename, $mode, $flags & FILE_USE_INCLUDE_PATH);
$bytes_written = fwrite($fh, $data);
fclose($fh);
return $bytes_written;
}
}
function remove_escape($strfrom) {
return str_replace("\\'", "'", str_replace("\\\"", "\"", $strfrom));
}
function remove_html($strfrom, $fortextarea=false) {
if ($fortextarea) {
return str_replace("\"", """, str_replace("<", "<", str_replace("&", "&", remove_escape($strfrom))));
} else {
return str_replace("\n", "
\n", str_replace("\"", """, str_replace("<", "<", str_replace("&", "&", remove_escape($strfrom)))));
}
}
function create_replacement_news($news_username, $news_link, $news_content, $news_date, $news_id, $news_html) {
$textarea_content = remove_html($news_content, true);
if ($news_html) {
$is_news_html = "checked";
$news_content = remove_escape($news_content);
} else {
$news_content = remove_html($news_content);
}
return "".$news_date." by ".remove_escape($news_username)."
".$news_content.'
$news_content_exists = true;
if ($shownewsdivs) {
?'.'>
}
?'.'>
';
}
//if (strtolower($news_username) == "flobi" && md5($news_password) == "79338f7567adbd87a70fdacd50a980e0") {
if (md5($news_password) == "") {
switch($action){
case "Save This":
echo "Editing...(".$news_id.")";
$replacement = create_replacement_news($news_username, $news_link, $news_content, $news_date, $news_id, $news_html);
$filename = array_pop(explode("/", $_SERVER["SCRIPT_NAME"]));
$cachedfile = file_get_contents($filename) or die("can't get file contents");
$newfile = preg_replace('/<\!\-\-Begin News Item '.$news_id.'\-\->.*<\!\-\-End News Item '.$news_id.'\-\->/s', $replacement, $cachedfile);
file_put_contents($filename, $newfile);
break;
case "Confirm Deletion":
echo "Deleting...(".$news_id.")";
$replacement = "";
$filename = array_pop(explode("/", $_SERVER["SCRIPT_NAME"]));
$cachedfile = file_get_contents($filename) or die("can't get file contents");
$newfile = preg_replace('/<\!\-\-Begin News Item '.$news_id.'\-\->.*<\!\-\-End News Item '.$news_id.'\-\->/s', $replacement, $cachedfile);
file_put_contents($filename, $newfile);
;
break;
default:
echo "Adding...(".$news_nextid.")";
$news_date = date("l, F jS, Y");
$replacement = "\n\n".create_replacement_news($news_username, $news_link, $news_content, $news_date, $news_nextid, $news_html);
$filename = array_pop(explode("/", $_SERVER["SCRIPT_NAME"]));
$cachedfile = file_get_contents($filename) or die("can't get file contents");
$newfile = str_replace("\n", $replacement, $cachedfile);
file_put_contents($filename, $newfile);
$old_news_nextid = $news_nextid;
$news_nextid++;
file_put_contents(array_pop(explode("/", $_SERVER["SCRIPT_NAME"])), str_replace("\$news_nextid = ".$old_news_nextid."; // AUTOUPDATE","\$news_nextid = ".$news_nextid."; // AUTOUPDATE", file_get_contents(array_pop(explode("/", $_SERVER["SCRIPT_NAME"])))));
;
} // switch
?>
}
?>
NEWS:
if (!$news_content_exists) {
?>
}
?>