Hey guys, i’ve been fiddling about with the php source for nokrev’s random footer generator trying to get this working for a different forum I am active on and have came across a few errors…hopefully someone here with a better understanding of PHP can help out as I am only beginning with PHP so spotting the error here has become slightly problematic.
You can see the errors that appear by refreshing the signature page, here:
http://www.bantermarket.com/forum/footer/footer.php
Here is the code for the footer.php file:
Footer.php
<?php
class Footer {
var $directory;
var $myPhrases;
var $yourPhrases;
var $userSubmittedImage;
var $font;
var $origin;
function getMyPhrases () {
// Make sure $file exist
if ( file_exists ( $this->directory."/".$this->myPhrases ) ) {
return explode ( "
", file_get_contents($this->directory."/".$this->myPhrases) );
} else return false; // Return false if file not found
}
function getYourPhrases () {
// Make sure $file exist
if ( file_exists ( $this->directory."/".$this->yourPhrases ) ) {
return explode ( "
", file_get_contents($this->directory."/".$this->yourPhrases ) );
} else return false; // Return false if file not found
}
function makeFooter () {
$myPhrases = $this->getMyPhrases();
$yourPhrases = $this->getYourPhrases();
$font = "HALVAR__.TTF";
if ( rand(0,1) == 0 ) {
$string = $myPhrases[rand ( 0, count ( $myPhrases ) - 1 )];
$this->origin = 1;
} else {
$string = $yourPhrases[rand ( 0, count ( $yourPhrases ) -1 )];
$this->origin = 2;
}
$backgrounds = array (
array ( 77, 52, 55 ),
array ( 63, 82, 95 ),
array ( 211, 234, 187 )
);
$colors = array (
array ( 242, 222, 224 ),
array ( 199, 216, 227 ),
array ( 79, 95, 63 )
);
$pallet = rand(1,count($backgrounds))-1;
$bg = $backgrounds[$pallet];
$cl = $colors[$pallet];
// Create Image
if ( $this->origin == 1 ) { // From scratch
$im = @imagecreate(300, 60);
$background_color = imagecolorallocate($im, $bg[0], $bg[1], $bg[2]);
$text_color = imagecolorallocate($im, $cl[0], $cl[1], $cl[2]);
imageantialias($im, 1);
} else { // Based off "user submitted" image
$im = imagecreatefrompng($this->userSubmittedImage);
$cl = array ( 252, 239, 235 );
$text_color = imagecolorallocate($im, $cl[0], $cl[1], $cl[2]);
imageantialias($im, 1);
}
// Loop through font sizes and center
if ( $this->origin == 1 ) {
for ( $fontsize = 28; $fontsize > 5; $fontsize-- ) {
$size = imagettfbbox ( $fontsize, 0, $font, $string );
if ( $size[2] < 270 ) {
imagettftext($im, $fontsize, 0, 15, 30-$size[5]/2, $text_color, $font, $string); break;
}
}
} else {
imagettftext($im, 18, 0, 5, 48, $text_color, $font, $string);
}
// Flush the output
$img = imagepng($im);
imagedestroy($im);
return $img;
}
function grabFooter () {
// Get Files
$dh = opendir($this->directory);
while (false !== ($filename = readdir($dh))) {
if ( strstr ( $filename, "txt" ) == false && $filename != $this->userSubmittedImage && $filename != $this->font ) {
$files[] = $filename;
}
}
sort($files);
// Remove . and ..
array_shift($files);
array_shift($files);
// Count and Randomize
$rand = rand(1, count($files))-1;
return $files[$rand];
}
function pickFooter () {
if ( rand ( 0,1 ) == 0 ) {
header("Content-type: image/png");
echo $this->makeFooter();
} else {
$file = $this->grabFooter();
switch ( strstr($file,".") ) {
case ".jpg":
case ".jpeg":
header("Content-type: image/jpeg");
break;
case ".gif":
header("Content-type: image/gif");
break;
case ".png":
header("Content-type: image/png");
break;
}
include ( "../../forum/footer/" . $file );
}
return true;
}
}
$footer = new Footer();
$footer->directory = "/home/bantmcs1/public_html/forum/footer/";
$footer->myPhrases = "your_phrases.txt"; // in images directory
$footer->yourPhrases = "your_phrases.txt"; // this too
$footer->userSubmittedImage = "usersubmitted.png"; // and this
$footer->font = "HALVAR__.TTF"; // and this...
$footer->pickFooter();
?>
And the code for the submit.php:
Submit.php
<?php
if ( isset ( $_POST['submit'] ) && isset ( $_POST['message'] ) ) {
$f = fopen("/home/bantmcs1/public_html/forum/footer/your_phrases.txt",'a');
$added = fwrite($f, "
".$_POST['message']);
fclose($f);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Signature Generator - nokrev</title>
</head>
<body>
<h1>Signature Generator - nokrev</h1>
<?php if ( $added ) { ?>
<p><strong>Success</strong>. Your message has been added to the list.</p>
<?php } ?>
<p>These appear marked as "User Submitted Message", when randomly seen
through my signature</p>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="comment_form">
<fieldset><legend>Forum Footer Messages</legend>
<div>
<label for="message">Message</label>
<input tabindex="1" id="message" name="message" />
<input type="submit" name="submit" tabindex="2" value="Submit"
/>
</div>
</fieldset>
</form>
<img src="footer.php" alt="KForum Footer Preview" />
</body>
</html>
Both are located in the same directory, and the paths seem to be fine yet there are still some errors.
Also, both text files have been CHMOD to 777.
The code was slightly modified to allow only user submitted content, I know for a fact this is not whats wrong though as before it was giving me errors too.
Appreciate any help :whistle: