From 374e85f9d0fd33eebc2ec7939a546a2779657be9 Mon Sep 17 00:00:00 2001 From: Matchu Date: Tue, 2 Aug 2011 20:01:48 -0400 Subject: [PATCH] drop in redirect image url for urls blocked on petpages --- app/controllers/items_controller.rb | 29 +++++++++++++------ app/helpers/closet_hangers_helper.rb | 15 ++++++++++ .../closet_hangers/_petpage_hanger.html.haml | 2 +- config/application.rb | 3 ++ 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index c3ecfcf5..d7243dce 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -41,16 +41,27 @@ class ItemsController < ApplicationController def show @item = Item.find params[:id] - @trading_closet_hangers_by_owned = { - true => @item.closet_hangers.owned_trading.newest.includes(:user), - false => @item.closet_hangers.wanted_trading.newest.includes(:user) - } + respond_to do |format| + format.html do - if user_signed_in? - @current_user_hangers = [true, false].map do |owned| - hanger = current_user.closet_hangers.find_or_initialize_by_item_id_and_owned(@item.id, owned) - hanger.quantity ||= 1 - hanger + @trading_closet_hangers_by_owned = { + true => @item.closet_hangers.owned_trading.newest.includes(:user), + false => @item.closet_hangers.wanted_trading.newest.includes(:user) + } + + if user_signed_in? + @current_user_hangers = [true, false].map do |owned| + hanger = current_user.closet_hangers.find_or_initialize_by_item_id_and_owned(@item.id, owned) + hanger.quantity ||= 1 + hanger + end + end + + end + + format.gif do + expires_in 1.month + redirect_to @item.thumbnail_url end end end diff --git a/app/helpers/closet_hangers_helper.rb b/app/helpers/closet_hangers_helper.rb index 5649019c..7e71e9d8 100644 --- a/app/helpers/closet_hangers_helper.rb +++ b/app/helpers/closet_hangers_helper.rb @@ -73,6 +73,21 @@ module ClosetHangersHelper item.name.gsub(/ on/i, ' on') end + PETPAGE_IMAGE_URL_BLACKLIST = %w(window. ondrop) + def petpage_item_thumbnail_url(item) + url = item.thumbnail_url + + # If the URL includes any of the blacklisted terms, use our redirect URL + PETPAGE_IMAGE_URL_BLACKLIST.each do |term| + if url.include?(term) + url = item_url(item, :format => :gif) + break + end + end + + url + end + def public_perspective? @public_perspective end diff --git a/app/views/closet_hangers/_petpage_hanger.html.haml b/app/views/closet_hangers/_petpage_hanger.html.haml index e3d69b20..683620f1 100644 --- a/app/views/closet_hangers/_petpage_hanger.html.haml +++ b/app/views/closet_hangers/_petpage_hanger.html.haml @@ -1,5 +1,5 @@ %div.dti-item - = image_tag hanger.item.thumbnail_url, :alt => nil, :class => 'dti-item-thumbnail' + = image_tag petpage_item_thumbnail_url(hanger.item), :alt => nil, :class => 'dti-item-thumbnail' - if hanger.item.nc? = image_tag nc_icon_url, :alt => 'NC', :class => 'dti-item-nc', :title => 'This is an NC Mall item' %span= petpage_item_name hanger.item diff --git a/config/application.rb b/config/application.rb index 3359da28..e571d0d7 100644 --- a/config/application.rb +++ b/config/application.rb @@ -39,5 +39,8 @@ module OpenneoImpressItems # Configure sensitive parameters which will be filtered from the log file. config.filter_parameters << :password + + Mime::Type.register "image/gif", :gif end end +