diff --git a/.gitignore b/.gitignore index 036746aa2..e6b6b47ec 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ log/*.log tmp/**/* public/data vendor/cache/*.gem +.sass-cache diff --git a/.sass-cache/b118d4c1b1aae4efe3003ca592302b34dd7f51b1/default.scssc b/.sass-cache/b118d4c1b1aae4efe3003ca592302b34dd7f51b1/default.scssc new file mode 100644 index 000000000..757869c64 Binary files /dev/null and b/.sass-cache/b118d4c1b1aae4efe3003ca592302b34dd7f51b1/default.scssc differ diff --git a/Gemfile b/Gemfile index e6167fe80..81b57ebfe 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,3 @@ -# Edit this Gemfile to bundle your application's dependencies. source 'http://gemcutter.org' group :test do @@ -8,8 +7,13 @@ group :test do gem "faker" end -gem "rails", "3.0.0.rc2" +gem "rails", "3.0.0" gem "pg" gem "memcache-client", :require => "memcache" gem "imagesize", :require => "image_size" gem "delayed_job" +gem "super_exception_notifier" +gem "haml" +gem "simple_form" + +gem "will_paginate", :git => "http://github.com/mislav/will_paginate.git", :branch => "rails3" diff --git a/Gemfile.lock b/Gemfile.lock index 4c69a0f98..e01b86639 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,13 +1,20 @@ +GIT + remote: http://github.com/mislav/will_paginate.git + revision: 3615938 + branch: rails3 + specs: + will_paginate (3.0.pre2) + GEM remote: http://gemcutter.org/ specs: abstract (1.0.0) - actionmailer (3.0.0.rc2) - actionpack (= 3.0.0.rc2) + actionmailer (3.0.0) + actionpack (= 3.0.0) mail (~> 2.2.5) - actionpack (3.0.0.rc2) - activemodel (= 3.0.0.rc2) - activesupport (= 3.0.0.rc2) + actionpack (3.0.0) + activemodel (= 3.0.0) + activesupport (= 3.0.0) builder (~> 2.1.2) erubis (~> 2.6.6) i18n (~> 0.4.1) @@ -15,21 +22,21 @@ GEM rack-mount (~> 0.6.12) rack-test (~> 0.5.4) tzinfo (~> 0.3.23) - activemodel (3.0.0.rc2) - activesupport (= 3.0.0.rc2) + activemodel (3.0.0) + activesupport (= 3.0.0) builder (~> 2.1.2) i18n (~> 0.4.1) - activerecord (3.0.0.rc2) - activemodel (= 3.0.0.rc2) - activesupport (= 3.0.0.rc2) - arel (~> 1.0.0.rc1) + activerecord (3.0.0) + activemodel (= 3.0.0) + activesupport (= 3.0.0) + arel (~> 1.0.0) tzinfo (~> 0.3.23) - activeresource (3.0.0.rc2) - activemodel (= 3.0.0.rc2) - activesupport (= 3.0.0.rc2) - activesupport (3.0.0.rc2) - arel (1.0.0.rc1) - activesupport (>= 3.0.0.beta) + activeresource (3.0.0) + activemodel (= 3.0.0) + activesupport (= 3.0.0) + activesupport (3.0.0) + arel (1.0.1) + activesupport (~> 3.0.0) builder (2.1.2) daemons (1.1.0) delayed_job (2.0.3) @@ -38,6 +45,7 @@ GEM abstract (>= 1.0.0) factory_girl (1.3.1) faker (0.3.1) + haml (3.0.21) i18n (0.4.1) imagesize (0.1.1) mail (2.2.5) @@ -55,21 +63,25 @@ GEM rack (>= 1.0.0) rack-test (0.5.4) rack (>= 1.0) - rails (3.0.0.rc2) - actionmailer (= 3.0.0.rc2) - actionpack (= 3.0.0.rc2) - activerecord (= 3.0.0.rc2) - activeresource (= 3.0.0.rc2) - activesupport (= 3.0.0.rc2) - bundler (>= 1.0.0.rc.6) - railties (= 3.0.0.rc2) - railties (3.0.0.rc2) - actionpack (= 3.0.0.rc2) - activesupport (= 3.0.0.rc2) - rake (>= 0.8.3) + rails (3.0.0) + actionmailer (= 3.0.0) + actionpack (= 3.0.0) + activerecord (= 3.0.0) + activeresource (= 3.0.0) + activesupport (= 3.0.0) + bundler (~> 1.0.0) + railties (= 3.0.0) + railties (3.0.0) + actionpack (= 3.0.0) + activesupport (= 3.0.0) + rake (>= 0.8.4) thor (~> 0.14.0) rake (0.8.7) shoulda (2.11.1) + simple_form (1.2.2) + super_exception_notifier (3.0.13) + actionmailer + rake thor (0.14.0) treetop (1.4.8) polyglot (>= 0.3.1) @@ -82,9 +94,13 @@ DEPENDENCIES delayed_job factory_girl faker + haml imagesize memcache-client mocha pg - rails (= 3.0.0.rc2) + rails (= 3.0.0) shoulda + simple_form + super_exception_notifier + will_paginate! diff --git a/app/controllers/admin/posts_controller.rb b/app/controllers/admin/posts_controller.rb new file mode 100644 index 000000000..70c6c2ff5 --- /dev/null +++ b/app/controllers/admin/posts_controller.rb @@ -0,0 +1,6 @@ +module Admin + class PostsController + def edit + end + end +end diff --git a/app/controllers/advertisement_hits_controller.rb b/app/controllers/advertisement_hits_controller.rb new file mode 100644 index 000000000..4fce30c13 --- /dev/null +++ b/app/controllers/advertisement_hits_controller.rb @@ -0,0 +1,12 @@ +class AdvertisementHitsController < ApplicationController + def create + advertisement = Advertisement.find(params[:id]) + advertisement.hits.create(:ip_addr => request.remote_ip) + redirect_to advertisement.referral_url + end + +protected + def set_title + @page_title = Danbooru.config.app_name + "/advertisements" + end +end diff --git a/app/controllers/advertisements_controller.rb b/app/controllers/advertisements_controller.rb index fa66d1ff1..4f2a56dc3 100644 --- a/app/controllers/advertisements_controller.rb +++ b/app/controllers/advertisements_controller.rb @@ -1,22 +1,60 @@ class AdvertisementsController < ApplicationController def new + @advertisement = Advertisement.new( + :ad_type => "vertical", + :status => "active" + ) end def edit + @advertisement = Advertisement.find(params[:id]) end def index + @advertisements = Advertisement.all + + if params[:start_date] + @start_date = Date.parse(params[:start_date]) + else + @start_date = 1.month.ago.to_date + end + + if params[:end_date] + @end_date = Date.parse(params[:end_date]) + else + @end_date = Date.today + end end def show + @advertisement = Advertisement.find(params[:id]) end def create + @advertisement = Advertisement.new(params[:advertisement]) + if @advertisement.save + flash[:notice] = "Advertisement created" + redirect_to advertisement_path(@advertisement) + else + flash[:notice] = "There were errors" + render :action => "new" + end end def update + @advertisement = Advertisement.find(params[:id]) + if @advertisement.update_attributes(params[:advertisement]) + flash[:notice] = "Advertisement updated" + redirect_to advertisement_path(@advertisement) + else + flash[:notice] = "There were errors" + render :action => "edit" + end end def destroy + @advertisement = Advertisement.find(params[:id]) + @advertisement.destroy + redirect_to advertisements_path end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 77e4d2449..117d1b007 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,6 +3,7 @@ class ApplicationController < ActionController::Base before_filter :set_current_user after_filter :reset_current_user before_filter :initialize_cookies + before_filter :set_title layout "default" protected @@ -65,4 +66,8 @@ protected cookies["blacklisted_tags"] = CurrentUser.user.blacklisted_tags end end + + def set_title + @page_title = Danbooru.config.app_name + "/#{params[:controller]}" + end end diff --git a/app/controllers/artist_versions_controller.rb b/app/controllers/artist_versions_controller.rb index f0c67eaa3..2f92c4022 100644 --- a/app/controllers/artist_versions_controller.rb +++ b/app/controllers/artist_versions_controller.rb @@ -1,7 +1,9 @@ class ArtistVersionsController < ApplicationController - def index - end + respond_to :html, :xml, :json - def show - end + def index + @artist = Artist.find(params[:artist_id]) + @artist_versions = ArtistVersion.paginate :order => "version desc", :per_page => 25, :page => params[:page], :conditions => ["artist_id = ?", @artist.id] + respond_with(@artist_versions) + end end diff --git a/app/controllers/artists_controller.rb b/app/controllers/artists_controller.rb index d13fe52c9..e24ce9386 100644 --- a/app/controllers/artists_controller.rb +++ b/app/controllers/artists_controller.rb @@ -1,4 +1,6 @@ class ArtistsController < ApplicationController + before_filter :member_only + def new @artist = Artist.new_with_defaults(params) end @@ -8,23 +10,45 @@ class ArtistsController < ApplicationController end def index - order = params[:order] == "date" ? "updated_at DESC" : "name" - limit = params[:limit] || 50 - @artists = Artist.paginate(Artist.build_relation()) + @artists = Artist.build_relation(params).paginate(:per_page => 25, :page => params[:page]) end def show + @artist = Artist.find(params[:id]) + + if @artist + @posts = Danbooru.config.select_posts_visible_to_user(CurrentUser.user, Post.find_by_tags(@artist.name, :limit => 6)) + else + redirect_to new_artist_path(params[:name]) + end end def create + @artist = Artist.create(params[:artist]) + + if @artist.errors.empty? + redirect_to artist_path(@artist) + else + flash[:notice] = "There were errors" + render :action => "new" + end end def update + @artist = Artist.find(params[:id]) + @artist.update_attributes(params[:artist]) + + if @artist.errors.empty? + redirect_to artist_path(@artist) + else + flash[:notice] = "There were errors" + render :action => "edit" + end end - def destroy - end - def revert + @artist = Artist.find(params[:id]) + @artist.revert_to!(params[:version]) + redirect_to artist_path(@artist) end end diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 672437795..a8c8fad85 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -14,7 +14,7 @@ class CommentsController < ApplicationController def create @comment = Comment.new(params[:comment]) @comment.post_id = params[:comment][:post_id] - @comment.creator_id = @current_user.id + @comment.creator_id = CurrentUser.user.id @comment.ip_addr = request.remote_ip @comment.score = 0 @comment.save diff --git a/app/controllers/favorites_controller.rb b/app/controllers/favorites_controller.rb index 5b5cff9c5..83f9506fe 100644 --- a/app/controllers/favorites_controller.rb +++ b/app/controllers/favorites_controller.rb @@ -1,14 +1,14 @@ class FavoritesController < ApplicationController def create @favorite = Favorite.create( - :user_id => @current_user.id, + :user_id => CurrentUser.user.id, :post_id => params[:favorite][:post_id] ) end def destroy Favorite.destroy( - :user_id => @current_user.id, + :user_id => CurrentUser.user.id, :post_id => params[:favorite][:post_id] ) end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 439f79801..051f10e28 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -4,10 +4,8 @@ class PostsController < ApplicationController respond_to :html, :xml, :json def index - @post_set = PostSet.new(params[:tags], params[:page], @current_user, params[:before_id]) - respond_with(@post_set) do |fmt| - fmt.js - end + @post_set = PostSet.new(params[:tags], params[:page], params[:before_id]) + respond_with(@post_set) end def show diff --git a/app/controllers/tag_aliases_controller.rb b/app/controllers/tag_aliases_controller.rb index c1e209b0a..3c384b711 100644 --- a/app/controllers/tag_aliases_controller.rb +++ b/app/controllers/tag_aliases_controller.rb @@ -16,4 +16,7 @@ class TagAliasesController < ApplicationController def destroy end + + def destroy_cache + end end diff --git a/app/controllers/uploads_controller.rb b/app/controllers/uploads_controller.rb index 0033546c6..880904c87 100644 --- a/app/controllers/uploads_controller.rb +++ b/app/controllers/uploads_controller.rb @@ -10,7 +10,7 @@ class UploadsController < ApplicationController end def index - @uploads = Upload.where("uploader_id = ?", @current_user.id).includes(:uploader).order("uploads.id desc").limit(10) + @uploads = Upload.where("uploader_id = ?", CurrentUser.user.id).includes(:uploader).order("uploads.id desc").limit(10) respond_with(@uploads) end @@ -19,7 +19,15 @@ class UploadsController < ApplicationController end def create - @upload = Upload.create(params[:upload].merge(:uploader_id => @current_user.id, :uploader_ip_addr => request.remote_ip)) + @upload = Upload.create(params[:upload]) respond_with(@upload) end + + def update + @upload = Upload.find(params[:id]) + @upload.process! + render :update do |page| + page.reload + end + end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 56086bb25..85b0c1f25 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,6 +1,6 @@ class UsersController < ApplicationController respond_to :html, :xml, :json - before_filter :member_only, :only => [:edit, :show, :update, :destroy, :create] + before_filter :member_only, :only => [:edit, :show, :update, :destroy] def new @user = User.new @@ -8,8 +8,8 @@ class UsersController < ApplicationController def edit @user = User.find(params[:id]) - unless @current_user.is_admin? - @user = @current_user + unless CurrentUser.user.is_admin? + @user = CurrentUser.user end end @@ -23,10 +23,13 @@ class UsersController < ApplicationController def create @user = User.new(params[:user].merge(:ip_addr => request.remote_ip)) if @user.save - flash[:notice] = "You have succesfully created a new account." + flash[:notice] = "You have succesfully created a new account" session[:user_id] = @user.id + redirect_to user_path(@user) + else + flash[:notice] = "There were errors" + render :action => "new" end - respond_with(@user) end def update diff --git a/app/helpers/advertisements_helper.rb b/app/helpers/advertisements_helper.rb index a7d3aa99c..08b0218fa 100644 --- a/app/helpers/advertisements_helper.rb +++ b/app/helpers/advertisements_helper.rb @@ -1,2 +1,28 @@ module AdvertisementsHelper + def render_advertisement(ad_type) + if Danbooru.config.can_user_see_ads?(CurrentUser.user) + @advertisement = Advertisement.find(:first, :conditions => ["ad_type = ? AND status = 'active'", ad_type], :order => "random()") + content_tag( + "div", + link_to_remote( + image_tag( + @advertisement.image_url, + :alt => "Advertisement", + :width => @advertisement.width, + :height => @advertisement.height + ), + advertisement_hit_path(:advertisement_id => @advertisement.id), + :style => "margin-bottom: 1em;" + ) + ) + else + "" + end + end + + def render_rss_advertisement + if Danbooru.config.can_user_see_ads?(CurrentUser.user) + render :partial => "static/jlist_rss_ads" + end + end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c0157128f..6b53b9c83 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -12,6 +12,16 @@ module ApplicationHelper def format_text(text, options = {}) DText.parse(text) end + + def error_messages_for(instance_name) + instance = instance_variable_get("@#{instance_name}") + + if instance.errors.any? + %{
}.html_safe + else + "" + end + end protected def nav_link_match(controller, url) diff --git a/app/helpers/artists_helper.rb b/app/helpers/artists_helper.rb index 52d21cb9a..e40c82124 100644 --- a/app/helpers/artists_helper.rb +++ b/app/helpers/artists_helper.rb @@ -1,2 +1,17 @@ module ArtistsHelper + def link_to_artist(name) + artist = Artist.find_by_name(name) + + if artist + link_to(artist.name, artist_path(artist)) + else + link_to(name, new_artist_path(:name => name)) + " " + content_tag("span", "*", :class => "new-artist") + end + end + + def link_to_artists(names) + names.map do |name| + link_to_artist(name) + end.join(", ").html_safe + end end diff --git a/app/logical/anonymous_user.rb b/app/logical/anonymous_user.rb index dfb3722f2..eb352dac4 100644 --- a/app/logical/anonymous_user.rb +++ b/app/logical/anonymous_user.rb @@ -108,6 +108,10 @@ class AnonymousUser "medium" end + def blacklisted_tags + [] + end + %w(member banned privileged contributor janitor moderator admin).each do |name| define_method("is_#{name}?") do false diff --git a/app/logical/current_user.rb b/app/logical/current_user.rb index 88551f0ae..11699b1a9 100644 --- a/app/logical/current_user.rb +++ b/app/logical/current_user.rb @@ -5,7 +5,7 @@ class CurrentUser self.user = user self.ip_addr = ip_addr - + begin yield ensure @@ -13,7 +13,7 @@ class CurrentUser self.ip_addr = old_ip_addr end end - + def self.user=(user) Thread.current[:current_user] = user end diff --git a/app/logical/d_text.rb b/app/logical/d_text.rb index 3ec2b8b9c..3c25ff6eb 100644 --- a/app/logical/d_text.rb +++ b/app/logical/d_text.rb @@ -2,52 +2,62 @@ require 'cgi' class DText def self.parse_inline(str, options = {}) - str = str.gsub(/&/, "&") - str.gsub!(/, "<") - str.gsub!(/>/, ">") - str.gsub!(/\[\[.+?\]\]/m) do |tag| - tag = tag[2..-3] - if tag =~ /^(.+?)\|(.+)$/ - tag = $1 - name = $2 - '' + name + '' - else - '' + tag + '' - end - end - str.gsub!(/\{\{.+?\}\}/m) do |tag| - tag = tag[2..-3] - '' + tag + '' - end - str.gsub!(/[Pp]ost #(\d+)/, 'post #\1') - str.gsub!(/[Ff]orum #(\d+)/, 'forum #\1') - str.gsub!(/[Cc]omment #(\d+)/, 'comment #\1') - str.gsub!(/[Pp]ool #(\d+)/, 'pool #\1') + str = parse_aliased_wiki_links(str) + str = parse_wiki_links(str) + str = parse_post_links(str) + str = parse_id_links(str) + str.gsub!(/\n/m, "' + html << 'There is no wiki for this tag.' + html << ' ' + html << template.link_to("Create a new page", template.new_wiki_page_path(:title => post_set.tags)) + html << '.' + html << '
' + else + html << '