Subject: chat notify block

Posted on: 17/12/03 09:03pm
By: paulmon

The following block really only helps people using the Flash Chat or some other externally reachable Java/Flash/Other chat system. This block us based on the who's online block and replaces that block. In this case it adds a radio button beside each logged in user, if you select the radio for a user and hit "Request Chat" button the user will get a big red alert in this block on their next refresh saying that your've requested a chat. It still needs some work but it does function and my users are already using it.

Instructions:

1) create required table to you geeklog database "gl_notifyblock" as follows:


CREATE TABLE `gl_notifyblock` (
  `recp_uid` mediumint(4) NOT NULL default '0',
  `send_name` varchar(35) NOT NULL default '',
  `time` datetime NOT NULL default '0000-00-00 00:00:00'
) TYPE=MyISAM;



2) Add the following code to lib-custom.php, this will require some editing depending on how you launch your chat. If you use Flash Chat in /FlashChat/ then it should work assuming your tables for FlashChat are the same as mine. Otherwise it should be pretty easy to edit.

function phpblock_whosimproved()
{

        global $_TABLES,$_USER,$HTTP_COOKIE_VARS,$HTTP_POST_VARS,$PHP_SELF,$REMOTE_ADDR,$LANG01,$_CONF;

    $expire_time = time() - $_CONF['whosonline_threshold'];

    $result = DB_query( "SELECT DISTINCT {$_TABLES['sessions']}.uid, username,photo,showonline FROM {$_TABLES['sessions']},{$_TABLES['users']},{$_TABLES['userprefs']} WHERE {$_TABLES['users']}.uid = {$_TABLES['sessions']}.uid AND {$_TABLES['users']}.uid = {$_TABLES['userprefs']}.uid AND start_time >= $expire_time AND {$_TABLES['sessions']}.uid <> 1 ORDER BY username" );
    $nrows = DB_numRows( $result );

    $num_anon = 0;

    for( $i = 1; $i <= $nrows; $i++ )
    {
        $A = DB_fetchArray( $result );

        $retval .= "<form action='$PHP_SELF' method='post'>";

        if( $A['showonline'] == 1 ) {

            $retval .= '<a href="' . $_CONF['site_url']
                    . '/users.php?mode=profile&uid=' . $A['uid'] . '">'
                    . $A['username'] . '</a>' . '<INPUT type="radio" name="notify" value="' . $A['uid'] . '" >';

            if( !empty( $A['photo'] ) AND $_CONF['allow_user_photo'] == 1)
            {
                $retval .= ' <a href="' . $_CONF['site_url']
                        . '/users.php?mode=profile&uid=' . $A['uid']
                        . '"><img src="' . $_CONF['layout_url']
                        . '/images/smallcamera.gif" border="0" alt=""></a>';
            }
            $retval .= '<br>';

        } else {
            // this user does not want to show up in Who's Online
            $num_anon++; // count as anonymous
        }

    }

    $result = DB_query( "SELECT DISTINCT uid,remote_ip FROM {$_TABLES['sessions']} WHERE uid = 1" );
    $num_anon += DB_numRows( $result );

    if( $num_anon > 0 )
    {
        $retval .= $LANG01[41] . ': ' . $num_anon . '<br>';
    }
        $retval .= '<input type="hidden" name="send_name" value="' . $_USER[username] . '"><input type="submit" value="Chat Notify"></form>';

        $notify_uid=COM_checkWords($HTTP_POST_VARS["notify"]);
        $send_name=COM_checkWords($HTTP_POST_VARS["send_name"]);

        if ( $notify_uid != 0 ) {
                $retval .= 'A chat request has been sent';
                $result = DB_query("INSERT INTO gl_notifyblock (recp_uid,send_name,time)"."VALUES ("$notify_uid", "$send_name",now() )");
        }

        $getnotifies = DB_query("SELECT * from gl_notifyblock WHERE recp_uid = $_USER[uid] AND NOW() - time < 300");
        $cleantable = DB_query("DELETE FROM gl_notifyblock WHERE NOW() - time > 300");

        $notifies = DB_fetchArray($getnotifies);

        $userquery = mysql_query( "SELECT * FROM chat_users WHERE name = '$_USER[username]'" );
        $inchat = DB_fetchArray($userquery);


        $recpuid = $notifies[recp_uid];
                if ($inchat[name] != $_USER[username]) {
                        if ($recpuid == $_USER[uid]) {
                                $retval .= '<TABLE BORDER=2><TR><TD align=center><font size=5 color=#FF0000>CHAT REQUEST FROM<br>' . $notifies[send_name] . '</FONT><br><a href="" onclick="window.open('/FlashChat/index.php',1,'directories=no,menubar=no,top=0,left=0,width=550,height=560');">Join Chat</a></TD></TR></TABLE>';
                        }
                }
    return $retval;
}




