Joined: Jan 02, 2003 Posts: 666 Location: Vancouver Island
Posted:
Fri Nov 28, 2008 7:30 am
I use LastSeen. It is a block since phpnuke 5.1. Over time there were three authors, then it was edited by tom back in 6.0 days.
I've only had a problem since rn2.3. The block is working fine, except for an interesting cookie issue.
The script is creating new records with invalid usernames with unique ips. ??**!!
The offending username is blank, or a user location field, ie: Victoria, Victoria, BC, etc. (Typical location values for my users.)
The table looks like this:
Code:
CREATE TABLE IF NOT EXISTS `nuke_lastseen` (
`id` int(15) NOT NULL auto_increment,
`username` text NOT NULL,
`date` int(15) NOT NULL default '0',
`ip` varchar(50) default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=811 ;
And some code looks like this. What's wrong with this script bit???
Joined: Jan 02, 2003 Posts: 666 Location: Vancouver Island
Posted:
Fri Nov 28, 2008 9:28 am
Thanks Montego...
I made the changes to my production site and now will see how things go during the day. I'm sure it's going to work way better with the !empty thingy.
I'll have a look through the rest of the code and see if I can't apply something learned to the other bits. I'll be back. Thanks again.
Joined: Jan 02, 2003 Posts: 666 Location: Vancouver Island
Posted:
Fri Nov 28, 2008 5:56 pm
Well, empty username isn't back, but one username is showing up. ie: Victoria, which isn't a valid username but is a valid, and much used, location. So, I'm still confused. Wouldn't I also want to cross check for the username in nuke_users too?
Joined: Jan 02, 2003 Posts: 666 Location: Vancouver Island
Posted:
Sun Nov 30, 2008 8:41 pm
I'm now getting There is no content for this block. Here is the entire script. Perhaps you can point to where I messed up? Perhaps putting the closing bracket below the last $content .=""; was a mistake?
Code:
<?
// Michael Yarbrough
//
Only registered users can see links on this board! Get registered or login to the forums!
// http://www.comediccadavers.com/
// PHP-Nuke 5.1 Blocks version by Thiago Campos aka Mr. Hemp (mrhemp@amigoz.org)
// Updated to work with PHP-Nuke 6.0 and the phpBB2 forum port by
// Tom Nitzschner (tom@toms-home.com)
// http://bbtonuke.sourceforge.net (http://www.toms-home.com)
//
// As always, make a backup before messing with anything. All code
// release by me is considered sample code only. It may be fully
// functual, but you use it at your own risk, if you break it,
// you get to fix it too. No waranty is given or implied.
//
// Please change your prefix to suit your database.
// Set $numusers to the count of people you want listed +1
//
if ( !defined('BLOCK_FILE') ) {
Header("Location: ../index.php");
die();
}
global $cookie, $prefix, $currentlang, $db, $username, $numusers, $users, $userinfo;
$prefix = "nuke";
$numusers = 10;
if(file_exists("language/lastseen/lastseen-$currentlang.php")) {
include("language/lastseen/lastseen-$currentlang.php");
}
else {
include("language/lastseen/lastseen-english.php");
}
getusrinfo($user);
if ((is_user($user)) AND (strtolower($userinfo['username']) == strtolower($cookie[1]))) {
$username = $cookie[1];
// sql_query("CREATE TABLE IF NOT EXISTS ".$prefix."_lastseen (id INT (15) not null AUTO_INCREMENT, username TEXT not null, date INT(15) not null, ip CHAR(50), PRIMARY KEY (id), UNIQUE (id))", $dbi);
if (isset($username) && !empty($username)) {
$ip = getenv("REMOTE_HOST");
if (empty($ip)) {
$ip = getenv("REMOTE_ADDR");
}
if (!ereg('^([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})$', $ip)) $ip = '';
$username = addslashes($username);
$result = $db->sql_query("SELECT * FROM ".$prefix."_lastseen WHERE username = '$username'");
if ($db->sql_numrows($result) > 0) {
$db->sql_query("UPDATE ".$prefix."_lastseen SET date = " . time() . " WHERE username = '$username'");
} else {
$db->sql_query("INSERT INTO ".$prefix."_lastseen VALUES ('', '$username', ".time().", '".$ip."')");
}
}
$content = "";
$result = $db->sql_query("SELECT username, date FROM ".$prefix."_lastseen ORDER BY date DESC limit $numusers");
while (list($uname, $date) = $db->sql_fetchrow($result)) {
if ($uname != $username) {
$realtime = time() - $date;
$dont = false;
// how many days ago?
if ($realtime >= (60*60*24*2)) { // if it's been more than 2 days
$days = floor($realtime / (60*60*24));
$dont = true;
} else if ($realtime >= (60*60*24)) { // if it's been less than 2 days
$days = 1;
$realtime -= (60*60*24);
}
if (!$dont) {
// how many hours ago?
if ($realtime >= (60*60)) {
//$content .= " ($realtime) ";
$hours = floor($realtime / (60*60));
$realtime -= (60*60*$hours);
}
// how many minutes ago?
if ($realtime >= 60) {
$mins = floor($realtime / 60);
$realtime -= (60*$mins);
}
// just a little precation, although I don't *think* mins will ever be 60...
if ($mins == 60) {
$mins = 0;
$hours += 1;
}
}
$myresult = $db->sql_query("select user_id from nuke_users where (username='$uname')");
list($uid) = $db->sql_fetchrow($myresult);
$content .= "<font class=tiny><a href=\"profile-.html".$uid."\">".$uname."</a>:";
if ($dont) {
$content .= " ".$days." "._LASTSEENDAYS."";
} else {
if ($days > 0) {
$content .= " ".$days." "._LASTSEENDAY."".(($hours == 0 && $mins == 0)?(""):(","));
}
if ($hours > 0) {
$content .= " ".$hours." ".(($hours > 1)?(""._LASTSEENHOURS.""):(""._LASTSEENHOUR."")).(($mins == 0)?(""):(","));
}
if ($mins > 0) {
$content .= " ".$mins." ".(($mins > 1)?(""._LASTSEENMINUTES.""):(""._LASTSEENMINUTE.""))."";
} else { // less than a minute :)
$content .= " ".$realtime." "._LASTSEENSECONDS."";
}
}
Joined: Aug 29, 2004 Posts: 9071 Location: Arizona
Posted:
Mon Dec 01, 2008 6:23 am
CodyG, I have re-coded the block some as I believe the if statement wrapped too much of the code. Hopefully this will work better. I also forgot a couple of things and I needed to reformat the indentation in order to see the structure better... hopefully you do not mind:
Code:
<?
// Michael Yarbrough
//
Only registered users can see links on this board! Get registered or login to the forums!
// http://www.comediccadavers.com/
// PHP-Nuke 5.1 Blocks version by Thiago Campos aka Mr. Hemp (mrhemp@amigoz.org)
// Updated to work with PHP-Nuke 6.0 and the phpBB2 forum port by
// Tom Nitzschner (tom@toms-home.com)
// http://bbtonuke.sourceforge.net (http://www.toms-home.com)
//
// As always, make a backup before messing with anything. All code
// release by me is considered sample code only. It may be fully
// functual, but you use it at your own risk, if you break it,
// you get to fix it too. No waranty is given or implied.
//
// Please change your prefix to suit your database.
// Set $numusers to the count of people you want listed +1
//
if ( !defined('BLOCK_FILE') ) {
Header("Location: ../index.php");
die();
}
global $cookie, $prefix, $currentlang, $db, $username, $numusers, $users, $userinfo;
$prefix = "nuke";
$numusers = 10;
$content = "";
if(file_exists("language/lastseen/lastseen-$currentlang.php")) {
include("language/lastseen/lastseen-$currentlang.php");
}
else {
include("language/lastseen/lastseen-english.php");
}
cookiedecode($user);
getusrinfo($user);
$username = $cookie[1];
if ((is_user($user)) AND (strtolower($userinfo['username']) == strtolower($cookie[1]))) {
// sql_query("CREATE TABLE IF NOT EXISTS ".$prefix."_lastseen (id INT (15) not null AUTO_INCREMENT, username TEXT not null, date INT(15) not null, ip CHAR(50), PRIMARY KEY (id), UNIQUE (id))", $dbi);
if (isset($username) && !empty($username)) {
$ip = getenv("REMOTE_HOST");
if (empty($ip)) {
$ip = getenv("REMOTE_ADDR");
}
if (!ereg('^([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})$', $ip)) $ip = '';
$username2 = addslashes($username);
$result = $db->sql_query("SELECT * FROM ".$prefix."_lastseen WHERE username = '$username2'");
if ($db->sql_numrows($result) > 0) {
$db->sql_query("UPDATE ".$prefix."_lastseen SET date = " . time() . " WHERE username = '$username2'");
} else {
$db->sql_query("INSERT INTO ".$prefix."_lastseen VALUES ('', '$username2', ".time().", '".$ip."')");
}
}
}
$result = $db->sql_query("SELECT username, date FROM ".$prefix."_lastseen ORDER BY date DESC limit $numusers");
while (list($uname, $date) = $db->sql_fetchrow($result)) {
if ($uname != $username) {
$days = 0;
$hours = 0;
$mins = 0;
$dont = false;
$realtime = time() - $date;
// how many days ago?
if ($realtime >= (60*60*24*2)) { // if it's been more than 2 days
$days = floor($realtime / (60*60*24));
$dont = true;
} else if ($realtime >= (60*60*24)) { // if it's been less than 2 days
$days = 1;
$realtime -= (60*60*24);
}
if (!$dont) {
// how many hours ago?
if ($realtime >= (60*60)) {
//$content .= " ($realtime) ";
$hours = floor($realtime / (60*60));
$realtime -= (60*60*$hours);
}
// how many minutes ago?
if ($realtime >= 60) {
$mins = floor($realtime / 60);
$realtime -= (60*$mins);
}
// just a little precation, although I don't *think* mins will ever be 60...
if ($mins == 60) {
$mins = 0;
$hours += 1;
}
}
$myresult = $db->sql_query("select user_id from nuke_users where (username='$uname')");
list($uid) = $db->sql_fetchrow($myresult);
$content .= "<font class=tiny><a href=\"profile-.html".$uid."\">".$uname."</a>:";
if ($dont) {
$content .= " ".$days." "._LASTSEENDAYS."";
} else {
if ($days > 0) {
$content .= " ".$days." "._LASTSEENDAY."".(($hours == 0 && $mins == 0)?(""):(","));
}
if ($hours > 0) {
$content .= " ".$hours." ".(($hours > 1)?(""._LASTSEENHOURS.""):(""._LASTSEENHOUR."")).(($mins == 0)?(""):(","));
}
if ($mins > 0) {
$content .= " ".$mins." ".(($mins > 1)?(""._LASTSEENMINUTES.""):(""._LASTSEENMINUTE.""))."";
} else { // less than a minute :)
$content .= " ".$realtime." "._LASTSEENSECONDS."";
}
}
Joined: Jan 02, 2003 Posts: 666 Location: Vancouver Island
Posted:
Mon Dec 01, 2008 7:19 am
Except ... $numusers is only outputting only 1 record and not the 10 asked for in $numusers.
And is: <a href=\"profile-.html".$uid."\">".$uname."</a>:"; something new in RN? a short link perhaps? It's throwing a Sorry, this Module isn't active.
And the _lastseen table doesn't appear to be updating. Has this something to do with $username2 and the table is username?
Joined: Mar 30, 2006 Posts: 2404 Location: Pennsylvania
Posted:
Mon Dec 01, 2008 8:01 am
<a href=\"profile-.html".$uid."\">".$uname."</a>
You need to set that to what ever it was before. The shortlinks on this site are messing up the code when it is posted.
As for why you are only getting one person to show I have no idea. The above code looks good to me. other than "$prefix = "nuke";" should not be there.
Joined: Jan 02, 2003 Posts: 666 Location: Vancouver Island
Posted:
Mon Dec 01, 2008 8:17 am
Yes, there are almost 732 records in the db table. $numusers is suppose to show the last 10. It's early here, 6:15am local and most users are local. But for the few users who have been online since I changed the code their _lastseen table records are not being updated at all.
Joined: Jan 02, 2003 Posts: 666 Location: Vancouver Island
Posted:
Mon Dec 01, 2008 10:31 am
I've made some changes, thanks for the clues! So, now we are updating the db again.
Unfortunately, "There isn't content right now ..." has reappeared.
Code:
<?
/* Michael Yarbrough
Only registered users can see links on this board! Get registered or login to the forums!
http://www.comediccadavers.com/
PHP-Nuke 5.1 Blocks version by Thiago Campos aka Mr. Hemp (mrhemp@amigoz.org)
Updated to work with PHP-Nuke 6.0 and the phpBB2 forum port by
Tom Nitzschner (tom@toms-home.com)
http://bbtonuke.sourceforge.net (http://www.toms-home.com)
Updated by the RavenNuke Team.
As always, make a backup before messing with anything. All code
release by me is considered sample code only. It may be fully
functual, but you use it at your own risk, if you break it,
you get to fix it too. No waranty is given or implied.
*/
// Set $numusers to the count of people you want listed +1
if ( !defined('BLOCK_FILE') ) {
Header("Location: ../index.php");
die();
}
global $cookie, $prefix, $currentlang, $db, $username, $user, $userinfo;
if ((is_user($user)) AND (strtolower($userinfo['username']) == strtolower($cookie[1]))) {
// sql_query("CREATE TABLE IF NOT EXISTS ".$prefix."_lastseen (id INT (15) not null AUTO_INCREMENT, username TEXT not null, date INT(15) not null, ip CHAR(50), PRIMARY KEY (id), UNIQUE (id))", $dbi);
if (isset($username) && !empty($username)) {
$ip = getenv("REMOTE_HOST");
if (empty($ip)) {
$ip = getenv("REMOTE_ADDR");
}
if (!ereg('^([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})$', $ip)) $ip = '';
$username2 = addslashes($username);
$result = $db->sql_query("SELECT * FROM ".$prefix."_lastseen WHERE username = '$username2'");
if ($db->sql_numrows($result) > 0) {
$db->sql_query("UPDATE ".$prefix."_lastseen SET date = " . time() . " WHERE username = '$username2'");
} else {
$db->sql_query("INSERT INTO ".$prefix."_lastseen VALUES ('', '$username2', ".time().", '".$ip."')");
}
}
}
$result = $db->sql_query("SELECT username, date FROM ".$prefix."_lastseen ORDER BY date DESC limit $numusers");
while (list($uname, $date) = $db->sql_fetchrow($result)) {
if ($uname != $username) {
$days = 0;
$hours = 0;
$mins = 0;
$dont = false;
$realtime = time() - $date;
// how many days ago?
if ($realtime >= (60*60*24*2)) { // if it's been more than 2 days
$days = floor($realtime / (60*60*24));
$dont = true;
} else if ($realtime >= (60*60*24)) { // if it's been less than 2 days
$days = 1;
$realtime -= (60*60*24);
}
if (!$dont) {
// how many hours ago?
if ($realtime >= (60*60)) {
//$content .= " ($realtime) ";
$hours = floor($realtime / (60*60));
$realtime -= (60*60*$hours);
}
// how many minutes ago?
if ($realtime >= 60) {
$mins = floor($realtime / 60);
$realtime -= (60*$mins);
}
// just a little precation, although I don't *think* mins will ever be 60...
if ($mins == 60) {
$mins = 0;
$hours += 1;
}
}
$myresult = $db->sql_query("select user_id from nuke_users where (username='$uname')");
list($uid) = $db->sql_fetchrow($myresult);
$content .= "<font class=tiny><a href=\"m_o_dules.pseehp?name=Forums&file=profile&mode=viewprofile&u=".$uid."\">".$uname."</a>:";
if ($dont) {
$content .= " ".$days." "._LASTSEENDAYS."";
} else {
if ($days > 0) {
$content .= " ".$days." "._LASTSEENDAY."".(($hours == 0 && $mins == 0)?(""):(","));
}
if ($hours > 0) {
$content .= " ".$hours." ".(($hours > 1)?(""._LASTSEENHOURS.""):(""._LASTSEENHOUR."")).(($mins == 0)?(""):(","));
}
if ($mins > 0) {
$content .= " ".$mins." ".(($mins > 1)?(""._LASTSEENMINUTES.""):(""._LASTSEENMINUTE.""))."";
} else { // less than a minute :)
$content .= " ".$realtime." "._LASTSEENSECONDS."";
}
}
Joined: Mar 30, 2006 Posts: 2404 Location: Pennsylvania
Posted:
Mon Dec 01, 2008 11:28 am
Interesting. So it is updating the DB, but not displaying anything.
The only reason there would be absoultly no content would be because of the 2 lines below. I don't see what is wrong with them at the moment and I am not home to test.
$result = $db->sql_query("SELECT username, date FROM ".$prefix."_lastseen ORDER BY date DESC limit $numusers");
while (list($uname, $date) = $db->sql_fetchrow($result)) {
Joined: Aug 28, 2003 Posts: 6300 Location: Vsetin, Czech Republic
Posted:
Mon Dec 01, 2008 4:31 pm
Wierd one!
Yes the global $users needs to be $user (no 's' on the end) as it is $user that is used.
Yes $prefix ="nuke" is not needed as you are using the global so you don't need to set it.
The sql statements create the tables and the INSERT is working.
The UPDATE appears to work also and the value $username2 is being set correctly (but there is only me online on the site I'm testing it on.
Hmm...
Joined: Jan 02, 2003 Posts: 666 Location: Vancouver Island
Posted:
Mon Dec 01, 2008 5:13 pm
The changes are so far are keeping 'blank' users from the output. And, the number of invalid usernames has dropped dramatically. For example, in the past 24 hours: 0/100, instead of 1/20. I haven't been deleting in the db table all day! yeehaw!
I cobbled a Last_Seen module so I can lastseen 1000. That script is working fine, atm. Soon, I'll enhance it to include $user_email output. Then it will be a simple copy/paste to send updates to more than 364 days ago users.
But first things first... what's up with that darn block $content?
Need clarity: $prefix is only required in the global? $prefix='nuke'; is redundant?
Having finally figured out return $content in another script, I've become totally confuddled by the same statement in this script.
Another Question: Why the introduction of $username2 ??
Joined: Mar 30, 2006 Posts: 2404 Location: Pennsylvania
Posted:
Mon Dec 01, 2008 5:34 pm
CodyG wrote:
Need clarity: $prefix is only required in the global? $prefix='nuke'; is redundant?
Yes, you only need the global because config.php is inlclued along the way which defines $prefix.
CodyG wrote:
Another Question: Why the introduction of $username2 ??
I am not 100% sure why Montego did that. Maybe he just wanted to keep $username in its standard form. It really does not matter. Since you said that I just noticed another little thing you can change. You can remove $username out of the globals.
Code:
global $cookie, $prefix, $currentlang, $db, $username, $user, $userinfo;
change to:
Code:
global $cookie, $prefix, $currentlang, $db, $user, $userinfo;
As for why no content, I am not sure yet. I haven't had time to play with it yet.
Joined: Aug 29, 2004 Posts: 9071 Location: Arizona
Posted:
Tue Dec 02, 2008 6:11 am
For use with the database calls, $username needed to have addslashes() to it, however, since $username is being used later on, one cannot just $username = addslashes($username). That is why I added $username2 = addslashes($username). I used $username2 everywhere it needed to be used. Sorry, but I didn't have time to create the table and test...
I just can't see why the content isn't showing either. Unfortunately, it will be some time before I can try and re-create this feature.
Joined: Jan 02, 2003 Posts: 666 Location: Vancouver Island
Posted:
Wed Dec 03, 2008 10:29 am
I became dazed and confused, then started over again with a copy from the backup dir. :/ Empty user and invalid usernames creeped back in within hours.
I went line by line making montego's changes. And, it's working for me for now. let's see what today brings.
Hurrah for return $content and all who shared.
I missed this before - why not use the new last visited field in RNYA (not the original one that was in standard Nuke that was only updated if a visitor visited the forums), at least for the members....
View next topic View previous topic
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