@ -10,7 +10,7 @@ var opmlParser = require ("opmlparser"); //6/23/15 by DW
var opmlData = {
flUseOutlineCache : false ,
outlineCache : new Object ( )
outlineCache : new Object ( ) ,
}
function getBoolean ( val ) { //12/5/13 by DW
@ -72,10 +72,6 @@ function getNameAtt (theNode) {
}
return ( nameatt ) ;
}
function typeIsDoc ( theNode ) {
var type = getNodeType ( theNode ) ;
return ( ( type !== undefined ) && ( type != "include" ) && ( type != "link" ) && ( type != "tweet" ) ) ;
}
function getNodeType ( theNode ) {
if ( theNode . type == "include" ) {
return ( theNode . includetype ) ; //this allows include nodes to have types
@ -96,20 +92,29 @@ function copyScalars (source, dest) { //8/31/14 by DW
}
}
}
function readInclude ( theIncludeNode , callback ) {
console . log ( "readInclude: url == " + theIncludeNode . url ) ;
readOpmlUrl ( theIncludeNode . url , function ( theOutline ) {
if ( theOutline === undefined ) {
callback ( undefined ) ;
function outlineVisiter ( theOutline , inlevelcallback , outlevelcallback , nodecallback , visitcompletecallback , flStopAtDocs ) {
function readInclude ( theIncludeNode , callback ) {
console . log ( "readInclude: url == " + theIncludeNode . url ) ;
readOpmlUrl ( theIncludeNode . url , function ( theOutline ) {
if ( theOutline === undefined ) {
callback ( undefined ) ;
}
else {
expandIncludes ( theOutline , function ( expandedOutline ) {
callback ( expandedOutline ) ;
} , flStopAtDocs ) ;
}
} ) ;
}
function typeIsDoc ( theNode ) {
if ( flStopAtDocs ) {
var type = getNodeType ( theNode ) ;
return ( ( type !== undefined ) && ( type != "include" ) && ( type != "link" ) && ( type != "tweet" ) ) ;
}
else {
expandIncludes ( theOutline , function ( expandedOutline ) {
callback ( expandedOutline ) ;
} ) ;
return ( false ) ;
}
} ) ;
}
function outlineVisiter ( theOutline , inlevelcallback , outlevelcallback , nodecallback , visitcompletecallback ) {
}
function doLevel ( head , path , levelcompletecallback ) {
function doOneSub ( head , ixsub ) {
if ( ( head . subs !== undefined ) && ( ixsub < head . subs . length ) ) {
@ -171,12 +176,17 @@ function outlineVisiter (theOutline, inlevelcallback, outlevelcallback, nodecall
doOneSub ( head , 0 ) ;
}
}
if ( flStopAtDocs === undefined ) { //7/15/15 by DW -- see note at top of routine
flStopAtDocs = true ;
}
doLevel ( theOutline , "" , function ( ) {
outlevelcallback ( ) ;
visitcompletecallback ( ) ;
} ) ;
}
function expandIncludes ( theOutline , callback ) {
function expandIncludes ( theOutline , callback , flStopAtDocs ) {
var theNewOutline = new Object ( ) , lastNewNode = theNewOutline , stack = new Array ( ) , currentOutline ;
function inlevelcallback ( ) {
stack [ stack . length ] = currentOutline ;
@ -195,11 +205,16 @@ function expandIncludes (theOutline, callback) {
currentOutline = stack [ stack . length - 1 ] ;
stack . length -- ; //pop the stack
}
if ( flStopAtDocs === undefined ) { //7/15/15 by DW
flStopAtDocs = true ;
}
outlineVisiter ( theOutline , inlevelcallback , outlevelcallback , nodecallback , function ( ) {
callback ( theNewOutline ) ;
} ) ;
} , flStopAtDocs );
}
function readOpmlString ( s , callback ) {
function readOpmlString ( s , callback , flExpandIncludes ) {
var opmlparser = new opmlParser ( ) ;
var outlineArray = new Array ( ) ;
var metadata = undefined ;
@ -265,14 +280,24 @@ function readOpmlString (s, callback) {
delete obj [ "#parentid" ] ;
}
}
expandIncludes ( theOutline , function ( expandedOutline ) {
if ( flExpandIncludes === undefined ) { //7/15/15 by DW
flExpandIncludes = true ;
}
if ( flExpandIncludes ) {
expandIncludes ( theOutline , function ( expandedOutline ) {
if ( callback != undefined ) {
callback ( expandedOutline , undefined ) ;
}
} , false ) ;
}
else {
if ( callback != undefined ) {
callback ( expandedOutline , undefined ) ;
callback ( th eOutline, undefined ) ;
}
} ) ;
}
} ) ;
}
function readOpmlFile ( f , callback ) { //6/25/15 by DW
fs . readFile ( f , function ( err , data ) {
if ( err ) {
@ -284,28 +309,24 @@ function readOpmlFile (f, callback) { //6/25/15 by DW
}
} ) ;
}
function readOpmlUrl ( urlOutline , callback ) {
if ( urlOutline === undefined ) { //6/28/15 by DW
console . log ( "readOpmlUrl: urlOutline is undefined." )
callback ( undefined ) ;
function readOpmlUrl ( urlOutline , callback , flExpandIncludes ) {
if ( flExpandIncludes === undefined ) {
flExpandIncludes = true ;
}
else {
request ( urlOutline , function ( err , response , body ) {
if ( err !== null ) {
console . log ( "readOpmlUrl: error reading file " + urlOutline + " == " + err . message )
request ( urlOutline , function ( err , response , body ) {
if ( err !== null ) {
console . log ( "readOpmlUrl: error reading file " + urlOutline + " == " + err . message )
callback ( undefined ) ;
}
else {
if ( response . statusCode != 200 ) {
console . log ( "readOpmlUrl: error reading file, statusCode == " + response . statusCode + ", urlOutline == " + urlOutline )
callback ( undefined ) ;
}
else {
if ( response . statusCode != 200 ) {
console . log ( "readOpmlUrl: error reading file, statusCode == " + response . statusCode + ", urlOutline == " + urlOutline )
callback ( undefined ) ;
}
else {
readOpmlString ( body . toString ( ) , callback ) ;
}
readOpmlString ( body . toString ( ) , callback , flExpandIncludes ) ;
}
} ) ;
}
}
} ) ;
}