caboose-cms 0.5.201 → 0.5.202

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +8 -8
  2. data/app/assets/javascripts/caboose/admin_block_edit.js +20 -10
  3. data/app/assets/javascripts/caboose/admin_post_edit_content.js +313 -0
  4. data/app/assets/stylesheets/caboose/admin_post_edit_content.css +46 -0
  5. data/app/controllers/caboose/admin_controller.rb +4 -4
  6. data/app/controllers/caboose/application_controller.rb +35 -0
  7. data/app/controllers/caboose/blocks_controller.rb +120 -78
  8. data/app/controllers/caboose/checkout_controller.rb +6 -0
  9. data/app/controllers/caboose/posts_controller.rb +87 -21
  10. data/app/controllers/caboose/sites_controller.rb +13 -1
  11. data/app/models/caboose/block.rb +14 -4
  12. data/app/models/caboose/caboose_plugin.rb +4 -0
  13. data/app/models/caboose/core_plugin.rb +1 -1
  14. data/app/models/caboose/post.rb +51 -7
  15. data/app/models/caboose/schema.rb +10 -3
  16. data/app/models/caboose/site.rb +5 -0
  17. data/app/views/caboose/admin/index.html.erb +43 -30
  18. data/app/views/caboose/application/show.html.erb +1 -1
  19. data/app/views/caboose/blocks/_layout_basic.html.erb +1 -1
  20. data/app/views/caboose/blocks/_layout_basic_content.html.erb +1 -1
  21. data/app/views/caboose/blocks/_layout_post.html.erb +28 -0
  22. data/app/views/caboose/blocks/_layout_post_content.html.erb +10 -0
  23. data/app/views/caboose/blocks/_layout_post_footer.html.erb +3 -0
  24. data/app/views/caboose/blocks/_layout_post_header.html.erb +3 -0
  25. data/app/views/caboose/blocks/_post.html.erb +30 -0
  26. data/app/views/caboose/blocks/admin_edit.html.erb +6 -7
  27. data/app/views/caboose/blocks/admin_new.html.erb +4 -3
  28. data/app/views/caboose/posts/_admin_header.html.erb +1 -0
  29. data/app/views/caboose/posts/admin_edit_content.html.erb +14 -21
  30. data/app/views/caboose/posts/admin_edit_content_old.html.erb +32 -0
  31. data/app/views/caboose/posts/admin_edit_general.html.erb +25 -12
  32. data/app/views/caboose/posts/admin_edit_layout.html.erb +48 -0
  33. data/app/views/caboose/posts/admin_edit_preview.html.erb +27 -0
  34. data/app/views/caboose/posts/show.html.erb +16 -0
  35. data/app/views/caboose/sites/admin_edit.html.erb +7 -5
  36. data/app/views/caboose/social/admin_edit.html.erb +1 -1
  37. data/app/views/layouts/caboose/application.html.erb +12 -6
  38. data/config/routes.rb +299 -278
  39. data/lib/caboose/version.rb +1 -1
  40. data/lib/tasks/caboose.rake +15 -1
  41. metadata +13 -2
@@ -4,10 +4,10 @@ module Caboose
4
4
 
5
5
  # GET /admin
6
6
  def index
7
- if logged_in?
8
- redirect_to '/admin/pages'
9
- return
10
- end
7
+ #if logged_in?
8
+ # redirect_to '/admin/pages'
9
+ # return
10
+ #end
11
11
  @return_url = params[:return_url].nil? ? '/admin/pages' : params[:return_url]
12
12
  end
13
13
 
@@ -255,6 +255,41 @@ module Caboose
255
255
  def admin_bulk_add() raise 'This method should be overridden.' end
256
256
  def admin_delete() raise 'This method should be overridden.' end
257
257
  def admin_bulk_delete() raise 'This method should be overridden.' end
258
+
259
+ # Make sure we're not under construction or on a forwarded domain
260
+ def under_construction_or_forwarding_domain?
261
+
262
+ d = Caboose::Domain.where(:domain => request.host_with_port).first
263
+ if d.nil?
264
+ Caboose.log("Could not find domain for #{request.host_with_port}\nAdd this domain to the caboose site.")
265
+ elsif d.under_construction == true
266
+ if d.site.under_construction_html && d.site.under_construction_html.strip.length > 0
267
+ render :text => d.site.under_construction_html
268
+ else
269
+ render :file => 'caboose/application/under_construction', :layout => false
270
+ end
271
+ return true
272
+ # See if we're on a forwarding domain
273
+ elsif d.primary == false && d.forward_to_primary == true
274
+ pd = d.site.primary_domain
275
+ if pd && pd.domain != request.host
276
+ url = "#{request.protocol}#{pd.domain}"
277
+ if request.fullpath && request.fullpath.strip.length > 0 && request.fullpath.strip != '/'
278
+ url << request.fullpath
279
+ end
280
+ redirect_to url
281
+ return true
282
+ end
283
+ # Check for a 301 redirect
284
+ else
285
+ new_url = PermanentRedirect.match(@site.id, request.fullpath)
286
+ if new_url
287
+ redirect_to new_url, :status => 301
288
+ return true
289
+ end
290
+ end
291
+ return false
292
+ end
258
293
 
