Yet Another Related Posts Plugin (YARPP) - Version 3.0b1

Version Description

Download this release

Release Info

Developer mitchoyoshitaka
Plugin Icon 128x128 Yet Another Related Posts Plugin (YARPP)
Version 3.0b1
Comparing to
See all releases

Code changes from version 2.1.5 to 3.0b1

i/close.gif ADDED
Binary file
i/spin.gif ADDED
Binary file
includes.php CHANGED
@@ -3,10 +3,17 @@
3
require_once('magic.php');
4
require_once('keywords.php');
5
require_once('intl.php');
6
7
// here's a list of all the options YARPP uses (except version), as well as their default values, sans the yarpp_ prefix, split up into binary options and value options. These arrays are used in updating settings (options.php) and other tasks.
8
$yarpp_value_options = array('threshold' => 5,
9
'limit' => 5,
10
'excerpt_length' => 10,
11
'before_title' => '<li>',
12
'after_title' => '</li>',
@@ -17,6 +24,7 @@ $yarpp_value_options = array('threshold' => 5,
17
'no_results' => '<p>No related posts.</p>',
18
'order' => 'score DESC',
19
'rss_limit' => 3,
20
'rss_excerpt_length' => 10,
21
'rss_before_title' => '<li>',
22
'rss_after_title' => '</li>',
@@ -34,20 +42,30 @@ $yarpp_value_options = array('threshold' => 5,
34
'discats' => '');
35
$yarpp_binary_options = array('past_only' => true,
36
'show_excerpt' => false,
37
'rss_show_excerpt' => false,
38
'show_pass_post' => false,
39
'cross_relate' => false,
40
'auto_display' => true,
41
'rss_display' => true,
42
'rss_excerpt_display' => true,
43
'promote_yarpp' => false,
44
- 'rss_promote_yarpp' => false);
45
46
function yarpp_enabled() {
47
global $wpdb;
48
$indexdata = $wpdb->get_results("show index from $wpdb->posts");
49
foreach ($indexdata as $index) {
50
- if ($index->Key_name == 'yarpp_title') return 1;
51
}
52
return 0;
53
}
@@ -69,7 +87,6 @@ function yarpp_activate() {
69
add_option("yarpp_$option",$yarpp_binary_options[$option]." ");
70
}
71
if (!yarpp_enabled()) {
72
- // $wpdb->query("ALTER TABLE `wp_posts` DROP INDEX `yarpp_cache`");
73
if (!$wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_title` ( `post_title`)")) {
74
echo "<!--".__('MySQL error on adding yarpp_title','yarpp').": ";
75
$wpdb->print_error();
@@ -80,12 +97,34 @@ function yarpp_activate() {
80
$wpdb->print_error();
81
echo "-->";
82
}
83
if (!yarpp_enabled()) {
84
return 0;
85
}
86
}
87
- add_option('yarpp_version','2.15');
88
- update_option('yarpp_version','2.15');
89
return 1;
90
}
91
@@ -138,8 +177,8 @@ function yarpp_upgrade_check($inuse = false) {
138
$wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_content` ( `post_content`)"); update_option('yarpp_version','2.03');
139
}
140
141
- if (get_option('yarpp_version') < 2.15) {
142
- update_option('yarpp_version','2.15');
143
}
144
145
// just in case, try to add the index one more time.
@@ -151,8 +190,16 @@ function yarpp_upgrade_check($inuse = false) {
151
}
152
153
function yarpp_admin_menu() {
154
- add_options_page(__('Related Posts (YARPP)','yarpp'),__('Related Posts (YARPP)','yarpp'), 8, 'yet-another-related-posts-plugin/options.php', 'yarpp_options_page');
155
//if (function_exists('add_submenu_page')) add_submenu_page('options-general.php', 'Related Posts (YARPP)', 'Related Posts (YARPP)', 8, 'yet-another-related-posts-plugin/options.php');
156
}
157
158
function yarpp_options_page() {
@@ -183,7 +230,7 @@ function yarpp_default($content) {
183
if (is_feed())
184
return yarpp_rss($content);
185
elseif (yarpp_get_option('auto_display') and is_single())
186
- return $content.yarpp_related(array('post'),array(),false,'website');
187
else
188
return $content;
189
}
@@ -191,15 +238,15 @@ function yarpp_default($content) {
191
function yarpp_rss($content) {
192
global $wpdb, $post;
193
if (yarpp_get_option('rss_display'))
194
- return $content.yarpp_related(array('post'),array(),false,'rss');
195
else
196
return $content;
197
}
198
199
function yarpp_rss_excerpt($content) {
200
global $wpdb, $post;
201
- if (yarpp_get_option('rss_excerpt_display') and yarpp_get_option('rss_display'))
202
- return $content.clean_pre(yarpp_related(array('post'),array(),false,'rss'));
203
else
204
return $content;
205
}
@@ -282,7 +329,7 @@ function apply_filters_if_white($tag, $value) {
282
// upgrade to 1.5!
283
function yarpp_upgrade_one_five() {
284
global $wpdb;
285
- $migrate_options = array('past_only','show_score','show_excerpt','show_pass_post','cross_relate','limit','threshold','before_title','after_title','before_post','after_post');
286
foreach ($migrate_options as $option) {
287
if (get_option($option)) {
288
update_option("yarpp_$option",get_option($option));
@@ -326,4 +373,10 @@ function yarpp_get_option($option,$escapehtml = false) {
326
return $return;
327
}
328
329
?>
3
require_once('magic.php');
4
require_once('keywords.php');
5
require_once('intl.php');
6
+ require_once('services.php');
7
+
8
+ if ( !defined('WP_CONTENT_URL') )
9
+ define('WP_CONTENT_URL', get_option('siteurl') . '/wp-content');
10
+ if ( !defined('WP_CONTENT_DIR') )
11
+ define('WP_CONTENT_DIR', ABSPATH . 'wp-content');
12
13
// here's a list of all the options YARPP uses (except version), as well as their default values, sans the yarpp_ prefix, split up into binary options and value options. These arrays are used in updating settings (options.php) and other tasks.
14
$yarpp_value_options = array('threshold' => 5,
15
'limit' => 5,
16
+ 'template_file' => '', // new in 2.2
17
'excerpt_length' => 10,
18
'before_title' => '<li>',
19
'after_title' => '</li>',
24
'no_results' => '<p>No related posts.</p>',
25
'order' => 'score DESC',
26
'rss_limit' => 3,
27
+ 'rss_template_file' => '', // new in 2.2
28
'rss_excerpt_length' => 10,
29
'rss_before_title' => '<li>',
30
'rss_after_title' => '</li>',
42
'discats' => '');
43
$yarpp_binary_options = array('past_only' => true,
44
'show_excerpt' => false,
45
+ 'use_template' => false, // new in 2.2
46
'rss_show_excerpt' => false,
47
+ 'rss_use_template' => false, // new in 2.2
48
'show_pass_post' => false,
49
'cross_relate' => false,
50
'auto_display' => true,
51
'rss_display' => true,
52
'rss_excerpt_display' => true,
53
'promote_yarpp' => false,
54
+ 'rss_promote_yarpp' => false,
55
+ 'ad_hoc_caching' => false);
56
57
function yarpp_enabled() {
58
global $wpdb;
59
$indexdata = $wpdb->get_results("show index from $wpdb->posts");
60
foreach ($indexdata as $index) {
61
+ if ($index->Key_name == 'yarpp_title') {
62
+ // now check for the cache tables
63
+ $tabledata = $wpdb->get_col("show tables");
64
+ if (array_search("{$wpdb->prefix}yarpp_related_cache",$tabledata) !== false and array_search("{$wpdb->prefix}yarpp_keyword_cache",$tabledata) !== false)
65
+ return 1;
66
+ else
67
+ return 0;
68
+ };
69
}
70
return 0;
71
}
87
add_option("yarpp_$option",$yarpp_binary_options[$option]." ");
88
}
89
if (!yarpp_enabled()) {
90
if (!$wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_title` ( `post_title`)")) {
91
echo "<!--".__('MySQL error on adding yarpp_title','yarpp').": ";
92
$wpdb->print_error();
97
$wpdb->print_error();
98
echo "-->";
99
}
100
+ if (!$wpdb->query("CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}yarpp_keyword_cache` (
101
+ `ID` bigint(20) unsigned NOT NULL default '0',
102
+ `body` text collate utf8_unicode_ci NOT NULL,
103
+ `title` text collate utf8_unicode_ci NOT NULL,
104
+ `date` timestamp NOT NULL default CURRENT_TIMESTAMP,
105
+ PRIMARY KEY (`ID`)
106
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='YARPP''s keyword cache table';")) {
107
+ echo "<!--".__('MySQL error on creating yarpp_keyword_cache table','yarpp').": ";
108
+ $wpdb->print_error();
109
+ echo "-->";
110
+ }
111
+ if (!$wpdb->query("CREATE TABLE IF NOT EXISTS `wp_yarpp_related_cache` (
112
+ `reference_ID` bigint(20) unsigned NOT NULL default '0',
113
+ `ID` bigint(20) unsigned NOT NULL default '0',
114
+ `score` float unsigned NOT NULL default '0',
115
+ `date` timestamp NOT NULL default CURRENT_TIMESTAMP,
116
+ PRIMARY KEY (`reference_ID`,`ID`)
117
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;")) {
118
+ echo "<!--".__('MySQL error on creating yarpp_related_cache table','yarpp').": ";
119
+ $wpdb->print_error();
120
+ echo "-->";
121
+ }
122
if (!yarpp_enabled()) {
123
return 0;
124
}
125
}
126
+ add_option('yarpp_version','3.0b1');
127
+ update_option('yarpp_version','3.0b1');
128
return 1;
129
}
130
177
$wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_content` ( `post_content`)"); update_option('yarpp_version','2.03');
178
}
179
180
+ if (get_option('yarpp_version') < 3.0) {
181
+ update_option('yarpp_version','3.0b1');
182
}
183
184
// just in case, try to add the index one more time.
190
}
191
192
function yarpp_admin_menu() {
193
+ $hook = add_options_page(__('Related Posts (YARPP)','yarpp'),__('Related Posts (YARPP)','yarpp'), 8, 'yet-another-related-posts-plugin/options.php', 'yarpp_options_page');
194
//if (function_exists('add_submenu_page')) add_submenu_page('options-general.php', 'Related Posts (YARPP)', 'Related Posts (YARPP)', 8, 'yet-another-related-posts-plugin/options.php');
195
+ add_action("load-$hook",'yarpp_load_thickbox');
196
+ }
197
+
198
+ function yarpp_load_thickbox() {
199
+ wp_enqueue_script( 'thickbox' );
200
+ if (function_exists('wp_enqueue_style')) {
201
+ wp_enqueue_style( 'thickbox' );
202
+ }
203
}
204
205
function yarpp_options_page() {
230
if (is_feed())
231
return yarpp_rss($content);
232
elseif (yarpp_get_option('auto_display') and is_single())
233
+ return $content.yarpp_related(array('post'),array(),false,false,'website');
234
else
235
return $content;
236
}
238
function yarpp_rss($content) {
239
global $wpdb, $post;
240
if (yarpp_get_option('rss_display'))
241
+ return $content.yarpp_related(array('post'),array(),false,false,'rss');
242
else
243
return $content;
244
}
245
246
function yarpp_rss_excerpt($content) {
247
global $wpdb, $post;
248
+ if (yarpp_get_option('rss_excerpt_display') && yarpp_get_option('rss_display'))
249
+ return $content.clean_pre(yarpp_related(array('post'),array(),false,false,'rss'));
250
else
251
return $content;
252
}
329
// upgrade to 1.5!
330
function yarpp_upgrade_one_five() {
331
global $wpdb;
332
+ $migrate_options = array('past_only','show_excerpt','show_pass_post','cross_relate','limit','threshold','before_title','after_title','before_post','after_post');
333
foreach ($migrate_options as $option) {
334
if (get_option($option)) {
335
update_option("yarpp_$option",get_option($option));
373
return $return;
374
}
375
376
+ function yarpp_microtime_float()
377
+ {
378
+ list($usec, $sec) = explode(" ", microtime());
379
+ return ((float)$usec + (float)$sec);
380
+ }
381
+
382
?>
keywords.php CHANGED
@@ -1,7 +1,7 @@
1
<?php
2
3
- function yarpp_extract_keywords($source,$num_to_ret = 20) {
4
- global $post, $overusedwords;
5
6
if (function_exists('mb_split')) {
7
mb_regex_encoding(get_option('blog_charset'));
@@ -10,39 +10,57 @@ function yarpp_extract_keywords($source,$num_to_ret = 20) {
10
$wordlist = preg_split('%\s*\W+\s*%', strtolower($source));
11
12
// Build an array of the unique words and number of times they occur.
13
- $a = array_count_values($wordlist);
14
15
// Remove the stop words from the list.
16
foreach ($overusedwords as $word) {
17
- unset($a[$word]);
18
}
19
- arsort($a, SORT_NUMERIC);
20
21
- $num_words = count($a);
22
- $num_to_ret = $num_words > $num_to_ret ? $num_to_ret : $num_words;
23
24
- $outwords = array_slice($a, 0, $num_to_ret);
25
- return implode(' ', array_keys($outwords));
26
}
27
28
- function post_title_keywords($max = 20) {
29
- global $post;
30
- return yarpp_extract_keywords($post->post_title,$max);
31
}
32
33
- function post_body_keywords($max = 20) {
34
- global $post;
35
- $content = strip_tags(apply_filters_if_white('the_content',$post->post_content));
36
return yarpp_extract_keywords($content,$max);
37
}
38
39
- /* yarpp_cache_keywords is EXPERIMENTAL and not used.
40
- * Don't worry about it. ^^
41
- */
42
- function yarpp_cache_keywords() {
43
- global $wpdb, $post, $yarpp_debug;
44
- $body_terms = post_body_keywords();
45
- $title_terms = post_title_keywords();
46
/*
47
CREATE TABLE `wp_yarpp_keyword_cache` (
48
`ID` BIGINT( 20 ) UNSIGNED NOT NULL ,
@@ -52,15 +70,58 @@ function yarpp_cache_keywords() {
52
PRIMARY KEY ( `ID` )
53
) ENGINE = MYISAM COMMENT = 'YARPP\'s keyword cache table'
54
*/
55
- $timeout = 400;
56
-
57
- if (!$wpdb->get_var("select count(*) as count from wp_yarpp_keyword_cache where ID = $post->ID and date > date_sub(now(),interval $timeout minute)")) {
58
- $wpdb->query('set names utf8');
59
60
- $wpdb->query("insert into wp_yarpp_keyword_cache (ID,body,title) values ($post->ID,'$body_terms','$title_terms') on duplicate key update body = '$body_terms', title = '$title_terms'");
61
62
- if ($yarpp_debug) echo "<!--"."insert into wp_yarpp_keyword_cache (ID,body,title) values ($post->ID,'$body_terms','$title_terms') on duplicate key update body = '$body_terms', title = '$title_terms'"."-->";
63
- }
64
}
65
66
?>
1
<?php
2
3
+ function yarpp_extract_keywords($source,$max = 20) {
4
+ global $overusedwords;
5
6
if (function_exists('mb_split')) {
7
mb_regex_encoding(get_option('blog_charset'));
10
$wordlist = preg_split('%\s*\W+\s*%', strtolower($source));
11
12
// Build an array of the unique words and number of times they occur.
13
+ $tokens = array_count_values($wordlist);
14
15
// Remove the stop words from the list.
16
foreach ($overusedwords as $word) {
17
+ unset($tokens[$word]);
18
}
19
+ // Remove words which are only a letter
20
+ foreach (array_keys($tokens) as $word) {
21
+ if (function_exists('mb_strlen'))
22
+ if (mb_strlen($word) < 2) unset($tokens[$word]);
23
+ else
24
+ if (strlen($word) < 2) unset($tokens[$word]);
25
+ }
26
+
27
+ arsort($tokens, SORT_NUMERIC);
28
29
+ $types = array_keys($tokens);
30
31
+ if (count($types) > $max)
32
+ $types = array_slice($types, 0, $max);
33
+ return implode(' ', $types);
34
+ }
35
+
36
+ function post_title_keywords($ID,$max = 20) {
37
+ global $wpdb;
38
+ return yarpp_extract_keywords(html_entity_strip($wpdb->get_var("select post_title from $wpdb->posts where ID = $ID")),$max);
39
}
40
41
+ function html_entity_strip($html) {
42
+ $html = preg_replace('/&#x[0-9a-f]+;/','',$html);
43
+ $html = preg_replace('/&#[0-9]+;/','',$html);
44
+ $html = preg_replace('/&[a-zA-Z]+;/','',$html);
45
+ return $html;
46
}
47
48
+ function post_body_keywords($ID,$max = 20) {
49
+ global $wpdb;
50
+ $content = strip_tags(apply_filters_if_white('the_content',$wpdb->get_var("select post_content from $wpdb->posts where ID = $ID")));
51
+ //echo "<!--".get_option('blog_charset')."-->";
52
+ /*if (get_option('blog_charset') == 'UTF-8')
53
+ $content = html_entity_decode_utf8($content);
54
+ else
55
+ $content = html_entity_decode($content,ENT_QUOTES,get_option('blog_charset'));*/
56
+ $content = html_entity_strip($content);
57
return yarpp_extract_keywords($content,$max);
58
}
59
60
+ function yarpp_cache_keywords($ID) {
61
+ global $wpdb, $yarpp_debug;
62
+ $body_terms = post_body_keywords($ID);
63
+ $title_terms = post_title_keywords($ID);
64
/*
65
CREATE TABLE `wp_yarpp_keyword_cache` (
66
`ID` BIGINT( 20 ) UNSIGNED NOT NULL ,
70
PRIMARY KEY ( `ID` )
71
) ENGINE = MYISAM COMMENT = 'YARPP\'s keyword cache table'
72
*/
73
74
+ $wpdb->query('set names utf8');
75
76
+ $wpdb->query("insert into {$wpdb->prefix}yarpp_keyword_cache (ID,body,title) values ($ID,'$body_terms ','$title_terms ') on duplicate key update date = now(), body = '$body_terms ', title = '$title_terms '");
77
+
78
+ //echo "<!--"."insert into {$wpdb->prefix}yarpp_keyword_cache (ID,body,title) values ($ID,'$body_terms','$title_terms') on duplicate key update date = now(), body = '$body_terms', title = '$title_terms'"."-->";
79
+
80
+ }
81
+
82
+ function yarpp_get_cached_keywords($ID,$type='body') {
83
+ global $wpdb;
84
+ $out = $wpdb->get_var("select $type from {$wpdb->prefix}yarpp_keyword_cache where ID = $ID");
85
+ if ($out === false or $out == '')
86
+ yarpp_cache_keywords($ID);
87
+ $out = $wpdb->get_var("select $type from {$wpdb->prefix}yarpp_keyword_cache where ID = $ID");
88
+ if ($out === false or $out == '')
89
+ echo "<!--YARPP ERROR: couldn't select/create yarpp $type keywords for $ID-->";
90
+ else
91
+ return $out;
92
+ return false;
93
+ }
94
+
95
+ // replacement html_entity_decode code from php.net
96
+ // author: laurynas dot butkus at gmail dot com
97
+
98
+ function html_entity_decode_utf8($string) {
99
+ static $trans_tbl;
100
+
101
+ // replace numeric entities
102
+ $string = preg_replace('~&#x([0-9a-f]+);~ei', 'code2utf(hexdec("\\1"))', $string);
103
+ $string = preg_replace('~&#([0-9]+);~e', 'code2utf(\\1)', $string);
104
+
105
+ // replace literal entities
106
+ if (!isset($trans_tbl))
107
+ {
108
+ $trans_tbl = array();
109
+
110
+ foreach (get_html_translation_table(HTML_ENTITIES) as $val=>$key)
111
+ $trans_tbl[$key] = utf8_encode($val);
112
+ }
113
+
114
+ return strtr($string, $trans_tbl);
115
+ }
116
+
117
+ // Returns the utf string corresponding to the unicode value (from php.net, courtesy - romans@void.lv)
118
+ function code2utf($num)
119
+ {
120
+ if ($num < 128) return chr($num);
121
+ if ($num < 2048) return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
122
+ if ($num < 65536) return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
123
+ if ($num < 2097152) return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
124
+ return '';
125
}
126
127
?>
magic.php CHANGED
@@ -1,8 +1,12 @@
1
<?php
2
3
- function yarpp_sql($type,$args,$giveresults = true,$domain='website') {
4
global $wpdb, $post, $yarpp_debug;
5
6
// set $yarpp_debug
7
if (isset($_REQUEST['yarpp_debug']))
8
$yarpp_debug = true;
@@ -14,10 +18,7 @@ function yarpp_sql($type,$args,$giveresults = true,$domain='website') {
14
$domainprefix = '';
15
16
$options = array('limit'=>"${domainprefix}limit",
17
- 'order'=>"${domainprefix}order",
18
'threshold'=>'threshold',
19
- 'show_excerpt'=>"${domainprefix}show_excerpt",
20
- 'excerpt_length'=>"${domainprefix}excerpt_length",
21
'show_pass_post'=>'show_pass_post',
22
'past_only'=>'past_only',
23
'cross_relate'=>'cross_relate',
@@ -41,18 +42,12 @@ function yarpp_sql($type,$args,$giveresults = true,$domain='website') {
41
// if cross_relate is set, override the type argument and make sure both matches are accepted in the sql query
42
if ($cross_relate) $type = array('post','page');
43
44
- //yarpp_cache_keywords(); /* TEST */
45
-
46
// Fetch keywords
47
- $body_terms = post_body_keywords();
48
- $title_terms = post_title_keywords();
49
50
if ($yarpp_debug) echo "<!--TITLE TERMS: $title_terms-->"; // debug
51
if ($yarpp_debug) echo "<!--BODY TERMS: $body_terms-->"; // debug
52
-
53
- // Make sure the post is not from the future
54
- $time_difference = get_settings('gmt_offset');
55
- $now = gmdate("Y-m-d H:i:s",(time()+($time_difference*3600)));
56
57
// get weights
58
@@ -68,8 +63,6 @@ function yarpp_sql($type,$args,$giveresults = true,$domain='website') {
68
69
$totalweight = $bodyweight + $titleweight + $tagweight + $catweight;
70
71
- $weightedthresh = $threshold/($totalweight + 0.1);
72
-
73
// get disallowed categories and tags
74
75
$disterms = implode(',', array_filter(array_merge(explode(',',$discats),explode(',',$distags)),'is_numeric'));
@@ -86,20 +79,17 @@ function yarpp_sql($type,$args,$giveresults = true,$domain='website') {
86
if ($catweight)
87
$criteria['cat'] = "COUNT( DISTINCT cattax.term_taxonomy_id )";
88
89
- $newsql = "SELECT ID, post_title, post_date, post_content, post_excerpt, ";
90
91
- foreach ($criteria as $key => $value) {
92
- $newsql .= "$value as ${key}score, ";
93
- }
94
95
$newsql .= '(0';
96
foreach ($criteria as $key => $value) {
97
$newsql .= "+ $value * ".$weights[$key];
98
}
99
$newsql .= ') as score';
100
-
101
- if ($usedisterms)
102
- $newsql .= ", count(blockterm.term_id) as block";
103
104
$newsql .= "\n from $wpdb->posts \n";
105
@@ -109,14 +99,14 @@ function yarpp_sql($type,$args,$giveresults = true,$domain='website') {
109
left join $wpdb->terms as blockterm on (blocktax.term_id = blockterm.term_id and blockterm.term_id in ($disterms))\n";
110
111
if ($tagweight)
112
- $newsql .= " left JOIN $wpdb->term_relationships AS thistag ON (thistag.object_id = $post->ID )
113
left JOIN $wpdb->term_relationships AS tagrel on (tagrel.term_taxonomy_id = thistag.term_taxonomy_id
114
AND tagrel.object_id = $wpdb->posts.ID)
115
left JOIN $wpdb->term_taxonomy AS tagtax ON ( tagrel.term_taxonomy_id = tagtax.term_taxonomy_id
116
AND tagtax.taxonomy = 'post_tag')\n";
117
118
if ($catweight)
119
- $newsql .= " left JOIN $wpdb->term_relationships AS thiscat ON (thiscat.object_id = $post->ID )
120
left JOIN $wpdb->term_relationships AS catrel on (catrel.term_taxonomy_id = thiscat.term_taxonomy_id
121
AND catrel.object_id = $wpdb->posts.ID)
122
left JOIN $wpdb->term_taxonomy AS cattax ON ( catrel.term_taxonomy_id = cattax.term_taxonomy_id
@@ -124,10 +114,10 @@ function yarpp_sql($type,$args,$giveresults = true,$domain='website') {
124
125
// WHERE
126
127
- $newsql .= " where (post_status IN ( 'publish', 'static' ) and ID != '$post->ID')";
128
129
if ($past_only)
130
- $newsql .= " and post_date <= '$now' ";
131
if (!$show_pass_post)
132
$newsql .= " and post_password ='' ";
133
@@ -136,15 +126,16 @@ function yarpp_sql($type,$args,$giveresults = true,$domain='website') {
136
// GROUP BY
137
$newsql .= "\n group by id \n";
138
// HAVING
139
- $newsql .= " having score >= $threshold";
140
if ($usedisterms)
141
- $newsql .= " and block = 0";
142
143
- $newsql .= (($categories == 3)?' and catscore >= 1':'');
144
- $newsql .= (($categories == 4)?' and catscore >= 2':'');
145
- $newsql .= (($tags == 3)?' and tagscore >= 1':'');
146
- $newsql .= (($tags == 4)?' and tagscore >= 2':'');
147
- $newsql .= " order by ".(($order?$order:"score desc"))." limit ".$limit;
148
149
if (!$giveresults) {
150
$newsql = "select count(t.ID) from ($newsql) as t";
@@ -156,8 +147,15 @@ function yarpp_sql($type,$args,$giveresults = true,$domain='website') {
156
157
/* new in 2.1! the domain argument refers to {website,widget,rss}, though widget is not used yet. */
158
159
- function yarpp_related($type,$args,$echo = true,$domain = 'website') {
160
- global $wpdb, $post, $userdata;
161
get_currentuserinfo();
162
163
// set the "domain prefix", used for all the preferences.
@@ -169,15 +167,9 @@ function yarpp_related($type,$args,$echo = true,$domain = 'website') {
169
// get options
170
// note the 2.1 change... the options array changed from what you might call a "list" to a "hash"... this changes the structure of the $args to something which is, in the long term, much more useful
171
$options = array(
172
- 'before_related'=>"${domainprefix}before_related",
173
- 'after_related'=>"${domainprefix}after_related",
174
- 'before_title'=>"${domainprefix}before_title",
175
- 'after_title'=>"${domainprefix}after_title",
176
- 'show_excerpt'=>"${domainprefix}show_excerpt",
177
- 'excerpt_length'=>"${domainprefix}excerpt_length",
178
- 'before_post'=>"${domainprefix}before_post",
179
- 'after_post'=>"${domainprefix}after_post",
180
- 'no_results'=>"${domainprefix}no_results",
181
'promote_yarpp'=>"${domainprefix}promote_yarpp");
182
$optvals = array();
183
foreach (array_keys($options) as $option) {
@@ -189,44 +181,59 @@ function yarpp_related($type,$args,$echo = true,$domain = 'website') {
189
}
190
extract($optvals);
191
192
- $sql = yarpp_sql($type,$args,true,$domain);
193
- $results = $wpdb->get_results($sql);
194
-
195
$output = '';
196
- if ($results) {
197
- foreach ($results as $result) {
198
- $title = stripslashes(apply_filters('the_title', $result->post_title));
199
- $permalink = get_permalink($result->ID);
200
-
201
- $post_content = strip_tags(apply_filters_if_white('the_content',$result->post_content));
202
- //$post_content = stripslashes($post_content);
203
-
204
- $post_excerpt = strip_tags($result->post_excerpt);
205
- if ($post_excerpt == '')
206
- $post_excerpt = $post_content; //this is okay because it will be clipped later anyway.
207
-
208
- $output .= "$before_title<a href='$permalink' rel='bookmark' title='Permanent Link: $title'>$title";
209
- if ($userdata->user_level >= 8 and $domain != 'rss')
210
- $output .= ' <abbr title="'.sprintf(__('%f is the YARPP match score between the current entry and this related entry. You are seeing this value because you are logged in to WordPress as an administrator. It is not shown to regular visitors.','yarpp'),round($result->score,3)).'">('.round($result->score,3).')</abbr>';
211
- $output .= '</a>';
212
- if ($show_excerpt) {
213
- $output .= $before_post . yarpp_excerpt($post_excerpt,$excerpt_length) . $after_post;
214
- }
215
- $output .= $after_title;
216
- }
217
- $output = stripslashes(stripslashes($before_related)).$output.stripslashes(stripslashes($after_related));
218
- if ($promote_yarpp)
219
- $output .= "\n<p>".__("Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.",'yarpp')."</p>";
220
-
221
} else {
222
- $output = $no_results;
223
- }
224
if ($echo) echo $output; else return ((!empty($output))?"\n\n":'').$output;
225
}
226
227
- function yarpp_related_exist($type,$args) {
228
- global $wpdb, $post;
229
230
$options = array('threshold'=>'threshold','show_pass_post'=>'show_pass_post','past_only'=>'past_only');
231
$optvals = array();
232
foreach (array_keys($options) as $option) {
@@ -238,34 +245,38 @@ function yarpp_related_exist($type,$args) {
238
}
239
extract($optvals);
240
241
- $result = $wpdb->get_var(yarpp_sql($type,$args,false,$domain));
242
return $result > 0 ? true: false;
243
}
244
245
- /* yarpp_cache_* are EXPERIMENTAL and not used.
246
- * Don't worry about it. ^^
247
- */
248
- function yarpp_cache_exists($post_id) {
249
- global $wpdb;
250
- /*
251
- CREATE TABLE `wp_yarpp_keyword_cache` (
252
- `ID` BIGINT( 20 ) UNSIGNED NOT NULL ,
253
- `body` TEXT NOT NULL ,
254
- `title` TEXT NOT NULL ,
255
- `date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
256
- PRIMARY KEY ( `ID` )
257
- ) ENGINE = MYISAM COMMENT = 'YARPP\'s keyword cache table'
258
- */
259
- $timeout = 400;
260
-
261
- if (!$wpdb->get_var("select count(*) as count from wp_yarpp_keyword_cache where ID = $post->ID and date > date_sub(now(),interval $timeout minute)")) {
262
- $wpdb->query('set names utf8');
263
264
- $wpdb->query("insert into wp_yarpp_keyword_cache (ID,body,title) values ($post->ID,'$body_terms','$title_terms') on duplicate key update body = '$body_terms', title = '$title_terms'");
265
266
- if ($yarpp_debug) echo "<!--"."insert into wp_yarpp_keyword_cache (ID,body,title) values ($post->ID,'$body_terms','$title_terms') on duplicate key update body = '$body_terms', title = '$title_terms'"."-->";
267
}
268
}
269
270
-
271
- ?>
1
<?php
2
3
+ function yarpp_sql($type,$args,$giveresults = true,$reference_ID=false,$domain='website') {
4
global $wpdb, $post, $yarpp_debug;
5
6
+ if (is_object($post) and !$reference_ID) {
7
+ $reference_ID = $post->ID;
8
+ }
9
+
10
// set $yarpp_debug
11
if (isset($_REQUEST['yarpp_debug']))
12
$yarpp_debug = true;
18
$domainprefix = '';
19
20
$options = array('limit'=>"${domainprefix}limit",
21
'threshold'=>'threshold',
22
'show_pass_post'=>'show_pass_post',
23
'past_only'=>'past_only',
24
'cross_relate'=>'cross_relate',
42
// if cross_relate is set, override the type argument and make sure both matches are accepted in the sql query
43
if ($cross_relate) $type = array('post','page');
44
45
// Fetch keywords
46
+ $body_terms = yarpp_get_cached_keywords($reference_ID,'body');
47
+ $title_terms = yarpp_get_cached_keywords($reference_ID,'title');
48
49
if ($yarpp_debug) echo "<!--TITLE TERMS: $title_terms-->"; // debug
50
if ($yarpp_debug) echo "<!--BODY TERMS: $body_terms-->"; // debug
51
52
// get weights
53
63
64
$totalweight = $bodyweight + $titleweight + $tagweight + $catweight;
65
66
// get disallowed categories and tags
67
68
$disterms = implode(',', array_filter(array_merge(explode(',',$discats),explode(',',$distags)),'is_numeric'));
79
if ($catweight)
80
$criteria['cat'] = "COUNT( DISTINCT cattax.term_taxonomy_id )";
81
82
+ $newsql = "SELECT $reference_ID, ID, "; //post_title, post_date, post_content, post_excerpt,
83
84
+ //foreach ($criteria as $key => $value) {
85
+ // $newsql .= "$value as ${key}score, ";
86
+ //}
87
88
$newsql .= '(0';
89
foreach ($criteria as $key => $value) {
90
$newsql .= "+ $value * ".$weights[$key];
91
}
92
$newsql .= ') as score';
93
94
$newsql .= "\n from $wpdb->posts \n";
95
99
left join $wpdb->terms as blockterm on (blocktax.term_id = blockterm.term_id and blockterm.term_id in ($disterms))\n";
100
101
if ($tagweight)
102
+ $newsql .= " left JOIN $wpdb->term_relationships AS thistag ON (thistag.object_id = $reference_ID )
103
left JOIN $wpdb->term_relationships AS tagrel on (tagrel.term_taxonomy_id = thistag.term_taxonomy_id
104
AND tagrel.object_id = $wpdb->posts.ID)
105
left JOIN $wpdb->term_taxonomy AS tagtax ON ( tagrel.term_taxonomy_id = tagtax.term_taxonomy_id
106
AND tagtax.taxonomy = 'post_tag')\n";
107
108
if ($catweight)
109
+ $newsql .= " left JOIN $wpdb->term_relationships AS thiscat ON (thiscat.object_id = $reference_ID )
110
left JOIN $wpdb->term_relationships AS catrel on (catrel.term_taxonomy_id = thiscat.term_taxonomy_id
111
AND catrel.object_id = $wpdb->posts.ID)
112
left JOIN $wpdb->term_taxonomy AS cattax ON ( catrel.term_taxonomy_id = cattax.term_taxonomy_id
114
115
// WHERE
116
117
+ $newsql .= " where (post_status IN ( 'publish', 'static' ) and ID != '$reference_ID')";
118
119
if ($past_only)
120
+ $newsql .= " and post_date <= NOW() ";
121
if (!$show_pass_post)
122
$newsql .= " and post_password ='' ";
123
126
// GROUP BY
127
$newsql .= "\n group by id \n";
128
// HAVING
129
+ $safethreshold = max($threshold/2,0.1); // this is so the new calibration system works.
130
+ $newsql .= " having score >= $safethreshold";
131
if ($usedisterms)
132
+ $newsql .= " and count(blockterm.term_id) = 0";
133
134
+ $newsql .= (($categories == 3)?' and '.$criteria['cat'].' >= 1':'');
135
+ $newsql .= (($categories == 4)?' and '.$criteria['cat'].' >= 2':'');
136
+ $newsql .= (($tags == 3)?' and '.$criteria['tag'].' >= 1':'');
137
+ $newsql .= (($tags == 4)?' and '.$criteria['tag'].' >= 2':'');
138
+ $newsql .= " order by score desc limit ".$limit;
139
140
if (!$giveresults) {
141
$newsql = "select count(t.ID) from ($newsql) as t";
147
148
/* new in 2.1! the domain argument refers to {website,widget,rss}, though widget is not used yet. */
149
150
+ function yarpp_related($type,$args,$echo = true,$reference_ID=false,$domain = 'website') {
151
+ global $wpdb, $post, $userdata, $yarpp_time, $wp_query, $id, $page, $pages;
152
+
153
+ if ($yarpp_time) // if we're already in a YARPP loop, stop now.
154
+ return false;
155
+
156
+ if (is_object($post) and !$reference_ID)
157
+ $reference_ID = $post->ID;
158
+
159
get_currentuserinfo();
160
161
// set the "domain prefix", used for all the preferences.
167
// get options
168
// note the 2.1 change... the options array changed from what you might call a "list" to a "hash"... this changes the structure of the $args to something which is, in the long term, much more useful
169
$options = array(
170
+ 'use_template'=>"${domainprefix}use_template",
171
+ 'order'=>"${domainprefix}order",
172
+ 'template_file'=>"${domainprefix}template_file",
173
'promote_yarpp'=>"${domainprefix}promote_yarpp");
174
$optvals = array();
175
foreach (array_keys($options) as $option) {
181
}
182
extract($optvals);
183
184
+ if (yarpp_get_option('ad_hoc_caching') == 1)
185
+ yarpp_cache_enforce($type,$reference_ID);
186
+
187
$output = '';
188
+
189
+ $yarpp_time = true; // get ready for YARPP TIME!
190
+ // just so we can return to normal later
191
+ $current_query = $wp_query;
192
+ $current_post = $post;
193
+ $current_id = $id;
194
+ $current_page = $page;
195
+ $current_pages = $pages;
196
+
197
+ $related_query = new WP_Query();
198
+ $orders = split(' ',$order);
199
+ $related_query->query("p=$reference_ID&orderby=".$orders[0]."&order=".$orders[1]);
200
+
201
+ if ($domain == 'metabox') {
202
+ include('template-metabox.php');
203
+ } elseif ($use_template) {
204
+ ob_start();
205
+ include('templates/'.$template_file);
206
+ $output = ob_get_contents();
207
+ ob_end_clean();
208
} else {
209
+ include('template-builtin.php');
210
+ }
211
+
212
+ unset($related_query);
213
+ $yarpp_time = false; // YARPP time is over... :(
214
+
215
+ // restore the older wp_query.
216
+ $wp_query = null; $wp_query = $current_query; unset($current_query);
217
+ $post = null; $post = $current_post; unset($current_post);
218
+ $pages = null; $pages = $current_pages; unset($current_pages);
219
+ $id = $current_id; unset($current_id);
220
+ $page = $current_page; unset($current_page);
221
+
222
+ if ($promote_yarpp and $domain != 'metabox')
223
+ $output .= "\n<p>".__("Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.",'yarpp')."</p>";
224
+
225
if ($echo) echo $output; else return ((!empty($output))?"\n\n":'').$output;
226
}
227
228
+ function yarpp_related_exist($type,$args,$reference_ID=false) {
229
+ global $wpdb, $post, $yarpp_time;
230
231
+ if (is_object($post) and !$reference_ID)
232
+ $reference_ID = $post->ID;
233
+
234
+ if ($yarpp_time) // if we're already in a YARPP loop, stop now.
235
+ return false;
236
+
237
$options = array('threshold'=>'threshold','show_pass_post'=>'show_pass_post','past_only'=>'past_only');
238
$optvals = array();
239
foreach (array_keys($options) as $option) {
245
}
246
extract($optvals);
247
248
+ $result = $wpdb->get_var(yarpp_sql($type,$args,false,$reference_ID));
249
return $result > 0 ? true: false;
250
}
251
252
+ function yarpp_cache_enforce($type=array('post'),$reference_ID,$force=false) {
253
+ global $wpdb, $yarpp_debug;
254
255
+ $timeout = 600;
256
257
+ if (!$force) {
258
+ if ($wpdb->get_var("select count(*) as count from {$wpdb->prefix}yarpp_related_cache where reference_ID = $reference_ID and date > date_sub(now(),interval $timeout minute)")) {
259
+ if ($yarpp_debug) echo "<!--YARPP is using the cache right now.-->";
260
+ return false;
261
+ }
262
+ }
263
+
264
+ yarpp_cache_keywords($reference_ID);
265
+
266
+ $wpdb->query("delete from {$wpdb->prefix}yarpp_related_cache where reference_ID = $reference_ID");
267
+
268
+ $wpdb->query("insert into {$wpdb->prefix}yarpp_related_cache (reference_ID,ID,score) ".yarpp_sql($type,array(),true,$reference_ID)." on duplicate key update date = now()");
269
+ if ($wpdb->rows_affected and $yarpp_debug) echo "<!--YARPP just set the cache.-->";
270
+ if (!$wpdb->rows_affected) {
271
+ $wpdb->query("insert into {$wpdb->prefix}yarpp_related_cache (reference_ID,ID,score) values ($reference_ID,0,0)");
272
+ if (!$wpdb->rows_affected)
273
+ return false;
274
}
275
+ //$wpdb->query("delete from {$wpdb->prefix}yarpp_related_cache where date <= date_sub(now(),interval $timeout minute)");
276
+ //if ($wpdb->rows_affected)
277
+ // if ($yarpp_debug) echo "<!--$wpdb->rows_affected rows were cleared as they had expired.-->";
278
+
279
+ return true;
280
+
281
}
282
options.php CHANGED
@@ -20,7 +20,7 @@ if (!yarpp_get_option('myisam_override')) {
20
."<br />"
21
.sprintf(__("If, despite this check, you are sure that <code>%s</code> is using the MyISAM engine, press this magic button:",'yarpp'),$wpdb->posts)
22
."<br />"
23
- ."<form method='post'><input type='submit' name='myisam_override' value='"
24
.__("Trust me. Let me use MyISAM features.",'yarpp')
25
."'></input></form>"
26
."</div>";
@@ -42,17 +42,29 @@ if (substr($wp_version,0,3) < 2.5) {
42
43
if ($yarpp_myisam) {
44
if (!yarpp_enabled()) {
45
- echo '<div class="updated">';
46
if (yarpp_activate())
47
_e('The YARPP database had an error but has been fixed.','yarpp');
48
else
49
_e('The YARPP database has an error which could not be fixed.','yarpp');
50
- echo '</div>';
51
}
52
}
53
54
yarpp_reinforce(); // just in case, set default options, etc.
55
56
//compute $tagmap
57
$tagmap = array();
58
foreach ($wpdb->get_results("select $wpdb->terms.term_id, name from $wpdb->terms natural join $wpdb->term_taxonomy where $wpdb->term_taxonomy.taxonomy = 'category'") as $tag) {
@@ -92,12 +104,14 @@ if (isset($_POST['update_yarpp'])) {
92
foreach (array_keys($yarpp_binary_options) as $option) {
93
(isset($_POST[$option])) ? yarpp_set_option($option,true) : yarpp_set_option($option,false);
94
}
95
- echo '<div id="message" class="updated fade" style="background-color: rgb(207, 235, 247);"><p>'.__('Options saved!','yarpp').'</p></div>';
96
}
97
98
function checkbox($option,$desc,$tr="<tr valign='top'>
99
<th class='th-full' colspan='2' scope='row'>",$inputplus = '',$thplus='') {
100
- echo " $tr<input $inputplus type='checkbox' name='$option' value='true'". ((yarpp_get_option($option)) ? ' checked="checked"': '' )." /> $desc</th>$thplus
101
</tr>";
102
}
103
function textbox($option,$desc,$size=2,$tr="<tr valign='top'>
@@ -159,6 +173,17 @@ function select($option,$desc,$type='word',$tr="<tr valign='top'>
159
}
160
161
?>
162
<script type="text/javascript">
163
//<!--
164
@@ -174,7 +199,46 @@ css.setAttribute("rel", "stylesheet");
174
css.setAttribute("type", "text/css");
175
css.setAttribute("href", "../wp-content/plugins/yet-another-related-posts-plugin/options.css");
176
document.getElementsByTagName("head")[0].appendChild(css);
177
- document.getElementsByTagName("body")[0].setAttribute('onload',"excerpt();rss_excerpt();do_rss_display();");
178
//-->
179
</script>
180
@@ -182,7 +246,6 @@ document.getElementsByTagName("body")[0].setAttribute('onload',"excerpt();rss_ex
182
<h2>
183
<a href='https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=66G4DATK4999L&item_name=mitcho%2ecom%2fcode%3a%20donate%20to%20Michael%20Yoshitaka%20Erlewine&no_shipping=1&no_note=1&tax=0&currency_code=USD&lc=US&charset=UTF%2d8' target='_new'><img src="https://www.paypal.com/<?php echo paypal_directory(); ?>i/btn/btn_donate_SM.gif" name="submit" alt="<?php _e('Donate to mitcho (Michael Yoshitaka Erlewine) for this plugin via PayPal');?>" title="<?php _e('Donate to mitcho (Michael Yoshitaka Erlewine) for this plugin via PayPal','yarpp');?>" style="float:right" /></a>
184
185
-
186
<?php _e('Yet Another Related Posts Plugin Options','yarpp');?> <small><?php
187
188
$display_version = yarpp_get_option('version');
@@ -196,10 +259,12 @@ document.getElementsByTagName("body")[0].setAttribute('onload',"excerpt();rss_ex
196
?></small>
197
</h2>
198
199
<form method="post">
200
201
202
- <p><small><?php _e('by <a href="http://mitcho.com/code/">mitcho (Michael 芳貴 Erlewine)</a> and based on the fabulous work of <a href="http://peter.mapledesign.co.uk/weblog/archives/wordpress-related-posts-plugin">Peter Bower</a>, <a href="http://wasabi.pbwiki.com/Related%20Entries">Alexander Malov &amp; Mike Lu</a>.','yarpp');?></small></p>
203
204
205
<!--The Pool-->
@@ -209,24 +274,10 @@ document.getElementsByTagName("body")[0].setAttribute('onload',"excerpt();rss_ex
209
<table class="form-table" style="margin-top: 0">
210
<tbody>
211
<tr valign='top'>
212
- <th scope='row'><?php _e('Disallow by category:','yarpp');?></th><td><div style="overflow:auto;max-height:100px;">
213
- <?php
214
- $discats = explode(',',yarpp_get_option('discats'));
215
- array_unshift($discats,' ');
216
- foreach ($wpdb->get_results("select $wpdb->terms.term_id, name from $wpdb->terms natural join $wpdb->term_taxonomy where $wpdb->term_taxonomy.taxonomy = 'category' order by name") as $cat) {
217
- echo "<input type='checkbox' name='discats[$cat->term_id]' value='true'". (array_search($cat->term_id,$discats) ? ' checked="checked"': '' )." /> <label>$cat->name</label> ";//for='discats[$cat->term_id]' it's not HTML. :(
218
- }?>
219
- </div></td></tr>
220
<tr valign='top'>
221
<th scope='row'><?php _e('Disallow by tag:','yarpp');?></th>
222
- <td><div style="overflow:auto;max-height:100px;">
223
- <?php
224
- $distags = explode(',',yarpp_get_option('distags'));
225
- array_unshift($distags,' ');
226
- foreach ($wpdb->get_results("select $wpdb->terms.term_id, name from $wpdb->terms natural join $wpdb->term_taxonomy where $wpdb->term_taxonomy.taxonomy = 'post_tag' order by name") as $tag) {
227
- echo "<input type='checkbox' name='distags[$tag->term_id]' value='true'". (array_search($tag->term_id,$distags) ? ' checked="checked"': '' )." /> <label>$tag->name</label> ";// for='distags[$tag->term_id]'
228
- }?>
229
- </div></td></tr>
230
<?php checkbox('show_past_post',__("Show password protected posts?",'yarpp')); ?>
231
<?php checkbox('past_only',__("Show only previous posts?",'yarpp')); ?>
232
</tbody>
@@ -234,6 +285,7 @@ document.getElementsByTagName("body")[0].setAttribute('onload',"excerpt();rss_ex
234
235
<!-- Relatedness -->
236
<h3><?php _e('"Relatedness" options','yarpp');?></h3>
237
<p><?php _e('YARPP is different than the <a href="http://wasabi.pbwiki.com/Related%20Entries">previous plugins it is based on</a> as it limits the related posts list by (1) a maximum number and (2) a <em>match threshold</em>.','yarpp');?> <a href="#" class='info'><?php _e('more&gt;','yarpp');?><span><?php _e('The higher the match threshold, the more restrictive, and you get less related posts overall. The default match threshold is 5. If you want to find an appropriate match threshhold, take a look at some post\'s related posts display and their scores. You can see what kinds of related posts are being picked up and with what kind of match scores, and determine an appropriate threshold for your site.','yarpp');?></span></a></p>
238
239
<table class="form-table" style="margin-top: 0">
@@ -254,37 +306,72 @@ document.getElementsByTagName("body")[0].setAttribute('onload',"excerpt();rss_ex
254
255
<script language="javascript">
256
//<!--
257
function excerpt() {
258
- display = 'none';
259
- if (document.getElementsByName('show_excerpt')[0].checked) {
260
- display = 'table-row';
261
}
262
- document.getElementsByName('excerpted')[0].style.display = display;
263
- document.getElementsByName('excerpted')[1].style.display = display;
264
}
265
function rss_excerpt() {
266
- display = 'none';
267
- if (document.getElementsByName('rss_display')[0].checked && document.getElementsByName('rss_show_excerpt')[0].checked) {
268
- display = 'table-row';
269
- }
270
- document.getElementsByName('rss_excerpted')[0].style.display = display;
271
- document.getElementsByName('rss_excerpted')[1].style.display = display;
272
}
273
- function do_rss_display() {
274
- display = 'none';
275
- if (document.getElementsByName('rss_display')[0].checked) {
276
- rss_excerpt();
277
- display = 'table-row';
278
- }
279
- document.getElementsByName('rss_displayed')[0].style.display = display;
280
- document.getElementsByName('rss_displayed')[1].style.display = display;
281
- document.getElementsByName('rss_displayed')[2].style.display = display;
282
- document.getElementsByName('rss_displayed')[3].style.display = display;
283
- document.getElementsByName('rss_displayed')[4].style.display = display;
284
- document.getElementsByName('rss_displayed')[5].style.display = display;
285
- document.getElementsByName('rss_displayed')[6].style.display = display;
286
- document.getElementsByName('rss_displayed')[7].style.display = display;
287
}
288
//-->
289
</script>
290
@@ -294,43 +381,43 @@ document.getElementsByTagName("body")[0].setAttribute('onload',"excerpt();rss_ex
294
295
<table class="form-table" style="margin-top: 0">
296
<?php
297
- // construct the demo code based on current preferences
298
-
299
- $democode = stripslashes(yarpp_get_option('before_related',true))."
300
- ";
301
- for ($i=1;$i<=yarpp_get_option('limit');$i++) {
302
- $democode .= stripslashes(yarpp_get_option('before_title',true)).stripslashes(htmlspecialchars("<a href='".__("PERMALINK",'yarpp')."$i'>".__("RELATED TITLE",'yarpp')." $i</a>")).(yarpp_get_option('show_excerpt')?"\r\t".stripslashes(yarpp_get_option('before_post',true)).yarpp_excerpt(LOREMIPSUM,yarpp_get_option('excerpt_length')).stripslashes(yarpp_get_option('before_post',true)):'').stripslashes(yarpp_get_option('after_title',true))."
303
- ";
304
- }
305
- $democode .= stripslashes(yarpp_get_option('after_related',true));
306
- if (yarpp_get_option('promote_yarpp'))
307
- $democode .= htmlspecialchars("\n<p>".__("Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.",'yarpp')."</p>");
308
-
309
checkbox('auto_display',__("Automatically display related posts?",'yarpp')." <a href='#' class='info'>".__('more&gt;','yarpp')."<span>".__("This option automatically displays related posts right after the content on single entry pages. If this option is off, you will need to manually insert <code>related_posts()</code> or variants (<code>related_pages()</code> and <code>related_entries()</code>) into your theme files.",'yarpp')."</span></a>","<tr valign='top'>
310
- <th class='th-full' colspan='2' scope='row'>",'','<td rowspan="10" style="border-left:8px white solid;"><b>'.__("Website display code example",'yarpp').'</b><br /><small>'.__("(Update options to reload.)",'yarpp').'</small><br/>'
311
- ."<code><pre style='overflow:auto;width:350px;'>".($democode)."</pre></code></td>"); ?>
312
<?php textbox('limit',__('Maximum number of related posts:','yarpp'))?>
313
- <tr valign='top'>
314
<th><?php _e("Before / after related entries:",'yarpp');?></th>
315
<td><input name="before_related" type="text" id="before_related" value="<?php echo stripslashes(yarpp_get_option('before_related',true)); ?>" size="10" /> / <input name="after_related" type="text" id="after_related" value="<?php echo stripslashes(yarpp_get_option('after_related',true)); ?>" size="10" /><em><small> <?php _e("For example:",'yarpp');?> &lt;ol&gt;&lt;/ol&gt; or &lt;div&gt;&lt;/div&gt;</small></em>
316
</td>
317
</tr>
318
- <tr valign='top'>
319
<th><?php _e("Before / after each related entry:",'yarpp');?></th>
320
<td><input name="before_title" type="text" id="before_title" value="<?php echo stripslashes(yarpp_get_option('before_title',true)); ?>" size="10" /> / <input name="after_title" type="text" id="after_title" value="<?php echo stripslashes(yarpp_get_option('after_title',true)); ?>" size="10" /><em><small> <?php _e("For example:",'yarpp');?> &lt;li&gt;&lt;/li&gt; or &lt;dl&gt;&lt;/dl&gt;</small></em>
321
</td>
322
</tr>
323
- <?php checkbox('show_excerpt',__("Show excerpt?",'yarpp'),"<tr valign='top'><th colspan='2'>",' onclick="javascript:excerpt()"'); ?>
324
- <?php textbox('excerpt_length',__('Excerpt length (No. of words):','yarpp'),null,"<tr name='excerpted' valign='top' ".(yarpp_get_option('show_excerpt')?'':"style='display:none'").">
325
<th>")?>
326
327
- <tr name="excerpted" valign='top' <?php echo (yarpp_get_option('show_excerpt')?'':"style='display:none'")?>>
328
<th><?php _e("Before / after (Excerpt):",'yarpp');?></th>
329
<td><input name="before_post" type="text" id="before_post" value="<?php echo stripslashes(yarpp_get_option('before_post',true)); ?>" size="10" /> / <input name="after_post" type="text" id="after_post" value="<?php echo stripslashes(yarpp_get_option('after_post')); ?>" size="10" /><em><small> <?php _e("For example:",'yarpp');?> &lt;li&gt;&lt;/li&gt; or &lt;dl&gt;&lt;/dl&gt;</small></em>
330
</td>
331
</tr>
332
333
- <tr name="excerpted" valign='top'>
334
<th><?php _e("Order results:",'yarpp');?></th>
335
<td><select name="order" id="order">
336
<option value="score DESC" <?php echo (yarpp_get_option('order')=='score DESC'?' selected="selected"':'')?>><?php _e("score (high relevance to low)",'yarpp');?></option>
@@ -343,57 +430,58 @@ checkbox('auto_display',__("Automatically display related posts?",'yarpp')." <a
343
</td>
344
</tr>
345
346
- <?php textbox('no_results',__('Default display if no results:','yarpp'),'40')?>
347
<?php checkbox('promote_yarpp',__("Help promote Yet Another Related Posts Plugin?",'yarpp')
348
." <a href='#' class='info'>".__('more&gt;','yarpp')."<span>"
349
- .sprintf(__("This option will add the code %s. Try turning it on, updating your options, and see the code in the code example to the right. These links and donations are greatly appreciated.",'yarpp'),"<code>".htmlspecialchars(__("Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.",'yarpp'))."</code>")
350
."</span></a>"); ?>
351
</table>
352
353
<!-- Display options for RSS -->
354
- <h3><?php _e("Display options <small>for RSS</small>",'yarpp');?> <span style='color:red;'>NEW!</span></h3>
355
356
<table class="form-table" style="margin-top: 0">
357
<?php
358
- // construct the demo code based on current preferences for RSS
359
360
- $democode = stripslashes(yarpp_get_option('rss_before_related',true))."
361
- ";
362
- for ($i=1;$i<=yarpp_get_option('rss_limit');$i++) {
363
- $democode .= stripslashes(yarpp_get_option('rss_before_title',true)).stripslashes(htmlspecialchars("<a href='".__("RELATED TITLE",'yarpp')."$i'>".__("RELATED TITLE",'yarpp')." $i</a>")).(yarpp_get_option('rss_show_excerpt')?"\r\t".stripslashes(yarpp_get_option('rss_before_post',true)).yarpp_excerpt(LOREMIPSUM,yarpp_get_option('rss_excerpt_length')).stripslashes(yarpp_get_option('rss_before_post',true)):'').stripslashes(yarpp_get_option('rss_after_title',true))."
364
- ";
365
- }
366
- $democode .= stripslashes(yarpp_get_option('rss_after_related',true));
367
- if (yarpp_get_option('rss_promote_yarpp'))
368
- $democode .= htmlspecialchars("\n<p>".__("Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.",'yarpp')."</p>");
369
-
370
- checkbox('rss_display',__("Display related posts in feeds?",'yarpp'),"<tr valign='top'><th colspan='3'>",' onclick="javascript:do_rss_display();"');
371
- checkbox('rss_excerpt_display',__("Display related posts in the descriptions?",'yarpp')." <a href='#' class='info'>".__('more&gt;','yarpp')."<span>".__("This option displays the related posts in the RSS description fields, not just the content. If your feeds are set up to only display excerpts, however, only the description field is used, so this option is required for any display at all.",'yarpp')."</span></a>","<tr name='rss_displayed' valign='top'>
372
- <th class='th-full' colspan='2' scope='row'>",'','<td rowspan="10" style="border-left:8px white solid;"><b>'.__("RSS display code example",'yarpp').'</b><br /><small>'.__("(Update options to reload.)",'yarpp').'</small><br/>'
373
- ."<code><pre style='overflow:auto;width:350px;'>".($democode)."</pre></code></td>"); ?>
374
- <?php textbox('rss_limit',__('Maximum number of related posts:','yarpp'),2,"<tr valign='top' name='rss_displayed'>
375
<th scope='row'>")?>
376
- <tr name='rss_displayed' valign='top'>
377
<th><?php _e("Before / after related entries display:",'yarpp');?></th>
378
<td><input name="rss_before_related" type="text" id="rss_before_related" value="<?php echo stripslashes(yarpp_get_option('rss_before_related',true)); ?>" size="10" /> / <input name="rss_after_related" type="text" id="rss_after_related" value="<?php echo stripslashes(yarpp_get_option('rss_after_related',true)); ?>" size="10" /><em><small> <?php _e("For example:",'yarpp');?> &lt;ol&gt;&lt;/ol&gt; or &lt;div&gt;&lt;/div&gt;</small></em>
379
</td>
380
</tr>
381
- <tr name='rss_displayed' valign='top'>
382
<th><?php _e("Before / after each related entry:",'yarpp');?></th>
383
<td><input name="rss_before_title" type="text" id="rss_before_title" value="<?php echo stripslashes(yarpp_get_option('rss_before_title',true)); ?>" size="10" /> / <input name="rss_after_title" type="text" id="rss_after_title" value="<?php echo stripslashes(yarpp_get_option('rss_after_title',true)); ?>" size="10" /><em><small> <?php _e("For example:",'yarpp');?> &lt;li&gt;&lt;/li&gt; or &lt;dl&gt;&lt;/dl&gt;</small></em>
384
</td>
385
</tr>
386
- <?php checkbox('rss_show_excerpt',__("Show excerpt?",'yarpp'),"<tr name='rss_displayed' valign='top'><th colspan='2'>",' onclick="javascript:rss_excerpt()"'); ?>
387
- <?php textbox('rss_excerpt_length',__('Excerpt length (No. of words):','yarpp'),null,"<tr name='rss_excerpted' valign='top' ".(yarpp_get_option('rss_show_excerpt')?'':"style='display:none'").">
388
<th>")?>
389
390
- <tr name="rss_excerpted" valign='top' <?php echo (yarpp_get_option('rss_show_excerpt')?'':"style='display:none'")?>>
391
<th><?php _e("Before / after (excerpt):",'yarpp');?></th>
392
<td><input name="rss_before_post" type="text" id="rss_before_post" value="<?php echo stripslashes(yarpp_get_option('rss_before_post',true)); ?>" size="10" /> / <input name="rss_after_post" type="text" id="rss_after_post" value="<?php echo stripslashes(yarpp_get_option('rss_after_post')); ?>" size="10" /><em><small> <?php _e("For example:",'yarpp');?> &lt;li&gt;&lt;/li&gt; or &lt;dl&gt;&lt;/dl&gt;</small></em>
393
</td>
394
</tr>
395
396
- <tr name='rss_displayed' valign='top'>
397
<th><?php _e("Order results:",'yarpp');?></th>
398
<td><select name="rss_order" id="rss_order">
399
<option value="score DESC" <?php echo (yarpp_get_option('rss_order')=='score DESC'?' selected="selected"':'')?>><?php _e("score (high relevance to low)",'yarpp');?></option>
@@ -406,14 +494,86 @@ checkbox('rss_excerpt_display',__("Display related posts in the descriptions?",'
406
</td>
407
</tr>
408
409
- <?php textbox('rss_no_results',__('Default display if no results:','yarpp'),'40',"<tr valign='top' name='rss_displayed'>
410
<th scope='row'>")?>
411
<?php checkbox('rss_promote_yarpp',__("Help promote Yet Another Related Posts Plugin?",'yarpp')." <a href='#' class='info'>".__('more&gt;','yarpp')."<span>"
412
.sprintf(__("This option will add the code %s. Try turning it on, updating your options, and see the code in the code example to the right. These links and donations are greatly appreciated."),"<code>".htmlspecialchars(__("Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.",'yarpp'))."</code>")
413
- ."</span></a>","<tr valign='top' name='rss_displayed'>
414
<th class='th-full' colspan='2' scope='row'>"); ?>
415
</table>
416
417
<div>
418
<p class="submit">
419
<input type="submit" name="update_yarpp" value="<?php _e("Update options",'yarpp')?>" />
20
."<br />"
21
.sprintf(__("If, despite this check, you are sure that <code>%s</code> is using the MyISAM engine, press this magic button:",'yarpp'),$wpdb->posts)
22
."<br />"
23
+ ."<form method='post'><input type='submit' class='button' name='myisam_override' value='"
24
.__("Trust me. Let me use MyISAM features.",'yarpp')
25
."'></input></form>"
26
."</div>";
42
43
if ($yarpp_myisam) {
44
if (!yarpp_enabled()) {
45
+ echo '<div class="updated"><p>';
46
if (yarpp_activate())
47
_e('The YARPP database had an error but has been fixed.','yarpp');
48
else
49
_e('The YARPP database has an error which could not be fixed.','yarpp');
50
+ echo '</div></p>';
51
}
52
}
53
54
yarpp_reinforce(); // just in case, set default options, etc.
55
56
+ // check if the cache is complete or not.
57
+ $cache_complete = $wpdb->get_var("select (count(p.ID)-sum(c.ID IS NULL))/count(p.ID)
58
+ FROM $wpdb->posts as p
59
+ LEFT JOIN {$wpdb->prefix}yarpp_related_cache as c ON ( p.ID = c.reference_ID )
60
+ WHERE p.post_status = 'publish' ");
61
+
62
+ if ($cache_complete > 0 and $cache_complete < 1)
63
+ echo '<div class="updated fade" style="background-color: rgb(207, 235, 247);"><p>'.str_replace('<A>','<a class="thickbox" title="'.__('Related posts cache status','yarpp').'" href="#TB_inline?height=100&width=300&inlineId=yarpp-cache-status">',__('Your related posts cache is incomplete. Please build your cache from the <A>related posts status pane</a>.','yarpp')).'</p></div>';
64
+
65
+ if ($cache_complete == 0)
66
+ echo '<div class="updated fade" style="background-color: rgb(207, 235, 247);"><p>'.str_replace('<A>','<a class="thickbox" title="'.__('Related posts cache status','yarpp').'" href="#TB_inline?height=100&width=300&inlineId=yarpp-cache-status">',__('Your related posts cache is empty. Please build your cache from the <A>related posts status pane</a>.','yarpp')).'</p></div>';
67
+
68
//compute $tagmap
69
$tagmap = array();
70
foreach ($wpdb->get_results("select $wpdb->terms.term_id, name from $wpdb->terms natural join $wpdb->term_taxonomy where $wpdb->term_taxonomy.taxonomy = 'category'") as $tag) {
104
foreach (array_keys($yarpp_binary_options) as $option) {
105
(isset($_POST[$option])) ? yarpp_set_option($option,true) : yarpp_set_option($option,false);
106
}
107
+ echo '<div class="updated fade" style="background-color: rgb(207, 235, 247);"><p>'.__('Options saved!','yarpp')
108
+ .' '.str_replace('<A>','<a class="thickbox" title="'.__('Related posts cache status','yarpp').'" href="#TB_inline?height=100&width=300&inlineId=yarpp-cache-status">',
109
+ __('If you updated the "pool" options or "relatedness" options displayed, please rebuild your cache now from the <A>related posts status pane</a>.','yarpp')).'</p></div>';
110
}
111
112
function checkbox($option,$desc,$tr="<tr valign='top'>
113
<th class='th-full' colspan='2' scope='row'>",$inputplus = '',$thplus='') {
114
+ echo " $tr<input $inputplus type='checkbox' name='$option' value='true'". ((yarpp_get_option($option) == 1) ? ' checked="checked"': '' )." /> $desc</th>$thplus
115
</tr>";
116
}
117
function textbox($option,$desc,$size=2,$tr="<tr valign='top'>
173
}
174
175
?>
176
+ <div id="yarpp-dialog-container" style="display:none;">
177
+ <div>
178
+ <h3 id="yarpp-dialog-header">
179
+ <!--<img alt="" id="yarpp-dialog-icon" class="alignleft" src="<?php echo CSP_PO_BASE_URL; ?>/images/gettext.gif" />-->
180
+ <span id="yarpp-dialog-caption" class="alignleft"><?php _e('Edit Catalog Entry','yarpp'); ?></span>
181
+ <img alt="" id="yarpp-dialog-cancel" class="alignright clickable" title="<?php _e('close', 'yarpp'); ?>" src="<?php echo WP_CONTENT_DIR."/plugins/yet-another-related-posts-plugin/i/close.gif"; ?>" onclick="yarpp_cancel_dialog();" />
182
+ <br class="clear" />
183
+ </h3>
184
+ <div id="yarpp-dialog-body"></div>
185
+ </div>
186
+ </div><!-- yarpp-dialog-container closed -->
187
<script type="text/javascript">
188
//<!--
189
199
css.setAttribute("type", "text/css");
200
css.setAttribute("href", "../wp-content/plugins/yet-another-related-posts-plugin/options.css");
201
document.getElementsByTagName("head")[0].appendChild(css);
202
+
203
+ function load_display_demo_web() {
204
+ jQuery.ajax({type:'POST',
205
+ url:'/blog/wp-admin/admin-ajax.php',
206
+ data:'action=yarpp_display_demo_web',
207
+ beforeSend:function(){jQuery('#display_demo_web').eq(0).html('<img src="../wp-content/plugins/yet-another-related-posts-plugin/i/spin.gif" alt="loading..."/>')},
208
+ success:function(html){jQuery('#display_demo_web').eq(0).html('<pre>'+html+'</pre>')},
209
+ dataType:'html'}
210
+ )
211
+ }
212
+
213
+ function load_display_demo_rss() {
214
+ jQuery.ajax({type:'POST',
215
+ url:'/blog/wp-admin/admin-ajax.php',
216
+ data:'action=yarpp_display_demo_rss',
217
+ beforeSend:function(){jQuery('#display_demo_rss').eq(0).html('<img src="../wp-content/plugins/yet-another-related-posts-plugin/i/spin.gif" alt="loading..."/>')},
218
+ success:function(html){jQuery('#display_demo_rss').eq(0).html('<pre>'+html+'</pre>')},
219
+ dataType:'html'}
220
+ )
221
+ }
222
+
223
+ function load_display_distags() {
224
+ jQuery.ajax({type:'POST',
225
+ url:'/blog/wp-admin/admin-ajax.php',
226
+ data:'action=yarpp_display_distags',
227
+ beforeSend:function(){jQuery('#display_distags').eq(0).html('<img src="../wp-content/plugins/yet-another-related-posts-plugin/i/spin.gif" alt="loading..."/>')},
228
+ success:function(html){jQuery('#display_distags').eq(0).html(html)},
229
+ dataType:'html'}
230
+ )
231
+ }
232
+
233
+ function load_display_discats() {
234
+ jQuery.ajax({type:'POST',
235
+ url:'/blog/wp-admin/admin-ajax.php',
236
+ data:'action=yarpp_display_discats',
237
+ beforeSend:function(){jQuery('#display_discats').eq(0).html('<img src="../wp-content/plugins/yet-another-related-posts-plugin/i/spin.gif" alt="loading..."/>')},
238
+ success:function(html){jQuery('#display_discats').eq(0).html(html)},
239
+ dataType:'html'}
240
+ )
241
+ }
242
//-->
243
</script>
244
246
<h2>
247
<a href='https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=66G4DATK4999L&item_name=mitcho%2ecom%2fcode%3a%20donate%20to%20Michael%20Yoshitaka%20Erlewine&no_shipping=1&no_note=1&tax=0&currency_code=USD&lc=US&charset=UTF%2d8' target='_new'><img src="https://www.paypal.com/<?php echo paypal_directory(); ?>i/btn/btn_donate_SM.gif" name="submit" alt="<?php _e('Donate to mitcho (Michael Yoshitaka Erlewine) for this plugin via PayPal');?>" title="<?php _e('Donate to mitcho (Michael Yoshitaka Erlewine) for this plugin via PayPal','yarpp');?>" style="float:right" /></a>
248
249
<?php _e('Yet Another Related Posts Plugin Options','yarpp');?> <small><?php
250
251
$display_version = yarpp_get_option('version');
259
?></small>
260
</h2>
261
262
+ <?php echo "<div id='yarpp-version' style='display:none;'>".yarpp_get_option('version')."</div>"; ?>
263
+
264
<form method="post">
265
266
267
+ <p><small><?php _e('by <a href="http://mitcho.com/code/">mitcho (Michael 芳貴 Erlewine)</a>','yarpp');?>. <?php _e('Follow <a href="http://twitter.com/yarpp/">Yet Another Related Posts Plugin on Twitter</a>','yarpp');?>.</small></p>
268
269
270
<!--The Pool-->
274
<table class="form-table" style="margin-top: 0">
275
<tbody>
276
<tr valign='top'>
277
+ <th scope='row'><?php _e('Disallow by category:','yarpp');?></th><td><div id='display_discats' style="overflow:auto;max-height:100px;"></div></td></tr>
278
<tr valign='top'>
279
<th scope='row'><?php _e('Disallow by tag:','yarpp');?></th>
280
+ <td><div id='display_distags' style="overflow:auto;max-height:100px;"></div></td></tr>
281
<?php checkbox('show_past_post',__("Show password protected posts?",'yarpp')); ?>
282
<?php checkbox('past_only',__("Show only previous posts?",'yarpp')); ?>
283
</tbody>
285
286
<!-- Relatedness -->
287
<h3><?php _e('"Relatedness" options','yarpp');?></h3>
288
+
289
<p><?php _e('YARPP is different than the <a href="http://wasabi.pbwiki.com/Related%20Entries">previous plugins it is based on</a> as it limits the related posts list by (1) a maximum number and (2) a <em>match threshold</em>.','yarpp');?> <a href="#" class='info'><?php _e('more&gt;','yarpp');?><span><?php _e('The higher the match threshold, the more restrictive, and you get less related posts overall. The default match threshold is 5. If you want to find an appropriate match threshhold, take a look at some post\'s related posts display and their scores. You can see what kinds of related posts are being picked up and with what kind of match scores, and determine an appropriate threshold for your site.','yarpp');?></span></a></p>
290
291
<table class="form-table" style="margin-top: 0">
306
307
<script language="javascript">
308
//<!--
309
+ function template() {
310
+ if (jQuery('.template').eq(0).attr('checked')) {
311
+ jQuery('.templated').show();
312
+ jQuery('.not_templated').hide();
313
+ } else {
314
+ jQuery('.templated').hide();
315
+ jQuery('.not_templated').show();
316
+ }
317
+ excerpt();
318
+ }
319
function excerpt() {
320
+ if (!jQuery('.template').eq(0).attr('checked') && jQuery('.show_excerpt').eq(0).attr('checked'))
321
+ jQuery('.excerpted').show();
322
+ else
323
+ jQuery('.excerpted').hide();
324
+ }
325
+
326
+ function rss_display() {
327
+ if (jQuery('.rss_display').eq(0).attr('checked'))
328
+ jQuery('.rss_displayed').show();
329
+ else
330
+ jQuery('.rss_displayed').hide();
331
+ rss_excerpt();
332
+ }
333
+ function rss_template() {
334
+ if (jQuery('.rss_template').eq(0).attr('checked')) {
335
+ jQuery('.rss_templated').show();
336
+ jQuery('.rss_not_templated').hide();
337
+ } else {
338
+ jQuery('.rss_templated').hide();
339
+ jQuery('.rss_not_templated').show();
340
}
341
+ rss_excerpt();
342
}
343
function rss_excerpt() {
344
+ if (jQuery('.rss_display').eq(0).attr('checked') && jQuery('.rss_show_excerpt').eq(0).attr('checked'))
345
+ jQuery('.rss_excerpted').show();
346
+ else
347
+ jQuery('.rss_excerpted').hide();
348
}
349
+
350
+ function yarpp_js_init() {
351
+ template();
352
+ rss_template();
353
+ load_display_discats();
354
+ load_display_distags();
355
+ load_display_demo_web();
356
+ load_display_demo_rss();
357
+ jQuery('#build-cache-button').click(function() {
358
+ jQuery('#yarpp-cache-message').hide();
359
+ jQuery('#build-cache-button').hide();
360
+ jQuery('#build-display').css('display','block');
361
+ yarppBuildRequest();
362
+ });
363
+
364
+ version = jQuery('#yarpp-version').html();
365
+ jQuery.post('http://mitcho.com/code/yarpp/checkversion.php',{version:version},function(json){
366
+ if (json.result == 'newbeta')
367
+ jQuery('#yarpp-version').addClass('updated').html(<?php echo "'<p>".str_replace('VERSION',"'+json.beta.version+'",str_replace('<A>',"<a href=\"'+json.beta.url+'\">",__("There is a new beta (VERSION) of Yet Another Related Posts Plugin. You can <A>download it here</a> at your own risk.","yarpp")))."</p>'"?>).show();
368
+ if (json.result == 'new')
369
+ jQuery('#yarpp-version').addClass('updated').html(<?php echo "'<p>".str_replace('VERSION',"'+json.current.version+'",str_replace('<A>',"<a href=\"'+json.current.url+'\">",__("There is a new version (VERSION) of Yet Another Related Posts Plugin available! You can <A>download it here</a>.","yarpp")))."</p>'"?>).show();
370
+ },'json');
371
}
372
+
373
+ jQuery(document).ready(yarpp_js_init);
374
+
375
//-->
376
</script>
377
381
382
<table class="form-table" style="margin-top: 0">
383
<?php
384
checkbox('auto_display',__("Automatically display related posts?",'yarpp')." <a href='#' class='info'>".__('more&gt;','yarpp')."<span>".__("This option automatically displays related posts right after the content on single entry pages. If this option is off, you will need to manually insert <code>related_posts()</code> or variants (<code>related_pages()</code> and <code>related_entries()</code>) into your theme files.",'yarpp')."</span></a>","<tr valign='top'>
385
+ <th class='th-full' colspan='2' scope='row'>",'','<td rowspan="11" style="border-left:8px white solid;"><b>'.__("Website display code example",'yarpp').'</b><br /><small>'.__("(Update options to reload.)",'yarpp').'</small><br/>'
386
+ ."<div id='display_demo_web' style='overflow:auto;width:350px;'></div></td>");?>
387
+
388
<?php textbox('limit',__('Maximum number of related posts:','yarpp'))?>
389
+ <?php checkbox('use_template',__("Display using a custom template file",'yarpp')." <span style='color:red;'>NEW!</span> <a href='#' class='info'>".__('more&gt;','yarpp')."<span>".__("This advanced option gives you full power to customize how your related posts are displayed. Templates (in the <code>yet-another-related-posts-plugin/templates</code> directory) are written in PHP.",'yarpp')."</span></a>","<tr valign='top'><th colspan='2'>",' class="template" onclick="javascript:template()"'); ?>
390
+ <tr valign='top' class='templated'>
391
+ <th><?php _e("Template file:",'yarpp');?></th>
392
+ <td>
393
+ <select name="template_file" id="template_file">
394
+ <?php foreach (glob(WP_CONTENT_DIR.'/plugins/yet-another-related-posts-plugin/templates/*.php') as $template): ?>
395
+ <option value='<?php echo htmlspecialchars(basename($template))?>'><?php echo htmlspecialchars(basename($template))?></option>
396
+ <?php endforeach; ?>
397
+ </select>
398
+ </td>
399
+ </tr>
400
+ <tr valign='top' class='not_templated'>
401
<th><?php _e("Before / after related entries:",'yarpp');?></th>
402
<td><input name="before_related" type="text" id="before_related" value="<?php echo stripslashes(yarpp_get_option('before_related',true)); ?>" size="10" /> / <input name="after_related" type="text" id="after_related" value="<?php echo stripslashes(yarpp_get_option('after_related',true)); ?>" size="10" /><em><small> <?php _e("For example:",'yarpp');?> &lt;ol&gt;&lt;/ol&gt; or &lt;div&gt;&lt;/div&gt;</small></em>
403
</td>
404
</tr>
405
+ <tr valign='top' class='not_templated'>
406
<th><?php _e("Before / after each related entry:",'yarpp');?></th>
407
<td><input name="before_title" type="text" id="before_title" value="<?php echo stripslashes(yarpp_get_option('before_title',true)); ?>" size="10" /> / <input name="after_title" type="text" id="after_title" value="<?php echo stripslashes(yarpp_get_option('after_title',true)); ?>" size="10" /><em><small> <?php _e("For example:",'yarpp');?> &lt;li&gt;&lt;/li&gt; or &lt;dl&gt;&lt;/dl&gt;</small></em>
408
</td>
409
</tr>
410
+ <?php checkbox('show_excerpt',__("Show excerpt?",'yarpp'),"<tr class='not_templated' valign='top'><th colspan='2'>",' class="show_excerpt" onclick="javascript:excerpt()"'); ?>
411
+ <?php textbox('excerpt_length',__('Excerpt length (No. of words):','yarpp'),null,"<tr class='excerpted' valign='top'>
412
<th>")?>
413
414
+ <tr class="excerpted" valign='top'>
415
<th><?php _e("Before / after (Excerpt):",'yarpp');?></th>
416
<td><input name="before_post" type="text" id="before_post" value="<?php echo stripslashes(yarpp_get_option('before_post',true)); ?>" size="10" /> / <input name="after_post" type="text" id="after_post" value="<?php echo stripslashes(yarpp_get_option('after_post')); ?>" size="10" /><em><small> <?php _e("For example:",'yarpp');?> &lt;li&gt;&lt;/li&gt; or &lt;dl&gt;&lt;/dl&gt;</small></em>
417
</td>
418
</tr>
419
420
+ <tr valign='top'>
421
<th><?php _e("Order results:",'yarpp');?></th>
422
<td><select name="order" id="order">
423
<option value="score DESC" <?php echo (yarpp_get_option('order')=='score DESC'?' selected="selected"':'')?>><?php _e("score (high relevance to low)",'yarpp');?></option>
430
</td>
431
</tr>
432
433
+ <?php textbox('no_results',__('Default display if no results:','yarpp'),'40',"<tr class='not_templated' valign='top'>
434
+ <th>")?>
435
<?php checkbox('promote_yarpp',__("Help promote Yet Another Related Posts Plugin?",'yarpp')
436
." <a href='#' class='info'>".__('more&gt;','yarpp')."<span>"
437
+ .sprintf(__("This option will add the code %s. Try turning it on, updating your options, and see the code in the code example to the right. These links and donations are greatly appreciated."),"<code>".htmlspecialchars(__("Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.",'yarpp'))."</code>")
438
."</span></a>"); ?>
439
</table>
440
441
<!-- Display options for RSS -->
442
+ <h3><?php _e("Display options <small>for RSS</small>",'yarpp');?></h3>
443
444
<table class="form-table" style="margin-top: 0">
445
<?php
446
447
+ checkbox('rss_display',__("Display related posts in feeds?",'yarpp')." <a href='#' class='info'>".__('more&gt;','yarpp')."<span>".__("This option displays related posts at the end of each item in your RSS and Atom feeds. No template changes are needed.",'yarpp')."</span></a>","<tr valign='top'><th colspan='3'>",' class="rss_display" onclick="javascript:rss_display();"');
448
+ checkbox('rss_excerpt_display',__("Display related posts in the descriptions?",'yarpp')." <a href='#' class='info'>".__('more&gt;','yarpp')."<span>".__("This option displays the related posts in the RSS description fields, not just the content. If your feeds are set up to only display excerpts, however, only the description field is used, so this option is required for any display at all.",'yarpp')."</span></a>","<tr class='rss_displayed' valign='top'>
449
+ <th class='th-full' colspan='2' scope='row'>",'','<td rowspan="9" style="border-left:8px white solid;"><b>'.__("RSS display code example",'yarpp').'</b><br /><small>'.__("(Update options to reload.)",'yarpp').'</small><br/>'
450
+ ."<div id='display_demo_rss' style='overflow:auto;width:350px;'></div></td>"); ?>
451
+ <?php checkbox('rss_use_template',__("Display using a custom template file",'yarpp')." <span style='color:red;'>NEW!</span> <a href='#' class='info'>".__('more&gt;','yarpp')."<span>".__("This advanced option gives you full power to customize how your related posts are displayed. Templates (in the <code>yet-another-related-posts-plugin/templates</code> directory) are written in PHP.",'yarpp')."</span></a>","<tr valign='top'><th colspan='2'>",' class="rss_template" onclick="javascript:rss_template()"'); ?>
452
+ <tr valign='top' class='rss_templated'>
453
+ <th><?php _e("Template file:",'yarpp');?></th>
454
+ <td>
455
+ <select name="rss_template_file" id="template_file">
456
+ <?php foreach (glob(WP_CONTENT_DIR.'/plugins/yet-another-related-posts-plugin/templates/*.php') as $template): ?>
457
+ <option value='<?php echo htmlspecialchars(basename($template))?>'><?php echo htmlspecialchars(basename($template))?></option>
458
+ <?php endforeach; ?>
459
+ </select>
460
+ </td>
461
+ </tr>
462
+ <?php textbox('rss_limit',__('Maximum number of related posts:','yarpp'),2,"<tr valign='top' class='rss_not_templated'>
463
<th scope='row'>")?>
464
+ <tr class='rss_not_templated' valign='top'>
465
<th><?php _e("Before / after related entries display:",'yarpp');?></th>
466
<td><input name="rss_before_related" type="text" id="rss_before_related" value="<?php echo stripslashes(yarpp_get_option('rss_before_related',true)); ?>" size="10" /> / <input name="rss_after_related" type="text" id="rss_after_related" value="<?php echo stripslashes(yarpp_get_option('rss_after_related',true)); ?>" size="10" /><em><small> <?php _e("For example:",'yarpp');?> &lt;ol&gt;&lt;/ol&gt; or &lt;div&gt;&lt;/div&gt;</small></em>
467
</td>
468
</tr>
469
+ <tr class='rss_not_templated' valign='top'>
470
<th><?php _e("Before / after each related entry:",'yarpp');?></th>
471
<td><input name="rss_before_title" type="text" id="rss_before_title" value="<?php echo stripslashes(yarpp_get_option('rss_before_title',true)); ?>" size="10" /> / <input name="rss_after_title" type="text" id="rss_after_title" value="<?php echo stripslashes(yarpp_get_option('rss_after_title',true)); ?>" size="10" /><em><small> <?php _e("For example:",'yarpp');?> &lt;li&gt;&lt;/li&gt; or &lt;dl&gt;&lt;/dl&gt;</small></em>
472
</td>
473
</tr>
474
+ <?php checkbox('rss_show_excerpt',__("Show excerpt?",'yarpp'),"<tr class='rss_not_templated' valign='top'><th colspan='2'>",' class="rss_show_excerpt" onclick="javascript:rss_excerpt()"'); ?>
475
+ <?php textbox('rss_excerpt_length',__('Excerpt length (No. of words):','yarpp'),null,"<tr class='rss_excerpted' valign='top'>
476
<th>")?>
477
478
+ <tr class="rss_excerpted" valign='top'>
479
<th><?php _e("Before / after (excerpt):",'yarpp');?></th>
480
<td><input name="rss_before_post" type="text" id="rss_before_post" value="<?php echo stripslashes(yarpp_get_option('rss_before_post',true)); ?>" size="10" /> / <input name="rss_after_post" type="text" id="rss_after_post" value="<?php echo stripslashes(yarpp_get_option('rss_after_post')); ?>" size="10" /><em><small> <?php _e("For example:",'yarpp');?> &lt;li&gt;&lt;/li&gt; or &lt;dl&gt;&lt;/dl&gt;</small></em>
481
</td>
482
</tr>
483
484
+ <tr class='rss_displayed' valign='top'>
485
<th><?php _e("Order results:",'yarpp');?></th>
486
<td><select name="rss_order" id="rss_order">
487
<option value="score DESC" <?php echo (yarpp_get_option('rss_order')=='score DESC'?' selected="selected"':'')?>><?php _e("score (high relevance to low)",'yarpp');?></option>
494
</td>
495
</tr>
496
497
+ <?php textbox('rss_no_results',__('Default display if no results:','yarpp'),'40',"<tr valign='top' class='rss_not_templated'>
498
<th scope='row'>")?>
499
<?php checkbox('rss_promote_yarpp',__("Help promote Yet Another Related Posts Plugin?",'yarpp')." <a href='#' class='info'>".__('more&gt;','yarpp')."<span>"
500
.sprintf(__("This option will add the code %s. Try turning it on, updating your options, and see the code in the code example to the right. These links and donations are greatly appreciated."),"<code>".htmlspecialchars(__("Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.",'yarpp'))."</code>")
501
+ ."</span></a>","<tr valign='top' class='rss_displayed'>
502
<th class='th-full' colspan='2' scope='row'>"); ?>
503
</table>
504
505
+ <h3><?php _e('Advanced','yarpp');?> <span style='color:red;'>NEW!</span></h3>
506
+
507
+ <table class="form-table" style="margin-top: 0">
508
+ <tr valign='top' colspan='2'><td><input class="thickbox button" type="button" value="<?php _e("Show cache status",'yarpp');?>" title="<?php _e('Related posts cache status','yarpp');?>" alt="#TB_inline?height=100&width=300&inlineId=yarpp-cache-status"/>
509
+ <?php checkbox('ad_hoc_caching',__("When the cache is incomplete, compute related posts on the fly?",'yarpp')." <a href='#' class='info'>".__('more&gt;','yarpp')."<span>"
510
+ .__("If a displayed post's related posts have not cached and this option is on, YARPP will compute them on the fly. Do not turn this option on if you have a high-traffic site.<br />If this option is off and a post's related posts have not been cached, it will display as if it has no related posts.",'yarpp')
511
+ ."</span></a>"); ?>
512
+ </table>
513
+
514
+ <script type='text/javascript'>
515
+ //<!--
516
+ time=0;i=0;m=0;id=0;
517
+ function yarppBuildRequest() {
518
+ jQuery.ajax({
519
+ url:'<?php echo get_option('siteurl') ;?>/wp-admin/admin-ajax.php',
520
+ type: 'post',
521
+ data: {action:'yarpp_build_cache_action',i:i,m:m,id:id},
522
+ dataType: 'json',
523
+ timeout: 10000,
524
+ success: function (json) {
525
+ if (json.result == 'success') {
526
+ i = json.i;
527
+ m = json.m;
528
+ id = json.id;
529
+ time = time + parseFloat(json.time);
530
+ var remaining = Math.floor((m-i)*(time/i));
531
+ var min = Math.floor(remaining/60);
532
+ var sec = Math.floor(remaining - 60*min);
533
+ if (i < m) {
534
+ jQuery('#yarpp-bar').css('width',json.percent+'%');
535
+ jQuery('#yarpp-percentage').html(json.percent+'%');
536
+ jQuery('#yarpp-latest').html(json.title);
537
+ if (min > 0) {
538
+ jQuery('#yarpp-time').html(<?php echo str_replace('SEC',"'+sec+'",str_replace('MIN',"'+min+'",__("'MIN minute(s) and SEC second(s) remaining'",'yarpp')));?>);
539
+ } else {
540
+ jQuery('#yarpp-time').html(<?php echo str_replace('SEC',"'+sec+'",__("'SEC second(s) remaining'",'yarpp'));?>);
541
+ }
542
+ yarppBuildRequest();
543
+ } else {
544
+ jQuery('#build-display').html('<p><?php _e("Your related posts cache is now complete.",'yarpp');?><br/><small><?php echo str_replace('SEC',"'+(Math.floor(time*10)/10)+'",__('The SQL queries took SEC seconds.','yarpp'));?></small></p>');
545
+ }
546
+ return;
547
+ }
548
+ if (json.result == 'error') {
549
+ i = json.i;
550
+ m = json.m;
551
+ id = json.id;
552
+ }
553
+ jQuery('#yarpp-latest').html('<?php echo str_replace('TITLE',"'+json.title+'",__('There was an error while constructing the related posts for TITLE','yarpp'))?>');
554
+ jQuery('#build-cache-button').show().val('<?php _e("try to continue");?>');
555
+ },
556
+ error: function(json) {
557
+ jQuery('#yarpp-latest').html('<?php echo str_replace('TITLE',"'+json.title+'",__('There was an error while constructing the related posts for TITLE','yarpp'))?>');
558
+ jQuery('#build-cache-button').show().val('<?php _e("try to continue");?>');
559
+ }
560
+ });
561
+ return false;
562
+ }
563
+ //-->
564
+ </script>
565
+
566
+ <div id='yarpp-cache-status' style='display:none;'><p id='yarpp-cache-message'><?php echo str_replace('PERCENT',floor($cache_complete * 1000)/10,__("Your related posts cache is PERCENT% complete.",'yarpp'));?></p>
567
+ <center><input type='button' class='button' id='build-cache-button' value='build the cache now'/></center>
568
+ <div id='build-display' style='display:none;margin-top:15px;'>
569
+ <div class="progress-container" style='border: 1px solid #ccc; width: 200px; margin: 2px 5px 2px 0; padding: 1px; float: left; background: white;'>
570
+ <div id='yarpp-bar' style="width: 0%; height: 12px; background-color: #21759B;">&nbsp;</div>
571
+ </div><div id='yarpp-percentage'>0%</div>
572
+ <p style='font-size: .8em' id='yarpp-latest'><?php _e('starting...','yarpp');?></p>
573
+ <p style='font-size: .8em' id='yarpp-time'></p>
574
+ </div>
575
+ </div>
576
+
577
<div>
578
<p class="submit">
579
<input type="submit" name="update_yarpp" value="<?php _e("Update options",'yarpp')?>" />
readme.txt CHANGED
@@ -7,7 +7,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=66G4D
7
Tags: related, posts, post, pages, page, RSS, feed, feeds
8
Requires at least: 2.3
9
Tested up to: 2.7
10
- Stable tag: 2.1.5
11
12
Returns a list of the related entries based on a unique algorithm using titles, post bodies, tags, and categories. Now with RSS feed support!
13
@@ -15,13 +15,12 @@ Returns a list of the related entries based on a unique algorithm using titles,
15
16
Yet Another Related Posts Plugin (YARPP) gives you a list of posts and/or pages related to the current entry, introducing the reader to other relevant content on your site. Key features include:
17
18
- 1. *Limiting by a threshold*: Peter Bowyer did the great work of making the algorithm use MySQL's [fulltext search](http://dev.mysql.com/doc/en/Fulltext_Search.html) score to identify related posts. But it just displayed, for example, the top 5 most "relevant" entries, even if some of them weren't at all relevant. Now you can set a threshold limit for relevance, and you get more related posts if there are more related posts and less if there are less. Ha!
19
- 2. *Using tags and categories*: **New in 2.0!** The new 2.0 algorithm uses tags and categories. The new options screen puts you in control of how these factors should be used.
20
- 3. *Related posts in RSS feeds*: **New in 2.1!** Display related posts in your RSS and Atom feeds with custom display options.
21
- 4. *Disallowing certain tags or categories*: **New in 2.0!** You can choose certain tags or categories as disallowed, meaning any page or post with such tags or categories will not be served up by the plugin.
22
- 5. *Related posts and pages*: **New in 1.1!** Puts you in control of pulling up related posts, pages, or both.
23
- 6. *Simple installation*: **New in 1.5!** Automatically displays related posts after content on single entry pages without any theme tinkering.
24
- 7. *Miscellany*: a nicer options screen (including a sample display of the code that is produced **New in 2.0**), displaying the fulltext match score on output for admins, an option to allow related posts from the future, a couple bug fixes, etc.
25
26
== Installation ==
27
@@ -226,11 +225,12 @@ If you are a bilingual speaker of English and another language and an avid user
226
* Some localization bugfixes
227
* Localizations:
228
* Japanese (`ja`) by myself ([mitcho (Michael Yoshitaka Erlewine)](http://mitcho.com))
229
-
230
== Future versions ==
231
232
The following feature requests have been made and may be incorporated into a future release. If you have a bug fix, please start a new thread on [the Wordpress.org forums](http://wordpress.org/tags/yet-another-related-posts-plugin).
233
234
- * More customizeable displays so that you can, for example, add the date and comment count in the excerpt ([by request](http://wordpress.org/support/topic/156231))
235
* More localizations
236
* Sentece-aware excerpts, [by request](http://wordpress.org/support/topic/162465)
7
Tags: related, posts, post, pages, page, RSS, feed, feeds
8
Requires at least: 2.3
9
Tested up to: 2.7
10
+ Stable tag: 2.1.6
11
12
Returns a list of the related entries based on a unique algorithm using titles, post bodies, tags, and categories. Now with RSS feed support!
13
15
16
Yet Another Related Posts Plugin (YARPP) gives you a list of posts and/or pages related to the current entry, introducing the reader to other relevant content on your site. Key features include:
17
18
+ 1. *An advanced and versatile algorithm*: Using a customizable algorithm considering post titles, content, tags, and categories, YARPP calculates a "match score" for each pair of posts on your blog. You choose the threshold limit for relevance and you get more related posts if there are more related posts and less if there are less.
19
+ 2. *Templating*: **New in 3.0!** A new [templating system](http://mitcho.com/blog/projects/yarpp-3-templatesyarpp-3-templates/) puts you in charge of how your posts are displayed.
20
+ 3. *Caching*: **New in 3.0!** YARPP now caches the related posts for all the posts and thus has significantly improved performance over versions 2.x.
21
+ 4. *Related posts in RSS feeds*: **New in 2.1!** Display related posts in your RSS and Atom feeds with custom display options.
22
+ 5. *Disallowing certain tags or categories*: **New in 2.0!** You can choose certain tags or categories as disallowed, meaning any page or post with such tags or categories will not be served up by the plugin.
23
+ 6. *Related posts and pages*: **New in 1.1!** Puts you in control of pulling up related posts, pages, or both.
24
25
== Installation ==
26
225
* Some localization bugfixes
226
* Localizations:
227
* Japanese (`ja`) by myself ([mitcho (Michael Yoshitaka Erlewine)](http://mitcho.com))
228
+ * 2.1.6
229
+ * Versioning bugfix - same as 2.1.5
230
+
231
== Future versions ==
232
233
The following feature requests have been made and may be incorporated into a future release. If you have a bug fix, please start a new thread on [the Wordpress.org forums](http://wordpress.org/tags/yet-another-related-posts-plugin).
234
235
* More localizations
236
* Sentece-aware excerpts, [by request](http://wordpress.org/support/topic/162465)
related-functions.php CHANGED
@@ -4,28 +4,28 @@
4
5
// Since YARPP 2.1, these functions receive (optionally) one array argument. See the documentation for instructions on how to customize their output.
6
7
- function related_posts($a = array(),$echo=true) {
8
- return yarpp_related(array('post'),$a,$echo);
9
}
10
11
- function related_pages($a = array(),$echo=true) {
12
- return yarpp_related(array('page'),$a,$echo);
13
}
14
15
- function related_entries($a = array(),$echo=true) {
16
- return yarpp_related(array('page','post'),$a,$echo);
17
}
18
19
- function related_posts_exist($a = array()) {
20
- return yarpp_related_exist(array('post'),$a);
21
}
22
23
- function related_pages_exist($a = array()) {
24
- return yarpp_related_exist(array('page'),$a);
25
}
26
27
- function related_entries_exist($a = array()) {
28
- return yarpp_related_exist(array('page','post'),$a);
29
}
30
31
?>
4
5
// Since YARPP 2.1, these functions receive (optionally) one array argument. See the documentation for instructions on how to customize their output.
6
7
+ function related_posts($a = array(),$echo=true,$reference_ID=false) {
8
+ return yarpp_related(array('post'),$a,$echo,$reference_ID);
9
}
10
11
+ function related_pages($a = array(),$echo=true,$reference_ID=false) {
12
+ return yarpp_related(array('page'),$a,$echo,$reference_ID);
13
}
14
15
+ function related_entries($a = array(),$echo=true,$reference_ID=false) {
16
+ return yarpp_related(array('page','post'),$a,$echo,$reference_ID);
17
}
18
19
+ function related_posts_exist($a = array(),$reference_ID=false) {
20
+ return yarpp_related_exist(array('post'),$a,$reference_ID);
21
}
22
23
+ function related_pages_exist($a = array(),$reference_ID=false) {
24
+ return yarpp_related_exist(array('page'),$a,$reference_ID);
25
}
26
27
+ function related_entries_exist($a = array(),$reference_ID=false) {
28
+ return yarpp_related_exist(array('page','post'),$a,$reference_ID);
29
}
30
31
?>
services.php ADDED
@@ -0,0 +1,97 @@
1
+ <?php
2
+
3
+ // setup the ajax action hooks
4
+ if (function_exists('add_action')) {
5
+ add_action('wp_ajax_yarpp_display_discats', 'yarpp_ajax_display_discats');
6
+ add_action('wp_ajax_yarpp_display_distags', 'yarpp_ajax_display_distags');
7
+ add_action('wp_ajax_yarpp_display_demo_web', 'yarpp_ajax_display_demo_web');
8
+ add_action('wp_ajax_yarpp_display_demo_rss', 'yarpp_ajax_display_demo_rss');
9
+ add_action('wp_ajax_yarpp_build_cache_action', 'yarpp_build_cache');
10
+ }
11
+
12
+ function yarpp_ajax_display_discats() {
13
+ global $wpdb;
14
+ $discats = explode(',',yarpp_get_option('discats'));
15
+ array_unshift($discats,' ');
16
+ foreach ($wpdb->get_results("select $wpdb->terms.term_id, name from $wpdb->terms natural join $wpdb->term_taxonomy where $wpdb->term_taxonomy.taxonomy = 'category' order by name") as $cat) {
17
+ echo "<input type='checkbox' name='discats[$cat->term_id]' value='true'". (array_search($cat->term_id,$discats) ? ' checked="checked"': '' )." /> <label>$cat->name</label> ";//for='discats[$cat->term_id]' it's not HTML. :(
18
+ }
19
+ exit;
20
+ }
21
+
22
+ function yarpp_ajax_display_distags() {
23
+ global $wpdb;
24
+ $distags = explode(',',yarpp_get_option('distags'));
25
+ array_unshift($distags,' ');
26
+ foreach ($wpdb->get_results("select $wpdb->terms.term_id, name from $wpdb->terms natural join $wpdb->term_taxonomy where $wpdb->term_taxonomy.taxonomy = 'post_tag' order by name") as $tag) {
27
+ echo "<input type='checkbox' name='distags[$tag->term_id]' value='true'". (array_search($tag->term_id,$distags) ? ' checked="checked"': '' )." /> <label>$tag->name</label> ";// for='distags[$tag->term_id]'
28
+ }
29
+ exit;
30
+ }
31
+
32
+ function yarpp_ajax_display_demo_web() {
33
+ $democode = stripslashes(yarpp_get_option('before_related',true))."\n";
34
+ for ($i=1;$i<=yarpp_get_option('limit');$i++) {
35
+ $democode .= stripslashes(yarpp_get_option('before_title',true)).stripslashes(htmlspecialchars("<a href='".__("PERMALINK",'yarpp')."$i'>".__("RELATED TITLE",'yarpp')." $i</a>")).(yarpp_get_option('show_excerpt')?"\r\t".stripslashes(yarpp_get_option('before_post',true)).yarpp_excerpt(LOREMIPSUM,yarpp_get_option('excerpt_length')).stripslashes(yarpp_get_option('before_post',true)):'').stripslashes(yarpp_get_option('after_title',true))."\n";
36
+ }
37
+ $democode .= stripslashes(yarpp_get_option('after_related',true));
38
+ if (yarpp_get_option('promote_yarpp'))
39
+ $democode .= htmlspecialchars("\n<p>".__("Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.",'yarpp')."</p>");
40
+ echo $democode;
41
+ exit;
42
+ }
43
+
44
+ function yarpp_ajax_display_demo_rss() {
45
+ $democode = stripslashes(yarpp_get_option('rss_before_related',true))."\n";
46
+ for ($i=1;$i<=yarpp_get_option('rss_limit');$i++) {
47
+ $democode .= stripslashes(yarpp_get_option('rss_before_title',true)).stripslashes(htmlspecialchars("<a href='".__("RELATED TITLE",'yarpp')."$i'>".__("RELATED TITLE",'yarpp')." $i</a>")).(yarpp_get_option('rss_show_excerpt')?"\r\t".stripslashes(yarpp_get_option('rss_before_post',true)).yarpp_excerpt(LOREMIPSUM,yarpp_get_option('rss_excerpt_length')).stripslashes(yarpp_get_option('rss_before_post',true)):'').stripslashes(yarpp_get_option('rss_after_title',true))."\n";
48
+ }
49
+ $democode .= stripslashes(yarpp_get_option('rss_after_related',true));
50
+ if (yarpp_get_option('rss_promote_yarpp'))
51
+ $democode .= htmlspecialchars("\n<p>".__("Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.",'yarpp')."</p>");
52
+ echo $democode;
53
+ exit;
54
+ }
55
+
56
+ function yarpp_build_cache() {
57
+ global $wpdb;
58
+ if (!is_user_logged_in() || !current_user_can('level_10')) {
59
+ wp_die(__('You cannot rebuild the YARPP cache.', 'yarpp'));
60
+ }
61
+
62
+ if (!$_POST['i']) {
63
+ $id = $wpdb->get_var("select min(ID), count(ID) from $wpdb->posts where post_status = 'publish'",0);
64
+ $i = 1;
65
+ $m = $wpdb->get_var(null,1);
66
+ } else {
67
+ $id = $_POST['id'];
68
+ $i = $_POST['i'];
69
+ $m = $_POST['m'];
70
+ }
71
+
72
+ $timeout = 3; // seconds
73
+ $start = yarpp_microtime_float();
74
+ while ((yarpp_microtime_float() - $start) < $timeout and $i <= $m) {
75
+ $result = yarpp_cache_enforce(array('post'),$id,true);
76
+
77
+ if (!$result) {
78
+ header('Content-Type: application/json');
79
+ echo "{result:'error',id: '$id', title: '".addslashes($title)."', i: $i, m: $m, percent: '".(floor(1000 * $i/$m)/10)."'}";
80
+ exit();
81
+ }
82
+
83
+ $id = $wpdb->get_var("select ID, post_title from $wpdb->posts where ID > $id and post_status = 'publish' order by ID asc limit 1",0);
84
+ $title = $wpdb->get_var(null,1);
85
+ $i++;
86
+ }
87
+
88
+ //header('Status: 404 Not Found');
89
+ //header('HTTP/1.1 404 Not Found');
90
+ //echo sprintf(__("You do not have the permission to write the file '%s'.", CSP_PO_TEXTDOMAIN), $_POST['pofile']);
91
+
92
+ header('Content-Type: application/json');
93
+ echo "{result:'success',time:'".(yarpp_microtime_float() - $start)."', id: '$id', title: '".addslashes($title)."', i: $i, m: $m, percent: '".(floor(1000 * $i/$m)/10)."'}";
94
+ exit();
95
+ }
96
+
97
+ ?>
template-builtin.php ADDED
@@ -0,0 +1,46 @@
1
+ <?php /*
2
+ YARPP's built-in "template"
3
+
4
+ This "template" is used when you choose not to use a template.
5
+
6
+ If you want to create a new template, look at templates/template-example.php as an example.
7
+ */
8
+
9
+ $options = array(
10
+ 'before_title'=>"${domainprefix}before_title",
11
+ 'after_title'=>"${domainprefix}after_title",
12
+ 'show_excerpt'=>"${domainprefix}show_excerpt",
13
+ 'excerpt_length'=>"${domainprefix}excerpt_length",
14
+ 'before_post'=>"${domainprefix}before_post",
15
+ 'after_post'=>"${domainprefix}after_post",
16
+ 'before_related'=>"${domainprefix}before_related",
17
+ 'after_related'=>"${domainprefix}after_related",
18
+ 'no_results'=>"${domainprefix}no_results");
19
+ $optvals = array();
20
+ foreach (array_keys($options) as $option) {
21
+ if (isset($args[$option])) {
22
+ $optvals[$option] = stripslashes($args[$option]);
23
+ } else {
24
+ $optvals[$option] = stripslashes(stripslashes(yarpp_get_option($options[$option])));
25
+ }
26
+ }
27
+ extract($optvals);
28
+
29
+ if ($related_query->have_posts()) {
30
+ while ($related_query->have_posts()) {
31
+ $related_query->the_post();
32
+
33
+ $output .= "$before_title<a href='".get_permalink()."' rel='bookmark' title='Permanent Link: ".get_the_title()."'>".get_the_title()."";
34
+ if ($userdata->user_level >= 8 and $domain != 'rss')
35
+ $output .= ' <abbr title="'.sprintf(__('%f is the YARPP match score between the current entry and this related entry. You are seeing this value because you are logged in to WordPress as an administrator. It is not shown to regular visitors.','yarpp'),round(get_the_score(),3)).'">('.round(get_the_score(),3).')</abbr>';
36
+ $output .= '</a>';
37
+ if ($show_excerpt) {
38
+ $output .= $before_post . yarpp_excerpt(get_the_excerpt(),$excerpt_length) . $after_post;
39
+ }
40
+ $output .= $after_title;
41
+
42
+ }
43
+ $output = stripslashes(stripslashes($before_related)).$output.stripslashes(stripslashes($after_related));
44
+ } else {
45
+ $output = $no_results;
46
+ }
template-functions.php ADDED
@@ -0,0 +1,13 @@
1
+ <?php
2
+
3
+ // two YARPP-specific Template Tags, to be used in the YARPP-template Loop.
4
+
5
+ function the_score() {
6
+ echo get_the_score();
7
+ }
8
+
9
+ function get_the_score() { // returns the score
10
+ global $post;
11
+ $score = $post->score;
12
+ return apply_filters('get_the_score', $score, $d, $gmt);
13
+ }
template-metabox.php ADDED
@@ -0,0 +1,28 @@
1
+ <?php
2
+
3
+ yarpp_save_cache($reference_ID,false); // enforce the cache, but don't force it
4
+
5
+ $body_terms = yarpp_get_cached_keywords($reference_ID,'body');
6
+ $title_terms = yarpp_get_cached_keywords($reference_ID,'title');
7
+
8
+ if ($yarpp_debug) $output .= "<p>last updated keywords: ".$wpdb->get_var("select date from {$wpdb->prefix}yarpp_keyword_cache where ID = '$reference_ID'")."</p>";
9
+ if ($yarpp_debug) $output .= "<p>body keywords: $body_terms</p>";
10
+ if ($yarpp_debug) $output .= "<p>title keywords: $title_terms</p>";
11
+
12
+ $output .= '<p>'.__( 'These are the related entries for this entry. Updating this post may change these related posts.' , 'yarpp').'</p>';
13
+
14
+ if ($yarpp_debug) $output .= "<p>last updated: ".$wpdb->get_var("select max(date) as updated from {$wpdb->prefix}yarpp_related_cache where reference_ID = '$reference_ID'")."</p>";
15
+
16
+ if ($related_query->have_posts()) {
17
+ $output .= '<ol>';
18
+ while ($related_query->have_posts()) {
19
+ $related_query->the_post();
20
+ $output .= "<li><a href='post.php?action=edit&post=$id'>".get_the_title()."</a>"; // FIXME: what if it's a page?
21
+ $output .= ' ('.round(get_the_score(),3).')';
22
+ $output .= '</li>';
23
+ }
24
+ $output .= '</ol>';
25
+ $output .= '<p>'.__( 'Whether all of these related entries are actually displayed and how they are displayed depends on your YARPP display options.' , 'yarpp').'</p>';
26
+ } else {
27
+ $output .= '<p><em>'.__('No related posts.').'</em></p>';
28
+ }
templates/template-example.php ADDED
@@ -0,0 +1,14 @@
1
+ <?php /*
2
+ Example template
3
+ Author: mitcho (Michael Yoshitaka Erlewine)
4
+ */ ?>
5
+ <h3>Related Posts</h3>
6
+ <?php if ($related_query->have_posts()):?>
7
+ <ol>
8
+ <?php while ($related_query->have_posts()) : $related_query->the_post(); ?>
9
+ <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a><!-- (<?php the_score(); ?>)--></li>
10
+ <?php endwhile; ?>
11
+ </ol>
12
+ <?php else: ?>
13
+ <p>No related posts.</p>
14
+ <?php endif; ?>
templates/template-list.php ADDED
@@ -0,0 +1,18 @@
1
+ <?php /*
2
+ List template
3
+ This template returns the related posts as a comma-separated list.
4
+ Author: mitcho (Michael Yoshitaka Erlewine)
5
+ */ ?>
6
+ <h3>Related Posts</h3>
7
+
8
+ <?php if ($related_query->have_posts()):
9
+ $postsArray = array();
10
+ while ($related_query->have_posts()) : $related_query->the_post();
11
+ $postsArray[] = '<li><a href="'.get_the_permalink().'" rel="bookmark">'.get_the_title().'</a><!-- ('.get_the_score().')--></li>';
12
+ endwhile;
13
+
14
+ echo implode(', ',$postsArray); // print out a list of the related items, separated by commas
15
+
16
+ else:
17
+ <p>No related posts.</p>
18
+ <?php endif; ?>
templates/template-photoblog.php ADDED
@@ -0,0 +1,17 @@
1
+ <?php /*
2
+ Example photoblog template for use with Yet Another Photoblog
3
+ Author: mitcho (Michael Yoshitaka Erlewine)
4
+ */ ?>
5
+ <h3>Related Photos</h3>
6
+ <?php if ($related_query->have_posts()):?>
7
+ <ol>
8
+ <?php while ($related_query->have_posts()) : $related_query->the_post(); ?>
9
+ <?php if (function_exists('yapb_is_photoblog_post')): if (yapb_is_photoblog_post()):?>
10
+ <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php yapb_get_thumbnail(); ?></a></li>
11
+ <?php endif; endif; ?>
12
+ <?php endwhile; ?>
13
+ </ol>
14
+
15
+ <?php else: ?>
16
+ <p>No related photos.</p>
17
+ <?php endif; ?>
templates/template-random.php ADDED
@@ -0,0 +1,18 @@
1
+ <?php /*
2
+ Example template: random
3
+ This template gives you some random other post in case there are no related posts
4
+ Author: mitcho (Michael Yoshitaka Erlewine)
5
+ */ ?>
6
+ <h3>Related Posts</h3>
7
+ <?php if ($related_query->have_posts()):?>
8
+ <ol>
9
+ <?php while ($related_query->have_posts()) : $related_query->the_post(); ?>
10
+ <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a><!-- (<?php the_score(); ?>)--></li>
11
+ <?php endwhile; ?>
12
+ </ol>
13
+
14
+ <?php else:
15
+ $related_query->query("orderby=rand&order=asc&limit=1");
16
+ $related_query->the_post();?>
17
+ <p>No related posts were found, so here's a consolation prize: <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>.</p>
18
+ <?php endif; ?>
yarpp.php CHANGED
@@ -3,13 +3,14 @@
3
Plugin Name: Yet Another Related Posts Plugin
4
Plugin URI: http://mitcho.com/code/yarpp/
5
Description: Returns a list of the related entries based on a unique algorithm using titles, post bodies, tags, and categories. Now with RSS feed support!
6
- Version: 2.1.5
7
Author: mitcho (Michael Yoshitaka Erlewine)
8
Author URI: http://mitcho.com/
9
*/
10
11
require_once('includes.php');
12
require_once('related-functions.php');
13
14
add_action('admin_menu','yarpp_admin_menu');
15
add_action('admin_print_scripts','yarpp_upgrade_check');
@@ -22,5 +23,82 @@ load_plugin_textdomain('yarpp', PLUGINDIR.'/'.dirname(plugin_basename(__FILE__))
22
23
// new in 2.0: add as a widget
24
add_action('plugins_loaded', 'widget_yarpp_init');
25
26
- ?>
3
Plugin Name: Yet Another Related Posts Plugin
4
Plugin URI: http://mitcho.com/code/yarpp/
5
Description: Returns a list of the related entries based on a unique algorithm using titles, post bodies, tags, and categories. Now with RSS feed support!
6
+ Version: 3.0b1
7
Author: mitcho (Michael Yoshitaka Erlewine)
8
Author URI: http://mitcho.com/
9
*/
10
11
require_once('includes.php');
12
require_once('related-functions.php');
13
+ require_once('template-functions.php');
14
15
add_action('admin_menu','yarpp_admin_menu');
16
add_action('admin_print_scripts','yarpp_upgrade_check');
23
24
// new in 2.0: add as a widget
25
add_action('plugins_loaded', 'widget_yarpp_init');
26
+ // new in 3.0: add meta box
27
+ add_action( 'admin_menu', 'yarpp_add_metabox');
28
+ function yarpp_add_metabox() {
29
+ add_meta_box( __( 'Related Posts' , 'yarpp'), __( 'Related Posts' , 'yarpp'), 'yarpp_metabox', 'post', 'normal' );
30
+ }
31
+ function yarpp_metabox() {
32
+ global $post;
33
+ echo '<div id="yarpp-related-posts">';
34
+ if ($post->ID)
35
+ yarpp_related(array('post'),array('limit'=>1000),true,false,'metabox');
36
+ else
37
+ echo "<p>Related entries may be displayed once you save your entry.</p>";
38
+ echo '</div>';
39
+ }
40
+
41
+ add_action('save_post','yarpp_save_cache');
42
+ function yarpp_save_cache($post_ID,$force=true) {
43
+ global $wpdb;
44
+ $parent_ID = $wpdb->get_var("select post_parent from $wpdb->posts where ID='$post_ID'");
45
+ if ($parent_ID != $post_ID and $parent_ID)
46
+ $post_ID = $parent_ID;
47
+ if (yarpp_get_option('cross_relate'))
48
+ $type = array('post','page');
49
+ else
50
+ $type = array('post');
51
+ yarpp_cache_enforce($type,$post_ID,$force);
52
+ }
53
+
54
+ //==TEMPLATING
55
+
56
+ add_filter('posts_join','yarpp_join_filter');
57
+ add_filter('posts_where','yarpp_where_filter');
58
+ add_filter('posts_orderby','yarpp_orderby_filter');
59
+ add_filter('posts_fields','yarpp_fields_filter');
60
+ add_action('parse_query','yarpp_set_score_override_flag'); // sets the score override flag.
61
+
62
+ function yarpp_set_score_override_flag($q) {
63
+ global $yarpp_time, $yarpp_score_override;
64
+ if ($yarpp_time) {
65
+ if ($q->query_vars['orderby'] == 'score')
66
+ $yarpp_score_override = true;
67
+ else
68
+ $yarpp_score_override = false;
69
+ }
70
+ }
71
+
72
+ function yarpp_join_filter($arg) {
73
+ global $wpdb, $yarpp_time;
74
+ if ($yarpp_time) {
75
+ $arg .= " join {$wpdb->prefix}yarpp_related_cache as yarpp using (ID)";
76
+ }
77
+ return $arg;
78
+ }
79
+
80
+ function yarpp_where_filter($arg) {
81
+ global $wpdb, $yarpp_time;
82
+ $threshold = yarpp_get_option('threshold');
83
+ if ($yarpp_time) {
84
+ $arg = str_replace("$wpdb->posts.ID = ","yarpp.score > $threshold and yarpp.reference_ID = ",$arg);
85
+ }
86
+ return $arg;
87
+ }
88
+
89
+ function yarpp_orderby_filter($arg) {
90
+ global $wpdb, $yarpp_time, $yarpp_score_override;
91
+ if ($yarpp_time and $yarpp_score_override) {
92
+ $arg = str_replace("$wpdb->posts.post_date","yarpp.score",$arg);
93
+ }
94
+ return $arg;
95
+ }
96
+
97
+ function yarpp_fields_filter($arg) {
98
+ global $wpdb, $yarpp_time;
99
+ if ($yarpp_time) {
100
+ $arg .= ", yarpp.score";
101
+ }
102
+ return $arg;
103
+ }
104