From fbc1fb1f5110c2a8e9e3ca1c99c0be2ca35f5b78 Mon Sep 17 00:00:00 2001 From: albert Date: Fri, 16 Sep 2011 10:58:02 -0400 Subject: [PATCH] fixes #80: Clicking Pixiv source address at the information panel --- app/helpers/posts_helper.rb | 4 ++-- app/models/post.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/helpers/posts_helper.rb b/app/helpers/posts_helper.rb index 39d4e01f4..f0123d0a7 100644 --- a/app/helpers/posts_helper.rb +++ b/app/helpers/posts_helper.rb @@ -23,8 +23,8 @@ module PostsHelper def post_source_tag(post) if post.source =~ /^http/ - text = truncate(post.source.sub(/^https?:\/\//, "")) - link_to(truncate(text, :length => 15), post.source) + text = truncate(post.normalized_source.sub(/^https?:\/\//, "")) + link_to(truncate(text, :length => 15), post.normalized_source) else truncate(post.source, :length => 100) end diff --git a/app/models/post.rb b/app/models/post.rb index 31e0a074e..9598ba1b7 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -319,6 +319,20 @@ class Post < ActiveRecord::Base "Safe" end end + + def normalized_source + if source =~ /pixiv\.net\/img\// + img_id = source[/(\d+)(_s|_m|(_big)?_p\d+)?\.[\w\?]+\s*$/, 1] + + if $2 =~ /_p/ + "http://www.pixiv.net/member_illust.php?mode=manga&illust_id=#{img_id}" + else + "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=#{img_id}" + end + else + source + end + end end module TagMethods