get_queried_object_id();
$idstr = 'AND ID != ' . $uid . ' ';
}
if($terms)
{
$term = explode(' ', $terms);
foreach ($term as $key => $t) {
$term[$key] = '+' . $t;
}
$bterms = implode(' ' ,$term);
$sql = "SELECT ID, post_title, post_content,"
. "MATCH (post_name, post_content) "
. "AGAINST ('$terms') AS score "
. "FROM $wpdb->posts WHERE "
. "MATCH (post_name, post_content) "
. "AGAINST ('$bterms' IN BOOLEAN MODE) "
. "AND (post_status IN ( 'publish', 'static' )) ";
if ($show_pass_post=='false') { $sql .= "AND post_password ='' "; }
$sql = $sql . $idstr;
$sql .= "ORDER BY score DESC LIMIT $limit";
$res = $wpdb->get_results($sql);
}
return $res;
}
function mk_landingsites_related($prefix, $referer, $terms, $limit) {
global $wpdb, $wp_query;
global $mk_landingsites_config;
$results = mk_landingsites_internal_search($terms, $limit);
if (count($results) != 0) {
$output = '';
echo $prefix;
echo "
";
foreach ($results as $result) {
$title = stripslashes(apply_filters('the_title', $result->post_title));
$permalink = get_permalink($result->ID);
$post_content = strip_tags($result->post_content);
$post_content = stripslashes($post_content);
$link = '' . $title . '';
$t = "- " . $mk_landingsites_config['link'] . "
";
$output .= str_replace('$link', $link, $t);
}
echo $output;
echo "
";
if ((count($results) == $limit) &&
($mk_landingsites_config['internalsearch'] == 1)) {
echo '' . $mk_landingsites_config['searchprefix'] . ' ';
echo '';
echo $mk_landingsites_config['searchlink'] .'
';
}
}
}
function mk_landingsites_install() {
global $wpdb;
global $table_prefix;
$sql = 'ALTER TABLE `'.$table_prefix.'posts` ADD FULLTEXT `post_related` ( `post_name` ,'
. ' `post_content` )';
$wpdb->hide_errors();
$sql_result = $wpdb->query($sql);
$wpdb->show_errors();
}
register_activation_hook(__FILE__, 'mk_landingsites_install');
function mk_landingsites_get_referer() {
global $mk_landingsites_referer;
return $mk_landingsites_referer;
}
function mk_landingsites_startloop() {
global $mk_landingsites_delimiter;
global $mk_landingsites_config;
$terms = mk_landingsites_get_terms();
if ($terms != '') {
$prefix = "" . $mk_landingsites_config[prefix] . "
";
$prefix=str_replace('$ref', mk_landingsites_get_referer(), $prefix);
$prefix=str_replace('$terms', $terms, $prefix);
mk_landingsites_related($prefix, mk_landingsites_get_referer(), $terms, $mk_landingsites_config['count']);
}
}
function mk_landingsites_header() {
header('Vary: Referer', FALSE);
}
function mk_landingsites_search_check_status($s) {
global $mk_landingsites_config;
if ($mk_landingsites_config[$s] == 1)
return 'checked=""';
return '';
}
function mk_landingsites_options_page() {
global $mk_landingsites_config;
$message="";
if (!empty($_POST['info_update']))
{
$mk_landingsites_config['prefix']=(string) $_POST['prefix'];
$mk_landingsites_config['link']=(string) $_POST['link'];
$mk_landingsites_config['searchprefix']=(string) $_POST['searchprefix'];
$mk_landingsites_config['searchplink']=(string) $_POST['searchplink'];
$mk_landingsites_config['count']=(int) $_POST['count'];
$mk_landingsites_config['internalsearch'] = 0;
if (isset($_POST['internalsearch']))
$mk_landingsites_config['internalsearch'] = 1;
$mk_landingsites_config['placeatbot'] = 0;
if (isset($_POST['placeatbot']))
$mk_landingsites_config['placeatbot'] = 1;
$mk_landingsites_config['placeattop'] = 0;
if (isset($_POST['placeattop']))
$mk_landingsites_config['placeattop'] = 1;
if(update_option("mk_landingsites_options",$mk_landingsites_config)) $message.=__('Configuration updated', 'mk_landingsites');
else $message.=__('Error', 'mk_landingsites');
//Print out the message to the user, if any
if($message!="") {
?>
$terms. The following posts might also be of interest to you:', 'mk_landingsites');
$mk_landingsites_config['link'] = '$link';
$mk_landingsites_config['searchprefix'] = __('More possible matches are available with the', 'mk_landingsites');
$mk_landingsites_config['searchlink'] = __('internal search', 'mk_landingsites');
$mk_landingsites_config['count'] = 5;
$mk_landingsites_config['internalsearch'] = 0;
$mk_landingsites_config['placeatbot'] = 0;
$mk_landingsites_config['placeattop'] = 1;
$mk_options=get_option("mk_landingsites_options");
if($mk_options) {
foreach($mk_options AS $k=>$v) {
$mk_landingsites_config[$k]=$v;
}
}
else update_option("mk_landingsites_options",$mk_landingsites_config);
add_action('admin_menu', 'mk_landingsites_admin');
if (isset($_SERVER['HTTP_REFERER']) && ($_SERVER['HTTP_REFERER'] != '')) {
$referer_info = parse_url($_SERVER['HTTP_REFERER']);
$mk_landingsites_referer = $referer_info['host'];
// Remove www. is it exists
if(substr($mk_landingsites_referer, 0, 4) == 'www.')
$mk_landingsites_referer = substr($mk_landingsites_referer, 4);
$mk_landingsites_delimiter = mk_landingsites_get_delim($referer);
if ($mk_landingsites_delimiter) {
if ($mk_landingsites_config['placeattop'] == 1)
add_action('loop_start', 'mk_landingsites_startloop');
if ($mk_landingsites_config['placeatbot'] == 1)
add_action('loop_end', 'mk_landingsites_startloop');
add_action('init', 'mk_landingsites_header');
}
}
?>