Installation and Theming for jPlayer for Drupal 6: An HTML5-based mp3 player

One of my clients' website viewers are moving from desktop to mobile devices. And of course, he is showcasing a lot of music on his website, currently being displayed using a Flash frontend player, which can't be viewed on iOS devices. To fix that, I recommended switching to jPlayer, a HTML5-based player that uses Flash as a fallback for browsers that don't support it yet. This post is intended to provide the missing pieces of information for those of us still, ahem, stuck with a Drupal 6 installation (the jPlayer documentation primarily focuses on Drupal 7).

Installation

Here's a quick overview on how getting jPlayer running on your Drupal 6 installation:
  1. Install Jplayer module for Drupal 6 and enable it like any usual module
  2. Download the jPlayer plugin version 1.2.0 from here or directly here. The most current version (jPlayer 2.0.0) is not compatible with the Drupal 6 jPlayer module. Extract the contents in 'sites/all/libraries/jplayer'
  3. Go to the configuration page of the jPlayer Drupal module (admin/config/media/jplayer) and specify the path for the jPlayer library as configured above ('sites/all/libraries/jplayer')
This should be all that's involved. You should be good to go to use jPlayer in your content types (select it under "Display Fields" for your content types that have MP3 files uploaded) or use it in Views.

Theming

Of course, it would be great if we could use jPlayer for just any node that has an MP3 file attached to it, either in our theme files or anywhere else we want to manually display an MP3 file using jPlayer. I wasn't able to find the theming documentation for it on the module page, so here's a quick code snippet to get you going. For this example, I'm assuming that you have a content type called 'song' setup, every song node has 1 MP3 file associated with it.

$nid = 100;                       // Example node id 100
$node = node_load($nid);          // Loading the full song node
$type_name = 'song';              // Machine-name of the node content type
$field_name = 'field_song_file';  // Machine-name of the CCK field you use to store the MP3 file
$jplayer_data = array(
  '#field_name' => $field_name,
  '#node' => $node,
  '#type_name' => $type_name,
  '#theme' => 'jplayer_formatter_single',
  '#item' => $node->{$field_name}[0],
);
print theme('jplayer_formatter_single', $jplayer_data);

jPlayer

Drupal 7 Push Notifications: How to register a device token using services

I recently published a module on drupal.org that allows site admins to send push notifications to users that have registered their mobile device tokens and got asked how users can register a device token. The Push Notifications module for Drupal 7 can be found here: http://drupal.org/project/push_notifications. Here's a quick tutorial on how to register a token through the services interface.
  1. Navigate to the Services admin interface at admin/structure/services: http://cl.ly/3F1429021N2W2y1s2j15
  2. Add a new services endpoint. For this example, I'm going to create an endpoint called "mobile_data". This will be the base URL for your services, e.g. http://www.yoursite.com/mobile_data. See http://cl.ly/0j3o0B102j1A1a46183C
  3. You should see your new endpoint listed at admin/structure/services: http://cl.ly/0U0f0p470S1e2J1o0A29. Click on "Edit Resources" for that endpoint
  4. On the "Resource" page for that endpoint, you will see a list of all resources. Make sure "push_notifications" and "create" underneath it is enabled: http://cl.ly/2m0C0Y393y0P2f3L3016
  5. Make sure to enable all parsing types you want, e.g. if you're sending url-encoded data, make sure it's enabled: http://cl.ly/1C3K3S3y372o140x1K1c
