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
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:
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.
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
(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.
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
<? 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).
<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).
<? include('parse.php'); doParse('tag.inc'); ?>
/* 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)
<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).
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.
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 ::