NP_Chat.php

Code download: http://hulan.info/blog/other/NP_Chat.txt Dead Link (30 Oct 2007)

(Author: Radek HulaN)

This a simple mini-chat plugin / shoutbox (displays last 15 messages, including user name and email/url, checks for message duplicity, also creates form for entering a new message). Messages are simple text lines, up to 255 chars, nothing to do with articles or comments, ideal for comments for the website as whole. Also adds mailto: and/or “http:” where relevant..

Now, multiple shoutboxes are supported.

Styles used (samples included):
 .chattable{
   background-color: #FFF8F0;
   border: 1px solid #9F9F9F;
   border-bottom: 1px solid #F4F4F4;
   font-size: 11px;
   height: 240px;
   line-height: 18px;
   overflow: auto;
   position: relative;
   width: auto;
 }
 .chatform{
   text-align: right;
 }

Also used styles (globally in Nucleus, and also by this plugin; samples):

 .formbutton{background-color:#BFBFBF;border:1px solid #A9A9A9;color:#353535}
 .formbutton:hover{background-color:#FFDA00;border:1px solid #000000;color:#000000}
 .formfield{background-color:#F4F4F4;border:1px solid #9F9F9F;border-bottom:1px solid #FAFAFA;color:#4A4A4A;margin:1px}
 .formfield:focus{background-color:#FFFFFF;border:1px solid #000000}

You can see it in action here (right column, way down..:): http://hulan.info/blog/

Chatbox/Shoutbox

Installing

Copy and paste code (above) into a file called NP_Chat.php. Upload the file into the nucleus plugin directory, than install or update the subscription list.

Usage:

  • Single chat:
  • <%Chat%>
  • Multiple, independent shoutboxes:
  • <%Chat(chatid)%> ,
  • e.g. <%Chat(1)%> for main page messages and <%Chat%(2)> for contact list messages
  • e.g. <%Chat(memberid)%>
  • e.g. <%Chat(blogid)%>
  • e.g. <%Chat(blogid*10+memberid)%>

Note: ONLY ONE SHOUTBOX PER ONE PAGE IS SUPPORTED. If you need to have more shoutboxes on a single page, let me know, I can adjust it, but I dont think it is useful, so didnt bother to make this mod… Being it a homepage, member page or a blog page, there is always only one shoutbox.

Version History

12-31-2003: release 0.1.0, tested with Nucleus 2.5Beta, but will work with ANY version 01-02-2004: release 0.1.2, added options for labels, textarea and number of messages, addded support for “mailto:” and “http:” 01-09-2004: release 0.2.0, added options for multiple chatboxes, old versions MUST be de-installed if you want to use this one,no need to upgrade if you need just single shoutbox

Funky Customizations

(by LengL - http://leng-lui.info/) Sick of NP_Chat stretching out your layouts? Tired of having to manually refresh to see new messages? Follow these instructions to get your chatbox to display in an iframe that automatically refreshes itself.

Known problems with this stopgap measure:
  • The input form is no longer output by the original plugin file so you can't use the options specified in the “edit plugin options” area to set the field
  • This results in usernames not being in bold if they leave the original email/url input field as it is

Fixes that involve messing with the code in NP_Chat using if statements end up causing double posts from users who leave the default email/url field as is - one bolded and the other hyperlinked.

A list of things I plan to fix in this plugin (not really in list format per se, but it's still kind of a list): http://forum.nucleuscms.org/viewtopic.php?t=4877

How To:
  1. Create a file called parse.php and place it in your root directory. It should contain the following lines:
<?
 include('config.php');
   function doParse($filename) {
      $handler = new ACTIONS('pageparser');
      $parser = new PARSER(SKIN::getAllowedActionsForType('pageparser'), $handler);
      $handler->parser =& $parser;
 
      if (!file_exists($filename)) doError('A file is missing');
 
      // read file
      $fd = fopen ($filename, 'r');
      $contents = fread ($fd, filesize ($filename));
      fclose ($fd);     
 
      // parse file contents
      $parser->parse($contents);
 
   }
?>

For reference, karma's thread on using skinvars in non-blog pages: http://forum.nucleuscms.org/viewtopic.php?t=464

You need this file so you can use the skinvar <%Chat%> in a non-blog page (the page that is your iframe source).

  1. . Create a file called tag.inc and place these lines of code:
<html>
 
<head>
  <title>Tagboard</title>
  <link rel="stylesheet" type="text/css" href="<%skinfile(yourskin/yourstyle.css)%>" />
  <meta http-equiv="refresh" content="10" />
</head>
 
<body>
<%Chat%>
</body>
 
</html>

To change how often it refreshes, change the value of content=“**” (it's in seconds, so 30 if you want it to refresh every 30 secs, etc).

  1. Create a file called tag.php and place it in your root directory. Have the following lines of code in it:
<?
include('parse.php');
doParse('tag.inc');
?>
  1. Open NP_Chat and find the following lines of code:
      /* show form to enter new NAME, EMAIL and MESSAGE */
      $prNAME = $this->getOption('ChatNAME');
      $prEMAIL = $this->getOption('ChatEMAIL');
      $prMESSAGE = $this->getOption('ChatMESSAGE');
      $prTEXTAREA = $this->getOption('ChatTEXTAREA');
      $prBUTTON = $this->getOption('ChatBUTTON');
 
      echo "<div class=\"chatform\">";
      echo "<form method=\"post\" action=\"index.php\">";
      echo "<label for=\"NAME\">$prNAME</label><input class=\"formfield\" type=\"text\" id=\"NAME\" NAME=\"NAME\" size=\"15\" maxlength=\"20\"><br>";
      echo "<label for=\"EMAIL\">$prEMAIL</label><input class=\"formfield\" type=\"text\" id=\"EMAIL\" NAME=\"EMAIL\" size=\"15\" maxlength=\"60\"><br>";
      echo "<label for=\"MESSAGE\">$prMESSAGE</label><textarea class=\"formfield\" id=\"MESSAGE\" NAME=\"MESSAGE\" cols=\"20\" rows=\"2\">$prTEXTAREA</ textarea><br>";
      echo "<input class=\"formbutton\" type=\"submit\" value=\"$prBUTTON\">";
      echo "</form>";
      echo "</div>";

Delete them otherwise they will show up in the brand new iframe shoutbox you have. (NB: The closing textarea tag will not have a gap in it - this is just to prevent it from breaking this page)

  1. On your actual blog page, where you want the shoutbox to appear, place the following code:
<iframe frameborder="0" width="200" height="200" id="tagboard" name="tagboard" src="tag.php"></iframe>
<div class="chatform">
  <form method="post" action="tag.php" target="tagboard">
  <input class="formfield" type="text" id="NAME" NAME="NAME" size="31" maxlength="20" value="Name" /><br />
  <input class="formfield" type="text" id="EMAIL" NAME="EMAIL" size="31" maxlength="60" value="Email / URL" /><br />
  <input class="formfield" id="MESSAGE" NAME="MESSAGE" size="31" value="Message" /><br />
  <input class="formbutton" type="reset" value="Clear message" />   <input class="formbutton" type="submit" value="Tag!" />
 
  </form>
</div>

And that's all there is to it! I changed the message field to an input field instead of a textarea field because it will do funny things to your Nucleus Admin area if you have a textarea inside your skin parts (for reference see http://forum.nucleuscms.org/viewtopic.php?t=4886).

Other Things You Can Do

To make the input field clear itself when clicked on, place

onClick="this.value='';"

inside the input tag, like this:

<input class="formfield" type="text" id="NAME" NAME="NAME" size="31" maxlength="20" value="Name" onClick="this.value='';" />

To make it only possible for members to post messages, use the following:

<%if(loggedin)%>
<put your form code here>
<%endif%>

For this solution to work, you must be displaying NP_Chat in an iframe. That way, all visitors will see your shoutbox which will refresh for new messages, but only members have access to the form to post messages.

EDIT by [[http://www.igwanarob.net/|IgwanaRob]]

If you have problems with apostrophes and other characters showing up with backslashes inside the chatbox, try replacing:

$msg['MESSAGE']

in lines 142 and 151 with:

$msg['MESSAGE']=stripslashes($msg['MESSAGE'])

It now should work fine. (as per http://plugins.nucleuscms.org/[[item/39|this thread]])

Also, when someone enters a URL instead of an email address, the default action launches that URL in the current browser. If someone wants to have those external links open up in a new browser window, simply change the URL part in line 151 from:

”<a href=\”$myurl\”>”

to:

”<a href=\”$myurl\” target=_blank>”

:: Back to Plugins Overview ::

chat.txt · Last modified: 2007/10/31 03:48 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki