OSDN Git Service

t#32471:add profiles
[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     before_filter :authenticate_author, :only => []
6   else
7     before_filter :authenticate_user, :only => []
8     before_filter :authenticate_resource_reader, :only => [:show, :credit, :search]
9     before_filter :authenticate_author, :only => []
10   end
11   before_filter :authenticate_admin!, :only => [:list, :browse]
12   
13   def show
14     @item = Picture.show(params[:id], [@user, @admin, @demand_user])
15
16     respond_to do |format|
17       opt = {:type => @item.mime_type, :disposition=>"inline"}
18       format.png { send_data(@item.restore(params[:subdir]), opt ) }
19       format.gif { send_data(@item.restore(params[:subdir]), opt ) }
20       format.jpeg { send_data(@item.restore(params[:subdir]), opt ) }
21       format.html 
22       format_prof format
23       format.json { render :json => @item.to_json}
24     end
25   end
26   
27   def credit
28     @picture = Picture.show(params[:id], [@user, @admin, @demand_user])
29
30     respond_to do |format|
31       format.html { render :layout => false } # show.html.erb
32       format.json { render :json => @picture.to_json}
33     end
34   end
35   
36   def search
37     @pictures = Picture.list_by_md5(params[:md5])
38     
39     respond_to do |format|
40       format.html
41       format.json { render json: @pictures.to_json }
42     end
43   end
44   
45   def list
46     @pictures = Picture.all
47
48     respond_to do |format|
49       format.html { render layout: 'system' }# index.html.erb
50       format.json { render json: @pictures }
51     end
52   end
53
54   def browse
55     @picture = Picture.find(params[:id])
56
57     respond_to do |format|
58       format.html { render layout: 'system' } # show.html.erb
59       format.json { render json: @picture }
60     end
61   end
62 end