259
294
  end
260
295
  end
@@ -4,47 +4,71 @@ module Caboose
4
4
  class BlocksController < ApplicationController
5
5
 
6
6
  helper :application
7
+ before_filter :before_blocks_action
7
8
 
9
+ def before_blocks_action
10
+ @p = params[:page_id] ? Page.find(params[:page_id]) : Post.find(params[:post_id])
11
+ end
12
+
13
+ def page_or_post
14
+ return params[:page_id] ? 'page' : 'post'
15
+ end
16
+
8
17
  #===========================================================================
9
18
  # Admin actions
10
19
  #===========================================================================
11
20
 
12
21
  # GET /admin/pages/:page_id/blocks
22
+ # GET /admin/posts/:post_id/blocks
13
23
  def admin_index
14
24
  return if !user_is_allowed('pages', 'view')
15
- blocks = Block.where(:page_id => params[:page_id]).reorder(:sort_order)
16
- render :json => blocks
25
+ #h = params[:post_id] ? { :post_id => params[:post_id] } : { :page_id => params[:page_id] }
26
+ #blocks = Block.where(h).reorder(:sort_order)
27
+ #render :json => blocks
28
+ render :json => @p.block
17
29
  end
18
30
 
19
31
  # GET /admin/pages/:page_id/blocks/:id/new
20
32
  # GET /admin/pages/:page_id/blocks/new
33
+ # GET /admin/posts/:post_id/blocks/:id/new
34
+ # GET /admin/posts/:post_id/blocks/new
21
35
  def admin_new
22
36
  return unless user_is_allowed('pages', 'add')
23
-
37
+
24
38
  if params[:id]
25
39
  block_type_id = params[:block_type_id]
26
40
  block_type_id = Block.find(params[:id]).block_type.default_child_block_type_id if block_type_id.nil?
27
41
  if block_type_id
28
42
  b = Block.new
29
- b.page_id = params[:page_id].to_i
43
+ if params[:page_id]
44
+ b.page_id = params[:page_id].to_i
45
+ else
46
+ b.post_id = params[:post_id].to_i
47
+ end
30
48
  b.parent_id = params[:id]
31
49
  b.block_type_id = block_type_id
32
50
  b.sort_order = Block.where(:parent_id => params[:id]).count
33
51
  b.save
34
- b.create_children
35
- redirect_to "/admin/pages/#{b.page_id}/blocks/#{b.id}/edit"
52
+ b.create_children
53
+ if params[:page_id]
54
+ redirect_to "/admin/pages/#{b.page_id}/blocks/#{b.id}/edit"
55
+ else
56
+ redirect_to "/admin/posts/#{b.post_id}/blocks/#{b.id}/edit"
57
+ end
36
58
  return
37
59
  end
38
60
  end
39
61
 
40
- @page = Page.find(params[:page_id])
41
- @block = params[:id] ? Block.find(params[:id]) : Block.new(:page_id => params[:page_id])
62
+ @page = Page.find(params[:page_id]) if params[:page_id]
63
+ @post = Post.find(params[:post_id]) if params[:post_id]
64
+ @block = params[:id] ? Block.find(params[:id]) : (params[:page_id] ? Block.new(:page_id => params[:page_id]) : Block.new(:post_id => params[:post_id]))
42
65
  @after_id = params[:after_id] ? params[:after_id] : nil
43
66
  @before_id = params[:before_id] ? params[:before_id] : nil
44
67
  render :layout => 'caboose/modal'
45
68
  end
46
69
 
47
70
  # GET /admin/pages/:page_id/blocks/:id
71
+ # GET /admin/posts/:post_id/blocks/:id
48
72
  def admin_show
49
73
  return unless user_is_allowed('pages', 'edit')
50
74
  block = Block.find(params[:id])
@@ -52,7 +76,9 @@ module Caboose
52
76
  end
53
77
 
54
78
  # GET /admin/pages/:page_id/blocks/tree
