From 96495504631d6a4d466b93a835d7d66853e2e12b Mon Sep 17 00:00:00 2001 From: Michael Save Date: Fri, 13 Apr 2012 02:11:41 +1000 Subject: start on mod interface rewrite --- inc/lib/Twig/Extensions/Extension/Tinyboard.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/lib') diff --git a/inc/lib/Twig/Extensions/Extension/Tinyboard.php b/inc/lib/Twig/Extensions/Extension/Tinyboard.php index 7e2149e5..cbb2e752 100644 --- a/inc/lib/Twig/Extensions/Extension/Tinyboard.php +++ b/inc/lib/Twig/Extensions/Extension/Tinyboard.php @@ -64,7 +64,7 @@ function twig_date_filter($date, $format) { return strftime($format, $date); } -function twig_hasPermission_filter($mod, $permission, $board) { +function twig_hasPermission_filter($mod, $permission, $board = false) { return hasPermission($permission, $board, $mod); } -- cgit v1.3 From e92ee2b4879d110f4076c17c0033267dfbbc9197 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Fri, 13 Apr 2012 20:48:37 +1000 Subject: moderation log --- inc/lib/Twig/Extensions/Extension/Tinyboard.php | 1 + templates/mod/log.html | 30 +++++++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) (limited to 'inc/lib') diff --git a/inc/lib/Twig/Extensions/Extension/Tinyboard.php b/inc/lib/Twig/Extensions/Extension/Tinyboard.php index cbb2e752..4111fc3c 100644 --- a/inc/lib/Twig/Extensions/Extension/Tinyboard.php +++ b/inc/lib/Twig/Extensions/Extension/Tinyboard.php @@ -21,6 +21,7 @@ class Twig_Extensions_Extension_Tinyboard extends Twig_Extension 'poster_id' => new Twig_Filter_Function('poster_id', array('needs_environment' => false)), 'remove_whitespace' => new Twig_Filter_Function('twig_remove_whitespace_filter', array('needs_environment' => false)), 'count' => new Twig_Filter_Function('count', array('needs_environment' => false)), + 'ago' => new Twig_Filter_Function('ago', array('needs_environment' => false)), 'until' => new Twig_Filter_Function('until', array('needs_environment' => false)) ); } diff --git a/templates/mod/log.html b/templates/mod/log.html index 2aa0ea0a..4f2beb40 100644 --- a/templates/mod/log.html +++ b/templates/mod/log.html @@ -1,11 +1,33 @@ - + + + + + {% for log in logs %} - + + + + + + + {% endfor %}
- - StaffIP addressAgoBoardAction
+ {{ log.username }} + + {{ log.ip }} + + {{ log.time|ago }} + + {% if log.board %} + {{ config.board_abbreviation|sprintf(log.board) }} + {% else %} + - + {% endif %} + + {{ log.text }} +
-- cgit v1.3 From 761cb4feab1a052e2e611a1d09d0a3513e011c06 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Fri, 13 Apr 2012 21:43:01 +1000 Subject: ?/users (user list) --- inc/lib/Twig/Extensions/Extension/Tinyboard.php | 45 +++++++++++++++---------- inc/mod/pages.php | 12 +++++++ mod.php | 4 ++- templates/mod/log.html | 12 ++++--- 4 files changed, 50 insertions(+), 23 deletions(-) (limited to 'inc/lib') diff --git a/inc/lib/Twig/Extensions/Extension/Tinyboard.php b/inc/lib/Twig/Extensions/Extension/Tinyboard.php index 4111fc3c..2691cc55 100644 --- a/inc/lib/Twig/Extensions/Extension/Tinyboard.php +++ b/inc/lib/Twig/Extensions/Extension/Tinyboard.php @@ -10,19 +10,21 @@ class Twig_Extensions_Extension_Tinyboard extends Twig_Extension public function getFilters() { return Array( - 'filesize' => new Twig_Filter_Function('format_bytes', Array('needs_environment' => false)), - 'truncate' => new Twig_Filter_Function('twig_truncate_filter', array('needs_environment' => false)), - 'truncate_body' => new Twig_Filter_Function('truncate', array('needs_environment' => false)), - 'extension' => new Twig_Filter_Function('twig_extension_filter', array('needs_environment' => false)), - 'sprintf' => new Twig_Filter_Function('sprintf', array('needs_environment' => false)), - 'capcode' => new Twig_Filter_Function('capcode', array('needs_environment' => false)), - 'hasPermission' => new Twig_Filter_Function('twig_hasPermission_filter', array('needs_environment' => false)), - 'date' => new Twig_Filter_Function('twig_date_filter', array('needs_environment' => false)), - 'poster_id' => new Twig_Filter_Function('poster_id', array('needs_environment' => false)), - 'remove_whitespace' => new Twig_Filter_Function('twig_remove_whitespace_filter', array('needs_environment' => false)), - 'count' => new Twig_Filter_Function('count', array('needs_environment' => false)), - 'ago' => new Twig_Filter_Function('ago', array('needs_environment' => false)), - 'until' => new Twig_Filter_Function('until', array('needs_environment' => false)) + 'filesize' => new Twig_Filter_Function('format_bytes'), + 'truncate' => new Twig_Filter_Function('twig_truncate_filter'), + 'truncate_body' => new Twig_Filter_Function('truncate'), + 'extension' => new Twig_Filter_Function('twig_extension_filter'), + 'sprintf' => new Twig_Filter_Function('sprintf'), + 'capcode' => new Twig_Filter_Function('capcode'), + 'hasPermission' => new Twig_Filter_Function('twig_hasPermission_filter'), + 'date' => new Twig_Filter_Function('twig_date_filter'), + 'poster_id' => new Twig_Filter_Function('poster_id'), + 'remove_whitespace' => new Twig_Filter_Function('twig_remove_whitespace_filter'), + 'count' => new Twig_Filter_Function('count'), + 'ago' => new Twig_Filter_Function('ago'), + 'until' => new Twig_Filter_Function('until'), + 'split' => new Twig_Filter_Function('twig_split_filter'), + 'push' => new Twig_Filter_Function('twig_push_filter'), ); } @@ -34,10 +36,10 @@ class Twig_Extensions_Extension_Tinyboard extends Twig_Extension public function getFunctions() { return Array( - 'time' => new Twig_Filter_Function('time', array('needs_environment' => false)), - 'timezone' => new Twig_Filter_Function('twig_timezone_function', array('needs_environment' => false)), - 'hiddenInputs' => new Twig_Filter_Function('hiddenInputs', array('needs_environment' => false)), - 'hiddenInputsHash' => new Twig_Filter_Function('hiddenInputsHash', array('needs_environment' => false)) + 'time' => new Twig_Filter_Function('time'), + 'timezone' => new Twig_Filter_Function('twig_timezone_function'), + 'hiddenInputs' => new Twig_Filter_Function('hiddenInputs'), + 'hiddenInputsHash' => new Twig_Filter_Function('hiddenInputsHash'), ); } @@ -57,6 +59,15 @@ function twig_timezone_function() { return sprintf("%s%02d", ($hr = (int)floor(($tz = date('Z')) / 3600)) > 0 ? '+' : '-', abs($hr)) . ':' . sprintf("%02d", (($tz / 3600) - $hr) * 60); } +function twig_split_filter($str, $delim) { + return explode($delim, $str); +} + +function twig_push_filter($array, $value) { + array_push($array, $value); + return $array; +} + function twig_remove_whitespace_filter($data) { return preg_replace('/[\t\r\n]/', '', $data); } diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 942cfd50..2b5487fd 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -250,3 +250,15 @@ function mod_delete($board, $post) { header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); } +function mod_users() { + global $config; + if(!hasPermission($config['mod']['manageusers'])) + error($config['error']['noaccess']); + + $args = array(); + $query = query("SELECT *, (SELECT `time` FROM `modlogs` WHERE `mod` = `id` ORDER BY `time` DESC LIMIT 1) AS `last`, (SELECT `text` FROM `modlogs` WHERE `mod` = `id` ORDER BY `time` DESC LIMIT 1) AS `action` FROM `mods` ORDER BY `type` DESC,`id`") or error(db_error()); + $args['users'] = $query->fetchAll(PDO::FETCH_ASSOC); + + mod_page("Manage users", 'mod/users.html', $args); +} + diff --git a/mod.php b/mod.php index 3aba6fe4..d95f9552 100644 --- a/mod.php +++ b/mod.php @@ -23,10 +23,12 @@ $query = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : ''; $pages = array( '!^$!' => ':?/', // redirect to dashboard '!^/$!' => 'dashboard', // dashboard + '!^/confirm/(.+)$!' => 'confirm', // confirm action (if javascript didn't work) '!^/log$!' => 'log', // modlog '!^/log/(\d+)$!' => 'log', // modlog + + '!^/users$!' => 'users', // manage users - '!^/confirm/(.+)$!' => 'confirm', // confirm action (if javascript didn't work) '!^/ban$!' => 'ban', // new ban '!^/IP/([\w.:]+)$!' => 'ip', // view ip address diff --git a/templates/mod/log.html b/templates/mod/log.html index fe1c5c1f..61243202 100644 --- a/templates/mod/log.html +++ b/templates/mod/log.html @@ -31,9 +31,11 @@ {% endfor %} -

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

+{% if count > logs|count %} +

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

+{% endif %} -- cgit v1.3 From a340c5b6eec89d0e023fc606081ec857f44a0b3d Mon Sep 17 00:00:00 2001 From: Michael Save Date: Mon, 16 Apr 2012 23:18:07 +1000 Subject: edit users --- inc/lib/Twig/Extensions/Extension/Tinyboard.php | 2 +- inc/mod/pages.php | 82 ++++++++++++++++++++++ mod.php | 1 + templates/mod/log.html | 2 +- templates/mod/user.html | 93 +++++++++++++++++++++++++ 5 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 templates/mod/user.html (limited to 'inc/lib') diff --git a/inc/lib/Twig/Extensions/Extension/Tinyboard.php b/inc/lib/Twig/Extensions/Extension/Tinyboard.php index 2691cc55..df652444 100644 --- a/inc/lib/Twig/Extensions/Extension/Tinyboard.php +++ b/inc/lib/Twig/Extensions/Extension/Tinyboard.php @@ -76,7 +76,7 @@ function twig_date_filter($date, $format) { return strftime($format, $date); } -function twig_hasPermission_filter($mod, $permission, $board = false) { +function twig_hasPermission_filter($mod, $permission, $board = null) { return hasPermission($permission, $board, $mod); } diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 31c78528..e388c509 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -313,6 +313,7 @@ function mod_lock($board, $unlock, $post) { $query->bindValue(':locked', $unlock ? 0 : 1); $query->execute() or error(db_error($query)); if($query->rowCount()) { + modLog(($unlock ? 'Unlocked' : 'Locked') . " thread #{$post}"); buildThread($post); buildIndex(); } @@ -334,6 +335,7 @@ function mod_sticky($board, $unsticky, $post) { $query->bindValue(':sticky', $unsticky ? 0 : 1); $query->execute() or error(db_error($query)); if($query->rowCount()) { + modLog(($unlock ? 'Unstickied' : 'Stickied') . " thread #{$post}"); buildThread($post); buildIndex(); } @@ -355,6 +357,7 @@ function mod_bumplock($board, $unbumplock, $post) { $query->bindValue(':bumplock', $unbumplock ? 0 : 1); $query->execute() or error(db_error($query)); if($query->rowCount()) { + modLog(($unlock ? 'Unbumplocked' : 'Bumplocked') . " thread #{$post}"); buildThread($post); buildIndex(); } @@ -382,6 +385,85 @@ function mod_delete($board, $post) { header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); } +function mod_user($uid) { + global $config, $mod; + + if (!hasPermission($config['mod']['editusers']) && !(hasPermission($config['mod']['change_password']) && $uid == $mod['id'])) + error($config['error']['noaccess']); + + $query = prepare('SELECT * FROM `mods` WHERE `id` = :id'); + $query->bindValue(':id', $uid); + $query->execute() or error(db_error($query)); + if (!$user = $query->fetch(PDO::FETCH_ASSOC)) + error($config['error']['404']); + + if (hasPermission($config['mod']['editusers']) && isset($_POST['username'], $_POST['password'])) { + if (isset($_POST['allboards'])) { + $boards = array('*'); + } else { + $_boards = listBoards(); + foreach ($_boards as &$board) { + $board = $board['uri']; + } + + $boards = array(); + foreach ($_POST as $name => $value) { + if (preg_match('/^board_(\w+)$/', $name, $matches) && in_array($matches[1], $_boards)) + $boards[] = $matches[1]; + } + } + + $query = prepare('UPDATE `mods` SET `username` = :username, `boards` = :boards WHERE `id` = :id'); + $query->bindValue(':id', $uid); + $query->bindValue(':username', $_POST['username']); + $query->bindValue(':boards', implode(',', $boards)); + $query->execute() or error(db_error($query)); + + if ($_POST['password'] != '') { + $query = prepare('UPDATE `mods` SET `password` = SHA1(:password) WHERE `id` = :id'); + $query->bindValue(':id', $uid); + $query->bindValue(':password', $_POST['password']); + $query->execute() or error(db_error($query)); + + if ($uid == $mod['id']) { + login($_POST['username'], $_POST['password']); + setCookies(); + } + } + + header('Location: ?/users', true, $config['redirect_http']); + return; + } + + if (hasPermission($config['mod']['change_password']) && $uid == $mod['id'] && isset($_POST['password'])) { + if ($_POST['password'] != '') { + $query = prepare('UPDATE `mods` SET `password` = SHA1(:password) WHERE `id` = :id'); + $query->bindValue(':id', $uid); + $query->bindValue(':password', $_POST['password']); + $query->execute() or error(db_error($query)); + + login($_POST['username'], $_POST['password']); + setCookies(); + } + + header('Location: ?/users', true, $config['redirect_http']); + return; + } + + if (hasPermission($config['mod']['modlog'])) { + $query = prepare('SELECT * FROM `modlogs` WHERE `mod` = :id ORDER BY `time` DESC LIMIT 5'); + $query->bindValue(':id', $uid); + $query->execute() or error(db_error($query)); + $log = $query->fetchAll(PDO::FETCH_ASSOC); + } else { + $log = array(); + } + + $user['boards'] = explode(',', $user['boards']); + + mod_page('Edit user', 'mod/user.html', array('user' => $user, 'logs' => $log, 'boards' => listBoards())); +} + function mod_users() { global $config; diff --git a/mod.php b/mod.php index 8af74a7b..85d10c6c 100644 --- a/mod.php +++ b/mod.php @@ -28,6 +28,7 @@ $pages = array( '!^/log/(\d+)$!' => 'log', // modlog '!^/users$!' => 'users', // manage users + '!^/users/(\d+)$!' => 'user', // edit user '!^/users/(\d+)/(promote|demote)$!' => 'user_promote', // prmote/demote user '!^/new_PM/([^/]+)$!' => 'new_pm', // create a new pm '!^/PM/(\d+)(/reply)?$!' => 'pm', // read a pm diff --git a/templates/mod/log.html b/templates/mod/log.html index 61243202..19924b1d 100644 --- a/templates/mod/log.html +++ b/templates/mod/log.html @@ -2,7 +2,7 @@ Staff IP address - Ago + Time Board Action diff --git a/templates/mod/user.html b/templates/mod/user.html new file mode 100644 index 00000000..87a57d92 --- /dev/null +++ b/templates/mod/user.html @@ -0,0 +1,93 @@ +
+ + + + + + + + + + + + + +
Username + {% if mod|hasPermission(config.mod.editusers) %} + + {% else %} + {{ user.username|e }} + {% endif %} +
Password (new; optional) + {% if mod|hasPermission(config.mod.editusers) or (mod|hasPermission(config.mod.change_password) and user.id == mod.id) %} + + {% else %} + - + {% endif %} +
Boards +
    +
  • + + +
  • + {% for board in boards %} +
  • + + +
  • + {% endfor %} +
+
+ +
    +
  • + {% if mod|hasPermission(config.mod.deleteusers) %} +
  • + {% endif %} +
+
+ +{% if logs|count > 0 %} + + + + + + + + {% for log in logs %} + + + + + + + {% endfor %} +
IP addressTimeBoardAction
+ {{ log.ip }} + + {{ log.time|ago }} + + {% if log.board %} + {{ config.board_abbreviation|sprintf(log.board) }} + {% else %} + - + {% endif %} + + {{ log.text }} +
+{% endif %} -- cgit v1.3 From 2a301de29feb08d40a9740a574dbef8b07bd595c Mon Sep 17 00:00:00 2001 From: Michael Save Date: Sat, 21 Apr 2012 15:15:32 +1000 Subject: Paginate ?/noticeboard --- inc/config.php | 4 +- inc/lib/Twig/Extensions/Extension/Tinyboard.php | 1 + inc/mod/pages.php | 55 +++++++++++++++++++-- mod.php | 6 ++- templates/mod/ban_list.html | 2 +- templates/mod/log.html | 2 +- templates/mod/noticeboard.html | 65 +++++++++++++++++++++++++ 7 files changed, 125 insertions(+), 10 deletions(-) create mode 100644 templates/mod/noticeboard.html (limited to 'inc/lib') diff --git a/inc/config.php b/inc/config.php index 8d93f266..06e100ea 100644 --- a/inc/config.php +++ b/inc/config.php @@ -832,8 +832,8 @@ // Maximum number of results to display for a search, per board $config['mod']['search_results'] = 75; - // Maximum number of notices to display on the moderator noticeboard - $config['mod']['noticeboard_display'] = 50; + // How many entries to show per page in the moderator noticeboard + $config['mod']['noticeboard_page'] = 50; // Number of entries to summarize and display on the dashboard $config['mod']['noticeboard_dashboard'] = 5; diff --git a/inc/lib/Twig/Extensions/Extension/Tinyboard.php b/inc/lib/Twig/Extensions/Extension/Tinyboard.php index df652444..c4810dad 100644 --- a/inc/lib/Twig/Extensions/Extension/Tinyboard.php +++ b/inc/lib/Twig/Extensions/Extension/Tinyboard.php @@ -37,6 +37,7 @@ class Twig_Extensions_Extension_Tinyboard extends Twig_Extension { return Array( 'time' => new Twig_Filter_Function('time'), + 'floor' => new Twig_Filter_Function('floor'), 'timezone' => new Twig_Filter_Function('twig_timezone_function'), 'hiddenInputs' => new Twig_Filter_Function('hiddenInputs'), 'hiddenInputsHash' => new Twig_Filter_Function('hiddenInputsHash'), diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 3754268d..d111a480 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -67,14 +67,14 @@ function mod_dashboard() { $args['boards'] = listBoards(); - if(hasPermission($config['mod']['noticeboard'])) { - if(!$config['cache']['enabled'] || !$args['noticeboard'] = cache::get('noticeboard_preview')) { + if (hasPermission($config['mod']['noticeboard'])) { + if (!$config['cache']['enabled'] || !$args['noticeboard'] = cache::get('noticeboard_preview')) { $query = prepare("SELECT `noticeboard`.*, `username` FROM `noticeboard` LEFT JOIN `mods` ON `mods`.`id` = `mod` ORDER BY `id` DESC LIMIT :limit"); $query->bindValue(':limit', $config['mod']['noticeboard_dashboard'], PDO::PARAM_INT); $query->execute() or error(db_error($query)); $args['noticeboard'] = $query->fetchAll(PDO::FETCH_ASSOC); - if($config['cache']['enabled']) + if ($config['cache']['enabled']) cache::set('noticeboard_preview', $args['noticeboard']); } } @@ -82,6 +82,47 @@ function mod_dashboard() { mod_page('Dashboard', 'mod/dashboard.html', $args); } +function mod_noticeboard($page_no = 1) { + global $config, $pdo, $mod; + + if (!hasPermission($config['mod']['noticeboard'])) + error($config['error']['noaccess']); + + if (isset($_POST['subject'], $_POST['body'])) { + if (!hasPermission($config['mod']['noticeboard_post'])) + error($config['error']['noaccess']); + + markup($_POST['body']); + + $query = prepare('INSERT INTO `noticeboard` VALUES (NULL, :mod, :time, :subject, :body)'); + $query->bindValue(':mod', $mod['id']); + $query->bindvalue(':time', time()); + $query->bindValue(':subject', $_POST['subject']); + $query->bindValue(':body', $_POST['body']); + $query->execute() or error(db_error($query)); + + if($config['cache']['enabled']) + cache::delete('noticeboard_preview'); + + header('Location: ?/noticeboard#' . $pdo->lastInsertId(), true, $config['redirect_http']); + } + + $query = prepare("SELECT `noticeboard`.*, `username` FROM `noticeboard` LEFT JOIN `mods` ON `mods`.`id` = `mod` ORDER BY `id` DESC LIMIT :offset, :limit"); + $query->bindValue(':limit', $config['mod']['noticeboard_page'], PDO::PARAM_INT); + $query->bindValue(':offset', ($page_no - 1) * $config['mod']['noticeboard_page'], PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + $noticeboard = $query->fetchAll(PDO::FETCH_ASSOC); + + if (empty($noticeboard)) + error($config['error']['404']); + + $query = prepare("SELECT COUNT(*) FROM `noticeboard`"); + $query->execute() or error(db_error($query)); + $count = $query->fetchColumn(0); + + mod_page('Noticeboard', 'mod/noticeboard.html', array('noticeboard' => $noticeboard, 'count' => $count)); +} + function mod_log($page_no = 1) { global $config; @@ -94,7 +135,10 @@ function mod_log($page_no = 1) { $query->execute() or error(db_error($query)); $logs = $query->fetchAll(PDO::FETCH_ASSOC); - $query = prepare("SELECT COUNT(*) AS `count` FROM `modlogs`"); + if (empty($logs)) + error($config['error']['404']); + + $query = prepare("SELECT COUNT(*) FROM `modlogs`"); $query->execute() or error(db_error($query)); $count = $query->fetchColumn(0); @@ -300,6 +344,9 @@ function mod_bans($page_no = 1) { $query->execute() or error(db_error($query)); $bans = $query->fetchAll(PDO::FETCH_ASSOC); + if (empty($bans)) + error($config['error']['404']); + $query = prepare("SELECT COUNT(*) FROM `bans`"); $query->execute() or error(db_error($query)); $count = $query->fetchColumn(0); diff --git a/mod.php b/mod.php index b5edd255..4495ae52 100644 --- a/mod.php +++ b/mod.php @@ -24,8 +24,6 @@ $pages = array( '!^$!' => ':?/', // redirect to dashboard '!^/$!' => 'dashboard', // dashboard '!^/confirm/(.+)$!' => 'confirm', // confirm action (if javascript didn't work) - '!^/log$!' => 'log', // modlog - '!^/log/(\d+)$!' => 'log', // modlog '!^/users$!' => 'users', // manage users '!^/users/(\d+)$!' => 'user', // edit user @@ -33,6 +31,10 @@ $pages = array( '!^/new_PM/([^/]+)$!' => 'new_pm', // create a new pm '!^/PM/(\d+)(/reply)?$!' => 'pm', // read a pm + '!^/noticeboard$!' => 'noticeboard', // view noticeboard + '!^/noticeboard/(\d+)$!' => 'noticeboard', // view noticeboard + '!^/log$!' => 'log', // modlog + '!^/log/(\d+)$!' => 'log', // modlog '!^/rebuild$!' => 'rebuild', // rebuild static files '!^/reports$!' => 'reports', // report queue '!^/reports/(\d+)/dismiss(all)?$!' => 'report_dismiss', // dismiss a report diff --git a/templates/mod/ban_list.html b/templates/mod/ban_list.html index 66471d6d..ea8183d6 100644 --- a/templates/mod/ban_list.html +++ b/templates/mod/ban_list.html @@ -75,7 +75,7 @@ {% if count > bans|count %}

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

diff --git a/templates/mod/log.html b/templates/mod/log.html index 19924b1d..9b0979cb 100644 --- a/templates/mod/log.html +++ b/templates/mod/log.html @@ -33,7 +33,7 @@ {% if count > logs|count %}

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

diff --git a/templates/mod/noticeboard.html b/templates/mod/noticeboard.html new file mode 100644 index 00000000..4d764d80 --- /dev/null +++ b/templates/mod/noticeboard.html @@ -0,0 +1,65 @@ +{% if mod|hasPermission(config.mod.noticeboard_post) %} +
+ {% trans 'New post' %} +
+ + + + + + + + + + + + + +
{% trans 'Name' %}{{ mod.username|e }}
{% trans 'Body' %}
+

+ +

+
+
+{% endif %} + +{% for post in noticeboard %} +
+ {% if mod|hasPermission(config.mod.noticeboard_delete) %} + + [{% trans 'delete' %}] + + {% endif %} +

+ + # + + {% if post.subject %} + {{ post.subject|e }} + {% else %} + {% trans 'no subject' %} + {% endif %} + + — by + {% if post.username %} + {{ post.username }} + {% else %} + deleted? + {% endif %} + at + {{ notice.time|date(config.post_date) }} + +

+

+ {{ post.body }} +

+
+{% endfor %} + +{% if count > noticeboard|count %} +

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

+{% endif %} -- cgit v1.3 From af61bcaf77204f7bd84ef482c489faa17b13a0b1 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Sun, 22 Apr 2012 17:50:53 +1000 Subject: Slightly less crappy stylesheet chooser --- inc/config.php | 2 +- inc/lib/Twig/Extensions/Extension/Tinyboard.php | 1 + stylesheets/default.css | 0 templates/main.js | 110 ++++++++++++++++-------- templates/page.html | 4 +- 5 files changed, 76 insertions(+), 41 deletions(-) delete mode 100644 stylesheets/default.css (limited to 'inc/lib') diff --git a/inc/config.php b/inc/config.php index c202d8c9..baa1d022 100644 --- a/inc/config.php +++ b/inc/config.php @@ -525,7 +525,7 @@ // $config['banner_height'] = 100; // Custom stylesheets available. The prefix for each stylesheet URI is defined below. - $config['stylesheets']['Yotsuba B'] = 'default.css'; + $config['stylesheets']['Yotsuba B'] = ''; // default $config['stylesheets']['Yotsuba'] = 'yotsuba.css'; // $config['stylesheets']['Futaba'] = 'futaba.css'; diff --git a/inc/lib/Twig/Extensions/Extension/Tinyboard.php b/inc/lib/Twig/Extensions/Extension/Tinyboard.php index c4810dad..0a128e7b 100644 --- a/inc/lib/Twig/Extensions/Extension/Tinyboard.php +++ b/inc/lib/Twig/Extensions/Extension/Tinyboard.php @@ -25,6 +25,7 @@ class Twig_Extensions_Extension_Tinyboard extends Twig_Extension 'until' => new Twig_Filter_Function('until'), 'split' => new Twig_Filter_Function('twig_split_filter'), 'push' => new Twig_Filter_Function('twig_push_filter'), + 'addslashes' => new Twig_Filter_Function('addslashes') ); } diff --git a/stylesheets/default.css b/stylesheets/default.css deleted file mode 100644 index e69de29b..00000000 diff --git a/templates/main.js b/templates/main.js index de62bd8b..b0a96393 100644 --- a/templates/main.js +++ b/templates/main.js @@ -1,12 +1,71 @@ {% raw %} -var selectedstyle = '{% endraw %}{{ config.default_stylesheet.0 }}{% raw %}'; -var styles = [ - {% endraw %}{% for stylesheet in stylesheets %}{% raw %}['{% endraw %}{{ stylesheet.name }}{% raw %}', '{% endraw %}{{ stylesheet.uri }}{% raw %}']{% endraw %}{% if not loop.last %}{% raw %}, - {% endraw %}{% endif %}{% endfor %}{% raw %} -]; var saved = {}; + +var selectedstyle = '{% endraw %}{{ config.default_stylesheet.0|addslashes }}{% raw %}'; +var styles = { + {% endraw %} + {% for stylesheet in stylesheets %}{% raw %}'{% endraw %}{{ stylesheet.name|addslashes }}{% raw %}' : '{% endraw %}{{ stylesheet.uri|addslashes }}{% raw %}', + {% endraw %}{% endfor %}{% raw %} +}; + +function changeStyle(styleName, link) { + localStorage.stylesheet = styleName; + + if (!document.getElementById('stylesheet')) { + var s = document.createElement('link'); + s.rel = 'stylesheet'; + s.type = 'text/css'; + s.id = 'stylesheet'; + var x = document.getElementsByTagName('head')[0]; + x.appendChild(s); + } + + document.getElementById('stylesheet').href = styles[styleName]; + selectedstyle = styleName; + + if (document.getElementsByClassName('styles').length != 0) { + var styleLinks = document.getElementsByClassName('styles')[0].childNodes; + for (i = 0; i < styleLinks.length; i++) { + styleLinks[i].className = ''; + } + } + + if (link) { + link.className = 'selected'; + } +} + +if (localStorage.stylesheet) { + for (styleName in styles) { + if (styleName == localStorage.stylesheet) { + changeStyle(styleName); + break; + } + } +} + +function init_stylechooser() { + var newElement = document.createElement('div'); + newElement.className = 'styles'; + + for (styleName in styles) { + var style = document.createElement('a'); + style.innerHTML = '[' + styleName + ']'; + style.onclick = function() { + changeStyle(this.innerHTML.substring(1, this.innerHTML.length - 1), this); + }; + if (styleName == selectedstyle) { + style.className = 'selected'; + } + style.href = 'javascript:void(0);'; + newElement.appendChild(style); + } + + document.getElementsByTagName('body')[0].insertBefore(newElement, document.getElementsByTagName('body')[0].lastChild.nextSibling); +} + function get_cookie(cookie_name) { var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)'); if (results) @@ -16,7 +75,7 @@ function get_cookie(cookie_name) { } function highlightReply(id) { - if(typeof window.event != "undefined" && event.which == 2) { + if (typeof window.event != "undefined" && event.which == 2) { // don't highlight on middle click return true; } @@ -57,6 +116,7 @@ function dopost(form) { return form.elements['body'].value != "" || form.elements['file'].value != ""; } + function citeReply(id) { var body = document.getElementById('body'); @@ -76,21 +136,6 @@ function citeReply(id) { } } -function changeStyle(x) { - localStorage.stylesheet = styles[x][1]; - document.getElementById('stylesheet').href = styles[x][1]; - selectedstyle = styles[x][0]; -} - -if(localStorage.stylesheet) { - for(var x = 0; x < styles.length ; x++) { - if(styles[x][1] == localStorage.stylesheet) { - changeStyle(x); - break; - } - } -} - function rememberStuff() { if (document.forms.post) { if (document.forms.post.password) { @@ -112,7 +157,7 @@ function rememberStuff() { if (get_cookie('{% endraw %}{{ config.cookies.js }}{% raw %}')) { // Remove successful posts var successful = JSON.parse(get_cookie('{% endraw %}{{ config.cookies.js }}{% raw %}')); - for(var url in successful) { + for (var url in successful) { saved[url] = null; } sessionStorage.body = JSON.stringify(saved); @@ -132,25 +177,13 @@ function rememberStuff() { } function init() { - var newElement = document.createElement('div'); - newElement.className = 'styles'; + init_stylechooser(); - for(x = 0; x < styles.length; x++) { - var style = document.createElement('a'); - style.innerHTML = '[' + styles[x][0] + ']'; - style.href = 'javascript:changeStyle(' + x + ');'; - if(selectedstyle == styles[x][0]) - style.className = 'selected'; - newElement.appendChild(style); - } - - document.getElementsByTagName('body')[0].insertBefore(newElement, document.getElementsByTagName('body')[0].lastChild.nextSibling) - - if(document.forms.postcontrols) { + if (document.forms.postcontrols) { document.forms.postcontrols.password.value = localStorage.password; } - if(window.location.hash.indexOf('q') != 1 && window.location.hash.substring(1)) + if (window.location.hash.indexOf('q') != 1 && window.location.hash.substring(1)) highlightReply(window.location.hash.substring(1)); } @@ -164,7 +197,7 @@ function onready(fnc) { } function ready() { - for(var i = 0; i < onready_callbacks.length; i++) { + for (var i = 0; i < onready_callbacks.length; i++) { onready_callbacks[i](); } } @@ -174,3 +207,4 @@ onready(init); {% endraw %}{% if config.google_analytics %}{% raw %} var _gaq = _gaq || [];_gaq.push(['_setAccount', '{% endraw %}{{ config.google_analytics }}{% raw %}']);{% endraw %}{% if config.google_analytics_domain %}{% raw %}_gaq.push(['_setDomainName', '{% endraw %}{{ config.google_analytics_domain }}{% raw %}']){% endraw %}{% endif %}{% if not config.google_analytics_domain %}{% raw %}_gaq.push(['_setDomainName', 'none']){% endraw %}{% endif %}{% raw %};_gaq.push(['_trackPageview']);(function() {var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);})();{% endraw %}{% endif %} + diff --git a/templates/page.html b/templates/page.html index a5dc3dc0..0f59e6b1 100644 --- a/templates/page.html +++ b/templates/page.html @@ -10,7 +10,7 @@ {% if not nojavascript %}{% endif %} - {% if pm %}
You have an unread PM{% if pm.waiting > 0 %}, plus {{ pm.waiting }} more waiting{% endif %}.

{% endif %} + {% if pm %}
You have an unread PM{% if pm.waiting > 0 %}, plus {{ pm.waiting }} more waiting{% endif %}.

{% endif %}

{{ title }}

@@ -21,7 +21,7 @@
{{ body }} -
+
-- cgit v1.3