Add new directory structure. Tags will contain current and past releases, and stable will contain any bug fixes to the current stable release so users won't have to get the potentially broken trunk build to fix a screwup in stable.

Trunk updated to 0.9

git-svn-id: http://kusabax.cultnet.net/svn/repo/stable@176 73d99b7e-4f53-4972-b7b7-2ecd3c4d89ee
This commit is contained in:
Sazpaimon committed 2009-05-27 06:37:50 +00:00
commit 88bacfad9c
316 files changed
+79806

No files matched your search

+135
View File
@@ -0,0 +1,135 @@
<?php
/*
* This file is part of kusaba.
*
* kusaba is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* kusaba is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* kusaba; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* Bans Class
*
* Assorted banning-related functions placed into class format
*
* @package kusaba
*/
class Bans {
/* Perform a check for a ban record for a specified IP address */
function BanCheck($ip, $board = '', $force_display = false) {
global $tc_db;
if (!isset($_COOKIE['tc_previousip'])) {
$_COOKIE['tc_previousip'] = '';
}
$bans = Array();
$results = $tc_db->GetAll("SELECT * FROM `".KU_DBPREFIX."banlist` WHERE ((`type` = '0' AND ( `ipmd5` = '" . md5($ip) . "' OR `ipmd5` = '". md5($_COOKIE['tc_previousip']) . "' )) OR `type` = '1') AND (`expired` = 0)" );
if (count($results)>0) {
foreach($results AS $line) {
if(($line['type'] == 1 && strpos($ip, md5_decrypt($line['ip'], KU_RANDOMSEED)) === 0) || $line['type'] == 0) {
if ($line['until'] != 0 && $line['until'] < time()){
$tc_db->Execute("UPDATE `".KU_DBPREFIX."banlist` SET `expired` = 1 WHERE `id` = ".$line['id']);
$line['expired'] = 1;
$this->UpdateHtaccess();
}
if ($line['globalban']!=1) {
if ((in_array($board, explode('|', $line['boards'])) || $board == '')) {
$line['appealin'] = substr(timeDiff($line['appealat'], true, 2), 0, -1);
$bans[] = $line;
}
} else {
$line['appealin'] = substr(timeDiff($line['appealat'], true, 2), 0, -1);
$bans[] = $line;
}
}
}
}
if(count($bans) > 0){
$tc_db->Execute("END TRANSACTION");
echo $this->DisplayBannedMessage($bans);
die();
}
if ($force_display) {
/* Instructed to display a page whether banned or not, so we will inform them today is their rucky day */
echo '<title>'._gettext('YOU ARE NOT BANNED!').'</title><div align="center"><img src="'. KU_WEBFOLDER .'youarenotbanned.jpg"><br /><br />'._gettext('Unable to find record of your IP being banned.').'</div>';
} else {
return true;
}
}
/* Add a ip/ip range ban */
function BanUser($ip, $modname, $globalban, $duration, $boards, $reason, $staffnote, $appealat=0, $type=0, $allowread=1, $proxyban=false) {
global $tc_db;
if ($duration>0) {
$ban_globalban = '0';
} else {
$ban_globalban = '1';
}
if ($duration>0) {
$ban_until = time()+$duration;
} else {
$ban_until = '0';
}
$tc_db->Execute("INSERT INTO `".KU_DBPREFIX."banlist` ( `ip` , `ipmd5` , `type` , `allowread` , `globalban` , `boards` , `by` , `at` , `until` , `reason`, `staffnote`, `appealat` ) VALUES ( ".$tc_db->qstr(md5_encrypt($ip, KU_RANDOMSEED))." , '".md5($ip)."' , '".$type."' , '".$allowread."' , '".$globalban."' , '".$boards."' , '".$modname."' , '".time()."' , ".$tc_db->qstr($ban_until)." , ".$reason." , ".$staffnote.", ".$appealat." ) ");
if (!$proxyban && $type == 1) {
$this->UpdateHtaccess();
}
return true;
}
/* Return the page which will inform the user a quite unfortunate message */
function DisplayBannedMessage($bans, $board='') {
/* Set a cookie with the users current IP address in case they use a proxy to attempt to make another post */
setcookie('tc_previousip', $_SERVER['REMOTE_ADDR'], (time() + 604800), KU_BOARDSFOLDER);
require_once KU_ROOTDIR . 'lib/dwoo.php';
$dwoo_data->assign('bans', $bans);
return $dwoo->get(KU_TEMPLATEDIR .'/banned.tpl', $dwoo_data);
}
function UpdateHtaccess() {
global $tc_db;
$htaccess_contents = file_get_contents(KU_BOARDSDIR.'.htaccess');
$htaccess_contents_preserve = substr($htaccess_contents, 0, strpos($htaccess_contents, '## !KU_BANS:')+12)."\n";
$htaccess_contents_bans_iplist = '';
$results = $tc_db->GetAll("SELECT `ip` FROM `".KU_DBPREFIX."banlist` WHERE `allowread` = 0 AND `type` = 0 AND (`expired` = 1) ORDER BY `ip` ASC");
if (count($results) > 0) {
$htaccess_contents_bans_iplist .= 'RewriteCond %{REMOTE_ADDR} (';
foreach($results AS $line) {
$htaccess_contents_bans_iplist .= str_replace('.', '\\.', md5_decrypt($line['ip'], KU_RANDOMSEED)) . '|';
}
$htaccess_contents_bans_iplist = substr($htaccess_contents_bans_iplist, 0, -1);
$htaccess_contents_bans_iplist .= ')$' . "\n";
}
if ($htaccess_contents_bans_iplist!='') {
$htaccess_contents_bans_start = "<IfModule mod_rewrite.c>\nRewriteEngine On\n";
$htaccess_contents_bans_end = "RewriteRule !^(banned.php|youarebanned.jpg|favicon.ico|css/site_futaba.css)$ " . KU_BOARDSFOLDER . "banned.php [L]\n</IfModule>";
} else {
$htaccess_contents_bans_start = '';
$htaccess_contents_bans_end = '';
}
$htaccess_contents_new = $htaccess_contents_preserve.$htaccess_contents_bans_start.$htaccess_contents_bans_iplist.$htaccess_contents_bans_end;
file_put_contents(KU_BOARDSDIR.'.htaccess', $htaccess_contents_new);
}
}
?>
+949
View File
@@ -0,0 +1,949 @@
<?php
/*
* This file is part of kusaba.
*
* kusaba is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* kusaba is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* kusaba; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* Board and Post classes
*
* @package kusaba
*/
/**
* Board class
*
* Contains all board configurations. This class handles all board page
* rendering, using the templates
*
* @package kusaba
*
* TODO: replace repetitive code blocks with functions.
*/
class Board {
/* Declare the public variables */
/**
* Array to hold the boards settings
*/
var $board = array();
/**
* Archive directory, set when archiving is enabled
*
* @var string Archive directory
*/
var $archive_dir;
/**
* Dwoo class
*
* @var class Dwoo
*/
var $dwoo;
/**
* Dwoo data class
*
* @var class Dwoo
*/
var $dwoo_data;
/**
* Load balancer class
*
* @var class Load balancer
*/
var $loadbalancer;
/**
* Initialization function for the Board class, which is called when a new
* instance of this class is created. Takes a board directory as an
* argument
*
* @param string $board Board name/directory
* @param boolean $extra grab additional data for page generation purposes. Only false if all that's needed is the board info.
* @return class
*/
function Board($board, $extra = true) {
global $tc_db, $CURRENTLOCALE;
// If the instance was created with the board argument present, get all of the board info and configuration values and save it inside of the class
if ($board!='') {
$query = "SELECT * FROM `".KU_DBPREFIX."boards` WHERE `name` = ".$tc_db->qstr($board)." LIMIT 1";
$results = $tc_db->GetAll($query);
foreach ($results[0] as $key=>$line) {
if (!is_numeric($key)) {
$this->board[$key] = $line;
}
}
// Type
$types = array('img', 'txt', 'oek', 'upl');
$this->board['text_readable'] = $types[$this->board['type']];
if ($extra) {
// Boardlist
$this->board['boardlist'] = $this->DisplayBoardList();
// Get the unique posts for this board
$this->board['uniqueposts'] = $tc_db->GetOne("SELECT COUNT(DISTINCT `ipmd5`) FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $this->board['id']. " AND `IS_DELETED` = 0");
if($this->board['type'] != 1) {
$this->board['filetypes_allowed'] = $tc_db->GetAll("SELECT ".KU_DBPREFIX."filetypes.filetype FROM ".KU_DBPREFIX."boards, ".KU_DBPREFIX."filetypes, ".KU_DBPREFIX."board_filetypes WHERE ".KU_DBPREFIX."boards.id = " . $this->board['id'] . " AND ".KU_DBPREFIX."board_filetypes.boardid = " . $this->board['id'] . " AND ".KU_DBPREFIX."board_filetypes.typeid = ".KU_DBPREFIX."filetypes.id ORDER BY ".KU_DBPREFIX."filetypes.filetype ASC;");
}
$this->board['loadbalanceurl_formatted'] = ($this->board['loadbalanceurl'] != '') ? substr($this->board['loadbalanceurl'], 0, strrpos($this->board['loadbalanceurl'], '/')) : '';
if ($this->board['loadbalanceurl'] != '' && $this->board['loadbalancepassword'] != '') {
require_once KU_ROOTDIR . 'inc/classes/loadbalancer.class.php';
$this->loadbalancer = new Load_Balancer;
$this->loadbalancer->url = $this->board['loadbalanceurl'];
$this->loadbalancer->password = $this->board['loadbalancepassword'];
}
if ($this->board['locale'] && $this->board['locale'] != KU_LOCALE) {
changeLocale($this->board['locale']);
}
}
}
}
function __destruct() {
changeLocale(KU_LOCALE);
}
/**
* Regenerate all board and thread pages
*/
function RegenerateAll() {
$this->RegeneratePages();
$this->RegenerateThreads();
}
/**
* Regenerate all pages
*/
function RegeneratePages() {
global $tc_db, $CURRENTLOCALE;
$this->InitializeDwoo();
$results = $tc_db->GetAll("SELECT `filetype` FROM `" . KU_DBPREFIX . "embeds`");
foreach ($results as $line) {
$this->board['filetypes'][] .= $line[0];
}
$this->dwoo_data->assign('filetypes', $this->board['filetypes']);
$maxpages = $this->board['maxpages'];
$numposts = $tc_db->GetAll("SELECT COUNT(*) FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $this->board['id'] . " AND `parentid` = 0 AND `IS_DELETED` = 0");
if ($this->board['type'] == 1) {
$postsperpage = KU_THREADSTXT;
} elseif ($this->board['type'] == 3) {
$postsperpage = 30;
} else {
$postsperpage = KU_THREADS;
}
$i = 0;
$liststooutput = 0;
$totalpages = calculatenumpages($this->board['type'], ($numposts[0][0]-1));
if ($totalpages == '-1') {
$totalpages = 0;
}
$this->dwoo_data->assign('numpages', $totalpages);
while ($i <= $totalpages) {
$newposts = Array();
$this->dwoo_data->assign('thispage', $i);
$threads = $tc_db->GetAll("SELECT * FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $this->board['id'] . " AND `parentid` = 0 AND `IS_DELETED` = 0 ORDER BY `stickied` DESC, `bumped` DESC LIMIT ". ($postsperpage)." OFFSET ". $postsperpage * $i);
$executiontime_start_page = microtime_float();
foreach ($threads as $thread) {
// If the thread is on the page set to mark, && hasn't been marked yet, mark it
if ($thread['deleted_timestamp'] == 0 && $this->board['markpage'] > 0 && $i >= $this->board['markpage']) {
$tc_db->Execute("UPDATE `".KU_DBPREFIX."posts` SET `deleted_timestamp` = '" . (time() + 7200) . "' WHERE `boardid` = " . $tc_db->qstr($this->board['id'])." AND `id` = '" . $thread['id'] . "'");
clearPostCache($thread['id'], $this->board['name']);
$this->RegenerateThreads($thread['id']);
$this->dwoo_data->assign('replythread', 0);
}
$replycount = Array();
if ($this->board['type'] == 1 || $this->board['type'] == 3 ) {
$replycount = $tc_db->GetAll("SELECT COUNT(`id`) FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $tc_db->qstr($this->board['id'])." AND `parentid` = " . $thread['id']);
} else {
if (KU_DBTYPE != 'sqlite')
$replycount = $tc_db->GetAll("SELECT COUNT(`id`) AS id , SUM( IF(file_md5!='',1,0) ) AS files FROM( SELECT id,file_md5 FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $this->board['id']." AND `parentid` = ".$thread['id']." AND `IS_DELETED` = 0 ORDER BY `timestamp` DESC LIMIT 100000000 OFFSET " . (($thread['stickied'] == 1) ? (KU_REPLIESSTICKY) : (KU_REPLIES)) . " ) AS replies");
else {
$replycount[0][] = $tc_db->GetOne("SELECT COUNT(`id`) FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $this->board['id']." AND `parentid` = ".$thread['id']." AND `IS_DELETED` = 0 OFFSET " . (($thread['stickied'] == 1) ? (KU_REPLIESSTICKY) : (KU_REPLIES)));
$replycount[0][] = $tc_db->GetOne("SELECT COUNT(`id`) FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $this->board['id']." AND `parentid` = ".$thread['id']." AND `file` != '' AND `IS_DELETED` = 0 OFFSET " . (($thread['stickied'] == 1) ? (KU_REPLIESSTICKY) : (KU_REPLIES)));
}
}
$thread['replies'] = $replycount[0][0];
$thread['images'] = (isset($replycount[0][1]) ? $replycount[0][1] : '');
$thread = $this->BuildPost($thread, true);
if ($this->board['type'] != 3) {
$posts = $tc_db->GetAll("SELECT * FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $this->board['id']." AND `parentid` = ".$thread['id']." " . (($this->board['type'] != 1) ? ("AND `IS_DELETED` = 0") : ("")) . " ORDER BY `id` DESC LIMIT ".(($thread['stickied'] == 1) ? (KU_REPLIESSTICKY) : (KU_REPLIES)));
foreach ($posts as $key=>$post) {
$posts[$key] = $this->BuildPost($post, true);
}
$posts = array_reverse($posts);
array_unshift($posts, $thread);
$newposts[] = $posts;
} else {
if (!$thread['tag']) $thread['tag'] = '*';
$newposts[] = $thread;
}
}
if ($this->board['type'] == 0 && !isset($embeds)) {
$embeds = $tc_db->GetAll("SELECT * FROM `" . KU_DBPREFIX . "embeds`");
$this->dwoo_data->assign('embeds', $embeds);
}
if (!isset($header)){
$header = $this->PageHeader();
$header = str_replace("<!sm_threadid>", 0, $header);
}
if (!isset($postbox)) {
$postbox = $this->Postbox();
$postbox = str_replace("<!sm_threadid>", 0, $postbox);
}
$this->dwoo_data->assign('posts', $newposts);
$this->dwoo_data->assign('file_path', getCLBoardPath($this->board['name'], $this->board['loadbalanceurl_formatted'], ''));
$content = $this->dwoo->get(KU_TEMPLATEDIR . '/' . $this->board['text_readable'] . '_board_page.tpl', $this->dwoo_data);
$footer = $this->Footer(false, (microtime_float() - $executiontime_start_page), (($this->board['type'] == 1) ? (true) : (false)));
$content = $header.$postbox.$content.$footer;
$content = str_replace("\t", '',$content);
$content = str_replace("&nbsp;\r\n", '&nbsp;',$content);
if ($i == 0) {
$page = KU_BOARDSDIR.$this->board['name'].'/'.KU_FIRSTPAGE;
$this->PrintPage($page, $content, $this->board['name']);
} else {
$page = KU_BOARDSDIR.$this->board['name'].'/'.$i.'.html';
$this->PrintPage($page, $content, $this->board['name']);
}
$i++;
}
// If text board, rebuild thread list html files
if ($this->board['type'] == 1) {
$numpostsleft = $tc_db->GetOne("SELECT COUNT(*) FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $this->board['id'] . " AND `IS_DELETED` = 0 AND `parentid` = 0");
$liststooutput = floor(($numpostsleft-1) / 40);
$this->dwoo_data->assign('numpages', $liststooutput+1);
$listpage = 0;
$currentpostwave = 0;
while ($numpostsleft>0) {
$this->dwoo_data->assign('thispage', $listpage+1);
$executiontime_start_list = microtime_float();
$page = $this->PageHeader(0, $currentpostwave, $liststooutput);
$this->Footer(false, (microtime_float()-$executiontime_start_list), true);
if ($listpage==0) {
$this->PrintPage(KU_BOARDSDIR.$this->board['name'].'/list.html', $page, $this->board['name']);
} else {
$this->PrintPage(KU_BOARDSDIR.$this->board['name'].'/list'.($listpage+1).'.html', $page, $this->board['name']);
}
$currentpostwave += 40;
$numpostsleft -= 40;
$listpage++;
}
}
// If the board has catalog mode enabled, build it
if ($this->board['enablecatalog'] == 1 && ($this->board['type'] == 0 || $this->board['type'] == 2)) {
$executiontime_start_catalog = microtime_float();
$catalog_head = $this->PageHeader().
'&#91;<a href="' . KU_BOARDSFOLDER . $this->board['name'] . '/">'._gettext('Return').'</a>&#93; <div class="catalogmode">'._gettext('Catalog Mode').'</div>' . "\n" .
'<table border="1" align="center">' . "\n" . '<tr>' . "\n";
$catalog_page = '';
$results = $tc_db->GetAll("SELECT `id` , `subject` , `file` , `file_type` FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $this->board['id'] . " AND `IS_DELETED` = 0 AND `parentid` = 0 ORDER BY `stickied` DESC, `bumped` DESC");
$numresults = count($results);
if ($numresults > 0) {
$celnum = 0;
$trbreak = 0;
$row = 1;
// Calculate the number of rows we will actually output
$maxrows = max(1, (($numresults - ($numresults % 12)) / 12));
foreach ($results as $line) {
$celnum++;
$trbreak++;
if ($trbreak == 13 && $celnum != $numresults) {
$catalog_page .= '</tr>' . "\n" . '<tr>' . "\n";
$row++;
$trbreak = 1;
}
if ($row <= $maxrows) {
$replies = $tc_db->GetOne("SELECT COUNT(*) FROM `".KU_DBPREFIX."posts` WHERE `boardid` = " . $this->board['id'] . " AND `IS_DELETED` = 0 AND `parentid` = " . $line['id']);
$catalog_page .= '<td valign="middle">' . "\n" .
'<a href="' . KU_BOARDSFOLDER . $this->board['name'] . '/res/' . $line['id'] . '.html"';
if ($line['subject'] != '') {
$catalog_page .= ' title="' . $line['subject'] . '"';
}
$catalog_page .= '>';
if ($line['file'] != '' && $line['file'] != 'removed') {
if ($line['file_type'] == 'jpg' || $line['file_type'] == 'png' || $line['file_type'] == 'gif') {
$file_path = getCLBoardPath($this->board['name'], $this->board['loadbalanceurl_formatted'], $this->archive_dir);
$catalog_page .= '<img src="' . $file_path . '/thumb/' . $line['file'] . 'c.' . $line['file_type'] . '" alt="' . $line['id'] . '" border="0" />';
} else {
$catalog_page .= _gettext('File');
}
} elseif ($line['file'] == 'removed') {
$catalog_page .= 'Rem.';
} else {
$catalog_page .= _gettext('None');
}
$catalog_page .= '</a><br />' . "\n" . '<small>' . $replies . '</small>' . "\n" . '</td>' . "\n";
}
}
} else {
$catalog_page .= '<td>' . "\n" .
_gettext('No threads.') . "\n" .
'</td>' . "\n";
}
$catalog_page .= '</tr>' . "\n" . '</table><br /><hr />' .
$this->Footer(false, (microtime_float()-$executiontime_start_catalog));
$this->PrintPage(KU_BOARDSDIR . $this->board['name'] . '/catalog.html', $catalog_head.$catalog_page, $this->board['name']);
}
// Delete old pages
$dir = KU_BOARDSDIR.$this->board['name'];
$files = glob ("$dir/*.html");
if (is_array($files)) {
foreach ($files as $htmlfile) {
if (preg_match("/[0-9+].html/", $htmlfile)) {
if (substr(basename($htmlfile), 0, strpos(basename($htmlfile), '.html'))>$totalpages) {
unlink($htmlfile);
}
}
if (preg_match("/list[0-9+].html/", $htmlfile)) {
if (substr(basename($htmlfile), 4, strpos(basename($htmlfile), '.html'))>($liststooutput+1)) {
unlink($htmlfile);
}
}
if (preg_match("/catalog.html/", $htmlfile)) {
if (!($this->board['enablecatalog'] == 1 && ($this->board['type'] == 0 || $this->board['type'] == 2))) {
unlink($htmlfile);
}
}
}
}
}
/**
* Regenerate each thread's corresponding html file, starting with the most recently bumped
*/
function RegenerateThreads($id = 0) {
global $tc_db, $CURRENTLOCALE;
require_once(KU_ROOTDIR."lib/dwoo.php");
if (!isset($this->dwoo)) { $this->dwoo = New Dwoo; $this->dwoo_data = new Dwoo_Data(); $this->InitializeDwoo(); }
$embeds = Array();
$numimages = 0;
if ($this->board['type'] != 1 && !$embeds) {
$embeds = $tc_db->GetAll("SELECT * FROM `" . KU_DBPREFIX . "embeds`");
$this->dwoo_data->assign('embeds', $embeds);
foreach ($embeds as $embed) {
$this->board['filetypes'][] .= $embed['filetype'];
}
$this->dwoo_data->assign('filetypes', $this->board['filetypes']);
}
if ($id == 0) {
// Build every thread
$header = $this->PageHeader(1);
if ($this->board['type'] != 2){
$postbox = $this->Postbox(1);
}
$threads = $tc_db->GetAll("SELECT * FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $this->board['id'] . " AND `parentid` = 0 AND `IS_DELETED` = 0 ORDER BY `id` DESC");
if (count($threads) > 0) {
foreach($threads as $thread) {
$numimages = 0;
$executiontime_start_thread = microtime_float();
$posts = $tc_db->GetAll("SELECT * FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $this->board['id'] . " AND (`id` = " . $thread['id'] . " OR `parentid` = " . $thread['id'] . ") " . (($this->board['type'] != 1) ? ("AND `IS_DELETED` = 0") : ("")) . " ORDER BY `id` ASC");
if ($this->board['type'] != 1 || ((isset($posts[0]['IS_DELETED']) && $posts[0]['IS_DELETED'] == 0) || (isset($posts[0]['is_deleted']) && $posts[0]['is_deleted'] == 0))) {
// There might be a chance that the post was deleted during another RegenerateThreads() session, if there are no posts, move on to the next thread.
if(count($posts) > 0){
foreach ($posts as $key=>$post) {
if (($post['file_type'] == 'jpg' || $post['file_type'] == 'gif' || $post['file_type'] == 'png') && $post['parentid'] != 0) {
$numimages++;
}
$posts[$key] = $this->BuildPost($post, false);
}
$header_replaced = str_replace("<!sm_threadid>", $thread['id'], $header);
$this->dwoo_data->assign('numimages', $numimages);
$this->dwoo_data->assign('replythread', $thread['id']);
$this->dwoo_data->assign('posts', $posts);
$this->dwoo_data->assign('file_path', getCLBoardPath($this->board['name'], $this->board['loadbalanceurl_formatted'], ''));
if ($this->board['type'] != 2){
$postbox_replaced = str_replace("<!sm_threadid>", $thread['id'], $postbox);
}
else {
$postbox_replaced = $this->Postbox($thread['id']);
}
$reply = $this->dwoo->get(KU_TEMPLATEDIR . '/' . $this->board['text_readable'] . '_reply_header.tpl', $this->dwoo_data);
$content = $this->dwoo->get(KU_TEMPLATEDIR . '/' . $this->board['text_readable'] . '_thread.tpl', $this->dwoo_data);
if (!isset($footer)) $footer = $this->Footer(false, (microtime_float() - $executiontime_start_thread), (($this->board['type'] == 1) ? (true) : (false)));
$content = $header_replaced.$reply.$postbox_replaced.$content.$footer;
$content = str_replace("\t", '',$content);
$content = str_replace("&nbsp;\r\n", '&nbsp;',$content);
$this->PrintPage(KU_BOARDSDIR . $this->board['name'] . $this->archive_dir . '/res/' . $thread['id'] . '.html', $content, $this->board['name']);
if (KU_FIRSTLAST) {
$replycount = (count($posts)-1);
if ($replycount > 50) {
$this->dwoo_data->assign('replycount', $replycount);
$this->dwoo_data->assign('modifier', "last50");
// Grab the last 50 replies
$posts50 = array_slice($posts, -50, 50);
// Add on the OP
array_unshift($posts50, $posts[0]);
$this->dwoo_data->assign('posts', $posts50);
$content = $this->dwoo->get(KU_TEMPLATEDIR . '/img_thread.tpl', $this->dwoo_data);
$content = $header_replaced.$reply.$postbox_replaced.$content.$footer;
$content = str_replace("\t", '',$content);
$content = str_replace("&nbsp;\r\n", '&nbsp;',$content);
unset($posts50);
$this->PrintPage(KU_BOARDSDIR . $this->board['name'] . $this->archive_dir . '/res/' . $thread['id'] . '+50.html', $content, $this->board['name']);
if ($replycount > 100) {
$this->dwoo_data->assign('modifier', "first100");
// Grab the first 100 posts
$posts100 = array_slice($posts, 0, 100);
$this->dwoo_data->assign('posts', $posts100);
$content = $this->dwoo->get(KU_TEMPLATEDIR . '/img_thread.tpl', $this->dwoo_data);
$content = $header_replaced.$reply.$postbox_replaced.$content.$footer;
$content = str_replace("\t", '',$content);
$content = str_replace("&nbsp;\r\n", '&nbsp;',$content);
unset($posts100);
$this->PrintPage(KU_BOARDSDIR . $this->board['name'] . $this->archive_dir . '/res/' . $thread['id'] . '-100.html', $content, $this->board['name']);
}
$this->dwoo_data->assign('modifier', "");
}
}
}
}
}
}
} else {
$executiontime_start_thread = microtime_float();
// Build only that thread
$thread = $tc_db->GetAll("SELECT * FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $this->board['id'] . " AND (`id` = " . $id . " OR `parentid` = " . $id . ") " . (($this->board['type'] != 1) ? ("AND `IS_DELETED` = 0") : ("")) . " ORDER BY `id` ASC");
if ($this->board['type'] != 1 || ((isset($thread[0]['IS_DELETED']) && $thread[0]['IS_DELETED'] == 0) || (isset($thread[0]['is_deleted']) && $thread[0]['is_deleted'] == 0))) {
foreach ($thread as $key=>$post) {
if (($post['file_type'] == 'jpg' || $post['file_type'] == 'gif' || $post['file_type'] == 'png') && $post['parentid'] != 0) {
$numimages++;
}
$thread[$key] = $this->BuildPost($post, false);
}
$header = $this->PageHeader($id);
$postbox = $this->Postbox($id);
$this->dwoo_data->assign('numimages', $numimages);
$header = str_replace("<!sm_threadid>", $id, $header);
$this->dwoo_data->assign('replythread', $id);
if ($this->board['type'] != 2){
$postbox = str_replace("<!sm_threadid>", $id, $postbox);
}
$this->dwoo_data->assign('threadid', $thread[0]['id']);
$this->dwoo_data->assign('posts', $thread);
$this->dwoo_data->assign('file_path', getCLBoardPath($this->board['name'], $this->board['loadbalanceurl_formatted'], ''));
$postbox = $this->dwoo->get(KU_TEMPLATEDIR . '/' . $this->board['text_readable'] . '_reply_header.tpl', $this->dwoo_data).$postbox;
$content = $this->dwoo->get(KU_TEMPLATEDIR . '/' . $this->board['text_readable'] . '_thread.tpl', $this->dwoo_data);
if (!isset($footer)) $footer = $this->Footer(false, (microtime_float() - $executiontime_start_thread), (($this->board['type'] == 1) ? (true) : (false)));
$content = $header.$postbox.$content.$footer;
$content = str_replace("\t", '',$content);
$content = str_replace("&nbsp;\r\n", '&nbsp;',$content);
$this->PrintPage(KU_BOARDSDIR . $this->board['name'] . $this->archive_dir . '/res/' . $id . '.html', $content, $this->board['name']);
if (KU_FIRSTLAST) {
$replycount = $tc_db->GetOne("SELECT COUNT(`id`) FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $this->board['id'] . " AND `parentid` = " . $id . " AND `IS_DELETED` = 0");
if ($replycount > 50) {
$this->dwoo_data->assign('replycount', $replycount);
$this->dwoo_data->assign('modifier', "last50");
// Grab the last 50 replies
$posts50 = array_slice($thread, -50, 50);
// Add the thread to the top of this, since it wont be included in the result
array_unshift($posts50, $thread[0]);
$this->dwoo_data->assign('posts', $posts50);
$content = $this->dwoo->get(KU_TEMPLATEDIR . '/img_thread.tpl', $this->dwoo_data);
$content = $header.$reply.$postbox.$content.$footer;
$content = str_replace("\t", '',$content);
$content = str_replace("&nbsp;\r\n", '&nbsp;',$content);
unset($posts50);
$this->PrintPage(KU_BOARDSDIR . $this->board['name'] . $this->archive_dir . '/res/' . $id . '+50.html', $content, $this->board['name']);
if ($replycount > 100) {
$this->dwoo_data->assign('modifier', "first100");
// Grab the first 100 posts
$posts100 = array_slice($thread, 0, 100);
$this->dwoo_data->assign('posts', $posts100);
$this->dwoo_data->assign('posts', $posts);
$content = $this->dwoo->get(KU_TEMPLATEDIR . '/img_thread.tpl', $this->dwoo_data);
$content = $header.$reply.$postbox.$content.$footer;
$content = str_replace("\t", '',$content);
$content = str_replace("&nbsp;\r\n", '&nbsp;',$content);
unset($posts100);
$this->PrintPage(KU_BOARDSDIR . $this->board['name'] . $this->archive_dir . '/res/' . $id . '-100.html', $content, $this->board['name']);
}
$this->dwoo_data->assign('modifier', "");
}
}
}
}
}
function BuildPost($post, $page) {
global $CURRENTLOCALE;
if ($this->board['type'] == 1 && ((isset($post['IS_DELETED']) && $post['IS_DELETED'] == 1) || (isset($post['is_deleted']) && $post['is_deleted'] == 1))) {
$post['name'] = '';
$post['email'] = '';
$post['tripcode'] = _gettext('Deleted');
$post['message'] = '<font color="gray">'._gettext('This post has been deleted.').'</font>';
}
$dateEmail = (empty($this->board['anonymous'])) ? $post['email'] : 0;
$post['message'] = stripslashes(formatLongMessage($post['message'], $this->board['name'], (($post['parentid'] == 0) ? ($post['id']) : ($post['parentid'])), $page));
$post['timestamp_formatted'] = formatDate($post['timestamp'], 'post', $CURRENTLOCALE, $dateEmail);
$post['reflink'] = formatReflink($this->board['name'], (($post['parentid'] == 0) ? ($post['id']) : ($post['parentid'])), $post['id'], $CURRENTLOCALE);
if (isset($this->board['filetypes']) && in_array($post['file_type'], $this->board['filetypes'])) {
$post['videobox'] = embeddedVideoBox($post);
}
if ($post['file_type'] == 'mp3' && $this->board['loadbalanceurl'] == '') {
//Grab the ID3 info. TODO: Make this work for load-balanced boards.
// include getID3() library
require_once(KU_ROOTDIR . 'lib/getid3/getid3.php');
// Initialize getID3 engine
$getID3 = new getID3;
$post['id3'] = $getID3->analyze(KU_BOARDSDIR.$this->board['name'].'/src/'.$post['file'].'.mp3');
getid3_lib::CopyTagsToComments($post['id3']);
}
if ($post['file_type']!='jpg'&&$post['file_type']!='gif'&&$post['file_type']!='png'&&$post['file_type']!=''&&!in_array($post['file_type'], $this->board['filetypes'])) {
if(!isset($filetype_info[$post['file_type']])) $filetype_info[$post['file_type']] = getfiletypeinfo($post['file_type']);
$post['nonstandard_file'] = KU_WEBPATH . '/inc/filetypes/' . $filetype_info[$post['file_type']][0];
if($post['thumb_w']!=0&&$post['thumb_h']!=0) {
if(file_exists(KU_BOARDSDIR.$this->board['name'].'/thumb/'.$post['file'].'s.jpg'))
$post['nonstandard_file'] = KU_WEBPATH . '/' .$this->board['name'].'/thumb/'.$post['file'].'s.jpg';
elseif(file_exists(KU_BOARDSDIR.$this->board['name'].'/thumb/'.$post['file'].'s.png'))
$post['nonstandard_file'] = KU_WEBPATH . '/' .$this->board['name'].'/thumb/'.$post['file'].'s.png';
elseif(file_exists(KU_BOARDSDIR.$this->board['name'].'/thumb/'.$post['file'].'s.gif'))
$post['nonstandard_file'] = KU_WEBPATH . '/' .$this->board['name'].'/thumb/'.$post['file'].'s.gif';
else {
$post['thumb_w'] = $filetype_info[$post['file_type']][1];
$post['thumb_h'] = $filetype_info[$post['file_type']][2];
}
}
else {
$post['thumb_w'] = $filetype_info[$post['file_type']][1];
$post['thumb_h'] = $filetype_info[$post['file_type']][2];
}
}
return $post;
}
/**
* Build the page header
*
* @param integer $replythread The ID of the thread the header is being build for. 0 if it is for a board page
* @param integer $liststart The number which the thread list starts on (text boards only)
* @param integer $liststooutput The number of list pages which will be generated (text boards only)
* @return string The built header
*/
function PageHeader($replythread = '0', $liststart = '0', $liststooutput = '-1') {
global $tc_db, $CURRENTLOCALE;
$tpl = Array();
$tpl['htmloptions'] = ((KU_LOCALE == 'he' && empty($this->board['locale'])) || $this->board['locale'] == 'he') ? ' dir="rtl"' : '' ;
$tpl['title'] = '';
if (KU_DIRTITLE) {
$tpl['title'] .= '/' . $this->board['name'] . '/ - ';
}
$tpl['title'] .= $this->board['desc'];
$ad_top = 185;
$ad_right = 25;
if ($this->board['type']==1) {
$ad_top -= 50;
} else {
if ($replythread!=0) {
$ad_top += 50;
}
}
if ($this->board['type']==2) {
$ad_top += 40;
}
$this->dwoo_data->assign('title', $tpl['title']);
$this->dwoo_data->assign('htmloptions', $tpl['htmloptions']);
$this->dwoo_data->assign('locale', $CURRENTLOCALE);
$this->dwoo_data->assign('ad_top', $ad_top);
$this->dwoo_data->assign('ad_right', $ad_right);
$this->dwoo_data->assign('board', $this->board);
$this->dwoo_data->assign('replythread', $replythread);
if ($this->board['type'] != 1) {
$topads = $tc_db->GetOne("SELECT code FROM `" . KU_DBPREFIX . "ads` WHERE `position` = 'top' AND `disp` = '1'");
$this->dwoo_data->assign('topads', $topads);
$this->dwoo_data->assign('ku_styles', explode(':', KU_STYLES));
$this->dwoo_data->assign('ku_defaultstyle', (!empty($this->board['defaultstyle']) ? ($this->board['defaultstyle']) : (KU_DEFAULTSTYLE)));
} else {
$this->dwoo_data->assign('ku_styles', explode(':', KU_TXTSTYLES));
$this->dwoo_data->assign('ku_defaultstyle', (!empty($this->board['defaultstyle']) ? ($this->board['defaultstyle']) : (KU_DEFAULTTXTSTYLE)));
}
$this->dwoo_data->assign('boardlist', $this->board['boardlist']);
$global_header = $this->dwoo->get(KU_TEMPLATEDIR . '/global_board_header.tpl', $this->dwoo_data);
if ($this->board['type'] != 1) {
$header = $this->dwoo->get(KU_TEMPLATEDIR . '/' . $this->board['text_readable'] . '_header.tpl', $this->dwoo_data);
} else {
if ($liststooutput == -1) {
$this->dwoo_data->assign('isindex', true);
} else {
$this->dwoo_data->assign('isindex', false);
}
if ($replythread != 0) $this->dwoo_data->assign('isthread', true);
$header = $this->dwoo->get(KU_TEMPLATEDIR . '/txt_header.tpl', $this->dwoo_data);
if ($replythread == 0) {
$startrecord = ($liststooutput >= 0 || $this->board['compactlist']) ? 40 : KU_THREADSTXT ;
$threads = $tc_db->GetAll("SELECT * FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $tc_db->qstr($this->board['id']) . " AND `parentid` = 0 AND `IS_DELETED` = 0 ORDER BY `stickied` DESC, `bumped` DESC LIMIT " . $startrecord . " OFFSET " . $liststart);
foreach($threads AS $key=>$thread) {
$replycount = $tc_db->GetOne("SELECT COUNT(`id`) FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $tc_db->qstr($this->board['id']) . " AND `parentid` = " . $thread['id']);
$threads[$key]['replies'] = $replycount;
}
$this->dwoo_data->assign('threads', $threads);
$header .= $this->dwoo->get(KU_TEMPLATEDIR . '/txt_threadlist.tpl', $this->dwoo_data);
}
}
return $global_header.$header;
}
/**
* Build the page header for an oekaki posting
*
* @param integer $replyto The ID of the thread being replied to. 0 for a new thread
*/
function OekakiHeader($replyto, $postoek) {
$executiontime_start = microtime_float();
$this->InitializeDwoo();
$page = $this->PageHeader();
$this->dwoo_data->assign('replythread', $replyto);
$page .= $this->Postbox();
$executiontime_stop = microtime_float();
$page .= $this->Footer(false, ($executiontime_stop - $executiontime_start));
$this->PrintPage('', $page, true);
}
/**
* Generate the postbox area
*
* @param integer $replythread The ID of the thread being replied to. 0 if not replying
* @param string $postboxnotice The postbox notice
* @return string The generated postbox
*/
function Postbox($replythread = 0) {
global $tc_db;
if (KU_BLOTTER && $this->board['type'] != 1) {
$this->dwoo_data->assign('blotter', getBlotter());
$this->dwoo_data->assign('blotter_updated', getBlotterLastUpdated());
}
$postbox = '';
if ($this->board['type'] == 2 && $replythread > 0) {
$oekposts = $tc_db->GetAll("SELECT `id` FROM `" . KU_DBPREFIX."posts` WHERE `boardid` = " . $this->board['id']." AND (`id` = ".$replythread." OR `parentid` = ".$replythread.") AND `file` != '' AND `file` != 'removed' AND `file_type` IN ('jpg', 'gif', 'png') AND `IS_DELETED` = 0 ORDER BY `parentid` ASC, `timestamp` ASC");
$this->dwoo_data->assign('oekposts', $oekposts);
}
if(($this->board['type'] == 1 && $replythread == 0) || $this->board['type'] != 1) {
$postbox .= $this->dwoo->get(KU_TEMPLATEDIR . '/' . $this->board['text_readable'] . '_post_box.tpl', $this->dwoo_data);
}
return $postbox;
}
/**
* Display the user-defined list of boards found in boards.html
*
* @param boolean $is_textboard If the board this is being displayed for is a text board
* @return string The board list
*/
function DisplayBoardList($is_textboard = false) {
if (KU_GENERATEBOARDLIST) {
global $tc_db;
$output = '';
$results = $tc_db->GetAll("SELECT `id` FROM `" . KU_DBPREFIX . "sections` ORDER BY `order` ASC");
$boards = array();
foreach($results AS $line) {
$results2 = $tc_db->GetAll("SELECT * FROM `" . KU_DBPREFIX . "boards` WHERE `section` = '" . $line['id'] . "' ORDER BY `order` ASC, `name` ASC");
foreach($results2 AS $line2) {
$boards[$line['id']][$line2['id']]['name'] = htmlspecialchars($line2['name']);
$boards[$line['id']][$line2['id']]['desc'] = htmlspecialchars($line2['desc']);
}
}
} else {
$boards = KU_ROOTDIR . 'boards.html';
}
return $boards;
}
/**
* Display the page footer
*
* @param boolean $noboardlist Force the board list to not be displayed
* @param string $executiontime The time it took the page to be created
* @param boolean $hide_extra Hide extra footer information, and display the manage link
* @return string The generated footer
*/
function Footer($noboardlist = false, $executiontime = '', $hide_extra = false) {
global $tc_db, $dwoo, $dwoo_data;
$footer = '';
if ($hide_extra || $noboardlist) $this->dwoo_data->assign('boardlist', '');
if ($executiontime != '') $this->dwoo_data->assign('executiontime', round($executiontime, 2));
$botads = $tc_db->GetOne("SELECT code FROM `" . KU_DBPREFIX . "ads` WHERE `position` = 'bot' AND `disp` = '1'");
$this->dwoo_data->assign('botads', $botads);
$footer = $this->dwoo->get(KU_TEMPLATEDIR . '/' . $this->board['text_readable'] . '_footer.tpl', $this->dwoo_data);
$footer .= $this->dwoo->get(KU_TEMPLATEDIR . '/global_board_footer.tpl', $this->dwoo_data);
return $footer;
}
/**
* Finalize the page and print it to the specified filename
*
* @param string $filename File to print the page to
* @param string $contents Page contents
* @param string $board Board which the file is being generated for
* @return string The page contents, if requested
*/
function PrintPage($filename, $contents, $board) {
if ($board !== true) {
print_page($filename, $contents, $board);
} else {
echo $contents;
}
}
/**
* Initialize the instance of smary which will be used for generating pages
*/
function InitializeDwoo() {
require_once KU_ROOTDIR . 'lib/dwoo.php';
$this->dwoo = new Dwoo();
$this->dwoo_data = new Dwoo_Data();
$this->dwoo_data->assign('cwebpath', getCWebpath());
$this->dwoo_data->assign('boardpath', getCLBoardPath());
}
/**
* Enable/disable archive mode
*
* @param boolean $mode True/false for enabling/disabling archive mode
*/
function ArchiveMode($mode) {
$this->archive_dir = ($mode && $this->board['enablearchiving'] == 1) ? '/arch' : '';
}
}
/**
* Post class
*
* Used for post insertion, deletion, and reporting.
*
* @package kusaba
*/
class Post extends Board {
// Declare the public variables
var $post = Array();
function Post($postid, $board, $boardid, $is_inserting = false) {
global $tc_db;
$results = $tc_db->GetAll("SELECT * FROM `".KU_DBPREFIX."posts` WHERE `boardid` = '" . $boardid . "' AND `id` = ".$tc_db->qstr($postid)." LIMIT 1");
if (count($results)==0&&!$is_inserting) {
exitWithErrorPage('Invalid post ID.');
} elseif ($is_inserting) {
$this->Board($board, false);
} else {
foreach ($results[0] as $key=>$line) {
if (!is_numeric($key)) $this->post[$key] = $line;
}
$results = $tc_db->GetAll("SELECT `cleared` FROM `".KU_DBPREFIX."reports` WHERE `postid` = ".$tc_db->qstr($this->post['id'])." LIMIT 1");
if (count($results)>0) {
foreach($results AS $line) {
$this->post['isreported'] = ($line['cleared'] == 0) ? true : 'cleared';
}
} else {
$this->post['isreported'] = false;
}
$this->post['isthread'] = ($this->post['parentid'] == 0) ? true : false;
if (empty($this->board) || $this->board['name'] != $board) {
$this->Board($board, false);
}
}
}
function Delete($allow_archive = false) {
global $tc_db;
$i = 0;
if ($this->post['isthread'] == true) {
if ($allow_archive && $this->board['enablearchiving'] == 1 && $this->board['loadbalanceurl'] == '') {
$this->ArchiveMode(true);
$this->RegenerateThreads($this->post['id']);
@copy(KU_BOARDSDIR . $this->board['name'] . '/src/' . $this->post['file'] . '.' . $this->post['filetype'], KU_BOARDSDIR . $this->board['name'] . $this->archive_dir . '/src/' . $this->post['file'] . '.' . $this->post['filetype']);
@copy(KU_BOARDSDIR . $this->board['name'] . '/thumb/' . $this->post['file'] . 's.' . $this->post['filetype'], KU_BOARDSDIR . $this->board['name'] . $this->archive_dir . '/thumb/' . $this->post['file'] . 's.' . $this->post['filetype']);
}
$results = $tc_db->GetAll("SELECT `id`, `file`, `file_type` FROM `".KU_DBPREFIX."posts` WHERE `boardid` = '" . $this->board['id'] . "' AND `IS_DELETED` = 0 AND `parentid` = ".$tc_db->qstr($this->post['id']));
foreach($results AS $line) {
$i++;
if ($allow_archive && $this->board['enablearchiving'] == 1) {
@copy(KU_BOARDSDIR . $this->board['name'] . '/src/' . $line['file'] . '.' . $line['file_type'], KU_BOARDSDIR . $this->board['name'] . $this->archive_dir . '/src/' . $line['file'] . '.' . $line['file_type']);
@copy(KU_BOARDSDIR . $this->board['name'] . '/thumb/' . $line['file'] . 's.' . $line['file_type'], KU_BOARDSDIR . $this->board['name'] . $this->archive_dir . '/thumb/' . $line['file'] . 's.' . $line['file_type']);
}
}
if ($allow_archive && $this->board['enablearchiving'] == 1) {
$this->ArchiveMode(false);
}
@unlink(KU_BOARDSDIR.$this->board['name'].'/res/'.$this->post['id'].'.html');
@unlink(KU_BOARDSDIR.$this->board['name'].'/res/'.$this->post['id'].'-100.html');
@unlink(KU_BOARDSDIR.$this->board['name'].'/res/'.$this->post['id'].'+50.html');
$this->DeleteFile(false, true);
foreach($results AS $line) {
$tc_db->Execute("UPDATE `".KU_DBPREFIX."posts` SET `IS_DELETED` = 1 , `deleted_timestamp` = '" . time() . "' WHERE `boardid` = '" . $this->board['id'] . "' AND `id` = '".$line['id']."' AND `parentid` = ".$tc_db->qstr($this->post['id']));
clearPostCache($line['id'], $this->board['name']);
}
$tc_db->Execute("DELETE FROM `".KU_DBPREFIX."watchedthreads` WHERE `threadid` = ".$tc_db->qstr($this->post['id'])." AND `board` = '".$this->board['name']."'");
$tc_db->Execute("UPDATE `".KU_DBPREFIX."posts` SET `IS_DELETED` = 1 , `deleted_timestamp` = '" . time() . "' WHERE `boardid` = '" . $this->board['id'] . "' AND `id` = ".$tc_db->qstr($this->post['id']));
clearPostCache($this->post['id'], $this->board['name']);
return $i.' ';
} else {
$this->DeleteFile(false);
$tc_db->Execute("UPDATE `".KU_DBPREFIX."posts` SET `IS_DELETED` = 1 , `deleted_timestamp` = '" . time() . "' WHERE `boardid` = '" . $this->board['id'] . "' AND `id` = ".$tc_db->qstr($this->post['id']));
clearPostCache($this->post['id'], $this->board['name']);
return true;
}
}
function DeleteFile($update_to_removed = true, $whole_thread = false) {
global $tc_db;
if ($whole_thread && $this->post['isthread']) {
$results = $tc_db->GetAll("SELECT `id`, `file`, `file_type` FROM `".KU_DBPREFIX."posts` WHERE `boardid` = " . $this->board['id'] . " AND `IS_DELETED` = 0 AND `parentid` = ".$tc_db->qstr($this->post['id']));
if (count($results)>0) {
foreach($results AS $line) {
if ($line['file'] != '' && $line['file'] != 'removed') {
if ($this->board['loadbalanceurl'] != '') {
$this->loadbalancer->Delete($line['file'], $line['file_type']);
} else {
@unlink(KU_BOARDSDIR.$this->board['name'].'/src/'.$line['file'].'.'.$line['file_type']);
@unlink(KU_BOARDSDIR.$this->board['name'].'/src/'.$line['file'].'.pch');
@unlink(KU_BOARDSDIR.$this->board['name'].'/thumb/'.$line['file'].'s.'.$line['file_type']);
@unlink(KU_BOARDSDIR.$this->board['name'].'/thumb/'.$line['file'].'c.'.$line['file_type']);
if ($line['file_type'] == 'mp3') {
@unlink(KU_BOARDSDIR.$this->board['name'].'/thumb/'.$line['file'].'s.jpg');
@unlink(KU_BOARDSDIR.$this->board['name'].'/thumb/'.$line['file'].'s.png');
@unlink(KU_BOARDSDIR.$this->board['name'].'/thumb/'.$line['file'].'s.gif');
}
}
if ($update_to_removed) {
$tc_db->Execute("UPDATE `".KU_DBPREFIX."posts` SET `file` = 'removed', `file_md5` = '' WHERE `boardid` = '" . $this->board['id'] . "' AND `id` = ".$line['id']);
clearPostCache($line['id'], $this->board['name']);
}
}
}
}
$this->DeleteFile($update_to_removed);
} else {
if ($this->post['file']!=''&&$this->post['file']!='removed') {
if ($this->board['loadbalanceurl'] != '') {
$this->loadbalancer->Delete($this->post['file'], $this->post['filetype']);
} else {
@unlink(KU_BOARDSDIR.$this->board['name'].'/src/'.$this->post['file'].'.'.$this->post['file_type']);
@unlink(KU_BOARDSDIR.$this->board['name'].'/src/'.$this->post['file'].'.pch');
@unlink(KU_BOARDSDIR.$this->board['name'].'/thumb/'.$this->post['file'].'s.'.$this->post['file_type']);
@unlink(KU_BOARDSDIR.$this->board['name'].'/thumb/'.$this->post['file'].'c.'.$this->post['file_type']);
if ($this->post['file_type'] == 'mp3') {
@unlink(KU_BOARDSDIR.$this->board['name'].'/thumb/'.$this->post['file'].'s.jpg');
@unlink(KU_BOARDSDIR.$this->board['name'].'/thumb/'.$this->post['file'].'s.png');
@unlink(KU_BOARDSDIR.$this->board['name'].'/thumb/'.$this->post['file'].'s.gif');
}
}
if ($update_to_removed) {
$tc_db->Execute("UPDATE `".KU_DBPREFIX."posts` SET `file` = 'removed', `file_md5` = '' WHERE `boardid` = '" . $this->board['id'] . "' AND `id` = ".$tc_db->qstr($this->post['id']));
clearPostCache($this->post['id'], $this->board['name']);
}
}
}
}
function Insert($parentid, $name, $tripcode, $email, $subject, $message, $filename, $file_original, $filetype, $file_md5, $image_w, $image_h, $filesize, $thumb_w, $thumb_h, $password, $timestamp, $bumped, $ip, $posterauthority, $tag, $stickied, $locked, $boardid) {
global $tc_db;
$query = "INSERT INTO `".KU_DBPREFIX."posts` ( `parentid` , `boardid`, `name` , `tripcode` , `email` , `subject` , `message` , `file` , `file_original`, `file_type` , `file_md5` , `image_w` , `image_h` , `file_size` , `file_size_formatted` , `thumb_w` , `thumb_h` , `password` , `timestamp` , `bumped` , `ip` , `ipmd5` , `posterauthority` , `tag` , `stickied` , `locked` ) VALUES ( ".$tc_db->qstr($parentid).", ".$tc_db->qstr($boardid).", ".$tc_db->qstr($name).", ".$tc_db->qstr($tripcode).", ".$tc_db->qstr($email).", ".$tc_db->qstr($subject).", ".$tc_db->qstr($message).", ".$tc_db->qstr($filename).", ".$tc_db->qstr($file_original).", ".$tc_db->qstr($filetype).", ".$tc_db->qstr($file_md5).", ".$tc_db->qstr(intval($image_w)).", ".$tc_db->qstr(intval($image_h)).", ".$tc_db->qstr($filesize).", ".$tc_db->qstr(ConvertBytes($filesize)).", ".$tc_db->qstr($thumb_w).", ".$tc_db->qstr($thumb_h).", ".$tc_db->qstr($password).", ".$tc_db->qstr($timestamp).", ".$tc_db->qstr($bumped).", ".$tc_db->qstr(md5_encrypt($ip, KU_RANDOMSEED)).", '".md5($ip)."', ".$tc_db->qstr($posterauthority).", ".$tc_db->qstr($tag).", ".$tc_db->qstr($stickied).", ".$tc_db->qstr($locked)." )";
$tc_db->Execute($query);
$id = $tc_db->Insert_Id();
if(!$id || KU_DBTYPE == 'sqlite') {
// Non-mysql installs don't return the insert ID after insertion, we need to manually get it.
$id = $tc_db->GetOne("SELECT `id` FROM `".KU_DBPREFIX."posts` WHERE `boardid` = ".$tc_db->qstr($boardid)." AND timestamp = ".$tc_db->qstr($timestamp)." AND `ipmd5` = '".md5($ip)."' LIMIT 1");
}
if ($id == 1 && $this->board['start'] > 1) {
$tc_db->Execute("UPDATE `".KU_DBPREFIX."posts` SET `id` = '".$this->board['start']."' WHERE `boardid` = ".$boardid);
return $this->board['start'];
}
return $id;
}
function Report() {
global $tc_db;
return $tc_db->Execute("INSERT INTO `".KU_DBPREFIX."reports` ( `board` , `postid` , `when` , `ip`, `reason` ) VALUES ( " . $tc_db->qstr($this->board['name']) . " , " . $tc_db->qstr($this->post['id']) . " , ".time()." , '" . md5_encrypt($_SERVER['REMOTE_ADDR'], KU_RANDOMSEED) . "', " . $tc_db->qstr($_POST['reportreason']) . " )");
}
}
?>
+83
View File
@@ -0,0 +1,83 @@
<?php
/*
* This file is part of kusaba.
*
* kusaba is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* kusaba is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* kusaba; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* +------------------------------------------------------------------------------+
* Load balancer class
* +------------------------------------------------------------------------------+
*/
class Load_Balancer {
var $url;
var $password;
function Send($type, $file, $targetname, $targetthumb = '', $targetthumb_c = '', $checkmime = '', $isreply = false, $handle_errors = false) {
$isreply_formatted = ($isreply) ? '1' : '0';
$ch = curl_init($this->url);
$post = array('password' => $this->password,
'type' => $type,
'isreply' => $isreply_formatted,
'file' => $file,
'targetname' => $targetname,
'targetthumb' => $targetthumb,
'targetthumb_c' => $targetthumb_c,
'checkmime' => $checkmime);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$return = curl_exec($ch);
curl_close($ch);
if ($handle_errors) {
if ($return == 'bad password') die(_gettext('The passwords of the load balancer password in the board configuration and the load receiver script differ.'));
if ($return == 'unable to thumbnail') die(_gettext('The load balancer script was unable to create the thumbnail for that image.'));
if ($return == 'file already exists') die(_gettext('That file already exists on the server.'));
if ($return == 'unable to copy') die(_gettext('The load balancer script was unable to copy the file you uploaded.'));
if ($return == 'bad mime type') die(_gettext('That file does not match up with the required mime type for that format.'));
if ($return == '' || $return == 'failure') die(_gettext('The load balancer script stopped unexpectedly.'));
}
return $return;
}
function Delete($filename, $filetype) {
$ch = curl_init($this->url);
$post = array('password' => $this->password,
'type' => 'delete',
'filename' => $filename,
'filetype' => $filetype);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$return = curl_exec($ch);
curl_close($ch);
return $return;
}
}
?>
File diff suppressed because it is too large. Load diff
+103
View File
@@ -0,0 +1,103 @@
<?php
/*
* This file is part of kusaba.
*
* kusaba is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* kusaba is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* kusaba; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* Menu class
*
* @package kusaba
*/
class Menu {
function GetMenu($savetofile = false, $option = false) {
global $tc_db, $dwoo, $dwoo_data, $kusabaxorg;
require_once KU_ROOTDIR.'lib/dwoo.php';
$dwoo_data->assign('boardpath', getCLBoardPath());
if (KU_MENUTYPE == 'normal') {
$dwoo_data->assign('styles', explode(':', KU_MENUSTYLES));
}
if ($savetofile) {
$files = array('menu.html', 'menu_dirs.html');
} else {
$files = array('menu.php', 'menu.php');
}
$dwoo_data->assign('files', $files);
$sections = Array();
$results_boardsexist = $tc_db->GetAll("SELECT `id` FROM `".KU_DBPREFIX."boards` LIMIT 1");
if (count($results_boardsexist) > 0) {
$sections = $tc_db->GetAll("SELECT * FROM `" . KU_DBPREFIX . "sections` ORDER BY `order` ASC");
foreach($sections AS $key=>$section) {
$results = $tc_db->GetAll("SELECT * FROM `" . KU_DBPREFIX . "boards` WHERE `section` = '" . $section['id'] . "' ORDER BY `order` ASC, `name` ASC /* MENU.CLASS.PHP */");
foreach($results AS $line) {
$sections[$key]['boards'][] = $line;
}
}
}
$dwoo_data->assign('boards', $sections);
$tpl_irc = '';
$dwoo_data->assign('irc', $tpl_irc);
for ($i = 0; $i < 2; $i++) {
if ($i == 0) $dwoo_data->assign('showdirs', 0);
else $dwoo_data->assign('showdirs', 1);
if ($savetofile) {
if ($i == 0) {
file_put_contents(KU_ROOTDIR . $files[0], $dwoo->get(KU_TEMPLATEDIR . '/menu.tpl', $dwoo_data));
} else {
file_put_contents(KU_ROOTDIR . $files[1], $dwoo->get(KU_TEMPLATEDIR . '/menu.tpl', $dwoo_data));
}
} else {
if ($i == 0) {
$menu_nodirs = $dwoo->get(KU_TEMPLATEDIR . '/menu.tpl', $dwoo_data);
if ($option == 'nodirs') {
return $menu_nodirs;
}
} else {
if ($option == 'dirs') {
$menu_dirs = $dwoo->get(KU_TEMPLATEDIR . '/menu.tpl', $dwoo_data);
return $menu_dirs;
}
}
}
}
if (isset($menu_nodirs) && isset($menu_dirs)) {
return array($menu_nodirs, $menu_dirs);
}
}
function Generate() {
return $this->GetMenu(true);
}
function PrintMenu($option = false) {
if ($option != false) {
return $this->GetMenu(false, $option);
} else {
return $this->GetMenu(false);
}
}
}
?>
+326
View File
@@ -0,0 +1,326 @@
<?php
/*
* This file is part of kusaba.
*
* kusaba is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* kusaba is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* kusaba; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* +------------------------------------------------------------------------------+
* Parse class
* +------------------------------------------------------------------------------+
* A post's message text will be passed, which will then be formatted and cleaned
* before being returned.
* +------------------------------------------------------------------------------+
*/
class Parse {
var $boardtype;
var $parentid;
var $id;
var $boardid;
function MakeClickable($txt) {
/* Make http:// urls in posts clickable */
$txt = preg_replace('#(http://|https://|ftp://)([^(\s<)]*)#', '<a href="\\1\\2">\\1\\2</a>', $txt);
return $txt;
}
function BBCode($string){
$patterns = array(
'`\[b\](.+?)\[/b\]`is',
'`\[i\](.+?)\[/i\]`is',
'`\[u\](.+?)\[/u\]`is',
'`\[s\](.+?)\[/s\]`is',
'`\[aa\](.+?)\[/aa\]`is',
'`\[spoiler\](.+?)\[/spoiler\]`is',
);
$replaces = array(
'<b>\\1</b>',
'<i>\\1</i>',
'<span style="border-bottom: 1px solid">\\1</span>',
'<strike>\\1</strike>',
'<div style="font-family: Mona,\'MS PGothic\' !important;">\\1</div>',
'<span class="spoiler" onmouseover="this.style.color=\'white\';" onmouseout="this.style.color=\'black\'">\\1</span>',
);
$string = preg_replace($patterns, $replaces , $string);
$string = preg_replace_callback('`\[code\](.+?)\[/code\]`is', array(&$this, 'code_callback'), $string);
return $string;
}
function code_callback($matches) {
$return = '<div style="white-space: pre !important;font-family: monospace !important;">'
. str_replace('<br />', '', $matches[1]) .
'</div>';
return $return;
}
function ColoredQuote($buffer, $boardtype) {
/* Add a \n to keep regular expressions happy */
if (substr($buffer, -1, 1)!="\n") {
$buffer .= "\n";
}
if ($boardtype==1) {
/* The css for text boards use 'quote' as the class for quotes */
$class = 'quote';
$linechar = '';
} else {
/* The css for imageboards use 'unkfunc' (???) as the class for quotes */
$class = 'unkfunc';
$linechar = "\n";
}
$buffer = preg_replace('/^(&gt;[^>](.*))\n/m', '<span class="'.$class.'">\\1</span>' . $linechar, $buffer);
/* Remove the > from the quoted line if it is a text board */
if ($boardtype==1) {
$buffer = str_replace('<span class="'.$class.'">&gt;', '<span class="'.$class.'">', $buffer);
}
return $buffer;
}
function ClickableQuote($buffer, $board, $boardtype, $parentid, $boardid, $ispage = false) {
global $thread_board_return;
$thread_board_return = $board;
$thread_board_id = $boardid;
/* Add html for links to posts in the board the post was made */
$buffer = preg_replace_callback('/&gt;&gt;([r]?[l]?[f]?[q]?[0-9,\-,\,]+)/', array(&$this, 'InterthreadQuoteCheck'), $buffer);
/* Add html for links to posts made in a different board */
$buffer = preg_replace_callback('/&gt;&gt;\/([a-z]+)\/([0-9]+)/', array(&$this, 'InterboardQuoteCheck'), $buffer);
return $buffer;
}
function InterthreadQuoteCheck($matches) {
global $tc_db, $ispage, $thread_board_return, $thread_board_id;
$lastchar = '';
// If the quote ends with a , or -, cut it off.
if(substr($matches[0], -1) == "," || substr($matches[0], -1) == "-") {
$lastchar = substr($matches[0], -1);
$matches[1] = substr($matches[1], 0, -1);
$matches[0] = substr($matches[0], 0, -1);
}
if ($this->boardtype != 1 && is_numeric($matches[1])) {
$query = "SELECT `parentid` FROM `".KU_DBPREFIX."posts` WHERE `boardid` = " . $this->boardid . " AND `id` = ".$tc_db->qstr($matches[1]);
$result = $tc_db->GetOne($query);
if ($result !== '') {
if ($result == 0) {
$realid = $matches[1];
} else {
$realid = $result;
}
} else {
return $matches[0];
}
$return = '<a href="'.KU_BOARDSFOLDER.$thread_board_return.'/res/'.$realid.'.html#'.$matches[1].'" onclick="return highlight(\'' . $matches[1] . '\', true);" class="ref|' . $thread_board_return . '|' .$realid . '|' . $matches[1] . '">'.$matches[0].'</a>'.$lastchar;
} else {
$return = $matches[0];
$postids = getQuoteIds($matches[1]);
if (count($postids) > 0) {
$realid = $this->parentid;
if ($realid === 0) {
if ($this->id > 0) {
$realid = $this->id;
}
}
if ($realid !== '') {
$return = '<a href="' . KU_BOARDSFOLDER . 'read.php';
if (KU_TRADITIONALREAD) {
$return .= '/' . $thread_board_return . '/' . $realid.'/' . $matches[1];
} else {
$return .= '?b=' . $thread_board_return . '&t=' . $realid.'&p=' . $matches[1];
}
$return .= '">' . $matches[0] . '</a>';
}
}
}
return $return;
}
function InterboardQuoteCheck($matches) {
global $tc_db;
$result = $tc_db->GetAll("SELECT `id`, `type` FROM `".KU_DBPREFIX."boards` WHERE `name` = ".$tc_db->qstr($matches[1])."");
if ($result[0]["type"] != '') {
$result2 = $tc_db->GetOne("SELECT `parentid` FROM `".KU_DBPREFIX."posts` WHERE `boardid` = " . $result[0]['id'] . " AND `id` = ".$tc_db->qstr($matches[2])."");
if ($result2 != '') {
if ($result2 == 0) {
$realid = $matches[2];
} else {
if ($result[0]['type'] != 1) {
$realid = $result2;
}
}
if ($result[0]["type"] != 1) {
return '<a href="'.KU_BOARDSFOLDER.$matches[1].'/res/'.$realid.'.html#'.$matches[2].'" class="ref|' . $matches[1] . '|' . $realid . '|' . $matches[2] . '">'.$matches[0].'</a>';
} else {
return '<a href="'.KU_BOARDSFOLDER.$matches[1].'/res/'.$realid.'.html" class="ref|' . $matches[1] . '|' . $realid . '|' . $realid . '">'.$matches[0].'</a>';
}
}
}
return $matches[0];
}
function Wordfilter($buffer, $board) {
global $tc_db;
$query = "SELECT * FROM `".KU_DBPREFIX."wordfilter`";
$results = $tc_db->GetAll($query);
foreach($results AS $line) {
$array_boards = explode('|', $line['boards']);
if (in_array($board, $array_boards)) {
$replace_word = $line['word'];
$replace_replacedby = $line['replacedby'];
$buffer = ($line['regex'] == 1) ? preg_replace($replace_word, $replace_replacedby, $buffer) : str_ireplace($replace_word, $replace_replacedby, $buffer);
}
}
return $buffer;
}
function CheckNotEmpty($buffer) {
$buffer_temp = str_replace("\n", "", $buffer);
$buffer_temp = str_replace("<br>", "", $buffer_temp);
$buffer_temp = str_replace("<br/>", "", $buffer_temp);
$buffer_temp = str_replace("<br />", "", $buffer_temp);
$buffer_temp = str_replace(" ", "", $buffer_temp);
if ($buffer_temp=="") {
return "";
} else {
return $buffer;
}
}
/* From http://us.php.net/wordwrap */
/*function CutWord($str, $maxLength, $char){
$wordEndChars = array(" ", "\n", "\r", "\f", "\v", "\0");
$count = 0;
$newStr = "";
$openTag = false;
for($i=0; $i<strlen($str); $i++){
$newStr .= $str{$i};
echo 'newstr: ' . $newStr . '<hr>' . "\n";
if($str{$i} == "<"){
$openTag = true;
continue;
}
if(($openTag) && ($str{$i} == ">")){
$openTag = false;
continue;
}
if(!$openTag){
if(!in_array($str{$i}, $wordEndChars)){//If not word ending char
$count++;
if($count==$maxLength){//if current word max length is reached
$newStr .= $char;//insert word break char
$count = 0;
}
}else{//Else char is word ending, reset word char count
$count = 0;
}
}
}//End for
die($newStr);
return $newStr;
}*/
/*function CutWord($txt, $where) {
if (empty($txt)) return false;
for ($c = 0, $a = 0, $g = 0; $c<strlen($txt); $c++) {
$d[$c+$g]=$txt[$c];
if ($txt[$c]!=' '&&$txt[$c]!=chr(10)) $a++;
else if ($txt[$c]==' '||$txt[$c]==chr(10)) $a = 0;
if ($a==$where) {
$g++;
$d[$c+$g]="\n";
$a = 0;
}
}
return implode("", $d);
}*/
function CutWord($txt, $where) {
$txt_split_primary = preg_split('/\n/', $txt);
$txt_processed = '';
$usemb = (function_exists('mb_substr') && function_exists('mb_strlen')) ? true : false;
foreach ($txt_split_primary as $txt_split) {
$txt_split_secondary = preg_split('/ /', $txt_split);
foreach ($txt_split_secondary as $txt_segment) {
$segment_length = ($usemb) ? mb_strlen($txt_segment) : strlen($txt_segment);
while ($segment_length > $where) {
if ($usemb) {
$txt_processed .= mb_substr($txt_segment, 0, $where) . "\n";
$txt_segment = mb_substr($txt_segment, $where);
$segment_length = mb_strlen($txt_segment);
} else {
$txt_processed .= substr($txt_segment, 0, $where) . "\n";
$txt_segment = substr($txt_segment, $where);
$segment_length = strlen($txt_segment);
}
}
$txt_processed .= $txt_segment . ' ';
}
$txt_processed = ($usemb) ? mb_substr($txt_processed, 0, -1) : substr($txt_processed, 0, -1);
$txt_processed .= "\n";
}
return $txt_processed;
}
function ParsePost($message, $board, $boardtype, $parentid, $boardid, $ispage = false) {
$this->boardtype = $boardtype;
$this->parentid = $parentid;
$this->boardid = $boardid;
$message = trim($message);
$message = $this->CutWord($message, (KU_LINELENGTH / 15));
$message = htmlspecialchars($message, ENT_QUOTES);
if (KU_MAKELINKS) {
$message = $this->MakeClickable($message);
}
$message = $this->ClickableQuote($message, $board, $boardtype, $parentid, $boardid, $ispage);
$message = $this->ColoredQuote($message, $boardtype);
/*if (KU_MARKDOWN) {
require KU_ROOTDIR . 'lib/markdown/markdown.php';
$message = Markdown($message);
}*/
$message = str_replace("\n", '<br />', $message);
$message = $this->BBCode($message);
$message = $this->Wordfilter($message, $board);
$message = $this->CheckNotEmpty($message);
return $message;
}
}
?>
+326
View File
@@ -0,0 +1,326 @@
<?php
/*
* This file is part of kusaba.
*
* kusaba is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* kusaba is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* kusaba; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* +------------------------------------------------------------------------------+
* Posting class
* +------------------------------------------------------------------------------+
*/
class Posting {
function CheckOekaki() {
global $board_class;
/* If oekaki seems to be in the url... */
if (isset($_POST['oekaki'])) {
/* See if it checks out and is a valid oekaki id */
if ($_POST['oekaki'] != '' && is_file(KU_CGIDIR . 'kusabaoek/' . $_POST['oekaki'] . '.png') && $board_class->board['type'] == '2') {
/* Set the variable to tell the script it is handling an oekaki posting, and the oekaki file which will be posted */
return KU_CGIDIR . 'kusabaoek/' . $_POST['oekaki'] . '.png';
}
}
return '';
}
function CheckReplyTime() {
global $tc_db, $board_class;
/* Get the timestamp of the last time a reply was made by this IP address */
$results = $tc_db->GetAll("SELECT MAX(timestamp) FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $board_class->board['id'] . " AND `parentid` != 0 AND `ipmd5` = '" . md5($_SERVER['REMOTE_ADDR']) . "' AND `timestamp` > " . (time() - KU_REPLYDELAY));
/* If they have posted before and it was recorded... */
if (isset($result)) {
/* If the time was shorter than the minimum time distance */
if (time() - $line['timestamp'] <= KU_REPLYDELAY) {
exitWithErrorPage(_gettext('Please wait a moment before posting again.'), _gettext('You are currently posting faster than the configured minimum post delay allows.'));
}
}
}
function CheckNewThreadTime() {
global $tc_db, $board_class;
/* Get the timestamp of the last time a new thread was made by this IP address */
$result = $tc_db->GetOne("SELECT MAX(timestamp) FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $board_class->board['id'] . " AND `parentid` = 0 AND `ipmd5` = '" . md5($_SERVER['REMOTE_ADDR']) . "' AND `timestamp` > " . (time() - KU_NEWTHREADDELAY));
/* If they have posted before and it was recorded... */
if (isset($result)) {
/* If the time was shorter than the minimum time distance */
if (time() - $result <= KU_NEWTHREADDELAY) {
exitWithErrorPage(_gettext('Please wait a moment before posting again.'), _gettext('You are currently posting faster than the configured minimum post delay allows.'));
}
}
}
function UTF8Strings() {
if (function_exists('mb_convert_encoding') && function_exists('mb_check_encoding')) {
if (isset($_POST['name']) && !mb_check_encoding($_POST['name'], 'UTF-8')) {
$_POST['name'] = mb_convert_encoding($_POST['name'], 'UTF-8');
}
if (isset($_POST['em']) && !mb_check_encoding($_POST['em'], 'UTF-8')) {
$_POST['em'] = mb_convert_encoding($_POST['em'], 'UTF-8');
}
if (isset($_POST['subject']) && !mb_check_encoding($_POST['subject'], 'UTF-8')) {
$_POST['subject'] = mb_convert_encoding($_POST['subject'], 'UTF-8');
}
if (isset($_POST['message']) && !mb_check_encoding($_POST['message'], 'UTF-8')) {
$_POST['message'] = mb_convert_encoding($_POST['message'], 'UTF-8');
}
}
}
function CheckValidPost($is_oekaki) {
global $tc_db, $board_class;
if (
( /* A message is set, or an image was provided */
isset($_POST['message']) ||
isset($_FILES['imagefile'])
) || /* It is a validated oekaki posting */
$is_oekaki ||
( /* It is a text board, meaning only a message is required */
$board_class->board['type'] == '1' &&
isset($_POST['message'])
) || (
( /* It has embedding allowed */
$board_class->board['uploadtype'] == '1' ||
$board_class->board['uploadtype'] == '2'
) && ( /* An embed ID was provided, or no file was checked and no ID was supplied */
isset($_POST['embed']) ||
(
$board_class->board['uploadtype'] == '2' &&
!isset($_FILES['imagefile']) &&
isset($_POST['nofile']) &&
$board_class->board['enablenofile'] == true
)
)
)
) {
return true;
} else {
return false;
}
}
function CheckMessageLength() {
global $board_class;
/* If the length of the message is greater than the board's maximum message length... */
if (strlen($_POST['message']) > $board_class->board['messagelength']) {
/* Kill the script, stopping the posting process */
exitWithErrorPage(sprintf(_gettext('Sorry, your message is too long. Message length: %d, maximum allowed length: %d'), strlen($_POST['message']), $board_class->board['messagelength']));
}
}
function CheckCaptcha() {
global $board_class;
/* If the board has captcha's enabled... */
if ($board_class->board['enablecaptcha'] == 1) {
/* Check if they entered the correct code. If not... */
if ($_SESSION['security_code'] != strtolower($_POST['captcha']) || empty($_SESSION['security_code'])) {
/* Kill the script, stopping the posting process */
exitWithErrorPage(_gettext('Incorrect captcha entered.'));
}
}
}
function CheckBannedHash() {
global $tc_db, $board_class, $bans_class;
/* Banned file hash check */
if (isset($_FILES['imagefile'])) {
if ($_FILES['imagefile']['name'] != '') {
$results = $tc_db->GetAll("SELECT `bantime` , `description` FROM `" . KU_DBPREFIX . "bannedhashes` WHERE `md5` = " . $tc_db->qstr(md5_file($_FILES['imagefile']['tmp_name'])) . " LIMIT 1");
if (count($results) > 0) {
$bans_class->BanUser($_SERVER['REMOTE_ADDR'], 'SERVER', '1', $results[0]['bantime'], '', 'Posting a banned file.<br />' . $results[0]['description'], 0, 0, 1);
$bans_class->BanCheck($_SERVER['REMOTE_ADDR'], $board_class->board['name']);
die();
}
}
}
}
function CheckIsReply() {
global $tc_db, $board_class;
/* If it appears this is a reply to a thread, and not a new thread... */
if (isset($_POST['replythread'])) {
if ($_POST['replythread'] != '0') {
/* Check if the thread id supplied really exists */
$results = $tc_db->GetOne("SELECT COUNT(*) FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $board_class->board['id'] . " AND `IS_DELETED` = '0' AND `id` = " . $tc_db->qstr($_POST['replythread']) . " AND `parentid` = '0' LIMIT 1");
/* If it does... */
if ($results > 0) {
return true;
/* If it doesn't... */
} else {
/* Kill the script, stopping the posting process */
exitWithErrorPage(_gettext('Invalid thread ID.'), _gettext('That thread may have been recently deleted.'));
}
}
}
return false;
}
function CheckNotDuplicateSubject($subject) {
global $tc_db, $board_class;
$result = $tc_db->GetOne("SELECT COUNT(*) FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $board_class->board['id'] . " AND `IS_DELETED` = '0' AND `subject` = " . $tc_db->qstr($subject) . " AND `parentid` = '0'");
if ($result > 0) {
exitWithErrorPage(_gettext('Duplicate thread subject'), _gettext('Text boards may have only one thread with a unique subject. Please pick another.'));
}
}
function GetThreadInfo($id) {
global $tc_db, $board_class;
/* Check if the thread id supplied really exists and if it is locked */
$results = $tc_db->GetAll("SELECT `id`,`locked` FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $board_class->board['id'] . " AND `IS_DELETED` = '0' AND `id` = " . $tc_db->qstr($id) . " AND `parentid` = '0'");
/* If it does... */
if (count($results) > 0) {
/* Get the thread's info */
$thread_locked = $results[0]['locked'];
$thread_replyto = $results[0]['id'];
/* Get the number of replies */
$result = $tc_db->GetOne("SELECT COUNT(id) FROM `" . KU_DBPREFIX ."posts` WHERE `boardid` = " . $board_class->board['id'] . " AND `IS_DELETED` = '0' AND `parentid` = " . $tc_db->qstr($id) . "");
$thread_replies = $result;
return array($thread_replies, $thread_locked, $thread_replyto);
} else {
/* If it doesn't, kill the script, stopping the posting process */
exitWithErrorPage(_gettext('Invalid thread ID.'), _gettext('That thread may have been recently deleted.'));
}
}
function GetFields() {
/* Fetch and process the name, email, and subject fields from the post data */
$post_name = isset($_POST['name']) ? htmlspecialchars($_POST['name'], ENT_QUOTES) : '';
$post_email = isset($_POST['em']) ? str_replace('"', '', strip_tags($_POST['em'])) : '';
/* If the user used a software function, don't store it in the database */
if ($post_email == 'return' || $post_email == 'noko') $post_email = '';
$post_subject = isset($_POST['subject']) ? htmlspecialchars($_POST['subject'], ENT_QUOTES) : '';
return array($post_name, $post_email, $post_subject);
}
function GetUserAuthority() {
global $tc_db, $board_class;
$user_authority = 0;
$flags = '';
if (isset($_POST['modpassword'])) {
$results = $tc_db->GetAll("SELECT `type`, `boards` FROM `" . KU_DBPREFIX . "staff` WHERE `username` = '" . md5_decrypt($_POST['modpassword'], KU_RANDOMSEED) . "' LIMIT 1");
if (count($results) > 0) {
if ($results[0][0] == 1) {
$user_authority = 1; // admin
} elseif ($results[0][0] == 2 && in_array($board_class->board['name'], explode('|', $results[0][1]))) {
$user_authority = 2; // mod
} elseif ($results[0][0] == 2 && $results[0][1] == 'allboards') {
$user_authority = 2;
}/* elseif ($results[0][0] == 3) {
$user_authority = 3; // VIP
}*/
if ($user_authority < 3) { /* set posting flags for mods and admins */
if (isset($_POST['displaystaffstatus'])) $flags .= 'D';
if (isset($_POST['lockonpost'])) $flags .= 'L';
if (isset($_POST['stickyonpost'])) $flags .= 'S';
if (isset($_POST['rawhtml'])) $flags .= 'RH';
if (isset($_POST['usestaffname'])) $flags .= 'N';
}
}
}
return array($user_authority, $flags);
}
function CheckBadUnicode($post_name, $post_email, $post_subject, $post_message) {
/* Check for bad characters which can cause the page to deform (right-to-left markers, etc) */
$bad_ords = array(8235, 8238);
$ords_name = unistr_to_ords($post_name);
$ords_email = unistr_to_ords($post_email);
$ords_subject = unistr_to_ords($post_subject);
$ords_message = unistr_to_ords($post_message);
$ords_filename = isset($_FILES['imagefile']) ? unistr_to_ords($_FILES['imagefile']['name']) : '';
foreach ($bad_ords as $bad_ord) {
if ($ords_name != '') {
if (in_array($bad_ord, $ords_name)) {
exitWithErrorPage(_gettext('Your post contains one or more illegal characters.'));
}
}
if ($ords_email != '') {
if (in_array($bad_ord, $ords_email)) {
exitWithErrorPage(_gettext('Your post contains one or more illegal characters.'));
}
}
if ($ords_subject != '') {
if (in_array($bad_ord, $ords_subject)) {
exitWithErrorPage(_gettext('Your post contains one or more illegal characters.'));
}
}
if ($ords_message != '') {
if (in_array($bad_ord, $ords_message)) {
exitWithErrorPage(_gettext('Your post contains one or more illegal characters.'));
}
}
if ($ords_filename != '') {
if (in_array($bad_ord, $ords_filename)) {
exitWithErrorPage(_gettext('Your post contains one or more illegal characters.'));
}
}
}
}
function GetPostTag() {
global $board_class;
/* Check for and parse tags if one was provided, and they are enabled */
$post_tag = '';
$tags = unserialize(KU_TAGS);
if ($board_class->board['type'] == 3 && $tags != '' && isset($_POST['tag'])) {
if ($_POST['tag'] != '') {
$validtag = false;
while (list($tag, $tag_abbr) = each($tags)) {
if ($tag_abbr == $_POST['tag']) {
$validtag = true;
}
}
if ($validtag) {
$post_tag = $_POST['tag'];
}
}
}
return $post_tag;
}
function CheckBlacklistedText() {
global $bans_class, $tc_db;
$badlinks = array_map('rtrim', file(KU_ROOTDIR . 'spam.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES));
foreach ($badlinks as $badlink) {
if (stripos($_POST['message'], $badlink) !== false) {
/* They included a blacklisted link in their post. Ban them for an hour */
$bans_class->BanUser($_SERVER['REMOTE_ADDR'], 'board.php', 1, 3600, '', $tc_db->qstr(_gettext('Posting a blacklisted link.') . ' (' . $badlink . ')'), $tc_db->qstr($_POST['message']));
exitWithErrorPage(sprintf(_gettext('Blacklisted link ( %s ) detected.'), $badlink));
}
}
}
}
?>
+98
View File
@@ -0,0 +1,98 @@
<?php
/*
* This file is part of kusaba.
*
* kusaba is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* kusaba is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* kusaba; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/***************************************************************************
*
* Author : Eric Sizemore ( www.secondversion.com & www.phpsociety.com )
* Package : Random Word
* Version : 1.0.1
* Copyright: (C) 2006 - 2007 Eric Sizemore
* Site : www.secondversion.com & www.phpsociety.com
* Email : esizemore05@gmail.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
***************************************************************************/
// Slightly inspired by class randomWord by kumar mcmillan
class Rand_Word {
var $vowels = array('a','e','i','o','u');
var $consonants = array('b','c','d','f','g','h','j','k','l','m','n','p','r','s','t','v','w','z','ch','qu','th','xy');
var $word = '';
/**
* Constructor.
*
* @param integer Length of the word
* @param boolean Return the word lowercase?
* @param boolean Reutrn the word with the first letter capitalized?
* @param boolean Return the word uppercase?
* @return string
*/
function rand_word($length = 5, $lower_case = true, $ucfirst = false, $upper_case = false)
{
$done = false;
$const_or_vowel = 1;
while (!$done)
{
switch ($const_or_vowel)
{
case 1:
$this->word .= $this->consonants[array_rand($this->consonants)];
$const_or_vowel = 2;
break;
case 2:
$this->word .= $this->vowels[array_rand($this->vowels)];
$const_or_vowel = 1;
break;
}
if (strlen($this->word) >= $length)
{
$done = true;
}
}
$this->word = substr($this->word, 0, $length);
if ($lower_case)
{
$this->word = strtolower($this->word);
}
else if ($ucfirst)
{
$this->word = ucfirst(strtolower($this->word));
}
else if ($upper_case)
{
$this->word = strtoupper($this->word);
}
return $this->word;
}
}
?>
+50
View File
@@ -0,0 +1,50 @@
<?php
/*
* This file is part of kusaba.
*
* kusaba is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* kusaba is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* kusaba; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* +------------------------------------------------------------------------------+
* RSS class
* +------------------------------------------------------------------------------+
* Generates latest posts RSS, as well as ModLog RSS
* +------------------------------------------------------------------------------+
*/
class RSS {
function GenerateRSS($rssboard, $rssboardid) {
if (isset($rssboard)) {
global $tc_db;
require_once KU_ROOTDIR.'lib/dwoo.php';
$dwoo = new Dwoo();
$dwoo_data = new Dwoo_Data();
$posts = $tc_db->GetAll("SELECT * FROM `".KU_DBPREFIX."posts` WHERE `boardid` = " . $rssboardid . " AND `IS_DELETED` = '0' ORDER BY `id` DESC LIMIT 15");
$dwoo_data->assign('posts', $posts);
$dwoo_data->assign('boardname', $rssboard);
$rss = $dwoo->get(KU_TEMPLATEDIR . '/rss_board.tpl', $dwoo_data);
}
return $rss;
}
function GenerateModLogRSS() {
global $tc_db;
require_once KU_ROOTDIR.'lib/dwoo.php';
$dwoo = new Dwoo();
$dwoo_data = new Dwoo_Data();
$entries = $tc_db->GetAll("SELECT * FROM `".KU_DBPREFIX."modlog` ORDER BY `timestamp` DESC LIMIT 15");
$dwoo_data->assign('entries', $entries);
$rss = $dwoo->get(KU_TEMPLATEDIR . '/rss_mod.tpl', $dwoo_data);
return($rss);
}
}
?>
+51
View File
@@ -0,0 +1,51 @@
<?php
/*
* This file is part of kusaba.
*
* kusaba is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* kusaba is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* kusaba; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* +------------------------------------------------------------------------------+
* SVG parsing class
* +------------------------------------------------------------------------------+
*/
class Svg {
var $width = 0;
var $height = 0;
var $id = '';
var $version = '';
var $namespaces;
var $docname = '';
var $docbase = '';
var $sodipodiversion = '';
var $inkscapeversion = '';
var $output_extension = '';
function Svg($svg){
$xml = new SimpleXMLElement($svg,1,1);
$this->width = (string) $xml['width'];
$this->height = (string) $xml['height'];
$this->id = (string) $xml['id'];
$this->version = (string) $xml['version'];
$this->namespaces = $xml->getNamespaces();
$sodipodi = $xml->attributes($this->namespaces['sodipodi']);
$this->docname = (string) $sodipodi['docname'];
$this->docbase = (string) $sodipodi['docbase'];
$this->sodipodiversion = (string) $sodipodi['version'];
$inkscape = $xml->attributes($this->namespaces['inkscape']);
$this->inkscapeversion = (string) $inkscape['version'];
$this->output_extension = (string) $inkscape['ouput_extension'];
}
}
?>
+407
View File
@@ -0,0 +1,407 @@
<?php
/*
* This file is part of kusaba.
*
* kusaba is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* kusaba is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* kusaba; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* +------------------------------------------------------------------------------+
* Upload class
* +------------------------------------------------------------------------------+
* Used for image/misc file upload through the post form on board/thread pages
* +------------------------------------------------------------------------------+
*/
class Upload {
var $file_name = '';
var $original_file_name = '';
var $file_type = '';
var $file_md5 = '';
var $file_location = '';
var $file_thumb_location = '';
var $file_is_special = false;
var $imgWidth = 0;
var $imgHeight = 0;
var $file_size = 0;
var $imgWidth_thumb = 0;
var $imgHeight_thumb = 0;
var $isreply = false;
function HandleUpload() {
global $tc_db, $board_class, $is_oekaki, $oekaki;
if (!$is_oekaki) {
if ($board_class->board['type'] == 0 || $board_class->board['type'] == 2 || $board_class->board['type'] == 3) {
$imagefile_name = isset($_FILES['imagefile']) ? $_FILES['imagefile']['name'] : '';
if ($imagefile_name != '') {
if (strpos($_FILES['imagefile']['name'], ',') != false) {
exitWithErrorPage(_gettext('Please select only one image to upload.'));
}
if ($_FILES['imagefile']['size'] > $board_class->board['maximagesize']) {
exitWithErrorPage(sprintf(_gettext('Please make sure your file is smaller than %dB'), $board_class->board['maximagesize']));
}
switch ($_FILES['imagefile']['error']) {
case UPLOAD_ERR_OK:
break;
case UPLOAD_ERR_INI_SIZE:
exitWithErrorPage(sprintf(_gettext('The uploaded file exceeds the upload_max_filesize directive (%s) in php.ini.')), ini_get('upload_max_filesize'));
break;
case UPLOAD_ERR_FORM_SIZE:
exitWithErrorPage(sprintf(_gettext('Please make sure your file is smaller than %dB'), $board_class->board['maximagesize']));
break;
case UPLOAD_ERR_PARTIAL:
exitWithErrorPage(_gettext('The uploaded file was only partially uploaded.'));
break;
case UPLOAD_ERR_NO_FILE:
exitWithErrorPage(_gettext('No file was uploaded.'));
break;
case UPLOAD_ERR_NO_TMP_DIR:
exitWithErrorPage(_gettext('Missing a temporary folder.'));
break;
case UPLOAD_ERR_CANT_WRITE:
exitWithErrorPage(_gettext('Failed to write file to disk'));
break;
default:
exitWithErrorPage(_gettext('Unknown File Error'));
}
$this->file_type = preg_replace('/.*(\..+)/','\1',$_FILES['imagefile']['name']);
if ($this->file_type == '.jpeg') {
/* Fix for the rarely used 4-char format */
$this->file_type = '.jpg';
}
$pass = true;
if (!is_file($_FILES['imagefile']['tmp_name']) || !is_readable($_FILES['imagefile']['tmp_name'])) {
$pass = false;
} else {
if ($this->file_type == '.jpg' || $this->file_type == '.gif' || $this->file_type == '.png') {
if (!@getimagesize($_FILES['imagefile']['tmp_name'])) {
$pass = false;
}
}
}
if (!$pass) {
exitWithErrorPage(_gettext('File transfer failure. Please go back and try again.'));
}
$this->file_name = substr(htmlspecialchars(preg_replace('/(.*)\..+/','\1',$_FILES['imagefile']['name']), ENT_QUOTES), 0, 50);
$this->file_name = str_replace('.','_',$this->file_name);
$this->original_file_name = $this->file_name;
$this->file_md5 = md5_file($_FILES['imagefile']['tmp_name']);
$exists_thread = checkMd5($this->file_md5, $board_class->board['name'], $board_class->board['id']);
if (is_array($exists_thread)) {
exitWithErrorPage(_gettext('Duplicate file entry detected.'), sprintf(_gettext('Already posted %shere%s.'),'<a href="' . KU_BOARDSPATH . '/' . $board_class->board['name'] . '/res/' . $exists_thread[0] . '.html#' . $exists_thread[1] . '">','</a>'));
}
if (strtolower($this->file_type) == 'svg') {
require_once 'svg.class.php';
$svg = new Svg($_FILES['imagefile']['tmp_name']);
$this->imgWidth = $svg->width;
$this->imgHeight = $svg->height;
} else {
$imageDim = getimagesize($_FILES['imagefile']['tmp_name']);
$this->imgWidth = $imageDim[0];
$this->imgHeight = $imageDim[1];
}
$this->file_type = strtolower($this->file_type);
$this->file_size = $_FILES['imagefile']['size'];
$filetype_forcethumb = $tc_db->GetOne("SELECT " . KU_DBPREFIX . "filetypes.force_thumb FROM " . KU_DBPREFIX . "boards, " . KU_DBPREFIX . "filetypes, " . KU_DBPREFIX . "board_filetypes WHERE " . KU_DBPREFIX . "boards.id = " . KU_DBPREFIX . "board_filetypes.boardid AND " . KU_DBPREFIX . "filetypes.id = " . KU_DBPREFIX . "board_filetypes.typeid AND " . KU_DBPREFIX . "boards.name = '" . $board_class->board['name'] . "' and " . KU_DBPREFIX . "filetypes.filetype = '" . substr($this->file_type, 1) . "';");
if ($filetype_forcethumb != '') {
if ($filetype_forcethumb == 0) {
$this->file_name = time() . mt_rand(1, 99);
/* If this board has a load balance url and password configured for it, attempt to use it */
if ($board_class->board['loadbalanceurl'] != '' && $board_class->board['loadbalancepassword'] != '') {
require_once KU_ROOTDIR . 'inc/classes/loadbalancer.class.php';
$loadbalancer = new Load_Balancer;
$loadbalancer->url = $board_class->board['loadbalanceurl'];
$loadbalancer->password = $board_class->board['loadbalancepassword'];
$response = $loadbalancer->Send('thumbnail', base64_encode(file_get_contents($_FILES['imagefile']['tmp_name'])), 'src/' . $this->file_name . $this->file_type, 'thumb/' . $this->file_name . 's' . $this->file_type, 'thumb/' . $this->file_name . 'c' . $this->file_type, '', $this->isreply, true);
if ($response != 'failure' && $response != '') {
$response_unserialized = unserialize($response);
$this->imgWidth_thumb = $response_unserialized['imgw_thumb'];
$this->imgHeight_thumb = $response_unserialized['imgh_thumb'];
$imageused = true;
} else {
exitWithErrorPage(_gettext('File was not properly thumbnailed').': ' . $response);
}
/* Otherwise, use this script alone */
} else {
$this->file_location = KU_BOARDSDIR . $board_class->board['name'] . '/src/' . $this->file_name . $this->file_type;
$this->file_thumb_location = KU_BOARDSDIR . $board_class->board['name'] . '/thumb/' . $this->file_name . 's' . $this->file_type;
$this->file_thumb_cat_location = KU_BOARDSDIR . $board_class->board['name'] . '/thumb/' . $this->file_name . 'c' . $this->file_type;
if (!move_uploaded_file($_FILES['imagefile']['tmp_name'], $this->file_location)) {
exitWithErrorPage(_gettext('Could not copy uploaded image.'));
}
chmod($this->file_location, 0644);
if ($_FILES['imagefile']['size'] == filesize($this->file_location)) {
if ((!$this->isreply && ($this->imgWidth > KU_THUMBWIDTH || $this->imgHeight > KU_THUMBHEIGHT)) || ($this->isreply && ($this->imgWidth > KU_REPLYTHUMBWIDTH || $this->imgHeight > KU_REPLYTHUMBHEIGHT))) {
if (!$this->isreply) {
if (!createThumbnail($this->file_location, $this->file_thumb_location, KU_THUMBWIDTH, KU_THUMBHEIGHT)) {
exitWithErrorPage(_gettext('Could not create thumbnail.'));
}
} else {
if (!createThumbnail($this->file_location, $this->file_thumb_location, KU_REPLYTHUMBWIDTH, KU_REPLYTHUMBHEIGHT)) {
exitWithErrorPage(_gettext('Could not create thumbnail.'));
}
}
} else {
if (!createThumbnail($this->file_location, $this->file_thumb_location, $this->imgWidth, $this->imgHeight)) {
exitWithErrorPage(_gettext('Could not create thumbnail.'));
}
}
if (!createThumbnail($this->file_location, $this->file_thumb_cat_location, KU_CATTHUMBWIDTH, KU_CATTHUMBHEIGHT)) {
exitWithErrorPage(_gettext('Could not create thumbnail.'));
}
$imageDim_thumb = getimagesize($this->file_thumb_location);
$this->imgWidth_thumb = $imageDim_thumb[0];
$this->imgHeight_thumb = $imageDim_thumb[1];
$imageused = true;
} else {
exitWithErrorPage(_gettext('File was not fully uploaded. Please go back and try again.'));
}
}
} else {
/* Fetch the mime requirement for this special filetype */
$filetype_required_mime = $tc_db->GetOne("SELECT `mime` FROM `" . KU_DBPREFIX . "filetypes` WHERE `filetype` = " . $tc_db->qstr(substr($this->file_type, 1)));
$this->file_name = htmlspecialchars_decode($this->file_name, ENT_QUOTES);
$this->file_name = stripslashes($this->file_name);
$this->file_name = str_replace("\x80", " ", $this->file_name);
$this->file_name = str_replace(' ', '_', $this->file_name);
$this->file_name = str_replace('#', '(number)', $this->file_name);
$this->file_name = str_replace('@', '(at)', $this->file_name);
$this->file_name = str_replace('/', '(fwslash)', $this->file_name);
$this->file_name = str_replace('\\', '(bkslash)', $this->file_name);
/* If this board has a load balance url and password configured for it, attempt to use it */
if ($board_class->board['loadbalanceurl'] != '' && $board_class->board['loadbalancepassword'] != '') {
require_once KU_ROOTDIR . 'inc/classes/loadbalancer.class.php';
$loadbalancer = new Load_Balancer;
$loadbalancer->url = $board_class->board['loadbalanceurl'];
$loadbalancer->password = $board_class->board['loadbalancepassword'];
if ($filetype_required_mime != '') {
$checkmime = $filetype_required_mime;
} else {
$checkmime = '';
}
$response = $loadbalancer->Send('direct', $_FILES['imagefile']['tmp_name'], 'src/' . $this->file_name . $this->file_type, '', '', $checkmime, false, true);
$this->file_is_special = true;
/* Otherwise, use this script alone */
} else {
$this->file_location = KU_BOARDSDIR . $board_class->board['name'] . '/src/' . $this->file_name . $this->file_type;
if($this->file_type == '.mp3') {
require_once(KU_ROOTDIR . 'lib/getid3/getid3.php');
$getID3 = new getID3;
$getID3->analyze($_FILES['imagefile']['tmp_name']);
if (isset($getID3->info['id3v2']['APIC'][0]['data']) && isset($getID3->info['id3v2']['APIC'][0]['image_mime'])) {
$source_data = $getID3->info['id3v2']['APIC'][0]['data'];
$mime = $getID3->info['id3v2']['APIC'][0]['image_mime'];
}
elseif (isset($getID3->info['id3v2']['PIC'][0]['data']) && isset($getID3->info['id3v2']['PIC'][0]['image_mime'])) {
$source_data = $getID3->info['id3v2']['PIC'][0]['data'];
$mime = $getID3->info['id3v2']['PIC'][0]['image_mime'];
}
if($source_data) {
$im = imagecreatefromstring($source_data);
if (preg_match("/png/", $mime)) {
$ext = ".png";
imagepng($im,$this->file_location.".tmp",0,PNG_ALL_FILTERS);
} else if (preg_match("/jpg|jpeg/", $mime)) {
$ext = ".jpg";
imagejpeg($im, $this->file_location.".tmp");
} else if (preg_match("/gif/", $mime)) {
$ext = ".gif";
imagegif($im, $this->file_location.".tmp");
}
$this->file_thumb_location = KU_BOARDSDIR . $board_class->board['name'] . '/thumb/' . $this->file_name .'s'. $ext;
if (!$this->isreply) {
if (!createThumbnail($this->file_location.".tmp", $this->file_thumb_location, KU_THUMBWIDTH, KU_THUMBHEIGHT)) {
exitWithErrorPage(_gettext('Could not create thumbnail.'));
}
} else {
if (!createThumbnail($this->file_location.".tmp", $this->file_thumb_location, KU_REPLYTHUMBWIDTH, KU_REPLYTHUMBHEIGHT)) {
exitWithErrorPage(_gettext('Could not create thumbnail.'));
}
}
$imageDim_thumb = getimagesize($this->file_thumb_location);
$this->imgWidth_thumb = $imageDim_thumb[0];
$this->imgHeight_thumb = $imageDim_thumb[1];
$imageused = true;
unlink($this->file_location.".tmp");
}
}
/* Move the file from the post data to the server */
if (!move_uploaded_file($_FILES['imagefile']['tmp_name'], $this->file_location)) {
exitWithErrorPage(_gettext('Could not copy uploaded image.'));
}
/* Check if the filetype provided comes with a MIME restriction */
if ($filetype_required_mime != '') {
/* Check if the MIMEs don't match up */
if (mime_content_type($this->file_location) != $filetype_required_mime) {
/* Delete the file we just uploaded and kill the script */
unlink($this->file_location);
exitWithErrorPage(_gettext('Invalid MIME type for this filetype.'));
}
}
/* Make sure the entire file was uploaded */
if ($_FILES['imagefile']['size'] == filesize($this->file_location)) {
$imageused = true;
} else {
exitWithErrorPage(_gettext('File transfer failure. Please go back and try again.'));
}
/* Flag that the file used isn't an internally supported type */
$this->file_is_special = true;
}
}
} else {
exitWithErrorPage(_gettext('Sorry, that filetype is not allowed on this board.'));
}
} elseif (isset($_POST['embed'])) {
if ($_POST['embed'] != '') {
$_POST['embed'] = strip_tags(substr($_POST['embed'], 0, 20));
$video_id = $_POST['embed'];
$this->file_name = $video_id;
if ($video_id != '' && strpos($video_id, '@') == false && strpos($video_id, '&') == false) {
$embeds = $tc_db->GetAll("SELECT HIGH_PRIORITY * FROM `" . KU_DBPREFIX . "embeds`");
$worked = false;
foreach ($embeds as $line) {
if ((strtolower($_POST['embedtype']) == strtolower($line['name'])) && in_array($line['filetype'], explode(',', $board_class->board['embeds_allowed']))) {
$worked = true;
$videourl_start = $line['videourl'];
$this->file_type = '.' . strtolower($line['filetype']);
}
}
if (!$worked) {
exitWithErrorPage(_gettext('Invalid video type.'));
}
$results = $tc_db->GetOne("SELECT COUNT(*) FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $board_class->board['id'] . " AND `file` = " . $tc_db->qstr($video_id) . " AND `IS_DELETED` = 0");
if ($results[0] == 0) {
$video_check = check_link($videourl_start . $video_id);
switch ($video_check[1]) {
case 404:
exitWithErrorPage(_gettext('Unable to connect to') .': '. $videourl_start . $video_id);
break;
case 303:
exitWithErrorPage(_gettext('Invalid video ID.'));
break;
case 302:
// Continue
break;
case 301:
// Continue
break;
case 200:
// Continue
break;
default:
exitWithErrorPage(_gettext('Invalid response code ') .':'. $video_check[1]);
break;
}
} else {
$results = $tc_db->GetAll("SELECT `id`,`parentid` FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` = " . $board_class->board['id'] . " AND `file` = " . $tc_db->qstr($video_id) . " AND `IS_DELETED` = 0 LIMIT 1");
foreach ($results as $line) {
$real_threadid = ($line[1] == 0) ? $line[0] : $line[1];
exitWithErrorPage(sprintf(_gettext('That video ID has already been posted %shere%s.'),'<a href="' . KU_BOARDSFOLDER . '/' . $board_class->board['name'] . '/res/' . $real_threadid . '.html#' . $line[1] . '">','</a>'));
}
}
} else {
exitWithErrorPage(_gettext('Invalid ID'));
}
}
}
}
} else {
$this->file_name = time() . mt_rand(1, 99);
$this->original_file_name = $this->file_name;
$this->file_md5 = md5_file($oekaki);
$this->file_type = '.png';
$this->file_size = filesize($oekaki);
$imageDim = getimagesize($oekaki);
$this->imgWidth = $imageDim[0];
$this->imgHeight = $imageDim[1];
if (!copy($oekaki, KU_BOARDSDIR . $board_class->board['name'] . '/src/' . $this->file_name . $this->file_type)) {
exitWithErrorPage(_gettext('Could not copy uploaded image.'));
}
$oekaki_animation = substr($oekaki, 0, -4) . '.pch';
if (file_exists($oekaki_animation)) {
if (!copy($oekaki_animation, KU_BOARDSDIR . $board_class->board['name'] . '/src/' . $this->file_name . '.pch')) {
exitWithErrorPage(_gettext('Could not copy animation.'));
}
unlink($oekaki_animation);
}
$thumbpath = KU_BOARDSDIR . $board_class->board['name'] . '/thumb/' . $this->file_name . 's' . $this->file_type;
$thumbpath_cat = KU_BOARDSDIR . $board_class->board['name'] . '/thumb/' . $this->file_name . 'c' . $this->file_type;
if (
(!$this->isreply && ($this->imgWidth > KU_THUMBWIDTH || $this->imgHeight > KU_THUMBHEIGHT)) ||
($this->isreply && ($this->imgWidth > KU_REPLYTHUMBWIDTH || $this->imgHeight > KU_REPLYTHUMBHEIGHT))
) {
if (!$this->isreply) {
if (!createThumbnail($oekaki, $thumbpath, KU_THUMBWIDTH, KU_THUMBHEIGHT)) {
exitWithErrorPage(_gettext('Could not create thumbnail.'));
}
} else {
if (!createThumbnail($oekaki, $thumbpath, KU_REPLYTHUMBWIDTH, KU_REPLYTHUMBHEIGHT)) {
exitWithErrorPage(_gettext('Could not create thumbnail.'));
}
}
} else {
if (!createThumbnail($oekaki, $thumbpath, $this->imgWidth, $this->imgHeight)) {
exitWithErrorPage(_gettext('Could not create thumbnail.'));
}
}
if (!createThumbnail($oekaki, $thumbpath_cat, KU_CATTHUMBWIDTH, KU_CATTHUMBHEIGHT)) {
exitWithErrorPage(_gettext('Could not create thumbnail.'));
}
$imgDim_thumb = getimagesize($thumbpath);
$this->imgWidth_thumb = $imgDim_thumb[0];
$this->imgHeight_thumb = $imgDim_thumb[1];
unlink($oekaki);
}
}
}
?>