"Recently Zoteroed," A Drupal Approach
Recently, Mark Sample posted a blog entry about making his Zotero library public, in which he outlined a nifty way to use Yahoo Pipes to streamline Zotero’s RSS output and place it in a block on his website. This is a great idea, and from the number of “Recently Zoteroed” blocks I’ve seen cropping up lately, it’s pretty clear that others agree as well. Not only does it make sense to put our research bibliographies in public (both for one’s own convenience as well as those interested in what one is working on), Mark’s blog offers a great how-to for those interested in seeing what Pipes can do.
I’ve jumped on the bandwagon too, and you can see the results in my “Zotero” block at the bottom right of this page. I took a different approach, however, and all of the aggregating and filtering is handled through Drupal, with no need for a third party between Zotero and my website. I thought this was a good chance to show the power that Drupal puts in the hands of its users. Whenever I talk (excitedly) in public about what I’m doing with Drupal, I get the sense that some of my audience is thinking, “Well, that’s great for you, but I don’t have time to figure out how to do all that.” Building a “Recently Zoteroed” block using Drupal is pretty easy, though, and it’s a good demonstration of what to do with one of Drupal’s most impressive modules, Views. In the remainder of this blog entry, I’ll explain how to build your own Zotero block using Views. This is somewhat lengthy, but I’ve tried to be very detailed in all of the steps involved. If you’re already familiar with Views, you can probably just skim it and get the main ideas.
First, for those already down with Views vocabulary, I’ll give you the short answer: add the appropriate zotero feed to your aggregator, create a “Aggregator Item” view, add a filter to skip content matching “Attachment”, etc. Then add a “block” display and place that block somewhere on your site.
1. Add the Zotero feed to your site’s aggregator
Drupal ships with a core module called “Aggregator,” which is disabled by default. To enable it, go to your modules page (Administer -> Site Building -> Modules), check the box next to Aggregator, and Save Configuration. (Aggregator is under the Core - optional heading.)
Once enabled, Aggregator gives you a few more menu options. To add a feed, look under Administer -> Content Management -> Feed aggregator, then click on the Add Feed tab:
Here, copy and paste your Zotero Library feed URL (of course, you could also use a group feed or a folder feed) into the URL box, and give your feed a title. This title is just for reference. You can always give your block a snappier name later on, but you do need to remember this title for building the view in the next steps.
In my case, I called the feed “Zotero”, and plugged in my default library URL: https://api.zotero.org/users/134/items .
Set the update interval to whatever you want, though it should be noted that Aggregator isn’t going to check the feed any more often than your site’s cron job. In my case, I’ve set up my cron to run every 6 hours, so I set my Zotero update interval to be 6 hours as well.
Save the feed, which will take you back to the “Feed Overview” page, then check that it’s working by clicking the “update items” link:
The page should refresh, and under the “Items” column, you should now see some number greater than 0.
For future updates, your site’s cron job will automatically update the feed. Just make sure it’s set up correctly.
At this point, you could go ahead and create a block of this feed. Under Administer -> Site Building -> Blocks, you’ll find a new block available called “Zotero feed latest items.” That feed, however, will include all of the attachments, notes, and other things that Mark used Pipes to filter out, so for Drupal, we can turn to Views to help solve the same problem.
2. Create an “Aggregator Item” view
Views is really one of the most important Drupal modules out there, so you should already have it installed. If not, download the latest release from it’s project page, unpack the contents, and upload the resulting “Views” folder into your /sites/all/modules directly. Then, go back to your modules administration page, and enable the Views module and Views UI. Views is under its own module category:
Now got Administer -> Site Building -> Views to create your first view. From the views overview page, you’ll see a bunch of pre-loaded views, which you can ignore for now. For our purposes, we want a new one, so click the “Add” tab.
The first screen just asks for some basic information about the view:
In my screenshot to the right, you’ll notice that I have a lot of view types available. For this view, we need the “Aggregator item” type. Basically, these types set up which database tables the view should work with, and since a view really is just a complicated SQL query, edited with a nice visual interface, this initial decision determines what kinds of data relationships are available once you start plugging in different options.
Now, click “Next”, and start playing with the Views UI. It can be a little disorienting at first, but the controls are pretty simple. Within each of the boxes, the plus sign will add values to that area (Fields, Arguments, Filters, etc.), and the up and down arrow will let you rearrange the order in which those are processed. If it applies to a given field, a gears symbol will let you adjust the settings for that field.
3. Configure Your View
Before going further, we need to add some display values to the view so we can see what it’s actually doing. Under the Fields box, add a new field. Among the list of available fields, you should see one called “Aggregator Title”. Check its box, and click the Add. Now set up the basic options for this field. Set the Label field to blank (delete the word “Title”), and check the box next to Display as Link. Click the Update button, then the Save button.
Now you can hit the Preview button and it should spit out an unformatted list of links.
If you have other feeds running in your aggregator, your view will be showing all aggregated links. We need to add a filter to only check the Zotero feed, so under the Filter box, add a new filter. Select Aggregator feed: Title as the filter value, and then Add. At the next screen, you’ll need to know the title of the feed you created (probably “Zotero”). Set the Operator to “Is equal to” and the value to “Zotero”:
Update the filter to save the configuration.
Just a few more settings left to configure. Under Basic Settings, next to Style: click “Unformatted”, and in the resulting configuration screen, set it to “HTML List.” Add a Sort Criteria item, Aggregator: Timestamp, set the Sort order to “Ascending” and the Granularity to “Second.”
Finally, following Mark’s example, we need to strip out some items from the feed. We don’t want see attachments and notes as separate examples, for example. In my case, I found it worked to just add one filter, instead of Mark’s five filters, but you may have to experiment with your own feed.
Add a Filter as before, but this time select Aggregator: Body for the field. I noticed that the items I wanted to strip out all start with Item Type Attachment in Zotero’s output, so set the operator to Does not contain “Type%Attachment” (without the quotation marks):
For the type of query this is going to run, “%” is the wildcard. So that filter excludes anything that contains the word Attachment after the word Type. I realize that could produce false positives, but I haven’t seen any yet. I’m sure this could be improved, so I may try and tweak it.
4. Create the block
Now that you’ve got the view configured, it’s time to create the block so it can be visible on your Drupal site. On the leftmost column of the Views UI, there’s a drop-down selector that’s set on “Page.” Switch it to Block and hit Add display. This is where Views starts to get really powerful: after configuring a query you’re satisfied with, you can create different versions of its output for different contexts. Most commonly, these are going to be a Page view and Block view. For instance, a Page view, which takes a URL setting, could be the complete list, whereas a Block view could just show the last 5 items.
With the Block Display selected on the left, configure the final display options. Click the number next to Items to display: and set its value to 5. Then, to create a direct link to your Zotero library page, click on the Footer option, check the box Display even if view has no result and enter something like this in the text field:
<p style="text-align:right"><a href="http://www.zotero.org/zachwhalen/items">more</a></p>
(Note: if you want to include inline styles like I did, set your Input Format to Full HTML.)
Finally, your Views UI display should look something like this (I’ve highlighted the important settings):
Make sure you hit Save, and then make the block visible on your site. Go to Administer -> Site Building -> Blocks, and look for a block listed under the “Disabled” section called “zoteroed: Block” (assuming you named your view “zoteroed”). Use the drop down selector on the right to assign it to some region. The available regions will depend on which theme you have enabled, but in my case, I added the block to “Footer right.” Selecting this will pop the block up into the enabled section where you can move the blocks around inside a region if there are more than one. (You can also drag a block from one region to another.)
Once you’re satisfied with the placement of the blocks, Save blocks. If you want the display title to be something other than “Zoteroed,” you can set that from the Blocks Administration page as well. To the right of the block listing, click the Configure link, and enter a value under the “Block Title” field. You can also set some visibility options, but you probably don’t need to. Once satisfied with the title, click Save Block and marvel at the shiny new Zotero block that will now appear wherever you set it.
In the future, make any adjustments to the content of the block by editing the view (Administer -> Site Building -> Views), and to edit the block itself, go to the Blocks overview page (Administer -> Site Building -> Blocks).
And there you have it: a “Recently Zoteroed” feed appearing on your Drupal site, with no need for a third party feed processor between you and Zotero.
Hopefully this little tutorial will be helpful to those who have been looking for an excuse to play with Drupal’s Views module. Personally, I like little task-oriented guides for learning new software, so I would have loved finding something like this when I was first getting into Drupal. If you do try following my instructions here, please post a comment and let me know how it goes. Also, if there’s something else you’d like to learn how to do with Drupal, let me know and I might post a similar walkthrough.