3) Add a PHP Blocked with the function phpblock_whosimproved

Enjoy.

Paul


Re:chat notify block

Posted on: 18/12/03 11:24am
By: destr0yr

*shrugs*
I get error that headers have already been sent. I know it normally due to white space after the ?>, but I checked that...



says the following:
Parse error: parse error in /homepages/12/d88571136/htdocs/okg/system/lib-custom.php on line 534

Warning: Cannot add header information - headers already sent by (output started at /homepages/12/d88571136/htdocs/okg/system/lib-custom.php:534) in /homepages/12/d88571136/htdocs/okg/system/lib-sessions.php on line 180

Warning: Cannot add header information - headers already sent by (output started at /homepages/12/d88571136/htdocs/okg/system/lib-custom.php:534) in /homepages/12/d88571136/htdocs/okg/system/lib-sessions.php on line 192


what'd I miss/do wrong?!

Re:chat notify block

Posted on: 04/01/04 01:10pm
By: paulmon

Can you post the 5 lines of code before and after line 534 in your lib-custom?

Cheers,

Paul

[QUOTE BY= destr0yr] *shrugs*
I get error that headers have already been sent. I know it normally due to white space after the ?>, but I checked that...



says the following:
Parse error: parse error in /homepages/12/d88571136/htdocs/okg/system/lib-custom.php on line 534

Warning: Cannot add header information - headers already sent by (output started at /homepages/12/d88571136/htdocs/okg/system/lib-custom.php:534) in /homepages/12/d88571136/htdocs/okg/system/lib-sessions.php on line 180

Warning: Cannot add header information - headers already sent by (output started at /homepages/12/d88571136/htdocs/okg/system/lib-custom.php:534) in /homepages/12/d88571136/htdocs/okg/system/lib-sessions.php on line 192



what'd I miss/do wrong?![/QUOTE]

Re:chat notify block

Posted on: 21/01/04 05:47pm
By: jnordquist

I get the same error. I also checked for trailing spaces, and everything else I could.

(PASTED)

Parse error: parse error in /home/kenosha/public_html/geek/system/lib-custom.php on line 470

Warning: Cannot modify header information - headers already sent by (output started at /home/kenosha/public_html/geek/system/lib-custom.php:470) in /home/kenosha/public_html/geek/system/lib-sessions.php on line 180

Warning: Cannot modify header information - headers already sent by (output started at /home/kenosha/public_html/geek/system/lib-custom.php:470) in /home/kenosha/public_html/geek/system/lib-sessions.php on line 192

chat notify block

Posted on: 17/03/04 10:31am
By: JoeyE

With the introduction of the FlashChat/gl integration, I am wondering if there is a fix to the above code. I went to www.tufat.com and looked at the rewrite of the whoschatting block. (nice btw and works like a charm)

But to stay on topic here:
What would be the rewrite of the above code to make this work for GL v1.3.8 + and for the new FlashChatv3.8.

Thanks in advance!

chat notify block

Posted on: 17/03/04 02:15pm
By: paulmon

Sorry guys, been really busy. I've got the "Chat Notify" block sorted for this new version of FlashChat. The way FlashChat uses the database is now COMPLETELY different. I've also modified, the GL Plugin code so the flash chat pops open a window and isn't integrated into the site (thanks Dewdoobrown). I don't have access to the code at the moment but I will post the new code with instructions when I get home tonight.

