Sha256: f233f27ea7c6496d5c3e112e2abb84cd2ab508a2fbd22d0b33bbb618c6d1a1ea

Contents?: true

Size: 1.59 KB

Versions: 16

Compression:

Stored size: 1.59 KB

Contents

class ArchivesSidebar < Sidebar
  description 'Displays links to monthly archives'
  setting :show_count, true, :label => 'Show article counts', :input_type => :checkbox
  setting :count,      10,   :label => 'Number of Months'

  attr_accessor :archives

  def self.date_func
    @date_func ||=
      begin
        if Content.connection.kind_of?(ActiveRecord::ConnectionAdapters::SQLiteAdapter)
          "strftime('%Y', published_at) as year, strftime('%m', published_at) as month"
        else
          "extract(year from published_at) as year,extract(month from published_at) as month"
        end
      rescue NameError
        "extract(year from published_at) as year,extract(month from published_at) as month"
      end
  end

  def parse_request(contents, params)
    # The original query that was here instantiated every article and every
    # tag, and then sorted through them just to do a 'group by date'.
    # Unfortunately, there's no universally-supported way to do this
    # across all three of our supported DBs.  So, we resort to a bit of
    # DB-specific code.
    date_func = self.class.date_func

    article_counts = Content.find_by_sql(["select count(*) as count, #{date_func} from contents where type='Article' and published = ? and published_at < ? group by year,month order by year desc,month desc limit ? ",true,Time.now,count.to_i])

    @archives = article_counts.map do |entry|
      {
        :name => _(Date::MONTHNAMES[entry.month.to_i]) + " #{entry.year}",
        :month => entry.month.to_i,
        :year => entry.year.to_i,
        :article_count => entry.count
      }
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
typo-5.5 vendor/plugins/archives_sidebar/lib/archives_sidebar.rb
typo-5.4.4 vendor/plugins/archives_sidebar/lib/archives_sidebar.rb
typo-5.4.3 vendor/plugins/archives_sidebar/lib/archives_sidebar.rb
typo-5.4.2 vendor/plugins/archives_sidebar/lib/archives_sidebar.rb
typo-5.4.1 vendor/plugins/archives_sidebar/lib/archives_sidebar.rb
typo-5.4 vendor/plugins/archives_sidebar/lib/archives_sidebar.rb
typo-5.0.3.98.1 vendor/plugins/archives_sidebar/lib/archives_sidebar.rb
typo-5.0.3.98 vendor/plugins/archives_sidebar/lib/archives_sidebar.rb
typo-5.1.2 vendor/plugins/archives_sidebar/lib/archives_sidebar.rb
typo-5.1.1 vendor/plugins/archives_sidebar/lib/archives_sidebar.rb
typo-5.1.3 vendor/plugins/archives_sidebar/lib/archives_sidebar.rb
typo-5.1.98 vendor/plugins/archives_sidebar/lib/archives_sidebar.rb
typo-5.1 vendor/plugins/archives_sidebar/lib/archives_sidebar.rb
typo-5.2.98 vendor/plugins/archives_sidebar/lib/archives_sidebar.rb
typo-5.2 vendor/plugins/archives_sidebar/lib/archives_sidebar.rb
typo-5.3 vendor/plugins/archives_sidebar/lib/archives_sidebar.rb