Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 7d0646d5d9b7a96803f5410e96bd2cb866f3d4f1 @unixcharles committed Mar 10, 2010
Showing with 3,410 additions and 0 deletions.
  1. BIN app/.DS_Store
  2. BIN app/controllers/.DS_Store
  3. +19 −0 app/controllers/admin/blog_settings_controller.rb
  4. +8 −0 app/controllers/admin/blogs_controller.rb
  5. +40 −0 app/controllers/admin/comments_controller.rb
  6. +116 −0 app/controllers/blogs_controller.rb
  7. +25 −0 app/models/blog.rb
  8. +34 −0 app/models/blog_mailer.rb
  9. +54 −0 app/models/blog_setting.rb
  10. +29 −0 app/models/comment.rb
  11. BIN app/views/admin/.DS_Store
  12. +16 −0 app/views/admin/blog_settings/_blog_setting.html.erb
  13. +22 −0 app/views/admin/blog_settings/_form.html.erb
  14. +1 −0 app/views/admin/blog_settings/edit.html.erb
  15. +23 −0 app/views/admin/blog_settings/index.html.erb
  16. +15 −0 app/views/admin/blogs/_blog.html.erb
  17. +71 −0 app/views/admin/blogs/_form.html.erb
  18. +1 −0 app/views/admin/blogs/edit.html.erb
  19. +49 −0 app/views/admin/blogs/index.html.erb
  20. +1 −0 app/views/admin/blogs/new.html.erb
  21. +24 −0 app/views/admin/comments/_comment.html.erb
  22. +40 −0 app/views/admin/comments/index.html.erb
  23. +66 −0 app/views/admin/comments/show.html.erb
  24. +3 −0 app/views/blogs/_blog.html.erb
  25. +11 −0 app/views/blogs/_comments.html.erb
  26. +34 −0 app/views/blogs/_form.html.erb
  27. +36 −0 app/views/blogs/_see_also.html.erb
  28. +48 −0 app/views/blogs/_side_body.html.erb
  29. +19 −0 app/views/blogs/index.html.erb
  30. +17 −0 app/views/blogs/index.rss.builder
  31. +63 −0 app/views/blogs/show.html.erb
  32. +37 −0 bin/refinerycms-blog-install
  33. +20 −0 config/routes.rb
  34. BIN db/.DS_Store
  35. +98 −0 db/migrate/20100301212444_create_blogs.rb
  36. +29 −0 db/migrate/20100307055735_acts_as_taggable_on_migration.rb
  37. BIN lib/.DS_Store
  38. +2,237 −0 lib/raptcha.rb
  39. +9 −0 lib/tasks/blog.rake
  40. +8 −0 license
  41. +12 −0 rails/init.rb
  42. +75 −0 readme.md
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,19 @@
+class Admin::BlogSettingsController < Admin::BaseController
+
+ crudify :blog_setting, :title_attribute => :name, :order => "id ASC", :searchable => false
+
+
+ def toggle_setting
+ @blog_setting = BlogSetting.find(params[:id])
+ @blog_setting.toggle!(:value)
+
+ flash[:notice] = "Comment from '#{@blog_setting.name}' has been set to " +
+ if @blog_setting.value
+ "true"
+ else
+ "false"
+ end
+
+ redirect_to :action => 'index'
+ end
+end
@@ -0,0 +1,8 @@
+class Admin::BlogsController < Admin::BaseController
+ before_filter :get_count, :only => 'index'
+ crudify :blog, :title_attribute => :title, :order => "publishing_date DESC"
+
+ def get_count
+ @unread_comments_count = Comment.unread.count
+ end
+end
@@ -0,0 +1,40 @@
+class Admin::CommentsController < Admin::BaseController
+ crudify :comment, :title_attribute => "name", :order => "created_at DESC"
+
+ before_filter :find_comment, :only => [:show, :status, :unread, :destroy]
+ before_filter :find_all_comments, :only => [:index]
+
+ def status
+ if params[:approved]
+ @comment.approved = false unless params[:approved] == "true"
+ @comment.save
+ else
+ @comment.toggle!(:approved)
+ end
+
+ flash[:notice] = "Comment from '#{@comment.name}' in '#{@comment.blog.title}' blog post has been " +
+ if @comment.is_approved
+ "approved"
+ else
+ "refused"
+ end
+
+ redirect_to :action => 'index'
+ end
+
+ def unread
+ @comment.approved = nil
+
+ if @comment.save
+ flash[:notice] = "You sent a comment from '#{@comment.name}' back to unread comments"
+ end
+
+ redirect_to :action => 'index'
+ end
+ protected
+
+ def find_all_comments
+ @comments_history = Comment.history.paginate :page => params[:page]
+ @unread_comments = Comment.unread
+ end
+end
@@ -0,0 +1,116 @@
+class BlogsController < ApplicationController
+
+ before_filter :find_blog, :only => ['comment', 'show', 'authorize']
+ before_filter :find_page, :except => ['captcha', 'authorize']
+ before_filter :load_blogs, :except => ['captcha', 'authorize', 'tag', 'category', 'author', 'show']
+ before_filter :load_tags, :except => ['captcha', 'authorize']
+
+ def index
+ present(@page)
+
+ respond_to do |format|
+ format.html
+ format.rss
+ end
+ end
+
+ def tag
+ @blogs = Blog.tagged_with(params[:tag], :on => :tags).published
+ present(@page)
+ render 'index'
+ end
+
+ def category
+ @blogs = Blog.tagged_with(params[:category], :on => :categories).published
+ present(@page)
+ render 'index'
+ end
+
+ def author
+ @blogs = Blog.tagged_with(params[:author], :on => :authors).published
+ present(@page)
+ render 'index'
+ end
+
+
+
+ def show
+ if @blog
+ @comment = @blog.comments.new
+ present(@page)
+ else
+ error_404
+ end
+ end
+
+ def comment
+ @comment = @blog.comments.new(params[:comment])
+
+ if Raptcha.valid?(params) || BlogSetting.enable_captcha == false
+ @comment.approved = true unless BlogSetting.manual_moderation
+ if @comment.save
+ flash[:notice] = "Comment was posted successfully! Waiting for approval!"
+ @message = @page[:successful_comment]
+ if BlogSetting.enable_email_notification
+ begin
+ BlogMailer.deliver_notification(@comment, request)
+ rescue
+ logger.warn "There was an error delivering a blog notification.\n#{$!}\n"
+ end
+ end
+ if BlogSetting.enable_approve_comment_by_email && BlogSetting.manual_moderation
+ begin
+ BlogMailer.deliver_confirmation(@comment, request)
+ rescue
+ logger.warn "There was an error delivering a blog confirmation.\n#{$!}\n"
+ end
+ end
+ @comment = @blog.comments.new
+ end
+ else
+ @message = @page[:invalid_comment]
+ end
+
+ present(@page)
+ render 'show'
+ end
+
+ def captcha
+ Raptcha.render(controller=self, params)
+ end
+
+ def authorize
+ if params[:token] && BlogSetting.enable_approve_comment_by_email && BlogSetting.manual_moderation
+ @comment = Comment.find_by_token(params[:token])
+ @comment.approved = true
+ redirect_to blog_post_url(@comment.blog.permalink) if @comment.save
+ else
+ redirect_to blog_url
+ end
+ end
+
+protected
+ def load_blogs
+ @blogs = Blog.published
+ @recent_blogs = Blog.published(:limit => 5) if BlogSetting.enable_recent_blogs
+ end
+
+ def find_blog
+ if @blog = Blog.find_by_permalink(params[:permalink], :conditions => ["publishing_date < ? and draft = false", Time.now])
+ @related_tags_blogs = @blog.find_related_tags if BlogSetting.enable_related_tags
+ @related_categories_blogs = @blog.find_related_categories if BlogSetting.enable_related_categories
+ @related_authors_blogs = @blog.find_related_authors if BlogSetting.enable_related_authors
+ @recent_blogs = Blog.find(:all, :limit => 5, :conditions => ["id != ? and publishing_date < ? and draft = false", Blog.first, Time.now]) if BlogSetting.enable_recent_blogs
+ end
+ end
+
+ def load_tags
+ @tags = Blog.published.tag_counts if BlogSetting.enable_tags
+ @categories = Blog.published.category_counts if BlogSetting.enable_categories
+ @authors = Blog.published.author_counts if BlogSetting.enable_authors
+ end
+
+ def find_page
+ @page = Page.find_by_link_url("/blog")
+ end
+end
@@ -0,0 +1,25 @@
+class Blog < ActiveRecord::Base
+ acts_as_taggable_on :categories, :tags, :authors
+ has_many :comments
+
+ named_scope :published, lambda {{:conditions => "publishing_date < '#{Time.now.to_formatted_s(:db)}' and draft IS NOT true",
+ :order => "publishing_date ASC"}}
+
+
+ acts_as_indexed :fields => [:title, :permalink, :excerpt, :body],
+ :index_file => [Rails.root.to_s, "tmp", "index"]
+
+ validates_presence_of :title, :permalink, :excerpt, :body
+ validates_uniqueness_of :title, :permalink
+
+ validates_format_of :permalink, :with => /^(([-_]|[a-z]|\d){1,100})$/, :message => " is invalid, only lowercase alphanumeric character and _-"
+ validates_length_of :permalink, :within => 4..99
+
+ def is_published?
+ if publishing_date >= Time.now || draft != true
+ true
+ else
+ false
+ end
+ end
+end
@@ -0,0 +1,34 @@
+class BlogMailer < ActionMailer::Base
+
+ def notification(comment, request)
+ subject "New comment on #{comment.blog.title}"
+ recipients BlogSetting.notification_email
+ from "\"#{RefinerySetting[:site_name]}\" <no-reply@#{request.domain(RefinerySetting.find_or_set(:tld_length, 1))}>"
+ sent_on Time.now
+ body "New comment on #{comment.blog.title} blog post.
+ Comment author: #{comment.name}
+ Comment title: #{comment.title}
+ Comment Body: #{comment.body}"
+ end
+
+ def confirmation(comment, request)
+ subject "#{RefinerySetting[:site_name]} - comment confirmation"
+ recipients comment.email
+ from "\"#{RefinerySetting[:site_name]}\" <no-reply@#{request.domain(RefinerySetting.find_or_set(:tld_length, 1))}>"
+ sent_on Time.now
+ content_type "text/html"
+ body "<html>
+ <body>
+ <p>You send a comment '#{comment.blog.title}' blog post at #{request.domain(RefinerySetting.find_or_set(:tld_length, 1))}.
+ <p>Comment author: #{comment.name}</p>
+ <p>Comment title: #{comment.title}</p>
+ <p>Comment Body: #{comment.body}</p>
+ <hr/>
+ <p>You're comment is currently not displayed to public, you need to confirm it first by clicking on the following link:</p>
+ <p><a href='http://#{request.domain(RefinerySetting.find_or_set(:tld_length, 1))}/blog/authorize/#{comment.token}'>http://#{request.domain(RefinerySetting.find_or_set(:tld_length, 1))}/blog/authorize/#{comment.token}</a></p>
+ <p><i>if can't click on the link, manually copy & paste this URL into a web browser</i></p>
+ </body>
+ </html>"
+ end
+
+end
@@ -0,0 +1,54 @@
+class BlogSetting < ActiveRecord::Base
+
+ # spam related options
+ def self.enable_captcha
+ find_or_create_by_name("Enable Captcha").value
+ end
+
+ def self.manual_moderation
+ find_or_create_by_name("Manual Moderation").value
+ end
+
+ # Tags & tag relations
+ def self.enable_categories
+ find_or_create_by_name("Enable Categories").value
+ end
+
+ def self.enable_tags
+ find_or_create_by_name("Enable Tags").value
+ end
+
+ def self.enable_authors
+ find_or_create_by_name("Enable Authors").value
+ end
+
+ def self.enable_recent_blogs
+ find_or_create_by_name("Enable Recent Blog").value
+ end
+
+ def self.enable_related_categories
+ find_or_create_by_name("Enable Related Categories").value
+ end
+
+ def self.enable_related_tags
+ find_or_create_by_name("Enable Related Tags").value
+ end
+
+ def self.enable_related_authors
+ find_or_create_by_name("Enable Related Authors").value
+ end
+
+ # email notification
+
+ def self.enable_email_notification
+ find_or_create_by_name("Enable email notification").value
+ end
+
+ def self.notification_email
+ find_or_create_by_name("Notification email").entry
+ end
+
+ def self.enable_approve_comment_by_email
+ find_or_create_by_name("Enable Approve Comment by email").value
+ end
+end
@@ -0,0 +1,29 @@
+class Comment < ActiveRecord::Base
+ belongs_to :blog
+
+ named_scope :unread, :conditions => {:approved => nil}
+ named_scope :history, :conditions => 'approved IS NOT NULL', :order => "created_at DESC"
+
+ named_scope :approved, :conditions => {:approved => true}
+
+ validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i,
+ :message => 'must be valid'
+
+ validates_presence_of :name, :email, :body, :title
+ validates_length_of :name, :email, :title, :within => 3..80
+ validates_length_of :body, :within => 3..1000
+
+ acts_as_indexed :fields => [:title, :body, :name, :email],
+ :index_file => [Rails.root.to_s, "tmp", "index"]
+
+
+ attr_accessible :name, :email, :body, :title
+
+ def is_approved
+ true if approved
+ end
+
+ def before_create
+ self.token ||= ActiveSupport::SecureRandom.hex(24) if BlogSetting.enable_approve_comment_by_email
+ end
+end
Binary file not shown.
@@ -0,0 +1,16 @@
+<li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(blog_setting) -%>">
+ <span class='title'>
+ <span class='actions'>
+ <%= link_to refinery_icon_tag("#{blog_setting.value ? 'cross' : 'tick'}.png"),
+ {:action => "toggle_setting", :id => blog_setting.id},
+ {:title => "Set this bsetting to #{blog_setting.value ? 'false' : 'true'}"} unless blog_setting.value.nil? %>
+
+ <%= link_to refinery_icon_tag("application_edit.png"), edit_admin_blog_setting_path(blog_setting),
+ :title => 'Edit this blog setting' if blog_setting.value.nil? %>
+ </span>
+ <strong><%=h blog_setting.name %></strong>
+ is set to <strong>"<%=h blog_setting.value.nil? ? blog_setting.entry : blog_setting.value %>"</strong>
+ <%= link_to '?', edit_admin_blog_setting_path(blog_setting), :title => blog_setting.description %>
+ <span class="preview">&nbsp;</span>
+ </span>
+</li>
@@ -0,0 +1,22 @@
+<%= error_messages_for :blog_setting -%>
+<% form_for [:admin, @blog_setting] do |f| -%>
+
+ <p>
+ <strong>
+ <%=h @blog_setting.description -%>
+ </strong>
+ </p>
+ <% if @blog_setting.value.nil? %>
+ <div class='field'>
+ <%= f.label :entry -%>
+ <%= f.text_field :entry -%>
+ </div>
+ <% else %>
+ <div class='field'>
+ <%= f.label :value -%>
+ <%= f.check_box :value -%>
+ </div>
+ <% end %>
+
+ <%= render :partial => "/shared/admin/form_actions", :locals => {:f => f, :continue_editing => false} %>
+<% end -%>
@@ -0,0 +1 @@
+<%= render :partial => "form" %>
Oops, something went wrong. Retry.

0 comments on commit 7d0646d

Please sign in to comment.