However I'm noticing some bugs with the new FlashChat. Several users have been booted out mid-chat and the system it uses for "loging out" of chat isn't the best. My site currently shows me logged into chat twice because for some reason, most likely my pop-up blocker, stopped the pop-up window from logging me out of the chat. I then opened the chat window again and it blocked me saying someone with my username was already logged in. So I can't get into chat now and will have to clear this row from the database so it doesn't think I'm logged in when I'm not. This means that the "Who's Chatting" block now shows me in chat twice. This isn't an issue with that "Who's Chatting" block but one that deals with the way that FlashChat and the GL integration work. I'll look into this and see what can be done.

Cheers,

Paul

chat notify block

Posted on: 17/03/04 02:23pm
By: PSF

in the FlashChat config PHP, the timeout settings are by default pretty low..and I've yet to find a happy medium. Lurking users get booted...people who leave without logging out propery don't get cleard from the userwindow on time.

I haven't tried your code yet, but the one I'm using seems to work perfectly for 'who's chatting' (no repeats, shows just who is in the room). I took the code somebody posted over at tufat.com and tweaked it a bit.

I've been using this version of flashchat since it started, and the only problem I have with it is the way it logs out...other than that, I love it.

chat notify block

Posted on: 17/03/04 02:33pm
By: paulmon

[QUOTE BY= PSF] in the FlashChat config PHP, the timeout settings are by default pretty low..and I've yet to find a happy medium. Lurking users get booted...people who leave without logging out propery don't get cleard from the userwindow on time.

I haven't tried your code yet, but the one I'm using seems to work perfectly for 'who's chatting' (no repeats, shows just who is in the room). I took the code somebody posted over at tufat.com and tweaked it a bit.

I've been using this version of flashchat since it started, and the only problem I have with it is the way it logs out...other than that, I love it.
[/QUOTE]

The post at tufat.com was my code. What did you tweak exactly?

I agree the way this new FlashChat handles logging out is fubar. I don't think I know anyone that doesn't run a pop-up blocker these days which instantly screws the loggout.

Paul

chat notify block

Posted on: 17/03/04 03:24pm
By: PSF

Few tiny things..the way you had it posted put some line breaks in there; I think that was due to the phpbb board over there...and the url had to have FlashChat instead of Flashchat it seemed...plus, I added a resize parameter in your link.

One thing I just changed in my gl_connections table was to make userid unique..that seems to help.

chat notify block

Posted on: 17/03/04 07:02pm
By: paulmon

Here's the updated block.


function phpblock_whochat() {

    global $_CONF,$_USER;
    $query = mysql_query( "SELECT COUNT(id) FROM gl_connections WHERE gl_connections.userid > 1" );
    $numchat = DB_fetchArray($query);
    $numinchat = $numchat[0];
    $userquery = mysql_query( "SELECT username FROM gl_users, gl_connections WHERE gl_users.uid = gl_connections.userid");
    //$userquery = mysql_query( "SELECT name FROM chat_users WHERE NOW() - datetime < 12");
    if ($numinchat > 0) {
        while ($usersinchat = DB_fetchArray($userquery)) {
                $retval = $retval . $usersinchat[username] . '<br>';
    }
    } else {
        $retval .= 'Currently no users in chat';
    }

                $retval .= "<br><a href=\"\"onclick=\"window.open('/FlashChat/index.php',1,'directories=no,menubar=no,top=0,left=0,width=600,height=490')\"><center>Join Chat</center></a>";

return $retval;
}





You'll also need to change the following in /FlashChat/index.php comment out the lines with COM_siteHeader and COM_siteFooter.

Finally edit plugins/FlashChat/functions.inc

Change the $menurul to:

$menurul = " \" onclick=\"window.open('/FlashChat/index.php',1,'directories=no,menubar=no,top=0,left=0,width=600,height=490')";




Enjoy.

Paul

Geeklog - Forum
https://www.geeklog.net/forum/viewtopic.php?showtopic=28055