Merge branch 'master' of https://github.com/r888888888/danbooru
This commit is contained in:
62
app/assets/stylesheets/mobile.css.scss
Normal file
62
app/assets/stylesheets/mobile.css.scss
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
*= require "./common/010_reset"
|
||||
*= require "./common/020_base"
|
||||
*= require "./common/030_links"
|
||||
*/
|
||||
|
||||
body {
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
/* paginator */
|
||||
div.paginator {
|
||||
font-size: 20pt;
|
||||
font-weight: bold;
|
||||
text-align: center;
|
||||
|
||||
li {
|
||||
display: inline;
|
||||
|
||||
a, span {
|
||||
border: 1px solid #EAEAEA;
|
||||
padding: 3px 18px;
|
||||
margin: 0 3px;
|
||||
display: inline-block;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* posts/index */
|
||||
article.post-preview {
|
||||
margin: 15px 0;
|
||||
width: 150px;
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
display: inline-block;
|
||||
a {
|
||||
width: 150px;
|
||||
display: block;
|
||||
margin: 0 auto;
|
||||
}
|
||||
img {
|
||||
margin: 0 auto;
|
||||
}
|
||||
}
|
||||
|
||||
/* posts/show */
|
||||
img#image {
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
div#tags {
|
||||
margin-top: 10px;
|
||||
|
||||
li {
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
a.search-tag {
|
||||
font-size: 24pt;
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
18
app/controllers/mobile/posts_controller.rb
Normal file
18
app/controllers/mobile/posts_controller.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
class Mobile::PostsController < ApplicationController
|
||||
layout "mobile"
|
||||
before_filter :set_mobile_mode
|
||||
|
||||
def index
|
||||
@post_set = PostSets::Post.new(params[:tags], params[:page], CurrentUser.user.per_page, false)
|
||||
@posts = @post_set.posts
|
||||
end
|
||||
|
||||
def show
|
||||
@post = Post.find(params[:id])
|
||||
end
|
||||
|
||||
private
|
||||
def set_mobile_mode
|
||||
CurrentUser.mobile_mode = true
|
||||
end
|
||||
end
|
||||
@@ -11,6 +11,7 @@ class CurrentUser
|
||||
ensure
|
||||
self.user = old_user
|
||||
self.ip_addr = old_ip_addr
|
||||
self.mobile_mode = false
|
||||
end
|
||||
end
|
||||
|
||||
@@ -30,6 +31,14 @@ class CurrentUser
|
||||
Thread.current[:current_ip_addr]
|
||||
end
|
||||
|
||||
def self.mobile_mode=(mode)
|
||||
Thread.current[:mobile_mode] = mode
|
||||
end
|
||||
|
||||
def self.mobile_mode?
|
||||
Thread.current[:mobile_mode]
|
||||
end
|
||||
|
||||
def self.id
|
||||
if user.nil?
|
||||
nil
|
||||
|
||||
@@ -118,6 +118,10 @@ class Post < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def file_url_for(user)
|
||||
if CurrentUser.mobile_mode?
|
||||
return large_file_url
|
||||
end
|
||||
|
||||
case user.default_image_size
|
||||
when "large"
|
||||
if image_width > Danbooru.config.large_image_width
|
||||
@@ -132,6 +136,10 @@ class Post < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def file_path_for(user)
|
||||
if CurrentUser.mobile_mode?
|
||||
return large_file_path
|
||||
end
|
||||
|
||||
case user.default_image_size
|
||||
when "large"
|
||||
if image_width > Danbooru.config.large_image_width
|
||||
@@ -155,6 +163,14 @@ class Post < ActiveRecord::Base
|
||||
end
|
||||
|
||||
module ImageMethods
|
||||
def device_scale
|
||||
if large_image_width > 320
|
||||
320.0 / (large_image_width + 10)
|
||||
else
|
||||
1.0
|
||||
end
|
||||
end
|
||||
|
||||
def twitter_card_supported?
|
||||
image_width.to_i >= 280 && image_height.to_i >= 150
|
||||
end
|
||||
@@ -181,6 +197,10 @@ class Post < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def image_width_for(user)
|
||||
if CurrentUser.mobile_mode?
|
||||
return large_image_width
|
||||
end
|
||||
|
||||
case user.default_image_size
|
||||
when "large"
|
||||
large_image_width
|
||||
@@ -191,6 +211,10 @@ class Post < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def image_height_for(user)
|
||||
if CurrentUser.mobile_mode?
|
||||
return large_image_height
|
||||
end
|
||||
|
||||
case user.default_image_size
|
||||
when "large"
|
||||
large_image_height
|
||||
|
||||
@@ -4,7 +4,7 @@ module PostSetPresenters
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def post_previews_html(template)
|
||||
def post_previews_html(template, options = {})
|
||||
html = ""
|
||||
|
||||
if posts.empty?
|
||||
@@ -12,7 +12,7 @@ module PostSetPresenters
|
||||
end
|
||||
|
||||
posts.each do |post|
|
||||
html << PostPresenter.preview(post, :tags => @post_set.tag_string, :raw => @post_set.raw)
|
||||
html << PostPresenter.preview(post, options.merge(:tags => @post_set.tag_string, :raw => @post_set.raw))
|
||||
html << "\n"
|
||||
end
|
||||
|
||||
|
||||
@@ -48,8 +48,8 @@ module PostSetPresenters
|
||||
RelatedTagCalculator.calculate_from_post_set_to_array(post_set).map(&:first)
|
||||
end
|
||||
|
||||
def tag_list_html(template)
|
||||
tag_set_presenter.tag_list_html(template)
|
||||
def tag_list_html(template, options = {})
|
||||
tag_set_presenter.tag_list_html(template, options)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
20
app/views/layouts/mobile.html.erb
Normal file
20
app/views/layouts/mobile.html.erb
Normal file
@@ -0,0 +1,20 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title><%= yield :page_title %></title>
|
||||
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
|
||||
<%= csrf_meta_tag %>
|
||||
<%= stylesheet_link_tag "mobile", :media => "screen" %>
|
||||
<%= javascript_include_tag "mobile" %>
|
||||
<%= Danbooru.config.custom_html_header_content %>
|
||||
<%= yield :html_header %>
|
||||
</head>
|
||||
<body lang="en">
|
||||
<header id="top">
|
||||
<h1><%= link_to Danbooru.config.app_name, "/" %></h1>
|
||||
</header>
|
||||
<div id="page">
|
||||
<%= yield :layout %>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
16
app/views/mobile/posts/index.html.erb
Normal file
16
app/views/mobile/posts/index.html.erb
Normal file
@@ -0,0 +1,16 @@
|
||||
<%= form_tag(m_posts_path, :method => "get") do %>
|
||||
<%= text_field_tag("tags", params[:tags], :size => 30) %>
|
||||
<%= submit_tag "Go", :name => nil %>
|
||||
<% end %>
|
||||
|
||||
<%= @post_set.presenter.post_previews_html(self, :path_prefix => "/m/posts") %>
|
||||
|
||||
<%= numbered_paginator(@post_set.posts) %>
|
||||
|
||||
<div id="tags">
|
||||
<%= @post_set.presenter.tag_list_html(self, :name_only => true, :path_prefix => "/m/posts") %>
|
||||
</div>
|
||||
|
||||
<%= content_for(:html_header) do %>
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<% end %>
|
||||
14
app/views/mobile/posts/show.html.erb
Normal file
14
app/views/mobile/posts/show.html.erb
Normal file
@@ -0,0 +1,14 @@
|
||||
<%= form_tag(m_posts_path, :method => "get") do %>
|
||||
<%= text_field_tag("tags", params[:tags], :size => 20) %>
|
||||
<%= submit_tag "Go", :name => nil %>
|
||||
<% end %>
|
||||
|
||||
<%= @post.presenter.image_html(self) %>
|
||||
|
||||
<div id="tags">
|
||||
<%= @post.presenter.tag_list_html(self, :name_only => true, :path_prefix => "/m/posts") %>
|
||||
</div>
|
||||
|
||||
<%= content_for(:html_header) do %>
|
||||
<meta name="viewport" content="width=device-width,initial-scale=<%= @post.device_scale %>">
|
||||
<% end %>
|
||||
@@ -10,5 +10,7 @@
|
||||
<% end %>
|
||||
|
||||
<li><%= link_to "Random post", random_posts_path(:tags => params[:tags]) %></li>
|
||||
|
||||
<li><%= link_to "Mobile version", m_posts_path(:tags => params[:tags]) %></li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
@@ -49,6 +49,8 @@
|
||||
<% if CurrentUser.is_admin? %>
|
||||
<li><%= link_to "Expunge", expunge_moderator_post_post_path(:post_id => post.id), :remote => true, :method => :post, :id => "expunge", :confirm => "This will permanently delete this post (meaning the file will be deleted). Are you sure you want to delete this post?" %></li>
|
||||
<% end %>
|
||||
|
||||
<li><%= link_to "Mobile version", m_post_path(post) %></li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
@@ -3,6 +3,9 @@ Danbooru::Application.routes.draw do
|
||||
resources :users, :only => [:edit, :update]
|
||||
resource :alias_and_implication_import, :only => [:new, :create]
|
||||
end
|
||||
namespace :mobile do
|
||||
resources :posts, :only => [:index, :show]
|
||||
end
|
||||
namespace :moderator do
|
||||
resource :dashboard, :only => [:show]
|
||||
resources :ip_addrs, :only => [:index] do
|
||||
@@ -257,6 +260,8 @@ Danbooru::Application.routes.draw do
|
||||
resources :wpages, :controller => "wiki_pages"
|
||||
resources :ftopics, :controller => "forum_topics"
|
||||
resources :fposts, :controller => "forum_posts"
|
||||
match "/m/posts", :controller => "mobile/posts", :action => "index"
|
||||
match "/m/posts/:id", :controller => "mobile/posts", :action => "show"
|
||||
|
||||
# legacy aliases
|
||||
match "/artist" => redirect {|params, req| "/artists?page=#{req.params[:page]}&search[name]=#{CGI::escape(req.params[:name].to_s)}"}
|
||||
|
||||
129
db/structure.sql
129
db/structure.sql
@@ -508,6 +508,78 @@ CREATE SEQUENCE amazon_backups_id_seq
|
||||
ALTER SEQUENCE amazon_backups_id_seq OWNED BY amazon_backups.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: artist_commentaries; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
CREATE TABLE artist_commentaries (
|
||||
id integer NOT NULL,
|
||||
post_id integer NOT NULL,
|
||||
original_title text,
|
||||
original_description text,
|
||||
translated_title text,
|
||||
translated_description text,
|
||||
created_at timestamp without time zone NOT NULL,
|
||||
updated_at timestamp without time zone NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: artist_commentaries_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE artist_commentaries_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MAXVALUE
|
||||
NO MINVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: artist_commentaries_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE artist_commentaries_id_seq OWNED BY artist_commentaries.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: artist_commentary_versions; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
CREATE TABLE artist_commentary_versions (
|
||||
id integer NOT NULL,
|
||||
post_id integer NOT NULL,
|
||||
updater_id integer NOT NULL,
|
||||
updater_ip_addr inet NOT NULL,
|
||||
original_title text,
|
||||
original_description text,
|
||||
translated_title text,
|
||||
translated_description text,
|
||||
created_at timestamp without time zone NOT NULL,
|
||||
updated_at timestamp without time zone NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: artist_commentary_versions_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE artist_commentary_versions_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MAXVALUE
|
||||
NO MINVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: artist_commentary_versions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE artist_commentary_versions_id_seq OWNED BY artist_commentary_versions.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: artist_urls; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
@@ -2814,6 +2886,20 @@ ALTER TABLE ONLY advertisements ALTER COLUMN id SET DEFAULT nextval('advertiseme
|
||||
ALTER TABLE ONLY amazon_backups ALTER COLUMN id SET DEFAULT nextval('amazon_backups_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY artist_commentaries ALTER COLUMN id SET DEFAULT nextval('artist_commentaries_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY artist_commentary_versions ALTER COLUMN id SET DEFAULT nextval('artist_commentary_versions_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
@@ -3797,6 +3883,22 @@ ALTER TABLE ONLY amazon_backups
|
||||
ADD CONSTRAINT amazon_backups_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: artist_commentaries_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY artist_commentaries
|
||||
ADD CONSTRAINT artist_commentaries_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: artist_commentary_versions_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY artist_commentary_versions
|
||||
ADD CONSTRAINT artist_commentary_versions_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: artist_urls_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
@@ -4114,6 +4216,27 @@ CREATE INDEX index_advertisement_hits_on_created_at ON advertisement_hits USING
|
||||
CREATE INDEX index_advertisements_on_ad_type ON advertisements USING btree (ad_type);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_artist_commentaries_on_post_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
CREATE UNIQUE INDEX index_artist_commentaries_on_post_id ON artist_commentaries USING btree (post_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_artist_commentary_versions_on_post_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
CREATE INDEX index_artist_commentary_versions_on_post_id ON artist_commentary_versions USING btree (post_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_artist_commentary_versions_on_updater_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
CREATE INDEX index_artist_commentary_versions_on_updater_id ON artist_commentary_versions USING btree (updater_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_artist_urls_on_artist_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
@@ -6431,4 +6554,8 @@ INSERT INTO schema_migrations (version) VALUES ('20130712162600');
|
||||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20130914175431');
|
||||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20131006193238');
|
||||
INSERT INTO schema_migrations (version) VALUES ('20131006193238');
|
||||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20131117150705');
|
||||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20131118153503');
|
||||
Reference in New Issue
Block a user