These are all the steps you need to take to enable your services endpoint. You can then register your device token at http://www.yoursite.com/mobile_data/push_notifications. You should use a POST on that URL and pass two arguments:
  • Token: The device token (argument name: 'token')
  • Device Type: The type of the device (argument name: 'type', options are either 'ios' for iOS devices or 'android' for Android devices
A very helpful tool is the Cocoa REST Client.

Picking the best theme for Drupal 7

Just like everyone else these days, I am jumping on the Drupal 7 bandwagon for my newer projects. And every time, I come across the question which theme to use. By default, I gravitate towards Zen. I know it inside out, it is still the most-used theme across all Drupal sites and it just seems like the right way to go. I'm not a big fan of splitting up my css into tens of stylesheets, but I can go with the flow.

Then there is Fusion, which is "a simplified 960px" grid theme and #2 on Drupal.org. As a developer, I often come across these red flags that should be slightly orange ones at best, but I just can't stop including them into my decision making process. With Fusion, that would be the fact that it is a theme by "Top Notch Themes". Nothing wrong with that company, but it's just that: there's a company behind it that sells most of their other themes. Other than that, it seems to be a perfectly fine theme.

And then there is the new kid on the block: Omega. With a cool name like that, how could you say no (even cooler: the core and starterkit themes are called Alpha and Omega => geek points for that!). Something that I need for my projects is to have most of the configuration to live in the code, not the database, for a lot of reasons other than "versionability". And from some developer friends, I've heard that Omega's configuration lives mostly in the database. That being said: the usage statistics for Drupal 7 are crazy good: http://drupal.org/project/usage/omega.

The theme package with the fanciest HTML 5 logo is AdaptiveTheme and its numerous sub-themes and sub-themes thereof.

Enough said, let's get to the trial & switch-to-another-theme part :)

Just like everyone else these days, I am jumping on the Drupal 7 bandwagon for my newer projects. And every time, I come across the question which theme to use. By default, I gravitate towards Zen (http://drupal.org/project/zen). I know it inside out, it is still the most-used theme across all Drupal sites and it just seems like the right way to go. I'm not a big fan of splitting up my css into tens of stylesheets, but I can go with the flow.
 
Then there is Fusion (http://drupal.org/project/fusion), which is "a simplified 960px" grid theme and #2 on Drupal.org. As a developer, I often come across these red flags that should be slightly orange ones at best, but I just can't stop including them into my decision making process. With Fusion, that would be the fact that it is a theme by "Top Notch Themes". Nothing wrong with that company, but it's just that: there's a company behind it that sells most of their other themes. Other than that, it seems to be a perfectly fine theme.
 
And then there is the new kid on the block: Omega (http://drupal.org/project/omega). With a cool name like that, how could you say no (even cooler: the core and starterkit themes are called Alpha and Omega => geek points for that!). Something that I need for my projects is to have most of the configuration to live in the code, not the database, for a lot of reasons other than "versionability". And from some developer friends, I've heard that Omega's configuration lives mostly in the database. That being said: the usage statistics for Drupal 7 are crazy good: http://drupal.org/project/usage/omega.
 
The theme package with the fanciest HTML 5 logo is AdaptiveTheme (http://drupal.org/project/adaptivetheme) and its numerous sub-themes and sub-themes thereof.
 
Enough said, let's get to the trial & switch-to-another-theme part
Picking the best theme for Drupal 7

Live Blogging from DrupalCon Chicago: JavaScript in Drupal 7

Presenters: Kat Bailey

Drush Make Demo File: katbailey.net/resources/d7js

New Ways to add JavaScript in D7:

  1. Add it in the .info (within a module, not just the theme)
  2. drupal_add_js: Function changed a bit since D6, allows additional of external JavaScript
  3. Add it in a Render API: Using the 'attached' property

Altering JavaScript in D7:

hook_js_alter allows coders to change any JavaScript file

JavaScript Libraries

  • hook_library: Defines your JavaScript library
  • hook_library_alter: Alter an existing library

Live Blogging from DrupalCon Chicago: Aphorisms of API Design

Presenter: Larry Garfield

  • A good example: noad_load_multiple: Wrapper by node_load in Drupal 7: It doesn't make a difference if you're loading 1 nore or 100 node
  • A not so good example: Search API. Only allows to search for one entity at one (i.e. the module doesn't allow the user to search for users and nodes)
  • Good APIs are picky: Instead of returning nothing / NULL, good APIs return exact error message (think of the "Invalid parameters supplied on line 2933 somewhere in forms.include"
  • In you rown module: don't use undocumented APIs and don't hardcode code that shouldn't be
  • A UI is not an API
  • A website is also not an API: An API does not need a website
  • 3 implementations should be required: 1. Simpletest. 2. Drush. 3. Webform

Live Blogging from DrupalCon Chicago: Media in Drupal 7

Presenter: Jacob Singh

  • Drupal 7 offers the new Media module, which replaces all the different media modules from before
  • Media attempts to be a "file browser to the Internet". Modules can plugin to the Media module (e.g. YouTube, Flickr etc.)
  • Main advantage of Media is that the interface and API is consistent
  • Media has security advantages that allows anyone to embed images and video that circumvents the issues of malicious tags in media files
  • The Media (module) attempts to be the default file-management tool in Drupal 8

DrupalCon Chicago

I'm at my first DrupalCon in Chicago. Yeah. Compared to the Drupal Camp in New York, this seems HUGE. If I actually used Twitter, I should have poster this there. But hey.
DrupalCon Chicago

New Drupal Module: Privatemsg Bulkmail

One of my favorite modules for Drupal is the Privatemsg module. It's basically the Drupal version of Gmail, including a huge feature set for (almost) any need. For one of my clients, I needed to create a feature set that allows him to send internal notifications. Although the newest version of the Privatemsg module comes with the feature to send messages to specific user groups (in Drupal talk: roles), that feature didn't quite fit the required needs, so I decided to write a contrib module with a larger feature-set: Privatemsg Bulkmail.

The Privatemsg Bulkmail module is intended for site administrators who want to send out an identical private message to a large user base (100.000 users and more). An example use case would be an internal notification to all registered users through a private message.

Here's the description of the feature set:

  • Send out private messages from a specific user (instead of the current user)
  • Define a dedicated bulk message user and prevent that user from logging in (to prevent performance issues)
  • Prevent users from responding to a bulk mail message
  • Include AND exclude recipient group of a bulk mail. Example: Send out a bulk mail to all authenticated users that are not site admins
  • Restrict the recipient group to users who logged in or signed up after a certain date
  • Send an individual test message to a specified user before sending out the bulk mail

If you have a use case for this module, try out Privatemsg Bulkmail and leave some feedback on the issue page.

New Drupal 7 Book: Drupal 7 Module Development

January 7th 2011 was a happy day for all Drupal fans: Drupal 7 got officially released. The two Drupal books that I used to get over the steep learning curve of Drupal 6 module development, Drupal 6 Module Development by Packt Publishing and Pro Drupal Development by Apress, got released for Drupal 7.

While the later is the definite development reference for Drupal, the former was written in a more approchable way. The Drupal 6 version of the book included lots of real-life module examples that made becoming acquainted with Drupal's API function a fun way to learning module development for Drupal. I can't wait to work myself through the updated version, "Drupal 7 Module Development", and will post a detailed review of the book thereafter.

Book Cover

New Drupal Module: Views Search

A feature request for one of my recent projects was an "Advanced Search" functionality, similar to the ones that is commonly found in social networking and personal sites. Rather than creating a completely custom search form using Drupal's Forms API, I decided to create a module called "Views Search" which uses the Views module and allows anyone to create advanced searches for anything Views can process without custom coding.

Views' exposed filter work very similar to the search functionality, however exposed filters in the Views module work like true filters, where a list of nodes is limited down to the intended results using a combination of several filters. In contrast to this approach, a more traditional search form allows users to define all criteria first (before seeing any results) and then click on a "Search" button to see the results. This module allows site administrators to easily use the behavior of a traditional search for selected views.

In addition, the Views Search module allows Drupal site members to save their searches for future usage.

Here's an overview of the feature set:

  • Separates the search form and results: selected views show a search form without showing the results on the first page and the search results without showing the search form/filters on the following pages
  • Allows users to start over with a search (using a button on search results page)
  • Allows users to modify the search criteria (using a button on the search results page that expands search criteria using jQuery)
  • Allows users to save a set of search criteria for later usage
  • Allows users to modify/overwrite the name and search criteria for a saved search
  • Provides a default view that allows the current user to manage saved searches
  • Provides a block showing a drop-down with saved searches for the current user
  • Enables site administrators to select views that should act like "search views"
  • Enables site administrators to limit the number of saved searches for certain user roles & set saved search limits per rule
  • Enables site administrators to batch-delete all saved searches for a specific view

You can download the module from the Views Search Module page on Drupal.org. I'm looking forward to any feedback.

Comparison of Views Exposed Filter and Views Search