From f051e04550f35343cb0ef5f6128fd699f9bedd5a Mon Sep 17 00:00:00 2001 From: albert Date: Fri, 8 Oct 2010 18:42:26 -0400 Subject: [PATCH] sync --- .gitignore | 1 + .../default.scssc | Bin 0 -> 16904 bytes Gemfile | 8 +- Gemfile.lock | 76 ++- app/controllers/admin/posts_controller.rb | 6 + .../advertisement_hits_controller.rb | 12 + app/controllers/advertisements_controller.rb | 38 ++ app/controllers/application_controller.rb | 5 + app/controllers/artist_versions_controller.rb | 10 +- app/controllers/artists_controller.rb | 36 +- app/controllers/comments_controller.rb | 2 +- app/controllers/favorites_controller.rb | 4 +- app/controllers/posts_controller.rb | 6 +- app/controllers/tag_aliases_controller.rb | 3 + app/controllers/uploads_controller.rb | 12 +- app/controllers/users_controller.rb | 13 +- app/helpers/advertisements_helper.rb | 26 + app/helpers/application_helper.rb | 10 + app/helpers/artists_helper.rb | 15 + app/logical/anonymous_user.rb | 4 + app/logical/current_user.rb | 4 +- app/logical/d_text.rb | 90 +-- app/logical/post_set.rb | 9 +- app/logical/remote_server.rb | 35 ++ app/models/advertisement.rb | 35 +- app/models/advertisement_hit.rb | 2 + app/models/artist.rb | 80 ++- app/models/post.rb | 15 + app/models/removed_post.rb | 4 + app/models/tag_alias.rb | 9 +- app/models/upload.rb | 25 +- app/models/wiki_page.rb | 20 +- app/presenters/post_presenter.rb | 10 +- app/presenters/post_set_presenter.rb | 34 +- app/views/advertisements/_form.html.erb | 28 + .../_secondary_nav_links.html.erb | 11 + app/views/advertisements/edit.html.erb | 3 + app/views/advertisements/index.html.erb | 45 ++ app/views/advertisements/new.html.erb | 3 + app/views/advertisements/show.html.erb | 7 + app/views/artist_versions/index.html.erb | 46 ++ app/views/artists/_form.html.erb | 41 ++ app/views/artists/_search.html.erb | 6 + .../artists/_secondary_nav_links.html.erb | 12 + app/views/artists/edit.html.erb | 3 + app/views/artists/index.html.erb | 35 ++ app/views/artists/new.html.erb | 5 + app/views/artists/show.html.erb | 90 +++ .../comments/partials/index/_list.html.erb | 2 +- .../comments/partials/show/_comment.html.erb | 2 +- app/views/layouts/default.html.erb | 26 +- app/views/posts/index.html.erb | 10 +- .../common/_secondary_links.html.erb} | 2 +- app/views/posts/partials/show/_edit.html.erb | 4 +- app/views/posts/partials/show/_image.html.erb | 2 +- .../posts/partials/show/_options.html.erb | 4 +- app/views/posts/show.html.erb | 6 +- app/views/sessions/new.html.erb | 65 +- app/views/uploads/show.html.erb | 7 +- app/views/users/_secondary_nav_links.html.erb | 15 + app/views/users/new.html.erb | 178 +++--- app/views/users/show.html.erb | 11 +- config/danbooru_default_config.rb | 33 +- config/routes.rb | 15 +- db/development_structure.sql | 64 +- db/migrate/20100214080549_create_artists.rb | 1 + .../images/advertisements/1283209929934.jpg | Bin 0 -> 34338 bytes public/javascripts/compiled/base.js | 505 ++++++++++++++++ public/javascripts/compiled/default.js | 563 ++++++++++++++++++ .../compiled/{posts/index.js => posts.js} | 96 +++ public/javascripts/src/app/application.js | 38 ++ public/javascripts/src/{ => app}/cookie.js | 0 .../src/{posts/index.js => app/posts.js} | 32 +- .../src/{uploads/new.js => app/uploads.js} | 0 public/javascripts/src/app/users.js | 13 + public/javascripts/src/application.js | 96 --- public/javascripts/src/lib/rails.js | 285 ++++----- public/stylesheets/compiled/default.css | 227 +++++++ .../{default.css => src/default.scss} | 186 ++++-- script/compile_javascripts | 12 - script/custom/compile_assets | 4 + script/custom/compile_javascripts | 10 + script/custom/compile_stylesheets | 4 + test/factories/artist.rb | 2 - test/factories/tag_alias.rb | 3 +- test/factories/tag_implication.rb | 3 +- test/unit/artist_test.rb | 36 +- test/unit/tag_implication_test.rb | 8 +- 88 files changed, 2865 insertions(+), 699 deletions(-) create mode 100644 .sass-cache/b118d4c1b1aae4efe3003ca592302b34dd7f51b1/default.scssc create mode 100644 app/controllers/admin/posts_controller.rb create mode 100644 app/controllers/advertisement_hits_controller.rb create mode 100644 app/logical/remote_server.rb create mode 100644 app/views/advertisements/_form.html.erb create mode 100644 app/views/advertisements/_secondary_nav_links.html.erb create mode 100644 app/views/advertisements/edit.html.erb create mode 100644 app/views/advertisements/index.html.erb create mode 100644 app/views/advertisements/new.html.erb create mode 100644 app/views/advertisements/show.html.erb create mode 100644 app/views/artist_versions/index.html.erb create mode 100644 app/views/artists/_form.html.erb create mode 100644 app/views/artists/_search.html.erb create mode 100644 app/views/artists/_secondary_nav_links.html.erb create mode 100644 app/views/artists/edit.html.erb create mode 100644 app/views/artists/index.html.erb create mode 100644 app/views/artists/new.html.erb create mode 100644 app/views/artists/show.html.erb rename app/views/posts/{_common_secondary_nav_links.html.erb => partials/common/_secondary_links.html.erb} (87%) create mode 100644 app/views/users/_secondary_nav_links.html.erb create mode 100644 public/images/advertisements/1283209929934.jpg create mode 100644 public/javascripts/compiled/default.js rename public/javascripts/compiled/{posts/index.js => posts.js} (72%) create mode 100644 public/javascripts/src/app/application.js rename public/javascripts/src/{ => app}/cookie.js (100%) rename public/javascripts/src/{posts/index.js => app/posts.js} (90%) rename public/javascripts/src/{uploads/new.js => app/uploads.js} (100%) create mode 100644 public/javascripts/src/app/users.js delete mode 100644 public/javascripts/src/application.js create mode 100644 public/stylesheets/compiled/default.css rename public/stylesheets/{default.css => src/default.scss} (59%) delete mode 100755 script/compile_javascripts create mode 100755 script/custom/compile_assets create mode 100755 script/custom/compile_javascripts create mode 100755 script/custom/compile_stylesheets 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 0000000000000000000000000000000000000000..757869c647bf528c65a3185ebe3b8602d3852b98 GIT binary patch literal 16904 zcmXrkGte_KRM2qFNh~g|RB%o#F3wD;)a0@-G%`vxFfvFqNK7;_w@5WgNli2}Ni{Gq zwX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B98+^(_ks&iNI3~^xPnarkJe(< z1)jA6Ys8V1K$SOWCJ>iygaObP2gMwsXomzB${ZCa8R$VbcEV?&6skc<6L}f|Ha`WK zXac1Zs0AhY1qkzzb%1<;m=ywh3aSOA!ckDblI-!A1D_cNH{OtwCp;~IrcS^Cjn|lz z%rdZ}z+>C6Bn~$NG-m-e0}^B?^ADgPgU>L4%>X6uywq|qTLHFu0m_3L37RATl^O~P z3JPeJDk#))ae>6aNdsLYXtW-uMzA&og`7;dE~F3z#Q}H_9i|=LfPuvUcvKuA3)X;K zfQ!*<#ad42G7H%8mx$);Tz2K@kKRdWGtQ54Bn;fJRrXA%PEV z+kngf8;z20L82I;hvXTsw_&4~P-`&MgNs9mNk}$;2OMER3=s!!09SwvA6kPnfQ<(S znF6@K0|_+5@EBrX1RUg(U>A zbCJ>{R5e<%K{6QRV9X&bxNS)8gcjVe$N@JMK@I|8s5P*(W(-SfFlRx1ftFn$K@RTU zfyawrQ2|nxmkJ#WvQmH+;2?W2%tNlxAPS)MnxO@xvVjOq9KM*3JDnq2@Xs2 zQ4@H`AUPhzfnagW%%K2YwGJ7>uu^~wTfqE_UJ!#EhvWoM6oJPU;C7=0H#~KNG=Z`< Nc&Hh4ssUtAGXV4L4;=si literal 0 HcmV?d00001 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? + %{

