MyBB Community Forums

Full Version: Time Spent Online on Postbit [Plugin]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
thats just moved the time online and warn level down but they are still on the same line...
[attachment=6185]
amywinehouseforum.co.uk Wrote:thats just moved the time online and warn level down but they are still on the same line...

Then add the <br /> after the TimeOnline ...

	$post['user_details'] = "{$post['user_details']}<font class=\"smalltext\">Spent Online: {$post['timeonline']}</font><br />";
nice one thanks. i did try that but just realised i had been putting the '/' before the 'br' and then my forum stopped working. but all is fine now.
cheers Lex-.
Works fine, thank you..
Is this supposed to be compatible for the latest version of mybb ?

When I active it i get an error

----------------------------------------------------
MyBB SQL Error
MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
1146 - Table 'chainzs.mybb_mybb_users' doesn't exist
Query:
SELECT timeonline FROM mybb_mybb_users WHERE uid='1'
------------------------------------------------------
Hi , 

just write this to me, it doesn't work well, can someone help me?

[Image: YbvBdHr.png]

(2007-05-11, 02:26 PM)LeX- Wrote: [ -> ]
amywinehouseforum.co.uk Wrote:where is the template for this plugin as the Time Spent Online and Warning Level are on the same line so I need to move one of them down?

There is no "template" for it, it just adds the "Time Online" to the $post['userdetails'].
There's a <br /> missing because you have that "warning level" thing ... normally there's a <br /> at the end of the $post['userdetails'].

See if this works ...
Open the plugin and find

	$post['user_details'] = "{$post['user_details']}<font class=\"smalltext\">Spent Online: {$post['timeonline']}</font>";

Replace By

	$post['user_details'] = "{$post['user_details']}<br /><font class=\"smalltext\">Spent Online: {$post['timeonline']}</font>";

Hi,
i did everything as you wrote but this error table was received
Can you help me ?

[Image: zHcC1Cj.png]
Please hel me !!!
Error in the plugin:
Original line $queryon = $db->simple_select(TABLE_PREFIX."users", "timeonline", "uid='$onuid'");

Corrected line $queryon = $db->simple_select("users", "timeonline", "uid='$onuid'");

The simple_select method automaticaly add TABLE_PREFIX to the table.

@MyBBEinstein : DO NOT DOUBLE POST.
(2021-02-22, 07:51 AM)Crazycat Wrote: [ -> ]Error in the plugin:
Original line $queryon = $db->simple_select(TABLE_PREFIX."users", "timeonline", "uid='$onuid'");

Corrected line $queryon = $db->simple_select("users", "timeonline", "uid='$onuid'");

The simple_select method automaticaly add TABLE_PREFIX to the table.

@MyBBEinstein : DO NOT DOUBLE POST.


Hi, but what do I need to do to

4059313

it shows me the whole thing, not the month / day / hour
why?


Plugin cod !


<?php
/**
 * Show Time Spent Online on Postbit 1.0
 * Copyright © 2006 DragonFever
 */
 
$plugins->add_hook("postbit", "timeonline_postbit");
 
function timeonline_info()
{
	return array(
		"name"				=> "Shows Time Spent Online on Postbit",
		"description"		=> "Shows Time Spent Online on Postbit.",
		"website"			=> "http://www.dragonfever.info/",
		"author"			=> "DragonFever",
		"authorsite"		=> "http://www.dragonfever.info/",
		"version"			=> "1.0",
		);
}
 
function timeonline_activate()
{
}
 
function timeonline_deactivate()
{
}
 
