diff --git a/.gitignore b/.gitignore index 0b238624a6..d69ab8bde5 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,6 @@ public/images/system/* nbproject index/**/* db/*.sqlite3 -*.tmproj \ No newline at end of file +*.tmproj +*.autobackupbyrefinery.* +refinerycms*.gem \ No newline at end of file diff --git a/bin/refinery-update-core b/bin/refinery-update-core index b30840ba1b..912c2760c0 100644 --- a/bin/refinery-update-core +++ b/bin/refinery-update-core @@ -20,10 +20,38 @@ unless RAILS_ROOT.nil? or RAILS_ROOT.length == 0 # copy any rake tasks from plugins to the main lib directory so they can be run. FileUtils::cp Dir[File.join(REFINERY_ROOT, %w(** tasks *.rake))], File.join(RAILS_ROOT, %w(lib tasks)) + # read in the config files + app_config = File.open(File.join(RAILS_ROOT, %w(config environment.rb)), "r").read + environment_updated = false + + # backup app's environment.rb + unless (app_refinery_gems_section = app_config.scan(/(#===REFINERY REQUIRED GEMS===)([^#]*)(#===REFINERY END OF REQUIRED GEMS===)/).join("")).length == 0 + # read in the config file in the gem + refinery_config = File.open(File.join(REFINERY_ROOT, %w(config environment.rb)), "r").read + FileUtils.cp File.join(RAILS_ROOT, %w(config environment.rb)), File.join(RAILS_ROOT, %w(config environment.autobackupbyrefinery.rb)) + + # write the new content into the file. + File.open(File.join(RAILS_ROOT, %w(config environment.rb)), "w").puts(app_config.gsub!( + app_refinery_gems_section, + refinery_config.scan(/(#===REFINERY REQUIRED GEMS===)([^#]*)(#===REFINERY END OF REQUIRED GEMS===)/).join("") + )) + + environment_updated = true + end + unless ARGV.include?("--from-refinery-installer") puts "---------" puts "Copied new Refinery core assets." + if environment_updated + puts "I've made a backup of your current config/environment.rb file as it has been updated with the latest Refinery RubyGem requirements." + puts "The backup is located at config/environment.autobackupbyrefinery.rb incase you need it." + end + puts "" + puts "=== ACTION REQUIRED ===" puts "Please run rake db:migrate to ensure your database is at the correct version." + puts "Please also run rake gems:install to ensure you have the currently specified gems." if environment_updated + + puts "" end else unless ARGV.include?("--from-refinery-installer") diff --git a/config/environment.rb b/config/environment.rb index 4636ce9292..b0a71955b5 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -7,7 +7,7 @@ # Specifies gem version of Rails to use when vendor/rails is not present RAILS_GEM_VERSION = '2.3.4' unless defined? RAILS_GEM_VERSION # Freeze to a specific version of refinerycms when running as a gem -# REFINERY_GEM_VERSION = 0.9.5.1 unless defined? REFINERY_GEM_VERSION +# REFINERY_GEM_VERSION = 0.9.5.10 unless defined? REFINERY_GEM_VERSION # Bootstrap the Rails environment, frameworks, and default configuration require File.join(File.dirname(__FILE__), 'boot') @@ -59,7 +59,10 @@ # Make Active Record use UTC-base instead of local time # config.active_record.default_timezone = :utc # - + + # Please add your gems above the Refinery required gems here: + + #===REFINERY REQUIRED GEMS=== config.gem "rake", :version => ">= 0.8.3", :lib => "rake" config.gem "friendly_id", :version => ">= 2.2.2", :lib => "friendly_id" config.gem "will_paginate", :version => ">= 2.3.11", :lib => "will_paginate", :source => "http://gemcutter.org" @@ -67,4 +70,6 @@ config.gem "aasm", :version => ">= 2.1.3", :lib => "aasm", :source => "http://gemcutter.org" config.gem "unicode", :version => ">= 0.1", :lib => "unicode" config.gem "slim_scrooge", :source => "http://gemcutter.org" + config.gem "hpricot", :version => "0.8.1", :lib => "hpricot", :source => "http://gemcutter.org" + #===REFINERY END OF REQUIRED GEMS=== end \ No newline at end of file diff --git a/public/javascripts/wymeditor/jquery.refinery.wymeditor.js b/public/javascripts/wymeditor/jquery.refinery.wymeditor.js index dd0a8b9e44..3c37ed77d4 100755 --- a/public/javascripts/wymeditor/jquery.refinery.wymeditor.js +++ b/public/javascripts/wymeditor/jquery.refinery.wymeditor.js @@ -1222,6 +1222,20 @@ WYMeditor.editor.prototype.dialog = function( dialogType ) { } selected = this.selected(); + if (dialogType == WYMeditor.DIALOG_LINK && jQuery.browser.mozilla) { + selection = this._iframe.contentWindow.getSelection(); + matches = selected.innerHTML.match(new RegExp(selection.anchorNode.textContent + "(.*)" + selection.focusNode.textContent)); + if (matches != null && matches.length > 0 && (possible_anchor_tag = matches.last()) != null) { + if ((href = possible_anchor_tag.match(/href="([^"]*)"/).last()) != null) { + possible_anchors = this._iframe.document().getElementsByTagName('a'); + for (i=0;i "created_at DESC", :conditions => "parent_id is NULL", :sortable => false before_filter :change_list_mode_if_specified + def index + if searching? + @images = Image.paginate_search params[:search], + :page => params[:page], + :order => "created_at DESC", + :conditions => "parent_id IS NULL" + else + @images = Image.paginate :page => params[:page], + :order => "created_at DESC", + :conditions => "parent_id IS NULL" + end + + if RefinerySetting.find_or_set(:group_images_by_date_uploaded, false) + @grouped_images = [] + @images.each do |image| + key = image.created_at.strftime("%Y-%m-%d") + image_group = @grouped_images.collect{|images| images.last if images.first == key }.flatten.compact << image + (@grouped_images.delete_if {|i| i.first == key}) << [key, image_group] + end + end + end + def new @image = Image.new @url_override = admin_images_url(:dialog => from_dialog?) diff --git a/vendor/plugins/images/app/views/admin/images/_list_view.html.erb b/vendor/plugins/images/app/views/admin/images/_list_view.html.erb index ec73e54255..15f26164a3 100644 --- a/vendor/plugins/images/app/views/admin/images/_list_view.html.erb +++ b/vendor/plugins/images/app/views/admin/images/_list_view.html.erb @@ -1,21 +1,12 @@ - \ No newline at end of file +<% if RefinerySetting.find_or_set(:group_images_by_date_uploaded, false) %> + <% @grouped_images.each do |container| %> +

<%= (image_group = container.last).first.created_at.strftime("%A, %d %B %Y") %>

+ + <% end %> +<% else %> + +<% end %> \ No newline at end of file diff --git a/vendor/plugins/images/app/views/admin/images/_list_view_image.html.erb b/vendor/plugins/images/app/views/admin/images/_list_view_image.html.erb new file mode 100644 index 0000000000..041f71b3a6 --- /dev/null +++ b/vendor/plugins/images/app/views/admin/images/_list_view_image.html.erb @@ -0,0 +1,17 @@ +<% if list_view_image.parent_id.nil? %> +
  • + + + <%= link_to refinery_icon_tag('eye.png'), list_view_image.public_filename, + :target => "_blank", :title => "#{image_fu list_view_image, :preview}" %> + <%= link_to refinery_icon_tag('application_edit.png'), edit_admin_image_path(list_view_image), + :title => 'Edit this image' %> + <%= link_to refinery_icon_tag('delete.png'), admin_image_path(list_view_image), + :confirm => "Are you sure you want to delete #{list_view_image.title}?", + :class => "cancel", :method => :delete, + :title => "Remove this image forever" %> + + <%= list_view_image.title %>   + +
  • +<% end %> \ No newline at end of file diff --git a/vendor/plugins/refinery/lib/refinery/application_helper.rb b/vendor/plugins/refinery/lib/refinery/application_helper.rb index ebc3c0752b..486c01b096 100644 --- a/vendor/plugins/refinery/lib/refinery/application_helper.rb +++ b/vendor/plugins/refinery/lib/refinery/application_helper.rb @@ -1,5 +1,6 @@ # Methods added to this helper will be available to all templates in the application. module Refinery::ApplicationHelper + include Refinery::HtmlTruncationHelper def add_meta_tags content_for :head, "" unless @page.meta_keywords.blank? @@ -80,41 +81,6 @@ def image_fu(image, thumbnail = nil , options={}) def refinery_icon_tag(filename, options = {}) image_tag "refinery/icons/#{filename}", {:width => 16, :height => 16}.merge!(options) end - - def truncate(text, *args) - truncated = super - unless truncated === text - options = args.extract_options! - if options[:preserve_html_tags] - truncated = truncated[0, truncated.length - options[:omission].length] - # scan for all HTML tags then the last tag - unless (tag_matches = truncated.scan(/<[^<>]{1,}>?/)).empty? or - (last_tag = tag_matches.last.gsub(/<|\/|\>/, "").split(" ").first).nil? or - last_tag.downcase == "p" or (tag_matches.last.split("<").last.first == "/") - - # scan until we find the exact tag we're looking for. - full_tag = text.scan(Regexp.new("(#{tag_matches.last})([^<]*)(<\/#{last_tag}>)"))[0..2].join("") # 0..2 because it'll be found as 3 tags together. - truncated.gsub!(tag_matches.last, full_tag) - - end - - truncated = truncated[0, truncated.length-1] if truncated.last == "<" # If a tag almost started, get rid of it. - - # add back on the omission - truncated = "#{truncated}#{options[:omission]}" - - # close the paragraph unless it closes already. - start_index = truncated.length-"

    ".length-options[:omission].length - length = (end_index = options[:omission].length + "

    ".length) - unless truncated[start_index, length].downcase == "

    " - truncated = "#{truncated}

    " - end - - end - end - - truncated - end # replace all system images with a thumbnail version of them (handy for all images inside a page part) def content_fu(content, thumbnail) diff --git a/vendor/plugins/refinery/lib/refinery/html_truncation_helper.rb b/vendor/plugins/refinery/lib/refinery/html_truncation_helper.rb new file mode 100644 index 0000000000..ede1a720c6 --- /dev/null +++ b/vendor/plugins/refinery/lib/refinery/html_truncation_helper.rb @@ -0,0 +1,114 @@ +# By Henrik Nyh 2008-01-30. +# Free to modify and redistribute with credit. + +# modified by Dave Nolan 2008-02-06 +# Ellipsis appended to text of last HTML node +# Ellipsis inserted after final word break + +# modified by Mark Dickson 2008-12-18 +# Option to truncate to last full word +# Option to include a 'more' link +# Check for nil last child + +# modified by Ken-ichi Ueda 2009-09-02 +# Rails 2.3 compatability (chars -> mb_chars), via Henrik +# Hpricot 0.8 compatability (avoid dup on Hpricot::Elem) + +# modified by Philip Arndt 2009-11-18 +# renamed function to truncate and activated html truncation when :preserve_html_tags is supplied and true. +# modified namespace to Refinery namespace and renamed module. + +require "rubygems" +require "hpricot" + +module Refinery::HtmlTruncationHelper + + # Like the Rails _truncate_ helper but doesn't break HTML tags, entities, and optionally. words. + def truncate(text, *args) + return if text.nil? + options = args.extract_options! + unless (options[:preserve_html_tags] == true) + return super + else + max_length = options[:length] || 30 + omission = options[:omission] || "..." + # use :link => link_to('more', post_path), or something to that effect + + doc = Hpricot(text.to_s) + omission_length = Hpricot(omission).inner_text.mb_chars.length + content_length = doc.inner_text.mb_chars.length + actual_length = max_length - omission_length + + if content_length > max_length + truncated_doc = doc.truncate(actual_length) + + if (options[:preserve_full_words] || false) + word_length = actual_length - (truncated_doc.inner_html.mb_chars.length - truncated_doc.inner_html.rindex(' ')) + truncated_doc = doc.truncate(word_length) + end + + last_child = truncated_doc.children.last + if last_child.inner_html.nil? + truncated_doc.inner_html + omission + options[:link] if options[:link] + else + last_child.inner_html = last_child.inner_html.gsub(/\W.[^\s]+$/, "") + omission + last_child.inner_html += options[:link] if options[:link] + truncated_doc + end + else + if options[:link] + last_child = doc.children.last + if last_child.inner_html.nil? + doc.inner_html + options[:link] + else + last_child.inner_html = last_child.inner_html.gsub(/\W.[^\s]+$/, "") + options[:link] + doc + end + else + text.to_s + end + end + end + end + + +end + +module HpricotTruncator + module NodeWithChildren + def truncate(max_length) + return self if inner_text.mb_chars.length <= max_length + truncated_node = if self.is_a?(Hpricot::Doc) + self.dup + else + self.class.send(:new, self.name, self.attributes) + end + truncated_node.children = [] + each_child do |node| + remaining_length = max_length - truncated_node.inner_text.mb_chars.length + break if remaining_length <= 0 + truncated_node.children << node.truncate(remaining_length) + end + truncated_node + end + end + + module TextNode + def truncate(max_length) + # We're using String#scan because Hpricot doesn't distinguish entities. + Hpricot::Text.new(content.scan(/&#?[^\W_]+;|./).first(max_length).join) + end + end + + module IgnoredTag + def truncate(max_length) + self + end + end +end + +Hpricot::Doc.send(:include, HpricotTruncator::NodeWithChildren) +Hpricot::Elem.send(:include, HpricotTruncator::NodeWithChildren) +Hpricot::Text.send(:include, HpricotTruncator::TextNode) +Hpricot::BogusETag.send(:include, HpricotTruncator::IgnoredTag) +Hpricot::Comment.send(:include, HpricotTruncator::IgnoredTag) \ No newline at end of file diff --git a/vendor/plugins/resources/app/controllers/admin/resources_controller.rb b/vendor/plugins/resources/app/controllers/admin/resources_controller.rb index 9790e59623..e225cd3634 100644 --- a/vendor/plugins/resources/app/controllers/admin/resources_controller.rb +++ b/vendor/plugins/resources/app/controllers/admin/resources_controller.rb @@ -29,6 +29,26 @@ def create end end + def index + if searching? + @resources = Resource.paginate_search params[:search], + :page => params[:page], + :order => "created_at DESC" + else + @resources = Resource.paginate :page => params[:page], + :order => "created_at DESC" + end + + if RefinerySetting.find_or_set(:group_resources_by_date_uploaded, false) + @grouped_resources = [] + @resources.each do |resource| + key = resource.created_at.strftime("%Y-%m-%d") + resource_group = @grouped_resources.collect{|resources| resources.last if resources.first == key }.flatten.compact << resource + (@grouped_resources.delete_if {|i| i.first == key}) << [key, resource_group] + end + end + end + def insert self.new if @resource.nil? @dialog = from_dialog? diff --git a/vendor/plugins/resources/app/views/admin/resources/index.html.erb b/vendor/plugins/resources/app/views/admin/resources/index.html.erb index 74a7718d7f..1e89b30cec 100644 --- a/vendor/plugins/resources/app/views/admin/resources/index.html.erb +++ b/vendor/plugins/resources/app/views/admin/resources/index.html.erb @@ -19,9 +19,18 @@ <% else %> <% if @resources.size > 0 -%> <%= will_paginate @resources, :previous_label => '«', :next_label => '»' %> -
      - <%= render :partial => "resource", :collection => @resources %> -
    + <% if RefinerySetting.find_or_set(:group_resources_by_date_uploaded, false) %> + <% @grouped_resources.each do |container| %> +

    <%= (resource_group = container.last).first.created_at.strftime("%A, %d %B %Y") %>

    +
      + <%= render :partial => "resource", :collection => resource_group %> +
    + <% end %> + <% else %> +
      + <%= render :partial => "resource", :collection => @resources %> +
    + <% end %> <%= will_paginate @resources, :previous_label => '«', :next_label => '»' %> <% else -%>