gluttonberg-core 2.5.5 → 2.5.6

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.
Files changed (66) hide show
  1. data/app/assets/javascripts/gb_application.js +34 -0
  2. data/app/assets/stylesheets/gb_admin-override.sass +17 -1
  3. data/app/controllers/gluttonberg/admin/asset_library/assets_controller.rb +4 -2
  4. data/app/controllers/gluttonberg/admin/content/articles_controller.rb +22 -22
  5. data/app/controllers/gluttonberg/admin/content/comments_controller.rb +80 -23
  6. data/app/controllers/gluttonberg/admin/main_controller.rb +1 -1
  7. data/app/controllers/gluttonberg/public/comments_controller.rb +9 -8
  8. data/app/helpers/gluttonberg/admin.rb +3 -3
  9. data/app/helpers/gluttonberg/asset_library.rb +14 -11
  10. data/app/models/gluttonberg/asset.rb +8 -6
  11. data/app/models/gluttonberg/comment.rb +57 -3
  12. data/app/models/gluttonberg/comment_subscription.rb +2 -0
  13. data/app/models/gluttonberg/setting.rb +11 -5
  14. data/app/views/gluttonberg/admin/asset_library/assets/_browser_root.html.haml +20 -3
  15. data/app/views/gluttonberg/admin/asset_library/assets/search.json.haml +1 -1
  16. data/app/views/gluttonberg/admin/content/comments/index.html.haml +36 -10
  17. data/app/views/gluttonberg/admin/content/main/_sidebar.html.haml +6 -3
  18. data/app/views/gluttonberg/admin/main/index.html.haml +4 -4
  19. data/app/views/gluttonberg/admin/settings/generic_settings/index.html.haml +11 -7
  20. data/config/routes.rb +10 -0
  21. data/db/migrate/20130201025800_spam_flag_for_comments.rb +6 -0
  22. data/lib/engine.rb +3 -2
  23. data/lib/generators/gluttonberg/installer/installer_generator.rb +33 -32
  24. data/lib/gluttonberg/content/block.rb +2 -0
  25. data/lib/gluttonberg/content/clean_html.rb +16 -14
  26. data/lib/gluttonberg/content/despamilator/conf/unusual_characters.txt +6674 -0
  27. data/lib/gluttonberg/content/despamilator/filter/emails.rb +49 -0
  28. data/lib/gluttonberg/content/despamilator/filter/gtubs_test_filter.rb +25 -0
  29. data/lib/gluttonberg/content/despamilator/filter/html_tags.rb +134 -0
  30. data/lib/gluttonberg/content/despamilator/filter/ip_address_url.rb +27 -0
  31. data/lib/gluttonberg/content/despamilator/filter/long_words.rb +29 -0
  32. data/lib/gluttonberg/content/despamilator/filter/mixed_case.rb +25 -0
  33. data/lib/gluttonberg/content/despamilator/filter/naughty_words.rb +80 -0
  34. data/lib/gluttonberg/content/despamilator/filter/no_vowels.rb +28 -0
  35. data/lib/gluttonberg/content/despamilator/filter/numbers_and_words.rb +55 -0
  36. data/lib/gluttonberg/content/despamilator/filter/obfuscated_urls.rb +45 -0
  37. data/lib/gluttonberg/content/despamilator/filter/prices.rb +23 -0
  38. data/lib/gluttonberg/content/despamilator/filter/script_tag.rb +25 -0
  39. data/lib/gluttonberg/content/despamilator/filter/shouting.rb +38 -0
  40. data/lib/gluttonberg/content/despamilator/filter/spammy_tlds.rb +26 -0
  41. data/lib/gluttonberg/content/despamilator/filter/square_brackets.rb +27 -0
  42. data/lib/gluttonberg/content/despamilator/filter/trailing_number.rb +25 -0
  43. data/lib/gluttonberg/content/despamilator/filter/unusual_characters.rb +51 -0
  44. data/lib/gluttonberg/content/despamilator/filter/urls.rb +45 -0
  45. data/lib/gluttonberg/content/despamilator/filter/very_long_domain_name.rb +31 -0
  46. data/lib/gluttonberg/content/despamilator/filter/weird_punctuation.rb +48 -0
  47. data/lib/gluttonberg/content/despamilator/filter.rb +57 -0
  48. data/lib/gluttonberg/content/despamilator/subject/text.rb +36 -0
  49. data/lib/gluttonberg/content/despamilator/subject.rb +34 -0
  50. data/lib/gluttonberg/content/despamilator/version.rb +7 -0
  51. data/lib/gluttonberg/content/despamilator.rb +79 -0
  52. data/lib/gluttonberg/content.rb +12 -11
  53. data/lib/gluttonberg/library/attachment_mixin.rb +52 -269
  54. data/lib/gluttonberg/library/config/image_sizes.rb +61 -0
  55. data/lib/gluttonberg/library/config.rb +10 -0
  56. data/lib/gluttonberg/library/processor/audio.rb +42 -0
  57. data/lib/gluttonberg/library/processor/image.rb +134 -0
  58. data/lib/gluttonberg/library/processor.rb +11 -0
  59. data/lib/gluttonberg/library/storage/filesystem.rb +76 -0
  60. data/lib/gluttonberg/library/storage/s3.rb +196 -0
  61. data/lib/gluttonberg/library/storage.rb +11 -0
  62. data/lib/gluttonberg/library.rb +87 -86
  63. data/lib/gluttonberg/record_history.rb +14 -15
  64. data/lib/gluttonberg/tasks/asset.rake +25 -3
  65. data/lib/gluttonberg/version.rb +1 -1
  66. metadata +53 -2
