/** * Saves keyword and referer info to db * * */ function save_keyword($keyword, $referer) { global $wpdb; if (!$keyword) { return false; } $date = date('YmdHi'); $referer_info = parse_url($referer); $mySearch =& new WP_Query("s={$keyword} & showposts=-1"); $NumResults = $mySearch->post_count; if (is_user_logged_in()) { global $current_user; get_currentuserinfo(); $user = $current_user->ID; } else { $user = '******'; } $search_count = search_count($keyword, $user); $repeat_coount = repeat_count($keyword, $user); if ($repeat_coount != null) { if (is_numeric($user)) { $row = $wpdb->get_var("SELECT id FROM " . SS_TABLE . " WHERE keywords = '" . mysql_escape_string($keyword) . "' and user='******'"); } else { $row = $wpdb->get_var("SELECT id FROM " . SS_TABLE . " WHERE keywords = '" . mysql_escape_string($keyword) . "'"); } $wpdb->update(SS_TABLE, array('query_date' => $date, 'repeat_count' => ++$repeat_coount, 'search_count' => $NumResults), array('id' => $row), array('%s', '%s', '%s', '%s', '%s', '%d', '%d')); } else { $wpdb->insert(SS_TABLE, array('keywords' => $keyword, 'query_date' => $date, 'source' => $referer_info['host'], 'user' => $user, 'agent' => $_SERVER['HTTP_USER_AGENT'], 'repeat_count' => 0, 'search_count' => $NumResults), array('%s', '%s', '%s', '%s', '%s', '%d', '%d')); } }
function search_show() { $args = func_get_args(); $cate = $args[2]; $time = get_post('time'); $page = get_post('page'); $key = trim(get_post('search')); $admin = get_post('admin'); if ($key and $key != "all") { include_once 'login.inc.php'; if (user_is_authenticated()) { search_history_add("", "", $cate); } } $data = get_search_result($key, 10, $cate, $time, $page); if (!$page and !$time and !$admin) { search_count("", "", $cate); echo ','; include_once 'follow.inc.php'; if ($key and $key != "all") { following_exist("", "", $key); } else { echo '0'; } echo ','; } $content = theme('result', $data, $key, $admin); theme('search', $key, $content); }