-function mkdru_block($op='list', $delta='sources', $edit=array()) {
- switch ($op) {
- case 'list':
- // facet blocks
- // NB: block caching is redundant for static content
- $blocks['mkdru_sources']['info'] = t('mkdru - source facets');
- $blocks['mkdru_sources']['cache'] = BLOCK_NO_CACHE;
- $blocks['mkdru_subjects']['info'] = t('mkdru - subject facets');
- $blocks['mkdru_subjects']['cache'] = BLOCK_NO_CACHE;
- $blocks['mkdru_authors']['info'] = t('mkdru - author facets');
- $blocks['mkdru_authors']['cache'] = BLOCK_NO_CACHE;
- // search blocks
- $result = db_query("SELECT title, nid FROM {node} WHERE type = 'mkdru';");
- while ($node = db_fetch_object($result)) {
- $blocks['mkdru_search_' . $node->nid]['info'] =
- t('mkdru - search box for "' . $node->title . '"');
- $blocks['mkdru_sources']['cache'] = BLOCK_NO_CACHE;
- };
- return $blocks;
-
- case 'view':
- switch ($delta) {
- // TODO: make the facet themable, I have no clue why this won't work
-// case 'mkdru_sources':
-// $block['subject'] = t('Source');
-// $block['content'] = theme('mkdru_block_facet', 'mkdru-sources');
-// return $block;
-// case 'mkdru_subjects':
-// $block['subject'] = t('Subject');
-// $block['content'] = theme('mkdru_block_facet', 'mkdru-subjects');
-// return $block;
-// case 'mkdru_authors':
-// $block['subject'] = t('Author');
-// $block['content'] = theme('mkdru_block_facet', 'mkdru-authors');
-// return $block;
- case 'mkdru_sources':
- $block['subject'] = t('Source');
- $block['content'] = '<div class="mkdru-facet mkdru-facet-sources"> </div>';
- return $block;
- case 'mkdru_subjects':
- $block['subject'] = t('Subject');
- $block['content'] = '<div class="mkdru-facet mkdru-facet-subjects"> </div>';
- return $block;
- case 'mkdru_authors':
- $block['subject'] = t('Author');
- $block['content'] = '<div class="mkdru-facet mkdru-facet-authors"> </div>';
- return $block;
- }
- if (substr($delta, 0, 13) == 'mkdru_search_') {
- $nid = substr($delta, 13);
- $block['content'] = theme('mkdru_block_search', $nid, '/node/' . $nid);
- return $block;
- }
+function mkdru_block_info() {
+ // facet blocks
+ $facets = variable_get('mkdru_facets');
+ foreach ($facets as $facet) {
+ // NB: block caching is redundant for static content
+ $blocks['mkdru_facet_' . $facet]['info'] = "mkdru - $facet " . t('facet');
+ $blocks['mkdru_facet_' . $facet]['cache'] = DRUPAL_NO_CACHE;
+ }
+
+ // search blocks
+ $result = db_query("SELECT title, nid FROM {node} WHERE type = 'mkdru';");
+ foreach($result as $node) {
+ $blocks['mkdru_search_' . $node->nid]['info'] =
+ t('mkdru - search box for "' . $node->title . '"');
+ $blocks['mkdru_sources']['cache'] = DRUPAL_NO_CACHE;
+ };
+
+ return $blocks;
+}
+
+/**
+* Implements hook_block_view()
+*/
+function mkdru_block_view($delta) {
+ if (substr($delta, 0, 12) == 'mkdru_facet_') {
+ $facet = substr($delta, 12);
+ $block['subject'] = t(ucwords($facet));
+ $block['content'] = theme('mkdru_block_facet',
+ array('class' => 'mkdru-facet-' . $facet));
+ return $block;
+ }
+ elseif (substr($delta, 0, 13) == 'mkdru_search_') {
+ $nid = substr($delta, 13);
+ $block['content'] = theme('mkdru_block_search',
+ array('nid' => $nid, 'path' => '/node/' . $nid));
+ return $block;