From c3b78b1752d8009d1d4700712435454e082d812e Mon Sep 17 00:00:00 2001 From: r888888888 Date: Tue, 23 Aug 2016 18:20:21 -0700 Subject: [PATCH] add user searches --- app/helpers/application_helper.rb | 2 +- app/helpers/posts_helper.rb | 12 ++++++++++++ app/models/user.rb | 3 ++- app/views/posts/index.html.erb | 2 ++ app/views/static/test.html.erb | 1 + app/views/users/_common_searches.html.erb | 17 +++++++++++++++++ app/views/users/edit.html.erb | 2 ++ config/schedule.rb | 2 +- 8 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 app/views/static/test.html.erb create mode 100644 app/views/users/_common_searches.html.erb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 873b70298..a4b8271bb 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -145,7 +145,7 @@ module ApplicationHelper string += '' string.html_safe end - + protected def nav_link_match(controller, url) url =~ case controller diff --git a/app/helpers/posts_helper.rb b/app/helpers/posts_helper.rb index 67120e1d2..cada08b1c 100644 --- a/app/helpers/posts_helper.rb +++ b/app/helpers/posts_helper.rb @@ -28,6 +28,18 @@ module PostsHelper return nil end + def common_searches_html(user) + return nil unless Danbooru.config.enable_post_search_counts + return nil unless user.is_platinum? + return nil unless user.enable_recent_searches? + + key = "uid" + value = user.id + digest = OpenSSL::Digest.new("sha256") + sig = OpenSSL::HMAC.hexdigest(digest, Danbooru.config.shared_remote_key, "#{key},#{value}") + render("users/common_searches", user: user, sig: sig) + end + def resize_image_links(post, user) links = [] diff --git a/app/models/user.rb b/app/models/user.rb index 9b569a415..acdf0e3c7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -35,13 +35,14 @@ class User < ActiveRecord::Base disable_categorized_saved_searches is_super_voter disable_tagged_filenames + enable_recent_searches ) include Danbooru::HasBitFlags has_bit_flags BOOLEAN_ATTRIBUTES, :field => "bit_prefs" attr_accessor :password, :old_password - attr_accessible :dmail_filter_attributes, :enable_privacy_mode, :enable_post_navigation, :new_post_navigation_layout, :password, :old_password, :password_confirmation, :password_hash, :email, :last_logged_in_at, :last_forum_read_at, :has_mail, :receive_email_notifications, :comment_threshold, :always_resize_images, :favorite_tags, :blacklisted_tags, :name, :ip_addr, :time_zone, :default_image_size, :enable_sequential_post_navigation, :per_page, :hide_deleted_posts, :style_usernames, :enable_auto_complete, :custom_style, :show_deleted_children, :disable_categorized_saved_searches, :disable_tagged_filenames, :as => [:moderator, :janitor, :gold, :member, :anonymous, :default, :builder, :admin] + attr_accessible :dmail_filter_attributes, :enable_privacy_mode, :enable_post_navigation, :new_post_navigation_layout, :password, :old_password, :password_confirmation, :password_hash, :email, :last_logged_in_at, :last_forum_read_at, :has_mail, :receive_email_notifications, :comment_threshold, :always_resize_images, :favorite_tags, :blacklisted_tags, :name, :ip_addr, :time_zone, :default_image_size, :enable_sequential_post_navigation, :per_page, :hide_deleted_posts, :style_usernames, :enable_auto_complete, :custom_style, :show_deleted_children, :disable_categorized_saved_searches, :disable_tagged_filenames, :enable_recent_searches, :as => [:moderator, :janitor, :gold, :member, :anonymous, :default, :builder, :admin] attr_accessible :level, :as => :admin validates_length_of :name, :within => 2..100, :on => :create validates_format_of :name, :with => /\A[^\s:]+\Z/, :on => :create, :message => "cannot have whitespace or colons" diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index 792a22e5b..66b1c03ae 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -7,6 +7,8 @@ <%= render "posts/partials/index/blacklist" %> + <%= raw common_searches_html(CurrentUser.user) %> +

Tags

<%= @post_set.presenter.tag_list_html(self) %> diff --git a/app/views/static/test.html.erb b/app/views/static/test.html.erb new file mode 100644 index 000000000..a441b269e --- /dev/null +++ b/app/views/static/test.html.erb @@ -0,0 +1 @@ +<%= raw common_searches_html(CurrentUser.user) %> diff --git a/app/views/users/_common_searches.html.erb b/app/views/users/_common_searches.html.erb new file mode 100644 index 000000000..54202372e --- /dev/null +++ b/app/views/users/_common_searches.html.erb @@ -0,0 +1,17 @@ + + + diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 87dc16087..5ebe22989 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -74,6 +74,8 @@ <%= f.input :disable_tagged_filenames, :as => :select, :collection => [["No", "false"], ["Yes", "true"]], :include_blank => false %> + <%= f.input :enable_recent_searches, :as => :select, :collection => [["No", "false"], ["Yes", "true"]], :include_blank => false %> +
diff --git a/config/schedule.rb b/config/schedule.rb index 27603b4dc..6d9a021c1 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -24,7 +24,7 @@ every 1.month, :at => "2:00 am" do end if environment == "production" - every 1.hour do + every 30.minutes do runner "PostUpdate.push" end