We've been doing a lot of work recently about the Common Look and Feel for the federal government here in Canada. One of the requirements of the CLF has been that documents are created with Dublin Core meta data to allow for it to be more machine readable. This is a great step, and it is nice to be working with an international standard like this. Unfortunately, there didn't seem to be any easy way to produce this meta data with existing modules.
Several people have started developing Dublin Core modules in the Drupal community, but none have finished it. The Meta tags module probably comes the closest as it is designed to produce meta tags for search engine optimization. Unfortunately extending the Meta tag output to allow for a much wider range values isn't presently allowed.
One of the best examples of code provided to allow for Dublin Core that I found was provided on the tech journalist David Fisco's blog. I wanted to have something wrapped into a function in the template.php file so took this and re-wrote it significantly for my needs.
The standard list of available terms within the Dublin Core is a lot larger than what I need for my purposes. I was just looking for a method to provide the basics. abstract, audience, created, creator, date, description, language, license, subject, title would be lots. Some of this can be pulled right from Drupal, I also provided opportunities for using leveraging the Mata tag module and using custom CCK fields as well.
- <?php
- function phptemplate_preprocess_page(&$vars) {
- $current_language = $vars['language']->language;
- $vars['dublin_core'] = simple_dublin_core($current_language, $vars['title'], $type, $format, $vars['node']);
- }
- function simple_dublin_core ($current_language, $title, $type, $format, $node) {
- $creator = 'OpenConcept Consulting Inc.';
- $publisher = 'OpenConcept Consulting Inc.';
- $rights_holder = 'Content Creator';
- // Set license & content
- $license_notice = 'This article is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License.';
- $license_content = 'Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License.';
- // Start producing metadata
- $dc_output .= "\n\n" . (!empty($title)) ? '<meta name="dc.title" content="' . $title . "\" />\n" : '';
- // Pull values from CCK (if defined)
- $cck_subject_field = $node->field_dublin_core_subjects[0]['value'];
- $cck_description_field = (!empty($node->field_dublin_core_description[0]['value'])) ? $node->field_dublin_core_description[0]['value'] : $node->field_dublin_core_abstract[0]['value'];
- $intended_audience = (!empty($node->field_intended_audience[0]['value'])) ? $node->field_intended_audience[0]['value'] : 'general public';
- // Get subject/description through either nodeword module or cck definitions
- $metatags = nodewords_get('node', $node->nid);
- foreach ($metatags as $tagname => $tagcontent) {
- if ($tagname == 'keywords') {
- $dc_output .= (!empty($tagcontent)) ? '<meta name="dc.subject" content="' . $tagcontent . "\" />\n" : '';
- }
- if ($tagname == 'description') {
- $dc_output .= (!empty($tagcontent)) ? '<meta name="dc.description" content="' . $tagcontent . "\" />\n" : '';
- }
- }
- } else {
- // field_dublin_core_subjects: a semi-colon-delimited list of additional subjects you want included in your metadata
- $dc_output .= (!empty($cck_subject_field)) ? '<meta name="dc.subject" content="' . str_replace(',', ';', $cck_subject_field) . "\" />\n" : '';
- $dc_output .= (!empty($cck_description_field)) ? '<meta name="dc.description" content="' . $cck_description_field . "\" />\n" : '';
- $dc_output .= (!empty($node->field_dublin_core_abstract[0]['value'])) ? '<meta name="dcterms.abstract" content="' . htmlspecialchars(ereg_replace("<[^>]*>", "", $node->field_dublin_core_abstract[0]['value'])) . "\" />\n" : '';
- }
- $dc_output .= (!empty($language)) ? '<meta name="dc.language" scheme="ISO639-2/T" content="' . $language . "\" />\n" : '';
- $dc_output .= '<meta name="dc.identifier" scheme="DCTERMS.URI" content="http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . "\" />\n";
- $dc_output .= '<meta name="dc.relation.IsPartOf" scheme="DCTERMS.URI" content="http://' . $_SERVER['HTTP_HOST'] . "\" />\n";
- $dc_output .= '<meta name="dc.creator" content="' . $creator . "\" />\n";
- $dc_output .= (!empty($publisher)) ? '<meta name="dc.publisher" content="' . $publisher . "\" />\n" : '';
- $dc_output .= '<meta name="dcterms.license" content="' . $license_content . "\" />\n";
- $dc_output .= '<meta name="dc.rights" content="' . $license_notice . "\" />\n";
- $dc_output .= '<meta name="dc.rightsHolder" content="' . $rights_holder . "\" />\n";
- // Date of Publication
- // Could be extended to look at node types
- $dc_output .= (!empty($type)) ? '<meta name="dc.type" scheme="W3CDTF" content="' . $type . "\" />\n" : "<meta name=\"dc.type\" content=\"text\" />\n";
- $dc_output .= (!empty($format)) ? '<meta name="dc.format" scheme="W3CDTF" content="' . $format . "\" />\n" : "<meta name=\"dc.format\" content=\"text/html\" />\n";
- $dc_output .= '<meta name="dc.audience" scheme="gcaudience" content="' . htmlspecialchars(ereg_replace("<[^>]*>", "", $intended_audience)) . "\" />\n";
- return $dc_output;
- }
Then this just needs to be placed in the header of the page.tpl.php file:
<?php print $dublin_core; ?>
Now there are problems with meta data as Cory Doctorow points out in his article "Metacrap: Putting the torch to seven straw-men of the meta-utopia", the old phrase garbage in, garbage out still applies.
After writing this code I ran into this article for bringing Dublin Core into CCK's Computed Fields and do think there is some more space for collaboration here.
In talking with Matthew Smith about Dublin Core, it became clear that it would also be very logical to pull the description from the teaser and the subject from the taxonomy. Simply exposing the taxonomies in a consistent way would have so many usability advantages.

