tag:blogger.com,1999:blog-18125548680557187102023-11-15T10:14:01.406-08:00austin texas dwi attorneyWeigh Losshttp://www.blogger.com/profile/09827093283544363808noreply@blogger.comBlogger1125tag:blogger.com,1999:blog-1812554868055718710.post-53166543529405629392011-03-09T02:36:00.001-08:002011-03-09T02:36:52.792-08:00<div dir="ltr" style="text-align: left;" trbidi="on"><?php<br />
/*<br />
Plugin Name:Similar Posts<br />
Plugin URI: http://rmarsh.com/plugins/similar-posts/<br />
Description: Displays a <a href="options-general.php?page=similar-posts.php">highly configurable</a> list of related posts. Similarity can be based on any combination of word usage in the content, title, or tags. Don't be disturbed if it takes a few moments to complete the installation -- the plugin is indexing your posts. <a href="http://rmarsh.com/plugins/post-options/">Instructions and help online</a>. Requires the latest version of the <a href="http://wordpress.org/extend/plugins/post-plugin-library/">Post-Plugin Library</a> to be installed.<br />
Version: 2.6.2.0<br />
Author: Rob Marsh, SJ<br />
Author URI: http://rmarsh.com/<br />
*/<br />
<br />
/*<br />
Copyright 2008 Rob Marsh, SJ (http://rmarsh.com)<br />
<br />
This program is free software; you can redistribute it and/or modify<br />
it under the terms of the GNU General Public License as published by<br />
the Free Software Foundation; either version 2 of the License, or<br />
(at your option) any later version.<br />
<br />
This program is distributed in the hope that it will be useful,<br />
but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br />
GNU General Public License for more details: http://www.gnu.org/licenses/gpl.txt<br />
*/<br />
<br />
$similar_posts_version = $similar_posts_feed_version= '2.6.2.0';<br />
<br />
/*<br />
Template Tag: Displays the posts most similar to the current post.<br />
e.g.: <?php similar_posts(); ?><br />
Full help and instructions at http://rmarsh.com/plugins/post-options/<br />
*/<br />
<br />
function similar_posts($args = '') {<br />
echo SimilarPosts::execute($args);<br />
}<br />
<br />
function similar_posts_mark_current(){<br />
global $post, $similar_posts_current_ID;<br />
$similar_posts_current_ID = $post->ID;<br />
}<br />
<br />
/*<br />
<br />
'innards'<br />
<br />
*/<br />
<br />
<br />
if (!defined('DSEP')) define('DSEP', DIRECTORY_SEPARATOR);<br />
if (!defined('POST_PLUGIN_LIBRARY')) SimilarPosts::install_post_plugin_library();<br />
<br />
$similar_posts_current_ID = -1;<br />
<br />
class SimilarPosts {<br />
<br />
function execute($args='', $default_output_template='<li>{link}</li>', $option_key='similar-posts'){<br />
if (!SimilarPosts::check_post_plugin_library('<a href="http://downloads.wordpress.org/plugin/post-plugin-library.zip">'.__('Post-Plugin Library missing').'</a>')) return '';<br />
global $table_prefix, $wpdb, $wp_version, $similar_posts_current_ID;<br />
$start_time = ppl_microtime();<br />
$postid = ppl_current_post_id($similar_posts_current_ID); <br />
if (defined('POC_CACHE_4')) {<br />
$cache_key = $option_key.$postid.$args;<br />
$result = poc_cache_fetch($cache_key);<br />
if ($result !== false) return $result . sprintf("<!-- Similar Posts took %.3f ms (cached) -->", 1000 * (ppl_microtime() - $start_time));<br />
}<br />
$table_name = $table_prefix . 'similar_posts';<br />
// First we process any arguments to see if any defaults have been overridden<br />
$options = ppl_parse_args($args);<br />
// Next we retrieve the stored options and use them unless a value has been overridden via the arguments<br />
$options = ppl_set_options($option_key, $options, $default_output_template);<br />
if (0 < $options['limit']) {<br />
$match_tags = ($options['match_tags'] !== 'false' && $wp_version >= 2.3);<br />
$exclude_cats = ($options['excluded_cats'] !== '');<br />
$include_cats = ($options['included_cats'] !== '');<br />
$exclude_authors = ($options['excluded_authors'] !== '');<br />
$include_authors = ($options['included_authors'] !== '');<br />
$exclude_posts = (trim($options['excluded_posts']) !== '');<br />
$include_posts = (trim($options['included_posts']) !== '');<br />
$match_category = ($options['match_cat'] === 'true');<br />
$match_author = ($options['match_author'] === 'true');<br />
$use_tag_str = ('' != trim($options['tag_str']) && $wp_version >= 2.3);<br />
$omit_current_post = ($options['omit_current_post'] !== 'false');<br />
$hide_pass = ($options['show_private'] === 'false');<br />
$check_age = ('none' !== $options['age']['direction']);<br />
$check_custom = (trim($options['custom']['key']) !== '');<br />
$limit = $options['skip'].', '.$options['limit'];<br />
<br />
//get the terms to do the matching<br />
if ($options['term_extraction'] === 'pagerank') {<br />
list( $contentterms, $titleterms, $tagterms) = sp_terms_by_textrank($postid, $options['num_terms']);<br />
} else {<br />
list( $contentterms, $titleterms, $tagterms) = sp_terms_by_freq($postid, $options['num_terms']);<br />
} <br />
// these should add up to 1.0<br />
$weight_content = $options['weight_content'];<br />
$weight_title = $options['weight_title'];<br />
$weight_tags = $options['weight_tags'];<br />
// below a threshold we ignore the weight completely and save some effort<br />
if ($weight_content < 0.001) $weight_content = (int) 0;<br />
if ($weight_title < 0.001) $weight_title = (int) 0; <br />
if ($weight_tags < 0.001) $weight_tags = (int) 0; <br />
<br />
$count_content = substr_count($contentterms, ' ') + 1;<br />
$count_title = substr_count($titleterms, ' ') + 1;<br />
$count_tags = substr_count($tagterms, ' ') + 1;<br />
if ($weight_content) $weight_content = 57.0 * $weight_content / $count_content;<br />
if ($weight_title) $weight_title = 18.0 * $weight_title / $count_title;<br />
if ($weight_tags) $weight_tags = 24.0 * $weight_tags / $count_tags;<br />
if ($options['hand_links'] === 'true') {<br />
// check custom field for manual links<br />
$forced_ids = $wpdb->get_var("SELECT meta_value FROM $wpdb->postmeta WHERE post_id = $postid AND meta_key = 'sp_similar' ") ;<br />
} <br />
// the workhorse...<br />
$sql = "SELECT *, ";<br />
$sql .= score_fulltext_match($table_name, $weight_title, $titleterms, $weight_content, $contentterms, $weight_tags, $tagterms, $forced_ids);<br />
<br />
if ($check_custom) $sql .= "LEFT JOIN $wpdb->postmeta ON post_id = ID ";<br />
<br />
// build the 'WHERE' clause<br />
$where = array();<br />
$where[] = where_fulltext_match($weight_title, $titleterms, $weight_content, $contentterms, $weight_tags, $tagterms);<br />
if (!function_exists('get_post_type')) { <br />
$where[] = where_hide_future();<br />
} else {<br />
$where[] = where_show_status($options['status'], $options['show_attachments']);<br />
}<br />
if ($match_category) $where[] = where_match_category();<br />
if ($match_tags) $where[] = where_match_tags($options['match_tags']);<br />
if ($match_author) $where[] = where_match_author();<br />
$where[] = where_show_pages($options['show_pages'], $options['show_attachments']); <br />
if ($include_cats) $where[] = where_included_cats($options['included_cats']);<br />
if ($exclude_cats) $where[] = where_excluded_cats($options['excluded_cats']);<br />
if ($exclude_authors) $where[] = where_excluded_authors($options['excluded_authors']);<br />
if ($include_authors) $where[] = where_included_authors($options['included_authors']);<br />
if ($exclude_posts) $where[] = where_excluded_posts(trim($options['excluded_posts']));<br />
if ($include_posts) $where[] = where_included_posts(trim($options['included_posts']));<br />
if ($use_tag_str) $where[] = where_tag_str($options['tag_str']);<br />
if ($omit_current_post) $where[] = where_omit_post($similar_posts_current_ID);<br />
if ($hide_pass) $where[] = where_hide_pass();<br />
if ($check_age) $where[] = where_check_age($options['age']['direction'], $options['age']['length'], $options['age']['duration']);<br />
if ($check_custom) $where[] = where_check_custom($options['custom']['key'], $options['custom']['op'], $options['custom']['value']);<br />
$sql .= "WHERE ".implode(' AND ', $where);<br />
if ($check_custom) $sql .= " GROUP BY $wpdb->posts.ID"; <br />
$sql .= " ORDER BY score DESC LIMIT $limit";<br />
//echo $sql;<br />
$results = $wpdb->get_results($sql);<br />
} else {<br />
$results = false;<br />
}<br />
if ($results) {<br />
$translations = ppl_prepare_template($options['output_template']);<br />
foreach ($results as $result) {<br />
$items[] = ppl_expand_template($result, $options['output_template'], $translations, $option_key);<br />
}<br />
if ($options['sort']['by1'] !== '') $items = ppl_sort_items($options['sort'], $results, $option_key, $options['group_template'], $items); <br />
$output = implode(($options['divider']) ? $options['divider'] : "\n", $items);<br />
$output = $options['prefix'] . $output . $options['suffix'];<br />
} else {<br />
// if we reach here our query has produced no output ... so what next?<br />
if ($options['no_text'] !== 'false') {<br />
$output = ''; // we display nothing at all<br />
} else {<br />
// we display the blank message, with tags expanded if necessary<br />
$translations = ppl_prepare_template($options['none_text']);<br />
$output = $options['prefix'] . ppl_expand_template(array(), $options['none_text'], $translations, $option_key) . $options['suffix'];<br />
}<br />
}<br />
if (defined('POC_CACHE_4')) poc_cache_store($cache_key, $output); <br />
return ($output) ? $output . sprintf("<!-- Similar Posts took %.3f ms -->", 1000 * (ppl_microtime() - $start_time)) : '';<br />
}<br />
<br />
// tries to install the post-plugin-library plugin<br />
function install_post_plugin_library() {<br />
$plugin_path = 'post-plugin-library/post-plugin-library.php';<br />
$current = get_option('active_plugins');<br />
if (!in_array($plugin_path, $current)) {<br />
$current[] = $plugin_path;<br />
update_option('active_plugins', $current);<br />
do_action('activate_'.$plugin_path);<br />
}<br />
}<br />
<br />
function check_post_plugin_library($msg) {<br />
$exists = function_exists('ppl_microtime');<br />
if (!$exists) echo $msg;<br />
return $exists;<br />
}<br />
<br />
}<br />
<br />
function sp_terms_by_freq($ID, $num_terms = 20) {<br />
if (!$ID) return array('', '', '');<br />
global $wpdb, $table_prefix;<br />
$table_name = $table_prefix . 'similar_posts';<br />
$terms = '';<br />
$results = $wpdb->get_results("SELECT title, content, tags FROM $table_name WHERE pID=$ID LIMIT 1", ARRAY_A);<br />
if ($results) {<br />
$word = strtok($results[0]['content'], ' ');<br />
$n = 0;<br />
$wordtable = array();<br />
while ($word !== false) {<br />
$wordtable[$word] += 1;<br />
$word = strtok(' ');<br />
}<br />
arsort($wordtable);<br />
if ($num_terms < 1) $num_terms = 1;<br />
$wordtable = array_slice($wordtable, 0, $num_terms);<br />
<br />
foreach ($wordtable as $word => $count) {<br />
$terms .= ' ' . $word;<br />
}<br />
<br />
$res[] = $terms;<br />
$res[] = $results[0]['title']; <br />
$res[] = $results[0]['tags'];<br />
}<br />
return $res;<br />
}<br />
<br />
<br />
// adapted PageRank algorithm see http://www.cs.unt.edu/~rada/papers/mihalcea.emnlp04.pdf<br />
// and the weighted version http://www.cs.unt.edu/~rada/papers/hassan.ieee07.pdf<br />
function sp_terms_by_textrank($ID, $num_terms = 20) {<br />
global $wpdb, $table_prefix;<br />
$table_name = $table_prefix . 'similar_posts';<br />
$terms = '';<br />
$results = $wpdb->get_results("SELECT title, content, tags FROM $table_name WHERE pID=$ID LIMIT 1", ARRAY_A);<br />
if ($results) {<br />
// build a directed graph with words as vertices and, as edges, the words which precede them<br />
$prev_word = 'aaaaa';<br />
$graph = array();<br />
$word = strtok($results[0]['content'], ' ');<br />
while ($word !== false) {<br />
$graph[$word][$prev_word] += 1; // list the incoming words and keep a tally of how many times words co-occur<br />
$out_edges[$prev_word] += 1; // count the number of different words that follow each word<br />
$prev_word = $word;<br />
$word = strtok(' ');<br />
}<br />
// initialise the list of PageRanks-- one for each unique word <br />
reset($graph);<br />
while (list($vertex, $in_edges) = each($graph)) {<br />
$oldrank[$vertex] = 0.25;<br />
}<br />
$n = count($graph);<br />
if ($n > 0) {<br />
$base = 0.15 / $n; <br />
$error_margin = $n * 0.005;<br />
do {<br />
$error = 0.0;<br />
// the edge-weighted PageRank calculation<br />
reset($graph);<br />
while (list($vertex, $in_edges) = each($graph)) {<br />
$r = 0;<br />
reset($in_edges);<br />
while (list($edge, $weight) = each($in_edges)) {<br />
$r += ($weight * $oldrank[$edge]) / $out_edges[$edge];<br />
}<br />
$rank[$vertex] = $base + 0.95 * $r;<br />
$error += abs($rank[$vertex] - $oldrank[$vertex]); <br />
}<br />
$oldrank = $rank;<br />
//echo $error . '<br>';<br />
} while ($error > $error_margin);<br />
arsort($rank);<br />
if ($num_terms < 1) $num_terms = 1;<br />
$rank = array_slice($rank, 0, $num_terms);<br />
foreach ($rank as $vertex => $score) {<br />
$terms .= ' ' . $vertex;<br />
}<br />
} <br />
$res[] = $terms;<br />
$res[] = $results[0]['title']; <br />
$res[] = $results[0]['tags'];<br />
}<br />
return $res;<br />
}<br />
<br />
function sp_save_index_entry($postID) {<br />
global $wpdb, $table_prefix;<br />
$table_name = $table_prefix . 'similar_posts';<br />
$post = $wpdb->get_row("SELECT post_content, post_title, post_type FROM $wpdb->posts WHERE ID = $postID", ARRAY_A);<br />
if ($post['post_type'] === 'revision') return $postid;<br />
//extract its terms<br />
$options = get_option('similar-posts');<br />
$utf8 = ($options['utf8'] === 'true');<br />
$cjk = ($options['cjk'] === 'true');<br />
$content = sp_get_post_terms($post['post_content'], $utf8, $options['use_stemmer'], $cjk);<br />
$title = sp_get_title_terms($post['post_title'], $utf8, $options['use_stemmer'], $cjk);<br />
$tags = sp_get_tag_terms($postID, $utf8);<br />
//check to see if the field is set<br />
$pid = $wpdb->get_var("SELECT pID FROM $table_name WHERE pID=$postID limit 1");<br />
//then insert if empty<br />
if (is_null($pid)) {<br />
$wpdb->query("INSERT INTO $table_name (pID, content, title, tags) VALUES ($postID, \"$content\", \"$title\", \"$tags\")");<br />
} else {<br />
$wpdb->query("UPDATE $table_name SET content=\"$content\", title=\"$title\", tags=\"$tags\" WHERE pID=$postID" ); <br />
}<br />
return $postID;<br />
}<br />
<br />
function sp_delete_index_entry($postID) {<br />
global $wpdb, $table_prefix;<br />
$table_name = $table_prefix . 'similar_posts';<br />
$wpdb->query("DELETE FROM $table_name WHERE pID = $postID ");<br />
return $postID;<br />
}<br />
<br />
function sp_clean_words($text) {<br />
$text = strip_tags($text);<br />
$text = strtolower($text);<br />
$text = str_replace("’", "'", $text); // convert MSWord apostrophe<br />
$text = preg_replace(array('/\[(.*?)\]/', '/&[^\s;]+;/', '/‘|’|—|“|â€|–|…/', "/'\W/"), ' ', $text); //anything in [..] or any entities or MS Word droppings<br />
return $text;<br />
}<br />
<br />
function sp_mb_clean_words($text) {<br />
mb_regex_encoding('UTF-8');<br />
mb_internal_encoding('UTF-8');<br />
$text = strip_tags($text);<br />
$text = mb_strtolower($text);<br />
$text = str_replace("’", "'", $text); // convert MSWord apostrophe<br />
$text = preg_replace(array('/\[(.*?)\]/u', '/&[^\s;]+;/u', '/‘|’|—|“|â€|–|…/u', "/'\W/u"), ' ', $text); //anything in [..] or any entities<br />
return $text;<br />
}<br />
<br />
function sp_mb_str_pad($text, $n, $c) {<br />
mb_internal_encoding('UTF-8');<br />
$l = mb_strlen($text);<br />
if ($l > 0 && $l < $n) {<br />
$text .= str_repeat($c, $n-$l);<br />
}<br />
return $text;<br />
}<br />
<br />
function sp_cjk_digrams($string) {<br />
mb_internal_encoding("UTF-8");<br />
$strlen = mb_strlen($string);<br />
$ascii = '';<br />
$prev = '';<br />
$result = array();<br />
for ($i = 0; $i < $strlen; $i++) {<br />
$c = mb_substr($string, $i, 1);<br />
// single-byte chars get combined<br />
if (strlen($c) > 1) {<br />
if ($ascii) {<br />
$result[] = $ascii;<br />
$ascii = '';<br />
$prev = $c;<br />
} else { <br />
$result[] = sp_mb_str_pad($prev.$c, 4, '_');<br />
$prev = $c;<br />
} <br />
} else {<br />
$ascii .= $c;<br />
}<br />
}<br />
if ($ascii) $result[] = $ascii;<br />
return implode(' ', $result);<br />
}<br />
<br />
function sp_get_post_terms($text, $utf8, $use_stemmer, $cjk) {<br />
global $overusedwords;<br />
if ($utf8) {<br />
mb_regex_encoding('UTF-8');<br />
mb_internal_encoding('UTF-8');<br />
$wordlist = mb_split("\W+", sp_mb_clean_words($text));<br />
$words = '';<br />
reset($wordlist);<br />
while (list($n, $word) = each($wordlist)) {<br />
if ( mb_strlen($word) > 3 && !isset($overusedwords[$word])) {<br />
switch ($use_stemmer) {<br />
case 'true':<br />
$words .= sp_mb_str_pad(stem($word), 4, '_') . ' ';<br />
break;<br />
case 'fuzzy':<br />
$words .= sp_mb_str_pad(metaphone($word), 4, '_') . ' ';<br />
break;<br />
case 'false':<br />
default: <br />
$words .= $word . ' '; <br />
} <br />
} <br />
} <br />
} else {<br />
$wordlist = str_word_count(sp_clean_words($text), 1);<br />
$words = ''; <br />
reset($wordlist);<br />
while (list($n, $word) = each($wordlist)) {<br />
if ( strlen($word) > 3 && !isset($overusedwords[$word])) {<br />
switch ($use_stemmer) {<br />
case 'true':<br />
$words .= str_pad(stem($word), 4, '_') . ' ';<br />
break;<br />
case 'fuzzy':<br />
$words .= str_pad(metaphone($word), 4, '_') . ' ';<br />
break;<br />
case 'false':<br />
default: <br />
$words .= $word . ' '; <br />
} <br />
} <br />
} <br />
}<br />
if ($cjk) $words = sp_cjk_digrams($words); <br />
return $words;<br />
}<br />
<br />
$tinywords = array('the' => 1, 'and' => 1, 'of' => 1, 'a' => 1, 'for' => 1, 'on' => 1);<br />
<br />
function sp_get_title_terms($text, $utf8, $use_stemmer, $cjk) {<br />
global $tinywords;<br />
if ($utf8) {<br />
mb_regex_encoding('UTF-8');<br />
mb_internal_encoding('UTF-8');<br />
$wordlist = mb_split("\W+", sp_mb_clean_words($text));<br />
$words = '';<br />
foreach ($wordlist as $word) {<br />
if (!isset($tinywords[$word])) {<br />
switch ($use_stemmer) {<br />
case 'true':<br />
$words .= sp_mb_str_pad(stem($word), 4, '_') . ' ';<br />
break;<br />
case 'fuzzy':<br />
$words .= sp_mb_str_pad(metaphone($word), 4, '_') . ' ';<br />
break;<br />
case 'false':<br />
default: <br />
$words .= sp_mb_str_pad($word, 4, '_') . ' ';<br />
} <br />
} <br />
} <br />
} else {<br />
$wordlist = str_word_count(sp_clean_words($text), 1);<br />
$words = '';<br />
foreach ($wordlist as $word) {<br />
if (!isset($tinywords[$word])) {<br />
switch ($use_stemmer) {<br />
case 'true':<br />
$words .= str_pad(stem($word), 4, '_') . ' ';<br />
break;<br />
case 'fuzzy':<br />
$words .= str_pad(metaphone($word), 4, '_') . ' ';<br />
break;<br />
case 'false':<br />
default: <br />
$words .= str_pad($word, 4, '_') . ' ';<br />
} <br />
}<br />
}<br />
}<br />
if ($cjk) $words = sp_cjk_digrams($words); <br />
return $words;<br />
}<br />
<br />
function sp_get_tag_terms($ID, $utf8) {<br />
global $wpdb;<br />
if (!function_exists('get_object_term_cache')) return ''; <br />
$tags = array();<br />
$query = "SELECT t.name FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = 'post_tag' AND tr.object_id = '$ID'";<br />
$tags = $wpdb->get_col($query);<br />
if (!empty ($tags)) {<br />
if ($utf8) {<br />
mb_internal_encoding('UTF-8');<br />
foreach ($tags as $tag) {<br />
$newtags[] = sp_mb_str_pad(mb_strtolower(str_replace('"', "'", $tag)), 4, '_');<br />
} <br />
} else {<br />
foreach ($tags as $tag) {<br />
$newtags[] = str_pad(strtolower(str_replace('"', "'", $tag)), 4, '_');<br />
} <br />
} <br />
$newtags = str_replace(' ', '_', $newtags); <br />
$tags = implode (' ', $newtags);<br />
} else {<br />
$tags = '';<br />
} <br />
return $tags; <br />
}<br />
<br />
if ( is_admin() ) {<br />
require(dirname(__FILE__).'/similar-posts-admin.php');<br />
}<br />
<br />
function widget_rrm_similar_posts_init() {<br />
if (! function_exists("register_sidebar_widget")) {<br />
return;<br />
}<br />
function widget_rrm_similar_posts($args) {<br />
extract($args);<br />
$options = get_option('widget_rrm_similar_posts');<br />
$opt = get_option('similar-posts');<br />
$widget_condition = $opt['widget_condition'];<br />
// the condition specified in the widget control overrides the placement setting screen<br />
if ($options['condition']) {<br />
$condition = $options['condition'];<br />
} else {<br />
if ($widget_condition) {<br />
$condition = $widget_condition;<br />
} else {<br />
$condition = 'true';<br />
}<br />
}<br />
$condition = (stristr($condition, "return")) ? $condition : "return ".$condition;<br />
$condition = rtrim($condition, '; ') . ' || is_admin();'; <br />
if (eval($condition)) {<br />
$title = empty($options['title']) ? __('Similar Posts', 'similar_posts') : $options['title'];<br />
if ( !$number = (int) $options['number'] )<br />
$number = 10;<br />
else if ( $number < 1 )<br />
$number = 1;<br />
else if ( $number > 15 )<br />
$number = 15;<br />
$options = get_option('recent-posts'); <br />
$widget_parameters = $options['widget_parameters'];<br />
$output = SimilarPosts::execute('limit='.$number.'&'.$widget_parameters);<br />
if ($output) {<br />
echo $before_widget;<br />
echo $before_title.$title.$after_title;<br />
echo $output;<br />
echo $after_widget;<br />
}<br />
}<br />
}<br />
function widget_rrm_similar_posts_control() {<br />
if ( $_POST['widget_rrm_similar_posts_submit'] ) {<br />
$options['title'] = strip_tags(stripslashes($_POST['widget_rrm_similar_posts_title']));<br />
$options['number'] = (int) $_POST["widget_rrm_similar_posts_number"];<br />
$options['condition'] = stripslashes(trim($_POST["widget_rrm_similar_posts_condition"], '; '));<br />
update_option("widget_rrm_similar_posts", $options);<br />
} else {<br />
$options = get_option('widget_rrm_similar_posts');<br />
} <br />
$title = attribute_escape($options['title']);<br />
if ( !$number = (int) $options['number'] )<br />
$number = 5;<br />
$condition = attribute_escape($options['condition']);<br />
?><br />
<p><label for="widget_rrm_similar_posts_title"> <?php _e('Title:', 'similar_posts'); ?> <input style="width: 200px;" id="widget_rrm_similar_posts_title" name="widget_rrm_similar_posts_title" type="text" value="<?php echo $title; ?>" /></label></p><br />
<p><label for="widget_rrm_similar_posts_number"> <?php _e('Number of posts to show:', 'similar_posts'); ?> <input style="width: 25px; text-align: center;" id="widget_rrm_similar_posts_number" name="widget_rrm_similar_posts_number" type="text" value="<?php echo $number; ?>" /></label> <?php _e('(at most 15)', 'similar_posts'); ?> </p><br />
<p><label for="widget_rrm_similar_posts_condition"> <?php echo sprintf(__('Show only if page: (e.g., %sis_single()%s)', 'similar_posts'), '<a href="http://codex.wordpress.org/Conditional_Tags" title="help">', '</a>'); ?> <input style="width: 200px;" id="widget_rrm_similar_posts_condition" name="widget_rrm_similar_posts_condition" type="text" value="<?php echo $condition; ?>" /></label></p><br />
<input type="hidden" id="widget_rrm_similar_posts_submit" name="widget_rrm_similar_posts_submit" value="1" /><br />
There are many more <a href="options-general.php?page=similar-posts.php">options</a> available.<br />
<?php<br />
}<br />
register_sidebar_widget(__('Similar Posts +', 'similar_posts'), 'widget_rrm_similar_posts');<br />
register_widget_control(__('Similar Posts +', 'similar_posts'), 'widget_rrm_similar_posts_control', 300, 100);<br />
}<br />
<br />
add_action('plugins_loaded', 'widget_rrm_similar_posts_init');<br />
<br />
<br />
/*<br />
now some language specific stuff<br />
*/<br />
<br />
//the next lines find the language WordPress is using<br />
$language = substr(WPLANG, 0, 2);<br />
//if no language is specified make it the default which is 'en'<br />
if ($language == '') {<br />
$language = 'en';<br />
}<br />
$languagedir = dirname(__FILE__).DSEP.'languages'.DSEP.$language.DSEP;<br />
//see if the directory exists and if not revert to the default English dir<br />
if (!file_exists($languagedir)) {<br />
$languagedir = dirname(__FILE__).DSEP.'languages'.DSEP.'en'.DSEP;<br />
}<br />
<br />
// import the stemming algorithm ... a single function called 'stem'<br />
require_once($languagedir.'stemmer.php');<br />
require_once($languagedir.'stopwords.php');<br />
global $overusedwords;<br />
$overusedwords = array_flip($overusedwords);<br />
<br />
// do not try and use this function directly -- it is automatically installed when the option is set to show similar posts in feeds // moreover it is deprecated and going soon<br />
function similar_posts_for_feed($content) {<br />
return (is_feed()) ? $content . SimilarPosts::execute('', '<li>{link}</li>', 'similar-posts-feed') : $content;<br />
}<br />
<br />
function similar_posts_init () {<br />
global $overusedwords, $wp_db_version;<br />
load_plugin_textdomain('similar_posts');<br />
<br />
$options = get_option('similar-posts');<br />
if ($options['feed_active'] === 'true') add_filter('the_content', 'similar_posts_for_feed');<br />
if ($options['content_filter'] === 'true' && function_exists('ppl_register_content_filter')) ppl_register_content_filter('SimilarPosts');<br />
if ($options['feed_on'] === 'true' && function_exists('ppl_register_post_filter')) ppl_register_post_filter('feed', 'similar-posts', 'SimilarPosts');<br />
if ($options['append_condition']) {<br />
$condition = $options['append_condition'];<br />
} else {<br />
$condition = 'true';<br />
}<br />
$condition = (stristr($condition, "return")) ? $condition : "return ".$condition;<br />
$condition = rtrim($condition, '; ') . ';'; <br />
if ($options['append_on'] === 'true' && function_exists('ppl_register_post_filter')) ppl_register_post_filter('append', 'similar-posts', 'SimilarPosts', $condition);<br />
<br />
//install the actions to keep the index up to date<br />
add_action('save_post', 'sp_save_index_entry', 1);<br />
add_action('delete_post', 'sp_delete_index_entry', 1);<br />
if ($wp_db_version < 3308 ) { <br />
add_action('edit_post', 'sp_save_index_entry', 1);<br />
add_action('publish_post', 'sp_save_index_entry', 1);<br />
} <br />
}<br />
<br />
add_action ('init', 'similar_posts_init', 1);<br />
<br />
?></div>Weigh Losshttp://www.blogger.com/profile/09827093283544363808noreply@blogger.com0