...

View Full Version : Page Layout Help



MindTheGap
02-21-2008, 11:07 PM
First: here is my script:

<?php
// Configuration (change these if you want)
$filename = "shouts.txt"; // The file to store shouts in
$date = "jS M, g:i A"; // Date format for shouts (see http://php.net/date)
$timemod = 0; // Time modifier, in hours, use this to adjust the time
$amount = 0; // Amount of shouts to show (0 = all)


$shouthtml = <<<HTML
{date}
<br />
{message}
<p />
HTML;

$html = <<<HTML
{shouts}
<form method="post">
{errors}
<p />
Message: <input type="text" name="message" />
<p />
<input type="submit" name="submit" value="Shout" />
</form>
<p />

HTML;

// Code

if (!file_exists($filename))
{
// File does not exist, create it
$f = @fopen($filename, "w") or die("Cannot access $filename, wrong permissions maybe?");
fclose($f);
}

if (isset($_POST['submit']))
{
// User has clicked the "Shout" button

// Make safe all posted data, also store other data
if (get_magic_quotes_gpc())
{
$postmessage = trim(stripslashes(htmlspecialchars($_POST['message'])));
}
else
{
$postmessage = trim(htmlspecialchars($_POST['message']));
}
$postdate = time();

if ($postmessage == "")
{
$error .= "<span style=\"color: #FF0000;\">Please enter a message.</span> <br />";
}

if (isset($error))
{
// An error has occurred
// Format "error" part of HTML
$html = str_replace("{errors}", $error . "<p />", $html);
}
else
{
// No errors :)
// Add the shout
$f = fopen($filename, "a");
fwrite($f, "[Date] $postdate\n[Msg] $postmessage\n");
fclose($f);
header("Location: " . $_SERVER['PHP_SELF']);
die();
}
}

// Below: Handle all "shout" formatting

$i = 0;
$f = file($filename);
foreach ($f as $val)
{
// Loop through every line in $filename
if (preg_match("/\[Date\] [^A-Za-z ][0-9].*/", $val))
{
// Date line
$shout[$i]['date'] = str_replace("[Date]", "", $val);
}
if (preg_match("/\[Msg\] .*/", $val))
{
// Message line
$shout[$i]['message'] = str_replace("[Msg]", "", $val);
$i++;
}
}

// Have shouts going from the top-down
$i = 0;
$shout = @array_reverse($shout);

if (isset($shout))
{
// If shouts exist
foreach ($shout as $val => $key)
{
// Limit shouts according to $amount
if ($i == $amount && $i != 0)
{
}
else
{
// Create shout HTML
$timeadd = (3600 * $timemod);
$moddate = date($date, $key['date'] + $timeadd); // Add time modifier to date

$temphtml = str_replace("{date}", $moddate, $shouthtml);
$temphtml = str_replace("{message}", $key['message'], $temphtml);
$allshouts .= $temphtml;
$i++;
}
}
}

// Below: Handle all formatting

// Format HTML to be outputted
$html = str_replace("{shouts}", $allshouts, $html);
$html = str_replace("{errors}", "", $html);
echo $html;

?>


I need to change it so that the message entering form always stays at the top. Any idea how to do this? Thanks.

MindTheGap
02-21-2008, 11:09 PM
Or, if possible make it so that after 50 shouts it creates a new page. (like facebook, or myspace)

_Aerospace_Eng_
02-21-2008, 11:13 PM
Why not just hard code the form into the html? As to the new page creation you are looking for pagination. There are many scripts available many of them for free on the net.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum