Revision [4200]

This is an old revision of WikkaForum made by GmBowen on 2005-01-07 15:27:05.

 

Wikka Forum

Last edited by GmBowen:
tpyo & code/files altered to prevent function conflicts (yay!!..thanks JW)
Fri, 07 Jan 2005 15:27 UTC [diff]


Often one finds wiki's used as adjuncts to other tools....discussion forums for instance. In those forums the main topic threads are determined by the administrator(s) and out of the hands of most of the users. Wiki's, such as Wikka, are meant to provide considerable flexibility for the users and place the control in their hands. At the same time, this freedom can lead to very unstructured and difficult to follow discussions. Below is code for a forum tool that allows an individual user to set up a structured forum thread on any page. The page owner can control the contributers to the forum discussions, or leave it open for all to participate. Apart from this, it's easier to set up the wiki & registration into it with a forum tool than to set up both a wiki & a forum.

As an example, see my original forum for one of my courses and the wiki-based clone of the forum using the forum tool. Almost identical functionality, and the wiki one was considerably faster and easier to set up. Additionally, I can add comments and links FAR more easily on individual forum pages in the clone than I ever could in the real forum software....and things are far easier to edit. Once I can get a private message system done (see here) then I'll use this forum approach for courses instead of an actual forum since I'll have all the needed functionality and more in one spot...and that's even more true when we get simple table formatting (hint hint), etc. (for those of you that notice that the original forum had "anonymous" contributions, it will be substantially easier to change the code in {{wikkaforum}} to accomplish that so that names are only shown to admin than it was in the code for PunBB)

The action allows you to open the discussion threads on any page using {{wikkaforum page="pagename"}}, although entries cannot be made anywhere but the home page (for security reasons). The page owner can designate a user list and a topic title (example: {{wikkaforum share="JavaWoman DarTar GmBowen" topic="Paged Comments"}}) or leave the discussion threads open to all users.

