function do_search($words, $type = 'AND', $non_format = FALSE, $base = '', $options = array()) { $def_options = array('db' => TRUE, 'field' => 'name,text', 'limit' => 0, 'offset' => 0, 'userid' => 0, 'spZen' => FALSE, 'context' => '', 'resultMax' => 0, 'msg_more_search' => ''); $options = array_merge($def_options, $options); if ($this->cont['LANG'] === 'ja' && function_exists("mb_convert_kana") && $options['spZen']) { $words = mb_convert_kana($words, 's'); } if (!$options['db']) { return parent::do_search($words, $type, $non_format, $base); } $keywords = preg_split('/\\s+/', $words, -1, PREG_SPLIT_NO_EMPTY); $fields = explode(',', $options['field']); $andor = $type === 'AND' ? 'AND' : 'OR'; $where_readable = $this->get_readable_where('p.'); $where = "p.editedtime != 0"; if ($base) { $where .= " AND p.name LIKE '" . addslashes($base) . "%'"; } if ($where_readable) { $where = "{$where} AND ({$where_readable})"; } $sel_desc = $options['context'] === 'db' ? ', t.plain' : ''; $sql = 'SELECT p.name, p.editedtime, p.title' . $sel_desc . ' FROM ' . $this->xpwiki->db->prefix($this->root->mydirname . "_pginfo") . " p INNER JOIN " . $this->xpwiki->db->prefix($this->root->mydirname . "_plain") . " t ON t.pgid=p.pgid WHERE ({$where}) "; if ($options['userid'] != 0) { $sql .= "AND (p.uid=" . $options['userid'] . ") "; } if (is_array($keywords) && $keywords) { // ±Ñ¿ô»ú¤ÏȾ³Ñ,¥«¥¿¥«¥Ê¤ÏÁ´³Ñ,¤Ò¤é¤¬¤Ê¤Ï¥«¥¿¥«¥Ê¤Ë $sql .= "AND ("; $i = 0; foreach ($keywords as $keyword) { if ($i++ !== 0) { $sql .= " {$andor} "; } if ($this->cont['LANG'] === 'ja' && function_exists("mb_convert_kana")) { // ±Ñ¿ô»ú¤ÏȾ³Ñ,¥«¥¿¥«¥Ê¤ÏÁ´³Ñ,¤Ò¤é¤¬¤Ê¤Ï¥«¥¿¥«¥Ê¤Ë $word = addslashes(mb_convert_kana($keyword, 'aKCV')); } else { $word = addslashes($keyword); } if (in_array('name', $fields) && in_array('text', $fields)) { $sql .= "(p.name_ci LIKE '%{$word}%' OR t.plain LIKE '%{$word}%')"; } else { if (in_array('name', $fields)) { $sql .= "p.name_ci LIKE '%{$word}%'"; } else { if (in_array('text', $fields)) { $sql .= "t.plain LIKE '%{$word}%'"; } } } } $sql .= ") "; } $result = $this->xpwiki->db->query($sql, $options['limit'], $options['offset']); $ret = array(); if (!$keywords) { $keywords = array(); } $sword = rawurlencode(join(' ', $keywords)); $pages = array(); if (in_array('source', $fields)) { foreach ($this->do_source_search($word, $type, true, $base) as $page) { $pages[$page] = ''; } } while ($myrow = $this->xpwiki->db->fetchArray($result)) { $pages[$myrow['name']] = array($myrow['editedtime'], $myrow['title']); if ($options['context'] === 'db') { $pages[$myrow['name']][2] = $myrow['plain']; } } if ($non_format) { return array_keys($pages); } $r_word = rawurlencode($words); $s_word = preg_replace('/&#(\\d+;)/', '&#$1', htmlspecialchars($words)); if (empty($pages)) { return str_replace('$1', $s_word, $this->root->_msg_notfoundresult); } ksort($pages); $count = count($this->get_existpages()); $resCount = count($pages); if ($options['resultMax'] && $resCount > $options['resultMax']) { $pages = array_splice($pages, 0, $options['resultMax']); } $retval = '<ul class="list1">' . "\n"; foreach ($pages as $page => $data) { if (empty($data[0])) { $data[0] = $this->get_filetime($page); } if (empty($data[1])) { $data[1] = $this->get_heading($page); } $s_page = htmlspecialchars($page); $passage = $this->root->show_passage ? ' ' . $this->get_passage($data[0]) : ''; $retval .= ' <li><a href="' . $this->get_page_uri($page, TRUE) . ($this->root->static_url ? '?' : '&') . 'word=' . $r_word . '">' . $s_page . '</a><small>' . $passage . '</small> [ ' . htmlspecialchars($data[1]) . ' ]' . "\n"; if ($options['context'] === 'db') { $retval .= '<div class="context">' . HypCommonFunc::make_context($data[2], $keywords) . '</div>'; } else { if ($options['context'] === 'conv') { $retval .= $this->get_page_context($page, $keywords); } } $retval .= '</li>'; } $retval .= '</ul>' . "\n"; $retval .= str_replace('$1', $s_word, str_replace('$2', $resCount, str_replace('$3', $count, $andor === 'AND' ? $this->root->_msg_andresult : $this->root->_msg_orresult))); if ($options['msg_more_search'] && $options['resultMax'] && $resCount > $options['resultMax']) { $retval .= $options['msg_more_search']; } return $retval; }