added pixiv proxy, report mailer
This commit is contained in:
94
app/logical/pixiv_proxy.rb
Normal file
94
app/logical/pixiv_proxy.rb
Normal file
@@ -0,0 +1,94 @@
|
||||
class PixivProxy
|
||||
def self.is_pixiv?(url)
|
||||
url =~ /pixiv\.net/
|
||||
end
|
||||
|
||||
def self.get(url)
|
||||
if url =~ /\/(\d+)(_m)?\.(jpg|jpeg|png|gif)/i
|
||||
url = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=#{$1}"
|
||||
get_single(url)
|
||||
elsif url =~ /member_illust\.php/ && url =~ /illust_id=/
|
||||
get_single(url)
|
||||
# elsif url =~ /member_illust\.php/ && url =~ /id=/
|
||||
# get_listing(url)
|
||||
# elsif url =~ /member\.php/ && url =~ /id=/
|
||||
# get_profile(url)
|
||||
else
|
||||
{}
|
||||
end
|
||||
end
|
||||
|
||||
def self.get_profile(url)
|
||||
url = URI.parse(url).request_uri
|
||||
mech = create_mechanize
|
||||
hash = {}
|
||||
mech.get(url) do |page|
|
||||
hash[:artist] = page.search("div#profile/div/a/img").attr("alt")
|
||||
hash[:listing_url] = "/member_illust.php?id=" + url[/id=(\d+)/, 1]
|
||||
end
|
||||
hash
|
||||
end
|
||||
|
||||
def self.get_single(url)
|
||||
url = URI.parse(url).request_uri
|
||||
mech = create_mechanize
|
||||
hash = {}
|
||||
mech.get(url) do |page|
|
||||
if page.search("div#profile/div/a/img")
|
||||
hash[:artist] = page.search("div#profile/div/a/img").attr("alt")
|
||||
hash[:image_url] = page.search("div#profile/div/a/img").attr("src").sub("_m.", ".")
|
||||
hash[:profile_url] = page.search("div#profile/div/a").attr("href")
|
||||
hash[:jp_tags] = page.search("div#tag_area/span#tags/a").map do |node|
|
||||
[node.inner_text, node.attribute("href").to_s]
|
||||
end
|
||||
else
|
||||
hash[:artist] = "?"
|
||||
hash[:image_url] = "?"
|
||||
hash[:profile_url] = "?"
|
||||
hash[:jp_tags] = []
|
||||
end
|
||||
end
|
||||
hash
|
||||
end
|
||||
|
||||
def self.get_listing(url)
|
||||
mech = create_mechanize
|
||||
p = 1
|
||||
url = URI.parse(url).request_uri.sub(/&p=\d+/, "") + "&p=1"
|
||||
more = true
|
||||
images = []
|
||||
|
||||
while more
|
||||
mech.get(url) do |page|
|
||||
links = page.search("div#illust_c4/ul/li/a")
|
||||
|
||||
if links.empty?
|
||||
more = false
|
||||
else
|
||||
images += links.map do |node|
|
||||
image_src = node.child.attribute("src").to_s
|
||||
[image_src, image_src.sub("_s.", "."), node.attribute("href").to_s]
|
||||
end
|
||||
end
|
||||
|
||||
p += 1
|
||||
url.sub!(/&p=\d+/, "&p=#{p}")
|
||||
end
|
||||
end
|
||||
|
||||
images
|
||||
end
|
||||
|
||||
def self.create_mechanize
|
||||
mech = WWW::Mechanize.new
|
||||
|
||||
mech.get("http://www.pixiv.net") do |page|
|
||||
page.form_with(:action => "index.php") do |form|
|
||||
form.pixiv_id = "uroobnad"
|
||||
form.pass = "uroobnad556"
|
||||
end.click_button
|
||||
end
|
||||
|
||||
mech
|
||||
end
|
||||
end
|
||||
@@ -9,7 +9,8 @@ class Comment < ActiveRecord::Base
|
||||
attr_accessor :do_not_bump_post
|
||||
|
||||
scope :recent, :order => "comments.id desc", :limit => 6
|
||||
scope :search_body, lambda {|query| {:conditions => ["body_index @@ plainto_tsquery(?)", query], :order => "id desc"}}
|
||||
scope :search_body, lambda {|query| where("body_index @@ plainto_tsquery(?)", query)}
|
||||
scope :hidden, lambda {|user| where("score < ?", user.comment_threshold)}
|
||||
|
||||
def update_last_commented_at
|
||||
return if do_not_bump_post
|
||||
|
||||
@@ -42,9 +42,9 @@ class Note < ActiveRecord::Base
|
||||
|
||||
def update_post
|
||||
if Note.exists?(["is_active = ? AND post_id = ?", true, post_id])
|
||||
Post.update(post_id, :last_noted_at => updated_at, :updater_id => updater_id, :updater_ip_addr => updater_ip_addr)
|
||||
execute_sql("UPDATE posts SET last_noted_at = ? WHERE id = ?", updated_at, post_id)
|
||||
else
|
||||
Post.update(post_id, :last_noted_at => nil, :updater_id => updater_id, :updater_ip_addr => updater_ip_addr)
|
||||
execute_sql("UPDATE posts SET last_noted_at = NULL WHERE id = ?", post_id)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -499,6 +499,20 @@ class Post < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
module CountMethods
|
||||
def fast_count(tags)
|
||||
Cache.get("pfc:#{Cache.sanitize(tags)}", 24.hours) do
|
||||
Post.find_by_tags(tags).count
|
||||
end
|
||||
end
|
||||
|
||||
def fast_delete_count(tags)
|
||||
Cache.get("pfdc:#{Cache.sanitize(tags)}", 24.hours) do
|
||||
Post.find_by_tags("#{tags} status:deleted").count
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
include FileMethods
|
||||
include ImageMethods
|
||||
include ModerationMethods
|
||||
@@ -510,6 +524,7 @@ class Post < ActiveRecord::Base
|
||||
include PoolMethods
|
||||
extend SearchMethods
|
||||
include VoteMethods
|
||||
extend CountMethods
|
||||
|
||||
def reload(options = nil)
|
||||
super
|
||||
|
||||
7
app/models/report_mailer.rb
Normal file
7
app/models/report_mailer.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
class ReportMailer < ActionMailer::Base
|
||||
default :host => Danbooru.config.server_host, :from => Danbooru.config.contact_email, :content_type => "text/html"
|
||||
|
||||
def moderator_report(email)
|
||||
mail(:to => email, :subject => "#{Danbooru.config.app_name} - Moderator Report")
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user