implemented blacklists

This commit is contained in:
albert 2011-08-07 15:44:54 -04:00
parent cbf3347eff
commit c6888984db
10 changed files with 174 additions and 13 deletions

View File

@ -0,0 +1,116 @@
(function() {
Danbooru.Blacklist = {};
Danbooru.Blacklist.blacklists = [];
Danbooru.Blacklist.parse_entries = function() {
var entries = (Danbooru.meta("blacklisted-tags") || "").replace(/(rating:[qes])\w+/, "$1").split(/,/);
$.each(entries, function(i, tags) {
var blacklist = {
"tags": tags,
"require": [],
"exclude": [],
"disabled": false,
"hits": 0
};
var matches = tags.match(/\S+/g) || [];
$.each(matches, function(i, tag) {
if (tag.charAt(0) === '-') {
blacklist.exclude.push(tag.slice(1));
} else {
blacklist.require.push(tag);
}
})
Danbooru.Blacklist.blacklists.push(blacklist);
});
}
Danbooru.Blacklist.toggle = function(e) {
$(".blacklisted").each(function(i, element) {
var $element = $(element);
if ($element.hasClass("blacklisted-active")) {
$element.removeClass("blacklisted-active");
} else {
$element.addClass("blacklisted-active");
}
});
}
Danbooru.Blacklist.update_sidebar = function() {
$.each(this.blacklists, function(i, blacklist) {
if (blacklist.hits === 0) {
return;
}
var item = $("<li/>");
var link = $("<a/>");
var count = $("<span/>");
link.html(blacklist.tags);
link.click(Danbooru.Blacklist.toggle);
count.html(blacklist.hits);
item.append(link);
item.append(" ");
item.append(count);
$("#blacklist-list").append(item);
});
$("#blacklist-box").show();
}
Danbooru.Blacklist.apply = function() {
$.each(this.blacklists, function(i, blacklist) {
blacklist.hits = 0;
});
var count = 0
$.each(this.posts(), function(i, post) {
$.each(Danbooru.Blacklist.blacklists, function(i, blacklist) {
if (Danbooru.Blacklist.post_match(post, blacklist)) {
Danbooru.Blacklist.post_hide(post);
blacklist.hits += 1;
count += 1;
}
});
});
return count;
}
Danbooru.Blacklist.posts = function() {
return $("article.post-preview");
}
Danbooru.Blacklist.post_match = function(post, blacklist) {
var $post = $(post);
var tags = $post.data("tags").match(/\S+/g) || [];
tags.push("rating:" + $post.data("rating"));
tags.push("uploader:" + $post.data("uploader"));
if (Danbooru.is_subset(tags, blacklist.require)) {
if (blacklist.exclude.length == 0 || (!Danbooru.is_subset(tags, blacklist.exclude))) {
return true;
}
}
return false;
}
Danbooru.Blacklist.post_hide = function(post) {
var $post = $(post);
$post.addClass("blacklisted").addClass("blacklisted-active");
}
Danbooru.Blacklist.initialize = function() {
Danbooru.Blacklist.parse_entries();
if (Danbooru.Blacklist.apply() > 0) {
Danbooru.Blacklist.update_sidebar();
} else {
$("#blacklist-box").hide();
}
}
})();
$(document).ready(function() {
Danbooru.Blacklist.initialize();
});

View File

@ -54,9 +54,9 @@
if (this.get("hide-news-ticker") == "1") {
$("#news-ticker").hide();
} else {
$("#close-news-ticker-link").observe("click", function(e) {
$("#close-news-ticker-link").click(function(e) {
$("#news-ticker").hide();
this.put("hide-news-ticker", "1", 1);
Danbooru.Cookie.put("hide-news-ticker", "1", 1);
return false;
});
}
@ -67,7 +67,7 @@
}
})();
$(document).ready(function() {
$(function() {
Danbooru.Cookie.initialize();
});

View File

@ -18,4 +18,16 @@
Danbooru.ajax_stop = function(target) {
$(target).next("img.wait").remove();
}
Danbooru.is_subset = function(array, subarray) {
var all = true;
$.each(subarray, function(i, val) {
if ($.inArray(val, array) === -1) {
all = false;
}
});
return all;
}
})();

