Cytat(banan @ 2004-06-04 16:34:25)
A ja wprowadzam małą poprawkę:
[php:1:59dec4463f]
<?php
##########################
## Last News for PSnews ##
##########################
## tiraeth [at] op.pl ##
##########################
## PSNews by Przybek ##
##########################
## Version v.01.2 ##
$PathToNews = "news"; // Nazwa katalogu z PSnews'em
$IndexPath = "index.php"; // Nazwa pliku w którym includujemy newsy <== poprawka
$File = file($PathToNews."/news.txt");
$File = array_reverse($File);
for($i=0; $i<5; $i++)
{
$Dane = explode("||", $File[$i]);
$Tytul = $Dane[1];
$Numer = $Dane[0];
echo '<a href="'.$IndexPath.'?function=show_all&no='.$Numer.'">'.$Tytul.'</a>';
// Tworzymy link do newsa (+komentarze)
echo '<br />'; // Dajemy <br /> aby przejsc do nowej linii
}
?>[/php:1:59dec4463f]
Więc skrypcik działa, ale jest taki problem, że lista tematów newsów wyświetla się zupełnie niepotrzebnie na postronie z konkretnym newsem, a przydałoby się, żeby ten spis wyświetlał się tylko na stronie głównej. Czy ktoś wie, jak to można zrobić. Dla niekorzystających ze skryptu PsNews zamieszczan kod pliku odpowiedzialnego za wyświetlanie newsów w PsNews.<?
if(eregi(\"://\", $newspath)){ die(\"Nieautoryzowany dostęp!\"); }
$newspath = \"news\";
}
include(\"$newspath/functions.php\");
$config = confload($newspath);
$userlist_f = file(\"$newspath/users.inc.php\"); while((list
($key, $val) = each($userlist_f))&&($logged!=\"true\")){ $expl = explode(\"||\", $val); $userlist[$expl[0]] = $expl;
}
/* FUNKCJE */
function news_wiadomosc($wiadomosc){
return tplparse
(array('{WIADOMOSC}'),array($wiadomosc),$config[\"template\"],$newspath,\"wiadomosc.html\"); }
switch($_GET[\"function\"]){
/* STRONA GŁÓWNA */
default:
$newsfile = file(\"$newspath/news.txt\"); $count = count($newsfile); if($config[\"stronicownie\"] != \"off\"){
if(!isset($_GET[\"npage\"])){ $npage = \"1\"; } else{ $npage = $_GET[\"npage\"]; }
$ilestron = $count/$config[\"stronicowanie\"];
$ilestron = ceil($ilestron); $begin = $count - $config[\"stronicowanie\"]*($npage-1);
if($begin>$count){ $begin = $count; }
$end = $begin - $config[\"stronicowanie\"];
if($end<0){ $end = 0; }
}
else{
$begin = $count;
$end = 0;
}
for($i=$begin-1; $i>=$end;$i--){
$news = explode(\"||\", $newsfile[$i]); if($config[\"skracanie\"] != \"off\"){
$news[2] = ps_substr($news[2], $config[\"skracanie\"], \"... <a class=\"granat\" href=\"\".$config[\"adres\"].\"function=show_all&no=$news[0]\">czytaj dalej</a>\");
}
$news[2] = pscode($news[2]);
if($config[\"emoty_news\"] == \"tak\"){
$news[2] = emots($news[2], $newspath);
}
//$news[1] = wordwrap($news[1], 50, \" \", 1);
//$news[2] = wordwrap($news[2], 50, \" \", 1);
$data = date(\"d.m.Y, H:i\", $news[3]);
if($config[\"nimgs\"]==\"tak\"){
$img_path = \"$newspath/nimgs/$news[5]\";
if((file_exists($img_path))&&($news[5]!=\"brak\")&&($news[5]!=\"\")){ $news[2] = \"<img src=\"$img_path\" class=\"obrazek2\" alt=\"\" /> \".$news[2];
}
}
if(file_exists(\"$newspath/komentarze/$news[0]\")){ $komfile = @file(\"$newspath/komentarze/$news[0]\"); $ilekomentarzy = count($komfile); }
else{ $ilekomentarzy = 0; }
$print_center.= tplparse
(array('{TYTUL}','{NEWS}','{AUTOR}','{EMAIL}','{DATA}','{KOMENTARZE}','{ILEKOMENTARZY}'),array($news[1
],$news[2
],$userlist[$news[4
]][3
],$userlist[$news[4
]][4
],$data,$config[\"adres\"].\"function=show_all&no=$news[0]\",$ilekomentarzy),$config[\"template\"],$newspath,\"news.html\"); }
break;
/* CAŁOŚĆ NEWSA + KOMENTARZE */
case show_all:
$newsfile = file(\"$newspath/news.txt\"); foreach($newsfile as $news){
$news = explode(\"||\", $news); if($news[0] == $_GET[\"no\"]){
$news[2] = pscode($news[2]);
if($config[\"emoty_news\"] == \"tak\"){
$news[2] = emots($news[2], $newspath);
}
$news[1
] = wordwrap($news[1], 50, \" \", 1); $news[2
] = wordwrap($news[2], 50, \" \", 1);
$data = date(\"d.m.Y, H:i\", $news[3]);
if($config[\"nimgs\"]==\"tak\"){
$img_path = \"$newspath/nimgs/$news[5]\";
if((file_exists($img_path))&&($news[5]!=\"brak\")&&($news[5]!=\"\")){ $news[2] = \"<img src=\"$img_path\" class=\"obrazek2\" alt=\"\" /> \".$news[2];
}
}
if(file_exists(\"$newspath/komentarze/$news[0]\")){ $komfile = file(\"$newspath/komentarze/$news[0]\"); $ilekomentarzy = count($komfile); }
else{ $ilekomentarzy = 0; }
$print_center.= tplparse
(array('{TYTUL}','{NEWS}','{AUTOR}','{EMAIL}','{DATA}','{KOMENTARZE}','{ILEKOMENTARZY}'),array($news[1
],$news[2
],$userlist[$news[4
]][3
],$userlist[$news[4
]][4
],$data,$config[\"adres\"].\"function=show_all&no=$news[0]\",$ilekomentarzy),$config[\"template\"],$newspath,\"news.html\"); }
}
$print_center.= \"<center>[<a class=\"czerw\" href=\"\". $config[\"adres\"] .\"function=add_kom&no=\". $_GET[\"no\"] .\"\">skomentuj</a>] [<a class=\"czarny\" href=\"\". $config[\"adres\"] .\"\">wróć do newsów</a>]</center><br/>\";
if($ilekomentarzy<1){ $print_center.= news_wiadomosc(\"Do tego newsa nie dodano jeszcze żadnego komentarza. Wyraź pierwszy swojš o
p
nię na teamt tej informacji.<br/>\"); }
else{
reset($komfile);
foreach($komfile as $kom){
$kom = explode(\"||\", $kom);
if($config[\"emoty_kom\"] == \"tak\"){
$kom[1] = emots($kom[1], $newspath);
}
$kom[2] = stripslashes($kom[2]);
$kom[2] = preg_replace(\"'||'s\", \"||\", $kom[2]);
$kom[1] = stripslashes($kom[1]);
$kom[1] = preg_replace(\"'||'s\", \"||\", $kom[1]);
$kom[1] = wordwrap($kom[1], 50, \" \", 1);
$kom[2] = wordwrap($kom[2], 50, \" \", 1);
$data = date(\"d.m.Y, H:i\", $kom[4]);
$print_center.= tplparse(array('{KOMENTARZ}','{AUTOR}','{EMAIL}','{DATA}'),array($kom[1],$kom[2],$kom[3],$data),$config[\"template\"],$newspath,\"komentarz.html\");
}
}
break;
/* DODAWANIE KOMENTARZA */
case add_kom:
$banfile = file(\"$newspath/ban.txt\");
$ip = $_SERVER[\"REMOTE_ADDR\"];
$ban = \"false\";
foreach($banfile as $linia){
$linia = explode(\"||\", $linia);
if($linia[0] == $ip){ $ban = \"true\"; }
}
if($ban == \"true\"){
$print_center = news_wiadomosc(\"Przepraszamy, ale nie masz zezwolenia na dodanie komentarza, ponieważ twój a
res IP ($ip) został zablokowany przez administratora.<br/>[<a class=\"ziel\" href=\"\".$config[\"adres\"].\"\">wróć do newsów</a>]\");
}
else{
if($_GET[\"do\"] == \"save\"){
$filename = \"$newspath/komentarze/\".$_GET[\"no\"];
if(file_exists($filename)){
$kom_autor = $_POST[\"kom_autor\"];
$kom_email = $_POST[\"kom_email\"];
$komentarz = $_POST[\"komentarz\"];
$kom_autor = strip_tags($kom_autor);
$kom_email = strip_tags($kom_email);
$komentarz = strip_tags($komentarz);
$kom_autor = str_replace(\"|\", \"|\", $kom_autor);
$kom_email = str_replace(\"|\", \"|\", $kom_email);
$komentarz = str_replace(\"|\", \"|\", $komentarz);
$kom_autor = preg_replace(\"'n|rn|r'si\", \"\", $kom_autor);
$kom_email = preg_replace(\"'n|rn|r'si\", \"\", $kom_email);
$komentarz = preg_replace(\"'n|rn|r'si\", \"<br/>\", $komentarz);
$numer = max_l_plik(0, \"||\", $filename)+1;
$file = fopen($filename, \"a+\");
flock($file, 2);
$puts = \"$numer||$komentarz||$kom_autor||$kom_email||\".time().\"||$ip||n\";
fputs($file, $puts);
flock($file, 3);
fclose($file);
$print_center = '<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL='.$config[\"adres\"].'\">';
}
else{
$print_center = news_wiadomosc(\"Nie można dodać komentarza - brak pliku z bazą danych do tego newsa.<br/>[<a class=\"ziel\" href=\".$config[\"adres\"].\">wróć do newsów</a>]\");
}
}
else{
$print_center.= \"<center>
<form action=\"\". $config[\"adres\"].\"function=add_kom&no=\".$_GET[\"no\"].\"&do=save\" method=post name=formularz>
Autor:<br/><input type=text name=\"kom_autor\"><br/>
Email:<br/><input type=text name=\"kom_email\"><br/>
Komentarz:<br/>\";
if($config[\"emoty_kom\"] == \"tak\"){ $print_center.= list_emots($newspath,\"komentarz\").\"<br/>\"; }
$print_center.= \"<textarea cols=\"30\" rows=\"10\" name=\"komentarz\"></textarea><br/>
<input type=submit value=\"dodaj\">
<br/><a class=\"czarny\" href=\"\".$config[\"adres\"].\"\">[rezygnuj]</a>
</form></center>
\";
}
}
break;
}
/* WYŚWIETLANIE */
eval(\"?>\".$print_center.\"<?\");
?>