diff --git a/app/assets/javascripts/utility.js b/app/assets/javascripts/utility.js index bc0a258d6..59101fd07 100644 --- a/app/assets/javascripts/utility.js +++ b/app/assets/javascripts/utility.js @@ -99,6 +99,21 @@ return string.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1"); } + Danbooru.get_url_parameter = function(sParam) { + var sPageURL = decodeURIComponent(window.location.search.substring(1)), + sURLVariables = sPageURL.split('&'), + sParameterName, + i; + + for (i = 0; i < sURLVariables.length; i++) { + sParameterName = sURLVariables[i].split('='); + + if (sParameterName[0] === sParam) { + return sParameterName[1] === undefined ? true : sParameterName[1]; + } + } + }; + String.prototype.hash = function() { var hash = 5381, i = this.length; diff --git a/app/controllers/explore/posts_controller.rb b/app/controllers/explore/posts_controller.rb index c0f2bfe5a..d7eebb24e 100644 --- a/app/controllers/explore/posts_controller.rb +++ b/app/controllers/explore/posts_controller.rb @@ -13,6 +13,10 @@ module Explore @search_service = PopularSearchService.new(@date, params[:scale] || "day") end + def missed_searches + @search_service = MissedSearchService.new + end + def intro @presenter = IntroPresenter.new render :layout => "blank" diff --git a/app/helpers/posts_helper.rb b/app/helpers/posts_helper.rb index eb47ef711..832e481ee 100644 --- a/app/helpers/posts_helper.rb +++ b/app/helpers/posts_helper.rb @@ -1,4 +1,13 @@ module PostsHelper + def missed_post_search_count_js + return nil unless Danbooru.config.enable_post_search_counts + + session_id = session.id + digest = OpenSSL::Digest.new("sha256") + sig = OpenSSL::HMAC.hexdigest(digest, Danbooru.config.shared_remote_key, ",#{session_id}") + return render("posts/partials/index/missed_search_count", session_id: session_id, sig: sig) + end + def post_search_count_js return nil unless Danbooru.config.enable_post_search_counts diff --git a/app/logical/missed_search_service.rb b/app/logical/missed_search_service.rb new file mode 100644 index 000000000..bf17d3e03 --- /dev/null +++ b/app/logical/missed_search_service.rb @@ -0,0 +1,22 @@ +# queries reportbooru to find missed post searches +class MissedSearchService + def each_search(&block) + fetch_data.scan(/(.+?) (\d+)\.0\n/).each(&block) + end + + def fetch_data + # Cache.get("ms", 1.minute) do + url = URI.parse("#{Danbooru.config.report_server}/missed_searches") + response = "" + Net::HTTP.start(url.host, url.port, :use_ssl => url.is_a?(URI::HTTPS)) do |http| + http.read_timeout = 1 + http.request_get(url.request_uri) do |res| + if res.is_a?(Net::HTTPSuccess) + response = res.body + end + end + end + response + # end + end +end diff --git a/app/views/explore/posts/missed_searches.html.erb b/app/views/explore/posts/missed_searches.html.erb new file mode 100644 index 000000000..eec9b7eb1 --- /dev/null +++ b/app/views/explore/posts/missed_searches.html.erb @@ -0,0 +1,28 @@ +
| Tags | +Count | +
|---|---|
| <%= link_to tags, posts_path(:tags => tags) %> | +<%= count.to_i %> | +