!','#',$row['name']);
if($imgonly) { $imgonly=1; } else { $imgonly=0; }
$row['sub'] = mysqli_escape_string($row['sub']);
$row['com'] = mysqli_escape_string($row['com']);
$row['filename'] = mysqli_escape_string($row['filename']);
mysqli_board_call($con, "INSERT INTO ".SQLLOGDEL." (imgonly,postno,board,name,sub,com,img,filename,admin) values('$imgonly','$resno','".SQLLOG."','$adname','{$row['sub']}','{$row['com']}','$adfsize','{$row['filename']}','$auser')");
}
if($row['resto']==0 && $children && !$imgonly) // select thread and children
$result=mysqli_board_call($con, "select no,resto,tim,ext from ".SQLLOG." where no=$resno or resto=$resno");
else // just select the post
$result=mysqli_board_call($con, "select no,resto,tim,ext from ".SQLLOG." where no=$resno");
while($delrow=mysqli_fetch_array($result)) {
// delete
$delfile = $path.$delrow['tim'].$delrow['ext']; //path to delete
$delthumb = THUMB_DIR.$delrow['tim'].'s.jpg';
if(is_file($delfile)) unlink($delfile); // delete image
if(is_file($delthumb)) unlink($delthumb); // delete thumb
if(OEKAKI_BOARD == 1 && is_file($path.$delrow['tim'].'.pch'))
unlink($path.$delrow['tim'].'.pch'); // delete oe animation
if(!$imgonly){ // delete thread page & log_cache row
if($delrow['resto'])
unset( $log[$delrow['resto']]['children'][$delrow['no']] );
unset( $log[$delrow['no']] );
$log['THREADS'] = array_diff($log['THREADS'], array($delrow['no'])); // remove from THREADS
//mysqli_board_call($con, "DELETE FROM reports WHERE no=".$delrow['no']); // clear reports
if(USE_GZIP == 1) {
@unlink(RES_DIR.$delrow['no'].PHP_EXT);
@unlink(RES_DIR.$delrow['no'].PHP_EXT.'.gz');
}
else {
@unlink(RES_DIR.$delrow['no'].PHP_EXT);
}
}
}
//delete from DB
if($row['resto']==0 && $children && !$imgonly) // delete thread and children
$result=mysqli_board_call($con, "delete from ".SQLLOG." where no=$resno or resto=$resno");
elseif(!$imgonly) // just delete the post
$result=mysqli_board_call($con, "delete from ".SQLLOG." where no=$resno");
return $row['resto']; // so the caller can know what pages need to be rebuilt
}
// purge old posts
// should be called whenever a new post is added.
function trim_db() {
global $con;
if(JANITOR_BOARD == 1) return;
log_cache();
$maxposts = LOG_MAX;
// max threads = max pages times threads-per-page
$maxthreads = (PAGE_MAX > 0)?(PAGE_MAX * PAGE_DEF):0;
// New max-page method
if($maxthreads) {
$exp_order = 'no';
if(EXPIRE_NEGLECTED == 1) $exp_order = 'root';
//logtime('trim_db before select threads');
$result = mysqli_board_call($con, "SELECT no FROM ".SQLLOG." WHERE sticky=0 AND resto=0 ORDER BY $exp_order ASC");
//logtime('trim_db after select threads');
$threadcount = mysqli_num_rows($result);
while($row=mysqli_fetch_array($result) and $threadcount >= $maxthreads) {
delete_post($row['no'], 'trim', 0, 1); // imgonly=0, automatic=1, children=1
$threadcount--;
}
mysqli_free_result($result);
// Original max-posts method (note: cleans orphaned posts later than parent posts)
} else {
// make list of stickies
$stickies = array(); // keys are stickied thread numbers
$result = mysqli_board_call($con, "SELECT no from ".SQLLOG." where sticky=1 and resto=0");
while($row=mysqli_fetch_array($result)) {
$stickies[ $row['no'] ] = 1;
}
$result = mysqli_board_call($con, "SELECT no,resto,sticky FROM ".SQLLOG." ORDER BY no ASC");
$postcount = mysqli_num_rows($result);
while($row=mysqli_fetch_array($result) and $postcount >= $maxposts) {
// don't delete if this is a sticky thread
if($row['sticky'] == 1) continue;
// don't delete if this is a REPLY to a sticky
if($row['resto'] != 0 && $stickies[ $row['resto'] ] == 1) continue;
delete_post($row['no'], 'trim', 0, 1, 0); // imgonly=0, automatic=1, children=0
$postcount--;
}
mysqli_free_result($result);
}
}
//resno - thread page to update (no of thread OP)
//rebuild - don't rebuild page indexes
function updatelog($resno=0,$rebuild=0){
global $log,$path;
global $con;
set_time_limit(60);
if($_SERVER['REQUEST_METHOD']=='GET' && !valid()) die(''); // anti ddos
log_cache();
$imgdir = ((USE_SRC_CGI==1)?str_replace('src','src.cgi',IMG_DIR2):IMG_DIR2);
if(defined('INTERSTITIAL_LINK')) $imgdir .= INTERSTITIAL_LINK;
$thumbdir = THUMB_DIR2;
$imgurl = DATA_SERVER;
$resno=(int)$resno;
if($resno){
if(!isset($log[$resno])) {
updatelog(0,$rebuild); // the post didn't exist, just rebuild the indexes
return;
}
else if($log[$resno]['resto']) {
updatelog($log[$resno]['resto'],$rebuild); // $resno is a reply, try rebuilding the parent
return;
}
}
if($resno){
$treeline = array($resno); //logtime("Formatting thread page");
if(!$treeline=mysqli_board_call($con, "select * from ".SQLLOG." where root>0 and no=".$resno." order by root desc")){echo S_SQLFAIL;}
}else{
$treeline = $log['THREADS']; //logtime("Formatting index page");
if(!$treeline=mysqli_board_call($con, "select * from ".SQLLOG." where root>0 order by root desc")){echo S_SQLFAIL;}
}
//$counttree=count($treeline);
$counttree=mysqli_num_rows($treeline);
if(!$counttree){
$logfilename=PHP_SELF2;
$dat='';
head($dat,$resno);
form($dat,$resno);
print_page($logfilename, $dat);
}
if(UPDATE_THROTTLING >= 1) {
$update_start = time();
touch("updatelog.stamp", $update_start);
$low_priority = false;
clearstatcache();
if(@filemtime(PHP_SELF) > $update_start-UPDATE_THROTTLING) {
$low_priority = true;
//touch($update_start . ".lowprio");
}
else {
touch(PHP_SELF,$update_start);
}
// $mt = @filemtime(PHP_SELF);
// touch($update_start . ".$mt.highprio");
}
// if we're using CACHE_TTL method
if(CACHE_TTL >= 1) {
if($resno) {
$logfilename = RES_DIR.$resno.PHP_EXT;
}
else {
$logfilename = PHP_SELF2;
}
//if(USE_GZIP == 1) $logfilename .= '.html';
// if the file has been made and it's younger than CACHE_TTL seconds ago
clearstatcache();
if(file_exists($logfilename) && filemtime($logfilename) > (time() - CACHE_TTL)) {
// save the post to be rebuilt later
rebuildqueue_add($resno);
// if it's a thread, try again on the indexes
if($resno && !$rebuild) updatelog();
// and we don't do any more rebuilding on this request
return true;
}
else {
// we're gonna update it now, so take it out of the queue
rebuildqueue_remove($resno);
// and make sure nobody else starts trying to update it because it's too old
touch($logfilename);
}
}
for($page=0;$page<$counttree;$page+=PAGE_DEF){
$dat='';
head($dat,$resno);
form($dat,$resno);
if(!$resno){
$st = $page;
}
$dat.='