Вход Регистрация
Файл: error-kitty/node_modules/cheerio/node_modules/htmlparser2/lib/FeedHandler.js
Строк: 144
<?php
var index = require("./index.js"),
    
DomHandler index.DomHandler,
    
DomUtils index.DomUtils;

//TODO: make this a streamable handler
function FeedHandler(callbackoptions){
    
this.init(callbackoptions);
}

require(
"util").inherits(FeedHandlerDomHandler);

FeedHandler.prototype.init DomHandler;

function 
getElements(whatwhere){
    return 
DomUtils.getElementsByTagName(whatwheretrue);
}
function 
getOneElement(whatwhere){
    return 
DomUtils.getElementsByTagName(whatwheretrue1)[0];
}
function 
fetch(whatwhererecurse){
    return 
DomUtils.getText(
        
DomUtils.getElementsByTagName(whatwhererecurse1)
    ).
trim();
}

function 
addConditionally(objpropwhatwhererecurse){
    var 
tmp fetch(whatwhererecurse);
    if(
tmpobj[prop] = tmp;
}

var 
isValidFeed = function(value) {
    return 
value === "rss" || value === "feed" || value === "rdf:RDF";
};

FeedHandler.prototype.onend = function() {
    var 
feed = {},
        
feedRoot getOneElement(isValidFeedthis.dom),
        
tmpchilds;

    if(
feedRoot){
        if(
feedRoot.name === "feed"){
            
childs feedRoot.children;

            
feed.type "atom";
            
addConditionally(feed"id""id"childs);
            
addConditionally(feed"title""title"childs);
            if((
tmp getOneElement("link"childs)) && (tmp tmp.attribs) && (tmp tmp.href)) feed.link tmp;
            
addConditionally(feed"description""subtitle"childs);
            if((
tmp fetch("updated"childs))) feed.updated = new Date(tmp);
            
addConditionally(feed"author""email"childstrue);

            
feed.items getElements("entry"childs).map(function(item){
                var 
entry = {}, tmp;

                
item item.children;

                
addConditionally(entry"id""id"item);
                
addConditionally(entry"title""title"item);
                if((
tmp getOneElement("link"item)) && (tmp tmp.attribs) && (tmp tmp.href)) entry.link tmp;
                
addConditionally(entry"description""summary"item);
                if((
tmp fetch("updated"item))) entry.pubDate = new Date(tmp);
                return 
entry;
            });
        } else {
            
childs getOneElement("channel"feedRoot.children).children;

            
feed.type feedRoot.name.substr(03);
            
feed.id "";
            
addConditionally(feed"title""title"childs);
            
addConditionally(feed"link""link"childs);
            
addConditionally(feed"description""description"childs);
            if((
tmp fetch("lastBuildDate"childs))) feed.updated = new Date(tmp);
            
addConditionally(feed"author""managingEditor"childstrue);

            
feed.items getElements("item"feedRoot.children).map(function(item){
                var 
entry = {}, tmp;

                
item item.children;

                
addConditionally(entry"id""guid"item);
                
addConditionally(entry"title""title"item);
                
addConditionally(entry"link""link"item);
                
addConditionally(entry"description""description"item);
                if((
tmp fetch("pubDate"item))) entry.pubDate = new Date(tmp);
                return 
entry;
            });
        }
    }
    
this.dom feed;
    
DomHandler.prototype._handleCallback.call(
        
thisfeedRoot null Error("couldn't find root of feed")
    );
};

module.exports FeedHandler;
?>
Онлайн: 0
Реклама