lib/feed_tools/feed_item.rb in feedtools-0.2.19 vs lib/feed_tools/feed_item.rb in feedtools-0.2.20

- old
+ new

@@ -342,19 +342,25 @@ # Returns the feed item content def content if @content.nil? repair_entities = false content_node = try_xpaths(self.root_node, [ + "atom10:content", + "atom03:content", + "atom:content", "content:encoded", "content", "fullitem", "xhtml:body", "body", "encoded", "description", "tagline", "subtitle", + "atom10:summary", + "atom03:summary", + "atom:summary", "summary", "abstract", "blurb", "info" ]) @@ -409,10 +415,89 @@ # Sets the feed item content def content=(new_content) @content = new_content end + + # Returns the feed item summary + def summary + if @summary.nil? + repair_entities = false + summary_node = try_xpaths(self.root_node, [ + "atom10:summary", + "atom03:summary", + "atom:summary", + "summary", + "abstract", + "blurb", + "description", + "tagline", + "subtitle", + "fullitem", + "xhtml:body", + "body", + "content:encoded", + "encoded", + "atom10:content", + "atom03:content", + "atom:content", + "content", + "info" + ]) + if summary_node.nil? + return nil + end + summary_type = try_xpaths(summary_node, "@type", + :select_result_value => true) + summary_mode = try_xpaths(summary_node, "@mode", + :select_result_value => true) + summary_encoding = try_xpaths(summary_node, "@encoding", + :select_result_value => true) + + # Note that we're checking for misuse of type, mode and encoding here + if !summary_encoding.blank? + @summary = + "[Embedded data objects are not currently supported.]" + elsif summary_node.cdatas.size > 0 + @summary = summary_node.cdatas.first.value + elsif summary_type == "base64" || summary_mode == "base64" || + summary_encoding == "base64" + @summary = Base64.decode64(summary_node.inner_xml.strip) + elsif summary_type == "xhtml" || summary_mode == "xhtml" || + summary_type == "xml" || summary_mode == "xml" || + summary_type == "application/xhtml+xml" + @summary = summary_node.inner_xml + elsif summary_type == "escaped" || summary_mode == "escaped" + @summary = FeedTools.unescape_entities( + summary_node.inner_xml) + else + @summary = summary_node.inner_xml + repair_entities = true + end + if @summary.blank? + @summary = self.itunes_summary + end + if @summary.blank? + @summary = self.itunes_subtitle + end + + unless @summary.blank? + @summary = FeedTools.sanitize_html(@summary, :strip) + @summary = FeedTools.unescape_entities(@summary) if repair_entities + @summary = FeedTools.tidy_html(@summary) + end + + @summary = @summary.strip unless @summary.nil? + @summary = nil if @summary.blank? + end + return @summary + end + + # Sets the feed item summary + def summary=(new_summary) + @summary = new_summary + end # Returns the contents of the itunes:summary element def itunes_summary if @itunes_summary.nil? @itunes_summary = try_xpaths(self.root_node, [ @@ -495,11 +580,13 @@ "guid[@isPermaLink='true']/text()", "@href", "a/@href" ], :select_result_value => true) if @link.blank? - if FeedTools.is_uri? self.guid + if FeedTools.is_uri?(self.guid) && + !(self.guid =~ /^urn:uuid:/) && + !(self.guid =~ /^tag:/) @link = self.guid end end if !@link.blank? @link = FeedTools.unescape_entities(@link) @@ -599,21 +686,23 @@ if @images.nil? @images = [] image_nodes = try_xpaths_all(self.root_node, [ "image", "logo", + "apple-wallpapers:image", "atom10:link", "atom03:link", "atom:link", "link" ]) unless image_nodes.blank? for image_node in image_nodes image = FeedTools::Feed::Image.new image.url = try_xpaths(image_node, [ "url/text()", - "@rdf:resource" + "@rdf:resource", + "text()" ], :select_result_value => true) if image.url.blank? && (image_node.name == "logo" || (image_node.attributes['type'].to_s =~ /^image/) == 0) image.url = try_xpaths(image_node, [ "@atom10:href", @@ -1213,27 +1302,39 @@ end end if @author.name.blank? @author.name = FeedTools.unescape_entities( try_xpaths(author_node, [ + "atom10:name/text()", + "atom03:name/text()", + "atom:name/text()", "name/text()", "@name" ], :select_result_value => true) ) end if @author.email.blank? @author.email = FeedTools.unescape_entities( try_xpaths(author_node, [ + "atom10:email/text()", + "atom03:email/text()", + "atom:email/text()", "email/text()", "@email" ], :select_result_value => true) ) end if @author.url.blank? @author.url = FeedTools.unescape_entities( try_xpaths(author_node, [ + "atom10:url/text()", + "atom03:url/text()", + "atom:url/text()", "url/text()", + "atom10:uri/text()", + "atom03:uri/text()", + "atom:uri/text()", "uri/text()", "@url", "@uri", "@href" ], :select_result_value => true) @@ -1919,11 +2020,9 @@ else raise "Unsupported feed format/version." end end - alias_method :summary, :content - alias_method :summary=, :content= alias_method :abstract, :content alias_method :abstract=, :content= alias_method :description, :content alias_method :description=, :content= alias_method :guid, :id