Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 0 additions & 150 deletions lib/plugins/system/meta/HTMLMetaHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,156 +43,6 @@ HTMLMetaHandler.prototype.onerror = function(err) {
this._callback(err);
};

HTMLMetaHandler.prototype.onopentag = function(name, attributes) {

if (this._end) return;

name = name.toUpperCase();

if (name === 'META') {

var metaTag = attributes;
var tagName = metaTag.property || metaTag.name;

if (tagName) {

if (/&[^;]+;/i.test(tagName)) {
tagName = decodeHTMLStrict(tagName);
}
var propertyParts = tagName.split(/(?::|\.)/);

var value = metaTag.content || metaTag.value || metaTag.src;

if (typeof value === 'string') {
// Remove new lines.
value = value.replace(/(\r\n|\n|\r)/gm, ' ');
}

if (/^\d+$/.test(value) && !/(title|description)/i.test(tagName)) { // convert to integer
value = parseInt(value, 10);
} else if (/^\d+\.\d+$/.test(value)) {
value = parseFloat(value);
}

if (typeof value !== 'undefined') {
merge(this._result, propertyParts, value);
}

} else if (!this._charset && metaTag['http-equiv'] && metaTag['http-equiv'].toLowerCase() == 'content-type') {

// Set encoding with <meta content='text/html; charset=UTF-8' http-equiv='Content-Type'/>
this._charset = getCharset(metaTag.content);

} else if (!this._charset && metaTag['charset']) {

// Set encoding with <meta charset="UTF-8" />.
this._charset = getCharset(metaTag.charset, true);

} else if (metaTag['http-equiv'] && metaTag['http-equiv'].toLowerCase() == 'x-frame-options') {

this._customProperties["x-frame-options"] = metaTag.content;

} else if (!this._refresh && metaTag['http-equiv'] && metaTag['http-equiv'].toLowerCase() == 'refresh') {

// ex.: http://tv.sme.sk/v/29770/kalinak-o-ficovi-cudujem-sa-ze-vedie-vladu.html
var refresh = metaTag.content && metaTag.content.match(/url=(?:'|")?([^'"]+)(?:'|")?/i);

if (refresh) {
this._refresh = decodeHTMLStrict(refresh[1]);
}

} else if (metaTag.name == "description") {

this._customProperties["html-description"] = metaTag.content;
}

} else if (name == 'TITLE') {

this._currentCustomTag = {
name: "html-title",
value: ""
};

} else if (name == 'LINK') {

var metaTag = attributes;
var name = metaTag.name;
var rel = metaTag.rel || name;
var title = metaTag.title;
var sizes = metaTag.sizes;
var type = metaTag.type;
var media = metaTag.media;
var color = metaTag.color; // for SVG
var href;

if (typeof(metaTag.href) == 'string') {
href = metaTag.href;
}

if (LINK_REL_SKIP_VALUES.indexOf(rel) == -1) {
var existingProperty = this._customProperties[rel];

if (existingProperty && !(existingProperty instanceof Array)) {
existingProperty = this._customProperties[rel] = [existingProperty];
}

if (!existingProperty && LINK_REL_ARRAY_VALUES.indexOf(rel) > -1) {
existingProperty = this._customProperties[rel] = [];
}

var property;
if (type || sizes || media || title || color) {
property = {
href: href
};
if (type) {
property.type = type;
}
if (sizes) {
property.sizes = sizes;
}
if (media) {
property.media = media;
}
if (title) {
property.title = title;
}
if (color) {
property.color = color;
}
} else {
property = href;
}

if (existingProperty) {
existingProperty.push(property);
} else {
this._customProperties[rel] = property;
}
}
} else if (name == 'SCRIPT') {

if (attributes.type === 'application/ld+json') {

this._currentCustomTag = {
name: "ld-json",
value: ""
}
}
} else if (name === 'HTML') {

if (attributes.dir) {this._customProperties['dir'] = attributes.dir;}
if (attributes.lang) {this._customProperties['lang'] = attributes.lang;}

}
};

HTMLMetaHandler.prototype.ontext = function(text) {
if (this._currentCustomTag) {
this._currentCustomTag.value += text;
}
};

HTMLMetaHandler.prototype.onclosetag = function(name) {

if (this._end) return;
Expand Down