This commit is contained in:
albert
2010-10-08 18:42:26 -04:00
parent 6bc469b05d
commit f051e04550
88 changed files with 2865 additions and 699 deletions

View File

@@ -108,6 +108,10 @@ class AnonymousUser
"medium"
end
def blacklisted_tags
[]
end
%w(member banned privileged contributor janitor moderator admin).each do |name|
define_method("is_#{name}?") do
false

View File

@@ -5,7 +5,7 @@ class CurrentUser
self.user = user
self.ip_addr = ip_addr
begin
yield
ensure
@@ -13,7 +13,7 @@ class CurrentUser
self.ip_addr = old_ip_addr
end
end
def self.user=(user)
Thread.current[:current_user] = user
end

View File

@@ -2,52 +2,62 @@ require 'cgi'
class DText
def self.parse_inline(str, options = {})
str = str.gsub(/&/, "&")
str.gsub!(/</, "&lt;")
str.gsub!(/>/, "&gt;")
str.gsub!(/\[\[.+?\]\]/m) do |tag|
tag = tag[2..-3]
if tag =~ /^(.+?)\|(.+)$/
tag = $1
name = $2
'<a href="/wiki/show?title=' + CGI.escape(CGI.unescapeHTML(tag.tr(" ", "_").downcase)) + '">' + name + '</a>'
else
'<a href="/wiki/show?title=' + CGI.escape(CGI.unescapeHTML(tag.tr(" ", "_").downcase)) + '">' + tag + '</a>'
end
end
str.gsub!(/\{\{.+?\}\}/m) do |tag|
tag = tag[2..-3]
'<a href="/post/index?tags=' + CGI.escape(CGI.unescapeHTML(tag)) + '">' + tag + '</a>'
end
str.gsub!(/[Pp]ost #(\d+)/, '<a href="/post/show/\1">post #\1</a>')
str.gsub!(/[Ff]orum #(\d+)/, '<a href="/forum/show/\1">forum #\1</a>')
str.gsub!(/[Cc]omment #(\d+)/, '<a href="/comment/show/\1">comment #\1</a>')
str.gsub!(/[Pp]ool #(\d+)/, '<a href="/pool/show/\1">pool #\1</a>')
str = parse_aliased_wiki_links(str)
str = parse_wiki_links(str)
str = parse_post_links(str)
str = parse_id_links(str)
str.gsub!(/\n/m, "<br>")
str.gsub!(/\[b\](.+?)\[\/b\]/, '<strong>\1</strong>')
str.gsub!(/\[i\](.+?)\[\/i\]/, '<em>\1</em>')
str.gsub!(/\[b\](.+?)\[\/b\]/i, '<strong>\1</strong>')
str.gsub!(/\[i\](.+?)\[\/i\]/i, '<em>\1</em>')
str.gsub!(/\[spoilers?\](.+?)\[\/spoilers?\]/m, '<span class="spoiler">\1</span>')
str.gsub!(/("[^"]+":(http:\/\/|\/)\S+|http:\/\/\S+)/m) do |link|
if link =~ /^"([^"]+)":(.+)$/
text = $1
link = $2
else
text = link
end
if link =~ /([;,.!?\)\]<>])$/
link.chop!
ch = $1
else
ch = ""
end
link.gsub!(/"/, '&quot;')
'<a href="' + link + '">' + text + '</a>' + ch
str.gsub!(/\[url\](.+?)\[\/url\]/i) do
%{<a href="#{u($1)}">#{h($1)}</a>}
end
str.gsub!(/\[url=(.+?)\](.+?)\[\/url\]/m) do
%{<a href="#{u($1)}">#{h($2)}</a>}
end
str
end
def self.parse_aliased_wiki_links(str)
str.gsub(/\[\[(.+?)\|(.+?)\]\]/m) do
text = $1
title = $2
wiki_page = WikiPage.find_title_and_id(title)
if wiki_page
%{[url=/wiki_pages/#{wiki_page.id}]#{text}[/url]}
else
%{[url=/wiki_pages/new?title=#{title}]#{text}[/url]}
end
end
end
def self.parse_wiki_links(str)
str.gsub(/\[\[(.+?)\]\]/) do
title = $1
wiki_page = WikiPage.find_title_and_id(title)
if wiki_page
%{[url=/wiki_pages/#{wiki_page.id}]#{title}[/url]}
else
%{[url=/wiki_pages/new?title=#{title}]#{title}[/url]}
end
end
end
def self.parse_post_links(str)
str.gsub(/\{\{(.+?)\}\}/, %{[url=/posts?tags=\1]\1[/url]})
end
def self.parse_id_links(str)
str = str.gsub(/\bpost #(\d+)/i, %{[url=/posts/\1]post #\1[/url]})
str = str.gsub(/\bforum #(\d+)/i, %{[url=/forum_posts/\1]forum #\1[/url]})
str = str.gsub(/\bcomment #(\d+)/i, %{[url=/comments/\1]comment #\1[/url]})
str = str.gsub(/\bpool #(\d+)/i, %{[url=/pools/\1]pool #\1[/url]})
end
def self.parse_list(str, options = {})
html = ""
layout = []

View File

@@ -11,6 +11,7 @@ class PostSet
@errors = []
load_associations
load_posts
load_suggestions
validate
end
@@ -54,8 +55,12 @@ class PostSet
@posts = Post.find_by_tags(tags, :before_id => before_id).all(:order => "posts.id desc", :limit => limit, :offset => offset)
end
def load_suggestions(count)
@suggestions = Tag.find_suggestions(tags) if count < limit && is_single_tag?
def load_suggestions
if count < limit && is_single_tag?
@suggestions = Tag.find_suggestions(tags)
else
@suggestions = []
end
end
def tag_array

View File

@@ -0,0 +1,35 @@
class RemoteServer
attr_accessor :hostname
def self.other_servers
Danbooru.config.other_server_hosts.map {|x| new(x)}
end
def self.copy_to_all(local_path, remote_path)
other_servers.each do |server|
server.copy(local_path, remote_path)
end
end
def self.delete_from_all(remote_path)
other_servers.each do |server|
server.delete(remote_path)
end
end
def initialize(hostname)
@hostname = hostname
end
def copy(local_path, remote_path)
Net::SFTP.start(hostname, Danbooru.config.remote_server_login) do |ftp|
ftp.upload!(local_path, remote_path)
end
end
def delete(remote_path)
Net::SFTP.start(hostname, Danbooru.config.remote_server_login) do |ftp|
ftp.remove(remote_path)
end
end
end