config.php
[php:1:ef667e546d]<?php
<?
//hasło administratora;
$password="administrator";
//Pełna ścieżka do katalogu w którym będzie umieszczony skrypt (bez slasha na końcu);
$main_url="http://localhost/news";
//Nazwa strony, na której wyświetlane będą newsy, np. "index.php";
$news_page="index.php";
//Liczba ostatnich newsów, które mają być wyświetlane;
$show_num=8;
//Włączenie: (1) lub wyłączenie: (0) tytułowego nagłówka na stronie z newsami;
$display_header=1;
//Kod HTML używany do oddzielania poszczególnych newsów, np. "<br><br>", "<hr>, itp;
$spacer="<hr size=1 noshade width='550' align='left'><br>";
//Strona kodowa w jakiej mają być wyświetlane newsy, np. "iso-8859-2";
$encoding="ISO-8859-2";
//Ścieżka do pliku graficznego, widocznego przy każdym Newsie;
$image="news/img/news_ico.gif";
//Ścieżka do arkusz stylów CSS, używanego przez skrypt Admina.
$styl="../style.css";
//Włączenie: (1) lub wyłączenie: (0) komentarzy;
$enable_comments=0;
//Treść potwierdzenia dodania komentarza;
$comment_confirm="Dziękuję. Twój komentarz został dodany...";
//Kolor czcionki nagłówka każdego newsa;
$header_font="#ffffff";
//Kolor tła nagłówka każdego newsa;
$header_bg="#330099";
//Kolor czcionki nagłówka każdego komentarza;
$cmnt_header_font="black";
//Kolor tła nagłówka każdego komentarza;
$cmnt_header_bg="#336699";
//Rozmiar czcionki, którą będzie pisana data dodania newsa lub komentarza;
$date_size=10;
?>
?>[/php:1:ef667e546d]
news.php
[php:1:ef667e546d]<?php
<?
require "news/config.php";
$newsdata="news/data/newsdata.dat";
if(!isset($action)) {
$action="display";
}
switch($action) {
case "display":
if(file_exists($newsdata)){
$size=(int)((filesize("$newsdata")+1023)/1024);
$table=file($newsdata);
$total=count($table);
if ($display_header==1) {
echo "<p align=center>$head_title</p>";
}
if ($list=="all") {
$max=0;
}
else {
$max=$total-$show_num;
}
if($max < 0) {
$max=0;
}
for ($i=$total; $i >= $max; $i--)
{
$table[$i]=trim($table[$i]);
if($table[$i]!="")
{
$data=explode("*|*", $table[$i]);
$data[5]=trim($data[5]);
$data[6]=trim($data[6]);
if($data[6]=="") {
$data[6]=0;
}
$date=$data[1];
$date=explode("-", $date);
$hour=$data[2];
$hour=explode(":", $hour);
$id=$i+1;
$comment_base="$date[0]"."$date[1]"."$date[2]"."$hour[0]"."$hour[1]";
echo "<table border="0" width="550" cellpadding="1"><tr><td width="550" colspan="2" style="color: $header_font; background:$header_bg;"> <B>$data[0]</B></td></tr><tr><td width="100%" colspan="2">
<span style="font-size: $date_size;font-weight:bold">$data[1]</span><BR><span style="text-align: justify;">$data[3]</span></td></tr><tr><td width="275" align="left" ></td><td width="275" align="right">";
if($enable_comments=="1") {
echo "";
}
else {
echo "</td></tr></table>$spacer";
}
}
}
if ($list!="all" && $total > $show_num) {
echo "<b>»</b> <a href=$news_page?list=all>archiwum newsów: $total ($size KB)</a><br><br>";
}
}
else {
echo "<br><center>Nie utworzono bazy newsów!<br><a href=news/admin.php>Panel Administratora</a>.</center><br>";
}
break;
case "comments":
if(!isset($id)) {
echo "Nie odnaleziono newsa o podanym Id!";
die();
}
$comments_base="news/data/$base.dat";
if(!file_exists($comments_base)) {
echo "Nie odnaleziono bazy komentarzy dla wybranego newsa!<br><br>";
}
else {
echo "<p align=center><b>Tre¶ć newsa:</b></p>";
$table=file($newsdata);
$max=count($table);
$nr=$id-1;
for($i=0; $i < $max; $i++) {
if($i==$nr) {
$data=explode("*|*", $table[$i]);
$data[5]=trim($data[5]);
$data[6]=trim($data[6]);
echo "<table border="0" width="100%"><tr><td width="100%" colspan="2" style="color: $header_font; background:$header_bg; font-weight:bold;"><img src=news/img/news_ico.gif align=bottom> <b>$data[0]</b></td></tr><tr><td width="100%" colspan="2"><span style="font-size: $date_size">$data[1], $data[2]</span><br><br></td></tr><tr><td width="100%" colspan="2">
<p style="text-align: justify;">$data[3]</p></td></tr><tr><td width="50%" align="left" ><br><b>dodał:</b> <a href=mailto:$data[4]>$data[5]</a></td><td width="50%" align="right"></td></tr></table>$spacer";
echo "<p align=center><b>Komentarze:</b></p>";
}
}
$comments=file($comments_base);
$all=count($comments);
for ($x=0; $x < $all; $x++) {
$data=explode("*|*", $comments[$x]);
$data[4]=trim($data[4]);
echo "<table border="0" width="100%"<tr><td width="100%" colspan="2" style="color: $cmnt_header_font; background:$cmnt_header_bg; font-weight:bold;">Dodano: $data[3], $data[4]</td></tr><tr><td width="100%" colspan="2"><p> </p></td><tr><td width="100%" colspan="2">
<p style="text-align: justify;">$data[2]</p></td></tr><tr><td width="50%" align="left" ><br><b>autor:</b> <a href=mailto:$data[1]>$data[0]</a></td><td width="50%" align="right"></td></tr></table>$spacer";
}
}
echo "<a href=java script:history.back()><b>«</b> wstecz</a> | <a href=$news_page?action=new_comment&id=$id>skomentuj</a><br><br>";
break;
case "new_comment":
if(!isset($id)) {
echo "Nie znaleziono newsa o podanym Id!<br>";
}
else {
echo "<p align=center><b>Tre¶ć newsa:</b></p>";
$table=file($newsdata);
$max=count($table);
$nr=$id-1;
for($i=0; $i < $max; $i++) {
if($i==$nr) {
$data=explode("*|*", $table[$i]);
$data[5]=trim($data[5]);
$data[6]=trim($data[6]);
echo "<table border="0" width="100%"><tr><td width="100%" colspan="2" style="color: $header_font; background:$header_bg; font-weight:bold;"><img src=news/img/news_ico.gif align=bottom> <b>$data[0]</b></td></tr><tr><td width="100%" colspan="2"><span style="font-size: $date_size">$data[1], $data[2]</span><br><br></td></tr><tr><td width="100%" colspan="2">
<p style="text-align: justify;">$data[3]</p></td></tr><tr><td width="50%" align="left" ><br><b>dodał:</b> <a href=mailto:$data[4]>$data[5]</a></td><td width="50%" align="right"></td></tr></table>$spacer";
}
}
echo "<p align=center><b>Dodaj komentarz:</b></p>";
echo "<form action="$news_page" method="POST">
<input type="hidden" name="id" value="$id">
<input type="hidden" name="action" value="add_comment">
nick:<br>
<input type="text" name="nick" maxlength="15"><br>
email:<br>
<input type="email" name="email" maxlength="50"><br>
komentarz:<br>
<textarea name="body" maxlength="650" rows="6" cols="35" wrap="virtual">
</textarea><br><br>
<input type="submit" value="dodaj"> <input type="reset" value="reset">
</form>";
}
echo "<hr noshade><a href=java script:history.back()><b>«</b> wstecz</a><br><br>";
break;
case "add_comment":
if(!isset($id)) {
echo "Nie znaleziono newsa o podanym Id!<br>";
}
else {
if($nick=="" || !eregi("@", $email) || $body =="") {
echo "Należy prawidłowo wypełnić wszystkie pola formularza!<br><br><a href=java script:history.back()><b>«</b> wstecz</a><br><br>";
}
else {
$body=substr($body, 0, 650);
$body=strip_tags($body, '<a><b><i><u>');
$body=stripslashes($body);
$body=str_replace("n", "<br>", $body);
$date=date("d-m-Y");
$hour=date("H:i");
$i=$id-1;
$table=file($newsdata);
$all=count($table);
$f=fopen($newsdata, "w");
flock($f, 2);
for($z=0; $z<$all; $z++) {
$data=explode("*|*", $table[$z]);
$data[5]=trim($data[5]);
$data[6]=trim($data[6]);
if($z==$i) {
$newsdate=explode("-", $data[1]);
$newshour=explode(":", $data[2]);
$newsdate="$newsdate[0]$newsdate[1]$newsdate[2]";
$newshour="$newshour[0]$newshour[1]";
$comment_base="$newsdate$newshour";
$data[6]++;
}
$write_str="$data[0]*|*$data[1]*|*$data[2]*|*$data[3]*|*$data[4]*|*$data[5]*|*$data[6]n";
fputs($f, $write_str);
}
flock($f, 3);
fclose($f);
$comment_base="news/data/$comment_base.dat";
if(file_exists($comment_base)) {
$fc=fopen($comment_base, "a");
}
else {
$fc=fopen($comment_base, "w");
}
flock($fc, 2);
$comment_str="$nick*|*$email*|*$body*|*$date*|*$hourn";
fputs($fc, $comment_str);
flock($fc, 3);
fclose($fc);
echo "<b>$comment_confirm</b><br><br>
<a href=$news_page>pokaż newsy</a><br><br>";
}
}
break;
}
?>
?>[/php:1:ef667e546d]
admin.php
[php:1:ef667e546d]<?php
<?
require "config.php";
error_reporting(0);
echo "<HTML>
<HEAD>
<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=$encoding">
<title>Administracja sytemem newsów</TITLE>
<link rel="stylesheet" href="$styl"></HEAD>";
$newsdata="data/newsdata.dat";
$login_form="<center><b>Podaj hasło administratora</b><br><br><form method=post action=admin.php>hasło: <input type=password name=pass size=20><br><br>
<input type=submit value=login></form>";
$menu="<b>Menu:</b> | <a href="http://www.tepenet/portal/portlet/si/si/viewArticle?articleId=478746" target="_new">NEWSy`</a> | <a href=admin.php?pass=$pass>administracja</a> | <a href=admin.php?action=delete&pass=$pass>usuń newsa</a> | <a href=admin.php?action=new&pass=$pass>dodaj newsa</a> |<hr size=1 noshade>";
if(!isset($action)) {
$action="drawmenu";
}
switch ($action) {
case "delete":
if($pass==$password)
{
echo "$menu<br>";
$table=file($newsdata);
$total=count($table);
$size=(int)((filesize("$newsdata")+1023)/1024);
if ($size==0) {
$total=0;
}
echo "<b>Liczba newsów w bazie:</b> $total<br> <b>Rozmiar bazy: </b>$size KB<hr size=1 noshade><br><br>";
$table=file($newsdata);
$total=count($table);
$nr=1;
for ($i=$total; $i >= 0; $i--)
{
$table[$i]=trim($table[$i]);
if($table[$i]!="")
{
$data=explode("*|*", $table[$i]);
$data[6]=trim($data[6]);
$text=str_replace("<img src=news/img/news_ico.gif align=bottom>", "", $table[$i]);
echo "<table border="0" width="590"><tr><td width="100%" colspan="2" style="color: $header_font; background:$header_bg; font-weight:bold;">$data[0]</td></tr><tr><td width="100%" colspan="2"><span style="font-size: $date_size">$data[1], $data[2]</span></td></tr><tr><td width="100%" colspan="2">
<p style="text-align: justify;">$data[3]</p></td></tr><tr><td width="50%" align="left" > | <a href=admin.php?action=remove&id=$i&pass=$pass>usuń newsa</a></td><td width="50%" align="right"></td></tr></table>$spacer";
$nr++;
}
}
}
else
{
echo "$login_form";
}
break;
case "new":
if($pass==$password)
{
echo("$menu<b>Dodaj newsa:</b><form method=POST action=admin.php?action=add>
Tytuł:<BR><textarea name=title rows=2 cols=70></textarea><br><br>
Tre¶ć:<BR><textarea rows=10 name=newsbody cols=70></textarea><br><br>
<input type=submit value=dodaj>
<input type=hidden name=pass value=$pass><br>
</form>");
}
else
{
echo "$login_form";
}
break;
case "add":
if($pass==$password)
{
$date=date("d-m-Y");
$hour=date("H:i");
if (eregi("8859-2", $encoding)) {
$newsbody=ereg_replace("Ą", "ˇ", $newsbody);
$newsbody=ereg_replace("Ś", "¦", $newsbody);
$newsbody=ereg_replace("Ź", "¬", $newsbody);
$newsbody=ereg_replace("ź", "Ľ", $newsbody);
$newsbody=ereg_replace("ą", "±", $newsbody);
$newsbody=ereg_replace("ś", "¶", $newsbody);
$title=ereg_replace("Ą", "ˇ", $title);
$title=ereg_replace("Ś", "¦", $title);
$title=ereg_replace("Ź", "¬", $title);
$title=ereg_replace("ź", "Ľ", $title);
$title=ereg_replace("ą", "±", $title);
$title=ereg_replace("ś", "¶", $title);
}
$newsbody=stripslashes($newsbody);
$newsbody=eregi_replace("n", "<br>", $newsbody);
$title=stripslashes($title);
$author=stripslashes($author);
$data="$title*|*$date*|*$hour*|*$newsbody*|*$email*|*$author*|*0n";
$f=fopen($newsdata, "a");
flock($f, "2");
fputs($f, $data);
flock($f, "3");
fclose($f);
echo "$menu<br><b>News został dodany</b>.";
}
else
{
echo "$login_form";
}
break;
case "remove":
$table=file($newsdata);
$total=count($table);
$f=fopen($newsdata, "w");
$data=explode("*|*", $table[$id]);
$date=explode("-", $data[1]);
$hour=explode(":", $data[2]);
$comments_file="$date[0]"."$date[1]"."$date[2]"."$hour[0]"."$hour[1]";
$comments_file="data/$comments_file.dat";
if(file_exists($comments_file)) {
unlink($comments_file);
}
flock($f, "2");
for ($i=0; $i <= $total; $i++)
{
if($i!=$id)
{
fputs($f, $table[$i]);
}
}
flock($f, "3");
fclose($f);
echo "$menu<br><b>Usunięto.</b>";
break;
case "drawmenu":
if($pass==$password)
{
echo "$menu<br>";
$table=file($newsdata);
$total=count($table);
$size=(int)((filesize("$newsdata")+1023)/1024);
if ($size==0) {
$total=0;
}
echo "<b>Liczba newsów w bazie:</b> $total<br> <b>Rozmiar bazy: </b>$size KB<hr size=1 noshade><br>";
}
else
{
echo "$login_form";
}
break;
}
?>
?>[/php:1:ef667e546d]
No i oczywiscie tworzysz pliczek newsdata.dat (u mnie w katalogu data)
O to chodzilo ?
Aha, jeszcze odrazu do kompletu masz style.css
Kod
BODY {
FONT-SIZE: 11px; FONT-FAMILY: Verdana, Geneva, Arial, Helvetica, sans-serif;
}
TEXTAREA {
FONT-SIZE: 11px; FONT-FAMILY: Verdana, Geneva, Arial, Helvetica, sans-serif; border: 1px black solid;
}
INPUT {
FONT-SIZE: 11px; FONT-FAMILY: Verdana, Geneva, Arial, Helvetica, sans-serif; border: 1px black solid;
}
TD {
FONT-SIZE: 11px; FONT-FAMILY: Verdana, Geneva, Arial, Helvetica, sans-serif;
}
TR {
FONT-SIZE: 11px; FONT-FAMILY: Verdana, Geneva, Arial, Helvetica, sans-serif;
}
TABLE {
FONT-SIZE: 11px; FONT-FAMILY: Verdana, Geneva, Arial, Helvetica, sans-serif;
border-collapse: collapse;
}
BR {
FONT-SIZE: 11px; FONT-FAMILY: Verdana, Geneva, Arial, Helvetica, sans-serif;
}
A {
COLOR: #3300FF; TEXT-DECORATION: none;
}
FONT {
FONT-SIZE: 11px; FONT-FAMILY: Verdana, Geneva, Arial, Helvetica, sans-serif;
}
a:hover { font-family:Verdana, Geneva, Arial, Helvetica, sans-serif; color:#3300FF; text-decoration:underline; }