diff --git a/app/assets/javascripts/uploads.js b/app/assets/javascripts/uploads.js index 5e3b9b502..9741399b1 100644 --- a/app/assets/javascripts/uploads.js +++ b/app/assets/javascripts/uploads.js @@ -13,6 +13,11 @@ this.initialize_similar(); $("#related-tags-button").trigger("click"); $("#find-artist-button").trigger("click"); + + $("#toggle-artist-commentary").click(function(e) { + Danbooru.Upload.toggle_commentary(); + e.preventDefault(); + }); } if ($("#iqdb-similar").length) { @@ -105,6 +110,7 @@ $("#upload_artist_commentary_title").val(data.artist_commentary.dtext_title); $("#upload_artist_commentary_desc").val(data.artist_commentary.dtext_description); + Danbooru.Upload.toggle_commentary(); $("#source-info span#loading-data").hide(); $("#source-info ul").show(); @@ -133,6 +139,16 @@ $("#image-resize-to-window-link").click(Danbooru.Upload.update_scale); } } + + Danbooru.Upload.toggle_commentary = function() { + if ($(".artist-commentary").is(":visible")) { + $("#toggle-artist-commentary").text("show »"); + } else { + $("#toggle-artist-commentary").text("« hide"); + } + + $(".artist-commentary").slideToggle(); + }; })(); $(function() { diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 0f59a2b9f..97036688e 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -4,7 +4,7 @@ class CommentsController < ApplicationController skip_before_filter :api_check def index - if params[:group_by] == "comment" + if params[:group_by] == "comment" || request.format == Mime::ATOM index_by_comment elsif request.format == Mime::JS index_for_post @@ -92,6 +92,10 @@ private @comments = Comment.search(params[:search]).paginate(params[:page], :limit => params[:limit], :search_count => params[:search]) respond_with(@comments) do |format| format.html {render :action => "index_by_comment"} + format.atom do + @comments = @comments.includes(:post, :creator).load + render :action => "index" + end format.xml do render :xml => @comments.to_xml(:root => "comments") end diff --git a/app/controllers/forum_topics_controller.rb b/app/controllers/forum_topics_controller.rb index bda3d3bb4..648258013 100644 --- a/app/controllers/forum_topics_controller.rb +++ b/app/controllers/forum_topics_controller.rb @@ -20,9 +20,15 @@ class ForumTopicsController < ApplicationController def index @query = ForumTopic.active.search(params[:search]) - @forum_topics = @query.includes([:creator, :updater]).order("is_sticky DESC, updated_at DESC").paginate(params[:page], :limit => per_page, :search_count => params[:search]) + @forum_topics = @query.order("is_sticky DESC, updated_at DESC").paginate(params[:page], :limit => per_page, :search_count => params[:search]) respond_with(@forum_topics) do |format| + format.html do + @forum_topics = @forum_topics.includes(:creator, :updater).load + end + format.atom do + @forum_topics = @forum_topics.includes(:creator, :original_post).load + end format.json do render :json => @forum_topics.to_json end @@ -37,8 +43,11 @@ class ForumTopicsController < ApplicationController @forum_topic.mark_as_read!(CurrentUser.user) end @forum_posts = ForumPost.search(:topic_id => @forum_topic.id).order("forum_posts.id").paginate(params[:page]) - @forum_posts.each # hack to force rails to eager load - respond_with(@forum_topic) + respond_with(@forum_topic) do |format| + format.atom do + @forum_posts = @forum_posts.includes(:creator).load + end + end end def create diff --git a/app/logical/sources/strategies/pixiv.rb b/app/logical/sources/strategies/pixiv.rb index cf0fc0215..e5f1a379f 100644 --- a/app/logical/sources/strategies/pixiv.rb +++ b/app/logical/sources/strategies/pixiv.rb @@ -79,7 +79,9 @@ module Sources @profile_url = get_profile_from_page(page) @pixiv_moniker = @metadata.moniker @zip_url, @ugoira_frame_data, @ugoira_content_type = get_zip_url_from_page(page) - @tags = @metadata.tags + @tags = @metadata.tags.map do |tag| + [tag, "https://www.pixiv.net/search.php?s_mode=s_tag_full&#{{word: tag}.to_param}"] + end @page_count = @metadata.page_count @artist_commentary_title = @metadata.artist_commentary_title @artist_commentary_desc = @metadata.artist_commentary_desc @@ -299,30 +301,6 @@ module Sources end end - def get_tags_from_page(page) - # puts page.root.to_xhtml - - links = page.search("ul.tags a.text").find_all do |node| - node["href"] =~ /search\.php/ - end - - original_flag = page.search("a.original-works") - - if links.any? - links.map! do |node| - [node.inner_text, "http://www.pixiv.net" + node.attr("href")] - end - - if original_flag.any? - links << ["オリジナル", "http://www.pixiv.net/search.php?s_mode=s_tag_full&word=%E3%82%AA%E3%83%AA%E3%82%B8%E3%83%8A%E3%83%AB"] - end - - links - else - [] - end - end - def get_page_count_from_page(page) elements = page.search("ul.meta li").find_all do |node| node.text =~ /Manga|漫画|複数枚投稿|Multiple images/ diff --git a/app/views/comments/index.atom.builder b/app/views/comments/index.atom.builder new file mode 100644 index 000000000..0c0396626 --- /dev/null +++ b/app/views/comments/index.atom.builder @@ -0,0 +1,24 @@ +atom_feed do |feed| + title = "Comments" + title += " by #{params[:search][:creator_name]}" if params.dig(:search, :creator_name).present? + title += " on #{params[:search][:post_tags_match]}" if params.dig(:search, :post_tags_match).present? + + feed.title(title) + feed.updated(@comments.first.try(:updated_at)) + + @comments.each do |comment| + feed.entry(comment, published: comment.created_at, updated: comment.updated_at) do |entry| + entry.title("@#{comment.creator_name} on post ##{comment.post_id} (#{comment.post.humanized_essential_tag_string})") + entry.content(<<-EOS.strip_heredoc, type: "html") + + + #{format_text(comment.body)} + EOS + + entry.author do |author| + author.name(comment.creator_name) + author.uri(user_url(comment.creator)) + end + end + end +end diff --git a/app/views/comments/index_by_comment.html.erb b/app/views/comments/index_by_comment.html.erb index fbe15cf40..99844b99f 100644 --- a/app/views/comments/index_by_comment.html.erb +++ b/app/views/comments/index_by_comment.html.erb @@ -29,3 +29,5 @@ <% content_for(:page_title) do %> Comments - <%= Danbooru.config.app_name %> <% end %> + +<% content_for(:html_header, auto_discovery_link_tag(:atom, comments_url(:atom, search: params[:search]), title: "Comments")) %> diff --git a/app/views/comments/index_by_post.html.erb b/app/views/comments/index_by_post.html.erb index d49f4c54f..3a496249b 100644 --- a/app/views/comments/index_by_post.html.erb +++ b/app/views/comments/index_by_post.html.erb @@ -37,3 +37,5 @@ <% content_for(:page_title) do %> Comments - <%= Danbooru.config.app_name %> <% end %> + +<% content_for(:html_header, auto_discovery_link_tag(:atom, comments_url(:atom, search: { do_not_bump_post: true }), title: "Comments")) %> diff --git a/app/views/forum_topics/index.atom.builder b/app/views/forum_topics/index.atom.builder new file mode 100644 index 000000000..c610dc19a --- /dev/null +++ b/app/views/forum_topics/index.atom.builder @@ -0,0 +1,16 @@ +atom_feed do |feed| + feed.title("Forum Topics") + feed.updated(@forum_topics.first.try(:updated_at)) + + @forum_topics.each do |topic| + feed.entry(topic, published: topic.created_at, updated: topic.updated_at) do |entry| + entry.title("[#{topic.category_name}] #{topic.title}") + entry.content(format_text(topic.original_post.body), type: "html") + + entry.author do |author| + author.name(topic.creator.name) + author.uri(user_url(topic.creator_id)) + end + end + end +end diff --git a/app/views/forum_topics/index.html.erb b/app/views/forum_topics/index.html.erb index 472e32b54..f59fd4af6 100644 --- a/app/views/forum_topics/index.html.erb +++ b/app/views/forum_topics/index.html.erb @@ -22,3 +22,5 @@ <% content_for(:page_title) do %> Forum - <%= Danbooru.config.app_name %> <% end %> + +<% content_for(:html_header, auto_discovery_link_tag(:atom, forum_topics_url(:atom), title: "Forum Topics")) %> diff --git a/app/views/forum_topics/show.atom.builder b/app/views/forum_topics/show.atom.builder new file mode 100644 index 000000000..c946e9eda --- /dev/null +++ b/app/views/forum_topics/show.atom.builder @@ -0,0 +1,16 @@ +atom_feed do |feed| + feed.title(@forum_topic.title) + feed.updated(@forum_topic.try(:updated_at)) + + @forum_posts.each do |post| + feed.entry(post, published: post.created_at, updated: post.updated_at) do |entry| + entry.title("@#{post.creator.name}: #{strip_dtext(post.body).truncate(50, separator: /[[:space:]]/)}") + entry.content(format_text(post.body), type: "html") + + entry.author do |author| + author.name(post.creator.name) + author.uri(user_url(post.creator)) + end + end + end +end diff --git a/app/views/forum_topics/show.html.erb b/app/views/forum_topics/show.html.erb index 0b999223a..2f74bfefd 100644 --- a/app/views/forum_topics/show.html.erb +++ b/app/views/forum_topics/show.html.erb @@ -57,3 +57,5 @@ }); <% end %> + +<% content_for(:html_header, auto_discovery_link_tag(:atom, forum_topics_url(@forum_topic, :atom), title: @forum_topic.title)) %> diff --git a/app/views/static/site_map.html.erb b/app/views/static/site_map.html.erb index a67fd8ee1..496d85807 100644 --- a/app/views/static/site_map.html.erb +++ b/app/views/static/site_map.html.erb @@ -73,11 +73,13 @@
  • Comments

  • <%= link_to("Help", wiki_pages_path(:title => "help:comments")) %>
  • <%= link_to("Listing", comments_path) %>
  • +
  • <%= link_to("RSS", comments_path(:atom)) %>