OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / wiki_main / include / plugin / search.inc.php
1 <?php
2 /**
3  * searchプラグイン
4  *
5  * PHP versions 5
6  *
7  * LICENSE: This source file is licensed under the terms of the GNU General Public License.
8  *
9  * @package    Magic3 Framework
10  * @author     平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
11  * @copyright  Copyright 2006-2009 Magic3 Project.
12  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
13  * @version    SVN: $Id: search.inc.php 1601 2009-03-21 05:51:06Z fishbone $
14  * @link       http://www.magic3.org
15  */
16
17 // Allow search via GET method 'index.php?plugin=search&word=keyword'
18 // NOTE: Also allows DoS to your site more easily by SPAMbot or worm or ...
19 define('PLUGIN_SEARCH_DISABLE_GET_ACCESS', 1); // 1, 0
20
21 define('PLUGIN_SEARCH_MAX_LENGTH', 80);
22 define('PLUGIN_SEARCH_MAX_BASE',   16); // #search(1,2,3,...,15,16)
23
24 // Show a search box on a page
25 function plugin_search_convert()
26 {
27         static $done;
28
29         if (isset($done)) {
30                 return '#search(): You already view a search box<br />' . "\n";
31         } else {
32                 $done = TRUE;
33                 $args = func_get_args();
34                 return plugin_search_search_form('', '', $args);
35         }
36 }
37
38 function plugin_search_action()
39 {
40         //global $post, $vars, $_title_result, $_title_search, $_msg_searching;
41         global $_title_result, $_title_search, $_msg_searching;
42
43         if (PLUGIN_SEARCH_DISABLE_GET_ACCESS) {
44                 //$s_word = isset($post['word']) ? htmlspecialchars($post['word']) : '';
45                 $word = WikiParam::getPostVar('word');
46         } else {
47                 //$s_word = isset($vars['word']) ? htmlspecialchars($vars['word']) : '';
48                 $word = WikiParam::getVar('word');
49         }
50         $s_word = htmlspecialchars($word);
51         
52         if (strlen($s_word) > PLUGIN_SEARCH_MAX_LENGTH) {
53                 //unset($vars['word']); // Stop using $_msg_word at lib/html.php
54                 die_message('Search words too long');
55         }
56
57         /*$type = isset($vars['type']) ? $vars['type'] : '';
58         $base = isset($vars['base']) ? $vars['base'] : '';*/
59         $type = WikiParam::getVar('type');
60         $base = WikiParam::getVar('base');
61
62         if ($s_word != '') {
63                 // Search
64                 $msg  = str_replace('$1', $s_word, $_title_result);
65                 //$body = do_search($vars['word'], $type, FALSE, $base);
66                 $body = do_search($word, $type, false, $base);
67         } else {
68                 // Init
69                 //unset($vars['word']); // Stop using $_msg_word at lib/html.php
70                 $msg  = $_title_search;
71                 $body = '<br />' . "\n" . $_msg_searching . "\n";
72         }
73
74         // Show search form
75         $bases = ($base == '') ? array() : array($base);
76         $body .= plugin_search_search_form($s_word, $type, $bases);
77
78         return array('msg'=>$msg, 'body'=>$body);
79 }
80
81 function plugin_search_search_form($s_word = '', $type = '', $bases = array())
82 {
83         global $script, $_btn_and, $_btn_or, $_btn_search;
84         global $_search_pages, $_search_all;
85
86         $and_check = $or_check = '';
87         if ($type == 'OR') {
88                 $or_check  = ' checked="checked"';
89         } else {
90                 $and_check = ' checked="checked"';
91         }
92
93         $base_option = '';
94         if (!empty($bases)) {
95                 $base_msg = '';
96                 $_num = 0;
97                 $check = ' checked="checked"';
98                 foreach($bases as $base) {
99                         ++$_num;
100                         if (PLUGIN_SEARCH_MAX_BASE < $_num) break;
101                         $label_id = '_p_search_base_id_' . $_num;
102                         $s_base   = htmlspecialchars($base);
103                         $base_str = '<strong>' . $s_base . '</strong>';
104                         $base_label = str_replace('$1', $base_str, $_search_pages);
105                         $base_msg  .=<<<EOD
106  <div>
107   <input type="radio" name="base" id="$label_id" value="$s_base" $check />
108   <label for="$label_id">$base_label</label>
109  </div>
110 EOD;
111                         $check = '';
112                 }
113                 $base_msg .=<<<EOD
114   <input type="radio" name="base" id="_p_search_base_id_all" value="" />
115   <label for="_p_search_base_id_all">$_search_all</label>
116 EOD;
117                 $base_option = '<div class="small">' . $base_msg . '</div>';
118         }
119         $postScript = $script . WikiParam::convQuery("?cmd=search");
120         $retValue = <<<EOD
121 <form action="$postScript" method="post" class="form">
122  <div>
123   <input type="text"  name="word" value="$s_word" size="20" />
124   <input type="radio" name="type" id="_p_search_AND" value="AND" $and_check />
125   <label for="_p_search_AND">$_btn_and</label>
126   <input type="radio" name="type" id="_p_search_OR"  value="OR"  $or_check  />
127   <label for="_p_search_OR">$_btn_or</label>
128   &nbsp;<input type="submit" class="button" value="$_btn_search" />
129  </div>
130 $base_option
131 </form>
132 EOD;
133         return $retValue;
134 }
135 ?>