From a44e0571bca5a872f204e8ff886a3e24d8d84aeb Mon Sep 17 00:00:00 2001 From: Michael Save Date: Thu, 24 Jan 2013 03:24:38 +1100 Subject: [PATCH 1/7] Automatically rotate and mirror images based on EXIF orientation (only compatiable with "convert" option selected at the moment) --- post.php | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/post.php b/post.php index 124e0c65..c5e68578 100644 --- a/post.php +++ b/post.php @@ -421,6 +421,81 @@ if (isset($_POST['delete'])) { error($config['error']['maxsize']); } + // The following code corrects the image orientation based on EXIF. + // Currently only works with the 'convert' option selected but it could easily be expanded to work with the rest if you can be bothered. + if ($config['thumb_method'] == 'convert') { + if ($post['extension'] == 'jpg' || $post['extension'] == 'jpeg') { + $exif = exif_read_data($upload); + if (isset($exif['Orientation'])) { + switch($exif['Orientation']) { + case 1: + // Normal + $args = false; + break; + case 2: + // 888888 + // 88 + // 8888 + // 88 + // 88 + + $args = '-flop'; + break; + case 3: + + // 88 + // 88 + // 8888 + // 88 + // 888888 + + $args = '-flip -flop'; + break; + case 4: + // 88 + // 88 + // 8888 + // 88 + // 888888 + + $args = '-flip'; + break; + case 5: + // 8888888888 + // 88 88 + // 88 + + $args = '-rotate 90 -flop'; + break; + case 6: + // 88 + // 88 88 + // 8888888888 + + $args = '-rotate 90'; + break; + case 7: + // 88 + // 88 88 + // 8888888888 + + $args = '-rotate "-90" -flop'; + break; + case 8: + // 8888888888 + // 88 88 + // 88 + + $args = '-rotate "-90"'; + break; + } + + if ($args) + shell_exec('convert ' . escapeshellarg($upload) . ' ' . $args . ' ' . escapeshellarg($upload)); + } + } + } + // create image object $image = new Image($upload, $post['extension']); From b086e47cfceabda8f96af52113e4441d1719e67a Mon Sep 17 00:00:00 2001 From: Michael Save Date: Thu, 24 Jan 2013 03:37:15 +1100 Subject: [PATCH 2/7] Em dash and en dash mix-up. Issue #88 --- inc/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/functions.php b/inc/functions.php index 2ceb8a5d..8117480f 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -1364,8 +1364,8 @@ function unicodify($body) { // En and em- dashes are rendered exactly the same in // most monospace fonts (they look the same in code // editors). - $body = str_replace('---', '–', $body); // em dash - $body = str_replace('--', '—', $body); // en dash + $body = str_replace('--', '–', $body); // en dash + $body = str_replace('---', '—', $body); // em dash return $body; } From 684b7f84929ac1c714e0dd803b23551f2e2acee4 Mon Sep 17 00:00:00 2001 From: asiekierka Date: Tue, 8 Jan 2013 04:31:09 +0100 Subject: [PATCH 3/7] [EDIT] added dummy page --- inc/mod/pages.php | 12 ++++++++++++ mod.php | 1 + 2 files changed, 13 insertions(+) diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 1c31631c..f0c1b7fc 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -986,6 +986,18 @@ function mod_ban_post($board, $delete, $post, $token = false) { mod_page(_('New ban'), 'mod/ban_form.html', $args); } +function mod_edit_post($board, $post) { + global $config, $mod; + + if (!openBoard($board)) + error($config['error']['noboard']); + + if (!hasPermission($config['mod']['editpost'], $board)) + error($config['error']['noaccess']); + + error("Unimplemented!"); +} + function mod_delete($board, $post) { global $config, $mod; diff --git a/mod.php b/mod.php index d9faf263..49010897 100644 --- a/mod.php +++ b/mod.php @@ -65,6 +65,7 @@ $pages = array( '/(\w+)/deletefile/(\d+)' => 'secure deletefile', // delete file from post '/(\w+)/deletebyip/(\d+)(/global)?' => 'secure deletebyip', // delete all posts by IP address '/(\w+)/(un)?lock/(\d+)' => 'secure lock', // lock thread + '/(\w+)/edit/(\d+)' => 'secure edit_post', // edit post '/(\w+)/(un)?sticky/(\d+)' => 'secure sticky', // sticky thread '/(\w+)/bump(un)?lock/(\d+)' => 'secure bumplock', // "bumplock" thread From 64e06dfcf366d79250a9828e87f760be691bbf23 Mon Sep 17 00:00:00 2001 From: asiekierka Date: Tue, 8 Jan 2013 04:35:22 +0100 Subject: [PATCH 4/7] [EDIT] added dummy form --- inc/mod/pages.php | 6 +++- templates/mod/edit_post_form.html | 55 +++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 templates/mod/edit_post_form.html diff --git a/inc/mod/pages.php b/inc/mod/pages.php index f0c1b7fc..345da133 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -995,7 +995,11 @@ function mod_edit_post($board, $post) { if (!hasPermission($config['mod']['editpost'], $board)) error($config['error']['noaccess']); - error("Unimplemented!"); + // error("Unimplemented!"); + $args = array( + 'test' => 1 + ); + mod_page(_('Edit post'), 'mod/edit_post_form.html', $args); } function mod_delete($board, $post) { diff --git a/templates/mod/edit_post_form.html b/templates/mod/edit_post_form.html new file mode 100644 index 00000000..ac7e207f --- /dev/null +++ b/templates/mod/edit_post_form.html @@ -0,0 +1,55 @@ +
+ + {% if not config.field_disable_name or (mod and post.mod|hasPermission(config.mod.bypass_field_disable, board.uri)) %} + + + {% endif %} + {% if not config.field_disable_email or (mod and post.mod|hasPermission(config.mod.bypass_field_disable, board.uri)) %} + + + {% endif %} + + + + + + + + + + + + +
+ {% trans %}Name{% endtrans %} + + +
+ {% trans %}Email{% endtrans %} + + +
+ {% trans %}Subject{% endtrans %} + + +
+ {% trans %}Comment{% endtrans %} + + +
+ {% trans %}Flags{% endtrans %} + + {% if not id and post.mod|hasPermission(config.mod.sticky, board.uri) %}
+ +
+
{% endif %} + {% if not id and post.mod|hasPermission(config.mod.lock, board.uri) %}
+
+ +
{% endif %} + {% if post.mod|hasPermission(config.mod.rawhtml, board.uri) %}
+
+ +
{% endif %} +
+
From c7c5a65a1f0c68cdbdafb464f6488c8f358115a4 Mon Sep 17 00:00:00 2001 From: asiekierka Date: Tue, 8 Jan 2013 07:52:13 +0100 Subject: [PATCH 5/7] [EDIT] basic edit support --- inc/config.php | 2 +- inc/mod/pages.php | 37 ++++++++++++++++++++++++++----- templates/mod/edit_post_form.html | 35 +++++++++-------------------- 3 files changed, 43 insertions(+), 31 deletions(-) diff --git a/inc/config.php b/inc/config.php index 9e1147d7..de09ee45 100644 --- a/inc/config.php +++ b/inc/config.php @@ -921,7 +921,7 @@ // View whether a thread has been bumplocked ("-1" to allow non-mods to see too) $config['mod']['view_bumplock'] = MOD; // Edit posts (EXPERIMENTAL) - $config['mod']['editpost'] = DISABLED; + $config['mod']['editpost'] = MOD; // "Move" a thread to another board (EXPERIMENTAL; has some known bugs) $config['mod']['move'] = DISABLED; // Bypass "field_disable_*" (forced anonymity, etc.) diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 345da133..4384412b 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -995,11 +995,38 @@ function mod_edit_post($board, $post) { if (!hasPermission($config['mod']['editpost'], $board)) error($config['error']['noaccess']); - // error("Unimplemented!"); - $args = array( - 'test' => 1 - ); - mod_page(_('Edit post'), 'mod/edit_post_form.html', $args); + $security_token = make_secure_link_token($board . '/ban/' . $post); + + $query = prepare(sprintf('SELECT * FROM `posts_%s` WHERE `id` = :id', $board)); + $query->bindValue(':id', $post); + $query->execute() or error(db_error($query)); + + if (!$_post = $query->fetch(PDO::FETCH_ASSOC)) + error($config['error']['404']); + + if(isset($_POST['mode']) && $_POST['mode'] == "edit") + { + $query = prepare(sprintf("UPDATE `posts_%s` SET `name` = :name,`email` = :email,`subject` = :subject,`body` = :body WHERE `id` = :id",$board)); + $query->bindValue(':id', $post); + $query->bindValue('name', $_POST['name']); + $query->bindValue(':email', $_POST['email']); + $query->bindValue(':subject', $_POST['subject']); + $query->bindValue(':body', $_POST['body']); + $query->execute() or error(db_error($query)); + + header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); + } else { + $args = array( + 'token' => $security_token, + 'name' => $_post['name'], + 'email' => $_post['email'], + 'subject' => $_post['subject'], + 'body' => $_post['body'], + 'mode' => "edit" + ); + + mod_page(_('Edit post'), 'mod/edit_post_form.html', $args); + } } function mod_delete($board, $post) { diff --git a/templates/mod/edit_post_form.html b/templates/mod/edit_post_form.html index ac7e207f..6748435e 100644 --- a/templates/mod/edit_post_form.html +++ b/templates/mod/edit_post_form.html @@ -1,27 +1,27 @@
- {% if not config.field_disable_name or (mod and post.mod|hasPermission(config.mod.bypass_field_disable, board.uri)) %} + - {% endif %} - {% if not config.field_disable_email or (mod and post.mod|hasPermission(config.mod.bypass_field_disable, board.uri)) %} + + - {% endif %} + @@ -29,27 +29,12 @@ {% trans %}Comment{% endtrans %} - - + +
{% trans %}Name{% endtrans %} - +
{% trans %}Email{% endtrans %} - +
{% trans %}Subject{% endtrans %} - +
- +
- {% trans %}Flags{% endtrans %} - - {% if not id and post.mod|hasPermission(config.mod.sticky, board.uri) %}
- -
-
{% endif %} - {% if not id and post.mod|hasPermission(config.mod.lock, board.uri) %}
-
- -
{% endif %} - {% if post.mod|hasPermission(config.mod.rawhtml, board.uri) %}
-
- -
{% endif %} -
From bceb314ce6f53247a307cf2d452238fd96d24d07 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Thu, 24 Jan 2013 04:16:09 +1100 Subject: [PATCH 6/7] Major fixes and clean-up for edit form --- inc/config.php | 4 ++-- inc/mod/pages.php | 36 ++++++++++++++----------------- mod.php | 2 +- templates/mod/edit_post_form.html | 17 +++++++-------- 4 files changed, 27 insertions(+), 32 deletions(-) diff --git a/inc/config.php b/inc/config.php index de09ee45..15deaeae 100644 --- a/inc/config.php +++ b/inc/config.php @@ -920,8 +920,8 @@ $config['mod']['bumplock'] = MOD; // View whether a thread has been bumplocked ("-1" to allow non-mods to see too) $config['mod']['view_bumplock'] = MOD; - // Edit posts (EXPERIMENTAL) - $config['mod']['editpost'] = MOD; + // Edit posts + $config['mod']['editpost'] = ADMIN; // "Move" a thread to another board (EXPERIMENTAL; has some known bugs) $config['mod']['move'] = DISABLED; // Bypass "field_disable_*" (forced anonymity, etc.) diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 4384412b..1a55ec7d 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -986,7 +986,7 @@ function mod_ban_post($board, $delete, $post, $token = false) { mod_page(_('New ban'), 'mod/ban_form.html', $args); } -function mod_edit_post($board, $post) { +function mod_edit_post($board, $postID) { global $config, $mod; if (!openBoard($board)) @@ -995,37 +995,33 @@ function mod_edit_post($board, $post) { if (!hasPermission($config['mod']['editpost'], $board)) error($config['error']['noaccess']); - $security_token = make_secure_link_token($board . '/ban/' . $post); + $security_token = make_secure_link_token($board . '/edit/' . $postID); $query = prepare(sprintf('SELECT * FROM `posts_%s` WHERE `id` = :id', $board)); - $query->bindValue(':id', $post); + $query->bindValue(':id', $postID); $query->execute() or error(db_error($query)); - if (!$_post = $query->fetch(PDO::FETCH_ASSOC)) + if (!$post = $query->fetch(PDO::FETCH_ASSOC)) error($config['error']['404']); - if(isset($_POST['mode']) && $_POST['mode'] == "edit") - { - $query = prepare(sprintf("UPDATE `posts_%s` SET `name` = :name,`email` = :email,`subject` = :subject,`body` = :body WHERE `id` = :id",$board)); - $query->bindValue(':id', $post); + if (isset($_POST['name'], $_POST['email'], $_POST['subject'], $_POST['body'])) { + $query = prepare(sprintf('UPDATE `posts_%s` SET `name` = :name, `email` = :email, `subject` = :subject, `body_nomarkup` = :body WHERE `id` = :id', $board)); + $query->bindValue(':id', $postID); $query->bindValue('name', $_POST['name']); $query->bindValue(':email', $_POST['email']); $query->bindValue(':subject', $_POST['subject']); $query->bindValue(':body', $_POST['body']); $query->execute() or error(db_error($query)); - - header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); + + rebuildPost($postID); + buildIndex(); + + header('Location: ?/' . sprintf($config['board_path'], $board) . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $postID) . '#' . $postID, true, $config['redirect_http']); } else { - $args = array( - 'token' => $security_token, - 'name' => $_post['name'], - 'email' => $_post['email'], - 'subject' => $_post['subject'], - 'body' => $_post['body'], - 'mode' => "edit" - ); - - mod_page(_('Edit post'), 'mod/edit_post_form.html', $args); + if ($config['minify_html']) + $post['body_nomarkup'] = str_replace("\n", ' ', $post['body_nomarkup']); + + mod_page(_('Edit post'), 'mod/edit_post_form.html', array('token' => $security_token, 'post' => $post)); } } diff --git a/mod.php b/mod.php index 49010897..7017dd05 100644 --- a/mod.php +++ b/mod.php @@ -61,11 +61,11 @@ $pages = array( '/ban' => 'secure_POST ban', // new ban '/(\w+)/ban(&delete)?/(\d+)' => 'secure_POST ban_post', // ban poster '/(\w+)/move/(\d+)' => 'secure_POST move', // move thread + '/(\w+)/edit/(\d+)' => 'secure_POST edit_post', // edit post '/(\w+)/delete/(\d+)' => 'secure delete', // delete post '/(\w+)/deletefile/(\d+)' => 'secure deletefile', // delete file from post '/(\w+)/deletebyip/(\d+)(/global)?' => 'secure deletebyip', // delete all posts by IP address '/(\w+)/(un)?lock/(\d+)' => 'secure lock', // lock thread - '/(\w+)/edit/(\d+)' => 'secure edit_post', // edit post '/(\w+)/(un)?sticky/(\d+)' => 'secure sticky', // sticky thread '/(\w+)/bump(un)?lock/(\d+)' => 'secure bumplock', // "bumplock" thread diff --git a/templates/mod/edit_post_form.html b/templates/mod/edit_post_form.html index 6748435e..22fa40cb 100644 --- a/templates/mod/edit_post_form.html +++ b/templates/mod/edit_post_form.html @@ -1,11 +1,13 @@ -
+ + + @@ -13,7 +15,7 @@ {% trans %}Email{% endtrans %} @@ -21,7 +23,8 @@ {% trans %}Subject{% endtrans %} @@ -29,12 +32,8 @@ {% trans %}Comment{% endtrans %} - - - -
{% trans %}Name{% endtrans %} - +
- +
- + +
- +
From 85578b7105f7b53e0f45fc886270540b9d07b2f3 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Thu, 24 Jan 2013 04:56:06 +1100 Subject: [PATCH 7/7] Bugfix: Anti-bot check not allowing posting from second page --- inc/anti-bot.php | 4 ++++ inc/functions.php | 9 ++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/inc/anti-bot.php b/inc/anti-bot.php index 554bb844..bf29b3cb 100644 --- a/inc/anti-bot.php +++ b/inc/anti-bot.php @@ -152,6 +152,10 @@ class AntiBot { return $html; } + public function reset() { + $this->index = 0; + } + public function hash() { global $config; diff --git a/inc/functions.php b/inc/functions.php index 8117480f..c597f1b1 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -1213,18 +1213,17 @@ function buildIndex() { $page = 1; while ($page <= $config['max_pages'] && $content = index($page)) { - $filename = $board['dir'] . ($page==1 ? $config['file_index'] : sprintf($config['file_page'], $page)); - if (file_exists($filename)) $md5 = md5_file($filename); + $filename = $board['dir'] . ($page == 1 ? $config['file_index'] : sprintf($config['file_page'], $page)); + + $antibot->reset(); $content['pages'] = $pages; $content['pages'][$page-1]['selected'] = true; $content['btn'] = getPageButtons($content['pages']); $content['antibot'] = $antibot; + file_write($filename, Element('index.html', $content)); - if (isset($md5) && $md5 == md5_file($filename)) { - break; - } $page++; } if ($page < $config['max_pages']) {