Search blocks for nodes. You can even have more than one.
authorJason Skomorowski <jason@indexdata.com>
Mon, 24 Jan 2011 03:51:52 +0000 (04:51 +0100)
committerJason Skomorowski <jason@indexdata.com>
Mon, 24 Jan 2011 03:51:52 +0000 (04:51 +0100)
mkdru-block-search.tpl.php [new file with mode: 0644]
mkdru.module

diff --git a/mkdru-block-search.tpl.php b/mkdru-block-search.tpl.php
new file mode 100644 (file)
index 0000000..d816c93
--- /dev/null
@@ -0,0 +1,4 @@
+<form id="mkdru-block-search-<?php print $nid ?>" target="_blank" onsubmit="document.location.href = '<?php print $path ?>#query=' + $('#mkdru-block-search-<?php print $nid ?> input:text').attr('value'); return false;">
+  <input type="text" width="100%"/></br>
+  <input type="submit" value="Search">
+</form>
index dc4f5b7..13ef18a 100644 (file)
@@ -243,6 +243,10 @@ function mkdru_theme() {
     'mkdru_js' => array(
       'arguments' => array('node' => NULL),
     ),
+    'mkdru_block_search' => array(
+      'template' => 'mkdru-block-search',
+      'arguments' => array('nid' => null, 'path' => NULL),
+    ),
 //     'mkdru_block_facet' => array(
 //       'template' => 'mkdru-block-facet',
 //       'arguments' => array('divId' => NULL),
@@ -289,12 +293,21 @@ function mkdru_view($node, $teaser = FALSE, $page = FALSE) {
 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':
@@ -325,5 +338,10 @@ function mkdru_block($op='list', $delta='sources', $edit=array()) {
           $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;
+    }
   }
 }