@@ -0,0 +1,76 @@
1
+ module Gluttonberg
2
+ module Library
3
+ module Storage
4
+ module Filesystem
5
+
6
+ module ClassMethods
7
+ # It run when the engine is loaded. It makes sure that all the required
8
+ # directories for storing assets are in the public dir, creating them if
9
+ # they are missing. It also stores the various paths so they can be
10
+ # retreived using the assets_dir method.
11
+ def self.storage_setup
12
+ Library.set_asset_root("public/user_assets", "public/user_assets", "public/test_assets")
13
+ FileUtils.mkdir(Library.root) unless File.exists?(Library.root) || File.symlink?(Library.root)
14
+ end
15
+ end
16
+
17
+ module InstanceMethods
18
+
19
+ # The generated directory where this file is located. If it is an image
20
+ # it’s thumbnails will be stored here as well.
21
+ def directory
22
+ Filesystem::ClassMethods.storage_setup if Library.root.blank?
23
+ Library.root + "/" + self.asset_hash
24
+ end
25
+
26
+ def tmp_directory
27
+ Filesystem::ClassMethods.storage_setup if Library.tmp_root.blank?
28
+ Library.tmp_root + "/" + self.asset_hash
29
+ end
30
+
31
+ def assets_directory_public_url
32
+ "/user_assets"
33
+ end
34
+
35
+ def make_backup
36
+ unless File.exist?(original_file_on_disk)
37
+ FileUtils.cp location_on_disk, original_file_on_disk
38
+ FileUtils.chmod(0755,original_file_on_disk)
39
+ end
40
+ end
41
+
42
+ def remove_file_from_storage
43
+ if File.exists?(directory)
44
+ FileUtils.rm_r(directory)
45
+ end
46
+ end
47
+
48
+ def remove_file_from_tmp_storage
49
+ # just dummy method. As we don't need to remove because tmp and actual folder is same for filesystem
50
+ end
51
+
52
+ def update_file_on_storage
53
+ if file
54
+ FileUtils.mkdir(directory) unless File.exists?(directory)
55
+ FileUtils.cp file.tempfile.path, location_on_disk
56
+ FileUtils.chmod(0755, location_on_disk)
57
+
58
+ # new file has been upload, if its image generate thumbnails, if mp3 collect sound info.
59
+ asset_processing
60
+ end
61
+ end
62
+
63
+ def move_tmp_file_to_actual_directory(file_name , tmp_file_dirty=true)
64
+ if self.file_dirty == true
65
+ self.file_dirty = false
66
+ end
67
+ end
68
+
69
+ # def write_file_to_disc(src_file_path , )
70
+ # end
71
+ end #InstanceMethods
72
+
73
+ end #Filesystem
74
+ end #Storage
75
+ end #Library
76
+ end #Gluttonberg
@@ -0,0 +1,196 @@
1
+ module Gluttonberg
2
+ module Library
3
+ module Storage
4
+ module S3
5
+ module ClassMethods
6
+ # It run when the engine is loaded. It makes sure that all the required
7
+ # directories for storing assets are in the public dir, creating them if
8
+ # they are missing. It also stores the various paths so they can be
9
+ # retreived using the assets_dir method.
10
+ TEMP_ASSET_DIRECTORY = "tmp/user_assets"
11
+ def self.storage_setup
12
+ Library.set_asset_root("user_assets", TEMP_ASSET_DIRECTORY, "public/test_assets")
13
+ FileUtils.mkdir(Library.root) unless File.exists?(Library.root) || File.symlink?(Library.root)
14
+ FileUtils.mkdir(Library.tmp_root) unless File.exists?(Library.tmp_root) || File.symlink?(Library.tmp_root)
15
+ end
16
+
17
+ def self.s3_server_url
18
+ Gluttonberg::Setting.get_setting("s3_server_url")
19
+ end
20
+
21
+ def self.s3_bucket_name
22
+ Gluttonberg::Setting.get_setting("s3_bucket")
23
+ end
24
+
25
+ def self.s3_server_key_id
26
+ Gluttonberg::Setting.get_setting("s3_key_id")
27
+ end
28
+
29
+ def self.s3_server_access_key
30
+ Gluttonberg::Setting.get_setting("s3_access_key")
31
+ end
32
+
33
+ def self.bucket_handle
34
+ key_id = S3::ClassMethods.s3_server_key_id
35
+ key_val = S3::ClassMethods.s3_server_access_key
36
+ s3_server_url = S3::ClassMethods.s3_server_url
37
+ s3_bucket = S3::ClassMethods.s3_bucket_name
38
+ if !key_id.blank? && !key_val.blank? && !s3_server_url.blank? && !s3_bucket.blank?
39
+ s3 = Aws::S3.new(key_id, key_val, {:server => s3_server_url})
40
+ bucket = s3.bucket(s3_bucket)
41
+ else
42
+ nil
43
+ end
44
+ end
45
+
46
+ #takes file from public/assets folder and upload to s3 if s3 info is given in CMS settings
47
+ def self.migrate_file_to_s3(asset_hash , file_name)
48
+ bucket = bucket_handle
49
+ unless bucket.blank?
50
+ local_file = "public/user_assets/" + asset_hash + "/" + file_name
51
+ key_for_s3 = "user_assets/" + asset_hash + "/" + file_name
52
+ date = Time.now+1.years
53
+ key = bucket.key(key_for_s3, true)
54
+ asset = Gluttonberg::Asset.where(:asset_hash => asset_hash).first
55
+ unless asset.blank?
56
+ puts " Copying #{local_file} to #{S3::ClassMethods.s3_bucket_name}"
57
+ unless asset.mime_type.blank?
58
+ key.put(File.open(local_file), 'public-read', {"Expires" => date.rfc2822, "content-type" => asset.mime_type})
59
+ else
60
+ key.put(File.open(local_file), 'public-read', {"Expires" => date.rfc2822})
61
+ end
62
+ Gluttonberg::Asset.update_attributes(:copied_to_s3 => true)
63
+ puts "Copied"
64
+ end
65
+ end
66
+ end
67
+
68
+ end
69
+
70
+ module InstanceMethods
71
+
72
+ def bucket_handle
73
+ unless @bucket.blank?
74
+ @bucket
75
+ else
76
+ @bucket = S3::ClassMethods.bucket_handle
77
+ end
78
+ end
79
+
80
+ # The generated directory where this file is located.
81
+ def directory
82
+ S3::ClassMethods.storage_setup if Library.root.blank?
83
+ Library.root + "/" + self.asset_hash
84
+ end
85
+
86
+ # The generated tmp directory where we will locate this file temporarily for processing.
87
+ def tmp_directory
88
+ S3::ClassMethods.storage_setup if Library.tmp_root.blank?
89
+ Library.tmp_root + "/" + self.asset_hash
90
+ end
91
+
92
+ def s3_bucket_root_url
93
+ "http://#{S3::ClassMethods.s3_server_url}/#{S3::ClassMethods.s3_bucket_name}"
94
+ end
95
+
96
+ def assets_directory_public_url
97
+ "#{s3_bucket_root_url}/user_assets"
98
+ end
99
+
100
+ def make_backup
101
+ unless File.exist?(tmp_original_file_on_disk)
102
+ FileUtils.cp tmp_location_on_disk, tmp_original_file_on_disk
103
+ FileUtils.chmod(0755,tmp_original_file_on_disk)
104
+ move_tmp_file_to_actual_directory("original_" + file_name , true)
105
+ end
106
+ end
107
+
108
+ def remove_file_from_storage
109
+ remove_file_from_tmp_storage
110
+ remove_asset_folder_from_s3
111
+ end
112
+
113
+ def remove_file_from_tmp_storage
114
+ if File.exists?(tmp_directory)
115
+ puts "Remove assset folder from tmp storage (tmp_directory)"
116
+ FileUtils.rm_r(tmp_directory)
117
+ end
118
+ end
119
+
120
+ def update_file_on_storage
121
+ if file
122
+ FileUtils.mkdir(tmp_directory) unless File.exists?(tmp_directory)
123
+ FileUtils.cp file.tempfile.path, tmp_location_on_disk
124
+ FileUtils.chmod(0755, tmp_location_on_disk)
125
+
126
+ move_tmp_file_to_actual_directory(file_name , false)
127
+ # new file has been upload, if its image generate thumbnails, if mp3 collect sound info.
128
+ asset_processing
129
+ # delete local tmp folder
130
+ remove_file_from_tmp_storage
131
+ end
132
+ end
133
+
134
+ def move_tmp_file_to_actual_directory(file_name , tmp_file_dirty=true)
135
+ if self.file_dirty == true || tmp_file_dirty == true
136
+ copy_file_to_s3(file_name)
137
+ self.file_dirty = false
138
+ end
139
+ end
140
+
141
+ #takes file from tmp folder and upload to s3 if s3 info is given in CMS settings
142
+ def copy_file_to_s3(file_name)
143
+ bucket = bucket_handle
144
+ unless bucket.blank?
145
+ local_file = self.tmp_directory + "/" + file_name
146
+ folder = self.asset_hash
147
+ date = Time.now+1.years
148
+ puts "Copying #{file_name} (#{local_file}) to #{S3::ClassMethods.s3_bucket_name}"
149
+ key = bucket.key(self.directory + "/" + file_name, true)
150
+ unless self.mime_type.blank?
151
+ key.put(File.open(local_file), 'public-read', {"Expires" => date.rfc2822, "content-type" => self.mime_type})
152
+ else
153
+ key.put(File.open(local_file), 'public-read', {"Expires" => date.rfc2822})
154
+ end
155
+ self.update_column(:copied_to_s3 , true)
156
+ puts "Copied"
157
+ end
158
+ end
159
+
160
+
161
+
162
+ # TODO
163
+ def remove_file_from_s3(file_name)
164
+ end
165
+
166
+ def remove_asset_folder_from_s3
167
+ bucket = bucket_handle
168
+ unless bucket.blank?
169
+ bucket.delete_folder(self.directory)
170
+ end
171
+ end
172
+
173
+ def download_asset_to_tmp_file
174
+ download_orginal_file_from_s3
175
+ end
176
+
177
+ def download_orginal_file_from_s3
178
+ FileUtils.mkdir(self.tmp_directory) unless File.exists?(self.tmp_directory)
179
+ bucket = bucket_handle
180
+ key = bucket.key(self.location_on_disk)
181
+ File.open(self.tmp_location_on_disk, "w") do |f|
182
+ f.write(key.get)
183
+ end
184
+ key = bucket.key(self.original_file_on_disk)
185
+ if key.exists?
186
+ File.open(self.tmp_original_file_on_disk, "w") do |f|
187
+ f.write(key.get)
188
+ end
189
+ end
190
+ end
191
+
192
+ end #InstanceMethods
193
+ end #S3
194
+ end #Storage
195
+ end #Library
196
+ end #Gluttonberg
@@ -0,0 +1,11 @@
1
+ library = Pathname(__FILE__).dirname.expand_path
2
+ require File.join(library, "storage", "s3")
3
+ require File.join(library, "storage", "filesystem")
4
+
5
+
6
+ module Gluttonberg
7
+ module Library
8
+ module Storage
9
+ end
10
+ end
11
+ end
@@ -1,44 +1,47 @@
1
1
  library = Pathname(__FILE__).dirname.expand_path
