OSDN Git Service

Merge branch 'v05' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v05
[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     @picture = Picture.show(params[:id], [@user, @admin, @demand_user])
15
16     respond_to do |format|
17       opt = {:type => @picture.mime_type, :disposition=>"inline"}
18       format.png { send_data(@picture.restore(params[:subdir]), opt ) }
19       format.gif { send_data(@picture.restore(params[:subdir]), opt ) }
20       format.jpeg { send_data(@picture.restore(params[:subdir]), opt ) }
21       format.html 
22       format.json { render :json => @picture.to_json}
23     end
24   end
25   
26   def credit
27     @picture = Picture.show(params[:id], [@user, @admin, @demand_user])
28
29     respond_to do |format|
30       format.html { render :layout => false } # show.html.erb
31       format.json { render :json => @picture.to_json}
32     end
33   end
34   
35   def search
36     @pictures = Picture.list_by_md5(params[:md5])
37     
38     respond_to do |format|
39       format.html
40       format.json { render json: @pictures.to_json }
41     end
42   end
43   
44   def list
45     @pictures = Picture.all
46
47     respond_to do |format|
48       format.html { render layout: 'system' }# index.html.erb
49       format.json { render json: @pictures }
50     end
51   end
52
53   def browse
54     @picture = Picture.find(params[:id])
55
56     respond_to do |format|
57       format.html { render layout: 'system' } # show.html.erb
58       format.json { render json: @picture }
59     end
60   end
61 end