From fe60590d192cebfdcd3f8e9cf0c687aea881577e Mon Sep 17 00:00:00 2001 From: kaf Date: Sat, 27 Sep 2014 16:21:54 +0000 Subject: Check spoiler_image size before ussuming it is 128×128px MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/mod/pages.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'inc/mod/pages.php') diff --git a/inc/mod/pages.php b/inc/mod/pages.php index c21086ed..36dec7bb 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -1567,10 +1567,12 @@ function mod_spoiler_image($board, $post, $file) { $result = $query->fetch(PDO::FETCH_ASSOC); $files = json_decode($result['files']); + + $size_spoiler_image = @getimagesize($config['spoiler_image']); file_unlink($board . '/' . $config['dir']['thumb'] . $files[$file]->thumb); $files[$file]->thumb = 'spoiler'; - $files[$file]->thumbheight = 128; - $files[$file]->thumbwidth = 128; + $files[$file]->thumbwidth = $size_spoiler[0]; + $files[$file]->thumbheight = $size_spoiler_image[1]; // Make thumbnail spoiler $query = prepare(sprintf("UPDATE ``posts_%s`` SET `files` = :files WHERE `id` = :id", $board)); -- cgit v1.3 From c4dc3f4d477b49a402e5300cdbf72e51e1665b39 Mon Sep 17 00:00:00 2001 From: 8chan Date: Mon, 6 Oct 2014 18:02:50 -0700 Subject: Fix spoiler image not working --- inc/mod/pages.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/mod/pages.php') diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 36dec7bb..ab2fb2d3 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -1571,7 +1571,7 @@ function mod_spoiler_image($board, $post, $file) { $size_spoiler_image = @getimagesize($config['spoiler_image']); file_unlink($board . '/' . $config['dir']['thumb'] . $files[$file]->thumb); $files[$file]->thumb = 'spoiler'; - $files[$file]->thumbwidth = $size_spoiler[0]; + $files[$file]->thumbwidth = $size_spoiler_image[0]; $files[$file]->thumbheight = $size_spoiler_image[1]; // Make thumbnail spoiler -- cgit v1.3 From 9b3fa77719642acd13a2ae6f29087dffcb261f4d Mon Sep 17 00:00:00 2001 From: czaks Date: Wed, 8 Oct 2014 23:23:59 +0200 Subject: new banlist implementation; also includes a public banlist --- inc/bans.php | 90 ++++++++++++----- inc/mod/pages.php | 42 ++++---- js/local-time.js | 10 -- js/mod/ban-list.js | 157 ++++++++++++++++++++++++++++++ mod.php | 2 +- templates/main.js | 47 +++++++++ templates/mod/ban_list.html | 137 +++++++------------------- templates/themes/public_banlist/info.php | 33 +++++++ templates/themes/public_banlist/theme.php | 56 +++++++++++ templates/themes/ukko/theme.php | 6 +- 10 files changed, 424 insertions(+), 156 deletions(-) create mode 100644 js/mod/ban-list.js create mode 100644 templates/themes/public_banlist/info.php create mode 100644 templates/themes/public_banlist/theme.php (limited to 'inc/mod/pages.php') diff --git a/inc/bans.php b/inc/bans.php index ed81c6e4..154094e5 100644 --- a/inc/bans.php +++ b/inc/bans.php @@ -148,49 +148,86 @@ class Bans { return $ban_list; } - - static public function list_all($offset = 0, $limit = 9001) { - $offset = (int)$offset; - $limit = (int)$limit; - + + static public function stream_json($out = false, $filter_ips = false, $filter_staff = false, $board_access = false) { $query = query("SELECT ``bans``.*, `username` FROM ``bans`` LEFT JOIN ``mods`` ON ``mods``.`id` = `creator` - ORDER BY `created` DESC LIMIT $offset, $limit") or error(db_error()); - $bans = $query->fetchAll(PDO::FETCH_ASSOC); - - foreach ($bans as &$ban) { - $ban['mask'] = self::range_to_string(array($ban['ipstart'], $ban['ipend'])); - } - - return $bans; - } - - static public function count($board = false) { - if (!$board) { - $query = prepare("SELECT COUNT(*) FROM ``bans``"); - } else { - $query = prepare("SELECT COUNT(*) FROM ``bans`` WHERE `board` = :board"); + ORDER BY `created` DESC") or error(db_error()); + $bans = $query->fetchAll(PDO::FETCH_ASSOC); + + if ($board_access && $board_access[0] == '*') $board_access = false; + + $out ? fputs($out, "[") : print("["); + + $end = end($bans); + + foreach ($bans as &$ban) { + $ban['mask'] = self::range_to_string(array($ban['ipstart'], $ban['ipend'])); + + if ($ban['post']) { + $post = json_decode($ban['post']); + $ban['message'] = $post->body; + } + unset($ban['ipstart'], $ban['ipend'], $ban['post'], $ban['creator']); + + if ($board_access === false || in_array ($ban['board'], $board_access)) { + $ban['access'] = true; + } + + if (filter_var($ban['mask'], FILTER_VALIDATE_IP) !== false) { + $ban['single_addr'] = true; + } + if ($filter_staff || ($board_access !== false && !in_array($ban['board'], $board_access))) { + $ban['username'] = '?'; + } + if ($filter_ips || ($board_access !== false && !in_array($ban['board'], $board_access))) { + list($ban['mask'], $subnet) = explode("/", $ban['mask']); + $ban['mask'] = preg_split("/[\.:]/", $ban['mask']); + $ban['mask'] = array_slice($ban['mask'], 0, 2); + $ban['mask'] = implode(".", $ban['mask']); + $ban['mask'] .= ".*"; + if (isset ($subnet)) { + $ban['mask'] .= "/$subnet"; + } + $ban['masked'] = true; + } + + $json = json_encode($ban); + $out ? fputs($out, $json) : print($json); + + if ($ban['id'] != $end['id']) { + $out ? fputs($out, ",") : print(","); + } } - $query->bindValue(':board', $board); - $query->execute() or error(db_error()); - return (int)$query->fetchColumn(); + + $out ? fputs($out, "]") : print("]"); + } static public function seen($ban_id) { $query = query("UPDATE ``bans`` SET `seen` = 1 WHERE `id` = " . (int)$ban_id) or error(db_error()); + rebuildThemes('bans'); } static public function purge() { $query = query("DELETE FROM ``bans`` WHERE `expires` IS NOT NULL AND `expires` < " . time() . " AND `seen` = 1") or error(db_error()); + rebuildThemes('bans'); } - static public function delete($ban_id, $modlog = false) { + static public function delete($ban_id, $modlog = false, $boards = false, $dont_rebuild = false) { + global $config; + + if ($boards && $boards[0] == '*') $boards = false; + if ($modlog) { $query = query("SELECT `ipstart`, `ipend` FROM ``bans`` WHERE `id` = " . (int)$ban_id) or error(db_error()); if (!$ban = $query->fetch(PDO::FETCH_ASSOC)) { // Ban doesn't exist return false; } + + if ($boards !== false && !in_array($ban['board'], $boards)) + error($config['error']['noaccess']); $mask = self::range_to_string(array($ban['ipstart'], $ban['ipend'])); @@ -199,6 +236,8 @@ class Bans { } query("DELETE FROM ``bans`` WHERE `id` = " . (int)$ban_id) or error(db_error()); + + if (!$dont_rebuild) rebuildThemes('bans'); return true; } @@ -265,6 +304,9 @@ class Bans { ' (#' . $pdo->lastInsertId() . ')' . ' with ' . ($reason ? 'reason: ' . utf8tohtml($reason) . '' : 'no reason')); } + + rebuildThemes('bans'); + return $pdo->lastInsertId(); } } diff --git a/inc/mod/pages.php b/inc/mod/pages.php index ab2fb2d3..c7722763 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -766,7 +766,7 @@ function mod_page_ip($ip) { if (!hasPermission($config['mod']['unban'])) error($config['error']['noaccess']); - Bans::delete($_POST['ban_id'], true); + Bans::delete($_POST['ban_id'], true, $mod['boards']); header('Location: ?/IP/' . $ip . '#bans', true, $config['redirect_http']); return; @@ -863,18 +863,16 @@ function mod_ban() { require_once 'inc/mod/ban.php'; Bans::new_ban($_POST['ip'], $_POST['reason'], $_POST['length'], $_POST['board'] == '*' ? false : $_POST['board']); - + if (isset($_POST['redirect'])) header('Location: ' . $_POST['redirect'], true, $config['redirect_http']); else header('Location: ?/', true, $config['redirect_http']); } -function mod_bans($page_no = 1) { +function mod_bans() { global $config; - - if ($page_no < 1) - error($config['error']['404']); + global $mod; if (!hasPermission($config['mod']['view_banlist'])) error($config['error']['noaccess']); @@ -892,29 +890,33 @@ function mod_bans($page_no = 1) { error(sprintf($config['error']['toomanyunban'], $config['mod']['unban_limit'], count($unban))); foreach ($unban as $id) { - Bans::delete($id, true); + Bans::delete($id, true, $mod['boards'], true); } + rebuildThemes('bans'); header('Location: ?/bans', true, $config['redirect_http']); return; } - $bans = Bans::list_all(($page_no - 1) * $config['mod']['banlist_page'], $config['mod']['banlist_page']); - - if (empty($bans) && $page_no > 1) - error($config['error']['404']); - - foreach ($bans as &$ban) { - if (filter_var($ban['mask'], FILTER_VALIDATE_IP) !== false) - $ban['single_addr'] = true; - } - mod_page(_('Ban list'), 'mod/ban_list.html', array( - 'bans' => $bans, - 'count' => Bans::count(), - 'token' => make_secure_link_token('bans') + 'mod' => $mod, + 'boards' => json_encode($mod['boards']), + 'token' => make_secure_link_token('bans'), + 'token_json' => make_secure_link_token('bans.json') )); } +function mod_bans_json() { + global $config, $mod; + + if (!hasPermission($config['mod']['ban'])) + error($config['error']['noaccess']); + + // Compress the json for faster loads + if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); + + Bans::stream_json(false, false, !hasPermission($config['mod']['view_banstaff']), $mod['boards']); +} + function mod_ban_appeals() { global $config, $board; diff --git a/js/local-time.js b/js/local-time.js index e6b3495d..a4e25d6d 100644 --- a/js/local-time.js +++ b/js/local-time.js @@ -25,16 +25,6 @@ onready(function(){ return [Math.pow(10, count - num.toString().length), num].join('').substr(1); }; - var datelocale = - { days: [_('Sunday'), _('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday')] - , shortDays: [_("Sun"), _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat")] - , months: [_('January'), _('February'), _('March'), _('April'), _('May'), _('June'), _('July'), _('August'), _('September'), _('October'), _('November'), _('December')] - , shortMonths: [_('Jan'), _('Feb'), _('Mar'), _('Apr'), _('May'), _('Jun'), _('Jul'), _('Aug'), _('Sep'), _('Oct'), _('Nov'), _('Dec')] - , AM: _('AM') - , PM: _('PM') - , am: _('am') - , pm: _('pm') - }; var dateformat = (typeof strftime === 'undefined') ? function(t) { return zeropad(t.getMonth() + 1, 2) + "/" + zeropad(t.getDate(), 2) + "/" + t.getFullYear().toString().substring(2) + " (" + [_("Sun"), _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun")][t.getDay()] + ") " + diff --git a/js/mod/ban-list.js b/js/mod/ban-list.js new file mode 100644 index 00000000..30529044 --- /dev/null +++ b/js/mod/ban-list.js @@ -0,0 +1,157 @@ +var banlist_init = function(token, my_boards, inMod) { + inMod = !inMod; + + var lt; + + var selected = {}; + + var time = function() { return Date.now()/1000|0; } + + $.getJSON(inMod ? ("?/bans.json/"+token) : token, function(t) { + $("#banlist").on("new-row", function(e, drow, el) { + var sel = selected[drow.id]; + if (sel) { + $(el).find('input.unban').prop("checked", true); + } + $(el).find('input.unban').on("click", function() { + selected[drow.id] = $(this).prop("checked"); + }); + + + if (drow.expires && drow.expires != 0 && drow.expires < time()) { + $(el).find("td").css("text-decoration", "line-through"); + } + }); + + var selall = ""; + + lt = $("#banlist").longtable({ + mask: {name: selall+_("IP address"), width: "220px", fmt: function(f) { + var pre = ""; + if (inMod && f.access) { + pre = ""; + } + + if (inMod && f.single_addr && !f.masked) { + return pre+""+f.mask+""; + } + return pre+f.mask; + } }, + reason: {name: _("Reason"), width: "calc(100% - 715px - 6 * 4px)", fmt: function(f) { + var add = "", suf = ''; + if (f.seen == 1) add += ""; + if (f.message) { + add += ""; + suf = "

"+_("Message:")+"
"+f.message; + } + + if (add) { add = "
"+add+"
"; } + + if (f.reason) return add + f.reason + suf; + else return add + "-" + suf; + } }, + board: {name: _("Board"), width: "60px", fmt: function(f) { + if (f.board) return "/"+f.board+"/"; + else return ""+_("all")+""; + } }, + created: {name: _("Set"), width: "100px", fmt: function(f) { + return ago(f.created) + _(" ago"); // in AGO form + } }, + // duration? + expires: {name: _("Expires"), width: "235px", fmt: function(f) { + if (!f.expires || f.expires == 0) return ""+_("never")+""; + return strftime(window.post_date, new Date((f.expires|0)*1000), datelocale) + + ((f.expires < time()) ? "" : " "+_("in ")+until(f.expires|0)+""); + } }, + username: {name: _("Staff"), width: "100px", fmt: function(f) { + var pre='',suf='',un=f.username; + if (inMod && f.username && f.username != '?') { + pre = ""; + suf = ""; + } + if (!f.username) { + un = ""+_("system")+""; + } + return pre + un + suf; + } } + }, {}, t); + + $("#select-all").click(function(e) { + var $this = $(this); + $("input.unban").prop("checked", $this.prop("checked")); + lt.get_data().forEach(function(v) { v.access && (selected[v.id] = $this.prop("checked")); }); + e.stopPropagation(); + }); + + var filter = function(e) { + if ($("#only_mine").prop("checked") && ($.inArray(e.board, my_boards) === -1)) return false; + if ($("#only_not_expired").prop("checked") && e.expires && e.expires != 0 && e.expires < time()) return false; + if ($("#search").val()) { + var terms = $("#search").val().split(" "); + + var fields = ["mask", "reason", "board", "staff", "message"]; + + var ret_false = false; + terms.forEach(function(t) { + var fs = fields; + + var re = /^(mask|reason|board|staff|message):/, ma; + if (ma = t.match(re)) { + fs = [ma[1]]; + t = t.replace(re, ""); + } + + var found = false + fs.forEach(function(f) { + if (e[f] && e[f].indexOf(t) !== -1) { + found = true; + } + }); + if (!found) ret_false = true; + }); + + if (ret_false) return false; + } + + return true; + }; + + $("#only_mine, #only_not_expired, #search").on("click input", function() { + lt.set_filter(filter); + }); + lt.set_filter(filter); + + $(".banform").on("submit", function() { return false; }); + + $("#unban").on("click", function() { + $(".banform .hiddens").remove(); + $("").appendTo(".banform"); + + $.each(selected, function(e) { + $("").appendTo(".banform"); + }); + + $(".banform").off("submit").submit(); + }); + + if (device_type == 'desktop') { + // Stick topbar + var stick_on = $(".banlist-opts").offset().top; + var state = true; + $(window).on("scroll resize", function() { + if ($(window).scrollTop() > stick_on && state == true) { + $("body").css("margin-top", $(".banlist-opts").height()); + $(".banlist-opts").addClass("boardlist top").detach().prependTo("body"); + $("#banlist tr:not(.row)").addClass("tblhead").detach().appendTo(".banlist-opts"); + state = !state; + } + else if ($(window).scrollTop() < stick_on && state == false) { + $("body").css("margin-top", "auto"); + $(".banlist-opts").removeClass("boardlist top").detach().prependTo(".banform"); + $(".tblhead").detach().prependTo("#banlist"); + state = !state; + } + }); + } + }); +} diff --git a/mod.php b/mod.php index 5428e84d..384eec88 100644 --- a/mod.php +++ b/mod.php @@ -62,7 +62,7 @@ $pages = array( '/ban' => 'secure_POST ban', // new ban '/bans' => 'secure_POST bans', // ban list - '/bans/(\d+)' => 'secure_POST bans', // ban list + '/bans.json' => 'secure bans_json', // ban list JSON '/ban-appeals' => 'secure_POST ban_appeals', // view ban appeals '/recent/(\d+)' => 'recent_posts', // view recent posts diff --git a/templates/main.js b/templates/main.js index 52f38e69..ed25f7d9 100644 --- a/templates/main.js +++ b/templates/main.js @@ -22,6 +22,53 @@ function fmt(s,a) { return s.replace(/\{([0-9]+)\}/g, function(x) { return a[x[1]]; }); } +function until($timestamp) { + var $difference = $timestamp - Date.now()/1000|0, $num; + switch(true){ + case ($difference < 60): + return "" + $difference + ' ' + _('second(s)'); + case ($difference < 3600): //60*60 = 3600 + return "" + ($num = Math.round($difference/(60))) + ' ' + _('minute(s)'); + case ($difference < 86400): //60*60*24 = 86400 + return "" + ($num = Math.round($difference/(3600))) + ' ' + _('hour(s)'); + case ($difference < 604800): //60*60*24*7 = 604800 + return "" + ($num = Math.round($difference/(86400))) + ' ' + _('day(s)'); + case ($difference < 31536000): //60*60*24*365 = 31536000 + return "" + ($num = Math.round($difference/(604800))) + ' ' + _('week(s)'); + default: + return "" + ($num = Math.round($difference/(31536000))) + ' ' + _('year(s)'); + } +} + +function ago($timestamp) { + var $difference = (Date.now()/1000|0) - $timestamp, $num; + switch(true){ + case ($difference < 60) : + return "" + $difference + ' ' + _('second(s)'); + case ($difference < 3600): //60*60 = 3600 + return "" + ($num = Math.round($difference/(60))) + ' ' + _('minute(s)'); + case ($difference < 86400): //60*60*24 = 86400 + return "" + ($num = Math.round($difference/(3600))) + ' ' + _('hour(s)'); + case ($difference < 604800): //60*60*24*7 = 604800 + return "" + ($num = Math.round($difference/(86400))) + ' ' + _('day(s)'); + case ($difference < 31536000): //60*60*24*365 = 31536000 + return "" + ($num = Math.round($difference/(604800))) + ' ' + _('week(s)'); + default: + return "" + ($num = Math.round($difference/(31536000))) + ' ' + _('year(s)'); + } +} + +var datelocale = + { days: [_('Sunday'), _('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday')] + , shortDays: [_("Sun"), _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat")] + , months: [_('January'), _('February'), _('March'), _('April'), _('May'), _('June'), _('July'), _('August'), _('September'), _('October'), _('November'), _('December')] + , shortMonths: [_('Jan'), _('Feb'), _('Mar'), _('Apr'), _('May'), _('Jun'), _('Jul'), _('Aug'), _('Sep'), _('Oct'), _('Nov'), _('Dec')] + , AM: _('AM') + , PM: _('PM') + , am: _('am') + , pm: _('pm') + }; + var saved = {}; diff --git a/templates/mod/ban_list.html b/templates/mod/ban_list.html index 97c02029..0c67f269 100644 --- a/templates/mod/ban_list.html +++ b/templates/mod/ban_list.html @@ -1,104 +1,41 @@ -{% if bans|count == 0 %} -

({% trans 'There are no active bans.' %})

-{% else %} -
- - - - - - - - - - - - - {% for ban in bans %} - - - - - - - - - - - {% endfor %} + + + + + + + + + + + {% if token %} + + {% endif %} +
+
+ {% if mod and mod.boards[0] != '*' %} + + {% endif %} + +
+
+ + {% if mod %} + + {% endif %} +
+ +
+
+ +
{% trans 'IP address/mask' %}{% trans 'Reason' %}{% trans 'Board' %}{% trans 'Set' %}{% trans 'Duration' %}{% trans 'Expires' %}{% trans 'Seen' %}{% trans 'Staff' %}
- - {% if ban.single_addr %} - {{ ban.mask }} - {% else %} - {{ ban.mask }} - {% endif %} - - {% if ban.reason %} - {{ ban.reason }} - {% else %} - - - {% endif %} - - {% if ban.board %} - {{ config.board_abbreviation|sprintf(ban.board) }} - {% else %} - {% trans 'all boards' %} - {% endif %} - - - {{ ban.created|ago }} ago - - - {% if ban.expires == 0 %} - - - {% else %} - {{ (ban.expires - ban.created + time()) | until }} - {% endif %} - - {% if ban.expires == 0 %} - {% trans 'never' %} - {% else %} - {{ ban.expires|date(config.post_date) }} - {% if ban.expires > time() %} - (in {{ ban.expires|until }}) - {% endif %} - {% endif %} - - {% if ban.seen %} - {% trans 'Yes' %} - {% else %} - {% trans 'No' %} - {% endif %} - - {% if ban.username %} - {% if mod|hasPermission(config.mod.view_banstaff) %} - {{ ban.username|e }} - {% else %} - {% if mod|hasPermission(config.mod.view_banquestionmark) %} - ? - {% else %} - - {% endif %} - {% endif %} - {% elseif ban.creator == -1 %} - system - {% else %} - {% trans 'deleted?' %} - {% endif %} -
+ + -

- -

+{% if token_json %} + +{% else %} + {% endif %} - -{% if count > bans|count %} -

- {% for i in range(0, (count - 1) / config.mod.modlog_page) %} - [{{ i + 1 }}] - {% endfor %} -

-{% endif %} - diff --git a/templates/themes/public_banlist/info.php b/templates/themes/public_banlist/info.php new file mode 100644 index 00000000..006ac38e --- /dev/null +++ b/templates/themes/public_banlist/info.php @@ -0,0 +1,33 @@ + 'JSON feed file', + 'name' => 'file_json', + 'type' => 'text', + 'default' => 'bans.json', + 'comment' => '(eg. "bans.json")' + ); + + $theme['config'][] = Array( + 'title' => 'Main HTML file', + 'name' => 'file_bans', + 'type' => 'text', + 'default' => 'bans.html', + 'comment' => '(eg. "bans.html")' + ); + + // Unique function name for building everything + $theme['build_function'] = 'pbanlist_build'; +?> diff --git a/templates/themes/public_banlist/theme.php b/templates/themes/public_banlist/theme.php new file mode 100644 index 00000000..b64b8d9e --- /dev/null +++ b/templates/themes/public_banlist/theme.php @@ -0,0 +1,56 @@ + $config, + 'mod' => false, + 'hide_dashboard_link' => true, + 'title' => _("Ban list"), + 'subtitle' => "", + 'nojavascript' => true, + 'body' => Element('mod/ban_list.html', array( + 'mod' => false, + 'boards' => "[]", + 'token' => false, + 'token_json' => false, + 'uri_json' => $config['dir']['home'] . $settings['file_json'], + )) + )); + } + }; + +?> diff --git a/templates/themes/ukko/theme.php b/templates/themes/ukko/theme.php index b2624ed7..058fc77b 100644 --- a/templates/themes/ukko/theme.php +++ b/templates/themes/ukko/theme.php @@ -4,7 +4,11 @@ function ukko_build($action, $settings) { $ukko = new ukko(); $ukko->settings = $settings; - + + if (! ($action == 'all' || $action == 'post' || $action == 'post-thread' || $action == 'post-delete')) { + return; + } + file_write($settings['uri'] . '/index.html', $ukko->build()); file_write($settings['uri'] . '/ukko.js', Element('themes/ukko/ukko.js', array())); } -- cgit v1.3 From bdb6001f3f7e93e0b9655c0491bbef6f1df8a5fa Mon Sep 17 00:00:00 2001 From: czaks Date: Tue, 10 Mar 2015 12:48:59 +0100 Subject: support for slugified links; may introduce a few bugs --- inc/config.php | 7 +- inc/display.php | 4 +- inc/functions.php | 92 +++++++++++++++++++++++-- inc/lib/Twig/Extensions/Extension/Tinyboard.php | 3 +- inc/mod/pages.php | 18 ++--- install.php | 6 +- mod.php | 5 ++ post.php | 19 +++-- templates/main.js | 1 + templates/mod/debug/recent_posts.html | 2 +- templates/mod/search_results.html | 4 +- templates/post_reply.html | 4 +- templates/post_thread.html | 10 +-- templates/posts.sql | 1 + templates/themes/catalog/theme.php | 2 +- templates/themes/recent/theme.php | 4 +- templates/themes/sitemap/sitemap.xml | 4 +- templates/themes/sitemap/theme.php | 2 +- 18 files changed, 145 insertions(+), 43 deletions(-) (limited to 'inc/mod/pages.php') diff --git a/inc/config.php b/inc/config.php index edbe7b2a..ac4acaa4 100644 --- a/inc/config.php +++ b/inc/config.php @@ -566,6 +566,9 @@ // Allow dice rolling: an email field of the form "dice XdY+/-Z" will result in X Y-sided dice rolled and summed, // with the modifier Z added, with the result displayed at the top of the post body. $config['allow_roll'] = false; + + // Use semantic URLs for threads, like /b/res/12345/daily-programming-thread.html + $config['slugify'] = false; /* * ==================== @@ -1118,8 +1121,10 @@ // Location of files. $config['file_index'] = 'index.html'; - $config['file_page'] = '%d.html'; + $config['file_page'] = '%d.html'; // NB: page is both an index page and a thread $config['file_page50'] = '%d+50.html'; + $config['file_page_slug'] = '%d-%s.html'; + $config['file_page50_slug'] = '%d-%s+50.html'; $config['file_mod'] = 'mod.php'; $config['file_post'] = 'post.php'; $config['file_script'] = 'main.js'; diff --git a/inc/display.php b/inc/display.php index 1a78e19b..65525ab9 100644 --- a/inc/display.php +++ b/inc/display.php @@ -383,7 +383,7 @@ class Post { public function link($pre = '', $page = false) { global $config, $board; - return $this->root . $board['dir'] . $config['dir']['res'] . sprintf(($page ? $page : $config['file_page']), $this->thread) . '#' . $pre . $this->id; + return $this->root . $board['dir'] . $config['dir']['res'] . link_for((array)$this, $page == '50') . '#' . $pre . $this->id; } public function build($index=false) { @@ -438,7 +438,7 @@ class Thread { public function link($pre = '', $page = false) { global $config, $board; - return $this->root . $board['dir'] . $config['dir']['res'] . sprintf(($page ? $page : $config['file_page']), $this->id) . '#' . $pre . $this->id; + return $this->root . $board['dir'] . $config['dir']['res'] . link_for((array)$this, $page == '50') . '#' . $pre . $this->id; } public function add(Post $post) { $this->posts[] = $post; diff --git a/inc/functions.php b/inc/functions.php index 25362a62..79d06f5c 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -150,7 +150,9 @@ function loadConfig() { preg_quote($config['dir']['res'], '/') . '(' . str_replace('%d', '\d+', preg_quote($config['file_page'], '/')) . '|' . - str_replace('%d', '\d+', preg_quote($config['file_page50'], '/')) . + str_replace('%d', '\d+', preg_quote($config['file_page50'], '/')) . '|' . + str_replace(array('%d', '%s'), array('\d+', '[a-z0-9-]+'), preg_quote($config['file_page_slug'], '/')) . '|' . + str_replace(array('%d', '%s'), array('\d+', '[a-z0-9-]+'), preg_quote($config['file_page50_slug'], '/')) . ')' . '|' . preg_quote($config['file_mod'], '/') . '\?\/.+' . @@ -912,7 +914,7 @@ function insertFloodPost(array $post) { function post(array $post) { global $pdo, $board; - $query = prepare(sprintf("INSERT INTO ``posts_%s`` VALUES ( NULL, :thread, :subject, :email, :name, :trip, :capcode, :body, :body_nomarkup, :time, :time, :files, :num_files, :filehash, :password, :ip, :sticky, :locked, 0, :embed)", $board['uri'])); + $query = prepare(sprintf("INSERT INTO ``posts_%s`` VALUES ( NULL, :thread, :subject, :email, :name, :trip, :capcode, :body, :body_nomarkup, :time, :time, :files, :num_files, :filehash, :password, :ip, :sticky, :locked, 0, :embed, :slug)", $board['uri'])); // Basic stuff if (!empty($post['subject'])) { @@ -981,6 +983,10 @@ function post(array $post) { $query->bindValue(':filehash', null, PDO::PARAM_NULL); } + if ($post['op']) { + $query->bindValue(':slug', slugify($post)); + } + if (!$query->execute()) { undoImage($post); error(db_error($query)); @@ -1094,8 +1100,8 @@ function deletePost($id, $error_if_doesnt_exist=true, $rebuild_after=true) { if (!$post['thread']) { // Delete thread HTML page - file_unlink($board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $post['id'])); - file_unlink($board['dir'] . $config['dir']['res'] . sprintf($config['file_page50'], $post['id'])); + file_unlink($board['dir'] . $config['dir']['res'] . link_for($post) ); + file_unlink($board['dir'] . $config['dir']['res'] . link_for($post, true) ); // noko50 file_unlink($board['dir'] . $config['dir']['res'] . sprintf('%d.json', $post['id'])); $antispam_query = prepare('DELETE FROM ``antispam`` WHERE `board` = :board AND `thread` = :thread'); @@ -2067,12 +2073,12 @@ function buildThread($id, $return = false, $mod = false) { if ($return) { return $body; } else { - $noko50fn = $board['dir'] . $config['dir']['res'] . sprintf($config['file_page50'], $id); + $noko50fn = $board['dir'] . $config['dir']['res'] . link_for($thread, true); if ($hasnoko50 || file_exists($noko50fn)) { buildThread50($id, $return, $mod, $thread, $antibot); } - file_write($board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $id), $body); + file_write($board['dir'] . $config['dir']['res'] . link_for($thread), $body); } } @@ -2152,7 +2158,7 @@ function buildThread50($id, $return = false, $mod = false, $thread = null, $anti if ($return) { return $body; } else { - file_write($board['dir'] . $config['dir']['res'] . sprintf($config['file_page50'], $id), $body); + file_write($board['dir'] . $config['dir']['res'] . link_for($thread, true), $body); } } @@ -2421,3 +2427,75 @@ function diceRoller($post) { } } } + +function slugify($post) { + $slug = ""; + + if (isset($post['thread']) && $post['thread']) + $slug = $post['thread']; + elseif (isset ($post['body_nomarkup']) && $post['body_nomarkup']) + $slug = $post['body_nomarkup']; + elseif (isset ($post['body']) && $post['body']) + $slug = strip_html($post['body']); + + // Fix UTF-8 first + $slug = mb_convert_encoding($slug, "UTF-8", "UTF-8"); + + // Transliterate local characters like ü, I wonder how would it work for weird alphabets :^) + $slug = iconv("UTF-8", "ASCII//TRANSLIT//IGNORE", $slug); + + // Downcase everything + $slug = strtolower($slug); + + // Strip bad characters, alphanumerics should suffice + $slug = preg_replace('/[^a-zA-Z0-9]/', '-', $slug); + + // Replace multiple dashes with single ones + $slug = preg_replace('/-+/', '-', $slug); + + // Strip dashes at the beginning and at the end + $slug = preg_replace('/^-|-$/', '', $slug); + + // Slug should be 200 characters long, at max + $slug = substr($slug, 0, 200); + + // Slug is now ready + return $slug; +} + +function link_for($post, $page50 = false, $foreignlink = false, $thread = false) { + global $config, $board; + + $post = (array)$post; + + // Where do we need to look for OP? + $b = $foreignlink ? $foreignlink : $board; + + $id = (isset($post['thread']) && $post['thread']) ? $post['thread'] : $post['id']; + + $slug = false; + + if ($config['slugify'] && isset($post['thread']) && $post['thread']) { + if (!$thread) { + // Oh fuck, we'd better optimize it ASAP + + $query = prepare(sprintf("SELECT `slug` FROM ``posts_%s`` WHERE `id` = :id", $board['uri'])); + $query->bindValue(':id', $id, PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + + $thread = $query->fetch(PDO::FETCH_ASSOC); + } + $slug = $thread['slug']; + } + elseif ($config['slugify']) { + $slug = $post['slug']; + } + + + if ( $page50 && $slug) $tpl = $config['file_page50_slug']; + else if (!$page50 && $slug) $tpl = $config['file_page_slug']; + else if ( $page50 && !$slug) $tpl = $config['file_page50']; + else if (!$page50 && !$slug) $tpl = $config['file_page']; + + return sprintf($tpl, $id, $slug); +} diff --git a/inc/lib/Twig/Extensions/Extension/Tinyboard.php b/inc/lib/Twig/Extensions/Extension/Tinyboard.php index 81276147..028db438 100644 --- a/inc/lib/Twig/Extensions/Extension/Tinyboard.php +++ b/inc/lib/Twig/Extensions/Extension/Tinyboard.php @@ -45,7 +45,8 @@ class Twig_Extensions_Extension_Tinyboard extends Twig_Extension new Twig_SimpleFunction('hiddenInputsHash', 'hiddenInputsHash'), new Twig_SimpleFunction('ratio', 'twig_ratio_function'), new Twig_SimpleFunction('secure_link_confirm', 'twig_secure_link_confirm'), - new Twig_SimpleFunction('secure_link', 'twig_secure_link') + new Twig_SimpleFunction('secure_link', 'twig_secure_link'), + new Twig_SimpleFunction('link_for', 'link_for') ); } diff --git a/inc/mod/pages.php b/inc/mod/pages.php index c7722763..79d1bf51 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -1161,7 +1161,7 @@ function mod_move_reply($originBoard, $postID) { $post = $query->fetch(PDO::FETCH_ASSOC); // redirect - header('Location: ?/' . sprintf($config['board_path'], $board['uri']) . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $newID) . '#' . $newID, true, $config['redirect_http']); + header('Location: ?/' . sprintf($config['board_path'], $board['uri']) . $config['dir']['res'] . link_for($post) . '#' . $newID, true, $config['redirect_http']); } else { @@ -1322,6 +1322,8 @@ function mod_move($originBoard, $postID) { // trigger themes rebuildThemes('post', $targetBoard); + $newboard = $board; + // return to original board openBoard($originBoard); @@ -1332,7 +1334,7 @@ function mod_move($originBoard, $postID) { $query->execute() or error(db_error($query)); // leave a reply, linking to the new thread - $post = array( + $spost = array( 'mod' => true, 'subject' => '', 'email' => '', @@ -1346,23 +1348,23 @@ function mod_move($originBoard, $postID) { 'op' => false ); - $post['body'] = $post['body_nomarkup'] = sprintf($config['mod']['shadow_mesage'], '>>>/' . $targetBoard . '/' . $newID); + $spost['body'] = $spost['body_nomarkup'] = sprintf($config['mod']['shadow_mesage'], '>>>/' . $targetBoard . '/' . $newID); - markup($post['body']); + markup($spost['body']); - $botID = post($post); + $botID = post($spost); buildThread($postID); buildIndex(); - header('Location: ?/' . sprintf($config['board_path'], $originBoard) . $config['dir']['res'] .sprintf($config['file_page'], $postID) . + header('Location: ?/' . sprintf($config['board_path'], $originBoard) . $config['dir']['res'] . link_for($post, false, $newboard) . '#' . $botID, true, $config['redirect_http']); } else { deletePost($postID); buildIndex(); openBoard($targetBoard); - header('Location: ?/' . sprintf($config['board_path'], $board['uri']) . $config['dir']['res'] . sprintf($config['file_page'], $newID), true, $config['redirect_http']); + header('Location: ?/' . sprintf($config['board_path'], $board['uri']) . $config['dir']['res'] . link_for($post, false, $newboard), true, $config['redirect_http']); } } @@ -1494,7 +1496,7 @@ function mod_edit_post($board, $edit_raw_html, $postID) { rebuildThemes('post', $board); - header('Location: ?/' . sprintf($config['board_path'], $board) . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $postID) . '#' . $postID, true, $config['redirect_http']); + header('Location: ?/' . sprintf($config['board_path'], $board) . $config['dir']['res'] . link_for($post) . '#' . $postID, true, $config['redirect_http']); } else { if ($config['minify_html']) { $post['body_nomarkup'] = str_replace("\n", ' ', utf8tohtml($post['body_nomarkup'])); diff --git a/install.php b/install.php index 2e050eee..95caf8ec 100644 --- a/install.php +++ b/install.php @@ -1,7 +1,7 @@ vichan upgrade path. query("CREATE TABLE IF NOT EXISTS ``search_queries`` ( `ip` varchar(39) NOT NULL, `time` int(11) NOT NULL, `query` text NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=utf8;") or error(db_error()); diff --git a/mod.php b/mod.php index 384eec88..e06d5db6 100644 --- a/mod.php +++ b/mod.php @@ -105,6 +105,11 @@ $pages = array( str_replace('%d', '(\d+)', preg_quote($config['file_page50'], '!')) => 'view_thread50', '/(\%b)/' . preg_quote($config['dir']['res'], '!') . str_replace('%d', '(\d+)', preg_quote($config['file_page'], '!')) => 'view_thread', + + '/(\%b)/' . preg_quote($config['dir']['res'], '!') . + str_replace(array('%d','%s'), array('(\d+)', '[a-z0-9-]+'), preg_quote($config['file_page50_slug'], '!')) => 'view_thread50', + '/(\%b)/' . preg_quote($config['dir']['res'], '!') . + str_replace(array('%d','%s'), array('(\d+)', '[a-z0-9-]+'), preg_quote($config['file_page_slug'], '!')) => 'view_thread', ); diff --git a/post.php b/post.php index d33c8150..93592590 100644 --- a/post.php +++ b/post.php @@ -85,7 +85,7 @@ if (isset($_POST['delete'])) { } _syslog(LOG_INFO, 'Deleted post: ' . - '/' . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $id) . ($post['thread'] ? '#' . $id : '') + '/' . $board['dir'] . $config['dir']['res'] . link_for($post) . ($post['thread'] ? '#' . $id : '') ); } } @@ -142,7 +142,7 @@ if (isset($_POST['delete'])) { if ($config['syslog']) _syslog(LOG_INFO, 'Reported post: ' . - '/' . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $thread ? $thread : $id) . ($thread ? '#' . $id : '') . + '/' . $board['dir'] . $config['dir']['res'] . link_for($post) . ($thread ? '#' . $id : '') . ' for "' . $reason . '"' ); $query = prepare("INSERT INTO ``reports`` VALUES (NULL, :time, :ip, :board, :post, :reason)"); @@ -250,7 +250,7 @@ if (isset($_POST['delete'])) { //Check if thread exists if (!$post['op']) { - $query = prepare(sprintf("SELECT `sticky`,`locked`,`sage` FROM ``posts_%s`` WHERE `id` = :id AND `thread` IS NULL LIMIT 1", $board['uri'])); + $query = prepare(sprintf("SELECT `sticky`,`locked`,`sage`,`slug` FROM ``posts_%s`` WHERE `id` = :id AND `thread` IS NULL LIMIT 1", $board['uri'])); $query->bindValue(':id', $post['thread'], PDO::PARAM_INT); $query->execute() or error(db_error()); @@ -259,6 +259,9 @@ if (isset($_POST['delete'])) { error($config['error']['nonexistant']); } } + else { + $thread = false; + } // Check for an embed field @@ -782,6 +785,7 @@ if (isset($_POST['delete'])) { $post = (object)$post; $post->files = array_map(function($a) { return (object)$a; }, $post->files); + $error = event('post', $post); $post->files = array_map(function($a) { return (array)$a; }, $post->files); @@ -845,19 +849,20 @@ if (isset($_POST['delete'])) { if ($noko) { $redirect = $root . $board['dir'] . $config['dir']['res'] . - sprintf($config['file_page'], $post['op'] ? $id:$post['thread']) . (!$post['op'] ? '#' . $id : ''); + link_for($post, false, false, $thread) . (!$post['op'] ? '#' . $id : ''); if (!$post['op'] && isset($_SERVER['HTTP_REFERER'])) { $regex = array( 'board' => str_replace('%s', '(\w{1,8})', preg_quote($config['board_path'], '/')), 'page' => str_replace('%d', '(\d+)', preg_quote($config['file_page'], '/')), - 'page50' => str_replace('%d', '(\d+)', preg_quote($config['file_page50'], '/')), + 'page50' => '(' . str_replace('%d', '(\d+)', preg_quote($config['file_page50'], '/')) . '|' . + str_replace(array('%d', '%s'), array('(\d+)', '[a-z0-9-]+'), preg_quote($config['file_page50_slug'], '/')) . ')', 'res' => preg_quote($config['dir']['res'], '/'), ); if (preg_match('/\/' . $regex['board'] . $regex['res'] . $regex['page50'] . '([?&].*)?$/', $_SERVER['HTTP_REFERER'])) { $redirect = $root . $board['dir'] . $config['dir']['res'] . - sprintf($config['file_page50'], $post['op'] ? $id:$post['thread']) . (!$post['op'] ? '#' . $id : ''); + link_for($post, true, false, $thread) . (!$post['op'] ? '#' . $id : ''); } } } else { @@ -867,7 +872,7 @@ if (isset($_POST['delete'])) { if ($config['syslog']) _syslog(LOG_INFO, 'New post: /' . $board['dir'] . $config['dir']['res'] . - sprintf($config['file_page'], $post['op'] ? $id : $post['thread']) . (!$post['op'] ? '#' . $id : '')); + link_for($post) . (!$post['op'] ? '#' . $id : '')); if (!$post['mod']) header('X-Associated-Content: "' . $redirect . '"'); diff --git a/templates/main.js b/templates/main.js index ead852fe..e948fd82 100644 --- a/templates/main.js +++ b/templates/main.js @@ -146,6 +146,7 @@ function changeStyle(styleName, link) { {% endraw %} {% if config.stylesheets_board %} {# This is such an unacceptable mess. There needs to be an easier way. #} + {# Needs fix for slugify #} var matches = document.URL.match(/\/(\w+)\/($|{{ config.dir.res|replace({'/': '\\/'}) }}{{ config.file_page|replace({'%d': '\\d+', '.': '\\.'}) }}|{{ config.file_index|replace({'.': '\\.'}) }}|{{ config.file_page|replace({'%d': '\\d+', '.': '\\.'}) }})/); {% raw %} if (matches) { diff --git a/templates/mod/debug/recent_posts.html b/templates/mod/debug/recent_posts.html index e4eb4f3a..ce4cffc4 100644 --- a/templates/mod/debug/recent_posts.html +++ b/templates/mod/debug/recent_posts.html @@ -63,7 +63,7 @@ {% else %} {% set thread = post.id %} {% endif %} - + {{ post.id }} diff --git a/templates/mod/search_results.html b/templates/mod/search_results.html index 0d3c2a10..186ee5db 100644 --- a/templates/mod/search_results.html +++ b/templates/mod/search_results.html @@ -195,7 +195,7 @@ {% else %} {% set thread = post.id %} {% endif %} - + {{ post.id }} @@ -265,4 +265,4 @@ [{{ i + 1 }}] {% endfor %}