2
2
  require File.join(library, "library", "attachment_mixin")
3
3
  require File.join(library, "library", "quick_magick")
4
+ require File.join(library, "library", "storage")
5
+ require File.join(library, "library", "processor")
6
+ require File.join(library, "library", "config")
4
7
 
5
8
  module Gluttonberg
6
- # The library module encapsulates the few bits of functionality that lives
7
- # outside of the library models and controllers. It contains some
9
+ # The library module encapsulates the few bits of functionality that lives
10
+ # outside of the library models and controllers. It contains some
8
11
  # configuration details and is responsible for bootstrapping the various bits
9
12
  # of meta-data used when categorising uploaded assets.
10
13
 
11
14
  module Library
12
15
  UNCATEGORISED_CATEGORY = 'uncategorised'
13
-
16
+
14
17
  @@assets_root = nil
15
18
  @@test_assets_root = nil
16
-
19
+ @@tmp_assets_root = nil
20
+
17
21
  def self.bootstrap
18
22
  build_default_asset_types
19
23
  end
20
-
21
- # Is run when the slice is loaded. It makes sure that all the required
22
- # directories for storing assets are in the public dir, creating them if
23
- # they are missing. It also stores the various paths so they can be
24
- # retreived using the assets_dir method.
25
- def self.setup
26
- #logger.info("AssetLibrary is checking for asset folder")
27
- @@assets_root = "public/user_assets"
28
- @@test_assets_root = "public/test_assets"
29
- FileUtils.mkdir(root) unless File.exists?(root) || File.symlink?(root)
24
+
25
+ def self.set_asset_root(asset_root , tmp_asset_root , test_asset_root)
26
+ @@assets_root = asset_root
27
+ @@tmp_assets_root = tmp_asset_root
28
+ @@test_assets_root = test_asset_root
30
29
  end
