| Class | CmsController |
| In: |
app/controllers/my_profile/cms_controller.rb
|
| Parent: | MyProfileController |
| check_ssl | -> | check_ssl_orig |
# File app/controllers/my_profile/cms_controller.rb, line 21
21: def available_article_types
22: articles = [
23: Folder,
24: TinyMceArticle,
25: TextileArticle,
26: RssFeed,
27: UploadedFile,
28: Event
29: ]
30: if profile.enterprise?
31: articles << EnterpriseHomepage
32: end
33: articles
34: end
# File app/controllers/my_profile/cms_controller.rb, line 15
15: def boxes_holder
16: profile
17: end
Redefines the SSL checking to avoid requiring SSL when creating the "New publication" button on article‘s public view.
# File app/controllers/my_profile/cms_controller.rb, line 9
9: def check_ssl
10: if ((params[:action] == 'new') && (!request.xhr?)) || (params[:action] != 'new')
11: check_ssl_orig
12: end
13: end
# File app/controllers/my_profile/cms_controller.rb, line 121
121: def destroy
122: @article = profile.articles.find(params[:id])
123: @article.destroy
124: redirect_to :action => (@article.parent ? 'view' : 'index'), :id => @article.parent
125: end
# File app/controllers/my_profile/cms_controller.rb, line 49
49: def edit
50: @article = profile.articles.find(params[:id])
51: @parent_id = params[:parent_id]
52: @type = params[:type]
53: record_coming_from_public_view
54: if request.post?
55: @article.last_changed_by = user
56: if @article.update_attributes(params[:article])
57: redirect_back
58: return
59: end
60: end
61: end
# File app/controllers/my_profile/cms_controller.rb, line 42
42: def index
43: @article = nil
44: @subitems = profile.top_level_articles.reject {|item| item.folder? }
45: @folders = profile.top_level_articles.select {|item| item.folder?}
46: render :action => 'view'
47: end
# File app/controllers/my_profile/cms_controller.rb, line 63
63: def new
64: # FIXME this method should share some logic wirh edit !!!
65:
66: # user must choose an article type first
67: @type = params[:type]
68:
69: if @type.blank?
70: @article_types = []
71: available_article_types.each do |type|
72: @article_types.push({
73: :name => type.name,
74: :short_description => type.short_description,
75: :description => type.description
76: })
77: end
78: @parent_id = params[:parent_id]
79: render :action => 'select_article_type', :layout => false
80: return
81: end
82:
83: raise "Invalid article type #{@type}" unless available_article_types.map {|item| item.name}.include?(@type)
84: klass = @type.constantize
85: @article = klass.new(params[:article])
86:
87:
88: if params[:parent_id]
89: parent = profile.articles.find(params[:parent_id])
90: if ! parent.allow_children?
91: raise ArgumentError.new("cannot create child of article which does not accept children")
92: end
93: @article.parent = parent
94: @parent_id = parent.id
95: end
96:
97: record_creating_from_public_view
98:
99: @article.profile = profile
100: @article.last_changed_by = user
101: if request.post?
102: if @article.save
103: redirect_back
104: return
105: end
106: end
107:
108: render :action => 'edit'
109: end
# File app/controllers/my_profile/cms_controller.rb, line 142
142: def publish
143:
144: @article = profile.articles.find(params[:id])
145: record_coming_from_public_view
146: @groups = profile.memberships - [profile]
147: @marked_groups = []
148: groups_ids = profile.memberships.map{|m|m.id.to_s}
149: @marked_groups = params[:marked_groups].map do |item|
150: if groups_ids.include?(item[:group_id])
151: item.merge :group => Profile.find(item.delete(:group_id))
152: end
153: end.compact unless params[:marked_groups].nil?
154: if request.post?
155: @marked_groups.each do |item|
156: task = ApproveArticle.create!(:article => @article, :name => item[:name], :target => item[:group], :requestor => profile)
157: task.finish unless item[:group].moderated_articles?
158: end
159: redirect_back
160: end
161: end
# File app/controllers/my_profile/cms_controller.rb, line 112
112: def set_home_page
113: @article = profile.articles.find(params[:id])
114: profile.home_page = @article
115: profile.save!
116: flash[:notice] = _('Article "%s" configured as home page.') % @article.name
117: redirect_to :action => 'view', :id => @article.id
118: end
# File app/controllers/my_profile/cms_controller.rb, line 131
131: def update_categories
132: @object = params[:id] ? @profile.articles.find(params[:id]) : Article.new
133: if params[:category_id]
134: @current_category = Category.find(params[:category_id])
135: @categories = @current_category.children
136: else
137: @categories = environment.top_level_categories.select{|i| !i.children.empty?}
138: end
139: render :partial => 'shared/select_categories', :locals => {:object_name => 'article', :multiple => true}, :layout => false
140: end
# File app/controllers/my_profile/cms_controller.rb, line 36
36: def view
37: @article = profile.articles.find(params[:id])
38: @subitems = @article.children.reject {|item| item.folder? }
39: @folders = @article.children.select {|item| item.folder? }
40: end
# File app/controllers/my_profile/cms_controller.rb, line 127
127: def why_categorize
128: render :action => params[:action], :layout => false
129: end
# File app/controllers/my_profile/cms_controller.rb, line 191
191: def maybe_ssl(url)
192: [url, url.sub('https:', 'http:')]
193: end
# File app/controllers/my_profile/cms_controller.rb, line 175
175: def record_coming_from_public_view
176: referer = request.referer
177: if (maybe_ssl(url_for(@article.url)).include?(referer)) || (@article == @profile.home_page && maybe_ssl(url_for(@profile.url)).include?(referer))
178: @back_to = 'public_view'
179: @back_url = @article.url
180: end
181: end
# File app/controllers/my_profile/cms_controller.rb, line 183
183: def record_creating_from_public_view
184: referer = request.referer
185: if (referer =~ Regexp.new("^#{(url_for(profile.url).sub('https:', 'https?:'))}"))
186: @back_to = 'public_view'
187: @back_url = referer
188: end
189: end
# File app/controllers/my_profile/cms_controller.rb, line 165
165: def redirect_back
166: if params[:back_to] == 'public_view'
167: redirect_to @article.url
168: elsif @article.parent
169: redirect_to :action => 'view', :id => @article.parent
170: else
171: redirect_to :action => 'index'
172: end
173: end