diff options
| author | Paul Merrill <napalminc@gmail.com> | 2010-11-05 09:02:43 -0700 |
|---|---|---|
| committer | Paul Merrill <napalminc@gmail.com> | 2010-11-05 09:02:43 -0700 |
| commit | 93c6012aee65908006c1864c835d40f321c5a1e4 (patch) | |
| tree | f9210cffc74e30b7b477f7be2adf77f61c6b8382 | |
| parent | 27d9d469d8dadcc6512e5013e27282d85460d9ed (diff) | |
| parent | 395aa543a6d3c14a269fbc4c0f93cc2d7a4da97b (diff) | |
Merge branch 'sti' of github.com:savetheinternet/Tinyboard into jamer
| -rw-r--r-- | inc/config.php | 21 | ||||
| -rw-r--r-- | inc/display.php | 8 | ||||
| -rw-r--r-- | inc/instance-config.php | 12 | ||||
| -rw-r--r-- | post.php | 17 | ||||
| -rw-r--r-- | templates/index.html | 1 | ||||
| -rw-r--r-- | templates/page.html | 2 | ||||
| -rw-r--r-- | templates/thread.html | 1 |
7 files changed, 48 insertions, 14 deletions
diff --git a/inc/config.php b/inc/config.php index 7115c2dc..397257fe 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<br>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); @@ -62,7 +63,11 @@ define('MAX_WIDTH', 10000, true); define('MAX_HEIGHT', MAX_WIDTH, true); - define('ALLOW_ZIP', true, 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', false, true); define('ZIP_IMAGE', 'src/zip.png', true); @@ -85,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); @@ -100,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/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 .= '<p class="fileinfo">File: <a href="' . ROOT . $this->file .'">' . basename($this->file) . '</a> <span class="unimportant">(' . + $built .= '<p class="fileinfo">File: <a href="' . ROOT . DIR_IMG . $this->file .'">' . $this->file . '</a> <span class="unimportant">(' . // Filesize format_bytes($this->filesize) . ', ' . // File dimensions @@ -94,7 +94,7 @@ // Filename $built .= ', ' . $this->filename . ')</span></p>' . // Thumbnail - '<a href="' . ROOT . $this->file.'"><img src="' . ROOT . $this->thumb.'" style="width:'.$this->thumbx.'px;height:'.$this->thumby.'px;" /></a>'; + '<a href="' . ROOT . DIR_IMG . $this->file.'"><img src="' . ROOT . DIR_THUMB . $this->thumb.'" style="width:'.$this->thumbx.'px;height:'.$this->thumby.'px;" /></a>'; } // Body @@ -131,7 +131,7 @@ public function build($index=false) { - $built = '<p class="fileinfo">File: <a href="' . ROOT . $this->file .'">' . basename($this->file) . '</a> <span class="unimportant">(' . + $built = '<p class="fileinfo">File: <a href="' . ROOT . DIR_IMG . $this->file .'">' . $this->file . '</a> <span class="unimportant">(' . // Filesize format_bytes($this->filesize) . ', ' . // File dimensions @@ -144,7 +144,7 @@ // Filename $built .= ', ' . $this->filename . ')</span></p>' . // Thumbnail - '<a href="' . ROOT . $this->file.'"><img src="' . ROOT . $this->thumb.'" style="width:'.$this->thumbx.'px;height:'.$this->thumby.'px;" /></a>'; + '<a href="' . ROOT . DIR_IMG . $this->file.'"><img src="' . ROOT . DIR_THUMB . $this->thumb.'" style="width:'.$this->thumbx.'px;height:'.$this->thumby.'px;" /></a>'; $built .= '<div class="post op"><p class="intro"' . (!$index?' id="' . $this->id . '"':'') . '>'; diff --git a/inc/instance-config.php b/inc/instance-config.php index 7655d344..1ae82a3f 100644 --- a/inc/instance-config.php +++ b/inc/instance-config.php @@ -1,4 +1,5 @@ <?php
+
/*
* Instance Configuration
* ----------------------
@@ -9,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');
*/
@@ -121,6 +121,13 @@ 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'])))
+ // TODO: Check if it's not empty and has at least one (valid) image
+ zip_close($zip);
+ else
+ error(ERR_INVALIDZIP);
+
$post['file'] = ZIP_IMAGE;
$post['extension'] = strtolower(substr($post['file'], strrpos($post['file'], '.') + 1));
}
@@ -173,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
@@ -191,7 +202,6 @@ if(in_array($extension, $allowed_ext)) {
if (zip_entry_open($zip, $entry, 'r')) {
-
// Fake post
$dump_post = Array(
'subject' => $post['subject'],
@@ -260,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);
}
@@ -297,7 +311,6 @@ } else {
if(!file_exists(FILE_INDEX)) {
buildIndex();
- sql_close();
}
header('Location: ' . ROOT . FILE_INDEX, true, 302);
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 @@ <link rel="stylesheet" media="screen" href="{index}style.css"/>
<title>{board[url]} - {board[name]}</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
+ <meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<script type="text/javascript" src="{index}main.js"></script>
</head>
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 @@ <head>
<link rel="stylesheet" media="screen" href="{index}style.css"/>
<title>{title}</title>
+ <meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
+ <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
</head>
<body>
<h1>{title}</h1>
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 @@ <link rel="stylesheet" media="screen" href="{index}style.css"/>
<title>{board[url]} - {board[name]}</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
+ <meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<script type="text/javascript" src="{index}main.js"></script>
</head>
|
