Add optional SWF support, make picture support optional, add text board mode
This commit is contained in:
parent
d97660fc18
commit
4041a57559
7 changed files with 139 additions and 53 deletions
|
@ -11,7 +11,7 @@ For demos see the [TinyIB Installations](https://github.com/tslocum/TinyIB/wiki)
|
|||
|
||||
Features
|
||||
------------
|
||||
- GIF, JPG, PNG and WebA/WebM upload.
|
||||
- GIF, JPG, PNG, SWF and WebA/WebM upload.
|
||||
- Reference links >>###
|
||||
- Delete post via password.
|
||||
- Management panel:
|
||||
|
@ -33,11 +33,11 @@ Installing
|
|||
- `git clone git://github.com/tslocum/TinyIB.git ./`
|
||||
4. Copy **settings.default.php** to **settings.php**
|
||||
5. Configure **settings.php**
|
||||
- To remove the play icon from .SWF/.WebM thumbnails, delete or rename **video_overlay.png**.
|
||||
- To allow WebA/WebM upload:
|
||||
- Ensure your web host is running Linux.
|
||||
- Install [mediainfo](http://mediaarea.net/en/MediaInfo) and [ffmpegthumbnailer](https://code.google.com/p/ffmpegthumbnailer/). On Ubuntu, run ``sudo apt-get install mediainfo ffmpegthumbnailer``.
|
||||
- Set ``TINYIB_WEBM`` to ``true``.
|
||||
- To remove the play icon from thumbnails, delete or rename **video_overlay.png**.
|
||||
6. [CHMOD](http://en.wikipedia.org/wiki/Chmod) write permissions to these directories:
|
||||
- ./ (the directory containing TinyIB)
|
||||
- ./src/
|
||||
|
|
66
imgboard.php
66
imgboard.php
|
@ -102,6 +102,7 @@ if (isset($_POST['message']) || isset($_POST['file'])) {
|
|||
$post['file_size'] = $_FILES['file']['size'];
|
||||
$post['file_size_formatted'] = convertBytes($post['file_size']);
|
||||
|
||||
// Uploaded file type
|
||||
$file_type = strtolower(preg_replace('/.*(\..+)/', '\1', $_FILES['file']['name']));
|
||||
if ($file_type == '.jpeg') {
|
||||
$file_type = '.jpg';
|
||||
|
@ -110,9 +111,19 @@ if (isset($_POST['message']) || isset($_POST['file'])) {
|
|||
$file_type = '.webm';
|
||||
}
|
||||
|
||||
// Thumbnail type
|
||||
if ($file_type == '.webm') {
|
||||
$thumb_type = '.jpg';
|
||||
} else if ($file_type == '.swf') {
|
||||
$thumb_type = '.png';
|
||||
} else {
|
||||
$thumb_type = $file_type;
|
||||
}
|
||||
|
||||
$file_name = time() . substr(microtime(), 2, 3);
|
||||
$post['file'] = $file_name . $file_type;
|
||||
$post['thumb'] = $file_name . "s" . ($file_type == '.webm' ? '.jpg' : $file_type);
|
||||
$post['thumb'] = $file_name . "s" . $thumb_type;
|
||||
|
||||
$file_location = "src/" . $post['file'];
|
||||
$thumb_location = "thumb/" . $post['thumb'];
|
||||
|
||||
|
@ -136,9 +147,9 @@ if (isset($_POST['message']) || isset($_POST['file'])) {
|
|||
$file_mime = $file_info['mime'];
|
||||
}
|
||||
|
||||
if (!($file_mime == "image/jpeg" || $file_mime == "image/gif" || $file_mime == "image/png" || (TINYIB_WEBM && ($file_mime == "video/webm" || $file_mime == "audio/webm")))) {
|
||||
if (!($file_mime == "image/jpeg" || $file_mime == "image/gif" || $file_mime == "image/png" || (TINYIB_WEBM && ($file_mime == "video/webm" || $file_mime == "audio/webm")) || (TINYIB_SWF && ($file_mime == "application/x-shockwave-flash")))) {
|
||||
@unlink($file_location);
|
||||
fancyDie("Only " . (TINYIB_WEBM ? "GIF, JPG, PNG, and WEBM" : "GIF, JPG, and PNG") . " files are allowed.");
|
||||
fancyDie(supportedFileTypes());
|
||||
}
|
||||
|
||||
if ($_FILES['file']['size'] != filesize($file_location)) {
|
||||
|
@ -175,24 +186,7 @@ if (isset($_POST['message']) || isset($_POST['file'])) {
|
|||
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];
|
||||
}
|
||||
addVideoOverlay($thumb_location);
|
||||
}
|
||||
|
||||
$duration = intval(shell_exec('mediainfo --Inform="' . ($file_mime == 'video/webm' ? 'Video' : 'Audio') . ';%Duration%" ' . $file_location));
|
||||
|
@ -206,25 +200,35 @@ if (isset($_POST['message']) || isset($_POST['file'])) {
|
|||
$post['image_width'] = $file_info[0];
|
||||
$post['image_height'] = $file_info[1];
|
||||
|
||||
list($thumb_maxwidth, $thumb_maxheight) = thumbnailDimensions($post);
|
||||
if ($file_mime == "application/x-shockwave-flash") {
|
||||
if (!copy('swf_thumbnail.png', $thumb_location)) {
|
||||
@unlink($file_location);
|
||||
fancyDie("Could not create thumbnail.");
|
||||
}
|
||||
|
||||
if (!createThumbnail($file_location, $thumb_location, $thumb_maxwidth, $thumb_maxheight)) {
|
||||
fancyDie("Could not create thumbnail.");
|
||||
addVideoOverlay($thumb_location);
|
||||
} else {
|
||||
list($thumb_maxwidth, $thumb_maxheight) = thumbnailDimensions($post);
|
||||
|
||||
if (!createThumbnail($file_location, $thumb_location, $thumb_maxwidth, $thumb_maxheight)) {
|
||||
@unlink($file_location);
|
||||
fancyDie("Could not create thumbnail.");
|
||||
}
|
||||
}
|
||||
|
||||
$thumb_info = getimagesize($thumb_location);
|
||||
$post['thumb_width'] = $thumb_info[0];
|
||||
$post['thumb_height'] = $thumb_info[1];
|
||||
}
|
||||
|
||||
$thumb_info = getimagesize($thumb_location);
|
||||
$post['thumb_width'] = $thumb_info[0];
|
||||
$post['thumb_height'] = $thumb_info[1];
|
||||
}
|
||||
}
|
||||
|
||||
if ($post['file'] == '') { // No file uploaded
|
||||
if ($post['parent'] == TINYIB_NEWTHREAD) {
|
||||
fancyDie("An image is required to start a thread.");
|
||||
if ($post['parent'] == TINYIB_NEWTHREAD && (TINYIB_PIC || TINYIB_SWF || TINYIB_WEBM)) {
|
||||
fancyDie("A file is required to start a thread.");
|
||||
}
|
||||
if (str_replace('<br>', '', $post['message']) == "") {
|
||||
fancyDie("Please enter a message and/or upload an image to make a reply.");
|
||||
fancyDie("Please enter a message" . ((TINYIB_PIC || TINYIB_SWF || TINYIB_WEBM) ? " and/or upload a file" : "") . ".");
|
||||
}
|
||||
} else {
|
||||
echo $post['file_original'] . ' uploaded.<br>';
|
||||
|
|
|
@ -18,6 +18,12 @@ if (!defined('TINYIB_MAXWOP')) {
|
|||
if (!defined('TINYIB_MAXHOP')) {
|
||||
define('TINYIB_MAXHOP', TINYIB_MAXH);
|
||||
}
|
||||
if (!defined('TINYIB_PIC')) {
|
||||
define('TINYIB_PIC', true);
|
||||
}
|
||||
if (!defined('TINYIB_SWF')) {
|
||||
define('TINYIB_SWF', false);
|
||||
}
|
||||
if (!defined('TINYIB_WEBM')) {
|
||||
define('TINYIB_WEBM', false);
|
||||
}
|
||||
|
|
|
@ -374,6 +374,36 @@ function fastImageCopyResampled(&$dst_image, &$src_image, $dst_x, $dst_y, $src_x
|
|||
return true;
|
||||
}
|
||||
|
||||
function addVideoOverlay($thumb_location) {
|
||||
if (file_exists('video_overlay.png')) {
|
||||
if (substr($thumb_location, -4) == ".jpg") {
|
||||
$thumbnail = imagecreatefromjpeg($thumb_location);
|
||||
} else {
|
||||
$thumbnail = imagecreatefrompng($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');
|
||||
|
||||
if (substr($thumb_location, -4) == ".png") {
|
||||
imagecolortransparent($thumbnail, imagecolorallocatealpha($thumbnail, 0, 0, 0, 127));
|
||||
imagealphablending($thumbnail, true);
|
||||
imagesavealpha($thumbnail, true);
|
||||
}
|
||||
|
||||
imagecopy($thumbnail, $overlay_play, ($width / 2) - ($overlay_width / 2), ($height / 2) - ($overlay_height / 2), 0, 0, $overlay_width, $overlay_height);
|
||||
|
||||
if (substr($thumb_location, -4) == ".jpg") {
|
||||
imagejpeg($thumbnail, $thumb_location);
|
||||
} else {
|
||||
imagepng($thumbnail, $thumb_location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function strallpos($haystack, $needle, $offset = 0) {
|
||||
$result = array();
|
||||
for ($i = $offset; $i < strlen($haystack); $i++) {
|
||||
|
|
84
inc/html.php
84
inc/html.php
|
@ -35,6 +35,36 @@ function pageFooter() {
|
|||
EOF;
|
||||
}
|
||||
|
||||
function supportedFileTypes() {
|
||||
$types_allowed = array();
|
||||
if (TINYIB_PIC) {
|
||||
array_push($types_allowed, "GIF", "JPG", "PNG");
|
||||
}
|
||||
if (TINYIB_SWF) {
|
||||
array_push($types_allowed, "SWF");
|
||||
}
|
||||
if (TINYIB_WEBM) {
|
||||
array_push($types_allowed, "WebM");
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
$types_count = count($types_allowed);
|
||||
$types_formatted = "";
|
||||
foreach ($types_allowed as $type) {
|
||||
if (++$i >= $types_count - 1) {
|
||||
$types_formatted .= $type . ($i == $types_count - 1 && $types_count > 1 ? " and " : "");
|
||||
} else {
|
||||
$types_formatted .= $type . ", ";
|
||||
}
|
||||
}
|
||||
|
||||
if ($types_formatted != "") {
|
||||
return "Supported file type" . ($types_count != 1 ? "s are " : " is ") . $types_formatted . ".";
|
||||
}
|
||||
|
||||
return $types_formatted;
|
||||
}
|
||||
|
||||
function buildPost($post, $res) {
|
||||
$return = "";
|
||||
$threadid = ($post['parent'] == TINYIB_NEWTHREAD) ? $post['id'] : $post['parent'];
|
||||
|
@ -165,21 +195,42 @@ EOF;
|
|||
$postingmode = '[<a href="../">Return</a>]<div class="replymode">Posting mode: Reply</div> ';
|
||||
}
|
||||
|
||||
$filetypes = (TINYIB_WEBM ? "GIF, JPG, PNG, and WEBM" : "GIF, JPG, and PNG");
|
||||
|
||||
$max_file_size_input_html = '';
|
||||
$max_file_size_rules_html = '';
|
||||
$filetypes_html = '';
|
||||
$file_input_html = '';
|
||||
$unique_posts_html = '';
|
||||
|
||||
if (TINYIB_PIC || TINYIB_WEBM || TINYIB_SWF) {
|
||||
if (TINYIB_MAXKB > 0) {
|
||||
$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>';
|
||||
}
|
||||
|
||||
$filetypes_html = '<li>' . supportedFileTypes() . '</li>';
|
||||
|
||||
$file_input_html = <<<EOF
|
||||
<tr>
|
||||
<td class="postblock">
|
||||
File
|
||||
</td>
|
||||
<td>
|
||||
<input type="file" name="file" size="35" accesskey="f">
|
||||
</td>
|
||||
</tr>
|
||||
EOF;
|
||||
}
|
||||
|
||||
$thumbnails_html = '';
|
||||
if (TINYIB_PIC) {
|
||||
$thumbnails_html = "<li>Images greater than $maxdimensions will be thumbnailed.</li>";
|
||||
}
|
||||
|
||||
$unique_posts = uniquePosts();
|
||||
if ($unique_posts > 0) {
|
||||
$unique_posts_html = "<li>Currently $unique_posts unique user posts.</li>\n";
|
||||
}
|
||||
|
||||
$max_file_size_input = '';
|
||||
$max_file_size_html = '';
|
||||
if (TINYIB_MAXKB > 0) {
|
||||
$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>';
|
||||
}
|
||||
|
||||
$body = <<<EOF
|
||||
<body>
|
||||
<div class="adminbar">
|
||||
|
@ -193,7 +244,7 @@ EOF;
|
|||
$postingmode
|
||||
<div class="postarea">
|
||||
<form name="postform" id="postform" action="imgboard.php" method="post" enctype="multipart/form-data">
|
||||
$max_file_size_input
|
||||
$max_file_size_input_html
|
||||
<input type="hidden" name="parent" value="$parent">
|
||||
<table class="postform">
|
||||
<tbody>
|
||||
|
@ -230,14 +281,7 @@ EOF;
|
|||
<textarea name="message" cols="48" rows="4" accesskey="m"></textarea>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="postblock">
|
||||
File
|
||||
</td>
|
||||
<td>
|
||||
<input type="file" name="file" size="35" accesskey="f">
|
||||
</td>
|
||||
</tr>
|
||||
$file_input_html
|
||||
<tr>
|
||||
<td class="postblock">
|
||||
Password
|
||||
|
@ -249,9 +293,9 @@ EOF;
|
|||
<tr>
|
||||
<td colspan="2" class="rules">
|
||||
<ul>
|
||||
<li>Supported file types are $filetypes.</li>
|
||||
$filetypes_html
|
||||
$max_file_size_rules_html
|
||||
<li>Images greater than $maxdimensions will be thumbnailed.</li>
|
||||
$thumbnails_html
|
||||
$unique_posts_html
|
||||
</ul>
|
||||
</td>
|
||||
|
|
|
@ -8,6 +8,8 @@ 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_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_PIC', true); // Enable .jpg, .png and .gif image file upload
|
||||
define('TINYIB_SWF', false); // Enable .swf Flash file upload
|
||||
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_MAXH', 250); // Maximum image height (reply)
|
||||
|
|
BIN
swf_thumbnail.png
Normal file
BIN
swf_thumbnail.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.8 KiB |
Loading…
Reference in a new issue