Add optional WebA and WebM support

This commit is contained in:
Trevor Slocum 2014-06-24 12:51:22 -07:00
parent 777800c696
commit 90a878f8ee
16 changed files with 860 additions and 705 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ settings.php
.posts.lock .posts.lock
.project .project
.settings/ .settings/
.idea/

View File

@ -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. **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 Features
------------ ------------
- GIF, JPG, PNG and WebA/WebM upload.
- Reference links >>### - Reference links >>###
- Delete post via password. - Delete post via password.
- Management panel: - Management panel:
@ -30,6 +33,11 @@ Installing
- `git clone git://github.com/tslocum/TinyIB.git ./` - `git clone git://github.com/tslocum/TinyIB.git ./`
4. Copy **settings.default.php** to **settings.php** 4. Copy **settings.default.php** to **settings.php**
5. Configure **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: 6. [CHMOD](http://en.wikipedia.org/wiki/Chmod) write permissions to these directories:
- ./ (the directory containing TinyIB) - ./ (the directory containing TinyIB)
- ./src/ - ./src/
@ -41,6 +49,15 @@ Installing
- Directories will be verified to be writable. - Directories will be verified to be writable.
- The file index.html will be created containing the new image board. - 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 Updating
------------ ------------

View File

@ -1,182 +1,215 @@
html, body { html, body {
font-size:12pt; font-size: 12pt;
background:#EEF2FF; background: #EEF2FF;
color:#000000; color: #000000;
} }
a { a {
background:inherit; background: inherit;
color:#34345C; color: #34345C;
text-decoration:none; text-decoration: none;
font-family:sans-serif; font-family: sans-serif;
} }
a:visited { a:visited {
background:inherit; background: inherit;
color:#34345C; color: #34345C;
text-decoration:none; text-decoration: none;
font-family:sans-serif; font-family: sans-serif;
} }
a:hover { a:hover {
color:#DD0000; color: #DD0000;
background:inherit; background: inherit;
font-family:sans-serif; font-family: sans-serif;
} }
.filesize a { .filesize a {
text-decoration:underline; text-decoration: underline;
} }
.filesize a:visited { .filesize a:visited {
text-decoration:underline; text-decoration: underline;
} }
.adminbar { .adminbar {
background:inherit; background: inherit;
} }
.logo { .logo {
clear:both; clear: both;
text-align:center; text-align: center;
background:inherit; background: inherit;
font-size:24pt; font-size: 24pt;
color:#AF0A0F; color: #AF0A0F;
width:100%; width: 100%;
} }
.replymode { .replymode {
background:#0010E0; background: #0010E0;
color:#FFFFFF; color: #FFFFFF;
width:100%; width: 100%;
} }
.manageinfo { .manageinfo {
background:#00B930; background: #00B930;
color:#FFFFFF; color: #FFFFFF;
width:100%; width: 100%;
} }
.catalogmode { .catalogmode {
background:#0040E0; background: #0040E0;
color:#FFFFFF; color: #FFFFFF;
width:100%; width: 100%;
} }
.postarea { .postarea {
background:inherit; background: inherit;
} }
.rules { .rules {
/*font-size:0.7em;*/ /*font-size:0.7em;*/
width: 468px; width: 468px;
font-size: 10px; font-size: 10px;
font-family: sans-serif; font-family: sans-serif;
} }
.rules li { .rules li {
margin-left: 1em; margin-left: 1em;
/*text-indent: 0em;*/ /*text-indent: 0em;*/
} }
.postblock { .postblock {
background:#9988EE; background: #9988EE;
color:#000000; color: #000000;
font-weight:800; font-weight: 800;
} }
.footer { .footer {
font-size:10px; font-size: 10px;
font-family:sans-serif; font-family: sans-serif;
} }
.passvalid { .passvalid {
background:#9988EE; background: #9988EE;
text-align:center; text-align: center;
width:100%; width: 100%;
color:#ffffff; color: #ffffff;
} }
.dellist { .dellist {
background:inherit; background: inherit;
text-align:center; text-align: center;
} }
.delbuttons { .delbuttons {
background:inherit; background: inherit;
text-align:center; text-align: center;
padding-bottom:4px; padding-bottom: 4px;
} }
.managehead { .managehead {
background:#0F8FE1; background: #0F8FE1;
color:#000000; color: #000000;
font-family:sans-serif; font-family: sans-serif;
font-size:14px; font-size: 14px;
padding:0px; padding: 0px;
} }
.postlists { .postlists {
background:#FFFFFF; background: #FFFFFF;
width:100%; width: 100%;
padding:0px; padding: 0px;
color:#000000; color: #000000;
} }
.row1 { .row1 {
background:#9AD2F6; background: #9AD2F6;
font-family:sans-serif; font-family: sans-serif;
font-size:12px; font-size: 12px;
color:#000000; color: #000000;
} }
.row2 { .row2 {
background:#FFFFFF; background: #FFFFFF;
font-family:sans-serif; font-family: sans-serif;
font-size:12px; font-size: 12px;
color:#000000; color: #000000;
} }
.unkfunc { .unkfunc {
color:#789922; color: #789922;
} }
.filesize { .filesize {
font-size:12px; font-size: 12px;
font-family:sans-serif; font-family: sans-serif;
text-decoration:underline; text-decoration: underline;
/*padding-left:3em;*/ /*padding-left:3em;*/
} }
.filetitle { .filetitle {
background:inherit; background: inherit;
font-size:18px; font-size: 18px;
font-family:serif; font-family: serif;
color:#0F0C5D; color: #0F0C5D;
font-weight:800; font-weight: 800;
} }
.postername { .postername {
background:inherit; background: inherit;
font-size:12px; font-size: 12px;
font-family:serif; font-family: serif;
color:#117743; color: #117743;
font-weight:800; font-weight: 800;
} }
.oldpost { .oldpost {
background:inherit; background: inherit;
font-size:18px; font-size: 18px;
font-family:serif; font-family: serif;
color:#0F0C5D; color: #0F0C5D;
font-weight:800; font-weight: 800;
} }
.omittedposts { .omittedposts {
background:inherit; background: inherit;
font-size:18px; font-size: 18px;
font-family:serif; font-family: serif;
color:#070707; color: #070707;
font-weight:800; font-weight: 800;
} }
.reply { .reply {
background:#D6DAF0; background: #D6DAF0;
color:#000000; color: #000000;
font-family:serif; font-family: serif;
} }
.replyhl { .replyhl {
background: #D6BAD0; background: #D6BAD0;
color: #000000; color: #000000;
} }
.replytitle { .replytitle {
background:inherit; background: inherit;
font-size:18px; font-size: 18px;
font-family:serif; font-family: serif;
color:#0F0C5D; color: #0F0C5D;
font-weight:800; font-weight: 800;
} }
.commentpostername { .commentpostername {
background:inherit; background: inherit;
font-size:12px; font-size: 12px;
font-family:serif; font-family: serif;
color:#117743; color: #117743;
font-weight:800; font-weight: 800;
} }
.thumbnailmsg { .thumbnailmsg {
background:inherit; background: inherit;
font-size:9px; font-size: 9px;
font-family:sans-serif; font-family: sans-serif;
color:#000000; color: #000000;
} }

View File

@ -1,151 +1,182 @@
html, body { html, body {
background:#FFFFEE; background: #FFFFEE;
color:#800000; color: #800000;
} }
a { a {
color:#0000EE; color: #0000EE;
} }
a:hover { a:hover {
color:#DD0000; color: #DD0000;
} }
.reflink a:hover{
.reflink a:hover {
font-weight: bold; font-weight: bold;
} }
.logo { .logo {
clear:both; clear: both;
text-align:center; text-align: center;
font-size:2em; font-size: 2em;
color:#800000; color: #800000;
width:100%; width: 100%;
} }
.replymode { .replymode {
background:#E04000; background: #E04000;
text-align:center; text-align: center;
padding:2px; padding: 2px;
color:#FFFFFF; color: #FFFFFF;
width:100%; width: 100%;
} }
.manageinfo { .manageinfo {
background:#00B930; background: #00B930;
text-align:center; text-align: center;
padding:2px; padding: 2px;
color:#FFFFFF; color: #FFFFFF;
width:100%; width: 100%;
} }
.catalogmode { .catalogmode {
background:#0040E0; background: #0040E0;
text-align:center; text-align: center;
padding:2px; padding: 2px;
color:#FFFFFF; color: #FFFFFF;
width:100%; width: 100%;
} }
.rules { .rules {
/*font-size:0.7em;*/ /*font-size:0.7em;*/
width: 468px; width: 468px;
font-size: 10px; font-size: 10px;
font-family: sans-serif; font-family: sans-serif;
} }
.rules li { .rules li {
margin-left: 1em; margin-left: 1em;
/*text-indent: 0em;*/ /*text-indent: 0em;*/
} }
.postblock { .postblock {
background:#EEAA88; background: #EEAA88;
color:#800000; color: #800000;
font-weight:800; font-weight: 800;
} }
.footer { .footer {
font-size:12px; font-size: 12px;
font-family:serif; font-family: serif;
} }
.passvalid { .passvalid {
background:#EEAA88; background: #EEAA88;
text-align:center; text-align: center;
width:100%; width: 100%;
color:#ffffff; color: #ffffff;
} }
.dellist { .dellist {
font-weight: bold; font-weight: bold;
text-align:center; text-align: center;
} }
.delbuttons { .delbuttons {
text-align:center; text-align: center;
padding-bottom:4px; padding-bottom: 4px;
} }
.managehead { .managehead {
background:#AAAA66; background: #AAAA66;
color:#400000; color: #400000;
padding:0px; padding: 0px;
} }
.postlists { .postlists {
background:#FFFFFF; background: #FFFFFF;
width:100%; width: 100%;
padding:0px; padding: 0px;
color:#800000; color: #800000;
} }
.row1 { .row1 {
background:#EEEECC; background: #EEEECC;
color:#800000; color: #800000;
} }
.row2 { .row2 {
background:#DDDDAA; background: #DDDDAA;
color:#800000; color: #800000;
} }
.unkfunc { .unkfunc {
background:inherit; background: inherit;
color:#789922; color: #789922;
} }
.filesize { .filesize {
text-decoration:none; text-decoration: none;
} }
.filetitle { .filetitle {
background:inherit; background: inherit;
font-size:1.2em; font-size: 1.2em;
color:#CC1105; color: #CC1105;
font-weight:800; font-weight: 800;
} }
.postername { .postername {
color:#117743; color: #117743;
font-weight:bold; font-weight: bold;
} }
.postertrip { .postertrip {
color:#228854; color: #228854;
} }
.oldpost { .oldpost {
color:#CC1105; color: #CC1105;
font-weight:800; font-weight: 800;
} }
.omittedposts { .omittedposts {
color:#707070; color: #707070;
} }
.reply { .reply {
background: #F0E0D6; background: #F0E0D6;
color: #800000; color: #800000;
} }
.replyhl { .replyhl {
background: #F0C0B0; background: #F0C0B0;
color: #800000; color: #800000;
} }
.replytitle { .replytitle {
font-size: 1.2em; font-size: 1.2em;
color:#CC1105; color: #CC1105;
font-weight:800; font-weight: 800;
} }
.commentpostername { .commentpostername {
color:#117743; color: #117743;
font-weight:800; font-weight: 800;
} }
.thumbnailmsg { .thumbnailmsg {
font-size: small; font-size: small;
color:#800000; color: #800000;
} }
.abbrev { .abbrev {
color:#707070; color: #707070;
} }
.highlight { .highlight {
background:#F0E0D6; background: #F0E0D6;
color:#800000; color: #800000;
border: 2px dashed #EEAA88; border: 2px dashed #EEAA88;
} }

View File

@ -22,9 +22,9 @@ form {
} }
.aa { .aa {
white-space: pre; white-space: pre;
text-align: left; text-align: left;
font-family: IPAMonaPGothic, Mona, 'MS PGothic', YOzFontAA97 !important; font-family: IPAMonaPGothic, Mona, 'MS PGothic', YOzFontAA97 !important;
} }
.thumb { .thumb {
@ -58,7 +58,7 @@ form {
text-decoration: none; text-decoration: none;
} }
.reflink a:hover{ .reflink a:hover {
color: #800000; color: #800000;
} }
@ -73,7 +73,7 @@ form {
} }
.doubledash { .doubledash {
vertical-align: top; vertical-align: top;
clear: both; clear: both;
float: left; float: left;
font-size: 1.75em; font-size: 1.75em;
@ -91,7 +91,7 @@ form {
.footer { .footer {
clear: both; clear: both;
text-align:center; text-align: center;
} }
.rules { .rules {
@ -118,4 +118,6 @@ form {
float: right; float: right;
} }
.adminbar a:link, .adminbar a:visited, .adminbar a:active, .adminbar a:hover { text-decoration: none; } .adminbar a:link, .adminbar a:visited, .adminbar a:active, .adminbar a:hover {
text-decoration: none;
}

View File

@ -10,10 +10,16 @@ ob_implicit_flush();
ob_end_flush(); ob_end_flush();
if (get_magic_quotes_gpc()) { if (get_magic_quotes_gpc()) {
foreach ($_GET as $key => $val) { $_GET[$key] = stripslashes($val); } foreach ($_GET as $key => $val) {
foreach ($_POST as $key => $val) { $_POST[$key] = stripslashes($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) { function fancyDie($message) {
die('<body text="#800000" bgcolor="#FFFFEE" align="center"><br><div style="display: inline-block; background-color: #F0E0D6;font-size: 1.25em;font-family: Tahoma, Geneva, sans-serif;padding: 7px;border: 1px solid #D9BFB7;border-left: none;border-top: none;">' . $message . '</div><br><br>- <a href="javascript:history.go(-1)">Click here to go back</a> -</body>'); die('<body text="#800000" bgcolor="#FFFFEE" align="center"><br><div style="display: inline-block; background-color: #F0E0D6;font-size: 1.25em;font-family: Tahoma, Geneva, sans-serif;padding: 7px;border: 1px solid #D9BFB7;border-left: none;border-top: none;">' . $message . '</div><br><br>- <a href="javascript:history.go(-1)">Click here to go back</a> -</body>');
@ -26,7 +32,9 @@ require 'settings.php';
// Check directories are writable by the script // Check directories are writable by the script
$writedirs = array("res", "src", "thumb"); $writedirs = array("res", "src", "thumb");
if (TINYIB_DBMODE == 'flatfile') { $writedirs[] = "inc/flatfile"; } if (TINYIB_DBMODE == 'flatfile') {
$writedirs[] = "inc/flatfile";
}
foreach ($writedirs as $dir) { foreach ($writedirs as $dir) {
if (!is_writable($dir)) { if (!is_writable($dir)) {
fancyDie("Directory '" . $dir . "' can not be written to. Please modify its permissions."); fancyDie("Directory '" . $dir . "' can not be written to. Please modify its permissions.");
@ -58,12 +66,12 @@ if (isset($_POST['message']) || isset($_POST['file'])) {
checkMessageSize(); checkMessageSize();
checkFlood(); checkFlood();
} }
$post = newPost(setParent()); $post = newPost(setParent());
$post['ip'] = $_SERVER['REMOTE_ADDR']; $post['ip'] = $_SERVER['REMOTE_ADDR'];
list($post['name'], $post['tripcode']) = nameAndTripcode($_POST['name']); list($post['name'], $post['tripcode']) = nameAndTripcode($_POST['name']);
$post['name'] = cleanString(substr($post['name'], 0, 75)); $post['name'] = cleanString(substr($post['name'], 0, 75));
$post['email'] = cleanString(str_replace('"', '&quot;', substr($_POST['email'], 0, 75))); $post['email'] = cleanString(str_replace('"', '&quot;', substr($_POST['email'], 0, 75)));
$post['subject'] = cleanString(substr($_POST['subject'], 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['password'] = ($_POST['password'] != '') ? md5(md5($_POST['password'])) : '';
$post['nameblock'] = nameBlock($post['name'], $post['tripcode'], $post['email'], time(), $rawposttext); $post['nameblock'] = nameBlock($post['name'], $post['tripcode'], $post['email'], time(), $rawposttext);
if (isset($_FILES['file'])) { if (isset($_FILES['file'])) {
if ($_FILES['file']['name'] != "") { if ($_FILES['file']['name'] != "") {
validateFileUpload(); validateFileUpload();
if (!is_file($_FILES['file']['tmp_name']) || !is_readable($_FILES['file']['tmp_name'])) { if (!is_file($_FILES['file']['tmp_name']) || !is_readable($_FILES['file']['tmp_name'])) {
fancyDie("File transfer failure. Please retry the submission."); fancyDie("File transfer failure. Please retry the submission.");
} }
if ((TINYIB_MAXKB > 0) && (filesize($_FILES['file']['tmp_name']) > (TINYIB_MAXKB * 1024))) { if ((TINYIB_MAXKB > 0) && (filesize($_FILES['file']['tmp_name']) > (TINYIB_MAXKB * 1024))) {
fancyDie("That file is larger than " . TINYIB_MAXKBDESC . "."); 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_hex'] = md5_file($_FILES['file']['tmp_name']);
$post['file_size'] = $_FILES['file']['size']; $post['file_size'] = $_FILES['file']['size'];
$post['file_size_formatted'] = convertBytes($post['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); $file_type = strtolower(preg_replace('/.*(\..+)/', '\1', $_FILES['file']['name']));
$post['file'] = $file_name . $file_type; if ($file_type == '.jpeg') {
$post['thumb'] = $file_name . "s" . $file_type; $file_type = '.jpg';
$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.");
} }
if ($file_type == '.weba') {
if (!@getimagesize($_FILES['file']['tmp_name'])) { $file_type = '.webm';
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.");
} }
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)) { if (!move_uploaded_file($_FILES['file']['tmp_name'], $file_location)) {
fancyDie("Could not copy uploaded file."); fancyDie("Could not copy uploaded file.");
} }
if ($_FILES['file']['size'] != filesize($file_location)) { if ($file_type == '.webm') {
fancyDie("File transfer failure. Please go back and try again."); $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)));
$post['image_width'] = $file_info[0]; $post['image_height'] = $file_info[1]; } else {
if (!@getimagesize($file_location)) {
list($thumb_maxwidth, $thumb_maxheight) = thumbnailDimensions($post); @unlink($file_location);
fancyDie("Failed to read the size of the uploaded file. Please retry the submission.");
if (!createThumbnail($file_location, $thumb_location, $thumb_maxwidth, $thumb_maxheight)) { }
fancyDie("Could not create thumbnail.");
$file_info = getimagesize($file_location);
$file_mime = $file_info['mime'];
} }
$thumb_info = getimagesize($thumb_location); if (!($file_mime == "image/jpeg" || $file_mime == "image/gif" || $file_mime == "image/png" || (TINYIB_WEBM && ($file_mime == "video/webm" || $file_mime == "audio/webm")))) {
$post['thumb_width'] = $thumb_info[0]; $post['thumb_height'] = $thumb_info[1]; @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['file'] == '') { // No file uploaded
if ($post['parent'] == TINYIB_NEWTHREAD) { if ($post['parent'] == TINYIB_NEWTHREAD) {
fancyDie("An image is required to start a thread."); fancyDie("An image is required to start a thread.");
@ -147,18 +229,18 @@ if (isset($_POST['message']) || isset($_POST['file'])) {
} else { } else {
echo $post['file_original'] . ' uploaded.<br>'; echo $post['file_original'] . ' uploaded.<br>';
} }
$post['id'] = insertPost($post); $post['id'] = insertPost($post);
if (strtolower($post['email']) == 'noko') { if (strtolower($post['email']) == 'noko') {
$redirect = 'res/' . ($post['parent'] == TINYIB_NEWTHREAD ? $post['id'] : $post['parent']) . '.html#' . $post['id']; $redirect = 'res/' . ($post['parent'] == TINYIB_NEWTHREAD ? $post['id'] : $post['parent']) . '.html#' . $post['id'];
} }
trimThreads(); trimThreads();
echo 'Updating thread...<br>'; echo 'Updating thread...<br>';
if ($post['parent'] != TINYIB_NEWTHREAD) { if ($post['parent'] != TINYIB_NEWTHREAD) {
rebuildThread($post['parent']); rebuildThread($post['parent']);
if (strtolower($post['email']) != 'sage') { if (strtolower($post['email']) != 'sage') {
if (TINYIB_MAXREPLIES == 0 || numRepliesToThreadByID($post['parent']) <= TINYIB_MAXREPLIES) { if (TINYIB_MAXREPLIES == 0 || numRepliesToThreadByID($post['parent']) <= TINYIB_MAXREPLIES) {
bumpThreadByID($post['parent']); bumpThreadByID($post['parent']);
@ -167,23 +249,29 @@ if (isset($_POST['message']) || isset($_POST['file'])) {
} else { } else {
rebuildThread($post['id']); rebuildThread($post['id']);
} }
echo 'Updating index...<br>'; echo 'Updating index...<br>';
rebuildIndexes(); rebuildIndexes();
// Check if the request is to delete a post and/or its associated image // Check if the request is to delete a post and/or its associated image
} elseif (isset($_GET['delete']) && !isset($_GET['manage'])) { } 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']); $post = postByID($_POST['delete']);
if ($post) { if ($post) {
list($loggedin, $isadmin) = manageCheckLogIn(); list($loggedin, $isadmin) = manageCheckLogIn();
if ($loggedin && $_POST['password'] == '') { if ($loggedin && $_POST['password'] == '') {
// Redirect to post moderation page // Redirect to post moderation page
echo '--&gt; --&gt; --&gt;<meta http-equiv="refresh" content="0;url=' . basename($_SERVER['PHP_SELF']) . '?manage&moderate=' . $_POST['delete'] . '">'; echo '--&gt; --&gt; --&gt;<meta http-equiv="refresh" content="0;url=' . basename($_SERVER['PHP_SELF']) . '?manage&moderate=' . $_POST['delete'] . '">';
} elseif ($post['password'] != '' && md5(md5($_POST['password'])) == $post['password']) { } elseif ($post['password'] != '' && md5(md5($_POST['password'])) == $post['password']) {
deletePostByID($post['id']); 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.'); fancyDie('Post deleted.');
} else { } else {
fancyDie('Invalid password.'); fancyDie('Invalid password.');
@ -195,12 +283,16 @@ if (isset($_POST['message']) || isset($_POST['file'])) {
$redirect = false; $redirect = false;
// Check if the request is to access the management area // Check if the request is to access the management area
} elseif (isset($_GET['manage'])) { } elseif (isset($_GET['manage'])) {
$text = ''; $onload = ''; $navbar = '&nbsp;'; $text = '';
$redirect = false; $loggedin = false; $isadmin = false; $onload = '';
$navbar = '&nbsp;';
$redirect = false;
$loggedin = false;
$isadmin = false;
$returnlink = basename($_SERVER['PHP_SELF']); $returnlink = basename($_SERVER['PHP_SELF']);
list($loggedin, $isadmin) = manageCheckLogIn(); list($loggedin, $isadmin) = manageCheckLogIn();
if ($loggedin) { if ($loggedin) {
if ($isadmin) { if ($isadmin) {
if (isset($_GET['rebuildall'])) { if (isset($_GET['rebuildall'])) {
@ -212,19 +304,19 @@ if (isset($_POST['message']) || isset($_POST['file'])) {
$text .= manageInfo('Rebuilt board.'); $text .= manageInfo('Rebuilt board.');
} elseif (isset($_GET['bans'])) { } elseif (isset($_GET['bans'])) {
clearExpiredBans(); clearExpiredBans();
if (isset($_POST['ip'])) { if (isset($_POST['ip'])) {
if ($_POST['ip'] != '') { if ($_POST['ip'] != '') {
$banexists = banByIP($_POST['ip']); $banexists = banByIP($_POST['ip']);
if ($banexists) { if ($banexists) {
fancyDie('Sorry, there is already a ban on record for that IP address.'); fancyDie('Sorry, there is already a ban on record for that IP address.');
} }
$ban = array(); $ban = array();
$ban['ip'] = $_POST['ip']; $ban['ip'] = $_POST['ip'];
$ban['expire'] = ($_POST['expire'] > 0) ? (time() + $_POST['expire']) : 0; $ban['expire'] = ($_POST['expire'] > 0) ? (time() + $_POST['expire']) : 0;
$ban['reason'] = $_POST['reason']; $ban['reason'] = $_POST['reason'];
insertBan($ban); insertBan($ban);
$text .= manageInfo('Ban record added for ' . $ban['ip']); $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']); $text .= manageInfo('Ban record lifted for ' . $ban['ip']);
} }
} }
$onload = manageOnLoad('bans'); $onload = manageOnLoad('bans');
$text .= manageBanForm(); $text .= manageBanForm();
$text .= manageBansTable(); $text .= manageBansTable();
@ -254,7 +346,7 @@ if (isset($_POST['message']) || isset($_POST['file'])) {
} }
} }
} }
if (isset($_GET['delete'])) { if (isset($_GET['delete'])) {
$post = postByID($_GET['delete']); $post = postByID($_GET['delete']);
if ($post) { if ($post) {
@ -303,5 +395,3 @@ if (isset($_POST['message']) || isset($_POST['file'])) {
if ($redirect) { if ($redirect) {
echo '--&gt; --&gt; --&gt;<meta http-equiv="refresh" content="0;url=' . (is_string($redirect) ? $redirect : 'index.html') . '">'; echo '--&gt; --&gt; --&gt;<meta http-equiv="refresh" content="0;url=' . (is_string($redirect) ? $redirect : 'index.html') . '">';
} }
?>

View File

@ -1,38 +1,40 @@
<?php <?php
if (!defined('TINYIB_BOARD')) { die(''); } if (!defined('TINYIB_BOARD')) {
die('');
}
# Post Structure # Post Structure
define('POSTS_FILE', '.posts'); define('POSTS_FILE', '.posts');
define('POST_ID', 0); define('POST_ID', 0);
define('POST_PARENT', 1); define('POST_PARENT', 1);
define('POST_TIMESTAMP', 2); define('POST_TIMESTAMP', 2);
define('POST_BUMPED', 3); define('POST_BUMPED', 3);
define('POST_IP', 4); define('POST_IP', 4);
define('POST_NAME', 5); define('POST_NAME', 5);
define('POST_TRIPCODE', 6); define('POST_TRIPCODE', 6);
define('POST_EMAIL', 7); define('POST_EMAIL', 7);
define('POST_NAMEBLOCK', 8); define('POST_NAMEBLOCK', 8);
define('POST_SUBJECT', 9); define('POST_SUBJECT', 9);
define('POST_MESSAGE', 10); define('POST_MESSAGE', 10);
define('POST_PASSWORD', 11); define('POST_PASSWORD', 11);
define('POST_FILE', 12); define('POST_FILE', 12);
define('POST_FILE_HEX', 13); define('POST_FILE_HEX', 13);
define('POST_FILE_ORIGINAL', 14); define('POST_FILE_ORIGINAL', 14);
define('POST_FILE_SIZE', 15); define('POST_FILE_SIZE', 15);
define('POST_FILE_SIZE_FORMATTED', 16); define('POST_FILE_SIZE_FORMATTED', 16);
define('POST_IMAGE_WIDTH', 17); define('POST_IMAGE_WIDTH', 17);
define('POST_IMAGE_HEIGHT', 18); define('POST_IMAGE_HEIGHT', 18);
define('POST_THUMB', 19); define('POST_THUMB', 19);
define('POST_THUMB_WIDTH', 20); define('POST_THUMB_WIDTH', 20);
define('POST_THUMB_HEIGHT', 21); define('POST_THUMB_HEIGHT', 21);
# Ban Structure # Ban Structure
define('BANS_FILE', '.bans'); define('BANS_FILE', '.bans');
define('BAN_ID', 0); define('BAN_ID', 0);
define('BAN_IP', 1); define('BAN_IP', 1);
define('BAN_TIMESTAMP', 2); define('BAN_TIMESTAMP', 2);
define('BAN_EXPIRE', 3); define('BAN_EXPIRE', 3);
define('BAN_REASON', 4); define('BAN_REASON', 4);
require_once 'flatfile/flatfile.php'; require_once 'flatfile/flatfile.php';
$db = new Flatfile(); $db = new Flatfile();
@ -51,7 +53,7 @@ function threadExistsByID($id) {
$compClause = new AndWhereClause(); $compClause = new AndWhereClause();
$compClause->add(new SimpleWhereClause(POST_ID, '=', $id, INTEGER_COMPARISON)); $compClause->add(new SimpleWhereClause(POST_ID, '=', $id, INTEGER_COMPARISON));
$compClause->add(new SimpleWhereClause(POST_PARENT, '=', 0, INTEGER_COMPARISON)); $compClause->add(new SimpleWhereClause(POST_PARENT, '=', 0, INTEGER_COMPARISON));
return count($GLOBALS['db']->selectWhere(POSTS_FILE, $compClause, 1)) > 0; return count($GLOBALS['db']->selectWhere(POSTS_FILE, $compClause, 1)) > 0;
} }
@ -67,7 +69,7 @@ function insertPost($newpost) {
$post[POST_EMAIL] = $newpost['email']; $post[POST_EMAIL] = $newpost['email'];
$post[POST_NAMEBLOCK] = $newpost['nameblock']; $post[POST_NAMEBLOCK] = $newpost['nameblock'];
$post[POST_SUBJECT] = $newpost['subject']; $post[POST_SUBJECT] = $newpost['subject'];
$post[POST_MESSAGE] = $newpost['message']; $post[POST_MESSAGE] = $newpost['message'];
$post[POST_PASSWORD] = $newpost['password']; $post[POST_PASSWORD] = $newpost['password'];
$post[POST_FILE] = $newpost['file']; $post[POST_FILE] = $newpost['file'];
$post[POST_FILE_HEX] = $newpost['file_hex']; $post[POST_FILE_HEX] = $newpost['file_hex'];
@ -99,7 +101,7 @@ function countThreads() {
return count($rows); return count($rows);
} }
function convertPostsToSQLStyle($posts, $singlepost=false) { function convertPostsToSQLStyle($posts, $singlepost = false) {
$newposts = array(); $newposts = array();
foreach ($posts as $oldpost) { foreach ($posts as $oldpost) {
$post = newPost(); $post = newPost();
@ -125,12 +127,14 @@ function convertPostsToSQLStyle($posts, $singlepost=false) {
$post['thumb'] = $oldpost[POST_THUMB]; $post['thumb'] = $oldpost[POST_THUMB];
$post['thumb_width'] = $oldpost[POST_THUMB_WIDTH]; $post['thumb_width'] = $oldpost[POST_THUMB_WIDTH];
$post['thumb_height'] = $oldpost[POST_THUMB_HEIGHT]; $post['thumb_height'] = $oldpost[POST_THUMB_HEIGHT];
if ($post['parent'] == '') { if ($post['parent'] == '') {
$post['parent'] = TINYIB_NEWTHREAD; $post['parent'] = TINYIB_NEWTHREAD;
} }
if ($singlepost) { return $post; } if ($singlepost) {
return $post;
}
$newposts[] = $post; $newposts[] = $post;
} }
return $newposts; return $newposts;
@ -150,7 +154,7 @@ function postsInThreadByID($id) {
$compClause = new OrWhereClause(); $compClause = new OrWhereClause();
$compClause->add(new SimpleWhereClause(POST_ID, '=', $id, INTEGER_COMPARISON)); $compClause->add(new SimpleWhereClause(POST_ID, '=', $id, INTEGER_COMPARISON));
$compClause->add(new SimpleWhereClause(POST_PARENT, '=', $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)); $rows = $GLOBALS['db']->selectWhere(POSTS_FILE, $compClause, -1, new OrderBy(POST_ID, ASCENDING, INTEGER_COMPARISON));
return convertPostsToSQLStyle($rows); return convertPostsToSQLStyle($rows);
} }
@ -175,7 +179,7 @@ function deletePostByID($id) {
$thispost = $post; $thispost = $post;
} }
} }
if (isset($thispost)) { if (isset($thispost)) {
if ($thispost['parent'] == 0) { if ($thispost['parent'] == 0) {
@unlink('res/' . $thispost['id'] . '.html'); @unlink('res/' . $thispost['id'] . '.html');
@ -190,7 +194,7 @@ function trimThreads() {
$numthreads = countThreads(); $numthreads = countThreads();
if ($numthreads > TINYIB_MAXTHREADS) { if ($numthreads > TINYIB_MAXTHREADS) {
$allthreads = allThreads(); $allthreads = allThreads();
for ($i=TINYIB_MAXTHREADS;$i<$numthreads;$i++) { for ($i = TINYIB_MAXTHREADS; $i < $numthreads; $i++) {
deletePostByID($allthreads[$i]['id']); deletePostByID($allthreads[$i]['id']);
} }
} }
@ -216,7 +220,7 @@ function allBans() {
return convertBansToSQLStyle($rows); return convertBansToSQLStyle($rows);
} }
function convertBansToSQLStyle($bans, $singleban=false) { function convertBansToSQLStyle($bans, $singleban = false) {
$newbans = array(); $newbans = array();
foreach ($bans as $oldban) { foreach ($bans as $oldban) {
$ban = array(); $ban = array();
@ -225,8 +229,10 @@ function convertBansToSQLStyle($bans, $singleban=false) {
$ban['timestamp'] = $oldban[BAN_TIMESTAMP]; $ban['timestamp'] = $oldban[BAN_TIMESTAMP];
$ban['expire'] = $oldban[BAN_EXPIRE]; $ban['expire'] = $oldban[BAN_EXPIRE];
$ban['reason'] = $oldban[BAN_REASON]; $ban['reason'] = $oldban[BAN_REASON];
if ($singleban) { return $ban; } if ($singleban) {
return $ban;
}
$newbans[] = $ban; $newbans[] = $ban;
} }
return $newbans; return $newbans;
@ -239,7 +245,7 @@ function insertBan($newban) {
$ban[BAN_TIMESTAMP] = time(); $ban[BAN_TIMESTAMP] = time();
$ban[BAN_EXPIRE] = $newban['expire']; $ban[BAN_EXPIRE] = $newban['expire'];
$ban[BAN_REASON] = $newban['reason']; $ban[BAN_REASON] = $newban['reason'];
return $GLOBALS['db']->insertWithAutoId(BANS_FILE, BAN_ID, $ban); return $GLOBALS['db']->insertWithAutoId(BANS_FILE, BAN_ID, $ban);
} }
@ -247,7 +253,7 @@ function clearExpiredBans() {
$compClause = new AndWhereClause(); $compClause = new AndWhereClause();
$compClause->add(new SimpleWhereClause(BAN_EXPIRE, '>', 0, INTEGER_COMPARISON)); $compClause->add(new SimpleWhereClause(BAN_EXPIRE, '>', 0, INTEGER_COMPARISON));
$compClause->add(new SimpleWhereClause(BAN_EXPIRE, '<=', time(), INTEGER_COMPARISON)); $compClause->add(new SimpleWhereClause(BAN_EXPIRE, '<=', time(), INTEGER_COMPARISON));
$bans = $GLOBALS['db']->selectWhere(BANS_FILE, $compClause, -1); $bans = $GLOBALS['db']->selectWhere(BANS_FILE, $compClause, -1);
foreach ($bans as $ban) { foreach ($bans as $ban) {
deleteBanByID($ban[BAN_ID]); deleteBanByID($ban[BAN_ID]);
@ -257,5 +263,3 @@ function clearExpiredBans() {
function deleteBanByID($id) { function deleteBanByID($id) {
$GLOBALS['db']->deleteWhere(BANS_FILE, new SimpleWhereClause(BAN_ID, '=', $id, INTEGER_COMPARISON)); $GLOBALS['db']->deleteWhere(BANS_FILE, new SimpleWhereClause(BAN_ID, '=', $id, INTEGER_COMPARISON));
} }
?>

View File

@ -1,5 +1,7 @@
<?php <?php
if (!defined('TINYIB_BOARD')) { die(''); } if (!defined('TINYIB_BOARD')) {
die('');
}
if (!function_exists('mysql_connect')) { if (!function_exists('mysql_connect')) {
fancyDie("MySQL library is not installed"); fancyDie("MySQL library is not installed");
@ -90,7 +92,7 @@ function countThreads() {
return mysql_result(mysql_query("SELECT COUNT(*) FROM `" . TINYIB_DBPOSTS . "` WHERE `parent` = 0"), 0, 0); return mysql_result(mysql_query("SELECT COUNT(*) FROM `" . TINYIB_DBPOSTS . "` WHERE `parent` = 0"), 0, 0);
} }
function allThreads() { function allThreads() {
$threads = array(); $threads = array();
$result = mysql_query("SELECT * FROM `" . TINYIB_DBPOSTS . "` WHERE `parent` = 0 ORDER BY `bumped` DESC"); $result = mysql_query("SELECT * FROM `" . TINYIB_DBPOSTS . "` WHERE `parent` = 0 ORDER BY `bumped` DESC");
if ($result) { if ($result) {
@ -105,7 +107,7 @@ function numRepliesToThreadByID($id) {
return mysql_result(mysql_query("SELECT COUNT(*) FROM `" . TINYIB_DBPOSTS . "` WHERE `parent` = " . $id), 0, 0); return mysql_result(mysql_query("SELECT COUNT(*) FROM `" . TINYIB_DBPOSTS . "` WHERE `parent` = " . $id), 0, 0);
} }
function postsInThreadByID($id) { function postsInThreadByID($id) {
$posts = array(); $posts = array();
$result = mysql_query("SELECT * FROM `" . TINYIB_DBPOSTS . "` WHERE `id` = " . $id . " OR `parent` = " . $id . " ORDER BY `id` ASC"); $result = mysql_query("SELECT * FROM `" . TINYIB_DBPOSTS . "` WHERE `id` = " . $id . " OR `parent` = " . $id . " ORDER BY `id` ASC");
if ($result) { if ($result) {
@ -116,7 +118,7 @@ function postsInThreadByID($id) {
return $posts; return $posts;
} }
function postsByHex($hex) { function postsByHex($hex) {
$posts = array(); $posts = array();
$result = mysql_query("SELECT `id`, `parent` FROM `" . TINYIB_DBPOSTS . "` WHERE `file_hex` = '" . mysql_real_escape_string($hex) . "' LIMIT 1"); $result = mysql_query("SELECT `id`, `parent` FROM `" . TINYIB_DBPOSTS . "` WHERE `file_hex` = '" . mysql_real_escape_string($hex) . "' LIMIT 1");
if ($result) { if ($result) {
@ -127,7 +129,7 @@ function postsByHex($hex) {
return $posts; return $posts;
} }
function latestPosts() { function latestPosts() {
$posts = array(); $posts = array();
$result = mysql_query("SELECT * FROM `" . TINYIB_DBPOSTS . "` ORDER BY `timestamp` DESC LIMIT 10"); $result = mysql_query("SELECT * FROM `" . TINYIB_DBPOSTS . "` ORDER BY `timestamp` DESC LIMIT 10");
if ($result) { if ($result) {
@ -138,7 +140,7 @@ function latestPosts() {
return $posts; return $posts;
} }
function deletePostByID($id) { function deletePostByID($id) {
$posts = postsInThreadByID($id); $posts = postsInThreadByID($id);
foreach ($posts as $post) { foreach ($posts as $post) {
if ($post['id'] != $id) { if ($post['id'] != $id) {
@ -159,7 +161,7 @@ function deletePostByID($id) {
function trimThreads() { function trimThreads() {
if (TINYIB_MAXTHREADS > 0) { if (TINYIB_MAXTHREADS > 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) { if ($result) {
while ($post = mysql_fetch_assoc($result)) { while ($post = mysql_fetch_assoc($result)) {
deletePostByID($post['id']); 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"); $replies = mysql_query("SELECT * FROM `" . TINYIB_DBPOSTS . "` WHERE `ip` = '" . $_SERVER['REMOTE_ADDR'] . "' ORDER BY `id` DESC LIMIT 1");
if ($replies) { if ($replies) {
while ($post = mysql_fetch_assoc($replies)) { while ($post = mysql_fetch_assoc($replies)) {
@ -224,5 +226,3 @@ function clearExpiredBans() {
function deleteBanByID($id) { function deleteBanByID($id) {
mysql_query("DELETE FROM `" . TINYIB_DBBANS . "` WHERE `id` = " . mysql_real_escape_string($id) . " LIMIT 1"); mysql_query("DELETE FROM `" . TINYIB_DBBANS . "` WHERE `id` = " . mysql_real_escape_string($id) . " LIMIT 1");
} }
?>

View File

@ -1,5 +1,7 @@
<?php <?php
if (!defined('TINYIB_BOARD')) { die(''); } if (!defined('TINYIB_BOARD')) {
die('');
}
if (!function_exists('sqlite_open')) { if (!function_exists('sqlite_open')) {
fancyDie("SQLite library is not installed"); fancyDie("SQLite library is not installed");
@ -75,11 +77,11 @@ function bumpThreadByID($id) {
sqlite_query($GLOBALS["db"], "UPDATE " . TINYIB_DBPOSTS . " SET bumped = " . time() . " WHERE id = " . $id); sqlite_query($GLOBALS["db"], "UPDATE " . TINYIB_DBPOSTS . " SET bumped = " . time() . " WHERE id = " . $id);
} }
function countThreads() { function countThreads() {
return sqlite_fetch_single(sqlite_query($GLOBALS["db"], "SELECT COUNT(*) FROM " . TINYIB_DBPOSTS . " WHERE parent = 0")); return sqlite_fetch_single(sqlite_query($GLOBALS["db"], "SELECT COUNT(*) FROM " . TINYIB_DBPOSTS . " WHERE parent = 0"));
} }
function allThreads() { function allThreads() {
$threads = array(); $threads = array();
$result = sqlite_fetch_all(sqlite_query($GLOBALS["db"], "SELECT * FROM " . TINYIB_DBPOSTS . " WHERE parent = 0 ORDER BY bumped DESC"), SQLITE_ASSOC); $result = sqlite_fetch_all(sqlite_query($GLOBALS["db"], "SELECT * FROM " . TINYIB_DBPOSTS . " WHERE parent = 0 ORDER BY bumped DESC"), SQLITE_ASSOC);
foreach ($result as $thread) { foreach ($result as $thread) {
@ -92,7 +94,7 @@ function numRepliesToThreadByID($id) {
return sqlite_fetch_single(sqlite_query($GLOBALS["db"], "SELECT COUNT(*) FROM " . TINYIB_DBPOSTS . " WHERE parent = " . $id)); return sqlite_fetch_single(sqlite_query($GLOBALS["db"], "SELECT COUNT(*) FROM " . TINYIB_DBPOSTS . " WHERE parent = " . $id));
} }
function postsInThreadByID($id) { function postsInThreadByID($id) {
$posts = array(); $posts = array();
$result = sqlite_fetch_all(sqlite_query($GLOBALS["db"], "SELECT * FROM " . TINYIB_DBPOSTS . " WHERE id = " . $id . " OR parent = " . $id . " ORDER BY id ASC"), SQLITE_ASSOC); $result = sqlite_fetch_all(sqlite_query($GLOBALS["db"], "SELECT * FROM " . TINYIB_DBPOSTS . " WHERE id = " . $id . " OR parent = " . $id . " ORDER BY id ASC"), SQLITE_ASSOC);
foreach ($result as $post) { foreach ($result as $post) {
@ -101,7 +103,7 @@ function postsInThreadByID($id) {
return $posts; return $posts;
} }
function postsByHex($hex) { function postsByHex($hex) {
$posts = array(); $posts = array();
$result = sqlite_fetch_all(sqlite_query($GLOBALS["db"], "SELECT id, parent FROM " . TINYIB_DBPOSTS . " WHERE file_hex = '" . sqlite_escape_string($hex) . "' LIMIT 1"), SQLITE_ASSOC); $result = sqlite_fetch_all(sqlite_query($GLOBALS["db"], "SELECT id, parent FROM " . TINYIB_DBPOSTS . " WHERE file_hex = '" . sqlite_escape_string($hex) . "' LIMIT 1"), SQLITE_ASSOC);
foreach ($result as $post) { foreach ($result as $post) {
@ -110,7 +112,7 @@ function postsByHex($hex) {
return $posts; return $posts;
} }
function latestPosts() { function latestPosts() {
$posts = array(); $posts = array();
$result = sqlite_fetch_all(sqlite_query($GLOBALS["db"], "SELECT * FROM " . TINYIB_DBPOSTS . " ORDER BY timestamp DESC LIMIT 10"), SQLITE_ASSOC); $result = sqlite_fetch_all(sqlite_query($GLOBALS["db"], "SELECT * FROM " . TINYIB_DBPOSTS . " ORDER BY timestamp DESC LIMIT 10"), SQLITE_ASSOC);
foreach ($result as $post) { foreach ($result as $post) {
@ -119,7 +121,7 @@ function latestPosts() {
return $posts; return $posts;
} }
function deletePostByID($id) { function deletePostByID($id) {
$posts = postsInThreadByID($id); $posts = postsInThreadByID($id);
foreach ($posts as $post) { foreach ($posts as $post) {
if ($post['id'] != $id) { if ($post['id'] != $id) {
@ -140,14 +142,14 @@ function deletePostByID($id) {
function trimThreads() { function trimThreads() {
if (TINYIB_MAXTHREADS > 0) { if (TINYIB_MAXTHREADS > 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) { foreach ($result as $post) {
deletePostByID($post['id']); 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); $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) { foreach ($result as $post) {
return $post; return $post;
@ -193,5 +195,3 @@ function clearExpiredBans() {
function deleteBanByID($id) { function deleteBanByID($id) {
sqlite_query($GLOBALS["db"], "DELETE FROM " . TINYIB_DBBANS . " WHERE id = " . sqlite_escape_string($id)); sqlite_query($GLOBALS["db"], "DELETE FROM " . TINYIB_DBBANS . " WHERE id = " . sqlite_escape_string($id));
} }
?>

View File

@ -1,5 +1,7 @@
<?php <?php
if (!defined('TINYIB_BOARD')) { die(''); } if (!defined('TINYIB_BOARD')) {
die('');
}
define('TINYIB_NEWTHREAD', '0'); define('TINYIB_NEWTHREAD', '0');
define('TINYIB_INDEXPAGE', false); define('TINYIB_INDEXPAGE', false);
@ -7,7 +9,15 @@ define('TINYIB_RESPAGE', true);
// The following are provided for backward compatibility and should not be relied upon // The following are provided for backward compatibility and should not be relied upon
// Copy new settings from settings.default.php to settings.php // Copy new settings from settings.default.php to settings.php
if (!defined('TINYIB_MAXREPLIES')) { define('TINYIB_MAXREPLIES', 0); } if (!defined('TINYIB_MAXREPLIES')) {
if (!defined('TINYIB_MAXWOP')) { define('TINYIB_MAXWOP', TINYIB_MAXW); } define('TINYIB_MAXREPLIES', 0);
if (!defined('TINYIB_MAXHOP')) { define('TINYIB_MAXHOP', TINYIB_MAXH); } }
?> 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);
}

View File

@ -27,7 +27,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* @license http://www.opensource.org/licenses/mit-license.php * @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 */ /** 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', ''); define('DEFAULT_COMPARISON', '');
@ -50,8 +50,7 @@ $comparison_type_for_col_type = array(
FLOAT_COL => NUMERIC_COMPARISON 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; global $comparison_type_for_col_type;
return $comparison_type_for_col_type[$coltype]; return $comparison_type_for_col_type[$coltype];
} }
@ -71,28 +70,27 @@ class Flatfile {
/** @access private */ /** @access private */
var $schemata; var $schemata;
/** The directory to store files in. /** The directory to store files in.
* @var string * @var string
*/ */
var $datadir; var $datadir;
function Flatfile() function Flatfile() {
{
$this->schemata = array(); $this->schemata = array();
} }
/** /**
* Get all rows from a table * 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 * @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])) if (!isset($this->tables[$tablename]))
$this->loadTable($tablename); $this->loadTable($tablename);
return $this->tables[$tablename]; return $this->tables[$tablename];
} }
/** /**
* Selects rows from a table that match the specified criteria * Selects rows from a table that match the specified criteria
* *
@ -103,26 +101,26 @@ class Flatfile {
* ORDER BY $orderBy [ASC | DESC] [, $orderBy2 ...] * ORDER BY $orderBy [ASC | DESC] [, $orderBy2 ...]
* </pre> * </pre>
* *
* @param string $tablename The table (file) to get the data from * @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 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 mixed $limit Specifies limits for the rows returned:
* - use -1 or omitted to return all rows * - use -1 or omitted to return all rows
* - use an integer n to return the first n 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, $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) * - 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 * @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])) if (!isset($this->tables[$tablename]))
$this->loadTable($tablename); $this->loadTable($tablename);
$table = $this->selectAll($tablename); // Get a copy $table = $this->selectAll($tablename); // Get a copy
$schema = $this->getSchema($tablename); $schema = $this->getSchema($tablename);
if ($orderBy !== NULL) if ($orderBy !== NULL)
usort($table, $this->getOrderByFunction($orderBy, $schema)); usort($table, $this->getOrderByFunction($orderBy, $schema));
$results = array(); $results = array();
$count = 0; $count = 0;
@ -130,10 +128,10 @@ class Flatfile {
$limit = array(0, -1); $limit = array(0, -1);
else if (!is_array($limit)) else if (!is_array($limit))
$limit = array(0, $limit); $limit = array(0, $limit);
foreach ($table as $row) { foreach ($table as $row) {
if ($whereClause === NULL || $whereClause->testRow($row, $schema)) { if ($whereClause === NULL || $whereClause->testRow($row, $schema)) {
if ($count >= $limit[0]) if ($count >= $limit[0])
$results[] = $row; $results[] = $row;
++$count; ++$count;
if (($count >= $limit[1]) && ($limit[1] != -1)) if (($count >= $limit[1]) && ($limit[1] != -1))
@ -142,22 +140,22 @@ class Flatfile {
} }
return $results; return $results;
} }
/** /**
* Select a row using a unique ID * Select a row using a unique ID
* @param string $tablename The table to get data from * @param string $tablename The table to get data from
* @param string $idField The index of the field containing the ID * @param string $idField The index of the field containing the ID
* @param string $id The ID to search for * @param string $id The ID to search for
* @return array The row of the table as an array * @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)); $result = $this->selectWhere($tablename, new SimpleWhereClause($idField, '=', $id));
if (count($result) > 0) if (count($result) > 0)
return $result[0]; return $result[0];
else else
return array(); return array();
} }
/* /*
* To correctly write a file, and not overwrite the changes * To correctly write a file, and not overwrite the changes
* another process is making, we need to: * another process is making, we need to:
@ -170,47 +168,44 @@ class Flatfile {
* the lock on a different file. getLock and releaseLock * the lock on a different file. getLock and releaseLock
* are helper functions to allow us to do this with little fuss * are helper functions to allow us to do this with little fuss
*/ */
/** Get a lock for writing a file /** Get a lock for writing a file
* @access private * @access private
*/ */
function getLock ($tablename) function getLock($tablename) {
{
ignore_user_abort(true); ignore_user_abort(true);
$fp = fopen($this->datadir . $tablename.'.lock','w'); $fp = fopen($this->datadir . $tablename . '.lock', 'w');
if (!flock($fp, LOCK_EX)) { if (!flock($fp, LOCK_EX)) {
// log error? // log error?
} }
$this->loadTable($tablename); $this->loadTable($tablename);
return $fp; return $fp;
} }
/** Release a lock /** Release a lock
* @access private * @access private
*/ */
function releaseLock ($lockfp) function releaseLock($lockfp) {
{
flock($lockfp, LOCK_UN); flock($lockfp, LOCK_UN);
ignore_user_abort(false); ignore_user_abort(false);
} }
/** /**
* Inserts a row with an automatically generated ID * Inserts a row with an automatically generated ID
* *
* The autogenerated ID will be the highest ID in the column so far plus one. The * 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 * ID field it contains will just be ignored
* *
* @param string $tablename The table to insert data into * @param string $tablename The table to insert data into
* @param int $idField The index of the field which is the ID field * @param int $idField The index of the field which is the ID field
* @param array $newRow The new row to add to the table * @param array $newRow The new row to add to the table
* @return int The newly assigned ID * @return int The newly assigned ID
*/ */
function insertWithAutoId ($tablename, $idField, $newRow) function insertWithAutoId($tablename, $idField, $newRow) {
{
$lockfp = $this->getLock($tablename); $lockfp = $this->getLock($tablename);
$rows = $this->selectWhere($tablename, null, 1, $rows = $this->selectWhere($tablename, null, 1,
new OrderBy($idField, DESCENDING, INTEGER_COMPARISON)); new OrderBy($idField, DESCENDING, INTEGER_COMPARISON));
if ($rows) { if ($rows) {
$newId = $rows[0][$idField] + 1; $newId = $rows[0][$idField] + 1;
} else { } else {
@ -226,50 +221,47 @@ class Flatfile {
/** /**
* Inserts a row in a table * Inserts a row in a table
* *
* @param string $tablename The table to insert data into * @param string $tablename The table to insert data into
* @param array $newRow The new row to add to the table * @param array $newRow The new row to add to the table
*/ */
function insert ($tablename, $newRow) function insert($tablename, $newRow) {
{ $lockfp = $this->getLock($tablename);
$lockfp = $this->getLock($tablename);
$this->tables[$tablename][] = $newRow; $this->tables[$tablename][] = $newRow;
$this->writeTable($tablename); $this->writeTable($tablename);
$this->releaseLock($lockfp); $this->releaseLock($lockfp);
} }
/** /**
* Updates an existing row using a unique ID * Updates an existing row using a unique ID
* *
* @param string $tablename The table to update * @param string $tablename The table to update
* @param int $idField The index of the field which is the ID field * @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 array $updatedRow The updated row to add to the table
*/ */
function updateRowById ($tablename, $idField, $updatedRow) function updateRowById($tablename, $idField, $updatedRow) {
{ $this->updateSetWhere($tablename, $updatedRow,
$this->updateSetWhere($tablename, $updatedRow,
new SimpleWhereClause($idField, '=', $updatedRow[$idField])); new SimpleWhereClause($idField, '=', $updatedRow[$idField]));
} }
/** /**
* Updates fields in a table for rows that match the provided criteria * 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 * $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 * hashtable of values (where the keys are integers which are the column
* indexes to update) * indexes to update)
* *
* @param string $tablename The table to update * @param string $tablename The table to update
* @param array $newFields A hashtable (with integer keys) of fields 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 WhereClause $whereClause The criteria or NULL to update all rows
*/ */
function updateSetWhere ($tablename, $newFields, $whereClause) function updateSetWhere($tablename, $newFields, $whereClause) {
{
$schema = $this->getSchema($tablename); $schema = $this->getSchema($tablename);
$lockfp = $this->getLock($tablename); $lockfp = $this->getLock($tablename);
for ($i = 0; $i < count($this->tables[$tablename]); ++$i) { for ($i = 0; $i < count($this->tables[$tablename]); ++$i) {
if ($whereClause === NULL || if ($whereClause === NULL ||
$whereClause->testRow($this->tables[$tablename][$i], $schema)) { $whereClause->testRow($this->tables[$tablename][$i], $schema)
foreach ($newFields as $k => $v) ) {
{ foreach ($newFields as $k => $v) {
$this->tables[$tablename][$i][$k] = $v; $this->tables[$tablename][$i][$k] = $v;
} }
} }
@ -278,19 +270,21 @@ class Flatfile {
$this->releaseLock($lockfp); $this->releaseLock($lockfp);
$this->loadTable($tablename); $this->loadTable($tablename);
} }
/** /**
* Deletes all rows in a table that match specified criteria * Deletes all rows in a table that match specified criteria
* *
* @param string $tablename The table to alter * @param string $tablename The table to alter
* @param object $whereClause. {@link WhereClause WhereClause} object that will select * @param object $whereClause . {@link WhereClause WhereClause} object that will select
* rows to be deleted. All rows are deleted if $whereClause === NULL * rows to be deleted. All rows are deleted if $whereClause === NULL
*/ */
function deleteWhere ($tablename, $whereClause) { function deleteWhere($tablename, $whereClause) {
$schema = $this->getSchema($tablename); $schema = $this->getSchema($tablename);
$lockfp = $this->getLock($tablename); $lockfp = $this->getLock($tablename);
for ($i = count($this->tables[$tablename]) - 1; $i >= 0 ; --$i) { for ($i = count($this->tables[$tablename]) - 1; $i >= 0; --$i) {
if ($whereClause === NULL || if ($whereClause === NULL ||
$whereClause->testRow($this->tables[$tablename][$i], $schema)) { $whereClause->testRow($this->tables[$tablename][$i], $schema)
) {
unset($this->tables[$tablename][$i]); unset($this->tables[$tablename][$i]);
} }
} }
@ -298,31 +292,30 @@ class Flatfile {
$this->releaseLock($lockfp); $this->releaseLock($lockfp);
$this->loadTable($tablename); // reset array indexes $this->loadTable($tablename); // reset array indexes
} }
/** /**
* Delete all rows in a table * 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); $this->deleteWhere($tablename, NULL);
} }
/**#@+ /**#@+
* @access private * @access private
*/ */
/** Gets a function that can be passed to usort to do the ORDER BY clause /** 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 * @return string function name
*/ */
function getOrderByFunction ($orderBy, $rowSchema = null) function getOrderByFunction($orderBy, $rowSchema = null) {
{
$orderer = new Orderer($orderBy, $rowSchema); $orderer = new Orderer($orderBy, $rowSchema);
return array(&$orderer, 'compare'); return array(&$orderer, 'compare');
} }
function loadTable ($tablename) { function loadTable($tablename) {
$filedata = @file($this->datadir . $tablename); $filedata = @file($this->datadir . $tablename);
$table = array(); $table = array();
if (is_array($filedata)) { if (is_array($filedata)) {
@ -334,9 +327,9 @@ class Flatfile {
$this->tables[$tablename] = $table; $this->tables[$tablename] = $table;
} }
function writeTable ($tablename) { function writeTable($tablename) {
$output = ''; $output = '';
foreach ($this->tables[$tablename] as $row) { foreach ($this->tables[$tablename] as $row) {
$keys = array_keys($row); $keys = array_keys($row);
rsort($keys, SORT_NUMERIC); rsort($keys, SORT_NUMERIC);
@ -344,7 +337,7 @@ class Flatfile {
for ($i = 0; $i <= $max; ++$i) { for ($i = 0; $i <= $max; ++$i) {
if ($i > 0) $output .= "\t"; if ($i > 0) $output .= "\t";
$data = (!isset($row[$i]) ? '' : $row[$i]); $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"; $output .= "\n";
} }
@ -356,50 +349,45 @@ class Flatfile {
/**#@-*/ /**#@-*/
/** /**
* Adds a schema definition to the DB for a specified regular expression * Adds a schema definition to the DB for a specified regular expression
* *
* Schemas are optional, and are only used for automatically determining * Schemas are optional, and are only used for automatically determining
* the comparison types that should be used when sorting and selecting. * the comparison types that should be used when sorting and selecting.
* *
* @param string $fileregex A regular expression used to match filenames * @param string $fileregex A regular expression used to match filenames
* @param string $rowSchema An array specifying the column types for data * @param string $rowSchema An array specifying the column types for data
* files that match the regex, using constants defined in flatfile_utils.php * 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)); array_push($this->schemata, array($fileregex, $rowSchema));
} }
/** Retrieves the schema for a given filename */ /** Retrieves the schema for a given filename */
function getSchema($filename) function getSchema($filename) {
{ foreach ($this->schemata as $rowSchemaPair) {
foreach ($this->schemata as $rowSchemaPair)
{
$fileregex = $rowSchemaPair[0]; $fileregex = $rowSchemaPair[0];
if (preg_match($fileregex, $filename)) if (preg_match($fileregex, $filename)) {
{
return $rowSchemaPair[1]; return $rowSchemaPair[1];
} }
} }
return null; return null;
} }
} }
/////////////////////////// UTILITY FUNCTIONS //////////////////////////////////// /////////////////////////// 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; 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; return (float)$a - (float)$b;
} }
@ -411,41 +399,39 @@ function numcmp ($a, $b)
* @abstract * @abstract
* @package flatfile * @package flatfile
*/ */
class WhereClause class WhereClause {
{
/** /**
* Tests a table row object * Tests a table row object
* @abstract * @abstract
* @param array $row The row to test * @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 $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 * @return bool True if the $row passes the WhereClause
* selection criteria, false otherwise * selection criteria, false otherwise
*/ */
function testRow ($row, $rowSchema = null) {} function testRow($row, $rowSchema = null) {
}
} }
/** /**
* Negates a where clause * Negates a where clause
* @package flatfile * @package flatfile
*/ */
class NotWhere extends WhereClause class NotWhere extends WhereClause {
{
/** @access private */ /** @access private */
var $clause; var $clause;
/** /**
* Contructs a new NotWhere object * 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. * of the WhereClause object passed in when testing rows.
* @param WhereClause $whereclause The WhereClause object to negate * @param WhereClause $whereclause The WhereClause object to negate
*/ */
function NotWhere ($whereclause) function NotWhere($whereclause) {
{
$this->clause = $whereclause; $this->clause = $whereclause;
} }
function testRow ($row, $rowSchema = null) { function testRow($row, $rowSchema = null) {
return !$this->clause->testRow($row, $rowSchema); return !$this->clause->testRow($row, $rowSchema);
} }
} }
@ -456,8 +442,7 @@ class NotWhere extends WhereClause
* *
* @package flatfile * @package flatfile
*/ */
class SimpleWhereClause extends WhereClause class SimpleWhereClause extends WhereClause {
{
/**#@+ /**#@+
* @access private * @access private
*/ */
@ -482,43 +467,38 @@ class SimpleWhereClause extends WhereClause
* - <= (less than or equal to) * - <= (less than or equal to)
* There are 3 pre-defined constants (STRING_COMPARISON, NUMERIC COMPARISON and * There are 3 pre-defined constants (STRING_COMPARISON, NUMERIC COMPARISON and
* INTEGER_COMPARISON) that modify the behaviour of these operators to do the comparison * 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 * 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. * behaviour of this class.
* *
* @param int $field The index (in the table row) of the field to test * @param int $field The index (in the table row) of the field to test
* @param string $operator The comparison operator, one of "=", "!=", "<", ">", "<=", ">=" * @param string $operator The comparison operator, one of "=", "!=", "<", ">", "<=", ">="
* @param mixed $value The value to compare to. * @param mixed $value The value to compare to.
* @param string $compare_type The comparison method to use - either * @param string $compare_type The comparison method to use - either
* STRING_COMPARISON (default), NUMERIC COMPARISON or INTEGER_COMPARISON * 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->field = $field;
$this->operator = $operator; $this->operator = $operator;
$this->value = $value; $this->value = $value;
$this->compare_type = $compare_type; $this->compare_type = $compare_type;
} }
function testRow ($tablerow, $rowSchema = null) { function testRow($tablerow, $rowSchema = null) {
if ($this->field < 0) if ($this->field < 0)
return TRUE; return TRUE;
$cmpfunc = $this->compare_type; $cmpfunc = $this->compare_type;
if ($cmpfunc == DEFAULT_COMPARISON) if ($cmpfunc == DEFAULT_COMPARISON) {
{ if ($rowSchema != null) {
if ($rowSchema != null)
{
$cmpfunc = get_comparison_type_for_col_type($rowSchema[$this->field]); $cmpfunc = get_comparison_type_for_col_type($rowSchema[$this->field]);
} } else {
else
{
$cmpfunc = STRING_COMPARISON; $cmpfunc = STRING_COMPARISON;
} }
} }
if ($this->field >= count($tablerow)) { if ($this->field >= count($tablerow)) {
$dbval = ""; $dbval = "";
} else { } else {
@ -537,7 +517,7 @@ class SimpleWhereClause extends WhereClause
return ($cmp <= 0); return ($cmp <= 0);
else if ($this->operator == '>=') else if ($this->operator == '>=')
return ($cmp >= 0); return ($cmp >= 0);
return FALSE; return FALSE;
} }
} }
@ -546,23 +526,21 @@ class SimpleWhereClause extends WhereClause
* {@link WhereClause WhereClause} class to work like a SQL 'LIKE' clause * {@link WhereClause WhereClause} class to work like a SQL 'LIKE' clause
* @package flatfile * @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 int $field Index of the field to look at
* @param string $value Value to look for. Supports using '%' as a * @param string $value Value to look for. Supports using '%' as a
* wildcard, and is case insensitve. e.g. 'test%' will match 'TESTS' and 'Testing' * 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->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]); return preg_match($this->regexp, $tablerow[$this->field]);
} }
} }
@ -580,40 +558,35 @@ class ListWhereClause extends WhereClause {
var $list; var $list;
/** @access private */ /** @access private */
var $compareAs; var $compareAs;
/** /**
* Creates a new ListWhereClause object * Creates a new ListWhereClause object
* *
* The resulting WhereClause will pass rows (return true) if the value of the specified * The resulting WhereClause will pass rows (return true) if the value of the specified
* field is in the array. * field is in the array.
* *
* @param int $field Field to match * @param int $field Field to match
* @param array $list List of items * @param array $list List of items
* @param string $compare_type Comparison type, string by default. * @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->list = $list;
$this->field = (int)$field; $this->field = (int)$field;
$this->compareAs = $compare_type; $this->compareAs = $compare_type;
} }
function testRow ($tablerow, $rowSchema = null) { function testRow($tablerow, $rowSchema = null) {
$func = $this->compareAs; $func = $this->compareAs;
if ($func == DEFAULT_COMPARISON) if ($func == DEFAULT_COMPARISON) {
{ if ($rowSchema) {
if ($rowSchema)
{
$func = get_comparison_type_for_col_type($rowSchema[$this->field]); $func = get_comparison_type_for_col_type($rowSchema[$this->field]);
} } else {
else
{
$func = STRING_COMPARISON; $func = STRING_COMPARISON;
} }
} }
foreach ($this->list as $item) foreach ($this->list as $item) {
{ if ($func($tablerow[$this->field], $item) == 0)
if ($func($tablerow[$this->field], $item) == 0)
return true; return true;
} }
return false; return false;
@ -624,21 +597,19 @@ class ListWhereClause extends WhereClause {
* Abstract class that combines zero or more {@link WhereClause WhereClause} objects * Abstract class that combines zero or more {@link WhereClause WhereClause} objects
* together. * together.
* @package flatfile * @package flatfile
*/ */
class CompositeWhereClause extends WhereClause class CompositeWhereClause extends WhereClause {
{ /**
/**
* @var array Stores the child clauses * @var array Stores the child clauses
* @access protected * @access protected
*/ */
var $clauses = array(); var $clauses = array();
/** /**
* Add a {@link WhereClause WhereClause} to the list of clauses to be used for testing * Add a {@link WhereClause WhereClause} to the list of clauses to be used for testing
* @param WhereClause $whereClause The WhereClause object to add * @param WhereClause $whereClause The WhereClause object to add
*/ */
function add ($whereClause) function add($whereClause) {
{
$this->clauses[] = $whereClause; $this->clauses[] = $whereClause;
} }
} }
@ -654,20 +625,19 @@ class CompositeWhereClause extends WhereClause
* false if no clauses have been added for consistency). * false if no clauses have been added for consistency).
* @package flatfile * @package flatfile
*/ */
class OrWhereClause extends CompositeWhereClause class OrWhereClause extends CompositeWhereClause {
{ function testRow($tablerow, $rowSchema = null) {
function testRow ($tablerow, $rowSchema = null) {
foreach ($this->clauses as $clause) { foreach ($this->clauses as $clause) {
if ($clause->testRow($tablerow, $rowSchema)) if ($clause->testRow($tablerow, $rowSchema))
return true; return true;
} }
return false; return false;
} }
/** /**
* Creates a new OrWhereClause * Creates a new OrWhereClause
* @param WhereClause $whereClause,... optional unlimited list of WhereClause objects to be added * @param WhereClause $whereClause,... optional unlimited list of WhereClause objects to be added
*/ */
function OrWhereClause() { function OrWhereClause() {
$this->clauses = func_get_args(); $this->clauses = func_get_args();
} }
@ -683,20 +653,19 @@ class OrWhereClause extends CompositeWhereClause
* true if no clauses have been added for consistency). * true if no clauses have been added for consistency).
* @package flatfile * @package flatfile
*/ */
class AndWhereClause extends CompositeWhereClause class AndWhereClause extends CompositeWhereClause {
{ function testRow($tablerow, $rowSchema = null) {
function testRow ($tablerow, $rowSchema = null) {
foreach ($this->clauses as $clause) { foreach ($this->clauses as $clause) {
if (!$clause->testRow($tablerow, $rowSchema)) if (!$clause->testRow($tablerow, $rowSchema))
return false; return false;
} }
return true; return true;
} }
/** /**
* Creates a new AndWhereClause * Creates a new AndWhereClause
* @param WhereClause $whereClause,... optional unlimited list of WhereClause objects to be added * @param WhereClause $whereClause,... optional unlimited list of WhereClause objects to be added
*/ */
function AndWhereClause() { function AndWhereClause() {
$this->clauses = func_get_args(); $this->clauses = func_get_args();
} }
@ -717,22 +686,21 @@ class OrderBy {
var $field; var $field;
/** @var int Order type - ASCENDING or DESCENDING */ /** @var int Order type - ASCENDING or DESCENDING */
var $orderType; 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; var $compareAs;
/** Creates a new OrderBy structure /** 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 * 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. * {@link strcmp strcmp()} to implement custom ordering.
* @param int $field The index of the field to order by * @param int $field The index of the field to order by
* @param int $orderType ASCENDING or DESCENDING * @param int $orderType ASCENDING or DESCENDING
* @param int $compareAs Comparison type: DEFAULT_COMPARISON, STRING_COMPARISON, INTEGER_COMPARISION, * @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. * 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->field = $field;
$this->orderType = $orderType; $this->orderType = $orderType;
$this->compareAs = $compareAs; $this->compareAs = $compareAs;
@ -746,56 +714,51 @@ class OrderBy {
* @package flatfile * @package flatfile
*/ */
class Orderer { class Orderer {
/** /**
* @var array Stores the OrderBy objects * @var array Stores the OrderBy objects
* @access private * @access private
*/ */
var $orderByList; var $orderByList;
/** /**
* Creates new Orderer that will provide a sort function * Creates new Orderer that will provide a sort function
* @param mixed $orderBy An OrderBy object or an array of them * @param mixed $orderBy An OrderBy object or an array of them
* @param array $rowSchema Option row schema * @param array $rowSchema Option row schema
*/ */
function Orderer($orderBy, $rowSchema = null) { function Orderer($orderBy, $rowSchema = null) {
if (!is_array($orderBy)) if (!is_array($orderBy))
$orderBy = array($orderBy); $orderBy = array($orderBy);
if ($rowSchema) if ($rowSchema) {
{
// Fix the comparison types // Fix the comparison types
foreach ($orderBy as $index => $discard) foreach ($orderBy as $index => $discard) {
{
$item =& $orderBy[$index]; // PHP4 $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]); $item->compareAs = get_comparison_type_for_col_type($rowSchema[$item->field]);
} }
} }
} }
$this->orderByList = $orderBy; $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(). * objects. This function is of the type that can be used passed to usort().
*/ */
function compare($row1, $row2) { function compare($row1, $row2) {
return $this->compare_priv($row1, $row2, 0); return $this->compare_priv($row1, $row2, 0);
} }
/** /**
* @access private * @access private
*/ */
function compare_priv($row1, $row2, $index) function compare_priv($row1, $row2, $index) {
{
$orderBy = $this->orderByList[$index]; $orderBy = $this->orderByList[$index];
$cmpfunc = $orderBy->compareAs; $cmpfunc = $orderBy->compareAs;
if ($cmpfunc == DEFAULT_COMPARISON) if ($cmpfunc == DEFAULT_COMPARISON) {
{
$cmpfunc = STRING_COMPARISON; $cmpfunc = STRING_COMPARISON;
} }
$cmp = $orderBy->orderType * $cmpfunc($row1[$orderBy->field], $row2[$orderBy->field]); $cmp = $orderBy->orderType * $cmpfunc($row1[$orderBy->field], $row2[$orderBy->field]);
if($cmp == 0) { if ($cmp == 0) {
if ($index == (count($this->orderByList) - 1)) if ($index == (count($this->orderByList) - 1))
return 0; return 0;
else else
@ -804,4 +767,3 @@ class Orderer {
return $cmp; return $cmp;
} }
} }
?>

View File

@ -13,23 +13,19 @@ define('DATE_COL', 'date');
/** EXPERIMENTAL: Encapsulates info about a column in a flatfile DB */ /** EXPERIMENTAL: Encapsulates info about a column in a flatfile DB */
class Column class Column {
{
/** /**
* Create a new column object * Create a new column object
*/ */
function Column($index, $type) function Column($index, $type) {
{
$this->index = $index; $this->index = $index;
$this->type = $type; $this->type = $type;
} }
} }
/** EXPERIMENTAL: Represent a column that is a foreign key. Used for temporarily building tables array */ /** EXPERIMENTAL: Represent a column that is a foreign key. Used for temporarily building tables array */
class JoinColumn class JoinColumn {
{ function JoinColumn($index, $tablename, $columnname) {
function JoinColumn($index, $tablename, $columnname)
{
$this->index = $index; $this->index = $index;
$this->tablename = $tablename; $this->tablename = $tablename;
$this->columnname = $columnname; $this->columnname = $columnname;
@ -39,74 +35,61 @@ class JoinColumn
/** /**
* EXPERIMENTAL: Utilities for handling definitions of tables. * 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 * 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 * @param tables This should be an associative array containing 'tablename' => tabledefinition
* tabledefinition is itself an associativive array of 'COLUMN_NAME_CONSTANT' => columndefintion * 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 * column definition should be a Column object or JoinColumn object
*/ */
function resolveJoins(&$tables) function resolveJoins(&$tables) {
{ foreach ($tables as $tablename => $discard) {
foreach ($tables as $tablename => $discard)
{
// PHP4 compatible: can't do : foreach ($tables as $tablename => &$tabledef) // 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) // foreach ($tables as $tablename => &$tabledef)
// $tabledef =& $tables[$tablename]; // $tabledef =& $tables[$tablename];
// then we get bugs // then we get bugs
$tabledef =& $tables[$tablename]; $tabledef =& $tables[$tablename];
foreach ($tabledef as $colname => $discard) foreach ($tabledef as $colname => $discard) {
{
$coldef =& $tabledef[$colname]; // PHP4 compatible $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); TableUtils::resolveColumnJoin($coldef, $tables);
} }
} }
} }
} }
/** @access private */ /** @access private */
function resolveColumnJoin(&$columndef, &$tables) function resolveColumnJoin(&$columndef, &$tables) {
{
// Doesn't work if the column it is joined to is also // 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 // a JoinColumn, but I can't think of ever wanting to do that
$columndef->type = $tables[$columndef->tablename][$columndef->columnname]->type; $columndef->type = $tables[$columndef->tablename][$columndef->columnname]->type;
} }
/** Uses 'define' to create global constants for all the column names */ /** Uses 'define' to create global constants for all the column names */
function createDefines(&$tables) function createDefines(&$tables) {
{ foreach ($tables as $tablename => $discard) {
foreach ($tables as $tablename => $discard) $tabledef = & $tables[$tablename]; // PHP4 compatible
{ foreach ($tabledef as $colname => $discard) {
$tabledef = &$tables[$tablename]; // PHP4 compatible $coldef = & $tabledef[$colname];
foreach ($tabledef as $colname => $discard)
{
$coldef = &$tabledef[$colname];
define(strtoupper($tablename) . '_' . $colname, $coldef->index); 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, * A row schema is just an array of the column types for a table,
* using the constants defined above. * using the constants defined above.
*/ */
function createRowSchema(&$tabledef) function createRowSchema(&$tabledef) {
{
$row_schema = array(); $row_schema = array();
foreach ($tabledef as $colname => $coldef) foreach ($tabledef as $colname => $coldef) {
{
$row_schema[$coldef->index] = $coldef->type; $row_schema[$coldef->index] = $coldef->type;
} }
return $row_schema; return $row_schema;
} }
} }
?>

View File

@ -1,18 +1,20 @@
<?php <?php
if (!defined('TINYIB_BOARD')) { die(''); } if (!defined('TINYIB_BOARD')) {
die('');
}
function cleanString($string) { function cleanString($string) {
$search = array("<", ">"); $search = array("<", ">");
$replace = array("&lt;", "&gt;"); $replace = array("&lt;", "&gt;");
return str_replace($search, $replace, $string); return str_replace($search, $replace, $string);
} }
function plural($singular, $count, $plural = 's') { function plural($singular, $count, $plural = 's') {
if ($plural == 's') { if ($plural == 's') {
$plural = $singular . $plural; $plural = $singular . $plural;
} }
return ($count == 1 ? $singular : $plural); return ($count == 1 ? $singular : $plural);
} }
function threadUpdated($id) { function threadUpdated($id) {
@ -22,26 +24,26 @@ function threadUpdated($id) {
function newPost($parent = TINYIB_NEWTHREAD) { function newPost($parent = TINYIB_NEWTHREAD) {
return array('parent' => $parent, return array('parent' => $parent,
'timestamp' => '0', 'timestamp' => '0',
'bumped' => '0', 'bumped' => '0',
'ip' => '', 'ip' => '',
'name' => '', 'name' => '',
'tripcode' => '', 'tripcode' => '',
'email' => '', 'email' => '',
'nameblock' => '', 'nameblock' => '',
'subject' => '', 'subject' => '',
'message' => '', 'message' => '',
'password' => '', 'password' => '',
'file' => '', 'file' => '',
'file_hex' => '', 'file_hex' => '',
'file_original' => '', 'file_original' => '',
'file_size' => '0', 'file_size' => '0',
'file_size_formatted' => '', 'file_size_formatted' => '',
'image_width' => '0', 'image_width' => '0',
'image_height' => '0', 'image_height' => '0',
'thumb' => '', 'thumb' => '',
'thumb_width' => '0', 'thumb_width' => '0',
'thumb_height' => '0'); 'thumb_height' => '0');
} }
function convertBytes($number) { function convertBytes($number) {
@ -49,26 +51,26 @@ function convertBytes($number) {
if ($len < 4) { if ($len < 4) {
return sprintf("%dB", $number); return sprintf("%dB", $number);
} elseif ($len <= 6) { } elseif ($len <= 6) {
return sprintf("%0.2fKB", $number/1024); return sprintf("%0.2fKB", $number / 1024);
} elseif ($len <= 9) { } 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) { function nameAndTripcode($name) {
if (preg_match("/(#|!)(.*)/", $name, $regs)) { if (preg_match("/(#|!)(.*)/", $name, $regs)) {
$cap = $regs[2]; $cap = $regs[2];
$cap_full = '#' . $regs[2]; $cap_full = '#' . $regs[2];
if (function_exists('mb_convert_encoding')) { if (function_exists('mb_convert_encoding')) {
$recoded_cap = mb_convert_encoding($cap, 'SJIS', 'UTF-8'); $recoded_cap = mb_convert_encoding($cap, 'SJIS', 'UTF-8');
if ($recoded_cap != '') { if ($recoded_cap != '') {
$cap = $recoded_cap; $cap = $recoded_cap;
} }
} }
if (strpos($name, '#') === false) { if (strpos($name, '#') === false) {
$cap_delimiter = '!'; $cap_delimiter = '!';
} elseif (strpos($name, '!') === false) { } elseif (strpos($name, '!') === false) {
@ -76,7 +78,7 @@ function nameAndTripcode($name) {
} else { } else {
$cap_delimiter = (strpos($name, '#') < strpos($name, '!')) ? '#' : '!'; $cap_delimiter = (strpos($name, '#') < strpos($name, '!')) ? '#' : '!';
} }
if (preg_match("/(.*)(" . $cap_delimiter . ")(.*)/", $cap, $regs_secure)) { if (preg_match("/(.*)(" . $cap_delimiter . ")(.*)/", $cap, $regs_secure)) {
$cap = $regs_secure[1]; $cap = $regs_secure[1];
$cap_secure = $regs_secure[3]; $cap_secure = $regs_secure[3];
@ -84,41 +86,41 @@ function nameAndTripcode($name) {
} else { } else {
$is_secure_trip = false; $is_secure_trip = false;
} }
$tripcode = ""; $tripcode = "";
if ($cap != "") { // Copied from Futabally if ($cap != "") { // Copied from Futabally
$cap = strtr($cap, "&amp;", "&"); $cap = strtr($cap, "&amp;", "&");
$cap = strtr($cap, "&#44;", ", "); $cap = strtr($cap, "&#44;", ", ");
$salt = substr($cap."H.", 1, 2); $salt = substr($cap . "H.", 1, 2);
$salt = preg_replace("/[^\.-z]/", ".", $salt); $salt = preg_replace("/[^\.-z]/", ".", $salt);
$salt = strtr($salt, ":;<=>?@[\\]^_`", "ABCDEFGabcdef"); $salt = strtr($salt, ":;<=>?@[\\]^_`", "ABCDEFGabcdef");
$tripcode = substr(crypt($cap, $salt), -10); $tripcode = substr(crypt($cap, $salt), -10);
} }
if ($is_secure_trip) { if ($is_secure_trip) {
if ($cap != "") { if ($cap != "") {
$tripcode .= "!"; $tripcode .= "!";
} }
$tripcode .= "!" . substr(md5($cap_secure . TINYIB_TRIPSEED), 2, 10); $tripcode .= "!" . substr(md5($cap_secure . TINYIB_TRIPSEED), 2, 10);
} }
return array(preg_replace("/(" . $cap_delimiter . ")(.*)/", "", $name), $tripcode); return array(preg_replace("/(" . $cap_delimiter . ")(.*)/", "", $name), $tripcode);
} }
return array($name, ""); return array($name, "");
} }
function nameBlock($name, $tripcode, $email, $timestamp, $rawposttext) { function nameBlock($name, $tripcode, $email, $timestamp, $rawposttext) {
$output = '<span class="postername">'; $output = '<span class="postername">';
$output .= ($name == '' && $tripcode == '') ? 'Anonymous' : $name; $output .= ($name == '' && $tripcode == '') ? 'Anonymous' : $name;
if ($tripcode != '') { if ($tripcode != '') {
$output .= '</span><span class="postertrip">!' . $tripcode; $output .= '</span><span class="postertrip">!' . $tripcode;
} }
$output .= '</span>'; $output .= '</span>';
if ($email != '' && strtolower($email) != 'noko') { if ($email != '' && strtolower($email) != 'noko') {
$output = '<a href="mailto:' . $email . '">' . $output . '</a>'; $output = '<a href="mailto:' . $email . '">' . $output . '</a>';
} }
@ -136,14 +138,14 @@ function writePage($filename, $contents) {
copy($tempfile, $filename); copy($tempfile, $filename);
unlink($tempfile); unlink($tempfile);
} }
chmod($filename, 0664); /* it was created 0600 */ chmod($filename, 0664); /* it was created 0600 */
} }
function fixLinksInRes($html) { function fixLinksInRes($html) {
$search = array(' href="css/', ' href="src/', ' href="thumb/', ' href="res/', ' href="imgboard.php', ' href="favicon.ico', 'src="thumb/', ' action="imgboard.php'); $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'); $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); return str_replace($search, $replace, $html);
} }
@ -160,13 +162,19 @@ function postLink($message) {
} }
function colorQuote($message) { function colorQuote($message) {
if (substr($message, -1, 1) != "\n") { $message .= "\n"; } if (substr($message, -1, 1) != "\n") {
$message .= "\n";
}
return preg_replace('/^(&gt;[^\>](.*))\n/m', '<span class="unkfunc">\\1</span>' . "\n", $message); return preg_replace('/^(&gt;[^\>](.*))\n/m', '<span class="unkfunc">\\1</span>' . "\n", $message);
} }
function deletePostImages($post) { function deletePostImages($post) {
if ($post['file'] != '') { @unlink('src/' . $post['file']); } if ($post['file'] != '') {
if ($post['thumb'] != '') { @unlink('thumb/' . $post['thumb']); } @unlink('src/' . $post['file']);
}
if ($post['thumb'] != '') {
@unlink('thumb/' . $post['thumb']);
}
} }
function checkBanned() { function checkBanned() {
@ -200,7 +208,8 @@ function checkMessageSize() {
} }
function manageCheckLogIn() { function manageCheckLogIn() {
$loggedin = false; $isadmin = false; $loggedin = false;
$isadmin = false;
if (isset($_POST['password'])) { if (isset($_POST['password'])) {
if ($_POST['password'] == TINYIB_ADMINPASS) { if ($_POST['password'] == TINYIB_ADMINPASS) {
$_SESSION['tinyib'] = TINYIB_ADMINPASS; $_SESSION['tinyib'] = TINYIB_ADMINPASS;
@ -208,7 +217,7 @@ function manageCheckLogIn() {
$_SESSION['tinyib'] = TINYIB_MODPASS; $_SESSION['tinyib'] = TINYIB_MODPASS;
} }
} }
if (isset($_SESSION['tinyib'])) { if (isset($_SESSION['tinyib'])) {
if ($_SESSION['tinyib'] == TINYIB_ADMINPASS) { if ($_SESSION['tinyib'] == TINYIB_ADMINPASS) {
$loggedin = true; $loggedin = true;
@ -217,7 +226,7 @@ function manageCheckLogIn() {
$loggedin = true; $loggedin = true;
} }
} }
return array($loggedin, $isadmin); return array($loggedin, $isadmin);
} }
@ -227,11 +236,11 @@ function setParent() {
if (!threadExistsByID($_POST['parent'])) { if (!threadExistsByID($_POST['parent'])) {
fancyDie("Invalid parent thread ID supplied, unable to create post."); fancyDie("Invalid parent thread ID supplied, unable to create post.");
} }
return $_POST["parent"]; return $_POST["parent"];
} }
} }
return TINYIB_NEWTHREAD; return TINYIB_NEWTHREAD;
} }
@ -242,7 +251,7 @@ function isRawPost() {
return true; return true;
} }
} }
return false; return false;
} }
@ -273,7 +282,7 @@ function validateFileUpload() {
} }
} }
function checkDuplicateImage($hex) { function checkDuplicateFile($hex) {
$hexmatches = postsByHex($hex); $hexmatches = postsByHex($hex);
if (count($hexmatches) > 0) { if (count($hexmatches) > 0) {
foreach ($hexmatches as $hexmatch) { foreach ($hexmatches as $hexmatch) {
@ -305,7 +314,7 @@ function createThumbnail($name, $filename, $new_w, $new_h) {
} else { } else {
return false; return false;
} }
if (!$src_img) { 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."); 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); $percent = ($old_x > $old_y) ? ($new_w / $old_x) : ($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);
$dst_img = ImageCreateTrueColor($thumb_w, $thumb_h); $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
fastImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y); fastImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
if (preg_match("/png/", $system[0])) { if (preg_match("/png/", $system[0])) {
if (!imagepng($dst_img, $filename)) { if (!imagepng($dst_img, $filename)) {
return false; return false;
@ -327,45 +336,47 @@ function createThumbnail($name, $filename, $new_w, $new_h) {
return false; return false;
} }
} else if (preg_match("/gif/", $system[0])) { } else if (preg_match("/gif/", $system[0])) {
if (!imagegif($dst_img, $filename)) { if (!imagegif($dst_img, $filename)) {
return false; return false;
} }
} }
imagedestroy($dst_img); imagedestroy($dst_img);
imagedestroy($src_img); imagedestroy($src_img);
return true; 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) { 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. // Author: Tim Eckel - Date: 12/17/04 - Project: FreeRingers.net - Freely distributable.
if (empty($src_image) || empty($dst_image)) { return false; } if (empty($src_image) || empty($dst_image)) {
return false;
}
if ($quality <= 1) { if ($quality <= 1) {
$temp = imagecreatetruecolor ($dst_w + 1, $dst_h + 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($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); imagecopyresized($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $dst_w, $dst_h);
imagedestroy ($temp); imagedestroy($temp);
} elseif ($quality < 5 && (($dst_w * $quality) < $src_w || ($dst_h * $quality) < $src_h)) { } elseif ($quality < 5 && (($dst_w * $quality) < $src_w || ($dst_h * $quality) < $src_h)) {
$tmp_w = $dst_w * $quality; $tmp_w = $dst_w * $quality;
$tmp_h = $dst_h * $quality; $tmp_h = $dst_h * $quality;
$temp = imagecreatetruecolor ($tmp_w + 1, $tmp_h + 1); $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); 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); imagecopyresampled($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $tmp_w, $tmp_h);
imagedestroy ($temp); imagedestroy($temp);
} else { } 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; return true;
} }
function strallpos($haystack, $needle, $offset = 0) { function strallpos($haystack, $needle, $offset = 0) {
$result = array(); $result = array();
for ($i = $offset;$i<strlen($haystack);$i++) { for ($i = $offset; $i < strlen($haystack); $i++) {
$pos = strpos($haystack, $needle, $i); $pos = strpos($haystack, $needle, $i);
if ($pos !== False) { if ($pos !== False) {
$offset = $pos; $offset = $pos;
@ -377,5 +388,3 @@ function strallpos($haystack, $needle, $offset = 0) {
} }
return $result; return $result;
} }
?>

View File

@ -1,5 +1,7 @@
<?php <?php
if (!defined('TINYIB_BOARD')) { die(''); } if (!defined('TINYIB_BOARD')) {
die('');
}
function pageHeader() { function pageHeader() {
$return = <<<EOF $return = <<<EOF
@ -37,8 +39,10 @@ function buildPost($post, $res) {
$return = ""; $return = "";
$threadid = ($post['parent'] == TINYIB_NEWTHREAD) ? $post['id'] : $post['parent']; $threadid = ($post['parent'] == TINYIB_NEWTHREAD) ? $post['id'] : $post['parent'];
$postlink = ($res == TINYIB_RESPAGE) ? ($threadid . '.html#' . $post['id']) : ('res/' . $threadid . '.html#' . $post['id']); $postlink = ($res == TINYIB_RESPAGE) ? ($threadid . '.html#' . $post['id']) : ('res/' . $threadid . '.html#' . $post['id']);
if (!isset($post["omitted"])) { $post["omitted"] = 0; } if (!isset($post["omitted"])) {
$post["omitted"] = 0;
}
if ($post["parent"] != TINYIB_NEWTHREAD) { if ($post["parent"] != TINYIB_NEWTHREAD) {
$return .= <<<EOF $return .= <<<EOF
<table> <table>
@ -58,7 +62,7 @@ EOF;
</a> </a>
EOF; EOF;
} }
$return .= <<<EOF $return .= <<<EOF
<a name="${post['id']}"></a> <a name="${post['id']}"></a>
<label> <label>
@ -68,7 +72,7 @@ EOF;
if ($post['subject'] != '') { if ($post['subject'] != '') {
$return .= ' <span class="filetitle">' . $post['subject'] . '</span> '; $return .= ' <span class="filetitle">' . $post['subject'] . '</span> ';
} }
$return .= <<<EOF $return .= <<<EOF
${post["nameblock"]} ${post["nameblock"]}
</label> </label>
@ -76,7 +80,7 @@ ${post["nameblock"]}
<a href="$postlink">No.${post["id"]}</a> <a href="$postlink">No.${post["id"]}</a>
</span> </span>
EOF; EOF;
if ($post['parent'] != TINYIB_NEWTHREAD && $post["file"] != "") { if ($post['parent'] != TINYIB_NEWTHREAD && $post["file"] != "") {
$return .= <<<EOF $return .= <<<EOF
<br> <br>
@ -87,11 +91,11 @@ EOF;
</a> </a>
EOF; EOF;
} }
if ($post['parent'] == TINYIB_NEWTHREAD && $res == TINYIB_INDEXPAGE) { if ($post['parent'] == TINYIB_NEWTHREAD && $res == TINYIB_INDEXPAGE) {
$return .= "&nbsp;[<a href=\"res/${post["id"]}.html\">Reply</a>]"; $return .= "&nbsp;[<a href=\"res/${post["id"]}.html\">Reply</a>]";
} }
if (TINYIB_TRUNCATE > 0 && !$res && substr_count($post['message'], '<br>') > TINYIB_TRUNCATE) { // Truncate messages on board index pages for readability if (TINYIB_TRUNCATE > 0 && !$res && substr_count($post['message'], '<br>') > TINYIB_TRUNCATE) { // Truncate messages on board index pages for readability
$br_offsets = strallpos($post['message'], '<br>'); $br_offsets = strallpos($post['message'], '<br>');
$post['message'] = substr($post['message'], 0, $br_offsets[TINYIB_TRUNCATE - 1]); $post['message'] = substr($post['message'], 0, $br_offsets[TINYIB_TRUNCATE - 1]);
@ -115,28 +119,28 @@ EOF;
</table> </table>
EOF; EOF;
} }
return $return; return $return;
} }
function buildPage($htmlposts, $parent, $pages=0, $thispage=0) { function buildPage($htmlposts, $parent, $pages = 0, $thispage = 0) {
$managelink = basename($_SERVER['PHP_SELF']) . "?manage"; $managelink = basename($_SERVER['PHP_SELF']) . "?manage";
$maxdimensions = TINYIB_MAXWOP . 'x' . TINYIB_MAXHOP; $maxdimensions = TINYIB_MAXWOP . 'x' . TINYIB_MAXHOP;
if (TINYIB_MAXW != TINYIB_MAXWOP || TINYIB_MAXH != TINYIB_MAXHOP) { if (TINYIB_MAXW != TINYIB_MAXWOP || TINYIB_MAXH != TINYIB_MAXHOP) {
$maxdimensions .= ' (new thread) or ' . TINYIB_MAXW . 'x' . TINYIB_MAXH . ' (reply)'; $maxdimensions .= ' (new thread) or ' . TINYIB_MAXW . 'x' . TINYIB_MAXH . ' (reply)';
} }
$postingmode = ""; $postingmode = "";
$pagenavigator = ""; $pagenavigator = "";
if ($parent == TINYIB_NEWTHREAD) { if ($parent == TINYIB_NEWTHREAD) {
$pages = max($pages, 0); $pages = max($pages, 0);
$previous = ($thispage == 1) ? "index" : $thispage - 1; $previous = ($thispage == 1) ? "index" : $thispage - 1;
$next = $thispage + 1; $next = $thispage + 1;
$pagelinks = ($thispage == 0) ? "<td>Previous</td>" : '<td><form method="get" action="' . $previous . '.html"><input value="Previous" type="submit"></form></td>'; $pagelinks = ($thispage == 0) ? "<td>Previous</td>" : '<td><form method="get" action="' . $previous . '.html"><input value="Previous" type="submit"></form></td>';
$pagelinks .= "<td>"; $pagelinks .= "<td>";
for ($i = 0;$i <= $pages;$i++) { for ($i = 0; $i <= $pages; $i++) {
if ($thispage == $i) { if ($thispage == $i) {
$pagelinks .= '&#91;' . $i . '&#93; '; $pagelinks .= '&#91;' . $i . '&#93; ';
} else { } else {
@ -145,9 +149,9 @@ function buildPage($htmlposts, $parent, $pages=0, $thispage=0) {
} }
} }
$pagelinks .= "</td>"; $pagelinks .= "</td>";
$pagelinks .= ($pages <= $thispage) ? "<td>Next</td>" : '<td><form method="get" action="' . $next . '.html"><input value="Next" type="submit"></form></td>'; $pagelinks .= ($pages <= $thispage) ? "<td>Next</td>" : '<td><form method="get" action="' . $next . '.html"><input value="Next" type="submit"></form></td>';
$pagenavigator = <<<EOF $pagenavigator = <<<EOF
<table border="1"> <table border="1">
<tbody> <tbody>
@ -160,20 +164,22 @@ EOF;
} else { } else {
$postingmode = '&#91;<a href="../">Return</a>&#93;<div class="replymode">Posting mode: Reply</div> '; $postingmode = '&#91;<a href="../">Return</a>&#93;<div class="replymode">Posting mode: Reply</div> ';
} }
$filetypes = (TINYIB_WEBM ? "GIF, JPG, PNG, and WEBM" : "GIF, JPG, and PNG");
$unique_posts_html = ''; $unique_posts_html = '';
$unique_posts = uniquePosts(); $unique_posts = uniquePosts();
if ($unique_posts > 0) { if ($unique_posts > 0) {
$unique_posts_html = "<li>Currently $unique_posts unique user posts.</li>\n"; $unique_posts_html = "<li>Currently $unique_posts unique user posts.</li>\n";
} }
$max_file_size_input = ''; $max_file_size_input = '';
$max_file_size_html = ''; $max_file_size_html = '';
if (TINYIB_MAXKB > 0) { if (TINYIB_MAXKB > 0) {
$max_file_size_input_html = '<input type="hidden" name="MAX_FILE_SIZE" value="' . strval(TINYIB_MAXKB * 1024) . '">'; $max_file_size_input_html = '<input type="hidden" name="MAX_FILE_SIZE" value="' . strval(TINYIB_MAXKB * 1024) . '">';
$max_file_size_rules_html = '<li>Maximum file size allowed is ' . TINYIB_MAXKBDESC . '.</li>'; $max_file_size_rules_html = '<li>Maximum file size allowed is ' . TINYIB_MAXKBDESC . '.</li>';
} }
$body = <<<EOF $body = <<<EOF
<body> <body>
<div class="adminbar"> <div class="adminbar">
@ -181,7 +187,7 @@ EOF;
</div> </div>
<div class="logo"> <div class="logo">
EOF; EOF;
$body .= TINYIB_LOGO . TINYIB_BOARDDESC . <<<EOF $body .= TINYIB_LOGO . TINYIB_BOARDDESC . <<<EOF
</div> </div>
<hr width="90%" size="1"> <hr width="90%" size="1">
$postingmode $postingmode
@ -243,7 +249,7 @@ EOF;
<tr> <tr>
<td colspan="2" class="rules"> <td colspan="2" class="rules">
<ul> <ul>
<li>Supported file types are GIF, JPG, and PNG.</li> <li>Supported file types are $filetypes.</li>
$max_file_size_rules_html $max_file_size_rules_html
<li>Images greater than $maxdimensions will be thumbnailed.</li> <li>Images greater than $maxdimensions will be thumbnailed.</li>
$unique_posts_html $unique_posts_html
@ -258,7 +264,7 @@ EOF;
<form id="delform" action="imgboard.php?delete" method="post"> <form id="delform" action="imgboard.php?delete" method="post">
<input type="hidden" name="board" <input type="hidden" name="board"
EOF; EOF;
$body .= 'value="' . TINYIB_BOARD . '">' . <<<EOF $body .= 'value="' . TINYIB_BOARD . '">' . <<<EOF
$htmlposts $htmlposts
<table class="userdelete"> <table class="userdelete">
<tbody> <tbody>
@ -276,31 +282,35 @@ EOF;
return pageHeader() . $body . pageFooter(); return pageHeader() . $body . pageFooter();
} }
function rebuildIndexes() { function rebuildIndexes() {
$page = 0; $i = 0; $htmlposts = ''; $page = 0;
$threads = allThreads(); $i = 0;
$htmlposts = '';
$threads = allThreads();
$pages = ceil(count($threads) / TINYIB_THREADSPERPAGE) - 1; $pages = ceil(count($threads) / TINYIB_THREADSPERPAGE) - 1;
foreach ($threads as $thread) { foreach ($threads as $thread) {
$replies = postsInThreadByID($thread['id']); $replies = postsInThreadByID($thread['id']);
$thread['omitted'] = max(0, count($replies) - TINYIB_PREVIEWREPLIES - 1); $thread['omitted'] = max(0, count($replies) - TINYIB_PREVIEWREPLIES - 1);
// Build replies for preview // Build replies for preview
$htmlreplies = array(); $htmlreplies = array();
for ($j = count($replies) - 1; $j > $thread['omitted']; $j--) { for ($j = count($replies) - 1; $j > $thread['omitted']; $j--) {
$htmlreplies[] = buildPost($replies[$j], TINYIB_INDEXPAGE); $htmlreplies[] = buildPost($replies[$j], TINYIB_INDEXPAGE);
} }
$htmlposts .= buildPost($thread, TINYIB_INDEXPAGE) . implode('', array_reverse($htmlreplies)) . "<br clear=\"left\">\n<hr>"; $htmlposts .= buildPost($thread, TINYIB_INDEXPAGE) . implode('', array_reverse($htmlreplies)) . "<br clear=\"left\">\n<hr>";
if (++$i >= TINYIB_THREADSPERPAGE) { if (++$i >= TINYIB_THREADSPERPAGE) {
$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++; $i = 0; $htmlposts = ''; $page++;
$i = 0;
$htmlposts = '';
} }
} }
if ($page == 0 || $htmlposts != '') { if ($page == 0 || $htmlposts != '') {
$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));
@ -313,20 +323,22 @@ function rebuildThread($id) {
foreach ($posts as $post) { foreach ($posts as $post) {
$htmlposts .= buildPost($post, TINYIB_RESPAGE); $htmlposts .= buildPost($post, TINYIB_RESPAGE);
} }
$htmlposts .= "<br clear=\"left\">\n<hr>\n"; $htmlposts .= "<br clear=\"left\">\n<hr>\n";
writePage('res/' . $id . '.html', fixLinksInRes(buildPage($htmlposts, $id))); writePage('res/' . $id . '.html', fixLinksInRes(buildPage($htmlposts, $id)));
} }
function adminBar() { function adminBar() {
global $loggedin, $isadmin, $returnlink; global $loggedin, $isadmin, $returnlink;
$return = '[<a href="' . $returnlink . '" style="text-decoration: underline;">Return</a>]'; $return = '[<a href="' . $returnlink . '" style="text-decoration: underline;">Return</a>]';
if (!$loggedin) { return $return; } if (!$loggedin) {
return $return;
}
return '[<a href="?manage">Status</a>] [' . (($isadmin) ? '<a href="?manage&bans">Bans</a>] [' : '') . '<a href="?manage&moderate">Moderate Post</a>] [<a href="?manage&rawpost">Raw Post</a>] [' . (($isadmin) ? '<a href="?manage&rebuildall">Rebuild All</a>] [' : '') . '<a href="?manage&logout">Log Out</a>] &middot; ' . $return; return '[<a href="?manage">Status</a>] [' . (($isadmin) ? '<a href="?manage&bans">Bans</a>] [' : '') . '<a href="?manage&moderate">Moderate Post</a>] [<a href="?manage&rawpost">Raw Post</a>] [' . (($isadmin) ? '<a href="?manage&rebuildall">Rebuild All</a>] [' : '') . '<a href="?manage&logout">Log Out</a>] &middot; ' . $return;
} }
function managePage($text, $onload='') { function managePage($text, $onload = '') {
$adminbar = adminBar(); $adminbar = adminBar();
$body = <<<EOF $body = <<<EOF
<body$onload> <body$onload>
@ -421,7 +433,7 @@ function manageRawPostForm() {
if (TINYIB_MAXKB > 0) { if (TINYIB_MAXKB > 0) {
$max_file_size_input_html = '<input type="hidden" name="MAX_FILE_SIZE" value="' . strval(TINYIB_MAXKB * 1024) . '">'; $max_file_size_input_html = '<input type="hidden" name="MAX_FILE_SIZE" value="' . strval(TINYIB_MAXKB * 1024) . '">';
} }
return <<<EOF return <<<EOF
<div class="postarea"> <div class="postarea">
<form id="tinyib" name="tinyib" method="post" action="?" enctype="multipart/form-data"> <form id="tinyib" name="tinyib" method="post" action="?" enctype="multipart/form-data">
@ -508,7 +520,7 @@ function manageModeratePost($post) {
$ban_info = (!$ban) ? ((!$isadmin) ? 'Only an administrator may ban an IP address.' : ('IP address: ' . $post["ip"])) : (' A ban record already exists for ' . $post['ip']); $ban_info = (!$ban) ? ((!$isadmin) ? 'Only an administrator may ban an IP address.' : ('IP address: ' . $post["ip"])) : (' A ban record already exists for ' . $post['ip']);
$delete_info = ($post['parent'] == TINYIB_NEWTHREAD) ? 'This will delete the entire thread below.' : 'This will delete the post below.'; $delete_info = ($post['parent'] == TINYIB_NEWTHREAD) ? 'This will delete the entire thread below.' : 'This will delete the post below.';
$post_or_thread = ($post['parent'] == TINYIB_NEWTHREAD) ? 'Thread' : 'Post'; $post_or_thread = ($post['parent'] == TINYIB_NEWTHREAD) ? 'Thread' : 'Post';
if ($post["parent"] == TINYIB_NEWTHREAD) { if ($post["parent"] == TINYIB_NEWTHREAD) {
$post_html = ""; $post_html = "";
$posts = postsInThreadByID($post["id"]); $posts = postsInThreadByID($post["id"]);
@ -518,7 +530,7 @@ function manageModeratePost($post) {
} else { } else {
$post_html = buildPost($post, TINYIB_INDEXPAGE); $post_html = buildPost($post, TINYIB_INDEXPAGE);
} }
return <<<EOF return <<<EOF
<fieldset> <fieldset>
<legend>Moderating No.${post['id']}</legend> <legend>Moderating No.${post['id']}</legend>
@ -565,15 +577,17 @@ function manageStatus() {
$threads = countThreads(); $threads = countThreads();
$bans = count(allBans()); $bans = count(allBans());
$info = $threads . ' ' . plural('thread', $threads) . ', ' . $bans . ' ' . plural('ban', $bans); $info = $threads . ' ' . plural('thread', $threads) . ', ' . $bans . ' ' . plural('ban', $bans);
$post_html = ''; $post_html = '';
$posts = latestPosts(); $posts = latestPosts();
$i = 0; $i = 0;
foreach ($posts as $post) { foreach ($posts as $post) {
if ($post_html != '') { $post_html .= '<tr><td colspan="2"><hr></td></tr>'; } if ($post_html != '') {
$post_html .= '<tr><td colspan="2"><hr></td></tr>';
}
$post_html .= '<tr><td>' . buildPost($post, TINYIB_INDEXPAGE) . '</td><td valign="top" align="right"><form method="get" action="?"><input type="hidden" name="manage" value=""><input type="hidden" name="moderate" value="' . $post['id'] . '"><input type="submit" value="Moderate" class="managebutton"></form></td></tr>'; $post_html .= '<tr><td>' . buildPost($post, TINYIB_INDEXPAGE) . '</td><td valign="top" align="right"><form method="get" action="?"><input type="hidden" name="manage" value=""><input type="hidden" name="moderate" value="' . $post['id'] . '"><input type="submit" value="Moderate" class="managebutton"></form></td></tr>';
} }
$output = <<<EOF $output = <<<EOF
<fieldset> <fieldset>
<legend>Status</legend> <legend>Status</legend>
@ -613,11 +627,10 @@ EOF;
</fieldset> </fieldset>
<br> <br>
EOF; EOF;
return $output; return $output;
} }
function manageInfo($text) { function manageInfo($text) {
return '<div class="manageinfo">' . $text . '</div>'; return '<div class="manageinfo">' . $text . '</div>';
} }
?>

View File

@ -8,6 +8,7 @@ define('TINYIB_PREVIEWREPLIES', 3); // Amount of replies previewed on index page
define('TINYIB_MAXREPLIES', 0); // Maximum replies before a thread stops bumping [0 to disable] define('TINYIB_MAXREPLIES', 0); // Maximum replies before a thread stops bumping [0 to disable]
define('TINYIB_MAXKB', 2048); // Maximum file size in kilobytes [0 to disable] define('TINYIB_MAXKB', 2048); // Maximum file size in kilobytes [0 to disable]
define('TINYIB_MAXKBDESC', "2 MB"); // Human-readable representation of the maximum file size define('TINYIB_MAXKBDESC', "2 MB"); // Human-readable representation of the maximum file size
define('TINYIB_WEBM', false); // Enable .weba and .webm audio/video file upload (see README for instructions)
define('TINYIB_MAXW', 250); // Maximum image width (reply) - Images exceeding these sizes will be thumbnailed define('TINYIB_MAXW', 250); // Maximum image width (reply) - Images exceeding these sizes will be thumbnailed
define('TINYIB_MAXH', 250); // Maximum image height (reply) define('TINYIB_MAXH', 250); // Maximum image height (reply)
define('TINYIB_MAXWOP', 250); // Maximum image width (new thread) define('TINYIB_MAXWOP', 250); // Maximum image width (new thread)
@ -17,7 +18,7 @@ define('TINYIB_LOGO', ""); // Logo HTML
define('TINYIB_TRIPSEED', ""); // Enter some random text - Used when generating secure tripcodes - Must not change once set define('TINYIB_TRIPSEED', ""); // Enter some random text - Used when generating secure tripcodes - Must not change once set
define('TINYIB_ADMINPASS', ""); // Text entered at the manage prompt to gain administrator access define('TINYIB_ADMINPASS', ""); // Text entered at the manage prompt to gain administrator access
define('TINYIB_MODPASS', ""); // Moderators only have access to delete posts ["" to disable] define('TINYIB_MODPASS', ""); // Moderators only have access to delete posts ["" to disable]
define('TINYIB_DBMODE', "flatfile"); // Choose: flatfile / mysql / sqlite define('TINYIB_DBMODE', "flatfile"); // Choose: flatfile / mysql / sqlite (flatfile is not recommended for popular sites)
// Note: The following only apply when TINYIB_DBMODE is set to mysql // Note: The following only apply when TINYIB_DBMODE is set to mysql
define('TINYIB_DBHOST', "localhost"); define('TINYIB_DBHOST', "localhost");
@ -26,4 +27,3 @@ define('TINYIB_DBPASSWORD', "");
define('TINYIB_DBNAME', ""); define('TINYIB_DBNAME', "");
define('TINYIB_DBPOSTS', TINYIB_BOARD . "_posts"); define('TINYIB_DBPOSTS', TINYIB_BOARD . "_posts");
define('TINYIB_DBBANS', "bans"); define('TINYIB_DBBANS', "bans");
?>

BIN
video_overlay.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB