2009-03-10 05:51:13 +00:00
|
|
|
{
|
|
|
|
"translatorID":"c82c574d-7fe8-49ca-a360-a05d6e34fec0",
|
|
|
|
"translatorType":4,
|
|
|
|
"label":"zotero.org",
|
|
|
|
"creator":"Dan Stillman",
|
2009-05-29 22:32:36 +00:00
|
|
|
"target":"^https?://[^/]*zotero\\.org/(groups/)?[^/]+/(items(/?[0-9]+?)?|items/collection/[0-9]+)(\\?.*)?$",
|
2009-03-10 05:51:13 +00:00
|
|
|
"minVersion":"1.0",
|
|
|
|
"maxVersion":"",
|
|
|
|
"priority":100,
|
|
|
|
"inRepository":true,
|
2009-09-22 07:04:36 +00:00
|
|
|
"lastUpdated":"2009-09-22 07:05:00"
|
2009-03-10 05:51:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function detectWeb(doc, url) {
|
2009-05-29 22:52:01 +00:00
|
|
|
// Skip private groups
|
|
|
|
if (url.match(/\/groups\/[0-9]+\/items/)) {
|
|
|
|
return false;
|
2009-05-20 21:04:39 +00:00
|
|
|
}
|
|
|
|
|
2009-09-22 07:04:36 +00:00
|
|
|
var a = doc.evaluate('//li[@id="library-tab"]/a[text()="My Library"]', doc, null, XPathResult.ANY_TYPE, null).iterateNext();
|
2009-03-10 05:51:13 +00:00
|
|
|
// Skip current user's library
|
|
|
|
if (a && url.indexOf(a.href.match(/(^.+)\/items/)[1]) == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Library and collections
|
|
|
|
if (url.match(/\/items\/?(\?.*)?$/) || url.match(/\/items\/collection\/[0-9]+(\?.*)?$/)) {
|
|
|
|
if (!doc.getElementById("field-table")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return "multiple";
|
|
|
|
}
|
2009-05-20 21:04:39 +00:00
|
|
|
|
2009-03-10 05:51:13 +00:00
|
|
|
// Individual item
|
|
|
|
else if (url.match(/\/items\/[0-9]+(\?.*)?$/)) {
|
2009-09-22 07:04:36 +00:00
|
|
|
// FIXME: temporarily broken
|
|
|
|
return false;
|
|
|
|
|
2009-03-10 05:51:13 +00:00
|
|
|
// TODO: embed in page, because this is absurd
|
|
|
|
var typeMap = {
|
|
|
|
"Note": "note",
|
|
|
|
"Attachment": "attachment",
|
|
|
|
"Book": "book",
|
|
|
|
"Book Section": "bookSection",
|
|
|
|
"Journal Article": "journalArticle",
|
|
|
|
"Magazine Article": "magazineArticle",
|
|
|
|
"Newspaper Article": "newspaperArticle",
|
|
|
|
"Thesis": "thesis",
|
|
|
|
"Letter": "letter",
|
|
|
|
"Manuscript": "manuscript",
|
|
|
|
"Interview": "interview",
|
|
|
|
"Film": "film",
|
|
|
|
"Artwork": "artwork",
|
|
|
|
"Web Page": "webpage",
|
|
|
|
"Report": "report",
|
|
|
|
"Bill": "bill",
|
|
|
|
"Case": "case",
|
|
|
|
"Hearing": "hearing",
|
|
|
|
"Patent": "patent",
|
|
|
|
"Statute": "statute",
|
|
|
|
"E-mail": "email",
|
|
|
|
"Map": "map",
|
|
|
|
"Blog Post": "blogPost",
|
|
|
|
"Instant Message": "instantMessage",
|
|
|
|
"Forum Post": "forumPost",
|
|
|
|
"Audio Recording": "audioRecording",
|
|
|
|
"Presentation": "presentation",
|
|
|
|
"Video Recording": "videoRecording",
|
|
|
|
"TV Broadcast": "tvBroadcast",
|
|
|
|
"Radio Broadcast": "radioBroadcast",
|
|
|
|
"Podcast": "podcast",
|
|
|
|
"Computer Program": "computerProgram",
|
|
|
|
"Conference Paper": "conferencePaper",
|
|
|
|
"Document": "document",
|
|
|
|
"Encyclopedia Article":"encyclopediaArticle",
|
|
|
|
"Dictionary Entry": "dictionaryEntry"
|
|
|
|
};
|
|
|
|
var td = doc.evaluate('//div[@id="content"]/div[@class="major-col"]/table//tr[th[text()="Item Type"]]/td', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
|
|
|
|
return td ? typeMap[td.textContent] : "book";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function xmlToItem(xmlItem) {
|
|
|
|
// "with ({});" needed to fix default namespace scope issue
|
|
|
|
// See https://bugzilla.mozilla.org/show_bug.cgi?id=330572
|
2009-07-01 08:38:38 +00:00
|
|
|
default xml namespace = 'http://zotero.org/ns/transfer'; with ({});
|
2009-03-10 05:51:13 +00:00
|
|
|
var itemType = xmlItem.@itemType;
|
|
|
|
|
|
|
|
// FIXME: translate.js only allow top-level attachments in import mode
|
|
|
|
if (itemType == 'attachment') {
|
|
|
|
itemType = 'document';
|
|
|
|
}
|
|
|
|
|
|
|
|
var newItem = new Zotero.Item(itemType);
|
|
|
|
|
|
|
|
// Don't auto-set repository
|
|
|
|
newItem.repository = false;
|
|
|
|
|
|
|
|
for each(var field in xmlItem.field) {
|
|
|
|
var fieldName = field.@name.toString();
|
|
|
|
newItem[fieldName] = field.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Item creators
|
|
|
|
for each(var creator in xmlItem.creator) {
|
|
|
|
var data = {
|
|
|
|
creatorType: creator.@creatorType
|
|
|
|
};
|
|
|
|
if (creator.creator.fieldMode == 1) {
|
|
|
|
data.fieldMode = 1;
|
|
|
|
data.lastName = creator.creator.name.toString();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
data.firstName = creator.creator.firstName.toString();
|
|
|
|
data.lastName = creator.creator.lastName.toString();
|
|
|
|
}
|
|
|
|
newItem.creators.push(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Both notes and attachments might have parents and notes
|
|
|
|
if (itemType == 'note' || itemType == 'attachment') {
|
|
|
|
newItem.note = xmlItem.note.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attachment metadata
|
|
|
|
if (itemType == 'attachment') {
|
|
|
|
//newItem.attachmentLinkMode = parseInt(xmlItem.@linkMode);
|
|
|
|
newItem.mimeType = xmlItem.@mimeType.toString();
|
|
|
|
newItem.charset = xmlItem.@charset.toString();
|
|
|
|
var path = xmlItem.path.toString();
|
|
|
|
if (path) {
|
|
|
|
newItem.path = path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
newItem.complete();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2.0b3 megacommit
- Support for group libraries
- General support for multiple libraries of different types
- Streamlined sync support
- Using solely libraryID and key rather than itemID, and removed all itemID-changing code
- Combined two requests for increased performance and decreased server load
- Added warning on user account change
- Provide explicit error message on SSL failure
- Removed snapshot and link toolbar buttons and changed browser context menu options and drags to create parent items + snapshots
- Closes #786, Add numPages field
- Fixes #1063, Duplicate item with tags broken in Sync Preview
- Added better purging of deleted tags
- Added local user key before first sync
- Add clientDateModified to all objects for more flexibility in syncing
- Added new triples-based Relation object type, currently used to store links between items copied between local and group libraries
- Updated zotero.org translator for groups
- Additional trigger-based consistency checks
- Fixed broken URL drag in Firefox 3.5
- Disabled zeroconf menu option (no longer functional)
Developer-specific changes:
- Overhauled data layer
- Data object constructors no longer take arguments (return to 1.0-like API)
- Existing objects can be retrieved by setting id or library/key properties
- id/library/key must be set for new objects before other fields
- New methods:
- ZoteroPane.getSelectedLibraryID()
- ZoteroPane.getSelectedGroup(asID)
- ZoteroPane.addItemFromDocument(doc, itemType, saveSnapshot)
- ZoteroPane.addItemFromURL(url, itemType)
- ZoteroPane.canEdit()
- Zotero.CollectionTreeView.selectLibrary(libraryID)
- New Zotero.URI methods
- Changed methods
- Many data object methods now take a libraryID
- ZoteroPane.addAttachmentFromPage(link, itemID)
- Removed saveItem and saveAttachments parameters from Zotero.Translate constructor
- translate() now takes a libraryID, null for local library, or false to not save items (previously on constructor)
- saveAttachments is now a translate() parameter
- Zotero.flattenArguments() better handles passed objects
- Zotero.File.getFileHash() (not currently used)
2009-05-14 18:23:40 +00:00
|
|
|
|
2009-03-10 05:51:13 +00:00
|
|
|
function doWeb(doc, url) {
|
|
|
|
var nsAtom = new Namespace('http://www.w3.org/2005/Atom');
|
2009-07-01 08:38:38 +00:00
|
|
|
var nsZXfer = new Namespace('http://zotero.org/ns/transfer');
|
2009-03-10 05:51:13 +00:00
|
|
|
|
|
|
|
if (detectWeb(doc, url) == "multiple") {
|
2009-09-22 07:04:36 +00:00
|
|
|
var itemRe = /^https?:\/\/[^\/]*zotero\.org\/(?:groups\/)?[^\/]+\/items\/([0-9]+)/;
|
|
|
|
|
|
|
|
var link = doc.evaluate('//link[@type="application/atom+xml" and @rel="alternate"]', doc, null, XPathResult.ANY_TYPE, null).iterateNext();
|
|
|
|
var libraryURI = link.getAttribute('href');
|
|
|
|
|
|
|
|
var column = doc.evaluate('//table[@id="field-table"]//td[1][@class="title"][not(contains(./a, "Unpublished Note"))]', doc, null, XPathResult.ANY_TYPE, null);
|
2009-03-10 05:51:13 +00:00
|
|
|
var elems = [], td;
|
|
|
|
while (td = column.iterateNext()) {
|
|
|
|
elems.push(td);
|
|
|
|
}
|
|
|
|
var items = Zotero.Utilities.getItemArray(doc, elems);
|
|
|
|
|
|
|
|
items = Zotero.selectItems(items);
|
|
|
|
if (!items) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-22 07:04:36 +00:00
|
|
|
var apiURIs = [], itemID, apiURI;
|
2009-03-10 05:51:13 +00:00
|
|
|
for (var url in items) {
|
|
|
|
itemID = url.match(itemRe)[1];
|
2009-09-22 07:04:36 +00:00
|
|
|
apiURI = libraryURI + "/" + itemID + "?content=full";
|
|
|
|
apiURIs.push(apiURI);
|
2009-03-10 05:51:13 +00:00
|
|
|
}
|
|
|
|
|
2009-09-22 07:04:36 +00:00
|
|
|
Zotero.Utilities.HTTP.doGet(apiURIs, function(text) {
|
2009-03-10 05:51:13 +00:00
|
|
|
// Strip XML declaration and convert to E4X
|
|
|
|
var entry = new XML(text.replace(/<\?xml.*\?>/, ''));
|
|
|
|
xmlToItem(entry.nsAtom::content.nsZXfer::item);
|
|
|
|
}, function () { Zotero.done(); });
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var itemID = url.match(itemRe)[1];
|
|
|
|
var apiURL = apiPrefix + "items/" + itemID + "?content=full";
|
|
|
|
Zotero.Utilities.doGet(apiURL, function (text) {
|
|
|
|
// Strip XML declaration and convert to E4X
|
|
|
|
var entry = new XML(text.replace(/<\?xml.*\?>/, ''));
|
|
|
|
xmlToItem(entry.nsAtom::content.nsZXfer::item);
|
|
|
|
Zotero.done();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
Zotero.wait();
|
|
|
|
}
|