There were errors

#{instance.__send__(:errors).full_messages.join(", ")}

}.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!(/\[\[.+?\]\]/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, "
") - str.gsub!(/\[b\](.+?)\[\/b\]/, '\1') - str.gsub!(/\[i\](.+?)\[\/i\]/, '\1') + str.gsub!(/\[b\](.+?)\[\/b\]/i, '\1') + str.gsub!(/\[i\](.+?)\[\/i\]/i, '\1') str.gsub!(/\[spoilers?\](.+?)\[\/spoilers?\]/m, '\1') - str.gsub!(/("[^"]+":(http:\/\/|\/)\S+|http:\/\/\S+)/m) do |link| - if link =~ /^"([^"]+)":(.+)$/ - text = $1 - link = $2 - else - text = link - end - - if link =~ /([;,.!?\)\]<>])$/ - link.chop! - ch = $1 - else - ch = "" - end - - link.gsub!(/"/, '"') - '' + text + '' + ch + str.gsub!(/\[url\](.+?)\[\/url\]/i) do + %{#{h($1)}} + end + str.gsub!(/\[url=(.+?)\](.+?)\[\/url\]/m) do + %{#{h($2)}} end str end + def self.parse_aliased_wiki_links(str) + str.gsub(/\[\[(.+?)\|(.+?)\]\]/m) do + text = $1 + title = $2 + wiki_page = WikiPage.find_title_and_id(title) + + if wiki_page + %{[url=/wiki_pages/#{wiki_page.id}]#{text}[/url]} + else + %{[url=/wiki_pages/new?title=#{title}]#{text}[/url]} + end + end + end + + def self.parse_wiki_links(str) + str.gsub(/\[\[(.+?)\]\]/) do + title = $1 + wiki_page = WikiPage.find_title_and_id(title) + + if wiki_page + %{[url=/wiki_pages/#{wiki_page.id}]#{title}[/url]} + else + %{[url=/wiki_pages/new?title=#{title}]#{title}[/url]} + end + end + end + + def self.parse_post_links(str) + str.gsub(/\{\{(.+?)\}\}/, %{[url=/posts?tags=\1]\1[/url]}) + end + + def self.parse_id_links(str) + str = str.gsub(/\bpost #(\d+)/i, %{[url=/posts/\1]post #\1[/url]}) + str = str.gsub(/\bforum #(\d+)/i, %{[url=/forum_posts/\1]forum #\1[/url]}) + str = str.gsub(/\bcomment #(\d+)/i, %{[url=/comments/\1]comment #\1[/url]}) + str = str.gsub(/\bpool #(\d+)/i, %{[url=/pools/\1]pool #\1[/url]}) + end + def self.parse_list(str, options = {}) html = "" layout = [] diff --git a/app/logical/post_set.rb b/app/logical/post_set.rb index 305b0b985..5a26ac15b 100644 --- a/app/logical/post_set.rb +++ b/app/logical/post_set.rb @@ -11,6 +11,7 @@ class PostSet @errors = [] load_associations load_posts + load_suggestions validate end @@ -54,8 +55,12 @@ class PostSet @posts = Post.find_by_tags(tags, :before_id => before_id).all(:order => "posts.id desc", :limit => limit, :offset => offset) end - def load_suggestions(count) - @suggestions = Tag.find_suggestions(tags) if count < limit && is_single_tag? + def load_suggestions + if count < limit && is_single_tag? + @suggestions = Tag.find_suggestions(tags) + else + @suggestions = [] + end end def tag_array diff --git a/app/logical/remote_server.rb b/app/logical/remote_server.rb new file mode 100644 index 000000000..263095140 --- /dev/null +++ b/app/logical/remote_server.rb @@ -0,0 +1,35 @@ +class RemoteServer + attr_accessor :hostname + + def self.other_servers + Danbooru.config.other_server_hosts.map {|x| new(x)} + end + + def self.copy_to_all(local_path, remote_path) + other_servers.each do |server| + server.copy(local_path, remote_path) + end + end + + def self.delete_from_all(remote_path) + other_servers.each do |server| + server.delete(remote_path) + end + end + + def initialize(hostname) + @hostname = hostname + end + + def copy(local_path, remote_path) + Net::SFTP.start(hostname, Danbooru.config.remote_server_login) do |ftp| + ftp.upload!(local_path, remote_path) + end + end + + def delete(remote_path) + Net::SFTP.start(hostname, Danbooru.config.remote_server_login) do |ftp| + ftp.remove(remote_path) + end + end +end diff --git a/app/models/advertisement.rb b/app/models/advertisement.rb index 03d41a3e1..d686b7474 100644 --- a/app/models/advertisement.rb +++ b/app/models/advertisement.rb @@ -1,6 +1,16 @@ class Advertisement < ActiveRecord::Base validates_inclusion_of :ad_type, :in => %w(horizontal vertical) has_many :hits, :class_name => "AdvertisementHit" + after_create :copy_to_servers + after_destroy :delete_from_servers + + def copy_to_servers + RemoteServer.copy_to_all(image_path, image_path) + end + + def delete_from_servers + RemoteServer.delete_from_all(image_path) + end def hit!(ip_addr) hits.create(:ip_addr => ip_addr) @@ -10,23 +20,21 @@ class Advertisement < ActiveRecord::Base hits.where(["created_at BETWEEN ? AND ?", start_date, end_date]).count end - def date_path - created_at.strftime("%Y%m%d") + def unique_identifier + @unique_identifier ||= ("%.0f" % (Time.now.to_f * 1_000)) end def image_url - "/images/ads-#{date_path}/#{file_name}" + "/images/advertisements/#{file_name}" end def image_path - "#{Rails.root}/public/#{image_url}" + "#{Rails.root}/public/images/advertisements/#{file_name}" end def file=(f) if f.size > 0 - self.created_at ||= Time.now - self.file_name = f.original_filename - FileUtils.mkdir_p(File.dirname(image_path)) + self.file_name = unique_identifier + File.extname(f.original_filename) if f.local_path FileUtils.cp(f.local_path, image_path) @@ -35,7 +43,6 @@ class Advertisement < ActiveRecord::Base end File.chmod(0644, image_path) - image_size = ImageSize.new(File.open(image_path, "rb")) self.width = image_size.get_width self.height = image_size.get_height @@ -43,23 +50,23 @@ class Advertisement < ActiveRecord::Base end def preview_width - if width > 200 || height > 200 + if width > 100 || height > 100 if width < height - ratio = 200.0 / height + ratio = 100.0 / height return (width * ratio).to_i else - return 200 + return 100 end end end def preview_height - if width > 200 || height > 200 + if width > 100 || height > 100 if height < width - ratio = 200.0 / width + ratio = 100.0 / width return (height * ratio) else - return 200 + return 100 end end end diff --git a/app/models/advertisement_hit.rb b/app/models/advertisement_hit.rb index 49988ce8f..b20905e59 100644 --- a/app/models/advertisement_hit.rb +++ b/app/models/advertisement_hit.rb @@ -1,3 +1,5 @@ class AdvertisementHit < ActiveRecord::Base belongs_to :advertisement + + scope :between, lambda {|start_date, end_date| where("created_at BETWEEN ? AND ?", start_date, end_date)} end diff --git a/app/models/artist.rb b/app/models/artist.rb index 6b337ffe0..842e5607d 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -1,19 +1,16 @@ class Artist < ActiveRecord::Base - attr_accessor :updater_id, :updater_ip_addr before_create :initialize_creator before_save :normalize_name after_save :create_version after_save :save_url_string validates_uniqueness_of :name - validates_presence_of :updater_id, :updater_ip_addr - belongs_to :updater, :class_name => "User" belongs_to :creator, :class_name => "User" has_many :members, :class_name => "Artist", :foreign_key => "group_name", :primary_key => "name" - has_many :artist_urls, :dependent => :destroy + has_many :urls, :dependent => :destroy, :class_name => "ArtistUrl" has_one :wiki_page, :foreign_key => "title", :primary_key => "name" has_one :tag_alias, :foreign_key => "antecedent_name", :primary_key => "name" accepts_nested_attributes_for :wiki_page - attr_accessible :name, :url_string, :other_names, :group_name, :wiki_page_attributes, :updater_id, :updater_ip_addr + attr_accessible :name, :url_string, :other_names, :group_name, :wiki_page_attributes, :notes module UrlMethods module ClassMethods @@ -24,7 +21,7 @@ class Artist < ActiveRecord::Base while artists.empty? && url.size > 10 u = url.sub(/\/+$/, "") + "/" u = u.to_escaped_for_sql_like.gsub(/\*/, '%') + '%' - artists += Artist.joins(:artist_urls).where(["artists.is_active = TRUE AND artist_urls.normalized_url LIKE ? ESCAPE E'\\\\'", u]).all(:order => "artists.name") + artists += Artist.joins(:urls).where(["artists.is_active = TRUE AND artist_urls.normalized_url LIKE ? ESCAPE E'\\\\'", u]).all(:order => "artists.name") url = File.dirname(url) + "/" end @@ -38,10 +35,10 @@ class Artist < ActiveRecord::Base def save_url_string if @url_string - artist_urls.clear + urls.clear @url_string.scan(/\S+/).each do |url| - artist_urls.create(:url => url) + urls.create(:url => url) end end end @@ -51,7 +48,7 @@ class Artist < ActiveRecord::Base end def url_string - @url_string || artist_urls.map {|x| x.url}.join("\n") + @url_string || urls.map {|x| x.url}.join("\n") end end @@ -80,13 +77,15 @@ class Artist < ActiveRecord::Base end end - module UpdaterMethods - def updater_name - User.id_to_name(updater_id).tr("_", " ") - end - end - module SearchMethods + def find_by_name_or_id(params) + if params[:name] + find_by_name(params[:name]) + else + find(params[:id]) + end + end + def find_by_any_name(name) build_relation(:name => name).first end @@ -120,6 +119,12 @@ class Artist < ActiveRecord::Base relation = relation.where(["id = ?", params[:id]]) end + if params[:order] == "date" + relation = relation.order("updated_at DESC") + else + relation = relation.order("name") + end + relation end end @@ -129,8 +134,8 @@ class Artist < ActiveRecord::Base ArtistVersion.create( :artist_id => id, :name => name, - :updater_id => updater_id, - :updater_ip_addr => updater_ip_addr, + :updater_id => CurrentUser.user.id, + :updater_ip_addr => CurrentUser.ip_addr, :url_string => url_string, :is_active => is_active, :other_names => other_names, @@ -138,14 +143,12 @@ class Artist < ActiveRecord::Base ) end - def revert_to!(version, reverter_id, reverter_ip_addr) + def revert_to!(version) self.name = version.name self.url_string = version.url_string self.is_active = version.is_active self.other_names = version.other_names self.group_name = version.group_name - self.updater_id = reverter_id - self.updater_ip_addr = reverter_ip_addr save end end @@ -172,18 +175,47 @@ class Artist < ActiveRecord::Base end end + module NoteMethods + def notes + if wiki_page + wiki_page.body + else + nil + end + end + + def notes=(msg) + if wiki_page.nil? + self.wiki_page = WikiPage.new + end + + wiki_page.title = name + wiki_page.body = msg + wiki_page.save + end + end + + module TagMethods + def has_tag_alias? + TagAlias.exists?(["antecedent_name = ?", name]) + end + + def tag_alias_name + TagAlias.find_by_antecedent_name(name).consequent_name + end + end + include UrlMethods include NameMethods include GroupMethods - include UpdaterMethods extend SearchMethods include VersionMethods extend FactoryMethods + include NoteMethods + include TagMethods def initialize_creator - if creator.nil? - self.creator_id = updater_id - end + self.creator_id = CurrentUser.user.id end end diff --git a/app/models/post.rb b/app/models/post.rb index 0b19b0bf5..efa4b28c0 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -8,6 +8,7 @@ class Post < ActiveRecord::Base before_save :create_tags before_save :update_tag_post_counts before_save :set_tag_counts + before_validation_on_create :initialize_uploader belongs_to :updater, :class_name => "User" belongs_to :approver, :class_name => "User" belongs_to :parent, :class_name => "Post" @@ -23,6 +24,7 @@ class Post < ActiveRecord::Base validates_presence_of :parent, :if => lambda {|rec| !rec.parent_id.nil?} validate :validate_parent_does_not_have_a_parent attr_accessible :source, :rating, :tag_string, :old_tag_string, :last_noted_at + scope :visible, lambda {|user| Danbooru.config.can_user_see_post_conditions(user)} module FileMethods def delete_files @@ -337,6 +339,10 @@ class Post < ActiveRecord::Base def filter_metatags(tags) tags.reject {|tag| tag =~ /\A(?:pool|rating|fav|approver|uploader):/} end + + def has_tag?(tag) + tag_string =~ /(?:^| )#{tag}(?:$| )/ + end end module FavoriteMethods @@ -581,6 +587,11 @@ class Post < ActiveRecord::Base end module UploaderMethods + def initialize_uploader + self.uploader = CurrentUser.user + self.uploader_ip_addr = CurrentUser.ip_addr + end + def uploader_id=(user_id) self.uploader = User.find(user_id) end @@ -758,6 +769,10 @@ class Post < ActiveRecord::Base tag_array.each {|x| expire_cache(x)} end end + + def is_removed? + false + end end include FileMethods diff --git a/app/models/removed_post.rb b/app/models/removed_post.rb index 5dfed4f70..e4b10423d 100644 --- a/app/models/removed_post.rb +++ b/app/models/removed_post.rb @@ -20,6 +20,10 @@ class RemovedPost < ActiveRecord::Base end count end + + def is_removed? + true + end include Post::FileMethods include Post::ImageMethods diff --git a/app/models/tag_alias.rb b/app/models/tag_alias.rb index 1897bd9f2..7bdaf1ed3 100644 --- a/app/models/tag_alias.rb +++ b/app/models/tag_alias.rb @@ -1,7 +1,8 @@ class TagAlias < ActiveRecord::Base attr_accessor :creator_ip_addr after_save :update_posts - after_destroy :clear_cache + after_commit :clear_cache + after_commit :clear_remote_cache validates_presence_of :creator_id, :creator_ip_addr validates_uniqueness_of :antecedent_name validate :absence_of_transitive_relation @@ -32,6 +33,12 @@ class TagAlias < ActiveRecord::Base Cache.delete("ta:#{Cache.sanitize(antecedent_name)}") end + def clear_remote_cache + Danbooru.config.other_server_hosts.each do |server| + Net::HTTP.delete(URI.parse("http://#{server}/tag_aliases/#{id}/cache")) + end + end + def update_cache Cache.put("ta:#{Cache.sanitize(antecedent_name)}", consequent_name) end diff --git a/app/models/upload.rb b/app/models/upload.rb index 2b49f32a2..2567b5456 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -7,7 +7,8 @@ class Upload < ActiveRecord::Base attr_accessor :file, :image_width, :image_height, :file_ext, :md5, :file_size belongs_to :uploader, :class_name => "User" belongs_to :post - before_create :initialize_status + before_validation_on_create :initialize_uploader + before_validation_on_create :initialize_status before_create :convert_cgi_file validate :uploader_is_not_limited @@ -15,7 +16,6 @@ class Upload < ActiveRecord::Base def uploader_is_not_limited if !uploader.can_upload? update_attribute(:status, "error: uploader has reached their daily limit") - raise end end @@ -28,21 +28,18 @@ class Upload < ActiveRecord::Base def validate_file_exists unless File.exists?(file_path) update_attribute(:status, "error: file does not exist") - raise end end def validate_file_content_type unless is_valid_content_type? update_attribute(:status, "error: invalid content type (#{file_ext} not allowed)") - raise end end def validate_md5_confirmation if !md5_confirmation.blank? && md5_confirmation != md5 update_attribute(:status, "error: md5 mismatch") - raise end end end @@ -71,6 +68,8 @@ class Upload < ActiveRecord::Base update_attribute(:status, "error: " + post.errors.full_messages.join(", ")) end end + rescue Exception => x + update_attribute(:status, "error: #{x} - #{x.message}") end def convert_to_post @@ -224,7 +223,7 @@ class Upload < ActiveRecord::Base end def temp_file_path - File.join(Dir::tmpdir, "#{Time.now.to_f}.#{$PROCESS_ID}") + File.join(Rails.root, "tmp", "#{Time.now.to_f}.#{$PROCESS_ID}") end end @@ -249,11 +248,11 @@ class Upload < ActiveRecord::Base def convert_cgi_file return if file.blank? || file.size == 0 + self.file_path = temp_file_path + if file.local_path - self.file_path = file.local_path + FileUtils.cp(file.local_path, file_path) else - self.file_path = temp_file_path - File.open(file_path, 'wb') do |out| out.write(file.read) end @@ -277,6 +276,13 @@ class Upload < ActiveRecord::Base end end + module UploaderMethods + def initialize_uploader + self.uploader_id = CurrentUser.user.id + self.uploader_ip_addr = CurrentUser.ip_addr + end + end + include ConversionMethods include ValidationMethods include FileMethods @@ -287,6 +293,7 @@ class Upload < ActiveRecord::Base include FilePathMethods include CgiFileMethods include StatusMethods + include UploaderMethods def presenter @presenter ||= UploadPresenter.new(self) diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index b14b34592..1ef46f025 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -1,13 +1,11 @@ class WikiPage < ActiveRecord::Base - attr_accessor :updater_id, :updater_ip_addr before_save :normalize_title before_create :initialize_creator after_save :create_version belongs_to :creator, :class_name => "User" - belongs_to :updater, :class_name => "User" validates_uniqueness_of :title, :case_sensitive => false - validates_presence_of :body, :updater_id, :updater_ip_addr - attr_accessible :title, :body, :updater_id, :updater_ip_addr + validates_presence_of :body + attr_accessible :title, :body scope :titled, lambda {|title| where(["title = ?", title.downcase.tr(" ", "_")])} has_one :tag, :foreign_key => "name", :primary_key => "title" has_one :artist, :foreign_key => "name", :primary_key => "title" @@ -27,12 +25,14 @@ class WikiPage < ActiveRecord::Base relation end + def self.find_title_and_id(title) + titled(title).select("title, id").first + end + def revert_to(version, reverter_id, reverter_ip_addr) self.title = version.title self.body = version.body self.is_locked = version.is_locked - self.updater_id = reverter_id - self.updater_ip_addr = reverter_ip_addr end def revert_to!(version, reverter_id, reverter_ip_addr) @@ -55,8 +55,8 @@ class WikiPage < ActiveRecord::Base def create_version if title_changed? || body_changed? || is_locked_changed? versions.create( - :updater_id => updater_id, - :updater_ip_addr => updater_ip_addr, + :updater_id => CurrentUser.user.id, + :updater_ip_addr => CurrentUser.ip_addr, :title => title, :body => body, :is_locked => is_locked @@ -65,8 +65,6 @@ class WikiPage < ActiveRecord::Base end def initialize_creator - if creator.nil? - self.creator_id = updater_id - end + self.creator_id = CurrentUser.user.id end end diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index 472b7444c..89eca855a 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -3,9 +3,9 @@ class PostPresenter < Presenter @post = post end - def image_html(template, current_user) - return template.content_tag("p", "This image was deleted.") if @post.is_deleted? && !current_user.is_janitor? - return template.content_tag("p", "You need a privileged account to see this image.") if !Danbooru.config.can_see_post?(@post, current_user) + def image_html(template) + return template.content_tag("p", "This image was deleted.") if @post.is_removed? && !CurrentUser.user.is_janitor? + return template.content_tag("p", "You need a privileged account to see this image.") if !Danbooru.config.can_see_post?(@post, CurrentUser.user) if @post.is_flash? template.render(:partial => "posts/partials/show/flash", :locals => {:post => @post}) @@ -14,8 +14,8 @@ class PostPresenter < Presenter end end - def tag_list_html(template, current_user) + def tag_list_html(template) @tag_set_presenter ||= TagSetPresenter.new(@post.tag_array) - @tag_set_presenter.tag_list_html(template, :show_extra_links => current_user.is_privileged?) + @tag_set_presenter.tag_list_html(template, :show_extra_links => CurrentUser.user.is_privileged?) end end diff --git a/app/presenters/post_set_presenter.rb b/app/presenters/post_set_presenter.rb index 33b94ceeb..e15a12491 100644 --- a/app/presenters/post_set_presenter.rb +++ b/app/presenters/post_set_presenter.rb @@ -15,12 +15,30 @@ class PostSetPresenter < Presenter "" end - def wiki_html - "" + def wiki_html(template) + if post_set.is_single_tag? + wiki_page = WikiPage.find_by_title(post_set.tags) + html = '
' + if wiki_page.nil? + html << '

' + 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 << '

' + html << template.h(wiki_page.title) + html << '

' + html << template.format_text(wiki_page.body) + end + html << '
' + html.html_safe + end end def pagination_html(template) - if @post_set.use_sequential_paginator? + if post_set.use_sequential_paginator? sequential_pagination_html(template) else numbered_pagination_html(template) @@ -30,9 +48,9 @@ class PostSetPresenter < Presenter def sequential_pagination_html(template) html = "" prev_url = template.request.env["HTTP_REFERER"] - next_url = template.posts_path(:tags => template.params[:tags], before_id => @post_set.posts[-1].id, :page => nil) + next_url = template.posts_path(:tags => template.params[:tags], before_id => post_set.posts[-1].id, :page => nil) html << %{
  • « Previous
  • } - if @post_set.posts.any? + if post_set.posts.any? html << %{
  • Next »
  • } end html << "
    " @@ -40,8 +58,8 @@ class PostSetPresenter < Presenter end def numbered_pagination_html(template) - total_pages = (@post_set.count.to_f / @post_set.limit.to_f).ceil - current_page = [1, @post_set.page].max + total_pages = (post_set.count.to_f / post_set.limit.to_f).ceil + current_page = [1, post_set.page].max html = "" window = 3 if total_pages <= (window * 2) + 5 @@ -94,7 +112,7 @@ class PostSetPresenter < Presenter flags = [] flags << "pending" if post.is_pending? flags << "flagged" if post.is_flagged? - flags << "deleted" if post.is_deleted? + flags << "removed" if post.is_removed? html << %{
    } html << %{} diff --git a/app/views/advertisements/_form.html.erb b/app/views/advertisements/_form.html.erb new file mode 100644 index 000000000..58a69cfc2 --- /dev/null +++ b/app/views/advertisements/_form.html.erb @@ -0,0 +1,28 @@ +<% form_for @advertisement, :html => {:multipart => true} do |f| %> + + + + + + + + + + + + + + + + + + + + + + + + + +
    <%= submit_tag "Submit" %>
    <%= f.label :file %><%= f.file_field "file" %>
    <%= f.label :referral_url %><%= f.text_field :referral_url %>
    <%= f.label :ad_type %><%= f.select :ad_type, ["vertical", "horizontal"] %>
    <%= f.label :status %><%= f.select :status, ["active", "inactive"] %>
    +<% end %> \ No newline at end of file diff --git a/app/views/advertisements/_secondary_nav_links.html.erb b/app/views/advertisements/_secondary_nav_links.html.erb new file mode 100644 index 000000000..414eb171a --- /dev/null +++ b/app/views/advertisements/_secondary_nav_links.html.erb @@ -0,0 +1,11 @@ +<% content_for(:secondary_nav_links) do %> + +
  • <%= link_to "Listing", advertisements_path %>
  • +
  • <%= link_to "New", new_advertisement_path %>
  • + <% if @advertisement && !@advertisement.new_record? %> +
  • |
  • +
  • <%= link_to "Edit", edit_advertisement_path(@advertisement) %>
  • +
  • <%= link_to "Show", advertisement_path(@advertisement) %>
  • + <% end %> +
    +<% end %> diff --git a/app/views/advertisements/edit.html.erb b/app/views/advertisements/edit.html.erb new file mode 100644 index 000000000..4ea518d4f --- /dev/null +++ b/app/views/advertisements/edit.html.erb @@ -0,0 +1,3 @@ +<%= image_tag(@advertisement.image_url) %> +<%= render :partial => "form" %> +<%= render :partial => "secondary_nav_links" %> diff --git a/app/views/advertisements/index.html.erb b/app/views/advertisements/index.html.erb new file mode 100644 index 000000000..8ecabec68 --- /dev/null +++ b/app/views/advertisements/index.html.erb @@ -0,0 +1,45 @@ +

    Advertisements

    + +
    + <% form_tag(advertisements_path, :method => :get) do %> + + + + + + + + + + + + + + + + + +
    <%= submit_tag "Search" %>
    <%= text_field_tag "start_date", @start_date %>
    <%= text_field_tag "end_date", @end_date %>
    + <% end %> +
    + + + + + + + + + + + <% @advertisements.each do |advertisement| %> + + + + + + <% end %> + +
    Hits
    <%= image_tag(advertisement.image_url, :width => advertisement.preview_width, :height => advertisement.preview_height) %><%= advertisement.hits.between(@start_date, @end_date).count %><%= link_to "Edit", edit_advertisement_path(advertisement) %>
    + +<%= render :partial => "secondary_nav_links" %> diff --git a/app/views/advertisements/new.html.erb b/app/views/advertisements/new.html.erb new file mode 100644 index 000000000..764c2c7a3 --- /dev/null +++ b/app/views/advertisements/new.html.erb @@ -0,0 +1,3 @@ +<%= error_messages_for :advertisement %> +<%= render :partial => "form" %> +<%= render :partial => "secondary_nav_links" %> diff --git a/app/views/advertisements/show.html.erb b/app/views/advertisements/show.html.erb new file mode 100644 index 000000000..59346be96 --- /dev/null +++ b/app/views/advertisements/show.html.erb @@ -0,0 +1,7 @@ +
    <%= image_tag(@advertisement.image_url, :width => @advertisement.preview_width, :height => @advertisement.preview_height) %>
    + +
      +
    • Hits: <%= @advertisement.hits.between(@start_date, @end_date).count %>
    • +
    + +<%= render :partial => "secondary_nav_links" %> diff --git a/app/views/artist_versions/index.html.erb b/app/views/artist_versions/index.html.erb new file mode 100644 index 000000000..eb710542a --- /dev/null +++ b/app/views/artist_versions/index.html.erb @@ -0,0 +1,46 @@ +

    History for <%= @artist.name %>

    + +
    + + + + + + + + + + + + + + <% @artist_versions.each do |artist_version| %> + + + + + + + + + + <% end %> + +
    NameOther NamesGroupUpdatedUpdated byActiveURLs
    <%= link_to h(artist_version.name), artist_versions_path(:artist_id => @artist.id) %><%= h artist_version.other_names %><%= h artist_version.group_name %><%= time_ago_in_words artist_version.created_at %> ago<%= link_to artist_version.updater_name, user_path(artist_version.user_id) %><%= artist_version.is_active? %><%= artist_version.urls.join(" ") %>
    +
    + +
    + <%= will_paginate(@artist_versions) %> +
    + +<% content_for("footer") do %> +
  • |
  • +
  • <%= link_to "Show", artist_path(@artist) %> +
  • <%= link_to "Edit", edit_artist_path(@artist) %>
  • +
  • <%= link_to "Delete", artist_path(@artist, :method => :delete) %>
  • +
  • <%= link_to "History", artist_versions_path(:artist_id => @artist) %>
  • +
  • <%= link_to "Posts", posts_path(:tags => @artist.name) %>
  • +<% end %> + +<%= render :partial => "footer" %> + diff --git a/app/views/artists/_form.html.erb b/app/views/artists/_form.html.erb new file mode 100644 index 000000000..4d18a66e8 --- /dev/null +++ b/app/views/artists/_form.html.erb @@ -0,0 +1,41 @@ +<%= form_for(@artist) do |f| %> + <%= error_messages_for "artist" %> + + + + + + + + + + + + + + + + + + + + + + + + + +
    <%= f.label :name %> + <%= f.text_field "name", :size => 30 %>
    + <%= f.label :other_names %> + + <%= f.text_field "other_names", :size => 30 %> + Separate with commas +
    <%= f.label :group_name %><%= f.text_field "group_name", :size => 30 %>
    <%= f.label :url_string, "URLs" %><%= f.text_area "url_string", :size => "50x6", :class => "no-block" %>
    <%= f.label :notes %> + <%= f.text_area "notes", :size => "50x10", :class => "no-block" %> + <%= link_to "Formatting help", wiki_page_path(:id => "help:dtext") %> +
    + <%= submit_tag "Save" %> + <%= button_to_function "Cancel", "history.back()" %> +
    +<% end %> \ No newline at end of file diff --git a/app/views/artists/_search.html.erb b/app/views/artists/_search.html.erb new file mode 100644 index 000000000..547332856 --- /dev/null +++ b/app/views/artists/_search.html.erb @@ -0,0 +1,6 @@ +
    + <% form_tag(artists_path, :method => :get) do %> + <%= text_field_tag "name", params[:name], :size => 40 %> + <%= submit_tag "Search" %> + <% end %> +
    diff --git a/app/views/artists/_secondary_nav_links.html.erb b/app/views/artists/_secondary_nav_links.html.erb new file mode 100644 index 000000000..7ea4f645c --- /dev/null +++ b/app/views/artists/_secondary_nav_links.html.erb @@ -0,0 +1,12 @@ +<% content_for(:secondary_nav_links) do %> + +
  • <%= link_to "Listing", artists_path %>
  • +
  • <%= link_to "New", new_artist_path %>
  • +
  • <%= link_to "Recent changes", artist_versions_path %>
  • + <% if @artist && !@artist.new_record? %> +
  • |
  • +
  • <%= link_to "Edit", edit_artist_path(@artist) %>
  • +
  • <%= link_to "Show", artist_path(@artist) %>
  • + <% end %> +
    +<% end %> diff --git a/app/views/artists/edit.html.erb b/app/views/artists/edit.html.erb new file mode 100644 index 000000000..851b02092 --- /dev/null +++ b/app/views/artists/edit.html.erb @@ -0,0 +1,3 @@ +
    + <%= render :partial => "form" %> +
    diff --git a/app/views/artists/index.html.erb b/app/views/artists/index.html.erb new file mode 100644 index 000000000..12fede550 --- /dev/null +++ b/app/views/artists/index.html.erb @@ -0,0 +1,35 @@ +
    + <%= render :partial => "search" %> + + + + + + + + + + <% @artists.each do |artist| %> + <% content_tag(:tr, :id => "artist-#{artist.id}") do %> + + + <% end %> + <% end %> + +
    Name
    + <%= link_to "P", posts_path(:tags => artist.name), :title => "Find posts for artist" %> + <%= link_to "E", edit_artist_path(artist), :title => "Edit artist" %> + <%= link_to "D", artist_path(artist, :method => :delete, :confirm => "Do you really want to delete this artist?") %> + + <%= link_to h(artist.name), artist_path(artist) %> + <% if !artist.group_name.blank? %> + [<%= link_to(artist.group_name, artist_path(artist)) %>] + <% end %> +
    + +
    + <%= will_paginate(@artists) %> +
    + + <%= render :partial => "secondary_nav_links" %> +
    diff --git a/app/views/artists/new.html.erb b/app/views/artists/new.html.erb new file mode 100644 index 000000000..c4cf99a16 --- /dev/null +++ b/app/views/artists/new.html.erb @@ -0,0 +1,5 @@ +
    + <%= render :partial => "form" %> +
    + +<%= render :partial => "secondary_nav_links" %> diff --git a/app/views/artists/show.html.erb b/app/views/artists/show.html.erb new file mode 100644 index 000000000..4a1cafd02 --- /dev/null +++ b/app/views/artists/show.html.erb @@ -0,0 +1,90 @@ +
    +

    Artist: <%= @artist.name.tr("_", " ") %>

    + + <% unless @artist.notes.blank? %> +
    + <%= format_text(@artist.notes) %> +
    + <% end %> + +
    + + + + + + + <% if @artist.has_tag_alias? %> + + + + + <% end %> + <% if !@artist.other_names.blank? %> + + + + + <% end %> + <% if !@artist.group_name.blank? %> + + + + + <% end %> + <% if @artist.members.any? %> + + + + + <% end %> + <% @artist.urls.each do |url| %> + + + + + <% end %> + +
    Status + <% if @artist.is_banned? %> + Banned + <% elsif @artist.is_active? %> + Active + <% else %> + Inactive + <% end %> +
    Tag Alias + <%= @artist.tag_alias_name %> +
    Other Names + <%= link_to_artists(@artist.other_names.split(/,/)) %> +
    Group + <%= link_to_artist(@artist.group_name) %> +
    Members + <%= link_to_artists(@artist.members.map(&:name)) %> +
    URLs + <%= link_to h(url.to_s), h(url.to_s) %> + <% if CurrentUser.user.is_moderator? %> + (<%= link_to("mass edit", mass_edit_admin_posts_path(:antecedent => "-#{@artist.name} source:#{ArtistUrl.normalize_for_search(url.to_s)}", :consequent => @artist.name)) %>) + <% end %> +
    +
    + +

    * Indicates new artist

    + +
    +

    Recent Posts

    +
    + <%#= @post_set.presenter.post_previews_html %> +
    +
    + + <% content_for("footer") do %> +
  • |
  • +
  • <%= link_to "Posts", posts_path(:tags => @artist.name) %>
  • +
  • <%= link_to "Edit", edit_artist_path(@artist) %>
  • +
  • <%= link_to "Delete", artist_path(@artist, :method => :delete) %>
  • +
  • <%= link_to "History", artist_versions_path(:artist_id => @artist.id) %>
  • + <% end %> + + <%= render :partial => "secondary_nav_links" %> +
    diff --git a/app/views/comments/partials/index/_list.html.erb b/app/views/comments/partials/index/_list.html.erb index a30c329ac..1c01c75b3 100644 --- a/app/views/comments/partials/index/_list.html.erb +++ b/app/views/comments/partials/index/_list.html.erb @@ -8,7 +8,7 @@
    - <% form_tag(comments_path) do %> + <%= form_tag(comments_path) do %> <%= hidden_field "comment", "post_id", :value => post.id%> <%= text_area "comment", "body", :size => "60x7" %>
    <%= submit_tag "Post" %> diff --git a/app/views/comments/partials/show/_comment.html.erb b/app/views/comments/partials/show/_comment.html.erb index 1f39c1cd1..ed840dc36 100644 --- a/app/views/comments/partials/show/_comment.html.erb +++ b/app/views/comments/partials/show/_comment.html.erb @@ -10,7 +10,7 @@