[Pmwiki-users] Re: Insert PHP Code into pmwiki

Steven Leite steven_leite
Tue Jun 1 21:23:31 CDT 2004


> Thanks again, here would be some script which shows how much users are
> online. How could I insert it into pmwiki?
>
>
> ALBI...

<?php

// Instructions:  Save this file as whos-online.php, then
// in your config.php file, add the line:
// include_once('local/scripts/whos-online.php');
// now you can put the $show_online_users syntax
// anywhere on your wiki pages, and your function
// will be output.

$InlineReplacements['/\$show_online_users/'] = ShowOnline();

function ShowOnline() {

/**********************************
* by Michael M?ller ***************
* Dieser Hinweis darf nicht *******
* entfernt werden *****************
**********************************/

  $datei = "useronline.dat";
  $min = 5;
  $time = time() - $min*60;
  $current_ip = $_SERVER['REMOTE_ADDR'];
  // alte Beitr?ge l?schen
  if(file_exists($datei))
    {
      $lines = file($datei);
      foreach($lines as $key=>$data)
     {
          list($ip, $timest) = explode("?", $data);
            if(trim($timest) < $time || trim($ip) == $current_ip)
        {unset($lines[$key]);}
        }
    }
  $lines[] = $current_ip."?".time()."\n";
  $save = implode("", $lines);
  $handle = fopen($datei, "w");
  fputs($handle, $save);
  fclose($handle);
  $user = count($lines);
  if($user == 1)
    {$html = "Es ist 1 User online";}
  else
    {$html = "Es sind ".$user." User online";}

  return $html;

}

?>


TIP:  When writing your functions, you should try to precede the
function name with the name of the module you are writing, it will
minimize the risk of declaring a function name that already exists in
PmWiki's scope, or in the scope of some other Cookbook recipe's that
people might have enabled.  For example, if you have an initialization
routine, rather than calling it Init($variable list), call it
WhosOnline_Init($variable list) instead.

-S




More information about the pmwiki-users mailing list