OSDN Git Service

12fc5f66a5eb802c16b6fc3cd6e53f8dce6b9fc1
[pettanr/pettanr.git] / app / controllers / pictures_controller.rb
1 class PicturesController < ApplicationController
2   layout 'test' if MagicNumber['test_layout']
3   if MagicNumber['run_mode'] == 0
4     before_filter :authenticate_user, :only => []
5   else
6     before_filter :authenticate_user, :only => []
7     before_filter :authenticate_resource_reader, :only => [:show, :credit, :search]
8   end
9   before_filter :authenticate_admin!, :only => [:list, :browse]
10   
11   def show
12     @picture = Picture.show(params[:id], [@author, @admin, @demand_user])
13
14     respond_to do |format|
15       opt = {:type => @picture.mime_type, :disposition=>"inline"}
16       format.png { send_data(@picture.restore(params[:subdir]), opt ) }
17       format.gif { send_data(@picture.restore(params[:subdir]), opt ) }
18       format.jpeg { send_data(@picture.restore(params[:subdir]), opt ) }
19       format.html 
20       format.json { render :json => @picture.to_json}
21     end
22   end
23   
24   def credit
25     @picture = Picture.show(params[:id], [@author, @admin, @demand_user])
26
27     respond_to do |format|
28       format.html { render :layout => false } # show.html.erb
29       format.json { render :json => @picture.to_json}
30     end
31   end
32   
33   def search
34     @pictures = Picture.list_by_md5(params[:md5])
35     
36     respond_to do |format|
37       format.html
38       format.json { render json: @pictures.to_json }
39     end
40   end
41   
42   def list
43     @pictures = Picture.all
44
45     respond_to do |format|
46       format.html { render layout: 'system' }# index.html.erb
47       format.json { render json: @pictures }
48     end
49   end
50
51   def browse
52     @picture = Picture.find(params[:id])
53
54     respond_to do |format|
55       format.html { render layout: 'system' } # show.html.erb
56       format.json { render json: @picture }
57     end
58   end
59 end