2007-10-23 07:11:59 +00:00
|
|
|
/*
|
|
|
|
***** BEGIN LICENSE BLOCK *****
|
|
|
|
|
2009-12-28 09:47:49 +00:00
|
|
|
Copyright © 2009 Center for History and New Media
|
|
|
|
George Mason University, Fairfax, Virginia, USA
|
|
|
|
http://zotero.org
|
2007-10-23 07:11:59 +00:00
|
|
|
|
2009-12-28 09:47:49 +00:00
|
|
|
This file is part of Zotero.
|
2007-10-23 07:11:59 +00:00
|
|
|
|
2009-12-28 09:47:49 +00:00
|
|
|
Zotero is free software: you can redistribute it and/or modify
|
2011-05-18 18:34:22 +00:00
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
2009-12-28 09:47:49 +00:00
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Zotero is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2011-05-18 18:34:22 +00:00
|
|
|
GNU Affero General Public License for more details.
|
2009-12-28 09:47:49 +00:00
|
|
|
|
2011-05-18 18:34:22 +00:00
|
|
|
You should have received a copy of the GNU Affero General Public License
|
2009-12-28 09:47:49 +00:00
|
|
|
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
|
2007-10-23 07:11:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
Based on nsChromeExtensionHandler example code by Ed Anuff at
|
|
|
|
http://kb.mozillazine.org/Dev_:_Extending_the_Chrome_Protocol
|
|
|
|
|
|
|
|
***** END LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
|
|
|
const ZOTERO_SCHEME = "zotero";
|
|
|
|
const ZOTERO_PROTOCOL_CID = Components.ID("{9BC3D762-9038-486A-9D70-C997AF848A7C}");
|
|
|
|
const ZOTERO_PROTOCOL_CONTRACTID = "@mozilla.org/network/protocol;1?name=" + ZOTERO_SCHEME;
|
|
|
|
const ZOTERO_PROTOCOL_NAME = "Zotero Chrome Extension Protocol";
|
|
|
|
|
2010-07-06 09:02:35 +00:00
|
|
|
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
// Dummy chrome URL used to obtain a valid chrome channel
|
|
|
|
// This one was chosen at random and should be able to be substituted
|
|
|
|
// for any other well known chrome URL in the browser installation
|
|
|
|
const DUMMY_CHROME_URL = "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul";
|
|
|
|
|
|
|
|
|
|
|
|
function ChromeExtensionHandler() {
|
|
|
|
this.wrappedJSObject = this;
|
|
|
|
this._systemPrincipal = null;
|
|
|
|
this._extensions = {};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Report generation extension for Zotero protocol
|
|
|
|
*
|
|
|
|
* Example URLs:
|
|
|
|
*
|
|
|
|
* zotero://report/ -- library
|
2009-12-05 20:16:42 +00:00
|
|
|
* zotero://report/collection/0_ABCD1234
|
|
|
|
* zotero://report/search/0_ABCD1234
|
|
|
|
* zotero://report/items/0_ABCD1234-0_BCDE2345-0_CDEF3456
|
|
|
|
* zotero://report/item/0_ABCD1234
|
2007-10-23 07:11:59 +00:00
|
|
|
*
|
2009-12-05 20:16:42 +00:00
|
|
|
* Optional format can be specified after hashes
|
2007-10-23 07:11:59 +00:00
|
|
|
*
|
2009-12-05 20:16:42 +00:00
|
|
|
* - 'html', 'rtf', 'csv' ['rtf' and 'csv' not yet supported]
|
2007-10-23 07:11:59 +00:00
|
|
|
* - defaults to 'html' if not specified
|
|
|
|
*
|
2009-12-05 20:16:42 +00:00
|
|
|
* e.g. zotero://report/collection/0_ABCD1234/rtf
|
2007-10-23 07:11:59 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Sorting:
|
|
|
|
*
|
|
|
|
* - 'sort' query string variable
|
|
|
|
* - format is field[/order] [, field[/order], ...]
|
|
|
|
* - order can be 'asc', 'a', 'desc' or 'd'; defaults to ascending order
|
|
|
|
*
|
2009-12-05 20:16:42 +00:00
|
|
|
* zotero://report/collection/0_ABCD1234?sort=itemType/d,title
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Also supports ids (e.g., zotero://report/collection/1234), but ids are not
|
|
|
|
* guaranteed to be consistent across synced machines
|
2007-10-23 07:11:59 +00:00
|
|
|
*/
|
|
|
|
var ReportExtension = new function(){
|
|
|
|
this.newChannel = newChannel;
|
|
|
|
|
2008-11-30 20:18:48 +00:00
|
|
|
this.__defineGetter__('loadAsChrome', function () { return false; });
|
Merged revisions 3080-3081,3084,3087-3088,3090,3092,3099-3103,3113-3114,3132,3134-3143,3145,3148-3151,3154-3159,3165,3174,3194,3234-3235,3239-3240,3244,3246-3254,3258-3262,3268,3270,3274,3279,3286-3288,3294-3295 from 1.0 branch via svnmerge
2008-09-01 01:54:00 +00:00
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
function newChannel(uri){
|
|
|
|
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIIOService);
|
|
|
|
|
|
|
|
var Zotero = Components.classes["@zotero.org/Zotero;1"]
|
|
|
|
.getService(Components.interfaces.nsISupports)
|
|
|
|
.wrappedJSObject;
|
|
|
|
|
|
|
|
generateContent:try {
|
|
|
|
var mimeType, content = '';
|
|
|
|
|
|
|
|
var [path, queryString] = uri.path.substr(1).split('?');
|
|
|
|
var [type, ids, format] = path.split('/');
|
|
|
|
|
|
|
|
// Get query string variables
|
|
|
|
if (queryString) {
|
|
|
|
var queryVars = queryString.split('&');
|
|
|
|
for (var i in queryVars) {
|
|
|
|
var [key, val] = queryVars[i].split('=');
|
|
|
|
switch (key) {
|
|
|
|
case 'sort':
|
|
|
|
var sortBy = val;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (type){
|
|
|
|
case 'collection':
|
2009-12-05 04:26:22 +00:00
|
|
|
var lkh = Zotero.Collections.parseLibraryKeyHash(ids);
|
|
|
|
if (lkh) {
|
|
|
|
var col = Zotero.Collections.getByLibraryAndKey(lkh.libraryID, lkh.key);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var col = Zotero.Collections.get(ids);
|
|
|
|
}
|
|
|
|
if (!col) {
|
|
|
|
mimeType = 'text/html';
|
|
|
|
content = 'Invalid collection ID or key';
|
|
|
|
break generateContent;
|
|
|
|
}
|
2007-10-23 07:11:59 +00:00
|
|
|
var results = col.getChildItems();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'search':
|
2009-12-05 04:26:22 +00:00
|
|
|
var lkh = Zotero.Searches.parseLibraryKeyHash(ids);
|
|
|
|
if (lkh) {
|
|
|
|
var s = Zotero.Searches.getByLibraryAndKey(lkh.libraryID, lkh.key);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var s = Zotero.Searches.get(ids);
|
|
|
|
}
|
|
|
|
if (!s) {
|
|
|
|
mimeType = 'text/html';
|
|
|
|
content = 'Invalid search ID or key';
|
|
|
|
break generateContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: Hack to exclude group libraries for now
|
|
|
|
var s2 = new Zotero.Search();
|
|
|
|
s2.setScope(s);
|
|
|
|
var groups = Zotero.Groups.getAll();
|
|
|
|
for each(var group in groups) {
|
|
|
|
s2.addCondition('libraryID', 'isNot', group.libraryID);
|
|
|
|
}
|
|
|
|
var ids = s2.search();
|
|
|
|
|
|
|
|
var results = Zotero.Items.get(ids);
|
2007-10-23 07:11:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'items':
|
|
|
|
case 'item':
|
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
|
|
|
ids = ids.split('-');
|
2009-12-05 04:26:22 +00:00
|
|
|
|
|
|
|
// Keys
|
|
|
|
if (Zotero.Items.parseLibraryKeyHash(ids[0])) {
|
|
|
|
var results = [];
|
|
|
|
for each(var lkh in ids) {
|
|
|
|
var lkh = Zotero.Items.parseLibraryKeyHash(lkh);
|
|
|
|
var item = Zotero.Items.getByLibraryAndKey(lkh.libraryID, lkh.key);
|
|
|
|
if (item) {
|
|
|
|
results.push(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// IDs
|
|
|
|
else {
|
|
|
|
var results = Zotero.Items.get(ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!results.length) {
|
|
|
|
mimeType = 'text/html';
|
|
|
|
content = 'Invalid ID';
|
|
|
|
break generateContent;
|
|
|
|
}
|
2007-10-23 07:11:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2008-11-30 20:18:48 +00:00
|
|
|
// Proxy CSS files
|
|
|
|
if (type.match(/^detail.*\.css$/)) {
|
|
|
|
var chromeURL = 'chrome://zotero/skin/report/' + type;
|
|
|
|
var ios = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIIOService);
|
|
|
|
var uri = ios.newURI(chromeURL, null, null);
|
|
|
|
var chromeReg = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
|
|
|
|
.getService(Components.interfaces.nsIChromeRegistry);
|
|
|
|
var fileURI = chromeReg.convertChromeURL(uri);
|
|
|
|
var ph = Components.classes["@mozilla.org/network/protocol;1?name=file"]
|
|
|
|
.createInstance(Components.interfaces.nsIFileProtocolHandler);
|
|
|
|
var channel = ioService.newChannelFromURI(fileURI);
|
|
|
|
return channel;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Display all items
|
2007-10-23 07:11:59 +00:00
|
|
|
var type = 'library';
|
|
|
|
var s = new Zotero.Search();
|
|
|
|
s.addCondition('noChildren', 'true');
|
|
|
|
var ids = s.search();
|
2009-12-05 04:26:22 +00:00
|
|
|
var results = Zotero.Items.get(ids);
|
2007-10-23 07:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var items = [];
|
|
|
|
var itemsHash = {}; // key = itemID, val = position in |items|
|
|
|
|
var searchItemIDs = {}; // hash of all selected items
|
|
|
|
var searchParentIDs = {}; // hash of parents of selected child items
|
|
|
|
var searchChildIDs = {}; // hash of selected chlid items
|
|
|
|
|
|
|
|
var includeAllChildItems = Zotero.Prefs.get('report.includeAllChildItems');
|
|
|
|
var combineChildItems = Zotero.Prefs.get('report.combineChildItems');
|
|
|
|
|
Merged revisions 2710-2712,2714-2716,2718-2728,2730-2731,2734,2736-2738,2740-2750,2752-2753,2755,2758-2768,2770-2779,2782,2789-2790,2794,2797-2802,2804,2808-2810,2812,2814-2824,2826-2832,2834-2835 via svnmerge from 1.0 branch
2008-06-11 08:55:59 +00:00
|
|
|
var unhandledParents = {};
|
2007-10-23 07:11:59 +00:00
|
|
|
for (var i=0; i<results.length; i++) {
|
|
|
|
// Don't add child items directly
|
|
|
|
// (instead mark their parents for inclusion below)
|
|
|
|
var sourceItemID = results[i].getSource();
|
|
|
|
if (sourceItemID) {
|
|
|
|
searchParentIDs[sourceItemID] = true;
|
|
|
|
searchChildIDs[results[i].getID()] = true;
|
|
|
|
|
|
|
|
// Don't include all child items if any child
|
|
|
|
// items were selected
|
|
|
|
includeAllChildItems = false;
|
|
|
|
}
|
Merged revisions 1986,1988-1990,1996,1998,2000-2004,2006,2008-2010,2013,2020-2028,2032-2034,2037,2039,2044-2049,2052-2056,2059,2065-2066,2068-2072,2075,2077-2079,2081,2083-2084,2086,2088-2094,2096,2099,2101,2103-2104,2107-2110,2115,2118,2120-2122,2126-2128,2131,2140,2142-2145,2149-2153,2155-2159,2165,2167-2168,2170-2171,2173-2176,2179-2183,2185-2186 via svnmerge from
https://www.zotero.org/svn/extension/branches/1.0
2008-01-30 09:53:19 +00:00
|
|
|
// If combining children or standalone note/attachment, add matching parents
|
Merged revisions 2710-2712,2714-2716,2718-2728,2730-2731,2734,2736-2738,2740-2750,2752-2753,2755,2758-2768,2770-2779,2782,2789-2790,2794,2797-2802,2804,2808-2810,2812,2814-2824,2826-2832,2834-2835 via svnmerge from 1.0 branch
2008-06-11 08:55:59 +00:00
|
|
|
else if (combineChildItems || !results[i].isRegularItem()
|
|
|
|
|| results[i].numChildren() == 0) {
|
|
|
|
itemsHash[results[i].getID()] = [items.length];
|
2007-10-23 07:11:59 +00:00
|
|
|
items.push(results[i].toArray(2));
|
|
|
|
// Flag item as a search match
|
|
|
|
items[items.length - 1].reportSearchMatch = true;
|
|
|
|
}
|
Merged revisions 2710-2712,2714-2716,2718-2728,2730-2731,2734,2736-2738,2740-2750,2752-2753,2755,2758-2768,2770-2779,2782,2789-2790,2794,2797-2802,2804,2808-2810,2812,2814-2824,2826-2832,2834-2835 via svnmerge from 1.0 branch
2008-06-11 08:55:59 +00:00
|
|
|
else {
|
|
|
|
unhandledParents[i] = true;
|
|
|
|
}
|
2007-10-23 07:11:59 +00:00
|
|
|
searchItemIDs[results[i].getID()] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If including all child items, add children of all matched
|
|
|
|
// parents to the child array
|
|
|
|
if (includeAllChildItems) {
|
|
|
|
for (var id in searchItemIDs) {
|
|
|
|
if (!searchChildIDs[id]) {
|
|
|
|
var children = [];
|
|
|
|
var item = Zotero.Items.get(id);
|
|
|
|
if (!item.isRegularItem()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
var func = function (ids) {
|
|
|
|
if (ids) {
|
|
|
|
for (var i=0; i<ids.length; i++) {
|
|
|
|
searchChildIDs[ids[i]] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
func(item.getNotes());
|
|
|
|
func(item.getAttachments());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Merged revisions 2710-2712,2714-2716,2718-2728,2730-2731,2734,2736-2738,2740-2750,2752-2753,2755,2758-2768,2770-2779,2782,2789-2790,2794,2797-2802,2804,2808-2810,2812,2814-2824,2826-2832,2834-2835 via svnmerge from 1.0 branch
2008-06-11 08:55:59 +00:00
|
|
|
// If not including all children, add matching parents,
|
|
|
|
// in case they don't have any matching children below
|
|
|
|
else {
|
|
|
|
for (var i in unhandledParents) {
|
|
|
|
itemsHash[results[i].id] = [items.length];
|
|
|
|
items.push(results[i].toArray(2));
|
|
|
|
// Flag item as a search match
|
|
|
|
items[items.length - 1].reportSearchMatch = true;
|
|
|
|
}
|
|
|
|
}
|
2007-10-23 07:11:59 +00:00
|
|
|
|
|
|
|
if (combineChildItems) {
|
|
|
|
// Add parents of matches if parents aren't matches themselves
|
|
|
|
for (var id in searchParentIDs) {
|
Merged revisions 2710-2712,2714-2716,2718-2728,2730-2731,2734,2736-2738,2740-2750,2752-2753,2755,2758-2768,2770-2779,2782,2789-2790,2794,2797-2802,2804,2808-2810,2812,2814-2824,2826-2832,2834-2835 via svnmerge from 1.0 branch
2008-06-11 08:55:59 +00:00
|
|
|
if (!searchItemIDs[id] && !itemsHash[id]) {
|
2007-10-23 07:11:59 +00:00
|
|
|
var item = Zotero.Items.get(id);
|
|
|
|
itemsHash[id] = items.length;
|
|
|
|
items.push(item.toArray(2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add children to reportChildren property of parents
|
|
|
|
for (var id in searchChildIDs) {
|
|
|
|
var item = Zotero.Items.get(id);
|
|
|
|
var parentItemID = item.getSource();
|
|
|
|
if (!items[itemsHash[parentItemID]].reportChildren) {
|
|
|
|
items[itemsHash[parentItemID]].reportChildren = {
|
|
|
|
notes: [],
|
|
|
|
attachments: []
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (item.isNote()) {
|
|
|
|
items[itemsHash[parentItemID]].reportChildren.notes.push(item.toArray());
|
|
|
|
}
|
|
|
|
if (item.isAttachment()) {
|
|
|
|
items[itemsHash[parentItemID]].reportChildren.attachments.push(item.toArray());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If not combining children, add a parent/child pair
|
|
|
|
// for each matching child
|
|
|
|
else {
|
|
|
|
for (var id in searchChildIDs) {
|
|
|
|
var item = Zotero.Items.get(id);
|
|
|
|
var parentID = item.getSource();
|
|
|
|
var parentItem = Zotero.Items.get(parentID);
|
|
|
|
|
|
|
|
if (!itemsHash[parentID]) {
|
|
|
|
// If parent is a search match and not yet added,
|
|
|
|
// add on its own
|
|
|
|
if (searchItemIDs[parentID]) {
|
|
|
|
itemsHash[parentID] = [items.length];
|
|
|
|
items.push(parentItem.toArray(2));
|
|
|
|
items[items.length - 1].reportSearchMatch = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
itemsHash[parentID] = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now add parent and child
|
|
|
|
itemsHash[parentID].push(items.length);
|
|
|
|
items.push(parentItem.toArray(2));
|
|
|
|
if (item.isNote()) {
|
|
|
|
items[items.length - 1].reportChildren = {
|
|
|
|
notes: [item.toArray()],
|
|
|
|
attachments: []
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else if (item.isAttachment()) {
|
|
|
|
items[items.length - 1].reportChildren = {
|
|
|
|
notes: [],
|
|
|
|
attachments: [item.toArray()]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Sort items
|
|
|
|
if (!sortBy) {
|
|
|
|
sortBy = 'title';
|
|
|
|
}
|
|
|
|
|
|
|
|
var sorts = sortBy.split(',');
|
|
|
|
for (var i=0; i<sorts.length; i++) {
|
|
|
|
var [field, order] = sorts[i].split('/');
|
Merged revisions 1986,1988-1990,1996,1998,2000-2004,2006,2008-2010,2013,2020-2028,2032-2034,2037,2039,2044-2049,2052-2056,2059,2065-2066,2068-2072,2075,2077-2079,2081,2083-2084,2086,2088-2094,2096,2099,2101,2103-2104,2107-2110,2115,2118,2120-2122,2126-2128,2131,2140,2142-2145,2149-2153,2155-2159,2165,2167-2168,2170-2171,2173-2176,2179-2183,2185-2186 via svnmerge from
https://www.zotero.org/svn/extension/branches/1.0
2008-01-30 09:53:19 +00:00
|
|
|
// Year field is really date field
|
|
|
|
if (field == 'year') {
|
|
|
|
field = 'date';
|
|
|
|
}
|
2007-10-23 07:11:59 +00:00
|
|
|
switch (order) {
|
|
|
|
case 'd':
|
|
|
|
case 'desc':
|
|
|
|
order = -1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
order = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
sorts[i] = {
|
|
|
|
field: field,
|
|
|
|
order: order
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var collation = Zotero.getLocaleCollation();
|
|
|
|
var compareFunction = function(a, b) {
|
|
|
|
var index = 0;
|
|
|
|
|
|
|
|
// Multidimensional sort
|
|
|
|
do {
|
Merged revisions 2710-2712,2714-2716,2718-2728,2730-2731,2734,2736-2738,2740-2750,2752-2753,2755,2758-2768,2770-2779,2782,2789-2790,2794,2797-2802,2804,2808-2810,2812,2814-2824,2826-2832,2834-2835 via svnmerge from 1.0 branch
2008-06-11 08:55:59 +00:00
|
|
|
// In combineChildItems, use note or attachment as item
|
|
|
|
if (!combineChildItems) {
|
|
|
|
if (a.reportChildren) {
|
|
|
|
if (a.reportChildren.notes.length) {
|
|
|
|
a = a.reportChildren.notes[0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
a = a.reportChildren.attachments[0];
|
|
|
|
}
|
Merged revisions 1986,1988-1990,1996,1998,2000-2004,2006,2008-2010,2013,2020-2028,2032-2034,2037,2039,2044-2049,2052-2056,2059,2065-2066,2068-2072,2075,2077-2079,2081,2083-2084,2086,2088-2094,2096,2099,2101,2103-2104,2107-2110,2115,2118,2120-2122,2126-2128,2131,2140,2142-2145,2149-2153,2155-2159,2165,2167-2168,2170-2171,2173-2176,2179-2183,2185-2186 via svnmerge from
https://www.zotero.org/svn/extension/branches/1.0
2008-01-30 09:53:19 +00:00
|
|
|
}
|
|
|
|
|
Merged revisions 2710-2712,2714-2716,2718-2728,2730-2731,2734,2736-2738,2740-2750,2752-2753,2755,2758-2768,2770-2779,2782,2789-2790,2794,2797-2802,2804,2808-2810,2812,2814-2824,2826-2832,2834-2835 via svnmerge from 1.0 branch
2008-06-11 08:55:59 +00:00
|
|
|
if (b.reportChildren) {
|
|
|
|
if (b.reportChildren.notes.length) {
|
|
|
|
b = b.reportChildren.notes[0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
b = b.reportChildren.attachments[0];
|
|
|
|
}
|
Merged revisions 1986,1988-1990,1996,1998,2000-2004,2006,2008-2010,2013,2020-2028,2032-2034,2037,2039,2044-2049,2052-2056,2059,2065-2066,2068-2072,2075,2077-2079,2081,2083-2084,2086,2088-2094,2096,2099,2101,2103-2104,2107-2110,2115,2118,2120-2122,2126-2128,2131,2140,2142-2145,2149-2153,2155-2159,2165,2167-2168,2170-2171,2173-2176,2179-2183,2185-2186 via svnmerge from
https://www.zotero.org/svn/extension/branches/1.0
2008-01-30 09:53:19 +00:00
|
|
|
}
|
Merged revisions 2710-2712,2714-2716,2718-2728,2730-2731,2734,2736-2738,2740-2750,2752-2753,2755,2758-2768,2770-2779,2782,2789-2790,2794,2797-2802,2804,2808-2810,2812,2814-2824,2826-2832,2834-2835 via svnmerge from 1.0 branch
2008-06-11 08:55:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var valA, valB;
|
|
|
|
|
|
|
|
if (sorts[index].field == 'title') {
|
|
|
|
// For notes, use content for 'title'
|
|
|
|
if (a.itemType == 'note') {
|
|
|
|
valA = a.note;
|
Merged revisions 1986,1988-1990,1996,1998,2000-2004,2006,2008-2010,2013,2020-2028,2032-2034,2037,2039,2044-2049,2052-2056,2059,2065-2066,2068-2072,2075,2077-2079,2081,2083-2084,2086,2088-2094,2096,2099,2101,2103-2104,2107-2110,2115,2118,2120-2122,2126-2128,2131,2140,2142-2145,2149-2153,2155-2159,2165,2167-2168,2170-2171,2173-2176,2179-2183,2185-2186 via svnmerge from
https://www.zotero.org/svn/extension/branches/1.0
2008-01-30 09:53:19 +00:00
|
|
|
}
|
|
|
|
else {
|
Merged revisions 2710-2712,2714-2716,2718-2728,2730-2731,2734,2736-2738,2740-2750,2752-2753,2755,2758-2768,2770-2779,2782,2789-2790,2794,2797-2802,2804,2808-2810,2812,2814-2824,2826-2832,2834-2835 via svnmerge from 1.0 branch
2008-06-11 08:55:59 +00:00
|
|
|
valA = a.title;
|
Merged revisions 1986,1988-1990,1996,1998,2000-2004,2006,2008-2010,2013,2020-2028,2032-2034,2037,2039,2044-2049,2052-2056,2059,2065-2066,2068-2072,2075,2077-2079,2081,2083-2084,2086,2088-2094,2096,2099,2101,2103-2104,2107-2110,2115,2118,2120-2122,2126-2128,2131,2140,2142-2145,2149-2153,2155-2159,2165,2167-2168,2170-2171,2173-2176,2179-2183,2185-2186 via svnmerge from
https://www.zotero.org/svn/extension/branches/1.0
2008-01-30 09:53:19 +00:00
|
|
|
}
|
|
|
|
|
Merged revisions 2710-2712,2714-2716,2718-2728,2730-2731,2734,2736-2738,2740-2750,2752-2753,2755,2758-2768,2770-2779,2782,2789-2790,2794,2797-2802,2804,2808-2810,2812,2814-2824,2826-2832,2834-2835 via svnmerge from 1.0 branch
2008-06-11 08:55:59 +00:00
|
|
|
if (b.itemType == 'note') {
|
|
|
|
valB = b.note;
|
Merged revisions 1986,1988-1990,1996,1998,2000-2004,2006,2008-2010,2013,2020-2028,2032-2034,2037,2039,2044-2049,2052-2056,2059,2065-2066,2068-2072,2075,2077-2079,2081,2083-2084,2086,2088-2094,2096,2099,2101,2103-2104,2107-2110,2115,2118,2120-2122,2126-2128,2131,2140,2142-2145,2149-2153,2155-2159,2165,2167-2168,2170-2171,2173-2176,2179-2183,2185-2186 via svnmerge from
https://www.zotero.org/svn/extension/branches/1.0
2008-01-30 09:53:19 +00:00
|
|
|
}
|
|
|
|
else {
|
Merged revisions 2710-2712,2714-2716,2718-2728,2730-2731,2734,2736-2738,2740-2750,2752-2753,2755,2758-2768,2770-2779,2782,2789-2790,2794,2797-2802,2804,2808-2810,2812,2814-2824,2826-2832,2834-2835 via svnmerge from 1.0 branch
2008-06-11 08:55:59 +00:00
|
|
|
valB = b.title;
|
Merged revisions 1986,1988-1990,1996,1998,2000-2004,2006,2008-2010,2013,2020-2028,2032-2034,2037,2039,2044-2049,2052-2056,2059,2065-2066,2068-2072,2075,2077-2079,2081,2083-2084,2086,2088-2094,2096,2099,2101,2103-2104,2107-2110,2115,2118,2120-2122,2126-2128,2131,2140,2142-2145,2149-2153,2155-2159,2165,2167-2168,2170-2171,2173-2176,2179-2183,2185-2186 via svnmerge from
https://www.zotero.org/svn/extension/branches/1.0
2008-01-30 09:53:19 +00:00
|
|
|
}
|
Merged revisions 2710-2712,2714-2716,2718-2728,2730-2731,2734,2736-2738,2740-2750,2752-2753,2755,2758-2768,2770-2779,2782,2789-2790,2794,2797-2802,2804,2808-2810,2812,2814-2824,2826-2832,2834-2835 via svnmerge from 1.0 branch
2008-06-11 08:55:59 +00:00
|
|
|
|
|
|
|
valA = Zotero.Items.getSortTitle(valA);
|
|
|
|
valB = Zotero.Items.getSortTitle(valB);
|
Merged revisions 1986,1988-1990,1996,1998,2000-2004,2006,2008-2010,2013,2020-2028,2032-2034,2037,2039,2044-2049,2052-2056,2059,2065-2066,2068-2072,2075,2077-2079,2081,2083-2084,2086,2088-2094,2096,2099,2101,2103-2104,2107-2110,2115,2118,2120-2122,2126-2128,2131,2140,2142-2145,2149-2153,2155-2159,2165,2167-2168,2170-2171,2173-2176,2179-2183,2185-2186 via svnmerge from
https://www.zotero.org/svn/extension/branches/1.0
2008-01-30 09:53:19 +00:00
|
|
|
}
|
2011-04-12 14:47:44 +00:00
|
|
|
else if (sorts[index].field == 'date') {
|
2012-04-26 20:28:55 +00:00
|
|
|
var itemA = Zotero.Items.getByLibraryAndKey(a.libraryID, a.key);
|
|
|
|
var itemB = Zotero.Items.getByLibraryAndKey(b.libraryID, b.key);
|
|
|
|
valA = itemA.getField('date', true, true);
|
|
|
|
valB = itemB.getField('date', true, true);
|
2011-04-12 14:47:44 +00:00
|
|
|
}
|
2012-01-12 00:02:57 +00:00
|
|
|
// TEMP: This is an ugly hack to make creator sorting
|
|
|
|
// slightly less broken. To do this right, real creator
|
|
|
|
// sorting needs to be abstracted from itemTreeView.js.
|
|
|
|
else if (sorts[index].field == 'firstCreator') {
|
|
|
|
var itemA = Zotero.Items.getByLibraryAndKey(a.libraryID, a.key);
|
|
|
|
var itemB = Zotero.Items.getByLibraryAndKey(b.libraryID, b.key);
|
|
|
|
valA = itemA.getField('firstCreator');
|
|
|
|
valB = itemB.getField('firstCreator');
|
|
|
|
}
|
Merged revisions 1986,1988-1990,1996,1998,2000-2004,2006,2008-2010,2013,2020-2028,2032-2034,2037,2039,2044-2049,2052-2056,2059,2065-2066,2068-2072,2075,2077-2079,2081,2083-2084,2086,2088-2094,2096,2099,2101,2103-2104,2107-2110,2115,2118,2120-2122,2126-2128,2131,2140,2142-2145,2149-2153,2155-2159,2165,2167-2168,2170-2171,2173-2176,2179-2183,2185-2186 via svnmerge from
https://www.zotero.org/svn/extension/branches/1.0
2008-01-30 09:53:19 +00:00
|
|
|
else {
|
2011-04-12 14:47:44 +00:00
|
|
|
valA = a[sorts[index].field];
|
|
|
|
valB = b[sorts[index].field];
|
Merged revisions 1986,1988-1990,1996,1998,2000-2004,2006,2008-2010,2013,2020-2028,2032-2034,2037,2039,2044-2049,2052-2056,2059,2065-2066,2068-2072,2075,2077-2079,2081,2083-2084,2086,2088-2094,2096,2099,2101,2103-2104,2107-2110,2115,2118,2120-2122,2126-2128,2131,2140,2142-2145,2149-2153,2155-2159,2165,2167-2168,2170-2171,2173-2176,2179-2183,2185-2186 via svnmerge from
https://www.zotero.org/svn/extension/branches/1.0
2008-01-30 09:53:19 +00:00
|
|
|
}
|
2007-10-23 07:11:59 +00:00
|
|
|
|
Merged revisions 2710-2712,2714-2716,2718-2728,2730-2731,2734,2736-2738,2740-2750,2752-2753,2755,2758-2768,2770-2779,2782,2789-2790,2794,2797-2802,2804,2808-2810,2812,2814-2824,2826-2832,2834-2835 via svnmerge from 1.0 branch
2008-06-11 08:55:59 +00:00
|
|
|
// Put empty values last
|
|
|
|
if (!valA && valB) {
|
|
|
|
var cmp = 1;
|
|
|
|
}
|
|
|
|
else if (valA && !valB) {
|
|
|
|
var cmp = -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var cmp = collation.compareString(0, valA, valB);
|
2007-10-23 07:11:59 +00:00
|
|
|
}
|
|
|
|
|
Merged revisions 2710-2712,2714-2716,2718-2728,2730-2731,2734,2736-2738,2740-2750,2752-2753,2755,2758-2768,2770-2779,2782,2789-2790,2794,2797-2802,2804,2808-2810,2812,2814-2824,2826-2832,2834-2835 via svnmerge from 1.0 branch
2008-06-11 08:55:59 +00:00
|
|
|
var result = 0;
|
|
|
|
if (cmp != 0) {
|
|
|
|
result = cmp * sorts[index].order;
|
|
|
|
}
|
2007-10-23 07:11:59 +00:00
|
|
|
index++;
|
|
|
|
}
|
|
|
|
while (result == 0 && sorts[index]);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
|
|
|
items.sort(compareFunction);
|
|
|
|
for (var i in items) {
|
|
|
|
if (items[i].reportChildren) {
|
|
|
|
items[i].reportChildren.notes.sort(compareFunction);
|
|
|
|
items[i].reportChildren.attachments.sort(compareFunction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pass off to the appropriate handler
|
|
|
|
switch (format){
|
|
|
|
case 'rtf':
|
|
|
|
mimeType = 'text/rtf';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'csv':
|
|
|
|
mimeType = 'text/plain';
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-04-27 21:33:01 +00:00
|
|
|
var content = Zotero.Report.generateHTMLDetails(items, combineChildItems);
|
|
|
|
|
|
|
|
// Serve invalid XML as text/html
|
|
|
|
//
|
|
|
|
// This is a temporary workaround until we figure out
|
|
|
|
// something better.
|
|
|
|
try {
|
|
|
|
var xml = new XML(content.replace(/^<\!DOCTYPE [^>]+>\n/, '').trim());
|
|
|
|
mimeType = 'application/xhtml+xml';
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
Zotero.debug(e);
|
|
|
|
mimeType = 'text/html';
|
|
|
|
}
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
format = 'html';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e){
|
|
|
|
Zotero.debug(e);
|
|
|
|
throw (e);
|
|
|
|
}
|
|
|
|
|
|
|
|
var uri_str = 'data:' + (mimeType ? mimeType + ',' : '') + encodeURIComponent(content);
|
|
|
|
var ext_uri = ioService.newURI(uri_str, null, null);
|
|
|
|
var extChannel = ioService.newChannelFromURI(ext_uri);
|
|
|
|
|
|
|
|
return extChannel;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var TimelineExtension = new function(){
|
|
|
|
this.newChannel = newChannel;
|
Merged revisions 3080-3081,3084,3087-3088,3090,3092,3099-3103,3113-3114,3132,3134-3143,3145,3148-3151,3154-3159,3165,3174,3194,3234-3235,3239-3240,3244,3246-3254,3258-3262,3268,3270,3274,3279,3286-3288,3294-3295 from 1.0 branch via svnmerge
2008-09-01 01:54:00 +00:00
|
|
|
|
|
|
|
this.__defineGetter__('loadAsChrome', function () { return true; });
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
/*
|
|
|
|
queryString key abbreviations: intervals = i | dateType = t | timelineDate = d
|
|
|
|
|
|
|
|
interval abbreviations: day = d | month = m | year = y | decade = e | century = c | millennium = i
|
|
|
|
dateType abbreviations: date = d | dateAdded = da | dateModified = dm
|
|
|
|
timelineDate format: shortMonthName.day.year (year is positive for A.D. and negative for B.C.)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
zotero://timeline -----> creates HTML for timeline
|
|
|
|
(defaults: type = library | intervals = month, year, decade | timelineDate = today's date | dateType = date)
|
|
|
|
|
|
|
|
|
|
|
|
Example URLs:
|
|
|
|
|
|
|
|
zotero://timeline/library?i=yec
|
|
|
|
zotero://timeline/collection/12345?t=da&d=Jul.24.2008
|
|
|
|
zotero://timeline/search/54321?d=Dec.1.-500&i=dmy&t=d
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
zotero://timeline/data ----->creates XML file
|
|
|
|
(defaults: type = library | dateType = date)
|
|
|
|
|
|
|
|
|
|
|
|
Example URLs:
|
|
|
|
|
|
|
|
zotero://timeline/data/library?t=da
|
|
|
|
zotero://timeline/data/collection/12345
|
|
|
|
zotero://timeline/data/search/54321?t=dm
|
|
|
|
|
|
|
|
*/
|
|
|
|
function newChannel(uri) {
|
|
|
|
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIIOService);
|
|
|
|
|
|
|
|
var Zotero = Components.classes["@zotero.org/Zotero;1"]
|
|
|
|
.getService(Components.interfaces.nsISupports)
|
|
|
|
.wrappedJSObject;
|
|
|
|
|
|
|
|
generateContent:try {
|
|
|
|
var mimeType, content = '';
|
|
|
|
|
|
|
|
var [path, queryString] = uri.path.substr(1).split('?');
|
|
|
|
var [intervals, timelineDate, dateType] = ['','',''];
|
|
|
|
|
|
|
|
if (queryString) {
|
|
|
|
var queryVars = queryString.split('&');
|
|
|
|
for (var i in queryVars) {
|
|
|
|
var [key, val] = queryVars[i].split('=');
|
|
|
|
if(val) {
|
|
|
|
switch (key) {
|
|
|
|
case 'i':
|
|
|
|
intervals = val;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
timelineDate = val;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
dateType = val;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var pathParts = path.split('/');
|
2009-12-05 20:16:42 +00:00
|
|
|
if (pathParts[0] != 'data') {
|
|
|
|
var [type, id] = pathParts;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var [, type, id] = pathParts;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the collection or search object
|
|
|
|
var collection, search;
|
|
|
|
switch (type) {
|
|
|
|
case 'collection':
|
|
|
|
var lkh = Zotero.Collections.parseLibraryKeyHash(id);
|
|
|
|
if (lkh) {
|
|
|
|
collection = Zotero.Collections.getByLibraryAndKey(lkh.libraryID, lkh.key);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
collection = Zotero.Collections.get(id);
|
|
|
|
}
|
|
|
|
if (!collection) {
|
|
|
|
mimeType = 'text/html';
|
|
|
|
content = 'Invalid collection ID or key';
|
|
|
|
break generateContent;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'search':
|
|
|
|
var lkh = Zotero.Searches.parseLibraryKeyHash(id);
|
|
|
|
if (lkh) {
|
|
|
|
var s = Zotero.Searches.getByLibraryAndKey(lkh.libraryID, lkh.key);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var s = Zotero.Searches.get(id);
|
|
|
|
}
|
|
|
|
if (!s) {
|
|
|
|
mimeType = 'text/html';
|
|
|
|
content = 'Invalid search ID or key';
|
|
|
|
break generateContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: Hack to exclude group libraries for now
|
|
|
|
var search = new Zotero.Search();
|
|
|
|
search.setScope(s);
|
|
|
|
var groups = Zotero.Groups.getAll();
|
|
|
|
for each(var group in groups) {
|
|
|
|
search.addCondition('libraryID', 'isNot', group.libraryID);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-10-23 07:11:59 +00:00
|
|
|
|
|
|
|
if (pathParts[0] != 'data') {
|
|
|
|
//creates HTML file
|
|
|
|
content = Zotero.File.getContentsFromURL('chrome://zotero/skin/timeline/timeline.html');
|
|
|
|
mimeType = 'text/html';
|
|
|
|
|
|
|
|
var [type, id] = pathParts;
|
2011-03-05 04:28:54 +00:00
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
if(!timelineDate){
|
|
|
|
timelineDate=Date();
|
|
|
|
var dateParts=timelineDate.toString().split(' ');
|
|
|
|
timelineDate=dateParts[1]+'.'+dateParts[2]+'.'+dateParts[3];
|
|
|
|
}
|
|
|
|
if (intervals.length < 3) {
|
|
|
|
intervals += "mye".substr(intervals.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
var theIntervals = new Object();
|
|
|
|
theIntervals['d'] = 'Timeline.DateTime.DAY';
|
|
|
|
theIntervals['m'] = 'Timeline.DateTime.MONTH';
|
|
|
|
theIntervals['y'] = 'Timeline.DateTime.YEAR';
|
|
|
|
theIntervals['e'] = 'Timeline.DateTime.DECADE';
|
|
|
|
theIntervals['c'] = 'Timeline.DateTime.CENTURY';
|
|
|
|
theIntervals['i'] = 'Timeline.DateTime.MILLENNIUM';
|
|
|
|
|
|
|
|
//sets the intervals of the timeline bands
|
|
|
|
var theTemp = '<body onload="onLoad(';
|
|
|
|
var a = (theIntervals[intervals[0]]) ? theIntervals[intervals[0]] : 'Timeline.DateTime.MONTH';
|
|
|
|
var b = (theIntervals[intervals[1]]) ? theIntervals[intervals[1]] : 'Timeline.DateTime.YEAR';
|
|
|
|
var c = (theIntervals[intervals[2]]) ? theIntervals[intervals[2]] : 'Timeline.DateTime.DECADE';
|
|
|
|
content = content.replace(theTemp, theTemp + a + ',' + b + ',' + c + ',\'' + timelineDate + '\'');
|
|
|
|
|
|
|
|
theTemp = 'document.write("<title>';
|
|
|
|
if(type == 'collection') {
|
2009-12-05 20:16:42 +00:00
|
|
|
content = content.replace(theTemp, theTemp + collection.name + ' - ');
|
2007-10-23 07:11:59 +00:00
|
|
|
}
|
|
|
|
else if(type == 'search') {
|
2009-12-05 20:16:42 +00:00
|
|
|
content = content.replace(theTemp, theTemp + search.name + ' - ');
|
2007-10-23 07:11:59 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
content = content.replace(theTemp, theTemp + Zotero.getString('pane.collections.library') + ' - ');
|
|
|
|
}
|
|
|
|
|
|
|
|
theTemp = 'Timeline.loadXML("zotero://timeline/data/';
|
|
|
|
var d = '';
|
|
|
|
//passes information (type,ids, dateType) for when the XML is created
|
|
|
|
if(!type || (type != 'collection' && type != 'search')) {
|
2011-03-05 04:28:54 +00:00
|
|
|
d += 'library' + (id ? "/" + id : "");
|
2007-10-23 07:11:59 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-05-18 15:48:45 +00:00
|
|
|
d += type + '/' + id;
|
2007-10-23 07:11:59 +00:00
|
|
|
}
|
2009-05-18 15:48:45 +00:00
|
|
|
|
|
|
|
if(dateType) {
|
|
|
|
d += '?t=' + dateType;
|
|
|
|
}
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
content = content.replace(theTemp, theTemp + d);
|
|
|
|
|
|
|
|
|
|
|
|
var uri_str = 'data:' + (mimeType ? mimeType + ',' : '') + encodeURIComponent(content);
|
|
|
|
var ext_uri = ioService.newURI(uri_str, null, null);
|
|
|
|
var extChannel = ioService.newChannelFromURI(ext_uri);
|
|
|
|
|
|
|
|
return extChannel;
|
|
|
|
}
|
2009-12-05 20:16:42 +00:00
|
|
|
// Create XML file
|
2007-10-23 07:11:59 +00:00
|
|
|
else {
|
2009-12-05 20:16:42 +00:00
|
|
|
switch (type) {
|
2007-10-23 07:11:59 +00:00
|
|
|
case 'collection':
|
2009-12-05 20:16:42 +00:00
|
|
|
var results = collection.getChildItems();
|
2007-10-23 07:11:59 +00:00
|
|
|
break;
|
2009-12-05 20:16:42 +00:00
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
case 'search':
|
2009-12-05 20:16:42 +00:00
|
|
|
var ids = search.search();
|
|
|
|
var results = Zotero.Items.get(ids);
|
2007-10-23 07:11:59 +00:00
|
|
|
break;
|
2009-12-05 20:16:42 +00:00
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
default:
|
|
|
|
type = 'library';
|
|
|
|
var s = new Zotero.Search();
|
2011-03-05 04:28:54 +00:00
|
|
|
s.addCondition('libraryID', 'is', id ? id : null);
|
2007-10-23 07:11:59 +00:00
|
|
|
s.addCondition('noChildren', 'true');
|
|
|
|
var ids = s.search();
|
2009-12-05 20:16:42 +00:00
|
|
|
var results = Zotero.Items.get(ids);
|
2007-10-23 07:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var items = [];
|
|
|
|
// Only include parent items
|
|
|
|
for (var i = 0; i < results.length; i++) {
|
|
|
|
if (!results[i].getSource()) {
|
|
|
|
items.push(results[i]);
|
|
|
|
}
|
|
|
|
}
|
2009-12-05 20:16:42 +00:00
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
if (!items) {
|
|
|
|
mimeType = 'text/html';
|
|
|
|
content = 'Invalid ID';
|
|
|
|
break generateContent;
|
|
|
|
}
|
2009-12-05 20:16:42 +00:00
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
mimeType = 'application/xml';
|
2009-12-05 20:16:42 +00:00
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
var theDateTypes = new Object();
|
|
|
|
theDateTypes['d'] = 'date';
|
|
|
|
theDateTypes['da'] = 'dateAdded';
|
|
|
|
theDateTypes['dm'] = 'dateModified';
|
|
|
|
|
|
|
|
//default dateType = date
|
|
|
|
if (!dateType || !theDateTypes[dateType]) {
|
|
|
|
dateType = 'd';
|
|
|
|
}
|
2009-12-05 20:16:42 +00:00
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
content = Zotero.Timeline.generateXMLDetails(items, theDateTypes[dateType]);
|
|
|
|
}
|
|
|
|
|
|
|
|
var uri_str = 'data:' + (mimeType ? mimeType + ',' : '') + encodeURIComponent(content);
|
|
|
|
var ext_uri = ioService.newURI(uri_str, null, null);
|
|
|
|
var extChannel = ioService.newChannelFromURI(ext_uri);
|
2009-12-05 20:16:42 +00:00
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
return extChannel;
|
|
|
|
}
|
|
|
|
catch (e){
|
|
|
|
Zotero.debug(e);
|
|
|
|
throw (e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
Merged revisions 2989,2994,2996-2999,3001,3003-3004,3007,3010,3012,3015-3016,3026-3029,3036-3038,3040-3041,3046,3048,3050,3052,3054-3055,3057-3058,3066,3069-3073 from 1.0 branch via svnmerge
2008-07-22 05:45:32 +00:00
|
|
|
zotero://attachment/[id]/
|
2007-10-23 07:11:59 +00:00
|
|
|
*/
|
Merged revisions 2989,2994,2996-2999,3001,3003-3004,3007,3010,3012,3015-3016,3026-3029,3036-3038,3040-3041,3046,3048,3050,3052,3054-3055,3057-3058,3066,3069-3073 from 1.0 branch via svnmerge
2008-07-22 05:45:32 +00:00
|
|
|
var AttachmentExtension = new function() {
|
|
|
|
this.newChannel = newChannel;
|
|
|
|
|
Merged revisions 3080-3081,3084,3087-3088,3090,3092,3099-3103,3113-3114,3132,3134-3143,3145,3148-3151,3154-3159,3165,3174,3194,3234-3235,3239-3240,3244,3246-3254,3258-3262,3268,3270,3274,3279,3286-3288,3294-3295 from 1.0 branch via svnmerge
2008-09-01 01:54:00 +00:00
|
|
|
this.__defineGetter__('loadAsChrome', function () { return false; });
|
|
|
|
|
Merged revisions 2989,2994,2996-2999,3001,3003-3004,3007,3010,3012,3015-3016,3026-3029,3036-3038,3040-3041,3046,3048,3050,3052,3054-3055,3057-3058,3066,3069-3073 from 1.0 branch via svnmerge
2008-07-22 05:45:32 +00:00
|
|
|
function newChannel(uri) {
|
|
|
|
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIIOService);
|
|
|
|
|
|
|
|
var Zotero = Components.classes["@zotero.org/Zotero;1"]
|
|
|
|
.getService(Components.interfaces.nsISupports)
|
|
|
|
.wrappedJSObject;
|
|
|
|
|
|
|
|
try {
|
|
|
|
var errorMsg;
|
|
|
|
var [id, fileName] = uri.path.substr(1).split('/');
|
|
|
|
|
|
|
|
if (parseInt(id) != id) {
|
Merged revisions 3080-3081,3084,3087-3088,3090,3092,3099-3103,3113-3114,3132,3134-3143,3145,3148-3151,3154-3159,3165,3174,3194,3234-3235,3239-3240,3244,3246-3254,3258-3262,3268,3270,3274,3279,3286-3288,3294-3295 from 1.0 branch via svnmerge
2008-09-01 01:54:00 +00:00
|
|
|
// Proxy annotation icons
|
|
|
|
if (id.match(/^annotation.*\.(png|html|css|gif)$/)) {
|
|
|
|
var chromeURL = 'chrome://zotero/skin/' + id;
|
2008-09-01 06:09:56 +00:00
|
|
|
var ios = Components.classes["@mozilla.org/network/io-service;1"].
|
|
|
|
getService(Components.interfaces.nsIIOService);
|
|
|
|
var uri = ios.newURI(chromeURL, null, null);
|
|
|
|
var chromeReg = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
|
|
|
|
.getService(Components.interfaces.nsIChromeRegistry);
|
|
|
|
var fileURI = chromeReg.convertChromeURL(uri);
|
Merged revisions 3080-3081,3084,3087-3088,3090,3092,3099-3103,3113-3114,3132,3134-3143,3145,3148-3151,3154-3159,3165,3174,3194,3234-3235,3239-3240,3244,3246-3254,3258-3262,3268,3270,3274,3279,3286-3288,3294-3295 from 1.0 branch via svnmerge
2008-09-01 01:54:00 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return _errorChannel("Attachment id not an integer");
|
|
|
|
}
|
Merged revisions 2989,2994,2996-2999,3001,3003-3004,3007,3010,3012,3015-3016,3026-3029,3036-3038,3040-3041,3046,3048,3050,3052,3054-3055,3057-3058,3066,3069-3073 from 1.0 branch via svnmerge
2008-07-22 05:45:32 +00:00
|
|
|
}
|
|
|
|
|
2008-09-01 06:09:56 +00:00
|
|
|
if (!fileURI) {
|
Merged revisions 3080-3081,3084,3087-3088,3090,3092,3099-3103,3113-3114,3132,3134-3143,3145,3148-3151,3154-3159,3165,3174,3194,3234-3235,3239-3240,3244,3246-3254,3258-3262,3268,3270,3274,3279,3286-3288,3294-3295 from 1.0 branch via svnmerge
2008-09-01 01:54:00 +00:00
|
|
|
var item = Zotero.Items.get(id);
|
|
|
|
if (!item) {
|
|
|
|
return _errorChannel("Item not found");
|
|
|
|
}
|
|
|
|
var file = item.getFile();
|
2008-09-01 06:09:56 +00:00
|
|
|
if (!file) {
|
Merged revisions 2989,2994,2996-2999,3001,3003-3004,3007,3010,3012,3015-3016,3026-3029,3036-3038,3040-3041,3046,3048,3050,3052,3054-3055,3057-3058,3066,3069-3073 from 1.0 branch via svnmerge
2008-07-22 05:45:32 +00:00
|
|
|
return _errorChannel("File not found");
|
|
|
|
}
|
2008-09-01 06:09:56 +00:00
|
|
|
if (fileName) {
|
|
|
|
file = file.parent;
|
|
|
|
file.append(fileName);
|
|
|
|
if (!file.exists()) {
|
|
|
|
return _errorChannel("File not found");
|
|
|
|
}
|
|
|
|
}
|
Merged revisions 2989,2994,2996-2999,3001,3003-3004,3007,3010,3012,3015-3016,3026-3029,3036-3038,3040-3041,3046,3048,3050,3052,3054-3055,3057-3058,3066,3069-3073 from 1.0 branch via svnmerge
2008-07-22 05:45:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var ph = Components.classes["@mozilla.org/network/protocol;1?name=file"].
|
|
|
|
createInstance(Components.interfaces.nsIFileProtocolHandler);
|
2008-09-01 06:09:56 +00:00
|
|
|
if (!fileURI) {
|
|
|
|
var fileURI = ph.newFileURI(file);
|
|
|
|
}
|
Merged revisions 2989,2994,2996-2999,3001,3003-3004,3007,3010,3012,3015-3016,3026-3029,3036-3038,3040-3041,3046,3048,3050,3052,3054-3055,3057-3058,3066,3069-3073 from 1.0 branch via svnmerge
2008-07-22 05:45:32 +00:00
|
|
|
var channel = ioService.newChannelFromURI(fileURI);
|
|
|
|
return channel;
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
Zotero.debug(e);
|
|
|
|
throw (e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function _errorChannel(msg) {
|
|
|
|
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIIOService);
|
|
|
|
var uriStr = 'data:text/plain,' + encodeURIComponent(msg);
|
|
|
|
var dataURI = ioService.newURI(uriStr, null, null);
|
|
|
|
var channel = ioService.newChannelFromURI(dataURI);
|
|
|
|
return channel;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
|
2009-12-05 20:16:42 +00:00
|
|
|
/**
|
|
|
|
* zotero://select/[type]/0_ABCD1234
|
|
|
|
* zotero://select/[type]/1234 (not consistent across synced machines)
|
|
|
|
*/
|
2007-10-23 07:11:59 +00:00
|
|
|
var SelectExtension = new function(){
|
|
|
|
this.newChannel = newChannel;
|
Merged revisions 3080-3081,3084,3087-3088,3090,3092,3099-3103,3113-3114,3132,3134-3143,3145,3148-3151,3154-3159,3165,3174,3194,3234-3235,3239-3240,3244,3246-3254,3258-3262,3268,3270,3274,3279,3286-3288,3294-3295 from 1.0 branch via svnmerge
2008-09-01 01:54:00 +00:00
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
function newChannel(uri) {
|
|
|
|
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIIOService);
|
|
|
|
|
|
|
|
var Zotero = Components.classes["@zotero.org/Zotero;1"]
|
|
|
|
.getService(Components.interfaces.nsISupports)
|
|
|
|
.wrappedJSObject;
|
|
|
|
|
|
|
|
generateContent:try {
|
|
|
|
var mimeType, content = '';
|
2009-12-05 20:16:42 +00:00
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
var [path, queryString] = uri.path.substr(1).split('?');
|
|
|
|
var [type, id] = path.split('/');
|
|
|
|
|
2011-06-14 00:36:21 +00:00
|
|
|
// currently only able to select one item
|
2007-10-23 07:11:59 +00:00
|
|
|
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
|
|
|
.getService(Components.interfaces.nsIWindowMediator);
|
2011-06-14 00:36:21 +00:00
|
|
|
var win = wm.getMostRecentWindow("navigator:browser");
|
2011-02-03 07:17:55 +00:00
|
|
|
|
2011-06-14 00:36:21 +00:00
|
|
|
// restore window if it's in the dock
|
|
|
|
if(win.windowState == Components.interfaces.nsIDOMChromeWindow.STATE_MINIMIZED) {
|
|
|
|
win.restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
// open Zotero pane
|
2011-01-30 09:44:01 +00:00
|
|
|
win.ZoteroPane.show();
|
2007-10-23 07:11:59 +00:00
|
|
|
|
2011-06-14 00:36:21 +00:00
|
|
|
if(!id) return;
|
|
|
|
|
2009-12-05 20:16:42 +00:00
|
|
|
var lkh = Zotero.Items.parseLibraryKeyHash(id);
|
|
|
|
if (lkh) {
|
|
|
|
var item = Zotero.Items.getByLibraryAndKey(lkh.libraryID, lkh.key);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var item = Zotero.Items.get(id);
|
|
|
|
}
|
|
|
|
if (!item) {
|
|
|
|
var msg = "Item " + id + " not found in zotero://select";
|
|
|
|
Zotero.debug(msg, 2);
|
|
|
|
Components.utils.reportError(msg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-03 07:17:55 +00:00
|
|
|
win.ZoteroPane.selectItem(item.id);
|
2007-10-23 07:11:59 +00:00
|
|
|
}
|
|
|
|
catch (e){
|
|
|
|
Zotero.debug(e);
|
|
|
|
throw (e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2009-07-27 11:12:42 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
zotero://fullscreen
|
|
|
|
*/
|
|
|
|
var FullscreenExtension = new function() {
|
|
|
|
this.newChannel = newChannel;
|
|
|
|
|
|
|
|
this.__defineGetter__('loadAsChrome', function () { return false; });
|
|
|
|
|
|
|
|
function newChannel(uri) {
|
|
|
|
var Zotero = Components.classes["@zotero.org/Zotero;1"]
|
|
|
|
.getService(Components.interfaces.nsISupports)
|
|
|
|
.wrappedJSObject;
|
|
|
|
|
|
|
|
generateContent: try {
|
2011-02-09 06:42:08 +00:00
|
|
|
var window = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
|
|
|
|
.getService(Components.interfaces.nsIWindowWatcher)
|
2011-07-02 04:27:57 +00:00
|
|
|
.openWindow(null, 'chrome://zotero/content/standalone/standalone.xul', '',
|
2011-02-09 06:42:08 +00:00
|
|
|
'chrome,centerscreen,resizable', null);
|
2009-07-27 11:12:42 +00:00
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
Zotero.debug(e);
|
|
|
|
throw (e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2009-08-10 16:44:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
zotero://debug/
|
|
|
|
*/
|
|
|
|
var DebugExtension = new function() {
|
|
|
|
this.newChannel = newChannel;
|
|
|
|
|
|
|
|
this.__defineGetter__('loadAsChrome', function () { return false; });
|
|
|
|
|
|
|
|
function newChannel(uri) {
|
|
|
|
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIIOService);
|
|
|
|
|
|
|
|
var Zotero = Components.classes["@zotero.org/Zotero;1"]
|
|
|
|
.getService(Components.interfaces.nsISupports)
|
|
|
|
.wrappedJSObject;
|
|
|
|
|
|
|
|
try {
|
|
|
|
var output = Zotero.Debug.get();
|
|
|
|
|
|
|
|
var uriStr = 'data:text/plain,' + encodeURIComponent(output);
|
|
|
|
var extURI = ioService.newURI(uriStr, null, null);
|
|
|
|
return ioService.newChannelFromURI(extURI);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
Zotero.debug(e);
|
|
|
|
throw (e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-09-23 04:14:19 +00:00
|
|
|
var ConnectorChannel = function(uri, data) {
|
|
|
|
var secMan = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
|
|
|
|
.getService(Components.interfaces.nsIScriptSecurityManager);
|
|
|
|
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIIOService);
|
|
|
|
|
|
|
|
this.name = uri;
|
|
|
|
this.URI = ioService.newURI(uri, "UTF-8", null);
|
|
|
|
this.owner = secMan.getCodebasePrincipal(this.URI);
|
|
|
|
this._isPending = true;
|
|
|
|
|
|
|
|
var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].
|
|
|
|
createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
|
|
|
|
converter.charset = "UTF-8";
|
|
|
|
this._stream = converter.convertToInputStream(data);
|
|
|
|
this.contentLength = this._stream.available();
|
|
|
|
}
|
|
|
|
|
|
|
|
ConnectorChannel.prototype.contentCharset = "UTF-8";
|
|
|
|
ConnectorChannel.prototype.contentType = "text/html";
|
2011-08-12 18:10:53 +00:00
|
|
|
ConnectorChannel.prototype.notificationCallbacks = null;
|
2010-09-23 04:14:19 +00:00
|
|
|
ConnectorChannel.prototype.securityInfo = null;
|
|
|
|
ConnectorChannel.prototype.status = 0;
|
|
|
|
ConnectorChannel.prototype.loadGroup = null;
|
|
|
|
ConnectorChannel.prototype.securityInfo = null;
|
|
|
|
ConnectorChannel.prototype.loadFlags = 393216;
|
|
|
|
|
|
|
|
ConnectorChannel.prototype.__defineGetter__("originalURI", function() { return this.URI });
|
|
|
|
ConnectorChannel.prototype.__defineSetter__("originalURI", function() { });
|
|
|
|
|
|
|
|
ConnectorChannel.prototype.asyncOpen = function(streamListener, context) {
|
2011-08-12 18:10:53 +00:00
|
|
|
if(this.loadGroup) this.loadGroup.addRequest(this, null);
|
2010-09-23 04:14:19 +00:00
|
|
|
streamListener.onStartRequest(this, context);
|
|
|
|
streamListener.onDataAvailable(this, context, this._stream, 0, this.contentLength);
|
|
|
|
streamListener.onStopRequest(this, context, this.status);
|
|
|
|
this._isPending = false;
|
2011-08-12 18:10:53 +00:00
|
|
|
if(this.loadGroup) this.loadGroup.removeRequest(this, null, 0);
|
2010-09-23 04:14:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ConnectorChannel.prototype.isPending = function() {
|
|
|
|
return this._isPending;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConnectorChannel.prototype.cancel = function(status) {
|
|
|
|
this.status = status;
|
|
|
|
this._isPending = false;
|
|
|
|
if(this._stream) this._stream.close();
|
|
|
|
}
|
|
|
|
|
2011-08-12 18:10:53 +00:00
|
|
|
ConnectorChannel.prototype.suspend = function() {}
|
2010-09-23 04:14:19 +00:00
|
|
|
|
2011-08-12 18:10:53 +00:00
|
|
|
ConnectorChannel.prototype.resume = function() {}
|
2010-09-23 04:14:19 +00:00
|
|
|
|
|
|
|
ConnectorChannel.prototype.open = function() {
|
|
|
|
return this._stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConnectorChannel.prototype.QueryInterface = function(iid) {
|
|
|
|
if (!iid.equals(Components.interfaces.nsIChannel) && !iid.equals(Components.interfaces.nsIRequest) &&
|
|
|
|
!iid.equals(Components.interfaces.nsISupports)) {
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* zotero://connector/
|
|
|
|
*
|
|
|
|
* URI spoofing for transferring page data across boundaries
|
|
|
|
*/
|
|
|
|
var ConnectorExtension = new function() {
|
|
|
|
this.loadAsChrome = false;
|
|
|
|
|
|
|
|
this.newChannel = function(uri) {
|
|
|
|
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIIOService);
|
|
|
|
var secMan = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
|
|
|
|
.getService(Components.interfaces.nsIScriptSecurityManager);
|
|
|
|
var Zotero = Components.classes["@zotero.org/Zotero;1"]
|
|
|
|
.getService(Components.interfaces.nsISupports)
|
|
|
|
.wrappedJSObject;
|
|
|
|
|
|
|
|
try {
|
|
|
|
var originalURI = uri.path;
|
|
|
|
originalURI = decodeURIComponent(originalURI.substr(originalURI.indexOf("/")+1));
|
2011-06-14 00:36:21 +00:00
|
|
|
if(!Zotero.Server.Connector.Data[originalURI]) {
|
2010-09-23 04:14:19 +00:00
|
|
|
return null;
|
|
|
|
} else {
|
2011-06-14 00:36:21 +00:00
|
|
|
return new ConnectorChannel(originalURI, Zotero.Server.Connector.Data[originalURI]);
|
2010-09-23 04:14:19 +00:00
|
|
|
}
|
|
|
|
} catch(e) {
|
|
|
|
Zotero.debug(e);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
var ReportExtensionSpec = ZOTERO_SCHEME + "://report"
|
|
|
|
this._extensions[ReportExtensionSpec] = ReportExtension;
|
2009-08-10 16:44:15 +00:00
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
var TimelineExtensionSpec = ZOTERO_SCHEME + "://timeline"
|
|
|
|
this._extensions[TimelineExtensionSpec] = TimelineExtension;
|
|
|
|
|
Merged revisions 2989,2994,2996-2999,3001,3003-3004,3007,3010,3012,3015-3016,3026-3029,3036-3038,3040-3041,3046,3048,3050,3052,3054-3055,3057-3058,3066,3069-3073 from 1.0 branch via svnmerge
2008-07-22 05:45:32 +00:00
|
|
|
var AttachmentExtensionSpec = ZOTERO_SCHEME + "://attachment"
|
|
|
|
this._extensions[AttachmentExtensionSpec] = AttachmentExtension;
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
var SelectExtensionSpec = ZOTERO_SCHEME + "://select"
|
|
|
|
this._extensions[SelectExtensionSpec] = SelectExtension;
|
2009-07-27 11:12:42 +00:00
|
|
|
|
|
|
|
var FullscreenExtensionSpec = ZOTERO_SCHEME + "://fullscreen"
|
|
|
|
this._extensions[FullscreenExtensionSpec] = FullscreenExtension;
|
2009-08-10 16:44:15 +00:00
|
|
|
|
|
|
|
var DebugExtensionSpec = ZOTERO_SCHEME + "://debug"
|
|
|
|
this._extensions[DebugExtensionSpec] = DebugExtension;
|
2010-09-23 04:14:19 +00:00
|
|
|
|
|
|
|
var ConnectorExtensionSpec = ZOTERO_SCHEME + "://connector"
|
|
|
|
this._extensions[ConnectorExtensionSpec] = ConnectorExtension;
|
2007-10-23 07:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Implements nsIProtocolHandler
|
|
|
|
*/
|
|
|
|
ChromeExtensionHandler.prototype = {
|
|
|
|
scheme: ZOTERO_SCHEME,
|
|
|
|
|
|
|
|
defaultPort : -1,
|
|
|
|
|
Merged revisions 3080-3081,3084,3087-3088,3090,3092,3099-3103,3113-3114,3132,3134-3143,3145,3148-3151,3154-3159,3165,3174,3194,3234-3235,3239-3240,3244,3246-3254,3258-3262,3268,3270,3274,3279,3286-3288,3294-3295 from 1.0 branch via svnmerge
2008-09-01 01:54:00 +00:00
|
|
|
protocolFlags :
|
|
|
|
Components.interfaces.nsIProtocolHandler.URI_NORELATIVE |
|
|
|
|
Components.interfaces.nsIProtocolHandler.URI_NOAUTH |
|
2008-11-30 20:18:48 +00:00
|
|
|
// DEBUG: This should be URI_IS_LOCAL_FILE, and MUST be if any
|
|
|
|
// extensions that modify data are added
|
|
|
|
// - https://www.zotero.org/trac/ticket/1156
|
|
|
|
//
|
2011-03-05 04:10:29 +00:00
|
|
|
Components.interfaces.nsIProtocolHandler.URI_IS_LOCAL_FILE,
|
|
|
|
//Components.interfaces.nsIProtocolHandler.URI_LOADABLE_BY_ANYONE,
|
Merged revisions 3080-3081,3084,3087-3088,3090,3092,3099-3103,3113-3114,3132,3134-3143,3145,3148-3151,3154-3159,3165,3174,3194,3234-3235,3239-3240,3244,3246-3254,3258-3262,3268,3270,3274,3279,3286-3288,3294-3295 from 1.0 branch via svnmerge
2008-09-01 01:54:00 +00:00
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
allowPort : function(port, scheme) {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
newURI : function(spec, charset, baseURI) {
|
|
|
|
var newURL = Components.classes["@mozilla.org/network/standard-url;1"]
|
|
|
|
.createInstance(Components.interfaces.nsIStandardURL);
|
|
|
|
newURL.init(1, -1, spec, charset, baseURI);
|
|
|
|
return newURL.QueryInterface(Components.interfaces.nsIURI);
|
|
|
|
},
|
|
|
|
|
|
|
|
newChannel : function(uri) {
|
|
|
|
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIIOService);
|
|
|
|
|
|
|
|
var chromeService = Components.classes["@mozilla.org/network/protocol;1?name=chrome"]
|
|
|
|
.getService(Components.interfaces.nsIProtocolHandler);
|
|
|
|
|
|
|
|
var newChannel = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
var uriString = uri.spec.toLowerCase();
|
|
|
|
|
Merged revisions 3080-3081,3084,3087-3088,3090,3092,3099-3103,3113-3114,3132,3134-3143,3145,3148-3151,3154-3159,3165,3174,3194,3234-3235,3239-3240,3244,3246-3254,3258-3262,3268,3270,3274,3279,3286-3288,3294-3295 from 1.0 branch via svnmerge
2008-09-01 01:54:00 +00:00
|
|
|
for (var extSpec in this._extensions) {
|
2007-10-23 07:11:59 +00:00
|
|
|
var ext = this._extensions[extSpec];
|
|
|
|
|
|
|
|
if (uriString.indexOf(extSpec) == 0) {
|
Merged revisions 3080-3081,3084,3087-3088,3090,3092,3099-3103,3113-3114,3132,3134-3143,3145,3148-3151,3154-3159,3165,3174,3194,3234-3235,3239-3240,3244,3246-3254,3258-3262,3268,3270,3274,3279,3286-3288,3294-3295 from 1.0 branch via svnmerge
2008-09-01 01:54:00 +00:00
|
|
|
if (ext.loadAsChrome && this._systemPrincipal == null) {
|
2007-10-23 07:11:59 +00:00
|
|
|
var chromeURI = chromeService.newURI(DUMMY_CHROME_URL, null, null);
|
|
|
|
var chromeChannel = chromeService.newChannel(chromeURI);
|
|
|
|
|
|
|
|
// Cache System Principal from chrome request
|
|
|
|
// so proxied pages load with chrome privileges
|
|
|
|
this._systemPrincipal = chromeChannel.owner;
|
|
|
|
|
|
|
|
var chromeRequest = chromeChannel.QueryInterface(Components.interfaces.nsIRequest);
|
|
|
|
chromeRequest.cancel(0x804b0002); // BINDING_ABORTED
|
|
|
|
}
|
|
|
|
|
|
|
|
var extChannel = ext.newChannel(uri);
|
|
|
|
// Extension returned null, so cancel request
|
|
|
|
if (!extChannel) {
|
|
|
|
var chromeURI = chromeService.newURI(DUMMY_CHROME_URL, null, null);
|
|
|
|
var extChannel = chromeService.newChannel(chromeURI);
|
|
|
|
var chromeRequest = extChannel.QueryInterface(Components.interfaces.nsIRequest);
|
|
|
|
chromeRequest.cancel(0x804b0002); // BINDING_ABORTED
|
|
|
|
}
|
|
|
|
|
Merged revisions 3080-3081,3084,3087-3088,3090,3092,3099-3103,3113-3114,3132,3134-3143,3145,3148-3151,3154-3159,3165,3174,3194,3234-3235,3239-3240,3244,3246-3254,3258-3262,3268,3270,3274,3279,3286-3288,3294-3295 from 1.0 branch via svnmerge
2008-09-01 01:54:00 +00:00
|
|
|
// Apply cached system principal to extension channel
|
|
|
|
if (ext.loadAsChrome) {
|
2007-10-23 07:11:59 +00:00
|
|
|
extChannel.owner = this._systemPrincipal;
|
|
|
|
}
|
|
|
|
|
2010-07-06 09:02:35 +00:00
|
|
|
if(!extChannel.originalURI) extChannel.originalURI = uri;
|
2007-10-23 07:11:59 +00:00
|
|
|
|
|
|
|
return extChannel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// pass request through to ChromeProtocolHandler::newChannel
|
|
|
|
if (uriString.indexOf("chrome") != 0) {
|
|
|
|
uriString = uri.spec;
|
|
|
|
uriString = "chrome" + uriString.substring(uriString.indexOf(":"));
|
|
|
|
uri = chromeService.newURI(uriString, null, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
newChannel = chromeService.newChannel(uri);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
throw Components.results.NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return newChannel;
|
|
|
|
},
|
|
|
|
|
2010-07-06 09:02:35 +00:00
|
|
|
contractID: ZOTERO_PROTOCOL_CONTRACTID,
|
|
|
|
classDescription: ZOTERO_PROTOCOL_NAME,
|
|
|
|
classID: ZOTERO_PROTOCOL_CID,
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsISupports,
|
|
|
|
Components.interfaces.nsIProtocolHandler])
|
2007-10-23 07:11:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// XPCOM goop
|
|
|
|
//
|
|
|
|
|
2010-07-06 09:02:35 +00:00
|
|
|
/**
|
|
|
|
* XPCOMUtils.generateNSGetFactory was introduced in Mozilla 2 (Firefox 4).
|
|
|
|
* XPCOMUtils.generateNSGetModule is for Mozilla 1.9.2 (Firefox 3.6).
|
|
|
|
*/
|
|
|
|
if (XPCOMUtils.generateNSGetFactory) {
|
|
|
|
var NSGetFactory = XPCOMUtils.generateNSGetFactory([ChromeExtensionHandler]);
|
|
|
|
} else {
|
|
|
|
var NSGetModule = XPCOMUtils.generateNSGetModule([ChromeExtensionHandler]);
|
|
|
|
}
|