From 61fc6f689950f256cdae1bd9dee89de7ca849603 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Fri, 5 Nov 2010 03:13:43 +1100 Subject: [PATCH 1/8] Change of comments in instance-config.php --- inc/instance-config.php | 1 + 1 file changed, 1 insertion(+) diff --git a/inc/instance-config.php b/inc/instance-config.php index 7655d344..2ebbad71 100644 --- a/inc/instance-config.php +++ b/inc/instance-config.php @@ -1,4 +1,5 @@ Date: Fri, 5 Nov 2010 03:14:33 +1100 Subject: [PATCH 2/8] Defaults change. Added ROOT. --- inc/instance-config.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/inc/instance-config.php b/inc/instance-config.php index 2ebbad71..1ae82a3f 100644 --- a/inc/instance-config.php +++ b/inc/instance-config.php @@ -10,10 +10,13 @@ /* - define('MY_SERVER', 'localhost', true); - define('MY_USER', '', true); - define('MY_PASSWORD', '', true); - define('MY_DATABASE', '', true); + // Database stuff + define('MY_SERVER', 'localhost'); + define('MY_USER', ''); + define('MY_PASSWORD', ''); + define('MY_DATABASE', ''); + + define('ROOT', '/'); // define('FOO', 'bar'); */ From fd36e447f252851e2bb18d73c6fc6a994a329006 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Fri, 5 Nov 2010 03:17:05 +1100 Subject: [PATCH 3/8] Descriptive comment about ZIP uploads --- inc/config.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/inc/config.php b/inc/config.php index 7115c2dc..9d1f260d 100644 --- a/inc/config.php +++ b/inc/config.php @@ -62,6 +62,10 @@ define('MAX_WIDTH', 10000, true); define('MAX_HEIGHT', MAX_WIDTH, true); + /* When you upload a ZIP as a file, all the images inside the archive + * get dumped into the thread as replies. + * Extremely beta and not recommended yet. + */ define('ALLOW_ZIP', true, true); define('ZIP_IMAGE', 'src/zip.png', true); From 6fc9db808747acf5a91caa65d65819d930f1b987 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Fri, 5 Nov 2010 03:18:05 +1100 Subject: [PATCH 4/8] ALLOW_ZIP defaults to false instead of true --- inc/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/config.php b/inc/config.php index 9d1f260d..e5c0b42e 100644 --- a/inc/config.php +++ b/inc/config.php @@ -66,7 +66,7 @@ * get dumped into the thread as replies. * Extremely beta and not recommended yet. */ - define('ALLOW_ZIP', true, true); + define('ALLOW_ZIP', false, true); define('ZIP_IMAGE', 'src/zip.png', true); From f6abfa61c693b9b55937be0db0a54ca074349cc6 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Fri, 5 Nov 2010 20:32:40 +1100 Subject: [PATCH 5/8] Added a check to verify if .ZIP files are infact archives. --- inc/config.php | 1 + post.php | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/inc/config.php b/inc/config.php index e5c0b42e..40ea923a 100644 --- a/inc/config.php +++ b/inc/config.php @@ -51,6 +51,7 @@ define('ERR_INVALIDIMG','Invalid image.', true); define('ERR_FILESIZE', 'Maximum file size: %maxsz% bytes
Your file\'s size: %filesz% bytes', true); define('ERR_MAXSIZE', 'The file was too big.', true); + define('ERR_INVALIDZIP', 'Invalid archive!', true); // For resizing, max values define('THUMB_WIDTH', 200, true); diff --git a/post.php b/post.php index 1c875f40..e10f3b4e 100644 --- a/post.php +++ b/post.php @@ -121,6 +121,12 @@ if(!@move_uploaded_file($_FILES['file']['tmp_name'], $post['file'])) error(ERROR_NOMOVE); if($post['zip']) { + // Validate ZIP file + if(is_resource($zip = zip_open($post['zip']))) + zip_close($zip); + else + error(ERR_INVALIDZIP); + $post['file'] = ZIP_IMAGE; $post['extension'] = strtolower(substr($post['file'], strrpos($post['file'], '.') + 1)); } @@ -191,7 +197,6 @@ if(in_array($extension, $allowed_ext)) { if (zip_entry_open($zip, $entry, 'r')) { - // Fake post $dump_post = Array( 'subject' => $post['subject'], From 247772323ecb035885778c8a6cc8f83f60482c30 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Fri, 5 Nov 2010 20:43:18 +1100 Subject: [PATCH 6/8] Allowed change of root directory for systems where it is not the current directory. --- inc/config.php | 14 +++++++++++--- post.php | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/inc/config.php b/inc/config.php index 40ea923a..397257fe 100644 --- a/inc/config.php +++ b/inc/config.php @@ -90,6 +90,11 @@ // The root directory, including the trailing slash, for Tinyboard. // examples: '/', '/board/', '/chan/' define('ROOT', '/', true); + + // If for some reason the folders and static HTML index files aren't in the current working direcotry, + // enter the directory path here. Otherwise, keep it false. + define('ROOT_FILE', false); + define('POST_URL', ROOT . 'post.php', true); define('FILE_INDEX', 'index.html', true); define('FILE_PAGE', '%d.html', true); @@ -105,11 +110,14 @@ define('BUTTON_NEWTOPIC', 'New Topic', true); define('BUTTON_REPLY', 'New Reply', true); - + define('ALWAYS_NOKO', false, true); - + define('URL_MATCH', '/^' . (@$_SERVER['HTTPS']?'https':'http').':\/\/'.$_SERVER['HTTP_HOST'] . '(' . preg_quote(ROOT, '/') . '|' . preg_quote(ROOT, '/') . '' . preg_quote(FILE_INDEX, '/') . '|' . preg_quote(ROOT, '/') . '' . str_replace('%d', '\d+', preg_quote(FILE_PAGE, '/')) . ')$/', true); - + + if(ROOT_FILE) { + chdir(ROOT_FILE); + } if(!defined('IS_INSTALLATION')) { if(!file_exists(DIR_IMG)) @mkdir(DIR_IMG) or error("Couldn't create " . DIR_IMG . ". Install manually.", true); if(!file_exists(DIR_THUMB)) @mkdir(DIR_THUMB) or error("Couldn't create " . DIR_IMG . ". Install manually.", true); diff --git a/post.php b/post.php index e10f3b4e..a1d32f27 100644 --- a/post.php +++ b/post.php @@ -123,6 +123,7 @@ if($post['zip']) { // Validate ZIP file if(is_resource($zip = zip_open($post['zip']))) + // TODO: Check if it's not empty and has at least one (valid) image zip_close($zip); else error(ERR_INVALIDZIP); From 43b62acb44893fc62682e09a387ce77f102c06ea Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Fri, 5 Nov 2010 20:51:39 +1100 Subject: [PATCH 7/8] Stopped storing the full path name of the images in the database. Should make it easier/possible to move the imageboard later. --- inc/display.php | 8 ++++---- post.php | 9 ++++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/inc/display.php b/inc/display.php index 132dcac5..71ecface 100644 --- a/inc/display.php +++ b/inc/display.php @@ -81,7 +81,7 @@ // File info if(!empty($this->file)) { - $built .= '

