Skip to content

Commit

Permalink
Merge branch 'refs/heads/master' into 0.9.13-issue-3574-wwwwww
Browse files Browse the repository at this point in the history
Conflicts:
	spec/models/story_parser_spec.rb
  • Loading branch information
neuroalien committed Feb 8, 2014
2 parents 764933e + 7da4e4d commit dd3b9b9
Show file tree
Hide file tree
Showing 16 changed files with 191 additions and 115 deletions.
7 changes: 5 additions & 2 deletions Gemfile
Expand Up @@ -61,8 +61,6 @@ gem 'best_in_place'
gem 'timeliness'

gem 'rpm_contrib'
gem 'newrelic_rpm', ">= 3.5.3.25"
gem 'newrelic-redis'

# for generating graphs
gem "google_visualr", ">= 2.1"
Expand All @@ -73,6 +71,11 @@ gem "google_visualr", ">= 2.1"
# Coveralls for code test coverage
gem 'coveralls', require: false

# Place the New Relic gem as low in the list as possible, allowing the
# frameworks above it to be instrumented when the gem initializes.
gem 'newrelic_rpm', "3.7.2.192"
gem 'newrelic-redis'

group :test do
gem 'rspec-rails', '>=2.6.0'
gem 'pickle'
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Expand Up @@ -154,7 +154,7 @@ GEM
newrelic-redis (1.4.0)
newrelic_rpm (~> 3.0)
redis (< 4.0)
newrelic_rpm (3.6.5.130)
newrelic_rpm (3.7.2.192)
nokogiri (1.6.0)
mini_portile (~> 0.5.0)
ntlm-http (0.1.1)
Expand Down Expand Up @@ -327,7 +327,7 @@ DEPENDENCIES
memcache-client
mysql2
newrelic-redis
newrelic_rpm (>= 3.5.3.25)
newrelic_rpm (= 3.7.2.192)
nokogiri (>= 1.4.2)
paperclip
permit_yo
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/works_controller.rb
Expand Up @@ -753,7 +753,11 @@ def marktoread
@work = Work.find(params[:id])
Reading.mark_to_read_later(@work, current_user)
read_later_path = user_readings_path(current_user, :show => 'to-read')
flash[:notice] = ts("This work was marked for later. You can find it in your #{view_context.link_to('history', read_later_path)}. (The work may take a short while to show up there.)").html_safe
if @work.marked_for_later?(current_user)
flash[:notice] = ts("This work was <strong>removed</strong> from your #{view_context.link_to('Marked for Later list', read_later_path)}. It may take a while for changes to show up.").html_safe
else
flash[:notice] = ts("This work was <strong>added</strong> to your #{view_context.link_to('Marked for Later list', read_later_path)}. It may take a while for changes to show up.").html_safe
end
redirect_to(request.env["HTTP_REFERER"] || root_path)
end

Expand Down
4 changes: 2 additions & 2 deletions app/helpers/works_helper.rb
Expand Up @@ -97,11 +97,11 @@ def marked_for_later?(work)
end

def marktoread_link(work)
link_to ts("Mark for later"), marktoread_work_path(work)
link_to ts("Mark for Later"), marktoread_work_path(work)
end

def markasread_link(work)
link_to ts("Mark as read"), marktoread_work_path(work)
link_to ts("Mark as Read"), marktoread_work_path(work)
end

def get_endnotes_link
Expand Down
2 changes: 2 additions & 0 deletions app/models/redis_mail_queue.rb
Expand Up @@ -36,6 +36,8 @@ def self.deliver_kudos
user_kudos["#{commentable_type}_#{commentable_id}"] = names
end

next if user_kudos.blank?

# queue the notification for delivery
begin
# don't die if we hit one deleted user
Expand Down
63 changes: 49 additions & 14 deletions app/models/story_parser.rb
Expand Up @@ -50,7 +50,7 @@ class Error < StandardError

# places for which we have a download_chaptered_from
# to get a set of chapters all together
CHAPTERED_STORY_LOCATIONS = %w(ffnet efiction)
CHAPTERED_STORY_LOCATIONS = %w(ffnet thearchive_net efiction)

