0
class MephistoController < ApplicationController
0
- caches_page_with_references :list, :show, :date
0
+ caches_page_with_references :dispatch
0
+ cache_sweeper :comment_sweeper
0
+ observer :comment_observer
0
- if params[:sections].blank?
0
- @section = site.sections.home
0
- @section.show_paged_articles? ? show_section_page(nil) : list_section_articles
0
- @section, page_name = site.sections.find_section_and_page_name(params[:sections].dup)
0
- @section ||= site.sections.home
0
- if @section.show_paged_articles?
0
- show_section_page(page_name)
0
- show_404 and return unless page_name.blank?
0
- conditions = ['(published_at IS NOT NULL AND published_at <= :now) AND (title LIKE :q OR excerpt LIKE :q OR body LIKE :q)',
0
- { :now => Time.now.utc, :q => "%#{params[:q]}%" }]
0
- search_count = site.articles.count(conditions)
0
- @article_pages = Paginator.new self, search_count, site.articles_per_page, params[:page]
0
- @articles = site.articles.find(:all, :conditions => conditions, :order => 'published_at DESC',
0
- :include => [:user, :sections],
0
- :limit => @article_pages.items_per_page,
0
- :offset => @article_pages.current.offset)
0
- render_liquid_template_for(:search, 'articles' => @articles,
0
- 'previous_page' => paged_search_url_for(@article_pages.current.previous),
0
- 'next_page' => paged_search_url_for(@article_pages.current.next),
0
- 'search_string' => params[:q],
0
- 'search_count' => search_count)
0
- @article = site.articles.find_by_permalink(params[:year], params[:month], params[:day], params[:permalink])
0
- show_404 and return unless @article
0
- @comments = @article.comments.collect { |c| c.to_liquid }
0
- self.cached_references << @article
0
- Mephisto::Liquid::CommentForm.article = @article
0
- @article = @article.to_liquid(:mode => :single)
0
- render_liquid_template_for(:single, 'articles' => [@article], 'article' => @article, 'comments' => @comments)
0
- @articles = site.articles.find_all_by_published_date(params[:year], params[:month], params[:day], :include => [:user, :sections])
0
- render_liquid_template_for(:archive, 'articles' => @articles)
0
- count = site.articles.count_by_published_date(params[:year], params[:month], params[:day])
0
- @article_pages = Paginator.new self, count, site.articles_per_page, params[:page]
0
- @articles = site.articles.find_all_by_published_date(params[:year], params[:month], params[:day],
0
- :include => [:user, :sections],
0
- :limit => @article_pages.items_per_page,
0
- :offset => @article_pages.current.offset)
0
- render_liquid_template_for(:archive, 'articles' => @articles,
0
- 'archive_date' => @articles.first.published_at,
0
- 'previous_page' => paged_monthly_url_for(@article_pages.current.previous),
0
- 'next_page' => paged_monthly_url_for(@article_pages.current.next))
0
+ @dispatch_path = Mephisto::Dispatcher.run(site, params[:path].dup)
0
+ @dispatch_action = @dispatch_path.shift
0
+ @section = @dispatch_path.shift
0
+ @dispatch_action == :error ? show_404 : send("dispatch_#{@dispatch_action}")
0
- def list_section_articles
0
- @article_pages = Paginator.new self, @section.articles.size, @section.articles_per_page, params[:page]
0
- @articles = @section.articles.find_by_date(
0
- :limit => @article_pages.items_per_page,
0
- :offset => @article_pages.current.offset)
0
+ @articles = @section.articles.find_by_date(:include => :user)
0
self.cached_references << @section
0
- render_liquid_template_for(:section, 'section' => @section.to_liquid(true),
0
- 'articles' => @articles,
0
- 'previous_page' => paged_section_url_for(@article_pages.current.previous),
0
- 'next_page' => paged_section_url_for(@article_pages.current.next))
0
+ render_liquid_template_for(:section, 'section' => @section.to_liquid(true),
0
+ 'articles' => @articles)
0
- def show_section_page(page_name)
0
- @article = page_name.nil? ? @section.articles.find_by_position : @section.articles.find_by_permalink(page_name)
0
+ @article = @dispatch_path.empty? ? @section.articles.find_by_position : @section.articles.find_by_permalink(@dispatch_path.first)
0
show_404 and return unless @article
0
self.cached_references << @section << @article
0
@@ -88,21 +29,94 @@ class MephistoController < ApplicationController
0
@section.articles.each_with_index do |article, i|
0
articles << article.to_liquid(:page => i.zero?)
0
- render_liquid_template_for(:page, 'section' => @section.to_liquid(true),
0
- 'article' => @article.to_liquid(:mode => :single),
0
- 'article_sections' => @article.sections.collect(&:to_liquid))
0
+ render_liquid_template_for(:page, 'section' => @section.to_liquid(true),
0
+ 'article' => @article.to_liquid(:mode => :single, :site => site))
0
- def paged_search_url_for(page)
0
- page ? search_url(:q => params[:q], :page => page) : ''
0
+ show_404 and return unless find_article
0
+ if request.get? || params[:comment].blank?
0
+ redirect_to site.permalink_for(@article) and return
0
+ @comment = @article.comments.build(params[:comment].merge(:author_ip => request.remote_ip))
0
+ @comment.approved = site.approve_comments?
0
+ if [:akismet_key, :akismet_url].all? { |attr| !site.send(attr).blank? }
0
+ @comment.approved = Akismet.new(site.akismet_key, site.akismet_url).comment_check \
0
+ :user_ip => @comment.author_ip,
0
+ :user_agent => request.user_agent,
0
+ :referrer => request.referer,
0
+ :permalink => "http://#{request.host_with_port}#{site.permalink_for(@article)}",
0
+ :comment_author => @comment.author,
0
+ :comment_author_email => @comment.author_email,
0
+ :comment_author_url => @comment.author_url,
0
+ :comment_content => @comment.body
0
+ logger.info "Checking Akismet (#{site.akismet_key}) for new comment on Article #{@article.id}. #{@comment.approved ? 'Approved' : 'Blocked'}"
0
+ redirect_to dispatch_path(:path => (site.permalink_for(@article)[1..-1].split('/') << 'comments' << @comment.id.to_s), :anchor => @comment.dom_id)
0
+ rescue ActiveRecord::RecordInvalid
0
+ show_article_with 'errors' => @comment.errors.full_messages, 'submitted' => params[:comment]
0
+ rescue Article::CommentNotAllowed
0
+ show_article_with 'errors' => ["Commenting has been disabled on this article"]
0
- def paged_monthly_url_for(page)
0
- page ? paged_monthly_url(:year => params[:year], :month => params[:month], :page => page) : ''
0
+ show_article_with 'message' => 'Thanks for the comment!'
0
+ @articles = site.articles.find_all_in_month(@dispatch_path.shift, @dispatch_path.shift, :include => :user)
0
+ render_liquid_template_for(:archive, 'articles' => @articles, 'archive_date' => @articles.first.published_at)
0
+ conditions = ['(published_at IS NOT NULL AND published_at <= :now) AND (title LIKE :q OR excerpt LIKE :q OR body LIKE :q)',
0
+ { :now => Time.now.utc, :q => "%#{params[:q]}%" }]
0
+ search_count = site.articles.count(conditions)
0
+ @article_pages = Paginator.new self, search_count, site.articles_per_page, params[:page]
0
+ @articles = site.articles.find(:all, :conditions => conditions, :order => 'published_at DESC',
0
+ :include => [:user, :sections],
0
+ :limit => @article_pages.items_per_page,
0
+ :offset => @article_pages.current.offset)
0
+ render_liquid_template_for(:search, 'articles' => @articles,
0
+ 'previous_page' => paged_search_url_for(@article_pages.current.previous),
0
+ 'next_page' => paged_search_url_for(@article_pages.current.next),
0
+ 'search_string' => params[:q],
0
+ 'search_count' => search_count)
0
- def paged_section_url_for(page)
0
- page ? section_url(:sections => @section.to_url << 'page' << page) : ''
0
+ raise NotImplementedError
0
+ def paged_search_url_for(page)
0
+ page ? search_url(:q => params[:q], :page => page) : ''
0
+ @article = site.articles.find_by_permalink(@dispatch_path.first)
0
+ def show_article_with(assigns = {})
0
+ find_article if @article.nil?
0
+ show_404 and return unless @article
0
+ @comments = @article.comments.reject(&:new_record?).collect(&:to_liquid)
0
+ self.cached_references << @article
0
+ Mephisto::Liquid::CommentForm.article = @article
0
+ @article = @article.to_liquid(:mode => :single, :site => site)
0
+ render_liquid_template_for(:single, assigns.merge('articles' => [@article], 'article' => @article, 'comments' => @comments))
0
+ alias show_article show_article_with