function timeonline_postbit($post)
{
	global $mybb, $lang, $db;
	$onuid = $post['uid'];
    $queryon = $db->simple_select("users", "timeonline", "uid='$onuid'");
    $memprofile = $db->fetch_array($queryon);
    
    if($memprofile['timeonline'] > 0)
    {
        $post['timeonline'] = fl_nice_time($memprofile['timeonline']);
    }
    else
    {
        $post['timeonline'] = $lang->na;
    }
	$post['user_details'] = "{$post['user_details']}<font class=\"smalltext\">Spent Online: {$post['timeonline']}</font>";
}
// First Lettered nice_time Funtion
function fl_nice_time($stamp)
{

	$ysecs = 365*24*60*60;
	$mosecs = 31*24*60*60;
	$wsecs = 7*24*60*60;
	$dsecs = 24*60*60;
	$hsecs = 60*60;
	$msecs = 60;

	$years = floor($stamp/$ysecs);
	$stamp %= $ysecs;
	$months = floor($stamp/$mosecs);
	$stamp %= $mosecs;
	$weeks = floor($stamp/$wsecs);
	$stamp %= $wsecs;
	$days = floor($stamp/$dsecs);
	$stamp %= $dsecs;
	$hours = floor($stamp/$hsecs);
	$stamp %= $hsecs;
	$minutes = floor($stamp/$msecs);
	$stamp %= $msecs;
	$seconds = $stamp;

	if($years == 1)
	{
		$flnicetime['years'] = "1 ".Y;
	}
	elseif($years > 1)
	{
		$flnicetime['years'] = $years." ".Y;
	}

	if($months == 1)
	{
		$flnicetime['months'] = "1 ".M;
	}
	elseif($months > 1)
	{
		$flnicetime['months'] = $months." ".M;
	}

	if($weeks == 1)
	{
		$flnicetime['weeks'] = "1 ".W;
	}
	elseif($weeks > 1)
	{
		$flnicetime['weeks'] = $weeks." ".W;
	}

	if($days == 1)
	{
		$flnicetime['days'] = "1 ".D;
	}
	elseif($days > 1)
	{
		$flnicetime['days'] = $days." ".D;
	}

	if($hours == 1)
	{
		$flnicetime['hours'] = "1 ".H;
	}
	elseif($hours > 1)
	{
		$flnicetime['hours'] = $hours." ".H;
	}

	if($minutes == 1)
	{
		$flnicetime['minutes'] = "1 ".M;
	}
	elseif($minutes > 1)
	{
		$flnicetime['minutes'] = $minutes." ".M;
	}

	if(is_array($flnicetime))
	{
		return implode(", ", $flnicetime);
	}
}
// Function Ends
?>
The $post must be passed by reference : function timeonline_postbit(&$post)

And this plugin will occure a lot of warning because it uses undefined constants (W, M, D, ...).
BTW, I think it could be higly improved.

Edit :
I did a modification of the fl_nice_time function. It uses the global translation from MyBB.
Now it takes 3 arguments:
  • timeonline : as before, unchanged
  • short : if setted to 1, then the function uses the short naming (d for days, m for months, ...) else it uses the full naming
  • prec : the number of max items you want to display

function fl_nice_time($timeonline, $short=1, $prec=3)
{
	global $lang;
	$start = DateTime::createFromFormat('Y-m-d H:i:s', '1970-01-01 00:00:00');
	$spent = new DateTime('@'.$timeonline);
	$interval = $spent->diff($start);
	$plural = function($nb,$str, $short=0) {
		global $lang;
		if ($short==1) { $suf = '_short'; } else { $suf = ''; }
		return $nb>1?$lang->{$str.'s'.$suf}:$lang->{$str.$suf};
	};
	$format = array();
    if($interval->y !== 0) {
        $format[] = '%y '.$plural($interval->y, 'year', $short);
    }
    if($interval->m !== 0) {
        $format[] = '%m '.$plural($interval->m, 'month', $short);
    }
    if($interval->d !== 0) {
        $format[] = '%d '.$plural($interval->d, 'day', $short);
    }
    if($interval->h !== 0) {
        $format[] = '%h '.$plural($interval->h, 'hour', $short);
    }
    if($interval->i !== 0) {
        $format[] = '%i '.$plural($interval->i, 'minute', $short);
    }
    if($interval->s !== 0) {
        if(!count($format)) {
            return $lang->rel_less_than . ' 1 ' . $plural(1, 'minute', $short);
        } else {
            $format[] = '%s '.$plural($interval->s, 'second', $short);
        }
    }
    if(count($format) > 1) {
		$format = implode(', ', array_slice($format, 0, (int) $prec));
    } else {
        $format = array_pop($format);
    }
    return $interval->format($format);
}

@TODO: add settings to the plugin to set short and prec.
Pages: 1 2 3