Welcome to Geeklog, Anonymous Thursday, March 28 2024 @ 07:00 am EDT

Geeklog Forums

Chatterblock


Anonymous

Anonymous
Hi all, I have finished writing an improved Shoutbox block for Geeklog, based on the Emessage nodeball for the Everything engine as seen on perlmonks. First, here's the SQL code to create the necessary table: # # Table structure for table 'gl_chatterblock' # CREATE TABLE gl_chatterblock ( id int(10) unsigned DEFAULT '0' NOT NULL auto_increment, time int(10) unsigned DEFAULT '0' NOT NULL, ip char(16) DEFAULT '' NOT NULL, author_user int(10) unsigned DEFAULT '0' NOT NULL, for_user int(10) unsigned, checkoff int(10) unsigned, msgtext char(255) DEFAULT '' NOT NULL, PRIMARY KEY (id) ); And you'll have to add this to lib-database.php: $_TABLES['chatterblock'] = $_DB_table_prefix . 'chatterblock'; And here's the diff to apply to a Geeklog 1.3.5sr1 installation to prevent commas from being used in usernames: --- geeklog-1.3.5sr1/public_html/users.php Sun Jun 9 23:26:51 2002 +++ users.php Sat Jul 6 23:34:59 2002 @@ -126,6 +126,7 @@ { global $_TABLES, $_CONF, $LANG04; + $username = strip_tags(str_replace(",", ".", $username)); $result = DB_query("SELECT email FROM WHERE username = '$username'"Wink; $nrows = DB_numRows($result); if ($nrows == 1) { @@ -173,6 +174,7 @@ { global $_TABLES, $LANG04, $_CONF; + $username = strip_tags(str_replace(",", ".", $username)); $ucount = DB_count($_TABLES['users'],'username',$username); $ecount = DB_count($_TABLES['users'],'email',$email); @@ -371,6 +373,7 @@ $display .= COM_siteFooter(); break; default: + $loginname = strip_tags(str_replace(",", ".", $loginname)); if (!empty($loginname) && !empty($passwd)) { $mypasswd = COM_getPassword($loginname); } else { And finally, here's the block: /** * Chatterblock * Inspired by the Chatterbox on http://perlmonks.org/ * Code based on Shoutbox by dreamscape: * http://www.geeklog.net/article.php?story=20020125060211603 * * This code is placed in the public domain. * */ function phpblock_Chatterblock() { global $_TABLES, $_USER, $HTTP_POST_VARS, $HTTP_GET_VARS, $PHP_SELF, $REMOTE_ADDR; // Maximum number of characters allowed in a word $max_width = 20; // Maximum number of lines to display in the chatterblock $max_display = 10; // Maximum length of time to display a line in the chatterblock $max_time = 300; // seconds // Where Chatterblock instructions are located; set to "" to disable link $howto_url = "http://example.com/staticpages/index.php?page=12345"; $cb_out = ""; foreach ($HTTP_POST_VARS as $key => $value) { // Check for checked off private messages if (substr($key, 0, 7) == 'cb_del_') { $id = addslashes(substr($key, 7, strlen($key)-7)); $query = 'update '.$_TABLES['chatterblock'] . ' set checkoff='.time() . ' where for_user='.$_USER['uid'].' &&' . " id='".$id."'"; DB_query($query); } } // Quote special characters to prevent abuse and mistakes $HTTP_POST_VARS['cb_message'] = htmlspecialchars($HTTP_POST_VARS['cb_message']); if ( !empty($_USER['uid']) && !empty($HTTP_POST_VARS['cb_message']) ) { if (substr($HTTP_POST_VARS['cb_message'], 0, 5) == '/msg ' || substr($HTTP_POST_VARS['cb_message'], 0, 3) == '/t ' || substr($HTTP_POST_VARS['cb_message'], 0, 6) == '/tell ') { $commapos = strpos($HTTP_POST_VARS['cb_message'], ','); if (!is_integer($commapos)) { $cb_out .= "Use comma after the name for targeted chat.<br>"; $cb_out .= '<em>You wrote: '.$HTTP_POST_VARS['cb_message'].'</em><br>'; $cb_needs_hr = 1; } else { $spacepos = strpos($HTTP_POST_VARS['cb_message'], ' '); $target = substr($HTTP_POST_VARS['cb_message'], $spacepos+1, $commapos-$spacepos-1); $message = substr($HTTP_POST_VARS['cb_message'], $commapos+1, strlen($HTTP_POST_VARS['cb_message'])-$commapos-1); if (substr($message, 0, 1) == ' ') { $message = substr($message, 1, strlen($message)-1); } $targetuid = cb_getuidbyname($target); $query = "insert into ".$_TABLES['chatterblock'] . "(msgtext, author_user, time, for_user, ip) values (" . "'".COM_checkWords($message)."'," . "'".$_USER['uid']."'," . time().", '$targetuid', '$REMOTE_ADDR')"; if (empty($targetuid)) { $cb_out .= "That person is not available now.<br>"; $cb_out .= '<em>You wrote: '.$HTTP_POST_VARS['cb_message'].'</em><br>'; $cb_needs_hr = 1; } else { DB_query($query); $cb_out_tail = "<em>You said \"$message\" to $target</em><br>"; } } } else { $query = "insert into ".$_TABLES['chatterblock'] . "(msgtext, author_user, time, for_user, ip) values (" . "'".COM_checkWords($HTTP_POST_VARS['cb_message'])."'," . "'".$_USER['uid']."'," . time().", NULL, '$REMOTE_ADDR')"; DB_query($query); } } $query = 'select * from '.$_TABLES['chatterblock'] . ' where for_user = "'.$_USER['uid'].'" && checkoff is null'; $result = DB_query($query); for ($i = 0; $i < DB_numrows($result); $i++) { $row = DB_fetchArray($result); $cb_out .= '<input type=checkbox name=cb_del_'.$row['id'].' value=y>' . '<em>'.cb_getnamebyuid($row['author_user']).' says: ' . wordwrap($row['msgtext'], $max_width, ' ', 1) . '</em><br>'; } if (DB_numrows($result) != 0 || $cb_needs_hr) { $cb_out .= '<hr>'; } $query = 'select * from '.$_TABLES['chatterblock'] . ' where time > "'.(time()-$max_time).'" && for_user is null' . ' order by id desc limit '.$max_display; $result = DB_query($query); for ($i = 0; $i < DB_numrows($result); $i++) { $row = DB_fetchArray($result); if (substr($row['msgtext'], 0, 4) == '/me ' || substr($row['msgtext'], 0, 3) == '/e ' || substr($row['msgtext'], 0, 4) == '/em ' || substr($row['msgtext'], 0, 7) == '/emote ') { $spacepos = strpos($row['msgtext'], ' '); $text = substr($row['msgtext'], $spacepos+1, strlen($row['msgtext'])-$spacepos-1); $line = '<em>'.cb_getnamebyuid($row['author_user']).' ' . wordwrap($text, $max_width, ' ', 1) . '</em><br>'; } else { $line = '<b>&lt;</b>' . cb_getnamebyuid($row['author_user']) . '<b>&gt;</b> ' . wordwrap($row['msgtext'], $max_width, ' ', 1).'<br>'; } $lines = $line . $lines; } $cb_out .= $lines; $loc = $PHP_SELF . '?'; foreach ($HTTP_GET_VARS as $getkey => $getvalue) { $loc .= urlencode($getkey) . '=' . urlencode($getvalue) . '&'; } $loc = substr($loc, 0, -1); $cb_out = "<form name=chatterblock action='$loc' method='post'>" . $cb_out; if (DB_numrows($result) == 0) { $cb_out .= "<em>and all is quiet...</em><br>"; } $cb_out .= "<br>" . $cb_out_tail; if (!empty($_USER['uid'])) { $cb_out .= "<input type=text name='cb_message' size='$max_width' maxwidth='255'>"; $cb_out .= "<input type=submit name='cb_submit' value='talk'>"; } $cb_out .= "</form>"; if (!empty($howto_url)) { $cb_out .= "<a href='$howto_url'><small><i>How do I use this?</i></small></a>"; } $cb_out .= "\n"; return str_replace("\\", "&#92;", $cb_out); } function cb_getnamebyuid($uid) { global $_TABLES; $query = 'select uid,username from '.$_TABLES['users']." where uid='$uid'"; $result = DB_fetchArray(DB_query($query)); return $result['username']; } function cb_getuidbyname($name) { global $_TABLES; $query = 'select uid,username from '.$_TABLES['users']." where username='$name'"; $result = DB_fetchArray(DB_query($query)); return $result['uid']; } Enjoy! Let me know in a comment to this story if you find any problems or make any improvements. (Erm, yuck... what horrible formatting. Could you please add <pre> tags (and set this story to HTML) before approving it? Thanks.)
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
FYI: Geeklog 1.3.6 will have support for the equivalent of the <pre> tag. However, with that much amount of code, it's usually easier to offer it for download somewhere ... bye, Dirk
 Quote

Status: offline

etegration

Forum User
Full Member
Registered: 02/20/02
Posts: 179
yes, can you please conpile it and i believe you already have them, just compress them and have them on your site for us to download please? It quite messy to see those codes that way...thanks!
http://www.etegration.com.sg
http://www.itcow.com
http://www.ministryofhosting.com
 Quote

Status: offline

squatty

Forum User
Full Member
Registered: 01/21/02
Posts: 269
A simple package of the block including a README and a .sql file for the table would be nice :-)

In addition, if you wouldn't mind can you upload the package here. I'm trying to keep track of all the GL blocks, themes, plugins, ect.

Thnx,
Squatty


In a world without walls and fences, who needs Windows and Gates?
 Quote

Status: offline

squatty

Forum User
Full Member
Registered: 01/21/02
Posts: 269
I packaged up the block myself...you can download it here.
In a world without walls and fences, who needs Windows and Gates?
 Quote

Anonymous

Anonymous
Ha ha, it seems I uploaded the file at the same time as squatty.
 Quote

Anonymous

Anonymous
Any idea where I can see this code in action?
 Quote

Status: offline

efarmboy

Forum User
Moderator
Registered: 02/26/02
Posts: 147
Sure - I have it installed on my site. I also created a help page (linked to a staticpage). I've integrated my IP-Plot hack as well. Blaine
 Quote

All times are EDT. The time is now 07:00 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content