OSDN Git Service

Added #search (convert) plugin, shows a search dialog.
authorhenoheno <henoheno>
Sun, 16 Jan 2005 14:10:46 +0000 (23:10 +0900)
committerhenoheno <henoheno>
Sun, 16 Jan 2005 14:10:46 +0000 (23:10 +0900)
(Started a patch by teanan)

plugin/search.inc.php

index 72a82ba..5d1afd0 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: search.inc.php,v 1.5 2005/01/09 03:13:41 henoheno Exp $
+// $Id: search.inc.php,v 1.6 2005/01/16 14:10:46 henoheno Exp $
 //
 // Search plugin
 
@@ -10,18 +10,24 @@ define('PLUGIN_SEARCH_DISABLE_GET_ACCESS', 1); // 1, 0
 
 define('PLUGIN_SEARCH_MAX_LENGTH', 80);
 
-function plugin_search_action()
+// Show a search box on a page
+function plugin_search_convert()
 {
-       global $script, $post, $vars, $_title_result, $_title_search;
-       global $_msg_searching, $_btn_and, $_btn_or, $_btn_search;
+       static $done;
 
-       $type   = isset($vars['type']) ? $vars['type'] : '';
-       $and_check = $or_check = '';
-       if ($type == 'OR') {
-               $or_check  = ' checked="checked"';
+       if (func_get_args()) {
+               return '#search(): No argument<br/>' . "\n";
+       } else if (isset($done)) {
+               return '#search(): You already view a search box<br/>' . "\n";
        } else {
-               $and_check = ' checked="checked"';
+               $done = TRUE;
+               return plugin_search_search_form();
        }
+}
+
+function plugin_search_action()
+{
+       global $post, $vars, $_title_result, $_title_search, $_msg_searching;
 
        if (PLUGIN_SEARCH_DISABLE_GET_ACCESS) {
                $s_word = isset($post['word']) ? htmlspecialchars($post['word']) : '';
@@ -32,16 +38,38 @@ function plugin_search_action()
                unset($vars['word']); // Stop using $_msg_word at lib/html.php
                die_message('Search words too long');
        }
-       if ($s_word == '') {
+
+       $type = isset($vars['type']) ? $vars['type'] : '';
+
+       if ($s_word != '') {
+               // Search
+               $msg  = str_replace('$1', $s_word, $_title_result);
+               $body = do_search($vars['word'], $type);
+       } else {
+               // Init
                unset($vars['word']); // Stop using $_msg_word at lib/html.php
                $msg  = $_title_search;
                $body = '<br />' . "\n" . $_msg_searching . "\n";
+       }
+
+       // Show search form
+       $body .= plugin_search_search_form($s_word, $type);
+
+       return array('msg'=>$msg, 'body'=>$body);
+}
+
+function plugin_search_search_form($s_word = '', $type = '')
+{
+       global $script, $_btn_and, $_btn_or, $_btn_search;
+
+       $and_check = $or_check = '';
+       if ($type == 'OR') {
+               $or_check  = ' checked="checked"';
        } else {
-               $msg  = str_replace('$1', $s_word, $_title_result);
-               $body = do_search($vars['word'], $type);
+               $and_check = ' checked="checked"';
        }
 
-       $body .= <<<EOD
+       return <<<EOD
 <form action="$script?cmd=search" method="post">
  <div>
   <input type="text"  name="word" value="$s_word" size="20" />
@@ -51,6 +79,5 @@ function plugin_search_action()
  </div>
 </form>
 EOD;
-
-       return array('msg'=>$msg, 'body'=>$body);
 }
+?>