diff --git a/chrome/content/zotero/xpcom/cite.js b/chrome/content/zotero/xpcom/cite.js index 3bb4c39bad..6d3fb66633 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/data/item.js b/chrome/content/zotero/xpcom/data/item.js index 40fd22af03..2563840a9f 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -821,6 +821,24 @@ Zotero.Item.prototype.setField = function(field, value, loadIn) { value = value.replace(/[\r\n]+/g, " ");; } + if (fieldID == Zotero.ItemFields.getID('ISBN')) { + // Hyphenate ISBNs, but only if everything is in expected format and valid + let isbns = ('' + value).trim().split(/\s*[,;]\s*|\s+/), + newISBNs = '', + failed = false; + for (let i=0; i= regRanges[j].length; j+=2) { + if(registrant.length == regRanges[j].length + && registrant >= regRanges[j] && registrant <= regRanges[j+1] // Falls within the range + ) { + parts.push(registrant); + found = true; + break; + } + } + + i++; + } + + if (!found) return ''; // Outside of valid range, but maybe we need to update our data + + parts.push(isbn.substring(i,isbn.length-1)); // Publication is the remainder up to last digit + parts.push(isbn.charAt(isbn.length-1)); // Check digit + + return parts.join('-'); } } diff --git a/components/zotero-service.js b/components/zotero-service.js index ca0c6e8b18..e80bb0e7e3 100644 --- a/components/zotero-service.js +++ b/components/zotero-service.js @@ -46,6 +46,7 @@ const xpcomFilesAll = [ 'translation/translate_firefox', 'translation/tlds', 'utilities', + 'isbn', 'utilities_internal', 'utilities_translate' ];