OSDN Git Service

BugTrack/791: Fix typo 0,91 => 0.91
[pukiwiki/pukiwiki.git] / plugin / search.inc.php
1 <?php
2 // PukiWiki - Yet another WikiWikiWeb clone.
3 // $Id: search.inc.php,v 1.6 2005/01/16 14:10:46 henoheno Exp $
4 //
5 // Search plugin
6
7 // Allow search via GET method 'index.php?plugin=search&word=keyword'
8 // NOTE: Also allows DoS to your site more easily by SPAMbot or worm or ...
9 define('PLUGIN_SEARCH_DISABLE_GET_ACCESS', 1); // 1, 0
10
11 define('PLUGIN_SEARCH_MAX_LENGTH', 80);
12
13 // Show a search box on a page
14 function plugin_search_convert()
15 {
16         static $done;
17
18         if (func_get_args()) {
19                 return '#search(): No argument<br/>' . "\n";
20         } else if (isset($done)) {
21                 return '#search(): You already view a search box<br/>' . "\n";
22         } else {
23                 $done = TRUE;
24                 return plugin_search_search_form();
25         }
26 }
27
28 function plugin_search_action()
29 {
30         global $post, $vars, $_title_result, $_title_search, $_msg_searching;
31
32         if (PLUGIN_SEARCH_DISABLE_GET_ACCESS) {
33                 $s_word = isset($post['word']) ? htmlspecialchars($post['word']) : '';
34         } else {
35                 $s_word = isset($vars['word']) ? htmlspecialchars($vars['word']) : '';
36         }
37         if (strlen($s_word) > PLUGIN_SEARCH_MAX_LENGTH) {
38                 unset($vars['word']); // Stop using $_msg_word at lib/html.php
39                 die_message('Search words too long');
40         }
41
42         $type = isset($vars['type']) ? $vars['type'] : '';
43
44         if ($s_word != '') {
45                 // Search
46                 $msg  = str_replace('$1', $s_word, $_title_result);
47                 $body = do_search($vars['word'], $type);
48         } else {
49                 // Init
50                 unset($vars['word']); // Stop using $_msg_word at lib/html.php
51                 $msg  = $_title_search;
52                 $body = '<br />' . "\n" . $_msg_searching . "\n";
53         }
54
55         // Show search form
56         $body .= plugin_search_search_form($s_word, $type);
57
58         return array('msg'=>$msg, 'body'=>$body);
59 }
60
61 function plugin_search_search_form($s_word = '', $type = '')
62 {
63         global $script, $_btn_and, $_btn_or, $_btn_search;
64
65         $and_check = $or_check = '';
66         if ($type == 'OR') {
67                 $or_check  = ' checked="checked"';
68         } else {
69                 $and_check = ' checked="checked"';
70         }
71
72         return <<<EOD
73 <form action="$script?cmd=search" method="post">
74  <div>
75   <input type="text"  name="word" value="$s_word" size="20" />
76   <input type="radio" name="type" value="AND" $and_check />$_btn_and
77   <input type="radio" name="type" value="OR"  $or_check  />$_btn_or
78   &nbsp;<input type="submit" value="$_btn_search" />
79  </div>
80 </form>
81 EOD;
82 }
83 ?>