Class: ClippingsController

Inherits:
BaseController show all
Defined in:
app/controllers/clippings_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#advertise, #cache_action?, #footer_content, #homepage_features, #plaxo, #rss_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 /clippings POST /clippings.xml



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'app/controllers/clippings_controller.rb', line 130

def create
  @user = current_user
  @clipping = @user.clippings.new(clipping_params)
  @clipping.user = @user
  @clipping.tag_list = params[:tag_list] || ''

  respond_to do |format|
    if @clipping.save!
      flash[:notice] = :clipping_was_successfully_created.l
      format.html {
        unless params[:user_id]
          redirect_to @clipping.url rescue redirect_to user_clipping_url(@user, @clipping)
        else
          redirect_to user_clipping_url(@user, @clipping)
        end
      }
    else
      format.html { render :action => "new" }
    end
  end
end

#destroyObject

DELETE /clippings/1 DELETE /clippings/1.xml



172
173
174
175
176
177
178
179
180
# File 'app/controllers/clippings_controller.rb', line 172

def destroy
  @user = User.find(params[:user_id])
  @clipping = Clipping.find(params[:id])
  @clipping.destroy

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

#editObject

GET /clippings/1;edit



123
124
125
126
# File 'app/controllers/clippings_controller.rb', line 123

def edit
  @clipping = Clipping.find(params[:id])
  @user = User.find(params[:user_id])
end

#indexObject

GET /clippings GET /clippings.xml



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/clippings_controller.rb', line 35

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

  @clippings = Clipping.includes(:tags).where(:user_id => @user.id).order("clippings.created_at DESC")

  @clippings = @clippings.where('tags.name = ?', params[:tag_name]) if params[:tag_name]

  @clippings = @clippings.page(params[:page])

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

  @clippings_data = @clippings.collect {|c| [c.id, c.image_url, c.description, c.url ]  }

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

  respond_to do |format|
    format.html # index.rhtml
    format.js { render :inline => @clippings_data.to_json }
    # format.widget { render :template => 'clippings/widget', :layout => false }
    format.rss {
      render_rss_feed_for(@clippings,
         { :feed => {:title => @rss_title, :link => url_for(:controller => 'clippings', :action => 'index', :user_id => @user) },
           :item => {:title => :title_for_rss,
                     :description => Proc.new {|clip| description_for_rss(clip)},
                     :link => :url,
                     :pub_date => :created_at} })

    }
  end
end

#load_images_from_uriObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/controllers/clippings_controller.rb', line 82

def load_images_from_uri
  uri = URI.parse(params[:uri])
  begin
    doc = Hpricot( open( uri ) )
  rescue
    return
  end
  @page_title = (doc/"title")
  # get the images
  @images = []
  (doc/"img").each do |img|
    begin
      if URI.parse(URI.escape(img['src'])).scheme.nil?
        img_uri = "#{uri.scheme}://#{uri.host}/#{img['src']}"
      else
        img_uri = img['src']
      end
      @images << img_uri
    rescue
      nil
    end
  end
  respond_to do |format|
    format.js
  end
end

#newObject

GET /clippings/new



117
118
119
120
# File 'app/controllers/clippings_controller.rb', line 117

def new
  @user = User.find(params[:user_id])
  @clipping = @user.clippings.new
end

#new_clippingObject



109
110
111
112
113
114
# File 'app/controllers/clippings_controller.rb', line 109

def new_clipping
  @user = current_user
  @clipping = @user.clippings.new({:url => params[:uri], :description => params[:selection]})
  @post = @user.posts.new_from_bookmarklet(params)
  render :action => "new_clipping", :layout => false
end

#showObject

GET /clippings/1 GET /clippings/1.xml



69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/clippings_controller.rb', line 69

def show
  @user = User.find(params[:user_id])
  @clipping = Clipping.find(params[:id])
  @previous = @clipping.previous_clipping
  @next = @clipping.next_clipping

  @related = Clipping.find_related_to(@clipping)

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

#site_indexObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/clippings_controller.rb', line 8

def site_index
  @clippings = Clipping.includes(:tags).order(params[:recent] ? "created_at DESC" : "clippings.favorited_count DESC")

  @clippings = @clippings.where('tags.name = ?', params[:tag_name]).references(:tags) if params[:tag_name]
  @clippings = @clippings.where('created_at > ?', 4.weeks.ago) unless params[:recent]

  @clippings = @clippings.page(params[:page])

  @rss_title = "#{configatron.community_name}: #{params[:popular] ? :popular.l : :recent.l} "+:clippings.l
  @rss_url = rss_site_clippings_path
  respond_to do |format|
    format.html
    format.rss {
      render_rss_feed_for(@clippings,
         { :feed => {:title => @rss_title, :link => url_for(:controller => 'clippings', :action => 'site_index') },
           :item => {:title => :title_for_rss,
                     :description => Proc.new {|clip| description_for_rss(clip)},
                     :link => Proc.new {|clip| user_clipping_url(clip.user, clip)},
                     :pub_date => :created_at} })

    }
  end

end

#updateObject

patch /clippings/1 patch /clippings/1.xml



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'app/controllers/clippings_controller.rb', line 154

def update
  @user = User.find(params[:user_id])
  @clipping = Clipping.find(params[:id])
  @clipping.tag_list = params[:tag_list] || ''

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