View File

@ -626,6 +626,10 @@ article.post-preview {
float: left;
}
article.post-preview.blacklisted-active {
display: none;
}
div#c-posts {
div.notice {
font-size: 0.8em;
@ -650,6 +654,23 @@ div#c-posts {
aside#sidebar > section > ul ul li {
margin-left: 1em;
}
aside#sidebar > section#blacklist-box ul {
margin-left: 1em;
li {
list-style-type: disc;
}
a {
color: $link_color;
cursor: pointer;
}
span {
color: #AAA;
}
}
h1 {
font-size: $h3_size;
@ -1048,6 +1069,14 @@ div#moderator-dashboard {
}
/*** page footer ***/
footer#page-footer {
clear: both;
margin: 1em;
text-align: center;
padding-top: 1em;
border-top: 2px solid #CCC;
}
/*** news ticker ***/
@ -1074,4 +1103,4 @@ div#news-ticker {
a#close-news-ticker-link {
float: right;
}
}
}

View File

@ -66,5 +66,7 @@
<footer>
<%= yield :page_footer_content %>
</footer>
<%= render "static/footer" %>
</body>
</html>

View File

@ -5,12 +5,12 @@
<%= render :partial => "posts/partials/index/mode_menu" %>
<%= render :partial => "posts/partials/index/blacklist" %>
<section id="tag-box">
<h1>Tags</h1>
<%= @post_set.presenter.tag_list_html(self) %>
</section>
<%= render :partial => "posts/partials/index/blacklist" %>
</aside>
<section id="content">

View File

@ -1,6 +1,5 @@
<section id="blacklist-box">
<h1>Blacklisted</h1>
<%= link_to "Hidden", "#" %>
<ul>
<ul id="blacklist-list">
</ul>
</section>

View File

@ -6,12 +6,12 @@
<li><%= link_to "Flag", new_post_flag_path(:post_id => post.id), :id => "flag" %></li>
<li><%= link_to "Appeal", new_post_appeal_path(:post_id => post.id), :id => "appeal" %></li>
<% if CurrentUser.is_janitor? %>
<li><%= link_to "Approve", moderation_post_approval_path(:post_id => post.id), :remote => true, :method => :post, :id => "approve" %></li>
<li><%= link_to "Disapprove", moderation_post_approval_path(:post_id => post.id), :remote => true, :method => :destroy, :id => "disapprove" %></li>
<li><%= link_to "Approve", moderator_post_approval_path(:post_id => post.id), :remote => true, :method => :post, :id => "approve" %></li>
<li><%= link_to "Disapprove", moderator_post_disapproval_path(:post_id => post.id), :remote => true, :method => :post, :id => "disapprove" %></li>
<% end %>
<% if CurrentUser.is_moderator? %>
<li><%= link_to "Undelete", moderation_post_deletion_path(:post_id => post.id), :remote => true, :method => :destroy, :id => "undelete" %></li>
<li><%= link_to "Delete", moderation_post_deletion_path(:post_id => post.id), :remote => true, :method => :post, :id => "delete" %></li>
<li><%= link_to "Undelete", undelete_moderator_post_post_path(:post_id => post.id), :remote => true, :method => :post, :id => "undelete" %></li>
<li><%= link_to "Delete", delete_moderator_post_post_path(:post_id => post.id), :remote => true, :method => :post, :id => "delete" %></li>
<% end %>
<li><%= link_to "Pool", "#", :id => "pool" %></li>
</ul>

View File

@ -0,0 +1,3 @@
<footer id="page-footer">
Running Danbooru v<%= Danbooru.config.version %>. <%= mail_to Danbooru.config.contact_email, "Contact", :encode => :hex %>.
</footer>

View File

@ -12,7 +12,7 @@ module Danbooru
# Contact email address of the admin.
def contact_email
"webmaster#{server_host}"
"webmaster@#{server_host}"
end
# Stripped of any special characters.