Skip to content

Instantly share code, notes, and snippets.

@miio
Created June 7, 2011 07:41
Show Gist options
  • Save miio/1011839 to your computer and use it in GitHub Desktop.
Save miio/1011839 to your computer and use it in GitHub Desktop.
Legacy Simple BBS
<?php
error_reporting(-1);
ini_set('display_errors','On');
/**
* TDDBC Lv3 or Lv4 LegacyCode
* Legacy Simple BBS
* [email protected]
*/
/**
* About Legacy Simple BBS
* Require:Read Comment
* Post Comment
* Reply Comment
* Attention:No Username
* No DeletePassword(Deletable Anonymouse)
*/
//DB Connection
$db = "legacy.db";
?>
<html>
<head>
<title>
<?php
$sqlite = sqlite_open($db,0666,$error);
if(isset($_GET["remove"])){
//Initialize
sqlite_query($sqlite, "Create Table Subject (id int, name varchar(255))", SQLITE_BOTH, $sqliteerror);
sqlite_query($sqlite, "Create Table Bord (id int, parent int, body text)", SQLITE_BOTH, $sqliteerror);
}
/*
$result = sqlite_query($sqlite, "SELECT name FROM Subject WHERE page=".$_GET["page"], SQLITE_BOTH, $sqliteerror);
$title = sqlite_fetch_array($result, SQLITE_ASSOC);
print $title['name'];
*/
?>
Lagacy Bord
</title>
</head>
<?php
print "<body>";
//View Post
$result = sqlite_query($sqlite, "SELECT * FROM Bord", SQLITE_BOTH, $sqliteerror);
$last = sqlite_num_rows($result);
++$last;
if(isset($_GET["add"])){
//Add Post
$result2 = sqlite_query($sqlite, " INSERT INTO Bord(id,parent,body) VALUES(".$last.",".$_POST["add_id"].",'".$_POST["body"]."')", SQLITE_BOTH, $sqliteerror);
}else if(isset($_GET["reply"])){
//Reply Post
$result2 = sqlite_query($sqlite, " INSERT INTO Bord(id,body) VALUES(".$last.",'".$_POST["body"]."')", SQLITE_BOTH, $sqliteerror);
}else if(isset($_GET["delete"])){
//Delete Post
$result2 = sqlite_query($sqlite, "DELETE FROM Bord WHERE id=".$_GET["remove_id"]."or parent=".$_GET["remove_id"], SQLITE_BOTH, $sqliteerror);
}
$result = sqlite_query($sqlite, "SELECT * FROM Bord", SQLITE_BOTH, $sqliteerror);
?>
<p style="font-weight:bold;color:#ff0000;"><?php echo $sqliteerror;?></p>
<?php
$tmp=array();
if($result){
for($i=0;$i < sqlite_num_rows($result) ;$i++){
$rows = sqlite_fetch_array($result, SQLITE_ASSOC);
if($rows){
if(is_null($rows["parent"])){
$tmp[][]=$rows;
}else{
for($l=0;$l<count($tmp);$l++){
for($m=0;$m<count($tmp[$l]);$m++){
if($tmp[$l][$m]["id"]==$rows["parent"]){
$tmp[$l][]=$rows;
}
}
}
}
}
}
if(count($tmp)>0){
for($j=0;$j < count($tmp) ;$j++){
if(isset($tmp[$j])){
for($k=0;$k<count($tmp[$j]);$k++){
if(isset($tmp[$j][$k])){
if($k==0){
print "<ui>";
}
print "<p>";
print "<li>";
print $tmp[$j][$k]["id"].":".$tmp[$j][$k]["body"];
if(!is_null($tmp[$j][$k]["parent"])){
print "parent_id : ".$tmp[$j][$k]["parent"];
}
print "</li>";
?>
<form action="?add=1" method="post">
<input type="text" name="body" />
<input type="hidden" name="add_id" value="<?php echo $tmp[$j][$k]['id'];?>" />
<input type="submit" value="reply" />
</form>
<form action="" method="get">
<input type="hidden" name="delete" value="1" />
<input type="hidden" name="remove_id" value="<?php echo $tmp[$j][$k]['id'];?>" />
<input type="submit" value="delete" />
</form>
</p>
<?php
if($k==count($tmp[$j])){
print "</ul>";
}
}
}
}
}
}
}
sqlite_close($sqlite);
?>
</ul>
投稿フォーム
<form action="?reply=1" method="POST">
<input type="text" name="body" />
<input type="submit" value="add" />
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment