diff --git a/.gitignore b/.gitignore index 201e4a2a7c..c8ded7448b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ public/system/* +public/themes/* log/*.log tmp/**/* .DS_Store @@ -13,4 +14,5 @@ db/*.sqlite3 *.autobackupbyrefinery.* refinerycms*.gem public/javascripts/cache -public/stylesheets/cache \ No newline at end of file +public/stylesheets/cache +config/database.yml.example diff --git a/public/images/refinery/icons/star-dull.png b/public/images/refinery/icons/star-dull.png new file mode 100644 index 0000000000..4fc67b96cb Binary files /dev/null and b/public/images/refinery/icons/star-dull.png differ diff --git a/public/images/refinery/icons/star.png b/public/images/refinery/icons/star.png new file mode 100755 index 0000000000..b88c857895 Binary files /dev/null and b/public/images/refinery/icons/star.png differ diff --git a/vendor/plugins/resources/app/models/resource.rb b/vendor/plugins/resources/app/models/resource.rb index 47cd53cbe1..a5b1b8eed0 100644 --- a/vendor/plugins/resources/app/models/resource.rb +++ b/vendor/plugins/resources/app/models/resource.rb @@ -1,8 +1,8 @@ class Resource < ActiveRecord::Base has_attachment :storage => (USE_S3_BACKEND ? :s3 : :file_system), - :size => 0.kilobytes..50.megabytes, - :path_prefix => (USE_S3_BACKEND ? nil : 'public/system/resources') + :size => 0.kilobytes..50.megabytes, + :path_prefix => (USE_S3_BACKEND ? nil : 'public/system/resources') acts_as_indexed :fields => [:title, :type_of_content], :index_file => [RAILS_ROOT,"tmp","index"] diff --git a/vendor/plugins/resources/config/routes.rb b/vendor/plugins/resources/config/routes.rb index 34d6db910c..d6a5a63671 100644 --- a/vendor/plugins/resources/config/routes.rb +++ b/vendor/plugins/resources/config/routes.rb @@ -1,7 +1,9 @@ ActionController::Routing::Routes.draw do |map| + map.resources :resources map.namespace(:admin) do |admin| admin.resources :resources, :collection => {:insert => :get} end -end + +end \ No newline at end of file diff --git a/vendor/plugins/themes/app/controllers/admin/themes_controller.rb b/vendor/plugins/themes/app/controllers/admin/themes_controller.rb index f0b6ba15ba..5b40b15028 100644 --- a/vendor/plugins/themes/app/controllers/admin/themes_controller.rb +++ b/vendor/plugins/themes/app/controllers/admin/themes_controller.rb @@ -2,7 +2,24 @@ class Admin::ThemesController < Admin::BaseController crudify :theme, :order => "updated_at DESC" - # allows the user to both select a theme on the index page - # and upload a zip file (new/create/update) which saves the unzipped version of it + before_filter :find_theme, :only => [:update, :destroy, :edit, :preview_image, :activate] + + # accessor method for theme preview image + def preview_image + if File.exists? @theme.preview_image + send_file(@theme.preview_image, :type => 'image/png', + :disposition => 'inline', + :stream => true) + else + return error_404 + end + end + + def activate + RefinerySetting[:theme] = @theme.title + + flash[:notice] = "'#{@theme.title}' applied to live site." + redirect_to admin_themes_url + end end \ No newline at end of file diff --git a/vendor/plugins/themes/app/models/theme.rb b/vendor/plugins/themes/app/models/theme.rb index efbfbdd012..dc44bd2fca 100644 --- a/vendor/plugins/themes/app/models/theme.rb +++ b/vendor/plugins/themes/app/models/theme.rb @@ -5,20 +5,25 @@ class Theme < ActiveRecord::Base before_save :read_theme - has_attachment :storage => :file_system, - :size => 0.kilobytes..15.megabytes, - :content_type => 'application/zip' - - # Once a zip is uploaded it unzips it into the themes directory + has_attachment :storage => (USE_S3_BACKEND ? :s3 : :file_system), + :size => 0.kilobytes..15.megabytes, + :path_prefix => (USE_S3_BACKEND ? nil : 'public/system/themes'), + :content_type => 'application/zip' + + # Once a zip is uploaded it unzips it into the themes directory if writable def after_attachment_saved - # make the folder for the them - FileUtils.mkdir(self.theme_path) unless File.exists?(self.theme_path) + if theme_directory_is_writable? + # make the folder for the them + FileUtils.mkdir(self.theme_path) unless File.exists? self.theme_path - # extracts the contents of the zip file into the theme directory - Zip::ZipFile.foreach(self.filename) do |entry| - FileUtils.mkdir_p(File.dirname("#{theme_path}/#{entry}")) - entry.extract("#{theme_path}/#{entry}") { true } - end + # extracts the contents of the zip file into the theme directory + Zip::ZipFile.foreach(self.filename) do |entry| + FileUtils.mkdir_p(File.dirname("#{theme_path}/#{entry}")) + entry.extract("#{theme_path}/#{entry}") { true } + end + else + raise "Theme directory not writable" + end end def theme_folder_title @@ -36,13 +41,17 @@ def preview_image def read_theme self.title = File.basename(self.filename).split(".").first.titleize - if File.exists?(File.join(theme_path, "LICENSE")) + if File.exists? File.join(theme_path, "LICENSE") self.license = File.open(File.join(theme_path, "LICENSE")).read end - if File.exists?(File.join(theme_path, "README")) + if File.exists? File.join(theme_path, "README") self.description = File.open(File.join(theme_path, "README")).read end end + + def theme_directory_is_writable? + File.writable? File.join(RAILS_ROOT, "themes") # Heroku users will receive false here + end end \ No newline at end of file diff --git a/vendor/plugins/themes/app/views/admin/themes/_theme.html.erb b/vendor/plugins/themes/app/views/admin/themes/_theme.html.erb index b3bbf79fb6..e024c778d0 100644 --- a/vendor/plugins/themes/app/views/admin/themes/_theme.html.erb +++ b/vendor/plugins/themes/app/views/admin/themes/_theme.html.erb @@ -1,18 +1,24 @@ -
  • - - - <%= link_to refinery_icon_tag('page_white_put.png'), theme.public_filename, - :title => "Download this theme (#{number_to_human_size(theme.size)})" %> - <%= link_to refinery_icon_tag('application_edit.png'), edit_admin_theme_url(theme), - :title => "Edit this theme" %> - <%= link_to refinery_icon_tag('delete.png'), admin_theme_path(theme), - :confirm => "Are you sure you want to delete '#{theme.title}'?", - :class => "cancel", :method => :delete, - :title => "Remove this theme forever" %> - - <%=h theme.title %> - - - <%= number_to_human_size(theme.size) %> - <%= theme.theme_path -%> - - +
  • + +

    + <%=h theme.title %> +

    + <%= image_tag(preview_image_admin_theme_url(theme), :width => 135, :height => 135) %> +

    + + + <%= link_to refinery_icon_tag('star.png'), activate_admin_theme_url(theme) %> + <%= link_to refinery_icon_tag('page_white_put.png'), theme.public_filename, + :title => "Download this theme (#{number_to_human_size(theme.size)})" %> + <% if Theme.first.theme_directory_is_writable? %> + <%= link_to refinery_icon_tag('application_edit.png'), edit_admin_theme_url(theme), + :title => "Edit this theme" %> + <% end %> + <%= link_to refinery_icon_tag('delete.png'), admin_theme_path(theme), + :confirm => "Are you sure you want to delete '#{theme.title}'?", + :class => "cancel", :method => :delete, + :title => "Remove this theme forever" %> + +

    +
  • diff --git a/vendor/plugins/themes/app/views/admin/themes/index.html.erb b/vendor/plugins/themes/app/views/admin/themes/index.html.erb index 70576465d0..11c3e4fd31 100644 --- a/vendor/plugins/themes/app/views/admin/themes/index.html.erb +++ b/vendor/plugins/themes/app/views/admin/themes/index.html.erb @@ -3,23 +3,25 @@
  • <%= render :partial => "/shared/admin/search", :locals => {:url => admin_themes_url} %>
  • -
  • - <%= link_to "Upload New Theme", new_admin_theme_url, :class => "add_icon" %> -
  • + <% if Theme.first.theme_directory_is_writable? %> +
  • + <%= link_to "Upload New Theme", new_admin_theme_url, :class => "add_icon" %> +
  • + <% end %>
    <% if searching? %>

    Search Results for "<%= params[:search] %>"

    <% if @themes.size > 0 %> - <%= render :partial => "resource", :collection => @themes %> + <%= render :partial => "theme", :collection => @themes %> <% else %>

    Sorry, no results found.

    <% end %> <% else %> <% if @themes.size > 0 -%> <%= will_paginate @themes, :previous_label => '«', :next_label => '»' %> -