コード例 #1
0
ファイル: board.php プロジェクト: stormeus/Kusaba-Z
            }
        }
        $tc_db->Execute("COMMIT");
        // Trim any threads which have been pushed past the limit, or exceed the maximum age limit
        TrimToPageLimit($board_class->board);
        // Regenerate board pages
        $board_class->RegeneratePages();
        if ($thread_replyto == '0') {
            // Regenerate the thread
            $board_class->RegenerateThreads($post_id);
        } else {
            // Regenerate the thread
            $board_class->RegenerateThreads($thread_replyto);
        }
    } else {
        exitWithErrorPage(_gettext('Sorry, this board is locked and can not be posted in.'));
    }
} elseif ((isset($_POST['deletepost']) || isset($_POST['reportpost']) || isset($_POST['moddelete']) || isset($_POST['edit'])) && isset($_POST['post'])) {
    $ismod = false;
    // Initialize the post class
    foreach ($_POST['post'] as $val) {
        $post_class = new Post($val, $board_class->board['name'], $board_class->board['id']);
        if (isset($_POST['reportpost'])) {
            // They clicked the Report button
            if ($board_class->board['enablereporting'] == 1) {
                $post_reported = $post_class->post['isreported'];
                if ($post_reported === 'cleared') {
                    echo _gettext('That post has been cleared as not requiring any deletion.') . '<br />';
                } elseif ($post_reported) {
                    echo _gettext('That post is already in the report list.') . '<br />';
                } else {
コード例 #2
0
ファイル: posts.php プロジェクト: nan0desu/xyntach
/**
 * Create a thumbnail
 *
 * @param string $name File to be thumbnailed
 * @param string $filename Path to place the thumbnail
 * @param integer $new_w Maximum width
 * @param integer $new_h Maximum height
 * @return boolean Success/fail
 */
function createThumbnail($name, $filename, $new_w, $new_h)
{
    if (KU_THUMBMETHOD == 'imagemagick') {
        $convert = 'convert ' . escapeshellarg($name);
        if (!KU_ANIMATEDTHUMBS) {
            $convert .= '[0] ';
        }
        $convert .= ' -resize ' . $new_w . 'x' . $new_h . ' -quality ';
        if (substr($filename, 0, -3) != 'gif') {
            $convert .= '70';
        } else {
            $convert .= '90';
        }
        $convert .= ' ' . escapeshellarg($filename);
        exec($convert);
        if (is_file($filename)) {
            return true;
        } else {
            return false;
        }
    } elseif (KU_THUMBMETHOD == 'gd') {
        $system = explode(".", $filename);
        $system = array_reverse($system);
        if (preg_match("/jpg|jpeg/", $system[0])) {
            $src_img = imagecreatefromjpeg($name);
        } else {
            if (preg_match("/png/", $system[0])) {
                $src_img = imagecreatefrompng($name);
            } else {
                if (preg_match("/gif/", $system[0])) {
                    $src_img = imagecreatefromgif($name);
                } else {
                    return false;
                }
            }
        }
        if (!$src_img) {
            exitWithErrorPage(_gettext('Unable to read uploaded file during thumbnailing.'), _gettext('A common cause for this is an incorrect extension when the file is actually of a different type.'));
        }
        $old_x = imageSX($src_img);
        $old_y = imageSY($src_img);
        if ($old_x > $old_y) {
            $percent = $new_w / $old_x;
        } else {
            $percent = $new_h / $old_y;
        }
        $thumb_w = round($old_x * $percent);
        $thumb_h = round($old_y * $percent);
        $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
        fastImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y, $system);
        if (preg_match("/png/", $system[0])) {
            if (!imagepng($dst_img, $filename, 0, PNG_ALL_FILTERS)) {
                echo 'unable to imagepng.';
                return false;
            }
        } else {
            if (preg_match("/jpg|jpeg/", $system[0])) {
                if (!imagejpeg($dst_img, $filename, 70)) {
                    echo 'unable to imagejpg.';
                    return false;
                }
            } else {
                if (preg_match("/gif/", $system[0])) {
                    if (!imagegif($dst_img, $filename)) {
                        echo 'unable to imagegif.';
                        return false;
                    }
                }
            }
        }
        imagedestroy($dst_img);
        imagedestroy($src_img);
        return true;
    }
    return false;
}
コード例 #3
0
ファイル: posting.class.php プロジェクト: stormeus/Kusaba-Z
 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, '', _gettext('Posting a blacklisted link.') . ' (' . $badlink . ')', $_POST['message']);
             exitWithErrorPage(sprintf(_gettext('Blacklisted link ( %s ) detected.'), $badlink));
         }
     }
 }
コード例 #4
0
ファイル: board-post.class.php プロジェクト: nan0desu/xyntach
 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);
         }
     }
 }
