$display_percentage*100) die(); # check the selected recommender type if($recommender_type == 'cb') { # content based recommendations # get home path to build url with /home/path/somewhere/else/?p=ID $baseurl = parse_url(get_option('home')); $homepath = $baseurl['path']; # get the most similar posts from the database $link = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if($link) { if(@mysql_select_db(DB_NAME, $link)) { $query = @sprintf("SELECT post_title, post_content FROM %sposts WHERE ID=%d", $table_prefix, $_GET['id']); $result = @mysql_query($query, $link); if($result) { $row = @mysql_fetch_assoc($result); if($row) $searchtext = @strip_tags(@mysql_escape_string($row['post_title'] . " ". $row['post_content'])); } if(!$searchtext) return; $query = @sprintf(" SELECT ID, post_title, MATCH (post_title, post_content) AGAINST ('%s') AS n FROM %sposts WHERE post_status='publish' AND post_type like '%s' AND MATCH (post_title, post_content) AGAINST ('%s') AND ID != %d ORDER BY n DESC LIMIT %d", $searchtext, $table_prefix, $display_position=='both'?'%':@substr($display_position, 0, 4), $searchtext, $_GET['id'], $list_size); $result = @mysql_query($query, $link); if($result) { while($row = @mysql_fetch_assoc($result)) $items[] = array('url' => $homepath . '/?p='.$row['ID'], 'title' => $row['post_title'], 'match' => $row['n']); } } } @mysql_close($link); } else { # collaborative filtering approach # get recommendations from server $secret_key = @get_option('recommender_secret_key'); $list_size = @get_option('recommender_list_size'); $response = @file_get_contents(sprintf("http://rec.aliiike.com/?account=%s&pk=%s&url=%s&size=%s&uid=%s&vid=%s", $_GET['account'], $secret_key, $_GET['url'], $list_size, $_COOKIE['uid'], $_COOKIE['vid'])); # decode response into array $items = @json_decode($response, true); } # do the output # if nothing was returned, echo nothing if(!@is_array($items)) return; # apply list size from wp settings $items = array_slice($items, 0, $list_size); # prepare elements for output $elements['ul'] = Array('open' => '', 'line_open' => '
  • ', 'line_close' => '
  • ', 'poweredby' => '
  • '); $elements['ol'] = Array('open' => '
      ', 'close' => '
    ', 'line_open' => '
  • ', 'line_close' => '
  • ', 'poweredby' => '
  • '); $elements['tb'] = Array('open' => '', 'close' => '
    ', 'line_open' => '', 'line_close' => '', 'poweredby' => ''); $elements['br'] = Array('open' => '
    ', 'close' => '', 'line_open' => '', 'line_close' => '
    ', 'poweredby' => ''); $elements['tm'] = Array('open' => '', 'close' => '
    ', 'line_open' => '
     
      ', 'line_close' => '', 'poweredby' => ''); # if display type not selected then the default display type is unordered list if(!@is_array($elements[$display_type])) $display_type = 'ul'; $max_match= $items[0]['match']; # do the output echo $tagline; echo $elements[$display_type]['open']; foreach($items as $item) echo @sprintf('%s%s%s', @sprintf($elements[$display_type]['line_open'], $item['match']*50/$max_match), $item['url'], $item['title'], $elements[$display_type]['line_close']); echo @sprintf('%s%s%s', $elements[$display_type]['poweredby'], 'http://aliiike.com/wordpress/', '', $elements[$display_type]['line_close']); echo $elements[$display_type]['close']; ?>