diff options
Diffstat (limited to 'app/controllers')
| -rw-r--r-- | app/controllers/admin/blogs_controller.rb | 7 | ||||
| -rw-r--r-- | app/controllers/admin/comments_controller.rb | 93 | ||||
| -rw-r--r-- | app/controllers/admin/games_controller.rb | 56 | ||||
| -rw-r--r-- | app/controllers/admin/links_controller.rb | 52 | ||||
| -rw-r--r-- | app/controllers/admin/quotes_controller.rb | 54 | ||||
| -rw-r--r-- | app/controllers/admin/streams_controller.rb | 4 | ||||
| -rw-r--r-- | app/controllers/admin/updates_controller.rb | 2 | ||||
| -rw-r--r-- | app/controllers/application_controller.rb | 20 | ||||
| -rw-r--r-- | app/controllers/blogs_controller.rb | 83 | ||||
| -rw-r--r-- | app/controllers/comments_controller.rb | 81 | ||||
| -rw-r--r-- | app/controllers/games_controller.rb | 21 | ||||
| -rw-r--r-- | app/controllers/quotes_controller.rb | 260 | ||||
| -rw-r--r-- | app/controllers/streams_controller.rb | 19 | ||||
| -rw-r--r-- | app/controllers/tags_controller.rb | 20 | ||||
| -rw-r--r-- | app/controllers/webmentions_controller.rb | 36 |
15 files changed, 792 insertions, 16 deletions
| diff --git a/app/controllers/admin/blogs_controller.rb b/app/controllers/admin/blogs_controller.rb index 1035c12..35f3514 100644 --- a/app/controllers/admin/blogs_controller.rb +++ b/app/controllers/admin/blogs_controller.rb | |||
| @@ -13,7 +13,7 @@ class Admin::BlogsController < Admin::AdminController | |||
| 13 | @blog = Blog.find(params[:id]) | 13 | @blog = Blog.find(params[:id]) |
| 14 | 14 | ||
| 15 | if @blog.published | 15 | if @blog.published |
| 16 | redirect_to blog_url(@blog.slug) | 16 | redirect_to @blog |
| 17 | else | 17 | else |
| 18 | render layout: "application" | 18 | render layout: "application" |
| 19 | end | 19 | end |
| @@ -25,6 +25,7 @@ class Admin::BlogsController < Admin::AdminController | |||
| 25 | 25 | ||
| 26 | def create | 26 | def create |
| 27 | @blog = Blog.new(blog_params) | 27 | @blog = Blog.new(blog_params) |
| 28 | @blog.user = current_user | ||
| 28 | 29 | ||
| 29 | if @blog.save | 30 | if @blog.save |
| 30 | flash.notice = "Blog created successfully!" | 31 | flash.notice = "Blog created successfully!" |
| @@ -44,7 +45,7 @@ class Admin::BlogsController < Admin::AdminController | |||
| 44 | def update | 45 | def update |
| 45 | @blog = Blog.find(params[:id]) | 46 | @blog = Blog.find(params[:id]) |
| 46 | 47 | ||
| 47 | if @blog.update_attributes(blog_params) | 48 | if @blog.update(blog_params) |
| 48 | flash.notice = "Blog updated successfully!" | 49 | flash.notice = "Blog updated successfully!" |
| 49 | else | 50 | else |
| 50 | flash.alert = "Error updating blog." | 51 | flash.alert = "Error updating blog." |
| @@ -56,7 +57,7 @@ class Admin::BlogsController < Admin::AdminController | |||
| 56 | private | 57 | private |
| 57 | 58 | ||
| 58 | def blog_params | 59 | def blog_params |
| 59 | params.require(:blog).permit(:title, :body, :slug, :published, records_attributes: [:description, :_destroy]) | 60 | params.require(:blog).permit(:title, :body, :slug, :published, :published_at, :tag_list, images: [], records_attributes: [:description, :_destroy]) |
| 60 | end | 61 | end |
| 61 | 62 | ||
| 62 | def set_section | 63 | def set_section |
| diff --git a/app/controllers/admin/comments_controller.rb b/app/controllers/admin/comments_controller.rb new file mode 100644 index 0000000..4d9502d --- /dev/null +++ b/app/controllers/admin/comments_controller.rb | |||
| @@ -0,0 +1,93 @@ | |||
| 1 | class Admin::CommentsController < Admin::AdminController | ||
| 2 | before_action :set_section | ||
| 3 | |||
| 4 | def index | ||
| 5 | @comments = Comment.where(status: :published).order(updated_at: :desc).paginate(page: params[:page], per_page: 20) | ||
| 6 | end | ||
| 7 | |||
| 8 | def pending | ||
| 9 | @comments = Comment.where(status: :pending).order(updated_at: :desc).paginate(page: params[:page], per_page: 20) | ||
| 10 | end | ||
| 11 | |||
| 12 | def accept | ||
| 13 | @comment = Comment.find(params[:id]) | ||
| 14 | @comment.status = :published | ||
| 15 | @comment.save! | ||
| 16 | |||
| 17 | if @comment.reply_to and @comment.reply_to.email != @comment.blog.user.email and @comment.reply_to.email != current_user.email | ||
| 18 | CommentMailer.with(comment: @comment).reply_comment_email.deliver_later | ||
| 19 | end | ||
| 20 | |||
| 21 | flash.notice = "Comment successfully published." | ||
| 22 | redirect_to pending_admin_comments_url | ||
| 23 | end | ||
| 24 | |||
| 25 | def reject | ||
| 26 | @comment = Comment.find(params[:id]) | ||
| 27 | @comment.status = :rejected | ||
| 28 | @comment.save! | ||
| 29 | |||
| 30 | flash.notice = "Comment successfully rejected." | ||
| 31 | redirect_to pending_admin_comments_url | ||
| 32 | end | ||
| 33 | |||
| 34 | def mark_spam | ||
| 35 | @comment = Comment.find(params[:id]) | ||
| 36 | perform_mark_spam(@comment) | ||
| 37 | |||
| 38 | flash.notice = "Comment successfully marked as spam." | ||
| 39 | redirect_back fallback_location: pending_admin_comments_url | ||
| 40 | end | ||
| 41 | |||
| 42 | def destroy | ||
| 43 | if Comment.destroy(params[:id]) | ||
| 44 | flash.notice = "Comment successfully deleted." | ||
| 45 | else | ||
| 46 | flash.alert = "Could not delete comment." | ||
| 47 | end | ||
| 48 | |||
| 49 | redirect_to admin_comments_url | ||
| 50 | end | ||
| 51 | |||
| 52 | def mass | ||
| 53 | if params[:mass_action] == "Delete" | ||
| 54 | Comment.destroy_by(id: params[:comment_ids]) | ||
| 55 | |||
| 56 | flash.notice = "Comments successfully deleted." | ||
| 57 | elsif params[:mass_action] == "Mark Spam" | ||
| 58 | @comments = Comment.find(params[:comment_ids]) | ||
| 59 | |||
| 60 | @comments.each do |comment| | ||
| 61 | perform_mark_spam(comment) | ||
| 62 | end | ||
| 63 | |||
| 64 | flash.notice = "Comments successfully marked as spam." | ||
| 65 | end | ||
| 66 | |||
| 67 | redirect_back fallback_location: pending_admin_comments_url | ||
| 68 | end | ||
| 69 | |||
| 70 | private | ||
| 71 | |||
| 72 | def set_section | ||
| 73 | @section = "comments" | ||
| 74 | end | ||
| 75 | |||
| 76 | def perform_mark_spam(comment) | ||
| 77 | akismet_params = { | ||
| 78 | type: "comment", | ||
| 79 | text: comment.body, | ||
| 80 | created_at: comment.created_at, | ||
| 81 | author: comment.username, | ||
| 82 | author_email: comment.email, | ||
| 83 | author_url: comment.website, | ||
| 84 | post_url: url_for(comment.blog), | ||
| 85 | post_modified_at: comment.blog.updated_at, | ||
| 86 | referrer: comment.referrer | ||
| 87 | } | ||
| 88 | |||
| 89 | Akismet.spam comment.request_ip, comment.user_agent, akismet_params | ||
| 90 | |||
| 91 | comment.destroy! | ||
| 92 | end | ||
| 93 | end | ||
| diff --git a/app/controllers/admin/games_controller.rb b/app/controllers/admin/games_controller.rb new file mode 100644 index 0000000..2da1e95 --- /dev/null +++ b/app/controllers/admin/games_controller.rb | |||
| @@ -0,0 +1,56 @@ | |||
| 1 | class Admin::GamesController < Admin::AdminController | ||
| 2 | before_action :set_section | ||
| 3 | |||
| 4 | def index | ||
| 5 | @games = Game.order(created_at: :desc) | ||
| 6 | end | ||
| 7 | |||
| 8 | def drafts | ||
| 9 | @games = Game.where(created_at: :desc) | ||
| 10 | end | ||
| 11 | |||
| 12 | def new | ||
| 13 | @game = Game.new | ||
| 14 | end | ||
| 15 | |||
| 16 | def create | ||
| 17 | @game = Game.new(game_params) | ||
| 18 | |||
| 19 | if @game.save | ||
| 20 | flash.notice = "Game created successfully!" | ||
| 21 | |||
| 22 | render :edit | ||
| 23 | else | ||
| 24 | flash.alert = "Error creating game." | ||
| 25 | |||
| 26 | render :new | ||
| 27 | end | ||
| 28 | end | ||
| 29 | |||
| 30 | def edit | ||
| 31 | @game = Game.find(params[:id]) | ||
| 32 | end | ||
| 33 | |||
| 34 | def update | ||
| 35 | @game = Game.find(params[:id]) | ||
| 36 | |||
| 37 | if @game.update(game_params) | ||
| 38 | flash.notice = "Game updated successfully!" | ||
| 39 | else | ||
| 40 | flash.alert = "Error updating game." | ||
| 41 | end | ||
| 42 | |||
| 43 | render :edit | ||
| 44 | end | ||
| 45 | |||
| 46 | private | ||
| 47 | |||
| 48 | def game_params | ||
| 49 | params.require(:game).permit(:title, :description, :status, :progress, :score, :started_on, :finished_on) | ||
| 50 | end | ||
| 51 | |||
| 52 | def set_section | ||
| 53 | @section = "games" | ||
| 54 | end | ||
| 55 | |||
| 56 | end | ||
| diff --git a/app/controllers/admin/links_controller.rb b/app/controllers/admin/links_controller.rb new file mode 100644 index 0000000..54f245a --- /dev/null +++ b/app/controllers/admin/links_controller.rb | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | class Admin::LinksController < Admin::AdminController | ||
| 2 | before_action :set_section | ||
| 3 | |||
| 4 | def index | ||
| 5 | @links = Link.order(created_at: :desc) | ||
| 6 | end | ||
| 7 | |||
| 8 | def new | ||
| 9 | @link = Link.new | ||
| 10 | end | ||
| 11 | |||
| 12 | def create | ||
| 13 | @link = Link.new(link_params) | ||
| 14 | |||
| 15 | if @link.save | ||
| 16 | flash.notice = "Link created successfully!" | ||
| 17 | |||
| 18 | render :edit | ||
| 19 | else | ||
| 20 | flash.alert = "Error creating link." | ||
| 21 | |||
| 22 | render :new | ||
| 23 | end | ||
| 24 | end | ||
| 25 | |||
| 26 | def edit | ||
| 27 | @link = Link.find(params[:id]) | ||
| 28 | end | ||
| 29 | |||
| 30 | def update | ||
| 31 | @link = Link.find(params[:id]) | ||
| 32 | |||
| 33 | if @link.update(link_params) | ||
| 34 | flash.notice = "Link updated successfully!" | ||
| 35 | else | ||
| 36 | flash.alert = "Error updating link." | ||
| 37 | end | ||
| 38 | |||
| 39 | render :edit | ||
| 40 | end | ||
| 41 | |||
| 42 | private | ||
| 43 | |||
| 44 | def link_params | ||
| 45 | params.require(:link).permit(:title, :url, :tag_list, records_attributes: [:description, :_destroy]) | ||
| 46 | end | ||
| 47 | |||
| 48 | def set_section | ||
| 49 | @section = "links" | ||
| 50 | end | ||
| 51 | |||
| 52 | end | ||
| diff --git a/app/controllers/admin/quotes_controller.rb b/app/controllers/admin/quotes_controller.rb new file mode 100644 index 0000000..3623463 --- /dev/null +++ b/app/controllers/admin/quotes_controller.rb | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | class Admin::QuotesController < Admin::AdminController | ||
| 2 | before_action :set_section | ||
| 3 | |||
| 4 | def index | ||
| 5 | @quotes = Quote.published.order(id: :desc).paginate(page: params[:page], per_page: 20) | ||
| 6 | end | ||
| 7 | |||
| 8 | def pending | ||
| 9 | @quotes = Quote.pending.order(id: :desc).paginate(page: params[:page], per_page: 20) | ||
| 10 | end | ||
| 11 | |||
| 12 | def edit | ||
| 13 | @quote = Quote.find(params[:id]) | ||
| 14 | end | ||
| 15 | |||
| 16 | def update | ||
| 17 | @quote = Quote.find(params[:id]) | ||
| 18 | |||
| 19 | if @quote.update(quote_params) | ||
| 20 | flash[:notice] = "Quote was successfully updated." | ||
| 21 | else | ||
| 22 | flash[:error] = "Error updating quote." | ||
| 23 | end | ||
| 24 | |||
| 25 | render :edit | ||
| 26 | end | ||
| 27 | |||
| 28 | def accept | ||
| 29 | @quote = Quote.find(params[:id]) | ||
| 30 | @quote.state = :published | ||
| 31 | @quote.save! | ||
| 32 | |||
| 33 | flash.notice = "Quote successfully accepted." | ||
| 34 | redirect_to pending_admin_quotes_url | ||
| 35 | end | ||
| 36 | |||
| 37 | def destroy | ||
| 38 | @quote = Quote.find(params[:id]) | ||
| 39 | @quote.destroy! | ||
| 40 | |||
| 41 | flash.notice = "Quote successfully rejected." | ||
| 42 | redirect_to pending_admin_quotes_url | ||
| 43 | end | ||
| 44 | |||
| 45 | private | ||
| 46 | |||
| 47 | def set_section | ||
| 48 | @section = "quotes" | ||
| 49 | end | ||
| 50 | |||
| 51 | def quote_params | ||
| 52 | params.require(:quote).permit(:content, :state, :notes, :submitter, :tag_list, :audio) | ||
| 53 | end | ||
| 54 | end | ||
| diff --git a/app/controllers/admin/streams_controller.rb b/app/controllers/admin/streams_controller.rb index 86dec06..91ecc31 100644 --- a/app/controllers/admin/streams_controller.rb +++ b/app/controllers/admin/streams_controller.rb | |||
| @@ -30,7 +30,7 @@ class Admin::StreamsController < Admin::AdminController | |||
| 30 | def update | 30 | def update |
| 31 | @stream = Stream.find(params[:id]) | 31 | @stream = Stream.find(params[:id]) |
| 32 | 32 | ||
| 33 | if @stream.update_attributes(stream_params) | 33 | if @stream.update(stream_params) |
| 34 | flash.notice = "Stream updated successfully!" | 34 | flash.notice = "Stream updated successfully!" |
| 35 | else | 35 | else |
| 36 | flash.alert = "Error updating stream." | 36 | flash.alert = "Error updating stream." |
| @@ -42,7 +42,7 @@ class Admin::StreamsController < Admin::AdminController | |||
| 42 | private | 42 | private |
| 43 | 43 | ||
| 44 | def stream_params | 44 | def stream_params |
| 45 | params.require(:stream).permit(:title, :body, :slug, records_attributes: [:description, :_destroy]) | 45 | params.require(:stream).permit(:title, :body, :slug, :tag_list, records_attributes: [:description, :_destroy]) |
| 46 | end | 46 | end |
| 47 | 47 | ||
| 48 | def set_section | 48 | def set_section |
| diff --git a/app/controllers/admin/updates_controller.rb b/app/controllers/admin/updates_controller.rb index 9bf9caf..226daa5 100644 --- a/app/controllers/admin/updates_controller.rb +++ b/app/controllers/admin/updates_controller.rb | |||
| @@ -30,7 +30,7 @@ class Admin::UpdatesController < Admin::AdminController | |||
| 30 | @stream = Stream.find(params[:stream_id]) | 30 | @stream = Stream.find(params[:stream_id]) |
| 31 | @update = Update.find(params[:id]) | 31 | @update = Update.find(params[:id]) |
| 32 | 32 | ||
| 33 | if @update.update_attributes(update_params) | 33 | if @update.update(update_params) |
| 34 | flash.notice = "Update updated successfully!" | 34 | flash.notice = "Update updated successfully!" |
| 35 | else | 35 | else |
| 36 | flash.alert = "Error updating update." | 36 | flash.alert = "Error updating update." |
| diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c9d4e15..ad46fb9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb | |||
| @@ -1,19 +1,19 @@ | |||
| 1 | class ApplicationController < ActionController::Base | 1 | class ApplicationController < ActionController::Base |
| 2 | protect_from_forgery with: :exception | 2 | protect_from_forgery with: :exception |
| 3 | 3 | before_action :choose_random_song | |
| 4 | protected | ||
| 5 | |||
| 6 | def authenticate_pokeviewer(login, token) | ||
| 7 | user = login && User.find_by_login(login) | ||
| 8 | |||
| 9 | ActiveSupport::SecurityUtils.secure_compare( | ||
| 10 | ::Digest::SHA256.hexdigest(user.pokeviewer_token), | ||
| 11 | ::Digest::SHA256.hexdigest(token)) | ||
| 12 | end | ||
| 13 | 4 | ||
| 14 | private | 5 | private |
| 15 | 6 | ||
| 16 | def after_sign_out_path_for(resource) | 7 | def after_sign_out_path_for(resource) |
| 17 | new_session_path(resource) | 8 | new_session_path(resource) |
| 18 | end | 9 | end |
| 10 | |||
| 11 | def choose_random_song | ||
| 12 | ids = Scrobble.ids | ||
| 13 | if ids.empty? | ||
| 14 | @random_song = nil | ||
| 15 | else | ||
| 16 | @random_song = Scrobble.find(ids.sample) | ||
| 17 | end | ||
| 18 | end | ||
| 19 | end | 19 | end |
| diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index 8ee472e..6e80754 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb | |||
| @@ -1,10 +1,93 @@ | |||
| 1 | |||
| 2 | |||
| 1 | class BlogsController < ApplicationController | 3 | class BlogsController < ApplicationController |
| 4 | include ApplicationHelper | ||
| 5 | |||
| 6 | def summary | ||
| 7 | @blogs = Blog.where(published: true).order(published_at: :desc).paginate(page: params[:page], per_page: 10) | ||
| 8 | if not params[:page] | ||
| 9 | @main_page = true | ||
| 10 | end | ||
| 11 | end | ||
| 12 | |||
| 13 | def index | ||
| 14 | @blogs = Blog.where(published: true).order(published_at: :desc) | ||
| 15 | |||
| 16 | respond_to do |format| | ||
| 17 | format.html | ||
| 18 | format.atom | ||
| 19 | end | ||
| 20 | end | ||
| 2 | 21 | ||
| 3 | def show | 22 | def show |
| 4 | @blog = Blog.find_by_slug(params[:slug]) | 23 | @blog = Blog.find_by_slug(params[:slug]) |
| 5 | 24 | ||
| 6 | raise ActiveRecord::RecordNotFound unless @blog | 25 | raise ActiveRecord::RecordNotFound unless @blog |
| 7 | raise ActiveRecord::RecordNotFound unless @blog.published | 26 | raise ActiveRecord::RecordNotFound unless @blog.published |
| 27 | |||
| 28 | @prev = @blog.prev | ||
| 29 | @next = @blog.next | ||
| 30 | |||
| 31 | body = stripped_markdown(@blog.body) | ||
| 32 | |||
| 33 | set_meta_tags(og: { | ||
| 34 | title: @blog.title, | ||
| 35 | type: "article", | ||
| 36 | description: body[0, 299], | ||
| 37 | url: blog_url(@blog, host: "www.fourisland.com"), | ||
| 38 | article: { | ||
| 39 | published_time: @blog.published_at.iso8601, | ||
| 40 | modified_time: @blog.updated_at.iso8601 | ||
| 41 | } | ||
| 42 | }) | ||
| 43 | end | ||
| 44 | |||
| 45 | def upvote | ||
| 46 | @blog = Blog.find_by_slug(params[:slug]) | ||
| 47 | |||
| 48 | raise ActiveRecord::RecordNotFound unless @blog | ||
| 49 | raise ActiveRecord::RecordNotFound unless @blog.published | ||
| 50 | |||
| 51 | respond_to do |format| | ||
| 52 | if @blog.upvote! request.remote_ip | ||
| 53 | format.html do | ||
| 54 | flash[:notice] = "You have upvoted the blog post \"#{@blog.title}\"." | ||
| 55 | redirect_to @blog | ||
| 56 | end | ||
| 57 | format.js { render "voted" } | ||
| 58 | format.xml { head :ok } | ||
| 59 | else | ||
| 60 | format.html do | ||
| 61 | flash[:notice] = "You have already voted on the blog post \"#{@blog.title}\"." | ||
| 62 | redirect_to @blog | ||
| 63 | end | ||
| 64 | format.xml { render :xml => { :error => "Someone from your IP address has already voted on this blog post."} } | ||
| 65 | end | ||
| 66 | end | ||
| 67 | end | ||
| 68 | |||
| 69 | def downvote | ||
| 70 | @blog = Blog.find_by_slug(params[:slug]) | ||
| 71 | |||
| 72 | raise ActiveRecord::RecordNotFound unless @blog | ||
| 73 | raise ActiveRecord::RecordNotFound unless @blog.published | ||
| 74 | |||
| 75 | respond_to do |format| | ||
| 76 | if @blog.downvote! request.remote_ip | ||
| 77 | format.html do | ||
| 78 | flash[:notice] = "You have downvoted the blog post \"#{@blog.title}\"." | ||
| 79 | redirect_to @blog | ||
| 80 | end | ||
| 81 | format.js { render "voted" } | ||
| 82 | format.xml { head :ok } | ||
| 83 | else | ||
| 84 | format.html do | ||
| 85 | flash[:notice] = "You have already voted on the blog post \"#{@blog.title}\"." | ||
| 86 | redirect_to @blog | ||
| 87 | end | ||
| 88 | format.xml { render :xml => { :error => "Someone from your IP address has already voted on this blog post."} } | ||
| 89 | end | ||
| 90 | end | ||
| 8 | end | 91 | end |
| 9 | 92 | ||
| 10 | end | 93 | end |
| diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb new file mode 100644 index 0000000..31fe411 --- /dev/null +++ b/app/controllers/comments_controller.rb | |||
| @@ -0,0 +1,81 @@ | |||
| 1 | class CommentsController < ApplicationController | ||
| 2 | def create | ||
| 3 | @blog = Blog.find_by_slug(params[:slug]) | ||
| 4 | |||
| 5 | raise ActiveRecord::RecordNotFound unless @blog | ||
| 6 | raise ActiveRecord::RecordNotFound unless @blog.published | ||
| 7 | |||
| 8 | unless verify_recaptcha | ||
| 9 | flash.alert = "Error posting comment." | ||
| 10 | render "blogs/show" | ||
| 11 | return | ||
| 12 | end | ||
| 13 | |||
| 14 | @comment = @blog.comments.new(comment_params) | ||
| 15 | @comment.request_ip = request.ip | ||
| 16 | @comment.user_agent = request.user_agent | ||
| 17 | @comment.referrer = request.referrer | ||
| 18 | |||
| 19 | unless @comment.valid? | ||
| 20 | flash.alert = "Error posting comment." | ||
| 21 | render "blogs/show" | ||
| 22 | return | ||
| 23 | end | ||
| 24 | |||
| 25 | akismet_vars = %w{ HTTP_ACCEPT HTTP_ACCEPT_ENCODING } | ||
| 26 | akismet_params = { | ||
| 27 | type: "comment", | ||
| 28 | text: @comment.body, | ||
| 29 | created_at: DateTime.now, | ||
| 30 | author: @comment.username, | ||
| 31 | author_email: @comment.email, | ||
| 32 | author_url: @comment.website, | ||
| 33 | post_url: url_for(@comment.blog), | ||
| 34 | post_modified_at: @comment.blog.updated_at, | ||
| 35 | referrer: @comment.referrer, | ||
| 36 | env: request.env.slice(*akismet_vars) | ||
| 37 | } | ||
| 38 | |||
| 39 | is_spam, is_blatant = Akismet.check(@comment.request_ip, @comment.user_agent, akismet_params) | ||
| 40 | |||
| 41 | if is_blatant | ||
| 42 | # I am lying. | ||
| 43 | flash.notice = "Comment submitted successfully! It will need to be moderated before it shows up on the blog." | ||
| 44 | |||
| 45 | Global.increment_filtered_comments | ||
| 46 | else | ||
| 47 | if is_spam | ||
| 48 | @comment.status = :pending | ||
| 49 | flash_message = "Comment submitted successfully! It will need to be moderated before it shows up on the blog." | ||
| 50 | else | ||
| 51 | @comment.status = :published | ||
| 52 | flash_message = "Comment posted successfully!" | ||
| 53 | end | ||
| 54 | |||
| 55 | if @comment.save | ||
| 56 | flash.notice = flash_message | ||
| 57 | |||
| 58 | if @comment.status == :published | ||
| 59 | CommentMailer.with(comment: @comment).new_comment_email.deliver_later | ||
| 60 | |||
| 61 | if @comment.reply_to and @comment.reply_to.email != @comment.blog.user.email | ||
| 62 | CommentMailer.with(comment: @comment).reply_comment_email.deliver_later | ||
| 63 | end | ||
| 64 | else | ||
| 65 | # CommentMailer.with(comment: @comment).new_pending_comment_email.deliver_later | ||
| 66 | # I'm disabling pending comment emails, at least for now, because I am getting too many. | ||
| 67 | end | ||
| 68 | else | ||
| 69 | flash.alert = "Error posting comment." | ||
| 70 | end | ||
| 71 | end | ||
| 72 | |||
| 73 | redirect_to @comment.blog | ||
| 74 | end | ||
| 75 | |||
| 76 | private | ||
| 77 | |||
| 78 | def comment_params | ||
| 79 | params.require(:comment).permit(:username, :email, :website, :body, :reply_to_id) | ||
| 80 | end | ||
| 81 | end | ||
| diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb new file mode 100644 index 0000000..a1405b9 --- /dev/null +++ b/app/controllers/games_controller.rb | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | class GamesController < ApplicationController | ||
| 2 | helper_method :sort_column, :sort_direction | ||
| 3 | |||
| 4 | def index | ||
| 5 | @games = Game.order(sort_column + " " + sort_direction) | ||
| 6 | |||
| 7 | if params[:status] | ||
| 8 | @games = @games.where(status: params[:status]) | ||
| 9 | end | ||
| 10 | end | ||
| 11 | |||
| 12 | private | ||
| 13 | |||
| 14 | def sort_column | ||
| 15 | (params[:sort] and Game.column_names.include?(params[:sort])) ? params[:sort] : "started_on" | ||
| 16 | end | ||
| 17 | |||
| 18 | def sort_direction | ||
| 19 | (params[:dir] and %[asc desc].include?(params[:dir])) ? params[:dir] : "asc" | ||
| 20 | end | ||
| 21 | end | ||
| diff --git a/app/controllers/quotes_controller.rb b/app/controllers/quotes_controller.rb new file mode 100644 index 0000000..468f6ea --- /dev/null +++ b/app/controllers/quotes_controller.rb | |||
| @@ -0,0 +1,260 @@ | |||
| 1 | class QuotesController < ApplicationController | ||
| 2 | protect_from_forgery with: :null_session, if: -> { request.format.json? or request.format.xml? } | ||
| 3 | |||
| 4 | def index | ||
| 5 | @quote = Quote.find(310) | ||
| 6 | @qnumber = Quote.published.count | ||
| 7 | @mnumber = Quote.pending.count | ||
| 8 | end | ||
| 9 | |||
| 10 | def latest | ||
| 11 | @quotes = Quote.published.order(id: :desc).paginate(page: params[:page], per_page: 10) | ||
| 12 | |||
| 13 | respond_to do |format| | ||
| 14 | format.html { render :list } | ||
| 15 | format.json { render :json => @quotes } | ||
| 16 | format.xml { render :xml => @quotes } | ||
| 17 | format.atom { render :atom => @quotes } | ||
| 18 | end | ||
| 19 | end | ||
| 20 | |||
| 21 | def top | ||
| 22 | @quotes = Quote.published | ||
| 23 | @quotes = @quotes.where("created_at > ?", Time.new(2015,1,1)) if params[:modern] | ||
| 24 | @quotes = @quotes.order(Arel.sql("(upvotes - downvotes) DESC, id ASC")).paginate(page: params[:page], per_page: 10) | ||
| 25 | |||
| 26 | respond_to do |format| | ||
| 27 | format.html { render :list } | ||
| 28 | format.json { render :json => @quotes } | ||
| 29 | format.xml { render :xml => @quotes } | ||
| 30 | end | ||
| 31 | end | ||
| 32 | |||
| 33 | def search_form | ||
| 34 | @q = Quote.published.ransack | ||
| 35 | end | ||
| 36 | |||
| 37 | def search | ||
| 38 | @quotes = Quote.published.ransack(params[:q]).result(distinct: true).paginate(page: params[:page], per_page: 10) | ||
| 39 | |||
| 40 | respond_to do |format| | ||
| 41 | format.html { render :list } | ||
| 42 | format.json { render :json => @quotes } | ||
| 43 | format.xml { render :xml => @quotes } | ||
| 44 | end | ||
| 45 | end | ||
| 46 | |||
| 47 | def random | ||
| 48 | picked = Quote.where(state: :published).ids.sample | ||
| 49 | redirect_to quote_url(picked) | ||
| 50 | end | ||
| 51 | |||
| 52 | def tags | ||
| 53 | @tags = Quote.published.tag_counts_on(:tags) | ||
| 54 | end | ||
| 55 | |||
| 56 | def tag | ||
| 57 | @quotes = Quote.published.tagged_with(params[:id]).order(id: :desc).paginate(page: params[:page], per_page: 10) | ||
| 58 | |||
| 59 | respond_to do |format| | ||
| 60 | format.html { render :list } | ||
| 61 | format.json { render :json => @quotes } | ||
| 62 | format.xml { render :xml => @quotes } | ||
| 63 | end | ||
| 64 | end | ||
| 65 | |||
| 66 | def stats | ||
| 67 | @months = [] | ||
| 68 | 0.upto(11) do |i| | ||
| 69 | month = i.months.ago.month | ||
| 70 | year = i.months.ago.year | ||
| 71 | beginning = i.months.ago.beginning_of_month.beginning_of_day | ||
| 72 | endtime = i.months.ago.end_of_month.end_of_day | ||
| 73 | quotes = Quote.published.where("created_at >= :start_date AND created_at <= :end_date", { :start_date => beginning, :end_date => endtime }).all | ||
| 74 | @months[11-i] = { :name => Date::MONTHNAMES[month], :number => quotes.count } | ||
| 75 | end | ||
| 76 | |||
| 77 | #@months2 = [] | ||
| 78 | #i = 0 | ||
| 79 | #while true | ||
| 80 | # month = i.months.ago.month | ||
| 81 | # year = i.months.ago.year | ||
| 82 | # beginning = i.months.ago.beginning_of_month.beginning_of_day | ||
| 83 | # endtime = i.months.ago.end_of_month.end_of_day | ||
| 84 | # quotes = Quote.where("created_at <= :end_date", { :end_date => endtime }).all | ||
| 85 | # @months2[i] = { :name => i.months.ago.strftime("%Y-%m"), :number => quotes.count } | ||
| 86 | # | ||
| 87 | # break if month == 4 and year == 2008 | ||
| 88 | # | ||
| 89 | # i=i+1 | ||
| 90 | #end | ||
| 91 | # | ||
| 92 | #@months2.reverse! | ||
| 93 | # | ||
| 94 | #@upvotes = Vote.where(upvote: 1, votable_type: :quote).count | ||
| 95 | #@downvotes = Vote.where(upvote: 0, votable_type: :quote).count | ||
| 96 | |||
| 97 | hardcoded_aliases = { | ||
| 98 | "hatkirby": "Hatkirby", | ||
| 99 | "Gryphic": "Drifty", | ||
| 100 | "DriftyBeyond": "Drifty", | ||
| 101 | "Starla": "Hatkirby", | ||
| 102 | "BleuM937": "Bluemonkey", | ||
| 103 | "BlueM937": "Bluemonkey", | ||
| 104 | "Drifty1": "Drifty", | ||
| 105 | "Starla Insigna": "Hatkirby", | ||
| 106 | "Starla Alice Insigna": "Hatkirby", | ||
| 107 | "tamasys": "Tamasys", | ||
| 108 | "Student 2": "Student", | ||
| 109 | "Старла Эппрет": "Hatkirby", | ||
| 110 | "Girl Without Slipper": "Hatkirby", | ||
| 111 | "Actias": "Drifty", | ||
| 112 | "Salaboy123": "Tamasys", | ||
| 113 | "TaMACsys": "Tamasys", | ||
| 114 | "RealityCheck": "Drifty", | ||
| 115 | "Student 3": "Student", | ||
| 116 | "toothpastecanyon": "ToothPasteCanyon", | ||
| 117 | "eka-caesium": "eka_caesium", | ||
| 118 | } | ||
| 119 | |||
| 120 | person_count = {} | ||
| 121 | Quote.published.each do |quote| | ||
| 122 | person_in_quote = {} | ||
| 123 | |||
| 124 | quote.content.split("\n").each do |line| | ||
| 125 | check = line.chomp | ||
| 126 | hi = /([\(\[][^\]\)]*[\]\)] )?([^:]*): /.match(check) | ||
| 127 | if hi and hi[2] then | ||
| 128 | person = hi[2] | ||
| 129 | if hardcoded_aliases.has_key? person.intern | ||
| 130 | person = hardcoded_aliases[person.intern] | ||
| 131 | end | ||
| 132 | unless person_in_quote.has_key? person | ||
| 133 | person_count[person] ||= 0 | ||
| 134 | person_count[person] += 1 | ||
| 135 | person_in_quote[person] = 1 | ||
| 136 | end | ||
| 137 | end | ||
| 138 | end | ||
| 139 | end | ||
| 140 | |||
| 141 | @by_speaker = person_count.to_a.sort_by {|hi| hi[1]}.reverse.take(20) | ||
| 142 | end | ||
| 143 | |||
| 144 | def show | ||
| 145 | @quote = Quote.published.find(params[:id]) | ||
| 146 | |||
| 147 | set_meta_tags(og: { | ||
| 148 | title: "Quote \##{@quote.id}", | ||
| 149 | type: "article", | ||
| 150 | description: (@quote.content.length <= 300 ? @quote.content : @quote.content[0..299]), | ||
| 151 | url: quote_url(@quote, host: "www.fourisland.com"), | ||
| 152 | article: { | ||
| 153 | published_time: @quote.created_at.iso8601, | ||
| 154 | modified_time: @quote.updated_at.iso8601 | ||
| 155 | } | ||
| 156 | }) | ||
| 157 | |||
| 158 | respond_to do |format| | ||
| 159 | format.html | ||
| 160 | format.json { render :json => @quote } | ||
| 161 | format.xml { render :xml => @quote } | ||
| 162 | end | ||
| 163 | end | ||
| 164 | |||
| 165 | def new | ||
| 166 | @quote = Quote.new | ||
| 167 | end | ||
| 168 | |||
| 169 | def create | ||
| 170 | @quote = Quote.new(quote_params) | ||
| 171 | @quote.submitter = nil if @quote.submitter.empty? | ||
| 172 | |||
| 173 | unless @quote.valid? | ||
| 174 | flash.alert = "Error submitting quote." | ||
| 175 | |||
| 176 | respond_to do |format| | ||
| 177 | format.html { render :new } | ||
| 178 | format.json { render json: { error: "Error submitting quote." }, status: :bad_request } | ||
| 179 | format.xml { render xml: { error: "Error submitting quote." }, status: :bad_request } | ||
| 180 | end | ||
| 181 | |||
| 182 | return | ||
| 183 | end | ||
| 184 | |||
| 185 | if user_signed_in? | ||
| 186 | @quote.state = :published | ||
| 187 | @quote.save! | ||
| 188 | |||
| 189 | flash[:notice] = "Thank you for submitting your quote!" | ||
| 190 | respond_to do |format| | ||
| 191 | format.html { redirect_to @quote } | ||
| 192 | format.json { render json: @quote } | ||
| 193 | format.xml { render xml: @quote } | ||
| 194 | end | ||
| 195 | else | ||
| 196 | @quote.state = :pending | ||
| 197 | @quote.save! | ||
| 198 | |||
| 199 | # hacky little thing to reduce the number of emails I get | ||
| 200 | unless @quote.submitter == "hatkirby" | ||
| 201 | QuoteMailer.with(quote: @quote).pending_quote_email.deliver_later | ||
| 202 | end | ||
| 203 | |||
| 204 | flash[:notice] = "Your quote has been submitted and is pending moderation." | ||
| 205 | respond_to do |format| | ||
| 206 | format.html { redirect_to new_quote_url } | ||
| 207 | format.json { render json: @quote } | ||
| 208 | format.xml { render xml: @quote } | ||
| 209 | end | ||
| 210 | end | ||
| 211 | end | ||
| 212 | |||
| 213 | def upvote | ||
| 214 | @quote = Quote.published.find(params[:id]) | ||
| 215 | |||
| 216 | respond_to do |format| | ||
| 217 | if @quote.upvote! request.remote_ip | ||
| 218 | format.html do | ||
| 219 | flash[:notice] = "You have upvoted Quote \"#{@quote.id}\"." | ||
| 220 | redirect_to @quote | ||
| 221 | end | ||
| 222 | format.js { render "voted" } | ||
| 223 | format.xml { head :ok } | ||
| 224 | else | ||
| 225 | format.html do | ||
| 226 | flash[:notice] = "You have already voted on Quote \"#{@quote.id}\"." | ||
| 227 | redirect_to @quote | ||
| 228 | end | ||
| 229 | format.xml { render :xml => { :error => "Someone from your IP address has already voted on this quote."} } | ||
| 230 | end | ||
| 231 | end | ||
| 232 | end | ||
| 233 | |||
| 234 | def downvote | ||
| 235 | @quote = Quote.published.find(params[:id]) | ||
| 236 | |||
| 237 | respond_to do |format| | ||
| 238 | if @quote.downvote! request.remote_ip | ||
| 239 | format.html do | ||
| 240 | flash[:notice] = "You have downvoted Quote \"#{@quote.id}\"." | ||
| 241 | redirect_to @quote | ||
| 242 | end | ||
| 243 | format.js { render "voted" } | ||
| 244 | format.xml { head :ok } | ||
| 245 | else | ||
| 246 | format.html do | ||
| 247 | flash[:notice] = "You have already voted on Quote \"#{@quote.id}\"." | ||
| 248 | redirect_to @quote | ||
| 249 | end | ||
| 250 | format.xml { render :xml => { :error => "Someone from your IP address has already voted on this quote."} } | ||
| 251 | end | ||
| 252 | end | ||
| 253 | end | ||
| 254 | |||
| 255 | private | ||
| 256 | |||
| 257 | def quote_params | ||
| 258 | params.require(:quote).permit(:content, :notes, :submitter, :tag_list) | ||
| 259 | end | ||
| 260 | end | ||
| diff --git a/app/controllers/streams_controller.rb b/app/controllers/streams_controller.rb index 664f533..ec4cee8 100644 --- a/app/controllers/streams_controller.rb +++ b/app/controllers/streams_controller.rb | |||
| @@ -1,7 +1,26 @@ | |||
| 1 | class StreamsController < ApplicationController | 1 | class StreamsController < ApplicationController |
| 2 | include ApplicationHelper | ||
| 3 | |||
| 4 | def index | ||
| 5 | @streams = Stream.order(latest_post_at: :desc).paginate(page: params[:page], per_page: 10) | ||
| 6 | end | ||
| 2 | 7 | ||
| 3 | def show | 8 | def show |
| 4 | @stream = Stream.find_by_slug(params[:slug]) | 9 | @stream = Stream.find_by_slug(params[:slug]) |
| 10 | @updates = @stream.updates.paginate(page: params[:page], per_page: 10) | ||
| 11 | |||
| 12 | body = stripped_markdown(@stream.body) | ||
| 13 | |||
| 14 | set_meta_tags(og: { | ||
| 15 | title: @stream.title, | ||
| 16 | type: "article", | ||
| 17 | description: body[0, 299], | ||
| 18 | url: stream_url(@stream, host: "www.fourisland.com"), | ||
| 19 | article: { | ||
| 20 | published_time: @stream.created_at.iso8601, | ||
| 21 | modified_time: @stream.latest_post_at.iso8601 | ||
| 22 | } | ||
| 23 | }) | ||
| 5 | end | 24 | end |
| 6 | 25 | ||
| 7 | end | 26 | end |
| diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb new file mode 100644 index 0000000..355706b --- /dev/null +++ b/app/controllers/tags_controller.rb | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | class TagsController < ApplicationController | ||
| 2 | |||
| 3 | def index | ||
| 4 | @tags = Blog.tag_counts | ||
| 5 | end | ||
| 6 | |||
| 7 | def show | ||
| 8 | @tag_name = params[:name] | ||
| 9 | @blogs = Blog.tagged_with(params[:name]).where(published: true).order(published_at: :desc).paginate(page: params[:page], per_page: 10) | ||
| 10 | end | ||
| 11 | |||
| 12 | def suggest | ||
| 13 | @tags = ActsAsTaggableOn::Tag.pluck(:name).select do |tag| | ||
| 14 | tag.starts_with? params[:term] | ||
| 15 | end | ||
| 16 | |||
| 17 | render json: @tags | ||
| 18 | end | ||
| 19 | |||
| 20 | end | ||
| diff --git a/app/controllers/webmentions_controller.rb b/app/controllers/webmentions_controller.rb new file mode 100644 index 0000000..d8aefc7 --- /dev/null +++ b/app/controllers/webmentions_controller.rb | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | require 'microformats' | ||
| 2 | require 'webmention' | ||
| 3 | |||
| 4 | class WebmentionsController < ApplicationController | ||
| 5 | skip_before_action :verify_authenticity_token | ||
| 6 | |||
| 7 | def create | ||
| 8 | source = params[:source] | ||
| 9 | target = params[:target] | ||
| 10 | |||
| 11 | verification = Webmention.verify_webmention(source, target) | ||
| 12 | unless verification.verified? | ||
| 13 | render json: { error: "Webmention could not be verified." } | ||
| 14 | return | ||
| 15 | end | ||
| 16 | |||
| 17 | target_parts = URI.parse(target).path.split("/").drop(1) | ||
| 18 | |||
| 19 | if target_parts[0] == "blog" | ||
| 20 | blog = Blog.find_by_slug(target_parts[1]) | ||
| 21 | |||
| 22 | raise ActiveRecord::RecordNotFound unless blog | ||
| 23 | raise ActiveRecord::RecordNotFound unless blog.published | ||
| 24 | |||
| 25 | response = Webmention::Request.get(source) | ||
| 26 | parsed = Microformats.parse(response.body.to_s) | ||
| 27 | |||
| 28 | if parsed.entry.properties.to_hash.include?("like-of") and parsed.entry.like_of(:all).map(&:to_s).include? target | ||
| 29 | blog.like!(parsed.entry.author.url, parsed.entry.author.name) | ||
| 30 | end | ||
| 31 | end | ||
| 32 | |||
| 33 | head :ok | ||
| 34 | end | ||
| 35 | |||
| 36 | end | ||
