imagine_cms 3.0.0.beta11 → 3.0.0.beta12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  Imagine CMS is a content management system developed by {Bigger Bird Creative, Inc.}[https://www.biggerbird.com] in 2006 for its clients. Other systems came with a learning curve: fine for daily users, but clients who only used it once a month or so would never remember how to use the system the next time they logged in. Simpler systems didn't allow us enough flexibility as designers and developers.
4
4
 
5
+ =Usage & Demo
6
+
7
+ Add to your Gemfile:
8
+ gem 'imagine_cms'
9
+
10
+ Working on the demo... it needs to be fairly resilient to hacking attempts, not a trivial thing to set up.
11
+
5
12
  =History and Roadmap
6
13
 
7
14
  Thus, Imagine was created in the Rails 1.0 days, to run a large number of technically simple content-based sites (versus the one or two highly customized web applications most Rails developers were building at the time). We wanted to provide a way to create and manage static content while also allowing some automation (navigation, RSS feeds, etc.) while also allowing limitless custom development. However, because plugins/engines were quite limited in those days, Imagine was implemented by monkey-patching core parts of Rails and creating a new framework on top of Rails. Although this allowed us great insight into the inner workings of Rails (and led to a minor contribution to Rails core), this approach proved extremely difficult to port to Rails 2. Thus, sites using Imagine have been stuck on Rails 1.2 since time immemorial.
@@ -50,7 +57,7 @@ Assets:
50
57
 
51
58
  Config changes:
52
59
  * Move constants from config/environment.rb to config/initializers/imagine_cms.rb. Use Object.send(:remove_const, :ConstantName) as needed to override default values (bit of a stupid workaround but it works).
53
- * Create config/amazon_s3.yml and add AWS account credentials (preferably IAM, not master account)
60
+ * [To enable S3 asset storage] Create config/imagine_cms.yml (see sample in test/dummy/config) and add AWS account credentials (preferably IAM, not master account). If using CloudFront, enable "Forward Query Strings" (Behaviors > Edit) to make sure visitors see the latest versions of uploaded assets.
54
61
 
55
62
  Third party libraries no longer included:
56
63
  * Install fop in vendor/ if needed.
@@ -434,6 +434,7 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
434
434
  @pg.published_version = @pg.version
435
435
  end
436
436
 
437
+ @pg.updated_on = Time.now.utc
437
438
  @pg.save
438
439
 
439
440
  # do a little bit of classification... for now, just identify page lists
@@ -703,7 +704,7 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
703
704
 
704
705
  def upload_image
705
706
  @pg = CmsPage.find_by_id(params[:id])
706
- target_dir = File.join(Rails.root, 'public', 'images', 'content', @pg.path)
707
+ target_dir = File.join(Rails.root, 'public', 'assets', 'content', @pg.path)
707
708
 
708
709
  if File.exists?(target_dir)
709
710
  redirect_to :action => 'select_gallery', :id => @pg, :gallery_id => params[:gallery_id]
@@ -715,33 +716,24 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
715
716
  def receive_image
716
717
  @pg = CmsPage.find_by_id(params[:id])
717
718
 
718
- data = params[:file][:data]
719
- original_filename = data.original_filename
720
719
  target_dir = File.join(Rails.root, 'public', 'assets', 'content', @pg.path)
721
- localfile = File.join(target_dir, original_filename)
722
-
723
720
  FileUtils.mkdir_p target_dir
724
721
 
725
- unless params[:overwrite].to_i == 1
726
- count = 0
727
- while File.exists?(localfile)
728
- count += 1
729
- localfile = File.join(target_dir, File.basename(original_filename, File.extname(original_filename))) + "-#{count}" + File.extname(original_filename)
730
- end
731
- end
732
-
722
+ data = params[:file][:data]
723
+ original_filename = data.original_filename.strip.gsub(/[\?\s\/\:\\]+/, '-').gsub(/^-/, '').gsub(/-$/, '')
724
+ localfile = File.join(target_dir, original_filename)
733
725
  FileUtils.cp(data.tempfile, localfile)
734
726
 
735
- finish_upload_status "'#{File.basename(localfile)}'" and return
727
+ finish_upload_status "'#{File.basename(localfile)}'"
736
728
  end
737
729
 
738
730
  def crop_image
739
731
  @pg = CmsPage.find_by_id(params[:id])
740
- localfile = File.basename(params[:filename])
732
+ localfile = File.join(Rails.root, 'public', 'assets', 'content', @pg.path, File.basename(params[:filename]))
741
733
 
742
734
  # get out now if user clicked finish
743
735
  if params[:next_clicked].to_i != 1
744
- @image_file = localfile
736
+ @image_file = localfile + "?#{File.mtime(localfile).to_i}"
745
737
  upload_to_s3(localfile, @pg)
746
738
 
747
739
  render :partial => 'crop_results' and return
@@ -749,8 +741,7 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
749
741
 
750
742
 
751
743
  # if we're still here... let's crop!
752
- target_dir = File.join(Rails.root, 'public', 'images', 'content', @pg.path)
753
- localfile = File.join(target_dir, localfile)
744
+ target_dir = File.join(Rails.root, 'public', 'assets', 'content', @pg.path)
754
745
  testfile = File.join(target_dir, File.basename(localfile, File.extname(localfile))) + '-croptest' + File.extname(localfile)
755
746
 
756
747
  # make a smaller version to help with cropping
@@ -770,7 +761,7 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
770
761
 
771
762
  def save_crop
772
763
  @pg = CmsPage.find_by_id(params[:id])
773
- target_dir = File.join(Rails.root, 'public', 'images', 'content', @pg.path)
764
+ target_dir = File.join(Rails.root, 'public', 'assets', 'content', @pg.path)
774
765
  testfile = File.join(target_dir, File.basename(params[:filename]))
775
766
  localfile = testfile.split(/-croptest/).join('')
776
767
 
@@ -806,7 +797,7 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
806
797
  end
807
798
 
808
799
  orig_im.write(localfile) if dirty
809
- @image_file = localfile
800
+ @image_file = localfile + "?#{File.mtime(localfile).to_i}"
810
801
  File.unlink testfile
811
802
  upload_to_s3(localfile, @pg)
812
803
 
@@ -815,78 +806,57 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
815
806
 
816
807
  def receive_gallery
817
808
  @pg = CmsPage.find_by_id(params[:id])
818
- begin
819
- data = params[:gallery_file][:data]
820
- target_dir = File.join(Rails.root, 'public', 'images', 'content', @pg.path)
821
- localdir = File.join(target_dir, 'gallery_1')
822
-
823
- begin
824
- FileUtils.mkdir_p target_dir
825
- rescue Exception => e
826
- logger.debug "Exception: #{e}"
827
- log_error(e)
828
- finish_upload_status "''" and return
829
- end
830
-
831
- unless params[:overwrite].to_i == 1
832
- count = 1
833
- while File.exists?(localdir)
834
- count += 1
835
- localdir = File.join(target_dir, "gallery_#{count}")
836
- end
837
- end
838
-
839
- begin
840
- FileUtils.mkdir_p File.join(localdir, 'temp')
841
- rescue Exception => e
842
- logger.debug "Exception: #{e}"
843
- log_error(e)
844
- finish_upload_status "''" and return
845
- end
809
+
810
+ target_dir = File.join(Rails.root, 'public', 'assets', 'content', @pg.path)
811
+ FileUtils.mkdir_p target_dir
812
+
813
+ count = 1
814
+ localdir = File.join(target_dir, 'gallery_1')
815
+ while File.exists?(localdir) && count < 100
816
+ count += 1
817
+ localdir = File.join(target_dir, "gallery_#{count}")
818
+ end
819
+ FileUtils.mkdir_p File.join(localdir, 'temp')
820
+
821
+ data = params[:gallery_file][:data]
822
+ # read zip file
823
+
824
+ entries = []
825
+ Zip::ZipFile.foreach(data.path) do |zipentry|
826
+ next if ![ '.jpg', '.jpeg', '.png', '.gif' ].include?(File.extname(zipentry.name).downcase) || zipentry.size < 1000
827
+ next if File.basename(zipentry.name) =~ /^\._/
846
828
 
847
- # read zip file
848
- entries = []
849
- Zip::ZipFile.foreach(data.path) do |zipentry|
850
- next if ![ '.jpg', '.jpeg', '.png', '.gif' ].include?(File.extname(zipentry.name).downcase) || zipentry.size < 1000
851
- next if File.basename(zipentry.name) =~ /^\._/
829
+ entries << zipentry
830
+ end
831
+ entries.sort! { |a,b| File.basename(a.name).downcase <=> File.basename(b.name).downcase }
832
+
833
+ Zip::ZipFile.open(data.path) do |zipfile|
834
+ entries.each_with_index do |zipentry, index|
835
+ upload_progress.message = "Extracting #{File.basename(zipentry.name)}"
836
+ ext = File.extname(zipentry.name)
837
+ localfile = File.join(localdir, 'temp', (index+1).to_s + ext.downcase)
838
+ jpgfile = File.join(localdir, 'temp', (index+1).to_s + '.jpg')
852
839
 
853
- entries << zipentry
854
- end
855
- entries.sort! { |a,b| File.basename(a.name).downcase <=> File.basename(b.name).downcase }
856
-
857
- Zip::ZipFile.open(data.path) do |zipfile|
858
- entries.each_with_index do |zipentry, index|
859
- upload_progress.message = "Extracting #{File.basename(zipentry.name)}"
860
- ext = File.extname(zipentry.name)
861
- localfile = File.join(localdir, 'temp', (index+1).to_s + ext.downcase)
862
- jpgfile = File.join(localdir, 'temp', (index+1).to_s + '.jpg')
840
+ begin
841
+ zipentry.extract(localfile)
863
842
 
864
- begin
865
- zipentry.extract(localfile)
866
-
867
- im = MiniMagick::Image.from_file(localfile)
868
- im.write(jpgfile)
869
-
870
- File.unlink(localfile) if localfile != jpgfile
871
-
872
- rescue Exception => e
873
- log_error(e)
874
- end
843
+ im = MiniMagick::Image.from_file(localfile)
844
+ im.write(jpgfile)
845
+
846
+ File.unlink(localfile) if localfile != jpgfile
847
+
848
+ rescue Exception => e
849
+ log_error(e)
875
850
  end
876
851
  end
877
- rescue Exception => e
878
- logger.debug params.inspect
879
- log_error(e)
880
- finish_upload_status "''" and return
881
852
  end
882
853
 
883
- upload_progress.message = "File received successfully."
884
- finish_upload_status "'#{File.basename(localdir)}'" and return
854
+ finish_upload_status "'#{File.basename(localdir)}'"
885
855
  end
886
856
 
887
857
  def gallery_setup
888
858
  @pg = CmsPage.find_by_id(params[:id])
889
- target_dir = File.join('images', 'content', @pg.path)
859
+ target_dir = File.join('assets', 'content', @pg.path)
890
860
  @dirname = File.join(target_dir, File.basename(params[:dirname]), 'temp')
891
861
  Dir.chdir(File.join(Rails.root, 'public'))
892
862
  @images = Dir.glob("#{@dirname}/*.{jpg,jpeg,png,gif}").sort
@@ -915,9 +885,10 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
915
885
  render :partial => 'gallery_setup'
916
886
  end
917
887
 
888
+
918
889
  def complete_gallery
919
890
  @pg = CmsPage.find(params[:id])
920
- target_dir = File.join('images', 'content', @pg.path)
891
+ target_dir = File.join('assets', 'content', @pg.path)
921
892
  @dirname = File.join(target_dir, File.basename(params[:dirname]))
922
893
  @thumbs = session[:gallery_thumbs_ordered]
923
894
  max_width = params[:max_width].to_i
@@ -968,7 +939,7 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
968
939
 
969
940
  def gallery_management
970
941
  @pg = CmsPage.find_by_id(params[:id])
971
- galleries_dir = File.join(Rails.root, 'public', 'images', 'content', @pg.path)
942
+ galleries_dir = File.join(Rails.root, 'public', 'assets', 'content', @pg.path)
972
943
  @galleries = Dir.glob("#{galleries_dir}/gallery_*")
973
944
  gallery_dir = File.join(galleries_dir, params[:gallery_id].to_s)
974
945
 
@@ -990,7 +961,7 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
990
961
 
991
962
  def select_gallery
992
963
  @pg = CmsPage.find_by_id(params[:id])
993
- @target_dir = File.join(Rails.root, 'public', 'images', 'content', @pg.path)
964
+ @target_dir = File.join(Rails.root, 'public', 'assets', 'content', @pg.path)
994
965
  @galleries = Dir.glob("#{@target_dir}/gallery_*")
995
966
 
996
967
  create_preview_images
@@ -1017,7 +988,7 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
1017
988
 
1018
989
  def sort_images
1019
990
  @pg = CmsPage.find_by_id(params[:id])
1020
- gallery_dir = File.join(Rails.root, 'public', 'images', 'content', @pg.path, params[:gallery_id])
991
+ gallery_dir = File.join(Rails.root, 'public', 'assets', 'content', @pg.path, params[:gallery_id])
1021
992
 
1022
993
  @images = Dir.glob("#{gallery_dir}/*.{jpg,jpeg,png,gif}").reject { |img| img.include?('thumb') }.map { |img| File.basename(img).split('.').first.to_i }.sort
1023
994
 
@@ -1031,7 +1002,7 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
1031
1002
 
1032
1003
  def sort_images_save
1033
1004
  @pg = CmsPage.find_by_id(params[:id])
1034
- gallery_dir = File.join(Rails.root, 'public', 'images', 'content', @pg.path, params[:gallery_id])
1005
+ gallery_dir = File.join(Rails.root, 'public', 'assets', 'content', @pg.path, params[:gallery_id])
1035
1006
  temp_dir = File.join(gallery_dir, 'temp')
1036
1007
  sorted_images = session[:gallery_images_sorted] || []
1037
1008
 
@@ -1081,7 +1052,7 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
1081
1052
  end
1082
1053
 
1083
1054
  def image_details
1084
- gallery_dir = File.join(Rails.root, 'public', 'images', 'content', params[:path].to_s, params[:gallery_id])
1055
+ gallery_dir = File.join(Rails.root, 'public', 'assets', 'content', params[:path].to_s, params[:gallery_id])
1085
1056
 
1086
1057
  # create blank captions.yml if it doesn't already exist
1087
1058
  create_captions_file(params[:id])
@@ -1095,7 +1066,7 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
1095
1066
 
1096
1067
  def update_caption
1097
1068
  if request.post?
1098
- gallery_dir = File.join(Rails.root, 'public', 'images', 'content', params[:path].to_s, params[:gallery_id])
1069
+ gallery_dir = File.join(Rails.root, 'public', 'assets', 'content', params[:path].to_s, params[:gallery_id])
1099
1070
 
1100
1071
  image_id = params[:image].split('.')[0].to_i
1101
1072
 
@@ -1113,7 +1084,7 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
1113
1084
 
1114
1085
  def add_to_gallery
1115
1086
  @pg = CmsPage.find_by_id(params[:id])
1116
- galleries_dir = File.join(Rails.root, 'public', 'images', 'content', @pg.path)
1087
+ galleries_dir = File.join(Rails.root, 'public', 'assets', 'content', @pg.path)
1117
1088
  @galleries = Dir.entries(galleries_dir).sort
1118
1089
  @gallery_dir = File.join(galleries_dir, params[:gallery_id])
1119
1090
  images = Dir.glob("#{@gallery_dir}/*-thumb.{jpg,jpeg,png,gif}")
@@ -1202,7 +1173,7 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
1202
1173
 
1203
1174
  def delete_photo
1204
1175
  if request.post?
1205
- gallery_dir = File.join(Rails.root, 'public', 'images', 'content', params[:path].to_s, params[:gallery_id])
1176
+ gallery_dir = File.join(Rails.root, 'public', 'assets', 'content', params[:path].to_s, params[:gallery_id])
1206
1177
 
1207
1178
  image_id = params[:image].split('.')[0].to_i
1208
1179
 
@@ -1245,7 +1216,7 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
1245
1216
 
1246
1217
  def delete_gallery
1247
1218
  @pg = CmsPage.find_by_id(params[:id])
1248
- galleries_dir = File.join(Rails.root, 'public', 'images', 'content', @pg.path)
1219
+ galleries_dir = File.join(Rails.root, 'public', 'assets', 'content', @pg.path)
1249
1220
  gallery_dir = File.join(galleries_dir, params[:gallery_id])
1250
1221
 
1251
1222
  FileUtils.rm_rf(gallery_dir)
@@ -1261,58 +1232,26 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
1261
1232
 
1262
1233
  def receive_file
1263
1234
  @pg = CmsPage.find_by_id(params[:id])
1264
- begin
1265
- data = params[:file][:data]
1266
- original_filename = data.original_filename.downcase.gsub(/[^\.\w\d]+/, '_')
1267
- target_dir = File.join(Rails.root, 'public', 'files', 'content', @pg.path)
1268
- localfile = File.join(target_dir, original_filename)
1269
-
1270
- begin
1271
- FileUtils.mkdir_p target_dir
1272
- rescue Exception => e
1273
- logger.debug "Exception: #{e}"
1274
- log_error(e)
1275
- finish_upload_status "''" and return
1276
- end
1277
-
1278
- unless params[:overwrite].to_i == 1
1279
- count = 0
1280
- while File.exists?(localfile)
1281
- count += 1
1282
- localfile = File.join(target_dir, File.basename(original_filename, File.extname(original_filename))) + "-#{count}" + File.extname(original_filename)
1283
- end
1284
- end
1285
-
1286
- begin
1287
- File.open(localfile, 'wb') { |f| f.write('test') }
1288
- rescue Exception => e
1289
- logger.debug "Exception: #{e}"
1290
- log_error(e)
1291
- finish_upload_status "''" and return
1292
- end
1293
-
1294
- begin
1295
- File.open(localfile, 'wb') { |f| f.write(data.read) }
1296
- rescue Exception => e
1297
- logger.debug "Exception: #{e}"
1298
- log_error(e)
1299
- finish_upload_status "''" and return
1300
- end
1301
- rescue Exception => e
1302
- logger.debug params.inspect
1303
- # logger.debug "Exception: #{e}"
1304
- log_error(e)
1305
- finish_upload_status "''" and return
1306
- end
1307
1235
 
1308
- upload_progress.message = "File received successfully."
1309
- finish_upload_status "'#{File.basename(localfile)}'" and return
1236
+ target_dir = File.join(Rails.root, 'public', 'assets', 'content', @pg.path)
1237
+ FileUtils.mkdir_p target_dir
1238
+
1239
+ data = params[:file][:data]
1240
+ original_filename = data.original_filename.strip.gsub(/[\?\s\/\:\\]+/, '-').gsub(/^-/, '').gsub(/-$/, '')
1241
+ localfile = File.join(target_dir, original_filename)
1242
+ FileUtils.cp(data.tempfile, localfile)
1243
+
1244
+ finish_upload_status "'#{File.basename(localfile)}'"
1310
1245
  end
1311
1246
 
1312
1247
  def create_file_link
1313
1248
  @pg = CmsPage.find_by_id(params[:id])
1314
- target_dir = File.join('files', 'content', @pg.path)
1315
- @filename = File.join(target_dir, File.basename(params[:filename]))
1249
+ localfile = File.join(Rails.root, 'public', 'assets', 'content', @pg.path, File.basename(params[:filename]))
1250
+
1251
+ @filename = localfile + "?#{File.mtime(localfile).to_i}"
1252
+ upload_to_s3(localfile, @pg, ImagineCmsConfig['amazon_s3'][Rails.env]['file_bucket'],
1253
+ ImagineCmsConfig['amazon_s3']['file_prefix'])
1254
+
1316
1255
  render :partial => 'create_file_link'
1317
1256
  end
1318
1257
 
@@ -1324,19 +1263,18 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
1324
1263
 
1325
1264
  def crop_thumb
1326
1265
  @pg = CmsPage.find_by_id(params[:id])
1327
- localfile = File.basename(params[:filename])
1266
+ localfile = File.join(Rails.root, 'public', 'assets', 'content', @pg.path, File.basename(params[:filename]))
1328
1267
 
1329
1268
  # get out now if user clicked finish
1330
1269
  if params[:next_clicked].to_i != 1
1331
- @image_file = localfile
1270
+ @image_file = localfile + "?#{File.mtime(localfile).to_i}"
1332
1271
  upload_to_s3(localfile, @pg)
1333
1272
  render :partial => 'crop_results_thumb' and return
1334
1273
  end
1335
1274
 
1336
1275
 
1337
1276
  # if we're still here... let's crop!
1338
- target_dir = File.join(Rails.root, 'public', 'images', 'content', @pg.path)
1339
- localfile = File.join(target_dir, localfile)
1277
+ target_dir = File.join(Rails.root, 'public', 'assets', 'content', @pg.path)
1340
1278
  testfile = File.join(target_dir, File.basename(localfile, File.extname(localfile))) + '-croptest' + File.extname(localfile)
1341
1279
 
1342
1280
  # make a smaller version to help with cropping
@@ -1356,7 +1294,7 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
1356
1294
 
1357
1295
  def save_crop_thumb
1358
1296
  @pg = CmsPage.find_by_id(params[:id])
1359
- target_dir = File.join(Rails.root, 'public', 'images', 'content', @pg.path)
1297
+ target_dir = File.join(Rails.root, 'public', 'assets', 'content', @pg.path)
1360
1298
  testfile = File.join(target_dir, File.basename(params[:filename]))
1361
1299
  localfile = testfile.split(/-croptest/).join('')
1362
1300
 
@@ -1394,7 +1332,7 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
1394
1332
  orig_im.write(localfile) if dirty
1395
1333
  File.chmod(0644, localfile)
1396
1334
 
1397
- @image_file = localfile
1335
+ @image_file = localfile + "?#{File.mtime(localfile).to_i}"
1398
1336
  File.unlink testfile
1399
1337
  upload_to_s3(localfile, @pg)
1400
1338
 
@@ -1408,19 +1346,18 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
1408
1346
 
1409
1347
  def crop_feature_image
1410
1348
  @pg = CmsPage.find_by_id(params[:id])
1411
- localfile = File.basename(params[:filename])
1349
+ localfile = File.join(Rails.root, 'public', 'assets', 'content', @pg.path, File.basename(params[:filename]))
1412
1350
 
1413
1351
  # get out now if user clicked finish
1414
1352
  if params[:next_clicked].to_i != 1
1415
- @image_file = localfile
1353
+ @image_file = localfile + "?#{File.mtime(localfile).to_i}"
1416
1354
  upload_to_s3(localfile, @pg)
1417
1355
  render :partial => 'crop_results_feature_image' and return
1418
1356
  end
1419
1357
 
1420
1358
 
1421
1359
  # if we're still here... let's crop!
1422
- target_dir = File.join(Rails.root, 'public', 'images', 'content', @pg.path)
1423
- localfile = File.join(target_dir, localfile)
1360
+ target_dir = File.join(Rails.root, 'public', 'assets', 'content', @pg.path)
1424
1361
  testfile = File.join(target_dir, File.basename(localfile, File.extname(localfile))) + '-croptest' + File.extname(localfile)
1425
1362
 
1426
1363
  # make a smaller version to help with cropping
@@ -1440,7 +1377,7 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
1440
1377
 
1441
1378
  def save_crop_feature_image
1442
1379
  @pg = CmsPage.find_by_id(params[:id])
1443
- target_dir = File.join(Rails.root, 'public', 'images', 'content', @pg.path)
1380
+ target_dir = File.join(Rails.root, 'public', 'assets', 'content', @pg.path)
1444
1381
  testfile = File.join(target_dir, File.basename(params[:filename]))
1445
1382
  localfile = testfile.split(/-croptest/).join('')
1446
1383
 
@@ -1478,7 +1415,7 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
1478
1415
  orig_im.write(localfile) if dirty
1479
1416
  File.chmod(0644, localfile)
1480
1417
 
1481
- @image_file = localfile
1418
+ @image_file = localfile + "?#{File.mtime(localfile).to_i}"
1482
1419
  File.unlink testfile
1483
1420
  upload_to_s3(localfile, @pg)
1484
1421
 
@@ -1493,8 +1430,6 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
1493
1430
  @template_options = HashObject.new
1494
1431
 
1495
1432
  if @pg.new_record? && @parent
1496
- # This does not appear to be a beneficial feature any longer
1497
- # @tags = @parent.tags.collect { |t| t.name }.join(', ')
1498
1433
  @parent.objects.find(:all, :conditions => [ "obj_type = 'attribute'" ]).each do |obj|
1499
1434
  key = "obj-#{obj.obj_type.to_s}-#{obj.name}"
1500
1435
  @page_objects[key] = obj.content
@@ -1532,7 +1467,7 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
1532
1467
  gallery_id = (!options[:gallery_id] ? params[:gallery_id] : options[:gallery_id])
1533
1468
 
1534
1469
  @pg = CmsPage.find_by_id(pg_id)
1535
- galleries_dir = File.join(Rails.root, 'public', 'images', 'content', @pg.path)
1470
+ galleries_dir = File.join(Rails.root, 'public', 'assets', 'content', @pg.path)
1536
1471
  gallery_dir = File.join(galleries_dir, gallery_id)
1537
1472
  captions_location = File.join(gallery_dir, 'captions.yml')
1538
1473
 
@@ -1543,7 +1478,7 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
1543
1478
 
1544
1479
  # prerequisites: @pg (CmsPage)
1545
1480
  def load_gallery_settings_from_file(gallery_id, options = {})
1546
- galleries_dir = File.join(Rails.root, 'public', 'images', 'content', @pg.path)
1481
+ galleries_dir = File.join(Rails.root, 'public', 'assets', 'content', @pg.path)
1547
1482
  gallery_dir = File.join(galleries_dir, gallery_id)
1548
1483
  settings_location = File.join(gallery_dir, 'settings.yml')
1549
1484
 
@@ -1566,7 +1501,7 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
1566
1501
  def save_gallery_settings_to_file(gallery_id, settings_hash, options = {})
1567
1502
  settings_hash = settings_hash.hash if settings_hash.kind_of?(HashObject)
1568
1503
 
1569
- galleries_dir = File.join(Rails.root, 'public', 'images', 'content', @pg.path)
1504
+ galleries_dir = File.join(Rails.root, 'public', 'assets', 'content', @pg.path)
1570
1505
  gallery_dir = File.join(galleries_dir, gallery_id)
1571
1506
  settings_location = File.join(gallery_dir, 'settings.yml')
1572
1507
 
@@ -1574,33 +1509,21 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
1574
1509
  end
1575
1510
 
1576
1511
  def resize_image(localfile)
1577
- ext = File.extname(localfile)
1578
-
1579
- # AKN: this would change all files to jpeg format... commenting out for now
1580
- # filename = File.join(File.dirname(localfile), File.basename(localfile, ext) + '.jpg')
1581
- filename = localfile
1582
-
1583
1512
  im = MiniMagick::Image::from_file(localfile)
1584
1513
 
1585
1514
  if im[:width] > GalleryMaxWidth || im[:height] > GalleryMaxHeight
1586
1515
  im.resize("#{GalleryMaxWidth}x#{GalleryMaxHeight}")
1587
- im.write(filename)
1588
- elsif filename != localfile
1589
- im.write(filename)
1516
+ im.write(localfile)
1590
1517
  end
1591
1518
 
1592
- File.unlink(localfile) unless localfile == filename
1593
-
1594
- filename
1519
+ localfile
1595
1520
  end
1596
1521
 
1597
1522
  def create_preview_image(src_file, dest, force = 0, overlay = 'gallery_small_overlay.png', thumb_size = 90)
1598
- require 'RMagick'
1599
-
1600
1523
  dest = File.join(dest, File.basename(src_file)) if File.directory?(dest)
1601
1524
  if !File.exists?(dest) || force == 1
1602
1525
  im = Magick::Image::read(src_file)[0]
1603
- im_overlay = Magick::Image::read(File.join(Rails.root, 'public', 'images', 'management', overlay))[0]
1526
+ im_overlay = Magick::Image::read(File.join(ImagineCms::Engine.root, 'assets', 'images', 'management', overlay))[0]
1604
1527
 
1605
1528
  im.crop_resized!(thumb_size, thumb_size)
1606
1529
  im = im.composite(im_overlay, Magick::CenterGravity, Magick::OverCompositeOp)
@@ -1615,10 +1538,9 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
1615
1538
  end
1616
1539
  end
1617
1540
 
1541
+ # prerequisites: @pg (CmsPage)
1618
1542
  def create_preview_images(options = {})
1619
- # assumes @pg has already been set before calling
1620
-
1621
- galleries_dir = File.join(Rails.root, 'public', 'images', 'content', @pg.path)
1543
+ galleries_dir = File.join(Rails.root, 'public', 'assets', 'content', @pg.path)
1622
1544
  session[:broken_galleries] = []
1623
1545
 
1624
1546
  # create preview images if not already made
@@ -1650,16 +1572,20 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
1650
1572
  end
1651
1573
  end
1652
1574
 
1653
- def upload_to_s3(filename, page)
1575
+ def upload_to_s3(filename, page, bucket = nil, prefix = nil)
1654
1576
  s3retries = 0
1655
1577
  s3success = false
1656
1578
 
1657
1579
  if ImagineCmsConfig['amazon_s3'] && ImagineCmsConfig['amazon_s3']['enabled']
1658
- filename = File.join(Rails.root, 'public', 'assets', 'content', page.path, File.basename(filename))
1659
- prefix = ImagineCmsConfig['amazon_s3'][Rails.env]['image_prefix']
1660
- bucket = ImagineCmsConfig['amazon_s3'][Rails.env]['image_bucket']
1580
+ bucket ||= ImagineCmsConfig['amazon_s3'][Rails.env]['image_bucket']
1581
+ prefix ||= ImagineCmsConfig['amazon_s3']['image_prefix']
1582
+
1583
+ # set options + metadata
1584
+ options = ImagineCmsConfig['amazon_s3']['metadata']
1585
+ options[:access] = :public_read
1586
+
1661
1587
  while s3retries < 2 && !s3success
1662
- response = AWS::S3::S3Object.store("#{prefix}/#{page.path.blank? ? 'index' : page.path}/#{File.basename(filename)}", open(filename), bucket, :access => :public_read)
1588
+ response = AWS::S3::S3Object.store("#{prefix}/#{page.path.blank? ? 'index' : page.path}/#{File.basename(filename)}", open(filename), bucket, options)
1663
1589
  s3success = response.code == 200
1664
1590
  s3retries += 1
1665
1591
  end
@@ -1670,3 +1596,21 @@ class Management::CmsController < Management::ApplicationController # :nodoc:
1670
1596
  end
1671
1597
 
1672
1598
  end
1599
+
1600
+ module MiniMagick
1601
+ class Image
1602
+ def crop_resized(ncols, nrows, gravity='Center')
1603
+ columns = self[:width].to_i
1604
+ rows = self[:height].to_i
1605
+
1606
+ if ncols != columns || nrows != rows
1607
+ scale = [ncols/columns.to_f, nrows/rows.to_f].max
1608
+ resize("#{scale*(columns+0.5).to_i}x#{scale*(rows+0.5).to_i}")
1609
+ end
1610
+
1611
+ columns = self[:width].to_i
1612
+ rows = self[:height].to_i
1613
+ crop("#{ncols}x#{nrows}+0+0", "-gravity", "#{gravity}") if ncols != columns || nrows != rows
1614
+ end
1615
+ end
1616
+ end
@@ -1096,11 +1096,25 @@ EOF
1096
1096
  ret += javascript_tag("cropper = new Cropper.Img('testImage', { minWidth: 0, minHeight: 0, captureKeys: false, onEndCrop: onEndCrop });")
1097
1097
  end
1098
1098
 
1099
+ # filename should include version number in query string
1100
+ def page_file_path(page, filename)
1101
+ if ImagineCmsConfig['amazon_s3'] && ImagineCmsConfig['amazon_s3']['enabled']
1102
+ prefix = ImagineCmsConfig['amazon_s3']['file_prefix']
1103
+ hostname = ImagineCmsConfig['amazon_s3'][Rails.env]['file_hostname']
1104
+ filename, timestamp = File.basename(filename).split('?')
1105
+ "//#{hostname}/#{prefix}/#{page.path.blank? ? 'index' : page.path}/#{ERB::Util.url_encode filename}?#{timestamp}"
1106
+ else
1107
+ "/#{File.join('assets', 'content', page.path, File.basename(filename))}"
1108
+ end
1109
+ end
1110
+
1111
+ # filename should include version number in query string
1099
1112
  def page_image_path(page, filename)
1100
1113
  if ImagineCmsConfig['amazon_s3'] && ImagineCmsConfig['amazon_s3']['enabled']
1101
- prefix = ImagineCmsConfig['amazon_s3'][Rails.env]['image_prefix']
1114
+ prefix = ImagineCmsConfig['amazon_s3']['image_prefix']
1102
1115
  hostname = ImagineCmsConfig['amazon_s3'][Rails.env]['image_hostname']
1103
- "//#{hostname}/#{prefix}/#{page.path.blank? ? 'index' : page.path}/#{File.basename(filename)}"
1116
+ filename, timestamp = File.basename(filename).split('?')
1117
+ "//#{hostname}/#{prefix}/#{page.path.blank? ? 'index' : page.path}/#{ERB::Util.url_encode filename}?#{timestamp}"
1104
1118
  else
1105
1119
  "/#{File.join('assets', 'content', page.path, File.basename(filename))}"
1106
1120
  end
@@ -1,6 +1,6 @@
1
1
  <%-
2
- ext = File.extname(@filename)
3
- ext = (ext.blank? ? 'generic' : ext.gsub(/\./, ''))
2
+ ext = File.extname(@filename).gsub(/\?\d+/, '')
3
+ ext = (ext.blank? ? 'generic' : ext.gsub(/\./, ''))
4
4
  -%>
5
5
  <%= javascript_tag <<-EOF
6
6
  var curInst = dojo.widget.Editor2Manager.getCurrentInstance();
@@ -15,7 +15,7 @@ if (!linkNode) {
15
15
  dojo.withGlobal(curInst.window, 'selectElement', dojo.html.selection, [linkNode]);
16
16
  }
17
17
 
18
- curInst.execCommand('inserthtml', '<a href=\"/#{@filename}\" class=\"file-#{ext}\" target=\"_blank\">'+html+'</a>');
18
+ curInst.execCommand('inserthtml', '<a href=\"#{page_file_path(@pg, @filename)}\" class=\"file-#{ext}\" target=\"_blank\">'+html+'</a>');
19
19
  cancelInsertFile();
20
20
  EOF
21
21
  %>
@@ -182,7 +182,7 @@ Pressing "Save Feature Image" will crop the image and set it as the new feature
182
182
  </tr>
183
183
  </table>
184
184
 
185
- <%= submit_tag 'Save Feature Image', :class => 'form_button', :style => 'width: 90px;', :onclick => 'cropper.remove(); this.disabled = true; this.value = "Saving...";' %>
185
+ <%= submit_tag 'Save Feature Image', :class => 'form_button', :onclick => 'cropper.remove(); this.disabled = true; this.value = "Saving...";' %>
186
186
  <%= link_to_function "Cancel", "cancelSelectThumbnail()" %>
187
187
  <%- end -%>
188
188
  </center>
@@ -182,7 +182,7 @@ Pressing "Save Thumbnail" will crop the thumbnail and set it as the new thumbnai
182
182
  </tr>
183
183
  </table>
184
184
 
185
- <%= submit_tag 'Save Thumbnail', :class => 'form_button', :style => 'width: 90px;', :onclick => 'cropper.remove(); this.disabled = true; this.value = "Saving...";' %>
185
+ <%= submit_tag 'Save Thumbnail', :class => 'form_button', :onclick => 'cropper.remove(); this.disabled = true; this.value = "Saving...";' %>
186
186
  <%= link_to_function "Cancel", "cancelSelectThumbnail()" %>
187
187
  <%- end -%>
188
188
  </center>
@@ -106,7 +106,7 @@
106
106
  <%- if @pg.new_record? -%>
107
107
  A thumbnail cannot be added until you save this page.
108
108
  <%- else -%>
109
- <div id="thumbnail_preview" style="width: 100%; overflow: auto;">
109
+ <div id="thumbnail_preview" style="width: 385px; overflow: auto;">
110
110
  <%- if @pg.thumbnail_path.empty? -%>
111
111
  no thumbnail image selected
112
112
  <%- else -%>
@@ -127,7 +127,7 @@
127
127
  <%- if @pg.new_record? -%>
128
128
  A feature image cannot be added until you save this page.
129
129
  <%- else -%>
130
- <div id="feature_image_preview" style="width: 100%; overflow: auto;">
130
+ <div id="feature_image_preview" style="width: 385px; overflow: auto;">
131
131
  <%- if @pg.feature_image_path.empty? -%>
132
132
  no feature image selected
133
133
  <%- else -%>
@@ -1,3 +1,3 @@
1
1
  module ImagineCms
2
- VERSION = "3.0.0.beta11"
2
+ VERSION = "3.0.0.beta12"
3
3
  end
@@ -0,0 +1,39 @@
1
+ amazon_s3:
2
+ enabled: true
3
+
4
+ metadata:
5
+ 'Cache-Control': 'max-age=2592000'
6
+
7
+ image_prefix: site1/images
8
+ file_prefix: site1/files
9
+ media_prefix: site1/media
10
+
11
+ development:
12
+ access_key_id:
13
+ secret_access_key:
14
+ image_bucket: abc-dev
15
+ file_bucket: abc-dev
16
+ media_bucket: abc-dev
17
+ image_hostname: abc-dev.s3.amazonaws.com
18
+ file_hostname: abc-dev.s3.amazonaws.com
19
+ media_hostname: abc-dev.s3.amazonaws.com
20
+
21
+ test:
22
+ access_key_id: AKIAIBZNS5FMNCMWOQCQ
23
+ secret_access_key: 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
24
+ image_bucket: abc-test
25
+ file_bucket: abc-test
26
+ media_bucket: abc-test
27
+ image_hostname: abc-test.s3.amazonaws.com
28
+ media_hostname: abc-test.s3.amazonaws.com
29
+ media_hostname: abc-test.s3.amazonaws.com
30
+
31
+ production:
32
+ access_key_id: AKIAJG6SL2GZP4C6GYFA
33
+ secret_access_key: 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
34
+ image_bucket: abc
35
+ file_bucket: abc
36
+ media_bucket: abc
37
+ image_hostname: abc123.cloudfront.net
38
+ file_hostname: abc123.cloudfront.net
39
+ media_hostname: abc123.cloudfront.net
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imagine_cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.beta11
4
+ version: 3.0.0.beta12
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -497,6 +497,7 @@ files:
497
497
  - test/dummy/config/environments/development.rb
498
498
  - test/dummy/config/environments/production.rb
499
499
  - test/dummy/config/environments/test.rb
500
+ - test/dummy/config/imagine_cms.yml
500
501
  - test/dummy/config/initializers/backtrace_silencers.rb
501
502
  - test/dummy/config/initializers/inflections.rb
502
503
  - test/dummy/config/initializers/mime_types.rb
@@ -558,6 +559,7 @@ test_files:
558
559
  - test/dummy/config/environments/development.rb
559
560
  - test/dummy/config/environments/production.rb
560
561
  - test/dummy/config/environments/test.rb
562
+ - test/dummy/config/imagine_cms.yml
561
563
  - test/dummy/config/initializers/backtrace_silencers.rb
562
564
  - test/dummy/config/initializers/inflections.rb
563
565
  - test/dummy/config/initializers/mime_types.rb