File: ' . basename($this->file) . ' (' . + $built .= '

File: ' . $this->file . ' (' . // Filesize format_bytes($this->filesize) . ', ' . // File dimensions @@ -94,7 +94,7 @@ // Filename $built .= ', ' . $this->filename . ')

' . // Thumbnail - ''; + ''; } // Body @@ -131,7 +131,7 @@ public function build($index=false) { - $built = '

File: ' . basename($this->file) . ' (' . + $built = '

File: ' . $this->file . ' (' . // Filesize format_bytes($this->filesize) . ', ' . // File dimensions @@ -144,7 +144,7 @@ // Filename $built .= ', ' . $this->filename . ')

' . // Thumbnail - ''; + ''; $built .= '

'; diff --git a/post.php b/post.php index a1d32f27..c3cf8cce 100644 --- a/post.php +++ b/post.php @@ -180,6 +180,10 @@ $post['thumbheight'] = $thumb['height']; } + // Remove DIR_* before inserting them into the database. + $post['file'] = substr_replace($post['file'], '', 0, strlen(DIR_IMG)); + $post['thumb'] = substr_replace($post['thumb'], '', 0, strlen(DIR_THUMB)); + // Todo: Validate some more, remove messy code, allow more specific configuration // MySQLify @@ -266,6 +270,10 @@ $dump_post['thumbwidth'] = $thumb['width']; $dump_post['thumbheight'] = $thumb['height']; + // Remove DIR_* before inserting them into the database. + $dump_post['file'] = substr_replace($dump_post['file'], '', 0, strlen(DIR_IMG)); + $dump_post['thumb'] = substr_replace($dump_post['thumb'], '', 0, strlen(DIR_THUMB)); + // Create the post post($dump_post, false); } @@ -303,7 +311,6 @@ } else { if(!file_exists(FILE_INDEX)) { buildIndex(); - sql_close(); } header('Location: ' . ROOT . FILE_INDEX, true, 302); From 395aa543a6d3c14a269fbc4c0f93cc2d7a4da97b Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Fri, 5 Nov 2010 20:54:44 +1100 Subject: [PATCH 8/8] Stopped caching HTML files on most browsers. --- templates/index.html | 1 + templates/page.html | 2 ++ templates/thread.html | 1 + 3 files changed, 4 insertions(+) diff --git a/templates/index.html b/templates/index.html index 2921e7f0..bc946db1 100644 --- a/templates/index.html +++ b/templates/index.html @@ -4,6 +4,7 @@ {board[url]} - {board[name]} + diff --git a/templates/page.html b/templates/page.html index 37259173..d9968b1e 100644 --- a/templates/page.html +++ b/templates/page.html @@ -3,6 +3,8 @@ {title} + +

{title}

diff --git a/templates/thread.html b/templates/thread.html index 79a9bcf5..bd1fca57 100644 --- a/templates/thread.html +++ b/templates/thread.html @@ -4,6 +4,7 @@ {board[url]} - {board[name]} +