55
- # GET /admin/pages/:page_id/blocks/:id/tree
79
+ # GET /admin/pages/:page_id/blocks/:id/tree
80
+ # GET /admin/posts/:post_id/blocks/tree
81
+ # GET /admin/posts/:post_id/blocks/:id/tree
56
82
  def admin_tree
57
83
  return unless user_is_allowed('pages', 'edit')
58
84
 
@@ -61,9 +87,10 @@ module Caboose
61
87
  b = Block.find(params[:id])
62
88
  blocks << { 'id' => b.id, 'children' => admin_tree_helper(b), 'field_type' => b.block_type.field_type }
63
89
  else
64
- Block.where("parent_id is null and page_id = ?", params[:page_id]).reorder(:sort_order).all.each do |b|
90
+ q = params[:page_id] ? ["parent_id is null and page_id = ?", params[:page_id]] : ["parent_id is null and post_id = ?", params[:post_id]]
91
+ Block.where(q).reorder(:sort_order).all.each do |b|
65
92
  blocks << { 'id' => b.id, 'allow_child_blocks' => b.block_type.allow_child_blocks, 'children' => admin_tree_helper(b), 'field_type' => b.block_type.field_type }
66
- end
93
+ end
67
94
  end
68
95
  render :json => blocks
69
96
  end
@@ -77,6 +104,7 @@ module Caboose
77
104
  end
78
105
 
79
106
  # GET /admin/pages/:page_id/blocks/:id/render
107
+ # GET /admin/posts/:post_id/blocks/:id/render
80
108
  def admin_render
81
109
  return unless user_is_allowed('pages', 'edit')
82
110
  b = Block.find(params[:id])
@@ -85,34 +113,50 @@ module Caboose
85
113
  bt = BlockType.where(:name => 'richtext').first
86
114
  b.block_type_id = bt.id
87
115
  b.save
88
- end
89
- #b.create_children
90
- html = b.render(b, {
91
- :empty_text => params[:empty_text],
92
- :editing => true
116
+ end
117
+ html = b.render(b, {
118
+ :view => nil,
119
+ :controller_view_content => nil,
120
+ :modal => false,
121
+ :editing => true,
122
+ :empty_text => params[:empty_text],
123
+ :css => '|CABOOSE_CSS|',
124
+ :js => '|CABOOSE_JAVASCRIPT|',
125
+ :csrf_meta_tags => '|CABOOSE_CSRF|',
126
+ :csrf_meta_tags2 => '|CABOOSE_CSRF|',
127
+ :logged_in_user => @logged_in_user,
128
+ :site => @site,
129
+ :page => params[:page_id] ? @p : nil,
130
+ :post => params[:post_id] ? @p : nil,
131
+ :request => request
93
132
  })
94
133
  render :json => html
95
- end
96
-
134
+ end
135
+
97
136
  # GET /admin/pages/:page_id/blocks/render
137
+ # GET /admin/posts/:post_id/blocks/render
98
138
  def admin_render_all
99
- return unless user_is_allowed('pages', 'edit')
100
- p = Page.find(params[:page_id])
101
- blocks = Block.where("page_id = ? and parent_id is null", p.id).reorder(:sort_order).collect do |b|
102
- #bt = b.block_type
103
- #if bt.nil?
104
- # bt = BlockType.where(:name => 'richtext').first
105
- # b.block_type_id = bt.id
106
- # b.save
107
- #end
108
- #b.create_children
139
+ return unless user_is_allowed('pages', 'edit')
140
+ blocks = Block.where("#{page_or_post}_id = ? and parent_id is null", @p.id).reorder(:sort_order).collect do |b|
109
141
  {
110
142
  :id => b.id,
111
143
  :block_type_id => b.block_type.id,
112
144
  :sort_order => b.sort_order,
113
145
  :html => b.render(b, {
114
- :empty_text => params[:empty_text],
115
- :editing => true
146
+ :view => nil,
147
+ :controller_view_content => nil,
148
+ :modal => false,
149
+ :editing => true,
150
+ :empty_text => params[:empty_text],
151
+ :css => '|CABOOSE_CSS|',
152
+ :js => '|CABOOSE_JAVASCRIPT|',
153
+ :csrf_meta_tags => '|CABOOSE_CSRF|',
154
+ :csrf_meta_tags2 => '|CABOOSE_CSRF|',
155
+ :logged_in_user => @logged_in_user,
156
+ :site => @site,
157
+ :page => params[:page_id] ? @p : nil,
158
+ :post => params[:post_id] ? @p : nil,
159
+ :request => request
116
160
  })
117
161
  }
118
162
  end
@@ -120,11 +164,10 @@ module Caboose
120
164
  end
121
165
 
122
166
  # GET /admin/pages/:page_id/blocks/render-second-level
167
+ # GET /admin/posts/:post_id/blocks/render-second-level
123
168
  def admin_render_second_level
124
- return unless user_is_allowed('pages', 'edit')
125
- p = Page.find(params[:page_id])
126
- @p = p
127
- blocks = p.block.children.collect do |b|
169
+ return unless user_is_allowed('pages', 'edit')
170
+ blocks = @p.block.children.collect do |b|
128
171
  {
129
172
  :id => b.id,
130
173
  :block_type_id => b.block_type.id,
@@ -141,22 +184,21 @@ module Caboose
141
184
  :csrf_meta_tags2 => '|CABOOSE_CSRF|',
142
185
  :logged_in_user => @logged_in_user,
143
186
  :site => @site,
144
- :page => p
187
+ :page => params[:page_id] ? @p : nil,
188
+ :post => params[:post_id] ? @p : nil,
189
+ :request => request
145
190
  })
146
191
  }
