summaryrefslogtreecommitdiff
path: root/templates
diff options
context:
space:
mode:
authorczaks <marcin@6irc.net>2014-10-08 23:23:59 +0200
committerczaks <marcin@6irc.net>2014-10-08 23:23:59 +0200
commit9b3fa77719642acd13a2ae6f29087dffcb261f4d (patch)
tree6ea26048a0f540c29d28041e1191920d5485f346 /templates
parent906764a62f6fbc263d8b1d21957531edb6481e59 (diff)
new banlist implementation; also includes a public banlist
Diffstat (limited to 'templates')
-rw-r--r--templates/main.js47
-rw-r--r--templates/mod/ban_list.html137
-rw-r--r--templates/themes/public_banlist/info.php33
-rw-r--r--templates/themes/public_banlist/theme.php56
-rw-r--r--templates/themes/ukko/theme.php6
5 files changed, 178 insertions, 101 deletions
diff --git a/templates/main.js b/templates/main.js
index 52f38e69..ed25f7d9 100644
--- a/templates/main.js
+++ b/templates/main.js
@@ -22,6 +22,53 @@ function fmt(s,a) {
return s.replace(/\{([0-9]+)\}/g, function(x) { return a[x[1]]; });
}
+function until($timestamp) {
+ var $difference = $timestamp - Date.now()/1000|0, $num;
+ switch(true){
+ case ($difference < 60):
+ return "" + $difference + ' ' + _('second(s)');
+ case ($difference < 3600): //60*60 = 3600
+ return "" + ($num = Math.round($difference/(60))) + ' ' + _('minute(s)');
+ case ($difference < 86400): //60*60*24 = 86400
+ return "" + ($num = Math.round($difference/(3600))) + ' ' + _('hour(s)');
+ case ($difference < 604800): //60*60*24*7 = 604800
+ return "" + ($num = Math.round($difference/(86400))) + ' ' + _('day(s)');
+ case ($difference < 31536000): //60*60*24*365 = 31536000
+ return "" + ($num = Math.round($difference/(604800))) + ' ' + _('week(s)');
+ default:
+ return "" + ($num = Math.round($difference/(31536000))) + ' ' + _('year(s)');
+ }
+}
+
+function ago($timestamp) {
+ var $difference = (Date.now()/1000|0) - $timestamp, $num;
+ switch(true){
+ case ($difference < 60) :
+ return "" + $difference + ' ' + _('second(s)');
+ case ($difference < 3600): //60*60 = 3600
+ return "" + ($num = Math.round($difference/(60))) + ' ' + _('minute(s)');
+ case ($difference < 86400): //60*60*24 = 86400
+ return "" + ($num = Math.round($difference/(3600))) + ' ' + _('hour(s)');
+ case ($difference < 604800): //60*60*24*7 = 604800
+ return "" + ($num = Math.round($difference/(86400))) + ' ' + _('day(s)');
+ case ($difference < 31536000): //60*60*24*365 = 31536000
+ return "" + ($num = Math.round($difference/(604800))) + ' ' + _('week(s)');
+ default:
+ return "" + ($num = Math.round($difference/(31536000))) + ' ' + _('year(s)');
+ }
+}
+
+var datelocale =
+ { days: [_('Sunday'), _('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday')]
+ , shortDays: [_("Sun"), _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat")]
+ , months: [_('January'), _('February'), _('March'), _('April'), _('May'), _('June'), _('July'), _('August'), _('September'), _('October'), _('November'), _('December')]
+ , shortMonths: [_('Jan'), _('Feb'), _('Mar'), _('Apr'), _('May'), _('Jun'), _('Jul'), _('Aug'), _('Sep'), _('Oct'), _('Nov'), _('Dec')]
+ , AM: _('AM')
+ , PM: _('PM')
+ , am: _('am')
+ , pm: _('pm')
+ };
+
var saved = {};
diff --git a/templates/mod/ban_list.html b/templates/mod/ban_list.html
index 97c02029..0c67f269 100644
--- a/templates/mod/ban_list.html
+++ b/templates/mod/ban_list.html
@@ -1,104 +1,41 @@
-{% if bans|count == 0 %}
- <p style="text-align:center" class="unimportant">({% trans 'There are no active bans.' %})</p>
-{% else %}
- <form action="?/bans" method="post">
- <input type="hidden" name="token" value="{{ token }}">
- <table class="mod" style="width:100%">
- <tr>
- <th>{% trans 'IP address/mask' %}</th>
- <th>{% trans 'Reason' %}</th>
- <th>{% trans 'Board' %}</th>
- <th>{% trans 'Set' %}</th>
- <th>{% trans 'Duration' %}</th>
- <th>{% trans 'Expires' %}</th>
- <th>{% trans 'Seen' %}</th>
- <th>{% trans 'Staff' %}</th>
- </tr>
- {% for ban in bans %}
- <tr{% if ban.expires != 0 and ban.expires < time() %} style="text-decoration:line-through"{% endif %}>
- <td style="white-space: nowrap">
- <input type="checkbox" name="ban_{{ ban.id }}">
- {% if ban.single_addr %}
- <a href="?/IP/{{ ban.mask }}">{{ ban.mask }}</a>
- {% else %}
- {{ ban.mask }}
- {% endif %}
- </td>
- <td>
- {% if ban.reason %}
- {{ ban.reason }}
- {% else %}
- -
- {% endif %}
- </td>
- <td style="white-space: nowrap">
- {% if ban.board %}
- {{ config.board_abbreviation|sprintf(ban.board) }}
- {% else %}
- <em>{% trans 'all boards' %}</em>
- {% endif %}
- </td>
- <td style="white-space: nowrap">
- <span title="{{ ban.created|date(config.post_date) }}">
- {{ ban.created|ago }} ago
- </span>
- </td>
- <td style="white-space: nowrap">
- {% if ban.expires == 0 %}
- -
- {% else %}
- {{ (ban.expires - ban.created + time()) | until }}
- {% endif %}
- </td>
- <td style="white-space: nowrap">
- {% if ban.expires == 0 %}
- <em>{% trans 'never' %}</em>
- {% else %}
- {{ ban.expires|date(config.post_date) }}
- {% if ban.expires > time() %}
- <small>(in {{ ban.expires|until }})</small>
- {% endif %}
- {% endif %}
- </td>
- <td>
- {% if ban.seen %}
- {% trans 'Yes' %}
- {% else %}
- {% trans 'No' %}
- {% endif %}
- </td>
- <td>
- {% if ban.username %}
- {% if mod|hasPermission(config.mod.view_banstaff) %}
- <a href="?/new_PM/{{ ban.username|e }}">{{ ban.username|e }}</a>
- {% else %}
- {% if mod|hasPermission(config.mod.view_banquestionmark) %}
- <em>?</em>
- {% else %}
-
- {% endif %}
- {% endif %}
- {% elseif ban.creator == -1 %}
- <em>system</em>
- {% else %}
- <em>{% trans 'deleted?' %}</em>
- {% endif %}
- </td>
- </tr>
- {% endfor %}
+<script src='main.js'></script>
+<script src='js/jquery.min.js'></script>
+<script src='js/mobile-style.js'></script>
+<script src='js/strftime.min.js'></script>
+<script src='js/longtable/longtable.js'></script>
+<script src='js/mod/ban-list.js'></script>
+<link rel='stylesheet' href='stylesheets/longtable/longtable.css'>
+<link rel='stylesheet' href='stylesheets/mod/ban-list.css'>
+
+ <form action="?/bans" method="post" class="banform">
+ {% if token %}
+ <input type="hidden" name="token" value="{{ token }}">
+ {% endif %}
+ <div class='banlist-opts'>
+ <div class='checkboxes'>
+ {% if mod and mod.boards[0] != '*' %}
+ <label><input type="checkbox" id="only_mine"> {% trans %}Show only bans from boards I moderate{% endtrans %}</label>
+ {% endif %}
+ <label><input type="checkbox" id="only_not_expired"> {% trans %}Show only active bans{% endtrans %}</label>
+ </div>
+ <div class='buttons'>
+ <input type="text" id="search" placeholder="{% trans %}Search{% endtrans %}">
+ {% if mod %}
+ <input type="submit" name="unban" id="unban" value="{% trans 'Unban selected' %}">
+ {% endif %}
+ </div>
+
+ <br class='clear'>
+ </div>
+
+ <table class="mod" style="width:100%" id="banlist">
</table>
+
+
- <p style="text-align:center">
- <input type="submit" name="unban" value="{% trans 'Unban selected' %}">
- </p>
</form>
+{% if token_json %}
+ <script>$(function(){ banlist_init("{{ token_json }}", {{ boards }}); });</script>
+{% else %}
+ <script>$(function(){ banlist_init("{{ uri_json }}", {{ boards }}, true); });</script>
{% endif %}
-
-{% if count > bans|count %}
- <p class="unimportant" style="text-align:center;word-wrap:break-word">
- {% for i in range(0, (count - 1) / config.mod.modlog_page) %}
- <a href="?/bans/{{ i + 1 }}">[{{ i + 1 }}]</a>
- {% endfor %}
- </p>
-{% endif %}
-
diff --git a/templates/themes/public_banlist/info.php b/templates/themes/public_banlist/info.php
new file mode 100644
index 00000000..006ac38e
--- /dev/null
+++ b/templates/themes/public_banlist/info.php
@@ -0,0 +1,33 @@
+<?php
+ $theme = Array();
+
+ // Theme name
+ $theme['name'] = 'Public Banlist';
+ // Description (you can use Tinyboard markup here)
+ $theme['description'] =
+'Shows a public list of bans, that were issued on all boards. Basically, this theme
+copies the banlist interface from moderation panel.';
+ $theme['version'] = 'v0.1';
+
+ // Theme configuration
+ $theme['config'] = Array();
+
+ $theme['config'][] = Array(
+ 'title' => 'JSON feed file',
+ 'name' => 'file_json',
+ 'type' => 'text',
+ 'default' => 'bans.json',
+ 'comment' => '(eg. "bans.json")'
+ );
+
+ $theme['config'][] = Array(
+ 'title' => 'Main HTML file',
+ 'name' => 'file_bans',
+ 'type' => 'text',
+ 'default' => 'bans.html',
+ 'comment' => '(eg. "bans.html")'
+ );
+
+ // Unique function name for building everything
+ $theme['build_function'] = 'pbanlist_build';
+?>
diff --git a/templates/themes/public_banlist/theme.php b/templates/themes/public_banlist/theme.php
new file mode 100644
index 00000000..b64b8d9e
--- /dev/null
+++ b/templates/themes/public_banlist/theme.php
@@ -0,0 +1,56 @@
+<?php
+ require 'info.php';
+
+ function pbanlist_build($action, $settings, $board) {
+ // Possible values for $action:
+ // - all (rebuild everything, initialization)
+ // - news (news has been updated)
+ // - boards (board list changed)
+ // - bans (ban list changed)
+
+ PBanlist::build($action, $settings);
+ }
+
+ // Wrap functions in a class so they don't interfere with normal Tinyboard operations
+ class PBanlist {
+ public static function build($action, $settings) {
+ global $config;
+
+ if ($action == 'all')
+ file_write($config['dir']['home'] . $settings['file_bans'], PBanlist::homepage($settings));
+
+ if ($action == 'all' || $action == 'bans')
+ file_write($config['dir']['home'] . $settings['file_json'], PBanlist::gen_json($settings));
+ }
+
+ public static function gen_json($settings) {
+ ob_start();
+ Bans::stream_json(false, false, !hasPermission($config['mod']['view_banstaff']), $mod['boards']);
+ $out = ob_get_contents();
+ ob_end_clean();
+ return $out;
+ }
+
+ // Build homepage
+ public static function homepage($settings) {
+ global $config;
+
+ return Element('page.html', array(
+ 'config' => $config,
+ 'mod' => false,
+ 'hide_dashboard_link' => true,
+ 'title' => _("Ban list"),
+ 'subtitle' => "",
+ 'nojavascript' => true,
+ 'body' => Element('mod/ban_list.html', array(
+ 'mod' => false,
+ 'boards' => "[]",
+ 'token' => false,
+ 'token_json' => false,
+ 'uri_json' => $config['dir']['home'] . $settings['file_json'],
+ ))
+ ));
+ }
+ };
+
+?>
diff --git a/templates/themes/ukko/theme.php b/templates/themes/ukko/theme.php
index b2624ed7..058fc77b 100644
--- a/templates/themes/ukko/theme.php
+++ b/templates/themes/ukko/theme.php
@@ -4,7 +4,11 @@
function ukko_build($action, $settings) {
$ukko = new ukko();
$ukko->settings = $settings;
-
+
+ if (! ($action == 'all' || $action == 'post' || $action == 'post-thread' || $action == 'post-delete')) {
+ return;
+ }
+
file_write($settings['uri'] . '/index.html', $ukko->build());
file_write($settings['uri'] . '/ukko.js', Element('themes/ukko/ukko.js', array()));
}