31
-
30
+
32
31
  # Returns the path to the directory where assets are stored.
33
32
  def self.root
34
33
  if ::Rails.env == "test"
35
34
  @@test_assets_root
36
- else
35
+ else
37
36
  @@assets_root
38
- end
37
+ end
38
+ end
39
+
40
+ def self.tmp_root
41
+ @@tmp_assets_root
39
42
  end
40
43
 
41
- # This method is mainly for administrative purposes. It will rebuild the
44
+ # This method is mainly for administrative purposes. It will rebuild the
42
45
  # table of asset types, then recategorise each asset.
43
46
  def self.rebuild
44
47
  Asset.clear_all_asset_types
@@ -56,79 +59,79 @@ module Gluttonberg
56
59
  # Adds a the inbuilt asset types to the database.
57
60
  def self.build_default_asset_types
58
61
  begin
59
- # ensure that all the categories exist
60
- AssetCategory.build_defaults
61
- ensure_type('Unknown Image', 'image', AssetCategory.image_category)
62
- ensure_type('Unknown Video', 'video', AssetCategory.video_category)
63
- ensure_type('Unknown Audio', 'audio', AssetCategory.audio_category)
64
- ensure_type('Unknown File', 'multi-part model message unknown', AssetCategory.uncategorised_category)
65
-
66
- ensure_type('Jpeg Image', 'image/jpeg image/pjpeg', AssetCategory.image_category)
67
- ensure_type('Gif Image', 'image/gif', AssetCategory.image_category)
68
- ensure_type('Png Image', 'image/png', AssetCategory.image_category)
69
- ensure_type('Tiff Image', 'image/tiff', AssetCategory.image_category)
70
- ensure_type('Adobe Photoshop Image', 'image/vnd.adobe.photoshop', AssetCategory.image_category)
71
- ensure_type('Autocad Image', 'image/vnd.dwg', AssetCategory.image_category)
72
- ensure_type('Autocad Image', 'image/vnd.dxf', AssetCategory.image_category)
73
- ensure_type('Icon Image', 'image/vnd.microsoft.icon', AssetCategory.image_category)
74
- ensure_type('Bitmap Image', 'image/x-bmp image/bmp image/x-win-bmp', AssetCategory.image_category)
75
- ensure_type('Paintshop Pro Image', 'image/x-paintshoppro', AssetCategory.image_category)
76
- ensure_type('Mobile Image (plb,psb,pvb)', 'application/vnd.3gpp.pic-bw-large application/vnd.3gpp.pic-bw-small application/vnd.3gpp.pic-bw-var', AssetCategory.image_category)
77
-
78
- ensure_type('Moile Audio (3gpp,3gpp2)', 'audio/3gpp audio/3gpp2', AssetCategory.audio_category)
79
- ensure_type('Dolby Digital Audio (ac3)', 'audio/ac3', AssetCategory.audio_category)
80
- ensure_type('Mpeg Audio (mpga,mp2,mp3,mp4,mpa)', 'audio/mpeg audio/mpeg4-generic audio/mp4 audio/mpa-robust', AssetCategory.audio_category) # @mpga,mp2,mp3
81
- ensure_type('Aiff Audio (aif,aifc,aiff)', 'audio/x-aiff', AssetCategory.audio_category)
82
- ensure_type('Midi Audio (mid,midi,kar)', 'audio/x-midi', AssetCategory.audio_category)
83
- ensure_type('Real Audio (rm,ram,ra)', 'audio/x-pn-realaudio audio/x-realaudio', AssetCategory.audio_category)
84
- ensure_type('Wav Audio (wav)', 'audio/x-wav', AssetCategory.audio_category)
85
- ensure_type('Ogg Vorbis Audio (ogg)', 'application/ogg', AssetCategory.audio_category)
86
-
87
- ensure_type('Mobile Video', 'video/3gpp video/3gpp-tt video/3gpp2', AssetCategory.video_category) # @3gp,3gpp 'RFC3839,DRAFT:draft-gellens-mime-bucket
88
- ensure_type('Digital Video', 'video/DV', AssetCategory.video_category) # RFC3189
89
- ensure_type('Compressed Video', 'application/mpeg4-iod-xmt application/mpeg4-iod application/mpeg4-generic video/mp4 application/mp4 video/MPV video/mpeg4-generic video/mpeg video/MP2T video/H261 video/H263 video/H263-1998 video/H263-2000 video/H264 video/MP1S video/MP2P', AssetCategory.video_category) # RFC3555
90
- ensure_type('Jpeg Video', 'video/JPEG video/MJ2', AssetCategory.video_category) # RFC3555
91
- ensure_type('Quicktime Video', 'video/quicktime', AssetCategory.video_category)
92
- ensure_type('Uncompressed Video', 'video/raw', AssetCategory.video_category)
93
- ensure_type('Mpeg Playlist (mxu,m4u)', 'video/vnd.mpegurl', AssetCategory.video_category)
94
- ensure_type('Avi Video (avi)', 'video/x-msvideo', AssetCategory.video_category)
95
- ensure_type('Flash Video', 'video/x-flv', AssetCategory.video_category)
96
-
97
- ensure_type('M4v Video', 'video/x-m4v', AssetCategory.video_category)
98
-
99
- #document category
100
- ensure_type('Generic Document', 'application/x-csh application/x-dvi application/oda application/pgp-encrypted application/pgp-keys application/pgp-signature', AssetCategory.document_category)
101
- ensure_type('Calendar Document', 'text/calendar text/x-vcalendar', AssetCategory.document_category)
102
- ensure_type('Comma Seperated Values Document (csv)', 'text/csv text/comma-separated-values', AssetCategory.document_category)
103
- ensure_type('Tab Seperated Values Text Document', 'text/tab-separated-values', AssetCategory.document_category)
104
- ensure_type('Web Document', 'text/html', AssetCategory.document_category)
105
- ensure_type('Plain Text Document', 'text/plain', AssetCategory.document_category)
106
- ensure_type('Rich Text Document', 'text/richtext text/rtf', AssetCategory.document_category)
107
- ensure_type('Sgml Document', 'text/sgml', AssetCategory.document_category)
108
- ensure_type('Wap Document', 'text/vnd.wap.wml text/vnd.wap.wmlscript', AssetCategory.document_category)
109
- ensure_type('XML Document', 'text/xml text/xml-external-parsed-entity', AssetCategory.document_category)
110
- ensure_type('V-Card Document (vcf)', 'text/x-vcard', AssetCategory.document_category)
111
- ensure_type('Apple Macintosh Document (hqx)', 'application/mac-binhex40', AssetCategory.document_category)
112
- ensure_type('Adobe Acrobat Document (pdf)', 'application/pdf', AssetCategory.document_category)
113
- ensure_type('Microsoft Word Document (doc,dot,docx)', 'application/msword application/word', AssetCategory.document_category)
114
- ensure_type('Microsoft Powerpoint Document (ppt,pps,pot,pptx)', 'application/vnd.ms-powerpoint application/powerpoint', AssetCategory.document_category)
115
- ensure_type('Microsoft Excel Document (xls,xlt,xlsx)', 'application/vnd.ms-excel application/excel', AssetCategory.document_category)
116
- ensure_type('Microsoft Works Document', 'application/vnd.ms-works', AssetCategory.document_category)
117
- ensure_type('Microsoft Project Document (mpp)', 'application/vnd.ms-project', AssetCategory.document_category)
118
- ensure_type('Microsoft Visio Document (vsd,vst,vsw,vss)', 'application/vnd.visio', AssetCategory.document_category)
119
- ensure_type('HTML Help Document (chm)', 'application/x-chm', AssetCategory.document_category)
120
-
121
-
62
+ # ensure that all the categories exist
63
+ AssetCategory.build_defaults
64
+ ensure_type('Unknown Image', 'image', AssetCategory.image_category)
65
+ ensure_type('Unknown Video', 'video', AssetCategory.video_category)
66
+ ensure_type('Unknown Audio', 'audio', AssetCategory.audio_category)
67
+ ensure_type('Unknown File', 'multi-part model message unknown', AssetCategory.uncategorised_category)
68
+
69
+ ensure_type('Jpeg Image', 'image/jpeg image/pjpeg', AssetCategory.image_category)
70
+ ensure_type('Gif Image', 'image/gif', AssetCategory.image_category)
71
+ ensure_type('Png Image', 'image/png', AssetCategory.image_category)
72
+ ensure_type('Tiff Image', 'image/tiff', AssetCategory.image_category)
73
+ ensure_type('Adobe Photoshop Image', 'image/vnd.adobe.photoshop', AssetCategory.image_category)
74
+ ensure_type('Autocad Image', 'image/vnd.dwg', AssetCategory.image_category)
75
+ ensure_type('Autocad Image', 'image/vnd.dxf', AssetCategory.image_category)
76
+ ensure_type('Icon Image', 'image/vnd.microsoft.icon', AssetCategory.image_category)
77
+ ensure_type('Bitmap Image', 'image/x-bmp image/bmp image/x-win-bmp', AssetCategory.image_category)
78
+ ensure_type('Paintshop Pro Image', 'image/x-paintshoppro', AssetCategory.image_category)
79
+ ensure_type('Mobile Image (plb,psb,pvb)', 'application/vnd.3gpp.pic-bw-large application/vnd.3gpp.pic-bw-small application/vnd.3gpp.pic-bw-var', AssetCategory.image_category)
80
+
81
+ ensure_type('Moile Audio (3gpp,3gpp2)', 'audio/3gpp audio/3gpp2', AssetCategory.audio_category)
82
+ ensure_type('Dolby Digital Audio (ac3)', 'audio/ac3', AssetCategory.audio_category)
83
+ ensure_type('Mpeg Audio (mpga,mp2,mp3,mp4,mpa)', 'audio/mpeg audio/mpeg4-generic audio/mp4 audio/mpa-robust', AssetCategory.audio_category) # @mpga,mp2,mp3
84
+ ensure_type('Aiff Audio (aif,aifc,aiff)', 'audio/x-aiff', AssetCategory.audio_category)
85
+ ensure_type('Midi Audio (mid,midi,kar)', 'audio/x-midi', AssetCategory.audio_category)
86
+ ensure_type('Real Audio (rm,ram,ra)', 'audio/x-pn-realaudio audio/x-realaudio', AssetCategory.audio_category)
87
+ ensure_type('Wav Audio (wav)', 'audio/x-wav', AssetCategory.audio_category)
88
+ ensure_type('Ogg Vorbis Audio (ogg)', 'application/ogg', AssetCategory.audio_category)
89
+
90
+ ensure_type('Mobile Video', 'video/3gpp video/3gpp-tt video/3gpp2', AssetCategory.video_category) # @3gp,3gpp 'RFC3839,DRAFT:draft-gellens-mime-bucket
91
+ ensure_type('Digital Video', 'video/DV', AssetCategory.video_category) # RFC3189
92
+ ensure_type('Compressed Video', 'application/mpeg4-iod-xmt application/mpeg4-iod application/mpeg4-generic video/mp4 application/mp4 video/MPV video/mpeg4-generic video/mpeg video/MP2T video/H261 video/H263 video/H263-1998 video/H263-2000 video/H264 video/MP1S video/MP2P', AssetCategory.video_category) # RFC3555
93
+ ensure_type('Jpeg Video', 'video/JPEG video/MJ2', AssetCategory.video_category) # RFC3555
94
+ ensure_type('Quicktime Video', 'video/quicktime', AssetCategory.video_category)
95
+ ensure_type('Uncompressed Video', 'video/raw', AssetCategory.video_category)
96
+ ensure_type('Mpeg Playlist (mxu,m4u)', 'video/vnd.mpegurl', AssetCategory.video_category)
97
+ ensure_type('Avi Video (avi)', 'video/x-msvideo', AssetCategory.video_category)
98
+ ensure_type('Flash Video', 'video/x-flv', AssetCategory.video_category)
99
+
100
+ ensure_type('M4v Video', 'video/x-m4v', AssetCategory.video_category)
101
+
102
+ #document category
103
+ ensure_type('Generic Document', 'application/x-csh application/x-dvi application/oda application/pgp-encrypted application/pgp-keys application/pgp-signature', AssetCategory.document_category)
104
+ ensure_type('Calendar Document', 'text/calendar text/x-vcalendar', AssetCategory.document_category)
105
+ ensure_type('Comma Seperated Values Document (csv)', 'text/csv text/comma-separated-values', AssetCategory.document_category)
106
+ ensure_type('Tab Seperated Values Text Document', 'text/tab-separated-values', AssetCategory.document_category)
107
+ ensure_type('Web Document', 'text/html', AssetCategory.document_category)
108
+ ensure_type('Plain Text Document', 'text/plain', AssetCategory.document_category)
109
+ ensure_type('Rich Text Document', 'text/richtext text/rtf', AssetCategory.document_category)
110
+ ensure_type('Sgml Document', 'text/sgml', AssetCategory.document_category)
111
+ ensure_type('Wap Document', 'text/vnd.wap.wml text/vnd.wap.wmlscript', AssetCategory.document_category)
112
+ ensure_type('XML Document', 'text/xml text/xml-external-parsed-entity', AssetCategory.document_category)
113
+ ensure_type('V-Card Document (vcf)', 'text/x-vcard', AssetCategory.document_category)
114
+ ensure_type('Apple Macintosh Document (hqx)', 'application/mac-binhex40', AssetCategory.document_category)
115
+ ensure_type('Adobe Acrobat Document (pdf)', 'application/pdf', AssetCategory.document_category)
116
+ ensure_type('Microsoft Word Document (doc,dot,docx)', 'application/msword application/word', AssetCategory.document_category)
117
+ ensure_type('Microsoft Powerpoint Document (ppt,pps,pot,pptx)', 'application/vnd.ms-powerpoint application/powerpoint', AssetCategory.document_category)
118
+ ensure_type('Microsoft Excel Document (xls,xlt,xlsx)', 'application/vnd.ms-excel application/excel', AssetCategory.document_category)
119
+ ensure_type('Microsoft Works Document', 'application/vnd.ms-works', AssetCategory.document_category)
120
+ ensure_type('Microsoft Project Document (mpp)', 'application/vnd.ms-project', AssetCategory.document_category)
121
+ ensure_type('Microsoft Visio Document (vsd,vst,vsw,vss)', 'application/vnd.visio', AssetCategory.document_category)
122
+ ensure_type('HTML Help Document (chm)', 'application/x-chm', AssetCategory.document_category)
123
+
124
+
122
125
  rescue => e