147
192
  end
148
- render :json => blocks
149
- #render :layout => false
150
-
151
- #respond_to do |format|
152
- # format.json
153
- #end
193
+ render :json => blocks
154
194
  end
155
195
 
156
196
  # GET /admin/pages/:page_id/blocks/:id/edit
197
+ # GET /admin/posts/:post_id/blocks/:id/edit
157
198
  def admin_edit
158
199
  return unless user_is_allowed('pages', 'edit')
159
- @page = Page.find(params[:page_id])
200
+ @page = Page.find(params[:page_id]) if params[:page_id]
201
+ @post = Post.find(params[:post_id]) if params[:post_id]
160
202
  @block = Block.find(params[:id])
161
203
  @block.create_children
162
204
  @modal = true
@@ -173,9 +215,11 @@ module Caboose
173
215
  end
174
216
 
175
217
  # GET /admin/pages/:page_id/blocks/:id/advanced
218
+ # GET /admin/posts/:post_id/blocks/:id/advanced
176
219
  def admin_edit_advanced
177
220
  return unless user_is_allowed('pages', 'edit')
178
- @page = Page.find(params[:page_id])
221
+ @page = Page.find(params[:page_id]) if params[:page_id]
222
+ @post = Post.find(params[:post_id]) if params[:post_id]
179
223
  @block = Block.find(params[:id])
180
224
  @block.create_children
181
225
  render :layout => 'caboose/modal'
@@ -183,6 +227,8 @@ module Caboose
183
227
 
184
228
  # POST /admin/pages/:page_id/blocks
185
229
  # POST /admin/pages/:page_id/blocks/:id
230
+ # POST /admin/posts/:post_id/blocks
231
+ # POST /admin/posts/:post_id/blocks/:id
186
232
  def admin_create
187
233
  return unless user_is_allowed('pages', 'add')
188
234
 
@@ -191,8 +237,12 @@ module Caboose
191
237
  'redirect' => nil
192
238
  })
193
239
 
194
- b = Block.new
195
- b.page_id = params[:page_id].to_i
240
+ b = Block.new
241
+ if params[:page_id]
242
+ b.page_id = params[:page_id].to_i
243
+ else
244
+ b.post_id = params[:post_id].to_i
245
+ end
196
246
  b.parent_id = params[:id] ? params[:id] : nil
197
247
  b.block_type_id = params[:block_type_id]
198
248
 
@@ -245,11 +295,16 @@ module Caboose
245
295
 
246
296
  # Send back the response
247
297
  #resp.block = b
248
- resp.redirect = "/admin/pages/#{b.page_id}/blocks/#{b.id}/edit"
298
+ if params[:page_id]
299
+ resp.redirect = "/admin/pages/#{b.page_id}/blocks/#{b.id}/edit"
300
+ else
301
+ resp.redirect = "/admin/posts/#{b.post_id}/blocks/#{b.id}/edit"
302
+ end
249
303
  render :json => resp
250
304
  end
251
305
 
252
306
  # PUT /admin/pages/:page_id/blocks/:id
307
+ # PUT /admin/posts/:post_id/blocks/:id
253
308
  def admin_update
254
309
  return unless user_is_allowed('pages', 'edit')
255
310
 
@@ -292,13 +347,15 @@ module Caboose
292
347
  end
293
348
 
294
349
  # Trigger the page cache to be updated
