Yet Another Related Posts Plugin (YARPP) - Version 3.4b2

Version Description

Download this release

Release Info

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

Code changes from version 3.3.3 to 3.4b2

cache-postmeta.php CHANGED
@@ -2,20 +2,18 @@
2
3
$yarpp_storage_class = 'YARPP_Cache_Postmeta';
4
5
- define('YARPP_POSTMETA_TITLE_KEYWORDS_KEY','_yarpp_title_keywords');
6
- define('YARPP_POSTMETA_BODY_KEYWORDS_KEY','_yarpp_body_keywords');
7
define('YARPP_POSTMETA_RELATED_KEY', '_yarpp_related');
8
- define('YARPP_NO_RELATED', ':(');
9
10
class YARPP_Cache_Postmeta {
11
// variables used for lookup
12
- var $related_postdata = array();
13
- var $related_IDs = array();
14
- var $name = "postmeta";
15
- var $yarpp_time = false;
16
- var $demo_time = false;
17
- var $score_override = false;
18
- var $online_limit = false;
19
20
/**
21
* SETUP/STATUS
@@ -29,17 +27,23 @@ class YARPP_Cache_Postmeta {
29
add_filter('post_limits',array(&$this,'limit_filter'));
30
}
31
32
- function is_enabled() {
33
return true; // always enabled.
34
}
35
36
- function setup() {
37
}
38
39
- function upgrade() {
40
}
41
42
- function cache_status() {
43
global $wpdb;
44
return $wpdb->get_var("select (count(p.ID)-sum(m.meta_value IS NULL))/count(p.ID)
45
FROM `{$wpdb->posts}` as p
@@ -47,7 +51,7 @@ class YARPP_Cache_Postmeta {
47
WHERE p.post_status = 'publish'");
48
}
49
50
- function uncached($limit = 20, $offset = 0) {
51
global $wpdb;
52
return $wpdb->get_col("select SQL_CALC_FOUND_ROWS p.ID
53
FROM `{$wpdb->posts}` as p
@@ -59,7 +63,7 @@ class YARPP_Cache_Postmeta {
59
/**
60
* MAGIC FILTERS
61
*/
62
- function where_filter($arg) {
63
global $wpdb;
64
if ($this->yarpp_time) {
65
$threshold = yarpp_get_option('threshold');
@@ -75,7 +79,7 @@ class YARPP_Cache_Postmeta {
75
return $arg;
76
}
77
78
- function orderby_filter($arg) {
79
global $wpdb;
80
// only order by score if the score function is added in fields_filter, which only happens
81
// if there are related posts in the postdata
@@ -85,7 +89,7 @@ class YARPP_Cache_Postmeta {
85
return $arg;
86
}
87
88
- function fields_filter($arg) {
89
global $wpdb, $wpdb;
90
if ($this->yarpp_time && is_array($this->related_postdata) && count($this->related_postdata)) {
91
$scores = array();
@@ -97,7 +101,7 @@ class YARPP_Cache_Postmeta {
97
return $arg;
98
}
99
100
- function demo_request_filter($arg) {
101
global $wpdb;
102
if ($this->demo_time) {
103
$wpdb->query("set @count = 0;");
@@ -109,7 +113,7 @@ class YARPP_Cache_Postmeta {
109
return $arg;
110
}
111
112
- function limit_filter($arg) {
113
global $wpdb;
114
if ($this->yarpp_time and $this->online_limit)
115
return " limit {$this->online_limit} ";
@@ -119,7 +123,11 @@ class YARPP_Cache_Postmeta {
119
/**
120
* RELATEDNESS CACHE CONTROL
121
*/
122
- function begin_yarpp_time($reference_ID) {
123
$this->yarpp_time = true;
124
// get the related posts from postdata, and also construct the relate_IDs array
125
$this->related_postdata = get_post_meta($reference_ID,YARPP_POSTMETA_RELATED_KEY,true);
@@ -127,17 +135,23 @@ class YARPP_Cache_Postmeta {
127
$this->related_IDs = array_map(create_function('$x','return $x["ID"];'), $this->related_postdata);
128
}
129
130
- function end_yarpp_time() {
131
$this->yarpp_time = false;
132
$this->related_IDs = array();
133
$this->related_postdata = array();
134
}
135
136
- function is_cached($reference_ID) {
137
- return get_post_meta($reference_ID, YARPP_POSTMETA_RELATED_KEY, true) != false;
138
}
139
140
- function clear($reference_ID) {
141
if (is_int($reference_ID))
142
$reference_ID = array($reference_ID);
143
// make sure that we have a non-trivial array
@@ -149,18 +163,19 @@ class YARPP_Cache_Postmeta {
149
}
150
}
151
152
- function update($reference_ID) {
153
global $wpdb, $yarpp_debug;
154
155
// $reference_ID must be numeric
156
- if ( !is_int( $reference_ID ) )
157
- return new WP_Error('yarpp_cache_error', "reference ID must be an int" );
158
159
$original_related = $this->related($reference_ID);
160
- $related = $wpdb->get_results(yarpp_sql(array(),true,$reference_ID), ARRAY_A);
161
$new_related = array_map(create_function('$x','return $x["ID"];'), $related);
162
163
- if (count($new_related)) {
164
update_post_meta($reference_ID, YARPP_POSTMETA_RELATED_KEY, $related);
165
if ($yarpp_debug) echo "<!--YARPP just set the cache for post $reference_ID-->";
166
@@ -169,21 +184,25 @@ class YARPP_Cache_Postmeta {
169
$this->clear(array_diff($original_related, $new_related));
170
$this->clear(array_diff($new_related, $original_related));
171
}
172
} else {
173
update_post_meta($reference_ID, YARPP_POSTMETA_RELATED_KEY, YARPP_NO_RELATED);
174
// Clear the caches of those which are no longer related.
175
- if (count($original_related)) {
176
$this->clear($original_related);
177
- }
178
}
179
}
180
181
- function flush() {
182
global $wpdb;
183
return $wpdb->query("delete from `{$wpdb->postmeta}` where meta_key = '" . YARPP_POSTMETA_RELATED_KEY . "'");
184
}
185
186
- function related($reference_ID = null, $related_ID = null) {
187
global $wpdb;
188
189
if ( !is_int( $reference_ID ) && !is_int( $related_ID ) )
@@ -217,24 +236,34 @@ class YARPP_Cache_Postmeta {
217
/**
218
* KEYWORDS CACHE CONTROL
219
*/
220
- function cache_keywords($ID) {
221
- update_post_meta($ID, YARPP_POSTMETA_BODY_KEYWORDS_KEY, post_body_keywords($ID));
222
- update_post_meta($ID, YARPP_POSTMETA_TITLE_KEYWORDS_KEY, post_title_keywords($ID));
223
}
224
225
- function get_keywords($ID, $type='body') {
226
- if ( !is_int($ID) )
227
return false;
228
229
- $key = $type == 'body' ? YARPP_POSTMETA_BODY_KEYWORDS_KEY : YARPP_POSTMETA_TITLE_KEYWORDS_KEY;
230
- $out = get_post_meta($ID, $key, true);
231
232
- // if empty, try caching them first
233
- if ($out === false) {
234
- $this->cache_keywords($ID);
235
- $out = get_post_meta($ID, $key, true);
236
- }
237
238
- return $out;
239
}
240
}
2
3
$yarpp_storage_class = 'YARPP_Cache_Postmeta';
4
5
+ define('YARPP_POSTMETA_KEYWORDS_KEY','_yarpp_keywords');
6
define('YARPP_POSTMETA_RELATED_KEY', '_yarpp_related');
7
8
class YARPP_Cache_Postmeta {
9
// variables used for lookup
10
+ private $related_postdata = array();
11
+ private $related_IDs = array();
12
+ public $name = "postmeta";
13
+ private $yarpp_time = false;
14
+ public $demo_time = false;
15
+ public $score_override = false;
16
+ public $online_limit = false;
17
18
/**
19
* SETUP/STATUS
27
add_filter('post_limits',array(&$this,'limit_filter'));
28
}
29
30
+ public function is_enabled() {
31
return true; // always enabled.
32
}
33
34
+ public function setup() {
35
}
36
37
+ public function upgrade( $last_version ) {
38
+ global $wpdb;
39
+ if ( $last_version && version_compare('3.4b1', $last_version) > 0 ) {
40
+ // 3.4 moved _yarpp_body_keywords and _yarpp_title_keywords into the single
41
+ // postmeta _yarpp_keywords, so clear out the old data now.
42
+ $wpdb->query("delete from {$wpdb->postmeta} where (meta_key = '_yarpp_title_keywords' or meta_key = '_yarpp_body_keywords')");
43
+ }
44
}
45
46
+ public function cache_status() {
47
global $wpdb;
48
return $wpdb->get_var("select (count(p.ID)-sum(m.meta_value IS NULL))/count(p.ID)
49
FROM `{$wpdb->posts}` as p
51
WHERE p.post_status = 'publish'");
52
}
53
54
+ public function uncached($limit = 20, $offset = 0) {
55
global $wpdb;
56
return $wpdb->get_col("select SQL_CALC_FOUND_ROWS p.ID
57
FROM `{$wpdb->posts}` as p
63
/**
64
* MAGIC FILTERS
65
*/
66
+ public function where_filter($arg) {
67
global $wpdb;
68
if ($this->yarpp_time) {
69
$threshold = yarpp_get_option('threshold');
79
return $arg;
80
}
81
82
+ public function orderby_filter($arg) {
83
global $wpdb;
84
// only order by score if the score function is added in fields_filter, which only happens
85
// if there are related posts in the postdata
89
return $arg;
90
}
91
92
+ public function fields_filter($arg) {
93
global $wpdb, $wpdb;
94
if ($this->yarpp_time && is_array($this->related_postdata) && count($this->related_postdata)) {
95
$scores = array();
101
return $arg;
102
}
103
104
+ public function demo_request_filter($arg) {
105
global $wpdb;
106
if ($this->demo_time) {
107
$wpdb->query("set @count = 0;");
113
return $arg;
114
}
115
116
+ public function limit_filter($arg) {
117
global $wpdb;
118
if ($this->yarpp_time and $this->online_limit)
119
return " limit {$this->online_limit} ";
123
/**
124
* RELATEDNESS CACHE CONTROL
125
*/
126
+ public function is_yarpp_time() {
127
+ return $this->yarpp_time;
128
+ }
129
+
130
+ public function begin_yarpp_time($reference_ID) {
131
$this->yarpp_time = true;
132
// get the related posts from postdata, and also construct the relate_IDs array
133
$this->related_postdata = get_post_meta($reference_ID,YARPP_POSTMETA_RELATED_KEY,true);
135
$this->related_IDs = array_map(create_function('$x','return $x["ID"];'), $this->related_postdata);
136
}
137
138
+ public function end_yarpp_time() {
139
$this->yarpp_time = false;
140
$this->related_IDs = array();
141
$this->related_postdata = array();
142
}
143
144
+ // @return YARPP_NO_RELATED | YARPP_RELATED | YARPP_NOT_CACHED
145
+ public function is_cached($reference_ID) {
146
+ $related = get_post_meta($reference_ID, YARPP_POSTMETA_RELATED_KEY, true);
147
+ if ( YARPP_NO_RELATED === $related )
148
+ return YARPP_NO_RELATED;
149
+ if ( '' == $related )
150
+ return YARPP_NOT_CACHED;
151
+ return YARPP_RELATED;
152
}
153
154
+ public function clear($reference_ID) {
155
if (is_int($reference_ID))
156
$reference_ID = array($reference_ID);
157
// make sure that we have a non-trivial array
163
}
164
}
165
166
+ // @return YARPP_NO_RELATED | YARPP_RELATED | YARPP_NOT_CACHED
167
+ public function update($reference_ID) {
168
global $wpdb, $yarpp_debug;
169
170
// $reference_ID must be numeric
171
+ if ( !$reference_ID = absint($reference_ID) )
172
+ return YARPP_NOT_CACHED;
173
174
$original_related = $this->related($reference_ID);
175
+ $related = $wpdb->get_results(yarpp_sql($reference_ID), ARRAY_A);
176
$new_related = array_map(create_function('$x','return $x["ID"];'), $related);
177
178
+ if ( count($new_related) ) {
179
update_post_meta($reference_ID, YARPP_POSTMETA_RELATED_KEY, $related);
180
if ($yarpp_debug) echo "<!--YARPP just set the cache for post $reference_ID-->";
181
184
$this->clear(array_diff($original_related, $new_related));
185
$this->clear(array_diff($new_related, $original_related));
186
}
187
+
188
+ return YARPP_RELATED;
189
} else {
190
update_post_meta($reference_ID, YARPP_POSTMETA_RELATED_KEY, YARPP_NO_RELATED);
191
+
192
// Clear the caches of those which are no longer related.
193
+ if (count($original_related))
194
$this->clear($original_related);
195
+
196
+ return YARPP_NO_RELATED;
197
}
198
}
199
200
+ public function flush() {
201
global $wpdb;
202
return $wpdb->query("delete from `{$wpdb->postmeta}` where meta_key = '" . YARPP_POSTMETA_RELATED_KEY . "'");
203
}
204
205
+ public function related($reference_ID = null, $related_ID = null) {
206
global $wpdb;
207
208
if ( !is_int( $reference_ID ) && !is_int( $related_ID ) )
236
/**
237
* KEYWORDS CACHE CONTROL
238
*/
239
+
240
+ // @return (array) with body and title keywords
241
+ private function cache_keywords($ID) {
242
+ $keywords = array(
243
+ 'body' => post_body_keywords($ID),
244
+ 'title' => post_title_keywords($ID)
245
+ );
246
+ update_post_meta($ID, YARPP_POSTMETA_KEYWORDS_KEY, $keywords);
247
+ return $keywords;
248
}
249
250
+ // @param $ID (int)
251
+ // @param $type (string) body | title | all
252
+ // @return (string|array) depending on whether "all" were requested or not
253
+ public function get_keywords( $ID, $type = 'all' ) {
254
+ if ( !$ID = absint($ID) )
255
return false;
256
257
+ $keywords = get_post_meta($ID, YARPP_POSTMETA_KEYWORDS_KEY, true);
258
259
+ if ( empty($keywords) ) // if empty, try caching them first.
260
+ $keywords = $this->cache_keywords($ID);
261
262
+ if ( empty($keywords) )
263
+ return false;
264
+
265
+ if ( 'all' == $type )
266
+ return $keywords;
267
+ return $keywords[$type];
268
}
269
}
cache-tables.php CHANGED
@@ -6,10 +6,11 @@ define('YARPP_TABLES_RELATED_TABLE', 'yarpp_related_cache');
6
define('YARPP_TABLES_KEYWORDS_TABLE', 'yarpp_keyword_cache');
7
8
class YARPP_Cache_Tables {
9
- var $name = "custom tables";
10
- var $yarpp_time = false;
11
- var $demo_time = false;
12
- var $score_override = false;
13
14
/**
15
* SETUP/STATUS
@@ -24,7 +25,7 @@ class YARPP_Cache_Tables {
24
add_filter('post_limits',array(&$this,'limit_filter'));
25
}
26
27
- function is_enabled() {
28
global $wpdb;
29
// now check for the cache tables
30
$tabledata = $wpdb->get_col("show tables");
@@ -35,7 +36,7 @@ class YARPP_Cache_Tables {
35
return false;
36
}
37
38
- function setup() {
39
global $wpdb;
40
$wpdb->query("CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}" . YARPP_TABLES_KEYWORDS_TABLE . "` (
41
`ID` bigint(20) unsigned NOT NULL default '0',
@@ -54,9 +55,9 @@ class YARPP_Cache_Tables {
54
) ENGINE=MyISAM;");
55
}
56
57
- function upgrade($last_version) {
58
global $wpdb;
59
- if (version_compare('3.2.1b4', $last_version) > 0) {
60
// Change primary key to be (reference_ID, ID) to ensure that we don't
61
// get duplicates.
62
// We unfortunately have to clear the cache first here, to ensure that there
@@ -69,7 +70,7 @@ class YARPP_Cache_Tables {
69
}
70
}
71
72
- function cache_status() {
73
global $wpdb;
74
return $wpdb->get_var("select (count(p.ID)-sum(c.ID IS NULL))/count(p.ID)
75
FROM `{$wpdb->posts}` as p
@@ -77,7 +78,7 @@ class YARPP_Cache_Tables {
77
WHERE p.post_status = 'publish' ");
78
}
79
80
- function uncached($limit = 20, $offset = 0) {
81
global $wpdb;
82
return $wpdb->get_col("select SQL_CALC_FOUND_ROWS p.ID
83
FROM `{$wpdb->posts}` as p
@@ -89,14 +90,14 @@ class YARPP_Cache_Tables {
89
/**
90
* MAGIC FILTERS
91
*/
92
- function join_filter($arg) {
93
global $wpdb;
94
if ($this->yarpp_time)
95
$arg .= " join {$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . " as yarpp on {$wpdb->posts}.ID = yarpp.ID";
96
return $arg;
97
}
98
99
- function where_filter($arg) {
100
global $wpdb;
101
$threshold = yarpp_get_option('threshold');
102
if ($this->yarpp_time) {
@@ -109,21 +110,21 @@ class YARPP_Cache_Tables {
109
return $arg;
110
}
111
112
- function orderby_filter($arg) {
113
global $wpdb;
114
if ($this->yarpp_time and $this->score_override)
115
$arg = str_replace("$wpdb->posts.post_date","yarpp.score",$arg);
116
return $arg;
117
}
118
119
- function fields_filter($arg) {
120
global $wpdb;
121
if ($this->yarpp_time)
122
$arg .= ", yarpp.score";
123
return $arg;
124
}
125
126
- function demo_request_filter($arg) {
127
global $wpdb;
128
if ($this->demo_time) {
129
$wpdb->query("set @count = 0;");
@@ -135,7 +136,7 @@ class YARPP_Cache_Tables {
135
return $arg;
136
}
137
138
- function limit_filter($arg) {
139
global $wpdb;
140
if ($this->yarpp_time and $this->online_limit) {
141
return " limit {$this->online_limit} ";
@@ -146,20 +147,42 @@ class YARPP_Cache_Tables {
146
/**
147
* RELATEDNESS CACHE CONTROL
148
*/
149
- function begin_yarpp_time() {
150
$this->yarpp_time = true;
151
}
152
153
- function end_yarpp_time() {
154
$this->yarpp_time = false;
155
}
156
157
- function is_cached($reference_ID) {
158
global $wpdb;
159
- return $wpdb->get_var("select count(*) as count from {$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . " where reference_ID = $reference_ID");
160
}
161
162
- function clear($reference_ID) {
163
global $wpdb;
164
if (is_array($reference_ID) && count($reference_ID))
165
$wpdb->query("delete from {$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . " where reference_ID in (".implode(',',$reference_ID).")");
@@ -167,24 +190,25 @@ class YARPP_Cache_Tables {
167
$wpdb->query("delete from {$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . " where reference_ID = {$reference_ID}");
168
}
169
170
- function update($reference_ID) {
171
global $wpdb, $yarpp_debug;
172
173
// $reference_ID must be numeric
174
- if ( !is_int( $reference_ID ) )
175
- return new WP_Error('yarpp_cache_error', "update's reference ID must be an int" );
176
177
$original_related = $this->related($reference_ID);
178
- //error_log('original:' . implode(':', $original_related));
179
180
// clear out the cruft
181
$this->clear($reference_ID);
182
183
- $wpdb->query("insert into {$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . " (reference_ID,ID,score) ".yarpp_sql(array(),true,$reference_ID)." on duplicate key update date = now()");
184
185
- if ($wpdb->rows_affected) {
186
$new_related = $this->related($reference_ID);
187
- //error_log('new:' . implode(':', $new_related));
188
if ($yarpp_debug) echo "<!--YARPP just set the cache for post $reference_ID-->";
189
190
// Clear the caches of any items which are no longer related or are newly related.
@@ -192,23 +216,29 @@ class YARPP_Cache_Tables {
192
$this->clear(array_diff($original_related, $new_related));
193
$this->clear(array_diff($new_related, $original_related));
194
}
195
} else {
196
$wpdb->query("insert into {$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . " (reference_ID,ID,score) values ($reference_ID,0,0) on duplicate key update date = now()");
197
- if (!$wpdb->rows_affected)
198
- return false;
199
// Clear the caches of those which are no longer related.
200
- if (count($original_related)) {
201
$this->clear($original_related);
202
- }
203
}
204
}
205
206
- function flush() {
207
global $wpdb;
208
- return $wpdb->query("truncate table `{$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . "`");
209
}
210
211
- function related($reference_ID = null, $related_ID = null) {
212
global $wpdb;
213
214
if ( !is_int( $reference_ID ) && !is_int( $related_ID ) )
@@ -235,7 +265,8 @@ class YARPP_Cache_Tables {
235
/**
236
* KEYWORDS CACHE CONTROL
237
*/
238
- function cache_keywords($ID) {
239
global $wpdb;
240
$body_terms = post_body_keywords($ID);
241
$title_terms = post_title_keywords($ID);
@@ -246,25 +277,27 @@ class YARPP_Cache_Tables {
246
247
$wpdb->query("insert into {$wpdb->prefix}" . YARPP_TABLES_KEYWORDS_TABLE . " (ID,body,title) values ($ID,'$body_terms ','$title_terms ') on duplicate key update date = now(), body = '$body_terms ', title = '$title_terms '");
248
249
}
250
251
- function get_keywords($ID, $type='body') {
252
global $wpdb;
253
254
if ( !is_int($ID) )
255
return false;
256
257
- $out = $wpdb->get_var("select $type from {$wpdb->prefix}" . YARPP_TABLES_KEYWORDS_TABLE . " where ID = $ID");
258
- if ( empty($out) ) { // if empty, try caching them first.
259
- $this->cache_keywords($ID);
260
- $out = $wpdb->get_var("select $type from {$wpdb->prefix}" . YARPP_TABLES_KEYWORDS_TABLE . " where ID = $ID");
261
- }
262
263
- if ( empty($out) ) { // if still empty... return false
264
- //echo "<!--YARPP ERROR: couldn't select/create yarpp $type keywords for $ID-->";
265
return false;
266
- } else {
267
- return $out;
268
- }
269
}
270
}
6
define('YARPP_TABLES_KEYWORDS_TABLE', 'yarpp_keyword_cache');
7
8
class YARPP_Cache_Tables {
9
+ public $name = "custom tables";
10
+ private $yarpp_time = false;
11
+ public $demo_time = false;
12
+ public $score_override = false; // @todo: should be private
13
+ public $online_limit = false; // @todo: should be private
14
15
/**
16
* SETUP/STATUS
25
add_filter('post_limits',array(&$this,'limit_filter'));
26
}
27
28
+ public function is_enabled() {
29
global $wpdb;
30
// now check for the cache tables
31
$tabledata = $wpdb->get_col("show tables");
36
return false;
37
}
38
39
+ public function setup() {
40
global $wpdb;
41
$wpdb->query("CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}" . YARPP_TABLES_KEYWORDS_TABLE . "` (
42
`ID` bigint(20) unsigned NOT NULL default '0',
55
) ENGINE=MyISAM;");
56
}
57
58
+ public function upgrade($last_version) {
59
global $wpdb;
60
+ if ( $last_version && version_compare('3.2.1b4', $last_version) > 0 ) {
61
// Change primary key to be (reference_ID, ID) to ensure that we don't
62
// get duplicates.
63
// We unfortunately have to clear the cache first here, to ensure that there
70
}
71
}
72
73
+ public function cache_status() {
74
global $wpdb;
75
return $wpdb->get_var("select (count(p.ID)-sum(c.ID IS NULL))/count(p.ID)
76
FROM `{$wpdb->posts}` as p
78
WHERE p.post_status = 'publish' ");
79
}
80
81
+ public function uncached($limit = 20, $offset = 0) {
82
global $wpdb;
83
return $wpdb->get_col("select SQL_CALC_FOUND_ROWS p.ID
84
FROM `{$wpdb->posts}` as p
90
/**
91
* MAGIC FILTERS
92
*/
93
+ public function join_filter($arg) {
94
global $wpdb;
95
if ($this->yarpp_time)
96
$arg .= " join {$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . " as yarpp on {$wpdb->posts}.ID = yarpp.ID";
97
return $arg;
98
}
99
100
+ public function where_filter($arg) {
101
global $wpdb;
102
$threshold = yarpp_get_option('threshold');
103
if ($this->yarpp_time) {
110
return $arg;
111
}
112
113
+ public function orderby_filter($arg) {
114
global $wpdb;
115
if ($this->yarpp_time and $this->score_override)
116
$arg = str_replace("$wpdb->posts.post_date","yarpp.score",$arg);
117
return $arg;
118
}
119
120
+ public function fields_filter($arg) {
121
global $wpdb;
122
if ($this->yarpp_time)
123
$arg .= ", yarpp.score";
124
return $arg;
125
}
126
127
+ public function demo_request_filter($arg) {
128
global $wpdb;
129
if ($this->demo_time) {
130
$wpdb->query("set @count = 0;");
136
return $arg;
137
}
138
139
+ public function limit_filter($arg) {
140
global $wpdb;
141
if ($this->yarpp_time and $this->online_limit) {
142
return " limit {$this->online_limit} ";
147
/**
148
* RELATEDNESS CACHE CONTROL
149
*/
150
+ public function is_yarpp_time() {
151
+ return $this->yarpp_time;
152
+ }
153
+
154
+ public function begin_yarpp_time() {
155
$this->yarpp_time = true;
156
}
157
158
+ public function end_yarpp_time() {
159
$this->yarpp_time = false;
160
}
161
162
+ // @return YARPP_NO_RELATED | YARPP_RELATED | YARPP_NOT_CACHED
163
+ public function is_cached($reference_ID) {
164
global $wpdb;
165
+
166
+ $result = wp_cache_get( 'is_cached_' . $reference_ID, 'yarpp' );
167
+ if ( false !== $result )
168
+ return $result;
169
+
170
+ $min_id = $wpdb->get_var("select min(ID) as min_id from {$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . " where reference_ID = $reference_ID");
171
+
172
+ if ( is_null( $min_id ) )
173
+ return YARPP_NOT_CACHED;
174
+
175
+ if ( 0 == $min_id )
176
+ $result = YARPP_NO_RELATED;
177
+ else
178
+ $result = YARPP_RELATED;
179
+
180
+ wp_cache_set( 'is_cached_' . $reference_ID, $result, 'yarpp' );
181
+
182
+ return $result;
183
}
184
185
+ public function clear($reference_ID) {
186
global $wpdb;
187
if (is_array($reference_ID) && count($reference_ID))
188
$wpdb->query("delete from {$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . " where reference_ID in (".implode(',',$reference_ID).")");
190
$wpdb->query("delete from {$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . " where reference_ID = {$reference_ID}");
191
}
192
193
+ // @return YARPP_RELATED | YARPP_NO_RELATED | YARPP_NOT_CACHED
194
+ public function update($reference_ID) {
195
global $wpdb, $yarpp_debug;
196
197
// $reference_ID must be numeric
198
+ if ( !$reference_ID = absint($reference_ID) )
199
+ return YARPP_NOT_CACHED;
200
201
$original_related = $this->related($reference_ID);
202
203
// clear out the cruft
204
$this->clear($reference_ID);
205
206
+ $wpdb->query("insert into {$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . " (reference_ID,ID,score) ".yarpp_sql($reference_ID)." on duplicate key update date = now()");
207
208
+ // If there were related entries saved...
209
+ if ( $wpdb->rows_affected ) {
210
$new_related = $this->related($reference_ID);
211
+
212
if ($yarpp_debug) echo "<!--YARPP just set the cache for post $reference_ID-->";
213
214
// Clear the caches of any items which are no longer related or are newly related.
216
$this->clear(array_diff($original_related, $new_related));
217
$this->clear(array_diff($new_related, $original_related));
218
}
219
+
220
+ return YARPP_RELATED;
221
} else {
222
$wpdb->query("insert into {$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . " (reference_ID,ID,score) values ($reference_ID,0,0) on duplicate key update date = now()");
223
+
224
+ //if (!$wpdb->rows_affected)
225
+ // return YARPP_NOT_CACHED;
226
+
227
// Clear the caches of those which are no longer related.
228
+ if ( count($original_related) )
229
$this->clear($original_related);
230
+
231
+ return YARPP_NO_RELATED;
232
}
233
}
234
235
+ public function flush() {
236
global $wpdb;
237
+ $wpdb->query("truncate table `{$wpdb->prefix}" . YARPP_TABLES_RELATED_TABLE . "`");
238
+ $wpdb->query("truncate table `{$wpdb->prefix}" . YARPP_TABLES_KEYWORDS_TABLE . "`");
239
}
240
241
+ public function related($reference_ID = null, $related_ID = null) {
242
global $wpdb;
243
244
if ( !is_int( $reference_ID ) && !is_int( $related_ID ) )
265
/**
266
* KEYWORDS CACHE CONTROL
267
*/
268
+ // @return (array) with body and title keywords
269
+ private function cache_keywords($ID) {
270
global $wpdb;
271
$body_terms = post_body_keywords($ID);
272
$title_terms = post_title_keywords($ID);
277
278
$wpdb->query("insert into {$wpdb->prefix}" . YARPP_TABLES_KEYWORDS_TABLE . " (ID,body,title) values ($ID,'$body_terms ','$title_terms ') on duplicate key update date = now(), body = '$body_terms ', title = '$title_terms '");
279
280
+ return array( 'body' => $body_terms, 'title' => $title_terms );
281
}
282
283
+ // @param $ID (int)
284
+ // @param $type (string) body | title | all
285
+ // @return (string|array) depending on whether "all" were requested or not
286
+ public function get_keywords( $ID, $type = 'all' ) {
287
global $wpdb;
288
289
if ( !is_int($ID) )
290
return false;
291
292
+ $keywords = $wpdb->get_row("select body, title from {$wpdb->prefix}" . YARPP_TABLES_KEYWORDS_TABLE . " where ID = $ID", ARRAY_A);
293
+ if ( empty($keywords) ) // if empty, try caching them first.
294
+ $keywords = $this->cache_keywords($ID);
295
296
+ if ( empty($keywords) )
297
return false;
298
+
299
+ if ( 'all' == $type )
300
+ return $keywords;
301
+ return $keywords[$type];
302
}
303
}
includes.php CHANGED
@@ -38,10 +38,10 @@ $yarpp_value_options = array(
38
'rss_after_related' => '</ol>',
39
'rss_no_results' => '<p>'.__('No related posts.','yarpp').'</p>',
40
'rss_order' => 'score DESC',
41
- 'title' => '2',
42
- 'body' => '2',
43
- 'categories' => '1', // changed default in 3.3
44
- 'tags' => '2',
45
'distags' => '',
46
'discats' => '');
47
$yarpp_binary_options = array(
@@ -57,7 +57,8 @@ $yarpp_binary_options = array(
57
'rss_display' => false, // changed default in 3.1.7
58
'rss_excerpt_display' => true,
59
'promote_yarpp' => false,
60
- 'rss_promote_yarpp' => false);
61
// These are options which, when updated, will trigger a clearing of the cache
62
$yarpp_clear_cache_options = array(
63
'distags','discats','show_pass_post','recent_only','threshold','title','body','categories',
@@ -76,15 +77,7 @@ function yarpp_enabled() {
76
}
77
78
function yarpp_activate() {
79
- global $yarpp_version, $wpdb, $yarpp_binary_options, $yarpp_value_options, $yarpp_cache;
80
- foreach (array_keys($yarpp_value_options) as $option) {
81
- if (get_option("yarpp_$option") === false)
82
- add_option("yarpp_$option",$yarpp_value_options[$option] . ' ');
83
- }
84
- foreach (array_keys($yarpp_binary_options) as $option) {
85
- if (get_option("yarpp_$option") === false)
86
- add_option("yarpp_$option",$yarpp_binary_options[$option]);
87
- }
88
89
$wpdb->get_results("show index from $wpdb->posts where Key_name='yarpp_title'");
90
if (!$wpdb->num_rows)
@@ -94,16 +87,16 @@ function yarpp_activate() {
94
if (!$wpdb->num_rows)
95
$wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_content` ( `post_content` )");
96
97
- if (!yarpp_enabled()) {
98
// If we are still not enabled, run the cache abstraction's setup method.
99
$yarpp_cache->setup();
100
// If we're still not enabled, give up.
101
- if (!yarpp_enabled())
102
return 0;
103
}
104
105
- if (!get_option('yarpp_version')) {
106
- add_option('yarpp_version',YARPP_VERSION);
107
yarpp_version_info(true);
108
} else {
109
yarpp_upgrade_check();
@@ -123,19 +116,14 @@ function yarpp_myisam_check() {
123
}
124
125
function yarpp_upgrade_check() {
126
- $last_version = get_option('yarpp_version');
127
if (version_compare(YARPP_VERSION, $last_version) === 0)
128
return;
129
130
- global $yarpp_value_options, $yarpp_binary_options, $yarpp_cache;
131
-
132
- foreach (array_keys($yarpp_value_options) as $option) {
133
- if (get_option("yarpp_$option") === false)
134
- add_option("yarpp_$option",$yarpp_value_options[$option].' ');
135
- }
136
- foreach (array_keys($yarpp_binary_options) as $option) {
137
- if (get_option("yarpp_$option") === false)
138
- add_option("yarpp_$option",$yarpp_binary_options[$option]);
139
}
140
141
$yarpp_cache->upgrade($last_version);
@@ -145,6 +133,48 @@ function yarpp_upgrade_check() {
145
update_option('yarpp_version',YARPP_VERSION);
146
}
147
148
function yarpp_admin_menu() {
149
$hook = add_options_page(__('Related Posts (YARPP)','yarpp'),__('Related Posts (YARPP)','yarpp'), 'manage_options', 'yarpp', 'yarpp_options_page');
150
add_action("load-$hook",'yarpp_load_thickbox');
@@ -184,7 +214,7 @@ function yarpp_options_page() {
184
}
185
186
function widget_yarpp_init() {
187
- register_widget('YARPP_Widget');
188
}
189
190
// vaguely based on code by MK Safi
@@ -289,7 +319,7 @@ function yarpp_default($content) {
289
if (yarpp_get_option('cross_relate'))
290
$type = array('post','page');
291
292
- if (yarpp_get_option('auto_display') and is_single())
293
return $content . yarpp_related($type,array(),false,false,'website');
294
else
295
return $content;
@@ -331,26 +361,35 @@ function yarpp_excerpt($content,$length) {
331
return implode(' ',array_slice(preg_split('/\s+/',$content),0,$length)).'...';
332
}
333
334
- function yarpp_set_option($option,$value) {
335
- global $yarpp_value_options, $yarpp_clear_cache_options, $yarpp_cache;
336
- if (array_search($option,array_keys($yarpp_value_options)) !== false)
337
- update_option("yarpp_$option",$value.' ');
338
- else
339
- update_option("yarpp_$option",$value);
340
// new in 3.1: clear cache when updating certain settings.
341
- if (array_search($option,$yarpp_clear_cache_options) !== false)
342
- $yarpp_cache->flush();
343
}
344
345
- function yarpp_get_option($option,$escapehtml = false) {
346
- global $yarpp_value_options;
347
- if (array_search($option,array_keys($yarpp_value_options)) !== false)
348
- $return = chop(get_option("yarpp_$option"));
349
- else
350
- $return = get_option("yarpp_$option");
351
- if ($escapehtml)
352
- $return = htmlspecialchars(stripslashes($return));
353
- return $return;
354
}
355
356
function yarpp_microtime_float() {
38
'rss_after_related' => '</ol>',
39
'rss_no_results' => '<p>'.__('No related posts.','yarpp').'</p>',
40
'rss_order' => 'score DESC',
41
+ 'title' => 2,
42
+ 'body' => 2,
43
+ 'categories' => 1, // changed default in 3.3
44
+ 'tags' => 2,
45
'distags' => '',
46
'discats' => '');
47
$yarpp_binary_options = array(
57
'rss_display' => false, // changed default in 3.1.7
58
'rss_excerpt_display' => true,
59
'promote_yarpp' => false,
60
+ 'rss_promote_yarpp' => false,
61
+ 'myisam_override' => false);
62
// These are options which, when updated, will trigger a clearing of the cache
63
$yarpp_clear_cache_options = array(
64
'distags','discats','show_pass_post','recent_only','threshold','title','body','categories',
77
}
78
79
function yarpp_activate() {
80
+ global $yarpp_version, $wpdb, $yarpp_cache;
81
82
$wpdb->get_results("show index from $wpdb->posts where Key_name='yarpp_title'");
83
if (!$wpdb->num_rows)
87
if (!$wpdb->num_rows)
88
$wpdb->query("ALTER TABLE $wpdb->posts ADD FULLTEXT `yarpp_content` ( `post_content` )");
89
90
+ if ( !yarpp_enabled() ) {
91
// If we are still not enabled, run the cache abstraction's setup method.
92
$yarpp_cache->setup();
93
// If we're still not enabled, give up.
94
+ if ( !yarpp_enabled() )
95
return 0;
96
}
97
98
+ if ( !get_option('yarpp_version') ) {
99
+ add_option( 'yarpp_version', YARPP_VERSION );
100
yarpp_version_info(true);
101
} else {
102
yarpp_upgrade_check();
116
}
117
118
function yarpp_upgrade_check() {
119
+ global $yarpp_cache;
120
+
121
+ $last_version = get_option( 'yarpp_version' );
122
if (version_compare(YARPP_VERSION, $last_version) === 0)
123
return;
124
125
+ if ( $last_version && version_compare('3.4b2', $last_version) > 0 ) {
126
+ yarpp_upgrade_3_4();
127
}
128
129
$yarpp_cache->upgrade($last_version);
133
update_option('yarpp_version',YARPP_VERSION);
134
}
135
136
+ function yarpp_upgrade_3_4() {
137
+ global $wpdb, $yarpp_value_options, $yarpp_binary_options;
138
+
139
+ $yarpp_options = array();
140
+ foreach ( $yarpp_value_options as $key => $default ) {
141
+ $value = get_option( "yarpp_$key", null );
142
+ if ( is_null($value) )
143
+ continue;
144
+
145
+ // value options used to be stored with a bajillion slashes...
146
+ $value = stripslashes(stripslashes($value));
147
+ // value options used to be stored with a blank space at the end... don't ask.
148
+ $value = rtrim($value, ' ');
149
+
150
+ if ( is_int($default) )
151
+ $yarpp_options[$key] = absint($value);
152
+ else
153
+ $yarpp_options[$key] = $value;
154
+ }
155
+ foreach ( $yarpp_binary_options as $key => $default ) {
156
+ $value = get_option( "yarpp_$key", null );
157
+ if ( is_null($value) )
158
+ continue;
159
+ $yarpp_options[$key] = (boolean) $value;
160
+ }
161
+
162
+ // add the options directly first, then call set_option which will ensure defaults,
163
+ // in case any new options have been added.
164
+ update_option( 'yarpp', $yarpp_options );
165
+ yarpp_set_option( $yarpp_options );
166
+
167
+ $option_keys = array_keys( $yarpp_options );
168
+ // append some keys for options which are long deprecated:
169
+ $option_keys[] = 'ad_hoc_caching';
170
+ $option_keys[] = 'excerpt_len';
171
+ $option_keys[] = 'show_score';
172
+ if ( count($option_keys) ) {
173
+ $in = "('yarpp_" . join("', 'yarpp_", $option_keys) . "')";
174
+ $wpdb->query("delete from {$wpdb->options} where option_name in {$in}");
175
+ }
176
+ }
177
+
178
function yarpp_admin_menu() {
179
$hook = add_options_page(__('Related Posts (YARPP)','yarpp'),__('Related Posts (YARPP)','yarpp'), 'manage_options', 'yarpp', 'yarpp_options_page');
180
add_action("load-$hook",'yarpp_load_thickbox');
214
}
215
216
function widget_yarpp_init() {
217
+ register_widget( 'YARPP_Widget' );
218
}
219
220
// vaguely based on code by MK Safi
319
if (yarpp_get_option('cross_relate'))
320
$type = array('post','page');
321
322
+ if (yarpp_get_option('auto_display') && is_single())
323
return $content . yarpp_related($type,array(),false,false,'website');
324
else
325
return $content;
361
return implode(' ',array_slice(preg_split('/\s+/',$content),0,$length)).'...';
362
}
363
364
+ function yarpp_set_option($options, $value = null) {
365
+ global $yarpp_clear_cache_options, $yarpp_cache;
366
+
367
+ $current_options = yarpp_get_option();
368
+
369
+ // we can call yarpp_set_option(key,value) if we like:
370
+ if ( !is_array($options) && isset($value) )
371
+ $options = array( $options => $value );
372
+
373
+ $new_options = array_merge( $current_options, $options );
374
+
375
// new in 3.1: clear cache when updating certain settings.
376
+ $new_options_which_require_flush = array_intersect( array_keys( array_diff($options, $current_options) ), $yarpp_clear_cache_options );
377
+ if ( count($new_options_which_require_flush) )
378
+ $yarpp_cache->flush();
379
+
380
+ update_option( 'yarpp', $new_options );
381
}
382
383
+ function yarpp_get_option($option = null) {
384
+ global $yarpp_value_options, $yarpp_binary_options;
385
+
386
+ $options = get_option( 'yarpp' );
387
+ // ensure defaults if not set:
388
+ $options = array_merge( $yarpp_value_options, $yarpp_binary_options, $options );
389
+
390
+ if ( !is_null( $option ) )
391
+ return $options[$option];
392
+ return $options;
393
}
394
395
function yarpp_microtime_float() {
lang/words-nl_NL.php CHANGED
@@ -1,3 +1,3 @@
1
- <?php
2
-
3
- $overusedwords = array('', 'een', 'de', 'het', 'of', 'in', 'naar', 'op', 'is', 'met', 'voor', 'als', 'dat', 'onder', 'dit', 'mijn', 'mij', 'was', 'ons', 'jij', 'zij', 'wij', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '10', 'over', 'na', 'alle', 'bijna', 'langs', 'ook', 'ander', 'enig', 'enige', 'zijn', 'ben', 'bent', 'beschikbaar', 'terug', 'omdat', 'geweest', 'doordat', 'beste', 'beter', 'groot', 'klein', 'beiden', 'maar', 'c', 'kom', 'komen','kan','kunnen','konden', 'controleren', 'zouden', 'zou', 'cursus', 'd', 'dan', 'dag', 'beslissen', 'deden', 'deed', 'doet', 'verschillend', 'doe', 'niet', 'nog', 'onder', 'rijden', 'e', 'elke', 'gemakkelijk', 'makkie', 'editie', 'versie', 'einde', 'genoeg', 'even', 'elke', 'voorbeeld', 'enkele', 'vinden', 'eerste', 'gevonden', 'vind', 'vindt', 'van', 'krijg', 'krijgen', 'gaan', 'ga', 'goed', 'snap', 'begrijpen', 'heb', 'hebben', 'had', 'hard', 'heeft', 'hij', 'hem', 'haar', 'hier', 'hoe', 'niet', 'wel', 'weten', 'laatste', 'links', 'rechts', 'leuk', 'klein', 'lang', 'kijk', 'kijken', 'veel', 'weinig', 'maken', 'maak', 'gemaakt', 'menu', 'misschien', 'wellicht', 'meer', 'minder', 'naam', 'nbsp', 'nodig', 'nieuw', 'nee', 'ja', 'niet', 'nu', 'nummer', 'uit', 'oud', 'een', 'alleen', 'originineel', 'ander', 'andere', 'anders', 'haar', 'over', 'deel', 'plek', 'plek', 'mooi', 'waarschijnlijk', 'probleem', 'plaats', 'ongeveer', 'gezegde', 're', 'werkelijk', 'uitkomst', 'plus', 'min','klopt', 's', 'zelfde','dezelfde', 'zag', 'zien', 'zie', 'verschillende','zou', 'zouden', 'since', 'maat', 'kleine', 'zo', 'sommige', 'iets', 'speciaal', 'stil','nog', 'dingen', 'zoals', 'natuurlijk', 'systeem', 't', 'nemen','neem', 'dan', 'hun', 'hen', 'daarna', 'er', 'deze', 'dingen', 'ding', 'denk', 'denken', 'zulke', 'moeilijk', 'door','doorheen', 'doordat','omdat', 'tijd', 'vandaag', 'samen', 'ook', 'nam', 'twee', 'gebruiken','gebruik', 'gebruikt', 'gebruikte', 'zeer', 'erg', 'want', 'manier', 'nou', 'nu', 'geweest', 'waar', 'wat', 'wanneer', 'waar', 'welke', 'ondertussen', 'terwijl', 'wit','zwart','wie','wil', 'zou','zouden', 'jou', 'jouw', 'haar', 'van','mensen', 'man', 'vrouw', 'persoon', 'goed', 'slecht', 'heel','later', 'eerder', 'nieuw', 'moet', 'moeten', 'mogen', 'mag', 'zegt', 'zeggen', 'zei', 'zeg', 'maak', 'maken', 'maakte', 'gemaakt', 'doe', 'doen', 'deed', 'deden', 'konden', 'word', 'wordt', 'werd', 'werden', 'ja', 'nee','uh', 'die','naar', 'je', 'maar','jaar','moet', 'aleen');
1
+ <?php
2
+
3
+ $overusedwords = array('', 'een', 'de', 'het', 'of', 'in', 'naar', 'op', 'is', 'met', 'voor', 'als', 'dat', 'onder', 'dit', 'mijn', 'mij', 'was', 'ons', 'jij', 'zij', 'wij', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '10', 'over', 'na', 'alle', 'bijna', 'langs', 'ook', 'ander', 'enig', 'enige', 'zijn', 'ben', 'bent', 'beschikbaar', 'terug', 'omdat', 'geweest', 'doordat', 'beste', 'beter', 'groot', 'klein', 'beiden', 'maar', 'c', 'kom', 'komen','kan','kunnen','konden', 'controleren', 'zouden', 'zou', 'cursus', 'd', 'dan', 'dag', 'beslissen', 'deden', 'deed', 'doet', 'verschillend', 'doe', 'niet', 'nog', 'onder', 'rijden', 'e', 'elke', 'gemakkelijk', 'makkie', 'editie', 'versie', 'einde', 'genoeg', 'even', 'elke', 'voorbeeld', 'enkele', 'vinden', 'eerste', 'gevonden', 'vind', 'vindt', 'van', 'krijg', 'krijgen', 'gaan', 'ga', 'goed', 'snap', 'begrijpen', 'heb', 'hebben', 'had', 'hard', 'heeft', 'hij', 'hem', 'haar', 'hier', 'hoe', 'niet', 'wel', 'weten', 'laatste', 'links', 'rechts', 'leuk', 'klein', 'lang', 'kijk', 'kijken', 'veel', 'weinig', 'maken', 'maak', 'gemaakt', 'menu', 'misschien', 'wellicht', 'meer', 'minder', 'naam', 'nbsp', 'nodig', 'nieuw', 'nee', 'ja', 'niet', 'nu', 'nummer', 'uit', 'oud', 'een', 'alleen', 'originineel', 'ander', 'andere', 'anders', 'haar', 'over', 'deel', 'plek', 'plek', 'mooi', 'waarschijnlijk', 'probleem', 'plaats', 'ongeveer', 'gezegde', 're', 'werkelijk', 'uitkomst', 'plus', 'min','klopt', 's', 'zelfde','dezelfde', 'zag', 'zien', 'zie', 'verschillende','zou', 'zouden', 'since', 'maat', 'kleine', 'zo', 'sommige', 'iets', 'speciaal', 'stil','nog', 'dingen', 'zoals', 'natuurlijk', 'systeem', 't', 'nemen','neem', 'dan', 'hun', 'hen', 'daarna', 'er', 'deze', 'dingen', 'ding', 'denk', 'denken', 'zulke', 'moeilijk', 'door','doorheen', 'doordat','omdat', 'tijd', 'vandaag', 'samen', 'ook', 'nam', 'twee', 'gebruiken','gebruik', 'gebruikt', 'gebruikte', 'zeer', 'erg', 'want', 'manier', 'nou', 'nu', 'geweest', 'waar', 'wat', 'wanneer', 'waar', 'welke', 'ondertussen', 'terwijl', 'wit','zwart','wie','wil', 'zou','zouden', 'jou', 'jouw', 'haar', 'van','mensen', 'man', 'vrouw', 'persoon', 'goed', 'slecht', 'heel','later', 'eerder', 'nieuw', 'moet', 'moeten', 'mogen', 'mag', 'zegt', 'zeggen', 'zei', 'zeg', 'maak', 'maken', 'maakte', 'gemaakt', 'doe', 'doen', 'deed', 'deden', 'konden', 'word', 'wordt', 'werd', 'werden', 'ja', 'nee','uh', 'die','naar', 'je', 'maar','jaar','moet', 'aleen');
lang/words-pt_BR.php ADDED
@@ -0,0 +1,3 @@
1
+ <?php
2
+
3
+ $overusedwords = array('a', 'acerca', 'agora', 'ainda', 'alguém', 'algum', 'alguma', 'algumas', 'alguns', 'ali', 'ambos', 'ampla', 'amplas', 'amplo', 'amplos', 'ante', 'antes', 'apontar', 'ao', 'aos', 'após', 'aquela', 'aquelas', 'aquele', 'aqueles', 'aqui', 'aquilo', 'as', 'até', 'atrás', 'através', 'bem', 'bom', 'cada', 'caminho', 'cima', 'coisa', 'coisas', 'com', 'como', 'conhecido', 'contra', 'contudo', 'corrente', 'da', 'daquela', 'daquelas', 'daquele', 'daqueles', 'das', 'de', 'debaixo', 'dela', 'delas', 'dele', 'deles', 'dentro', 'depois', 'desde', 'desligado', 'dessa', 'dessas', 'desse', 'desses', 'desta', 'destas', 'deste', 'deste', 'destes', 'deve', 'devem', 'devendo', 'dever', 'dever', 'deverão', 'deveria', 'deveriam', 'devia', 'deviam', 'direita', 'disse', 'disso', 'disto', 'dito', 'diz', 'dizem', 'do', 'dois', 'dos', 'e', 'é', 'ela', 'elas', 'ele', 'eles', 'em', 'enquanto', 'então', 'entre', 'era', 'essa', 'essas', 'esse', 'esses', 'esta', 'está', 'estamos', 'estão', 'estar', 'estará', 'estas', 'estava', 'estavam', 'estávamos', 'este', 'estes', 'estou', 'eu', 'fará', 'faz', 'fazendo', 'fazer', 'fazia', 'feita', 'feitas', 'feito', 'feitos', 'fez', 'fim', 'foi', 'for', 'fora', 'foram', 'fosse', 'fossem', 'grande', 'grandes', 'há', 'hora', 'horas', 'iniciar', 'início', 'ir', 'irá', 'isso', 'isto', 'já', 'ligado', 'maioria', 'maiorias', 'mais', 'mas', 'me', 'mesma', 'mesmas', 'mesmo', 'mesmos', 'meu', 'meus', 'minha', 'minhas', 'muita', 'muitas', 'muito', 'muitos', 'na', 'não', 'nas', 'nem', 'nenhum', 'nessa', 'nessas', 'nesta', 'nestas', 'ninguém', 'no', 'nome', 'nos', 'nós', 'nossa', 'nossas', 'nosso', 'nossos', 'novo', 'num', 'numa', 'nunca', 'o', 'onde', 'os', 'ou', 'outra', 'outras', 'outro', 'outros', 'para', 'parte', 'pegar', 'pela', 'pelas', 'pelo', 'pelos', 'pequena', 'pequenas', 'pequeno', 'pequenos', 'perante', 'pessoa', 'pessoas', 'pode', 'podendo', 'poder', 'poderá', 'poderia', 'poderiam', 'podia', 'podiam', 'pois', 'por', 'porém', 'porque', 'posso', 'pouca', 'poucas', 'pouco', 'poucos', 'povo', 'primeiro', 'primeiros', 'própria', 'próprio', 'próprios', 'quais', 'qual', 'qualquer', 'quando', 'quanto', 'quantos', 'que', 'quê', 'quem', 'saber', 'são', 'se', 'seja', 'sejam', 'sem', 'sempre', 'sendo', 'ser', 'será', 'serão', 'seu', 'seus', 'si', 'sido', 'só', 'sob', 'sobre', 'somente', 'sua', 'suas', 'tal', 'talvez', 'também', 'tampouco', 'te', 'tem', 'têm', 'tempo', 'tendo', 'tenha', 'tenho', 'tentaram', 'tentarem', 'ter', 'teu', 'teus', 'teve', 'ti', 'tido', 'tinha', 'tinham', 'tipo', 'tive', 'toda', 'todas', 'todavia', 'todo', 'todos', 'tu', 'tua', 'tuas', 'tudo', 'última', 'últimas', 'último', 'últimos', 'um', 'uma', 'umas', 'uns', 'usa', 'usar', 'veja', 'vendo', 'ver', 'verdade', 'verdadeiro', 'vez', 'vindo', 'vir', 'você');
magic.php CHANGED
@@ -4,94 +4,67 @@
4
5
function yarpp_set_score_override_flag($q) {
6
global $yarpp_cache;
7
- if ($yarpp_cache->yarpp_time) {
8
$yarpp_cache->score_override = ($q->query_vars['orderby'] == 'score');
9
10
if (!empty($q->query_vars['showposts'])) {
11
$yarpp_cache->online_limit = $q->query_vars['showposts'];
12
} else {
13
$yarpp_cache->online_limit = false;
14
- }
15
} else {
16
- $yarpp_cache->score_override = false;
17
- $yarpp_cache->online_limit = false;
18
}
19
}
20
21
//=CACHING===========
22
23
- function yarpp_sql($args,$giveresults = true,$reference_ID=false,$domain='website') {
24
global $wpdb, $post, $yarpp_debug, $yarpp_cache;
25
26
- if (is_object($post) and !$reference_ID) {
27
$reference_ID = $post->ID;
28
}
29
30
- // set the "domain prefix", used for all the preferences.
31
- if ($domain == 'rss')
32
- $domainprefix = 'rss_';
33
- else
34
- $domainprefix = '';
35
-
36
- $options = array('limit'=>"${domainprefix}limit",
37
- 'threshold'=>'threshold',
38
- 'show_pass_post'=>'show_pass_post',
39
- 'past_only'=>'past_only',
40
- 'body'=>'body',
41
- 'title'=>'title',
42
- 'tags'=>'tags',
43
- 'categories'=>'categories',
44
- 'distags'=>'distags',
45
- 'discats'=>'discats',
46
- 'recent_only'=>'recent_only',
47
- 'recent_number'=>'recent_number',
48
- 'recent_units'=>'recent_units');
49
- $optvals = array();
50
- foreach (array_keys($options) as $option) {
51
- if (isset($args[$option])) {
52
- $optvals[$option] = stripslashes($args[$option]);
53
- } else {
54
- $optvals[$option] = stripslashes(stripslashes(yarpp_get_option($options[$option])));
55
- }
56
- }
57
-
58
extract($optvals);
59
60
- // Fetch keywords
61
- $body_terms = $yarpp_cache->get_keywords($reference_ID,'body');
62
- $title_terms = $yarpp_cache->get_keywords($reference_ID,'title');
63
64
- if ($yarpp_debug) echo "<!--TITLE TERMS: $title_terms-->"; // debug
65
- if ($yarpp_debug) echo "<!--BODY TERMS: $body_terms-->"; // debug
66
67
// get weights
68
-
69
- $bodyweight = (($body == 3)?3:(($body == 2)?1:0));
70
- $titleweight = (($title == 3)?3:(($title == 2)?1:0));
71
- $tagweight = (($tags != 1)?1:0);
72
- $catweight = (($categories != 1)?1:0);
73
- $weights = array();
74
- $weights['body'] = $bodyweight;
75
- $weights['title'] = $titleweight;
76
- $weights['cat'] = $catweight;
77
- $weights['tag'] = $tagweight;
78
-
79
- $totalweight = $bodyweight + $titleweight + $tagweight + $catweight;
80
81
// get disallowed categories and tags
82
-
83
- $disterms = implode(',', array_filter(array_merge(explode(',',$discats),explode(',',$distags)),'is_numeric'));
84
-
85
- $usedisterms = count(array_filter(array_merge(explode(',',$discats),explode(',',$distags)),'is_numeric'));
86
87
$criteria = array();
88
- if ($bodyweight)
89
- $criteria['body'] = "(MATCH (post_content) AGAINST ('".$wpdb->escape($body_terms)."'))";
90
- if ($titleweight)
91
- $criteria['title'] = "(MATCH (post_title) AGAINST ('".$wpdb->escape($title_terms)."'))";
92
- if ($tagweight)
93
$criteria['tag'] = "COUNT( DISTINCT tagtax.term_taxonomy_id )";
94
- if ($catweight)
95
$criteria['cat'] = "COUNT( DISTINCT cattax.term_taxonomy_id )";
96
97
$newsql = "SELECT $reference_ID as reference_ID, ID, "; //post_title, post_date, post_content, post_excerpt,
@@ -109,14 +82,14 @@ function yarpp_sql($args,$giveresults = true,$reference_ID=false,$domain='websit
109
left join $wpdb->term_taxonomy as blocktax using (`term_taxonomy_id`)
110
left join $wpdb->terms as blockterm on (blocktax.term_id = blockterm.term_id and blockterm.term_id in ($disterms))\n";
111
112
- if ($tagweight)
113
$newsql .= " left JOIN $wpdb->term_relationships AS thistag ON (thistag.object_id = $reference_ID )
114
left JOIN $wpdb->term_relationships AS tagrel on (tagrel.term_taxonomy_id = thistag.term_taxonomy_id
115
AND tagrel.object_id = $wpdb->posts.ID)
116
left JOIN $wpdb->term_taxonomy AS tagtax ON ( tagrel.term_taxonomy_id = tagtax.term_taxonomy_id
117
AND tagtax.taxonomy = 'post_tag')\n";
118
119
- if ($catweight)
120
$newsql .= " left JOIN $wpdb->term_relationships AS thiscat ON (thiscat.object_id = $reference_ID )
121
left JOIN $wpdb->term_relationships AS catrel on (catrel.term_taxonomy_id = thiscat.term_taxonomy_id
122
AND catrel.object_id = $wpdb->posts.ID)
@@ -125,13 +98,13 @@ function yarpp_sql($args,$giveresults = true,$reference_ID=false,$domain='websit
125
126
// WHERE
127
128
- $newsql .= " where (post_status IN ( 'publish', 'static' ) and ID != '$reference_ID')";
129
130
if ($past_only) { // 3.1.8: revised $past_only option
131
- if ( is_object($post) && $reference_ID == $post->ID )
132
- $reference_post_date = $post->post_date;
133
- else
134
- $reference_post_date = $wpdb->get_var("select post_date from $wpdb->posts where ID = $reference_ID");
135
$newsql .= " and post_date <= '$reference_post_date' ";
136
}
137
if (!$show_pass_post)
@@ -139,7 +112,7 @@ function yarpp_sql($args,$giveresults = true,$reference_ID=false,$domain='websit
139
if ($recent_only)
140
$newsql .= " and post_date > date_sub(now(), interval $recent_number $recent_units) ";
141
142
- $newsql .= " and post_type = 'post'";
143
144
// GROUP BY
145
$newsql .= "\n group by ID \n";
@@ -157,13 +130,9 @@ function yarpp_sql($args,$giveresults = true,$reference_ID=false,$domain='websit
157
$newsql .= (($tags == 4)?' and '.$criteria['tag'].' >= 2':'');
158
$newsql .= " order by score desc limit ".$limit;
159
160
- if (!$giveresults) {
161
- $newsql = "select count(t.ID) from ($newsql) as t";
162
- }
163
-
164
- // in caching, we cross-relate regardless of whether we're going to actually
165
- // use it or not.
166
- $newsql = "($newsql) union (".str_replace("post_type = 'post'","post_type = 'page'",$newsql).")";
167
168
if ($yarpp_debug) echo "<!--$newsql-->";
169
return $newsql;
@@ -174,25 +143,25 @@ function yarpp_sql($args,$giveresults = true,$reference_ID=false,$domain='websit
174
/* new in 3.0! new query-based approach: EXTREMELY HACKY! */
175
176
function yarpp_related($type,$args,$echo = true,$reference_ID=false,$domain = 'website') {
177
- global $post, $wp_query, $id, $page, $pages, $authordata, $day, $currentmonth, $multipage, $more, $pagenow, $numpages, $yarpp_cache;
178
179
yarpp_upgrade_check();
180
181
- if ($domain != 'demo_web' and $domain != 'demo_rss') {
182
- if ($yarpp_cache->yarpp_time) // if we're already in a YARPP loop, stop now.
183
return false;
184
-
185
- if (is_object($post) and !$reference_ID)
186
- $reference_ID = $post->ID;
187
} else {
188
- if ($yarpp_cache->demo_time) // if we're already in a YARPP loop, stop now.
189
return false;
190
}
191
192
get_currentuserinfo();
193
194
// set the "domain prefix", used for all the preferences.
195
- if ($domain == 'rss' or $domain == 'demo_rss')
196
$domainprefix = 'rss_';
197
else
198
$domainprefix = '';
@@ -200,8 +169,8 @@ function yarpp_related($type,$args,$echo = true,$reference_ID=false,$domain = 'w
200
// get options
201
// 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
202
$options = array(
203
- 'cross_relate'=>"cross_relate",
204
- 'limit'=>"${domainprefix}limit",
205
'use_template'=>"${domainprefix}use_template",
206
'order'=>"${domainprefix}order",
207
'template_file'=>"${domainprefix}template_file",
@@ -209,9 +178,9 @@ function yarpp_related($type,$args,$echo = true,$reference_ID=false,$domain = 'w
209
$optvals = array();
210
foreach (array_keys($options) as $option) {
211
if (isset($args[$option])) {
212
- $optvals[$option] = stripslashes($args[$option]);
213
} else {
214
- $optvals[$option] = stripslashes(stripslashes(yarpp_get_option($options[$option])));
215
}
216
}
217
extract($optvals);
@@ -219,41 +188,44 @@ function yarpp_related($type,$args,$echo = true,$reference_ID=false,$domain = 'w
219
if ($cross_relate)
220
$type = array('post','page');
221
222
- yarpp_cache_enforce($reference_ID);
223
224
$output = '';
225
226
- if ($domain != 'demo_web' and $domain != 'demo_rss')
227
- $yarpp_cache->begin_yarpp_time($reference_ID); // get ready for YARPP TIME!
228
- else {
229
$yarpp_cache->demo_time = true;
230
if ($domain == 'demo_web')
231
$yarpp_cache->demo_limit = yarpp_get_option('limit');
232
else
233
$yarpp_cache->demo_limit = yarpp_get_option('rss_limit');
234
}
235
- // just so we can return to normal later
236
$current_query = $wp_query;
237
- $current_post = $post;
238
- $current_id = $id;
239
- $current_page = $page;
240
- $current_pages = $pages;
241
- $current_authordata = $authordata;
242
- $current_numpages = $numpages;
243
- $current_multipage = $multipage;
244
- $current_more = $more;
245
$current_pagenow = $pagenow;
246
- $current_day = $day;
247
- $current_currentmonth = $currentmonth;
248
249
- $related_query = new WP_Query();
250
$orders = explode(' ',$order);
251
- if ($domain != 'demo_web' and $domain != 'demo_rss')
252
- $related_query->query(array('p'=>$reference_ID,'orderby'=>$orders[0],'order'=>$orders[1],'showposts'=>$limit,'post_type'=>$type));
253
- else
254
- $related_query->query('');
255
256
- $wp_query = $related_query;
257
$wp_query->in_the_loop = true;
258
$wp_query->is_feed = $current_query->is_feed;
259
// make sure we get the right is_single value
@@ -273,25 +245,18 @@ function yarpp_related($type,$args,$echo = true,$reference_ID=false,$domain = 'w
273
include(YARPP_DIR.'/template-builtin.php');
274
}
275
276
- unset($related_query);
277
- if ($domain != 'demo_web' and $domain != 'demo_rss')
278
- $yarpp_cache->end_yarpp_time(); // YARPP time is over... :(
279
- else
280
$yarpp_cache->demo_time = false;
281
282
// restore the older wp_query.
283
- $wp_query = null; $wp_query = $current_query; unset($current_query);
284
- $post = null; $post = $current_post; unset($current_post);
285
- $authordata = null; $authordata = $current_authordata; unset($current_authordata);
286
- $pages = null; $pages = $current_pages; unset($current_pages);
287
- $id = $current_id; unset($current_id);
288
- $page = $current_page; unset($current_page);
289
- $numpages = null; $numpages = $current_numpages; unset($current_numpages);
290
- $multipage = null; $multipage = $current_multipage; unset($current_multipage);
291
- $more = null; $more = $current_more; unset($current_more);
292
- $pagenow = null; $pagenow = $current_pagenow; unset($current_pagenow);
293
- $day = null; $day = $current_day; unset($current_day);
294
- $currentmonth = null; $currentmonth = $current_currentmonth; unset($current_currentmonth);
295
296
if ($promote_yarpp and $domain != 'metabox')
297
$output .= "\n<p>".sprintf(__("Related posts brought to you by <a href='%s'>Yet Another Related Posts Plugin</a>.",'yarpp'), 'http://yarpp.org')."</p>";
@@ -304,21 +269,24 @@ function yarpp_related_exist($type,$args,$reference_ID=false) {
304
305
yarpp_upgrade_check();
306
307
- if (is_object($post) and !$reference_ID)
308
$reference_ID = $post->ID;
309
310
- if ($yarpp_cache->yarpp_time) // if we're already in a YARPP loop, stop now.
311
return false;
312
313
if (yarpp_get_option('cross_relate'))
314
$type = array('post','page');
315
316
- yarpp_cache_enforce($reference_ID);
317
318
$yarpp_cache->begin_yarpp_time($reference_ID); // get ready for YARPP TIME!
319
$related_query = new WP_Query();
320
// Note: why is this 10000? Should we just make it 1?
321
- $related_query->query(array('p'=>$reference_ID,'showposts'=>10000,'post_type'=>$type));
322
$return = $related_query->have_posts();
323
unset($related_query);
324
$yarpp_cache->end_yarpp_time(); // YARPP time is over. :(
@@ -345,48 +313,55 @@ function yarpp_save_cache($post_ID, $force=true) {
345
// Clear the cache for this entry and for all posts which are "related" to it.
346
// New in 3.2: This is called when a post is deleted.
347
function yarpp_delete_cache($post_ID) {
348
- global $yarpp_cache;
349
350
- // Clear the cache for this post.
351
$yarpp_cache->clear($post_ID);
352
353
// Find all "peers" which list this post as a related post.
354
$peers = $yarpp_cache->related(null, $post_ID);
355
// Clear the peers' caches.
356
- $yarpp_cache->clear($peers);
357
}
358
359
// New in 3.2.1: handle various post_status transitions
360
function yarpp_status_transition($new_status, $old_status, $post) {
361
- global $yarpp_cache;
362
- switch ($new_status) {
363
- case "draft":
364
- yarpp_delete_cache($post->ID);
365
- break;
366
- case "publish":
367
- // find everything which is related to this post, and clear them, so that this
368
- // post might show up as related to them.
369
- $related = $yarpp_cache->related($post->ID, null);
370
- $yarpp_cache->clear($related);
371
- }
372
}
373
374
- function yarpp_cache_enforce($reference_ID, $force=false) {
375
global $yarpp_debug, $yarpp_cache;
376
377
- if ( empty($reference_ID) || !is_int($reference_ID) )
378
- return false;
379
-
380
- if (!$force && $yarpp_cache->is_cached($reference_ID)) {
381
- if ($yarpp_debug) echo "<!--YARPP is using the cache right now.-->";
382
return false;
383
- }
384
385
- $yarpp_cache->cache_keywords($reference_ID);
386
387
- // let's update the related post
388
- $yarpp_cache->update($reference_ID);
389
- return true;
390
391
}
392
4
5
function yarpp_set_score_override_flag($q) {
6
global $yarpp_cache;
7
+ if ($yarpp_cache->is_yarpp_time()) {
8
$yarpp_cache->score_override = ($q->query_vars['orderby'] == 'score');
9
10
if (!empty($q->query_vars['showposts'])) {
11
$yarpp_cache->online_limit = $q->query_vars['showposts'];
12
} else {
13
$yarpp_cache->online_limit = false;
14
+ }
15
} else {
16
+ $yarpp_cache->score_override = false;
17
+ $yarpp_cache->online_limit = false;
18
}
19
}
20
21
//=CACHING===========
22
23
+ function yarpp_sql( $reference_ID = false ) {
24
global $wpdb, $post, $yarpp_debug, $yarpp_cache;
25
26
+ if ( is_object($post) && !$reference_ID ) {
27
$reference_ID = $post->ID;
28
}
29
30
+ $options = array( 'threshold', 'show_pass_post', 'past_only', 'body', 'title', 'tags', 'categories', 'distags', 'discats', 'recent_only', 'recent_number', 'recent_units');
31
+ $yarpp_options = yarpp_get_option();
32
+ // mask it so we only get the ones specified in $options
33
+ $optvals = array_intersect_key($yarpp_options, array_flip($options));
34
extract($optvals);
35
36
+ $limit = max(yarpp_get_option('limit'), yarpp_get_option('rss_limit'));
37
38
+ // Fetch keywords
39
+ $keywords = $yarpp_cache->get_keywords($reference_ID);
40
41
// get weights
42
+ $weights = array(
43
+ 'body' => (($body == 3)?3:(($body == 2)?1:0)),
44
+ 'title' => (($title == 3)?3:(($title == 2)?1:0)),
45
+ 'tag' => (($tags != 1)?1:0),
46
+ 'cat' => (($categories != 1)?1:0)
47
+ );
48
+ $totalweight = array_sum( array_values( $weights ) );
49
50
// get disallowed categories and tags
51
+ $disterms = array_filter(
52
+ array_merge(
53
+ explode(',',$discats),
54
+ explode(',',$distags)
55
+ ),
56
+ 'is_numeric');
57
+ $usedisterms = count($disterms);
58
+ $disterms = implode(',', $disterms);
59
60
$criteria = array();
61
+ if ($weights['body'])
62
+ $criteria['body'] = "(MATCH (post_content) AGAINST ('".$wpdb->escape($keywords['body'])."'))";
63
+ if ($weights['title'])
64
+ $criteria['title'] = "(MATCH (post_title) AGAINST ('".$wpdb->escape($keywords['title'])."'))";
65
+ if ($weights['tag'])
66
$criteria['tag'] = "COUNT( DISTINCT tagtax.term_taxonomy_id )";
67
+ if ($weights['cat'])
68
$criteria['cat'] = "COUNT( DISTINCT cattax.term_taxonomy_id )";
69
70
$newsql = "SELECT $reference_ID as reference_ID, ID, "; //post_title, post_date, post_content, post_excerpt,
82
left join $wpdb->term_taxonomy as blocktax using (`term_taxonomy_id`)
83
left join $wpdb->terms as blockterm on (blocktax.term_id = blockterm.term_id and blockterm.term_id in ($disterms))\n";
84
85
+ if ($weights['tag'])
86
$newsql .= " left JOIN $wpdb->term_relationships AS thistag ON (thistag.object_id = $reference_ID )
87
left JOIN $wpdb->term_relationships AS tagrel on (tagrel.term_taxonomy_id = thistag.term_taxonomy_id
88
AND tagrel.object_id = $wpdb->posts.ID)
89
left JOIN $wpdb->term_taxonomy AS tagtax ON ( tagrel.term_taxonomy_id = tagtax.term_taxonomy_id
90
AND tagtax.taxonomy = 'post_tag')\n";
91
92
+ if ($weights['cat'])
93
$newsql .= " left JOIN $wpdb->term_relationships AS thiscat ON (thiscat.object_id = $reference_ID )
94
left JOIN $wpdb->term_relationships AS catrel on (catrel.term_taxonomy_id = thiscat.term_taxonomy_id
95
AND catrel.object_id = $wpdb->posts.ID)
98
99
// WHERE
100
101
+ $newsql .= " where (post_status IN ( 'publish', 'static' ) and ID != '$reference_ID')";
102
103
if ($past_only) { // 3.1.8: revised $past_only option
104
+ if ( is_object($post) && $reference_ID == $post->ID )
105
+ $reference_post_date = $post->post_date;
106
+ else
107
+ $reference_post_date = $wpdb->get_var("select post_date from $wpdb->posts where ID = $reference_ID");
108
$newsql .= " and post_date <= '$reference_post_date' ";
109
}
110
if (!$show_pass_post)
112
if ($recent_only)
113
$newsql .= " and post_date > date_sub(now(), interval $recent_number $recent_units) ";
114
115
+ $newsql .= " and post_type = 'post'";
116
117
// GROUP BY
118
$newsql .= "\n group by ID \n";
130
$newsql .= (($tags == 4)?' and '.$criteria['tag'].' >= 2':'');
131
$newsql .= " order by score desc limit ".$limit;
132
133
+ // in caching, we cross-relate regardless of whether we're going to actually
134
+ // use it or not.
135
+ $newsql = "($newsql) union (".str_replace("post_type = 'post'","post_type = 'page'",$newsql).")";
136
137
if ($yarpp_debug) echo "<!--$newsql-->";
138
return $newsql;
143
/* new in 3.0! new query-based approach: EXTREMELY HACKY! */
144
145
function yarpp_related($type,$args,$echo = true,$reference_ID=false,$domain = 'website') {
146
+ global $wp_query, $pagenow, $yarpp_cache;
147
148
yarpp_upgrade_check();
149
150
+ if ($domain == 'demo_web' || $domain == 'demo_rss') {
151
+ if ($yarpp_cache->demo_time) // if we're already in a YARPP loop, stop now.
152
return false;
153
} else {
154
+ if ($yarpp_cache->is_yarpp_time()) // if we're already in a YARPP loop, stop now.
155
return false;
156
+
157
+ if ( !$reference_ID )
158
+ $reference_ID = get_the_ID();
159
}
160
161
get_currentuserinfo();
162
163
// set the "domain prefix", used for all the preferences.
164
+ if ($domain == 'rss' || $domain == 'demo_rss')
165
$domainprefix = 'rss_';
166
else
167
$domainprefix = '';
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
+ 'cross_relate'=>"cross_relate",
173
+ 'limit'=>"${domainprefix}limit",
174
'use_template'=>"${domainprefix}use_template",
175
'order'=>"${domainprefix}order",
176
'template_file'=>"${domainprefix}template_file",
178
$optvals = array();
179
foreach (array_keys($options) as $option) {
180
if (isset($args[$option])) {
181
+ $optvals[$option] = $args[$option];
182
} else {
183
+ $optvals[$option] = yarpp_get_option($options[$option]);
184
}
185
}
186
extract($optvals);
188
if ($cross_relate)
189
$type = array('post','page');
190
191
+ $cache_status = yarpp_cache_enforce($reference_ID);
192
193
$output = '';
194
195
+ if ($domain == 'demo_web' || $domain == 'demo_rss') {
196
+ // It's DEMO TIME!
197
$yarpp_cache->demo_time = true;
198
if ($domain == 'demo_web')
199
$yarpp_cache->demo_limit = yarpp_get_option('limit');
200
else
201
$yarpp_cache->demo_limit = yarpp_get_option('rss_limit');
202
+ } else if ( YARPP_NO_RELATED == $cache_status ) {
203
+ // There are no results, so no yarpp time for us... :'(
204
+ } else {
205
+ // Get ready for YARPP TIME!
206
+ $yarpp_cache->begin_yarpp_time($reference_ID);
207
}
208
+
209
+ // so we can return to normal later
210
$current_query = $wp_query;
211
$current_pagenow = $pagenow;
212
213
+ $wp_query = new WP_Query();
214
$orders = explode(' ',$order);
215
+ if ( 'demo_web' == $domain || 'demo_rss' == $domain ) {
216
+ $wp_query->query('');
217
+ } else if ( YARPP_NO_RELATED == $cache_status ) {
218
+ // If there are no related posts, get no query
219
+ } else {
220
+ $wp_query->query(array(
221
+ 'p' => $reference_ID,
222
+ 'orderby' => $orders[0],
223
+ 'order' => $orders[1],
224
+ 'showposts' => $limit,
225
+ 'post_type' => $type
226
+ ));
227
+ }
228
229
$wp_query->in_the_loop = true;
230
$wp_query->is_feed = $current_query->is_feed;
231
// make sure we get the right is_single value
245
include(YARPP_DIR.'/template-builtin.php');
246
}
247
248
+ if ( 'demo_web' == $domain || 'demo_rss' == $domain ) {
249
$yarpp_cache->demo_time = false;
250
+ } else if ( YARPP_NO_RELATED == $cache_status ) {
251
+ // Uh, do nothing. Stay very still.
252
+ } else {
253
+ $yarpp_cache->end_yarpp_time(); // YARPP time is over... :(
254
+ }
255
256
// restore the older wp_query.
257
+ $wp_query = $current_query; unset($current_query);
258
+ wp_reset_postdata();
259
+ $pagenow = $current_pagenow; unset($current_pagenow);
260
261
if ($promote_yarpp and $domain != 'metabox')
262
$output .= "\n<p>".sprintf(__("Related posts brought to you by <a href='%s'>Yet Another Related Posts Plugin</a>.",'yarpp'), 'http://yarpp.org')."</p>";
269
270
yarpp_upgrade_check();
271
272
+ if (is_object($post) && !$reference_ID)
273
$reference_ID = $post->ID;
274
275
+ if ($yarpp_cache->is_yarpp_time()) // if we're already in a YARPP loop, stop now.
276
return false;
277
278
if (yarpp_get_option('cross_relate'))
279
$type = array('post','page');
280
281
+ $cache_status = yarpp_cache_enforce($reference_ID);
282
+
283
+ if ( YARPP_NO_RELATED == $cache_status )
284
+ return false;
285
286
$yarpp_cache->begin_yarpp_time($reference_ID); // get ready for YARPP TIME!
287
$related_query = new WP_Query();
288
// Note: why is this 10000? Should we just make it 1?
289
+ $related_query->query(array('p'=>$reference_ID,'showposts'=>1,'post_type'=>$type));
290
$return = $related_query->have_posts();
291
unset($related_query);
292
$yarpp_cache->end_yarpp_time(); // YARPP time is over. :(
313
// Clear the cache for this entry and for all posts which are "related" to it.
314
// New in 3.2: This is called when a post is deleted.
315
function yarpp_delete_cache($post_ID) {
316
+ global $yarpp_cache;
317
318
+ // Clear the cache for this post.
319
$yarpp_cache->clear($post_ID);
320
321
// Find all "peers" which list this post as a related post.
322
$peers = $yarpp_cache->related(null, $post_ID);
323
// Clear the peers' caches.
324
+ $yarpp_cache->clear($peers);
325
}
326
327
// New in 3.2.1: handle various post_status transitions
328
function yarpp_status_transition($new_status, $old_status, $post) {
329
+ global $yarpp_cache;
330
+ switch ($new_status) {
331
+ case "draft":
332
+ yarpp_delete_cache($post->ID);
333
+ break;
334
+ case "publish":
335
+ // find everything which is related to this post, and clear them, so that this
336
+ // post might show up as related to them.
337
+ $related = $yarpp_cache->related($post->ID, null);
338
+ $yarpp_cache->clear($related);
339
+ }
340
}
341
342
+ // Note: return value changed in 3.4
343
+ // return YARPP_NO_RELATED | YARPP_RELATED | false if no good input
344
+ function yarpp_cache_enforce($reference_ID, $force = false) {
345
global $yarpp_debug, $yarpp_cache;
346
347
+ if ( !$reference_ID = absint($reference_ID) )
348
return false;
349
350
+ $status = $yarpp_cache->is_cached($reference_ID);
351
+
352
+ // If not cached, process now:
353
+ if ( YARPP_NOT_CACHED == $status || $force ) {
354
+ $status = $yarpp_cache->update($reference_ID);
355
+ // if still not cached, there's a problem, but for the time being return NO RELATED
356
+ if ( YARPP_NOT_CACHED === $status )
357
+ return YARPP_NO_RELATED;
358
+ }
359
360
+ // There are no related posts
361
+ if ( YARPP_NO_RELATED === $status )
362
+ return YARPP_NO_RELATED;
363
364
+ // There are results
365
+ return YARPP_RELATED;
366
}
367
options-meta-boxes.php CHANGED
@@ -8,7 +8,7 @@ class YARPP_Meta_Box {
8
}
9
function textbox($option,$desc,$size=2,$tr="<tr valign='top'>
10
<th scope='row'>", $note = '') {
11
- $value = stripslashes(yarpp_get_option($option,true));
12
echo " $tr$desc</th>
13
<td><input name='$option' type='text' id='$option' value='$value' size='$size' />";
14
if ( !empty($note) )
@@ -20,9 +20,9 @@ class YARPP_Meta_Box {
20
<th scope='row'>", $note = '') {
21
echo " $tr$desc</th>
22
<td>";
23
- $value = stripslashes(yarpp_get_option($options[0],true));
24
echo "<input name='{$options[0]}' type='text' id='{$options[0]}' value='$value' size='$size' /> / ";
25
- $value = stripslashes(yarpp_get_option($options[1],true));
26
echo "<input name='{$options[1]}' type='text' id='{$options[1]}' value='$value' size='$size' />";
27
if ( !empty($note) )
28
echo " <em><small>{$note}</small></em>";
@@ -70,15 +70,17 @@ class YARPP_Meta_Box {
70
71
function select($option,$desc,$type='word',$tr="<tr valign='top'>
72
<th scope='row'>",$inputplus = '') {
73
echo " $tr$desc</th>
74
<td>
75
- <input $inputplus type='radio' name='$option' value='1'". ((yarpp_get_option($option) == 1) ? ' checked="checked"': '' )." />
76
".__("do not consider",'yarpp')."
77
- <input $inputplus type='radio' name='$option' value='2'". ((yarpp_get_option($option) == 2) ? ' checked="checked"': '' )." />
78
".__("consider",'yarpp')."
79
- <input $inputplus type='radio' name='$option' value='3'". ((yarpp_get_option($option) == 3) ? ' checked="checked"': '' )." />
80
".sprintf(__("require at least one %s in common",'yarpp'),__($type,'yarpp'))."
81
- <input $inputplus type='radio' name='$option' value='4'". ((yarpp_get_option($option) == 4) ? ' checked="checked"': '' )." />
82
".sprintf(__("require more than one %s in common",'yarpp'),__($type,'yarpp'))."
83
</td>
84
</tr>";
@@ -100,11 +102,12 @@ class YARPP_Meta_Box_Pool extends YARPP_Meta_Box {
100
<?php
101
$this->checkbox('show_pass_post',__("Show password protected posts?",'yarpp'));
102
103
- $recent_number = "<input name=\"recent_number\" type=\"text\" id=\"recent_number\" value=\"".stripslashes(yarpp_get_option('recent_number',true))."\" size=\"2\" />";
104
$recent_units = "<select name=\"recent_units\" id=\"recent_units\">
105
- <option value='day'". (('day'==yarpp_get_option('recent_units'))?" selected='selected'":'').">".__('day(s)','yarpp')."</option>
106
- <option value='week'". (('week'==yarpp_get_option('recent_units'))?" selected='selected'":'').">".__('week(s)','yarpp')."</option>
107
- <option value='month'". (('month'==yarpp_get_option('recent_units'))?" selected='selected'":'').">".__('month(s)','yarpp')."</option>
108
</select>";
109
$this->checkbox('recent_only',str_replace('NUMBER',$recent_number,str_replace('UNITS',$recent_units,__("Show only posts from the past NUMBER UNITS",'yarpp'))));
110
?>
@@ -166,7 +169,7 @@ class YARPP_Meta_Box_Display_Web extends YARPP_Meta_Box {
166
<td>
167
<select name="template_file" id="template_file">
168
<?php foreach (glob(STYLESHEETPATH . '/yarpp-template-*.php') as $template): ?>
169
- <option value='<?php echo htmlspecialchars(basename($template))?>'<?php echo (basename($template)==yarpp_get_option('template_file'))?" selected='selected'":'';?>><?php echo htmlspecialchars(basename($template))?></option>
170
<?php endforeach; ?>
171
</select>
172
</td>
@@ -181,19 +184,20 @@ class YARPP_Meta_Box_Display_Web extends YARPP_Meta_Box {
181
182
<tr class="excerpted" valign='top'>
183
<th><?php _e("Before / after (Excerpt):",'yarpp');?></th>
184
- <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;<?php _e(' or ','yarpp');?>&lt;dl&gt;&lt;/dl&gt;</small></em>
185
</td>
186
</tr>
187
188
<tr valign='top'>
189
<th><?php _e("Order results:",'yarpp');?></th>
190
<td><select name="order" id="order">
191
- <option value="score DESC" <?php echo (yarpp_get_option('order')=='score DESC'?' selected="selected"':'')?>><?php _e("score (high relevance to low)",'yarpp');?></option>
192
- <option value="score ASC" <?php echo (yarpp_get_option('order')=='score ASC'?' selected="selected"':'')?>><?php _e("score (low relevance to high)",'yarpp');?></option>
193
- <option value="post_date DESC" <?php echo (yarpp_get_option('order')=='post_date DESC'?' selected="selected"':'')?>><?php _e("date (new to old)",'yarpp');?></option>
194
- <option value="post_date ASC" <?php echo (yarpp_get_option('order')=='post_date ASC'?' selected="selected"':'')?>><?php _e("date (old to new)",'yarpp');?></option>
195
- <option value="post_title ASC" <?php echo (yarpp_get_option('order')=='post_title ASC'?' selected="selected"':'')?>><?php _e("title (alphabetical)",'yarpp');?></option>
196
- <option value="post_title DESC" <?php echo (yarpp_get_option('order')=='post_title DESC'?' selected="selected"':'')?>><?php _e("title (reverse alphabetical)",'yarpp');?></option>
197
</select>
198
</td>
199
</tr>
@@ -253,12 +257,13 @@ $this->checkbox('rss_excerpt_display',__("Display related posts in the descripti
253
<tr class='rss_displayed' valign='top'>
254
<th><?php _e("Order results:",'yarpp');?></th>
255
<td><select name="rss_order" id="rss_order">
256
- <option value="score DESC" <?php echo (yarpp_get_option('rss_order')=='score DESC'?' selected="selected"':'')?>><?php _e("score (high relevance to low)",'yarpp');?></option>
257
- <option value="score ASC" <?php echo (yarpp_get_option('rss_order')=='score ASC'?' selected="selected"':'')?>><?php _e("score (low relevance to high)",'yarpp');?></option>
258
- <option value="post_date DESC" <?php echo (yarpp_get_option('rss_order')=='post_date DESC'?' selected="selected"':'')?>><?php _e("date (new to old)",'yarpp');?></option>
259
- <option value="post_date ASC" <?php echo (yarpp_get_option('rss_order')=='post_date ASC'?' selected="selected"':'')?>><?php _e("date (old to new)",'yarpp');?></option>
260
- <option value="post_title ASC" <?php echo (yarpp_get_option('rss_order')=='post_title ASC'?' selected="selected"':'')?>><?php _e("title (alphabetical)",'yarpp');?></option>
261
- <option value="post_title DESC" <?php echo (yarpp_get_option('rss_order')=='post_title DESC'?' selected="selected"':'')?>><?php _e("title (reverse alphabetical)",'yarpp');?></option>
262
</select>
263
</td>
264
</tr>
8
}
9
function textbox($option,$desc,$size=2,$tr="<tr valign='top'>
10
<th scope='row'>", $note = '') {
11
+ $value = esc_attr(yarpp_get_option($option));
12
echo " $tr$desc</th>
13
<td><input name='$option' type='text' id='$option' value='$value' size='$size' />";
14
if ( !empty($note) )
20
<th scope='row'>", $note = '') {
21
echo " $tr$desc</th>
22
<td>";
23
+ $value = esc_attr(yarpp_get_option($options[0]));
24
echo "<input name='{$options[0]}' type='text' id='{$options[0]}' value='$value' size='$size' /> / ";
25
+ $value = esc_attr(yarpp_get_option($options[1]));
26
echo "<input name='{$options[1]}' type='text' id='{$options[1]}' value='$value' size='$size' />";
27
if ( !empty($note) )
28
echo " <em><small>{$note}</small></em>";
70
71
function select($option,$desc,$type='word',$tr="<tr valign='top'>
72
<th scope='row'>",$inputplus = '') {
73
+ $value = yarpp_get_option($option);
74
+
75
echo " $tr$desc</th>
76
<td>
77
+ <input $inputplus type='radio' name='$option' value='1'". (($value == 1) ? ' checked="checked"': '' )." />
78
".__("do not consider",'yarpp')."
79
+ <input $inputplus type='radio' name='$option' value='2'". (($value == 2) ? ' checked="checked"': '' )." />
80
".__("consider",'yarpp')."
81
+ <input $inputplus type='radio' name='$option' value='3'". (($value == 3) ? ' checked="checked"': '' )." />
82
".sprintf(__("require at least one %s in common",'yarpp'),__($type,'yarpp'))."
83
+ <input $inputplus type='radio' name='$option' value='4'". (($value == 4) ? ' checked="checked"': '' )." />
84
".sprintf(__("require more than one %s in common",'yarpp'),__($type,'yarpp'))."
85
</td>
86
</tr>";
102
<?php
103
$this->checkbox('show_pass_post',__("Show password protected posts?",'yarpp'));
104
105
+ $recent_number = "<input name=\"recent_number\" type=\"text\" id=\"recent_number\" value=\"".esc_attr(yarpp_get_option('recent_number'))."\" size=\"2\" />";
106
+ $recent_units = yarpp_get_option('recent_units');
107
$recent_units = "<select name=\"recent_units\" id=\"recent_units\">
108
+ <option value='day'". (('day'==$recent_units)?" selected='selected'":'').">".__('day(s)','yarpp')."</option>
109
+ <option value='week'". (('week'==$recent_units)?" selected='selected'":'').">".__('week(s)','yarpp')."</option>
110
+ <option value='month'". (('month'==$recent_units)?" selected='selected'":'').">".__('month(s)','yarpp')."</option>
111
</select>";
112
$this->checkbox('recent_only',str_replace('NUMBER',$recent_number,str_replace('UNITS',$recent_units,__("Show only posts from the past NUMBER UNITS",'yarpp'))));
113
?>
169
<td>
170
<select name="template_file" id="template_file">
171
<?php foreach (glob(STYLESHEETPATH . '/yarpp-template-*.php') as $template): ?>
172
+ <option value='<?php echo esc_attr(basename($template))?>'<?php echo (basename($template)==yarpp_get_option('template_file'))?" selected='selected'":'';?>><?php echo htmlspecialchars(basename($template))?></option>
173
<?php endforeach; ?>
174
</select>
175
</td>
184
185
<tr class="excerpted" valign='top'>
186
<th><?php _e("Before / after (Excerpt):",'yarpp');?></th>
187
+ <td><input name="before_post" type="text" id="before_post" value="<?php echo esc_attr(yarpp_get_option('before_post')); ?>" size="10" /> / <input name="after_post" type="text" id="after_post" value="<?php echo esc_attr(yarpp_get_option('after_post')); ?>" size="10" /><em><small> <?php _e("For example:",'yarpp');?> &lt;li&gt;&lt;/li&gt;<?php _e(' or ','yarpp');?>&lt;dl&gt;&lt;/dl&gt;</small></em>
188
</td>
189
</tr>
190
191
<tr valign='top'>
192
<th><?php _e("Order results:",'yarpp');?></th>
193
<td><select name="order" id="order">
194
+ <?php $order = yarpp_get_option('order'); ?>
195
+ <option value="score DESC" <?php echo ($order == 'score DESC'?' selected="selected"':'')?>><?php _e("score (high relevance to low)",'yarpp');?></option>
196
+ <option value="score ASC" <?php echo ($order == 'score ASC'?' selected="selected"':'')?>><?php _e("score (low relevance to high)",'yarpp');?></option>
197
+ <option value="post_date DESC" <?php echo ($order == 'post_date DESC'?' selected="selected"':'')?>><?php _e("date (new to old)",'yarpp');?></option>
198
+ <option value="post_date ASC" <?php echo ($order == 'post_date ASC'?' selected="selected"':'')?>><?php _e("date (old to new)",'yarpp');?></option>
199
+ <option value="post_title ASC" <?php echo ($order == 'post_title ASC'?' selected="selected"':'')?>><?php _e("title (alphabetical)",'yarpp');?></option>
200
+ <option value="post_title DESC" <?php echo ($order == 'post_title DESC'?' selected="selected"':'')?>><?php _e("title (reverse alphabetical)",'yarpp');?></option>
201
</select>
202
</td>
203
</tr>
257
<tr class='rss_displayed' valign='top'>
258
<th><?php _e("Order results:",'yarpp');?></th>
259
<td><select name="rss_order" id="rss_order">
260
+ <?php $order = yarpp_get_option('rss_order'); ?>
261
+ <option value="score DESC" <?php echo ($order=='score DESC'?' selected="selected"':'')?>><?php _e("score (high relevance to low)",'yarpp');?></option>
262
+ <option value="score ASC" <?php echo ($order == 'score ASC'?' selected="selected"':'')?>><?php _e("score (low relevance to high)",'yarpp');?></option>
263
+ <option value="post_date DESC" <?php echo ($order == 'post_date DESC'?' selected="selected"':'')?>><?php _e("date (new to old)",'yarpp');?></option>
264
+ <option value="post_date ASC" <?php echo ($order == 'post_date ASC'?' selected="selected"':'')?>><?php _e("date (old to new)",'yarpp');?></option>
265
+ <option value="post_title ASC" <?php echo ($order == 'post_title ASC'?' selected="selected"':'')?>><?php _e("title (alphabetical)",'yarpp');?></option>
266
+ <option value="post_title DESC" <?php echo ($order == 'post_title DESC'?' selected="selected"':'')?>><?php _e("title (reverse alphabetical)",'yarpp');?></option>
267
</select>
268
</td>
269
</tr>
options.php CHANGED
@@ -3,7 +3,7 @@
3
global $wpdb, $yarpp_value_options, $yarpp_binary_options, $wp_version, $yarpp_cache, $yarpp_templates, $yarpp_myisam;
4
5
// Reenforce YARPP setup:
6
- if (!get_option('yarpp_version'))
7
yarpp_activate();
8
else
9
yarpp_upgrade_check();
@@ -16,8 +16,7 @@ if (isset($_GET['action']) && $_GET['action'] == 'flush') {
16
// check to see that templates are in the right place
17
$yarpp_templates = glob(STYLESHEETPATH . '/yarpp-template-*.php');
18
if ( !(is_array($yarpp_templates) && count($yarpp_templates)) ) {
19
- yarpp_set_option('use_template',false);
20
- yarpp_set_option('rss_use_template',false);
21
}
22
23
// 3.3: move version checking here, in PHP:
@@ -56,7 +55,7 @@ if (isset($_POST['myisam_override'])) {
56
}
57
58
$yarpp_myisam = true;
59
- if (!yarpp_get_option('myisam_override')) {
60
$yarpp_check_return = yarpp_myisam_check();
61
if ($yarpp_check_return !== true) { // if it's not *exactly* true
62
echo "<div class='updated'>"
@@ -71,8 +70,7 @@ if (!yarpp_get_option('myisam_override')) {
71
."'></input></form>"
72
."</div>";
73
74
- yarpp_set_option('title',1);
75
- yarpp_set_option('body',1);
76
$yarpp_myisam = false;
77
}
78
}
@@ -89,28 +87,35 @@ if ($yarpp_myisam && !yarpp_enabled()) {
89
}
90
91
if (isset($_POST['update_yarpp'])) {
92
foreach (array_keys($yarpp_value_options) as $option) {
93
- if (isset($_POST[$option]) && is_string($_POST[$option]))
94
- yarpp_set_option($option,addslashes($_POST[$option]));
95
}
96
foreach (array('title','body','tags','categories') as $key) {
97
- if (!isset($_POST[$key])) yarpp_set_option($key,1);
98
}
99
- if (isset($_POST['discats'])) {
100
- yarpp_set_option('discats',implode(',',array_keys($_POST['discats']))); // discats is different
101
} else {
102
- yarpp_set_option('discats','');
103
}
104
105
- if (isset($_POST['distags'])) {
106
- yarpp_set_option('distags',implode(',',array_keys($_POST['distags']))); // distags is also different
107
} else {
108
- yarpp_set_option('distags','');
109
}
110
111
foreach (array_keys($yarpp_binary_options) as $option) {
112
- (isset($_POST[$option])) ? yarpp_set_option($option,1) : yarpp_set_option($option,0);
113
}
114
echo '<div class="updated fade"><p>'.__('Options saved!','yarpp').'</p></div>';
115
}
116
@@ -170,11 +175,11 @@ function load_display_discats() {
170
<div class="wrap">
171
<h2>
172
<?php _e('Yet Another Related Posts Plugin Options','yarpp');?> <small><?php
173
- echo yarpp_get_option('version');
174
?></small>
175
</h2>
176
177
- <?php echo "<div id='yarpp-version' style='display:none;'>".yarpp_get_option('version')."</div>"; ?>
178
179
<form method="post">
180
@@ -192,13 +197,13 @@ wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
192
193
<div class="inner-sidebar" id="side-info-column">
194
<?php
195
- do_meta_boxes('settings_page_yarpp', 'side', array());
196
?>
197
</div>
198
199
<div id="post-body-content">
200
<?php
201
- do_meta_boxes('settings_page_yarpp', 'normal', array());
202
?>
203
</div>
204
3
global $wpdb, $yarpp_value_options, $yarpp_binary_options, $wp_version, $yarpp_cache, $yarpp_templates, $yarpp_myisam;
4
5
// Reenforce YARPP setup:
6
+ if ( !get_option('yarpp_version') )
7
yarpp_activate();
8
else
9
yarpp_upgrade_check();
16
// check to see that templates are in the right place
17
$yarpp_templates = glob(STYLESHEETPATH . '/yarpp-template-*.php');
18
if ( !(is_array($yarpp_templates) && count($yarpp_templates)) ) {
19
+ yarpp_set_option(array('use_template' => false, 'rss_use_template' => false));
20
}
21
22
// 3.3: move version checking here, in PHP:
55
}
56
57
$yarpp_myisam = true;
58
+ if ( !yarpp_get_option('myisam_override') ) {
59
$yarpp_check_return = yarpp_myisam_check();
60
if ($yarpp_check_return !== true) { // if it's not *exactly* true
61
echo "<div class='updated'>"
70
."'></input></form>"
71
."</div>";
72
73
+ yarpp_set_option(array('title' => 1, 'body' => 1));
74
$yarpp_myisam = false;
75
}
76
}
87
}
88
89
if (isset($_POST['update_yarpp'])) {
90
+
91
+ $new_options = array();
92
+
93
foreach (array_keys($yarpp_value_options) as $option) {
94
+ if ( isset($_POST[$option]) && is_string($_POST[$option]) )
95
+ $new_options[$option] = stripslashes($_POST[$option]);
96
}
97
foreach (array('title','body','tags','categories') as $key) {
98
+ if ( !isset($_POST[$key]) )
99
+ $new_options[$key] = 1;
100
}
101
+ if ( isset($_POST['discats']) ) {
102
+ $new_options['discats'] = implode(',',array_keys($_POST['discats'])); // discats is different
103
} else {
104
+ $new_options['discats'] = '';
105
}
106
107
+ if ( isset($_POST['distags']) ) {
108
+ $new_options['distags'] = implode(',',array_keys($_POST['distags'])); // distags is also different
109
} else {
110
+ $new_options['distags'] = '';
111
}
112
113
foreach (array_keys($yarpp_binary_options) as $option) {
114
+ $new_options[$option] = isset($_POST[$option]);
115
}
116
+
117
+ yarpp_set_option($new_options);
118
+
119
echo '<div class="updated fade"><p>'.__('Options saved!','yarpp').'</p></div>';
120
}
121
175
<div class="wrap">
176
<h2>
177
<?php _e('Yet Another Related Posts Plugin Options','yarpp');?> <small><?php
178
+ echo esc_html(get_option('yarpp_version'));
179
?></small>
180
</h2>
181
182
+ <?php echo "<div id='yarpp-version' style='display:none;'>" . esc_html(get_option('yarpp_version')) . "</div>"; ?>
183
184
<form method="post">
185
197
198
<div class="inner-sidebar" id="side-info-column">
199
<?php
200
+ do_meta_boxes( 'settings_page_yarpp', 'side', array() );
201
?>
202
</div>
203
204
<div id="post-body-content">
205
<?php
206
+ do_meta_boxes( 'settings_page_yarpp', 'normal', array() );
207
?>
208
</div>
209
readme.txt CHANGED
@@ -199,6 +199,14 @@ If you are a bilingual speaker of English and another language and an avid user
199
200
== Changelog ==
201
202
= 3.3.3 =
203
* [Bug fix](http://wordpress.org/support/topic/no-related-posts-1): a fix for keyword computation for pages; should improve results on pages. May require flushing of cache: see FAQ for instructions.
204
* Init YARPP on the `init` action, [for compatibility with WPML](https://wordpress.org/support/topic/plugin-yet-another-related-posts-plugin-load-sequence-yarpp-starts-before-the-wordpress-init-completes)
199
200
== Changelog ==
201
202
+ = 3.4 =
203
+ * Significant code cleanup
204
+ * Removed the many different options entries, replacing them with a single `yarpp` option (except `yarpp_version`)
205
+ * Fixed issues with display options field data escaping and slashing once and for all
206
+ * Performance improvements on pages with "no related posts"
207
+ * Streamlined keyword storage in YARPP_Cache_Postmeta
208
+ * Updated minor bug for computing how many results should be cached
209
+ * Added Portuguese stopwords by Leandro Coelho ([Logística Descomplicada](http://www.logisticadescomplicada.com))
210
= 3.3.3 =
211
* [Bug fix](http://wordpress.org/support/topic/no-related-posts-1): a fix for keyword computation for pages; should improve results on pages. May require flushing of cache: see FAQ for instructions.
212
* Init YARPP on the `init` action, [for compatibility with WPML](https://wordpress.org/support/topic/plugin-yet-another-related-posts-plugin-load-sequence-yarpp-starts-before-the-wordpress-init-completes)
template-builtin.php CHANGED
@@ -18,17 +18,13 @@ $options = array(
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='" . esc_attr(get_the_title() ? get_the_title() : get_the_ID()) . "'>".get_the_title()."";
34
if (current_user_can('manage_options') && $domain != 'rss')
@@ -42,7 +38,7 @@ if ($related_query->have_posts()) {
42
$output .= $after_title."\n";
43
44
}
45
- $output = stripslashes(stripslashes($before_related)).$output.stripslashes(stripslashes($after_related));
46
} else {
47
$output = $no_results;
48
}
18
'no_results'=>"${domainprefix}no_results");
19
$optvals = array();
20
foreach (array_keys($options) as $option) {
21
+ $optvals[$option] = yarpp_get_option($options[$option]);
22
}
23
extract($optvals);
24
25
+ if (have_posts()) {
26
+ while (have_posts()) {
27
+ the_post();
28
29
$output .= "$before_title<a href='" . get_permalink() . "' rel='bookmark' title='" . esc_attr(get_the_title() ? get_the_title() : get_the_ID()) . "'>".get_the_title()."";
30
if (current_user_can('manage_options') && $domain != 'rss')
38
$output .= $after_title."\n";
39
40
}
41
+ $output = $before_related . $output . $after_related;
42
} else {
43
$output = $no_results;
44
}
template-metabox.php CHANGED
@@ -3,20 +3,19 @@ global $yarpp_debug;
3
4
yarpp_save_cache($reference_ID,false); // enforce the cache, but don't force it
5
6
- $body_terms = $yarpp_cache->get_keywords($reference_ID,'body');
7
- $title_terms = $yarpp_cache->get_keywords($reference_ID,'title');
8
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>";
21
$output .= ' ('.round(get_the_score(),3).')';
22
$output .= '</li>';
3
4
yarpp_save_cache($reference_ID,false); // enforce the cache, but don't force it
5
6
+ $keywords = $yarpp_cache->get_keywords($reference_ID);
7
8
+ if ($yarpp_debug) $output .= "<p>body keywords: {$keywords['body']}</p>";
9
+ if ($yarpp_debug) $output .= "<p>title keywords: {$keywords['title']}</p>";
10
11
$output .= '<p>'.__( 'These are the related entries for this entry. Updating this post may change these related posts.' , 'yarpp').'</p>';
12
13
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>";
14
15
+ if (have_posts()) {
16
$output .= '<ol>';
17
+ while (have_posts()) {
18
+ the_post();
19
$output .= "<li><a href='post.php?action=edit&post=$id'>".get_the_title()."</a>";
20
$output .= ' ('.round(get_the_score(),3).')';
21
$output .= '</li>';
template-widget.php CHANGED
@@ -1,9 +1,9 @@
1
<?php
2
3
- if ($related_query->have_posts()) {
4
$output .= '<ol>';
5
- while ($related_query->have_posts()) {
6
- $related_query->the_post();
7
$output .= '<li><a href="'.get_permalink().'" rel="bookmark">'.get_the_title().'</a>';
8
// $output .= ' ('.round(get_the_score(),3).')';
9
$output .= '</li>';
1
<?php
2
3
+ if (have_posts()) {
4
$output .= '<ol>';
5
+ while (have_posts()) {
6
+ the_post();
7
$output .= '<li><a href="'.get_permalink().'" rel="bookmark">'.get_the_title().'</a>';
8
// $output .= ' ('.round(get_the_score(),3).')';
9
$output .= '</li>';
yarpp.php CHANGED
@@ -3,14 +3,17 @@
3
Plugin Name: Yet Another Related Posts Plugin
4
Plugin URI: http://yarpp.org/
5
Description: Returns a list of related entries based on a unique algorithm for display on your blog and RSS feeds. A templating feature allows customization of the display.
6
- Version: 3.3.3
7
Author: mitcho (Michael Yoshitaka Erlewine)
8
Author URI: http://mitcho.com/
9
Donate link: http://tinyurl.com/donatetomitcho
10
*/
11
12
- define('YARPP_VERSION','3.3.3');
13
- define('YARPP_DIR',dirname(__FILE__));
14
15
require_once(YARPP_DIR.'/includes.php');
16
require_once(YARPP_DIR.'/related-functions.php');
3
Plugin Name: Yet Another Related Posts Plugin
4
Plugin URI: http://yarpp.org/
5
Description: Returns a list of related entries based on a unique algorithm for display on your blog and RSS feeds. A templating feature allows customization of the display.
6
+ Version: 3.4b2
7
Author: mitcho (Michael Yoshitaka Erlewine)
8
Author URI: http://mitcho.com/
9
Donate link: http://tinyurl.com/donatetomitcho
10
*/
11
12
+ define('YARPP_VERSION', '3.4b2');
13
+ define('YARPP_DIR', dirname(__FILE__));
14
+ define('YARPP_NO_RELATED', ':(');
15
+ define('YARPP_RELATED', ':)');
16
+ define('YARPP_NOT_CACHED', ':/');
17
18
require_once(YARPP_DIR.'/includes.php');
19
require_once(YARPP_DIR.'/related-functions.php');