123
126
  puts "asset library init fails."
124
127
  puts e
125
- end
128
+ end
126
129
 
127
130
  end
128
131
 
129
132
  private
130
-
131
- # Makes sure the specified type exists in the DB, if it doesn’t it creates
133
+
134
+ # Makes sure the specified type exists in the DB, if it doesn’t it creates
132
135
  # a new record.
133
136
  def self.ensure_type(name, mime_type, category)
134
137
  asset_type = AssetType.first( :conditions => "name = '#{name}'" )
@@ -145,7 +148,5 @@ module Gluttonberg
145
148
  asset_type.save
146
149
  end
147
150
 
148
-
149
-
150
151
  end # Library
151
152
  end # Gluttonberg
@@ -2,18 +2,18 @@
2
2
  module Gluttonberg
3
3
  module RecordHistory
4
4
  def self.setup
5
- ::ActionController::Base.send :include, Gluttonberg::RecordHistory::ActionController
5
+ ::ActionController::Base.send :include, Gluttonberg::RecordHistory::ActionController
6
6
  end
7
7
 
8
8
  module ActionController
9
9
  def self.included(base)
10
10
  base.extend(ClassMethods)
11
11
  end
12
-
13
-
12
+
13
+
14
14
  module ClassMethods
15
15
  def record_history(object_name, title_field_name="", options = {})
