1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-29 01:34:31 +01:00

Merge pull request #72 from peerau/master

Changes to allow media-file clustering and CDN possibilities.
This commit is contained in:
Fredrick Brennan 2014-09-25 17:34:02 -04:00
commit 5cbdbd312a
5 changed files with 40 additions and 27 deletions

View File

@ -130,6 +130,10 @@ foreach($delete as $i => $d){
// Delete entire board directory // Delete entire board directory
rrmdir($board['uri'] . '/'); rrmdir($board['uri'] . '/');
rrmdir('static/banners/' . $board['uri']); rrmdir('static/banners/' . $board['uri']);
// HAAAAAX
if($config['dir']['img_root'] != '')
rrmdir($config['dir']['img_root'] . $board['uri']);
cache::delete('board_' . $board['uri']); cache::delete('board_' . $board['uri']);
_syslog(LOG_NOTICE, "Board deleted: {$board['uri']}"); _syslog(LOG_NOTICE, "Board deleted: {$board['uri']}");

View File

@ -1132,6 +1132,12 @@
$config['dir']['thumb'] = 'thumb/'; $config['dir']['thumb'] = 'thumb/';
$config['dir']['res'] = 'res/'; $config['dir']['res'] = 'res/';
// Images in a seperate directory - For CDN or media servers
// This is a particularly advanced feature - contact ctrlcctrlv or rails unless you
// really know what you're doing
$config['dir']['img_root'] = '';
// For load balancing, having a seperate server (and domain/subdomain) for serving static content is // For load balancing, having a seperate server (and domain/subdomain) for serving static content is
// possible. This can either be a directory or a URL. Defaults to $config['root'] . 'static/'. // possible. This can either be a directory or a URL. Defaults to $config['root'] . 'static/'.
// $config['dir']['static'] = 'http://static.example.org/'; // $config['dir']['static'] = 'http://static.example.org/';

View File

@ -425,12 +425,12 @@ function setupBoard($array) {
if (!file_exists($board['dir'])) if (!file_exists($board['dir']))
@mkdir($board['dir'], 0777) or error("Couldn't create " . $board['dir'] . ". Check permissions.", true); @mkdir($board['dir'], 0777) or error("Couldn't create " . $board['dir'] . ". Check permissions.", true);
if (!file_exists($board['dir'] . $config['dir']['img'])) if (!file_exists($config['dir']['img_root'] . $board['dir'] . $config['dir']['img']))
@mkdir($board['dir'] . $config['dir']['img'], 0777) @mkdir($config['dir']['img_root'] . $board['dir'] . $config['dir']['img'], 0777)
or error("Couldn't create " . $board['dir'] . $config['dir']['img'] . ". Check permissions.", true); or error("Couldn't create " . $config['dir']['img_root'] . $board['dir'] . $config['dir']['img'] . ". Check permissions.", true);
if (!file_exists($board['dir'] . $config['dir']['thumb'])) if (!file_exists($config['dir']['img_root'] . $board['dir'] . $config['dir']['thumb']))
@mkdir($board['dir'] . $config['dir']['thumb'], 0777) @mkdir($config['dir']['img_root'] . $board['dir'] . $config['dir']['thumb'], 0777)
or error("Couldn't create " . $board['dir'] . $config['dir']['img'] . ". Check permissions.", true); or error("Couldn't create " . $config['dir']['img_root'] . $board['dir'] . $config['dir']['img'] . ". Check permissions.", true);
if (!file_exists($board['dir'] . $config['dir']['res'])) if (!file_exists($board['dir'] . $config['dir']['res']))
@mkdir($board['dir'] . $config['dir']['res'], 0777) @mkdir($board['dir'] . $config['dir']['res'], 0777)
or error("Couldn't create " . $board['dir'] . $config['dir']['img'] . ". Check permissions.", true); or error("Couldn't create " . $board['dir'] . $config['dir']['img'] . ". Check permissions.", true);
@ -997,11 +997,11 @@ function deleteFile($id, $remove_entirely_if_already=true, $file=null) {
foreach ($files as $i => $f) { foreach ($files as $i => $f) {
if (($file !== false && $i == $file) || $file === null) { if (($file !== false && $i == $file) || $file === null) {
// Delete thumbnail // Delete thumbnail
file_unlink($board['dir'] . $config['dir']['thumb'] . $f->thumb); file_unlink($config['dir']['img_root'] . $board['dir'] . $config['dir']['thumb'] . $f->thumb);
unset($files[$i]->thumb); unset($files[$i]->thumb);
// Delete file // Delete file
file_unlink($board['dir'] . $config['dir']['img'] . $f->file); file_unlink($config['dir']['img_root'] . $board['dir'] . $config['dir']['img'] . $f->file);
$files[$i]->file = 'deleted'; $files[$i]->file = 'deleted';
} }
} }
@ -1080,8 +1080,8 @@ function deletePost($id, $error_if_doesnt_exist=true, $rebuild_after=true) {
// Delete file // Delete file
foreach (json_decode($post['files']) as $i => $f) { foreach (json_decode($post['files']) as $i => $f) {
if ($f->file !== 'deleted') { if ($f->file !== 'deleted') {
file_unlink($board['dir'] . $config['dir']['img'] . $f->file); file_unlink($config['dir']['img_root'] . $board['dir'] . $config['dir']['img'] . $f->file);
file_unlink($board['dir'] . $config['dir']['thumb'] . $f->thumb); file_unlink($config['dir']['img_root'] . $board['dir'] . $config['dir']['thumb'] . $f->thumb);
} }
} }
} }

View File

@ -429,6 +429,9 @@ function mod_edit_board($boardName) {
// Delete entire board directory // Delete entire board directory
rrmdir($board['uri'] . '/'); rrmdir($board['uri'] . '/');
// To reiterate: HAAAAAX
if($config['dir']['img_root'] != '')
rrmdir($config['dir']['img_root'] . $board['uri']);
} else { } else {
$query = prepare('UPDATE ``boards`` SET `title` = :title, `subtitle` = :subtitle WHERE `uri` = :uri'); $query = prepare('UPDATE ``boards`` SET `title` = :title, `subtitle` = :subtitle WHERE `uri` = :uri');
$query->bindValue(':uri', $board['uri']); $query->bindValue(':uri', $board['uri']);
@ -1121,8 +1124,8 @@ function mod_move_reply($originBoard, $postID) {
$post['files'] = json_decode($post['files'], TRUE); $post['files'] = json_decode($post['files'], TRUE);
$post['has_file'] = true; $post['has_file'] = true;
foreach ($post['files'] as $i => &$file) { foreach ($post['files'] as $i => &$file) {
$file['file_path'] = sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $file['file']; $file['file_path'] = sprintf($config['board_path'], $config['dir']['img_root'] . $board['uri']) . $config['dir']['img'] . $file['file'];
$file['thumb_path'] = sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $file['thumb']; $file['thumb_path'] = sprintf($config['board_path'], $config['dir']['img_root'] . $board['uri']) . $config['dir']['thumb'] . $file['thumb'];
} }
} else { } else {
$post['has_file'] = false; $post['has_file'] = false;
@ -1140,9 +1143,9 @@ function mod_move_reply($originBoard, $postID) {
if ($post['has_file']) { if ($post['has_file']) {
foreach ($post['files'] as $i => &$file) { foreach ($post['files'] as $i => &$file) {
// move the image // move the image
rename($file['file_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $file['file']); rename($file['file_path'], sprintf($config['board_path'], $config['dir']['img_root'] . $board['uri']) . $config['dir']['img'] . $file['file']);
if ($file['thumb'] != 'spoiler') { //trying to move/copy the spoiler thumb raises an error if ($file['thumb'] != 'spoiler') { //trying to move/copy the spoiler thumb raises an error
rename($file['thumb_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $file['thumb']); rename($file['thumb_path'], sprintf($config['board_path'], $config['dir']['img_root'] . $board['uri']) . $config['dir']['thumb'] . $file['thumb']);
} }
} }
} }
@ -1222,8 +1225,8 @@ function mod_move($originBoard, $postID) {
foreach ($post['files'] as $i => &$file) { foreach ($post['files'] as $i => &$file) {
if ($file['file'] === 'deleted') if ($file['file'] === 'deleted')
continue; continue;
$file['file_path'] = sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $file['file']; $file['file_path'] = sprintf($config['board_path'], $config['dir']['img_root'] . $board['uri']) . $config['dir']['img'] . $file['file'];
$file['thumb_path'] = sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $file['thumb']; $file['thumb_path'] = sprintf($config['board_path'], $config['dir']['img_root'] . $board['uri']) . $config['dir']['thumb'] . $file['thumb'];
} }
} else { } else {
$post['has_file'] = false; $post['has_file'] = false;
@ -1242,9 +1245,9 @@ function mod_move($originBoard, $postID) {
// copy image // copy image
foreach ($post['files'] as $i => &$file) { foreach ($post['files'] as $i => &$file) {
if ($file['file'] !== 'deleted') if ($file['file'] !== 'deleted')
$clone($file['file_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $file['file']); $clone($file['file_path'], sprintf($config['board_path'], $config['dir']['img_root'] . $board['uri']) . $config['dir']['img'] . $file['file']);
if (isset($file['thumb']) && !in_array($file['thumb'], array('spoiler', 'deleted', 'file'))) if (isset($file['thumb']) && !in_array($file['thumb'], array('spoiler', 'deleted', 'file')))
$clone($file['thumb_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $file['thumb']); $clone($file['thumb_path'], sprintf($config['board_path'], $config['dir']['img_root'] . $board['uri']) . $config['dir']['thumb'] . $file['thumb']);
} }
} }
@ -1265,8 +1268,8 @@ function mod_move($originBoard, $postID) {
$post['files'] = json_decode($post['files'], TRUE); $post['files'] = json_decode($post['files'], TRUE);
$post['has_file'] = true; $post['has_file'] = true;
foreach ($post['files'] as $i => &$file) { foreach ($post['files'] as $i => &$file) {
$file['file_path'] = sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $file['file']; $file['file_path'] = sprintf($config['board_path'], $config['dir']['img_root'] . $board['uri']) . $config['dir']['img'] . $file['file'];
$file['thumb_path'] = sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $file['thumb']; $file['thumb_path'] = sprintf($config['board_path'], $config['dir']['img_root'] . $board['uri']) . $config['dir']['thumb'] . $file['thumb'];
} }
} else { } else {
$post['has_file'] = false; $post['has_file'] = false;
@ -1305,8 +1308,8 @@ function mod_move($originBoard, $postID) {
if ($post['has_file']) { if ($post['has_file']) {
// copy image // copy image
foreach ($post['files'] as $i => &$file) { foreach ($post['files'] as $i => &$file) {
$clone($file['file_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $file['file']); $clone($file['file_path'], sprintf($config['board_path'], $config['dir']['img_root'] . $board['uri']) . $config['dir']['img'] . $file['file']);
$clone($file['thumb_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $file['thumb']); $clone($file['thumb_path'], sprintf($config['board_path'], $config['dir']['img_root'] . $board['uri']) . $config['dir']['thumb'] . $file['thumb']);
} }
} }
// insert reply // insert reply
@ -1582,7 +1585,7 @@ function mod_spoiler_image($board, $post, $file) {
$result = $query->fetch(PDO::FETCH_ASSOC); $result = $query->fetch(PDO::FETCH_ASSOC);
$files = json_decode($result['files']); $files = json_decode($result['files']);
file_unlink($board . '/' . $config['dir']['thumb'] . $files[$file]->thumb); file_unlink($config['dir']['img_root'] . $board . '/' . $config['dir']['thumb'] . $files[$file]->thumb);
$files[$file]->thumb = 'spoiler'; $files[$file]->thumb = 'spoiler';
$files[$file]->thumbheight = 128; $files[$file]->thumbheight = 128;
$files[$file]->thumbwidth = 128; $files[$file]->thumbwidth = 128;

View File

@ -445,8 +445,8 @@ if (isset($_POST['delete'])) {
if (sizeof($_FILES) > 1) if (sizeof($_FILES) > 1)
$file['file_id'] .= "-$i"; $file['file_id'] .= "-$i";
$file['file'] = $board['dir'] . $config['dir']['img'] . $file['file_id'] . '.' . $file['extension']; $file['file'] = $config['dir']['img_root'] . $board['dir'] . $config['dir']['img'] . $file['file_id'] . '.' . $file['extension'];
$file['thumb'] = $board['dir'] . $config['dir']['thumb'] . $file['file_id'] . '.' . ($config['thumb_ext'] ? $config['thumb_ext'] : $file['extension']); $file['thumb'] = $config['dir']['img_root'] . $board['dir'] . $config['dir']['thumb'] . $file['file_id'] . '.' . ($config['thumb_ext'] ? $config['thumb_ext'] : $file['extension']);
$post['files'][] = $file; $post['files'][] = $file;
$i++; $i++;
} }
@ -771,9 +771,9 @@ if (isset($_POST['delete'])) {
foreach ($post['files'] as $key => &$file) { foreach ($post['files'] as $key => &$file) {
$file['file_path'] = $file['file']; $file['file_path'] = $file['file'];
$file['thumb_path'] = $file['thumb']; $file['thumb_path'] = $file['thumb'];
$file['file'] = mb_substr($file['file'], mb_strlen($board['dir'] . $config['dir']['img'])); $file['file'] = mb_substr($file['file'], mb_strlen($config['dir']['img_root'] . $board['dir'] . $config['dir']['img']));
if ($file['is_an_image'] && $file['thumb'] != 'spoiler') if ($file['is_an_image'] && $file['thumb'] != 'spoiler')
$file['thumb'] = mb_substr($file['thumb'], mb_strlen($board['dir'] . $config['dir']['thumb'])); $file['thumb'] = mb_substr($file['thumb'], mb_strlen($config['dir']['img_root'] . $board['dir'] . $config['dir']['thumb']));
} }
} }