Code:
<?php
if(phpversion() >= "4.2.0")
{
//PHP 4.2.0 Patch
extract($HTTP_POST_VARS);
extract($HTTP_GET_VARS);
}
// use smileys > true or false
$useSmileys = true;
// reverse answer list > true or false
$reverseAnswers = false;
// number of answers/topics per page
$itemsPerPage = 20;
//----------------------------------------------------------------------------------------------
// retrieving all variables
//----------------------------------------------------------------------------------------------
if($_POST) { extract($_POST, EXTR_PREFIX_SAME, "post_"); }
if($_GET) { extract($_GET, EXTR_PREFIX_SAME, "get_"); }
if($_COOKIE) { extract($_COOKIE, EXTR_PREFIX_SAME, "cookie_"); }
if(!isset($_ForumNick)) { $_ForumNick = ""; }
//----------------------------------------------------------------------------------------------
// list the available topics and print add topic form
//----------------------------------------------------------------------------------------------
if (!isset($act) || $act == "list") {
// reading topic list into array
$n = 0;
$list = array();
$fp = fopen("data/topics.txt", "r");
while (!feof($fp)) {
$lastpost = fgets($fp, 1024);
$nickname = fgets($fp, 1024);
$description = fgets($fp, 1024);
$file = fgets($fp, 1024);
$ans = fgets($fp, 1024);
if ($lastpost && $nickname && $description && $file && $ans) {
$list[$n][0] = str_replace("\n","",$lastpost);
$list[$n][1] = str_replace("\n","",$nickname);
$list[$n][2] = str_replace("\n","",$description);
$list[$n][3] = str_replace("\n","",$file);
$list[$n][4] = str_replace("\n","",$ans);
$n++;
}
}
fclose($fp);
array_multisort($list);
$list = array_reverse($list);
// checking the number of last topic in case a topic will be added
$max = 0;
for($i=0; $i<sizeof($list); $i++) {
if ( intval($list[$i][3]) > $max) { $max = intval($list[$i][3]); } }
// start printing the page
include("header.php");
?>
<table border="0" cellpadding="4" cellspacing="0" width="700"><tr>
<td class="row" width=20%>Poslao/la</td>
<td class="row" width="45%">Naslov poruke</td>
<td class="row" width=15%>Odgovora</td>
<td class="row" width=20%>Poslednji upis </td>
</tr>
<?
// build pagination
if (!isset($s)) { $s=0; $e=$itemsPerPage; } else { $e=$s+$itemsPerPage; }
if($e>sizeof($list)) { $e=sizeof($list); }
//show pagination
if ($s>0) {
echo "<tr><td colspan=\"4\"></td></tr>";
echo "<tr><td></td><td class=\"grey\" colspan=\"3\">prikaz ".($s+1)."-$e od ".sizeof($list)."\n";
echo " | <a href=\"?s=".($s-$itemsPerPage)."\" class=\"grey\">prethodna stranica</a>\n";
echo "</td></tr><tr><td colspan=\"4\"></td></tr>\n\n";
}
// building the topic list
for ($i=$s; $i<$e; $i++) {
if ($i/2 == round($i/2)) { echo " <tr>\n"; }
else { echo " <tr class=\"light\">\n"; }
echo" <td>".$list[$i][1]."</td>\n";
echo " <td><a href=?act=show&nr=".$list[$i][3].">".$list[$i][2]."</td>\n";
echo " <td>".$list[$i][4]."</td><td>".date("d. m. Y. u H:i", $list[$i][0])."</td></tr>\n\n";
}
// show pagination
if ($e != sizeof($list)) {
echo "<tr><td colspan=\"4\"></td></tr>";
echo "<tr><td class=\"grey\"></td><td class=\"grey\" colspan=\"3\">prikaz ".($s+1)."-$e od ".sizeof($list)."\n";
echo " | <a href=\"?s=".($s+$itemsPerPage)."\" class=\"grey\">naredna stranica</a>\n";
echo "</td></tr>\n\n";
}
//showing the topic form
?>
<script language="javascript">
function checkform (form) {
if (form["desc"].value == "") {
alert("Please insert Description");
form["desc"].focus();
return false ; }
if (form["nick"].value == "") {
alert("Please insert Nickname");
form["nick"].focus();
return false ; }
if (form["txt"].value == "") {
alert("Please insert Questions/Remarks");
form["txt"].focus();
return false ; }
return true; }
</script>
<form action="?act=addt" method="post" name="form" onsubmit="return checkform(this);">
<input type="hidden" name="nr" value="<? echo $max+1; ?>">
<tr><td colspan="4"><br></td></tr>
<tr><td class="row"></td>
<td colspan="3" class="row">Započni temu</td>
</tr>
<tr>
<td style="vertical-align:middle">Ime:</td>
<td colspan="3"><input type="text" name="nick" value="<?=$_ForumNick?>" maxlength="20"></td></tr>
<tr>
<td style="vertical-align:middle">Naslov teme:</td>
<td colspan="3"><input type="text" name="desc" maxlength="40"></td></tr>
<tr>
<td style="padding-top:8px">Poruka:</td>
<td colspan="3"><textarea rows="6" name="txt"></textarea></td></tr>
<tr><td></td><td colspan=3><? if ($useSmileys == true) { insertSmileys(); } ?></td></tr>
<tr><td></td><td colspan="3"><input type="submit" value="Pošalji" class="button"></td>
</tr></table>
</form>
<?
//closing the page
include("footer.php");
//----------------------------------------------------------------------------------------------
// show the specified topic list and add answer form
//----------------------------------------------------------------------------------------------
} else if ($act == "show") {
// reading the answers into an array
$n = 0;
$topic = array();
$fp = fopen("data/topic".$nr.".txt", "r");
$description = str_replace("\n","",fgets($fp, 1024));
while (!feof($fp)) {
$date = fgets($fp, 1024);
$nickname = fgets($fp, 1024);
$text = fgets($fp, 9000);
if ($date && $nickname && $text) {
$topic[$n][0] = str_replace("\n","",$date);
$topic[$n][1] = str_replace("\n","",$nickname);
$topic[$n][2] = str_replace("\n","",$text);
$n++;
}
}
fclose($fp);
if ($reverseAnswers == true) { $topic = array_reverse($topic); }
// start building the page
include("header.php");
?>
<table border="0" cellpadding="4" cellspacing="0" width=560><tr>
<td class="row" width="25%"></td><td class="row" width="75%"><?=$description?></td></tr>
<?
// build pagination
if (!isset($s)) { $s=0; $e=$itemsPerPage; } else { $e=$s+$itemsPerPage; }
if($e>sizeof($topic)) { $e=sizeof($topic); }
//show pagination
echo "<tr><td colspan=\"2\"></td></tr>";
echo "<tr><td></td><td class=\"grey\">odgovor ".($s+1)."-$e od ".sizeof($topic)."\n";
echo " | <a href=\"?act=list\" class=\"grey\">nazad na teme</a>\n";
if ($s>0) { echo " | <a href=\"?act=show&nr=$nr&s=".($s-$itemsPerPage)."\" class=\"grey\">prethodna stranica</a>\n"; }
echo "</td></tr><tr><td colspan=\"2\"></td></tr>\n\n";
// print answers list
for ($i=$s; $i<$e; $i++) {
if ($i/2 != round($i/2)) { echo " <tr>\n"; }
else { echo " <tr class=\"light\">\n"; }
echo " <td><b>".$topic[$i][1]."</b><br>".date("d. m. Y. u H:i", $topic[$i][0])."</td>\n";
if ($useSmileys == true) {
echo " <td>".showSmileys($topic[$i][2])."\n\n </td></tr>\n\n";
} else {
echo " <td>".$topic[$i][2]."\n\n </td></tr>\n\n";
}
}
// show pagination
echo "<tr><td colspan=\"2\"></td></tr>";
echo "<tr><td class=\"grey\"></td><td class=\"grey\">odgovor ".($s+1)."-$e od ".sizeof($topic)."\n";
echo " | <a href=\"?act=list\" class=\"grey\">nazad na teme</a>\n";
if ($e != sizeof($topic)) { echo " | <a href=\"?act=show&nr=$nr&s=".($s+$itemsPerPage)."\" class=\"grey\">naredna</a>\n"; }
echo "</td></tr>\n\n";
// print reaction form
?>
<script language="javascript">
function checkform (form) {
if (form["nick"].value == "") {
alert("Please insert Nickname");
form["nick"].focus();
return false ; }
if (form["txt"].value == "") {
alert("Please insert Answer");
form["txt"].focus();
return false ; }
return true; }
</script>
<form name="form" action="?act=adda" method="post" onsubmit="return checkform(this);">
<input type="hidden" name="nr" value="<?=$nr?>">
<tr><td colspan="2"><br></td></tr>
<tr><td class="row"></td>
<td class="row">Odgovori</td>
</tr>
<tr><td style="vertical-align:middle">Ime:</td>
<td><input type="text" name="nick" value="<?=$_ForumNick?>" maxlength=20></td></tr>
<tr><td style="padding-top:8px">Poruka:</td>
<td><textarea rows="6" name="txt"></textarea></td></tr>
<tr><td></td><td colspan="3"><? if ($useSmileys == true) { insertSmileys(); } ?></td></tr>
<tr><td></td><td><input type="submit" value="Odgovori" class="button"></td>
</tr></table>
</form>
<?
include("footer.php");
//----------------------------------------------------------------------------------------------
// add a topic from the form to the topic list
//----------------------------------------------------------------------------------------------
} else if ($act == "addt") {
// save nickname as cookie
setcookie("_ForumNick", $nick, time()+3600*24*90);
// strip tags
$desc = substr(strip_tags($desc),0,40);
$nick = substr(strip_tags($nick),0,20);
$txt = strip_tags($txt);
// add topic to list
$fp = fopen("data/topics.txt", "a");
fputs($fp, time()."\n");
fputs($fp, stripslashes($nick)."\n");
fputs($fp, stripslashes($desc)."\n");
fputs($fp, stripslashes($nr)."\n");
fputs($fp, "0\n");
fclose($fp);
// add first answer to topic
$fp = fopen("data/topic".$nr.".txt", "w");
fputs($fp, stripslashes($desc)."\n");
fputs($fp, time()."\n");
fputs($fp, stripslashes($nick)."\n");
fputs($fp, stripslashes(str_replace("\r", "", str_replace("\n", "", nl2br($txt))))."\n");
fclose($fp);
// jump to topic
header("Location: index.php?act=show&nr=$nr");
//----------------------------------------------------------------------------------------------
// add an answer to the current topic
//----------------------------------------------------------------------------------------------
} else if ($act == "adda") {
// save nickname as cookie
setcookie("_ForumNick", $nick, time()+3600*24*90);
// strip tags
$nick = substr(strip_tags($nick),0,20);
$txt = strip_tags($txt);
// add answer to the corresponding topic
$fp = fopen("data/topic".$nr.".txt", "a");
fputs($fp, time()."\n");
fputs($fp, stripslashes($nick)."\n");
fputs($fp, stripslashes(str_replace("\r", "", str_replace("\n", "", nl2br($txt))))."\n");
fclose($fp);
// read the topic list
$n = 0;
$list = array();
$fp = fopen("data/topics.txt", "r");
while (!feof($fp)) {
$lastpost = fgets($fp, 1024);
$nickname = fgets($fp, 1024);
$description = fgets($fp, 1024);
$file = fgets($fp, 1024);
$ans = fgets($fp, 1024);
// update time and munber of andwers to the right topic
if ($lastpost && $nickname && $description && $file && $ans) {
if (trim($file) == $nr) { $list[$n][0] = time()."\n"; }
else { $list[$n][0] = $lastpost; }
$list[$n][1] = $nickname;
$list[$n][2] = $description;
$list[$n][3] = $file;
if (trim($file) == $nr) { $list[$n][4] = ($ans+1)."\n"; }
else { $list[$n][4] = $ans; }
}
$n++;
}
fclose($fp);
// write the updated topic list
$fp = fopen("data/topics.txt", "w");
for ($i=0; $i<sizeof($list); $i++) {
fputs($fp, stripslashes($list[$i][0]));
fputs($fp, stripslashes($list[$i][1]));
fputs($fp, stripslashes($list[$i][2]));
fputs($fp, stripslashes($list[$i][3]));
fputs($fp, stripslashes($list[$i][4]));
}
fclose($fp);
// jump to topic
header("Location: index.php?act=show&nr=$nr");
}
?>
Ovde hocu da ubacim IP:
Code:
for ($i=$s; $i<$e; $i++) {
if ($i/2 != round($i/2)) { echo " <tr>\n"; }
else { echo " <tr class=\"light\">\n"; }
echo " <td><b>".$topic[$i][1]."</b><br>".date("d. m. Y. u H:i", $topic[$i][0])."</td>\n";
Izmedju topic i date.
Ovako izgleda deo u .txt fajlu sa pohranjenim podacima:
Code:
Proba|1118230602|Psyche|tra la la