16
- class << self;
16
+ class << self;
17
17
  attr_accessor :object_name, :title_field_name;
18
18
  end
19
19
  self.object_name = object_name
@@ -23,7 +23,7 @@ module Gluttonberg
23
23
  after_filter :log_update , :only => [:update]
24
24
  after_filter :log_destroy, :only => [:destroy]
25
25
  end
26
-
26
+
27
27
  end # class methods
28
28
 
29
29
  module ControllerHelperClassMethods
@@ -32,22 +32,22 @@ module Gluttonberg
32
32
  if object.new_record?
33
33
  else
34
34
  Gluttonberg::Feed.log(current_user, object ,object_title , "created")
35
- end
36
- end
35
+ end
36
+ end
37
37
  end
38
38
 
39
39
  def log_update
40
40
  unless object.blank?
41
41
  if object.errors.blank?
42
42
  Gluttonberg::Feed.log(current_user, object ,object_title , "updated")
43
- end
44
- end
43
+ end
44
+ end
45
45
  end
46
46
 
47
47
  def log_destroy
48
48
  if object && object.destroyed?()
49
49
  Gluttonberg::Feed.log(current_user, object ,object_title , "deleted")
50
- end
50
+ end
51
51
  end
52
52
 
53
53
  def object
@@ -73,21 +73,20 @@ module Gluttonberg
73
73
  field_name = :id
