diff --git a/app/controllers/flickr_controller.rb b/app/controllers/flickr_controller.rb index b5cbd4c..8bc1f1b 100644 --- a/app/controllers/flickr_controller.rb +++ b/app/controllers/flickr_controller.rb @@ -1,18 +1,21 @@ class FlickrController < ApplicationController FlickrawOptions = { :lazyload => true, :timeout => 2 } require 'flickraw' - @@flickr_id = "13827925@N00" + + caches_action :interesting, :recent + + def photo @pid = params[:id] begin @pinfo = flickr.photos.getInfo :photo_id => @pid rescue => e flash[:error] = "Photo " + params[:id].to_s + " could not be found. Random photo displayed." - @pid = flickr.photos.search(:user_id => @@flickr_id).rand.id + @pid = flickr.photos.search(:user_id => get_user_id).rand.id @pinfo = flickr.photos.getInfo :photo_id => @pid end @psize = flickr.photos.getSizes(:photo_id => @pid).find{|m| m.label == "Medium"} @@ -24,7 +27,7 @@ class FlickrController < ApplicationController end def home - @pid = flickr.photos.search(:user_id => @@flickr_id).rand.id + @pid = flickr.photos.search(:user_id => get_user_id).rand.id @pinfo = flickr.photos.getInfo(:photo_id => @pid) @psize = flickr.photos.getSizes(:photo_id => @pid).find{|m| m.label == "Medium"} @@ -36,7 +39,7 @@ class FlickrController < ApplicationController def interesting @parray = Array.new - result = flickr.photos.search(:user_id => @@flickr_id, :per_page => 20, :sort => "interestingness-desc") + result = flickr.photos.search(:user_id => get_user_id, :per_page => 20, :sort => "interestingness-desc") for r in result do @parray += [:id => r.id, :source => flickr.photos.getSizes(:photo_id => r.id).find{|m| m.label == "Thumbnail"}.source] end @@ -49,7 +52,7 @@ class FlickrController < ApplicationController def recent @parray = Array.new - result = flickr.photos.search(:user_id => @@flickr_id, :per_page => 20) + result = flickr.photos.search(:user_id => get_user_id, :per_page => 20) for r in result do @parray += [:id => r.id, :source => flickr.photos.getSizes(:photo_id => r.id).find{|m| m.label == "Thumbnail"}.source] end @@ -58,5 +61,26 @@ class FlickrController < ApplicationController format.html end end + + + + + + + + def get_user_id + if params and params[:user_id] + user_id = params[:user_id] + else + user_id = "13827925@N00" + end + + return user_id + end + + + + + end diff --git a/config/routes.rb b/config/routes.rb index 191b1dc..d4659a7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -39,19 +39,19 @@ ActionController::Routing::Routes.draw do |map| # Note: These default routes make all actions in every controller accessible via GET requests. You should # consider removing or commenting them out if you're using named routes and resources. - map.connect 'f/i', :controller => "flickr", :action => "interesting" + map.connect 'u/:user_id/r', :controller => "flickr", :action => "recent", :requirements => { :user_id => /.*/ } + map.connect 'u/:user_id/i', :controller => "flickr", :action => "interesting", :requirements => { :user_id => /.*/ } + map.connect 'u/:user_id/p/:id', :controller => "flickr", :action => "photo", :requirements => { :user_id => /.*/ } + map.connect 'u/:user_id', :controller => "flickr", :action => "home", :requirements => {:user_id => /.*/} + + map.connect 'r', :controller => "flickr", :action => "recent" + map.connect 'i', :controller => "flickr", :action => "interesting" map.connect 'p/:id', :controller => "flickr", :action => "photo" - map.connect 'f/:action/:id', :controller => "flickr", :action => "recent" - map.connect 's/i', :controller => "screenshot", :action => "index" map.connect 's/:filename', :controller => "screenshot", :action => "single", :requirements => { :filename => /.*/ } + map.connect 'o/:action', :controller => "info" - map.connect 'i/:action', :controller => "info" - - map.connect ':controller/:action/:id' - map.connect ':controller/:action/:id.:format' - map.root :controller => "flickr", :action => "home" end