View Full Version : Users Online Footer
bigmtnskier
February 2nd, 2006, 11:29 PM
Well, Here is my new footer:hugegrin: What it does is loads the html of the index page of the forum and gets the users online. Then, it picks a random user and displays it with GD.
http://frozenpeak.com/kirupa/beetypesig.php
Just to let you know.. I did not use any reference from nokrev's code :P
@a mod: Is it fine to do this, or do you not want the script loading a page from the forum? It could potentially take up some bandwidth, couldn't it? I won't apply it until I hear from one of you...
:sc:
<?php
$kirupa = file_get_contents("http://www.kirupa.com/forum/");
$blockpos = strpos($kirupa,"<!-- logged-in users -->");
$blocklen = strpos($kirupa,"<!-- end logged-in users -->") - $blockpos;
$kirupa = strip_tags(substr($kirupa, $blockpos, $blocklen));
$lines = explode("\n",$kirupa);
$linetoevaluate = "";
$nextline = false;
for($i=0; $i<count($lines); $i++){
$line = $lines[$i];
if ($nextline){
$linetoevaluate = trim($line);
break;
}
if (strpos($line,"Most users ever online") !== false){
$nextline = true;
}
}
$matches = explode(", ",$linetoevaluate);
if (count($matches) == 0){
$string = "Error Acquiring Users";
}else{
$string = "Hi " . $matches[array_rand($matches)] . "!";
}
$params = array();
$params['string'] = $string;
$params['bgcolor'] = array(0x28a9d9,0x0b75e1,0x0e5e7b);
$params['fgcolor'] = 0xffffff;
$params['size'] = 25;
$params['font'] = "Stylograph.ttf";
$params['width'] = 300;
$params['height'] = 50;
$params['align'] = "center";
$bounding = imagettfbbox($params['size'], 0, $params['font'], $params['string']);
$width = max($bounding[4] - $bounding[6], $bounding[0] - $bounding[2]);
$ybounding = imagettfbbox($params['size'], 0, $params['font'], "ygpq");
$height = max($ybounding[3] - $ybounding[5], $ybounding[1] - $ybounding[7]);
$buffer = $params['size'] / 10 + 3;
$offset_x = 0;
$offset_y = 0;
if (!isset($params['width']) || !isset($params['height'])){
$width_final = $width + $buffer;
$height_final = $height + $height / 2;
}else{
$align = ($params['align'] == "center" || $params['align'] == "right") ? $params['align'] : "left";
$width_final = $params['width'];
$height_final = $params['height'];
if ($align == "center"){
$offset_x = $width_final / 2 - ($width + $buffer) / 2 - $buffer;
}else if($align == "right"){
$offset_x = $width_final - $width - $buffer;
}else{
$offset_x = 0;
}
$offset_y = $height_final / 2 - $height / 2;
}
$canvas = imagecreatetruecolor($width_final, $height_final);
imageantialias($canvas, true);
imagefill($canvas, 0, 0, $params['bgcolor'][array_rand($params['bgcolor'])]);
imagettftext($canvas, $params['size'], 0, $offset_x, $height + $offset_y, $params['fgcolor'], $params['font'], $params['string']);
header("Content-type: image/jpeg");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
imagejpeg($canvas,"",100);
imagedestroy($canvas);
?>
-bigmtnskier :D
nobody
February 2nd, 2006, 11:36 PM
I would imagine that it wouldn't be too taxing on the forums assuming the traffic this place gets. I'd wait for kirupa's take on the situation though. That's a sweet footer though, one of my favorite's I've seen in all the years I've been here. Very smart. (Make my name bold :P )
TheCanadian
February 2nd, 2006, 11:39 PM
That is really neat :thumb:
3d Nirvana
February 2nd, 2006, 11:41 PM
cool, have it choose from the users viewing the thread it's in a the bottom.... that would be cool!
bigmtnskier
February 2nd, 2006, 11:42 PM
Thanks! :beam:
(Make my name bold :P ) :lol: I don't think its possible in GD :P
Edit:
cool, have it choose from the users viewing the thread it's in a the bottom.... that would be cool!
I would if I could, but to my knowledge that is not possible :(
Jeff Wheeler
February 2nd, 2006, 11:47 PM
Good idea. Once I tried getting some data from the specific user, but profile pages require you to be logged in. You may notice that I have an account called something like nokrev-script or similar.
I suggest you look at my code and see how I make it so that if there are more characters than will fit, it'll size it down. ;)
Oh, and you really should be using cURL rather than file_get_contents().
bigmtnskier
February 2nd, 2006, 11:50 PM
Good idea. Once I tried getting some data from the specific user, but profile pages require you to be logged in. You may notice that I have an account called something like nokrev-script or similar.
I suggest you look at my code and see how I make it so that if there are more characters than will fit, it'll size it down. ;) Thanks nokrev. Yeah, I didn't even think of resising it down. I'll do that when I get time... maybe tomorrow :) Time to finish writing an essay...
Why cURL instead of file_get_contents?
kirupa
February 3rd, 2006, 02:18 AM
Feel free to use it big ;) I doubt a few extra queries will cause any problems.
:thumb:
kdd
February 3rd, 2006, 02:23 AM
ahh, finally it said "Hi kdd!" great work! :thumb:
so, basically you're taking whatever is in between <!--logged> and <!-end> and then finding out a way to get each member name, and then making an image file using the php, right?
kirupa
February 3rd, 2006, 02:56 AM
There might be an easier way by getting the appropriate data from global.php (http://www.kirupa.com/forum/global.php) I don't fully know all of the methods in it, but I read data from that file in order to display the log-in/register thing on the left columns on the site.
nobody
February 3rd, 2006, 03:13 AM
He won't have access to that file, kirupa. If people could see your php files we'd have major security issues :)
Seb Hughes
February 3rd, 2006, 04:56 AM
Very Nice Brian :D
kdd
February 3rd, 2006, 02:12 PM
yeah kirupa, i can't see it, as xxviii said. otherwise, you guys would be in a huge trouble.
bigmtnskier
February 3rd, 2006, 03:23 PM
Thanks kirupa! I have added it up :hugegrin:
If it takes too much bandwidth or queries just delete it. I don't have a problem with that. ;)
He won't have access to that file, kirupa. If people could see your php files we'd have major security issues :) Agreed :P
-bigmtnskier
kirupa
February 3rd, 2006, 04:11 PM
Oh, I meant that there are some functions in global.php that could make this easier. I'll try to see if I can go through and provide the code needed to easily retrieve a list of users currently online as an array.
For example, this is the PHP code used to display your log-in status on the site:
<?php
//Change chdir to fit where your forum is.
$real_path = realpath("index.php");
$real_path = dirname($real_path);
chdir("$real_path/");
require('./global.php');
require('./includes/functions_user.php');
chdir("$real_path/");
echo "<body bgcolor=#D2E9FF>";
if ($vbulletin->userinfo['userid'] != 0)
{
echo "<p align=\"left\"><font size=\"1\" face=\"Verdana\">";
echo "Welcome back ";
echo "<br><strong> ";
echo $vbulletin->userinfo['username'];
echo "</strong>";
echo "<br>";
echo "<a target=\"_parent\" href=http://www.kirupa.com/forum/search.php?do=getnew";
echo ">";
echo "New Posts";
echo "</a>";
echo "<font face=\"Verdana\" size=\"3\"> </font>";
echo "| ";
echo "<a target=\"_parent\" href=http://www.kirupa.com/forum/usercp.php";
echo ">";
echo "User CP";
echo "</a>";
echo " ";
echo "</font></p>";
}
if ($vbulletin->userinfo['userid'] == 0)
{
echo "
<p><font size=\"1\" face=\"Verdana\">Welcome, <strong>Guest</strong>.<br>
Please log-in.<br>
[<a target=\"_parent\" href=\"http://www.kirupa.com/forum/register.php\"><font color=\"#0000CC\">Register</font></a>]</font><font face=\"Verdana\">
</font><font size=\"1\" face=\"Verdana\">[<a target=\"_parent\" href=\"http://www.kirupa.com/forum/login.php\"><font color=\"#0000CC\">Login</font></a>]</font><font size=\"1\"> </font></p>
";
}
?>
:goatee:
bigmtnskier
February 3rd, 2006, 04:15 PM
Although, that will not work unless the footer script is on the same server :(
Seb Hughes
February 3rd, 2006, 05:31 PM
Brian nice job. Can i use it as my footer?
bigmtnskier
February 3rd, 2006, 06:08 PM
Sure :)
Can you put a "Created by bigmtnskier" under it? Just kidding :P
Jeff Wheeler
February 3rd, 2006, 06:44 PM
@kirupa: Hey! You wouldn't do that for me! :(
bigmtnskier
February 3rd, 2006, 06:50 PM
@kirupa: Hey! You wouldn't do that for me! :( I guess mine is just cooler!
Just kidding with ya nokrev :P
Jeff Wheeler
February 3rd, 2006, 07:05 PM
I sure am jealous. ;)
nobody
February 3rd, 2006, 07:08 PM
It's the clash of the dynamic footer titans. Everyone run!
Jeff Wheeler
February 3rd, 2006, 07:10 PM
But mine's OOP. Therefore, mine's superior. ;)
bigmtnskier
February 3rd, 2006, 07:43 PM
:lol: Aha! Not anymore :P
<?php
class UsersOnlineFooter{
var $params = array();
function __construct(){
//Set the defaults
$this->params['bgcolor'] = array(0x28a9d9,0x0b75e1,0x0e5e7b);
$this->params['fgcolor'] = 0xffffff;
$this->params['size'] = 25;
$this->params['font'] = "Stylograph.ttf";
$this->params['width'] = 300;
$this->params['height'] = 50;
$this->params['align'] = "center";
}
function UsersOnlineFooter(){
$this->__construct();
}
function Create(){
$kirupa = file_get_contents("http://www.kirupa.com/forum/");
$blockpos = strpos($kirupa,"<!-- logged-in users -->");
$blocklen = strpos($kirupa,"<!-- end logged-in users -->") - $blockpos;
$kirupa = strip_tags(substr($kirupa, $blockpos, $blocklen));
$lines = explode("\n",$kirupa);
$linetoevaluate = "";
$nextline = false;
for($i=0; $i<count($lines); $i++){
$line = $lines[$i];
if ($nextline){
$linetoevaluate = trim($line);
break;
}
if (strpos($line,"Most users ever online") !== false){
$nextline = true;
}
}
$matches = explode(", ",$linetoevaluate);
if (count($matches) == 0){
$string = "Error Aquiring Users";
}else{
$usr = $matches[array_rand($matches)];
//Pick another if it is nokrev :P
$usr = ($usr == "nokrev") ? $matches[array_rand($matches)] : $usr;
$string = "Hi " . $usr . "!";
}
$bounding = imagettfbbox($this->params['size'], 0, $this->params['font'], $string);
$width = max($bounding[4] - $bounding[6], $bounding[0] - $bounding[2]);
$ybounding = imagettfbbox($this->params['size'], 0, $this->params['font'], "ygpq");
$height = max($ybounding[3] - $ybounding[5], $ybounding[1] - $ybounding[7]);
$buffer = $this->params['size'] / 10 + 3;
$offset_x = 0;
$offset_y = 0;
if (!isset($this->params['width']) || !isset($this->params['height'])){
$width_final = $width + $buffer;
$height_final = $height + $height / 2;
}else{
$align = ($this->params['align'] == "center" || $this->params['align'] == "right") ? $this->params['align'] : "left";
$width_final = $this->params['width'];
$height_final = $this->params['height'];
if ($align == "center"){
$offset_x = $width_final / 2 - ($width + $buffer) / 2 - $buffer;
}else if($align == "right"){
$offset_x = $width_final - $width - $buffer;
}else{
$offset_x = 0;
}
$offset_y = $height_final / 2 - $height / 2;
}
$canvas = imagecreatetruecolor($width_final, $height_final);
imageantialias($canvas, true);
imagefill($canvas, 0, 0, $this->params['bgcolor'][array_rand($this->params['bgcolor'])]);
imagettftext($canvas, $this->params['size'], 0, $offset_x, $height + $offset_y, $this->params['fgcolor'], $this->params['font'], $string);
header("Content-type: image/jpeg");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
imagejpeg($canvas,"",100);
imagedestroy($canvas);
}
}
$footer = new UsersOnlineFooter();
$footer->Create();
?>
-bigmtnskier :)
Jeff Wheeler
February 3rd, 2006, 07:58 PM
Blast! Too bad your Create method is !OOP. It's just all the work stuck in one big thing. ;)
Of course, mine is too…
bigmtnskier
February 3rd, 2006, 08:07 PM
Blast! Too bad your Create method is !OOP. It's just all the work stuck in one big thing. ;)
Of course, mine is too…
Ah, true indeed.
I just had an ingenious new idea :devious: I won't probably have time for it until after Feb 14th though... :(
Jeff Wheeler
February 3rd, 2006, 08:12 PM
Not another hit into my glory! :P
bigmtnskier
February 3rd, 2006, 08:48 PM
//Pick another if it is nokrev :P
$usr = ($usr == "nokrev") ? $matches[array_rand($matches)] : $usr; Touche :P btw.. this wasn't my new idea
Don't worry, I won't have user-submitted phases or the witty random funny ones... Like: "I don't eat rulers, and that's a good thing." You will indeed still have your glory. Your footers inspired me to create this thing. ;)
Jeff Wheeler
February 3rd, 2006, 08:56 PM
Ha, thanks. :)
And I was curious why I never saw mine. ;)
Oh, and what happens if either a) I'm the only person online, or b) it picks me twice? Then your little tertiary operator won't work correctly. You should use a while loop:
do { $usr = $users[array_rand($users)]; } while ($usr=="nokrev");
Although you may want to do some infinite loop check.
bigmtnskier
February 3rd, 2006, 09:28 PM
Yeah, you do have a point. It was just a joke regarding what xxviii said :P
It's the clash of the dynamic footer titans. Everyone run!
I took it out now :)
kdd
February 3rd, 2006, 10:24 PM
oh, i just found a bug... if the username is too long, "hi" gets cut off. you probably want to adjust the size of the text depending on the length of the username. :)
bigmtnskier
February 3rd, 2006, 10:34 PM
I knew about that :) I'll fix it as soon as I can ;)
Jeff Wheeler
February 3rd, 2006, 10:40 PM
Arg! I've returned your volley. :P
http://nokrev.com/dump/kirupa/bigmtskier-footer.jpg
Also added to my footer rotation.
(All in good fun, my friend.)
freeskier89
February 3rd, 2006, 11:30 PM
haha lol nokrev :P
This is getting good :D
Jeff Wheeler
February 4th, 2006, 12:11 AM
:P
bigmtnskier
February 4th, 2006, 12:15 AM
Arg! I've returned your volley. :P
http://nokrev.com/dump/kirupa/bigmtskier-footer.jpg
Also added to my footer rotation.
(All in good fun, my friend.) Haha ROFL! :lol: No offence taken :P
I guess I'll have to come up with something... hmm..
This shall be interesting! You shall wait and see....
This is war :gi:
Jeff Wheeler
February 4th, 2006, 12:35 AM
War, it is indeed. :)
Edit: To start off and remind myself of the script, I changed the submitted image format. Hope you like it. (Yes, it is a rip of the one I designed for you.)
bigmtnskier
February 4th, 2006, 01:55 AM
Nice :thumb: I like it a lot better than the old red configuration!
----
Hehe... beat this. :devious:
I made it so that the text is sized down until it fits. Also, I added "Today's Birthdays" You might have to refresh a couple times to see it...
-bigmtnskier :P
Jeff Wheeler
February 4th, 2006, 02:08 AM
Impressive. I'm working on some cURL that you'll be impressed with. ;)
bigmtnskier
February 4th, 2006, 02:14 AM
Cool. What are you creating? Don't worry I won't do it. I have never used cURL before :P
Jeff Wheeler
February 4th, 2006, 02:15 AM
I'm trying to catch some user data through logging in… as a script. ;)
bigmtnskier
February 4th, 2006, 02:17 AM
Hm.. Sounds interesting :) I guess I'll just have to wait and see!
Hacker Nokrev :P Just kidding
Jeff Wheeler
February 4th, 2006, 02:18 AM
Very true. Sadly, when I asked K to host, he wouldn't even dignify me with a response. He's never been so low. :P
bigmtnskier
February 4th, 2006, 02:19 AM
Very true. Sadly, when I asked K to host, he wouldn't even dignify me with a response. He's never been so low. :P :lol: Gee.. I wonder why... :P
Jeff Wheeler
February 4th, 2006, 02:23 AM
Because he dropped something on the floor. He told me after he got up again. ;)
Seb Hughes
February 4th, 2006, 03:31 AM
Sure :)
Can you put a "Created by bigmtnskier" under it? Just kidding :P
Thanks :love:
bigmtnskier
February 5th, 2006, 03:44 PM
Oh, Here is the sourcecode if anyone wants it :)
<?php
class KirupaFooter{
var $params = array();
function __construct(){
//Set the defaults
$this->params['bgcolor'] = array(0x28a9d9,0x0b75e1,0x0e5e7b);
$this->params['fgcolor'] = 0xffffff;
$this->params['size'] = 25;
$this->params['font'] = "Stylograph.ttf";
$this->params['width'] = 300;
$this->params['height'] = 50;
$this->params['align'] = "center";
}
function KirupaFooter(){
$this->__construct();
}
function Create_Random(){
$rand = rand(0,3);
if ($rand == 0){
$this->Create_Birthday();
}else{
$this->Create_UserOnline();
}
}
function Create_Birthday(){
$canvas = imagecreatefromjpeg("bdaybg.jpg");
$kirupa = file_get_contents("http://www.kirupa.com/forum/");
$blockpos = strpos($kirupa,"<!-- today's birthdays -->");
$blocklen = strpos($kirupa,"<!-- end today's birthdays -->") - $blockpos;
$kirupa = substr($kirupa, $blockpos, $blocklen);
$lines = explode("\n",$kirupa);
$linetoevaluate = "";
$nextline = false;
for($i=0; $i<count($lines); $i++){
$line = $lines[$i];
if ($nextline){
$linetoevaluate = strip_tags(trim($line));
break;
}
if (strpos($line,"View Birthdays") !== false){
$nextline = true;
}
}
$linetoevaluate = preg_replace("/\(\d+\), /","_____",$linetoevaluate);
$matches = explode("_____",$linetoevaluate);
if (count($matches) == 0){
//No birthdays today :(
$this->Create_UserOnline();
die();
}else{
$usr = $matches[array_rand($matches)];
$string = $usr;
}
$offset_x = 0;
$offset_y = 0;
$useStandardTextsize = true;
$bounding = imagettfbbox(18, 0, $this->params['font'], $string);
$width = max($bounding[4] - $bounding[6], $bounding[0] - $bounding[2]);
$ybounding = imagettfbbox(18, 0, $this->params['font'], "ygpq");
$height = max($ybounding[3] - $ybounding[5], $ybounding[1] - $ybounding[7]);
$txtwidth = $width;
$txtsize = 18;
while ($txtwidth >= 140){
$useStandardTextsize = false;
$txtsize -= 2;
$bounding = imagettfbbox($txtsize, 0, "Californian.ttf", $string);
$txtwidth = max($bounding[4] - $bounding[6], $bounding[0] - $bounding[2]);
}
if (!$useStandardTextsize){
$bounding = imagettfbbox($txtsize, 0, "Californian.ttf", $string);
$width = max($bounding[4] - $bounding[6], $bounding[0] - $bounding[2]);
$ybounding = imagettfbbox($txtsize, 0, "Californian.ttf", "ygpq");
$height = max($ybounding[3] - $ybounding[5], $ybounding[1] - $ybounding[7]);
}
$align = ($this->params['align'] == "center" || $this->params['align'] == "right") ? $this->params['align'] : "left";
$width_final = $this->params['width'];
$height_final = $this->params['height'];
$offset_y = $height_final / 2 - $height / 2;
$offset_x = 145 + (145 - $width)/2;
imageantialias($canvas, true);
imagettftext($canvas, $txtsize, 0, $offset_x, $height + $offset_y, 0xFF3000, "Californian.ttf", $string);
header("Content-type: image/jpeg");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
imagejpeg($canvas,"",98);
imagedestroy($canvas);
}
function Create_UserOnline(){
$kirupa = file_get_contents("http://www.kirupa.com/forum/");
$blockpos = strpos($kirupa,"<!-- logged-in users -->");
$blocklen = strpos($kirupa,"<!-- end logged-in users -->") - $blockpos;
$kirupa = strip_tags(substr($kirupa, $blockpos, $blocklen));
$lines = explode("\n",$kirupa);
$linetoevaluate = "";
$nextline = false;
for($i=0; $i<count($lines); $i++){
$line = $lines[$i];
if ($nextline){
$linetoevaluate = trim($line);
break;
}
if (strpos($line,"Most users ever online") !== false){
$nextline = true;
}
}
$matches = explode(", ",$linetoevaluate);
if (count($matches) == 0){
$string = "Error Aquiring Users";
}else{
$usr = $matches[array_rand($matches)];
$string = "Hi " . $usr . "!";
}
$offset_x = 0;
$offset_y = 0;
$useStandardTextsize = true;
$bounding = imagettfbbox($this->params['size'], 0, $this->params['font'], $string);
$width = max($bounding[4] - $bounding[6], $bounding[0] - $bounding[2]);
$ybounding = imagettfbbox($this->params['size'], 0, $this->params['font'], "ygpq");
$height = max($ybounding[3] - $ybounding[5], $ybounding[1] - $ybounding[7]);
$buffer = $this->params['size'] / 10 + 3;
$txtwidth = $width;
$txtsize = $this->params['size'];
while ($txtwidth >= $this->params['width'] - 20){
$useStandardTextsize = false;
$txtsize -= 2;
$bounding = imagettfbbox($txtsize, 0, $this->params['font'], $string);
$txtwidth = max($bounding[4] - $bounding[6], $bounding[0] - $bounding[2]);
}
if (!$useStandardTextsize){
$bounding = imagettfbbox($txtsize, 0, $this->params['font'], $string);
$width = max($bounding[4] - $bounding[6], $bounding[0] - $bounding[2]);
$ybounding = imagettfbbox($txtsize, 0, $this->params['font'], "ygpq");
$height = max($ybounding[3] - $ybounding[5], $ybounding[1] - $ybounding[7]);
$buffer = $txtsize / 10 + 3;
}
$align = ($this->params['align'] == "center" || $this->params['align'] == "right") ? $this->params['align'] : "left";
$width_final = $this->params['width'];
$height_final = $this->params['height'];
if ($align == "center"){
$offset_x = $width_final / 2 - ($width + $buffer) / 2 - $buffer;
}else if($align == "right"){
$offset_x = $width_final - $width - $buffer;
}else{
$offset_x = 0;
}
$offset_y = $height_final / 2 - $height / 2;
$canvas = imagecreatetruecolor($width_final, $height_final);
imageantialias($canvas, true);
imagefill($canvas, 0, 0, $this->params['bgcolor'][array_rand($this->params['bgcolor'])]);
imagettftext($canvas, $txtsize, 0, $offset_x, $height + $offset_y, $this->params['fgcolor'], $this->params['font'], $string);
header("Content-type: image/jpeg");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
imagejpeg($canvas,"",100);
imagedestroy($canvas);
}
}
$footer = new KirupaFooter();
$footer->Create_Random();
?>
It's a mess.. I know.. :P
-Bigmtnskier
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.