Minor code cleanup

This commit is contained in:
tslocum 2011-01-21 20:53:37 -08:00
parent b9c02d466e
commit 4d14cb7434
2 changed files with 16 additions and 43 deletions

View File

@ -111,12 +111,7 @@ function nameAndTripcode($name) {
function nameBlock($name, $tripcode, $email, $timestamp, $modposttext) { function nameBlock($name, $tripcode, $email, $timestamp, $modposttext) {
$output = '<span class="postername">'; $output = '<span class="postername">';
$output .= ($name == "" && $tripcode == "") ? "Anonymous" : $name;
if ($name == "" && $tripcode == "") {
$output .= "Anonymous";
} else {
$output .= $name;
}
if ($tripcode != "") { if ($tripcode != "") {
$output .= '</span><span class="postertrip">!' . $tripcode; $output .= '</span><span class="postertrip">!' . $tripcode;
@ -280,33 +275,24 @@ function checkDuplicateImage($hex) {
$hexmatches = postsByHex($hex); $hexmatches = postsByHex($hex);
if (count($hexmatches) > 0) { if (count($hexmatches) > 0) {
foreach ($hexmatches as $hexmatch) { foreach ($hexmatches as $hexmatch) {
if ($hexmatch["parent"] == "0") { fancyDie("Duplicate file uploaded. That file has already been posted <a href=\"res/" . (($hexmatch["parent"] == "0") ? $hexmatch["id"] : $hexmatch["parent"]) . ".html#" . $hexmatch["id"] . "\">here</a>.");
$goto = $hexmatch["id"];
} else {
$goto = $hexmatch["parent"];
}
fancyDie("Duplicate file uploaded. That file has already been posted <a href=\"res/" . $goto . ".html#" . $hexmatch["id"] . "\">here</a>.");
} }
} }
} }
function thumbnailDimensions($width, $height) { function thumbnailDimensions($width, $height) {
if ($width > 250 || $height > 250) { return ($width > 250 || $height > 250) ? array(250, 250) : array($width, $height);
return array(250, 250);
} else {
return array($width, $height);
}
} }
function createThumbnail($name, $filename, $new_w, $new_h) { function createThumbnail($name, $filename, $new_w, $new_h) {
$system = explode(".", $filename); $system = explode(".", $filename);
$system = array_reverse($system); $system = array_reverse($system);
if (preg_match("/jpg|jpeg/", $system[0])) { if (preg_match("/jpg|jpeg/", $system[0])) {
$src_img=imagecreatefromjpeg($name); $src_img = imagecreatefromjpeg($name);
} else if (preg_match("/png/", $system[0])) { } else if (preg_match("/png/", $system[0])) {
$src_img=imagecreatefrompng($name); $src_img = imagecreatefrompng($name);
} else if (preg_match("/gif/", $system[0])) { } else if (preg_match("/gif/", $system[0])) {
$src_img=imagecreatefromgif($name); $src_img = imagecreatefromgif($name);
} else { } else {
return false; return false;
} }
@ -316,11 +302,7 @@ function createThumbnail($name, $filename, $new_w, $new_h) {
} }
$old_x = imageSX($src_img); $old_x = imageSX($src_img);
$old_y = imageSY($src_img); $old_y = imageSY($src_img);
if ($old_x > $old_y) { $percent = ($old_x > $old_y) ? ($new_w / $old_x) : ($new_h / $old_y);
$percent = $new_w / $old_x;
} else {
$percent = $new_h / $old_y;
}
$thumb_w = round($old_x * $percent); $thumb_w = round($old_x * $percent);
$thumb_h = round($old_y * $percent); $thumb_h = round($old_y * $percent);

View File

@ -259,37 +259,28 @@ EOF;
} }
function rebuildIndexes() { function rebuildIndexes() {
$htmlposts = ""; $page = 0; $i = 0; $htmlposts = "";
$page = 0;
$i = 0;
$pages = ceil(countThreads() / 10) - 1; $pages = ceil(countThreads() / 10) - 1;
$threads = allThreads(); $threads = allThreads();
foreach ($threads as $thread) { foreach ($threads as $thread) {
$htmlreplies = array();
$replies = latestRepliesInThreadByID($thread['id']); $replies = latestRepliesInThreadByID($thread['id']);
foreach ($replies as $reply) {
$htmlreplies = array();
foreach ($replies as $reply) {
$htmlreplies[] = buildPost($reply, False); $htmlreplies[] = buildPost($reply, False);
} }
if (count($htmlreplies) == 3) {
$thread["omitted"] = (count(postsInThreadByID($thread['id'])) - 4);
} else {
$thread["omitted"] = 0;
}
$htmlposts .= buildPost($thread, False); $thread["omitted"] = (count($htmlreplies) == 3) ? (count(postsInThreadByID($thread['id'])) - 4) : 0;
$htmlposts .= implode("", array_reverse($htmlreplies)); $htmlposts .= buildPost($thread, False) . implode("", array_reverse($htmlreplies)) . "<br clear=\"left\">\n<hr>";
$htmlposts .= "<br clear=\"left\">\n" .
"<hr>";
$i += 1; $i += 1;
if ($i == 10) { if ($i == 10) {
$file = ($page == 0) ? "index.html" : $page . ".html"; $file = ($page == 0) ? "index.html" : $page . ".html";
writePage($file, buildPage($htmlposts, 0, $pages, $page)); writePage($file, buildPage($htmlposts, 0, $pages, $page));
$page += 1; $page += 1; $i = 0; $htmlposts = "";
$i = 0;
$htmlposts = "";
} }
} }