Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby27/share/ruby/rss
File: atom.rb
# frozen_string_literal: false
[0] Fix | Delete
require_relative 'parser'
[1] Fix | Delete
[2] Fix | Delete
module RSS
[3] Fix | Delete
##
[4] Fix | Delete
# Atom is an XML-based document format that is used to describe 'feeds' of related information.
[5] Fix | Delete
# A typical use is in a news feed where the information is periodically updated and which users
[6] Fix | Delete
# can subscribe to. The Atom format is described in http://tools.ietf.org/html/rfc4287
[7] Fix | Delete
#
[8] Fix | Delete
# The Atom module provides support in reading and creating feeds.
[9] Fix | Delete
#
[10] Fix | Delete
# See the RSS module for examples consuming and creating feeds.
[11] Fix | Delete
module Atom
[12] Fix | Delete
[13] Fix | Delete
##
[14] Fix | Delete
# The Atom URI W3C Namespace
[15] Fix | Delete
[16] Fix | Delete
URI = "http://www.w3.org/2005/Atom"
[17] Fix | Delete
[18] Fix | Delete
##
[19] Fix | Delete
# The XHTML URI W3C Namespace
[20] Fix | Delete
[21] Fix | Delete
XHTML_URI = "http://www.w3.org/1999/xhtml"
[22] Fix | Delete
[23] Fix | Delete
module CommonModel
[24] Fix | Delete
NSPOOL = {}
[25] Fix | Delete
ELEMENTS = []
[26] Fix | Delete
[27] Fix | Delete
def self.append_features(klass)
[28] Fix | Delete
super
[29] Fix | Delete
klass.install_must_call_validator("atom", URI)
[30] Fix | Delete
[
[31] Fix | Delete
["lang", :xml],
[32] Fix | Delete
["base", :xml],
[33] Fix | Delete
].each do |name, uri, required|
[34] Fix | Delete
klass.install_get_attribute(name, uri, required, [nil, :inherit])
[35] Fix | Delete
end
[36] Fix | Delete
klass.class_eval do
[37] Fix | Delete
class << self
[38] Fix | Delete
# Returns the Atom URI W3C Namespace
[39] Fix | Delete
def required_uri
[40] Fix | Delete
URI
[41] Fix | Delete
end
[42] Fix | Delete
[43] Fix | Delete
# Returns true
[44] Fix | Delete
def need_parent?
[45] Fix | Delete
true
[46] Fix | Delete
end
[47] Fix | Delete
end
[48] Fix | Delete
end
[49] Fix | Delete
end
[50] Fix | Delete
end
[51] Fix | Delete
[52] Fix | Delete
module ContentModel
[53] Fix | Delete
module ClassMethods
[54] Fix | Delete
def content_type
[55] Fix | Delete
@content_type ||= nil
[56] Fix | Delete
end
[57] Fix | Delete
end
[58] Fix | Delete
[59] Fix | Delete
class << self
[60] Fix | Delete
def append_features(klass)
[61] Fix | Delete
super
[62] Fix | Delete
klass.extend(ClassMethods)
[63] Fix | Delete
klass.content_setup(klass.content_type, klass.tag_name)
[64] Fix | Delete
end
[65] Fix | Delete
end
[66] Fix | Delete
[67] Fix | Delete
def maker_target(target)
[68] Fix | Delete
target
[69] Fix | Delete
end
[70] Fix | Delete
[71] Fix | Delete
private
[72] Fix | Delete
def setup_maker_element_writer
[73] Fix | Delete
"#{self.class.name.split(/::/).last.downcase}="
[74] Fix | Delete
end
[75] Fix | Delete
[76] Fix | Delete
def setup_maker_element(target)
[77] Fix | Delete
target.__send__(setup_maker_element_writer, content)
[78] Fix | Delete
super
[79] Fix | Delete
end
[80] Fix | Delete
end
[81] Fix | Delete
[82] Fix | Delete
module URIContentModel
[83] Fix | Delete
class << self
[84] Fix | Delete
def append_features(klass)
[85] Fix | Delete
super
[86] Fix | Delete
klass.class_eval do
[87] Fix | Delete
@content_type = [nil, :uri]
[88] Fix | Delete
include(ContentModel)
[89] Fix | Delete
end
[90] Fix | Delete
end
[91] Fix | Delete
end
[92] Fix | Delete
end
[93] Fix | Delete
[94] Fix | Delete
# The TextConstruct module is used to define a Text construct Atom element,
[95] Fix | Delete
# which is used to store small quantities of human-readable text.
[96] Fix | Delete
#
[97] Fix | Delete
# The TextConstruct has a type attribute, e.g. text, html, xhtml
[98] Fix | Delete
#
[99] Fix | Delete
# Reference: https://validator.w3.org/feed/docs/rfc4287.html#text.constructs
[100] Fix | Delete
module TextConstruct
[101] Fix | Delete
def self.append_features(klass)
[102] Fix | Delete
super
[103] Fix | Delete
klass.class_eval do
[104] Fix | Delete
[
[105] Fix | Delete
["type", ""],
[106] Fix | Delete
].each do |name, uri, required|
[107] Fix | Delete
install_get_attribute(name, uri, required, :text_type)
[108] Fix | Delete
end
[109] Fix | Delete
[110] Fix | Delete
content_setup
[111] Fix | Delete
add_need_initialize_variable("xhtml")
[112] Fix | Delete
[113] Fix | Delete
class << self
[114] Fix | Delete
def xml_getter
[115] Fix | Delete
"xhtml"
[116] Fix | Delete
end
[117] Fix | Delete
[118] Fix | Delete
def xml_setter
[119] Fix | Delete
"xhtml="
[120] Fix | Delete
end
[121] Fix | Delete
end
[122] Fix | Delete
end
[123] Fix | Delete
end
[124] Fix | Delete
[125] Fix | Delete
attr_writer :xhtml
[126] Fix | Delete
[127] Fix | Delete
# Returns or builds the XHTML content.
[128] Fix | Delete
def xhtml
[129] Fix | Delete
return @xhtml if @xhtml.nil?
[130] Fix | Delete
if @xhtml.is_a?(XML::Element) and
[131] Fix | Delete
[@xhtml.name, @xhtml.uri] == ["div", XHTML_URI]
[132] Fix | Delete
return @xhtml
[133] Fix | Delete
end
[134] Fix | Delete
[135] Fix | Delete
children = @xhtml
[136] Fix | Delete
children = [children] unless children.is_a?(Array)
[137] Fix | Delete
XML::Element.new("div", nil, XHTML_URI,
[138] Fix | Delete
{"xmlns" => XHTML_URI}, children)
[139] Fix | Delete
end
[140] Fix | Delete
[141] Fix | Delete
# Returns true if type is "xhtml".
[142] Fix | Delete
def have_xml_content?
[143] Fix | Delete
@type == "xhtml"
[144] Fix | Delete
end
[145] Fix | Delete
[146] Fix | Delete
# Raises a MissingTagError or NotExpectedTagError
[147] Fix | Delete
# if the element is not properly formatted.
[148] Fix | Delete
def atom_validate(ignore_unknown_element, tags, uri)
[149] Fix | Delete
if have_xml_content?
[150] Fix | Delete
if @xhtml.nil?
[151] Fix | Delete
raise MissingTagError.new("div", tag_name)
[152] Fix | Delete
end
[153] Fix | Delete
unless [@xhtml.name, @xhtml.uri] == ["div", XHTML_URI]
[154] Fix | Delete
raise NotExpectedTagError.new(@xhtml.name, @xhtml.uri, tag_name)
[155] Fix | Delete
end
[156] Fix | Delete
end
[157] Fix | Delete
end
[158] Fix | Delete
[159] Fix | Delete
private
[160] Fix | Delete
def maker_target(target)
[161] Fix | Delete
target.__send__(self.class.name.split(/::/).last.downcase) {|x| x}
[162] Fix | Delete
end
[163] Fix | Delete
[164] Fix | Delete
def setup_maker_attributes(target)
[165] Fix | Delete
target.type = type
[166] Fix | Delete
target.content = content
[167] Fix | Delete
target.xml_content = @xhtml
[168] Fix | Delete
end
[169] Fix | Delete
end
[170] Fix | Delete
[171] Fix | Delete
# The PersonConstruct module is used to define a person Atom element that can be
[172] Fix | Delete
# used to describe a person, corporation or similar entity.
[173] Fix | Delete
#
[174] Fix | Delete
# The PersonConstruct has a Name, Uri and Email child elements.
[175] Fix | Delete
#
[176] Fix | Delete
# Reference: https://validator.w3.org/feed/docs/rfc4287.html#atomPersonConstruct
[177] Fix | Delete
module PersonConstruct
[178] Fix | Delete
[179] Fix | Delete
# Adds attributes for name, uri, and email to the +klass+
[180] Fix | Delete
def self.append_features(klass)
[181] Fix | Delete
super
[182] Fix | Delete
klass.class_eval do
[183] Fix | Delete
[
[184] Fix | Delete
["name", nil],
[185] Fix | Delete
["uri", "?"],
[186] Fix | Delete
["email", "?"],
[187] Fix | Delete
].each do |tag, occurs|
[188] Fix | Delete
install_have_attribute_element(tag, URI, occurs, nil, :content)
[189] Fix | Delete
end
[190] Fix | Delete
end
[191] Fix | Delete
end
[192] Fix | Delete
[193] Fix | Delete
def maker_target(target)
[194] Fix | Delete
target.__send__("new_#{self.class.name.split(/::/).last.downcase}")
[195] Fix | Delete
end
[196] Fix | Delete
[197] Fix | Delete
# The name of the person or entity.
[198] Fix | Delete
#
[199] Fix | Delete
# Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.name
[200] Fix | Delete
class Name < RSS::Element
[201] Fix | Delete
include CommonModel
[202] Fix | Delete
include ContentModel
[203] Fix | Delete
end
[204] Fix | Delete
[205] Fix | Delete
# The URI of the person or entity.
[206] Fix | Delete
#
[207] Fix | Delete
# Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.uri
[208] Fix | Delete
class Uri < RSS::Element
[209] Fix | Delete
include CommonModel
[210] Fix | Delete
include URIContentModel
[211] Fix | Delete
end
[212] Fix | Delete
[213] Fix | Delete
# The email of the person or entity.
[214] Fix | Delete
#
[215] Fix | Delete
# Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.email
[216] Fix | Delete
class Email < RSS::Element
[217] Fix | Delete
include CommonModel
[218] Fix | Delete
include ContentModel
[219] Fix | Delete
end
[220] Fix | Delete
end
[221] Fix | Delete
[222] Fix | Delete
# Element used to describe an Atom date and time in the ISO 8601 format
[223] Fix | Delete
#
[224] Fix | Delete
# Examples:
[225] Fix | Delete
# * 2013-03-04T15:30:02Z
[226] Fix | Delete
# * 2013-03-04T10:30:02-05:00
[227] Fix | Delete
module DateConstruct
[228] Fix | Delete
def self.append_features(klass)
[229] Fix | Delete
super
[230] Fix | Delete
klass.class_eval do
[231] Fix | Delete
@content_type = :w3cdtf
[232] Fix | Delete
include(ContentModel)
[233] Fix | Delete
end
[234] Fix | Delete
end
[235] Fix | Delete
[236] Fix | Delete
# Raises NotAvailableValueError if element content is nil
[237] Fix | Delete
def atom_validate(ignore_unknown_element, tags, uri)
[238] Fix | Delete
raise NotAvailableValueError.new(tag_name, "") if content.nil?
[239] Fix | Delete
end
[240] Fix | Delete
end
[241] Fix | Delete
[242] Fix | Delete
module DuplicateLinkChecker
[243] Fix | Delete
# Checks if there are duplicate links with the same type and hreflang attributes
[244] Fix | Delete
# that have an alternate (or empty) rel attribute
[245] Fix | Delete
#
[246] Fix | Delete
# Raises a TooMuchTagError if there are duplicates found
[247] Fix | Delete
def validate_duplicate_links(links)
[248] Fix | Delete
link_infos = {}
[249] Fix | Delete
links.each do |link|
[250] Fix | Delete
rel = link.rel || "alternate"
[251] Fix | Delete
next unless rel == "alternate"
[252] Fix | Delete
key = [link.hreflang, link.type]
[253] Fix | Delete
if link_infos.has_key?(key)
[254] Fix | Delete
raise TooMuchTagError.new("link", tag_name)
[255] Fix | Delete
end
[256] Fix | Delete
link_infos[key] = true
[257] Fix | Delete
end
[258] Fix | Delete
end
[259] Fix | Delete
end
[260] Fix | Delete
[261] Fix | Delete
# Defines the top-level element of an Atom Feed Document.
[262] Fix | Delete
# It consists of a number of children Entry elements,
[263] Fix | Delete
# and has the following attributes:
[264] Fix | Delete
#
[265] Fix | Delete
# * author
[266] Fix | Delete
# * categories
[267] Fix | Delete
# * category
[268] Fix | Delete
# * content
[269] Fix | Delete
# * contributor
[270] Fix | Delete
# * entries (aliased as items)
[271] Fix | Delete
# * entry
[272] Fix | Delete
# * generator
[273] Fix | Delete
# * icon
[274] Fix | Delete
# * id
[275] Fix | Delete
# * link
[276] Fix | Delete
# * logo
[277] Fix | Delete
# * rights
[278] Fix | Delete
# * subtitle
[279] Fix | Delete
# * title
[280] Fix | Delete
# * updated
[281] Fix | Delete
#
[282] Fix | Delete
# Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.feed
[283] Fix | Delete
class Feed < RSS::Element
[284] Fix | Delete
include RootElementMixin
[285] Fix | Delete
include CommonModel
[286] Fix | Delete
include DuplicateLinkChecker
[287] Fix | Delete
[288] Fix | Delete
install_ns('', URI)
[289] Fix | Delete
[290] Fix | Delete
[
[291] Fix | Delete
["author", "*", :children],
[292] Fix | Delete
["category", "*", :children, "categories"],
[293] Fix | Delete
["contributor", "*", :children],
[294] Fix | Delete
["generator", "?"],
[295] Fix | Delete
["icon", "?", nil, :content],
[296] Fix | Delete
["id", nil, nil, :content],
[297] Fix | Delete
["link", "*", :children],
[298] Fix | Delete
["logo", "?"],
[299] Fix | Delete
["rights", "?"],
[300] Fix | Delete
["subtitle", "?", nil, :content],
[301] Fix | Delete
["title", nil, nil, :content],
[302] Fix | Delete
["updated", nil, nil, :content],
[303] Fix | Delete
["entry", "*", :children, "entries"],
[304] Fix | Delete
].each do |tag, occurs, type, *args|
[305] Fix | Delete
type ||= :child
[306] Fix | Delete
__send__("install_have_#{type}_element",
[307] Fix | Delete
tag, URI, occurs, tag, *args)
[308] Fix | Delete
end
[309] Fix | Delete
[310] Fix | Delete
# Creates a new Atom feed
[311] Fix | Delete
def initialize(version=nil, encoding=nil, standalone=nil)
[312] Fix | Delete
super("1.0", version, encoding, standalone)
[313] Fix | Delete
@feed_type = "atom"
[314] Fix | Delete
@feed_subtype = "feed"
[315] Fix | Delete
end
[316] Fix | Delete
[317] Fix | Delete
alias_method :items, :entries
[318] Fix | Delete
[319] Fix | Delete
# Returns true if there are any authors for the feed or any of the Entry
[320] Fix | Delete
# child elements have an author
[321] Fix | Delete
def have_author?
[322] Fix | Delete
authors.any? {|author| !author.to_s.empty?} or
[323] Fix | Delete
entries.any? {|entry| entry.have_author?(false)}
[324] Fix | Delete
end
[325] Fix | Delete
[326] Fix | Delete
private
[327] Fix | Delete
def atom_validate(ignore_unknown_element, tags, uri)
[328] Fix | Delete
unless have_author?
[329] Fix | Delete
raise MissingTagError.new("author", tag_name)
[330] Fix | Delete
end
[331] Fix | Delete
validate_duplicate_links(links)
[332] Fix | Delete
end
[333] Fix | Delete
[334] Fix | Delete
def have_required_elements?
[335] Fix | Delete
super and have_author?
[336] Fix | Delete
end
[337] Fix | Delete
[338] Fix | Delete
def maker_target(maker)
[339] Fix | Delete
maker.channel
[340] Fix | Delete
end
[341] Fix | Delete
[342] Fix | Delete
def setup_maker_element(channel)
[343] Fix | Delete
prev_dc_dates = channel.dc_dates.to_a.dup
[344] Fix | Delete
super
[345] Fix | Delete
channel.about = id.content if id
[346] Fix | Delete
channel.dc_dates.replace(prev_dc_dates)
[347] Fix | Delete
end
[348] Fix | Delete
[349] Fix | Delete
def setup_maker_elements(channel)
[350] Fix | Delete
super
[351] Fix | Delete
items = channel.maker.items
[352] Fix | Delete
entries.each do |entry|
[353] Fix | Delete
entry.setup_maker(items)
[354] Fix | Delete
end
[355] Fix | Delete
end
[356] Fix | Delete
[357] Fix | Delete
# PersonConstruct that contains information regarding the author
[358] Fix | Delete
# of a Feed or Entry.
[359] Fix | Delete
#
[360] Fix | Delete
# Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.author
[361] Fix | Delete
class Author < RSS::Element
[362] Fix | Delete
include CommonModel
[363] Fix | Delete
include PersonConstruct
[364] Fix | Delete
end
[365] Fix | Delete
[366] Fix | Delete
# Contains information about a category associated with a Feed or Entry.
[367] Fix | Delete
# It has the following attributes:
[368] Fix | Delete
#
[369] Fix | Delete
# * term
[370] Fix | Delete
# * scheme
[371] Fix | Delete
# * label
[372] Fix | Delete
#
[373] Fix | Delete
# Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.category
[374] Fix | Delete
class Category < RSS::Element
[375] Fix | Delete
include CommonModel
[376] Fix | Delete
[377] Fix | Delete
[
[378] Fix | Delete
["term", "", true],
[379] Fix | Delete
["scheme", "", false, [nil, :uri]],
[380] Fix | Delete
["label", ""],
[381] Fix | Delete
].each do |name, uri, required, type|
[382] Fix | Delete
install_get_attribute(name, uri, required, type)
[383] Fix | Delete
end
[384] Fix | Delete
[385] Fix | Delete
private
[386] Fix | Delete
def maker_target(target)
[387] Fix | Delete
target.new_category
[388] Fix | Delete
end
[389] Fix | Delete
end
[390] Fix | Delete
[391] Fix | Delete
# PersonConstruct that contains information regarding the
[392] Fix | Delete
# contributors of a Feed or Entry.
[393] Fix | Delete
#
[394] Fix | Delete
# Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.contributor
[395] Fix | Delete
class Contributor < RSS::Element
[396] Fix | Delete
include CommonModel
[397] Fix | Delete
include PersonConstruct
[398] Fix | Delete
end
[399] Fix | Delete
[400] Fix | Delete
# Contains information on the agent used to generate the feed.
[401] Fix | Delete
#
[402] Fix | Delete
# Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.generator
[403] Fix | Delete
class Generator < RSS::Element
[404] Fix | Delete
include CommonModel
[405] Fix | Delete
include ContentModel
[406] Fix | Delete
[407] Fix | Delete
[
[408] Fix | Delete
["uri", "", false, [nil, :uri]],
[409] Fix | Delete
["version", ""],
[410] Fix | Delete
].each do |name, uri, required, type|
[411] Fix | Delete
install_get_attribute(name, uri, required, type)
[412] Fix | Delete
end
[413] Fix | Delete
[414] Fix | Delete
private
[415] Fix | Delete
def setup_maker_attributes(target)
[416] Fix | Delete
target.generator do |generator|
[417] Fix | Delete
generator.uri = uri if uri
[418] Fix | Delete
generator.version = version if version
[419] Fix | Delete
end
[420] Fix | Delete
end
[421] Fix | Delete
end
[422] Fix | Delete
[423] Fix | Delete
# Defines an image that provides a visual identification for a eed.
[424] Fix | Delete
# The image should have an aspect ratio of 1:1.
[425] Fix | Delete
#
[426] Fix | Delete
# Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.icon
[427] Fix | Delete
class Icon < RSS::Element
[428] Fix | Delete
include CommonModel
[429] Fix | Delete
include URIContentModel
[430] Fix | Delete
end
[431] Fix | Delete
[432] Fix | Delete
# Defines the Universally Unique Identifier (UUID) for a Feed or Entry.
[433] Fix | Delete
#
[434] Fix | Delete
# Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.id
[435] Fix | Delete
class Id < RSS::Element
[436] Fix | Delete
include CommonModel
[437] Fix | Delete
include URIContentModel
[438] Fix | Delete
end
[439] Fix | Delete
[440] Fix | Delete
# Defines a reference to a Web resource. It has the following
[441] Fix | Delete
# attributes:
[442] Fix | Delete
#
[443] Fix | Delete
# * href
[444] Fix | Delete
# * rel
[445] Fix | Delete
# * type
[446] Fix | Delete
# * hreflang
[447] Fix | Delete
# * title
[448] Fix | Delete
# * length
[449] Fix | Delete
#
[450] Fix | Delete
# Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.link
[451] Fix | Delete
class Link < RSS::Element
[452] Fix | Delete
include CommonModel
[453] Fix | Delete
[454] Fix | Delete
[
[455] Fix | Delete
["href", "", true, [nil, :uri]],
[456] Fix | Delete
["rel", ""],
[457] Fix | Delete
["type", ""],
[458] Fix | Delete
["hreflang", ""],
[459] Fix | Delete
["title", ""],
[460] Fix | Delete
["length", ""],
[461] Fix | Delete
].each do |name, uri, required, type|
[462] Fix | Delete
install_get_attribute(name, uri, required, type)
[463] Fix | Delete
end
[464] Fix | Delete
[465] Fix | Delete
private
[466] Fix | Delete
def maker_target(target)
[467] Fix | Delete
target.new_link
[468] Fix | Delete
end
[469] Fix | Delete
end
[470] Fix | Delete
[471] Fix | Delete
# Defines an image that provides a visual identification for the Feed.
[472] Fix | Delete
# The image should have an aspect ratio of 2:1 (horizontal:vertical).
[473] Fix | Delete
#
[474] Fix | Delete
# Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.logo
[475] Fix | Delete
class Logo < RSS::Element
[476] Fix | Delete
include CommonModel
[477] Fix | Delete
include URIContentModel
[478] Fix | Delete
[479] Fix | Delete
def maker_target(target)
[480] Fix | Delete
target.maker.image
[481] Fix | Delete
end
[482] Fix | Delete
[483] Fix | Delete
private
[484] Fix | Delete
def setup_maker_element_writer
[485] Fix | Delete
"url="
[486] Fix | Delete
end
[487] Fix | Delete
end
[488] Fix | Delete
[489] Fix | Delete
# TextConstruct that contains copyright information regarding
[490] Fix | Delete
# the content in an Entry or Feed. It should not be used to
[491] Fix | Delete
# convey machine readable licensing information.
[492] Fix | Delete
#
[493] Fix | Delete
# Reference: https://validator.w3.org/feed/docs/rfc4287.html#element.rights
[494] Fix | Delete
class Rights < RSS::Element
[495] Fix | Delete
include CommonModel
[496] Fix | Delete
include TextConstruct
[497] Fix | Delete
end
[498] Fix | Delete
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function