From 78f3ea783394dba14b51b27f7f2db3974ce8b8b3 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Fri, 13 Apr 2012 09:29:08 +1000 Subject: View IP adress page, ban form. --- templates/mod/dashboard.html | 81 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 templates/mod/dashboard.html (limited to 'templates/mod/dashboard.html') diff --git a/templates/mod/dashboard.html b/templates/mod/dashboard.html new file mode 100644 index 00000000..2a90d709 --- /dev/null +++ b/templates/mod/dashboard.html @@ -0,0 +1,81 @@ +
+ Boards + + +
+ +{% if mod|hasPermission(config.mod.noticeboard) %} +
+ Noticeboard + + {# TODO #} +
+{% endif %} + +
+ Administration + + +
+ +{% if mod|hasPermission(config.mod.themes) %} +
+ Themes + + {# TODO #} +
+{% endif %} + +
+ Search + + {# TODO #} +
-- cgit v1.3 From cc614e36b4135d5b8ac000bad8ed450df0e61ffe Mon Sep 17 00:00:00 2001 From: Michael Save Date: Mon, 16 Apr 2012 20:11:10 +1000 Subject: multiple improvements --- inc/mod/ban.php | 2 +- inc/mod/pages.php | 80 ++++++++++++++++++++++++++++++++++++--- mod.php | 11 +++++- templates/mod/dashboard.html | 10 +++++ templates/mod/debug/antispam.html | 42 ++++++++++++++++++++ templates/page.html | 2 +- 6 files changed, 138 insertions(+), 9 deletions(-) create mode 100644 templates/mod/debug/antispam.html (limited to 'templates/mod/dashboard.html') diff --git a/inc/mod/ban.php b/inc/mod/ban.php index e7110edf..4d73488f 100644 --- a/inc/mod/ban.php +++ b/inc/mod/ban.php @@ -80,7 +80,7 @@ function ban($mask, $reason, $length, $board) { $query->execute() or error(db_error($query)); - modLog('Created a new ban (#' . $pdo->lastInsertId() . ') for ' . utf8tohtml($mask) . ' with ' . ($reason ? 'reason: ' . $reason . '' : 'no reason')); + modLog('Created a new ban (#' . $pdo->lastInsertId() . ') for ' . utf8tohtml($mask) . ' with ' . ($reason ? 'reason: ' . utf8tohtml($reason) . '' : 'no reason')); } function unban($id) { diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 3c3c08a4..7e6cddfe 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -15,6 +15,7 @@ function mod_page($title, $template, $args) { echo Element('page.html', array( 'config' => $config, 'mod' => $mod, + 'hide_dashboard_link' => $template == 'mod/dashboard.html', 'title' => $title, 'body' => Element($template, array_merge( @@ -262,10 +263,12 @@ function mod_bans($page_no = 1) { $unban[] = $match[1]; } - query('DELETE FROM `bans` WHERE `id` = ' . implode(' OR `id` = ', $unban)) or error(db_error()); + if (!empty($unban)) { + query('DELETE FROM `bans` WHERE `id` = ' . implode(' OR `id` = ', $unban)) or error(db_error()); - foreach ($unban as $id) { - modLog("Removed ban #{$id}"); + foreach ($unban as $id) { + modLog("Removed ban #{$id}"); + } } header('Location: ?/bans', true, $config['redirect_http']); @@ -278,8 +281,8 @@ function mod_bans($page_no = 1) { $query = prepare("SELECT `bans`.*, `username` FROM `bans` INNER JOIN `mods` ON `mod` = `mods`.`id` WHERE `expires` = 0 OR `expires` > :time ORDER BY `set` DESC LIMIT :offset, :limit"); } $query->bindValue(':time', time(), PDO::PARAM_INT); - $query->bindValue(':limit', $config['mod']['modlog_page'], PDO::PARAM_INT); - $query->bindValue(':offset', ($page_no - 1) * $config['mod']['modlog_page'], PDO::PARAM_INT); + $query->bindValue(':limit', $config['mod']['banlist_page'], PDO::PARAM_INT); + $query->bindValue(':offset', ($page_no - 1) * $config['mod']['banlist_page'], PDO::PARAM_INT); $query->execute() or error(db_error($query)); $bans = $query->fetchAll(PDO::FETCH_ASSOC); @@ -295,6 +298,58 @@ function mod_bans($page_no = 1) { mod_page('Ban list', 'mod/ban_list.html', array('bans' => $bans, 'count' => $count)); } + +function mod_lock($board, $unlock, $post) { + global $config; + + if (!openBoard($board)) + error($config['error']['noboard']); + + if (!hasPermission($config['mod']['lock'], $board)) + error($config['error']['noaccess']); + + $query = prepare(sprintf('UPDATE `posts_%s` SET `locked` = :locked WHERE `id` = :id AND `thread` IS NULL', $board)); + $query->bindValue(':id', $post); + $query->bindValue(':locked', $unlock ? 0 : 1); + $query->execute() or error(db_error($query)); + + header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); +} + +function mod_sticky($board, $unsticky, $post) { + global $config; + + if (!openBoard($board)) + error($config['error']['noboard']); + + if (!hasPermission($config['mod']['sticky'], $board)) + error($config['error']['noaccess']); + + $query = prepare(sprintf('UPDATE `posts_%s` SET `sticky` = :sticky WHERE `id` = :id AND `thread` IS NULL', $board)); + $query->bindValue(':id', $post); + $query->bindValue(':sticky', $unsticky ? 0 : 1); + $query->execute() or error(db_error($query)); + + header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); +} + +function mod_bumplock($board, $unbumplock, $post) { + global $config; + + if (!openBoard($board)) + error($config['error']['noboard']); + + if (!hasPermission($config['mod']['bumplock'], $board)) + error($config['error']['noaccess']); + + $query = prepare(sprintf('UPDATE `posts_%s` SET `sage` = :bumplock WHERE `id` = :id AND `thread` IS NULL', $board)); + $query->bindValue(':id', $post); + $query->bindValue(':bumplock', $unbumplock ? 0 : 1); + $query->execute() or error(db_error($query)); + + header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); +} + function mod_delete($board, $post) { global $config, $mod; @@ -599,4 +654,19 @@ function mod_report_dismiss($id, $all = false) { header('Location: ?/reports', true, $config['redirect_http']); } +function mod_debug_antispam() { + $args = array(); + + $query = query('SELECT COUNT(*) FROM `antispam`') or error(db_error()); + $args['total'] = number_format($query->fetchColumn(0)); + + $query = query('SELECT COUNT(*) FROM `antispam` WHERE `expires` IS NOT NULL') or error(db_error()); + $args['expiring'] = number_format($query->fetchColumn(0)); + + $query = query('SELECT * FROM `antispam` /* WHERE `passed` > 0 */ ORDER BY `passed` DESC LIMIT 25') or error(db_error()); + $args['top'] = $query->fetchAll(PDO::FETCH_ASSOC); + + mod_page("Debug: Anti-spam", 'mod/debug/antispam.html', $args); +} + diff --git a/mod.php b/mod.php index 86169b59..8af74a7b 100644 --- a/mod.php +++ b/mod.php @@ -43,10 +43,17 @@ $pages = array( '!^/bans/(\d+)$!' => 'bans', // ban list '!^/(\w+)/delete/(\d+)$!' => 'delete', // delete post + '!^/(\w+)/(un)?lock/(\d+)$!' => 'lock', // lock thread + '!^/(\w+)/(un)?sticky/(\d+)$!' => 'sticky', // sticky thread + '!^/(\w+)/bump(un)?lock/(\d+)$!' => 'bumplock', // "bumplock" thread + + // these pages aren't listed in the dashboard without $config['debug'] + '!^/debug/antispam$!' => 'debug_antispam', // This should always be at the end: - '!^/(\w+)/' . preg_quote($config['file_index'], '!') . '?$!' => 'view_board', - '!^/(\w+)/' . str_replace('%d', '(\d+)', preg_quote($config['file_page'], '!')) . '$!' => 'view_board', + '!^/(\w+)/$!' => 'view_board', + '!^/(\w+)/' . preg_quote($config['file_index'], '!') . '$!' => 'view_board', + '!^/(\w+)/' . str_replace('%d', '(\d+)', preg_quote($config['file_page'], '!')) . '$!' => 'view_board', '!^/(\w+)/' . preg_quote($config['dir']['res'], '!') . str_replace('%d', '(\d+)', preg_quote($config['file_page'], '!')) . '$!' => 'view_thread', ); diff --git a/templates/mod/dashboard.html b/templates/mod/dashboard.html index 2a90d709..e9290e12 100644 --- a/templates/mod/dashboard.html +++ b/templates/mod/dashboard.html @@ -79,3 +79,13 @@ {# TODO #} + +{% if config.debug %} +
+ Debug + +
+{% endif %} + diff --git a/templates/mod/debug/antispam.html b/templates/mod/debug/antispam.html new file mode 100644 index 00000000..af5354ed --- /dev/null +++ b/templates/mod/debug/antispam.html @@ -0,0 +1,42 @@ +

+ Most used (in active): +

+ + + + + + + + + + {% for hash in top %} + + + + + + + + + {% endfor %} +
BoardThreadHash (CRC32)CreatedExpiresPassed
{{ config.board_abbreviation|sprintf(hash.board) }} + {% if hash.thread %} + {{ hash.thread }} + {% else %} + - + {% endif %}{{ hash.hash }} + {{ hash.created|ago }} ago + + {% if hash.expires %} + + {{ hash.expires|until }} + + {% else %} + - + {% endif %} + {{ hash.passed }}
+

+ Total: {{ total }} ({{ expiring }} set to expire) +

+ diff --git a/templates/page.html b/templates/page.html index 39d73bbd..0c0264d1 100644 --- a/templates/page.html +++ b/templates/page.html @@ -17,7 +17,7 @@ {% if subtitle %} {{ subtitle }} {% endif %} - {% if mod %}

{% trans %}Return to dashboard{% endtrans %}

{% endif %} + {% if mod and not hide_dashboard_link %}

{% trans %}Return to dashboard{% endtrans %}

{% endif %} {{ body }} -- cgit v1.3 From 07fc56b80b36fcf41e8959844d1d8329a8852a99 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Fri, 20 Apr 2012 21:54:30 +1000 Subject: Noticeboard on dashboard --- inc/mod/pages.php | 14 +++++++++ templates/mod/dashboard.html | 67 +++++++++++++++++++++++++++++++------------- 2 files changed, 62 insertions(+), 19 deletions(-) (limited to 'templates/mod/dashboard.html') diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 78f560ec..e40dc241 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -61,10 +61,24 @@ function mod_confirm($request) { } function mod_dashboard() { + global $config; + $args = array(); $args['boards'] = listBoards(); + 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']) + cache::set('noticeboard_preview', $args['noticeboard']); + } + } + mod_page('Dashboard', 'mod/dashboard.html', $args); } diff --git a/templates/mod/dashboard.html b/templates/mod/dashboard.html index e9290e12..173c0e94 100644 --- a/templates/mod/dashboard.html +++ b/templates/mod/dashboard.html @@ -1,5 +1,5 @@
- Boards + {% trans 'Boards' %}
{% if mod|hasPermission(config.mod.noticeboard) %}
- Noticeboard - - {# TODO #} + {% trans 'Noticeboard' %} +
{% endif %}
- Administration + {% trans 'Administration' %}
{% if mod|hasPermission(config.mod.themes) %}
- Themes + {% trans 'Themes' %} {# TODO #}
{% endif %}
- Search + {% trans 'Search' %} {# TODO #}
{% if config.debug %}
- Debug + {% trans 'Debug' %}
{% endif %} -- cgit v1.3 From 2c1f14d24b644e02f59758d04e1a029e2e73ed5a Mon Sep 17 00:00:00 2001 From: Michael Save Date: Sat, 21 Apr 2012 12:42:41 +1000 Subject: Improvements to new mod panel --- inc/mod/pages.php | 2 +- templates/mod/dashboard.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'templates/mod/dashboard.html') diff --git a/inc/mod/pages.php b/inc/mod/pages.php index e40dc241..3754268d 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -508,7 +508,7 @@ function mod_user($uid) { return; } - if (hasPermission($config['dmod']['change_password']) && $uid == $mod['id'] && isset($_POST['password'])) { + 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); diff --git a/templates/mod/dashboard.html b/templates/mod/dashboard.html index 173c0e94..984aa03e 100644 --- a/templates/mod/dashboard.html +++ b/templates/mod/dashboard.html @@ -27,7 +27,7 @@
{% trans 'Noticeboard' %}
    - {% if noticeboard %} + {% if noticeboard|count > 0 %}
  • {% trans 'Latest posts:' %}
      -- cgit v1.3 From 19ea6e3d44186544c15166aa13e4faa1b8804c99 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Sat, 21 Apr 2012 15:29:57 +1000 Subject: ?/deletefile --- inc/mod/pages.php | 40 +++++++++++++++++++++++++++++++++++++--- mod.php | 1 + templates/mod/dashboard.html | 3 --- 3 files changed, 38 insertions(+), 6 deletions(-) (limited to 'templates/mod/dashboard.html') diff --git a/inc/mod/pages.php b/inc/mod/pages.php index d111a480..5bba5145 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -85,6 +85,9 @@ function mod_dashboard() { function mod_noticeboard($page_no = 1) { global $config, $pdo, $mod; + if ($page_no < 1) + error($config['error']['404']); + if (!hasPermission($config['mod']['noticeboard'])) error($config['error']['noaccess']); @@ -113,7 +116,7 @@ function mod_noticeboard($page_no = 1) { $query->execute() or error(db_error($query)); $noticeboard = $query->fetchAll(PDO::FETCH_ASSOC); - if (empty($noticeboard)) + if (empty($noticeboard) && $page_no > 1) error($config['error']['404']); $query = prepare("SELECT COUNT(*) FROM `noticeboard`"); @@ -126,6 +129,9 @@ function mod_noticeboard($page_no = 1) { function mod_log($page_no = 1) { global $config; + if ($page_no < 1) + error($config['error']['404']); + if (!hasPermission($config['mod']['modlog'])) error($config['error']['noaccess']); @@ -135,7 +141,7 @@ function mod_log($page_no = 1) { $query->execute() or error(db_error($query)); $logs = $query->fetchAll(PDO::FETCH_ASSOC); - if (empty($logs)) + if (empty($logs) && $page_no > 1) error($config['error']['404']); $query = prepare("SELECT COUNT(*) FROM `modlogs`"); @@ -308,6 +314,9 @@ function mod_ban() { function mod_bans($page_no = 1) { global $config; + if ($page_no < 1) + error($config['error']['404']); + if (!hasPermission($config['mod']['view_banlist'])) error($config['error']['noaccess']); @@ -344,7 +353,7 @@ function mod_bans($page_no = 1) { $query->execute() or error(db_error($query)); $bans = $query->fetchAll(PDO::FETCH_ASSOC); - if (empty($bans)) + if (empty($bans) && $page_no > 1) error($config['error']['404']); $query = prepare("SELECT COUNT(*) FROM `bans`"); @@ -505,6 +514,26 @@ function mod_delete($board, $post) { header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); } +function mod_deletefile($board, $post) { + global $config, $mod; + + if (!openBoard($board)) + error($config['error']['noboard']); + + if (!hasPermission($config['mod']['deletefile'], $board)) + error($config['error']['noaccess']); + + // Delete file + deleteFile($post); + // Record the action + modLog("Deleted file from post #{$post}"); + // Rebuild board + buildIndex(); + + // Redirect + header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); +} + function mod_user($uid) { global $config, $mod; @@ -699,6 +728,11 @@ function mod_rebuild() { $rebuilt_scripts = array(); if (isset($_POST['rebuild_cache'])) { + if ($config['cache']['enabled']) { + $log[] = 'Flushing cache'; + Cache::flush(); + } + $log[] = 'Clearing template cache'; load_twig(); $twig->clearCacheFiles(); diff --git a/mod.php b/mod.php index 4495ae52..f3726c24 100644 --- a/mod.php +++ b/mod.php @@ -47,6 +47,7 @@ $pages = array( '!^/(\w+)/delete/(\d+)$!' => 'delete', // delete post '!^/(\w+)/ban(&delete)?/(\d+)$!' => 'ban_post', // ban poster + '!^/(\w+)/deletefile/(\d+)$!' => 'deletefile', // delete file from post '!^/(\w+)/(un)?lock/(\d+)$!' => 'lock', // lock thread '!^/(\w+)/(un)?sticky/(\d+)$!' => 'sticky', // sticky thread '!^/(\w+)/bump(un)?lock/(\d+)$!' => 'bumplock', // "bumplock" thread diff --git a/templates/mod/dashboard.html b/templates/mod/dashboard.html index 984aa03e..fc510ac7 100644 --- a/templates/mod/dashboard.html +++ b/templates/mod/dashboard.html @@ -84,9 +84,6 @@ {% if mod|hasPermission(config.mod.rebuild) %}
    • {% trans 'Rebuild' %}
    • - {% if config.cache.enabled %} -
    • {% trans 'Clear cache' %}
    • - {% endif %} {% endif %} {% if mod|hasPermission(config.mod.show_config) %} -- cgit v1.3 From a6104587203f1b1b448e6977066d6e649de91ae8 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Sun, 6 May 2012 01:33:10 +1000 Subject: a lot more improvements --- inc/config.php | 5 +- inc/functions.php | 25 +- inc/mod/pages.php | 396 +++++++++++++++++++++++++++++-- install.php | 4 +- js/show-op.js | 2 - mod.php | 39 ++- templates/generic_page.html | 71 ++++++ templates/index.html | 16 +- templates/mod/ban_form.html | 20 +- templates/mod/ban_list.html | 24 +- templates/mod/board.html | 44 ++++ templates/mod/confirm.html | 4 +- templates/mod/dashboard.html | 56 ++++- templates/mod/inbox.html | 36 +++ templates/mod/log.html | 18 +- templates/mod/login.html | 4 +- templates/mod/new_pm.html | 6 +- templates/mod/news.html | 70 ++++++ templates/mod/noticeboard.html | 8 +- templates/mod/pm.html | 14 +- templates/mod/rebuild.html | 20 +- templates/mod/rebuilt.html | 4 +- templates/mod/report.html | 12 +- templates/mod/reports.html | 3 +- templates/mod/user.html | 64 +++-- templates/mod/users.html | 57 +++-- templates/mod/view_ip.html | 72 +++--- templates/page.html | 10 +- templates/themes/basic/info.php | 4 +- templates/themes/basic/theme.php | 2 +- templates/themes/categories/info.php | 4 +- templates/themes/categories/sidebar.html | 2 +- templates/themes/categories/theme.php | 12 +- templates/themes/frameset/sidebar.html | 2 +- templates/themes/frameset/theme.php | 6 +- templates/themes/recent/info.php | 6 +- templates/themes/recent/theme.php | 28 +-- templates/themes/rrdtool/info.php | 16 +- templates/themes/rrdtool/theme.php | 54 +++-- templates/thread.html | 17 +- 40 files changed, 986 insertions(+), 271 deletions(-) create mode 100644 templates/generic_page.html create mode 100644 templates/mod/board.html create mode 100644 templates/mod/inbox.html create mode 100644 templates/mod/news.html (limited to 'templates/mod/dashboard.html') diff --git a/inc/config.php b/inc/config.php index 414d5262..c202d8c9 100644 --- a/inc/config.php +++ b/inc/config.php @@ -816,8 +816,6 @@ // Do a DNS lookup on IP addresses to get their hostname on the IP summary page $config['mod']['dns_lookup'] = true; - // Show ban form on the IP summary page - $config['mod']['ip_banform'] = true; // How many recent posts, per board, to show in the IP summary page $config['mod']['ip_recentposts'] = 5; @@ -829,6 +827,9 @@ // How many bans to show per page in the ban list $config['mod']['banlist_page'] = 350; + // Number of news entries to display per page + $config['mod']['news_page'] = 40; + // Maximum number of results to display for a search, per board $config['mod']['search_results'] = 75; diff --git a/inc/functions.php b/inc/functions.php index 3ca5f599..ac0a1c96 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -32,7 +32,30 @@ function loadConfig() { if (!isset($_SERVER['REMOTE_ADDR'])) $_SERVER['REMOTE_ADDR'] = '0.0.0.0'; - $arrays = array('db', 'cache', 'cookies', 'error', 'dir', 'mod', 'spam', 'flood_filters', 'wordfilters', 'custom_capcode', 'custom_tripcode', 'dnsbl', 'dnsbl_exceptions', 'remote', 'allowed_ext', 'allowed_ext_files', 'file_icons', 'footer', 'stylesheets', 'additional_javascript', 'markup'); + $arrays = array( + 'db', + 'cache', + 'cookies', + 'error', + 'dir', + 'mod', + 'spam', + 'flood_filters', + 'wordfilters', + 'custom_capcode', + 'custom_tripcode', + 'dnsbl', + 'dnsbl_exceptions', + 'remote', + 'allowed_ext', + 'allowed_ext_files', + 'file_icons', + 'footer', + 'stylesheets', + 'additional_javascript', + 'markup', + 'custom_pages' + ); $config = array(); foreach ($arrays as $key) { diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 260ad94c..c56570a5 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -9,7 +9,7 @@ if (realpath($_SERVER['SCRIPT_FILENAME']) == str_replace('\\', '/', __FILE__)) { exit; } -function mod_page($title, $template, $args) { +function mod_page($title, $template, $args, $subtitle = false) { global $config, $mod; echo Element('page.html', array( @@ -17,6 +17,7 @@ function mod_page($title, $template, $args) { 'mod' => $mod, 'hide_dashboard_link' => $template == 'mod/dashboard.html', 'title' => $title, + 'subtitle' => $subtitle, 'body' => Element($template, array_merge( array('config' => $config, 'mod' => $mod), @@ -28,6 +29,8 @@ function mod_page($title, $template, $args) { } function mod_login() { + global $config; + $args = array(); if (isset($_POST['login'])) { @@ -60,8 +63,14 @@ function mod_confirm($request) { mod_page('Confirm action', 'mod/confirm.html', array('request' => $request)); } +function mod_logout() { + destroyCookies(); + + header('Location: ?/', true, $config['redirect_http']); +} + function mod_dashboard() { - global $config; + global $config, $mod; $args = array(); @@ -79,9 +88,180 @@ function mod_dashboard() { } } + $query = prepare('SELECT COUNT(*) FROM `pms` WHERE `to` = :id AND `unread` = 1'); + $query->bindValue(':id', $mod['id']); + $query->execute() or error(db_error($query)); + $args['unread_pms'] = $query->fetchColumn(0); + + if ($mod['type'] >= ADMIN && $config['check_updates']) { + if (!$config['version']) + error(_('Could not find current version! (Check .installed)')); + + if (isset($_COOKIE['update'])) { + $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)) { + eval($code); + if (preg_match('/v(\d+)\.(\d)\.(\d+)(-dev.+)?$/', $config['version'], $matches)) { + $current = array( + 'massive' => (int) $matches[1], + 'major' => (int) $matches[2], + 'minor' => (int) $matches[3] + ); + if (isset($m[4])) { + // Development versions are always ahead in the versioning numbers + $current['minor'] --; + } + // Check if it's newer + if (!( $latest['massive'] > $current['massive'] || + $latest['major'] > $current['major'] || + ($latest['massive'] == $current['massive'] && + $latest['major'] == $current['major'] && + $latest['minor'] > $current['minor'] + ))) + $latest = false; + } else { + $latest = false; + } + } else { + // Couldn't get latest version + $latest = false; + } + + setcookie('update', serialize($latest), time() + $config['check_updates_time'], $config['cookies']['jail'] ? $config['cookies']['path'] : '/', null, false, true); + } + + if ($latest) + $args['newer_release'] = $latest; + } + mod_page('Dashboard', 'mod/dashboard.html', $args); } +function mod_edit_board($boardName) { + global $board, $config; + + if (!openBoard($boardName)) + error($config['error']['noboard']); + + if (!hasPermission($config['mod']['manageboards'], $board['uri'])) + error($config['error']['noaccess']); + + if (isset($_POST['title'], $_POST['subtitle'])) { + if (isset($_POST['delete'])) { + if (!hasPermission($config['mod']['manageboards'], $board['uri'])) + error($config['error']['deleteboard']); + + $query = prepare('DELETE FROM `boards` WHERE `uri` = :uri'); + $query->bindValue(':uri', $board['uri']); + $query->execute() or error(db_error($query)); + + modLog('Deleted board: ' . sprintf($config['board_abbreviation'], $board['uri']), false); + + // Delete entire board directory + rrmdir($board['uri'] . '/'); + + // Delete posting table + $query = query(sprintf('DROP TABLE IF EXISTS `posts_%s`', $board['uri'])) or error(db_error()); + + // Clear reports + $query = prepare('DELETE FROM `reports` WHERE `board` = :id'); + $query->bindValue(':id', $board['uri'], PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + + // Delete from table + $query = prepare('DELETE FROM `boards` WHERE `uri` = :uri'); + $query->bindValue(':uri', $board['uri'], PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + + if ($config['cache']['enabled']) { + cache::delete('board_' . $board['uri']); + cache::delete('all_boards'); + } + + $query = prepare("SELECT `board`, `post` FROM `cites` WHERE `target_board` = :board"); + $query->bindValue(':board', $board['uri']); + $query->execute() or error(db_error($query)); + while ($cite = $query->fetch(PDO::FETCH_ASSOC)) { + if ($board['uri'] != $cite['board']) { + if (!isset($tmp_board)) + $tmp_board = $board; + openBoard($cite['board']); + rebuildPost($cite['post']); + } + } + + $query = prepare('DELETE FROM `cites` WHERE `board` = :board OR `target_board` = :board'); + $query->bindValue(':board', $board['uri']); + $query->execute() or error(db_error($query)); + + $query = prepare('DELETE FROM `antispam` WHERE `board` = :board'); + $query->bindValue(':board', $board['uri']); + $query->execute() or error(db_error($query)); + } else { + $query = prepare('UPDATE `boards` SET `title` = :title, `subtitle` = :subtitle WHERE `uri` = :uri'); + $query->bindValue(':uri', $board['uri']); + $query->bindValue(':title', $_POST['title']); + $query->bindValue(':subtitle', $_POST['subtitle']); + $query->execute() or error(db_error($query)); + } + + rebuildThemes('boards'); + + header('Location: ?/', true, $config['redirect_http']); + } else { + mod_page('Edit board: ' . sprintf($config['board_abbreviation'], $board['uri']), 'mod/board.html', array('board' => $board)); + } +} + +function mod_new_board() { + global $config, $board; + + if (!hasPermission($config['mod']['newboard'])) + error($config['error']['noaccess']); + + if (isset($_POST['uri'], $_POST['title'], $_POST['subtitle'])) { + if ($_POST['uri'] == '') + error(sprintf($config['error']['required'], 'URI')); + + if ($_POST['title'] == '') + error(sprintf($config['error']['required'], 'title')); + + if (!preg_match('/^\w+$/', $_POST['uri'])) + error(sprintf($config['error']['invalidfield'], 'URI')); + + if (openBoard($_POST['uri'])) { + error(sprintf($config['error']['boardexists'], $board['url'])); + } + + $query = prepare('INSERT INTO `boards` VALUES (:uri, :title, :subtitle)'); + $query->bindValue(':uri', $_POST['uri']); + $query->bindValue(':title', $_POST['title']); + $query->bindValue(':subtitle', $_POST['subtitle']); + $query->execute() or error(db_error($query)); + + modLog('Created a new board: ' . sprintf($config['board_abbreviation'], $_POST['uri'])); + + if (!openBoard($_POST['uri'])) + error(_("Couldn't open board after creation.")); + + query(Element('posts.sql', array('board' => $board['uri']))) or error(db_error()); + + if ($config['cache']['enabled']) + cache::delete('all_boards'); + + // Build the board + buildIndex(); + + rebuildThemes('boards'); + + header('Location: ?/' . $board['uri'] . '/' . $config['file_index'], true, $config['redirect_http']); + } + + mod_page('New board', 'mod/board.html', array('new' => true)); +} + function mod_noticeboard($page_no = 1) { global $config, $pdo, $mod; @@ -104,9 +284,11 @@ function mod_noticeboard($page_no = 1) { $query->bindValue(':body', $_POST['body']); $query->execute() or error(db_error($query)); - if($config['cache']['enabled']) + if ($config['cache']['enabled']) cache::delete('noticeboard_preview'); + modLog('Posted a noticeboard entry'); + header('Location: ?/noticeboard#' . $pdo->lastInsertId(), true, $config['redirect_http']); } @@ -126,6 +308,78 @@ function mod_noticeboard($page_no = 1) { mod_page('Noticeboard', 'mod/noticeboard.html', array('noticeboard' => $noticeboard, 'count' => $count)); } +function mod_noticeboard_delete($id) { + global $config; + + if (!hasPermission($config['mod']['noticeboard_delete'])) + error($config['error']['noaccess']); + + $query = prepare('DELETE FROM `noticeboard` WHERE `id` = :id'); + $query->bindValue(':id', $id); + $query->execute() or error(db_error($query)); + + modLog('Deleted a noticeboard entry'); + + header('Location: ?/noticeboard', true, $config['redirect_http']); +} + +function mod_news($page_no = 1) { + global $config, $pdo, $mod; + + if ($page_no < 1) + error($config['error']['404']); + + if (isset($_POST['subject'], $_POST['body'])) { + if (!hasPermission($config['mod']['news'])) + error($config['error']['noaccess']); + + markup($_POST['body']); + + $query = prepare('INSERT INTO `news` VALUES (NULL, :name, :time, :subject, :body)'); + $query->bindValue(':name', isset($_POST['name']) && hasPermission($config['mod']['news_custom']) ? $_POST['name'] : $mod['username']); + $query->bindvalue(':time', time()); + $query->bindValue(':subject', $_POST['subject']); + $query->bindValue(':body', $_POST['body']); + $query->execute() or error(db_error($query)); + + modLog('Posted a news entry'); + + rebuildThemes('news'); + + header('Location: ?/news#' . $pdo->lastInsertId(), true, $config['redirect_http']); + } + + $query = prepare("SELECT * FROM `news` ORDER BY `id` DESC LIMIT :offset, :limit"); + $query->bindValue(':limit', $config['mod']['news_page'], PDO::PARAM_INT); + $query->bindValue(':offset', ($page_no - 1) * $config['mod']['news_page'], PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + $news = $query->fetchAll(PDO::FETCH_ASSOC); + + if (empty($news) && $page_no > 1) + error($config['error']['404']); + + $query = prepare("SELECT COUNT(*) FROM `news`"); + $query->execute() or error(db_error($query)); + $count = $query->fetchColumn(0); + + mod_page('News', 'mod/news.html', array('news' => $news, 'count' => $count)); +} + +function mod_news_delete($id) { + global $config; + + if (!hasPermission($config['mod']['news_delete'])) + error($config['error']['noaccess']); + + $query = prepare('DELETE FROM `news` WHERE `id` = :id'); + $query->bindValue(':id', $id); + $query->execute() or error(db_error($query)); + + modLog('Deleted a news entry'); + + header('Location: ?/news', true, $config['redirect_http']); +} + function mod_log($page_no = 1) { global $config; @@ -135,7 +389,7 @@ function mod_log($page_no = 1) { if (!hasPermission($config['mod']['modlog'])) error($config['error']['noaccess']); - $query = prepare("SELECT `username`, `ip`, `board`, `time`, `text` FROM `modlogs` LEFT JOIN `mods` ON `mod` = `mods`.`id` ORDER BY `time` DESC LIMIT :offset, :limit"); + $query = prepare("SELECT `username`, `mod`, `ip`, `board`, `time`, `text` FROM `modlogs` LEFT JOIN `mods` ON `mod` = `mods`.`id` ORDER BY `time` DESC LIMIT :offset, :limit"); $query->bindValue(':limit', $config['mod']['modlog_page'], PDO::PARAM_INT); $query->bindValue(':offset', ($page_no - 1) * $config['mod']['modlog_page'], PDO::PARAM_INT); $query->execute() or error(db_error($query)); @@ -196,7 +450,7 @@ function mod_ip_remove_note($ip, $id) { modLog("Removed a note for {$ip}"); - header('Location: ?/IP/' . $ip, true, $config['redirect_http']); + header('Location: ?/IP/' . $ip . '#notes', true, $config['redirect_http']); } function mod_page_ip($ip) { @@ -212,7 +466,8 @@ function mod_page_ip($ip) { require_once 'inc/mod/ban.php'; unban($_POST['ban_id']); - header('Location: ?/IP/' . $ip, true, $config['redirect_http']); + + header('Location: ?/IP/' . $ip . '#bans', true, $config['redirect_http']); return; } @@ -230,7 +485,7 @@ function mod_page_ip($ip) { modLog("Added a note for {$ip}"); - header('Location: ?/IP/' . $ip, true, $config['redirect_http']); + header('Location: ?/IP/' . $ip . '#notes', true, $config['redirect_http']); return; } @@ -238,6 +493,9 @@ function mod_page_ip($ip) { $args['ip'] = $ip; $args['posts'] = array(); + if ($config['mod']['dns_lookup']) + $args['hostname'] = rDNS($ip); + $boards = listBoards(); foreach ($boards as $board) { openBoard($board['uri']); @@ -287,7 +545,7 @@ function mod_page_ip($ip) { $args['notes'] = $query->fetchAll(PDO::FETCH_ASSOC); } - mod_page("IP: $ip", 'mod/view_ip.html', $args); + mod_page("IP: $ip", 'mod/view_ip.html', $args, $args['hostname']); } function mod_ban() { @@ -382,7 +640,7 @@ function mod_lock($board, $unlock, $post) { $query->bindValue(':id', $post); $query->bindValue(':locked', $unlock ? 0 : 1); $query->execute() or error(db_error($query)); - if($query->rowCount()) { + if ($query->rowCount()) { modLog(($unlock ? 'Unlocked' : 'Locked') . " thread #{$post}"); buildThread($post); buildIndex(); @@ -404,7 +662,7 @@ function mod_sticky($board, $unsticky, $post) { $query->bindValue(':id', $post); $query->bindValue(':sticky', $unsticky ? 0 : 1); $query->execute() or error(db_error($query)); - if($query->rowCount()) { + if ($query->rowCount()) { modLog(($unlock ? 'Unstickied' : 'Stickied') . " thread #{$post}"); buildThread($post); buildIndex(); @@ -426,7 +684,7 @@ function mod_bumplock($board, $unbumplock, $post) { $query->bindValue(':id', $post); $query->bindValue(':bumplock', $unbumplock ? 0 : 1); $query->execute() or error(db_error($query)); - if($query->rowCount()) { + if ($query->rowCount()) { modLog(($unlock ? 'Unbumplocked' : 'Bumplocked') . " thread #{$post}"); buildThread($post); buildIndex(); @@ -447,7 +705,7 @@ function mod_ban_post($board, $delete, $post) { $query = prepare(sprintf('SELECT `ip`, `thread` 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)) + if (!$_post = $query->fetch(PDO::FETCH_ASSOC)) error($config['error']['404']); $thread = $_post['thread']; @@ -624,25 +882,54 @@ function mod_user($uid) { } } + if (isset($_POST['delete'])) { + if (!hasPermission($config['mod']['deleteusers'])) + error($config['error']['noaccess']); + + $query = prepare('DELETE FROM `mods` WHERE `id` = :id'); + $query->bindValue(':id', $uid); + $query->execute() or error(db_error($query)); + + modLog('Deleted user ' . utf8tohtml($user['username']) . ' (#' . $user['id'] . ')'); + + header('Location: ?/users', true, $config['redirect_http']); + + return; + } + + if ($_POST['username'] == '') + error(sprintf($config['error']['required'], 'username')); + $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 ($user['username'] !== $_POST['username']) { + // account was renamed + modLog('Renamed user "' . utf8tohtml($user['username']) . '" (#' . $user['id'] . ') to "' . utf8tohtml($_POST['username']) . '"'); + } + 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)); + modLog('Changed password for ' . utf8tohtml($_POST['username']) . ' (#' . $user['id'] . ')'); + if ($uid == $mod['id']) { login($_POST['username'], $_POST['password']); setCookies(); } } - header('Location: ?/users', true, $config['redirect_http']); + if (hasPermission($config['mod']['manageusers'])) + header('Location: ?/users', true, $config['redirect_http']); + else + header('Location: ?/', true, $config['redirect_http']); + return; } @@ -653,11 +940,17 @@ function mod_user($uid) { $query->bindValue(':password', $_POST['password']); $query->execute() or error(db_error($query)); - login($_POST['username'], $_POST['password']); + modLog('Changed own password'); + + login($user['username'], $_POST['password']); setCookies(); } - header('Location: ?/users', true, $config['redirect_http']); + if (hasPermission($config['mod']['manageusers'])) + header('Location: ?/users', true, $config['redirect_http']); + else + header('Location: ?/', true, $config['redirect_http']); + return; } @@ -675,6 +968,47 @@ function mod_user($uid) { mod_page('Edit user', 'mod/user.html', array('user' => $user, 'logs' => $log, 'boards' => listBoards())); } +function mod_user_new() { + if (isset($_POST['username'], $_POST['password'], $_POST['type'])) { + if ($_POST['username'] == '') + error(sprintf($config['error']['required'], 'username')); + if ($_POST['password'] == '') + error(sprintf($config['error']['required'], '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]; + } + } + + $_POST['type'] = (int) $_POST['type']; + if ($_POST['type'] !== JANITOR && $_POST['type'] !== MOD && $_POST['type'] !== ADMIN) + error(sprintf($config['error']['invalidfield'], 'type')); + + $query = prepare('INSERT INTO `mods` VALUES (NULL, :username, SHA1(:password), :type, :boards)'); + $query->bindValue(':username', $_POST['username']); + $query->bindValue(':password', $_POST['password']); + $query->bindValue(':type', $_POST['type']); + $query->bindValue(':boards', implode(',', $boards)); + $query->execute() or error(db_error($query)); + + header('Location: ?/users', true, $config['redirect_http']); + return; + } + + mod_page('Edit user', 'mod/user.html', array('new' => true, 'boards' => listBoards())); +} + + function mod_users() { global $config; @@ -734,12 +1068,38 @@ function mod_pm($id, $reply = false) { if (!$pm['to_username']) error($config['error']['404']); // deleted? - mod_page("New PM for {$pm['to_username']}", 'mod/new_pm.html', array('username' => $pm['to_username'], 'id' => $pm['to'], 'message' => quote($pm['message']))); + mod_page("New PM for {$pm['to_username']}", 'mod/new_pm.html', array( + 'username' => $pm['username'], 'id' => $pm['sender'], 'message' => quote($pm['message']) + )); } else { mod_page("Private message – #$id", 'mod/pm.html', $pm); } } +function mod_inbox() { + global $config, $mod; + + $query = prepare('SELECT `unread`,`pms`.`id`, `time`, `sender`, `to`, `message`, `username` FROM `pms` LEFT JOIN `mods` ON `mods`.`id` = `sender` WHERE `to` = :mod ORDER BY `unread` DESC, `time` DESC'); + $query->bindValue(':mod', $mod['id']); + $query->execute() or error(db_error($query)); + $messages = $query->fetchAll(PDO::FETCH_ASSOC); + + $query = prepare('SELECT COUNT(*) FROM `pms` WHERE `to` = :mod AND `unread` = 1'); + $query->bindValue(':mod', $mod['id']); + $query->execute() or error(db_error($query)); + $unread = $query->fetchColumn(0); + + foreach ($messages as &$message) { + $message['snippet'] = pm_snippet($message['message']); + } + + mod_page('PM inbox (' . (count($messages) > 0 ? $unread . ' unread' : 'empty') . ')', 'mod/inbox.html', array( + 'messages' => $messages, + 'unread' => $unread + )); +} + + function mod_new_pm($username) { global $config, $mod; @@ -920,7 +1280,7 @@ function mod_reports() { $body .= $po->build(true) . '
      '; - if(isset($__old_body_truncate_char)) + if (isset($__old_body_truncate_char)) $config['body_truncate_char'] = $__old_body_truncate_char; } @@ -971,7 +1331,7 @@ function mod_debug_antispam() { if (isset($_POST['board'], $_POST['thread'])) { $where = '`board` = ' . $pdo->quote($_POST['board']); - if($_POST['thread'] != '') + if ($_POST['thread'] != '') $where .= ' AND `thread` = ' . $pdo->quote($_POST['thread']); if (isset($_POST['purge'])) { diff --git a/install.php b/install.php index 2e732c4c..1e872911 100644 --- a/install.php +++ b/install.php @@ -1,7 +1,7 @@ ':?/', // redirect to dashboard '!^/$!' => 'dashboard', // dashboard '!^/confirm/(.+)$!' => 'confirm', // confirm action (if javascript didn't work) + '!^/logout$!' => 'logout', // logout '!^/users$!' => 'users', // manage users '!^/users/(\d+)$!' => 'user', // edit user '!^/users/(\d+)/(promote|demote)$!' => 'user_promote', // prmote/demote user + '!^/users/new$!' => 'user_new', // create a new user '!^/new_PM/([^/]+)$!' => 'new_pm', // create a new pm '!^/PM/(\d+)(/reply)?$!' => 'pm', // read a pm + '!^/inbox$!' => 'inbox', // pm inbox '!^/noticeboard$!' => 'noticeboard', // view noticeboard '!^/noticeboard/(\d+)$!' => 'noticeboard', // view noticeboard + '!^/noticeboard/delete/(\d+)$!' => 'noticeboard_delete',// delete from noticeboard '!^/log$!' => 'log', // modlog '!^/log/(\d+)$!' => 'log', // modlog + '!^/news$!' => 'news', // view news + '!^/news/(\d+)$!' => 'news', // view news + '!^/news/delete/(\d+)$!' => 'news_delete', // delete from news + + '!^/edit/(\w+)$!' => 'edit_board', // edit board details + '!^/new-board$!' => 'new_board', // create a new board + '!^/rebuild$!' => 'rebuild', // rebuild static files '!^/reports$!' => 'reports', // report queue '!^/reports/(\d+)/dismiss(all)?$!' => 'report_dismiss', // dismiss a report @@ -64,8 +75,14 @@ $pages = array( str_replace('%d', '(\d+)', preg_quote($config['file_page'], '!')) . '$!' => 'view_thread', ); -if (!$mod) + +if (!$mod) { $pages = array('//' => 'login'); +} elseif (isset($_GET['status'], $_GET['r'])) { + header('Location: ' . $_GET['r'], true, (int)$_GET['stats']); +} elseif (isset($config['mod']['custom_pages'])) { + $pages = array_merge($pages, $config['mod']['custom_pages']); +} foreach ($pages as $uri => $handler) { if (preg_match($uri, $query, $matches)) { @@ -79,14 +96,20 @@ foreach ($pages as $uri => $handler) { ); } - if ($handler[0] == ':') { - header('Location: ' . substr($handler, 1), true, $config['redirect_http']); - } elseif (is_callable("mod_page_$handler")) { - call_user_func_array("mod_page_$handler", $matches); - } elseif (is_callable("mod_$handler")) { - call_user_func_array("mod_$handler", $matches); + if (is_string($handler)) { + if ($handler[0] == ':') { + header('Location: ' . substr($handler, 1), true, $config['redirect_http']); + } elseif (is_callable("mod_page_$handler")) { + call_user_func_array("mod_page_$handler", $matches); + } elseif (is_callable("mod_$handler")) { + call_user_func_array("mod_$handler", $matches); + } else { + error("Mod page '$handler' not found!"); + } + } elseif (is_callable($handler)) { + call_user_func_array($handler, $matches); } else { - error("Mod page '$handler' not found!"); + error("Mod page '$handler' not a string, and not callable!"); } exit; diff --git a/templates/generic_page.html b/templates/generic_page.html new file mode 100644 index 00000000..e834aad0 --- /dev/null +++ b/templates/generic_page.html @@ -0,0 +1,71 @@ + + + + {% block head %} + + {% if config.url_favicon %}{% endif %} + {{ board.url }} - {{ board.name }} + + + {% if config.meta_keywords %}{% endif %} + {% if config.default_stylesheet.1 != '' %}{% endif %} + {% if not nojavascript %} + + {% if not config.additional_javascript_compile %} + {% for javascript in config.additional_javascript %}{% endfor %} + {% endif %} + {% endif %} + {% if config.recaptcha %}{% endif %} + {% endblock %} + + + {{ boardlist.top }} + {% if pm %}
      You have an unread PM{% if pm.waiting > 0 %}, plus {{ pm.waiting }} more waiting{% endif %}.

      {% endif %} + {% if config.url_banner %}{% endif %} +
      +

      {{ board.url }} - {{ board.name }}

      +
      + {% if board.title %} + {{ board.title|e }} + {% endif %} + {% if mod %}

      {% trans %}Return to dashboard{% endtrans %}

      {% endif %} +
      +
      + + {% include 'post_form.html' %} + + {% if config.blotter %}
      {{ config.blotter }}
      {% endif %} +
      +
      + + {% if mod %}{% endif %} + {{ body }} + {% include 'report_delete.html' %} +
      +
      {{ btn.prev }} {% for page in pages %} + [{{ page.num }}]{% if loop.last %} {% endif %} + {% endfor %} {{ btn.next }}
      + {{ boardlist.bottom }} +
      +

      Powered by Tinyboard {{ config.version }} | Tinyboard Copyright © 2010-2012 Tinyboard Development Group

      + {% for footer in config.footer %}

      {{ footer }}

      {% endfor %} +
      + + + diff --git a/templates/index.html b/templates/index.html index f12e2517..a28724a1 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,13 +1,13 @@ - - {% if config.url_favicon %}{% endif %} + + + {% if config.url_favicon %}{% endif %} {{ board.url }} - {{ board.name }} - - - {% if config.meta_keywords %}{% endif %} - + + {% if config.meta_keywords %}{% endif %} + {% if config.default_stylesheet.1 != '' %}{% endif %} {% if not nojavascript %} {% if not config.additional_javascript_compile %} @@ -35,10 +35,10 @@ {% if pm %}
      You have an unread PM{% if pm.waiting > 0 %}, plus {{ pm.waiting }} more waiting{% endif %}.

      {% endif %} {% if config.url_banner %}{% endif %}
      -

      {{ board.url }} - {{ board.title }}

      +

      {{ board.url }} - {{ board.title|e }}

      {% if board.subtitle %} - {{ board.subtitle }} + {{ board.subtitle|e }} {% endif %} {% if mod %}

      {% trans %}Return to dashboard{% endtrans %}

      {% endif %}
      diff --git a/templates/mod/ban_form.html b/templates/mod/ban_form.html index 9d4d6728..5d5f2b81 100644 --- a/templates/mod/ban_form.html +++ b/templates/mod/ban_form.html @@ -16,19 +16,19 @@ - + {% if not hide_ip %} {% else %} - hidden + {% trans 'hidden' %} {% endif %} - + @@ -37,12 +37,12 @@ {% if post and board and not delete %} - + - (public; attached to post) + ({% trans 'public; attached to post' %}) {% endif %} diff --git a/templates/themes/basic/info.php b/templates/themes/basic/info.php index b782a6d4..0b8ba98b 100644 --- a/templates/themes/basic/info.php +++ b/templates/themes/basic/info.php @@ -44,9 +44,9 @@ $theme['build_function'] = 'basic_build'; $theme['install_callback'] = 'build_install'; - if(!function_exists('build_install')) { + if (!function_exists('build_install')) { function build_install($settings) { - if(!is_numeric($settings['no_recent']) || $settings['no_recent'] < 0) + if (!is_numeric($settings['no_recent']) || $settings['no_recent'] < 0) return Array(false, '' . utf8tohtml($settings['no_recent']) . ' is not a non-negative integer.'); } } diff --git a/templates/themes/basic/theme.php b/templates/themes/basic/theme.php index a07dc7ec..806a331a 100644 --- a/templates/themes/basic/theme.php +++ b/templates/themes/basic/theme.php @@ -15,7 +15,7 @@ public static function build($action, $settings) { global $config; - if($action == 'all' || $action == 'news') + if ($action == 'all' || $action == 'news') file_write($config['dir']['home'] . $settings['file'], Basic::homepage($settings)); } diff --git a/templates/themes/categories/info.php b/templates/themes/categories/info.php index 5ae3d296..62d8f6bb 100644 --- a/templates/themes/categories/info.php +++ b/templates/themes/categories/info.php @@ -54,11 +54,11 @@ Requires $config[\'categories\'].'; $theme['build_function'] = 'categories_build'; $theme['install_callback'] = 'categories_install'; - if(!function_exists('categories_install')) { + if (!function_exists('categories_install')) { function categories_install($settings) { global $config; - if(!isset($config['categories'])) { + if (!isset($config['categories'])) { return Array(false, '

      Prerequisites not met!

      ' . 'This theme requires $config[\'boards\'] and $config[\'categories\'] to be set.'); } diff --git a/templates/themes/categories/sidebar.html b/templates/themes/categories/sidebar.html index a4bc28ae..856930ab 100644 --- a/templates/themes/categories/sidebar.html +++ b/templates/themes/categories/sidebar.html @@ -31,7 +31,7 @@ {% for board in boards %}
    • - {{ board.title }} + {{ board.title|e }}
    • {% endfor %}
diff --git a/templates/themes/categories/theme.php b/templates/themes/categories/theme.php index 648034e7..11fcbbaf 100644 --- a/templates/themes/categories/theme.php +++ b/templates/themes/categories/theme.php @@ -15,13 +15,13 @@ public static function build($action, $settings) { global $config; - if($action == 'all') + if ($action == 'all') file_write($config['dir']['home'] . $settings['file_main'], Categories::homepage($settings)); - if($action == 'all' || $action == 'boards') + if ($action == 'all' || $action == 'boards') file_write($config['dir']['home'] . $settings['file_sidebar'], Categories::sidebar($settings)); - if($action == 'all' || $action == 'news') + if ($action == 'all' || $action == 'news') file_write($config['dir']['home'] . $settings['file_news'], Categories::news($settings)); } @@ -52,10 +52,10 @@ $categories = $config['categories']; - foreach($categories as &$boards) { - foreach($boards as &$board) { + foreach ($categories as &$boards) { + foreach ($boards as &$board) { $title = boardTitle($board); - if(!$title) + if (!$title) $title = $board; // board doesn't exist, but for some reason you want to display it anyway $board = Array('title' => $title, 'uri' => sprintf($config['board_path'], $board)); } diff --git a/templates/themes/frameset/sidebar.html b/templates/themes/frameset/sidebar.html index 457ecec8..40e2d719 100644 --- a/templates/themes/frameset/sidebar.html +++ b/templates/themes/frameset/sidebar.html @@ -30,7 +30,7 @@ {% for board in boards %}
  • - {{ board.title }} + {{ board.title|e }}
  • {% endfor %} diff --git a/templates/themes/frameset/theme.php b/templates/themes/frameset/theme.php index f3e1b139..015eebaf 100644 --- a/templates/themes/frameset/theme.php +++ b/templates/themes/frameset/theme.php @@ -15,13 +15,13 @@ public static function build($action, $settings) { global $config; - if($action == 'all') + if ($action == 'all') file_write($config['dir']['home'] . $settings['file_main'], Frameset::homepage($settings)); - if($action == 'all' || $action == 'boards') + if ($action == 'all' || $action == 'boards') file_write($config['dir']['home'] . $settings['file_sidebar'], Frameset::sidebar($settings)); - if($action == 'all' || $action == 'news') + if ($action == 'all' || $action == 'news') file_write($config['dir']['home'] . $settings['file_news'], Frameset::news($settings)); } diff --git a/templates/themes/recent/info.php b/templates/themes/recent/info.php index 83d7477a..d4cf1029 100644 --- a/templates/themes/recent/info.php +++ b/templates/themes/recent/info.php @@ -60,11 +60,11 @@ $theme['build_function'] = 'recentposts_build'; $theme['install_callback'] = 'recentposts_install'; - if(!function_exists('recentposts_install')) { + if (!function_exists('recentposts_install')) { function recentposts_install($settings) { - if(!is_numeric($settings['limit_images']) || $settings['limit_images'] < 0) + if (!is_numeric($settings['limit_images']) || $settings['limit_images'] < 0) return Array(false, '' . utf8tohtml($settings['limit_images']) . ' is not a non-negative integer.'); - if(!is_numeric($settings['limit_posts']) || $settings['limit_posts'] < 0) + if (!is_numeric($settings['limit_posts']) || $settings['limit_posts'] < 0) return Array(false, '' . utf8tohtml($settings['limit_posts']) . ' is not a non-negative integer.'); } } diff --git a/templates/themes/recent/theme.php b/templates/themes/recent/theme.php index 13a5546f..986fac6a 100644 --- a/templates/themes/recent/theme.php +++ b/templates/themes/recent/theme.php @@ -17,13 +17,13 @@ public function build($action, $settings) { global $config, $_theme; - if($action == 'all') { + if ($action == 'all') { copy('templates/themes/recent/recent.css', $config['dir']['home'] . $settings['css']); } $this->excluded = explode(' ', $settings['exclude']); - if($action == 'all' || $action == 'post') + if ($action == 'all' || $action == 'post') file_write($config['dir']['home'] . $settings['html'], $this->homepage($settings)); } @@ -38,15 +38,15 @@ $boards = listBoards(); $query = ''; - foreach($boards as &$_board) { - if(in_array($_board['uri'], $this->excluded)) + foreach ($boards as &$_board) { + if (in_array($_board['uri'], $this->excluded)) continue; $query .= sprintf("SELECT *, '%s' AS `board` FROM `posts_%s` WHERE `file` IS NOT NULL AND `file` != 'deleted' AND `thumb` != 'spoiler' UNION ALL ", $_board['uri'], $_board['uri']); } $query = preg_replace('/UNION ALL $/', 'ORDER BY `time` DESC LIMIT ' . (int)$settings['limit_images'], $query); $query = query($query) or error(db_error()); - while($post = $query->fetch()) { + while ($post = $query->fetch()) { openBoard($post['board']); // board settings won't be available in the template file, so generate links now @@ -58,15 +58,15 @@ $query = ''; - foreach($boards as &$_board) { - if(in_array($_board['uri'], $this->excluded)) + foreach ($boards as &$_board) { + if (in_array($_board['uri'], $this->excluded)) continue; $query .= sprintf("SELECT *, '%s' AS `board` FROM `posts_%s` UNION ALL ", $_board['uri'], $_board['uri']); } $query = preg_replace('/UNION ALL $/', 'ORDER BY `time` DESC LIMIT ' . (int)$settings['limit_posts'], $query); $query = query($query) or error(db_error()); - while($post = $query->fetch()) { + while ($post = $query->fetch()) { openBoard($post['board']); $post['link'] = $config['root'] . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], ($post['thread'] ? $post['thread'] : $post['id'])) . '#' . $post['id']; @@ -78,8 +78,8 @@ // Total posts $query = 'SELECT SUM(`top`) AS `count` FROM ('; - foreach($boards as &$_board) { - if(in_array($_board['uri'], $this->excluded)) + foreach ($boards as &$_board) { + if (in_array($_board['uri'], $this->excluded)) continue; $query .= sprintf("SELECT MAX(`id`) AS `top` FROM `posts_%s` UNION ALL ", $_board['uri']); } @@ -90,8 +90,8 @@ // Unique IPs $query = 'SELECT COUNT(DISTINCT(`ip`)) AS `count` FROM ('; - foreach($boards as &$_board) { - if(in_array($_board['uri'], $this->excluded)) + foreach ($boards as &$_board) { + if (in_array($_board['uri'], $this->excluded)) continue; $query .= sprintf("SELECT `ip` FROM `posts_%s` UNION ALL ", $_board['uri']); } @@ -102,8 +102,8 @@ // Active content $query = 'SELECT SUM(`filesize`) AS `count` FROM ('; - foreach($boards as &$_board) { - if(in_array($_board['uri'], $this->excluded)) + foreach ($boards as &$_board) { + if (in_array($_board['uri'], $this->excluded)) continue; $query .= sprintf("SELECT `filesize` FROM `posts_%s` UNION ALL ", $_board['uri']); } diff --git a/templates/themes/rrdtool/info.php b/templates/themes/rrdtool/info.php index 73658a22..46a20587 100644 --- a/templates/themes/rrdtool/info.php +++ b/templates/themes/rrdtool/info.php @@ -28,7 +28,7 @@ $__boards = listBoards(); $__default_boards = Array(); - foreach($__boards as $__board) + foreach ($__boards as $__board) $__default_boards[] = $__board['uri']; $theme['config'][] = Array( @@ -83,31 +83,31 @@ ); $theme['install_callback'] = 'rrdtool_install'; - if(!function_exists('rrdtool_install')) { + if (!function_exists('rrdtool_install')) { function rrdtool_install($settings) { global $config; - if(!is_numeric($settings['interval']) || $settings['interval'] < 1 || $settings['interval'] > 86400) + if (!is_numeric($settings['interval']) || $settings['interval'] < 1 || $settings['interval'] > 86400) return Array(false, 'Invalid interval: ' . $settings['interval'] . '. Must be an integer greater than 1 and less than 86400.'); - if(!is_numeric($settings['width']) || $settings['width'] < 1) + if (!is_numeric($settings['width']) || $settings['width'] < 1) return Array(false, 'Invalid width: ' . $settings['width'] . '!'); - if(!is_numeric($settings['height']) || $settings['height'] < 1) + if (!is_numeric($settings['height']) || $settings['height'] < 1) return Array(false, 'Invalid height: ' . $settings['height'] . '!'); - if(!in_array($settings['rate'], Array('second', 'minute', 'day', 'hour', 'week', 'month', 'year'))) + if (!in_array($settings['rate'], Array('second', 'minute', 'day', 'hour', 'week', 'month', 'year'))) return Array(false, 'Invalid rate: ' . $settings['rate'] . '!'); $job = '*/' . $settings['interval'] . ' * * * * php -q ' . str_replace('\\', '/', dirname(__FILE__)) . '/cron.php' . PHP_EOL; - if(function_exists('system')) { + if (function_exists('system')) { $crontab = tempnam($config['tmp'], 'tinyboard-rrdtool'); file_write($crontab, $job); @system('crontab ' . escapeshellarg($crontab), $ret); unlink($crontab); - if($ret === 0) + if ($ret === 0) return ''; // it seems to install okay? } diff --git a/templates/themes/rrdtool/theme.php b/templates/themes/rrdtool/theme.php index 20a00e76..eed2ac9a 100644 --- a/templates/themes/rrdtool/theme.php +++ b/templates/themes/rrdtool/theme.php @@ -17,7 +17,7 @@ public function build($action, $settings) { global $config, $_theme, $argv; - if(!$settings) { + if (!$settings) { error('This theme is not currently installed.'); } @@ -26,18 +26,18 @@ // exclude boards from the "combined" graph $this->combined_exclude = Array(); - if($action == 'cron') { - if(!file_exists($settings['path'])) + if ($action == 'cron') { + if (!file_exists($settings['path'])) mkdir($settings['path']); - if(!file_exists($settings['images'])) + if (!file_exists($settings['images'])) mkdir($settings['images']); - foreach($this->boards as &$board) { + foreach ($this->boards as &$board) { $file = $settings['path'] . '/' . $board . '.rrd'; - if(!file_exists($file)) { + if (!file_exists($file)) { // Create graph - if(!rrd_create($file, Array( + if (!rrd_create($file, Array( '-s 60', 'DS:posts:COUNTER:86400:0:10000', @@ -59,22 +59,22 @@ } // debug just the graphing (not updating) with the --debug switch - if(!isset($argv[1]) || $argv[1] != '--debug') { + if (!isset($argv[1]) || $argv[1] != '--debug') { // Update graph $query = query(sprintf("SELECT MAX(`id`) AS `count` FROM `posts_%s`", $board)); $count = $query->fetch(); $count = $count['count']; - if(!rrd_update($file, Array( + if (!rrd_update($file, Array( '-t', 'posts', 'N:' . $count))) error('RRDtool failed: ' . htmlentities(rrd_error())); } - foreach($this->spans as &$span) { + foreach ($this->spans as &$span) { // Graph graph - if(!rrd_graph($settings['images'] . '/' . $board . '-' . $span . '.png', Array( + if (!rrd_graph($settings['images'] . '/' . $board . '-' . $span . '.png', Array( '-s -1' . $span, '-t Posts on ' . sprintf($config['board_abbreviation'], $board) .' this ' . $span, '--lazy', @@ -105,7 +105,7 @@ } // combined graph - foreach($this->spans as &$span) { + foreach ($this->spans as &$span) { $options = Array( '-s -1' . $span, '-t Posts this ' . $span, @@ -129,8 +129,8 @@ $c = 1; $cc = 0; $red = 2; - foreach($this->boards as &$board) { - if(in_array($board, $this->combined_exclude)) + foreach ($this->boards as &$board) { + if (in_array($board, $this->combined_exclude)) continue; $color = str_pad(dechex($red*85), 2, '0', STR_PAD_LEFT) . str_pad(dechex($green*85), 2, '0', STR_PAD_LEFT) . @@ -147,31 +147,35 @@ sprintf($config['board_abbreviation'], $board); // Randomize colors using this horrible undocumented algorithm I threw together while debugging - if($c == 0) + if ($c == 0) $red++; - elseif($c == 1) + elseif ($c == 1) $green++; - elseif($c == 2) + elseif ($c == 2) $blue++; - elseif($c == 3) + elseif ($c == 3) $green--; - elseif($c == 4) + elseif ($c == 4) $red--; $cc++; - if($cc > 2) { + if ($cc > 2) { $c++; $cc = 0; } - if($c>4) $c = 0; + if ($c > 4) + $c = 0; - if($red>3) $red = 0; - if($green>3) $green = 0; - if($blue>3) $blue = 0; + if ($red > 3) + $red = 0; + if ($green > 3) + $green = 0; + if ($blue > 3) + $blue = 0; } $options[] = 'HRULE:0#000000'; - if(!rrd_graph($settings['images'] . '/combined-' . $span . '.png', $options)) + if (!rrd_graph($settings['images'] . '/combined-' . $span . '.png', $options)) error('RRDtool failed: ' . htmlentities(rrd_error())); } } diff --git a/templates/thread.html b/templates/thread.html index 9a56a50f..e7c65f9b 100644 --- a/templates/thread.html +++ b/templates/thread.html @@ -1,13 +1,13 @@ - - {% if config.url_favicon %}{% endif %} + + + {% if config.url_favicon %}{% endif %} {{ board.url }} - {{ board.name }} - - - {% if config.meta_keywords %}{% endif %} - + + {% if config.meta_keywords %}{% endif %} + {% if config.default_stylesheet.1 != '' %}{% endif %} {% if not nojavascript %} {% if not config.additional_javascript_compile %} @@ -29,17 +29,16 @@ display: block; } {% endraw %}{% endif %} - {{ boardlist.top }} {% if pm %}
    You have an unread PM{% if pm.waiting > 0 %}, plus {{ pm.waiting }} more waiting{% endif %}.

    {% endif %} {% if config.url_banner %}{% endif %}
    -

    {{ board.url }} - {{ board.title }}

    +

    {{ board.url }} - {{ board.title|e }}

    {% if board.subtitle %} - {{ board.subtitle }} + {{ board.subtitle|e }} {% endif %} {% if mod %}

    {% trans %}Return to dashboard{% endtrans %}

    {% endif %}
    -- cgit v1.3 From d6a1f16555376fc4b57a572e21758a400db8852a Mon Sep 17 00:00:00 2001 From: Michael Save Date: Sat, 19 May 2012 21:12:40 +1000 Subject: bugfix: noticeboard timestamps --- templates/mod/dashboard.html | 2 +- templates/mod/noticeboard.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'templates/mod/dashboard.html') diff --git a/templates/mod/dashboard.html b/templates/mod/dashboard.html index 9e50e6ed..a10b0cf2 100644 --- a/templates/mod/dashboard.html +++ b/templates/mod/dashboard.html @@ -48,7 +48,7 @@ deleted? {% endif %} at - {{ notice.time|date(config.post_date) }} + {{ post.time|date(config.post_date) }} {% endfor %} diff --git a/templates/mod/noticeboard.html b/templates/mod/noticeboard.html index 4a0a068f..463b8430 100644 --- a/templates/mod/noticeboard.html +++ b/templates/mod/noticeboard.html @@ -47,7 +47,7 @@ {% trans 'deleted?' %} {% endif %} {% trans 'at' %} - {{ notice.time|date(config.post_date) }} + {{ post.time|date(config.post_date) }}

    -- cgit v1.3 From e4b6c89375d60424e1e029cb3d10c8ec2be49620 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Fri, 25 May 2012 21:40:01 +1000 Subject: show number of reports from dashboard; translatable mod panel --- inc/mod/pages.php | 57 ++++++++++++++++++++++++-------------------- templates/mod/dashboard.html | 6 ++++- 2 files changed, 36 insertions(+), 27 deletions(-) (limited to 'templates/mod/dashboard.html') diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 7278afa3..878df92d 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -56,11 +56,11 @@ function mod_login() { if (isset($_POST['username'])) $args['username'] = $_POST['username']; - mod_page('Login', 'mod/login.html', $args); + mod_page(_('Login'), 'mod/login.html', $args); } function mod_confirm($request) { - mod_page('Confirm action', 'mod/confirm.html', array('request' => $request)); + mod_page(_('Confirm action'), 'mod/confirm.html', array('request' => $request)); } function mod_logout() { @@ -98,6 +98,9 @@ function mod_dashboard() { cache::set('pm_unreadcount_' . $mod['id'], $args['unread_pms']); } + $query = query('SELECT COUNT(*) FROM `reports`') or error(db_error($query)); + $args['reports'] = $query->fetchColumn(0); + if ($mod['type'] >= ADMIN && $config['check_updates']) { if (!$config['version']) error(_('Could not find current version! (Check .installed)')); @@ -141,7 +144,7 @@ function mod_dashboard() { $args['newer_release'] = $latest; } - mod_page('Dashboard', 'mod/dashboard.html', $args); + mod_page(_('Dashboard'), 'mod/dashboard.html', $args); } function mod_edit_board($boardName) { @@ -216,7 +219,7 @@ function mod_edit_board($boardName) { header('Location: ?/', true, $config['redirect_http']); } else { - mod_page('Edit board: ' . sprintf($config['board_abbreviation'], $board['uri']), 'mod/board.html', array('board' => $board)); + mod_page(sprintf('%s: ' . $config['board_abbreviation'], _('Edit board'), $board['uri']), 'mod/board.html', array('board' => $board)); } } @@ -264,7 +267,7 @@ function mod_new_board() { header('Location: ?/' . $board['uri'] . '/' . $config['file_index'], true, $config['redirect_http']); } - mod_page('New board', 'mod/board.html', array('new' => true)); + mod_page(_('New board'), 'mod/board.html', array('new' => true)); } function mod_noticeboard($page_no = 1) { @@ -310,7 +313,7 @@ function mod_noticeboard($page_no = 1) { $query->execute() or error(db_error($query)); $count = $query->fetchColumn(0); - mod_page('Noticeboard', 'mod/noticeboard.html', array('noticeboard' => $noticeboard, 'count' => $count)); + mod_page(_('Noticeboard'), 'mod/noticeboard.html', array('noticeboard' => $noticeboard, 'count' => $count)); } function mod_noticeboard_delete($id) { @@ -367,7 +370,7 @@ function mod_news($page_no = 1) { $query->execute() or error(db_error($query)); $count = $query->fetchColumn(0); - mod_page('News', 'mod/news.html', array('news' => $news, 'count' => $count)); + mod_page(_('News'), 'mod/news.html', array('news' => $news, 'count' => $count)); } function mod_news_delete($id) { @@ -407,7 +410,7 @@ function mod_log($page_no = 1) { $query->execute() or error(db_error($query)); $count = $query->fetchColumn(0); - mod_page('Moderation log', 'mod/log.html', array('logs' => $logs, 'count' => $count)); + mod_page(_('Moderation log'), 'mod/log.html', array('logs' => $logs, 'count' => $count)); } function mod_view_board($boardName, $page_no = 1) { @@ -550,7 +553,7 @@ function mod_page_ip($ip) { $args['notes'] = $query->fetchAll(PDO::FETCH_ASSOC); } - mod_page("IP: $ip", 'mod/view_ip.html', $args, $args['hostname']); + mod_page(sprintf('%s: %s', _('IP'), $ip), 'mod/view_ip.html', $args, $args['hostname']); } function mod_ban() { @@ -560,7 +563,7 @@ function mod_ban() { error($config['error']['noaccess']); if (!isset($_POST['ip'], $_POST['reason'], $_POST['length'], $_POST['board'])) { - mod_page("New ban", 'mod/ban_form.html', array()); + mod_page(_('New ban'), 'mod/ban_form.html', array()); return; } @@ -628,7 +631,7 @@ function mod_bans($page_no = 1) { $ban['real_ip'] = true; } - mod_page('Ban list', 'mod/ban_list.html', array('bans' => $bans, 'count' => $count)); + mod_page(_('Ban list'), 'mod/ban_list.html', array('bans' => $bans, 'count' => $count)); } @@ -880,7 +883,7 @@ function mod_move($originBoard, $postID) { if (count($boards) <= 1) error(_('Impossible to move thread; there is only one board.')); - mod_page("Move thread", 'mod/move.html', array('post' => $postID, 'board' => $originBoard, 'boards' => $boards)); + mod_page(_('Move thread'), 'mod/move.html', array('post' => $postID, 'board' => $originBoard, 'boards' => $boards)); } function mod_ban_post($board, $delete, $post) { @@ -939,7 +942,7 @@ function mod_ban_post($board, $delete, $post) { 'boards' => listBoards() ); - mod_page("New ban", 'mod/ban_form.html', $args); + mod_page(_('New ban'), 'mod/ban_form.html', $args); } function mod_delete($board, $post) { @@ -1155,7 +1158,7 @@ function mod_user($uid) { $user['boards'] = explode(',', $user['boards']); - mod_page('Edit user', 'mod/user.html', array('user' => $user, 'logs' => $log, 'boards' => listBoards())); + mod_page(_('Edit user'), 'mod/user.html', array('user' => $user, 'logs' => $log, 'boards' => listBoards())); } function mod_user_new() { @@ -1204,7 +1207,7 @@ function mod_user_new() { return; } - mod_page('Edit user', 'mod/user.html', array('new' => true, 'boards' => listBoards())); + mod_page(_('Edit user'), 'mod/user.html', array('new' => true, 'boards' => listBoards())); } @@ -1218,7 +1221,7 @@ function mod_users() { $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); + mod_page(_('Manage users'), 'mod/users.html', $args); } function mod_user_promote($uid, $action) { @@ -1280,11 +1283,11 @@ function mod_pm($id, $reply = false) { if (!$pm['to_username']) error($config['error']['404']); // deleted? - mod_page("New PM for {$pm['to_username']}", 'mod/new_pm.html', array( + mod_page(sprintf('%s %s', _('New PM for'), $pm['to_username']), 'mod/new_pm.html', array( 'username' => $pm['username'], 'id' => $pm['sender'], 'message' => quote($pm['message']) )); } else { - mod_page("Private message – #$id", 'mod/pm.html', $pm); + mod_page(sprintf('%s – #%d', _('Private message'), $id), 'mod/pm.html', $pm); } } @@ -1305,7 +1308,7 @@ function mod_inbox() { $message['snippet'] = pm_snippet($message['message']); } - mod_page('PM inbox (' . (count($messages) > 0 ? $unread . ' unread' : 'empty') . ')', 'mod/inbox.html', array( + mod_page(sprintf('%s (%s)', _('PM inbox'), count($messages) > 0 ? $unread . ' unread' : 'empty'), 'mod/inbox.html', array( 'messages' => $messages, 'unread' => $unread )); @@ -1352,7 +1355,7 @@ function mod_new_pm($username) { header('Location: ?/', true, $config['redirect_http']); } - mod_page("New PM for {$username}", 'mod/new_pm.html', array('username' => $username, 'id' => $id)); + mod_page(sprintf('%s %s', _('New PM for'), $username), 'mod/new_pm.html', array('username' => $username, 'id' => $id)); } function mod_rebuild() { @@ -1414,11 +1417,11 @@ function mod_rebuild() { } } - mod_page("Rebuild", 'mod/rebuilt.html', array('logs' => $log)); + mod_page(_('Rebuild'), 'mod/rebuilt.html', array('logs' => $log)); return; } - mod_page("Rebuild", 'mod/rebuild.html', array('boards' => listBoards())); + mod_page(_('Rebuild'), 'mod/rebuild.html', array('boards' => listBoards())); } function mod_reports() { @@ -1449,6 +1452,7 @@ function mod_reports() { } } + $count = 0; $body = ''; foreach ($reports as $report) { if (!isset($report_posts[$report['board']][$report['post']])) { @@ -1499,9 +1503,11 @@ function mod_reports() { if (isset($__old_body_truncate_char)) $config['body_truncate_char'] = $__old_body_truncate_char; + + $count++; } - mod_page("Report queue", 'mod/reports.html', array('reports' => $body)); + mod_page(sprintf('%s (%d)', _('Report queue'), $count), 'mod/reports.html', array('reports' => $body, 'count' => $count)); } function mod_report_dismiss($id, $all = false) { @@ -1623,7 +1629,7 @@ function mod_config() { exit; } - mod_page('Config editor', 'mod/config-editor.html', array('conf' => $conf)); + mod_page(_('Config editor'), 'mod/config-editor.html', array('conf' => $conf)); } function mod_debug_antispam() { @@ -1657,7 +1663,6 @@ function mod_debug_antispam() { $query = query('SELECT * FROM `antispam` ' . ($where ? "WHERE $where" : '') . ' ORDER BY `passed` DESC LIMIT 40') or error(db_error()); $args['top'] = $query->fetchAll(PDO::FETCH_ASSOC); - mod_page("Debug: Anti-spam", 'mod/debug/antispam.html', $args); + mod_page(_('Debug: Anti-spam'), 'mod/debug/antispam.html', $args); } - diff --git a/templates/mod/dashboard.html b/templates/mod/dashboard.html index a10b0cf2..1c70bf06 100644 --- a/templates/mod/dashboard.html +++ b/templates/mod/dashboard.html @@ -74,7 +74,11 @@

      {% if mod|hasPermission(config.mod.reports) %} -
    • {% trans 'Report queue' %}
    • +
    • + {% if reports > 0 %}{% endif %} + {% trans 'Report queue' %} ({{ reports }}) + {% if reports > 0 %}{% endif %} +
    • {% endif %} {% if mod|hasPermission(config.mod.view_banlist) %} -- cgit v1.3 From 8d96bfc3e90dd5293f3b39beac975850822f8a4b Mon Sep 17 00:00:00 2001 From: Michael Save Date: Mon, 28 May 2012 17:08:29 +1000 Subject: minor change --- inc/mod/pages.php | 7 ++++--- templates/mod/dashboard.html | 6 ++---- 2 files changed, 6 insertions(+), 7 deletions(-) (limited to 'templates/mod/dashboard.html') diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 878df92d..72c8c195 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -978,6 +978,8 @@ function mod_deletefile($board, $post) { deleteFile($post); // Record the action modLog("Deleted file from post #{$post}"); + // Rebuild thread + buildThread($post); // Rebuild board buildIndex(); @@ -1217,11 +1219,10 @@ function mod_users() { 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); + $users = $query->fetchAll(PDO::FETCH_ASSOC); - mod_page(_('Manage users'), 'mod/users.html', $args); + mod_page(sprintf('%s (%d)', _('Manage users'), count($users)), 'mod/users.html', array('users' => $users)); } function mod_user_promote($uid, $action) { diff --git a/templates/mod/dashboard.html b/templates/mod/dashboard.html index 1c70bf06..47a25390 100644 --- a/templates/mod/dashboard.html +++ b/templates/mod/dashboard.html @@ -60,10 +60,8 @@
    • {% trans 'News' %}
    • - {% trans 'PM inbox' %} - {% if unread_pms > 0 %} - ({{ unread_pms }} unread) - {% endif %} + {% trans 'PM inbox' %} + {% if unread_pms > 0 %}{%endif %}({{ unread_pms }} unread){% if unread_pms > 0 %}{%endif %}
    -- cgit v1.3 From c5ec20684e77456fe9377a8cbf62c78cfb580b64 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Mon, 13 Aug 2012 00:18:13 +1000 Subject: themes --- inc/mod/pages.php | 127 +++++++++++++++++++++++++++++++++++++ mod.php | 5 ++ templates/mod/dashboard.html | 18 ++---- templates/mod/theme_config.html | 27 ++++++++ templates/mod/theme_installed.html | 9 +++ templates/mod/theme_rebuilt.html | 2 + templates/mod/themes.html | 40 ++++++++++++ 7 files changed, 214 insertions(+), 14 deletions(-) create mode 100644 templates/mod/theme_config.html create mode 100644 templates/mod/theme_installed.html create mode 100644 templates/mod/theme_rebuilt.html create mode 100644 templates/mod/themes.html (limited to 'templates/mod/dashboard.html') diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 72c8c195..ad69ae39 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -1667,3 +1667,130 @@ function mod_debug_antispam() { mod_page(_('Debug: Anti-spam'), 'mod/debug/antispam.html', $args); } +function mod_themes_list() { + global $config; + + if (!hasPermission($config['mod']['themes'])) + error($config['error']['noaccess']); + + if(!is_dir($config['dir']['themes'])) + error(_('Themes directory doesn\'t exist!')); + if(!$dir = opendir($config['dir']['themes'])) + error(_('Cannot open themes directory; check permissions.')); + + $query = query('SELECT `theme` FROM `theme_settings` WHERE `name` IS NULL AND `value` IS NULL') or error(db_error()); + $themes_in_use = $query->fetchAll(PDO::FETCH_COLUMN); + + // Scan directory for themes + $themes = array(); + while ($file = readdir($dir)) { + if ($file[0] != '.' && is_dir($config['dir']['themes'] . '/' . $file)) { + $themes[$file] = loadThemeConfig($file); + } + } + closedir($dir); + + mod_page(_('Manage themes'), 'mod/themes.html', array( + 'themes' => $themes, + 'themes_in_use' => $themes_in_use, + )); +} + +function mod_theme_configure($theme_name) { + global $config; + + if (!hasPermission($config['mod']['themes'])) + error($config['error']['noaccess']); + + if(!$theme = loadThemeConfig($theme_name)) { + error($config['error']['invalidtheme']); + } + + if(isset($_POST['install'])) { + // Check if everything is submitted + foreach($theme['config'] as &$conf) { + if(!isset($_POST[$conf['name']]) && $conf['type'] != 'checkbox') + error(sprintf($config['error']['required'], $c['title'])); + } + + // Clear previous settings + $query = prepare("DELETE FROM `theme_settings` WHERE `theme` = :theme"); + $query->bindValue(':theme', $theme_name); + $query->execute() or error(db_error($query)); + + foreach($theme['config'] as &$conf) { + $query = prepare("INSERT INTO `theme_settings` VALUES(:theme, :name, :value)"); + $query->bindValue(':theme', $theme_name); + $query->bindValue(':name', $conf['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)); + + $result = true; + $message = false; + if(isset($theme['install_callback'])) { + $ret = $theme['install_callback'](themeSettings($theme_name)); + if($ret && !empty($ret)) { + if(is_array($ret) && count($ret) == 2) { + $result = $ret[0]; + $message = $ret[1]; + } + } + } + + if(!$result) { + // Install failed + $query = prepare("DELETE FROM `theme_settings` WHERE `theme` = :theme"); + $query->bindValue(':theme', $theme_name); + $query->execute() or error(db_error($query)); + } + + // Build themes + rebuildThemes('all'); + + mod_page(sprintf(_($result ? 'Installed theme: %s' : 'Installation failed: %s'), $theme['name']), 'mod/theme_installed.html', array( + 'theme_name' => $theme_name, + 'theme' => $theme, + 'result' => $result, + 'message' => $message, + )); + } + + $settings = themeSettings($theme_name); + + mod_page(sprintf(_('Configuring theme: %s'), $theme['name']), 'mod/theme_config.html', array( + 'theme_name' => $theme_name, + 'theme' => $theme, + 'settings' => $settings, + )); +} + +function mod_theme_uninstall($theme_name) { + global $config; + + 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)); + + header('Location: ?/themes', true, $config['redirect_http']); +} + +function mod_theme_rebuild($theme_name) { + global $config; + + if (!hasPermission($config['mod']['themes'])) + error($config['error']['noaccess']); + + rebuildTheme($theme_name, 'all'); + + mod_page(sprintf(_('Rebuilt theme: %s'), $theme_name), 'mod/theme_rebuilt.html', array( + 'theme_name' => $theme_name, + )); +} diff --git a/mod.php b/mod.php index 5fa040ee..52f340d2 100644 --- a/mod.php +++ b/mod.php @@ -65,6 +65,11 @@ $pages = array( '/(\w+)/bump(un)?lock/(\d+)' => 'bumplock', // "bumplock" thread '/(\w+)/move/(\d+)' => 'move', // move thread + '/themes' => 'themes_list', // manage themes + '/themes/(\w+)' => 'theme_configure', // configure/reconfigure theme + '/themes/(\w+)/rebuild' => 'theme_rebuild', // rebuild theme + '/themes/(\w+)/uninstall' => 'theme_uninstall', // uninstall theme + '/config' => 'config', // config editor // these pages aren't listed in the dashboard without $config['debug'] diff --git a/templates/mod/dashboard.html b/templates/mod/dashboard.html index 47a25390..30742dc1 100644 --- a/templates/mod/dashboard.html +++ b/templates/mod/dashboard.html @@ -10,7 +10,6 @@ {% if board.subtitle %} — {{ board.subtitle|e }} {% endif %} - {% if mod|hasPermission(config.mod.manageboards) %} [{% trans 'edit' %}] {% endif %} @@ -78,39 +77,30 @@ {% if reports > 0 %}{% endif %} {% endif %} - {% if mod|hasPermission(config.mod.view_banlist) %}
  • {% trans 'Ban list' %}
  • {% endif %} - {% if mod|hasPermission(config.mod.manageusers) %}
  • {% trans 'Manage users' %}
  • {% elseif mod|hasPermission(config.mod.change_password) %}
  • {% trans 'Change password' %}
  • {% endif %} - + {% if mod|hasPermission(config.mod.themes) %} +
  • {% trans 'Manage themes' %}
  • + {% endif %} {% if mod|hasPermission(config.mod.modlog) %}
  • {% trans 'Moderation log' %}
  • {% endif %} - {% if mod|hasPermission(config.mod.rebuild) %}
  • {% trans 'Rebuild' %}
  • {% endif %} - {% if mod|hasPermission(config.mod.show_config) %}
  • {% trans 'Configuration' %}
  • {% endif %} + -{% if mod|hasPermission(config.mod.themes) %} -
    - {% trans 'Themes' %} - - {# TODO #} -
    -{% endif %} -
    {% trans 'Search' %} diff --git a/templates/mod/theme_config.html b/templates/mod/theme_config.html new file mode 100644 index 00000000..2dbb8397 --- /dev/null +++ b/templates/mod/theme_config.html @@ -0,0 +1,27 @@ +
    + {% if not config %} +

    (No configuration required.)

    + {% else %} + + {% for conf in theme.config %} + + + + + {% endfor %} +
    {{ conf.title }} + + {% if conf.comment %} + {{ conf.comment }} + {% endif %} +
    + {% endif %} +

    + +

    +
    diff --git a/templates/mod/theme_installed.html b/templates/mod/theme_installed.html new file mode 100644 index 00000000..e6beec10 --- /dev/null +++ b/templates/mod/theme_installed.html @@ -0,0 +1,9 @@ +{% if message %} +
    {{ message }}
    +{% endif %} + +{% if result %} +

    {% trans 'Successfully installed and built theme.' %}

    +{% endif %} + +

    {% trans 'Go back to themes' %}.

    diff --git a/templates/mod/theme_rebuilt.html b/templates/mod/theme_rebuilt.html new file mode 100644 index 00000000..b366e7a6 --- /dev/null +++ b/templates/mod/theme_rebuilt.html @@ -0,0 +1,2 @@ +

    {{ 'Successfully rebuilt the %s theme.'|trans|sprintf(theme_name) }}

    +

    {% trans 'Go back to themes' %}.

    diff --git a/templates/mod/themes.html b/templates/mod/themes.html new file mode 100644 index 00000000..b596826d --- /dev/null +++ b/templates/mod/themes.html @@ -0,0 +1,40 @@ +{% if themes|count == 0 %} +

    ({% trans 'There are no themes available.' %})

    +{% else %} + + {% for theme_name, theme in themes %} + + + + + + + + + + + + + + + + + + + + + + + {% endfor %} +
    {% trans 'Name' %}{{ theme.name }}
    {% trans 'Version' %}{{ theme.version }}
    {% trans 'Description' %}{{ theme.description }}
    {% trans 'Thumbnail' %} + +
    {% trans 'Actions' %}

    +{% endif %} -- cgit v1.3