PDA

View Full Version : Footer with Content Submissions



Jeff Wheeler
October 9th, 2005, 01:17 AM
I've finally gotten around to adding the final (for now) feature to my footer. You can submit your own content :)

Submit your own:
http://deadstats.nokrev.com/submission.php

View the footer (without visiting the kforums):
http://deadstats.nokrev.com/footer.php

Source code (view variables at the bottom to use it yourself):

<?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 ( "\n", 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 ( "\n", 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 = "MyriadPro-Bold.otf";

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 Ranhdomize
$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 ( "../images/kirupa_footers/" . $file );
}
return true;
}
}

$footer = new Footer();
$footer->directory = "[path to your images]";
$footer->myPhrases = "phrases.txt"; // in images directory
$footer->yourPhrases = "yourPhrases.txt"; // this too
$footer->userSubmittedImage = "usersubmitted.png"; // and this
$footer->font = "MyriadPro-Bold.otf"; // and this...

$footer->pickFooter();

?>

And the source for the submission page:

<?php
if ( isset ( $_POST['submit'] ) && isset ( $_POST['message'] ) ) {
$f = fopen("[path to your file]/yourPhrases.txt",'a');
$added = fwrite($f, "\n".$_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>Submit KForum Footer Messages</title>
</head>
<body>
<h1>Submit a KForum Footer Message</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 the KForum footer.</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>

nobody
October 9th, 2005, 01:45 AM
It needs a bit of work. It cut off antidisestablishmentariansms. Sheesh!

Jeff Wheeler
October 9th, 2005, 01:51 AM
Yeah. On my messages, that problem is fixed.

B3NKobe
October 9th, 2005, 01:56 AM
Well i have refreshed the page like 30 times waiting for my msg to appear :-(

bigmtnskier
October 9th, 2005, 01:57 AM
I think I found a typo in your code :P


action="<?php echo $_SERVER['PHP_SERLF']; ?>"

Jeff Wheeler
October 9th, 2005, 02:07 AM
What's the error?

bigmtnskier
October 9th, 2005, 02:09 AM
PHP_SERLF should be PHP_SELF

:)

Jeff Wheeler
October 9th, 2005, 02:13 AM
Ha. Indeed, nice find. Changing now, thanks :)

Jeff Wheeler
October 9th, 2005, 03:06 AM
Sorry for double posting, but my friend just created a script that'll download and it'll list all the ones he has:
http://blakek.com/phptest/download/view.php

To add more to the list, simply keep hitting this page:
http://blakek.com/phptest/download/

2nd day
October 9th, 2005, 09:27 AM
man, your footer rocks! i totally love this idea!

btw the "this is not my message"-footer is mine

Jeff Wheeler
October 9th, 2005, 10:51 AM
Heh, thanks :)

icio
October 10th, 2005, 08:33 AM
How about a preview feature before actually submitting? That way we don't accidentally submit stuff that looks rubbish.

eilsoe
October 10th, 2005, 08:45 AM
is there a way to get different footers here on the boards? I get the same one all the way down the page... it's be nice to have more :(

Jeff Wheeler
October 10th, 2005, 12:32 PM
I prevented it from doing that to protect it from getting bigger than 15 mb.

bigmtnskier
October 10th, 2005, 12:44 PM
can you get different footers on each post by setting the time to expire in the past?

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

Jeff Wheeler
October 10th, 2005, 12:45 PM
I know about how to do it, but I don't think I'm allowed.

bigmtnskier
October 10th, 2005, 12:46 PM
Why? Bandwidth?

Jeff Wheeler
October 10th, 2005, 12:47 PM
Because your footer isn't allowed to be larger than 15mb, and having several could be greater.

bigmtnskier
October 10th, 2005, 12:48 PM
Ahh that makes sense :lol:

Okay

Jeff Wheeler
October 10th, 2005, 12:50 PM
Actually, now that I've used this, is still doesn't work even when I try:


header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache, must-revalidate");

bigmtnskier
October 10th, 2005, 04:32 PM
Hm... wierd, I wonder if there is another way to get around cacheing...

Krilnon
October 10th, 2005, 04:35 PM
Correction: Footers can't be bigger than 15.0 KB ;) You said mb twice. :P

Jeff Wheeler
October 10th, 2005, 04:58 PM
I can never get that stuff right…

medicated
October 10th, 2005, 08:26 PM
Ooooh, thats pretty cool. Hmm, seems like i've seen something like this used for advertising but I can't remember where.

deletedUser459
October 10th, 2005, 08:27 PM
i think its great nokrev, except i think it would be cool if there were different color schemes for the user submitted ones. i don't really like seeing the same thing over and over



i see 'rawr' a lot. is there a reason that comes up so often?

Jeff Wheeler
October 10th, 2005, 08:29 PM
Yeah, the guy who submitted rawr submitted it a gazillion times ;)

I'll work on more color schemes when I get time…

b.rich
October 11th, 2005, 12:52 AM
Nice idea Nokrev. Thanks for sharing.

hl
October 11th, 2005, 01:11 AM
it's not going to change on each post because the cache WILL have a little bit in it. else a site wouldn't be able to display. a video will not stream. when you refresh it gives a new one. else there is a small expanding cache :P

man my footer would be so much more understandable had it been displayed in different colors all over the page :P

hl
October 11th, 2005, 01:14 AM
submitted a couple messages a million times :P you really should disable duplication.

Jeff Wheeler
October 11th, 2005, 05:33 PM
Yeah, I don't have time though at the moment. School again :(