# regular expressions to match against the URLS
SOURCE_LJ = '((live|dead|insane)?journal(fen)?\.com)|dreamwidth\.org'
Expand All @@ -61,11 +61,16 @@ class Error < StandardError
SOURCE_DEVIANTART = 'deviantart\.com'
SOURCE_LOTRFANFICTION = 'lotrfanfiction\.com'
SOURCE_TWILIGHTARCHIVES = 'twilightarchives\.com'
SOURCE_THEARCHIVE_NET = 'the\-archive\.net'
SOURCE_EFICTION = 'viewstory\.php'

# time out if we can't download fast enough
STORY_DOWNLOAD_TIMEOUT = 60
MAX_CHAPTER_COUNT = 200

# To check for duplicate chapters, take a slice this long out of the story
# (in characters)
DUPLICATE_CHAPTER_LENGTH = 10000


# Import many stories
Expand Down Expand Up @@ -431,14 +436,6 @@ def download_text(location)
story = eval("download_from_#{source.downcase}(location)")
end

# clean up any erroneously included string terminator (Issue 785)
story = story.gsub("\000", "")

#story = fix_bad_characters(story)
# ^ This eats ALL special characters. I don't think we need it at all
# so I'm taking it out. If we want it back, it should be the last
# thing we do with the parsed bits after Nokogiri has parsed the content
# and worked it's magic with encoding --rebecca
return story
end

Expand Down Expand Up @@ -489,23 +486,42 @@ def download_chaptered_from_ffnet(location)
# end
# return @chapter_contents
end



# this is an efiction archive but it doesn't handle chapters normally
# best way to handle is to get the full story printable version
# We have to make it a download-chaptered because otherwise it gets sent to the
# generic efiction version since chaptered sources are checked first
def download_chaptered_from_thearchive_net(location)
if location.match(/^(.*)\/.*viewstory\.php.*[^p]sid=(\d+)($|&)/i)
location = "#{$1}/viewstory.php?action=printable&psid=#{$2}"
end
text = download_with_timeout(location)
text.sub!('</style>', '</style></head>') unless text.match('</head>')
return [text]
end

