Similar Posts – Best Related Posts Plugin for WordPress - Version 2.75

Version Description

Download this release

Release Info

Developer WebFactory
Plugin Icon 128x128 Similar Posts – Best Related Posts Plugin for WordPress
Version 2.75
Comparing to
See all releases

Code changes from version 2.71 to 2.75

admin-subpages.php CHANGED
@@ -3,8 +3,8 @@
3
  * Similar Posts
4
  * (c) Web factory Ltd, 2008 - 2017
5
  */
6
-
7
-
8
  /*
9
  A simple library class to ease the use of a further level of submenus in the admin pages
10
  Uses no javascript but 'borrows' some CSS it shouldn't
@@ -30,17 +30,17 @@ class admin_subpages {
30
  }
31
  $this->parent_page = $parent_page;
32
  }
33
-
34
  function add_subpage($title, $slug, $view) {
35
  $this->pages[] = array('title' => $title, 'slug' => $slug, 'view' => $view);
36
  }
37
-
38
  function add_subpages($pages) {
39
  foreach ($pages as $page) {
40
  $this->pages[] = array('title' => $page[0], 'slug' => $page[1], 'view' => $page[2]);
41
  }
42
  }
43
-
44
  function page_from_slug($slug) {
45
  if (!isset($slug) || !$slug) {
46
  return $this->pages[0];
@@ -54,12 +54,13 @@ class admin_subpages {
54
  }
55
 
56
  function display_menu() {
 
57
  echo "\n<ul id=\"submenu\" class=\"similarposts-tabs-menu\" style=\"display: block\">\n";
58
  // for compatibility with WP mu
59
  $base = (isset($_SERVER['REDIRECT_URL'])) ? $_SERVER['REDIRECT_URL'] : $_SERVER['PHP_SELF'];
60
  $base .= '?page=' . $this->parent_page . '&subpage=';
61
  $this->current_page = (isset($_GET['subpage']))?$this->page_from_slug($_GET['subpage']):$this->page_from_slug(false);
62
- foreach($this->pages as $page) {
63
  if($page === $this->current_page) {
64
  echo "<li style=\"display: inline\"><a href=\"$base{$page['slug']}\" class=\"current\" style=\"display: inline\">{$page['title']}</a></li>\n";
65
  } else {
@@ -68,7 +69,7 @@ class admin_subpages {
68
  }
69
  echo "</ul>\n";
70
  }
71
-
72
  function display_view() {
73
  $this->current_page['view']();
74
  }
@@ -77,5 +78,5 @@ class admin_subpages {
77
  $this->display_menu();
78
  $this->display_view();
79
  }
80
-
81
  }
3
  * Similar Posts
4
  * (c) Web factory Ltd, 2008 - 2017
5
  */
6
+
7
+
8
  /*
9
  A simple library class to ease the use of a further level of submenus in the admin pages
10
  Uses no javascript but 'borrows' some CSS it shouldn't
30
  }
31
  $this->parent_page = $parent_page;
32
  }
33
+
34
  function add_subpage($title, $slug, $view) {
35
  $this->pages[] = array('title' => $title, 'slug' => $slug, 'view' => $view);
36
  }
37
+
38
  function add_subpages($pages) {
39
  foreach ($pages as $page) {
40
  $this->pages[] = array('title' => $page[0], 'slug' => $page[1], 'view' => $page[2]);
41
  }
42
  }
43
+
44
  function page_from_slug($slug) {
45
  if (!isset($slug) || !$slug) {
46
  return $this->pages[0];
54
  }
55
 
56
  function display_menu() {
57
+ echo '<a title="Test your site\'s security with Security Ninja" id="ninja" href="https://wpsecurityninja.com/?utm_source=WP%20admin&utm_medium=banner&utm_campaign=Similar%20Posts&utm_content=ninja" target="_blank"><img title="Test your site\'s security with Security Ninja" alt="Test your site\'s security with Security Ninja" src="' . WP_PLUGIN_URL . '/similar-posts/images/ninja.png"></a>';
58
  echo "\n<ul id=\"submenu\" class=\"similarposts-tabs-menu\" style=\"display: block\">\n";
59
  // for compatibility with WP mu
60
  $base = (isset($_SERVER['REDIRECT_URL'])) ? $_SERVER['REDIRECT_URL'] : $_SERVER['PHP_SELF'];
61
  $base .= '?page=' . $this->parent_page . '&subpage=';
62
  $this->current_page = (isset($_GET['subpage']))?$this->page_from_slug($_GET['subpage']):$this->page_from_slug(false);
63
+ foreach($this->pages as $page) {
64
  if($page === $this->current_page) {
65
  echo "<li style=\"display: inline\"><a href=\"$base{$page['slug']}\" class=\"current\" style=\"display: inline\">{$page['title']}</a></li>\n";
66
  } else {
69
  }
70
  echo "</ul>\n";
71
  }
72
+
73
  function display_view() {
74
  $this->current_page['view']();
75
  }
78
  $this->display_menu();
79
  $this->display_view();
80
  }
81
+
82
  }
css/similar-posts-admin.css CHANGED
@@ -57,3 +57,9 @@
57
  .similarposts-inner-table tr td{
58
  border:1px solid #CCC;
59
  }
 
 
 
 
 
 
57
  .similarposts-inner-table tr td{
58
  border:1px solid #CCC;
59
  }
60
+
61
+ #ninja {
62
+ position: absolute;
63
+ right: 100px;
64
+ top: 67px;
65
+ }
images/ninja.png ADDED
Binary file
readme.txt CHANGED
@@ -1,11 +1,11 @@
1
- === Similar Posts - Powerful Related Posts Plugin for WordPress ===
2
  Contributors: WebFactory
3
  Tags: related posts, similar posts, connected posts, related posts widget, linked posts
4
  License: GPLv2 or later
5
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
6
  Requires at least: 4.0
7
- Tested up to: 4.7
8
- Stable tag: 2.71
9
 
10
  Displays a list of related posts similar to the current one based on content, title and/or tags. Works with all themes and is very customizable!
11
 
@@ -23,8 +23,6 @@ Similar Posts displays a list of posts that are similar or related to the curren
23
  * output in posts, widgets and RSS
24
  * over 50 options available
25
 
26
- [Full list of options and instructions](http://rmarsh.com/plugins/post-options/).
27
-
28
  Originally developed by [Robert Marsh](http://rmarsh.com/).
29
 
30
 
@@ -68,9 +66,12 @@ Read the <a href="http://wordpress.org/support/plugin/similar-posts">support for
68
 
69
  == ChangeLog ==
70
 
 
 
 
71
  * 2.71 - 2017/04/02
72
  * minor update
73
-
74
  * 2.7 - 2016/09/13
75
  * WebFactory took over development
76
  * no longer requires any additional plugins
1
+ === Similar Posts - Best Related Posts Plugin for WordPress ===
2
  Contributors: WebFactory
3
  Tags: related posts, similar posts, connected posts, related posts widget, linked posts
4
  License: GPLv2 or later
5
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
6
  Requires at least: 4.0
7
+ Tested up to: 4.9
8
+ Stable tag: 2.75
9
 
10
  Displays a list of related posts similar to the current one based on content, title and/or tags. Works with all themes and is very customizable!
11
 
23
  * output in posts, widgets and RSS
24
  * over 50 options available
25
 
 
 
26
  Originally developed by [Robert Marsh](http://rmarsh.com/).
27
 
28
 
66
 
67
  == ChangeLog ==
68
 
69
+ * 2.75 - 2017/07/27
70
+ * minor update
71
+
72
  * 2.71 - 2017/04/02
73
  * minor update
74
+
75
  * 2.7 - 2016/09/13
76
  * WebFactory took over development
77
  * no longer requires any additional plugins
similar-posts-admin.php CHANGED
@@ -3,8 +3,8 @@
3
  * Similar Posts
4
  * (c) Web factory Ltd, 2008 - 2017
5
  */
6
-
7
-
8
  // Admin stuff for Similar Posts Plugin, Version 2.6.2.0
9
 
