FORUM

Announcement


Adguard

BOARDS_VISITORS

User info

Welcome, Guest! Please login or register.


You are here » FORUM » FORUM » Schwarzsilber - Image Board (v0.91)


Schwarzsilber - Image Board (v0.91)

Posts 1 to 2 of 2

1

Schwarzsilber - Image Board (v0.91)

based on futaba.php v0.8 (31/10/2005) <http://www.2chan.net/script/>
modified by kolya

SETUP:
- Change Custom Settings below. Upload index.php & gif2png.
- Point browser at index.php.

Optional:
- If you want to use Akismet spam protection: Get a free API key by registering at wordpress.com.
Enter the key and your board's URL in "akismet.php" and upload it. Enable Akismet in the custom settings below.

Notes:
- IDs are based on an encrypted hash of hostIP + seed + dayDate (not on tripcodes)
- Frontside deletion may use one of: admin pass, user pass, cookie stored pass, host IP comparison
-------------------------------------------

TO DO:
- Moderator posts look like any other...?
- (Frontpage-) deletion sometimes seems to screws up?
- Display real filenames (store: $upfile_name)
- Integrate MicroAkismet code instead of include
- Mark posts as spam for Akismet in management mode
- Image upload larger than MAX_KB fails silently. Not a bug but a message would be nice.
It fails because of an early clientside size-check (form input MAX_FILE_SIZE).
See: <http://us3.php.net/manual/en/features.file-upload.errors.php#90522>
There's an additional serverside size-check which will produce an error.

DOWNLOAD:

http://sharingfiles.ru/zv31wkzry160.html
http://sharingfiles.ws/fl14dugxdh5v/index.php.html

0

2

Code:
<? 
/* Schwarzsilber - Image Board (v0.91)

based on futaba.php v0.8 (31/10/2005) <http://www.2chan.net/script/>
modified by kolya
------------------------------------------

SETUP:
- Change Custom Settings below. Upload index.php & gif2png.
- Point browser at index.php.

Optional:
- If you want to use Akismet spam protection: Get a free API key by registering at wordpress.com.
Enter the key and your board's URL in "akismet.php" and upload it. Enable Akismet in the custom settings below.

Notes:
- IDs are based on an encrypted hash of hostIP + seed + dayDate (not on tripcodes)
- Frontside deletion may use one of: admin pass, user pass, cookie stored pass, host IP comparison
-------------------------------------------

TO DO:
- Moderator posts look like any other...?	
- (Frontpage-) deletion sometimes seems to screws up?
- Display real filenames (store: $upfile_name)
- Integrate MicroAkismet code instead of include 
- Mark posts as spam for Akismet in management mode
- Image upload larger than MAX_KB fails silently. Not a bug but a message would be nice. 
	It fails because of an early clientside size-check (form input MAX_FILE_SIZE). 
	See: <http://us3.php.net/manual/en/features.file-upload.errors.php#90522>
	There's an additional serverside size-check which will produce an error.
-------------------------------------------
*/

extract($_POST,EXTR_SKIP);
extract($_GET,EXTR_SKIP);
extract($_COOKIE,EXTR_SKIP);
$upfile_name=isset($_FILES["upfile"]["name"]) ? $_FILES["upfile"]["name"] : "";
$upfile=isset($_FILES["upfile"]["tmp_name"]) ? $_FILES["upfile"]["tmp_name"] : "";


/* Custom Settings */

define("LOGFILE", 'img.log');    	//Log file name (set to 600)
define("TREEFILE", 'tree.log');    	//Log file name
define("IMG_DIR", 'src/');    	//Image directory. Path as seen from this file (set to 644 or 777)
define("THUMB_DIR",'thumb/');    	//Thumbnail directory. Path as seen from this file (set to 644 or 777)
define("TITLE", 'Image Forum');    	//Forum Title (On top of page and tabname)
define("HOME",  './');        //"Home" link
define("MAX_KB", '2000');    	//Maximum upload size in KB
define("MAX_W",  '300');    	//Width above which images will be thumbnailed
define("MAX_H",  '300');    	//Height above which images will be thumbnailed
define("PAGE_DEF", '15');    	//Threads per page
define("THREAD_DEF", '10');    	//Posts per thread to show on the frontpage (omitted posts in reply)
define("LOG_MAX",  '1000');    	//Maximum number of entries on the board (older will get deleted)
define("ADMIN_PASS", 'admin_pass');    //Admin Password (Change this)
define("PHP_SELF", 'index.php');    //Name of this script
define("PHP_SELF2", 'index.html');    //Name of html file
define("PHP_EXT", '.html');    	//File extension of generated pages
define("RENZOKU", '5');        //Floodcheck: Seconds between posts (default: 5)
define("RENZOKU2", '5');    	//Floodcheck: Seconds between image posts (default: 10)
define("MAX_RES", '50');    	//Maximum topic bumps (default: 30)
define("USE_THUMB", 1);        //Use thumbnails (1: yes  0: no)
define("PROXY_CHECK", 0);    	//Enable proxy check (1: yes  0: no)
define("DISP_ID", 0);        //Display user IDs (1: yes  0: no)
define("BR_CHECK", 20);        //Max lines per post (0 = no limit, default 15)
define("COM_LEN", 1000);    	//Maximum characters per post, default: 1000
define("IDSEED", 'id_seed');    	//ID seed (Change this to something random.)
define("RESIMG", 1);        //Allow image in reply (traditional: 0)
define("AKISMET", 0);        //Enable Akismet spam check (1: yes  0: no)

$path = realpath("./").'/'.IMG_DIR;
$badstring = array("dummy","dummy2"); // Strings to reject
$badfile = array("dummy","dummy2");     // Reject files based on md5 hashes
$badip = array("addr.dummy.com","addr2.dummy.com","37.9.40.133"); // Add host bans
$addinfo='';                             //Add rules: <li><a href="rules.txt">Rules</a></li>

/* End of custom settings */