74
74
  end
75
75
  else
76
- field_name = self.class.title_field_name
76
+ field_name = self.class.title_field_name
77
77
  end
78
- puts "==================== field_name #{field_name}"
79
78
  unless field_name.blank?
80
79
  object.send(field_name)
81
80
  end
82
- end
83
- end
81
+ end
82
+ end
84
83
 
85
84
  end #ControllerHelperClassMethods
86
85
 
87
86
 
88
87
  end
89
88
 
90
- end #RecordHistory
89
+ end #RecordHistory
91
90
  end #Gluttonberg
92
91
 
93
92
 
@@ -12,9 +12,14 @@ namespace :gluttonberg do
12
12
  assets = category.assets #Asset.all
13
13
  assets.each do |asset|
14
14
  p "thumb-nailing '#{asset.file_name}' "
15
- asset.generate_image_thumb
16
- asset.generate_proper_resolution
17
- asset.save
15
+ if !File.exist?(asset.tmp_location_on_disk) && !File.exist?(asset.tmp_original_file_on_disk)
16
+ asset.download_asset_to_tmp_file
17
+ end
18
+ # asset.generate_image_thumb
19
+ # asset.generate_proper_resolution
20
+ # asset.save
21
+ Gluttonberg::Library::Processor::Image.process(asset)
22
+ asset.remove_file_from_tmp_storage
18
23
  end
19
24
  end
20
25
  end
@@ -44,5 +49,22 @@ namespace :gluttonberg do
44
49
  Gluttonberg::Asset.update_assets_synopsis_from_csv
45
50
  end
46
51
 
52
+ desc "Migrate assets from public/user_assets folder to S3"
53
+ task :migrate_assets_to_s3 => :environment do
54
+ Dir.entries("public/user_assets").each do |asset_folder|
55
+ if !asset_folder.include?(".DS_Store") && File.directory?("public/user_assets/" + asset_folder)
56
+ Dir.entries("public/user_assets/"+asset_folder).each do |asset_file|
57
+ if !asset_file.include?(".DS_Store") && !File.directory?("public/user_assets/" + asset_folder+"/"+asset_file)
58
+ begin
59
+ Gluttonberg::Library::Storage::S3::ClassMethods.migrate_file_to_s3(asset_folder , asset_file)
60
+ rescue => e
61
+ puts "Error: #{e.message}"
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+
47
69
  end
48
70
  end
@@ -1,3 +1,3 @@
1
1
  module Gluttonberg
2
- VERSION = "2.5.5"
2
+ VERSION = "2.5.6"
3
3
  end