1 class DiaryEntryController < ApplicationController
2 layout 'site', :except => :rss
4 before_filter :set_locale
5 before_filter :authorize_web
6 before_filter :require_user, :only => [:new, :edit]
7 before_filter :check_database_readable
8 before_filter :check_database_writable, :only => [:new, :edit]
11 @title = 'New diary entry'
13 if params[:diary_entry]
14 @diary_entry = DiaryEntry.new(params[:diary_entry])
15 @diary_entry.user = @user
16 @diary_entry.language = Language.find_by_code(params[:language])
17 @diary_entry.language = Language.find_by_code("en") if @diary_entry.language.nil?
20 redirect_to :controller => 'diary_entry', :action => 'list', :display_name => @user.display_name
22 render :action => 'edit'
25 render :action => 'edit'
30 @title= 'Edit diary entry'
31 @diary_entry = DiaryEntry.find(params[:id])
33 if @user != @diary_entry.user
34 redirect_to :controller => 'diary_entry', :action => 'view', :id => params[:id]
35 elsif params[:diary_entry]
36 params[:diary_entry][:language] = Language.find_by_code(params[:diary_entry][:language])
37 params[:diary_entry][:language] = Language.find_by_code("en") if params[:diary_entry][:language].nil?
38 if @diary_entry.update_attributes(params[:diary_entry])
39 redirect_to :controller => 'diary_entry', :action => 'view', :id => params[:id]
42 rescue ActiveRecord::RecordNotFound
43 render :action => "no_such_entry", :status => :not_found
47 @entry = DiaryEntry.find(params[:id])
48 @diary_comment = @entry.diary_comments.build(params[:diary_comment])
49 @diary_comment.user = @user
50 if @diary_comment.save
51 Notifier::deliver_diary_comment_notification(@diary_comment)
52 redirect_to :controller => 'diary_entry', :action => 'view', :display_name => @entry.user.display_name, :id => @entry.id
54 render :action => 'view'
59 if params[:display_name]
60 @this_user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
63 @title = @this_user.display_name + "'s diary"
64 @entry_pages, @entries = paginate(:diary_entries,
65 :conditions => ['user_id = ?', @this_user.id],
66 :order => 'created_at DESC',
69 @not_found_user = params[:display_name]
71 render :action => 'no_such_user', :status => :not_found
74 @title = "Users' diaries"
75 @entry_pages, @entries = paginate(:diary_entries, :include => :user,
76 :conditions => ["users.visible = ?", true],
77 :order => 'created_at DESC',
83 if params[:display_name]
84 user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
87 @entries = DiaryEntry.find(:all, :conditions => ['user_id = ?', user.id], :order => 'created_at DESC', :limit => 20)
88 @title = "OpenStreetMap diary entries for #{user.display_name}"
89 @description = "Recent OpenStreetmap diary entries from #{user.display_name}"
90 @link = "http://#{SERVER_URL}/user/#{user.display_name}/diary"
92 render :content_type => Mime::RSS
94 render :nothing => true, :status => :not_found
96 elsif params[:language]
97 @entries = DiaryEntry.find(:all, :include => :user,
98 :conditions => ["users.visible = ? AND diary_entries.language = ?", true, params[:language]],
99 :order => 'created_at DESC', :limit => 20)
100 @title = "OpenStreetMap diary entries in #{params[:language]}"
101 @description = "Recent diary entries from users of OpenStreetMap"
102 @link = "http://#{SERVER_URL}/diary/#{params[:language]}"
104 render :content_type => Mime::RSS
106 @entries = DiaryEntry.find(:all, :include => :user,
107 :conditions => ["users.visible = ?", true],
108 :order => 'created_at DESC', :limit => 20)
109 @title = "OpenStreetMap diary entries"
110 @description = "Recent diary entries from users of OpenStreetMap"
111 @link = "http://#{SERVER_URL}/diary"
113 render :content_type => Mime::RSS
118 user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
121 @entry = DiaryEntry.find(:first, :conditions => ['user_id = ? AND id = ?', user.id, params[:id]])
123 @title = "Users' diaries | #{params[:display_name]}"
125 render :action => 'no_such_entry', :status => :not_found
128 @not_found_user = params[:display_name]
130 render :action => 'no_such_user', :status => :not_found