From 90a878f8ee0a01328d64593ed2122a2a95c56f83 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Tue, 24 Jun 2014 12:51:22 -0700 Subject: [PATCH] Add optional WebA and WebM support --- .gitignore | 1 + README.md | 19 +- css/burichan.css | 243 ++++++++++--------- css/futaba.css | 169 +++++++------ css/global.css | 16 +- imgboard.php | 220 ++++++++++++----- inc/database_flatfile.php | 94 ++++---- inc/database_mysql.php | 20 +- inc/database_sqlite.php | 22 +- inc/defines.php | 20 +- inc/flatfile/flatfile.php | 406 +++++++++++++++----------------- inc/flatfile/flatfile_utils.php | 65 ++--- inc/functions.php | 165 +++++++------ inc/html.php | 101 ++++---- settings.default.php | 4 +- video_overlay.png | Bin 0 -> 6480 bytes 16 files changed, 860 insertions(+), 705 deletions(-) create mode 100644 video_overlay.png diff --git a/.gitignore b/.gitignore index e61e79f..ca9eee4 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ settings.php .posts.lock .project .settings/ +.idea/ diff --git a/README.md b/README.md index 4fadeb1..91bbb9f 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,13 @@ TinyIB - A Lightweight and Efficient [Image Board](http://en.wikipedia.org/wiki/ **No database? No problem.** Store posts as text files for a portable set-up capable of running on virtually any PHP host. -For demos see [example installations](https://github.com/tslocum/TinyIB/wiki). [![githalytics.com alpha](https://cruel-carlota.pagodabox.com/5135372febbc40bacddbb13c1f0a8333 "githalytics.com")](http://githalytics.com/tslocum/TinyIB) +To allow new threads without requiring an image, see the [Text Board Mode](https://github.com/tslocum/TinyIB/wiki/Text-Board-Mode) page. + +For demos see the [TinyIB Installations](https://github.com/tslocum/TinyIB/wiki) page. [![githalytics.com alpha](https://cruel-carlota.pagodabox.com/5135372febbc40bacddbb13c1f0a8333 "githalytics.com")](http://githalytics.com/tslocum/TinyIB) Features ------------ + - GIF, JPG, PNG and WebA/WebM upload. - Reference links >>### - Delete post via password. - Management panel: @@ -30,6 +33,11 @@ Installing - `git clone git://github.com/tslocum/TinyIB.git ./` 4. Copy **settings.default.php** to **settings.php** 5. Configure **settings.php** + - To allow WebA/WebM upload: + - Ensure your web host is running Linux. + - Install [mediainfo](http://mediaarea.net/en/MediaInfo). On Ubuntu, run ``sudo apt-get install mediainfo``. + - Set ``TINYIB_WEBM`` to ``true``. + - To remove the play icon from thumbnails, delete or rename **video_overlay.png**. 6. [CHMOD](http://en.wikipedia.org/wiki/Chmod) write permissions to these directories: - ./ (the directory containing TinyIB) - ./src/ @@ -41,6 +49,15 @@ Installing - Directories will be verified to be writable. - The file index.html will be created containing the new image board. +Moderating +------------ + + 1. If you are not logged in already, log in to the management panel by clicking **[Manage]**. + 2. On the board, tick the checkbox next to the offending post. + 3. Scroll to the bottom of the page. + 4. Click **Delete** with the password field blank. + - From this page you are able to delete the post and/or ban the author. + Updating ------------ diff --git a/css/burichan.css b/css/burichan.css index 46db906..515f675 100644 --- a/css/burichan.css +++ b/css/burichan.css @@ -1,182 +1,215 @@ html, body { - font-size:12pt; - background:#EEF2FF; - color:#000000; + font-size: 12pt; + background: #EEF2FF; + color: #000000; } + a { - background:inherit; - color:#34345C; - text-decoration:none; - font-family:sans-serif; + background: inherit; + color: #34345C; + text-decoration: none; + font-family: sans-serif; } + a:visited { - background:inherit; - color:#34345C; - text-decoration:none; - font-family:sans-serif; + background: inherit; + color: #34345C; + text-decoration: none; + font-family: sans-serif; } + a:hover { - color:#DD0000; - background:inherit; - font-family:sans-serif; + color: #DD0000; + background: inherit; + font-family: sans-serif; } + .filesize a { - text-decoration:underline; + text-decoration: underline; } + .filesize a:visited { - text-decoration:underline; + text-decoration: underline; } + .adminbar { - background:inherit; + background: inherit; } + .logo { - clear:both; - text-align:center; - background:inherit; - font-size:24pt; - color:#AF0A0F; - width:100%; + clear: both; + text-align: center; + background: inherit; + font-size: 24pt; + color: #AF0A0F; + width: 100%; } + .replymode { - background:#0010E0; - color:#FFFFFF; - width:100%; + background: #0010E0; + color: #FFFFFF; + width: 100%; } + .manageinfo { - background:#00B930; - color:#FFFFFF; - width:100%; + background: #00B930; + color: #FFFFFF; + width: 100%; } + .catalogmode { - background:#0040E0; - color:#FFFFFF; - width:100%; + background: #0040E0; + color: #FFFFFF; + width: 100%; } + .postarea { - background:inherit; + background: inherit; } + .rules { /*font-size:0.7em;*/ width: 468px; font-size: 10px; font-family: sans-serif; } + .rules li { margin-left: 1em; /*text-indent: 0em;*/ } + .postblock { - background:#9988EE; - color:#000000; - font-weight:800; + background: #9988EE; + color: #000000; + font-weight: 800; } + .footer { - font-size:10px; - font-family:sans-serif; + font-size: 10px; + font-family: sans-serif; } + .passvalid { - background:#9988EE; - text-align:center; - width:100%; - color:#ffffff; + background: #9988EE; + text-align: center; + width: 100%; + color: #ffffff; } + .dellist { - background:inherit; - text-align:center; + background: inherit; + text-align: center; } + .delbuttons { - background:inherit; - text-align:center; - padding-bottom:4px; + background: inherit; + text-align: center; + padding-bottom: 4px; } + .managehead { - background:#0F8FE1; - color:#000000; - font-family:sans-serif; - font-size:14px; - padding:0px; + background: #0F8FE1; + color: #000000; + font-family: sans-serif; + font-size: 14px; + padding: 0px; } + .postlists { - background:#FFFFFF; - width:100%; - padding:0px; - color:#000000; + background: #FFFFFF; + width: 100%; + padding: 0px; + color: #000000; } + .row1 { - background:#9AD2F6; - font-family:sans-serif; - font-size:12px; - color:#000000; + background: #9AD2F6; + font-family: sans-serif; + font-size: 12px; + color: #000000; } + .row2 { - background:#FFFFFF; - font-family:sans-serif; - font-size:12px; - color:#000000; + background: #FFFFFF; + font-family: sans-serif; + font-size: 12px; + color: #000000; } + .unkfunc { - color:#789922; + color: #789922; } + .filesize { - font-size:12px; - font-family:sans-serif; - text-decoration:underline; + font-size: 12px; + font-family: sans-serif; + text-decoration: underline; /*padding-left:3em;*/ } + .filetitle { - background:inherit; - font-size:18px; - font-family:serif; - color:#0F0C5D; - font-weight:800; + background: inherit; + font-size: 18px; + font-family: serif; + color: #0F0C5D; + font-weight: 800; } + .postername { - background:inherit; - font-size:12px; - font-family:serif; - color:#117743; - font-weight:800; + background: inherit; + font-size: 12px; + font-family: serif; + color: #117743; + font-weight: 800; } + .oldpost { - background:inherit; - font-size:18px; - font-family:serif; - color:#0F0C5D; - font-weight:800; + background: inherit; + font-size: 18px; + font-family: serif; + color: #0F0C5D; + font-weight: 800; } + .omittedposts { - background:inherit; - font-size:18px; - font-family:serif; - color:#070707; - font-weight:800; + background: inherit; + font-size: 18px; + font-family: serif; + color: #070707; + font-weight: 800; } + .reply { - background:#D6DAF0; - color:#000000; - font-family:serif; + background: #D6DAF0; + color: #000000; + font-family: serif; } + .replyhl { background: #D6BAD0; color: #000000; } + .replytitle { - background:inherit; - font-size:18px; - font-family:serif; - color:#0F0C5D; - font-weight:800; + background: inherit; + font-size: 18px; + font-family: serif; + color: #0F0C5D; + font-weight: 800; } + .commentpostername { - background:inherit; - font-size:12px; - font-family:serif; - color:#117743; - font-weight:800; + background: inherit; + font-size: 12px; + font-family: serif; + color: #117743; + font-weight: 800; } + .thumbnailmsg { - background:inherit; - font-size:9px; - font-family:sans-serif; - color:#000000; + background: inherit; + font-size: 9px; + font-family: sans-serif; + color: #000000; } \ No newline at end of file diff --git a/css/futaba.css b/css/futaba.css index d7f17e3..fbd4008 100644 --- a/css/futaba.css +++ b/css/futaba.css @@ -1,151 +1,182 @@ html, body { - background:#FFFFEE; - color:#800000; + background: #FFFFEE; + color: #800000; } + a { - color:#0000EE; + color: #0000EE; } + a:hover { - color:#DD0000; + color: #DD0000; } -.reflink a:hover{ + +.reflink a:hover { font-weight: bold; } + .logo { - clear:both; - text-align:center; - font-size:2em; - color:#800000; - width:100%; + clear: both; + text-align: center; + font-size: 2em; + color: #800000; + width: 100%; } + .replymode { - background:#E04000; - text-align:center; - padding:2px; - color:#FFFFFF; - width:100%; + background: #E04000; + text-align: center; + padding: 2px; + color: #FFFFFF; + width: 100%; } + .manageinfo { - background:#00B930; - text-align:center; - padding:2px; - color:#FFFFFF; - width:100%; + background: #00B930; + text-align: center; + padding: 2px; + color: #FFFFFF; + width: 100%; } + .catalogmode { - background:#0040E0; - text-align:center; - padding:2px; - color:#FFFFFF; - width:100%; + background: #0040E0; + text-align: center; + padding: 2px; + color: #FFFFFF; + width: 100%; } + .rules { /*font-size:0.7em;*/ width: 468px; font-size: 10px; font-family: sans-serif; } + .rules li { margin-left: 1em; /*text-indent: 0em;*/ } + .postblock { - background:#EEAA88; - color:#800000; - font-weight:800; + background: #EEAA88; + color: #800000; + font-weight: 800; } + .footer { - font-size:12px; - font-family:serif; + font-size: 12px; + font-family: serif; } + .passvalid { - background:#EEAA88; - text-align:center; - width:100%; - color:#ffffff; + background: #EEAA88; + text-align: center; + width: 100%; + color: #ffffff; } + .dellist { font-weight: bold; - text-align:center; + text-align: center; } + .delbuttons { - text-align:center; - padding-bottom:4px; + text-align: center; + padding-bottom: 4px; } + .managehead { - background:#AAAA66; - color:#400000; - padding:0px; + background: #AAAA66; + color: #400000; + padding: 0px; } + .postlists { - background:#FFFFFF; - width:100%; - padding:0px; - color:#800000; + background: #FFFFFF; + width: 100%; + padding: 0px; + color: #800000; } + .row1 { - background:#EEEECC; - color:#800000; + background: #EEEECC; + color: #800000; } + .row2 { - background:#DDDDAA; - color:#800000; + background: #DDDDAA; + color: #800000; } + .unkfunc { - background:inherit; - color:#789922; + background: inherit; + color: #789922; } + .filesize { - text-decoration:none; + text-decoration: none; } + .filetitle { - background:inherit; - font-size:1.2em; - color:#CC1105; - font-weight:800; + background: inherit; + font-size: 1.2em; + color: #CC1105; + font-weight: 800; } + .postername { - color:#117743; - font-weight:bold; + color: #117743; + font-weight: bold; } + .postertrip { - color:#228854; + color: #228854; } + .oldpost { - color:#CC1105; - font-weight:800; + color: #CC1105; + font-weight: 800; } + .omittedposts { - color:#707070; + color: #707070; } + .reply { background: #F0E0D6; color: #800000; } + .replyhl { background: #F0C0B0; color: #800000; } + .replytitle { font-size: 1.2em; - color:#CC1105; - font-weight:800; + color: #CC1105; + font-weight: 800; } + .commentpostername { - color:#117743; - font-weight:800; + color: #117743; + font-weight: 800; } + .thumbnailmsg { font-size: small; - color:#800000; + color: #800000; } .abbrev { - color:#707070; + color: #707070; } + .highlight { - background:#F0E0D6; - color:#800000; + background: #F0E0D6; + color: #800000; border: 2px dashed #EEAA88; } \ No newline at end of file diff --git a/css/global.css b/css/global.css index b2ae048..6f018e4 100644 --- a/css/global.css +++ b/css/global.css @@ -22,9 +22,9 @@ form { } .aa { - white-space: pre; - text-align: left; - font-family: IPAMonaPGothic, Mona, 'MS PGothic', YOzFontAA97 !important; + white-space: pre; + text-align: left; + font-family: IPAMonaPGothic, Mona, 'MS PGothic', YOzFontAA97 !important; } .thumb { @@ -58,7 +58,7 @@ form { text-decoration: none; } -.reflink a:hover{ +.reflink a:hover { color: #800000; } @@ -73,7 +73,7 @@ form { } .doubledash { - vertical-align: top; + vertical-align: top; clear: both; float: left; font-size: 1.75em; @@ -91,7 +91,7 @@ form { .footer { clear: both; - text-align:center; + text-align: center; } .rules { @@ -118,4 +118,6 @@ form { float: right; } -.adminbar a:link, .adminbar a:visited, .adminbar a:active, .adminbar a:hover { text-decoration: none; } \ No newline at end of file +.adminbar a:link, .adminbar a:visited, .adminbar a:active, .adminbar a:hover { + text-decoration: none; +} \ No newline at end of file diff --git a/imgboard.php b/imgboard.php index e0257be..1071f8e 100644 --- a/imgboard.php +++ b/imgboard.php @@ -10,10 +10,16 @@ ob_implicit_flush(); ob_end_flush(); if (get_magic_quotes_gpc()) { - foreach ($_GET as $key => $val) { $_GET[$key] = stripslashes($val); } - foreach ($_POST as $key => $val) { $_POST[$key] = stripslashes($val); } + foreach ($_GET as $key => $val) { + $_GET[$key] = stripslashes($val); + } + foreach ($_POST as $key => $val) { + $_POST[$key] = stripslashes($val); + } +} +if (get_magic_quotes_runtime()) { + set_magic_quotes_runtime(0); } -if (get_magic_quotes_runtime()) { set_magic_quotes_runtime(0); } function fancyDie($message) { die('
' . $message . '


- Click here to go back -'); @@ -26,7 +32,9 @@ require 'settings.php'; // Check directories are writable by the script $writedirs = array("res", "src", "thumb"); -if (TINYIB_DBMODE == 'flatfile') { $writedirs[] = "inc/flatfile"; } +if (TINYIB_DBMODE == 'flatfile') { + $writedirs[] = "inc/flatfile"; +} foreach ($writedirs as $dir) { if (!is_writable($dir)) { fancyDie("Directory '" . $dir . "' can not be written to. Please modify its permissions."); @@ -58,12 +66,12 @@ if (isset($_POST['message']) || isset($_POST['file'])) { checkMessageSize(); checkFlood(); } - + $post = newPost(setParent()); $post['ip'] = $_SERVER['REMOTE_ADDR']; - + list($post['name'], $post['tripcode']) = nameAndTripcode($_POST['name']); - + $post['name'] = cleanString(substr($post['name'], 0, 75)); $post['email'] = cleanString(str_replace('"', '"', substr($_POST['email'], 0, 75))); $post['subject'] = cleanString(substr($_POST['subject'], 0, 75)); @@ -76,67 +84,141 @@ if (isset($_POST['message']) || isset($_POST['file'])) { } $post['password'] = ($_POST['password'] != '') ? md5(md5($_POST['password'])) : ''; $post['nameblock'] = nameBlock($post['name'], $post['tripcode'], $post['email'], time(), $rawposttext); - + if (isset($_FILES['file'])) { if ($_FILES['file']['name'] != "") { validateFileUpload(); - + if (!is_file($_FILES['file']['tmp_name']) || !is_readable($_FILES['file']['tmp_name'])) { fancyDie("File transfer failure. Please retry the submission."); } - + if ((TINYIB_MAXKB > 0) && (filesize($_FILES['file']['tmp_name']) > (TINYIB_MAXKB * 1024))) { fancyDie("That file is larger than " . TINYIB_MAXKBDESC . "."); } - - $post['file_original'] = htmlentities(substr($_FILES['file']['name'], 0, 50), ENT_QUOTES); + + $post['file_original'] = trim(htmlentities(substr($_FILES['file']['name'], 0, 50), ENT_QUOTES)); $post['file_hex'] = md5_file($_FILES['file']['tmp_name']); $post['file_size'] = $_FILES['file']['size']; $post['file_size_formatted'] = convertBytes($post['file_size']); - $file_type = strtolower(preg_replace('/.*(\..+)/', '\1', $_FILES['file']['name'])); if ($file_type == '.jpeg') { $file_type = '.jpg'; } - $file_name = time() . substr(microtime(), 2, 3); - $post['file'] = $file_name . $file_type; - $post['thumb'] = $file_name . "s" . $file_type; - $file_location = "src/" . $post['file']; - $thumb_location = "thumb/" . $post['thumb']; - - if (!($file_type == '.jpg' || $file_type == '.gif' || $file_type == '.png')) { - fancyDie("Only GIF, JPG, and PNG files are allowed."); + + $file_type = strtolower(preg_replace('/.*(\..+)/', '\1', $_FILES['file']['name'])); + if ($file_type == '.jpeg') { + $file_type = '.jpg'; } - - if (!@getimagesize($_FILES['file']['tmp_name'])) { - fancyDie("Failed to read the size of the uploaded file. Please retry the submission."); - } - $file_info = getimagesize($_FILES['file']['tmp_name']); - $file_mime = $file_info['mime']; - - if (!($file_mime == "image/jpeg" || $file_mime == "image/gif" || $file_mime == "image/png")) { - fancyDie("Only GIF, JPG, and PNG files are allowed."); + if ($file_type == '.weba') { + $file_type = '.webm'; } - checkDuplicateImage($post['file_hex']); - + $file_name = time() . substr(microtime(), 2, 3); + $post['file'] = $file_name . $file_type; + $post['thumb'] = $file_name . "s" . ($file_type == '.webm' ? '.jpg' : $file_type); + $file_location = "src/" . $post['file']; + $thumb_location = "thumb/" . $post['thumb']; + + checkDuplicateFile($post['file_hex']); + if (!move_uploaded_file($_FILES['file']['tmp_name'], $file_location)) { fancyDie("Could not copy uploaded file."); } - - if ($_FILES['file']['size'] != filesize($file_location)) { - fancyDie("File transfer failure. Please go back and try again."); - } - - $post['image_width'] = $file_info[0]; $post['image_height'] = $file_info[1]; - - list($thumb_maxwidth, $thumb_maxheight) = thumbnailDimensions($post); - - if (!createThumbnail($file_location, $thumb_location, $thumb_maxwidth, $thumb_maxheight)) { - fancyDie("Could not create thumbnail."); + + if ($file_type == '.webm') { + $file_mime_output = shell_exec('file --mime-type ' . $file_location); + $file_mime_split = explode(' ', $file_mime_output); + $file_mime = strtolower(trim(array_pop($file_mime_split))); + } else { + if (!@getimagesize($file_location)) { + @unlink($file_location); + fancyDie("Failed to read the size of the uploaded file. Please retry the submission."); + } + + $file_info = getimagesize($file_location); + $file_mime = $file_info['mime']; } - $thumb_info = getimagesize($thumb_location); - $post['thumb_width'] = $thumb_info[0]; $post['thumb_height'] = $thumb_info[1]; + if (!($file_mime == "image/jpeg" || $file_mime == "image/gif" || $file_mime == "image/png" || (TINYIB_WEBM && ($file_mime == "video/webm" || $file_mime == "audio/webm")))) { + @unlink($file_location); + fancyDie("Only " . (TINYIB_WEBM ? "GIF, JPG, PNG, and WEBM" : "GIF, JPG, and PNG") . " files are allowed."); + } + + if ($_FILES['file']['size'] != filesize($file_location)) { + @unlink($file_location); + fancyDie("File transfer failure. Please go back and try again."); + } + + if ($file_mime == "audio/webm" || $file_mime == "video/webm") { + $post['image_width'] = intval(shell_exec('mediainfo --Inform="Video;%Width%" ' . $file_location)); + $post['image_height'] = intval(shell_exec('mediainfo --Inform="Video;%Height%" ' . $file_location)); + + if ($post['image_width'] <= 0 || $post['image_height'] <= 0) { + $post['image_width'] = 0; + $post['image_height'] = 0; + + $file_location_old = $file_location; + $file_location = substr($file_location, 0, -1) . 'a'; // replace webm with weba + rename($file_location_old, $file_location); + + $post['file'] = substr($post['file'], 0, -1) . 'a'; // replace webm with weba + } + + if ($file_mime == "video/webm") { + list($thumb_maxwidth, $thumb_maxheight) = thumbnailDimensions($post); + shell_exec("ffmpegthumbnailer -s " . max($thumb_maxwidth, $thumb_maxheight) . " -i $file_location -o $thumb_location") . '!'; + + $thumb_info = getimagesize($thumb_location); + $post['thumb_width'] = $thumb_info[0]; + $post['thumb_height'] = $thumb_info[1]; + + if ($post['thumb_width'] <= 0 || $post['thumb_height'] <= 0) { + @unlink($file_location); + @unlink($thumb_location); + fancyDie("Sorry, your video appears to be corrupt."); + } + + if (file_exists('video_overlay.png')) { + $thumbnail = imagecreatefromjpeg($thumb_location); + list($width, $height, $type, $attr) = getimagesize($thumb_location); + + $overlay_play = imagecreatefrompng('video_overlay.png'); + imagealphablending($overlay_play, false); + imagesavealpha($overlay_play, true); + list($overlay_width, $overlay_height, $overlay_type, $overlay_attr) = getimagesize('video_overlay.png'); + + $new_thumbnail = imagecreatetruecolor($width, $height); + imagecopyresampled($new_thumbnail, $thumbnail, 0, 0, 0, 0, $width, $height, $width, $height); + imagecopyresampled($new_thumbnail, $overlay_play, ($width / 2) - ($overlay_width / 2), ($height / 2) - ($overlay_height / 2), 0, 0, $overlay_width, $overlay_width, $overlay_width, $overlay_height); + imagejpeg($new_thumbnail, $thumb_location); + + $thumb_info = getimagesize($thumb_location); + $post['thumb_width'] = $thumb_info[0]; + $post['thumb_height'] = $thumb_info[1]; + } + } + + $duration = intval(shell_exec('mediainfo --Inform="' . ($file_mime == 'video/webm' ? 'Video' : 'Audio') . ';%Duration%" ' . $file_location)); + $mins = floor(round($duration / 1000) / 60); + $secs = str_pad(floor(round($duration / 1000) % 60), 2, "0", STR_PAD_LEFT); + + $post['file_original'] = "$mins:$secs" . ($post['file_original'] != '' ? (', ' . $post['file_original']) : ''); + } else { + $file_info = getimagesize($file_location); + + $post['image_width'] = $file_info[0]; + $post['image_height'] = $file_info[1]; + + list($thumb_maxwidth, $thumb_maxheight) = thumbnailDimensions($post); + + if (!createThumbnail($file_location, $thumb_location, $thumb_maxwidth, $thumb_maxheight)) { + fancyDie("Could not create thumbnail."); + } + + $thumb_info = getimagesize($thumb_location); + $post['thumb_width'] = $thumb_info[0]; + $post['thumb_height'] = $thumb_info[1]; + } } } - + if ($post['file'] == '') { // No file uploaded if ($post['parent'] == TINYIB_NEWTHREAD) { fancyDie("An image is required to start a thread."); @@ -147,18 +229,18 @@ if (isset($_POST['message']) || isset($_POST['file'])) { } else { echo $post['file_original'] . ' uploaded.
'; } - + $post['id'] = insertPost($post); if (strtolower($post['email']) == 'noko') { $redirect = 'res/' . ($post['parent'] == TINYIB_NEWTHREAD ? $post['id'] : $post['parent']) . '.html#' . $post['id']; } - + trimThreads(); - + echo 'Updating thread...
'; if ($post['parent'] != TINYIB_NEWTHREAD) { rebuildThread($post['parent']); - + if (strtolower($post['email']) != 'sage') { if (TINYIB_MAXREPLIES == 0 || numRepliesToThreadByID($post['parent']) <= TINYIB_MAXREPLIES) { bumpThreadByID($post['parent']); @@ -167,23 +249,29 @@ if (isset($_POST['message']) || isset($_POST['file'])) { } else { rebuildThread($post['id']); } - + echo 'Updating index...
'; rebuildIndexes(); // Check if the request is to delete a post and/or its associated image } elseif (isset($_GET['delete']) && !isset($_GET['manage'])) { - if (!isset($_POST['delete'])) { fancyDie('Tick the box next to a post and click "Delete" to delete it.'); } + if (!isset($_POST['delete'])) { + fancyDie('Tick the box next to a post and click "Delete" to delete it.'); + } $post = postByID($_POST['delete']); if ($post) { list($loggedin, $isadmin) = manageCheckLogIn(); - + if ($loggedin && $_POST['password'] == '') { // Redirect to post moderation page echo '--> --> -->'; } elseif ($post['password'] != '' && md5(md5($_POST['password'])) == $post['password']) { deletePostByID($post['id']); - if ($post['parent'] == TINYIB_NEWTHREAD) { threadUpdated($post['id']); } else { threadUpdated($post['parent']); } + if ($post['parent'] == TINYIB_NEWTHREAD) { + threadUpdated($post['id']); + } else { + threadUpdated($post['parent']); + } fancyDie('Post deleted.'); } else { fancyDie('Invalid password.'); @@ -195,12 +283,16 @@ if (isset($_POST['message']) || isset($_POST['file'])) { $redirect = false; // Check if the request is to access the management area } elseif (isset($_GET['manage'])) { - $text = ''; $onload = ''; $navbar = ' '; - $redirect = false; $loggedin = false; $isadmin = false; + $text = ''; + $onload = ''; + $navbar = ' '; + $redirect = false; + $loggedin = false; + $isadmin = false; $returnlink = basename($_SERVER['PHP_SELF']); - + list($loggedin, $isadmin) = manageCheckLogIn(); - + if ($loggedin) { if ($isadmin) { if (isset($_GET['rebuildall'])) { @@ -212,19 +304,19 @@ if (isset($_POST['message']) || isset($_POST['file'])) { $text .= manageInfo('Rebuilt board.'); } elseif (isset($_GET['bans'])) { clearExpiredBans(); - + if (isset($_POST['ip'])) { if ($_POST['ip'] != '') { $banexists = banByIP($_POST['ip']); if ($banexists) { fancyDie('Sorry, there is already a ban on record for that IP address.'); } - + $ban = array(); $ban['ip'] = $_POST['ip']; $ban['expire'] = ($_POST['expire'] > 0) ? (time() + $_POST['expire']) : 0; $ban['reason'] = $_POST['reason']; - + insertBan($ban); $text .= manageInfo('Ban record added for ' . $ban['ip']); } @@ -235,7 +327,7 @@ if (isset($_POST['message']) || isset($_POST['file'])) { $text .= manageInfo('Ban record lifted for ' . $ban['ip']); } } - + $onload = manageOnLoad('bans'); $text .= manageBanForm(); $text .= manageBansTable(); @@ -254,7 +346,7 @@ if (isset($_POST['message']) || isset($_POST['file'])) { } } } - + if (isset($_GET['delete'])) { $post = postByID($_GET['delete']); if ($post) { @@ -303,5 +395,3 @@ if (isset($_POST['message']) || isset($_POST['file'])) { if ($redirect) { echo '--> --> -->'; } - -?> diff --git a/inc/database_flatfile.php b/inc/database_flatfile.php index 80e5cdd..c8ed053 100644 --- a/inc/database_flatfile.php +++ b/inc/database_flatfile.php @@ -1,38 +1,40 @@ add(new SimpleWhereClause(POST_ID, '=', $id, INTEGER_COMPARISON)); $compClause->add(new SimpleWhereClause(POST_PARENT, '=', 0, INTEGER_COMPARISON)); - + return count($GLOBALS['db']->selectWhere(POSTS_FILE, $compClause, 1)) > 0; } @@ -67,7 +69,7 @@ function insertPost($newpost) { $post[POST_EMAIL] = $newpost['email']; $post[POST_NAMEBLOCK] = $newpost['nameblock']; $post[POST_SUBJECT] = $newpost['subject']; - $post[POST_MESSAGE] = $newpost['message']; + $post[POST_MESSAGE] = $newpost['message']; $post[POST_PASSWORD] = $newpost['password']; $post[POST_FILE] = $newpost['file']; $post[POST_FILE_HEX] = $newpost['file_hex']; @@ -99,7 +101,7 @@ function countThreads() { return count($rows); } -function convertPostsToSQLStyle($posts, $singlepost=false) { +function convertPostsToSQLStyle($posts, $singlepost = false) { $newposts = array(); foreach ($posts as $oldpost) { $post = newPost(); @@ -125,12 +127,14 @@ function convertPostsToSQLStyle($posts, $singlepost=false) { $post['thumb'] = $oldpost[POST_THUMB]; $post['thumb_width'] = $oldpost[POST_THUMB_WIDTH]; $post['thumb_height'] = $oldpost[POST_THUMB_HEIGHT]; - + if ($post['parent'] == '') { $post['parent'] = TINYIB_NEWTHREAD; } - - if ($singlepost) { return $post; } + + if ($singlepost) { + return $post; + } $newposts[] = $post; } return $newposts; @@ -150,7 +154,7 @@ function postsInThreadByID($id) { $compClause = new OrWhereClause(); $compClause->add(new SimpleWhereClause(POST_ID, '=', $id, INTEGER_COMPARISON)); $compClause->add(new SimpleWhereClause(POST_PARENT, '=', $id, INTEGER_COMPARISON)); - + $rows = $GLOBALS['db']->selectWhere(POSTS_FILE, $compClause, -1, new OrderBy(POST_ID, ASCENDING, INTEGER_COMPARISON)); return convertPostsToSQLStyle($rows); } @@ -175,7 +179,7 @@ function deletePostByID($id) { $thispost = $post; } } - + if (isset($thispost)) { if ($thispost['parent'] == 0) { @unlink('res/' . $thispost['id'] . '.html'); @@ -190,7 +194,7 @@ function trimThreads() { $numthreads = countThreads(); if ($numthreads > TINYIB_MAXTHREADS) { $allthreads = allThreads(); - for ($i=TINYIB_MAXTHREADS;$i<$numthreads;$i++) { + for ($i = TINYIB_MAXTHREADS; $i < $numthreads; $i++) { deletePostByID($allthreads[$i]['id']); } } @@ -216,7 +220,7 @@ function allBans() { return convertBansToSQLStyle($rows); } -function convertBansToSQLStyle($bans, $singleban=false) { +function convertBansToSQLStyle($bans, $singleban = false) { $newbans = array(); foreach ($bans as $oldban) { $ban = array(); @@ -225,8 +229,10 @@ function convertBansToSQLStyle($bans, $singleban=false) { $ban['timestamp'] = $oldban[BAN_TIMESTAMP]; $ban['expire'] = $oldban[BAN_EXPIRE]; $ban['reason'] = $oldban[BAN_REASON]; - - if ($singleban) { return $ban; } + + if ($singleban) { + return $ban; + } $newbans[] = $ban; } return $newbans; @@ -239,7 +245,7 @@ function insertBan($newban) { $ban[BAN_TIMESTAMP] = time(); $ban[BAN_EXPIRE] = $newban['expire']; $ban[BAN_REASON] = $newban['reason']; - + return $GLOBALS['db']->insertWithAutoId(BANS_FILE, BAN_ID, $ban); } @@ -247,7 +253,7 @@ function clearExpiredBans() { $compClause = new AndWhereClause(); $compClause->add(new SimpleWhereClause(BAN_EXPIRE, '>', 0, INTEGER_COMPARISON)); $compClause->add(new SimpleWhereClause(BAN_EXPIRE, '<=', time(), INTEGER_COMPARISON)); - + $bans = $GLOBALS['db']->selectWhere(BANS_FILE, $compClause, -1); foreach ($bans as $ban) { deleteBanByID($ban[BAN_ID]); @@ -257,5 +263,3 @@ function clearExpiredBans() { function deleteBanByID($id) { $GLOBALS['db']->deleteWhere(BANS_FILE, new SimpleWhereClause(BAN_ID, '=', $id, INTEGER_COMPARISON)); } - -?> diff --git a/inc/database_mysql.php b/inc/database_mysql.php index 9ab33e9..44f0e3e 100644 --- a/inc/database_mysql.php +++ b/inc/database_mysql.php @@ -1,5 +1,7 @@ 0) { - $result = mysql_query("SELECT `id` FROM `" . TINYIB_DBPOSTS . "` WHERE `parent` = 0 ORDER BY `bumped` DESC LIMIT " . TINYIB_MAXTHREADS. ", 10"); + $result = mysql_query("SELECT `id` FROM `" . TINYIB_DBPOSTS . "` WHERE `parent` = 0 ORDER BY `bumped` DESC LIMIT " . TINYIB_MAXTHREADS . ", 10"); if ($result) { while ($post = mysql_fetch_assoc($result)) { deletePostByID($post['id']); @@ -168,7 +170,7 @@ function trimThreads() { } } -function lastPostByIP() { +function lastPostByIP() { $replies = mysql_query("SELECT * FROM `" . TINYIB_DBPOSTS . "` WHERE `ip` = '" . $_SERVER['REMOTE_ADDR'] . "' ORDER BY `id` DESC LIMIT 1"); if ($replies) { while ($post = mysql_fetch_assoc($replies)) { @@ -224,5 +226,3 @@ function clearExpiredBans() { function deleteBanByID($id) { mysql_query("DELETE FROM `" . TINYIB_DBBANS . "` WHERE `id` = " . mysql_real_escape_string($id) . " LIMIT 1"); } - -?> \ No newline at end of file diff --git a/inc/database_sqlite.php b/inc/database_sqlite.php index ce35a91..4d5145e 100644 --- a/inc/database_sqlite.php +++ b/inc/database_sqlite.php @@ -1,5 +1,7 @@ 0) { - $result = sqlite_fetch_all(sqlite_query($GLOBALS["db"], "SELECT id FROM " . TINYIB_DBPOSTS . " WHERE parent = 0 ORDER BY bumped DESC LIMIT " . TINYIB_MAXTHREADS. ", 10"), SQLITE_ASSOC); + $result = sqlite_fetch_all(sqlite_query($GLOBALS["db"], "SELECT id FROM " . TINYIB_DBPOSTS . " WHERE parent = 0 ORDER BY bumped DESC LIMIT " . TINYIB_MAXTHREADS . ", 10"), SQLITE_ASSOC); foreach ($result as $post) { deletePostByID($post['id']); } } } -function lastPostByIP() { +function lastPostByIP() { $result = sqlite_fetch_all(sqlite_query($GLOBALS["db"], "SELECT * FROM " . TINYIB_DBPOSTS . " WHERE ip = '" . $_SERVER['REMOTE_ADDR'] . "' ORDER BY id DESC LIMIT 1"), SQLITE_ASSOC); foreach ($result as $post) { return $post; @@ -193,5 +195,3 @@ function clearExpiredBans() { function deleteBanByID($id) { sqlite_query($GLOBALS["db"], "DELETE FROM " . TINYIB_DBBANS . " WHERE id = " . sqlite_escape_string($id)); } - -?> \ No newline at end of file diff --git a/inc/defines.php b/inc/defines.php index 12c99af..13959d2 100644 --- a/inc/defines.php +++ b/inc/defines.php @@ -1,5 +1,7 @@ \ No newline at end of file +if (!defined('TINYIB_MAXREPLIES')) { + define('TINYIB_MAXREPLIES', 0); +} +if (!defined('TINYIB_MAXWOP')) { + define('TINYIB_MAXWOP', TINYIB_MAXW); +} +if (!defined('TINYIB_MAXHOP')) { + define('TINYIB_MAXHOP', TINYIB_MAXH); +} +if (!defined('TINYIB_WEBM')) { + define('TINYIB_WEBM', false); +} diff --git a/inc/flatfile/flatfile.php b/inc/flatfile/flatfile.php index 54d4895..91dee7e 100644 --- a/inc/flatfile/flatfile.php +++ b/inc/flatfile/flatfile.php @@ -27,7 +27,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * @license http://www.opensource.org/licenses/mit-license.php */ -require_once('flatfile_utils.php'); +require_once('flatfile_utils.php'); /** Used to indicate the default comparison should be done, which is STRING_COMPARISON in the absence of a schema, or whatever the schema specifies if one has been added */ define('DEFAULT_COMPARISON', ''); @@ -50,8 +50,7 @@ $comparison_type_for_col_type = array( FLOAT_COL => NUMERIC_COMPARISON ); -function get_comparison_type_for_col_type($coltype) -{ +function get_comparison_type_for_col_type($coltype) { global $comparison_type_for_col_type; return $comparison_type_for_col_type[$coltype]; } @@ -71,28 +70,27 @@ class Flatfile { /** @access private */ var $schemata; - - /** The directory to store files in. + + /** The directory to store files in. * @var string */ var $datadir; - function Flatfile() - { + function Flatfile() { $this->schemata = array(); } /** * Get all rows from a table - * @param string $tablename The table to get rows from + * @param string $tablename The table to get rows from * @return array The table as an array of rows, where each row is an array of columns */ - function selectAll ($tablename) { + function selectAll($tablename) { if (!isset($this->tables[$tablename])) $this->loadTable($tablename); - return $this->tables[$tablename]; + return $this->tables[$tablename]; } - + /** * Selects rows from a table that match the specified criteria * @@ -103,26 +101,26 @@ class Flatfile { * ORDER BY $orderBy [ASC | DESC] [, $orderBy2 ...] * * - * @param string $tablename The table (file) to get the data from - * @param object $whereClause Either a {@link WhereClause WhereClause} object to do selection of rows, or NULL to select all - * @param mixed $limit Specifies limits for the rows returned: + * @param string $tablename The table (file) to get the data from + * @param object $whereClause Either a {@link WhereClause WhereClause} object to do selection of rows, or NULL to select all + * @param mixed $limit Specifies limits for the rows returned: * - use -1 or omitted to return all rows * - use an integer n to return the first n rows * - use a two item array ($startrow, $endrow) to return rows $startrow to $endrow - 1 (zero indexed) * - use a two item array ($startrow, -1) to return rows $startrow to the end (zero indexed) - * @param mixed $orderBy Either an {@link OrderBy} object or an array of them, defining the sorting that should be applied (if an array, then the first object in the array is the first key to sort on etc). Use NULL for no sorting. + * @param mixed $orderBy Either an {@link OrderBy} object or an array of them, defining the sorting that should be applied (if an array, then the first object in the array is the first key to sort on etc). Use NULL for no sorting. * @return array The matching data, as an array of rows, where each row is an array of columns */ - function selectWhere ($tablename, $whereClause, $limit = -1, $orderBy = NULL) { + function selectWhere($tablename, $whereClause, $limit = -1, $orderBy = NULL) { if (!isset($this->tables[$tablename])) $this->loadTable($tablename); - + $table = $this->selectAll($tablename); // Get a copy - + $schema = $this->getSchema($tablename); if ($orderBy !== NULL) usort($table, $this->getOrderByFunction($orderBy, $schema)); - + $results = array(); $count = 0; @@ -130,10 +128,10 @@ class Flatfile { $limit = array(0, -1); else if (!is_array($limit)) $limit = array(0, $limit); - + foreach ($table as $row) { if ($whereClause === NULL || $whereClause->testRow($row, $schema)) { - if ($count >= $limit[0]) + if ($count >= $limit[0]) $results[] = $row; ++$count; if (($count >= $limit[1]) && ($limit[1] != -1)) @@ -142,22 +140,22 @@ class Flatfile { } return $results; } - + /** * Select a row using a unique ID - * @param string $tablename The table to get data from - * @param string $idField The index of the field containing the ID - * @param string $id The ID to search for - * @return array The row of the table as an array + * @param string $tablename The table to get data from + * @param string $idField The index of the field containing the ID + * @param string $id The ID to search for + * @return array The row of the table as an array */ - function selectUnique ($tablename, $idField, $id) { + function selectUnique($tablename, $idField, $id) { $result = $this->selectWhere($tablename, new SimpleWhereClause($idField, '=', $id)); if (count($result) > 0) return $result[0]; else return array(); } - + /* * To correctly write a file, and not overwrite the changes * another process is making, we need to: @@ -170,47 +168,44 @@ class Flatfile { * the lock on a different file. getLock and releaseLock * are helper functions to allow us to do this with little fuss */ - + /** Get a lock for writing a file * @access private */ - function getLock ($tablename) - { + function getLock($tablename) { ignore_user_abort(true); - $fp = fopen($this->datadir . $tablename.'.lock','w'); + $fp = fopen($this->datadir . $tablename . '.lock', 'w'); if (!flock($fp, LOCK_EX)) { - // log error? + // log error? } $this->loadTable($tablename); return $fp; } - + /** Release a lock * @access private */ - function releaseLock ($lockfp) - { + function releaseLock($lockfp) { flock($lockfp, LOCK_UN); ignore_user_abort(false); } - + /** * Inserts a row with an automatically generated ID * * The autogenerated ID will be the highest ID in the column so far plus one. The - * supplied row should include all fields required for the table, and the + * supplied row should include all fields required for the table, and the * ID field it contains will just be ignored * - * @param string $tablename The table to insert data into - * @param int $idField The index of the field which is the ID field - * @param array $newRow The new row to add to the table - * @return int The newly assigned ID + * @param string $tablename The table to insert data into + * @param int $idField The index of the field which is the ID field + * @param array $newRow The new row to add to the table + * @return int The newly assigned ID */ - function insertWithAutoId ($tablename, $idField, $newRow) - { + function insertWithAutoId($tablename, $idField, $newRow) { $lockfp = $this->getLock($tablename); - $rows = $this->selectWhere($tablename, null, 1, - new OrderBy($idField, DESCENDING, INTEGER_COMPARISON)); + $rows = $this->selectWhere($tablename, null, 1, + new OrderBy($idField, DESCENDING, INTEGER_COMPARISON)); if ($rows) { $newId = $rows[0][$idField] + 1; } else { @@ -226,50 +221,47 @@ class Flatfile { /** * Inserts a row in a table * - * @param string $tablename The table to insert data into - * @param array $newRow The new row to add to the table + * @param string $tablename The table to insert data into + * @param array $newRow The new row to add to the table */ - function insert ($tablename, $newRow) - { - $lockfp = $this->getLock($tablename); + function insert($tablename, $newRow) { + $lockfp = $this->getLock($tablename); $this->tables[$tablename][] = $newRow; $this->writeTable($tablename); $this->releaseLock($lockfp); } - + /** * Updates an existing row using a unique ID * - * @param string $tablename The table to update - * @param int $idField The index of the field which is the ID field - * @param array $updatedRow The updated row to add to the table + * @param string $tablename The table to update + * @param int $idField The index of the field which is the ID field + * @param array $updatedRow The updated row to add to the table */ - function updateRowById ($tablename, $idField, $updatedRow) - { - $this->updateSetWhere($tablename, $updatedRow, + function updateRowById($tablename, $idField, $updatedRow) { + $this->updateSetWhere($tablename, $updatedRow, new SimpleWhereClause($idField, '=', $updatedRow[$idField])); } - + /** * Updates fields in a table for rows that match the provided criteria - * + * * $newFields can be a complete row or it can be a sparsely populated * hashtable of values (where the keys are integers which are the column * indexes to update) * - * @param string $tablename The table to update - * @param array $newFields A hashtable (with integer keys) of fields to update - * @param WhereClause $whereClause The criteria or NULL to update all rows + * @param string $tablename The table to update + * @param array $newFields A hashtable (with integer keys) of fields to update + * @param WhereClause $whereClause The criteria or NULL to update all rows */ - function updateSetWhere ($tablename, $newFields, $whereClause) - { + function updateSetWhere($tablename, $newFields, $whereClause) { $schema = $this->getSchema($tablename); $lockfp = $this->getLock($tablename); for ($i = 0; $i < count($this->tables[$tablename]); ++$i) { if ($whereClause === NULL || - $whereClause->testRow($this->tables[$tablename][$i], $schema)) { - foreach ($newFields as $k => $v) - { + $whereClause->testRow($this->tables[$tablename][$i], $schema) + ) { + foreach ($newFields as $k => $v) { $this->tables[$tablename][$i][$k] = $v; } } @@ -278,19 +270,21 @@ class Flatfile { $this->releaseLock($lockfp); $this->loadTable($tablename); } + /** * Deletes all rows in a table that match specified criteria * - * @param string $tablename The table to alter - * @param object $whereClause. {@link WhereClause WhereClause} object that will select + * @param string $tablename The table to alter + * @param object $whereClause . {@link WhereClause WhereClause} object that will select * rows to be deleted. All rows are deleted if $whereClause === NULL */ - function deleteWhere ($tablename, $whereClause) { + function deleteWhere($tablename, $whereClause) { $schema = $this->getSchema($tablename); - $lockfp = $this->getLock($tablename); - for ($i = count($this->tables[$tablename]) - 1; $i >= 0 ; --$i) { + $lockfp = $this->getLock($tablename); + for ($i = count($this->tables[$tablename]) - 1; $i >= 0; --$i) { if ($whereClause === NULL || - $whereClause->testRow($this->tables[$tablename][$i], $schema)) { + $whereClause->testRow($this->tables[$tablename][$i], $schema) + ) { unset($this->tables[$tablename][$i]); } } @@ -298,31 +292,30 @@ class Flatfile { $this->releaseLock($lockfp); $this->loadTable($tablename); // reset array indexes } - + /** * Delete all rows in a table * - * @param string $tablename The table to alter + * @param string $tablename The table to alter */ - function deleteAll ($tablename) { + function deleteAll($tablename) { $this->deleteWhere($tablename, NULL); } /**#@+ * @access private */ - + /** Gets a function that can be passed to usort to do the ORDER BY clause - * @param mixed $orderBy Either an OrderBy object or an array of them + * @param mixed $orderBy Either an OrderBy object or an array of them * @return string function name */ - function getOrderByFunction ($orderBy, $rowSchema = null) - { + function getOrderByFunction($orderBy, $rowSchema = null) { $orderer = new Orderer($orderBy, $rowSchema); return array(&$orderer, 'compare'); } - function loadTable ($tablename) { + function loadTable($tablename) { $filedata = @file($this->datadir . $tablename); $table = array(); if (is_array($filedata)) { @@ -334,9 +327,9 @@ class Flatfile { $this->tables[$tablename] = $table; } - function writeTable ($tablename) { + function writeTable($tablename) { $output = ''; - + foreach ($this->tables[$tablename] as $row) { $keys = array_keys($row); rsort($keys, SORT_NUMERIC); @@ -344,7 +337,7 @@ class Flatfile { for ($i = 0; $i <= $max; ++$i) { if ($i > 0) $output .= "\t"; $data = (!isset($row[$i]) ? '' : $row[$i]); - $output .= str_replace(array("\t","\r","\n"), array(''), $data); + $output .= str_replace(array("\t", "\r", "\n"), array(''), $data); } $output .= "\n"; } @@ -356,50 +349,45 @@ class Flatfile { /**#@-*/ /** * Adds a schema definition to the DB for a specified regular expression - * + * * Schemas are optional, and are only used for automatically determining * the comparison types that should be used when sorting and selecting. - * - * @param string $fileregex A regular expression used to match filenames - * @param string $rowSchema An array specifying the column types for data + * + * @param string $fileregex A regular expression used to match filenames + * @param string $rowSchema An array specifying the column types for data * files that match the regex, using constants defined in flatfile_utils.php */ - function addSchema($fileregex, $rowSchema) - { + function addSchema($fileregex, $rowSchema) { array_push($this->schemata, array($fileregex, $rowSchema)); } /** Retrieves the schema for a given filename */ - function getSchema($filename) - { - foreach ($this->schemata as $rowSchemaPair) - { + function getSchema($filename) { + foreach ($this->schemata as $rowSchemaPair) { $fileregex = $rowSchemaPair[0]; - if (preg_match($fileregex, $filename)) - { + if (preg_match($fileregex, $filename)) { return $rowSchemaPair[1]; } } return null; } - - + + } + /////////////////////////// UTILITY FUNCTIONS //////////////////////////////////// -/** - * equivalent of strcmp for comparing integers, used internally for sorting and comparing +/** + * equivalent of strcmp for comparing integers, used internally for sorting and comparing */ -function intcmp ($a, $b) -{ +function intcmp($a, $b) { return (int)$a - (int)$b; } -/** - * equivalent of strcmp for comparing floats, used internally for sorting and comparing +/** + * equivalent of strcmp for comparing floats, used internally for sorting and comparing */ -function numcmp ($a, $b) -{ +function numcmp($a, $b) { return (float)$a - (float)$b; } @@ -411,41 +399,39 @@ function numcmp ($a, $b) * @abstract * @package flatfile */ -class WhereClause -{ +class WhereClause { /** * Tests a table row object * @abstract - * @param array $row The row to test - * @param array $rowSchema An optional array specifying the schema of the table, using the INT_COL, STRING_COL etc constants + * @param array $row The row to test + * @param array $rowSchema An optional array specifying the schema of the table, using the INT_COL, STRING_COL etc constants * @return bool True if the $row passes the WhereClause * selection criteria, false otherwise */ - function testRow ($row, $rowSchema = null) {} + function testRow($row, $rowSchema = null) { + } } /** * Negates a where clause * @package flatfile */ -class NotWhere extends WhereClause -{ +class NotWhere extends WhereClause { /** @access private */ var $clause; - + /** * Contructs a new NotWhere object * - * The constructed WhereClause will return the negation + * The constructed WhereClause will return the negation * of the WhereClause object passed in when testing rows. * @param WhereClause $whereclause The WhereClause object to negate */ - function NotWhere ($whereclause) - { + function NotWhere($whereclause) { $this->clause = $whereclause; } - - function testRow ($row, $rowSchema = null) { + + function testRow($row, $rowSchema = null) { return !$this->clause->testRow($row, $rowSchema); } } @@ -456,8 +442,7 @@ class NotWhere extends WhereClause * * @package flatfile */ -class SimpleWhereClause extends WhereClause -{ +class SimpleWhereClause extends WhereClause { /**#@+ * @access private */ @@ -482,43 +467,38 @@ class SimpleWhereClause extends WhereClause * - <= (less than or equal to) * There are 3 pre-defined constants (STRING_COMPARISON, NUMERIC COMPARISON and * INTEGER_COMPARISON) that modify the behaviour of these operators to do the comparison - * as strings, floats and integers respectively. Howevers, these constants are + * as strings, floats and integers respectively. Howevers, these constants are * just the names of functions that do the comparison (the first being the builtin - * function {@link strcmp strcmp()}, so you can supply your own function here to customise the + * function {@link strcmp strcmp()}, so you can supply your own function here to customise the * behaviour of this class. - * - * @param int $field The index (in the table row) of the field to test - * @param string $operator The comparison operator, one of "=", "!=", "<", ">", "<=", ">=" - * @param mixed $value The value to compare to. - * @param string $compare_type The comparison method to use - either + * + * @param int $field The index (in the table row) of the field to test + * @param string $operator The comparison operator, one of "=", "!=", "<", ">", "<=", ">=" + * @param mixed $value The value to compare to. + * @param string $compare_type The comparison method to use - either * STRING_COMPARISON (default), NUMERIC COMPARISON or INTEGER_COMPARISON * */ - function SimpleWhereClause ($field, $operator, $value, $compare_type = DEFAULT_COMPARISON) - { + function SimpleWhereClause($field, $operator, $value, $compare_type = DEFAULT_COMPARISON) { $this->field = $field; $this->operator = $operator; $this->value = $value; $this->compare_type = $compare_type; } - - function testRow ($tablerow, $rowSchema = null) { + + function testRow($tablerow, $rowSchema = null) { if ($this->field < 0) return TRUE; - + $cmpfunc = $this->compare_type; - if ($cmpfunc == DEFAULT_COMPARISON) - { - if ($rowSchema != null) - { + if ($cmpfunc == DEFAULT_COMPARISON) { + if ($rowSchema != null) { $cmpfunc = get_comparison_type_for_col_type($rowSchema[$this->field]); - } - else - { + } else { $cmpfunc = STRING_COMPARISON; } } - + if ($this->field >= count($tablerow)) { $dbval = ""; } else { @@ -537,7 +517,7 @@ class SimpleWhereClause extends WhereClause return ($cmp <= 0); else if ($this->operator == '>=') return ($cmp >= 0); - + return FALSE; } } @@ -546,23 +526,21 @@ class SimpleWhereClause extends WhereClause * {@link WhereClause WhereClause} class to work like a SQL 'LIKE' clause * @package flatfile */ -class LikeWhereClause extends WhereClause -{ +class LikeWhereClause extends WhereClause { /** - * Creates a new LikeWhereClause + * Creates a new LikeWhereClause * - * @param int $field Index of the field to look at - * @param string $value Value to look for. Supports using '%' as a + * @param int $field Index of the field to look at + * @param string $value Value to look for. Supports using '%' as a * wildcard, and is case insensitve. e.g. 'test%' will match 'TESTS' and 'Testing' */ - function LikeWhereClause ($field, $value) - { + function LikeWhereClause($field, $value) { $this->field = $field; - $this->regexp = '/^' . str_replace('%','.*', preg_quote($value)) . '$/i'; + $this->regexp = '/^' . str_replace('%', '.*', preg_quote($value)) . '$/i'; } - - function testRow ($tablerow, $rowSchema = NULL) { + + function testRow($tablerow, $rowSchema = NULL) { return preg_match($this->regexp, $tablerow[$this->field]); } } @@ -580,40 +558,35 @@ class ListWhereClause extends WhereClause { var $list; /** @access private */ var $compareAs; - + /** * Creates a new ListWhereClause object * * The resulting WhereClause will pass rows (return true) if the value of the specified * field is in the array. - * - * @param int $field Field to match - * @param array $list List of items + * + * @param int $field Field to match + * @param array $list List of items * @param string $compare_type Comparison type, string by default. */ - function ListWhereClause ($field, $list, $compare_type = DEFAULT_COMPARISON) { + function ListWhereClause($field, $list, $compare_type = DEFAULT_COMPARISON) { $this->list = $list; $this->field = (int)$field; $this->compareAs = $compare_type; } - - function testRow ($tablerow, $rowSchema = null) { + + function testRow($tablerow, $rowSchema = null) { $func = $this->compareAs; - if ($func == DEFAULT_COMPARISON) - { - if ($rowSchema) - { + if ($func == DEFAULT_COMPARISON) { + if ($rowSchema) { $func = get_comparison_type_for_col_type($rowSchema[$this->field]); - } - else - { + } else { $func = STRING_COMPARISON; } } - - foreach ($this->list as $item) - { - if ($func($tablerow[$this->field], $item) == 0) + + foreach ($this->list as $item) { + if ($func($tablerow[$this->field], $item) == 0) return true; } return false; @@ -624,21 +597,19 @@ class ListWhereClause extends WhereClause { * Abstract class that combines zero or more {@link WhereClause WhereClause} objects * together. * @package flatfile - */ -class CompositeWhereClause extends WhereClause -{ - /** + */ +class CompositeWhereClause extends WhereClause { + /** * @var array Stores the child clauses - * @access protected + * @access protected */ var $clauses = array(); - + /** * Add a {@link WhereClause WhereClause} to the list of clauses to be used for testing - * @param WhereClause $whereClause The WhereClause object to add - */ - function add ($whereClause) - { + * @param WhereClause $whereClause The WhereClause object to add + */ + function add($whereClause) { $this->clauses[] = $whereClause; } } @@ -654,20 +625,19 @@ class CompositeWhereClause extends WhereClause * false if no clauses have been added for consistency). * @package flatfile */ -class OrWhereClause extends CompositeWhereClause -{ - function testRow ($tablerow, $rowSchema = null) { +class OrWhereClause extends CompositeWhereClause { + function testRow($tablerow, $rowSchema = null) { foreach ($this->clauses as $clause) { if ($clause->testRow($tablerow, $rowSchema)) return true; } return false; } - + /** - * Creates a new OrWhereClause + * Creates a new OrWhereClause * @param WhereClause $whereClause,... optional unlimited list of WhereClause objects to be added - */ + */ function OrWhereClause() { $this->clauses = func_get_args(); } @@ -683,20 +653,19 @@ class OrWhereClause extends CompositeWhereClause * true if no clauses have been added for consistency). * @package flatfile */ -class AndWhereClause extends CompositeWhereClause -{ - function testRow ($tablerow, $rowSchema = null) { +class AndWhereClause extends CompositeWhereClause { + function testRow($tablerow, $rowSchema = null) { foreach ($this->clauses as $clause) { if (!$clause->testRow($tablerow, $rowSchema)) return false; } return true; } - + /** - * Creates a new AndWhereClause + * Creates a new AndWhereClause * @param WhereClause $whereClause,... optional unlimited list of WhereClause objects to be added - */ + */ function AndWhereClause() { $this->clauses = func_get_args(); } @@ -717,22 +686,21 @@ class OrderBy { var $field; /** @var int Order type - ASCENDING or DESCENDING */ var $orderType; - /** @var string Comparison type - usually either DEFAULT_COMPARISON, STRING_COMPARISON, INTEGER_COMPARISION, or NUMERIC_COMPARISON*/ + /** @var string Comparison type - usually either DEFAULT_COMPARISON, STRING_COMPARISON, INTEGER_COMPARISION, or NUMERIC_COMPARISON */ var $compareAs; - + /** Creates a new OrderBy structure * - * The $compareAs parameter can be supplied using one of the pre-defined constants, but + * The $compareAs parameter can be supplied using one of the pre-defined constants, but * this is actually implemented by defining the constants as names of functions to do the - * comparison. You can therefore supply the name of any function that works like + * comparison. You can therefore supply the name of any function that works like * {@link strcmp strcmp()} to implement custom ordering. - * @param int $field The index of the field to order by - * @param int $orderType ASCENDING or DESCENDING - * @param int $compareAs Comparison type: DEFAULT_COMPARISON, STRING_COMPARISON, INTEGER_COMPARISION, + * @param int $field The index of the field to order by + * @param int $orderType ASCENDING or DESCENDING + * @param int $compareAs Comparison type: DEFAULT_COMPARISON, STRING_COMPARISON, INTEGER_COMPARISION, * or NUMERIC_COMPARISON, or the name of a user defined function that you want to use for doing the comparison. */ - function OrderBy($field, $orderType, $compareAs = DEFAULT_COMPARISON) - { + function OrderBy($field, $orderType, $compareAs = DEFAULT_COMPARISON) { $this->field = $field; $this->orderType = $orderType; $this->compareAs = $compareAs; @@ -746,56 +714,51 @@ class OrderBy { * @package flatfile */ class Orderer { - /** + /** * @var array Stores the OrderBy objects - * @access private + * @access private */ var $orderByList; - + /** * Creates new Orderer that will provide a sort function - * @param mixed $orderBy An OrderBy object or an array of them - * @param array $rowSchema Option row schema + * @param mixed $orderBy An OrderBy object or an array of them + * @param array $rowSchema Option row schema */ function Orderer($orderBy, $rowSchema = null) { if (!is_array($orderBy)) $orderBy = array($orderBy); - if ($rowSchema) - { + if ($rowSchema) { // Fix the comparison types - foreach ($orderBy as $index => $discard) - { + foreach ($orderBy as $index => $discard) { $item =& $orderBy[$index]; // PHP4 - if ($item->compareAs == DEFAULT_COMPARISON) - { + if ($item->compareAs == DEFAULT_COMPARISON) { $item->compareAs = get_comparison_type_for_col_type($rowSchema[$item->field]); } } } $this->orderByList = $orderBy; } - + /** - * Compares two table rows using the comparisons defined by the OrderBy + * Compares two table rows using the comparisons defined by the OrderBy * objects. This function is of the type that can be used passed to usort(). */ function compare($row1, $row2) { return $this->compare_priv($row1, $row2, 0); } - + /** * @access private */ - function compare_priv($row1, $row2, $index) - { + function compare_priv($row1, $row2, $index) { $orderBy = $this->orderByList[$index]; $cmpfunc = $orderBy->compareAs; - if ($cmpfunc == DEFAULT_COMPARISON) - { + if ($cmpfunc == DEFAULT_COMPARISON) { $cmpfunc = STRING_COMPARISON; } $cmp = $orderBy->orderType * $cmpfunc($row1[$orderBy->field], $row2[$orderBy->field]); - if($cmp == 0) { + if ($cmp == 0) { if ($index == (count($this->orderByList) - 1)) return 0; else @@ -804,4 +767,3 @@ class Orderer { return $cmp; } } -?> \ No newline at end of file diff --git a/inc/flatfile/flatfile_utils.php b/inc/flatfile/flatfile_utils.php index a1a37e7..8f5b1cd 100644 --- a/inc/flatfile/flatfile_utils.php +++ b/inc/flatfile/flatfile_utils.php @@ -13,23 +13,19 @@ define('DATE_COL', 'date'); /** EXPERIMENTAL: Encapsulates info about a column in a flatfile DB */ -class Column -{ +class Column { /** * Create a new column object */ - function Column($index, $type) - { + function Column($index, $type) { $this->index = $index; $this->type = $type; } } /** EXPERIMENTAL: Represent a column that is a foreign key. Used for temporarily building tables array */ -class JoinColumn -{ - function JoinColumn($index, $tablename, $columnname) - { +class JoinColumn { + function JoinColumn($index, $tablename, $columnname) { $this->index = $index; $this->tablename = $tablename; $this->columnname = $columnname; @@ -39,74 +35,61 @@ class JoinColumn /** * EXPERIMENTAL: Utilities for handling definitions of tables. */ -class TableUtils -{ - /** +class TableUtils { + /** * Finds JoinColumns in an array of tables, and adds 'type' fields by looking up the columns * * @param tables This should be an associative array containing 'tablename' => tabledefinition * tabledefinition is itself an associativive array of 'COLUMN_NAME_CONSTANT' => columndefintion - * COLUMN_NAME_CONSTANT should be a unique constant within the table, and + * COLUMN_NAME_CONSTANT should be a unique constant within the table, and * column definition should be a Column object or JoinColumn object */ - function resolveJoins(&$tables) - { - foreach ($tables as $tablename => $discard) - { + function resolveJoins(&$tables) { + foreach ($tables as $tablename => $discard) { // PHP4 compatible: can't do : foreach ($tables as $tablename => &$tabledef) - // and strangely, if we do + // and strangely, if we do // foreach ($tables as $tablename => &$tabledef) // $tabledef =& $tables[$tablename]; // then we get bugs - $tabledef =& $tables[$tablename]; - foreach ($tabledef as $colname => $discard) - { + $tabledef =& $tables[$tablename]; + foreach ($tabledef as $colname => $discard) { $coldef =& $tabledef[$colname]; // PHP4 compatible - if (is_a($coldef, 'JoinColumn') or is_subclass_of($coldef, 'JoinColumn')) - { + if (is_a($coldef, 'JoinColumn') or is_subclass_of($coldef, 'JoinColumn')) { TableUtils::resolveColumnJoin($coldef, $tables); } } - } + } } /** @access private */ - function resolveColumnJoin(&$columndef, &$tables) - { + function resolveColumnJoin(&$columndef, &$tables) { // Doesn't work if the column it is joined to is also // a JoinColumn, but I can't think of ever wanting to do that $columndef->type = $tables[$columndef->tablename][$columndef->columnname]->type; } /** Uses 'define' to create global constants for all the column names */ - function createDefines(&$tables) - { - foreach ($tables as $tablename => $discard) - { - $tabledef = &$tables[$tablename]; // PHP4 compatible - foreach ($tabledef as $colname => $discard) - { - $coldef = &$tabledef[$colname]; + function createDefines(&$tables) { + foreach ($tables as $tablename => $discard) { + $tabledef = & $tables[$tablename]; // PHP4 compatible + foreach ($tabledef as $colname => $discard) { + $coldef = & $tabledef[$colname]; define(strtoupper($tablename) . '_' . $colname, $coldef->index); } } } - /** - * Creates a 'row schema' for a given table definition. + /** + * Creates a 'row schema' for a given table definition. * * A row schema is just an array of the column types for a table, * using the constants defined above. */ - function createRowSchema(&$tabledef) - { + function createRowSchema(&$tabledef) { $row_schema = array(); - foreach ($tabledef as $colname => $coldef) - { + foreach ($tabledef as $colname => $coldef) { $row_schema[$coldef->index] = $coldef->type; } return $row_schema; } } - -?> \ No newline at end of file diff --git a/inc/functions.php b/inc/functions.php index f0cb8f8..984dc8b 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -1,18 +1,20 @@ "); $replace = array("<", ">"); - + return str_replace($search, $replace, $string); } function plural($singular, $count, $plural = 's') { if ($plural == 's') { - $plural = $singular . $plural; - } - return ($count == 1 ? $singular : $plural); + $plural = $singular . $plural; + } + return ($count == 1 ? $singular : $plural); } function threadUpdated($id) { @@ -22,26 +24,26 @@ function threadUpdated($id) { function newPost($parent = TINYIB_NEWTHREAD) { return array('parent' => $parent, - 'timestamp' => '0', - 'bumped' => '0', - 'ip' => '', - 'name' => '', - 'tripcode' => '', - 'email' => '', - 'nameblock' => '', - 'subject' => '', - 'message' => '', - 'password' => '', - 'file' => '', - 'file_hex' => '', - 'file_original' => '', - 'file_size' => '0', - 'file_size_formatted' => '', - 'image_width' => '0', - 'image_height' => '0', - 'thumb' => '', - 'thumb_width' => '0', - 'thumb_height' => '0'); + 'timestamp' => '0', + 'bumped' => '0', + 'ip' => '', + 'name' => '', + 'tripcode' => '', + 'email' => '', + 'nameblock' => '', + 'subject' => '', + 'message' => '', + 'password' => '', + 'file' => '', + 'file_hex' => '', + 'file_original' => '', + 'file_size' => '0', + 'file_size_formatted' => '', + 'image_width' => '0', + 'image_height' => '0', + 'thumb' => '', + 'thumb_width' => '0', + 'thumb_height' => '0'); } function convertBytes($number) { @@ -49,26 +51,26 @@ function convertBytes($number) { if ($len < 4) { return sprintf("%dB", $number); } elseif ($len <= 6) { - return sprintf("%0.2fKB", $number/1024); + return sprintf("%0.2fKB", $number / 1024); } elseif ($len <= 9) { - return sprintf("%0.2fMB", $number/1024/1024); + return sprintf("%0.2fMB", $number / 1024 / 1024); } - return sprintf("%0.2fGB", $number/1024/1024/1024); + return sprintf("%0.2fGB", $number / 1024 / 1024 / 1024); } function nameAndTripcode($name) { if (preg_match("/(#|!)(.*)/", $name, $regs)) { $cap = $regs[2]; $cap_full = '#' . $regs[2]; - + if (function_exists('mb_convert_encoding')) { $recoded_cap = mb_convert_encoding($cap, 'SJIS', 'UTF-8'); if ($recoded_cap != '') { $cap = $recoded_cap; } } - + if (strpos($name, '#') === false) { $cap_delimiter = '!'; } elseif (strpos($name, '!') === false) { @@ -76,7 +78,7 @@ function nameAndTripcode($name) { } else { $cap_delimiter = (strpos($name, '#') < strpos($name, '!')) ? '#' : '!'; } - + if (preg_match("/(.*)(" . $cap_delimiter . ")(.*)/", $cap, $regs_secure)) { $cap = $regs_secure[1]; $cap_secure = $regs_secure[3]; @@ -84,41 +86,41 @@ function nameAndTripcode($name) { } else { $is_secure_trip = false; } - + $tripcode = ""; if ($cap != "") { // Copied from Futabally $cap = strtr($cap, "&", "&"); $cap = strtr($cap, ",", ", "); - $salt = substr($cap."H.", 1, 2); + $salt = substr($cap . "H.", 1, 2); $salt = preg_replace("/[^\.-z]/", ".", $salt); - $salt = strtr($salt, ":;<=>?@[\\]^_`", "ABCDEFGabcdef"); + $salt = strtr($salt, ":;<=>?@[\\]^_`", "ABCDEFGabcdef"); $tripcode = substr(crypt($cap, $salt), -10); } - + if ($is_secure_trip) { if ($cap != "") { $tripcode .= "!"; } - + $tripcode .= "!" . substr(md5($cap_secure . TINYIB_TRIPSEED), 2, 10); } - + return array(preg_replace("/(" . $cap_delimiter . ")(.*)/", "", $name), $tripcode); } - + return array($name, ""); } function nameBlock($name, $tripcode, $email, $timestamp, $rawposttext) { $output = ''; $output .= ($name == '' && $tripcode == '') ? 'Anonymous' : $name; - + if ($tripcode != '') { $output .= '!' . $tripcode; } - + $output .= ''; - + if ($email != '' && strtolower($email) != 'noko') { $output = '' . $output . ''; } @@ -136,14 +138,14 @@ function writePage($filename, $contents) { copy($tempfile, $filename); unlink($tempfile); } - + chmod($filename, 0664); /* it was created 0600 */ } function fixLinksInRes($html) { $search = array(' href="css/', ' href="src/', ' href="thumb/', ' href="res/', ' href="imgboard.php', ' href="favicon.ico', 'src="thumb/', ' action="imgboard.php'); $replace = array(' href="../css/', ' href="../src/', ' href="../thumb/', ' href="../res/', ' href="../imgboard.php', ' href="../favicon.ico', 'src="../thumb/', ' action="../imgboard.php'); - + return str_replace($search, $replace, $html); } @@ -160,13 +162,19 @@ function postLink($message) { } function colorQuote($message) { - if (substr($message, -1, 1) != "\n") { $message .= "\n"; } + if (substr($message, -1, 1) != "\n") { + $message .= "\n"; + } return preg_replace('/^(>[^\>](.*))\n/m', '\\1' . "\n", $message); } function deletePostImages($post) { - if ($post['file'] != '') { @unlink('src/' . $post['file']); } - if ($post['thumb'] != '') { @unlink('thumb/' . $post['thumb']); } + if ($post['file'] != '') { + @unlink('src/' . $post['file']); + } + if ($post['thumb'] != '') { + @unlink('thumb/' . $post['thumb']); + } } function checkBanned() { @@ -200,7 +208,8 @@ function checkMessageSize() { } function manageCheckLogIn() { - $loggedin = false; $isadmin = false; + $loggedin = false; + $isadmin = false; if (isset($_POST['password'])) { if ($_POST['password'] == TINYIB_ADMINPASS) { $_SESSION['tinyib'] = TINYIB_ADMINPASS; @@ -208,7 +217,7 @@ function manageCheckLogIn() { $_SESSION['tinyib'] = TINYIB_MODPASS; } } - + if (isset($_SESSION['tinyib'])) { if ($_SESSION['tinyib'] == TINYIB_ADMINPASS) { $loggedin = true; @@ -217,7 +226,7 @@ function manageCheckLogIn() { $loggedin = true; } } - + return array($loggedin, $isadmin); } @@ -227,11 +236,11 @@ function setParent() { if (!threadExistsByID($_POST['parent'])) { fancyDie("Invalid parent thread ID supplied, unable to create post."); } - + return $_POST["parent"]; } } - + return TINYIB_NEWTHREAD; } @@ -242,7 +251,7 @@ function isRawPost() { return true; } } - + return false; } @@ -273,7 +282,7 @@ function validateFileUpload() { } } -function checkDuplicateImage($hex) { +function checkDuplicateFile($hex) { $hexmatches = postsByHex($hex); if (count($hexmatches) > 0) { foreach ($hexmatches as $hexmatch) { @@ -305,7 +314,7 @@ function createThumbnail($name, $filename, $new_w, $new_h) { } else { return false; } - + if (!$src_img) { fancyDie("Unable to read uploaded file during thumbnailing. A common cause for this is an incorrect extension when the file is actually of a different type."); } @@ -314,10 +323,10 @@ function createThumbnail($name, $filename, $new_w, $new_h) { $percent = ($old_x > $old_y) ? ($new_w / $old_x) : ($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); - + if (preg_match("/png/", $system[0])) { if (!imagepng($dst_img, $filename)) { return false; @@ -327,45 +336,47 @@ function createThumbnail($name, $filename, $new_w, $new_h) { return false; } } else if (preg_match("/gif/", $system[0])) { - if (!imagegif($dst_img, $filename)) { + if (!imagegif($dst_img, $filename)) { return false; } } - - imagedestroy($dst_img); - imagedestroy($src_img); - + + imagedestroy($dst_img); + imagedestroy($src_img); + return true; } function fastImageCopyResampled(&$dst_image, &$src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality = 3) { - // Author: Tim Eckel - Date: 12/17/04 - Project: FreeRingers.net - Freely distributable. - if (empty($src_image) || empty($dst_image)) { return false; } + // Author: Tim Eckel - Date: 12/17/04 - Project: FreeRingers.net - Freely distributable. + if (empty($src_image) || empty($dst_image)) { + return false; + } if ($quality <= 1) { - $temp = imagecreatetruecolor ($dst_w + 1, $dst_h + 1); - - imagecopyresized ($temp, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w + 1, $dst_h + 1, $src_w, $src_h); - imagecopyresized ($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $dst_w, $dst_h); - imagedestroy ($temp); + $temp = imagecreatetruecolor($dst_w + 1, $dst_h + 1); + + imagecopyresized($temp, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w + 1, $dst_h + 1, $src_w, $src_h); + imagecopyresized($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $dst_w, $dst_h); + imagedestroy($temp); } elseif ($quality < 5 && (($dst_w * $quality) < $src_w || ($dst_h * $quality) < $src_h)) { $tmp_w = $dst_w * $quality; $tmp_h = $dst_h * $quality; - $temp = imagecreatetruecolor ($tmp_w + 1, $tmp_h + 1); - - imagecopyresized ($temp, $src_image, $dst_x * $quality, $dst_y * $quality, $src_x, $src_y, $tmp_w + 1, $tmp_h + 1, $src_w, $src_h); - imagecopyresampled ($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $tmp_w, $tmp_h); - imagedestroy ($temp); + $temp = imagecreatetruecolor($tmp_w + 1, $tmp_h + 1); + + imagecopyresized($temp, $src_image, $dst_x * $quality, $dst_y * $quality, $src_x, $src_y, $tmp_w + 1, $tmp_h + 1, $src_w, $src_h); + imagecopyresampled($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $tmp_w, $tmp_h); + imagedestroy($temp); } else { - imagecopyresampled ($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); + imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); } - + return true; } function strallpos($haystack, $needle, $offset = 0) { $result = array(); - for ($i = $offset;$i diff --git a/inc/html.php b/inc/html.php index c852c16..f9dab57 100644 --- a/inc/html.php +++ b/inc/html.php @@ -1,5 +1,7 @@ @@ -58,7 +62,7 @@ EOF; EOF; } - + $return .= <<