Quer-Verweis

ein kleines Forum

Ein kleines Forum ...

Voraussetzungen:

  • openEngine 1.6 im Verzeichnis /htdocs

Ziel: Ein Forum mit Grundfunktionen.

Schritt 1: Anlegen einer neuen Datenbanktabelle:

CREATE TABLE `oe_forum` (
  `forum_thread` varchar(255) NOT NULL default '',
  `forum_author` varchar(255) NOT NULL default '',
  `forum_date` datetime NOT NULL default '0000-00-00 00:00:00',
  `forum_header` varchar(255) NOT NULL default '',
  `forum_content` mediumtext NOT NULL,
  PRIMARY KEY  (`forum_date`,`forum_author`)
) TYPE=MyISAM;

Schritt 2: Forum-Skript im Verzeichnis /htdocs/system/addOns/Forum.php anlegen:

<style>
.forum {
font-size:11px;
font-family:verdana;
width:100%;
overflow:hidden;
}
.forumitem {
border:1px solid #eee;     
}
.forumhead, .forumheader{
background-color:#f3f3f3;
}
.forumheader {
font-weight:bold;
}
.forumbody {
}
.forumcontent {
font-size:11px;
font-family:verdana;
width:404;
height:80px;
overflow:hidden;
}
#mess {
position:absolute;
top:0;
left:0;
width:414;
height:140;
padding:4 4 4 4;
border:1 solid #888;
border-top:12 solid #888;
background-color:#f7f7f7;
visibility:hidden;
}
</style>

Bis hierhin nur Style ...

<?
  global $db_praefix;$link=connectDB();
  if ($_POST["thread"] == "") {
    $query="SELECT DISTINCT forum_thread FROM ".$db_praefix."forum ORDER BY 1";
    $res=mysql_query($query);closeDB($link);
?>
    Themen-Auswahl:<br><div class=forum><form name=f method=post>
<?  while ($row = mysql_fetch_array($res)){
?>
      <a href='javascript:f.thread.value="<?= $row["forum_thread"] ?>"; f.submit();'>
      <?= $row["forum_thread"] ?></a><br />
<?    } //endwhile ?>
    <input type=hidden name=thread value="" /></form></div>
<? // Ende der Themenauswahl ----------------------------------------}
  else {
  if (($_POST["title"] <> "") and (strlen($_POST["content"]) < 4096)) {
    if ($_POST["author"] == "") $_POST["author"] = "Gast";
    $query="INSERT INTO ".$db_praefix."forum VALUES ('".htmlspecialchars($_POST["thread"])."','".$_POST["author"]."','".$_POST["date"]."','".htmlspecialchars($_POST["title"])."','".htmlspecialchars($_POST["content"])."')";
    $res=mysql_query($query);
    $_POST["title"]="";
    }
  $query="SELECT * FROM ".$db_praefix."forum WHERE forum_thread='".$_POST["thread"]."' ORDER BY 3";
  $res=mysql_query($query);closeDB($link);
  $anzahl=mysql_num_rows($res);
  if ($anzahl == 1) $anzahl = $anzahl . " Beitrag"; else $anzahl = $anzahl . " Beiträge";
?>
  <form name=f method=post>
  Thema: <?= $_POST["thread"] ?> [ <?= $anzahl ?> ] |
  <span onclick="with (document.getElementById('mess').style) { visibility='visible';top=0;left=0}">Beitrag verfassen</span>
  <br /><span onclick="movedown('middle_col','middle_col_content',100000);stopscroll();">zum letzten Eintrag</span>
  <div class=forum title="Beitrag verfassen = Doppelklick" ondblclick="with (document.getElementById('mess').style)
  {visibility='visible';top=window.event.offsetY; left=window.event.offsetX;} ">
<?  while ($row = mysql_fetch_array($res)){ ?>
      <div class=forumitem>
      <div class=forumhead>
      <span style="width:50%"><?= $row["forum_author"] ?></span>
      <span style="width:45%; text-align:right"><?= substr($row["forum_date"],0,16) ?></span>
      <div class=forumheader onClick="f.title.value=this.innerHTML"><?= $row["forum_header"] ?></div></div>
      <div class=forumbody><?= $row["forum_content"] ?></div></div>
<?  } //end while ?>
  <span onclick="moveup('middle_col','middle_col_content',100000);stopscroll();">zum ersten Eintrag</span>
  </div>
  <input type=hidden name=author value="<?= $_SESSION["account_firstname"] ?> <?= $_SESSION["account_lastname"] ?>" />
  <input type=hidden name=date value="<?= date("Y-m-d H:i:s") ?>" />
  <!-- 
       PopUp für die Eingabe eines neuen Diskussionsbeitrags -------------------------
  -->
  <div id=mess title="Fenster schliessen = Doppelklick" ondblClick="this.style.visibility='hidden'">
  <span style="width:40">Thema</span>
  <input type=input maxlenght=254 name=thread style="width:360" value="<?= $_POST["thread"] ?>" >
  <span style="width:40">Titel</span>
  <input type=text name=title maxlength=254 style="width:360" value="" /><br />
  <textarea name=content class=forumcontent ></textarea><br>
  <input class=button style="width:49.5%" type=button value=schliessen
  onclick="document.getElementById('mess').style.visibility='hidden'" />
  <input class=button style="width:49.5%" type=submit value=absenden
  onclick="document.getElementById('mess').style.visibility='hidden'"/></form></div>
<? } //endif ?>

Anmerkungen:

Das Scolling wird an anderer Stelle besprochen ...
Der Diskussionsbeitrag wird auf 4096 Zeichen begrenzt.
Die Eingabe läßt keine HTML-Formate durch (htmlspecialchars-Funktion).
Es sollte also einigermaßen sicher sein, dass keine "Nebeneffekte" auftreten...

Was noch fehlt, ist der Ausschluß einer permanenten Beitragschreibers, 'schlimme'-Worte-Zensur, ...

Es ist halt ein 'kleines' Diskussionsforum und will auch nicht die anderen Lösungen ersetzen (phpbb usw.). Es kann zum Gästebuch oder FAQ leicht umgebaut werden...

© 2005 cptc | Impressum | powered by OpenEngine 1.6