diff --git a/chrome/content/zotero/xpcom/cite.js b/chrome/content/zotero/xpcom/cite.js index 3bb4c39ba..6d3fb6663 100644 --- a/chrome/content/zotero/xpcom/cite.js +++ b/chrome/content/zotero/xpcom/cite.js @@ -522,100 +522,20 @@ Zotero.Cite.System.prototype = { throw "Zotero.Cite.System.retrieveItem called on non-item "+item; } - // don't return URL or accessed information for journal articles if a - // pages field exists - var itemType = Zotero.ItemTypes.getName(zoteroItem.itemTypeID); - var cslType = CSL_TYPE_MAPPINGS[itemType]; - if(!cslType) cslType = "article"; - var ignoreURL = ((zoteroItem.getField("accessDate", true, true) || zoteroItem.getField("url", true, true)) && - ["journalArticle", "newspaperArticle", "magazineArticle"].indexOf(itemType) !== -1 + var cslItem = Zotero.Utilities.itemToCSLJSON(zoteroItem); + + if (!Zotero.Prefs.get("export.citePaperJournalArticleURL")) { + var itemType = Zotero.ItemTypes.getName(zoteroItem.itemTypeID); + // don't return URL or accessed information for journal articles if a + // pages field exists + if (["journalArticle", "newspaperArticle", "magazineArticle"].indexOf(itemType) !== -1 && zoteroItem.getField("pages") - && !Zotero.Prefs.get("export.citePaperJournalArticleURL")); - - var cslItem = { - 'id':zoteroItem.id, - 'type':cslType - }; - - // get all text variables (there must be a better way) - // TODO: does citeproc-js permit short forms? - for(var variable in CSL_TEXT_MAPPINGS) { - var fields = CSL_TEXT_MAPPINGS[variable]; - if(variable == "URL" && ignoreURL) continue; - for each(var field in fields) { - var value = zoteroItem.getField(field, false, true).toString(); - if(value != "") { - // Strip enclosing quotes - if(value.match(/^".+"$/)) { - value = value.substr(1, value.length-2); - } - cslItem[variable] = value; - break; - } + ) { + delete cslItem.URL; + delete cslItem.accessed; } } - // separate name variables - var authorID = Zotero.CreatorTypes.getPrimaryIDForType(zoteroItem.itemTypeID); - var creators = zoteroItem.getCreators(); - for each(var creator in creators) { - if(creator.creatorTypeID == authorID) { - var creatorType = "author"; - } else { - var creatorType = Zotero.CreatorTypes.getName(creator.creatorTypeID); - } - - var creatorType = CSL_NAMES_MAPPINGS[creatorType]; - if(!creatorType) continue; - - var nameObj = {'family':creator.ref.lastName, 'given':creator.ref.firstName}; - - if(cslItem[creatorType]) { - cslItem[creatorType].push(nameObj); - } else { - cslItem[creatorType] = [nameObj]; - } - } - - // get date variables - for(var variable in CSL_DATE_MAPPINGS) { - var date = zoteroItem.getField(CSL_DATE_MAPPINGS[variable], false, true); - if(date) { - var dateObj = Zotero.Date.strToDate(date); - // otherwise, use date-parts - var dateParts = []; - if(dateObj.year) { - // add year, month, and day, if they exist - dateParts.push(dateObj.year); - if(dateObj.month !== undefined) { - dateParts.push(dateObj.month+1); - if(dateObj.day) { - dateParts.push(dateObj.day); - } - } - cslItem[variable] = {"date-parts":[dateParts]}; - - // if no month, use season as month - if(dateObj.part && !dateObj.month) { - cslItem[variable].season = dateObj.part; - } - } else { - // if no year, pass date literally - cslItem[variable] = {"literal":date}; - } - } - } - - // extract PMID - var extra = zoteroItem.getField("extra", false, true); - if(typeof extra === "string") { - var m = /(?:^|\n)PMID:\s*([0-9]+)/.exec(extra); - if(m) cslItem.PMID = m[1]; - m = /(?:^|\n)PMCID:\s*((?:PMC)?[0-9]+)/.exec(extra); - if(m) cslItem.PMCID = m[1]; - } - - //this._cache[zoteroItem.id] = cslItem; return cslItem; }, diff --git a/chrome/content/zotero/xpcom/utilities.js b/chrome/content/zotero/xpcom/utilities.js index a81a11dab..0e40eecb1 100644 --- a/chrome/content/zotero/xpcom/utilities.js +++ b/chrome/content/zotero/xpcom/utilities.js @@ -1504,89 +1504,78 @@ Zotero.Utilities = { /** * Converts an item from toArray() format to citeproc-js JSON - * @param {Zotero.Item} item + * @param {Zotero.Item} zoteroItem * @return {Object} The CSL item */ - "itemToCSLJSON":function(item) { - if(item instanceof Zotero.Item) { - item = item.toArray(); + "itemToCSLJSON":function(zoteroItem) { + if (zoteroItem instanceof Zotero.Item) { + zoteroItem = zoteroItem.toArray(); } - var itemType = item.itemType; - var cslType = CSL_TYPE_MAPPINGS[itemType]; - if(!cslType) cslType = "article"; + var cslType = CSL_TYPE_MAPPINGS[zoteroItem.itemType] || "article"; + var itemTypeID = Zotero.ItemTypes.getID(zoteroItem.itemType); var cslItem = { - 'id':item.itemID, + 'id':zoteroItem.itemID, 'type':cslType }; - // Map text fields - var itemTypeID = Zotero.ItemTypes.getID(itemType); + // get all text variables (there must be a better way) for(var variable in CSL_TEXT_MAPPINGS) { var fields = CSL_TEXT_MAPPINGS[variable]; for(var i=0, n=fields.length; i