コード例 #5
0
ファイル: manage.class.php プロジェクト: stormeus/Kusaba-Z
    function deletepostsbyip($from_ban = false)
    {
        global $tc_db, $tpl_page, $board_class;
        $this->ModeratorsOnly();
        if (!$from_ban) {
            $tpl_page .= '<h2>' . _gettext('Delete all posts by IP') . '</h2><br />';
        }
        if (isset($_POST['ip']) || isset($_POST['multiban'])) {
            if ($_POST['ip'] != '' || !empty($_POST['multiban'])) {
                $deletion_boards = array();
                $deletion_new_boards = array();
                $board_ids = '';
                if (isset($_POST['banfromall'])) {
                    $results = $tc_db->GetAll("SELECT HIGH_PRIORITY `id`, `name` FROM `" . KU_DBPREFIX . "boards`");
                    foreach ($results as $line) {
                        if (!$this->CurrentUserIsModeratorOfBoard($line['name'], $_SESSION['manageusername'])) {
                            exitWithErrorPage('/' . $line['name'] . '/: ' . _gettext('You can only delete posts from boards you moderate.'));
                        }
                        $delete_boards[$line['id']] = $line['name'];
                        $board_ids .= $line['id'] . ',';
                    }
                } else {
                    if (empty($_POST['deletefrom'])) {
                        exitWithErrorPage(_gettext('Please select a board.'));
                    }
                    foreach ($_POST['deletefrom'] as $board) {
                        if (!$this->CurrentUserIsModeratorOfBoard($board, $_SESSION['manageusername'])) {
                            exitWithErrorPage('/' . $board . '/: ' . _gettext('You can only delete posts from boards you moderate.'));
                        }
                        $id = $tc_db->GetOne("SELECT `id` FROM `" . KU_DBPREFIX . "boards` WHERE `name` = " . $tc_db->qstr($board));
                        $board_ids .= $tc_db->qstr($id) . ',';
                        $delete_boards[$id] = $board;
                    }
                }
                $board_ids = substr($board_ids, 0, -1);
                $i = 0;
                if (isset($_POST['multiban'])) {
                    $ips = unserialize($_POST['multiban']);
                } else {
                    $ips = array($_POST['ip']);
                }
                foreach ($ips as $ip) {
                    $i = 0;
                    $post_list = $tc_db->GetAll("SELECT `id`, `boardid` FROM `" . KU_DBPREFIX . "posts` WHERE `boardid` IN (" . $board_ids . ") AND `IS_DELETED` = '0' AND `ipmd5` = '" . md5($ip) . "'");
                    if (count($post_list) > 0) {
                        foreach ($post_list as $post) {
                            $i++;
                            $post_class = new Post($post['id'], $delete_boards[$post['boardid']], $post['boardid']);
                            $post_class->Delete();
                            $boards_deleted[$post['boardid']] = $delete_boards[$post['boardid']];
                            unset($post_class);
                        }
                        $tpl_page .= _gettext('All threads/posts by that IP in selected boards successfully deleted.') . '<br /><strong>' . $i . '</strong> posts were removed.<br />';
                        management_addlogentry(_gettext('Deleted posts by ip') . ' ' . $ip, 7);
                    } else {
                        $tpl_page .= _gettext('No posts for that IP found');
                    }
                    if (isset($boards_deleted)) {
                        foreach ($boards_deleted as $board) {
                            $board_class = new Board($board);
                            $board_class->RegenerateAll();
                            unset($board_class);
                        }
                    }
                }
                $tpl_page .= '<hr />';
            }
        }
        if (!$from_ban) {
            $tpl_page .= '<form action="?action=deletepostsbyip" method="post">

			<fieldset><legend>IP</legend>
			<label for="ip">' . _gettext('IP') . ':</label>
			<input type="text" id="ip" name="ip"';
            if (isset($_GET['ip'])) {
                $tpl_page .= ' value="' . $_GET['ip'] . '"';
            }
            $tpl_page .= ' /></fieldset><br /><fieldset>
			<legend>' . _gettext('Boards') . '</legend>

			<label for="banfromall"><strong>' . _gettext('All boards') . '</strong></label>
			<input type="checkbox" id="banfromall" name="banfromall" /><br /><hr /><br />' . $this->MakeBoardListCheckboxes('deletefrom', $this->BoardList($_SESSION['manageusername'])) . '<br /></fieldset>

			<input type="submit" value="' . _gettext('Delete posts') . '" />

			</form>';
        }
    }
コード例 #6
0
ファイル: posting.php プロジェクト: D4rk4/Kusaba-z
 public function doUpload(&$postData, $board)
 {
     $uploadClass = $this->environment->get('kx:classes:board:upload:id');
     @mkdir(KX_BOARD . '/' . $board->board_name, 0777, true);
     @mkdir(KX_BOARD . '/' . $board->board_name . '/src/', 0777, true);
     @mkdir(KX_BOARD . '/' . $board->board_name . '/thumb/', 0777, true);
     @mkdir(KX_BOARD . '/' . $board->board_name . '/res/', 0777, true);
     if (!isset($this->request['nofile']) && $board->board_enable_no_file == 1 || $board->board_enable_no_file == 0) {
         $uploadClass->HandleUpload($postData, $board);
     }
     if (!$uploadClass->isvideo) {
         foreach ($uploadClass->files as $key => $file) {
             if (!file_exists(KX_BOARD . '/' . $board->board_name . '/src/' . $file['file_name'] . $file['file_type']) || !$file['file_is_special'] && !file_exists(KX_BOARD . '/' . $board->board_name . '/thumb/' . $file['file_name'] . 's' . $file['file_type'])) {
                 exitWithErrorPage(_gettext('Could not copy uploaded image.'));
             }
         }
     }
     if (isset($postData['is_oekaki']) && $postData['is_oekaki']) {
         if (file_exists(KX_BOARD . '/' . $board->board_name . '/src/' . $uploadClass->files[0]['file_name'] . '.pch')) {
             $postData['thread_info']['message'] .= '<br /><small><a href="' . KX_SCRIPT . '/animation.php?board=' . $board->board_name . '&amp;id=' . $uploadClass->files[0]['file_name'] . '">' . _gettext('View animation') . '</a></small>';
         }
     }
     return $uploadClass->files;
 }
コード例 #7
0
ファイル: upload.class.php プロジェクト: stormeus/Kusaba-Z
 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("€", " ", $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);
     }
 }