Easy textfile news system w/out categories.
This script is an easy way to have a text based news system.
It is very simple to customize and will build the folder structure itself. All you have to upload to your webspace is this one file after providing a password for the "add news" form.
Simple, straight forward, easy to use.
Hope you like it!
Chris
<?php
/*
Easy textfile news system
This script is an easy way to have a text based news system.
To add news, call index.php?add=true in your browser. Please provide a password
in the function showaddform().
The system will generate a folder structure like the folloing
In the newsfile, the first line is the title, second is the header text and third and following are regular text lines
Programmed by Christian Haensel, christian@chftp.com, http://www.chftp.com
Exclusively published on weberdev.com
If you like my scripts, please let me know or link to me.
You may copy, redistirubte, change and alter my scripts as long as this information remains intact
*/
function datefolders() {
// This function checks the existance of the news directory for this day
// and, if necessary, creates the directories for year, month and day.
$checkyear = date("Y");
$checkmonth = date("m");
$checkday = date("d");
// Checking for this year's folder
if(!is_dir("news/".$checkyear)) {
mkdir("news/".$checkyear,0755);
}
// Checking for this month's folder
if(!is_dir("news/".$checkyear."/".$checkmonth)) {
mkdir("news/".$checkyear."/".$checkmonth,0755);
}
// Checking for today's folder
if(!is_dir("news/".$checkyear."/".$checkmonth."/".$checkday)) {
mkdir("news/".$checkyear."/".$checkmonth."/".$checkday,0755);
}
}
function check_news() {
// This function checks for news in the directories. It will take URL-Parameters
// like day, month and year. If thos are not set, it will take the current date
if(eregi("\.", $_GET['day']) || eregi("\.", $_GET['month']) || eregi("\.", $_GET['year'])) {
die("No hacking");
}
if(isset($_GET['year'])) {
$newsyear = $_GET['year'];
} else {
$newsyear = date("Y");
}
if(isset($_GET['month'])) {
$newsmonth = $_GET['month'];
} else {
$newsmonth = date("m");
}
if(isset($_GET['day'])) {
$newsday = $_GET['day'];
} else {
$newsday = date("d");
}
// Check for news in the directory
$news_arr = array();
$newsfolder = @opendir("news/".$newsyear."/".$newsmonth."/".$newsday) or die("No news for this time");
while($news = readdir($newsfolder)) {
if(eregi(".news", $news)) {
array_push($news_arr, $news);
}
}
sort($news_arr);
$news_arr = array_reverse($news_arr);
foreach($news_arr as $news) {
readnews($newsday,$newsmonth,$newsyear,$news);
}
}