Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks
Author Message
CodyG
Life Cycles Becoming CPU Cycles


Joined: Jan 02, 2003
Posts: 712
Location: Vancouver Island

PostPosted: Wed Nov 22, 2006 1:00 pm Reply with quote

I had this block working on my nuke 6.9 and would like to get it working with rn2.02.
It's showing 'No content found' and is throwing an sql error in the logs:
PHP Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /var/www/vhosts/blah.ca/httpdocs/includes/sql_layer.php on line 287, referer: Only registered users can see links on this board! Get registered or login!

I changed the original $dbi to $db. I haven't modified it in anyways.
The table isn't being populate.

The table structure for this block looks like this:
Code:
CREATE TABLE `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=1 ;


See message below this for current code.

Any and all clues and/or fixes are welcome. I'll take you to lunch. Wink

Happy Nuke Day!

_________________
"We want to see if life is ubiquitous." D.Goldin

Last edited by CodyG on Fri Nov 24, 2006 9:16 am; edited 1 time in total 
View user's profile Send private message
Gremmie
Former Moderator in Good Standing


Joined: Apr 06, 2006
Posts: 2415
Location: Iowa, USA

PostPosted: Wed Nov 22, 2006 1:07 pm Reply with quote

If you are converting it to to use the newer database abstraction layer, then you need to use the object syntax:

Code:


$result = $db->sql_query("select blah blah blah");

$row = $db->sql_fetchrow($result);

$n = $db->sql_numrows($result);


Take a look at db/mysql.php to see the class and the member functions.
 
View user's profile Send private message
CodyG
PostPosted: Wed Nov 22, 2006 5:10 pm Reply with quote

Thanks Gremmie, but this conversion is a little beyond me. I tried to get my head around it, but made a mess of it instead.
Could there be anyone else who runs this block on their rn2.02 and is will to share the code?
 
Gremmie
PostPosted: Wed Nov 22, 2006 5:55 pm Reply with quote

Doesn't it still work as-is? I think the old database calls are still supported.
 
CodyG
PostPosted: Wed Nov 22, 2006 7:29 pm Reply with quote

Nope .. not working for me in rn 2.01. See my first message. It's very old code, so I'm not surprised it doesn't work, just thought it would be nice to get it working.
I think it's an sql issue, but it could be something else.
 
CodyG
PostPosted: Thu Nov 23, 2006 6:38 am Reply with quote

Anyone have this block working on rn 2.02?
 
Gremmie
PostPosted: Thu Nov 23, 2006 2:35 pm Reply with quote

Well if you go back to the original code, and then turn on error reporting, what errors do you see? Also, anything in the logs?
 
CodyG
PostPosted: Thu Nov 23, 2006 3:18 pm Reply with quote

No errors in the block. Only the following in the log, and this shouldn't be a show stopper, right?
The problem seems to be getting the data out of the user table and into the lastseen table... that data input just doesn't happen.
Quote:

[client xx.xx.xx.xx] PHP Notice: Use of undefined constant _lastseen - assumed '_lastseen' in /var/www/vhosts/blah.com/httpdocs/blocks/block-lastseen.php on line 49, referer: Only registered users can see links on this board! Get registered or login!
[client xx.xx.xx.xx] PHP Notice: Use of undefined constant _lastseen - assumed '_lastseen' in /var/www/vhosts/blah.com/httpdocs/blocks/block-lastseen.php on line 53, referer: Only registered users can see links on this board! Get registered or login!
 
evaders99
Former Moderator in Good Standing


Joined: Apr 30, 2004
Posts: 3221

PostPosted: Thu Nov 23, 2006 8:54 pm Reply with quote

Well that's just a warning, but go ahead and fix it

Code:


$prefix"._lastseen."

TO

".$prefix."_lastseen

Please note, there should be a space after the _lastseen part

_________________
- Only registered users can see links on this board! Get registered or login! -

Need help? Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
CodyG
PostPosted: Fri Nov 24, 2006 9:15 am Reply with quote

Hmmm... I don't know if I'm any closer to solving this, but there is some progress.
Below is the current code ... (changes to the $prefix as suggested by Evaders, I didn't change the sql abstraction as suggested by Gremmie.)

At first I thought the code wasn't putting anything in to the lastseen table. But then it started putting my username/ip in the table. The block would still say No Content because it never did show your own nick. I deleted the db record several times, just to make sure that I wasn't seeing things and next time I checked, sure enough, there was my own record.... but no other users.

I started wondering if because I had this block set up for Groups, and that the Group had only me in it, I wondered if that had anything to do with anything not working. So I set the block for all registered users ... and sure enough, records for other users started appearing in the lastseen table. And the block is working!

In the last incarnation of this site this block was viewable by registered members. Some people had some issues about this ... so now I thought I'd set up this block to be visible only to that group of which I am the only member because it's handy data ... it gives me an idea of how many people have been on the site in the last X minutes.

So, is that clear as mud? Do I need additional "group" code to make this all work?

Code:
<?


// Michael Yarbrough
// Only registered users can see links on this board! Get registered or login!
// 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
//

global $cookie, $prefix, $currentlang, $dbi, $username, $numusers;
$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");
}

        $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)) {
                $ip = getenv("REMOTE_HOST");
                if (empty($ip)) {
                        $ip = getenv("REMOTE_ADDR");
                }

                $result = sql_query("SELECT * FROM ".$prefix."_lastseen WHERE username = \"$username\"", $dbi);
                if (sql_num_rows($result, $dbi) > 0) {
                        sql_query("UPDATE ".$prefix."_lastseen SET date = " . time() . " WHERE username = \"$username\"", $dbi);
                } else {
                        sql_query("INSERT INTO ".$prefix."_lastseen VALUES (\"\", \"$username\", ".time().", \"".$ip."\")", $dbi);
                }
        }
        $content = "";
        $result = sql_query("SELECT username, date FROM ".$prefix."_lastseen ORDER BY date DESC limit $numusers", $dbi);
        while (list($uname, $date) = sql_fetch_row($result, $dbi)) {
                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 = sql_query("select user_id from nuke_users where (username='$uname')", $dbi);
                            list($uid) = sql_fetch_row($myresult, $dbi);
                        $content .= "<font class=tiny><a href=\"forum-userprofile-.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."";
                                }
                        }

                        $content .= " "._LASTSEENAGO."</font><br>";

                        $days = 0;
                        $hours = 0;
                        $mins = 0;
                        $dont = false;
                }
        }

        $content .= "";


?>
Confused
 
CodyG
PostPosted: Fri Nov 24, 2006 11:23 am Reply with quote

Interesting ... I set the Block Admin permissions to Administrator and it stopped working.

iow, this bit of beauty block code is only working in one permission mode, registered users. This would be fixable?
 
Gremmie
PostPosted: Fri Nov 24, 2006 11:58 am Reply with quote

I would remove this line:

$prefix = "nuke";

That would break things for people who changed the $prefix.

I doesn't look like this block was meant to be used for non-registered users. They don't have usernames, so they won't be found (no cookies).

Admins have a different cookie or something, so its probably not finding them.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks

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
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©