-{% endif %} \ No newline at end of file +{% endif %} diff --git a/templates/post_reply.html b/templates/post_reply.html index e7343230..451ff1b9 100644 --- a/templates/post_reply.html +++ b/templates/post_reply.html @@ -12,8 +12,8 @@ {% include 'post/time.html' %} {% include 'post/poster_id.html' %}  - No. - {{ post.id }} + No. + {{ post.id }}

{% include 'post/fileinfo.html' %} {% include 'post/post_controls.html' %} diff --git a/templates/post_thread.html b/templates/post_thread.html index 08b4c4c1..61146491 100644 --- a/templates/post_thread.html +++ b/templates/post_thread.html @@ -15,8 +15,8 @@ {% include 'post/time.html' %} {% include 'post/poster_id.html' %}  - No. - {{ post.id }} + No. + {{ post.id }} {% if post.sticky %} {% if config.font_awesome %} @@ -39,14 +39,14 @@ {% endif %} {% endif %} {% if index %} - [{% trans %}Reply{% endtrans %}] + [{% trans %}Reply{% endtrans %}] {% endif %} {% if isnoko50 %} - [{% trans %}View All{% endtrans %}] + [{% trans %}View All{% endtrans %}] {% endif %} {% if hasnoko50 and not isnoko50 %} {% set lastcount = config.noko50_count %} - [{% trans %}Last 1 Post{% plural lastcount %}Last {{ count }} Posts{% endtrans %}] + [{% trans %}Last 1 Post{% plural lastcount %}Last {{ count }} Posts{% endtrans %}] {% endif %} {% include 'post/post_controls.html' %}

