così come è il codice, l'inserimento delle news non è del tutto corretto....
allora ho utilizzato la funzione glob() per identificare tutti i file con estensione .txt, e quindi modificato il codice in questo modo:
pagina post.php:
Codice PHP:
<?php
/***********************************************\
* Bc - TagBoard!
* Bc Scripts (C) 2004
* Boris Carollo - bc.scripts@lycos.com
* http://bcscripts.zapto.org
\***********************************************/
// Includo le variabili importanti
include ("config.php");
include ("vars.php");
//new on 15/06/2010 by eurosalute:
if (isset($_REQUEST['nextpage']) && !empty($_REQUEST['nextpage'])){
$nextpage = trim($_REQUEST['nextpage']);
if (!is_numeric($nextpage) && !is_int($nextpage)) $nextpage=1;
if (!file_exists("messages_page".$nextpage.".txt")) $nextpage=1;
//$file="messages_page".$nextpage.".txt";
}
else $nextpage=1;
foreach (glob('*.txt') as $file_name) {
$cont = implode ("",file($file_name));
$gets = substr_count ($cont,"</tr>");
if ($gets == $messaggi_xpage) $nextpage = $nextpage+1;
}
$file="messages_page".$nextpage.".txt";
//end modifica
// Conto i messaggi, un "</tr>" vale un messaggio
//$cont = implode ("",file($file));
//$gets = substr_count ($cont,"</tr>");
// Controllo se i campi sono stati inseriti
if (($name == "") || ($mess == "") || ($send == FALSE)) {
echo ("
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\" />
<title>$site (Bc - TagBoard $vers)</title>
<link rel=\"stylesheet\" type=\"text/css\" href=\"$dcss\" />
</head>
<body>
<!-- Bc - TagBoard $vers -->
<br />
<div align=\"center\">
<table cellspacing=\"1\" cellpadding=\"4\">
<tr>
<td class=\"bottd\" width=\"150\">
<div align=\"center\">
Tutti i campi sono obbligatori!
<br /> <br />
<a href=\"javascript:history.back(-1)\">Indietro</a>
</div>
</td>
</tr>
</table>
</div>
<br />
<!-- Bc - TagBoard $vers -->
</body>
</html>
");
}
else {
$join = join ("",file($file));
$open = fopen ($file,"w+");
$name = stripslashes ($name);
$mess = stripslashes ($mess);
$name = eregi_replace ("<","<",$name);
$mess = eregi_replace ("<","<",$mess);
$name = eregi_replace ("'","'",$name);
$mess = eregi_replace ("'","'",$mess);
$mess = ereg_replace ("\n","<br />",$mess);
$mess = wordwrap ($mess,30,"<br />",1);
$mess = str_replace (":)","<img src=\"http://forum.it.altervista.org/images/01.gif\" alt=\"\" border=\"0\" />",$mess);
$mess = str_replace (":(","<img src=\"http://forum.it.altervista.org/images/02.gif\" alt=\"\" border=\"0\" />",$mess);
$mess = str_replace (":D","<img src=\"http://forum.it.altervista.org/images/03.gif\" alt=\"\" border=\"0\" />",$mess);
$mess = str_replace (":F","<img src=\"http://forum.it.altervista.org/images/04.gif\" alt=\"\" border=\"0\" />",$mess);
$mess = str_replace (";)","<img src=\"http://forum.it.altervista.org/images/05.gif\" alt=\"\" border=\"0\" />",$mess);
$mess = str_replace (";(","<img src=\"http://forum.it.altervista.org/images/06.gif\" alt=\"\" border=\"0\" />",$mess);
$mess = str_replace (":P","<img src=\"http://forum.it.altervista.org/images/07.gif\" alt=\"\" border=\"0\" />",$mess);
$mess = str_replace (":O","<img src=\"http://forum.it.altervista.org/images/08.gif\" alt=\"\" border=\"0\" />",$mess);
flock ($open,2);
fputs ($open,"
<!-- Message -->
<tr>
<td class=\"bottd\" width=\"150\">
Messaggio da <b>$name</b>
<br /> <br />
$mess
<br /> <br />
<i>$date - $time</i>
</td>
</tr>
$join
");
flock ($open,3);
fclose ($open);
// Costruisco il codice HTML
echo ("
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\" />
<meta http-equiv=\"Refresh\" content=\"2; url=index.php\" />
<title>$site (Bc - GuestBook $vers)</title>
<link rel=\"stylesheet\" type=\"text/css\" href=\"$dcss\" />
</head>
<body>
<!-- Bc - TagBoard $vers -->
<br />
<div align=\"center\">
<table cellspacing=\"1\" cellpadding=\"4\">
<tr>
<td class=\"bottd\" width=\"150\">
<div align=\"center\">
Messaggio inserito!
<br /> <br />
<a href=\"index.php\">Home</a>
</div>
</td>
</tr>
</table>
</div>
<br />
<!-- Bc - TagBoard $vers -->
</body>
</html>
");
}
?>
pagina index.php(modificato codice per far visualizzare le nuove news per prime):
Codice PHP:
<?php
/***********************************************\
* Bc - TagBoard!
* Bc Scripts (C) 2004
* Boris Carollo - bc.scripts@lycos.com
* http://bcscripts.zapto.org
\***********************************************/
// Includo le variabili importanti
include ("config.php");
include ("vars.php");
//new on 15/06/2010 by eurosalute:
$array_files=glob('*.txt')?glob('*.txt'):array();
$count_array_files=count($array_files);
if (isset($_REQUEST['nextpage']) && !empty($_REQUEST['nextpage'])){
$nextpage = trim($_REQUEST['nextpage']);
if (!is_numeric($nextpage) && !is_int($nextpage)) $nextpage=$count_array_files;
if (!file_exists("messages_page".$nextpage.".txt")) $nextpage=$count_array_files;
//$file="messages_page".$nextpage.".txt";
}
else $nextpage=$count_array_files;
$file="messages_page".$nextpage.".txt";
//end modifica
// Conto i messaggi, un "</tr>" vale un messaggio
$cont = implode ("",file($file));
$gets = substr_count ($cont,"</tr>");
// Costruisco il codice HTML
echo ("
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\" />
<title>$site (Bc - TagBoard $vers)</title>
<link rel=\"stylesheet\" type=\"text/css\" href=\"$dcss\" />
</head>
<body>
<!-- Bc - TagBoard $vers -->
<br />
<div align=\"center\">
<table cellspacing=\"1\" cellpadding=\"4\">
<tr>
<td class=\"toptd\" width=\"150\" height=\"20\">
Messaggi: <b>$gets</b>
</td>
</tr>
");
// Includo i messaggi
include ($file);
//new on 15/06/2010 by eurosalute:
echo ("Pagine: ");
//if ($gets == $messaggi_xpage) $nextpage = $nextpage+1;
for ($i=$count_array_files;$i>0;$i--) echo ("<a href=\"index.php?nextpage=$i\">$i</a> |");
//end modifica
// Footer
echo ("
<form method=\"post\" action=\"post.php\">
<tr>
<td class=\"bottd\" width=\"150\" valign=\"top\">
<div align=\"center\">
<b>Scrivi</b>
<br /> <br />
Nome:
<br />
<input type=\"text\" name=\"name\" size=\"20\" maxlength=\"15\">
<br />
Messaggio:
<br />
<input type=\"text\" name=\"mess\" size=\"20\" maxlength=\"90\">
<br /> <br />
<input type=\"submit\" name=\"send\" value=\"invia\" /> <input type=\"reset\" value=\"reset\" />
</td>
</tr>
</form>");
echo ("
</table>
</div>
<br />
<!-- Bc - TagBoard $vers -->
</body>
</html>
");
?>