7 * LICENSE: This source file is licensed under the terms of the GNU General Public License.
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
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
21 define('PLUGIN_SEARCH_MAX_LENGTH', 80);
22 define('PLUGIN_SEARCH_MAX_BASE', 16); // #search(1,2,3,...,15,16)
24 // Show a search box on a page
25 function plugin_search_convert()
30 return '#search(): You already view a search box<br />' . "\n";
33 $args = func_get_args();
34 return plugin_search_search_form('', '', $args);
38 function plugin_search_action()
40 //global $post, $vars, $_title_result, $_title_search, $_msg_searching;
41 global $_title_result, $_title_search, $_msg_searching;
43 if (PLUGIN_SEARCH_DISABLE_GET_ACCESS) {
44 //$s_word = isset($post['word']) ? htmlspecialchars($post['word']) : '';
45 $word = WikiParam::getPostVar('word');
47 //$s_word = isset($vars['word']) ? htmlspecialchars($vars['word']) : '';
48 $word = WikiParam::getVar('word');
50 $s_word = htmlspecialchars($word);
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');
57 /*$type = isset($vars['type']) ? $vars['type'] : '';
58 $base = isset($vars['base']) ? $vars['base'] : '';*/
59 $type = WikiParam::getVar('type');
60 $base = WikiParam::getVar('base');
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);
69 //unset($vars['word']); // Stop using $_msg_word at lib/html.php
70 $msg = $_title_search;
71 $body = '<br />' . "\n" . $_msg_searching . "\n";
75 $bases = ($base == '') ? array() : array($base);
76 $body .= plugin_search_search_form($s_word, $type, $bases);
78 return array('msg'=>$msg, 'body'=>$body);
81 function plugin_search_search_form($s_word = '', $type = '', $bases = array())
83 global $script, $_btn_and, $_btn_or, $_btn_search;
84 global $_search_pages, $_search_all;
86 $and_check = $or_check = '';
88 $or_check = ' checked="checked"';
90 $and_check = ' checked="checked"';
97 $check = ' checked="checked"';
98 foreach($bases as $base) {
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);
107 <input type="radio" name="base" id="$label_id" value="$s_base" $check />
108 <label for="$label_id">$base_label</label>
114 <input type="radio" name="base" id="_p_search_base_id_all" value="" />
115 <label for="_p_search_base_id_all">$_search_all</label>
117 $base_option = '<div class="small">' . $base_msg . '</div>';
119 $postScript = $script . WikiParam::convQuery("?cmd=search");
121 <form action="$postScript" method="post" class="form">
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 <input type="submit" class="button" value="$_btn_search" />