10
  function similar_posts_option_menu() {
@@ -36,10 +36,10 @@ add_action('plugins_loaded', 'juggle_similar_posts_menus');
36
 
37
  function similar_posts_options_page(){
38
  echo '<div class="wrap"><h2>';
39
- _e('Similar Posts ', 'similar_posts');
40
  echo '</h2></div>';
41
-
42
-
43
  $m = new admin_subpages();
44
  $m->add_subpage('General', 'general', 'similar_posts_general_options_subpage');
45
  $m->add_subpage('Output', 'output', 'similar_posts_output_options_subpage');
@@ -48,90 +48,90 @@ function similar_posts_options_page(){
48
  $m->add_subpage('Misc', 'other', 'similar_posts_other_options_subpage');
49
  $m->add_subpage('Manage the Index', 'index', 'similar_posts_index_options_subpage');
50
  $m->display();
51
-
52
  //echo '<div class="wrap"><a target="_blank" href="http://rmarsh.com/plugins/post-options/">';
53
- //_e('Detailed help &amp; instructions');
54
  //echo '</a></div>';
55
-
56
  add_action('in_admin_footer', 'similar_posts_admin_footer');
57
  }
58
 
59
  function similar_posts_admin_footer() {
60
  ppl_admin_footer(str_replace('-admin', '', __FILE__), "similar-posts");
61
-
62
  }
63
 
64
  function similar_posts_general_options_subpage(){
65
  global $wpdb, $wp_version;
66
  $options = get_option('similar-posts');
67
  if (isset($_POST['update_options'])) {
68
- check_admin_referer('similar-posts-update-options');
69
  if (defined('POC_CACHE_4')) poc_cache_flush();
70
  // Fill up the options with the values chosen...
71
  $options = ppl_options_from_post($options, array('limit', 'skip', 'show_private', 'show_pages', 'show_attachments', 'status', 'age', 'omit_current_post', 'match_cat', 'match_tags', 'match_author'));
72
  update_option('similar-posts', $options);
73
  // Show a message to say we've done something
74
  echo '<div class="updated settings-error notice"><p>' . __('<b>Settings saved.</b>', 'similar_posts') . '</p></div>';
75
- }
76
  //now we drop into html to display the option page form
77
  ?>
78
  <div class="wrap similarposts-tab-content">
79
-
80
  <form method="post" action="">
81
-
82
  <table class="optiontable form-table">
83
- <?php
84
- ppl_display_limit($options['limit']);
85
- ppl_display_skip($options['skip']);
86
- ppl_display_show_private($options['show_private']);
87
- ppl_display_show_pages($options['show_pages']);
88
- ppl_display_show_attachments($options['show_attachments']);
89
  ppl_display_status($options['status']);
90
  ppl_display_age($options['age']);
91
- ppl_display_omit_current_post($options['omit_current_post']);
92
- ppl_display_match_cat($options['match_cat']);
93
- ppl_display_match_tags($options['match_tags']);
94
- ppl_display_match_author($options['match_author']);
95
  ?>
96
  </table>
97
  <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Settings', 'similar_posts') ?>" /></div>
98
  <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-update-options'); ?>
99
- </form>
100
  </div>
101
- <?php
102
  }
103
 
104
  function similar_posts_output_options_subpage(){
105
  global $wpdb, $wp_version;
106
  $options = get_option('similar-posts');
107
  if (isset($_POST['update_options'])) {
108
- check_admin_referer('similar-posts-update-options');
109
  if (defined('POC_CACHE_4')) poc_cache_flush();
110
  // Fill up the options with the values chosen...
111
  $options = ppl_options_from_post($options, array('output_template', 'prefix', 'suffix', 'none_text', 'no_text', 'divider', 'sort', 'group_template'));
112
  update_option('similar-posts', $options);
113
  // Show a message to say we've done something
114
  echo '<div class="updated settings-error notice"><p>' . __('<b>Settings saved.</b>', 'similar_posts') . '</p></div>';
115
- }
116
  //now we drop into html to display the option page form
117
  ?>
118
  <div class="wrap similarposts-tab-content">
119
-
120
  <form method="post" action="">
121
-
122
  <table class="optiontable form-table">
123
  <tr>
124
  <td style="padding-top: 0; vertical-align: top;">
125
  <table>
126
- <?php
127
- ppl_display_output_template($options['output_template']);
128
- ppl_display_prefix($options['prefix']);
129
- ppl_display_suffix($options['suffix']);
130
- ppl_display_none_text($options['none_text']);
131
- ppl_display_no_text($options['no_text']);
132
- ppl_display_divider($options['divider']);
133
  ppl_display_sort($options['sort']);
134
- ppl_display_group_template($options['group_template']);
135
  ?>
136
  </table>
137
  </td>
@@ -141,124 +141,124 @@ function similar_posts_output_options_subpage(){
141
  </table>
142
  <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Settings', 'similar_posts') ?>" /></div>
143
  <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-update-options'); ?>
144
- </form>
145
  </div>
146
- <?php
147
  }
148
 
149
  function similar_posts_filter_options_subpage(){
150
  global $wpdb, $wp_version;
151
  $options = get_option('similar-posts');
152
  if (isset($_POST['update_options'])) {
153
- check_admin_referer('similar-posts-update-options');
154
  if (defined('POC_CACHE_4')) poc_cache_flush();
155
  // Fill up the options with the values chosen...
156
  $options = ppl_options_from_post($options, array('excluded_posts', 'included_posts', 'excluded_authors', 'included_authors', 'excluded_cats', 'included_cats', 'tag_str', 'custom'));
157
  update_option('similar-posts', $options);
158
  // Show a message to say we've done something
159
  echo '<div class="updated settings-error notice"><p>' . __('<b>Settings saved.</b>', 'similar_posts') . '</p></div>';
160
- }
161
  //now we drop into html to display the option page form
162
  ?>
163
  <div class="wrap similarposts-tab-content">
164
-
165
  <form method="post" action="">
166
-
167
  <table class="optiontable form-table">
168
- <?php
169
- ppl_display_excluded_posts($options['excluded_posts']);
170
- ppl_display_included_posts($options['included_posts']);
171
- ppl_display_authors($options['excluded_authors'], $options['included_authors']);
172
- ppl_display_cats($options['excluded_cats'], $options['included_cats']);
173
- ppl_display_tag_str($options['tag_str']);
174
- ppl_display_custom($options['custom']);
175
  ?>
176
  </table>
177
  <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Settings', 'similar_posts') ?>" /></div>
178
  <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-update-options'); ?>
179
- </form>
180
  </div>
181
- <?php
182
  }
183
 
184
  function similar_posts_placement_options_subpage(){
185
  global $wpdb, $wp_version;
186
  $options = get_option('similar-posts');
187
  if (isset($_POST['update_options'])) {
188
- check_admin_referer('similar-posts-update-options');
189
  if (defined('POC_CACHE_4')) poc_cache_flush();
190
  // Fill up the options with the values chosen...
191
  $options = ppl_options_from_post($options, array('content_filter', 'widget_parameters', 'widget_condition', 'feed_on', 'feed_priority', 'feed_parameters', 'append_on', 'append_priority', 'append_parameters', 'append_condition'));
192
  update_option('similar-posts', $options);
193
  // Show a message to say we've done something
194
  echo '<div class="updated settings-error notice"><p>' . __('<b>Settings saved.</b>', 'similar_posts') . '</p></div>';
195
- }
196
  //now we drop into html to display the option page form
197
  ?>
198
  <div class="wrap similarposts-tab-content">
199
-
200
  <form method="post" action="">
201
-
202
  <table class="optiontable form-table">
203
- <?php
204
- ppl_display_append($options);
205
- ppl_display_feed($options);
206
- ppl_display_widget($options);
207
  ppl_display_content_filter($options['content_filter']);
208
  ?>
209
  </table>
210
  <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Settings', 'similar_posts') ?>" /></div>
211
  <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-update-options'); ?>
212
- </form>
213
  </div>
214
- <?php
215
  }
216
 
217
  function similar_posts_other_options_subpage(){
218
  global $wpdb, $wp_version;
219
  $options = get_option('similar-posts');
220
  if (isset($_POST['update_options'])) {
221
- check_admin_referer('similar-posts-update-options');
222
  if (defined('POC_CACHE_4')) poc_cache_flush();
223
  // Fill up the options with the values chosen...
224
  $options = ppl_options_from_post($options, array('stripcodes', 'feed_active', 'term_extraction', 'num_terms', 'weight_title', 'weight_content', 'weight_tags', 'hand_links'));
225
- $wcontent = $options['weight_content'] + 0.0001;
226
  $wtitle = $options['weight_title'] + 0.0001;
227
  $wtags = $options['weight_tags'] + 0.0001;
228
  $wcombined = $wcontent + $wtitle + $wtags;
229
- $options['weight_content'] = $wcontent / $wcombined;
230
- $options['weight_title'] = $wtitle / $wcombined;
231
- $options['weight_tags'] = $wtags / $wcombined;
232
  update_option('similar-posts', $options);
233
  // Show a message to say we've done something
234
  echo '<div class="updated settings-error notice"><p>' . __('<b>Settings saved.</b>', 'similar_posts') . '</p></div>';
235
- }
236
  //now we drop into html to display the option page form
237
  ?>
238
  <div class="wrap similarposts-tab-content">
239
-
240
  <form method="post" action="">
241
-
242
  <table class="optiontable form-table">
243
- <?php
244
- ppl_display_weights($options);
245
- ppl_display_num_terms($options['num_terms']);
246
- ppl_display_term_extraction($options['term_extraction']);
247
  ppl_display_hand_links($options['hand_links']);
248
  ppl_display_feed_active($options['feed_active']);
249
- ppl_display_stripcodes($options['stripcodes']);
250
  ?>
251
  </table>
252
  <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Settings', 'similar_posts') ?>" /></div>
253
  <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-update-options'); ?>
254
- </form>
255
  </div>
256
- <?php
257
  }
258
 
259
  function similar_posts_index_options_subpage(){
260
  if (isset($_POST['reindex_all'])) {
261
- check_admin_referer('similar-posts-manage-update-options');
262
  if (defined('POC_CACHE_4')) poc_cache_flush();
263
  $options = get_option('similar-posts');
264
  $options['utf8'] = $_POST['utf8'];
@@ -282,17 +282,17 @@ function similar_posts_index_options_subpage(){
282
  $options = get_option('similar-posts');
283
  }
284
  ?>
285
- <div class="wrap similarposts-tab-content">
286
- <?php
287
  echo '<p>'.__('Similar Posts maintains a special index to help search for related posts. The index is created when the plugin is activated and then kept up-to-date automatically when posts are added, edited, or deleted.', 'similar_posts').'</p>';
288
  echo '<p>'.__('The options that affect the index can be set below.', 'similar_posts').'</p>';
289
  echo '<p>'.__('If you are using a language other than english you may find that the plugin mangles some characters since PHP is normally blind to multibyte characters. You can force the plugin to interpret extended characters as UTF-8 at the expense of a little speed but this facility is only available if your installation of PHP supports the mbstring functions.', 'similar_posts').'</p>';
290
  echo '<p>'.__('Languages like Chinese, Korean and Japanese pose a special difficulty for the full-text search algorithm. As an experiment I have introduced an option below to work around some of these issues. The text must be encoded as UTF-8. I would be very grateful for feedback from any users knowledgeable in these languages.', 'similar_posts').'</p>';
291
- echo '<p>'.__('Some related word forms should really be counted together, e.g., "follow", "follows", and "following". By default, Similar Posts treats such differences strictly but has two other algorithms which are more relaxed: <em>stemming</em> and <em>fuzzy matching</em>. The stemming algorithm tries to reduce related forms to their root stem. Stemming algorithms are provided for english, german, spanish, french and italian but stemmers for other languages can be created: see the help for instructions. Fuzzy matching uses the "metaphone" algorithm to handle word variations. Note: both stemming and fuzzy matching slow down the indexing more than a little. It is worth experimenting with the three possibilities to see what improves the similarity of posts in your particular circumstances.', 'similar_posts').'</p>';
292
- echo '<p>'.__('The indexing routine processes posts in batches of 100 by default. If you run into problems with limited memory you can opt to make the batches smaller.', 'similar_posts').'</p>';
293
- echo '<p>'.__('Note: the process of indexing may take a little while. On my modest machine 500 posts take between 5 seconds and 20 seconds (with stemming and utf-8 support). Don\'t worry if the screen fails to update until finished.', 'similar_posts').'</p>';
294
  ?>
295
- <form method="post" action="">
296
  <table class="optiontable form-table">
297
  <tr valign="top">
298
  <th scope="row"><label for="utf8"><?php _e('Handle extended characters?', 'similar_posts') ?></label></th>
@@ -301,7 +301,7 @@ function similar_posts_index_options_subpage(){
301
  <option <?php if($options['utf8'] == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
302
  <option <?php if($options['utf8'] == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
303
  </select>
304
- </td>
305
  </tr>
306
  <tr valign="top">
307
  <th scope="row"><label for="cjk"><?php _e('Treat as Chinese, Korean, or Japanese?', 'similar_posts') ?></label></th>
@@ -310,7 +310,7 @@ function similar_posts_index_options_subpage(){
310
  <option <?php if($options['cjk'] == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
311
  <option <?php if($options['cjk'] == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
312
  </select>
313
- </td>
314
  </tr>
315
  <tr valign="top">
316
  <th scope="row"><label for="use_stemmer"><?php _e('Treat Related Word Variations:', 'similar_posts') ?></label></th>
@@ -320,7 +320,7 @@ function similar_posts_index_options_subpage(){
320
  <option <?php if($options['use_stemmer'] == 'true') { echo 'selected="selected"'; } ?> value="true">By Stem</option>
321
  <option <?php if($options['use_stemmer'] == 'fuzzy') { echo 'selected="selected"'; } ?> value="fuzzy">Fuzzily</option>
322
  </select>
323
- </td>
324
  </tr>
325
  <tr valign="top">
326
  <th scope="row"><label for="batch"><?php _e('Batch size:', 'similar_posts') ?></label></th>
@@ -330,8 +330,8 @@ function similar_posts_index_options_subpage(){
330
  <div class="submit">
331
  <input type="submit" class="button button-primary" name="reindex_all" value="<?php _e('Recreate Index', 'similar_posts') ?>" />
332
  <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-manage-update-options'); ?>
333
- </div>
334
- </form>
335
  </div>
336
  <?php
337
  }
@@ -340,9 +340,9 @@ function similar_posts_index_options_subpage(){
340
 
341
  function similar_posts_for_feed_options_page(){
342
  echo '<div class="wrap"><h2>';
343
- _e('Similar Posts Feed ', 'similar_posts');
344
  echo '<a href="http://rmarsh.com/plugins/post-options/" style="font-size: 0.8em;">';
345
- _e('help and instructions');
346
  echo '</a></h2></div>';
347
  $m = new admin_subpages();
348
  $m->add_subpage('General', 'general', 'similar_posts_feed_general_options_subpage');
@@ -356,14 +356,14 @@ function similar_posts_feed_general_options_subpage(){
356
  global $wpdb, $wp_version;
357
  $options = get_option('similar-posts-feed');
358
  if (isset($_POST['update_options'])) {
359
- check_admin_referer('similar-posts-feed-update-options');
360
  if (defined('POC_CACHE_4')) poc_cache_flush();
361
  // Fill up the options with the values chosen...
362
  $options = ppl_options_from_post($options, array('limit', 'skip', 'show_private', 'show_pages', 'show_attachments', 'status', 'age', 'omit_current_post', 'match_cat', 'match_tags', 'match_author'));
363
  update_option('similar-posts-feed', $options);
364
  // Show a message to say we've done something
365
  echo '<div class="updated fade similarposts-settings-saved"><p>' . __('Settings saved', 'similar_posts') . '</p></div>';
366
- }
367
  //now we drop into html to display the option page form
368
  ?>
369
  <div class="wrap similarposts-tab-content">
@@ -371,39 +371,39 @@ function similar_posts_feed_general_options_subpage(){
371
  <form method="post" action="">
372
  <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save General Settings', 'similar_posts') ?>" /></div>
373
  <table class="optiontable form-table">
374
- <?php
375
- ppl_display_limit($options['limit']);
376
- ppl_display_skip($options['skip']);
377
- ppl_display_show_private($options['show_private']);
378
- ppl_display_show_pages($options['show_pages']);
379
- ppl_display_show_attachments($options['show_attachments']);
380
  ppl_display_status($options['status']);
381
  ppl_display_age($options['age']);
382
- ppl_display_omit_current_post($options['omit_current_post']);
383
- ppl_display_match_cat($options['match_cat']);
384
- ppl_display_match_tags($options['match_tags']);
385
- ppl_display_match_author($options['match_author']);
386
  ?>
387
  </table>
388
  <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save General Settings', 'similar_posts') ?>" /></div>
389
  <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-feed-update-options'); ?>
390
- </form>
391
  </div>
392
- <?php
393
  }
394
 
395
  function similar_posts_feed_output_options_subpage(){
396
  global $wpdb, $wp_version;
397
  $options = get_option('similar-posts-feed');
398
  if (isset($_POST['update_options'])) {
399
- check_admin_referer('similar-posts-feed-update-options');
400
  if (defined('POC_CACHE_4')) poc_cache_flush();
401
  // Fill up the options with the values chosen...
402
  $options = ppl_options_from_post($options, array('output_template', 'prefix', 'suffix', 'none_text', 'no_text', 'divider', 'sort', 'group_template'));
403
  update_option('similar-posts-feed', $options);
404
  // Show a message to say we've done something
405
  echo '<div class="updated fade similarposts-settings-saved"><p>' . __('Settings saved', 'similar_posts') . '</p></div>';
406
- }
407
  //now we drop into html to display the option page form
408
  ?>
409
  <div class="wrap similarposts-tab-content">
@@ -414,15 +414,15 @@ function similar_posts_feed_output_options_subpage(){
414
  <tr>
415
  <td>
416
  <table>
417
- <?php
418
- ppl_display_output_template($options['output_template']);
419
- ppl_display_prefix($options['prefix']);
420
- ppl_display_suffix($options['suffix']);
421
- ppl_display_none_text($options['none_text']);
422
- ppl_display_no_text($options['no_text']);
423
- ppl_display_divider($options['divider']);
424
  ppl_display_sort($options['sort']);
425
- ppl_display_group_template($options['group_template']);
426
  ?>
427
  </table>
428
  </td>
@@ -432,23 +432,23 @@ function similar_posts_feed_output_options_subpage(){
432
  </table>
433
  <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Output Settings', 'similar_posts') ?>" /></div>
434
  <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-feed-update-options'); ?>
435
- </form>
436
  </div>
437
- <?php
438
  }
439
 
440
  function similar_posts_feed_filter_options_subpage(){
441
  global $wpdb, $wp_version;
442
  $options = get_option('similar-posts-feed');
443
  if (isset($_POST['update_options'])) {
444
- check_admin_referer('similar-posts-feed-update-options');
445
  if (defined('POC_CACHE_4')) poc_cache_flush();
446
  // Fill up the options with the values chosen...
447
  $options = ppl_options_from_post($options, array('excluded_posts', 'included_posts', 'excluded_authors', 'included_authors', 'excluded_cats', 'included_cats', 'tag_str', 'custom'));
448
  update_option('similar-posts-feed', $options);
449
  // Show a message to say we've done something
450
  echo '<div class="updated fade similarposts-settings-saved"><p>' . __('Settings saved', 'similar_posts') . '</p></div>';
451
- }
452
  //now we drop into html to display the option page form
453
  ?>
454
  <div class="wrap similarposts-tab-content">
@@ -456,41 +456,41 @@ function similar_posts_feed_filter_options_subpage(){
456
  <form method="post" action="">
457
  <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Filter Settings', 'similar_posts') ?>" /></div>
458
  <table class="optiontable form-table">
459
- <?php
460
- ppl_display_excluded_posts($options['excluded_posts']);
461
- ppl_display_included_posts($options['included_posts']);
462
- ppl_display_authors($options['excluded_authors'], $options['included_authors']);
463
- ppl_display_cats($options['excluded_cats'], $options['included_cats']);
464
- ppl_display_tag_str($options['tag_str']);
465
- ppl_display_custom($options['custom']);
466
  ?>
467
  </table>
468
  <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Filter Settings', 'similar_posts') ?>" /></div>
469
  <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-feed-update-options'); ?>
470
- </form>
471
  </div>
472
- <?php
473
  }
474
 
475
  function similar_posts_feed_other_options_subpage(){
476
  global $wpdb, $wp_version;
477
  $options = get_option('similar-posts-feed');
478
  if (isset($_POST['update_options'])) {
479
- check_admin_referer('similar-posts-feed-update-options');
480
  if (defined('POC_CACHE_4')) poc_cache_flush();
481
  // Fill up the options with the values chosen...
482
  $options = ppl_options_from_post($options, array('stripcodes', 'term_extraction', 'num_terms', 'weight_title', 'weight_content', 'weight_tags', 'hand_links'));
483
- $wcontent = $options['weight_content'] + 0.0001;
484
  $wtitle = $options['weight_title'] + 0.0001;
485
  $wtags = $options['weight_tags'] + 0.0001;
486
  $wcombined = $wcontent + $wtitle + $wtags;
487
- $options['weight_content'] = $wcontent / $wcombined;
488
- $options['weight_title'] = $wtitle / $wcombined;
489
- $options['weight_tags'] = $wtags / $wcombined;
490
  update_option('similar-posts-feed', $options);
491
  // Show a message to say we've done something
492
  echo '<div class="updated fade similarposts-settings-saved"><p>' . __('Settings saved', 'similar_posts') . '</p></div>';
493
- }
494
  //now we drop into html to display the option page form
495
  ?>
496
  <div class="wrap similarposts-tab-content">
@@ -498,19 +498,19 @@ function similar_posts_feed_other_options_subpage(){
498
  <form method="post" action="">
499
  <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Other Settings', 'similar_posts') ?>" /></div>
500
  <table class="optiontable form-table">
501
- <?php
502
- ppl_display_weights($options);
503
- ppl_display_num_terms($options['num_terms']);
504
- ppl_display_term_extraction($options['term_extraction']);
505
  ppl_display_hand_links($options['hand_links']);
506
- ppl_display_stripcodes($options['stripcodes']);
507
  ?>
508
  </table>
509
  <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Other Settings', 'similar_posts') ?>" /></div>
510
  <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-feed-update-options'); ?>
511
- </form>
512
  </div>
513
- <?php
514
  }
515
 
516
 
@@ -545,7 +545,7 @@ function save_index_entries ($utf8=false, $use_stemmer='false', $batch=100, $cjk
545
  // this function gets called when the plugin is installed to set up the index and default options
546
  function similar_posts_install() {
547
  global $wpdb, $table_prefix;
548
-
549
  $table_name = $table_prefix . 'similar_posts';
550
  $errorlevel = error_reporting(0);
551
  $suppress = $wpdb->hide_errors();
@@ -612,12 +612,12 @@ function similar_posts_install() {
612
  if (!isset($options['group_template'])) $options['group_template'] = '';
613
  if (!isset($options['weight_content'])) $options['weight_content'] = 0.9;
614
  if (!isset($options['weight_title'])) $options['weight_title'] = 0.1;
615
- if (!isset($options['weight_tags'])) $options['weight_tags'] = 0.0;
616
  if (!isset($options['num_terms'])) $options['num_terms'] = 20;
617
  if (!isset($options['term_extraction'])) $options['term_extraction'] = 'frequency';
618
  if (!isset($options['hand_links'])) $options['hand_links'] = 'false';
619
  update_option('similar-posts-feed', $options);
620
-
621
  $options = (array) get_option('similar-posts');
622
  // check each of the option values and, if empty, assign a default (doing it this long way
623
  // lets us add new options in later versions)
@@ -669,7 +669,7 @@ function similar_posts_install() {
669
  if (!isset($options['group_template'])) $options['group_template'] = '';
670
  if (!isset($options['weight_content'])) $options['weight_content'] = 0.9;
671
  if (!isset($options['weight_title'])) $options['weight_title'] = 0.1;
672
- if (!isset($options['weight_tags'])) $options['weight_tags'] = 0.0;
673
  if (!isset($options['num_terms'])) $options['num_terms'] = 20;
674
  if (!isset($options['term_extraction'])) $options['term_extraction'] = 'frequency';
675
  if (!isset($options['hand_links'])) $options['hand_links'] = 'false';
@@ -679,33 +679,33 @@ function similar_posts_install() {
679
  if (!function_exists('mb_internal_encoding')) $options['cjk'] = 'false';
680
  if (!isset($options['use_stemmer'])) $options['use_stemmer'] = 'false';
681
  if (!isset($options['batch'])) $options['batch'] = '100';
682
-
683
  update_option('similar-posts', $options);
684
 
685
  // initial creation of the index, if the table is empty
686
  $num_index_posts = $wpdb->get_var("SELECT COUNT(*) FROM `$table_name`");
687
- if ($num_index_posts == 0) save_index_entries (($options['utf8'] === 'true'), 'false', $options['batch'], ($options['cjk'] === 'true'));
688
 
689
  // deactivate legacy Similar Posts Feed if present
690
  $current = get_option('active_plugins');
691
  if (in_array('Similar_Posts_Feed/similar-posts-feed.php', $current)) {
692
- array_splice($current, array_search('Similar_Posts_Feed/similar-posts-feed.php', $current), 1);
693
- update_option('active_plugins', $current);
694
  }
695
  unset($current);
696
-
697
  // clear legacy custom fields
698
  $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_key = 'similarterms'");
699
-
700
  // clear legacy index
701
  $indices = $wpdb->get_results("SHOW INDEX FROM $wpdb->posts", ARRAY_A);
702
  foreach ($indices as $index) {
703
  if ($index['Key_name'] === 'post_similar') {
704
  $wpdb->query("ALTER TABLE $wpdb->posts DROP INDEX post_similar");
705
  break;
706
- }
707
  }
708
-
709
  $wpdb->show_errors($suppress);
710
  error_reporting($errorlevel);
711
  }
@@ -713,7 +713,7 @@ function similar_posts_install() {
713
 
714
 
715
  if (!function_exists('ppl_plugin_basename')) {
716
- if ( !defined('WP_PLUGIN_DIR') ) define( 'WP_PLUGIN_DIR', ABSPATH . 'wp-content/plugins' );
717
  function ppl_plugin_basename($file) {
718
  $file = str_replace('\\','/',$file); // sanitize for Win32 installs
719
  $file = preg_replace('|/+|','/', $file); // remove any duplicate slash
3
  * Similar Posts
4
  * (c) Web factory Ltd, 2008 - 2017
5
  */
6
+
7
+
8
  // Admin stuff for Similar Posts Plugin, Version 2.6.2.0
9
 
10
  function similar_posts_option_menu() {
36
 
37
  function similar_posts_options_page(){
38
  echo '<div class="wrap"><h2>';
39
+ _e('Similar Posts ', 'similar_posts');
40
  echo '</h2></div>';
41
+
42
+
43
  $m = new admin_subpages();
44
  $m->add_subpage('General', 'general', 'similar_posts_general_options_subpage');
45
  $m->add_subpage('Output', 'output', 'similar_posts_output_options_subpage');
48
  $m->add_subpage('Misc', 'other', 'similar_posts_other_options_subpage');
49
  $m->add_subpage('Manage the Index', 'index', 'similar_posts_index_options_subpage');
50
  $m->display();
51
+
52
  //echo '<div class="wrap"><a target="_blank" href="http://rmarsh.com/plugins/post-options/">';
53
+ //_e('Detailed help &amp; instructions');
54
  //echo '</a></div>';
55
+
56
  add_action('in_admin_footer', 'similar_posts_admin_footer');
57
  }
58
 
59
  function similar_posts_admin_footer() {
60
  ppl_admin_footer(str_replace('-admin', '', __FILE__), "similar-posts");
61
+
62
  }
63
 
64
  function similar_posts_general_options_subpage(){
65
  global $wpdb, $wp_version;
66
  $options = get_option('similar-posts');
67
  if (isset($_POST['update_options'])) {
68
+ check_admin_referer('similar-posts-update-options');
69
  if (defined('POC_CACHE_4')) poc_cache_flush();
70
  // Fill up the options with the values chosen...
71
  $options = ppl_options_from_post($options, array('limit', 'skip', 'show_private', 'show_pages', 'show_attachments', 'status', 'age', 'omit_current_post', 'match_cat', 'match_tags', 'match_author'));
72
  update_option('similar-posts', $options);
73
  // Show a message to say we've done something
74
  echo '<div class="updated settings-error notice"><p>' . __('<b>Settings saved.</b>', 'similar_posts') . '</p></div>';
75
+ }
76
  //now we drop into html to display the option page form
77
  ?>
78
  <div class="wrap similarposts-tab-content">
79
+
80
  <form method="post" action="">
81
+
82
  <table class="optiontable form-table">
83
+ <?php
84
+ ppl_display_limit($options['limit']);
85
+ ppl_display_skip($options['skip']);
86
+ ppl_display_show_private($options['show_private']);
87
+ ppl_display_show_pages($options['show_pages']);
88
+ ppl_display_show_attachments($options['show_attachments']);
89
  ppl_display_status($options['status']);
90
  ppl_display_age($options['age']);
91
+ ppl_display_omit_current_post($options['omit_current_post']);
92
+ ppl_display_match_cat($options['match_cat']);
93
+ ppl_display_match_tags($options['match_tags']);
94
+ ppl_display_match_author($options['match_author']);
95
  ?>
96
  </table>
97
  <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Settings', 'similar_posts') ?>" /></div>
98
  <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-update-options'); ?>
99
+ </form>
100
  </div>
101
+ <?php
102
  }
103
 
104
  function similar_posts_output_options_subpage(){
105
  global $wpdb, $wp_version;
106
  $options = get_option('similar-posts');
107
  if (isset($_POST['update_options'])) {
108
+ check_admin_referer('similar-posts-update-options');
109
  if (defined('POC_CACHE_4')) poc_cache_flush();
110
  // Fill up the options with the values chosen...
111
  $options = ppl_options_from_post($options, array('output_template', 'prefix', 'suffix', 'none_text', 'no_text', 'divider', 'sort', 'group_template'));
112
  update_option('similar-posts', $options);
113
  // Show a message to say we've done something
114
  echo '<div class="updated settings-error notice"><p>' . __('<b>Settings saved.</b>', 'similar_posts') . '</p></div>';
115
+ }
116
  //now we drop into html to display the option page form
117
  ?>
118
  <div class="wrap similarposts-tab-content">
119
+
120
  <form method="post" action="">
121
+
122
  <table class="optiontable form-table">
123
  <tr>
124
  <td style="padding-top: 0; vertical-align: top;">
125
  <table>
126
+ <?php
127
+ ppl_display_output_template($options['output_template']);
128
+ ppl_display_prefix($options['prefix']);
129
+ ppl_display_suffix($options['suffix']);
130
+ ppl_display_none_text($options['none_text']);
131
+ ppl_display_no_text($options['no_text']);
132
+ ppl_display_divider($options['divider']);
133
  ppl_display_sort($options['sort']);
134
+ ppl_display_group_template($options['group_template']);
135
  ?>
136
  </table>
137
  </td>
141
  </table>
142
  <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Settings', 'similar_posts') ?>" /></div>
143
  <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-update-options'); ?>
144
+ </form>
145
  </div>
146
+ <?php
147
  }
148
 
149
  function similar_posts_filter_options_subpage(){
150
  global $wpdb, $wp_version;
151
  $options = get_option('similar-posts');
152
  if (isset($_POST['update_options'])) {
153
+ check_admin_referer('similar-posts-update-options');
154
  if (defined('POC_CACHE_4')) poc_cache_flush();
155
  // Fill up the options with the values chosen...
156
  $options = ppl_options_from_post($options, array('excluded_posts', 'included_posts', 'excluded_authors', 'included_authors', 'excluded_cats', 'included_cats', 'tag_str', 'custom'));
157
  update_option('similar-posts', $options);
158
  // Show a message to say we've done something
159
  echo '<div class="updated settings-error notice"><p>' . __('<b>Settings saved.</b>', 'similar_posts') . '</p></div>';
160
+ }
161
  //now we drop into html to display the option page form
162
  ?>
163
  <div class="wrap similarposts-tab-content">
164
+
165
  <form method="post" action="">
166
+
167
  <table class="optiontable form-table">
168
+ <?php
169
+ ppl_display_excluded_posts($options['excluded_posts']);
170
+ ppl_display_included_posts($options['included_posts']);
171
+ ppl_display_authors($options['excluded_authors'], $options['included_authors']);
172
+ ppl_display_cats($options['excluded_cats'], $options['included_cats']);
173
+ ppl_display_tag_str($options['tag_str']);
174
+ ppl_display_custom($options['custom']);
175
  ?>
176
  </table>
177
  <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Settings', 'similar_posts') ?>" /></div>
178
  <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-update-options'); ?>
179
+ </form>
180
  </div>
181
+ <?php
182
  }
183
 
184
  function similar_posts_placement_options_subpage(){
185
  global $wpdb, $wp_version;
186
  $options = get_option('similar-posts');
187
  if (isset($_POST['update_options'])) {
188
+ check_admin_referer('similar-posts-update-options');
189
  if (defined('POC_CACHE_4')) poc_cache_flush();
190
  // Fill up the options with the values chosen...
191
  $options = ppl_options_from_post($options, array('content_filter', 'widget_parameters', 'widget_condition', 'feed_on', 'feed_priority', 'feed_parameters', 'append_on', 'append_priority', 'append_parameters', 'append_condition'));
192
  update_option('similar-posts', $options);
193
  // Show a message to say we've done something
194
  echo '<div class="updated settings-error notice"><p>' . __('<b>Settings saved.</b>', 'similar_posts') . '</p></div>';
195
+ }
196
  //now we drop into html to display the option page form
197
  ?>
198
  <div class="wrap similarposts-tab-content">
199
+
200
  <form method="post" action="">
201
+
202
  <table class="optiontable form-table">
203
+ <?php
204
+ ppl_display_append($options);
205
+ ppl_display_feed($options);
206
+ ppl_display_widget($options);
207
  ppl_display_content_filter($options['content_filter']);
208
  ?>
209
  </table>
210
  <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Settings', 'similar_posts') ?>" /></div>
211
  <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-update-options'); ?>
212
+ </form>
213
  </div>
214
+ <?php
215
  }
216
 
217
  function similar_posts_other_options_subpage(){
218
  global $wpdb, $wp_version;
219
  $options = get_option('similar-posts');
220
  if (isset($_POST['update_options'])) {
221
+ check_admin_referer('similar-posts-update-options');
222
  if (defined('POC_CACHE_4')) poc_cache_flush();
223
  // Fill up the options with the values chosen...
224
  $options = ppl_options_from_post($options, array('stripcodes', 'feed_active', 'term_extraction', 'num_terms', 'weight_title', 'weight_content', 'weight_tags', 'hand_links'));
225
+ $wcontent = $options['weight_content'] + 0.0001;
226
  $wtitle = $options['weight_title'] + 0.0001;
227
  $wtags = $options['weight_tags'] + 0.0001;
228
  $wcombined = $wcontent + $wtitle + $wtags;
229
+ $options['weight_content'] = $wcontent / $wcombined;
230
+ $options['weight_title'] = $wtitle / $wcombined;
231
+ $options['weight_tags'] = $wtags / $wcombined;
232
  update_option('similar-posts', $options);
233
  // Show a message to say we've done something
234
  echo '<div class="updated settings-error notice"><p>' . __('<b>Settings saved.</b>', 'similar_posts') . '</p></div>';
235
+ }
236
  //now we drop into html to display the option page form
237
  ?>
238
  <div class="wrap similarposts-tab-content">
239
+
240
  <form method="post" action="">
241
+
242
  <table class="optiontable form-table">
243
+ <?php
244
+ ppl_display_weights($options);
245
+ ppl_display_num_terms($options['num_terms']);
246
+ ppl_display_term_extraction($options['term_extraction']);
247
  ppl_display_hand_links($options['hand_links']);
248
  ppl_display_feed_active($options['feed_active']);
249
+ ppl_display_stripcodes($options['stripcodes']);
250
  ?>
251
  </table>
252
  <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Settings', 'similar_posts') ?>" /></div>
253
  <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-update-options'); ?>
254
+ </form>
255
  </div>
256
+ <?php
257
  }
258
 
259
  function similar_posts_index_options_subpage(){
260
  if (isset($_POST['reindex_all'])) {
261
+ check_admin_referer('similar-posts-manage-update-options');
262
  if (defined('POC_CACHE_4')) poc_cache_flush();
263
  $options = get_option('similar-posts');
264
  $options['utf8'] = $_POST['utf8'];
282
  $options = get_option('similar-posts');
283
  }
284
  ?>
285
+ <div class="wrap similarposts-tab-content">
286
+ <?php
287
  echo '<p>'.__('Similar Posts maintains a special index to help search for related posts. The index is created when the plugin is activated and then kept up-to-date automatically when posts are added, edited, or deleted.', 'similar_posts').'</p>';
288
  echo '<p>'.__('The options that affect the index can be set below.', 'similar_posts').'</p>';
289
  echo '<p>'.__('If you are using a language other than english you may find that the plugin mangles some characters since PHP is normally blind to multibyte characters. You can force the plugin to interpret extended characters as UTF-8 at the expense of a little speed but this facility is only available if your installation of PHP supports the mbstring functions.', 'similar_posts').'</p>';
290
  echo '<p>'.__('Languages like Chinese, Korean and Japanese pose a special difficulty for the full-text search algorithm. As an experiment I have introduced an option below to work around some of these issues. The text must be encoded as UTF-8. I would be very grateful for feedback from any users knowledgeable in these languages.', 'similar_posts').'</p>';
291
+ echo '<p>'.__('Some related word forms should really be counted together, e.g., "follow", "follows", and "following". By default, Similar Posts treats such differences strictly but has two other algorithms which are more relaxed: <em>stemming</em> and <em>fuzzy matching</em>. The stemming algorithm tries to reduce related forms to their root stem. Stemming algorithms are provided for english, german, spanish, french and italian but stemmers for other languages can be created: see the help for instructions. Fuzzy matching uses the "metaphone" algorithm to handle word variations. Note: both stemming and fuzzy matching slow down the indexing more than a little. It is worth experimenting with the three possibilities to see what improves the similarity of posts in your particular circumstances.', 'similar_posts').'</p>';
292
+ echo '<p>'.__('The indexing routine processes posts in batches of 100 by default. If you run into problems with limited memory you can opt to make the batches smaller.', 'similar_posts').'</p>';
293
+ echo '<p>'.__('Note: the process of indexing may take a little while. On my modest machine 500 posts take between 5 seconds and 20 seconds (with stemming and utf-8 support). Don\'t worry if the screen fails to update until finished.', 'similar_posts').'</p>';
294
  ?>
295
+ <form method="post" action="">
296
  <table class="optiontable form-table">
297
  <tr valign="top">
298
  <th scope="row"><label for="utf8"><?php _e('Handle extended characters?', 'similar_posts') ?></label></th>
301
  <option <?php if($options['utf8'] == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
302
  <option <?php if($options['utf8'] == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
303
  </select>
304
+ </td>
305
  </tr>
306
  <tr valign="top">
307
  <th scope="row"><label for="cjk"><?php _e('Treat as Chinese, Korean, or Japanese?', 'similar_posts') ?></label></th>
310
  <option <?php if($options['cjk'] == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
311
  <option <?php if($options['cjk'] == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
312
  </select>
313
+ </td>
314
  </tr>
315
  <tr valign="top">
316
  <th scope="row"><label for="use_stemmer"><?php _e('Treat Related Word Variations:', 'similar_posts') ?></label></th>
320
  <option <?php if($options['use_stemmer'] == 'true') { echo 'selected="selected"'; } ?> value="true">By Stem</option>
321
  <option <?php if($options['use_stemmer'] == 'fuzzy') { echo 'selected="selected"'; } ?> value="fuzzy">Fuzzily</option>
322
  </select>
323
+ </td>
324
  </tr>
325
  <tr valign="top">
326
  <th scope="row"><label for="batch"><?php _e('Batch size:', 'similar_posts') ?></label></th>
330
  <div class="submit">
331
  <input type="submit" class="button button-primary" name="reindex_all" value="<?php _e('Recreate Index', 'similar_posts') ?>" />
332
  <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-manage-update-options'); ?>
333
+ </div>
334
+ </form>
335
  </div>
336
  <?php
337
  }
340
 
341
  function similar_posts_for_feed_options_page(){
342
  echo '<div class="wrap"><h2>';
343
+ _e('Similar Posts Feed ', 'similar_posts');
344
  echo '<a href="http://rmarsh.com/plugins/post-options/" style="font-size: 0.8em;">';
345
+ _e('help and instructions');
346
  echo '</a></h2></div>';
347
  $m = new admin_subpages();
348
  $m->add_subpage('General', 'general', 'similar_posts_feed_general_options_subpage');
356
  global $wpdb, $wp_version;
357
  $options = get_option('similar-posts-feed');
358
  if (isset($_POST['update_options'])) {
359
+ check_admin_referer('similar-posts-feed-update-options');
360
  if (defined('POC_CACHE_4')) poc_cache_flush();
361
  // Fill up the options with the values chosen...
362
  $options = ppl_options_from_post($options, array('limit', 'skip', 'show_private', 'show_pages', 'show_attachments', 'status', 'age', 'omit_current_post', 'match_cat', 'match_tags', 'match_author'));
363
  update_option('similar-posts-feed', $options);
364
  // Show a message to say we've done something
365
  echo '<div class="updated fade similarposts-settings-saved"><p>' . __('Settings saved', 'similar_posts') . '</p></div>';
366
+ }
367
  //now we drop into html to display the option page form
368
  ?>
369
  <div class="wrap similarposts-tab-content">
371
  <form method="post" action="">
372
  <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save General Settings', 'similar_posts') ?>" /></div>
373
  <table class="optiontable form-table">
374
+ <?php
375
+ ppl_display_limit($options['limit']);
376
+ ppl_display_skip($options['skip']);
377
+ ppl_display_show_private($options['show_private']);
378
+ ppl_display_show_pages($options['show_pages']);
379
+ ppl_display_show_attachments($options['show_attachments']);
380
  ppl_display_status($options['status']);
381
  ppl_display_age($options['age']);
382
+ ppl_display_omit_current_post($options['omit_current_post']);
383
+ ppl_display_match_cat($options['match_cat']);
384
+ ppl_display_match_tags($options['match_tags']);
385
+ ppl_display_match_author($options['match_author']);
386
  ?>
387
  </table>
388
  <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save General Settings', 'similar_posts') ?>" /></div>
389
  <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-feed-update-options'); ?>
390
+ </form>
391
  </div>
392
+ <?php
393
  }
394
 
395
  function similar_posts_feed_output_options_subpage(){
396
  global $wpdb, $wp_version;
397
  $options = get_option('similar-posts-feed');
398
  if (isset($_POST['update_options'])) {
399
+ check_admin_referer('similar-posts-feed-update-options');
400
  if (defined('POC_CACHE_4')) poc_cache_flush();
401
  // Fill up the options with the values chosen...
402
  $options = ppl_options_from_post($options, array('output_template', 'prefix', 'suffix', 'none_text', 'no_text', 'divider', 'sort', 'group_template'));
403
  update_option('similar-posts-feed', $options);
404
  // Show a message to say we've done something
405
  echo '<div class="updated fade similarposts-settings-saved"><p>' . __('Settings saved', 'similar_posts') . '</p></div>';
406
+ }
407
  //now we drop into html to display the option page form
408
  ?>
409
  <div class="wrap similarposts-tab-content">
414
  <tr>
415
  <td>
416
  <table>
417
+ <?php
418
+ ppl_display_output_template($options['output_template']);
419
+ ppl_display_prefix($options['prefix']);
420
+ ppl_display_suffix($options['suffix']);
421
+ ppl_display_none_text($options['none_text']);
422
+ ppl_display_no_text($options['no_text']);
423
+ ppl_display_divider($options['divider']);
424
  ppl_display_sort($options['sort']);
425
+ ppl_display_group_template($options['group_template']);
426
  ?>
427
  </table>
428
  </td>
432
  </table>
433
  <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Output Settings', 'similar_posts') ?>" /></div>
434
  <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-feed-update-options'); ?>
435
+ </form>
436
  </div>
437
+ <?php
438
  }
439
 
440
  function similar_posts_feed_filter_options_subpage(){
441
  global $wpdb, $wp_version;
442
  $options = get_option('similar-posts-feed');
443
  if (isset($_POST['update_options'])) {
444
+ check_admin_referer('similar-posts-feed-update-options');
445
  if (defined('POC_CACHE_4')) poc_cache_flush();
446
  // Fill up the options with the values chosen...
447
  $options = ppl_options_from_post($options, array('excluded_posts', 'included_posts', 'excluded_authors', 'included_authors', 'excluded_cats', 'included_cats', 'tag_str', 'custom'));
448
  update_option('similar-posts-feed', $options);
449
  // Show a message to say we've done something
450
  echo '<div class="updated fade similarposts-settings-saved"><p>' . __('Settings saved', 'similar_posts') . '</p></div>';
451
+ }
452
  //now we drop into html to display the option page form
453
  ?>
454
  <div class="wrap similarposts-tab-content">
456
  <form method="post" action="">
457
  <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Filter Settings', 'similar_posts') ?>" /></div>
458
  <table class="optiontable form-table">
459
+ <?php
460
+ ppl_display_excluded_posts($options['excluded_posts']);
461
+ ppl_display_included_posts($options['included_posts']);
462
+ ppl_display_authors($options['excluded_authors'], $options['included_authors']);
463
+ ppl_display_cats($options['excluded_cats'], $options['included_cats']);
464
+ ppl_display_tag_str($options['tag_str']);
465
+ ppl_display_custom($options['custom']);
466
  ?>
467
  </table>
468
  <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Filter Settings', 'similar_posts') ?>" /></div>
469
  <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-feed-update-options'); ?>
470
+ </form>
471
  </div>
472
+ <?php
473
  }
474
 
475
  function similar_posts_feed_other_options_subpage(){
476
  global $wpdb, $wp_version;
477
  $options = get_option('similar-posts-feed');
478
  if (isset($_POST['update_options'])) {
479
+ check_admin_referer('similar-posts-feed-update-options');
480
  if (defined('POC_CACHE_4')) poc_cache_flush();
481
  // Fill up the options with the values chosen...
482
  $options = ppl_options_from_post($options, array('stripcodes', 'term_extraction', 'num_terms', 'weight_title', 'weight_content', 'weight_tags', 'hand_links'));
483
+ $wcontent = $options['weight_content'] + 0.0001;
484
  $wtitle = $options['weight_title'] + 0.0001;
485
  $wtags = $options['weight_tags'] + 0.0001;
486
  $wcombined = $wcontent + $wtitle + $wtags;
487
+ $options['weight_content'] = $wcontent / $wcombined;
488
+ $options['weight_title'] = $wtitle / $wcombined;
489
+ $options['weight_tags'] = $wtags / $wcombined;
490
  update_option('similar-posts-feed', $options);
491
  // Show a message to say we've done something
492
  echo '<div class="updated fade similarposts-settings-saved"><p>' . __('Settings saved', 'similar_posts') . '</p></div>';
493
+ }
494
  //now we drop into html to display the option page form
495
  ?>
496
  <div class="wrap similarposts-tab-content">
498
  <form method="post" action="">
499
  <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Other Settings', 'similar_posts') ?>" /></div>
500
  <table class="optiontable form-table">
501
+ <?php
502
+ ppl_display_weights($options);
503
+ ppl_display_num_terms($options['num_terms']);
504
+ ppl_display_term_extraction($options['term_extraction']);
505
  ppl_display_hand_links($options['hand_links']);
506
+ ppl_display_stripcodes($options['stripcodes']);
507
  ?>
508
  </table>
509
  <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Other Settings', 'similar_posts') ?>" /></div>
510
  <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-feed-update-options'); ?>
511
+ </form>
512
  </div>
513
+ <?php
514
  }
515
 
516
 
545
  // this function gets called when the plugin is installed to set up the index and default options
546
  function similar_posts_install() {
547
  global $wpdb, $table_prefix;
548
+
549
  $table_name = $table_prefix . 'similar_posts';
550
  $errorlevel = error_reporting(0);
551
  $suppress = $wpdb->hide_errors();
612
  if (!isset($options['group_template'])) $options['group_template'] = '';
613
  if (!isset($options['weight_content'])) $options['weight_content'] = 0.9;
614
  if (!isset($options['weight_title'])) $options['weight_title'] = 0.1;
615
+ if (!isset($options['weight_tags'])) $options['weight_tags'] = 0.0;
616
  if (!isset($options['num_terms'])) $options['num_terms'] = 20;
617
  if (!isset($options['term_extraction'])) $options['term_extraction'] = 'frequency';
618
  if (!isset($options['hand_links'])) $options['hand_links'] = 'false';
619
  update_option('similar-posts-feed', $options);
620
+
621
  $options = (array) get_option('similar-posts');
622
  // check each of the option values and, if empty, assign a default (doing it this long way
623
  // lets us add new options in later versions)
669
  if (!isset($options['group_template'])) $options['group_template'] = '';
670
  if (!isset($options['weight_content'])) $options['weight_content'] = 0.9;
671
  if (!isset($options['weight_title'])) $options['weight_title'] = 0.1;
672
+ if (!isset($options['weight_tags'])) $options['weight_tags'] = 0.0;
673
  if (!isset($options['num_terms'])) $options['num_terms'] = 20;
674
  if (!isset($options['term_extraction'])) $options['term_extraction'] = 'frequency';
675
  if (!isset($options['hand_links'])) $options['hand_links'] = 'false';
679
  if (!function_exists('mb_internal_encoding')) $options['cjk'] = 'false';
680
  if (!isset($options['use_stemmer'])) $options['use_stemmer'] = 'false';
681
  if (!isset($options['batch'])) $options['batch'] = '100';
682
+
683
  update_option('similar-posts', $options);
684
 
685
  // initial creation of the index, if the table is empty
686
  $num_index_posts = $wpdb->get_var("SELECT COUNT(*) FROM `$table_name`");
687
+ if ($num_index_posts == 0) save_index_entries (($options['utf8'] === 'true'), 'false', $options['batch'], ($options['cjk'] === 'true'));
688
 
689
  // deactivate legacy Similar Posts Feed if present
690
  $current = get_option('active_plugins');
691
  if (in_array('Similar_Posts_Feed/similar-posts-feed.php', $current)) {
692
+ array_splice($current, array_search('Similar_Posts_Feed/similar-posts-feed.php', $current), 1);
693
+ update_option('active_plugins', $current);
694
  }
695
  unset($current);
696
+
697
  // clear legacy custom fields
698
  $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_key = 'similarterms'");
699
+
700
  // clear legacy index
701
  $indices = $wpdb->get_results("SHOW INDEX FROM $wpdb->posts", ARRAY_A);
702
  foreach ($indices as $index) {
703
  if ($index['Key_name'] === 'post_similar') {
704
  $wpdb->query("ALTER TABLE $wpdb->posts DROP INDEX post_similar");
705
  break;
706
+ }
707
  }
708
+
709
  $wpdb->show_errors($suppress);
710
  error_reporting($errorlevel);
711
  }
713
 
714
 
715
  if (!function_exists('ppl_plugin_basename')) {
716
+ if ( !defined('WP_PLUGIN_DIR') ) define( 'WP_PLUGIN_DIR', ABSPATH . 'wp-content/plugins' );
717
  function ppl_plugin_basename($file) {
718
  $file = str_replace('\\','/',$file); // sanitize for Win32 installs
719
  $file = preg_replace('|/+|','/', $file); // remove any duplicate slash
similar-posts.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Similar Posts
4
  Plugin URI: https://wordpress.org/plugins/similar-posts/
5
  Description: Displays a highly configurable list of related posts. Similarity can be based on any combination of word usage in the content, title, or tags.
6
- Version: 2.71
7
  Author: Web Factory Ltd
8
  Author URI: http://www.webfactoryltd.com/
9
  Text Domain: similar-posts
@@ -49,7 +49,7 @@ if ( ! defined( 'WP_PLUGIN_URL' ) )
49
  define( 'WP_PLUGIN_URL', WP_CONTENT_URL. '/plugins' );
50
  if ( ! defined( 'WP_PLUGIN_DIR' ) )
51
  define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
52
-
53
  if (!defined('CF_LIBRARY')) require(WP_PLUGIN_DIR.'/similar-posts/common_functions.php');
54
  if (!defined('ACF_LIBRARY')) require(WP_PLUGIN_DIR.'/similar-posts/admin_common_functions.php');
55
  if (!defined('OT_LIBRARY')) require(WP_PLUGIN_DIR.'/similar-posts/output_tags.php');
@@ -62,14 +62,14 @@ $similar_posts_current_ID = -1;
62
 
63
  class SimilarPosts {
64
  static $version = 0;
65
-
66
  static function get_plugin_version() {
67
  $plugin_data = get_file_data(__FILE__, array('version' => 'Version'), 'plugin');
68
  SimilarPosts::$version = $plugin_data['version'];
69
-
70
  return $plugin_data['version'];
71
  } // get_plugin_version
72
-
73
  // check if plugin's admin page is shown
74
  static function is_plugin_admin_page($page = 'settings') {
75
  $current_screen = get_current_screen();
@@ -80,7 +80,7 @@ class SimilarPosts {
80
 
81
  return false;
82
  } // is_plugin_admin_page
83
-
84
  // add settings link to plugins page
85
  static function plugin_action_links($links) {
86
  $settings_link = '<a href="' . admin_url('options-general.php?page=similar-posts') . '" title="Settings for Similar Posts">Settings</a>';
@@ -90,11 +90,11 @@ class SimilarPosts {
90
  return $links;
91
  } // plugin_action_links
92
 
93
-
94
  static function execute($args='', $default_output_template='<li>{link}</li>', $option_key='similar-posts'){
95
  global $table_prefix, $wpdb, $wp_version, $similar_posts_current_ID;
96
  $start_time = ppl_microtime();
97
- $postid = ppl_current_post_id($similar_posts_current_ID);
98
  if (defined('POC_CACHE_4')) {
99
  $cache_key = $option_key.$postid.$args;
100
  $result = poc_cache_fetch($cache_key);
@@ -127,16 +127,16 @@ class SimilarPosts {
127
  list( $contentterms, $titleterms, $tagterms) = sp_terms_by_textrank($postid, $options['num_terms']);
128
  } else {
129
  list( $contentterms, $titleterms, $tagterms) = sp_terms_by_freq($postid, $options['num_terms']);
130
- }
131
  // these should add up to 1.0
132
  $weight_content = $options['weight_content'];
133
  $weight_title = $options['weight_title'];
134
  $weight_tags = $options['weight_tags'];
135
  // below a threshold we ignore the weight completely and save some effort
136
  if ($weight_content < 0.001) $weight_content = (int) 0;
137
- if ($weight_title < 0.001) $weight_title = (int) 0;
138
- if ($weight_tags < 0.001) $weight_tags = (int) 0;
139
-
140
  $count_content = substr_count($contentterms, ' ') + 1;
141
  $count_title = substr_count($titleterms, ' ') + 1;
142
  $count_tags = substr_count($tagterms, ' ') + 1;
@@ -152,13 +152,13 @@ class SimilarPosts {
152
  // the workhorse...
153
  $sql = "SELECT *, ";
154
  $sql .= score_fulltext_match($table_name, $weight_title, $titleterms, $weight_content, $contentterms, $weight_tags, $tagterms, $forced_ids);
155
-
156
  if ($check_custom) $sql .= "LEFT JOIN $wpdb->postmeta ON post_id = ID ";
157
-
158
  // build the 'WHERE' clause
159
  $where = array();
160
  $where[] = where_fulltext_match($weight_title, $titleterms, $weight_content, $contentterms, $weight_tags, $tagterms);
161
- if (!function_exists('get_post_type')) {
162
  $where[] = where_hide_future();
163
  } else {
164
  $where[] = where_show_status($options['status'], $options['show_attachments']);
@@ -166,7 +166,7 @@ class SimilarPosts {
166
  if ($match_category) $where[] = where_match_category();
167
  if ($match_tags) $where[] = where_match_tags($options['match_tags']);
168
  if ($match_author) $where[] = where_match_author();
169
- $where[] = where_show_pages($options['show_pages'], $options['show_attachments']);
170
  if ($include_cats) $where[] = where_included_cats($options['included_cats']);
171
  if ($exclude_cats) $where[] = where_excluded_cats($options['excluded_cats']);
172
  if ($exclude_authors) $where[] = where_excluded_authors($options['excluded_authors']);
@@ -179,7 +179,7 @@ class SimilarPosts {
179
  if ($check_age) $where[] = where_check_age($options['age']['direction'], $options['age']['length'], $options['age']['duration']);
180
  if ($check_custom) $where[] = where_check_custom($options['custom']['key'], $options['custom']['op'], $options['custom']['value']);
181
  $sql .= "WHERE ".implode(' AND ', $where);
182
- if ($check_custom) $sql .= " GROUP BY $wpdb->posts.ID";
183
  $sql .= " ORDER BY score DESC LIMIT $limit";
184
  //echo $sql;
185
  $results = $wpdb->get_results($sql);
@@ -191,7 +191,7 @@ class SimilarPosts {
191
  foreach ($results as $result) {
192
  $items[] = ppl_expand_template($result, $options['output_template'], $translations, $option_key);
193
  }
194
- if ($options['sort']['by1'] !== '') $items = ppl_sort_items($options['sort'], $results, $option_key, $options['group_template'], $items);
195
  $output = implode(($options['divider']) ? $options['divider'] : "\n", $items);
196
  $output = $options['prefix'] . $output . $options['suffix'];
197
  } else {
@@ -204,7 +204,7 @@ class SimilarPosts {
204
  $output = $options['prefix'] . ppl_expand_template(array(), $options['none_text'], $translations, $option_key) . $options['suffix'];
205
  }
206
  }
207
- if (defined('POC_CACHE_4')) poc_cache_store($cache_key, $output);
208
  return ($output) ? $output . sprintf("<!-- Similar Posts took %.3f ms -->", 1000 * (ppl_microtime() - $start_time)) : '';
209
  }
210
 
@@ -218,7 +218,7 @@ class SimilarPosts {
218
  update_option('similar_posts_meta', $options);
219
  }
220
  } // activate
221
-
222
  } // similarposts class
223
 
224
  function sp_terms_by_freq($ID, $num_terms = 20) {
@@ -241,13 +241,13 @@ function sp_terms_by_freq($ID, $num_terms = 20) {
241
  arsort($wordtable);
242
  if ($num_terms < 1) $num_terms = 1;
243
  $wordtable = array_slice($wordtable, 0, $num_terms);
244
-
245
  foreach ($wordtable as $word => $count) {
246
  $terms .= ' ' . $word;
247
  }
248
-
249
  $res[] = $terms;
250
- $res[] = $results[0]['title'];
251
  $res[] = $results[0]['tags'];
252
  }
253
  return $res;
@@ -272,14 +272,14 @@ function sp_terms_by_textrank($ID, $num_terms = 20) {
272
  $prev_word = $word;
273
  $word = strtok(' ');
274
  }
275
- // initialise the list of PageRanks-- one for each unique word
276
  reset($graph);
277
  while (list($vertex, $in_edges) = each($graph)) {
278
  $oldrank[$vertex] = 0.25;
279
  }
280
  $n = count($graph);
281
  if ($n > 0) {
282
- $base = 0.15 / $n;
283
  $error_margin = $n * 0.005;
284
  do {
285
  $error = 0.0;
@@ -292,7 +292,7 @@ function sp_terms_by_textrank($ID, $num_terms = 20) {
292
  $r += ($weight * $oldrank[$edge]) / $out_edges[$edge];
293
  }
294
  $rank[$vertex] = $base + 0.95 * $r;
295
- $error += abs($rank[$vertex] - $oldrank[$vertex]);
296
  }
297
  $oldrank = $rank;
298
  //echo $error . '<br>';
@@ -303,9 +303,9 @@ function sp_terms_by_textrank($ID, $num_terms = 20) {
303
  foreach ($rank as $vertex => $score) {
304
  $terms .= ' ' . $vertex;
305
  }
306
- }
307
  $res[] = $terms;
308
- $res[] = $results[0]['title'];
309
  $res[] = $results[0]['tags'];
310
  }
311
  return $res;
@@ -329,7 +329,7 @@ function sp_save_index_entry($postID) {
329
  if (is_null($pid)) {
330
  $wpdb->query("INSERT INTO $table_name (pID, content, title, tags) VALUES ($postID, \"$content\", \"$title\", \"$tags\")");
331
  } else {
332
- $wpdb->query("UPDATE $table_name SET content=\"$content\", title=\"$title\", tags=\"$tags\" WHERE pID=$postID" );
333
  }
334
  return $postID;
335
  }
@@ -382,10 +382,10 @@ function sp_cjk_digrams($string) {
382
  $result[] = $ascii;
383
  $ascii = '';
384
  $prev = $c;
385
- } else {
386
  $result[] = sp_mb_str_pad($prev.$c, 4, '_');
387
  $prev = $c;
388
- }
389
  } else {
390
  $ascii .= $c;
391
  }
@@ -412,14 +412,14 @@ function sp_get_post_terms($text, $utf8, $use_stemmer, $cjk) {
412
  $words .= sp_mb_str_pad(metaphone($word), 4, '_') . ' ';
413
  break;
414
  case 'false':
415
- default:
416
- $words .= $word . ' ';
417
- }
418
- }
419
- }
420
  } else {
421
  $wordlist = str_word_count(sp_clean_words($text), 1);
422
- $words = '';
423
  reset($wordlist);
424
  while (list($n, $word) = each($wordlist)) {
425
  if ( strlen($word) > 3 && !isset($overusedwords[$word])) {
@@ -431,13 +431,13 @@ function sp_get_post_terms($text, $utf8, $use_stemmer, $cjk) {
431
  $words .= str_pad(metaphone($word), 4, '_') . ' ';
432
  break;
433
  case 'false':
434
- default:
435
- $words .= $word . ' ';
436
- }
437
- }
438
- }
439
  }
440
- if ($cjk) $words = sp_cjk_digrams($words);
441
  return $words;
442
  }
443
 
@@ -460,11 +460,11 @@ function sp_get_title_terms($text, $utf8, $use_stemmer, $cjk) {
460
  $words .= sp_mb_str_pad(metaphone($word), 4, '_') . ' ';
461
  break;
462
  case 'false':
463
- default:
464
  $words .= sp_mb_str_pad($word, 4, '_') . ' ';
465
- }
466
- }
467
- }
468
  } else {
469
  $wordlist = str_word_count(sp_clean_words($text), 1);
470
  $words = '';
@@ -478,19 +478,19 @@ function sp_get_title_terms($text, $utf8, $use_stemmer, $cjk) {
478
  $words .= str_pad(metaphone($word), 4, '_') . ' ';
479
  break;
480
  case 'false':
481
- default:
482
  $words .= str_pad($word, 4, '_') . ' ';
483
- }
484
  }
485
  }
486
  }
487
- if ($cjk) $words = sp_cjk_digrams($words);
488
  return $words;
489
  }
490
 
491
  function sp_get_tag_terms($ID, $utf8) {
492
  global $wpdb;
493
- if (!function_exists('get_object_term_cache')) return '';
494
  $tags = array();
495
  $query = "SELECT t.name FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = 'post_tag' AND tr.object_id = '$ID'";
496
  $tags = $wpdb->get_col($query);
@@ -499,18 +499,18 @@ function sp_get_tag_terms($ID, $utf8) {
499
  mb_internal_encoding('UTF-8');
500
  foreach ($tags as $tag) {
501
  $newtags[] = sp_mb_str_pad(mb_strtolower(str_replace('"', "'", $tag)), 4, '_');
502
- }
503
  } else {
504
  foreach ($tags as $tag) {
505
  $newtags[] = str_pad(strtolower(str_replace('"', "'", $tag)), 4, '_');
506
- }
507
- }
508
- $newtags = str_replace(' ', '_', $newtags);
509
  $tags = implode (' ', $newtags);
510
  } else {
511
  $tags = '';
512
- }
513
- return $tags;
514
  }
515
 
516
  if ( is_admin() ) {
@@ -537,7 +537,7 @@ function widget_rrm_similar_posts_init() {
537
  }
538
  }
539
  $condition = (stristr($condition, "return")) ? $condition : "return ".$condition;
540
- $condition = rtrim($condition, '; ') . ' || is_admin();';
541
  if (eval($condition)) {
542
  $title = empty($options['title']) ? __('Similar Posts', 'similar_posts') : $options['title'];
543
  if ( !$number = (int) $options['number'] )
@@ -546,7 +546,7 @@ function widget_rrm_similar_posts_init() {
546
  $number = 1;
547
  else if ( $number > 15 )
548
  $number = 15;
549
- $options = get_option('recent-posts');
550
  $widget_parameters = $options['widget_parameters'];
551
  $output = SimilarPosts::execute('limit='.$number.'&'.$widget_parameters);
552
  if ($output) {
@@ -565,7 +565,7 @@ function widget_rrm_similar_posts_init() {
565
  update_option("widget_rrm_similar_posts", $options);
566
  } else {
567
  $options = get_option('widget_rrm_similar_posts');
568
- }
569
  $title = esc_attr($options['title']);
570
  if ( !$number = (int) $options['number'] )
571
  $number = 5;
@@ -593,7 +593,7 @@ add_action('plugins_loaded', 'widget_rrm_similar_posts_init');
593
  if(defined('WPLANG')){
594
  $language = substr(WPLANG, 0, 2);
595
  } else {
596
- $language = '';
597
  }
598
  //if no language is specified make it the default which is 'en'
599
  if ($language == '') {
@@ -632,9 +632,9 @@ function similar_posts_wp_admin_style() {
632
  function similar_posts_init () {
633
  global $overusedwords, $wp_db_version;
634
  load_plugin_textdomain('similar_posts');
635
-
636
  SimilarPosts::get_plugin_version();
637
-
638
  $options = get_option('similar-posts');
639
  if ($options['feed_active'] === 'true') add_filter('the_content', 'similar_posts_for_feed');
640
  if ($options['content_filter'] === 'true' && function_exists('ppl_register_content_filter')) ppl_register_content_filter('SimilarPosts');
@@ -645,18 +645,18 @@ function similar_posts_init () {
645
  $condition = 'true';
646
  }
647
  $condition = (stristr($condition, "return")) ? $condition : "return ".$condition;
648
- $condition = rtrim($condition, '; ') . ';';
649
  if ($options['append_on'] === 'true' && function_exists('ppl_register_post_filter')) ppl_register_post_filter('append', 'similar-posts', 'SimilarPosts', $condition);
650
 
651
  //install the actions to keep the index up to date
652
  add_action('save_post', 'sp_save_index_entry', 1);
653
  add_action('delete_post', 'sp_delete_index_entry', 1);
654
- if ($wp_db_version < 3308 ) {
655
  add_action('edit_post', 'sp_save_index_entry', 1);
656
  add_action('publish_post', 'sp_save_index_entry', 1);
657
- }
658
  add_action( 'admin_enqueue_scripts', 'similar_posts_wp_admin_style' );
659
-
660
  // aditional links in plugin description
661
  add_filter('plugin_action_links_' . basename(dirname(__FILE__)) . '/' . basename(__FILE__),
662
  array('SimilarPosts', 'plugin_action_links'));
3
  Plugin Name: Similar Posts
4
  Plugin URI: https://wordpress.org/plugins/similar-posts/
5
  Description: Displays a highly configurable list of related posts. Similarity can be based on any combination of word usage in the content, title, or tags.
6
+ Version: 2.75
7
  Author: Web Factory Ltd
8
  Author URI: http://www.webfactoryltd.com/
9
  Text Domain: similar-posts
49
  define( 'WP_PLUGIN_URL', WP_CONTENT_URL. '/plugins' );
50
  if ( ! defined( 'WP_PLUGIN_DIR' ) )
51
  define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
52
+
53
  if (!defined('CF_LIBRARY')) require(WP_PLUGIN_DIR.'/similar-posts/common_functions.php');
54
  if (!defined('ACF_LIBRARY')) require(WP_PLUGIN_DIR.'/similar-posts/admin_common_functions.php');
55
  if (!defined('OT_LIBRARY')) require(WP_PLUGIN_DIR.'/similar-posts/output_tags.php');
62
 
63
  class SimilarPosts {
64
  static $version = 0;
65
+
66
  static function get_plugin_version() {
67
  $plugin_data = get_file_data(__FILE__, array('version' => 'Version'), 'plugin');
68
  SimilarPosts::$version = $plugin_data['version'];
69
+
70
  return $plugin_data['version'];
71
  } // get_plugin_version
72
+
73
  // check if plugin's admin page is shown
74
  static function is_plugin_admin_page($page = 'settings') {
75
  $current_screen = get_current_screen();
80
 
81
  return false;
82
  } // is_plugin_admin_page
83
+
84
  // add settings link to plugins page
85
  static function plugin_action_links($links) {
86
  $settings_link = '<a href="' . admin_url('options-general.php?page=similar-posts') . '" title="Settings for Similar Posts">Settings</a>';
90
  return $links;
91
  } // plugin_action_links
92
 
93
+
94
  static function execute($args='', $default_output_template='<li>{link}</li>', $option_key='similar-posts'){
95
  global $table_prefix, $wpdb, $wp_version, $similar_posts_current_ID;
96
  $start_time = ppl_microtime();
97
+ $postid = ppl_current_post_id($similar_posts_current_ID);
98
  if (defined('POC_CACHE_4')) {
99
  $cache_key = $option_key.$postid.$args;
100
  $result = poc_cache_fetch($cache_key);
127
  list( $contentterms, $titleterms, $tagterms) = sp_terms_by_textrank($postid, $options['num_terms']);
128
  } else {
129
  list( $contentterms, $titleterms, $tagterms) = sp_terms_by_freq($postid, $options['num_terms']);
130
+ }
131
  // these should add up to 1.0
132
  $weight_content = $options['weight_content'];
133
  $weight_title = $options['weight_title'];
134
  $weight_tags = $options['weight_tags'];
135
  // below a threshold we ignore the weight completely and save some effort
136
  if ($weight_content < 0.001) $weight_content = (int) 0;
137
+ if ($weight_title < 0.001) $weight_title = (int) 0;
138
+ if ($weight_tags < 0.001) $weight_tags = (int) 0;
139
+
140
  $count_content = substr_count($contentterms, ' ') + 1;
141
  $count_title = substr_count($titleterms, ' ') + 1;
142
  $count_tags = substr_count($tagterms, ' ') + 1;
152
  // the workhorse...
153
  $sql = "SELECT *, ";
154
  $sql .= score_fulltext_match($table_name, $weight_title, $titleterms, $weight_content, $contentterms, $weight_tags, $tagterms, $forced_ids);
155
+
156
  if ($check_custom) $sql .= "LEFT JOIN $wpdb->postmeta ON post_id = ID ";
157
+
158
  // build the 'WHERE' clause
159
  $where = array();
160
  $where[] = where_fulltext_match($weight_title, $titleterms, $weight_content, $contentterms, $weight_tags, $tagterms);
161
+ if (!function_exists('get_post_type')) {
162
  $where[] = where_hide_future();
163
  } else {
164
  $where[] = where_show_status($options['status'], $options['show_attachments']);
166
  if ($match_category) $where[] = where_match_category();
167
  if ($match_tags) $where[] = where_match_tags($options['match_tags']);
168
  if ($match_author) $where[] = where_match_author();
169
+ $where[] = where_show_pages($options['show_pages'], $options['show_attachments']);
170
  if ($include_cats) $where[] = where_included_cats($options['included_cats']);
171
  if ($exclude_cats) $where[] = where_excluded_cats($options['excluded_cats']);
172
  if ($exclude_authors) $where[] = where_excluded_authors($options['excluded_authors']);
179
  if ($check_age) $where[] = where_check_age($options['age']['direction'], $options['age']['length'], $options['age']['duration']);
180
  if ($check_custom) $where[] = where_check_custom($options['custom']['key'], $options['custom']['op'], $options['custom']['value']);
181
  $sql .= "WHERE ".implode(' AND ', $where);
182
+ if ($check_custom) $sql .= " GROUP BY $wpdb->posts.ID";
183
  $sql .= " ORDER BY score DESC LIMIT $limit";
184
  //echo $sql;
185
  $results = $wpdb->get_results($sql);
191
  foreach ($results as $result) {
192
  $items[] = ppl_expand_template($result, $options['output_template'], $translations, $option_key);
193
  }
194
+ if ($options['sort']['by1'] !== '') $items = ppl_sort_items($options['sort'], $results, $option_key, $options['group_template'], $items);
195
  $output = implode(($options['divider']) ? $options['divider'] : "\n", $items);
196
  $output = $options['prefix'] . $output . $options['suffix'];
197
  } else {
204
  $output = $options['prefix'] . ppl_expand_template(array(), $options['none_text'], $translations, $option_key) . $options['suffix'];
205
  }
206
  }
207
+ if (defined('POC_CACHE_4')) poc_cache_store($cache_key, $output);
208
  return ($output) ? $output . sprintf("<!-- Similar Posts took %.3f ms -->", 1000 * (ppl_microtime() - $start_time)) : '';
209
  }
210
 
218
  update_option('similar_posts_meta', $options);
219
  }
220
  } // activate
221
+
222
  } // similarposts class
223
 
224
  function sp_terms_by_freq($ID, $num_terms = 20) {
241
  arsort($wordtable);
242
  if ($num_terms < 1) $num_terms = 1;
243
  $wordtable = array_slice($wordtable, 0, $num_terms);
244
+
245
  foreach ($wordtable as $word => $count) {
246
  $terms .= ' ' . $word;
247
  }
248
+
249
  $res[] = $terms;
250
+ $res[] = $results[0]['title'];
251
  $res[] = $results[0]['tags'];
252
  }
253
  return $res;
272
  $prev_word = $word;
273
  $word = strtok(' ');
274
  }
275
+ // initialise the list of PageRanks-- one for each unique word
276
  reset($graph);
277
  while (list($vertex, $in_edges) = each($graph)) {
278
  $oldrank[$vertex] = 0.25;
279
  }
280
  $n = count($graph);
281
  if ($n > 0) {
282
+ $base = 0.15 / $n;
283
  $error_margin = $n * 0.005;
284
  do {
285
  $error = 0.0;
292
  $r += ($weight * $oldrank[$edge]) / $out_edges[$edge];
293
  }
294
  $rank[$vertex] = $base + 0.95 * $r;
295
+ $error += abs($rank[$vertex] - $oldrank[$vertex]);
296
  }
297
  $oldrank = $rank;
298
  //echo $error . '<br>';
303
  foreach ($rank as $vertex => $score) {
304
  $terms .= ' ' . $vertex;
305
  }
306
+ }
307
  $res[] = $terms;
308
+ $res[] = $results[0]['title'];
309
  $res[] = $results[0]['tags'];
310
  }
311
  return $res;
329
  if (is_null($pid)) {
330
  $wpdb->query("INSERT INTO $table_name (pID, content, title, tags) VALUES ($postID, \"$content\", \"$title\", \"$tags\")");
331
  } else {
332
+ $wpdb->query("UPDATE $table_name SET content=\"$content\", title=\"$title\", tags=\"$tags\" WHERE pID=$postID" );
333
  }
334
  return $postID;
335
  }
382
  $result[] = $ascii;
383
  $ascii = '';
384
  $prev = $c;
385
+ } else {
386
  $result[] = sp_mb_str_pad($prev.$c, 4, '_');
387
  $prev = $c;
388
+ }
389
  } else {
390
  $ascii .= $c;
391
  }
412
  $words .= sp_mb_str_pad(metaphone($word), 4, '_') . ' ';
413
  break;
414
  case 'false':
415
+ default:
416
+ $words .= $word . ' ';
417
+ }
418
+ }
419
+ }
420
  } else {
421
  $wordlist = str_word_count(sp_clean_words($text), 1);
422
+ $words = '';
423
  reset($wordlist);
424
  while (list($n, $word) = each($wordlist)) {
425
  if ( strlen($word) > 3 && !isset($overusedwords[$word])) {
431
  $words .= str_pad(metaphone($word), 4, '_') . ' ';
432
  break;
433
  case 'false':
434
+ default:
435
+ $words .= $word . ' ';
436
+ }
437
+ }
438
+ }
439
  }
440
+ if ($cjk) $words = sp_cjk_digrams($words);
441
  return $words;
442
  }
443
 
460
  $words .= sp_mb_str_pad(metaphone($word), 4, '_') . ' ';
461
  break;
462
  case 'false':
463
+ default:
464
  $words .= sp_mb_str_pad($word, 4, '_') . ' ';
465
+ }
466
+ }
467
+ }
468
  } else {
469
  $wordlist = str_word_count(sp_clean_words($text), 1);
470
  $words = '';
478
  $words .= str_pad(metaphone($word), 4, '_') . ' ';
479
  break;
480
  case 'false':
481
+ default:
482
  $words .= str_pad($word, 4, '_') . ' ';
483
+ }
484
  }
485
  }
486
  }
487
+ if ($cjk) $words = sp_cjk_digrams($words);
488
  return $words;
489
  }
490
 
491
  function sp_get_tag_terms($ID, $utf8) {
492
  global $wpdb;
493
+ if (!function_exists('get_object_term_cache')) return '';
494
  $tags = array();
495
  $query = "SELECT t.name FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = 'post_tag' AND tr.object_id = '$ID'";
496
  $tags = $wpdb->get_col($query);
499
  mb_internal_encoding('UTF-8');
500
  foreach ($tags as $tag) {
501
  $newtags[] = sp_mb_str_pad(mb_strtolower(str_replace('"', "'", $tag)), 4, '_');
502
+ }
503
  } else {
504
  foreach ($tags as $tag) {
505
  $newtags[] = str_pad(strtolower(str_replace('"', "'", $tag)), 4, '_');
506
+ }
507
+ }
508
+ $newtags = str_replace(' ', '_', $newtags);
509
  $tags = implode (' ', $newtags);
510
  } else {
511
  $tags = '';
512
+ }
513
+ return $tags;
514
  }
515
 
516
  if ( is_admin() ) {
537
  }
538
  }
539
  $condition = (stristr($condition, "return")) ? $condition : "return ".$condition;
540
+ $condition = rtrim($condition, '; ') . ' || is_admin();';
541
  if (eval($condition)) {
542
  $title = empty($options['title']) ? __('Similar Posts', 'similar_posts') : $options['title'];
543
  if ( !$number = (int) $options['number'] )
546
  $number = 1;
547
  else if ( $number > 15 )
548
  $number = 15;
549
+ $options = get_option('recent-posts');
550
  $widget_parameters = $options['widget_parameters'];
551
  $output = SimilarPosts::execute('limit='.$number.'&'.$widget_parameters);
552
  if ($output) {
565
  update_option("widget_rrm_similar_posts", $options);
566
  } else {
567
  $options = get_option('widget_rrm_similar_posts');
568
+ }
569
  $title = esc_attr($options['title']);
570
  if ( !$number = (int) $options['number'] )
571
  $number = 5;
593
  if(defined('WPLANG')){
594
  $language = substr(WPLANG, 0, 2);
595
  } else {
596
+ $language = '';
597
  }
598
  //if no language is specified make it the default which is 'en'
599
  if ($language == '') {
632
  function similar_posts_init () {
633
  global $overusedwords, $wp_db_version;
634
  load_plugin_textdomain('similar_posts');
635
+
636
  SimilarPosts::get_plugin_version();
637
+
638
  $options = get_option('similar-posts');
639
  if ($options['feed_active'] === 'true') add_filter('the_content', 'similar_posts_for_feed');
640
  if ($options['content_filter'] === 'true' && function_exists('ppl_register_content_filter')) ppl_register_content_filter('SimilarPosts');
645
  $condition = 'true';
646
  }
647
  $condition = (stristr($condition, "return")) ? $condition : "return ".$condition;
648
+ $condition = rtrim($condition, '; ') . ';';
649
  if ($options['append_on'] === 'true' && function_exists('ppl_register_post_filter')) ppl_register_post_filter('append', 'similar-posts', 'SimilarPosts', $condition);
650
 
651
  //install the actions to keep the index up to date
652
  add_action('save_post', 'sp_save_index_entry', 1);
653
  add_action('delete_post', 'sp_delete_index_entry', 1);
654
+ if ($wp_db_version < 3308 ) {
655
  add_action('edit_post', 'sp_save_index_entry', 1);
656
  add_action('publish_post', 'sp_save_index_entry', 1);
657
+ }
658
  add_action( 'admin_enqueue_scripts', 'similar_posts_wp_admin_style' );
659
+
660
  // aditional links in plugin description
661
  add_filter('plugin_action_links_' . basename(dirname(__FILE__)) . '/' . basename(__FILE__),
662
  array('SimilarPosts', 'plugin_action_links'));