Forms-ShoutBox

The design for this ShoutBox is blatant theft from Shoutbox that KMcC did for Fox. Basically it gives a quick chat capability in the sidebar. "Imitation is the sincerest form of flattery..." :-)

This WikiSh version of shoutbox adds the capability of cleaning the comments that occurred more than an hour ago by clicking the "Clean" button. You can also over-ride your nickname...

DEPENDENCY: Toggle - make sure you install this first...

To see it in action go to http://pmwiki.qdk.org and look in the sidebar on the left.

Features:

  • Only the last 2 hours of comments are displayed (configurable via argument (# of seconds) to the ListShout MX)
  • Resizable comment box using arguments (1st=height, 2nd=width -- include "em" or "px") of the (:shoutbox ...:) markup
  • Capability of cleaning the page of older comments, but option normally hidden
  • Option (show/hide-able) to over-ride your nickname (defaults to your author name if you are logged in, defaults to showing the option if you don't have one set)
  • Allows you to specify how many lines of history to list (over-rides time limit)
  • Scrolling list of comments allows view of history (javascript must be enabled on your browser to scroll to the bottom)

Put the following in WikiSh.WikiShRC:

set -s ShoutPage = "Site.ShoutBox"

function ProcShout
{
   # If the user set the nickname on the form, use it
   if test -n ${shoutname}
   then
      set -s --session shoutname = ${shoutname}
   fi
   if test -z ${~shoutname}
   then
      set -s --session shoutname = {$Author}
   fi
   set -s shoutname = ${~shoutname}
   set -s --form shoutname = ${shoutname}
   if test -n ${shoutname}
   then
      set -s shoutid = "${shoutname}: "
   else
      set -s shoutid = ""
   fi
   if test -n ${shoutsave} && test -n ${shouttext}
   then
      echo "${NOW}: ${shoutid}${shouttext}" >>${ShoutPage}
   fi
}

function ListShout
{
   if test -n ${shoutlines}
   then
      set lines = ${shoutlines}
      set deadline = 0
   else
      if test -n ${1}
      then
         set lines = ${1}
      else
         set lines = 100
      fi
      if test -n "${2}"
      then
        set deadline = ${NOW} - ${2}
      else
         set deadline = ${NOW} - 7200
      fi
   fi
   tail -n ${lines} ${ShoutPage} | while read -IFS:": " timestamp rest
   do
      if test ${timestamp} >= ${deadline}
      then
         echo "${rest}"
      fi
   done
   if test -n ${shoutname}
   then
      set -s ShoutShowHide = 'hide'
      set -s ShoutNameLabel = 'Name:'
   else
      set -s ShoutShowHide = 'show'
      set -s ShoutNameLabel = "'''Name:'''"
   fi
}

function CleanShout
{
   if test -z ${shoutclean}
   then
      return
   fi
   set boundary = ${NOW} - 3600
   if test -f Tmp.Shout
   then
      rm Tmp.Shout
   fi
   cat ${ShoutPage} | while read --IFS:": " time line
   do
      if test ${time} -ge ${boundary}
      then
         echo "${time}: ${line}" >>Tmp.Shout
      fi
   done
   cat Tmp.Shout >${ShoutPage}
}

Put the following in the desired location in the Site.SideBar (or whatever page your skin uses for the sidebar):

(:linebreaks:)
(:shoutbox:)
{(wikish_form process)}{(wikish ProcShout; CleanShout; ListShout 25 10800)}
(:shoutboxend:)
(:nolinebreaks:)
{(wikish_form QUICKFORM name=shoutbox method=GET)}
(:input text shouttext value="" size=30:) 
(:input submit shoutsave "Shout!":) 
(:toggle ${ShoutShowHide} box1 button=1 show="More>>" hide="Hide Options" :)
>>id=box1 border="1px solid #999" padding=5px bgcolor=#fed<<
${ShoutNameLabel} (:input text shoutname size=18:)\\
Lines to Show: (:input text shoutlines size=3:)
(:input submit shoutclean "Clean Old Entries":)
>><<
(:input end:)

Now put the following markups (for a prettily styled shoutbox, the javascript to scroll to the bottom of the list, etc.) in your config.php:

Markup('shoutbox', '<{$var}',
   '/\(:shoutbox(?:\s+(\S+)(?:\s+(\S+))?)?:\)/ie', 
   "Keep('<div id=\"shoutbox\" name=\"shoutbox\" style=\"background-color: #ffffa1; width:'.('$1'?'$1':'210px').'; font-size: smaller; height:'.('$2'?'$2':'20em').'; overflow:auto;\" ><span style=\"padding: 0px 4px; background-color: #ffe53e;\">Shout Box</span>')");
Markup('shoutboxend', '>shoutbox',
   '/\(:shoutboxend:\)/ie', 
   "Keep('</div><script type=\"text/javascript\">o=document.getElementById(\"shoutbox\");o.scrollTop = o.scrollHeight;</script>')");