# grab all the chapters of a story from an efiction-based site
def download_chaptered_from_efiction(location)
@chapter_contents = []
if location.match(/^(.*)\/.*viewstory\.php.*sid=(\d+)($|&)/i)
site = $1
storyid = $2
chapnum = 1
last_body = ""
Timeout::timeout(STORY_DOWNLOAD_TIMEOUT) {
loop do
url = "#{site}/viewstory.php?action=printable&sid=#{storyid}&chapter=#{chapnum}"
body = download_with_timeout(url)
if body.nil? || chapnum > MAX_CHAPTER_COUNT || body.match(/<div class='chaptertitle'> by <\/div>/) || body.match(/Access denied./) || body.match(/Chapter : /)
body = download_with_timeout(url)
# get a section to check that this isn't a duplicate of previous chapter
body_to_check = body.slice(10,DUPLICATE_CHAPTER_LENGTH)
if body.nil? || body_to_check == last_body || chapnum > MAX_CHAPTER_COUNT || body.match(/<div class='chaptertitle'> by <\/div>/) || body.match(/Access denied./) || body.match(/Chapter : /)
break
end
# save the value to check for duplicate chapter
last_body = body_to_check

# clean up the broken head in many efiction printable sites
body.sub!('</style>', '</style></head>') unless body.match('</head>')
@chapter_contents << body
chapnum = chapnum + 1
end
Expand Down Expand Up @@ -533,6 +549,20 @@ def parse_common(story, location = nil, encoding = nil)
work_params = { :title => "UPLOADED WORK", :chapter_attributes => {:content => ""} }

@doc = Nokogiri::HTML.parse(story, nil, encoding) rescue ""

# Try to convert all relative links to absolute
base = @doc.css('base').present? ? @doc.css('base')[0]['href'] : location.split('?').first
if base.present?
@doc.css('a').each do |link|
if link['href'].present?
begin
query = link['href'].match(/(\?.*)$/) ? $1 : ''
link['href'] = URI.join(base, link['href'].gsub(/(\?.*)$/, '')).to_s + query
rescue
end
end
end
end

if location && (source = get_source_if_known(KNOWN_STORY_PARSERS, location))
params = eval("parse_story_from_#{source.downcase}(story)")
Expand Down Expand Up @@ -797,6 +827,7 @@ def parse_story_from_ffnet(story)
if !divs[0].nil?
divs[0].remove
end

storytext = clean_storytext(storytext.inner_html)

work_params[:notes] = ((@doc/"#storytext")/"p").first.try(:inner_html)
Expand Down Expand Up @@ -1017,9 +1048,13 @@ def download_with_timeout(location, limit = 10)
if story.blank?
raise Error, "We couldn't download anything from #{location}. Please make sure that the URL is correct and complete, and try again."
end

# clean up any erroneously included string terminator (Issue 785)
story.gsub!("\000", "")

story
end

def get_last_modified(location)
Timeout::timeout(STORY_DOWNLOAD_TIMEOUT) {
resp = open(location)
Expand Down
4 changes: 4 additions & 0 deletions app/models/work.rb
Expand Up @@ -427,6 +427,10 @@ def save_new_recipients
end
end

def marked_for_later?(user)
Reading.where(work_id: self.id, user_id: user.id, toread: true).exists?
end

########################################################################
# VISIBILITY
########################################################################
Expand Down
8 changes: 3 additions & 5 deletions app/views/external_authors/claim.html.erb
Expand Up @@ -2,7 +2,7 @@

<p class="message">
<%= ts("An archive including some of your work(s) has been moved to the Archive of Our Own. Please let us know what you'd
like us to do with them. If you do nothing, the archivist will keep watch over the work(s).") %>
like us to do with them. If you do nothing, the work(s) will remain attached to the archivist account.") %>
</p>

<p class="message">
Expand Down Expand Up @@ -92,7 +92,6 @@
</ul>
<p class="important message">
<%= ts("Important: If you tick \"Do not email me in future\" but do not tick \"Do not import works\", works may be imported without you being told. If that's not what you want, turn off importing as well as emails.") %>
<a href="#notimport"><%= ts("If that's not what you want, turn off importing") %></a>.
</p>
<%= submit_fieldset(f) %>
</fieldset>
Expand All @@ -102,10 +101,9 @@
<div class="notes module">
<h3><%= ts("Wait, wait, go over this again?") %></h3>
<ul class="notes">
<!--BACK END PLS LINKIFY-->
<li><%= ts("If you do nothing, the archivist will keep watch over the works.")%></li>
<li><%= ts("If you do nothing, the work(s) will remain attached to the archivist account.") %></li>
<% if logged_in? %>
<li><%= ts("You can claim your works.")%></li>
<li><%= ts("You can claim your works.") %></li>
<% else %>
<li><%= ts("You can create an account and claim your works (if you already have an account, log in to claim them)") %></li>
<% end %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/menu/_menu_search.html.erb
@@ -1,6 +1,6 @@
<ul class="menu" role="menu">
<li><%= span_if_current ts("Works"), search_works_path %></li>
<li><%= span_if_current ts("People"), search_people_path %></li>
<li><%= span_if_current ts("Bookmarks"), search_bookmarks_path %></li>
<li><%= span_if_current ts("Tags"), search_tags_path %></li>
</ul>
<li><%= span_if_current ts("People"), search_people_path %></li>
</ul>
2 changes: 1 addition & 1 deletion app/views/readings/_reading_blurb.html.erb
Expand Up @@ -22,7 +22,7 @@
<% else %>
<%= ts("Viewed %{count} times", :count => reading.view_count) %>
<% end %>
<% if reading.toread? %><%= ts('(Marked for later.)') %><% end %>
<% if reading.toread? %><%= ts('(Marked for Later.)') %><% end %>
<% if reading.toskip? %><%= ts('(Flagged to skip.)') %><% end %>
</h4>
Expand Down

0 comments on commit dd3b9b9

Please sign in to comment.