diff --git a/templates/posts.sql b/templates/posts.sql index 9a47c6ad..6b2249ef 100644 --- a/templates/posts.sql +++ b/templates/posts.sql @@ -19,6 +19,7 @@ CREATE TABLE IF NOT EXISTS ``posts_{{ board }}`` ( `locked` int(1) NOT NULL, `sage` int(1) NOT NULL, `embed` text, + `slug` varchar(256) DEFAULT NULL, UNIQUE KEY `id` (`id`), KEY `thread_id` (`thread`,`id`), KEY `filehash` (`filehash`(40)), diff --git a/templates/themes/catalog/theme.php b/templates/themes/catalog/theme.php index 9ba2d27a..b3b7caf7 100644 --- a/templates/themes/catalog/theme.php +++ b/templates/themes/catalog/theme.php @@ -42,7 +42,7 @@ $board_name, $board_name, $board_name, $board_name, $board_name)) or error(db_error()); while ($post = $query->fetch(PDO::FETCH_ASSOC)) { - $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], ($post['thread'] ? $post['thread'] : $post['id'])); + $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . link_for($post)); $post['board_name'] = $board['name']; if ($post['embed'] && preg_match('/^https?:\/\/(\w+\.)?(?:youtube\.com\/watch\?v=|youtu\.be\/)([a-zA-Z0-9\-_]{10,11})(&.+)?$/i', $post['embed'], $matches)) { diff --git a/templates/themes/recent/theme.php b/templates/themes/recent/theme.php index b1153477..2ea6a7b9 100644 --- a/templates/themes/recent/theme.php +++ b/templates/themes/recent/theme.php @@ -62,7 +62,7 @@ // board settings won't be available in the template file, so generate links now $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] - . sprintf($config['file_page'], ($post['thread'] ? $post['thread'] : $post['id'])) . '#' . $post['id']; + . link_for($post) . '#' . $post['id']; if ($files) { if ($files[0]->thumb == 'spoiler') { @@ -92,7 +92,7 @@ while ($post = $query->fetch(PDO::FETCH_ASSOC)) { openBoard($post['board']); - $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], ($post['thread'] ? $post['thread'] : $post['id'])) . '#' . $post['id']; + $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . link_for($post) . '#' . $post['id']; if ($post['body'] != "") $post['snippet'] = pm_snippet($post['body'], 30); else diff --git a/templates/themes/sitemap/sitemap.xml b/templates/themes/sitemap/sitemap.xml index 733da607..95dfdd26 100644 --- a/templates/themes/sitemap/sitemap.xml +++ b/templates/themes/sitemap/sitemap.xml @@ -9,11 +9,11 @@ {% for board, thread_list in threads %} {% for thread in thread_list %} - {{ settings.url ~ (config.board_path | format(board)) ~ config.dir.res ~ (config.file_page | format(thread.thread_id)) }} + {{ settings.url ~ (config.board_path | format(board)) ~ config.dir.res ~ link_for(thread) }} {{ thread.lastmod | date('%Y-%m-%dT%H:%M:%S') }}{{ timezone() }} {{ settings.changefreq }} {% endfor %} {% endfor %} -{% endfilter %} \ No newline at end of file +{% endfilter %} diff --git a/templates/themes/sitemap/theme.php b/templates/themes/sitemap/theme.php index 3e048dd5..1cebcdb6 100644 --- a/templates/themes/sitemap/theme.php +++ b/templates/themes/sitemap/theme.php @@ -26,7 +26,7 @@ $threads = array(); foreach ($boards as $board) { - $query = query(sprintf("SELECT `id` AS `thread_id`, (SELECT `time` FROM ``posts_%s`` WHERE `thread` = `thread_id` OR `id` = `thread_id` ORDER BY `time` DESC LIMIT 1) AS `lastmod` FROM ``posts_%s`` WHERE `thread` IS NULL", $board, $board)) or error(db_error()); + $query = query(sprintf("SELECT `id`, `slug`, (SELECT `time` FROM ``posts_%s`` WHERE `thread` = `thread_id` OR `id` = `thread_id` ORDER BY `time` DESC LIMIT 1) AS `lastmod` FROM ``posts_%s`` WHERE `thread` IS NULL", $board, $board)) or error(db_error()); $threads[$board] = $query->fetchAll(PDO::FETCH_ASSOC); } -- cgit v1.3 From 58b60f0aa4ef14589315a66fcf58d749928483c7 Mon Sep 17 00:00:00 2001 From: czaks Date: Tue, 10 Mar 2015 13:46:34 +0100 Subject: ... --- inc/mod/pages.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'inc/mod/pages.php') diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 79d1bf51..2b7de134 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -1224,7 +1224,10 @@ function mod_move($originBoard, $postID) { // create the new thread $newID = post($post); - + + $op = $post; + $op['id'] = $newID; + if ($post['has_file']) { // copy image foreach ($post['files'] as $i => &$file) { @@ -1357,14 +1360,14 @@ function mod_move($originBoard, $postID) { buildIndex(); - header('Location: ?/' . sprintf($config['board_path'], $originBoard) . $config['dir']['res'] . link_for($post, false, $newboard) . + header('Location: ?/' . sprintf($config['board_path'], $originBoard) . $config['dir']['res'] . link_for($op, false, $newboard) . '#' . $botID, true, $config['redirect_http']); } else { deletePost($postID); buildIndex(); openBoard($targetBoard); - header('Location: ?/' . sprintf($config['board_path'], $board['uri']) . $config['dir']['res'] . link_for($post, false, $newboard), true, $config['redirect_http']); + header('Location: ?/' . sprintf($config['board_path'], $board['uri']) . $config['dir']['res'] . link_for($op, false, $newboard), true, $config['redirect_http']); } } -- cgit v1.3 From 2f7aeec53128b08e000e89bc031f25c0501565f3 Mon Sep 17 00:00:00 2001 From: czaks Date: Tue, 10 Mar 2015 13:48:33 +0100 Subject: ... --- inc/mod/pages.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/mod/pages.php') diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 2b7de134..be713f57 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -1360,14 +1360,14 @@ function mod_move($originBoard, $postID) { buildIndex(); - header('Location: ?/' . sprintf($config['board_path'], $originBoard) . $config['dir']['res'] . link_for($op, false, $newboard) . + header('Location: ?/' . sprintf($config['board_path'], $newboard['uri']) . $config['dir']['res'] . link_for($op, false, $newboard) . '#' . $botID, true, $config['redirect_http']); } else { deletePost($postID); buildIndex(); openBoard($targetBoard); - header('Location: ?/' . sprintf($config['board_path'], $board['uri']) . $config['dir']['res'] . link_for($op, false, $newboard), true, $config['redirect_http']); + header('Location: ?/' . sprintf($config['board_path'], $newboard['uri']) . $config['dir']['res'] . link_for($op, false, $newboard), true, $config['redirect_http']); } } -- cgit v1.3 From b78b3db0105c832f3e5b1f5cca019bb41a137662 Mon Sep 17 00:00:00 2001 From: czaks Date: Sun, 5 Apr 2015 16:59:04 +0200 Subject: uncache themes on settings change --- inc/mod/pages.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'inc/mod/pages.php') diff --git a/inc/mod/pages.php b/inc/mod/pages.php index be713f57..969c570e 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -2501,10 +2501,14 @@ function mod_theme_configure($theme_name) { $query->bindValue(':value', $_POST[$conf['name']]); $query->execute() or error(db_error($query)); } - + $query = prepare("INSERT INTO ``theme_settings`` VALUES(:theme, NULL, NULL)"); $query->bindValue(':theme', $theme_name); $query->execute() or error(db_error($query)); + + // Clean cache + Cache::delete("themes"); + Cache::delete("theme_settings_".$theme); $result = true; $message = false; @@ -2552,11 +2556,15 @@ function mod_theme_uninstall($theme_name) { if (!hasPermission($config['mod']['themes'])) error($config['error']['noaccess']); - + $query = prepare("DELETE FROM ``theme_settings`` WHERE `theme` = :theme"); $query->bindValue(':theme', $theme_name); $query->execute() or error(db_error($query)); + // Clean cache + Cache::delete("themes"); + Cache::delete("theme_settings_".$theme); + header('Location: ?/themes', true, $config['redirect_http']); } -- cgit v1.3 From 4c1d2f924c60b1b33d6ab96b2ad26e48d6bd68b4 Mon Sep 17 00:00:00 2001 From: czaks Date: Thu, 23 Apr 2015 07:57:52 +0200 Subject: fix error while installing themes; thanks xixi --- inc/mod/pages.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/mod/pages.php') diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 969c570e..804c1e43 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -2508,7 +2508,7 @@ function mod_theme_configure($theme_name) { // Clean cache Cache::delete("themes"); - Cache::delete("theme_settings_".$theme); + Cache::delete("theme_settings_".$theme_name); $result = true; $message = false; -- cgit v1.3 From 2d9214ac63b34ea1066efa2dbc759258f2ca661a Mon Sep 17 00:00:00 2001 From: czaks Date: Thu, 23 Apr 2015 08:18:36 +0200 Subject: version check should point at engine.vichan.net and not tinyboard.org actually --- inc/mod/pages.php | 4 ++-- templates/mod/dashboard.html | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'inc/mod/pages.php') diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 804c1e43..2c679b20 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -111,7 +111,7 @@ function mod_dashboard() { $latest = unserialize($_COOKIE['update']); } else { $ctx = stream_context_create(array('http' => array('timeout' => 5))); - if ($code = @file_get_contents('http://tinyboard.org/version.txt', 0, $ctx)) { + if ($code = @file_get_contents('http://engine.vichan.net/version.txt', 0, $ctx)) { $ver = strtok($code, "\n"); if (preg_match('@^// v(\d+)\.(\d+)\.(\d+)\s*?$@', $ver, $matches)) { @@ -120,7 +120,7 @@ function mod_dashboard() { 'major' => $matches[2], 'minor' => $matches[3] ); - if (preg_match('/v(\d+)\.(\d)\.(\d+)(-dev.+)?$/', $config['version'], $matches)) { + if (preg_match('/(\d+)\.(\d)\.(\d+)(-dev.+)?$/', $config['version'], $matches)) { $current = array( 'massive' => (int) $matches[1], 'major' => (int) $matches[2], diff --git a/templates/mod/dashboard.html b/templates/mod/dashboard.html index 2c370a11..7e25555b 100644 --- a/templates/mod/dashboard.html +++ b/templates/mod/dashboard.html @@ -155,9 +155,9 @@ Update
  • - A newer version of Tinyboard + A newer version of vichan (v{{ newer_release.massive }}.{{ newer_release.major }}.{{ newer_release.minor }}) is available! - See http://tinyboard.org/ for upgrade instructions. + See https://engine.vichan.net/ for upgrade instructions.
-- cgit v1.3