const SCHOLAR_CONFIG = { GUID: 'scholar@chnm.gmu.edu', DB_FILE: 'scholar.sqlite', DB_REBUILD: false, // erase DB and recreate from schema DEBUG_LOGGING: true, DEBUG_TO_CONSOLE: true, // dump debug messages to console rather than (much slower) Debug Logger REPOSITORY_URL: 'http://chnm.gmu.edu/firefoxscholar/repo', REPOSITORY_CHECK_INTERVAL: 3600, // temp -- 86400, // 24 hours REPOSITORY_RETRY_INTERVAL: 3600 // 1 hour }; /* * Core functions */ var Scholar = new function(){ var _initialized = false; var _localizedStringBundle; // Privileged (public) methods this.init = init; this.debug = debug; this.varDump = varDump; this.getString = getString; this.flattenArguments = flattenArguments; this.join = join; this.inArray = inArray; this.arraySearch = arraySearch; this.randomString = randomString; this.getRandomID = getRandomID; // Public properties this.version; /* * Initialize the extension */ function init(){ if (_initialized){ return false; } // Load in the preferences branch for the extension Scholar.Prefs.init(); // Load in the extension version from the extension manager var nsIUpdateItem = Components.interfaces.nsIUpdateItem; var gExtensionManager = Components.classes["@mozilla.org/extensions/manager;1"] .getService(Components.interfaces.nsIExtensionManager); var itemType = nsIUpdateItem.TYPE_EXTENSION; this.version = gExtensionManager.getItemForID(SCHOLAR_CONFIG['GUID']).version; // Load in the localization stringbundle for use by getString(name) var src = 'chrome://scholar/locale/scholar.properties'; var localeService = Components.classes["@mozilla.org/intl/nslocaleservice;1"] .getService(Components.interfaces.nsILocaleService); var appLocale = localeService.getApplicationLocale(); var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"] .getService(Components.interfaces.nsIStringBundleService); _localizedStringBundle = stringBundleService.createBundle(src, appLocale); // Trigger updating of schema and scrapers Scholar.Schema.updateSchema(); Scholar.Schema.updateScrapersRemote(); _initialized = true; return true; } /* * Debug logging function * * Uses DebugLogger extension available from http://mozmonkey.com/debuglogger/ * if available, otherwise the console (in which case boolean browser.dom.window.dump.enabled * must be created and set to true in about:config) * * Defaults to log level 3 if level not provided */ function debug(message, level) { if (!SCHOLAR_CONFIG['DEBUG_LOGGING']){ return false; } if (typeof message!='string'){ message = Scholar.varDump(message); } if (!level){ level = 3; } if (!SCHOLAR_CONFIG['DEBUG_TO_CONSOLE']){ try { var logManager = Components.classes["@mozmonkey.com/debuglogger/manager;1"] .getService(Components.interfaces.nsIDebugLoggerManager); var logger = logManager.registerLogger("Scholar for Firefox"); } catch (e){} } if (logger){ logger.log(level, message); } else { dump('scholar(' + level + '): ' + message + "\n\n"); } return true; } /** * PHP var_dump equivalent for JS * * Adapted from http://binnyva.blogspot.com/2005/10/dump-function-javascript-equivalent-of.html */ function varDump(arr,level) { var dumped_text = ""; if (!level){ level = 0; } // The padding given at the beginning of the line. var level_padding = ""; for (var j=0;j function(...){...} \n"; } else { dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n"; } } } } else { // Stings/Chars/Numbers etc. dumped_text = "===>"+arr+"<===("+typeof(arr)+")"; } return dumped_text; } function getString(name){ try { var l10n = _localizedStringBundle.GetStringFromName(name); } catch (e){ throw ('Localized string not available for ' + name); } return l10n; } /* * Flattens mixed arrays/values in a passed _arguments_ object and returns * an array of values -- allows for functions to accept both arrays of * values and/or an arbitrary number of individual values */ function flattenArguments(args){ // Put passed scalar values into an array if (typeof args!='object'){ args = [args]; } var returns = new Array(); for (var i=0; i