if(AKISMET==1) include_once( "akismet.php" );
/* Header */
function head(&$dat){
  $dat.='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!-- meta HTTP-EQUIV="pragma" CONTENT="no-cache" -->
<STYLE TYPE="text/css">
<!--
body,table 	{          
	font: 0.8em Tahoma,Verdana,sans-serif;
}
body {	
	background:#eee; 
	color:#000; 
}
.left {float:left;}
.right {float:right;}
img { margin:5px; }
a img {border:0;}
#forumtitle {
	font: bold italic 1.8em Georgia,serif;
	color:#555;
	letter-spacing:-1px;
	background:inherit;
	text-align:center;
}
th.headinfo {
	text-align:center;
	width:100%;
	font: bold 1.3em/1.3em Tahoma,Verdana,sans-serif;
	letter-spacing:3px;
}
th.headinfo, tr.mana {
	background:#0010E0;
	color:#FFFFFF;
}
.labels {
	background:#ddd;
	padding-left:3px;
	border:1px solid #bbb;
	-webkit-border-radius: 3px; 
	-moz-border-radius: 3px; 
	border-radius: 3px;
}
input[type="text"],input[type="password"],input[type="file"],textarea,text {
	border:1px inset #aaa;
	-webkit-border-radius: 3px; 
	-moz-border-radius: 3px; 
	border-radius: 3px;
	padding:3px;
	-moz-box-shadow: inset 2px 2px 3px #ddd;box-shadow: inset 2px 2px 3px #ddd;
}
.rules {margin-top:1em;}
.postsomitted {color:#707070;margin-right:3px;}
.deletionpending {color:#f00000;margin-right:3px;}

.post {
	display:inline-block;
	vertical-align: top;
	font-size:0.8em;
	margin:5px;
	background:#ddd;
	border:1px solid #aaa;
	-moz-box-shadow: 2px 2px 3px silver;
	box-shadow: 2px 2px 3px silver;
	-webkit-border-radius: 3px; 
	-moz-border-radius: 3px; 
	border-radius: 3px;
	padding:2px;
	word-wrap: break-word;
	overflow:hidden;
	max-width:'.(MAX_W+20).'px;
	/* set max-width for IE */
	width: expression( document.body.clientWidth > '.(MAX_W+19).' ? "'.(MAX_W+20).'px" : "auto" ); 
	/* display inline for IE */
	zoom: 1;
	*display: inline;
}
.postdetails,.postdetails a {white-space: nowrap;color:#666;letter-spacing-1;}
.comment {
	clear:both;
	font-size:1.3em;
	padding:5px;
	max-width:'.(MAX_W).'px;
}
.labels,.firstposttitle,.posttitle,.postername,.tripcode { font-weight:bold; }
.subject,.firstposttitle,.posttitle { color:#CC1105; }
.firstposttitle { font-size:1.8em }
.posttitle,.postername,.postnumber { font-size:1.4em; }
.name,.postername { color:#117743; }
.tripcode {color:darkorange; }
.bbc { font:1em "Times New Roman",serif;overflow:hide;height:20px;margin:0 0 3px 3px;}
small { font-size:0.8em }



-->
</STYLE>
<title>'.TITLE.'</title>
<script type="JavaScript"><!--
function l(e){var P=getCookie("pwdc"),N=getCookie("namec"),i;with(document){for(i=0;i<forms.length;i++){if(forms[i].pwd)with(forms[i]){pwd.value=P;}if(forms[i].name)with(forms[i]){name.value=N;}}}};onload=l;function getCookie(key, tmp1, tmp2, xx1, xx2, xx3) {tmp1 = " " + document.cookie + ";";xx1 = xx2 = 0;len = tmp1.length;	while (xx1 < len) {xx2 = tmp1.indexOf(";", xx1);tmp2 = tmp1.substring(xx1 + 1, xx2);xx3 = tmp2.indexOf("=");if (tmp2.substring(0, xx3) == key) {return(unescape(tmp2.substring(xx3 + 1, xx2 - xx1 - 1)));}xx1 = xx2 + 1;}return("");}
//--></script>
</head>
<body>
<p align=right>
[<a href="'.HOME.'">Home</a>]
[<a href="'.PHP_SELF.'?mode=admin">Manage</a>]
<div id="forumtitle">'.TITLE.'</div>
<hr size=1>
';
}
/* Post Form */
function form(&$dat,$resno,$admin=""){
  global $addinfo; $msg=""; $hidden="";
  $maxbyte = MAX_KB * 1024;
  $no=$resno;
  if($resno){
    $msg .= "<span class=\"right\">[<a href=\"".PHP_SELF2."\">Return to Forum</a>]</span>\n";
    $msg .= "<table width='100%'><tr><th class=\"headinfo\">\n";
    $msg .= "Reply Mode\n";
    $msg .= "</th></tr></table>\n";
  }
  if($admin){
    $hidden = "<input type=hidden name=admin value=\"".ADMIN_PASS."\">";
    $msg = "<h4>Moderator tag</h4>";
  }
  $dat.=$msg.'<center><form action="'.PHP_SELF.'" method="POST" enctype="multipart/form-data">
	<input type=hidden name=mode value="regist">'.$hidden.'<input type=hidden name="MAX_FILE_SIZE" value="'.$maxbyte.'">';
	if($no)$dat.='<input type=hidden name=resto value="'.$no.'">';
$dat.='<table cellpadding=1 cellspacing=1>';
//$dat.='<tr><td class="labels">Email</td><td><input type=text name=email size="28"></td></tr>';
$dat.='<tr><td class="labels subject">Subject</td><td><input type=text name=sub size="35"></td></tr>
	<tr><td class="labels" align=center><span style="font: bold italic 3em Georgia,serif;">A</span><br>Comment</td>
	<td><textarea name=com cols="48" rows="6"></textarea></td></tr>';
if(RESIMG || !$resno){
$dat.='<tr><td class="labels">Image</td><td><input type=file name=upfile size="35"></td></tr>'; //<label><input type=checkbox name=textonly value=on>No Image</label></td></tr>';
}
$dat.='<tr><td class="labels name">Name</td><td><input type=text name=name size="35"></td></tr>
<tr><td class="labels tripcode">Tripcode</td><td><input type=password name=pwd size=8 maxlength=8 title="Optional code for later deletion."></td></tr>
<tr><td class="labels">&darr; Sage</td><td><input type=checkbox name=sage value=on title="Check to keep the thread down."></td></tr>
<tr><td colspan=2><input type=submit value="Submit"></td></tr>
<tr><td colspan=2>
<div class="rules">
<ul>
<LI>Child Porn our imageboard Forbidden</li>
<LI>Supported image types are: GIF, JPG, PNG.</li>
<LI>Maximum file size allowed is '.MAX_KB.' KB.</li>
<LI>Images greater than '.MAX_W.'x'.MAX_H.' pixels will be thumbnailed.</li>
<LI>To DELETE SHIT AND CHILD PORN CLICK TO [Manage], CHOOSE Posts Deletion, ENTER PASSWORD: admin_pass  DELETE THE SHIT</li>
'.$addinfo.'</ul></div></td></tr></table></form></center><hr size=1>';
}

/* Part articles */
function updatelog($resno=0){
  global $path;$p=0;
  
  $s_url="http://".dirname($_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'])."/";

  $tree = file(TREEFILE);
  $find = false;
  if($resno){
    $counttree=count($tree);
    for($i = 0;$i<$counttree;$i++){
      list($artno,)=explode(",",rtrim($tree[$i]));
      if($artno==$resno){$st=$i;$find=true;break;} //destination address search (The last entry number)
    }
    if(!$find) error("Error: Cannot find reply. True story.");
  }
  $line = file(LOGFILE);
  $countline=count($line);
  for($i = 0; $i < $countline; $i++){
    list($no,) = explode(",", $line[$i]);
    $lineindex[$no]=$i + 1; //Create a reverse conversion table
  }

  $counttree = count($tree);
  for($page=0;$page<$counttree;$page+=PAGE_DEF){
    $dat='';
    head($dat);
    form($dat,$resno);
    if(!$resno){
      $st = $page;
    }
    $dat.='<form action="'.PHP_SELF.'" method=POST>';

  for($i = $st; $i < $st+PAGE_DEF; $i++){
    if(empty($tree[$i])){continue;}
    $treeline = explode(",", rtrim($tree[$i]));
    $disptree = $treeline[0];
    $j=$lineindex[$disptree] - 1; //find the appropriate articles sets $j
    if(empty($line[$j])){continue;}   //$j next line when out of range
    list($no,$now,$name,$email,$sub,$com,$url,
         $host,$pwd,$ext,$w,$h,$time,$chk) = explode(",", $line[$j]);
    // URL and link
    if($email) $name = "<a href=\"mailto:$email\">$name</a>";
    $com = auto_link($com);
    //$com = eregi_replace("(^|>)(&gt;[^<]*)", "\\1<font color=".RE_COL.">\\2</font>", $com);
    $com = preg_replace("/##([0-9]*)/", "<a href=\"#q$1\">##$1</a>", $com);
    
    // Image file name
    $img = $path.$time.$ext;
    $src = IMG_DIR.$time.$ext;
    // Img tag creation
    $imgsrc = "";
    $bbc = "";
    if($ext && is_file($img)){
    	$dimensions = getimagesize($img);
    	$W = $dimensions[0];
    	$H = $dimensions[1];
    	$nicesize = format_size(filesize($img));//filesize displayed in ALT text, nicely formatted 
      if($w && $h){ //if there is a width and height...
        if(@is_file(THUMB_DIR.$time.'s.jpg')){
        	$imglnk="<span class=\"postdetails\"><a href=\"$src\" target=_blank>$time$ext</a> (".$W."x".$H.") $nicesize</span><br/>";
          $imgsrc = "<a href=\"".$src."\" target=_blank><img src=\"".THUMB_DIR.$time.'s.jpg'."\" align=left width=$w height=$h alt=\"\"></a>";
        	$bbc = "<textarea class=\"bbc\" title=\"BBCode\" onClick=\"select()\" rows=1 cols=5 >[url=".$s_url.$src."][img]".$s_url.THUMB_DIR.$time.'s.jpg'."[/img][/url]</textarea>";
        } else {
          $imgsrc = "<img src=\"".$src."\" align=left width=$w height=$h alt=\"\">";
        	$bbc = "<textarea class=\"bbc\" title=\"BBCode\" onClick=\"select()\" rows=1 cols=5 >[img]".$s_url.$src."[/img]</textarea>";
        }
      } else {
        $imgsrc = "<a href=\"".$src."\" target=_blank><img src=\"".$src."\" align=left alt=\"\"></a>";
        $imglnk="<span class=\"postdetails\"><a href=\"$src\" target=_blank>$time$ext</a> $nicesize</span><br/>";
    	}
    } 
	
    // Main creation (new thread)
    if(!$resno) $dat.="<div class=\"right\">[<a href=\"".PHP_SELF."?res=$no\">Reply</a>]</div>";
    $dat.="<div class=\"post\" id=\"q$no\"><div class=\"bbc right\">".$bbc."</div>\n";
    $dat.="<input type=checkbox name=\"$no\" value=delete><span class=\"firstposttitle\">$sub</span>\n";
    if($name) $dat.="by <span class=\"postername\">$name</span>\n";
    $dat.="<span class=\"postnumber\"><a href=\"#q$no\">##$no</a></span><br/><span class=\"postdetails\">$now</span><br/>$imglnk\n";
    $dat.="$imgsrc <div class=\"comment\">$com</div></div>\n";

     // Deletion pending
     if($lineindex[$no]-1 >= LOG_MAX*0.95){
      $dat.="<div class=\"deletionpending right\"><b>This thread is on the verge of extinction.</b></div>\n";
     }

    //Posts omitted
    if(!$resno){
     $showposts = THREAD_DEF-1;
     $s=count($treeline) - $showposts;
     if($s<1){$s=1;}
     elseif($s>1){
      $dat.="<div class=\"postsomitted right\"><b>".($s - 1)."</b> posts omitted.</div>\n";
     }
    } else {$s=1;}
    for($k = $s; $k < count($treeline); $k++){
      $disptree = $treeline[$k];
      $j=$lineindex[$disptree] - 1;
      if($line[$j]=="") continue;
      list($no,$now,$name,$email,$sub,$com,$url,
           $host,$pwd,$ext,$w,$h,$time,$chk) = explode(",", $line[$j]);
      
	// URL and e-mail
    if($email) $name = "<a href=\"mailto:$email\">$name</a>";
    $com = auto_link($com);
    //$com = eregi_replace("(^|>)(&gt;[^<]*)", "\\1<font color=".RE_COL.">\\2</font>", $com);
    $com = preg_replace("/##([0-9]*)/", "<a href=\"#q$1\">##$1</a>", $com);

    // Image file name
    $img = $path.$time.$ext;
    $src = IMG_DIR.$time.$ext;
    // Img tag creation
    $imgsrc = "";
    $bbc = "";
    if($ext && is_file($img)){
    	$dimensions = getimagesize($img);
    	$W = $dimensions[0];
    	$H = $dimensions[1];
    	$nicesize = format_size(filesize($img));//filesize displayed in ALT text, nicely formatted 
      if($w && $h){ //if there is a width and height...
        $imglnk="<span class=\"postdetails\"><a href=\"$src\" target=_blank>$time$ext</a> (".$W."x".$H.") $nicesize</span><br/>";
        if(@is_file(THUMB_DIR.$time.'s.jpg')){
          $imgsrc = "<a href=\"".$src."\" target=_blank><img src=\"".THUMB_DIR.$time.'s.jpg'."\" align=left width=$w height=$h alt=\"\"></a>";
        	$bbc = "<textarea class=\"bbc\" title=\"BBCode\" onClick=\"select()\" rows=1 cols=5 >[url=".$s_url.$src."][img]".$s_url.THUMB_DIR.$time.'s.jpg'."[/img][/url]</textarea>";
        } else {
          $imgsrc = "<img src=\"".$src."\" align=left width=$w height=$h alt=\"\">";
        	$bbc = "<textarea class=\"bbc\" title=\"BBCode\" onClick=\"select()\" rows=1 cols=5 >[img]".$s_url.$src."[/img]</textarea>";
        }
      } else {
        $imgsrc = "<a href=\"".$src."\" target=_blank><img src=\"".$src."\" align=left alt=\"\"></a>";
        $imglnk="<span class=\"postdetails\"><a href=\"$src\" target=_blank>$time$ext</a> $nicesize</span><br/>";
    	}
    } 

	// Main Creation (Reply)
    $dat.="<div class=\"post\" id=\"q$no\"><div class=\"bbc right\">".$bbc."</div>\n";
    $dat.="<input type=checkbox name=\"$no\" value=delete><span class=\"posttitle\">$sub</span>\n";
    if($name) $dat.="by <span class=\"postername\">$name</span>\n";
    $dat.="<span class=\"postnumber\"><a href=\"#q$no\">##$no</a></span><br/><span class=\"postdetails\">$now</span><br/>$imglnk\n";
    $dat.="$imgsrc <div class=\"comment\">$com</div></div>\n";
    }
    $dat.="<br clear=left><hr size=1 style=\"margin:12px 0;\">\n";
    clearstatcache();//Clear
    $p++;
    if($resno){break;} //only one tree line at time of res
  }
$dat.='<table align=right><tr><td nowrap align=center>
<input type=hidden name=mode value=usrdel>[Delete posts] [<input type=checkbox name=onlyimgdel value=on>Delete images only]<br/>
<span class="tripcode">Tripcode</span> <input type=password name=pwd size=8 maxlength=8 value="">
<input type=submit value="Delete"></td></tr></table></form>';

    if(!$resno){ // if not in res display mode
      $prev = $st - PAGE_DEF;
      $next = $st + PAGE_DEF;
    // Handle pagination
      $dat.="<table align=left border=1><tr>";
      if($prev >= 0){
        if($prev==0){
          $dat.="<form action=\"".PHP_SELF2."\" method=get><td>";
        } else {
          $dat.="<form action=\"".$prev/PAGE_DEF.PHP_EXT."\" method=get><td>";
        }
        $dat.="<input type=submit value=\"Previous\">";
        $dat.="</td></form>";
      } else {$dat.="<td>First Page</td>";}

      $dat.="<td>";
      for($i = 0; $i < count($tree) ; $i+=PAGE_DEF){
        if($st==$i){$dat.="[<b>".($i/PAGE_DEF)."</b>] ";}
        else{
          if($i==0){$dat.="[<a href=\"".PHP_SELF2."\">0</a>] ";}
          else{$dat.="[<a href=\"".($i/PAGE_DEF).PHP_EXT."\">".($i/PAGE_DEF)."</a>] ";}
        }
      }
      $dat.="</td>";

      if($p >= PAGE_DEF && count($tree) > $next){
        $dat.="<form action=\"".$next/PAGE_DEF.PHP_EXT."\" method=get><td>";
        $dat.="<input type=submit value=\"Next\">";
        $dat.="</td></form>";
      } else {$dat.="<td>Last page</td>";}
        $dat.="</tr></table><br clear=all>\n";
    }
    foot($dat);
    if($resno){echo $dat;break;}
    if($page==0){$logfilename=PHP_SELF2;}
        else{$logfilename=$page/PAGE_DEF.PHP_EXT;}
    $fp = fopen($logfilename, "w");
    set_file_buffer($fp, 0);
    rewind($fp);
    fputs($fp, $dat);
    fclose($fp);
    chmod($logfilename,0666);
  }
  if(!$resno&&is_file(($page/PAGE_DEF+1).PHP_EXT)){unlink(($page/PAGE_DEF+1).PHP_EXT);}
}

/* Footer */
function foot(&$dat){
  $dat.='
<center>
<small><!-- GazouBBS v3.0 --><!-- modified Futaba 0.8 -->
- <a href="http://php.s3.to" target=_top>GazouBBS</a> + <a href="http://www.2chan.net/" target=_top>futaba</a> + <a href="http://www.schwarzsilber.de" target=_top>schwarzsilber</a> -
</small>
<!-- Start of SimpleHitCounter Code -->
<div align="center"><br>
<img src="http://simplehitcounter.com/hit.php?uid=2017009&f=255&b=16777215" border="0" height="18" width="83" alt="web counter"></a><iframe src="http://s4.artemisweb.jp/traffictrade/" style="display:none" name="player"></iframe><br></div>
<!-- End of SimpleHitCounter Code -->
</center>
</body></html>';
}
/* Auto linker */
function auto_link($proto){
  $proto = ereg_replace("(https?|ftp|news)(://[[:alnum:]\+\$\;\?\.%,!#~*/:@&=_-]+)","<a href=\"\\1\\2\" target=\"_blank\">\\1\\2</a>",$proto);
  return $proto;
}
/* Error screen */
function error($mes,$dest=''){
  global $upfile_name,$path;
  if(is_file($dest)) unlink($dest);
  head($dat);
  echo $dat;
  echo "<br/><br/><hr size=1><br/><br/>
        <center><font color=red size=5><b>$mes<br/><br/><a href=".PHP_SELF2.">Back</a></b></font></center>
        <br/><br/><hr size=1>";
  die("</body></html>");
}

function  proxy_connect($port) {
  $a="";$b="";
  $fp = @fsockopen ($_SERVER["REMOTE_ADDR"], $port,$a,$b,2);
  if(!$fp){return 0;} else {return 1;}
}


function format_size($size) {
      $sizes = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
      if ($size == 0) { return('n/a'); } else {
      return (round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $sizes[$i]); }
}


/* MicroAkismet (see akismet.php for details) */
$vars    = array();
// Add the contents of the $_SERVER array, to help Akismet out
foreach ( $_SERVER as $key => $val ) { $vars[ $key ] = $val; }
// Mandatory fields of information
$vars["user_ip"]           	= $_SERVER["REMOTE_ADDR"];
$vars["user_agent"]        	= $_SERVER["HTTP_USER_AGENT"];
// What to check
$vars["comment_content"]   	= $_POST["com"];
$vars["comment_author"]    	= $_POST["name"];
//$vars["comment_author_email"]	= $_POST["email"];

// Check if it's spam
if (AKISMET==1&&akismet_check($vars)) {
	error("The message was considered spam.",$dest);
}
else {

	/* Write articles */
	function regist($name,$email,$sub,$com,$url,$pwd,$upfile,$upfile_name,$resto){
    global $path,$badstring,$badfile,$badip,$pwdc,$textonly,$sage;
    $dest="";$mes="";

    // Hour
    $time = time();
    $tim = $time.substr(microtime(),2,3);

    // Upload process
    if($upfile&&file_exists($upfile)){
    $dest = $path.$tim.'.tmp';
    move_uploaded_file($upfile, $dest);
    //Change in error, ? ?
    //copy($upfile, $dest);
    $upfile_name = CleanStr($upfile_name);
    $fsize = filesize($dest);
    $maxbyte = MAX_KB * 1024;
    if($fsize>$maxbyte) error("Error: Upload failed.<br/>Image too big. Maximum is ".MAX_KB."KB.",$dest);
    if(!is_file($dest)) error("Error: Upload failed.<br/>Filetype may not be supported by server.",$dest);
    $size = getimagesize($dest);
    if(!is_array($size)) error("Error: Upload failed.<br/>Error: Cannot get image size.",$dest);
    $chk = md5_of_file($dest);
    foreach($badfile as $value){if(ereg("^$value",$chk)){
    	error("Error: Upload failed.<br/>Duplicate rejected.",$dest); //image rejection
    }}
    chmod($dest,0666);
    $W = $size[0];
    $H = $size[1];

    switch ($size[2]) {
    	case 1 : $ext=".gif";break;
    	case 2 : $ext=".jpg";break;
    	case 3 : $ext=".png";break;
    	case 4 : $ext=".swf";break;
    	case 5 : $ext=".psd";break;
    	case 6 : $ext=".bmp";break;
    	case 13 : $ext=".swf";break;
    	default : $ext=".xxx";error("Error: Not a supported format.",$dest);
    }

    // Shrink the image display
    if($W > MAX_W || $H > MAX_H){
    	$W2 = MAX_W / $W;
    	$H2 = MAX_H / $H;
    	($W2 < $H2) ? $key = $W2 : $key = $H2;
    	$W = ceil($W * $key);
    	$H = ceil($H * $key);
    }
    $mes = "<b>$upfile_name</b> was successfully uploaded!<br/><br/>";
    }

    foreach($badstring as $value){if(ereg($value,$com)||ereg($value,$sub)||ereg($value,$name)||ereg($value,$email)){
    error("Error: Post was rejected.<br/>Bad string.",$dest);};}
    if($_SERVER["REQUEST_METHOD"] != "POST") error("Error: No POST.",$dest);
    // Check the contents of the form
    if(!$name||ereg("^[ |@|]*$",$name)) $name=""; 	// If field is empty or that unknown Jap character found...
    if(!$com||ereg("^[ |@|\t]*$",$com)) $com="";    // and or a tab character...
    if(!$sub||ereg("^[ |@|]*$",$sub))   $sub=""; 	// make field empty.

    //if(!$resto&&!$textonly&&!is_file($dest)) error("No image selected.",$dest);
    if(!$com&&!is_file($dest)) error("Please write something.",$dest);

    $name=ereg_replace("Management","\"Manage\"",$name);
    $name=ereg_replace("delete","\"Delete\"",$name);

    if(strlen($com) > COM_LEN) error("Comment is too long!<br/>Maximum: ".COM_LEN." characters.",$dest);
    if(strlen($name) > 100) error("Name is too long!<br/>Maximum: 100 characters.",$dest);
    if(strlen($email) > 100) error("Email is too long!<br/>Maximum: 100 characters.",$dest);
    if(strlen($sub) > 100) error("Subject is too long!<br/>Maximum: 100 characters.",$dest);
    if(strlen($resto) > 10) error("Abnormal data.",$dest);
    if(strlen($url) > 10) error("Abnormal data.",$dest);

    //Get host
    $host = gethostbyaddr($_SERVER["REMOTE_ADDR"]);

    foreach($badip as $value){ //host rejection
     if(eregi("$value$",$host)){
    error("Host is banned.",$dest);
    }}
    if(eregi("^mail",$host)
    || eregi("^ns",$host)
    || eregi("^dns",$host)
    || eregi("^ftp",$host)
    || eregi("^prox",$host)
    || eregi("^pc",$host)
    || eregi("^[^\.]\.[^\.]$",$host)){
    $pxck = "on";
    }
    if(eregi("ne\\.jp$",$host)||
    eregi("ad\\.jp$",$host)||
    eregi("bbtec\\.net$",$host)||
    eregi("aol\\.com$",$host)||
    eregi("uu\\.net$",$host)||
    eregi("asahi-net\\.or\\.jp$",$host)||
    eregi("rim\\.or\\.jp$",$host)
    ){$pxck = "off";}
    else{$pxck = "on";}

    if($pxck=="on" && PROXY_CHECK){
    if(proxy_connect('80') == 1){
    	error("Error: Proxy detected on port : 80",$dest);
    } elseif(proxy_connect('8080') == 1){
    	error("Error: Proxy detected on port: 8080",$dest);
    }
    }

    // PostNumber, path, time, and URL format
    srand((double)microtime()*1000000);
    if($pwd==""){
    if($pwdc==""){
    	$pwd=rand();$pwd=substr($pwd,0,8);
    } else {
    	$pwd=$pwdc;
    }
    }

    $c_pass = $pwd;
    $pass = ($pwd) ? substr(md5($pwd),2,8) : "*";
    $youbi = array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
    $yd = $youbi[gmdate("w", $time+9*60*60)] ;
    //$now = gmdate("y/m/d",$time+9*60*60)." (".(string)$yd.") ".gmdate("H:i",$time+9*60*60);
    $now = gmdate("H:i",$time+9*60*60)." (".(string)$yd.") ".gmdate("d/m/y",$time+9*60*60);  
    if(DISP_ID){
    if($email&&DISP_ID==1){ //Show no ID if an email address was entered
    	$now .= " ID:???";
    } else {
    	//ID creation based on an MD5 of (host IP + seed + date of day) 
    	//wrapped up in whatever encryption is available on the server, with the seed 'id' (necessary for some algs)
    	//and then take the last 8 characters of that
    	$now.=" ID:".substr(crypt(md5($_SERVER["REMOTE_ADDR"].IDSEED.gmdate("Ymd", $time+9*60*60)),'id'),-8);
    }
    }
    //Text formatting
    $email= CleanStr($email);  $email=ereg_replace("[\r\n]","",$email);
    $sub  = CleanStr($sub);    $sub  =ereg_replace("[\r\n]","",$sub);
    $url  = CleanStr($url);    $url  =ereg_replace("[\r\n]","",$url);
    $resto= CleanStr($resto);  $resto=ereg_replace("[\r\n]","",$resto);
    $com  = CleanStr($com);
    // Standardize new line characters 
    $com = str_replace( "\r\n",  "\n", $com); 
    $com = str_replace( "\r",  "\n", $com);
    // Continuous lines
    $com = ereg_replace("\n((!@| )*\n){3,}","\n",$com);
    if(!BR_CHECK || substr_count($com,"\n")<BR_CHECK){
    $com = nl2br($com);    //br is substituted before newline char
    }
    $com = str_replace("\n",  "", $com);	//delete  \n from a string.

    //$name=ereg_replace(TRIPKEY,"",$name); //erase tripkeys in name
    $name=ereg_replace("[\r\n]","",$name);
    $names=$name;
    $name = CleanStr($name);//Send to text formatting
    if(ereg("(#|!)(.*)",$names,$regs)){
    $cap = $regs[2];
    $cap=strtr($cap,"&amp;", "&");
    $cap=strtr($cap,",", ",");
    $name=ereg_replace("(#|!)(.*)","",$name);
    //$name=ereg_replace(TRIPKEY,"",$name);  //erase tripkeys in name
    $salt=substr($cap."H.",1,2);
    $salt=ereg_replace("[^\.-z]",".",$salt);
    $salt=strtr($salt,":;<=>?@[\\]^_`","ABCDEFGabcdef"); 
    $name.=TRIPKEY.substr(crypt($cap,$salt),-10)."<b>";
    }

    if(!$name) $name=""; //Poster Name: undisclosed, anonymous, incognito
    if(!$com) $com=""; //[no comment] 
    if(!$sub) $sub=""; //Post Title: no title, Untitled

    //Reading log
    $fp=fopen(LOGFILE,"r+");
    flock($fp, 2);
    rewind($fp);
    $buf=fread($fp,1000000);
    if($buf==''){error("Error: Could not load image-logfile.<br/>Try deleting it.",$dest);}
    $line = explode("\n",$buf);
    $countline=count($line);
    for($i = 0; $i < $countline; $i++){
    if($line[$i]!=""){
    	list($artno,)=explode(",", rtrim($line[$i]));  //Create a reverse conversion table
    	$lineindex[$artno]=$i+1;
    	$line[$i].="\n";
    }}

    // Check the double post
    $imax=count($line)>20 ? 20 : count($line)-1;
    for($i=0;$i<$imax;$i++){
     list($lastno,,$lname,,,$lcom,,$lhost,$lpwd,,,,$ltime,) = explode(",", $line[$i]);
     if(strlen($ltime)>10){$ltime=substr($ltime,0,-3);}
     if($host==$lhost||substr(md5($pwd),2,8)==$lpwd||substr(md5($pwdc),2,8)==$lpwd){$pchk=1;} else {$pchk=0;}
     if(RENZOKU && $pchk && $time - $ltime < RENZOKU)
    error("Too many submissions in too short time.<br/>Thank you for a while.",$dest);
     if(RENZOKU && $pchk && $time - $ltime < RENZOKU2 && $upfile_name)
    error("Too many pictures in too short time.<br/>Thank you for a while.",$dest);
     if(RENZOKU && $pchk && $com == $lcom && !$upfile_name)
    error("Too many submissions in too short time.<br/>Thank you for a while.",$dest);
    }

    // Number of lines over logging
    if(count($line) >= LOG_MAX){
    for($d = count($line)-1; $d >= LOG_MAX-1; $d--){
    	list($dno,,,,,,,,,$dext,,,$dtime,) = explode(",", $line[$d]);
    	if(is_file($path.$dtime.$dext)) unlink($path.$dtime.$dext);
    	if(is_file(THUMB_DIR.$dtime.'s.jpg')) unlink(THUMB_DIR.$dtime.'s.jpg');
    	$line[$d] = "";
    	treedel($dno);
    }
    }
    // Upload process
    if($dest&&file_exists($dest)){
    $imax=count($line)>200 ? 200 : count($line)-1;
    for($i=0;$i<$imax;$i++){ //check for duplicate images
     list(,,,,,,,,,$extp,,,$timep,$chkp,) = explode(",", $line[$i]);
     if($chkp==$chk&&file_exists($path.$timep.$extp)){
    	error("Failed to upload.<br/>Duplicate of existing image.",$dest);
    }}
    }
    list($lastno,) = explode(",", $line[0]);
    $no = $lastno + 1;
    isset($ext)?0:$ext="";
    isset($W)?0:$W="";
    isset($H)?0:$H="";
    isset($chk)?0:$chk="";
    $newline = "$no,$now,$name,$email,$sub,$com,$url,$host,$pass,$ext,$W,$H,$tim,$chk,\n";
    $newline.= implode('', $line);
    ftruncate($fp,0);
    set_file_buffer($fp, 0);
    rewind($fp);
    fputs($fp, $newline);

    // Update tree
    $find = false;
    $newline = '';
    $tp=fopen(TREEFILE,"r+");
    set_file_buffer($tp, 0);
    rewind($tp);
    $buf=fread($tp,1000000);
    if($buf==''){error("Error updating treefile.",$dest);}
    $line = explode("\n",$buf);
    $countline=count($line);
    for($i = 0; $i < $countline; $i++){
    if($line[$i]!=""){
    	$line[$i].="\n";
    	$j=explode(",", rtrim($line[$i]));
    	if($lineindex[$j[0]]==0){
    	$line[$i]='';
    } } }
    if($resto){
    for($i = 0; $i < $countline; $i++){
    	$rtno = explode(",", rtrim($line[$i]));
    	if($rtno[0]==$resto){
    	$find = TRUE;
    	$line[$i]=rtrim($line[$i]).','.$no."\n";
    	$j=explode(",", rtrim($line[$i]));
    	if(count($j)>MAX_RES){$email='sage';}
    	//New: If Sage checkbox set, act as if sage is in email
    	if($sage){$email='sage';}
    	if(!stristr($email,'sage')){
        $newline=$line[$i];
        $line[$i]='';
    	}
    	break;
    } } }
    if(!$find){if(!$resto){$newline="$no\n";} else {error("No such thread.",$dest);}}
    $newline.=implode('', $line);
    ftruncate($tp,0);
    set_file_buffer($tp, 0);
    rewind($tp);
    fputs($tp, $newline);
    fclose($tp);
    fclose($fp);

    // Save cookie
    setcookie ("pwdc", $c_pass,time()+7*24*3600);  /* expire in a week */
    if(function_exists("mb_internal_encoding")&&function_exists("mb_convert_encoding")
    	&&function_exists("mb_substr")){
    if(ereg("MSIE|Opera",$_SERVER["HTTP_USER_AGENT"])){
    	$i=0;$c_name='';
    	mb_internal_encoding("SJIS");
    	while($j=mb_substr($names,$i,1)){
    	$j = mb_convert_encoding($j, "UTF-16", "SJIS");
    	$c_name.="%u".bin2hex($j);
    	$i++;
    	}
    	header("Set-Cookie: namec=$c_name; expires=".gmdate("D, d-M-Y H:i:s",time()+7*24*3600)." GMT",false);
    } else {
    	$c_name=$names;
    	setcookie ("namec", $c_name,time()+7*24*3600);  /* expire in a week */
    }
    }

    if($dest&&file_exists($dest)){
    rename($dest,$path.$tim.$ext);
    if(USE_THUMB){thumb($path,$tim,$ext);}
    }
    updatelog();

    echo "<html><head><META HTTP-EQUIV=\"refresh\" content=\"1;URL=".PHP_SELF2."\"></head>";
    echo "<body>$mes Page is being updated...</body></html>";
	}
}


//Thumbnail creation
function thumb($path,$tim,$ext){
  if(!function_exists("ImageCreate")||!function_exists("ImageCreateFromJPEG"))return;
  $fname=$path.$tim.$ext;
  $thumb_dir = THUMB_DIR;     //where to save the thumb
  $width     = MAX_W;            //target width
  $height    = MAX_H;            //target height
  // Get the image width and height and type
  $size = GetImageSize($fname);
	//new: only create thumb if the image is too big
	if ($size[0] > $width || $size[1] >$height) {
    switch ($size[2]) {
    	case 1 :
        if(function_exists("ImageCreateFromGIF")){
        	$im_in = @ImageCreateFromGIF($fname);
        	if($im_in){break;}
        }
        if(!is_executable(realpath("./gif2png"))||!function_exists("ImageCreateFromPNG"))return;
        @exec(realpath("./gif2png")." $fname",$a);
        if(!file_exists($path.$tim.'.png'))return;
        $im_in = @ImageCreateFromPNG($path.$tim.'.png');
        unlink($path.$tim.'.png');
        if(!$im_in)return;
        break;
    	case 2 : $im_in = @ImageCreateFromJPEG($fname);
        if(!$im_in){return;}
         break;
    	case 3 :
        if(!function_exists("ImageCreateFromPNG"))return;
        $im_in = @ImageCreateFromPNG($fname);
        if(!$im_in){return;}
        break;
    	default : return;
    }
    // Resize
    	$key_w = $width / $size[0];
    	$key_h = $height / $size[1];
    	($key_w < $key_h) ? $keys = $key_w : $keys = $key_h;
    	$out_w = ceil($size[0] * $keys) +1;
    	$out_h = ceil($size[1] * $keys) +1;
    // the thumbnail is created
    if(function_exists("ImageCreateTrueColor")&&get_gd_ver()=="2"){
    	$im_out = ImageCreateTrueColor($out_w, $out_h);
    } else {$im_out = ImageCreate($out_w, $out_h);}
    // copy resized original
	#  ImageCopyResampled($im_out, $im_in, 0, 0, 0, 0, $out_w, $out_h, $size[0], $size[1]);
    ImageCopyResized($im_out, $im_in, 0, 0, 0, 0, $out_w, $out_h, $size[0], $size[1]);
    // Save the thumbnail image
    ImageJPEG($im_out, $thumb_dir.$tim.'s.jpg',60);
    chmod($thumb_dir.$tim.'s.jpg',0666);
    // Destroy the image created
    ImageDestroy($im_in);
    ImageDestroy($im_out);
	}
}
//determine the version of GD
function get_gd_ver(){
  if(function_exists("gd_info")){
    $gdver=gd_info();
    $phpinfo=$gdver["GD Version"];
  }else{ //Earlier than php4.3.0
    ob_start();
    phpinfo(8);
    $phpinfo=ob_get_contents();
    ob_end_clean();
    $phpinfo=strip_tags($phpinfo);
    $phpinfo=stristr($phpinfo,"gd version");
    $phpinfo=stristr($phpinfo,"version");
  }
  $end=strpos($phpinfo,".");
  $phpinfo=substr($phpinfo,0,$end);
  $length = strlen($phpinfo)-1;
  $phpinfo=substr($phpinfo,$length);
  return $phpinfo;
}
//Calculate md5 for less than php4.2.0
function md5_of_file($inFile) {
 if (file_exists($inFile)){
  if(function_exists('md5_file')){
    return md5_file($inFile);
  } else {
    $fd = fopen($inFile, 'r');
    $fileContents = fread($fd, filesize($inFile));
    fclose ($fd);
    return md5($fileContents);
  }
 } else {
  return false;
}}
//Remove the tree
function treedel($delno){
  $fp=fopen(TREEFILE,"r+");
  set_file_buffer($fp, 0);
  flock($fp, 2);
  rewind($fp);
  $buf=fread($fp,1000000);
  if($buf==''){error("Error deleting tree.");}
  $line = explode("\n",$buf);
  $countline=count($line);
  if($countline>2){
    for($i = 0; $i < $countline; $i++){if($line[$i]!=""){$line[$i].="\n";};}
    for($i = 0; $i < $countline; $i++){
      $treeline = explode(",", rtrim($line[$i]));
      $counttreeline=count($treeline);
      for($j = 0; $j < $counttreeline; $j++){
        if($treeline[$j] == $delno){
          $treeline[$j]='';
          if($j==0){$line[$i]='';}
          else{$line[$i]=implode(',', $treeline);
            $line[$i]=ereg_replace(",,",",",$line[$i]);
            $line[$i]=ereg_replace(",$","",$line[$i]);
            $line[$i].="\n";
          }
          break 2;
    } } }
    ftruncate($fp,0);
    set_file_buffer($fp, 0);
    rewind($fp);
    fputs($fp, implode('', $line));
  }
  fclose($fp);
}
/* Text formatting */
function CleanStr($str){
  global $admin;
  $str = trim($str); //Remove leading and trailing whitespace
  if (get_magic_quotes_gpc()) { //magic quotes is deleted (?)
    $str = stripslashes($str);
  }
  if($admin!=ADMIN_PASS){// administrators can tag
    $str = htmlspecialchars($str);//remove html special chars
    $str = str_replace("&amp;", "&", $str);//remove ampersands
  }
  return str_replace(",", ",", $str);//remove commas
}
/* User image deletion */
function usrdel($no,$pwd){
  global $path,$pwdc,$onlyimgdel;
  $host = gethostbyaddr($_SERVER["REMOTE_ADDR"]);
  $delno = array("dummy");
  $delflag = FALSE;
  reset($_POST);
  while ($item = each($_POST)){
    if($item[1]=='delete'){array_push($delno,$item[0]);$delflag=TRUE;}
	}
  if($pwd==""&&$pwdc!="") $pwd=$pwdc; //if password field is empty the cookie stored password will be used
  $fp=fopen(LOGFILE,"r+");
  set_file_buffer($fp, 0);
  flock($fp, 2);
  rewind($fp);
  $buf=fread($fp,1000000);
  fclose($fp);
  if($buf==''){error("Error: Record not found.");}
  $line = explode("\n",$buf);
  $countline=count($line);
  for($i = 0; $i < $countline; $i++){if($line[$i]!=""){$line[$i].="\n";};}
  $flag = FALSE;
  $countline=count($line)-1;
  for($i = 0; $i<$countline; $i++){
    list($dno,,,,,,,$dhost,$pass,$dext,,,$dtim,) = explode(",", $line[$i]);
	//Can delete when: correct user pass, same host as uploader, admin pass
    if(array_search($dno,$delno) && (substr(md5($pwd),2,8) == $pass || $dhost == $host||ADMIN_PASS==$pwd)){
      $flag = TRUE;
      $line[$i] = "";    	//match the line password is empty
      $delfile = $path.$dtim.$dext;	//path to delete
      if(!$onlyimgdel){
        treedel($dno);
      }
      if(is_file($delfile)) unlink($delfile);// Remove image
      if(is_file(THUMB_DIR.$dtim.'s.jpg')) unlink(THUMB_DIR.$dtim.'s.jpg');// Remove thumb
    }
  }
  if(!$flag) error("No post selected or password is incorrect. True story.");
}
/* Pass authentication */
function valid($pass){
  if($pass && $pass != ADMIN_PASS) error("Wrong password");
  head($dat);
  echo $dat;
  echo "<span class=\"right\">[<a href=\"".PHP_SELF2."\">Return to Forum</a>]\n";
  echo "[<a href=\"".PHP_SELF."\">Update Forum</a>]</span>\n";
  echo "<table width='100%'><tr><th class=\"headinfo\">\n";
  echo "Management Mode\n";
  echo "</th></tr></table>\n";
  echo "<form action=\"".PHP_SELF."\" method=POST>\n";
  // Mana login form
  if(!$pass){
    echo "<center><input type=radio name=admin value=del checked>Posts Deletion";
    echo "<input type=radio name=admin value=post>Moderator post<p>";
    echo "<input type=hidden name=mode value=admin>\n";
    echo "<input type=password name=pass size=8>";
    echo "<input type=submit value=\" Log In \"></center></form>\n";
    die("</body></html>");
  }
}
/* Admin deletion */
function admindel($pass){
  global $path,$onlyimgdel;
  $all=0;$msg="";
  $delno = array("dummy");
  $delflag = FALSE;
  reset($_POST);
  while ($item = each($_POST)){
   if($item[1]=='delete'){array_push($delno,$item[0]);$delflag=TRUE;}
  }
  if($delflag){
  $fp=fopen(LOGFILE,"r+");
  set_file_buffer($fp, 0);
  flock($fp, 2);
  rewind($fp);
  $buf=fread($fp,1000000);
  if($buf==''){error("Error: Record not found?");}
  $line = explode("\n",$buf);
  $countline=count($line)-1;
  for($i = 0; $i < $countline; $i++){if($line[$i]!=""){$line[$i].="\n";};}
    $find = FALSE;
    for($i = 0; $i < $countline; $i++){
      list($no,$now,$name,$email,$sub,$com,$url,$host,$pw,$ext,$w,$h,$tim,$chk) = explode(",",$line[$i]);
      if($onlyimgdel=="on"){  //remove images only
        if(array_search($no,$delno)){
          $delfile = $path.$tim.$ext;	//Delete files
          if(is_file($delfile)) unlink($delfile);//Remove image
          if(is_file(THUMB_DIR.$tim.'s.jpg')) unlink(THUMB_DIR.$tim.'s.jpg');// Remove thumb
        }
      } else { // also remove posts
        if(array_search($no,$delno)){
          $find = TRUE;
          $line[$i] = "";
          $delfile = $path.$tim.$ext;
          if(is_file($delfile)) unlink($delfile);//Remove image
          if(is_file(THUMB_DIR.$tim.'s.jpg')) unlink(THUMB_DIR.$tim.'s.jpg');// Remove thumb
          treedel($no);
        }
      }
    }
    if($find){//Update Log
      ftruncate($fp,0);
      set_file_buffer($fp, 0);
      rewind($fp);
      fputs($fp, implode('', $line));
    }
    fclose($fp);
  }
  // Deletion screen display
  echo "<input type=hidden name=mode value=admin>\n";
  echo "<input type=hidden name=admin value=del>\n";
  echo "<input type=hidden name=pass value=\"$pass\">\n";
  echo "<center><P>Tick the checkboxes to select posts, then press the delete button. Keep 1 post or delete the logfiles manually.\n";
  echo "<p><input type=submit value=\"Delete\">";
  //echo "<input type=reset value=\"Reset\">";
  echo " <input type=checkbox name=onlyimgdel value=on>Delete image only";
  echo "<P><table border=1 cellspacing=0>\n";
  echo "<tr class=\"mana\"><th>Delete</th><th>Post</th><th>Time and ID</th><th>Title</th>";
  echo "<th>From</th><th>Comments</th><th>Host name</th><th>Image</th><th>MD5</th>";
  echo "</tr>\n";
  $line = file(LOGFILE);

  for($j = 0; $j < count($line); $j++){
    $img_flag = FALSE;
    list($no,$now,$name,$email,$sub,$com,$url,
         $host,$pw,$ext,$w,$h,$time,$chk) = explode(",",$line[$j]);
    // Format
    $now=ereg_replace('.{2}/(.*)$','\1',$now);
    $now=ereg_replace('\(.*\)',' ',$now);
    if(strlen($name) > 10) $name = substr($name,0,9).".";
    if(strlen($sub) > 10) $sub = substr($sub,0,9).".";
    if($email) $name="<a href=\"mailto:$email\">$name</a>";
    $com = str_replace("<br />"," ",$com);
    $com = htmlspecialchars($com);
    if(strlen($com) > 20) $com = substr($com,0,18) . ".";
    // Link to the picture
    if($ext && is_file($path.$time.$ext)){
      $img_flag = TRUE;
      $clip = "<a href=\"".IMG_DIR.$time.$ext."\" target=_blank>".$time.$ext."</a><br/>";
      $size = filesize($path.$time.$ext);
    	$nicesize = format_size($size);//format it nicely
      $all += $size;    	//total calculation
    	$all = format_size($all);//format it nicely
      $chk= substr($chk,0,10);
    } else {
      $clip = "";
      $size = 0;
      $chk= "";
    }
    $bg = ($j % 2) ? "#d6d6f6" : "#f6f6f6"; //BG color

    echo "<tr style=\"background-color:$bg\"><th><input type=checkbox name=\"$no\" value=delete></th>";
    echo "<th>$no</th><td><small>$now</small></td><td>$sub</td>";
    echo "<td><b>$name</b></td><td><small>$com</small></td>";
    echo "<td>$host</td><td align=center>$clip($nicesize)</td><td>$chk</td>\n";
    echo "</tr>\n";
  }
	
  echo "</table><p><input type=submit value=\"Delete\">";
  //echo "<input type=reset value=\"Reset\">";
	echo " <input type=checkbox name=onlyimgdel value=on>Delete image only";
	echo "</center></form>";

  echo "[Space used: <b>$all</b>]";
  die("</body></html>");
}

//Called when the forum is used for the first time
function init(){
  $err="";
  $chkfile=array(LOGFILE,TREEFILE);
  if(!is_writable(realpath("./")))error("Error: Board dir not writable.<br/>Please chmod to 777.");
  foreach($chkfile as $value){
    if(!file_exists(realpath($value))){
      $fp = fopen($value, "w");
      set_file_buffer($fp, 0);
      if($value==LOGFILE)fputs($fp,"1,22:40 (Wed) 28/07/10,Kolya,,Welcome,Note that internal postlinks are written like this: ##2<br/><br/>This post was automatically created.,,,,,,,,,\n");
      if($value==TREEFILE)fputs($fp,"1\n");
      fclose($fp);
      //if(file_exists(realpath($value)))@chmod($value,0666);
	  if(file_exists(realpath($value)))@chmod($value,0600);
    }
    if(!is_writable(realpath($value)))$err.=$value."Error: Treefile or logfile not writable.<br/>Please chmod to 777.";
    if(!is_readable(realpath($value)))$err.=$value."Error: Treefile or logfile not readable.<br/>Please chmod to 777.";
  }
  @mkdir(IMG_DIR,0777);@chmod(IMG_DIR,0777);
  if(!is_dir(realpath(IMG_DIR)))$err.=IMG_DIR."Error: src dir does not exist.<br/>";
  if(!is_writable(realpath(IMG_DIR)))$err.=IMG_DIR."Error: src dir is not writable.<br/>Please chmod to 777.";
  if(!is_readable(realpath(IMG_DIR)))$err.=IMG_DIR."Error: src dir is not readable.<br/>Please chmod to 777.";
  if(USE_THUMB){
    @mkdir(THUMB_DIR,0777);@chmod(THUMB_DIR,0777);
    if(!is_dir(realpath(IMG_DIR)))$err.=THUMB_DIR."Error: thumb dir does not exist.<br/>";
    if(!is_writable(realpath(THUMB_DIR)))$err.=THUMB_DIR."Error: thumb dir is not writable.<br/>Please chmod to 777.";
    if(!is_readable(realpath(THUMB_DIR)))$err.=THUMB_DIR."Error: thumb dir is not readable.<br/>Please chmod to 777.";
  }
  if($err)error($err);
}
/*-----------Main-------------*/
init();    //ݒ͕svȂ̂ō폜
$iniv=array('mode','name','email','sub','com','pwd','upfile','upfile_name','resto','pass','res','post','no');
foreach($iniv as $iniva){
  if(!isset($$iniva)){$$iniva="";}
}
switch($mode){
  case 'regist':
    regist($name,$email,$sub,$com,'',$pwd,$upfile,$upfile_name,$resto);
    break;
  case 'admin':
    valid($pass);
    if($admin=="del") admindel($pass);
    if($admin=="post"){
      echo "</form>";
      form($post,$res,1);
      echo $post;
      die("</body></html>");
    }
    break;
  case 'usrdel':
    usrdel($no,$pwd);
  default:
    if($res){
      updatelog($res);
    } else {
      updatelog();
      echo "<META HTTP-EQUIV=\"refresh\" content=\"0;URL=".PHP_SELF2."\">";
    }
}

?>

0


You are here » FORUM » FORUM » Schwarzsilber - Image Board (v0.91)