Change default theme based on amount of online users

  Post new topicReply to topicPrintable Version
<< View previous topic View next topic >>
Share: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
#1   Change default theme based on amount of online users
diabluntd
CZ Newbie
Status: Offline
Joined: Oct 31, 2003
0.00 posts per day
Posts: 6
Points: 784
   
I'm looking for a mod to change my default theme when my site hits a certain amount of online users. I haven't seen one that exists already but if there is i apologize (and would like a link) icon_smile.gif

Does anybody out there feel like working on this with me? I know nuke very well.... but i'm not a coder at ALL. I would think it shouldn't be too hard and i think it would be a useful mod that a lot of people who lack dedicated server resources would utilize.

If you think you're able to tackle this or can point me in the right direction i would REALLY appreciate it!

Thanks,
Diab



Back to top Reply with quote
#2   
Telli
Site Admin
Occupation: Self Employed
Age: 46
Gender: Male
Fav. Sports Team: Detroit Red Wings
Website:
Status: Offline
Joined: May 26, 2003
1.03 posts per day
Posts: 8089
Points: 494,430
   
If there a user then there theme is stored in thier cookie kinda hard to change that unless you re set the cookie and do a page refresh everytime you hit the number. Now for people that arn't a user you could just do something this inside your function online located in your mainfile.php. If you paste the code I'll show you what to put there.




_________________
The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he, who in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee. Ezekiel 25:17
Back to top Reply with quote
#3   
diabluntd
CZ Newbie
Status: Offline
Joined: Oct 31, 2003
0.00 posts per day
Posts: 6
Points: 784
   


Originally posted by Telli @ Thu Feb 24, 2005 3:01 am:

If there a user then there theme is stored in thier cookie kinda hard to change that unless you re set the cookie and do a page refresh everytime you hit the number. Now for people that arn't a user you could just do something this inside your function online located in your mainfile.php. If you paste the code I'll show you what to put there.
Thanks a bunch man. Yeah, i'm not worried about users logged in, only visitors. In 99% of the situations when a lot of users are online they're mostly visitors.

Here is my function online... running PNP 7.6

function online() {
    global $user, $cookie, $prefix, $db;
    cookiedecode($user);
    $ip = $_SERVER["REMOTE_ADDR"];
    $uname = $cookie[1];
    if (!isset($uname)) {
        $uname = "$ip";
        $guest = 1;
    }
    $past = time()-1200;
    $db->sql_query("DELETE FROM ".$prefix."_session WHERE time < '$past'");
    $result = $db->sql_query("SELECT time FROM ".$prefix."_session WHERE uname='$uname'");
    $ctime = time();
    if ($uname!="") {
    $uname = substr("$uname", 0,25);
    if ($row = $db->sql_fetchrow($result)) {
   $db->sql_query("UPDATE ".$prefix."_session SET uname='$uname', time='$ctime', host_addr='$ip', guest='$guest' WHERE uname='$uname'");
    } else {
   $db->sql_query("INSERT INTO ".$prefix."_session (uname, time, host_addr, guest) VALUES ('$uname', '$ctime', '$ip', '$guest')");
    }
  }
}
]

*edit* just some quick notes...
if the # of users could be easily configurable though a variable or whatever that would probably help keep the mod nice and easy. also, it's probably obvious but the code should check for greater then X amount of users then change to the "lite" theme but also check for less then X amount of users to change it back to the default theme. thx again in advance.


Back to top Reply with quote
#4   
Telli
Site Admin
Occupation: Self Employed
Age: 46
Gender: Male
Fav. Sports Team: Detroit Red Wings
Website:
Status: Offline
Joined: May 26, 2003
1.03 posts per day
Posts: 8089
Points: 494,430
   
Try this out..


function online() {
    global $user, $cookie, $prefix, $db;
    cookiedecode($user);
    $ip = $_SERVER["REMOTE_ADDR"];
    $uname = $cookie[1];
    if (!isset($uname)) {
        $uname = "$ip";
        $guest = 1;
    }
    $past = time()-1200;
    $db->sql_query("DELETE FROM ".$prefix."_session WHERE time < '$past'");
   
    $maxswitch = 100; //Online number that theme will switch at
    $maxswitchtheme = "DeepBlue"; //When $maxswitch is reached
    $minswitchtheme = "ExtraLite"; //Under $maxswitch
    $result = $db->sql_query("select Default_Theme from ".$prefix."_config");
    list($maintheme) = $db->sql_fetchrow($result);
    $onlinenum = $db->sql_numrows($db->sql_query("SELECT * FROM ".$prefix."_session"));
    if ($onlinenum > $maxswitch) {
           if ($maintheme != $maxswitchtheme) {
               $db->sql_query("UPDATE ".$prefix."_config SET Default_Theme='$maxswitchtheme'");
           }
    } elseif ($onlinenum < $maxswitch) {
           if ($maintheme != $minswitchtheme) {
               $db->sql_query("UPDATE ".$prefix."_config SET Default_Theme='$minswitchtheme'");
           }
    }

    $result = $db->sql_query("SELECT time FROM ".$prefix."_session WHERE uname='$uname'");
    $ctime = time();
    if ($uname!="") {
    $uname = substr("$uname", 0,25);
    if ($row = $db->sql_fetchrow($result)) {
   $db->sql_query("UPDATE ".$prefix."_session SET uname='$uname', time='$ctime', host_addr='$ip', guest='$guest' WHERE uname='$uname'");
    } else {
   $db->sql_query("INSERT INTO ".$prefix."_session (uname, time, host_addr, guest) VALUES ('$uname', '$ctime', '$ip', '$guest')");
    }
  }
}




_________________
The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he, who in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee. Ezekiel 25:17
Back to top Reply with quote
#5   re: Change default theme based on amount of online users
diabluntd
CZ Newbie
Status: Offline
Joined: Oct 31, 2003
0.00 posts per day
Posts: 6
Points: 784
   
I had pieced something together that worked but i'm going to use yours since you know what you're doing. icon_smile.gif

only problem with the above code... in case anybody else wants to use this...

when telli grabbed all the sessions he used $onlinenum

when he checks twice if it's above or below he used $onlinnum (with no e). otherwise this works great and i've already taken advantage of it. i'm on shared hosting and the current main theme i use is XHalo, made by the techgfx team. It's a great looking theme but is very intensive. I'm looking into changing away from it totally but for now this is great. I set it to 85 members (a little low but mine as well start saving resources early) and my site was flying with a lot of members on... without this switch my site really started to crawl with the same number.

Thanks telli, you rock!



Back to top Reply with quote
#6   
Telli
Site Admin
Occupation: Self Employed
Age: 46
Gender: Male
Fav. Sports Team: Detroit Red Wings
Website:
Status: Offline
Joined: May 26, 2003
1.03 posts per day
Posts: 8089
Points: 494,430
   
Thanks I corrected the typo.




_________________
The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he, who in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee. Ezekiel 25:17
Back to top Reply with quote
Display posts from previous:      
Add To: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
<< View previous topic View next topic >>
Post new topicReply to topic

Jump to 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum