Class: PhotosController

Inherits:
BaseController show all
Includes:
Viewable
Defined in:
app/controllers/photos_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#advertise, #cache_action?, #footer_content, #homepage_features, #plaxo, #rss_site_index, #site_index

Methods included from BaseHelper

#add_friend_link, #ajax_spinner_for, #avatar_for, #block_to_partial, #box, #city_cloud, #clippings_link, #commentable_url, #container_title, #excerpt_with_jump, #flash_class, #forum_page?, #is_current_user_and_featured?, #jumbotron, #last_active, #more_comments_links, #page_title, #paginating_links, #possesive, #profile_completeness, #render_jumbotron, #render_widgets, #rounded, #search_posts_title, #search_user_posts_path, #show_footer_content?, #tag_auto_complete_field, #time_ago_in_words, #time_ago_in_words_or_date, #topnav_tab, #truncate_words, #truncate_words_with_highlight, #widget

Methods included from LocalizedApplication

#get_matching_ui_locale, #get_sorted_langs_from_accept_header, #get_valid_lang_from_accept_header, #set_locale

Methods included from AuthenticatedSystem

#login_by_token, #update_last_seen_at

Instance Method Details

#createObject

POST /photos POST /photos.xml



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'app/controllers/photos_controller.rb', line 131

def create
  @user = current_user
  @photo = Photo.new(photo_params)
  @photo.user = @user
  @photo.tag_list = params[:tag_list] || ''

  @photo.album_id = params[:album_id] || ''
  @photo.album_id = params[:album_selected] unless params[:album_selected].blank?


  respond_to do |format|
    if @photo.save
      flash[:notice] = :photo_was_successfully_created.l

      format.html {
        render :action => 'inline_new', :layout => false and return if params[:inline]
        if params[:album_id]
          redirect_to user_album_path(current_user,params[:album_id])
        else
          redirect_to user_photo_url(:id => @photo, :user_id => @photo.user)
        end
      }
      format.js {
        # render create.js.erb
      }
    else
      format.html {
        render :action => 'inline_new', :layout => false and return if params[:inline]
        render :action => "new"
      }
      format.js {
        # render create.js.erb
        @alert = :sorry_there_was_an_error_uploading_the_photo.l
      }
    end
  end
end

#create_photosObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/controllers/photos_controller.rb', line 60

def create_photos
  @photo = current_user.photos.new
  file = params[:qqfile] ||params[:upload]
  @photo.photo = Ckeditor::Http.normalize_param(file, request)
  callback = ckeditor_before_create_asset(@photo)

  if callback && @photo.save
    hash = {
      :id => @photo.id,
      :type => 'ckeditor::picture',
      :url_content => @photo.photo.url,
      :url_thumb => @photo.photo.url(:thumb),
      :filename => @photo.photo_file_name,
      :format_created_at => @photo.created_at,
      :size => @photo.photo_file_size
    }

    body = params[:CKEditor].blank? ? hash.to_json : %Q"<script type='text/javascript'>
    window.parent.CKEDITOR.tools.callFunction(#{params[:CKEditorFuncNum]}, '#{config.relative_url_root}#{Ckeditor::Utils.escape_single_quotes(@photo.photo.url)}');
  </script>"

    render :text => body

  else
    if params[:CKEditor].blank?
      render :nothing => true, :format => :json
    else
      render :text => %Q"<script type='text/javascript'>
          window.parent.CKEDITOR.tools.callFunction(#{params[:CKEditorFuncNum]}, null, '#{Ckeditor::Utils.escape_single_quotes(@photo.errors.full_messages.first)}');
        </script>"
    end
  end

end

#destroyObject

DELETE /photos/1 DELETE /photos/1.xml



190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'app/controllers/photos_controller.rb', line 190

def destroy
  @user = User.find(params[:user_id])
  @photo = Photo.find(params[:id])
  if @user.avatar.eql?(@photo)
    @user.avatar = nil
    @user.save!
  end
  @photo.destroy

  respond_to do |format|
    format.html { redirect_to user_photos_url(@photo.user)   }
  end
end

#editObject

GET /photos/1;edit



124
125
126
127
# File 'app/controllers/photos_controller.rb', line 124

def edit
  @photo = Photo.find(params[:id])
  @user = @photo.user
end

#indexObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/photos_controller.rb', line 17

def index
  @user = User.find(params[:user_id])

  @photos = Photo.where(:user_id => @user.id).includes(:tags)
  if params[:tag_name]
    @photos = @photos.where('tags.name = ?', params[:tag_name])
  end

  @photos = @photos.recent.page(params[:page]).per(20)

  @tags = Photo.includes(:taggings).where(:user_id => @user.id).tag_counts(:limit => 20)

  @rss_title = "#{configatron.community_name}: #{@user.}'s photos"
  @rss_url = user_photos_path(@user,:format => :rss)

  respond_to do |format|
    format.html
    format.rss {
      render_rss_feed_for(@photos,
         { :feed => {:title => @rss_title, :link => url_for(:controller => 'photos', :action => 'index', :user_id => @user) },
           :item => {:title => :name,
                     :description => Proc.new {|photo| description_for_rss(photo)},
                     :link => Proc.new {|photo| user_photo_url(photo.user, photo)},
                     :pub_date => :created_at} })

    }
    format.xml { render :action => 'index.rxml', :layout => false}
  end
end

#manage_photosObject



47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/photos_controller.rb', line 47

def manage_photos
  if logged_in?
    @user = current_user
    @pictures = current_user.photos.recent.includes(:tags).page(params[:page]).per(10)
  end
  respond_to do |format|
    format.html {
      render :template => 'ckeditor/pictures/index', :layout => 'ckeditor/application'
    }
    format.js
  end
end

#newObject

GET /photos/new



114
115
116
117
118
119
120
121
# File 'app/controllers/photos_controller.rb', line 114

def new
  @user = User.find(params[:user_id])
  @photo = Photo.new
  if params[:inline]
    render :action => 'inline_new', :layout => false
  end

end

#recentObject



13
14
15
# File 'app/controllers/photos_controller.rb', line 13

def recent
  @photos = Photo.recent.page(params[:page])
end

#showObject

GET /photos/1 GET /photos/1.xml



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'app/controllers/photos_controller.rb', line 97

def show
  @photo = @user.photos.find(params[:id])
  update_view_count(@photo) if current_user && current_user.id != @photo.user_id

  @is_current_user = @user.eql?(current_user)
  @comment = Comment.new

  @previous = @photo.previous_photo
  @next = @photo.next_photo
  @related = Photo.find_related_to(@photo)

  respond_to do |format|
    format.html # show.rhtml
  end
end

#updateObject

patch /photos/1 patch /photos/1.xml



172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'app/controllers/photos_controller.rb', line 172

def update
  @photo = Photo.find(params[:id])
  @user = @photo.user
  @photo.tag_list = params[:tag_list] || ''
  @photo.album_id = photo_params[:album_id]

  respond_to do |format|
    if @photo.update_attributes(photo_params)
      format.html { redirect_to user_photo_url(@photo.user, @photo) }
    else
      format.html { render :action => "edit" }
    end
  end
end