Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Author Topic: [MOD] Users Online v.0.1 (sNews All Versions)  (Read 7749 times)

bramsyuur

  • Hero Member
  • *****
  • Karma: 23
  • Posts: 873
    • http://snews.vietbee.net
[MOD] Users Online v.0.1 (sNews All Versions)
« on: May 12, 2006, 02:27:20 AM »

This is a mod for adding, anywhere in your site, a comment about your connected users.

*******************************
** Backup your snews file FIRST!!! **
*******************************

- First of all, create a file named "users_ip_list.txt" and make it chmoded 777 in the same directory of snews are.
- Next, create under //WEBSITE FUNCTIONS this code:
Code: [Select]
// Mod Users Online by bramsyuur
function users_online() {
$rip = $_SERVER['REMOTE_ADDR'];
$sd  = time();
$count = 1;

$file1 = "users_ip_list.txt";
$lines = file($file1);
$line2 = "";

foreach ($lines as $line_num => $line)
        {
        $fp = strpos($line,'****');
        $nam = substr($line,0,$fp);
        $sp = strpos($line,'++++');
        $val = substr($line,$fp+4,$sp-($fp+4));
        $diff = $sd-$val;
        if($diff < 300 && $nam != $rip)
            {
            $count = $count+1;
            $line2 = $line2.$line;
            }
        }
$my = $rip."****".$sd."++++\n";
$open1 = fopen($file1, "w");
fwrite($open1,"$line2");
fwrite($open1,"$my");
fclose($open1);

echo "

". l('users_online') ." ($count)

";
}
- Next, add into // LANGUAGE VARIABLES, this:
Code: [Select]
// MOD Users online by bramsyuur
$l['users_online'] = "Users online"; // The text that you want to display.
- Final steep, add anywhere you want, into your index.php this function:
Code: [Select]
And this is all!! :D
Here a 'super-wide-panoramic' :D working screenshot:

Thanks,
bramsyuur
Logged
La comunidad sNews en tu idioma!
Comunidad sNews en Espaņol

gomisan

  • Full Member
  • ***
  • Karma: 0
  • Posts: 194
    • http://fish-cam.net/
[MOD] Users Online v.0.1 (sNews All Versions)
« Reply #1 on: May 12, 2006, 03:59:32 AM »

Nice little mod... with all this mod activity I think I need to sit down and rebuild my sites :) to take advantage of the new stuff.

and then I'll re-release that pre-modded sNews file.
Logged
Check out my sNews powered Tropical Fishtank site, live Fish-Cam !!

bryn

  • Hero Member
  • *****
  • Karma: 2
  • Posts: 934
    • http://www.cssugly.com
[MOD] Users Online v.0.1 (sNews All Versions)
« Reply #2 on: May 12, 2006, 08:56:37 AM »

good work bramsyuur ;)

just a little suggestion - change the part into a css class for better validation purposes, to be added to snews.php and the css file

nice though :)
Logged
Over 1,000 posts of joy, sNews is not only brilliant, but fun too! thanks guys :D

gomisan

  • Full Member
  • ***
  • Karma: 0
  • Posts: 194
    • http://fish-cam.net/
[MOD] Users Online v.0.1 (sNews All Versions)
« Reply #3 on: May 18, 2006, 06:24:47 AM »

Since this would be nice to 'standardise' how should the output be constructed so it's most flexible?

Perhaps just output the number? No other text.
Logged
Check out my sNews powered Tropical Fishtank site, live Fish-Cam !!

bramsyuur

  • Hero Member
  • *****
  • Karma: 23
  • Posts: 873
    • http://snews.vietbee.net
[MOD] Users Online v.0.1 (sNews All Versions)
« Reply #4 on: May 18, 2006, 09:49:42 PM »

Hi Gomisan,
If you want only a number, modify this line:
Code: [Select]
echo "

". l('users_online') ." ($count)

";
with this one:
Code: [Select]
echo $count;and you can call this function, for example, into your index.php like this:
Code: [Select]

My_text_here

Or, if you want only a number, put this:
Code: [Select]
Thanks,
bram.

Quote from: gomisan
Since this would be nice to 'standardise' how should the output be constructed so it's most flexible?

Perhaps just output the number? No other text.
Logged
La comunidad sNews en tu idioma!
Comunidad sNews en Espaņol

gomisan

  • Full Member
  • ***
  • Karma: 0
  • Posts: 194
    • http://fish-cam.net/
[MOD] Users Online v.0.1 (sNews All Versions)
« Reply #5 on: May 19, 2006, 04:12:59 AM »

LOL

thanks, I hadn't really needed a step by step to display just the number :)
Logged
Check out my sNews powered Tropical Fishtank site, live Fish-Cam !!

michael kennedy

  • Full Member
  • ***
  • Karma: 3
  • Posts: 207
    • SpektreDesign
[MOD] Users Online v.0.1 (sNews All Versions)
« Reply #6 on: January 23, 2007, 08:42:34 PM »

Very nice :D  This is something I had on my site before I converted it to sNews. But will this work with 1.5?

And what if I wish to call to it from index.php?

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
[MOD] Users Online v.0.1 (sNews All Versions)
« Reply #7 on: January 23, 2007, 09:43:13 PM »

Sure it will ;)
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version

piXelatedEmpire

  • MIA
  • ULTIMATE member
  • ******
  • Karma: 37
  • Posts: 1401
  • currently MIA
[MOD] Users Online v.0.1 (sNews All Versions)
« Reply #8 on: January 23, 2007, 11:56:10 PM »

I suggest reposting in sNews 1.5  ;)
Logged
my apologies to the sNews crew, but I will be MIA for the forseeable future

henrich

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 381
  • Passion for quality and excellence!
    • My personal blog and portofolio
Re: [MOD] Users Online v.0.1 (sNews All Versions)
« Reply #9 on: January 31, 2008, 08:04:18 AM »

I have rewritten this MOD a little bit :)

Quote
function users_online() {
   $rip = $_SERVER['REMOTE_ADDR'];
   $sd  = time();
   $count = 1;
   $file1 = "users_ip_list.txt";
   $lines = file($file1);
   $line2 = "";
   foreach ($lines as $line_num => $line) {
      $fp = strpos($line,'****');
      $nam = substr($line,0,$fp);
      $sp = strpos($line,'++++');
      $val = substr($line,$fp+4,$sp-($fp+4));
      $diff = $sd-$val;
      if($diff < 300 && $nam != $rip) {
         $count = $count+1;
         $line2 = $line2.$line;
      }
   }
   $my = $rip."****".$sd."++++\n";
   $open1 = fopen($file1, "w");
   fwrite($open1,"$line2");
   fwrite($open1,"$my");
   fclose($open1);
   if ($count == 1) {
      echo ''.$count.' '.l('visitor_online').'';
   } else {
      echo ''.$count.' '.l('visitors_online').'';
   }

}

So if only 1 visitor is online will show:

1 visitor online

If 2 or more visitors:

X visitors online

Language variables:

Quote
$l['visitor_online'] = "visitor online";
$l['visitors_online'] = "visitors online";

Calling the function:

Code: [Select]
<p><?php users_online(); ?></p>
I suggest to move this MOD to the v1.6  ;D
Logged
By(e) Henrich :)
------------------------------
IT related blog