Create the follow table in your wikka database (note that you might have to change the table prefix to what you use for your wikka)
CREATE TABLE `wakka_wikkaforum` (
  `id` int(11) NOT NULL auto_increment,
  `wid` int(11) NOT NULL default '0',
  `for_ptitle` varchar(255) NOT NULL default '',
  `for_text` text NOT NULL,
  `tag` varchar(50) NOT NULL default '',
  `for_data` datetime NOT NULL default '0000-00-00 00:00:00',
  `for_dataw` datetime NOT NULL default '0000-00-00 00:00:00',
  `for_ip` varchar(15) NOT NULL default '000.000.000.000',
  `for_name` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM;


Place the following code as wikkaforum.php in the actions directory.
<?php
<?php
// wikkaforum.php Version 1.0e
// Use: {{wikkaforum [topic="topic description"] [page="pagename"] [share="name1 name2 name3 etc"]}}
// MODIFIED from SForum class V1.2 for use in wikka wiki by GmBowen for a SSHRC research project.
// Modifications & original code released under GPL
// The file wikkaforumfunctions.php MUST be included in a directory in wikka root called "scripts"
// Original Simple Forum code available from www.phpclasses.org
/**********************************
* SForum class
* @author: Wojciech Napiera&#322;a XII.2004
* @help: Ondra Marek ondra.marek@interval.cz
* @
* voytass@op.pl
*
* @license: GNU GPL
**********************************
*/

$link = $this->config["base_url"].$this->MiniHref($method, $tag);
$username=$this->GetUserName();
$prefix=$this->config["table_prefix"];
if (empty($page)) {
    $tag=$this->getPageTag();
    $pageX=$tag;
    }
    else
    {
    $tag=$page;
    }

// code to determine who can contribute to the threads
if(empty($share)){$share = 'ALL';}
$tok = strtok($share, " \n\t");
  while ($tok) {
   if($tok == $this->GetUserName() || $tok == "ALL") { $use = 'true';}
   $tok = strtok(" \n\t");
  }
if (strtoupper($this->GetUserName())==strtoupper($this->GetPageOwner())){$use = 'true';}

// check so that when there are multiple instances of the action one cannot "add" to the database
// in response to having a thread from another page open (trust me, this code is necessary)
$tablepgname = $this->LoadSingle("SELECT tag FROM ".$this->config['table_prefix']."wikkaforum WHERE wid='".$_GET['wid']."' LIMIT 0,1");
$shouldwrite = $tablepgname[tag];
if (($shouldwrite==$this->getPageTag()) || (empty($shouldwrite))) {$use2 = 'true';}

// CLASS STATEMENT STARTS HERE. Using include_once prevents function conflicts & allows multiple instances on the same page
include_once("./scripts/wikkaforumfunctions.php");
// CLASS STATEMENT ENDS HERE.

if (!isset($forum)) {
    $forum = new SForum;
}
?>
<div align="center">
<table WIDTH='90%' border='0'><tr ALIGN='left'><td>
<?php
$forum->Show_SFname($topic);
echo "&nbsp;&nbsp;<A HREF=\"".$link."\"><small>Return to Front Menu</small></A>\n";
print("<br>\n");

if (isset($_POST['submit'])) {
    if (!empty($_POST['frm_ptitle']))
    {
        if(empty($page))
        {
        $forum->Add_new_post($_POST['frm_ptitle'],$_POST['frm_text'],$tag,$_POST['frm_ip'],$username,$_POST['frm_wid'],$prefix);
        }
    }
}
if (isset($_GET['wid'])) {
    #phpinfo();
    $forum->Show_SForum_Threads($_GET['wid'], $tag, $prefix);
    $forum->pansw = $_GET['wid'];
    } else {
    $forum->Show_SForum($link, $tag, $prefix);
    $forum->pansw = 0;
}
if ($user = $this->GetUser())
    {
        if ($pageX==$this->getPageTag())
        {
            if ($use == 'true')
            {
                if(empty($page))
                {
                    if ($use2 == 'true')
                    {
                    $forum->Show_frm($forum->ptitle, $link);
                    }
                }
            }
        }
        else
        {
echo "<small>&nbsp;&nbsp;This forum originates from ".$page.".</small><br>";
        }
    }
    else
    {
    print("<small>Sorry, you need to be a registered & logged-in user to contribute to the forums.</small>");
        if ($pageX!=$this->getPageTag()){print("<small>&nbsp;&nbsp;This forum originates from ".$pageX.".</small><br>");}
}
print("\n");
echo "&nbsp;&nbsp;<A HREF=\"".$link."\"><small>Return to Front Menu</small></A>\n";
?>
</td></tr></table></div>


The following file contains the functions for wikkaforum.php and must be saved in a file called wikkaforumfunctions.php and stored in a directory called scripts placed in the wikka root. (Thanks to JW to steering me towards this approach!!)
<?php
// wikkaforumfunctions.php Version 1.0e
// Use: required to use wikkaforum.php action. This file must be placed in a file in wikka root called "scripts".
// MODIFIED from SForum class V1.2 for use in wikka wiki by GmBowen for a SSHRC research project.
// Modifications & original code released under GPL
// Original Simple Forum code available from www.phpclasses.org
/**********************************
* SForum class
* @author: Wojciech Napiera&#322;a XII.2004
* @help: Ondra Marek ondra.marek@interval.cz
* @
* voytass@op.pl
*
* @license: GNU GPL
**********************************
*/

class SForum {
    var $ptitle;
    var $react;              // number of answers in a thread
    var $pansw;
    var $title;

    // SForum: constructor
    function SForum() {
        $this->ptitle = NULL;
        $this->pansw = 0;
        $this->title = "<TITLE>$this->SFname</TITLE>";
        print($this->title);
    }

    // Show_frm: displays the form
    function Show_frm($ptitle=NULL, $link) {
        if(!empty($ptitle)) {
            $this->ptitle = "Re: ".$ptitle;
        }
        $zawartosc = "\n\n<FORM ACTION=\"".$link."\" METHOD=\"post\" NAME=\"frm\">\n"
        . "<TABLE><TR>\n"
        . "<TD>Title:</TD><TD><INPUT TYPE=\"text\" NAME=\"frm_ptitle\" VALUE=\"$this->ptitle\" SIZE=\"65\"></TD>\n"
        . "</TR><TR>\n"
        . "<TD VALIGN=top>Text:</TD><TD><TEXTAREA NAME=\"frm_text\" cols=\"65\" rows=\"10\"></TEXTAREA></TD>\n"
        . "</TR><TR>\n"
        . "<TD></TD><TD COLLSPAN=\"2\"><INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Submit Comment\"></TD>\n"
        . "</tr></TABLE>\n"
        . "<INPUT TYPE=\"hidden\" NAME=\"frm_ip\" VALUE=\"".$_SERVER['REMOTE_ADDR']."\">\n"
        . "<INPUT TYPE=\"hidden\" NAME=\"frm_wid\" VALUE=\"".$this->pansw."\">\n"
        . "</FORM>\n\n";
        print($zawartosc);
    }

    // Show_SFname : Show SForum name as text
    function Show_SFname($topic) {
        print("<H2>$topic</H2>\n");
    }

    // Add_new_post: Adds new record to DB
    function Add_new_post($ptitle,$text,$tag,$ip,$name,$frm_wid,$prefix) {

        $this->ptitle = addslashes(htmlspecialchars(trim($ptitle)));

        $this->text = addslashes(htmlspecialchars(trim($text)));
        if ($frm_wid == 0) {
            $zapytanie = "INSERT INTO ".$prefix."wikkaforum (wid,for_ptitle,for_text,tag,for_data,for_dataw,for_ip,for_name) VALUES('$frm_wid', '$this->ptitle', '$this->text', '$tag', now(), now(), '$ip', '$name')";
            $sql = mysql_query($zapytanie) or die (mysql_error());
        } else {
            $zapytanie = "INSERT INTO ".$prefix."wikkaforum (wid,for_ptitle,for_text,tag,for_data,for_ip,for_name) VALUES('$frm_wid', '$this->ptitle', '$this->text', '$tag', now(), '$ip', '$name')";
            $sql = mysql_query($zapytanie) or die (mysql_error());
        }
        $id = mysql_insert_id();
        if ($frm_wid == 0) {
            $zapytanie = "UPDATE ".$prefix."wikkaforum SET wid='$id' WHERE id='$id'";
            #print $zapytanie;
            $sql = mysql_query($zapytanie) or die (mysql_error());
        } else {
            $zapytanie = "UPDATE ".$prefix."wikkaforum SET for_dataw=now() WHERE id='$frm_wid'";
            #print $zapytanie;
            $sql = mysql_query($zapytanie) or die (mysql_error());
        }

    }

    // Show_SForum: Displays the main message of threads
    function Show_SForum($link, $tag, $prefix) {
        $sql = "SELECT * FROM ".$prefix."wikkaforum WHERE id=wid AND tag='$tag' ORDER BY for_dataw DESC";
        #print $sql."<br>\n";
        $sql = mysql_query($sql) or die (mysql_error());
        $iledokumentow = mysql_affected_rows();
        if ($iledokumentow > 0) {
            print("<TABLE BORDER=\"1\" WIDTH=\"100%\">\n");
            while ($row = mysql_fetch_array($sql)) {
                $sql1 = "SELECT COUNT(wid)-1 AS num FROM ".$prefix."wikkaforum WHERE wid=".$row['id']." AND tag='$tag' GROUP BY wid";
                #print $sql1."<br>\n";
                $sql1 = mysql_query($sql1) or die (mysql_error());
                $row1 = mysql_fetch_array($sql1);
                //number of reactions
                $this->react=$row1['num'];
                if ($row['for_name'] == "") {
                    $row['for_name'] = "Go&#347;&#263;";
                }
                $this->ptitle = stripslashes($row['for_ptitle']);
                print("<tr ALIGN='left'><TD>$link2<A HREF=\"".$link."&wid=".$row['id']."\">".$this->ptitle."</A></TD><TD ALIGN=\"center\">Replies:&nbsp;".$this->react."</TD><TD ALIGN=\"center\"  WIDTH=\"20%\">".$row['for_name']."</TD><TD ALIGN=\"center\"  WIDTH=\"20%\">".$row['for_data']."</TD></tr>\n\n");
            }
            unset($this->react);
            print("</TABLE>\n");
        } else {
            print("&nbsp;There are no threaded topics yet. Why don't you start one?<br>\n");
        }
        $this->ptitle = ""; //the new thread's title is empty
    }

    // Show_SForum_Threads: Displays all messages of a thread
    function Show_SForum_Threads($wid, $tag, $prefix) {
        //$this->pansw = $wid;
        $zapytanie = "SELECT * FROM ".$prefix."wikkaforum WHERE wid='$wid' AND tag='$tag' ORDER BY for_data ASC";
        //print $zapytanie;
        $sql = mysql_query($zapytanie) or die (mysql_error());
        $iledokumentow = mysql_affected_rows();
        if ($iledokumentow > 0) {
            print("<TABLE BORDER=\"1\" WIDTH=\"100%\">\n");
            while ($row = mysql_fetch_array($sql)) {
                $this->ptitle = stripslashes($row['for_ptitle']);
                $this->text = nl2br(stripslashes($row['for_text']));
                if ($row['for_name'] == "") {
                    $row['for_name'] = "Go&#347;&#263;";
                }
                    $pmail = NULL;
                    $kmail = NULL;
                print("<tr ALIGN='left'><TD><b>".$this->ptitle."</b><div ALIGN=\"right\"><i>$pmail".$row['for_name']."$kmail&nbsp;&nbsp;<FONT SIZE=\"1\">".$row['for_data']."</FONT></i></div>\n\n");
                print("<hr>".$this->text."<br><br></TD></tr>\n\n");
            }
            print("</TABLE>\n");
        } else {
            print("&nbsp;&nbsp;&nbsp;No threads(s) exist for this topic.<br>\n");
        }
        $zapytanie = "SELECT * FROM ".$prefix."wikkaforum WHERE id='$wid' LIMIT 0,1";
        $sql = mysql_query($zapytanie) or die (mysql_error());
        $row = mysql_fetch_array($sql);
        $this->ptitle = stripslashes($row['for_ptitle']);  //Re title for form
    }
}
?>


The "main page" looks like this.....
http://gmbowen.educ.unb.ca/wikitest/discussionforum.jpg
and the threads look like this....
http://gmbowen.educ.unb.ca/wikitest/discussionforum2.jpg

To Do/Further Development list:


CategoryDevelopment
There are 14 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki