SmugMug.js
Go to the documentation of this file.
1 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
2 Components.utils.import("resource://app/jsmodules/sbLibraryUtils.jsm");
3 Components.utils.import("resource://app/jsmodules/sbProperties.jsm");
4 
5 const Cc = Components.classes;
6 const Ci = Components.interfaces;
7 const Cr = Components.results;
8 
9 const DESCRIPTION = "mashTape Provider: SmugMug Provider";
10 const CID = "{68551fc0-6a50-11dd-ad8b-0800200c9a66}";
11 const CONTRACTID = "@songbirdnest.com/mashTape/provider/photo/SmugMug;1";
12 
13 // XPCOM constructor for our SmugMug mashTape provider
14 function SmugMug() {
15  this.wrappedJSObject = this;
16  Components.utils.import("resource://mashtape/mtUtils.jsm");
17 }
18 
19 SmugMug.prototype.constructor = SmugMug;
20 SmugMug.prototype = {
22  classID: Components.ID(CID),
24  QueryInterface: XPCOMUtils.generateQI([Ci.sbIMashTapePhotoProvider,
25  Ci.sbIMashTapeProvider]),
26 
27  providerName: "SmugMug",
28  providerType: "photo",
29  providerIcon: "chrome://mashTape/content/tabs/smugmug.png",
30 
31  query: function(searchTerms, updateFn) {
32  var req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
33  .createInstance(Ci.nsIXMLHttpRequest);
34 
35  var prefBranch = Cc["@mozilla.org/preferences-service;1"]
36  .getService(Ci.nsIPrefService).getBranch("extensions.mashTape.");
37  var keywords = prefBranch.getCharPref("photo.keywords");
38  if (keywords != "")
39  searchTerms += "%20" + escape(keywords);
40 
41  var url = "http://www.smugmug.com/hack/feed.mg?Type=keyword&format=rss&ImageCount=100&Data=" + escape(searchTerms);
42  req.open("GET", url, true);
43  req.provider = this;
44  req.updateFn = updateFn;
45  req.onreadystatechange = function() {
46  if (this.readyState != 4)
47  return;
48  if (this.status == 200) {
49  var results = new Array();
50  var x = new XML(this.responseText.replace(
51  '<?xml version="1.0" encoding="utf-8"?>', ""));
52  var mediaNs = new Namespace("http://search.yahoo.com/mrss/");
53 
54  for each (var entry in x..item) {
55  if (entry..mediaNs::content.length() < 4)
56  continue;
57  var small = entry..mediaNs::content[1].@url;
58  var med = entry..mediaNs::content[2].@url;
59  var large = entry..mediaNs::content[3].@url;
60  var escapedTitle = entry.title.split(/[\n\r]/).join(" ")
61  .replace(/'/g, "\'");
62  dump("title: " + escapedTitle + ":\n");
63  var item = {
64  title: escapedTitle,
65  url: entry.link,
66  small: small,
67  medium: med,
68  large: large,
69  owner: entry.mediaNs::copyright.toString(),
70  ownerUrl: entry.mediaNs::copyright.@url.toString(),
71  time: Date.parse(entry.pubDate.toString()),
72  width: entry..mediaNs::content[2].@width,
73  height: entry..mediaNs::content[2].@height,
74  }
75  results.push(item);
76  }
77 
78  results.wrappedJSObject = results;
79  this.updateFn.wrappedJSObject.update(CONTRACTID, results);
80  }
81  }
82  req.send(null);
83  },
84 }
85 
86 var components = [SmugMug];
87 function NSGetModule(compMgr, fileSpec) {
88  return XPCOMUtils.generateModule([SmugMug]);
89 }
classDescription entry
Definition: FeedWriter.js:1427
const DESCRIPTION
Definition: SmugMug.js:9
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
const Cr
Definition: SmugMug.js:7
sbOSDControlService prototype QueryInterface
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
function SmugMug()
Definition: SmugMug.js:14
const CID
Definition: SmugMug.js:10
function url(spec)
const Ci
Definition: SmugMug.js:6
sbDeviceFirmwareAutoCheckForUpdate prototype classID
const CONTRACTID
Definition: SmugMug.js:11
const Cc
Definition: SmugMug.js:5