From ca066b0ca8293bbe6eeaf3810f40a914b1ebd7c8 Mon Sep 17 00:00:00 2001 From: Fredrick Brennan Date: Wed, 6 May 2015 20:40:11 +0800 Subject: [PATCH] New feature: custom board assets --- inc/8chan-mod-config.php | 2 + inc/8chan-mod-pages.php | 128 ++++++++++++++++++++++++++++- inc/config.php | 5 +- templates/mod/settings.html | 3 +- templates/themes/catalog/theme.php | 4 +- 5 files changed, 137 insertions(+), 5 deletions(-) diff --git a/inc/8chan-mod-config.php b/inc/8chan-mod-config.php index 1c2ed2ac..962b5a51 100644 --- a/inc/8chan-mod-config.php +++ b/inc/8chan-mod-config.php @@ -15,6 +15,7 @@ $config['mod']['mod_board_log'] = MOD; $config['mod']['editpost'] = BOARDVOLUNTEER; $config['mod']['edit_banners'] = MOD; + $config['mod']['edit_assets'] = MOD; $config['mod']['edit_flags'] = MOD; $config['mod']['edit_settings'] = MOD; $config['mod']['edit_volunteers'] = MOD; @@ -51,3 +52,4 @@ $config['mod']['custom_pages']['/flags/(\%b)'] = '8_flags'; $config['mod']['custom_pages']['/banners/(\%b)'] = '8_banners'; $config['mod']['custom_pages']['/settings/(\%b)'] = '8_settings'; + $config['mod']['custom_pages']['/assets/(\%b)'] = '8_assets'; diff --git a/inc/8chan-mod-pages.php b/inc/8chan-mod-pages.php index 3f16e16c..67495517 100644 --- a/inc/8chan-mod-pages.php +++ b/inc/8chan-mod-pages.php @@ -303,6 +303,121 @@ FLAGS; mod_page(_('Edit flags'), 'mod/flags.html', array('board'=>$board,'banners'=>$banners,'token'=>make_secure_link_token('banners/'.$board['uri']))); } + function mod_8_assets($b) { + global $config, $mod, $board; + require_once 'inc/image.php'; + + if (!hasPermission($config['mod']['edit_assets'], $b)) + error($config['error']['noaccess']); + + if (!openBoard($b)) + error("Could not open board!"); + + $dir = 'static/assets/'.$b; + + if (!is_dir($dir)){ + mkdir($dir, 0777, true); + + symlink(getcwd() . '/' . $config['image_deleted'], "$dir/deleted.png"); + symlink(getcwd() . '/' . $config['spoiler_image'], "$dir/spoiler.png"); + symlink(getcwd() . '/' . $config['no_file_image'], "$dir/no-file.png"); + } + + // "File deleted" + if (isset($_FILES['deleted_file']) && !empty($_FILES['deleted_file']['tmp_name'])){ + $upload = $_FILES['deleted_file']['tmp_name']; + $extension = strtolower(mb_substr($_FILES['deleted_file']['name'], mb_strrpos($_FILES['deleted_file']['name'], '.') + 1)); + var_dump($_FILES); + + if (!is_readable($upload)) { + error($config['error']['nomove']); + } + + if (filesize($upload) > 512000){ + error('File too large!'); + } + + if (!in_array($extension, array('png', 'gif'))) { + error('File must be PNG or GIF format.'); + } + + if (!$size = @getimagesize($upload)) { + error($config['error']['invalidimg']); + } + + if ($size[0] != 140 or $size[1] != 50){ + error('Image wrong size!'); + } + + unlink("$dir/deleted.png"); + copy($upload, "$dir/deleted.png"); + purge("$dir/deleted.png"); + } + + // Spoiler file + if (isset($_FILES['spoiler_file']) && !empty($_FILES['spoiler_file']['tmp_name'])){ + $upload = $_FILES['spoiler_file']['tmp_name']; + $extension = strtolower(mb_substr($_FILES['spoiler_file']['name'], mb_strrpos($_FILES['spoiler_file']['name'], '.') + 1)); + + if (!is_readable($upload)) { + error($config['error']['nomove']); + } + + if (filesize($upload) > 512000){ + error('File too large!'); + } + + + if (!in_array($extension, array('png', 'gif'))) { + error('File must be PNG or GIF format.'); + } + + if (!$size = @getimagesize($upload)) { + error($config['error']['invalidimg']); + } + + if ($size[0] != 128 or $size[1] != 128){ + error('Image wrong size!'); + } + + unlink("$dir/spoiler.png"); + copy($upload, "$dir/spoiler.png"); + purge("$dir/spoiler.png"); + } + + // No file + if (isset($_FILES['nofile_file']) && !empty($_FILES['nofile_file']['tmp_name'])){ + $upload = $_FILES['nofile_file']['tmp_name']; + $extension = strtolower(mb_substr($_FILES['nofile_file']['name'], mb_strrpos($_FILES['nofile_file']['name'], '.') + 1)); + + if (!is_readable($upload)) { + error($config['error']['nomove']); + } + + if (filesize($upload) > 512000){ + error('File too large!'); + } + + if (!in_array($extension, array('png', 'gif'))) { + error('File must be PNG or GIF format.'); + } + + if (!$size = @getimagesize($upload)) { + error($config['error']['invalidimg']); + } + + if ($size[0] != 500 or $size[1] != 500){ + error('Image wrong size!'); + } + + unlink("$dir/no-file.png"); + copy($upload, "$dir/no-file.png"); + purge("$dir/no-file.png"); + } + + mod_page(_('Edit board assets'), 'mod/assets.html', array('board'=>$board,'token'=>make_secure_link_token('assets/'.$board['uri']))); + } + function mod_8_banners($b) { global $config, $mod, $board; require_once 'inc/image.php'; @@ -431,6 +546,16 @@ FLAGS; $multiimage = ''; } + if (isset($_POST['custom_assets'])) { + $assets = "\$config['custom_assets'] = true; + \$config['spoiler_image'] = 'static/assets/$b/spoiler.png'; + \$config['image_deleted'] = 'static/assets/$b/deleted.png'; + \$config['no_file_image'] = 'static/assets/$b/no-file.png'; + "; + } else { + $assets = ''; + } + $file_board = ''; if ($fileboard) { $force_image_op = true; @@ -588,7 +713,8 @@ FLAGS; \$config['max_pages'] = $max_pages; \$config['max_newlines'] = $max_newlines; \$config['oekaki'] = $oekaki; -$code_tags $katex $replace $multiimage $allow_flash $allow_pdf $user_flags +$code_tags $katex $replace $multiimage $allow_flash $allow_pdf $user_flags +$assets $locale $anal_filenames $file_board diff --git a/inc/config.php b/inc/config.php index da569b3d..fb749ae4 100644 --- a/inc/config.php +++ b/inc/config.php @@ -839,7 +839,7 @@ // Location of thumbnail to use for spoiler images. $config['spoiler_image'] = 'static/spoiler.png'; // Location of thumbnail to use for deleted images. - // $config['image_deleted'] = 'static/deleted.png'; + $config['image_deleted'] = 'static/deleted.png'; // Location of placeholder image for fileless posts in catalog. $config['no_file_image'] = 'static/no-file.png'; @@ -1784,3 +1784,6 @@ // Allowed HTML tags in ?/edit_pages. $config['allowed_html'] = 'a[href|title],p,br,li,ol,ul,strong,em,u,h2,b,i,tt,div,img[src|alt|title],hr,h1,h2,h3,h4,h5'; + + // Use custom assets? (spoiler file, etc; this is used by ?/settings and ?/assets) + $config['custom_assets'] = false; diff --git a/templates/mod/settings.html b/templates/mod/settings.html index d559c96e..c6b98be0 100644 --- a/templates/mod/settings.html +++ b/templates/mod/settings.html @@ -30,7 +30,8 @@ {% trans %}Country flags{% endtrans %} - {% trans %}/pol/-style user flags{% endtrans %}
Enabling this disables country flags
Make sure to actually upload some first!
+ {% trans %}/pol/-style user flags{% endtrans %}
Enabling this disables country flags
Make sure to actually upload some first on the flags page!
+ {% trans %}Custom board assets{% endtrans %}
Enabling this uses your custom spoiler/deleted/no file images.
Make sure to actually upload some first on the assets page or they will 404!
{% trans %}Forced anonymous{% endtrans %} {% trans %}YouTube/Voocaroo embedding{% endtrans %} {% trans %}Require image for OP{% endtrans %} diff --git a/templates/themes/catalog/theme.php b/templates/themes/catalog/theme.php index 9354b251..69db0119 100644 --- a/templates/themes/catalog/theme.php +++ b/templates/themes/catalog/theme.php @@ -76,10 +76,10 @@ if ($files[0]) { if ($files[0]->file == 'deleted') { - $post['file'] = $config['image_deleted']; + $post['file'] = $config['root'] . $config['image_deleted']; } else if($files[0]->thumb == 'spoiler') { - $post['file'] = '/' . $config['spoiler_image']; + $post['file'] = $config['root'] . $config['spoiler_image']; } else { if ($files[0]->thumb == 'file') {