295
- pc = PageCache.where(:page_id => b.page_id).first
296
- if pc
297
- pc.refresh = true
298
- pc.save
299
- PageCacher.delay.refresh
300
- else
301
- PageCacher.delay.cache(b.page_id)
350
+ if params[:page_id]
351
+ pc = PageCache.where(:page_id => b.page_id).first
352
+ if pc
353
+ pc.refresh = true
354
+ pc.save
355
+ PageCacher.delay.refresh
356
+ else
357
+ PageCacher.delay.cache(b.page_id)
358
+ end
302
359
  end
303
360
 
304
361
  resp.success = save && b.save
@@ -307,6 +364,7 @@ module Caboose
307
364
  end
308
365
 
309
366
  # POST /admin/pages/:page_id/blocks/:id/image
367
+ # POST /admin/posts/:post_id/blocks/:id/image
310
368
  def admin_update_image
311
369
  return unless user_is_allowed('pages', 'edit')
312
370
 
@@ -321,6 +379,7 @@ module Caboose
321
379
  end
322
380
 
323
381
  # POST /admin/pages/:page_id/blocks/:id/file
382
+ # POST /admin/posts/:post_id/blocks/:id/file
324
383
  def admin_update_file
325
384
  return unless user_is_allowed('pages', 'edit')
326
385
 
@@ -335,6 +394,7 @@ module Caboose
335
394
  end
336
395
 
337
396
  # DELETE /admin/pages/:page_id/blocks/:id
397
+ # DELETE /admin/posts/:post_id/blocks/:id
338
398
  def admin_delete
339
399
  return unless user_is_allowed('pages', 'delete')
340
400
 
@@ -342,7 +402,11 @@ module Caboose
342
402
  b = Block.find(params[:id])
343
403
  parent_id = b.parent_id
344
404
  if b.parent_id
345
- resp.redirect = "/admin/pages/#{b.page_id}/blocks/#{b.parent_id}/edit"
405
+ if params[:page_id]
406
+ resp.redirect = "/admin/pages/#{b.page_id}/blocks/#{b.parent_id}/edit"
407
+ else
408
+ resp.redirect = "/admin/posts/#{b.post_id}/blocks/#{b.parent_id}/edit"
409
+ end
346
410
  else
347
411
  resp.close = true
348
412
  end
@@ -361,6 +425,7 @@ module Caboose
361
425
  end
362
426
 
363
427
  # PUT /admin/pages/:page_id/blocks/:id/move-up
428
+ # PUT /admin/posts/:post_id/blocks/:id/move-up
364
429
  def admin_move_up
365
430
  return unless user_is_allowed('pages', 'delete')
366
431
 
@@ -372,33 +437,11 @@ module Caboose
372
437
  else
373
438
  resp.success = "The block has been moved up successfully."
374
439
  end
375
-
376
- #if b.sort_order == 0
377
- # resp.error = "The block is already at the top."
378
- #else
379
- # b2 = nil
380
- #
381
- # new_sort_order = b.sort_order - 1
382
- # while new_sort_order > 0 do
383
- # b2 = Block.where("parent_id = ? and sort_order = ?", b.parent_id, new_sort_order).first
384
- # break if b2
385
- # new_sort_order = new_sort_order - 1
386
- # end
387
- # if b2
388
- # b2.sort_order = new_sort_order + 1
389
- # b2.save
390
- # else
391
- # new_sort_order = 1
392
- # end
393
- # b.sort_order = new_sort_order
394
- # b.save
395
- # resp.success = "The block has been moved up successfully."
396
- #end
397
-
398
440
  render :json => resp
399
441
  end
400
442
 
401
443
  # PUT /admin/pages/:page_id/blocks/:id/move-down
444
+ # PUT /admin/posts/:post_id/blocks/:id/move-down
402
445
  def admin_move_down
403
446
  return unless user_is_allowed('pages', 'delete')
404
447
 
@@ -419,5 +462,4 @@ module Caboose
419
462
  end
420
463
 
421
464
  end
422
-
423
465
  end
@@ -298,6 +298,12 @@ module Caboose
298
298
  def authnet_relay
299
299
  Caboose.log("Authorize.net relay, order #{params[:x_invoice_id]}")
300
300
 
301
+ if params[:x_invoice_num].nil?
302
+ Caboose.log("Error: no x_invoice_id in given parameters.")
303
+ render :json => { :error => "Invalid x_invoice_id." }
304
+ return
305
+ end
306
+
301
307
  order = Caboose::Order.find(params[:x_invoice_num])
302
308
  ot = Caboose::OrderTransaction.new(
303
309
  :order_id => order.id,