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

Version Description

(13-October-2021) = * To use WP Template Conditionals in Similar Posts widget settings or Admin: + Require manage_options and unfiltered_html user capability. Note: In WordPress Multisite, only Super Admins have the unfiltered_html capability. + Check whether file editing is allowed per DISALLOW_FILE_EDIT constant * Show educational warning before allowing use of WP Template Conditionals

Download this release

Release Info

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

Code changes from version 3.1.5 to 3.1.6

admin-subpages.php CHANGED
@@ -1,76 +1,76 @@
1
- <?php
2
-
3
- /*
4
- A simple library class to ease the use of a further level of submenus in the admin pages
5
- Uses no javascript but 'borrows' some CSS it shouldn't
6
- */
7
-
8
- define('ADMIN_SUBPAGES_LIBRARY', true);
9
-
10
- class admin_subpages {
11
- var $pages = array();
12
- var $parent_page = '';
13
- var $current_page = array();
14
-
15
- function __construct($parent_page='') {
16
- if ($parent_page === '') {
17
- $parent_page = $_SERVER['QUERY_STRING'];
18
- $p1 = strpos($parent_page, 'page=');
19
- $p2 = strpos($parent_page, '&');
20
- if ($p2 === false) {
21
- $parent_page = substr($parent_page, $p1+5);
22
- } else {
23
- $parent_page = substr($parent_page, $p1+5, $p2-$p1-5);
24
- }
25
- }
26
- $this->parent_page = $parent_page;
27
- }
28
-
29
- function add_subpage($title, $slug, $view) {
30
- $this->pages[] = array('title' => $title, 'slug' => $slug, 'view' => $view);
31
- }
32
-
33
- function add_subpages($pages) {
34
- foreach ($pages as $page) {
35
- $this->pages[] = array('title' => $page[0], 'slug' => $page[1], 'view' => $page[2]);
36
- }
37
- }
38
-
39
- function page_from_slug($slug) {
40
- if (!isset($slug) || !$slug) {
41
- return $this->pages[0];
42
- }
43
- foreach ($this->pages as $page) {
44
- if ($page['slug'] === $slug) {
45
- return $page;
46
- }
47
- }
48
- die('non-existent slug');
49
- }
50
-
51
- function display_menu() {
52
- echo "\n<ul id=\"submenu\" class=\"similarposts-tabs-menu\" style=\"display: block\">\n";
53
- // for compatibility with WP mu
54
- $base = (isset($_SERVER['REDIRECT_URL'])) ? $_SERVER['REDIRECT_URL'] : $_SERVER['PHP_SELF'];
55
- $base .= '?page=' . $this->parent_page . '&subpage=';
56
- $this->current_page = (isset($_GET['subpage']))?$this->page_from_slug($_GET['subpage']):$this->page_from_slug(false);
57
- foreach($this->pages as $page) {
58
- if($page === $this->current_page) {
59
- echo "<li style=\"display: inline\"><a href=\"$base{$page['slug']}\" class=\"current\" style=\"display: inline\">{$page['title']}</a></li>\n";
60
- } else {
61
- echo "<li style=\"display: inline\"><a href=\"$base{$page['slug']}\" style=\"display: inline\">{$page['title']}</a></li>\n";
62
- }
63
- }
64
- echo "</ul>\n";
65
- }
66
-
67
- function display_view() {
68
- $this->current_page['view']();
69
- }
70
-
71
- function display() {
72
- $this->display_menu();
73
- $this->display_view();
74
- }
75
-
76
- }
1
+ <?php
2
+
3
+ /*
4
+ A simple library class to ease the use of a further level of submenus in the admin pages
5
+ Uses no javascript but 'borrows' some CSS it shouldn't
6
+ */
7
+
8
+ define('ADMIN_SUBPAGES_LIBRARY', true);
9
+
10
+ class admin_subpages {
11
+ var $pages = array();
12
+ var $parent_page = '';
13
+ var $current_page = array();
14
+
15
+ function __construct($parent_page='') {
16
+ if ($parent_page === '') {
17
+ $parent_page = $_SERVER['QUERY_STRING'];
18
+ $p1 = strpos($parent_page, 'page=');
19
+ $p2 = strpos($parent_page, '&');
20
+ if ($p2 === false) {
21
+ $parent_page = substr($parent_page, $p1+5);
22
+ } else {
23
+ $parent_page = substr($parent_page, $p1+5, $p2-$p1-5);
24
+ }
25
+ }
26
+ $this->parent_page = $parent_page;
27
+ }
28
+
29
+ function add_subpage($title, $slug, $view) {
30
+ $this->pages[] = array('title' => $title, 'slug' => $slug, 'view' => $view);
31
+ }
32
+
33
+ function add_subpages($pages) {
34
+ foreach ($pages as $page) {
35
+ $this->pages[] = array('title' => $page[0], 'slug' => $page[1], 'view' => $page[2]);
36
+ }
37
+ }
38
+
39
+ function page_from_slug($slug) {
40
+ if (!isset($slug) || !$slug) {
41
+ return $this->pages[0];
42
+ }
43
+ foreach ($this->pages as $page) {
44
+ if ($page['slug'] === $slug) {
45
+ return $page;
46
+ }
47
+ }
48
+ die('non-existent slug');
49
+ }
50
+
51
+ function display_menu() {
52
+ echo "\n<ul id=\"submenu\" class=\"similarposts-tabs-menu\" style=\"display: block\">\n";
53
+ // for compatibility with WP mu
54
+ $base = (isset($_SERVER['REDIRECT_URL'])) ? $_SERVER['REDIRECT_URL'] : $_SERVER['PHP_SELF'];
55
+ $base .= '?page=' . $this->parent_page . '&subpage=';
56
+ $this->current_page = (isset($_GET['subpage']))?$this->page_from_slug($_GET['subpage']):$this->page_from_slug(false);
57
+ foreach($this->pages as $page) {
58
+ if($page === $this->current_page) {
59
+ echo "<li style=\"display: inline\"><a href=\"$base{$page['slug']}\" class=\"current\" style=\"display: inline\">{$page['title']}</a></li>\n";
60
+ } else {
61
+ echo "<li style=\"display: inline\"><a href=\"$base{$page['slug']}\" style=\"display: inline\">{$page['title']}</a></li>\n";
62
+ }
63
+ }
64
+ echo "</ul>\n";
65
+ }
66
+
67
+ function display_view() {
68
+ $this->current_page['view']();
69
+ }
70
+
71
+ function display() {
72
+ $this->display_menu();
73
+ $this->display_view();
74
+ }
75
+
76
+ }
admin_common_functions.php CHANGED
@@ -1,1036 +1,1038 @@
1
- <?php
2
-
3
- /*
4
- Library for the Recent Posts, Random Posts, Recent Comments, and Similar Posts plugins
5
- -- provides the admin routines which the plugins share
6
- */
7
-
8
- define('ACF_LIBRARY', true);
9
-
10
- function ppl_options_from_post($options, $args) {
11
- foreach ($args as $arg) {
12
- switch ($arg) {
13
- case 'limit':
14
- case 'skip':
15
- $options[$arg] = ppl_check_cardinal($_POST[$arg]);
16
- break;
17
- case 'excluded_cats':
18
- case 'included_cats':
19
- if (isset($_POST[$arg])) {
20
- // get the subcategories too
21
- if (function_exists('get_term_children')) {
22
- $catarray = $_POST[$arg];
23
- foreach ($catarray as $cat) {
24
- $catarray = array_merge($catarray, get_term_children($cat, 'category'));
25
- }
26
- $_POST[$arg] = array_unique($catarray);
27
- }
28
- $options[$arg] = implode(',', $_POST[$arg]);
29
- } else {
30
- $options[$arg] = '';
31
- }
32
- break;
33
- case 'excluded_authors':
34
- case 'included_authors':
35
- if (isset($_POST[$arg])) {
36
- $options[$arg] = implode(',', $_POST[$arg]);
37
- } else {
38
- $options[$arg] = '';
39
- }
40
- break;
41
- case 'excluded_posts':
42
- case 'included_posts':
43
- $check = explode(',', rtrim($_POST[$arg]));
44
- $ids = array();
45
- foreach ($check as $id) {
46
- $id = ppl_check_cardinal($id);
47
- if ($id !== 0) $ids[] = $id;
48
- }
49
- $options[$arg] = implode(',', array_unique($ids));
50
- break;
51
- case 'stripcodes':
52
- $st = explode("\n", trim($_POST['starttags']));
53
- $se = explode("\n", trim($_POST['endtags']));
54
- if (count($st) != count($se)) {
55
- $options['stripcodes'] = array(array());
56
- } else {
57
- $num = count($st);
58
- for ($i = 0; $i < $num; $i++) {
59
- $options['stripcodes'][$i]['start'] = $st[$i];
60
- $options['stripcodes'][$i]['end'] = $se[$i];
61
- }
62
- }
63
- break;
64
- case 'age':
65
- $options['age']['direction'] = $_POST['age-direction'];
66
- $options['age']['length'] = ppl_check_cardinal($_POST['age-length']);
67
- $options['age']['duration'] = $_POST['age-duration'];
68
- break;
69
- case 'custom':
70
- $options['custom']['key'] = $_POST['custom-key'];
71
- $options['custom']['op'] = $_POST['custom-op'];
72
- $options['custom']['value'] = $_POST['custom-value'];
73
- break;
74
- case 'sort':
75
- $options['sort']['by1'] = $_POST['sort-by1'];
76
- $options['sort']['order1'] = $_POST['sort-order1'];
77
- if ($options['sort']['order1'] === 'SORT_ASC') $options['sort']['order1'] = SORT_ASC; else $options['sort']['order1'] = SORT_DESC;
78
- $options['sort']['case1'] = $_POST['sort-case1'];
79
- $options['sort']['by2'] = $_POST['sort-by2'];
80
- $options['sort']['order2'] = $_POST['sort-order2'];
81
- if ($options['sort']['order2'] === 'SORT_ASC') $options['sort']['order2'] = SORT_ASC; else $options['sort']['order2'] = SORT_DESC;
82
- $options['sort']['case2'] = $_POST['sort-case2'];
83
- if ($options['sort']['by1'] === '') {
84
- $options['sort']['order1'] = SORT_ASC;
85
- $options['sort']['case1'] = 'false';
86
- $options['sort']['by2'] = '';
87
- }
88
- if ($options['sort']['by2'] === '') {
89
- $options['sort']['order2'] = SORT_ASC;
90
- $options['sort']['case2'] = 'false';
91
- }
92
- break;
93
- case 'status':
94
- unset($options['status']);
95
- $options['status']['publish'] = $_POST['status-publish'];
96
- $options['status']['private'] = $_POST['status-private'];
97
- $options['status']['draft'] = $_POST['status-draft'];
98
- $options['status']['future'] = $_POST['status-future'];
99
- break;
100
- case 'num_terms':
101
- $options['num_terms'] = $_POST['num_terms'];
102
- if ($options['num_terms'] < 1) $options['num_terms'] = 20;
103
- break;
104
- default:
105
- $options[$arg] = trim($_POST[$arg]);
106
- }
107
- }
108
- return $options;
109
- }
110
-
111
- function ppl_check_cardinal($string) {
112
- $value = intval($string);
113
- return ($value > 0) ? $value : 0;
114
- }
115
-
116
- function ppl_display_available_tags($plugin_name) {
117
- ?>
118
- <h3><?php _e('Available Tags', 'post_plugin_library'); ?></h3>
119
- <ul style="list-style-type: none;">
120
- <li title="">{author}</li>
121
- <li title="">{authorurl}</li>
122
- <li title="">{categoryid}</li>
123
- <li title="">{categorylinks}</li>
124
- <li title="">{categorynames}</li>
125
- <li title="">{commentcount}</li>
126
- <li title="">{custom}</li>
127
- <li title="">{date}</li>
128
- <li title="">{dateedited}</li>
129
- <li title="">{excerpt}</li>
130
- <li title="">{fullpost}</li>
131
- <li title="">{gravatar}</li>
132
- <li title="">{if}</li>
133
- <li title="">{image}</li>
134
- <li title="">{imagealt}</li>
135
- <li title="">{imagesrc}</li>
136
- <li title="">{link}</li>
137
- <li title="">{php}</li>
138
- <li title="">{postid}</li>
139
- <li title="">{postviews}</li>
140
- <?php if ($plugin_name === 'similar-posts') { ?>
141
- <li title="">{score}</li>
142
- <?php } ?>
143
- <li title="">{snippet}</li>
144
- <li title="">{tags}</li>
145
- <li title="">{taglinks}</li>
146
- <li title="">{title}</li>
147
- <li title="">{time}</li>
148
- <li title="">{timeedited}</li>
149
- <li title="">{totalpages}</li>
150
- <li title="">{totalposts}</li>
151
- <li title="">{url}</li>
152
- </ul>
153
- <?php
154
- }
155
-
156
- function ppl_display_available_comment_tags() {
157
- ?>
158
- <ul style="list-style-type: none;">
159
- <li title="">{commentexcerpt}</li>
160
- <li title="">{commentsnippet}</li>
161
- <li title="">{commentdate}</li>
162
- <li title="">{commenttime}</li>
163
- <li title="">{commentdategmt}</li>
164
- <li title="">{commenttimegmt}</li>
165
- <li title="">{commenter}</li>
166
- <li title="">{commenterip}</li>
167
- <li title="">{commenterurl}</li>
168
- <li title="">{commenterlink}</li>
169
- <li title="">{commenturl}</li>
170
- <li title="">{commentpopupurl}</li>
171
- <li title="">{commentlink}</li>
172
- <li title="">{commentlink2}</li>
173
- </ul>
174
- <?php
175
- }
176
-
177
- /*
178
-
179
- inserts a form button to submit a bug report to my web site
180
-
181
- */
182
- function get_plugin_version($prefix) {
183
- $plugin_version = str_replace('-', '_', $prefix) . '_version';
184
- global $$plugin_version;
185
- return ${$plugin_version};
186
- }
187
-
188
-
189
-
190
- /*
191
-
192
- inserts a form button to completely remove the plugin and all its options etc.
193
-
194
- */
195
-
196
- function ppl_confirm_eradicate() {
197
- return (isset($_POST['eradicate-check']) && 'yes'===$_POST['eradicate-check']);
198
- }
199
-
200
- function ppl_deactivate_plugin($plugin_file) {
201
- $current = get_option('active_plugins');
202
- $plugin_file = substr($plugin_file, strlen(WP_PLUGIN_DIR)+1);
203
- $plugin_file = str_replace('\\', '/', $plugin_file);
204
- if (in_array($plugin_file, $current)) {
205
- array_splice($current, array_search($plugin_file, $current), 1);
206
- update_option('active_plugins', $current);
207
- }
208
- }
209
-
210
-
211
- /*
212
-
213
- For the display of the option pages
214
-
215
- */
216
-
217
- function ppl_display_limit($limit) {
218
- ?>
219
- <tr valign="top">
220
- <th scope="row"><label for="limit"><?php _e('Number of posts to show:', 'post_plugin_library') ?></label></th>
221
- <td><input name="limit" type="number" id="limit" style="width: 60px;" value="<?php echo $limit; ?>" size="2" /></td>
222
- </tr>
223
- <?php
224
- }
225
-
226
- function ppl_display_unique($unique) {
227
- ?>
228
- <tr valign="top">
229
- <th scope="row"><label for="unique"><?php _e('Show just one comment per post?', 'post_plugin_library') ?></label></th>
230
- <td>
231
- <select name="unique" id="unique" >
232
- <option <?php if($unique == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
233
- <option <?php if($unique == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
234
- </select>
235
- </td>
236
- </tr>
237
- <?php
238
- }
239
-
240
- function ppl_display_skip($skip) {
241
- ?>
242
- <tr valign="top">
243
- <th scope="row"><label for="skip"><?php _e('Number of posts to skip:', 'post_plugin_library') ?></label></th>
244
- <td><input name="skip" type="number" id="skip" style="width: 60px;" value="<?php echo $skip; ?>" size="2" /></td>
245
- </tr>
246
- <?php
247
- }
248
-
249
- function ppl_display_omit_current_post($omit_current_post) {
250
- ?>
251
- <tr valign="top">
252
- <th scope="row"><label for="omit_current_post"><?php _e('Omit the current post?', 'post_plugin_library') ?></label></th>
253
- <td>
254
- <select name="omit_current_post" id="omit_current_post" >
255
- <option <?php if($omit_current_post == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
256
- <option <?php if($omit_current_post == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
257
- </select>
258
- </td>
259
- </tr>
260
- <?php
261
- }
262
-
263
- function ppl_display_just_current_post($just_current_post) {
264
- ?>
265
- <tr valign="top">
266
- <th scope="row"><label for="just_current_post"><?php _e('Show just the current post?', 'post_plugin_library') ?></label></th>
267
- <td>
268
- <select name="just_current_post" id="just_current_post" >
269
- <option <?php if($just_current_post == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
270
- <option <?php if($just_current_post == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
271
- </select>
272
- </td>
273
- </tr>
274
- <?php
275
- }
276
-
277
- function ppl_display_show_private($show_private) {
278
- ?>
279
- <tr valign="top">
280
- <th scope="row"><label for="show_private"><?php _e('Show password-protected posts?', 'post_plugin_library') ?></label></th>
281
- <td>
282
- <select name="show_private" id="show_private">
283
- <option <?php if($show_private == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
284
- <option <?php if($show_private == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
285
- </select>
286
- </td>
287
- </tr>
288
- <?php
289
- }
290
-
291
- function ppl_display_show_pages($show_pages) {
292
- ?>
293
- <tr valign="top">
294
- <th scope="row"><label for="show_pages"><?php _e('Show static pages?', 'post_plugin_library') ?></label></th>
295
- <td>
296
- <select name="show_pages" id="show_pages">
297
- <option <?php if($show_pages == 'false') { echo 'selected="selected"'; } ?> value="false">No pages, just posts</option>
298
- <option <?php if($show_pages == 'true') { echo 'selected="selected"'; } ?> value="true">Both pages and posts</option>
299
- <option <?php if($show_pages == 'but') { echo 'selected="selected"'; } ?> value="but">Pages but no posts</option>
300
- </select>
301
- </td>
302
- </tr>
303
- <?php
304
- }
305
-
306
- function ppl_display_show_attachments($show_attachments) {
307
- ?>
308
- <tr valign="top">
309
- <th scope="row"><label for="show_attachments"><?php _e('Show attachments?', 'post_plugin_library') ?></label></th>
310
- <td>
311
- <select name="show_attachments" id="show_attachments">
312
- <option <?php if($show_attachments == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
313
- <option <?php if($show_attachments == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
314
- </select>
315
- </td>
316
- </tr>
317
- <?php
318
- }
319
-
320
- function ppl_display_match_author($match_author) {
321
- ?>
322
- <tr valign="top">
323
- <th scope="row"><label for="match_author"><?php _e('Match the current post\'s author?', 'post_plugin_library') ?></label></th>
324
- <td>
325
- <select name="match_author" id="match_author">
326
- <option <?php if($match_author == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
327
- <option <?php if($match_author == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
328
- </select>
329
- </td>
330
- </tr>
331
- <?php
332
- }
333
-
334
- function ppl_display_match_cat($match_cat) {
335
- ?>
336
- <tr valign="top">
337
- <th scope="row"><label for="match_cat"><?php _e('Match the current post\'s category?', 'post_plugin_library') ?></label></th>
338
- <td>
339
- <select name="match_cat" id="match_cat">
340
- <option <?php if($match_cat == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
341
- <option <?php if($match_cat == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
342
- </select>
343
- </td>
344
- </tr>
345
- <?php
346
- }
347
-
348
- function ppl_display_match_tags($match_tags) {
349
- global $wp_version;
350
- ?>
351
- <tr valign="top">
352
- <th scope="row"><label for="match_tags"><?php _e('Match the current post\'s tags?', 'post_plugin_library') ?></label></th>
353
- <td>
354
- <select name="match_tags" id="match_tags" <?php if ($wp_version < 2.3) echo 'disabled="true"'; ?> >
355
- <option <?php if($match_tags == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
356
- <option <?php if($match_tags == 'any') { echo 'selected="selected"'; } ?> value="any">Any tag</option>
357
- <option <?php if($match_tags == 'all') { echo 'selected="selected"'; } ?> value="all">Every tag</option>
358
- </select>
359
- </td>
360
- </tr>
361
- <?php
362
- }
363
-
364
- function ppl_display_none_text($none_text) {
365
- ?>
366
- <tr valign="top">
367
- <th scope="row"><label for="none_text"><?php _e('Default display if no matches:', 'post_plugin_library') ?></label></th>
368
- <td><input name="none_text" type="text" id="none_text" value="<?php echo htmlspecialchars(stripslashes($none_text)); ?>" size="40" /></td>
369
- </tr>
370
- <?php
371
- }
372
-
373
- function ppl_display_no_text($no_text) {
374
- ?>
375
- <tr valign="top">
376
- <th scope="row"><label for="no_text"><?php _e('Show nothing if no matches?', 'post_plugin_library') ?></label></th>
377
- <td>
378
- <select name="no_text" id="no_text">
379
- <option <?php if($no_text == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
380
- <option <?php if($no_text == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
381
- </select>
382
- </td>
383
- </tr>
384
- <?php
385
- }
386
-
387
- function ppl_display_prefix($prefix) {
388
- ?>
389
- <tr valign="top">
390
- <th scope="row"><label for="prefix"><?php _e('Text and codes before the list:', 'post_plugin_library') ?></label></th>
391
- <td><input name="prefix" type="text" id="prefix" value="<?php echo htmlspecialchars(stripslashes($prefix)); ?>" size="40" /></td>
392
- </tr>
393
- <?php
394
- }
395
-
396
- function ppl_display_suffix($suffix) {
397
- ?>
398
- <tr valign="top">
399
- <th scope="row"><label for="suffix"><?php _e('Text and codes after the list:', 'post_plugin_library') ?></label></th>
400
- <td><input name="suffix" type="text" id="suffix" value="<?php echo htmlspecialchars(stripslashes($suffix)); ?>" size="40" /></td>
401
- </tr>
402
- <?php
403
- }
404
-
405
- function ppl_display_output_template($output_template) {
406
- ?>
407
- <tr valign="top">
408
- <th scope="row"><label for="output_template"><?php _e('Output template:', 'post_plugin_library') ?></label></th>
409
- <td><textarea name="output_template" id="output_template" rows="4" cols="38"><?php echo htmlspecialchars(stripslashes($output_template)); ?></textarea></td>
410
- </tr>
411
- <?php
412
- }
413
-
414
- function ppl_display_divider($divider) {
415
- ?>
416
- <tr valign="top">
417
- <th scope="row"><label for="divider"><?php _e('Text and codes between items:', 'post_plugin_library') ?></label></th>
418
- <td><input name="divider" type="text" id="divider" value="<?php echo $divider; ?>" size="40" /></td>
419
- </tr>
420
- <?php
421
- }
422
-
423
- function ppl_display_tag_str($tag_str) {
424
- global $wp_version;
425
- ?>
426
- <tr valign="top">
427
- <th scope="row"><label for="tag_str"><?php _e('Match posts with tags:<br />(a,b matches posts with either tag, a+b only matches posts with both tags)', 'post_plugin_library') ?></label></th>
428
- <td><input name="tag_str" type="text" id="tag_str" value="<?php echo $tag_str; ?>" <?php if ($wp_version < 2.3) echo 'disabled="true"'; ?> size="40" /></td>
429
- </tr>
430
- <?php
431
- }
432
-
433
- function ppl_display_excluded_posts($excluded_posts) {
434
- ?>
435
- <tr valign="top">
436
- <th scope="row"><label for="excluded_posts"><?php _e('Posts to exclude:', 'post_plugin_library') ?></label></th>
437
- <td><input name="excluded_posts" type="text" id="excluded_posts" value="<?php echo $excluded_posts; ?>" size="40" /> <?php _e('comma-separated IDs', 'post_plugin_library'); ?></td>
438
- </tr>
439
- <?php
440
- }
441
-
442
- function ppl_display_included_posts($included_posts) {
443
- ?>
444
- <tr valign="top">
445
- <th scope="row"><label for="included_posts"><?php _e('Posts to include:', 'post_plugin_library') ?></label></th>
446
- <td><input name="included_posts" type="text" id="included_posts" value="<?php echo $included_posts; ?>" size="40" /> <?php _e('comma-separated IDs', 'post_plugin_library'); ?></td>
447
- </tr>
448
- <?php
449
- }
450
-
451
- function ppl_display_authors($excluded_authors, $included_authors) {
452
- global $wpdb;
453
- ?>
454
- <tr valign="top">
455
- <th scope="row"><?php _e('Authors to exclude/include:', 'post_plugin_library') ?></th>
456
- <td>
457
- <table class="similarposts-inner-table">
458
- <?php
459
- $users = $wpdb->get_results("SELECT ID, user_login FROM $wpdb->users ORDER BY user_login");
460
- if ($users) {
461
- $excluded = explode(',', $excluded_authors);
462
- $included = explode(',', $included_authors);
463
- echo "\n\t<tr valign=\"top\"><td><strong>Author</strong></td><td><strong>Exclude</strong></td><td><strong>Include</strong></td></tr>";
464
- foreach ($users as $user) {
465
- if (false === in_array($user->ID, $excluded)) {
466
- $ex_ischecked = '';
467
- } else {
468
- $ex_ischecked = 'checked';
469
- }
470
- if (false === in_array($user->ID, $included)) {
471
- $in_ischecked = '';
472
- } else {
473
- $in_ischecked = 'checked';
474
- }
475
- echo "\n\t<tr valign=\"top\"><td>$user->user_login</td><td><input type=\"checkbox\" name=\"excluded_authors[]\" value=\"$user->ID\" $ex_ischecked /></td><td><input type=\"checkbox\" name=\"included_authors[]\" value=\"$user->ID\" $in_ischecked /></td></tr>";
476
- }
477
- }
478
- ?>
479
- </table>
480
- </td>
481
- </tr>
482
- <?php
483
- }
484
-
485
- function ppl_display_cats($excluded_cats, $included_cats) {
486
- global $wpdb;
487
- ?>
488
- <tr valign="top">
489
- <th scope="row"><?php _e('Categories to exclude/include:', 'post_plugin_library') ?></th>
490
- <td>
491
- <table class="similarposts-inner-table">
492
- <?php
493
- if (function_exists("get_categories")) {
494
- $categories = get_categories();//('&hide_empty=1');
495
- } else {
496
- //$categories = $wpdb->get_results("SELECT * FROM $wpdb->categories WHERE category_count <> 0 ORDER BY cat_name");
497
- $categories = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY cat_name");
498
- }
499
- if ($categories) {
500
- echo "\n\t<tr valign=\"top\"><td><strong>Category</strong></td><td><strong>Exclude</strong></td><td><strong>Include</strong></td></tr>";
501
- $excluded = explode(',', $excluded_cats);
502
- $included = explode(',', $included_cats);
503
- $level = 0;
504
- $cats_added = array();
505
- $last_parent = 0;
506
- $cat_parent = 0;
507
- foreach ($categories as $category) {
508
- $category->cat_name = esc_html($category->cat_name);
509
- if (false === in_array($category->cat_ID, $excluded)) {
510
- $ex_ischecked = '';
511
- } else {
512
- $ex_ischecked = 'checked';
513
- }
514
- if (false === in_array($category->cat_ID, $included)) {
515
- $in_ischecked = '';
516
- } else {
517
- $in_ischecked = 'checked';
518
- }
519
- $last_parent = $cat_parent;
520
- $cat_parent = $category->category_parent;
521
- if ($cat_parent == 0) {
522
- $level = 0;
523
- } elseif ($last_parent != $cat_parent) {
524
- if (in_array($cat_parent, $cats_added)) {
525
- $level = $level - 1;
526
- } else {
527
- $level = $level + 1;
528
- }
529
- $cats_added[] = $cat_parent;
530
- }
531
- $pad = str_repeat('&nbsp;', 3*$level);
532
- echo "\n\t<tr valign=\"top\"><td>$pad$category->cat_name</td><td><input type=\"checkbox\" name=\"excluded_cats[]\" value=\"$category->cat_ID\" $ex_ischecked /></td><td><input type=\"checkbox\" name=\"included_cats[]\" value=\"$category->cat_ID\" $in_ischecked /></td></tr>";
533
- }
534
- }
535
- ?>
536
- </table>
537
- </td>
538
- </tr>
539
- <?php
540
- }
541
-
542
- function ppl_display_stripcodes($stripcodes) {
543
- ?>
544
- <tr valign="top">
545
- <th scope="row"><?php _e('Other plugins\' tags to remove from snippet:', 'post_plugin_library') ?></th>
546
- <td>
547
- <table>
548
- <tr><td style="border-bottom-width: 0"><label for="starttags"><?php _e('opening', 'post_plugin_library') ?></label></td><td style="border-bottom-width: 0"><label for="endtags"><?php _e('closing', 'post_plugin_library') ?></label></td></tr>
549
- <tr valign="top"><td style="border-bottom-width: 0">
550
- <textarea name="starttags" id="starttags" rows="4" cols="20"><?php
551
- foreach ($stripcodes as $tag) {
552
- if(array_key_exists('start',$tag)){
553
- echo htmlspecialchars(stripslashes($tag['start']))."\n";
554
- }
555
- }
556
- ?></textarea></td><td style="border-bottom-width: 0">
557
-
558
- <textarea name="endtags" id="endtags" rows="4" cols="20"><?php
559
- foreach ($stripcodes as $tag) {
560
- if(array_key_exists('end',$tag)){
561
- echo htmlspecialchars(stripslashes($tag['end']))."\n";
562
- }
563
- }
564
- ?></textarea>
565
- </td></tr>
566
- </table>
567
- </td>
568
- </tr>
569
- <?php
570
- }
571
-
572
- function ppl_display_age($age) {
573
- ?>
574
- <tr valign="top">
575
- <th scope="row"><label for="age-direction"><?php _e('Ignore posts:', 'post_plugin_library') ?></label></th>
576
- <td>
577
-
578
- <select name="age-direction" id="age-direction">
579
- <option <?php if($age['direction'] == 'before') { echo 'selected="selected"'; } ?> value="before">less than</option>
580
- <option <?php if($age['direction'] == 'after') { echo 'selected="selected"'; } ?> value="after">more than</option>
581
- <option <?php if($age['direction'] == 'none') { echo 'selected="selected"'; } ?> value="none">-----</option>
582
- </select>
583
- <input style="vertical-align: middle; width: 60px;" name="age-length" type="number" id="age-length" value="<?php echo $age['length']; ?>" size="4" />
584
-
585
- <select name="age-duration" id="age-duration">
586
- <option <?php if($age['duration'] == 'day') { echo 'selected="selected"'; } ?> value="day">day(s)</option>
587
- <option <?php if($age['duration'] == 'month') { echo 'selected="selected"'; } ?> value="month">month(s)</option>
588
- <option <?php if($age['duration'] == 'year') { echo 'selected="selected"'; } ?> value="year">year(s)</option>
589
- </select>
590
- old
591
-
592
- </td>
593
- </tr>
594
- <?php
595
- }
596
-
597
- function ppl_display_status($status) {
598
- ?>
599
- <tr valign="top">
600
- <th scope="row"><?php _e('Display posts that are:', 'post_plugin_library') ?></th>
601
- <td>
602
-
603
- <label for="status-publish">Published</label>
604
- <select name="status-publish" id="status-publish" <?php if (!function_exists('get_post_type')) echo 'disabled="true"'; ?>>
605
- <option <?php if($status['publish'] == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
606
- <option <?php if($status['publish'] == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
607
- </select>
608
-
609
- <label for="status-private">Private</label>
610
- <select name="status-private" id="status-private" <?php if (!function_exists('get_post_type')) echo 'disabled="true"'; ?>>
611
- <option <?php if($status['private'] == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
612
- <option <?php if($status['private'] == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
613
- </select>
614
-
615
- <label for="status-draft">Draft</label>
616
- <select name="status-draft" id="status-draft" <?php if (!function_exists('get_post_type')) echo 'disabled="true"'; ?>>
617
- <option <?php if($status['draft'] == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
618
- <option <?php if($status['draft'] == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
619
- </select>
620
-
621
- <label for="status-future">Future</label>
622
- <select name="status-future" id="status-future" <?php if (!function_exists('get_post_type')) echo 'disabled="true"'; ?>>
623
- <option <?php if($status['future'] == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
624
- <option <?php if($status['future'] == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
625
- </select>
626
-
627
- </td>
628
- </tr>
629
- <?php
630
- }
631
-
632
- function ppl_display_custom($custom) {
633
- ?>
634
- <tr valign="top">
635
- <th scope="row"><?php _e('Match posts by custom field:', 'post_plugin_library') ?></th>
636
- <td>
637
- <table>
638
- <tr><td style="border-bottom-width: 0">Field Name</td><td style="border-bottom-width: 0"></td><td style="border-bottom-width: 0">Field Value</td></tr>
639
- <tr>
640
- <td style="border-bottom-width: 0"><input name="custom-key" type="text" id="custom-key" value="<?php echo $custom['key']; ?>" size="20" /></td>
641
- <td style="border-bottom-width: 0">
642
- <select name="custom-op" id="custom-op">
643
- <option <?php if($custom['op'] == '=') { echo 'selected="selected"'; } ?> value="=">=</option>
644
- <option <?php if($custom['op'] == '!=') { echo 'selected="selected"'; } ?> value="!=">!=</option>
645
- <option <?php if($custom['op'] == '>') { echo 'selected="selected"'; } ?> value=">">></option>
646
- <option <?php if($custom['op'] == '>=') { echo 'selected="selected"'; } ?> value=">=">>=</option>
647
- <option <?php if($custom['op'] == '<') { echo 'selected="selected"'; } ?> value="<"><</option>
648
- <option <?php if($custom['op'] == '<=') { echo 'selected="selected"'; } ?> value="<="><=</option>
649
- <option <?php if($custom['op'] == 'LIKE') { echo 'selected="selected"'; } ?> value="LIKE">LIKE</option>
650
- <option <?php if($custom['op'] == 'NOT LIKE') { echo 'selected="selected"'; } ?> value="NOT LIKE">NOT LIKE</option>
651
- <option <?php if($custom['op'] == 'REGEXP') { echo 'selected="selected"'; } ?> value="REGEXP">REGEXP</option>
652
- <option <?php if($custom['op'] == 'EXISTS') { echo 'selected="selected"'; } ?> value="EXISTS">EXISTS</option>
653
- </select>
654
- </td>
655
- <td style="border-bottom-width: 0"><input name="custom-value" type="text" id="custom-value" value="<?php echo $custom['value']; ?>" size="20" /></td>
656
- </tr>
657
- </table>
658
- </td>
659
- </tr>
660
- <?php
661
- }
662
-
663
- function ppl_display_append($options) {
664
- ?>
665
- <tr valign="top">
666
- <th scope="row"><?php _e('Output after post:', 'post_plugin_library') ?></th>
667
- <td>
668
- <table>
669
- <tr><td style="border-bottom-width: 0"><label for="append_on">Activate</label></td><td style="border-bottom-width: 0"><label for="append_priority">Priority</label></td><td style="border-bottom-width: 0"><label for="append_parameters">Parameters</label></td><td style="border-bottom-width: 0"><label for="append_condition">Condition</label></td></tr>
670
- <tr>
671
- <td style="border-bottom-width: 0">
672
- <select name="append_on" id="append_on">
673
- <option <?php if($options['append_on'] == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
674
- <option <?php if($options['append_on'] == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
675
- </select>
676
- </td>
677
- <td style="border-bottom-width: 0"><input name="append_priority" type="number" id="append_priority" style="width: 60px;" value="<?php echo $options['append_priority']; ?>" size="3" /></td>
678
- <td style="border-bottom-width: 0"><textarea name="append_parameters" id="append_parameters" rows="4" cols="38"><?php echo htmlspecialchars(stripslashes($options['append_parameters'])); ?></textarea></td>
679
- <td style="border-bottom-width: 0"><textarea name="append_condition" id="append_condition" rows="4" cols="20"><?php echo htmlspecialchars(stripslashes($options['append_condition'])); ?></textarea></td>
680
- </tr></table>
681
- </td>
682
- </tr>
683
- <?php
684
- }
685
-
686
- function ppl_display_feed($options) {
687
- ?>
688
- <tr valign="top">
689
- <th scope="row"><?php _e('Output in RSS feeds:', 'post_plugin_library') ?></th>
690
- <td>
691
- <table>
692
- <tr><td style="border-bottom-width: 0"><label for="feed_on">Activate</label></td><td style="border-bottom-width: 0"><label for="feed_priority">Priority</label></td><td style="border-bottom-width: 0"><label for="feed_parameters">Parameters</label></td></tr>
693
- <tr>
694
- <td style="border-bottom-width: 0">
695
- <select name="feed_on" id="feed_on">
696
- <option <?php if($options['feed_on'] == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
697
- <option <?php if($options['feed_on'] == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
698
- </select>
699
- </td>
700
- <td style="border-bottom-width: 0"><input name="feed_priority" type="number" id="feed_priority" style="width: 60px;" value="<?php echo $options['feed_priority']; ?>" size="3" /></td>
701
- <td style="border-bottom-width: 0"><textarea name="feed_parameters" id="feed_parameters" rows="4" cols="38"><?php echo htmlspecialchars(stripslashes($options['feed_parameters'])); ?></textarea></td>
702
- </tr></table>
703
- </td>
704
- </tr>
705
- <?php
706
- }
707
-
708
- function ppl_display_widget($options) {
709
- ?>
710
- <tr valign="top">
711
- <th scope="row"><?php _e('Output in widget:', 'post_plugin_library') ?></th>
712
- <td>
713
- <table>
714
- <tr><td style="border-bottom-width: 0"></td><td style="border-bottom-width: 0"></td><td style="border-bottom-width: 0"><label for="widget_parameters">Parameters</label></td><td style="border-bottom-width: 0"><label for="widget_condition">Condition</label></td></tr>
715
- <tr>
716
- <td style="border-bottom-width: 0;visibility: hidden;">
717
- <select name="dummy" id="dummy1">
718
- <option value="false">No</option>
719
- <option value="true">Yes</option>
720
- </select>
721
- </td>
722
- <td style="border-bottom-width: 0;visibility: hidden;"><input name="dummy2" type="text" id="dummy2" value="" size="3" /></td>
723
- <td style="border-bottom-width: 0"><textarea name="widget_parameters" id="widget_parameters" rows="4" cols="38"><?php echo htmlspecialchars(stripslashes($options['widget_parameters'])); ?></textarea></td>
724
- <td style="border-bottom-width: 0"><textarea name="widget_condition" id="widget_condition" rows="4" cols="20"><?php echo htmlspecialchars(stripslashes($options['widget_condition'])); ?></textarea></td>
725
- </tr></table>
726
- </td>
727
- </tr>
728
- <?php
729
- }
730
-
731
- function ppl_display_feed_active($feed_active) {
732
- ?>
733
- <tr valign="top">
734
- <th scope="row"><label for="feed_active"><?php _e('Add Similar Posts to feeds? (DEPRECATED! This setting will be removed in the next major release - use the placement settings instead)', 'post_plugin_library') ?></label></th>
735
- <td>
736
- <select name="feed_active" id="feed_active">
737
- <option <?php if($feed_active == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
738
- <option <?php if($feed_active == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
739
- </select>
740
- </td>
741
- </tr>
742
- <?php
743
- }
744
-
745
- function ppl_display_content_filter($content_filter) {
746
- ?>
747
- <tr valign="top">
748
- <th scope="row"><?php _e('Output in content:<br />(<em>via</em> special tags)', 'post_plugin_library') ?></th>
749
- <td>
750
- <table>
751
- <tr><td style="border-bottom-width: 0"><label for="content_filter">Activate</label></td></tr>
752
- <tr>
753
- <td style="border-bottom-width: 0">
754
- <select name="content_filter" id="content_filter">
755
- <option <?php if($content_filter == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
756
- <option <?php if($content_filter == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
757
- </select>
758
- </td>
759
- </tr>
760
- </table>
761
- </td>
762
- </tr>
763
- <?php
764
- }
765
-
766
- function ppl_display_sort($sort) {
767
- global $wpdb;
768
- ?>
769
- <tr valign="top">
770
- <th scope="row"><?php _e('Sort Output By:<br />leave blank for default order', 'post_plugin_library') ?></th>
771
- <td>
772
- <table>
773
- <tr><td style="border-bottom-width: 0"></td><td style="border-bottom-width: 0">Output Tag</td><td style="border-bottom-width: 0">Order</td><td style="border-bottom-width: 0">Case</td></tr>
774
- <tr>
775
- <td style="border-bottom-width: 0">first</td>
776
- <td style="border-bottom-width: 0"><input name="sort-by1" type="text" id="sort-by1" value="<?php echo $sort['by1']; ?>" size="20" /></td>
777
- <td style="border-bottom-width: 0">
778
- <select name="sort-order1" id="sort-order1">
779
- <option <?php if($sort['order1'] == SORT_ASC) { echo 'selected="selected"'; } ?> value="SORT_ASC">ascending</option>
780
- <option <?php if($sort['order1'] == SORT_DESC) { echo 'selected="selected"'; } ?> value="SORT_DESC">descending</option>
781
- </select>
782
- </td>
783
- <td style="border-bottom-width: 0">
784
- <select name="sort-case1" id="sort-case1">
785
- <option <?php if($sort['case1'] == 'false') { echo 'selected="selected"'; } ?> value="false">case-sensitive</option>
786
- <option <?php if($sort['case1'] == 'true') { echo 'selected="selected"'; } ?> value="true">case-insensitive</option>
787
- </select>
788
- </td>
789
- </tr>
790
- <tr>
791
- <td style="border-bottom-width: 0">then</td>
792
- <td style="border-bottom-width: 0"><input name="sort-by2" type="text" id="sort-by2" value="<?php echo $sort['by2']; ?>" size="20" /></td>
793
- <td style="border-bottom-width: 0">
794
- <select name="sort-order2" id="sort-order2">
795
- <option <?php if($sort['order2'] == SORT_ASC) { echo 'selected="selected"'; } ?> value="SORT_ASC">ascending</option>
796
- <option <?php if($sort['order2'] == SORT_DESC) { echo 'selected="selected"'; } ?> value="SORT_DESC">descending</option>
797
- </select>
798
- </td>
799
- <td style="border-bottom-width: 0">
800
- <select name="sort-case2" id="sort-case2">
801
- <option <?php if($sort['case2'] == 'false') { echo 'selected="selected"'; } ?> value="false">case-sensitive</option>
802
- <option <?php if($sort['case2'] == 'true') { echo 'selected="selected"'; } ?> value="true">case-insensitive</option>
803
- </select>
804
- </td>
805
- </tr>
806
- </table>
807
- </td>
808
- </tr>
809
- <?php
810
- }
811
-
812
- function ppl_display_orderby($options) {
813
- global $wpdb;
814
- $limit = 30;
815
- $keys = $wpdb->get_col( "
816
- SELECT meta_key
817
- FROM $wpdb->postmeta
818
- WHERE meta_key NOT LIKE '\_%'
819
- GROUP BY meta_key
820
- ORDER BY meta_id DESC
821
- LIMIT $limit" );
822
- $metaselect = "<select id='orderby' name='orderby'>\n\t<option value=''></option>";
823
- if ( $keys ) {
824
- natcasesort($keys);
825
- foreach ( $keys as $key ) {
826
- $key = esc_attr( $key );
827
- if ($options['orderby'] == $key) {
828
- $metaselect .= "\n\t<option selected='selected' value='$key'>$key</option>";
829
- } else {
830
- $metaselect .= "\n\t<option value='$key'>$key</option>";
831
- }
832
- }
833
- $metaselect .= "</select>";
834
- }
835
-
836
- ?>
837
- <tr valign="top">
838
- <th scope="row"><?php _e('Select output by custom field:', 'post_plugin_library') ?></th>
839
- <td>
840
- <table>
841
- <tr><td style="border-bottom-width: 0">Field</td><td style="border-bottom-width: 0">Order</td><td style="border-bottom-width: 0">Case</td></tr>
842
- <tr>
843
- <td style="border-bottom-width: 0">
844
- <?php echo $metaselect; ?>
845
- </td>
846
- <td style="border-bottom-width: 0">
847
- <select name="orderby_order" id="orderby_order">
848
- <option <?php if($options['orderby_order'] == 'ASC') { echo 'selected="selected"'; } ?> value="ASC">ascending</option>
849
- <option <?php if($options['orderby_order'] == 'DESC') { echo 'selected="selected"'; } ?> value="DESC">descending</option>
850
- </select>
851
- </td>
852
- <td style="border-bottom-width: 0">
853
- <select name="orderby_case" id="orderby_case">
854
- <option <?php if($options['orderby_case'] == 'false') { echo 'selected="selected"'; } ?> value="false">case-sensitive</option>
855
- <option <?php if($options['orderby_case'] == 'true') { echo 'selected="selected"'; } ?> value="true">case-insensitive</option>
856
- <option <?php if($options['orderby_case'] == 'num') { echo 'selected="selected"'; } ?> value="num">numeric</option>
857
- </select>
858
- </td>
859
- </tr>
860
- </table>
861
- </td>
862
- </tr>
863
- <?php
864
- }
865
-
866
- // now for similar_posts
867
-
868
- function ppl_display_num_terms($num_terms) {
869
- ?>
870
- <tr valign="top">
871
- <th scope="row"><label for="num_terms"><?php _e('Maximum number of words to use for match:', 'post_plugin_library') ?></label></th>
872
- <td><input name="num_terms" type="number" id="num_terms" style="width: 60px;" value="<?php echo $num_terms; ?>" size="3" /></td>
873
- </tr>
874
- <?php
875
- }
876
-
877
- function ppl_display_term_extraction($term_extraction) {
878
- ?>
879
- <tr valign="top">
880
- <th scope="row" title=""><label for="term_extraction"><?php _e('Extract terms to match by:', 'post_plugin_library') ?></label></th>
881
- <td>
882
- <select name="term_extraction" id="term_extraction">
883
- <option <?php if($term_extraction == 'frequency') { echo 'selected="selected"'; } ?> value="frequency">Word Frequency</option>
884
- <option <?php if($term_extraction == 'pagerank') { echo 'selected="selected"'; } ?> value="pagerank">TextRank Algorithm</option>
885
- </select>
886
- </td>
887
- </tr>
888
- <?php
889
- }
890
-
891
- function ppl_display_weights($options) {
892
- ?>
893
- <tr valign="top">
894
- <th scope="row"><?php _e('Relative importance of:', 'post_plugin_library') ?></th>
895
- <td>
896
- <label for="weight_content">content: </label><input name="weight_content" type="number" style="width: 60px;" id="weight_content" value="<?php echo round(100 * $options['weight_content']); ?>" size="3" /> %
897
- <label for="weight_title" style="margin-left:20px;">title: </label><input name="weight_title" type="number" style="width: 60px;" id="weight_title" value="<?php echo round(100 * $options['weight_title']); ?>" size="3" /> %
898
- <label for="weight_tags" style="margin-left:20px;">tags: </label><input name="weight_tags" type="number" style="width: 60px;" id="weight_tags" value="<?php echo round(100 * $options['weight_tags']); ?>" size="3" /> % ( adds up to 100% )
899
- </td>
900
- </tr>
901
- <?php
902
- }
903
-
904
- function ppl_display_hand_links($hand_links) {
905
- ?>
906
- <tr valign="top">
907
- <th scope="row"><label for="hand_links"><?php _e('Look for manual links in custom field?', 'post_plugin_library') ?></label></th>
908
- <td>
909
- <select name="hand_links" id="hand_links">
910
- <option <?php if($hand_links == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
911
- <option <?php if($hand_links == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
912
- </select>
913
- </td>
914
- </tr>
915
- <?php
916
- }
917
-
918
- // now for recent_comments
919
-
920
- function ppl_display_show_type($show_type) {
921
- ?>
922
- <tr valign="top">
923
- <th scope="row" title=""><label for="show_type"><?php _e('Type of comment to show:', 'post_plugin_library') ?></label></th>
924
- <td>
925
- <select name="show_type" id="show_type">
926
- <option <?php if($show_type == 'all') { echo 'selected="selected"'; } ?> value="all">All kinds of comment</option>
927
- <option <?php if($show_type == 'comments') { echo 'selected="selected"'; } ?> value="comments">Just plain comments</option>
928
- <option <?php if($show_type == 'trackbacks') { echo 'selected="selected"'; } ?> value="trackbacks">Just trackbacks and pingbacks</option>
929
- </select>
930
- </td>
931
- </tr>
932
- <?php
933
- }
934
-
935
- function ppl_display_group_by($group_by) {
936
- ?>
937
- <tr valign="top">
938
- <th scope="row" title=""><?php _e('Type of grouping:', 'post_plugin_library') ?></th>
939
- <td>
940
- <select name="group_by" id="group_by">
941
- <option <?php if($group_by == 'post') { echo 'selected="selected"'; } ?> value="post">By Post</option>
942
- <option <?php if($group_by == 'none') { echo 'selected="selected"'; } ?> value="none">Ungrouped</option>
943
- <option <?php if($group_by == 'author') { echo 'selected="selected"'; } ?> value="author">By Commenter</option>
944
- </select>
945
- (overrides the sort criteria above)
946
- </td>
947
- </tr>
948
- <?php
949
- }
950
-
951
- function ppl_display_group_template($group_template) {
952
- ?>
953
- <tr valign="top">
954
- <th scope="row"><label for="group_template"><?php _e('Group title template:', 'post_plugin_library') ?></label></th>
955
- <td><textarea name="group_template" id="group_template" rows="4" cols="38"><?php echo htmlspecialchars(stripslashes($group_template)); ?></textarea></td>
956
- </tr>
957
- <?php
958
- }
959
-
960
- function ppl_display_no_author_comments($no_author_comments) {
961
- ?>
962
- <tr valign="top">
963
- <th scope="row"><label for="no_author_comments"><?php _e('Omit comments by the post author?', 'post_plugin_library') ?></label></th>
964
- <td>
965
- <select name="no_author_comments" id="no_author_comments">
966
- <option <?php if($no_author_comments == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
967
- <option <?php if($no_author_comments == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
968
- </select>
969
- </td>
970
- </tr>
971
- <?php
972
- }
973
-
974
- function ppl_display_no_user_comments($no_user_comments) {
975
- ?>
976
- <tr valign="top">
977
- <th scope="row"><label for="no_user_comments"><?php _e('Omit comments by registered users?', 'post_plugin_library') ?></label></th>
978
- <td>
979
- <select name="no_user_comments" id="no_user_comments">
980
- <option <?php if($no_user_comments == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
981
- <option <?php if($no_user_comments == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
982
- </select>
983
- </td>
984
- </tr>
985
- <?php
986
- }
987
-
988
- function ppl_display_date_modified($date_modified) {
989
- ?>
990
- <tr valign="top">
991
- <th scope="row"><?php _e('Order by date of last edit rather than date of creation?', 'post_plugin_library') ?></th>
992
- <td>
993
- <select name="date_modified" id="date_modified">
994
- <option <?php if($date_modified == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
995
- <option <?php if($date_modified == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
996
- </select>
997
- </td>
998
- </tr>
999
- <?php
1000
- }
1001
-
1002
- // 'borrowed', with adaptations, from Stephen Rider at http://striderweb.com/nerdaphernalia/
1003
- function ppl_get_plugin_data($plugin_file) {
1004
- // You can optionally pass a specific value to fetch, e.g. 'Version' -- but it's inefficient to do that multiple times
1005
- // As of WP 2.5.1: 'Name', 'Title', 'Description', 'Author', 'Version'
1006
- // As of WP 2.7-bleeding: 'Name', 'PluginURI', 'Description', 'Author', 'AuthorURI', 'Version', 'TextDomain', 'DomainPath'
1007
- if(!function_exists( 'get_plugin_data' ) ) require_once( ABSPATH . 'wp-admin/includes/plugin.php');
1008
- static $plugin_data;
1009
- if(!$plugin_data) {
1010
- $plugin_data = get_plugin_data($plugin_file);
1011
- if (!isset($plugin_data['Title'])) {
1012
- if ('' != $plugin_data['PluginURI'] && '' != $plugin_data['Name']) {
1013
- $plugin_data['Title'] = '<a href="' . $plugin_data['PluginURI'] . '" title="'. __('Visit plugin homepage', 'post-plugin-library') . '">' . $plugin_data['Name'] . '</a>';
1014
- } else {
1015
- $plugin_data['Title'] = $name;
1016
- }
1017
- }
1018
- }
1019
- return $plugin_data;
1020
- }
1021
-
1022
- function ppl_admin_footer($plugin_file, $donate_key='') {
1023
- /*$plugin_data = ppl_get_plugin_data($plugin_file);
1024
- $output = array();
1025
- $output[] = $plugin_data['Title'] . ' plugin';
1026
- $output[] = 'Version ' . $plugin_data['Version'];
1027
- $output[] = 'by ' . $plugin_data['Author'];
1028
- if ($donate_key) {
1029
- $donate_url = 'http://rmarsh.com/donate/' . $donate_key . '/';
1030
- // random shades of red, orange and yellow to attract attention -- subtly I hope
1031
- $colour = '#ff' . dechex(mt_rand(0, 255)) . '00';
1032
- $output[] = '<a href="' . $donate_url . '" style="font-weight: bold;color: '.$colour.';" rel="nofollow" title="If you like ' . $plugin_data['Name'] . ' plugin why not make a tiny/small/large donation towards its upkeep">All donations welcomed!</a>';
1033
- }
1034
- echo implode(' | ', $output) . '<br />';
1035
- */
1036
- }
 
 
1
+ <?php
2
+
3
+ /*
4
+ Library for the Recent Posts, Random Posts, Recent Comments, and Similar Posts plugins
5
+ -- provides the admin routines which the plugins share
6
+ */
7
+
8
+ define('ACF_LIBRARY', true);
9
+
10
+ function ppl_options_from_post($options, $args) {
11
+ foreach ($args as $arg) {
12
+ switch ($arg) {
13
+ case 'limit':
14
+ case 'skip':
15
+ $options[$arg] = ppl_check_cardinal($_POST[$arg]);
16
+ break;
17
+ case 'excluded_cats':
18
+ case 'included_cats':
19
+ if (isset($_POST[$arg])) {
20
+ // get the subcategories too
21
+ if (function_exists('get_term_children')) {
22
+ $catarray = $_POST[$arg];
23
+ foreach ($catarray as $cat) {
24
+ $catarray = array_merge($catarray, get_term_children($cat, 'category'));
25
+ }
26
+ $_POST[$arg] = array_unique($catarray);
27
+ }
28
+ $options[$arg] = implode(',', $_POST[$arg]);
29
+ } else {
30
+ $options[$arg] = '';
31
+ }
32
+ break;
33
+ case 'excluded_authors':
34
+ case 'included_authors':
35
+ if (isset($_POST[$arg])) {
36
+ $options[$arg] = implode(',', $_POST[$arg]);
37
+ } else {
38
+ $options[$arg] = '';
39
+ }
40
+ break;
41
+ case 'excluded_posts':
42
+ case 'included_posts':
43
+ $check = explode(',', rtrim($_POST[$arg]));
44
+ $ids = array();
45
+ foreach ($check as $id) {
46
+ $id = ppl_check_cardinal($id);
47
+ if ($id !== 0) $ids[] = $id;
48
+ }
49
+ $options[$arg] = implode(',', array_unique($ids));
50
+ break;
51
+ case 'stripcodes':
52
+ $st = explode("\n", trim($_POST['starttags']));
53
+ $se = explode("\n", trim($_POST['endtags']));
54
+ if (count($st) != count($se)) {
55
+ $options['stripcodes'] = array(array());
56
+ } else {
57
+ $num = count($st);
58
+ for ($i = 0; $i < $num; $i++) {
59
+ $options['stripcodes'][$i]['start'] = $st[$i];
60
+ $options['stripcodes'][$i]['end'] = $se[$i];
61
+ }
62
+ }
63
+ break;
64
+ case 'age':
65
+ $options['age']['direction'] = $_POST['age-direction'];
66
+ $options['age']['length'] = ppl_check_cardinal($_POST['age-length']);
67
+ $options['age']['duration'] = $_POST['age-duration'];
68
+ break;
69
+ case 'custom':
70
+ $options['custom']['key'] = $_POST['custom-key'];
71
+ $options['custom']['op'] = $_POST['custom-op'];
72
+ $options['custom']['value'] = $_POST['custom-value'];
73
+ break;
74
+ case 'sort':
75
+ $options['sort']['by1'] = $_POST['sort-by1'];
76
+ $options['sort']['order1'] = $_POST['sort-order1'];
77
+ if ($options['sort']['order1'] === 'SORT_ASC') $options['sort']['order1'] = SORT_ASC; else $options['sort']['order1'] = SORT_DESC;
78
+ $options['sort']['case1'] = $_POST['sort-case1'];
79
+ $options['sort']['by2'] = $_POST['sort-by2'];
80
+ $options['sort']['order2'] = $_POST['sort-order2'];
81
+ if ($options['sort']['order2'] === 'SORT_ASC') $options['sort']['order2'] = SORT_ASC; else $options['sort']['order2'] = SORT_DESC;
82
+ $options['sort']['case2'] = $_POST['sort-case2'];
83
+ if ($options['sort']['by1'] === '') {
84
+ $options['sort']['order1'] = SORT_ASC;
85
+ $options['sort']['case1'] = 'false';
86
+ $options['sort']['by2'] = '';
87
+ }
88
+ if ($options['sort']['by2'] === '') {
89
+ $options['sort']['order2'] = SORT_ASC;
90
+ $options['sort']['case2'] = 'false';
91
+ }
92
+ break;
93
+ case 'status':
94
+ unset($options['status']);
95
+ $options['status']['publish'] = $_POST['status-publish'];
96
+ $options['status']['private'] = $_POST['status-private'];
97
+ $options['status']['draft'] = $_POST['status-draft'];
98
+ $options['status']['future'] = $_POST['status-future'];
99
+ break;
100
+ case 'num_terms':
101
+ $options['num_terms'] = $_POST['num_terms'];
102
+ if ($options['num_terms'] < 1) $options['num_terms'] = 20;
103
+ break;
104
+ default:
105
+ $options[$arg] = isset( $_POST[ $arg ] ) ? trim( $_POST[ $arg ] ) : '';
106
+ }
107
+ }
108
+ return $options;
109
+ }
110
+
111
+ function ppl_check_cardinal($string) {
112
+ $value = intval($string);
113
+ return ($value > 0) ? $value : 0;
114
+ }
115
+
116
+ function ppl_display_available_tags($plugin_name) {
117
+ ?>
118
+ <h3><?php _e('Available Tags', 'post_plugin_library'); ?></h3>
119
+ <ul style="list-style-type: none;">
120
+ <li title="">{author}</li>
121
+ <li title="">{authorurl}</li>
122
+ <li title="">{categoryid}</li>
123
+ <li title="">{categorylinks}</li>
124
+ <li title="">{categorynames}</li>
125
+ <li title="">{commentcount}</li>
126
+ <li title="">{custom}</li>
127
+ <li title="">{date}</li>
128
+ <li title="">{dateedited}</li>
129
+ <li title="">{excerpt}</li>
130
+ <li title="">{fullpost}</li>
131
+ <li title="">{gravatar}</li>
132
+ <li title="">{if}</li>
133
+ <li title="">{image}</li>
134
+ <li title="">{imagealt}</li>
135
+ <li title="">{imagesrc}</li>
136
+ <li title="">{link}</li>
137
+ <li title="">{php}</li>
138
+ <li title="">{postid}</li>
139
+ <li title="">{postviews}</li>
140
+ <?php if ($plugin_name === 'similar-posts') { ?>
141
+ <li title="">{score}</li>
142
+ <?php } ?>
143
+ <li title="">{snippet}</li>
144
+ <li title="">{tags}</li>
145
+ <li title="">{taglinks}</li>
146
+ <li title="">{title}</li>
147
+ <li title="">{time}</li>
148
+ <li title="">{timeedited}</li>
149
+ <li title="">{totalpages}</li>
150
+ <li title="">{totalposts}</li>
151
+ <li title="">{url}</li>
152
+ </ul>
153
+ <?php
154
+ }
155
+
156
+ function ppl_display_available_comment_tags() {
157
+ ?>
158
+ <ul style="list-style-type: none;">
159
+ <li title="">{commentexcerpt}</li>
160
+ <li title="">{commentsnippet}</li>
161
+ <li title="">{commentdate}</li>
162
+ <li title="">{commenttime}</li>
163
+ <li title="">{commentdategmt}</li>
164
+ <li title="">{commenttimegmt}</li>
165
+ <li title="">{commenter}</li>
166
+ <li title="">{commenterip}</li>
167
+ <li title="">{commenterurl}</li>
168
+ <li title="">{commenterlink}</li>
169
+ <li title="">{commenturl}</li>
170
+ <li title="">{commentpopupurl}</li>
171
+ <li title="">{commentlink}</li>
172
+ <li title="">{commentlink2}</li>
173
+ </ul>
174
+ <?php
175
+ }
176
+
177
+ /*
178
+
179
+ inserts a form button to submit a bug report to my web site
180
+
181
+ */
182
+ function get_plugin_version($prefix) {
183
+ $plugin_version = str_replace('-', '_', $prefix) . '_version';
184
+ global $$plugin_version;
185
+ return ${$plugin_version};
186
+ }
187
+
188
+
189
+
190
+ /*
191
+
192
+ inserts a form button to completely remove the plugin and all its options etc.
193
+
194
+ */
195
+
196
+ function ppl_confirm_eradicate() {
197
+ return (isset($_POST['eradicate-check']) && 'yes'===$_POST['eradicate-check']);
198
+ }
199
+
200
+ function ppl_deactivate_plugin($plugin_file) {
201
+ $current = get_option('active_plugins');
202
+ $plugin_file = substr($plugin_file, strlen(WP_PLUGIN_DIR)+1);
203
+ $plugin_file = str_replace('\\', '/', $plugin_file);
204
+ if (in_array($plugin_file, $current)) {
205
+ array_splice($current, array_search($plugin_file, $current), 1);
206
+ update_option('active_plugins', $current);
207
+ }
208
+ }
209
+
210
+
211
+ /*
212
+
213
+ For the display of the option pages
214
+
215
+ */
216
+
217
+ function ppl_display_limit($limit) {
218
+ ?>
219
+ <tr valign="top">
220
+ <th scope="row"><label for="limit"><?php _e('Number of posts to show:', 'post_plugin_library') ?></label></th>
221
+ <td><input name="limit" type="number" id="limit" style="width: 60px;" value="<?php echo $limit; ?>" size="2" /></td>
222
+ </tr>
223
+ <?php
224
+ }
225
+
226
+ function ppl_display_unique($unique) {
227
+ ?>
228
+ <tr valign="top">
229
+ <th scope="row"><label for="unique"><?php _e('Show just one comment per post?', 'post_plugin_library') ?></label></th>
230
+ <td>
231
+ <select name="unique" id="unique" >
232
+ <option <?php if($unique == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
233
+ <option <?php if($unique == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
234
+ </select>
235
+ </td>
236
+ </tr>
237
+ <?php
238
+ }
239
+
240
+ function ppl_display_skip($skip) {
241
+ ?>
242
+ <tr valign="top">
243
+ <th scope="row"><label for="skip"><?php _e('Number of posts to skip:', 'post_plugin_library') ?></label></th>
244
+ <td><input name="skip" type="number" id="skip" style="width: 60px;" value="<?php echo $skip; ?>" size="2" /></td>
245
+ </tr>
246
+ <?php
247
+ }
248
+
249
+ function ppl_display_omit_current_post($omit_current_post) {
250
+ ?>
251
+ <tr valign="top">
252
+ <th scope="row"><label for="omit_current_post"><?php _e('Omit the current post?', 'post_plugin_library') ?></label></th>
253
+ <td>
254
+ <select name="omit_current_post" id="omit_current_post" >
255
+ <option <?php if($omit_current_post == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
256
+ <option <?php if($omit_current_post == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
257
+ </select>
258
+ </td>
259
+ </tr>
260
+ <?php
261
+ }
262
+
263
+ function ppl_display_just_current_post($just_current_post) {
264
+ ?>
265
+ <tr valign="top">
266
+ <th scope="row"><label for="just_current_post"><?php _e('Show just the current post?', 'post_plugin_library') ?></label></th>
267
+ <td>
268
+ <select name="just_current_post" id="just_current_post" >
269
+ <option <?php if($just_current_post == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
270
+ <option <?php if($just_current_post == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
271
+ </select>
272
+ </td>
273
+ </tr>
274
+ <?php
275
+ }
276
+
277
+ function ppl_display_show_private($show_private) {
278
+ ?>
279
+ <tr valign="top">
280
+ <th scope="row"><label for="show_private"><?php _e('Show password-protected posts?', 'post_plugin_library') ?></label></th>
281
+ <td>
282
+ <select name="show_private" id="show_private">
283
+ <option <?php if($show_private == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
284
+ <option <?php if($show_private == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
285
+ </select>
286
+ </td>
287
+ </tr>
288
+ <?php
289
+ }
290
+
291
+ function ppl_display_show_pages($show_pages) {
292
+ ?>
293
+ <tr valign="top">
294
+ <th scope="row"><label for="show_pages"><?php _e('Show static pages?', 'post_plugin_library') ?></label></th>
295
+ <td>
296
+ <select name="show_pages" id="show_pages">
297
+ <option <?php if($show_pages == 'false') { echo 'selected="selected"'; } ?> value="false">No pages, just posts</option>
298
+ <option <?php if($show_pages == 'true') { echo 'selected="selected"'; } ?> value="true">Both pages and posts</option>
299
+ <option <?php if($show_pages == 'but') { echo 'selected="selected"'; } ?> value="but">Pages but no posts</option>
300
+ </select>
301
+ </td>
302
+ </tr>
303
+ <?php
304
+ }
305
+
306
+ function ppl_display_show_attachments($show_attachments) {
307
+ ?>
308
+ <tr valign="top">
309
+ <th scope="row"><label for="show_attachments"><?php _e('Show attachments?', 'post_plugin_library') ?></label></th>
310
+ <td>
311
+ <select name="show_attachments" id="show_attachments">
312
+ <option <?php if($show_attachments == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
313
+ <option <?php if($show_attachments == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
314
+ </select>
315
+ </td>
316
+ </tr>
317
+ <?php
318
+ }
319
+
320
+ function ppl_display_match_author($match_author) {
321
+ ?>
322
+ <tr valign="top">
323
+ <th scope="row"><label for="match_author"><?php _e('Match the current post\'s author?', 'post_plugin_library') ?></label></th>
324
+ <td>
325
+ <select name="match_author" id="match_author">
326
+ <option <?php if($match_author == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
327
+ <option <?php if($match_author == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
328
+ </select>
329
+ </td>
330
+ </tr>
331
+ <?php
332
+ }
333
+
334
+ function ppl_display_match_cat($match_cat) {
335
+ ?>
336
+ <tr valign="top">
337
+ <th scope="row"><label for="match_cat"><?php _e('Match the current post\'s category?', 'post_plugin_library') ?></label></th>
338
+ <td>
339
+ <select name="match_cat" id="match_cat">
340
+ <option <?php if($match_cat == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
341
+ <option <?php if($match_cat == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
342
+ </select>
343
+ </td>
344
+ </tr>
345
+ <?php
346
+ }
347
+
348
+ function ppl_display_match_tags($match_tags) {
349
+ global $wp_version;
350
+ ?>
351
+ <tr valign="top">
352
+ <th scope="row"><label for="match_tags"><?php _e('Match the current post\'s tags?', 'post_plugin_library') ?></label></th>
353
+ <td>
354
+ <select name="match_tags" id="match_tags" <?php if ($wp_version < 2.3) echo 'disabled="true"'; ?> >
355
+ <option <?php if($match_tags == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
356
+ <option <?php if($match_tags == 'any') { echo 'selected="selected"'; } ?> value="any">Any tag</option>
357
+ <option <?php if($match_tags == 'all') { echo 'selected="selected"'; } ?> value="all">Every tag</option>
358
+ </select>
359
+ </td>
360
+ </tr>
361
+ <?php
362
+ }
363
+
364
+ function ppl_display_none_text($none_text) {
365
+ ?>
366
+ <tr valign="top">
367
+ <th scope="row"><label for="none_text"><?php _e('Default display if no matches:', 'post_plugin_library') ?></label></th>
368
+ <td><input name="none_text" type="text" id="none_text" value="<?php echo htmlspecialchars(stripslashes($none_text)); ?>" size="40" /></td>
369
+ </tr>
370
+ <?php
371
+ }
372
+
373
+ function ppl_display_no_text($no_text) {
374
+ ?>
375
+ <tr valign="top">
376
+ <th scope="row"><label for="no_text"><?php _e('Show nothing if no matches?', 'post_plugin_library') ?></label></th>
377
+ <td>
378
+ <select name="no_text" id="no_text">
379
+ <option <?php if($no_text == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
380
+ <option <?php if($no_text == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
381
+ </select>
382
+ </td>
383
+ </tr>
384
+ <?php
385
+ }
386
+
387
+ function ppl_display_prefix($prefix) {
388
+ ?>
389
+ <tr valign="top">
390
+ <th scope="row"><label for="prefix"><?php _e('Text and codes before the list:', 'post_plugin_library') ?></label></th>
391
+ <td><input name="prefix" type="text" id="prefix" value="<?php echo htmlspecialchars(stripslashes($prefix)); ?>" size="40" /></td>
392
+ </tr>
393
+ <?php
394
+ }
395
+
396
+ function ppl_display_suffix($suffix) {
397
+ ?>
398
+ <tr valign="top">
399
+ <th scope="row"><label for="suffix"><?php _e('Text and codes after the list:', 'post_plugin_library') ?></label></th>
400
+ <td><input name="suffix" type="text" id="suffix" value="<?php echo htmlspecialchars(stripslashes($suffix)); ?>" size="40" /></td>
401
+ </tr>
402
+ <?php
403
+ }
404
+
405
+ function ppl_display_output_template($output_template) {
406
+ ?>
407
+ <tr valign="top">
408
+ <th scope="row"><label for="output_template"><?php _e('Output template:', 'post_plugin_library') ?></label></th>
409
+ <td><textarea name="output_template" id="output_template" rows="4" cols="38"><?php echo htmlspecialchars(stripslashes($output_template)); ?></textarea></td>
410
+ </tr>
411
+ <?php
412
+ }
413
+
414
+ function ppl_display_divider($divider) {
415
+ ?>
416
+ <tr valign="top">
417
+ <th scope="row"><label for="divider"><?php _e('Text and codes between items:', 'post_plugin_library') ?></label></th>
418
+ <td><input name="divider" type="text" id="divider" value="<?php echo $divider; ?>" size="40" /></td>
419
+ </tr>
420
+ <?php
421
+ }
422
+
423
+ function ppl_display_tag_str($tag_str) {
424
+ global $wp_version;
425
+ ?>
426
+ <tr valign="top">
427
+ <th scope="row"><label for="tag_str"><?php _e('Match posts with tags:<br />(a,b matches posts with either tag, a+b only matches posts with both tags)', 'post_plugin_library') ?></label></th>
428
+ <td><input name="tag_str" type="text" id="tag_str" value="<?php echo $tag_str; ?>" <?php if ($wp_version < 2.3) echo 'disabled="true"'; ?> size="40" /></td>
429
+ </tr>
430
+ <?php
431
+ }
432
+
433
+ function ppl_display_excluded_posts($excluded_posts) {
434
+ ?>
435
+ <tr valign="top">
436
+ <th scope="row"><label for="excluded_posts"><?php _e('Posts to exclude:', 'post_plugin_library') ?></label></th>
437
+ <td><input name="excluded_posts" type="text" id="excluded_posts" value="<?php echo $excluded_posts; ?>" size="40" /> <?php _e('comma-separated IDs', 'post_plugin_library'); ?></td>
438
+ </tr>
439
+ <?php
440
+ }
441
+
442
+ function ppl_display_included_posts($included_posts) {
443
+ ?>
444
+ <tr valign="top">
445
+ <th scope="row"><label for="included_posts"><?php _e('Posts to include:', 'post_plugin_library') ?></label></th>
446
+ <td><input name="included_posts" type="text" id="included_posts" value="<?php echo $included_posts; ?>" size="40" /> <?php _e('comma-separated IDs', 'post_plugin_library'); ?></td>
447
+ </tr>
448
+ <?php
449
+ }
450
+
451
+ function ppl_display_authors($excluded_authors, $included_authors) {
452
+ global $wpdb;
453
+ ?>
454
+ <tr valign="top">
455
+ <th scope="row"><?php _e('Authors to exclude/include:', 'post_plugin_library') ?></th>
456
+ <td>
457
+ <table class="similarposts-inner-table">
458
+ <?php
459
+ $users = $wpdb->get_results("SELECT ID, user_login FROM $wpdb->users ORDER BY user_login");
460
+ if ($users) {
461
+ $excluded = explode(',', $excluded_authors);
462
+ $included = explode(',', $included_authors);
463
+ echo "\n\t<tr valign=\"top\"><td><strong>Author</strong></td><td><strong>Exclude</strong></td><td><strong>Include</strong></td></tr>";
464
+ foreach ($users as $user) {
465
+ if (false === in_array($user->ID, $excluded)) {
466
+ $ex_ischecked = '';
467
+ } else {
468
+ $ex_ischecked = 'checked';
469
+ }
470
+ if (false === in_array($user->ID, $included)) {
471
+ $in_ischecked = '';
472
+ } else {
473
+ $in_ischecked = 'checked';
474
+ }
475
+ echo "\n\t<tr valign=\"top\"><td>$user->user_login</td><td><input type=\"checkbox\" name=\"excluded_authors[]\" value=\"$user->ID\" $ex_ischecked /></td><td><input type=\"checkbox\" name=\"included_authors[]\" value=\"$user->ID\" $in_ischecked /></td></tr>";
476
+ }
477
+ }
478
+ ?>
479
+ </table>
480
+ </td>
481
+ </tr>
482
+ <?php
483
+ }
484
+
485
+ function ppl_display_cats($excluded_cats, $included_cats) {
486
+ global $wpdb;
487
+ ?>
488
+ <tr valign="top">
489
+ <th scope="row"><?php _e('Categories to exclude/include:', 'post_plugin_library') ?></th>
490
+ <td>
491
+ <table class="similarposts-inner-table">
492
+ <?php
493
+ if (function_exists("get_categories")) {
494
+ $categories = get_categories();//('&hide_empty=1');
495
+ } else {
496
+ //$categories = $wpdb->get_results("SELECT * FROM $wpdb->categories WHERE category_count <> 0 ORDER BY cat_name");
497
+ $categories = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY cat_name");
498
+ }
499
+ if ($categories) {
500
+ echo "\n\t<tr valign=\"top\"><td><strong>Category</strong></td><td><strong>Exclude</strong></td><td><strong>Include</strong></td></tr>";
501
+ $excluded = explode(',', $excluded_cats);
502
+ $included = explode(',', $included_cats);
503
+ $level = 0;
504
+ $cats_added = array();
505
+ $last_parent = 0;
506
+ $cat_parent = 0;
507
+ foreach ($categories as $category) {
508
+ $category->cat_name = esc_html($category->cat_name);
509
+ if (false === in_array($category->cat_ID, $excluded)) {
510
+ $ex_ischecked = '';
511
+ } else {
512
+ $ex_ischecked = 'checked';
513
+ }
514
+ if (false === in_array($category->cat_ID, $included)) {
515
+ $in_ischecked = '';
516
+ } else {
517
+ $in_ischecked = 'checked';
518
+ }
519
+ $last_parent = $cat_parent;
520
+ $cat_parent = $category->category_parent;
521
+ if ($cat_parent == 0) {
522
+ $level = 0;
523
+ } elseif ($last_parent != $cat_parent) {
524
+ if (in_array($cat_parent, $cats_added)) {
525
+ $level = $level - 1;
526
+ } else {
527
+ $level = $level + 1;
528
+ }
529
+ $cats_added[] = $cat_parent;
530
+ }
531
+ $pad = str_repeat('&nbsp;', 3*$level);
532
+ echo "\n\t<tr valign=\"top\"><td>$pad$category->cat_name</td><td><input type=\"checkbox\" name=\"excluded_cats[]\" value=\"$category->cat_ID\" $ex_ischecked /></td><td><input type=\"checkbox\" name=\"included_cats[]\" value=\"$category->cat_ID\" $in_ischecked /></td></tr>";
533
+ }
534
+ }
535
+ ?>
536
+ </table>
537
+ </td>
538
+ </tr>
539
+ <?php
540
+ }
541
+
542
+ function ppl_display_stripcodes($stripcodes) {
543
+ ?>
544
+ <tr valign="top">
545
+ <th scope="row"><?php _e('Other plugins\' tags to remove from snippet:', 'post_plugin_library') ?></th>
546
+ <td>
547
+ <table>
548
+ <tr><td style="border-bottom-width: 0"><label for="starttags"><?php _e('opening', 'post_plugin_library') ?></label></td><td style="border-bottom-width: 0"><label for="endtags"><?php _e('closing', 'post_plugin_library') ?></label></td></tr>
549
+ <tr valign="top"><td style="border-bottom-width: 0">
550
+ <textarea name="starttags" id="starttags" rows="4" cols="20"><?php
551
+ foreach ($stripcodes as $tag) {
552
+ if(array_key_exists('start',$tag)){
553
+ echo htmlspecialchars(stripslashes($tag['start']))."\n";
554
+ }
555
+ }
556
+ ?></textarea></td><td style="border-bottom-width: 0">
557
+
558
+ <textarea name="endtags" id="endtags" rows="4" cols="20"><?php
559
+ foreach ($stripcodes as $tag) {
560
+ if(array_key_exists('end',$tag)){
561
+ echo htmlspecialchars(stripslashes($tag['end']))."\n";
562
+ }
563
+ }
564
+ ?></textarea>
565
+ </td></tr>
566
+ </table>
567
+ </td>
568
+ </tr>
569
+ <?php
570
+ }
571
+
572
+ function ppl_display_age($age) {
573
+ ?>
574
+ <tr valign="top">
575
+ <th scope="row"><label for="age-direction"><?php _e('Ignore posts:', 'post_plugin_library') ?></label></th>
576
+ <td>
577
+
578
+ <select name="age-direction" id="age-direction">
579
+ <option <?php if($age['direction'] == 'before') { echo 'selected="selected"'; } ?> value="before">less than</option>
580
+ <option <?php if($age['direction'] == 'after') { echo 'selected="selected"'; } ?> value="after">more than</option>
581
+ <option <?php if($age['direction'] == 'none') { echo 'selected="selected"'; } ?> value="none">-----</option>
582
+ </select>
583
+ <input style="vertical-align: middle; width: 60px;" name="age-length" type="number" id="age-length" value="<?php echo $age['length']; ?>" size="4" />
584
+
585
+ <select name="age-duration" id="age-duration">
586
+ <option <?php if($age['duration'] == 'day') { echo 'selected="selected"'; } ?> value="day">day(s)</option>
587
+ <option <?php if($age['duration'] == 'month') { echo 'selected="selected"'; } ?> value="month">month(s)</option>
588
+ <option <?php if($age['duration'] == 'year') { echo 'selected="selected"'; } ?> value="year">year(s)</option>
589
+ </select>
590
+ old
591
+
592
+ </td>
593
+ </tr>
594
+ <?php
595
+ }
596
+
597
+ function ppl_display_status($status) {
598
+ ?>
599
+ <tr valign="top">
600
+ <th scope="row"><?php _e('Display posts that are:', 'post_plugin_library') ?></th>
601
+ <td>
602
+
603
+ <label for="status-publish">Published</label>
604
+ <select name="status-publish" id="status-publish" <?php if (!function_exists('get_post_type')) echo 'disabled="true"'; ?>>
605
+ <option <?php if($status['publish'] == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
606
+ <option <?php if($status['publish'] == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
607
+ </select>
608
+
609
+ <label for="status-private">Private</label>
610
+ <select name="status-private" id="status-private" <?php if (!function_exists('get_post_type')) echo 'disabled="true"'; ?>>
611
+ <option <?php if($status['private'] == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
612
+ <option <?php if($status['private'] == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
613
+ </select>
614
+
615
+ <label for="status-draft">Draft</label>
616
+ <select name="status-draft" id="status-draft" <?php if (!function_exists('get_post_type')) echo 'disabled="true"'; ?>>
617
+ <option <?php if($status['draft'] == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
618
+ <option <?php if($status['draft'] == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
619
+ </select>
620
+
621
+ <label for="status-future">Future</label>
622
+ <select name="status-future" id="status-future" <?php if (!function_exists('get_post_type')) echo 'disabled="true"'; ?>>
623
+ <option <?php if($status['future'] == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
624
+ <option <?php if($status['future'] == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
625
+ </select>
626
+
627
+ </td>
628
+ </tr>
629
+ <?php
630
+ }
631
+
632
+ function ppl_display_custom($custom) {
633
+ ?>
634
+ <tr valign="top">
635
+ <th scope="row"><?php _e('Match posts by custom field:', 'post_plugin_library') ?></th>
636
+ <td>
637
+ <table>
638
+ <tr><td style="border-bottom-width: 0">Field Name</td><td style="border-bottom-width: 0"></td><td style="border-bottom-width: 0">Field Value</td></tr>
639
+ <tr>
640
+ <td style="border-bottom-width: 0"><input name="custom-key" type="text" id="custom-key" value="<?php echo $custom['key']; ?>" size="20" /></td>
641
+ <td style="border-bottom-width: 0">
642
+ <select name="custom-op" id="custom-op">
643
+ <option <?php if($custom['op'] == '=') { echo 'selected="selected"'; } ?> value="=">=</option>
644
+ <option <?php if($custom['op'] == '!=') { echo 'selected="selected"'; } ?> value="!=">!=</option>
645
+ <option <?php if($custom['op'] == '>') { echo 'selected="selected"'; } ?> value=">">></option>
646
+ <option <?php if($custom['op'] == '>=') { echo 'selected="selected"'; } ?> value=">=">>=</option>
647
+ <option <?php if($custom['op'] == '<') { echo 'selected="selected"'; } ?> value="<"><</option>
648
+ <option <?php if($custom['op'] == '<=') { echo 'selected="selected"'; } ?> value="<="><=</option>
649
+ <option <?php if($custom['op'] == 'LIKE') { echo 'selected="selected"'; } ?> value="LIKE">LIKE</option>
650
+ <option <?php if($custom['op'] == 'NOT LIKE') { echo 'selected="selected"'; } ?> value="NOT LIKE">NOT LIKE</option>
651
+ <option <?php if($custom['op'] == 'REGEXP') { echo 'selected="selected"'; } ?> value="REGEXP">REGEXP</option>
652
+ <option <?php if($custom['op'] == 'EXISTS') { echo 'selected="selected"'; } ?> value="EXISTS">EXISTS</option>
653
+ </select>
654
+ </td>
655
+ <td style="border-bottom-width: 0"><input name="custom-value" type="text" id="custom-value" value="<?php echo $custom['value']; ?>" size="20" /></td>
656
+ </tr>
657
+ </table>
658
+ </td>
659
+ </tr>
660
+ <?php
661
+ }
662
+
663
+ function ppl_display_append($options) {
664
+ ?>
665
+ <tr valign="top">
666
+ <th scope="row"><?php _e('Output after post:', 'post_plugin_library') ?></th>
667
+ <td>
668
+ <table>
669
+ <tr>
670
+ <td style="border-bottom-width: 0"><label for="append_on">Activate</label></td>
671
+ <td style="border-bottom-width: 0"><label for="append_priority">Priority</label></td>
672
+ <td style="border-bottom-width: 0"><label for="append_parameters">Parameters</label></td>
673
+ <?php if ( true === sp_is_user_allowed_to_add_php_code() ) { ?>
674
+ <td style="border-bottom-width: 0"><label for="append_condition">Condition</label></td></tr>
675
+ <?php } ?>
676
+ <tr>
677
+ <td style="border-bottom-width: 0">
678
+ <select name="append_on" id="append_on">
679
+ <option <?php if($options['append_on'] == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
680
+ <option <?php if($options['append_on'] == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
681
+ </select>
682
+ </td>
683
+ <td style="border-bottom-width: 0"><input name="append_priority" type="number" id="append_priority" style="width: 60px;" value="<?php echo $options['append_priority']; ?>" size="3" /></td>
684
+ <td style="border-bottom-width: 0"><textarea name="append_parameters" id="append_parameters" rows="4" cols="38"><?php echo htmlspecialchars(stripslashes($options['append_parameters'])); ?></textarea></td>
685
+ <?php if ( true === sp_is_user_allowed_to_add_php_code() ) { ?>
686
+ <td style="border-bottom-width: 0"><textarea readonly name="append_condition" id="append_condition" rows="4" cols="20"><?php echo htmlspecialchars(stripslashes($options['append_condition'])); ?></textarea></td>
687
+ <?php } ?>
688
+ </tr></table>
689
+ </td>
690
+ </tr>
691
+ <?php
692
+ }
693
+
694
+ function ppl_display_feed($options) {
695
+ ?>
696
+ <tr valign="top">
697
+ <th scope="row"><?php _e('Output in RSS feeds:', 'post_plugin_library') ?></th>
698
+ <td>
699
+ <table>
700
+ <tr><td style="border-bottom-width: 0"><label for="feed_on">Activate</label></td><td style="border-bottom-width: 0"><label for="feed_priority">Priority</label></td><td style="border-bottom-width: 0"><label for="feed_parameters">Parameters</label></td></tr>
701
+ <tr>
702
+ <td style="border-bottom-width: 0">
703
+ <select name="feed_on" id="feed_on">
704
+ <option <?php if($options['feed_on'] == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
705
+ <option <?php if($options['feed_on'] == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
706
+ </select>
707
+ </td>
708
+ <td style="border-bottom-width: 0"><input name="feed_priority" type="number" id="feed_priority" style="width: 60px;" value="<?php echo $options['feed_priority']; ?>" size="3" /></td>
709
+ <td style="border-bottom-width: 0"><textarea name="feed_parameters" id="feed_parameters" rows="4" cols="38"><?php echo htmlspecialchars(stripslashes($options['feed_parameters'])); ?></textarea></td>
710
+ </tr></table>
711
+ </td>
712
+ </tr>
713
+ <?php
714
+ }
715
+
716
+ function ppl_display_widget($options) {
717
+ ?>
718
+ <tr valign="top">
719
+ <th scope="row"><?php _e('Output in widget:', 'post_plugin_library') ?></th>
720
+ <td>
721
+ <table>
722
+ <tr>
723
+ <td style="border-bottom-width: 0"></td>
724
+ <td style="border-bottom-width: 0"></td>
725
+ <td style="border-bottom-width: 0"><label for="widget_parameters">Parameters</label></td>
726
+ <?php if ( true === sp_is_user_allowed_to_add_php_code() ) { ?>
727
+ <td style="border-bottom-width: 0"><label for="widget_condition">Condition</label></td>
728
+ <?php } ?>
729
+ </tr>
730
+ <tr>
731
+ <td style="border-bottom-width: 0;visibility: hidden;">
732
+ <select name="dummy" id="dummy1">
733
+ <option value="false">No</option>
734
+ <option value="true">Yes</option>
735
+ </select>
736
+ </td>
737
+ <td style="border-bottom-width: 0;visibility: hidden;"><input name="dummy2" type="text" id="dummy2" value="" size="3" /></td>
738
+ <td style="border-bottom-width: 0"><textarea name="widget_parameters" id="widget_parameters" rows="4" cols="38"><?php echo htmlspecialchars(stripslashes($options['widget_parameters'])); ?></textarea></td>
739
+ <?php if ( true === sp_is_user_allowed_to_add_php_code() ) { ?>
740
+ <td style="border-bottom-width: 0"><textarea readonly name="widget_condition" id="widget_condition" rows="4" cols="20"><?php echo htmlspecialchars(stripslashes($options['widget_condition'])); ?></textarea></td>
741
+ <?php } ?>
742
+ </tr></table>
743
+ </td>
744
+ </tr>
745
+ <?php
746
+ }
747
+
748
+ function ppl_display_feed_active($feed_active) {
749
+ ?>
750
+ <tr valign="top">
751
+ <th scope="row"><label for="feed_active"><?php _e('Add Similar Posts to feeds? (DEPRECATED! This setting will be removed in the next major release - use the placement settings instead)', 'post_plugin_library') ?></label></th>
752
+ <td>
753
+ <select name="feed_active" id="feed_active">
754
+ <option <?php if($feed_active == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
755
+ <option <?php if($feed_active == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
756
+ </select>
757
+ </td>
758
+ </tr>
759
+ <?php
760
+ }
761
+
762
+ function ppl_display_content_filter($content_filter) {
763
+ ?>
764
+ <tr valign="top">
765
+ <th scope="row"><?php _e('Output in content:<br />(<em>via</em> special tags)', 'post_plugin_library') ?></th>
766
+ <td>
767
+ <table>
768
+ <tr><td style="border-bottom-width: 0"><label for="content_filter">Activate</label></td></tr>
769
+ <tr>
770
+ <td style="border-bottom-width: 0">
771
+ <select name="content_filter" id="content_filter">
772
+ <option <?php if($content_filter == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
773
+ <option <?php if($content_filter == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
774
+ </select>
775
+ </td>
776
+ </tr>
777
+ </table>
778
+ </td>
779
+ </tr>
780
+ <?php
781
+ }
782
+
783
+ function ppl_display_sort($sort) {
784
+ global $wpdb;
785
+ ?>
786
+ <tr valign="top">
787
+ <th scope="row"><?php _e('Sort Output By:<br />leave blank for default order', 'post_plugin_library') ?></th>
788
+ <td>
789
+ <table>
790
+ <tr><td style="border-bottom-width: 0"></td><td style="border-bottom-width: 0">Output Tag</td><td style="border-bottom-width: 0">Order</td><td style="border-bottom-width: 0">Case</td></tr>
791
+ <tr>
792
+ <td style="border-bottom-width: 0">first</td>
793
+ <td style="border-bottom-width: 0"><input name="sort-by1" type="text" id="sort-by1" value="<?php echo $sort['by1']; ?>" size="20" /></td>
794
+ <td style="border-bottom-width: 0">
795
+ <select name="sort-order1" id="sort-order1">
796
+ <option <?php if($sort['order1'] == SORT_ASC) { echo 'selected="selected"'; } ?> value="SORT_ASC">ascending</option>
797
+ <option <?php if($sort['order1'] == SORT_DESC) { echo 'selected="selected"'; } ?> value="SORT_DESC">descending</option>
798
+ </select>
799
+ </td>
800
+ <td style="border-bottom-width: 0">
801
+ <select name="sort-case1" id="sort-case1">
802
+ <option <?php if($sort['case1'] == 'false') { echo 'selected="selected"'; } ?> value="false">case-sensitive</option>
803
+ <option <?php if($sort['case1'] == 'true') { echo 'selected="selected"'; } ?> value="true">case-insensitive</option>
804
+ </select>
805
+ </td>
806
+ </tr>
807
+ <tr>
808
+ <td style="border-bottom-width: 0">then</td>
809
+ <td style="border-bottom-width: 0"><input name="sort-by2" type="text" id="sort-by2" value="<?php echo $sort['by2']; ?>" size="20" /></td>
810
+ <td style="border-bottom-width: 0">
811
+ <select name="sort-order2" id="sort-order2">
812
+ <option <?php if($sort['order2'] == SORT_ASC) { echo 'selected="selected"'; } ?> value="SORT_ASC">ascending</option>
813
+ <option <?php if($sort['order2'] == SORT_DESC) { echo 'selected="selected"'; } ?> value="SORT_DESC">descending</option>
814
+ </select>
815
+ </td>
816
+ <td style="border-bottom-width: 0">
817
+ <select name="sort-case2" id="sort-case2">
818
+ <option <?php if($sort['case2'] == 'false') { echo 'selected="selected"'; } ?> value="false">case-sensitive</option>
819
+ <option <?php if($sort['case2'] == 'true') { echo 'selected="selected"'; } ?> value="true">case-insensitive</option>
820
+ </select>
821
+ </td>
822
+ </tr>
823
+ </table>
824
+ </td>
825
+ </tr>
826
+ <?php
827
+ }
828
+
829
+ function ppl_display_orderby($options) {
830
+ global $wpdb;
831
+ $limit = 30;
832
+ $keys = $wpdb->get_col( "
833
+ SELECT meta_key
834
+ FROM $wpdb->postmeta
835
+ WHERE meta_key NOT LIKE '\_%'
836
+ GROUP BY meta_key
837
+ ORDER BY meta_id DESC
838
+ LIMIT $limit" );
839
+ $metaselect = "<select id='orderby' name='orderby'>\n\t<option value=''></option>";
840
+ if ( $keys ) {
841
+ natcasesort($keys);
842
+ foreach ( $keys as $key ) {
843
+ $key = esc_attr( $key );
844
+ if ($options['orderby'] == $key) {
845
+ $metaselect .= "\n\t<option selected='selected' value='$key'>$key</option>";
846
+ } else {
847
+ $metaselect .= "\n\t<option value='$key'>$key</option>";
848
+ }
849
+ }
850
+ $metaselect .= "</select>";
851
+ }
852
+
853
+ ?>
854
+ <tr valign="top">
855
+ <th scope="row"><?php _e('Select output by custom field:', 'post_plugin_library') ?></th>
856
+ <td>
857
+ <table>
858
+ <tr><td style="border-bottom-width: 0">Field</td><td style="border-bottom-width: 0">Order</td><td style="border-bottom-width: 0">Case</td></tr>
859
+ <tr>
860
+ <td style="border-bottom-width: 0">
861
+ <?php echo $metaselect; ?>
862
+ </td>
863
+ <td style="border-bottom-width: 0">
864
+ <select name="orderby_order" id="orderby_order">
865
+ <option <?php if($options['orderby_order'] == 'ASC') { echo 'selected="selected"'; } ?> value="ASC">ascending</option>
866
+ <option <?php if($options['orderby_order'] == 'DESC') { echo 'selected="selected"'; } ?> value="DESC">descending</option>
867
+ </select>
868
+ </td>
869
+ <td style="border-bottom-width: 0">
870
+ <select name="orderby_case" id="orderby_case">
871
+ <option <?php if($options['orderby_case'] == 'false') { echo 'selected="selected"'; } ?> value="false">case-sensitive</option>
872
+ <option <?php if($options['orderby_case'] == 'true') { echo 'selected="selected"'; } ?> value="true">case-insensitive</option>
873
+ <option <?php if($options['orderby_case'] == 'num') { echo 'selected="selected"'; } ?> value="num">numeric</option>
874
+ </select>
875
+ </td>
876
+ </tr>
877
+ </table>
878
+ </td>
879
+ </tr>
880
+ <?php
881
+ }
882
+
883
+ // now for similar_posts
884
+
885
+ function ppl_display_num_terms($num_terms) {
886
+ ?>
887
+ <tr valign="top">
888
+ <th scope="row"><label for="num_terms"><?php _e('Maximum number of words to use for match:', 'post_plugin_library') ?></label></th>
889
+ <td><input name="num_terms" type="number" id="num_terms" style="width: 60px;" value="<?php echo $num_terms; ?>" size="3" /></td>
890
+ </tr>
891
+ <?php
892
+ }
893
+
894
+ function ppl_display_term_extraction($term_extraction) {
895
+ ?>
896
+ <tr valign="top">
897
+ <th scope="row" title=""><label for="term_extraction"><?php _e('Extract terms to match by:', 'post_plugin_library') ?></label></th>
898
+ <td>
899
+ <select name="term_extraction" id="term_extraction">
900
+ <option <?php if($term_extraction == 'frequency') { echo 'selected="selected"'; } ?> value="frequency">Word Frequency</option>
901
+ <option <?php if($term_extraction == 'pagerank') { echo 'selected="selected"'; } ?> value="pagerank">TextRank Algorithm</option>
902
+ </select>
903
+ </td>
904
+ </tr>
905
+ <?php
906
+ }
907
+
908
+ function ppl_display_weights($options) {
909
+ ?>
910
+ <tr valign="top">
911
+ <th scope="row"><?php _e('Relative importance of:', 'post_plugin_library') ?></th>
912
+ <td>
913
+ <label for="weight_content">content: </label><input name="weight_content" type="number" style="width: 60px;" id="weight_content" value="<?php echo round(100 * $options['weight_content']); ?>" size="3" /> %
914
+ <label for="weight_title" style="margin-left:20px;">title: </label><input name="weight_title" type="number" style="width: 60px;" id="weight_title" value="<?php echo round(100 * $options['weight_title']); ?>" size="3" /> %
915
+ <label for="weight_tags" style="margin-left:20px;">tags: </label><input name="weight_tags" type="number" style="width: 60px;" id="weight_tags" value="<?php echo round(100 * $options['weight_tags']); ?>" size="3" /> % ( adds up to 100% )
916
+ </td>
917
+ </tr>
918
+ <?php
919
+ }
920
+
921
+ function ppl_display_hand_links($hand_links) {
922
+ ?>
923
+ <tr valign="top">
924
+ <th scope="row"><label for="hand_links"><?php _e('Look for manual links in custom field?', 'post_plugin_library') ?></label></th>
925
+ <td>
926
+ <select name="hand_links" id="hand_links">
927
+ <option <?php if($hand_links == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
928
+ <option <?php if($hand_links == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
929
+ </select>
930
+ </td>
931
+ </tr>
932
+ <?php
933
+ }
934
+
935
+ // now for recent_comments
936
+
937
+ function ppl_display_show_type($show_type) {
938
+ ?>
939
+ <tr valign="top">
940
+ <th scope="row" title=""><label for="show_type"><?php _e('Type of comment to show:', 'post_plugin_library') ?></label></th>
941
+ <td>
942
+ <select name="show_type" id="show_type">
943
+ <option <?php if($show_type == 'all') { echo 'selected="selected"'; } ?> value="all">All kinds of comment</option>
944
+ <option <?php if($show_type == 'comments') { echo 'selected="selected"'; } ?> value="comments">Just plain comments</option>
945
+ <option <?php if($show_type == 'trackbacks') { echo 'selected="selected"'; } ?> value="trackbacks">Just trackbacks and pingbacks</option>
946
+ </select>
947
+ </td>
948
+ </tr>
949
+ <?php
950
+ }
951
+
952
+ function ppl_display_group_by($group_by) {
953
+ ?>
954
+ <tr valign="top">
955
+ <th scope="row" title=""><?php _e('Type of grouping:', 'post_plugin_library') ?></th>
956
+ <td>
957
+ <select name="group_by" id="group_by">
958
+ <option <?php if($group_by == 'post') { echo 'selected="selected"'; } ?> value="post">By Post</option>
959
+ <option <?php if($group_by == 'none') { echo 'selected="selected"'; } ?> value="none">Ungrouped</option>
960
+ <option <?php if($group_by == 'author') { echo 'selected="selected"'; } ?> value="author">By Commenter</option>
961
+ </select>
962
+ (overrides the sort criteria above)
963
+ </td>
964
+ </tr>
965
+ <?php
966
+ }
967
+
968
+ function ppl_display_group_template($group_template) {
969
+ ?>
970
+ <tr valign="top">
971
+ <th scope="row"><label for="group_template"><?php _e('Group title template:', 'post_plugin_library') ?></label></th>
972
+ <td><textarea name="group_template" id="group_template" rows="4" cols="38"><?php echo htmlspecialchars(stripslashes($group_template)); ?></textarea></td>
973
+ </tr>
974
+ <?php
975
+ }
976
+
977
+ function ppl_display_no_author_comments($no_author_comments) {
978
+ ?>
979
+ <tr valign="top">
980
+ <th scope="row"><label for="no_author_comments"><?php _e('Omit comments by the post author?', 'post_plugin_library') ?></label></th>
981
+ <td>
982
+ <select name="no_author_comments" id="no_author_comments">
983
+ <option <?php if($no_author_comments == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
984
+ <option <?php if($no_author_comments == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
985
+ </select>
986
+ </td>
987
+ </tr>
988
+ <?php
989
+ }
990
+
991
+ function ppl_display_no_user_comments($no_user_comments) {
992
+ ?>
993
+ <tr valign="top">
994
+ <th scope="row"><label for="no_user_comments"><?php _e('Omit comments by registered users?', 'post_plugin_library') ?></label></th>
995
+ <td>
996
+ <select name="no_user_comments" id="no_user_comments">
997
+ <option <?php if($no_user_comments == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
998
+ <option <?php if($no_user_comments == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
999
+ </select>
1000
+ </td>
1001
+ </tr>
1002
+ <?php
1003
+ }
1004
+
1005
+ function ppl_display_date_modified($date_modified) {
1006
+ ?>
1007
+ <tr valign="top">
1008
+ <th scope="row"><?php _e('Order by date of last edit rather than date of creation?', 'post_plugin_library') ?></th>
1009
+ <td>
1010
+ <select name="date_modified" id="date_modified">
1011
+ <option <?php if($date_modified == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
1012
+ <option <?php if($date_modified == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
1013
+ </select>
1014
+ </td>
1015
+ </tr>
1016
+ <?php
1017
+ }
1018
+
1019
+ // 'borrowed', with adaptations, from Stephen Rider at http://striderweb.com/nerdaphernalia/
1020
+ function ppl_get_plugin_data($plugin_file) {
1021
+ // You can optionally pass a specific value to fetch, e.g. 'Version' -- but it's inefficient to do that multiple times
1022
+ // As of WP 2.5.1: 'Name', 'Title', 'Description', 'Author', 'Version'
1023
+ // As of WP 2.7-bleeding: 'Name', 'PluginURI', 'Description', 'Author', 'AuthorURI', 'Version', 'TextDomain', 'DomainPath'
1024
+ if(!function_exists( 'get_plugin_data' ) ) require_once( ABSPATH . 'wp-admin/includes/plugin.php');
1025
+ static $plugin_data;
1026
+ if(!$plugin_data) {
1027
+ $plugin_data = get_plugin_data($plugin_file);
1028
+ if (!isset($plugin_data['Title'])) {
1029
+ if ('' != $plugin_data['PluginURI'] && '' != $plugin_data['Name']) {
1030
+ $plugin_data['Title'] = '<a href="' . $plugin_data['PluginURI'] . '" title="'. __('Visit plugin homepage', 'post-plugin-library') . '">' . $plugin_data['Name'] . '</a>';
1031
+ } else {
1032
+ $plugin_data['Title'] = $name;
1033
+ }
1034
+ }
1035
+ }
1036
+ return $plugin_data;
1037
+ }
1038
+
common_functions.php CHANGED
@@ -1,660 +1,660 @@
1
- <?php
2
-
3
- /*
4
- Library for the Recent Posts, Random Posts, Recent Comments, and Similar Posts plugins
5
- -- provides the routines which the plugins share
6
- */
7
-
8
- define('CF_LIBRARY', true);
9
-
10
- function ppl_parse_args($args) {
11
- // $args is of the form 'key1=val1&key2=val2'
12
- // The code copes with null values, e.g., 'key1=&key2=val2'
13
- // and arguments with embedded '=', e.g. 'output_template=<li class="stuff">{...}</li>'.
14
- $result = array();
15
- if($args){
16
- // the default separator is '&' but you may wish to include the character in a title, say,
17
- // so you can specify an alternative separator by making the first character of $args
18
- // '&' and the second character your new separator...
19
- if (substr($args, 0, 1) === '&') {
20
- $s = substr($args, 1, 1);
21
- $args = substr($args, 2);
22
- } else {
23
- $s = '&';
24
- }
25
- // separate the arguments into key=value pairs
26
- $arguments = explode($s, $args);
27
- foreach($arguments as $arg){
28
- if($arg){
29
- // find the position of the first '='
30
- $i = strpos($arg, '=');
31
- // if not a valid format ('key=value) we ignore it
32
- if ($i){
33
- $key = substr($arg, 0, $i);
34
- $val = substr($arg, $i+1);
35
- $result[$key]=$val;
36
- }
37
- }
38
- }
39
- }
40
- return $result;
41
- }
42
-
43
- function ppl_set_options($option_key, $arg, $default_output_template) {
44
- $options = get_option($option_key);
45
- // deal with compound options
46
- if (isset($arg['custom-key'])) {$arg['custom']['key'] = $arg['custom-key']; unset($arg['custom-key']);}
47
- if (isset($arg['custom-op'])) {$arg['custom']['op'] = $arg['custom-op']; unset($arg['custom-op']);}
48
- if (isset($arg['custom-value'])) {$arg['custom']['value'] = $arg['custom-value']; unset($arg['custom-value']);}
49
- if (isset($arg['age-direction'])) {$arg['age']['direction'] = $arg['age-direction']; unset($arg['age-direction']);}
50
- if (isset($arg['age-length'])) {$arg['age']['length'] = $arg['age-length']; unset($arg['age-length']);}
51
- if (isset($arg['age-duration'])) {$arg['age']['duration'] = $arg['age-duration']; unset($arg['age-duration']);}
52
- if (isset($arg['sort-by1'])) {$arg['sort']['by1'] = $arg['sort-by1']; unset($arg['sort-by1']);}
53
- if (isset($arg['sort-order1'])) {$arg['sort']['order1'] = $arg['sort-order1']; unset($arg['sort-order1']);}
54
- if (isset($arg['sort-case1'])) {$arg['sort']['case1'] = $arg['sort-case1']; unset($arg['sort-case1']);}
55
- if (isset($arg['sort-by2'])) {$arg['sort']['by2'] = $arg['sort-by2']; unset($arg['sort-by2']);}
56
- if (isset($arg['sort-order2'])) {$arg['sort']['order2'] = $arg['sort-order2']; unset($arg['sort-order2']);}
57
- if (isset($arg['sort-case2'])) {$arg['sort']['case2'] = $arg['sort-case2']; unset($arg['sort-case2']);}
58
- if (isset($arg['status-publish'])) {$arg['status']['publish'] = $arg['status-publish']; unset($arg['status-publish']);}
59
- if (isset($arg['status-private'])) {$arg['status']['private'] = $arg['status-private']; unset($arg['status-private']);}
60
- if (isset($arg['status-draft'])) {$arg['status']['draft'] = $arg['status-draft']; unset($arg['status-draft']);}
61
- if (isset($arg['status-future'])) {$arg['status']['future'] = $arg['status-future']; unset($arg['status-future']);}
62
- // then fill in the defaults
63
- if (!isset($arg['limit'])) $arg['limit'] = stripslashes(@$options['limit']);
64
- if (!isset($arg['skip'])) $arg['skip'] = stripslashes(@$options['skip']);
65
- if (!isset($arg['divider'])) $arg['divider'] = stripslashes(@$options['divider']);
66
- if (!isset($arg['omit_current_post'])) $arg['omit_current_post'] = @$options['omit_current_post'];
67
- if (!isset($arg['just_current_post'])) $arg['just_current_post'] = @$options['just_current_post'];
68
- if (!isset($arg['show_private'])) $arg['show_private'] = @$options['show_private'];
69
- if (!isset($arg['show_pages'])) $arg['show_pages'] = @$options['show_pages'];
70
- if (!isset($arg['show_attachments'])) $arg['show_attachments'] = @$options['show_attachments'];
71
- if (!isset($arg['none_text'])) $arg['none_text'] = stripslashes(@$options['none_text']);
72
- if (!isset($arg['no_text'])) $arg['no_text'] = @$options['no_text'];
73
- if (!isset($arg['tag_str'])) $arg['tag_str'] = stripslashes(@$options['tag_str']);
74
- if (!isset($arg['excluded_cats'])) $arg['excluded_cats'] = stripslashes(@$options['excluded_cats']);
75
- if (!isset($arg['included_cats'])) $arg['included_cats'] = stripslashes(@$options['included_cats']);
76
- if (!isset($arg['excluded_authors'])) $arg['excluded_authors'] = stripslashes(@$options['excluded_authors']);
77
- if (!isset($arg['included_authors'])) $arg['included_authors'] = stripslashes(@$options['included_authors']);
78
- if (!isset($arg['excluded_posts'])) $arg['excluded_posts'] = stripslashes(@$options['excluded_posts']);
79
- if (!isset($arg['included_posts'])) $arg['included_posts'] = stripslashes(@$options['included_posts']);
80
- if (!isset($arg['stripcodes'])) $arg['stripcodes'] = @$options['stripcodes'];
81
- if (!isset($arg['prefix'])) $arg['prefix'] = stripslashes(@$options['prefix']);
82
- if (!isset($arg['suffix'])) $arg['suffix'] = stripslashes(@$options['suffix']);
83
- if (!isset($arg['output_template'])) $arg['output_template'] = stripslashes(@$options['output_template']);
84
- // an empty output_template makes no sense so we fall back to the default
85
- if ($arg['output_template'] == '') $arg['output_template'] = $default_output_template;
86
- if (!isset($arg['match_cat'])) $arg['match_cat'] = @$options['match_cat'];
87
- if (!isset($arg['match_tags'])) $arg['match_tags'] = @$options['match_tags'];
88
- if (!isset($arg['match_author'])) $arg['match_author'] = @$options['match_author'];
89
- if (!isset($arg['age'])) $arg['age'] = @$options['age'];
90
- if (!isset($arg['custom'])) $arg['custom'] = @$options['custom'];
91
- if (!isset($arg['sort'])) $arg['sort'] = @$options['sort'];
92
- if (!isset($arg['status'])) $arg['status'] = @$options['status'];
93
-
94
- // just for recent_posts
95
- if (!isset($arg['date_modified'])) $arg['date_modified'] = @$options['date_modified'];
96
-
97
- // just for recent_comments
98
- if (!isset($arg['group_by'])) $arg['group_by'] = @$options['group_by'];
99
- if (!isset($arg['group_template'])) $arg['group_template'] = stripslashes(@$options['group_template']);
100
- if (!isset($arg['show_type'])) $arg['show_type'] = @$options['show_type'];
101
- if (!isset($arg['no_author_comments'])) $arg['no_author_comments'] = @$options['no_author_comments'];
102
- if (!isset($arg['no_user_comments'])) $arg['no_user_comments'] = @$options['no_user_comments'];
103
- if (!isset($arg['unique'])) $arg['unique'] = @$options['unique'];
104
-
105
- // just for similar_posts[feed]
106
- if (!isset($arg['combine'])) $arg['combine'] = @$options['crossmatch'];
107
- if (!isset($arg['weight_content'])) $arg['weight_content'] = @$options['weight_content'];
108
- if (!isset($arg['weight_title'])) $arg['weight_title'] = @$options['weight_title'];
109
- if (!isset($arg['weight_tags'])) $arg['weight_tags'] = @$options['weight_tags'];
110
- if (!isset($arg['num_terms'])) $arg['num_terms'] = stripslashes(@$options['num_terms']);
111
- if (!isset($arg['term_extraction'])) $arg['term_extraction'] = @$options['term_extraction'];
112
- if (!isset($arg['hand_links'])) $arg['hand_links'] = @$options['hand_links'];
113
-
114
- // just for other_posts
115
- if (!isset($arg['orderby'])) $arg['orderby'] = stripslashes(@$options['orderby']);
116
- if (!isset($arg['orderby_order'])) $arg['orderby_order'] = @$options['orderby_order'];
117
- if (!isset($arg['orderby_case'])) $arg['orderby_case'] = @$options['orderby_case'];
118
-
119
- // the last options cannot be set via arguments
120
- $arg['stripcodes'] = @$options['stripcodes'];
121
- $arg['utf8'] = @$options['utf8'];
122
- $arg['cjk'] = @$options['cjk'];
123
- $arg['use_stemmer'] = @$options['use_stemmer'];
124
- $arg['batch'] = @$options['batch'];
125
- $arg['content_filter'] = @$options['content_filter'];
126
- $arg['widget_parameters'] = stripslashes(@$options['widget_parameters']);
127
- $arg['widget_condition'] = stripslashes(@$options['widget_condition']);
128
- $arg['feed_on'] = @$options['feed_on'];
129
- $arg['feed_priority'] = @$options['feed_priority'];
130
- $arg['feed_parameters'] = stripslashes(@$options['feed_parameters']);
131
- $arg['append_on'] = @$options['append_on'];
132
- $arg['append_priority'] = @$options['append_priority'];
133
- $arg['append_parameters'] = stripslashes(@$options['append_parameters']);
134
- $arg['append_condition'] = stripslashes(@$options['append_condition']);
135
- $arg['exclude_users'] = @$options['exclude_users'];
136
- $arg['count_home'] = @$options['count_home'];
137
- $arg['count_feed'] = @$options['count_feed'];
138
- $arg['count_single'] = @$options['count_single'];
139
- $arg['count_archive'] = @$options['count_archive'];
140
- $arg['count_category'] = @$options['count_category'];
141
- $arg['count_page'] = @$options['count_page'];
142
- $arg['count_search'] = @$options['count_search'];
143
-
144
- return $arg;
145
- }
146
-
147
- function ppl_prepare_template($template) {
148
- // Now we process the output_template to find the embedded tags which are to be replaced
149
- // with values taken from the database.
150
- // A tag is of the form, {tag:ext}, where the tag part will be evaluated and replaced
151
- // and the optional ext part provides extra data pertinent to that tag
152
-
153
-
154
- preg_match_all('/{((?:[^{}]|{[^{}]*})*)}/', $template, $matches);
155
- $translations = array();
156
- if(is_array($matches)){
157
-
158
- foreach($matches[1] as $match) {
159
- if(strpos($match,':')!==false){
160
- list($tag, $ext) = explode(':', $match, 2);
161
- } else {
162
- $tag = $match;
163
- $ext = false;
164
- }
165
- $action = output_tag_action($tag);
166
- if (function_exists($action)) {
167
- // store the action that instantiates the tag
168
- $translations['acts'][] = $action;
169
- // add the tag in a form ready to use in translation later
170
- $translations['fulltags'][] = '{'.$match.'}';
171
- // the extra data if any
172
- $translations['exts'][] = $ext;
173
- }
174
- }
175
- }
176
- return $translations;
177
- }
178
-
179
- function ppl_expand_template($result, $template, $translations, $option_key) {
180
- global $wpdb, $wp_version;
181
- $replacements = array();
182
-
183
- if(array_key_exists('fulltags',$translations)){
184
- $numtags = count($translations['fulltags']);
185
- for ($i = 0; $i < $numtags; $i++) {
186
- $fulltag = $translations['fulltags'][$i];
187
- $act = $translations['acts'][$i];
188
- $ext = $translations['exts'][$i];
189
- $replacements[$fulltag] = $act($option_key, $result, $ext);
190
- }
191
- }
192
- // Replace every valid tag with its value
193
- $tmp = strtr($template, $replacements)."\n";
194
- return $tmp;
195
- }
196
-
197
-
198
- function ppl_sort_items($sort, $results, $option_key, $group_template, $items) {
199
- $translations1 = ppl_prepare_template($sort['by1']);
200
- foreach ($results as $result) {
201
- $key1 = ppl_expand_template($result, $sort['by1'], $translations1, $option_key);
202
- if ($sort['case1'] !== 'false') $key1 = strtolower($key1);
203
- $keys1[] = $key1;
204
- }
205
- if ($sort['by2'] !== '') {
206
- $translations2 = ppl_prepare_template($sort['by2']);
207
- foreach ($results as $result) {
208
- $key2 = ppl_expand_template($result, $sort['by2'], $translations2, $option_key);
209
- if ($sort['case2'] !== 'false') $key2 = strtolower($key2);
210
- $keys2[] = $key2;
211
- }
212
- }
213
- if (!empty($keys2)) {
214
- array_multisort($keys1, intval($sort['order1']), $keys2, intval($sort['order2']), $results, $items);
215
- } else {
216
- array_multisort($keys1, intval($sort['order1']), $results, $items);
217
- }
218
- // merge the group titles into the items
219
- if ($group_template) {
220
- $group_translations = ppl_prepare_template($group_template);
221
- $prev_key = '';
222
- $insertions = 0;
223
- foreach ($keys1 as $n => $key) {
224
- if ($prev_key !== $key) {
225
- array_splice($items, $n+$insertions, 0, ppl_expand_template($results[$n], $group_template, $group_translations, $option_key));
226
- $insertions++;
227
- }
228
- $prev_key = $key;
229
- }
230
- }
231
- return $items;
232
- }
233
-
234
- // the $post global can be overwritten by the use of $wp_query so we go back to the source
235
- // note the addition of a 'manual overide' allowing the current posts to me marked by similar_posts_mark_current for example
236
- function ppl_current_post_id ($manual_current_ID = -1) {
237
- $the_ID = -1;
238
- if ($manual_current_ID > 0) {
239
- $the_ID = $manual_current_ID;
240
- } else if (isset($GLOBALS['wp_the_query'])) {
241
- $the_ID = $GLOBALS['wp_the_query']->post->ID;
242
- if (!$the_ID) {
243
- $the_ID = $GLOBALS['wp_the_query']->posts[0]->ID;
244
- }
245
- } else {
246
- $the_ID = $GLOBALS['post']->ID;
247
- }
248
- return $the_ID;
249
- }
250
-
251
-
252
- /*
253
-
254
- Functions to fill in the WHERE part of the workhorse SQL
255
-
256
- */
257
-
258
- function where_match_author() {
259
- $current_author = $GLOBALS['wp_the_query']->post->post_author;
260
- return "post_author = $current_author";
261
- }
262
-
263
- function where_match_tags($match_tags) {
264
- global $wpdb, $wp_version;
265
- $args = array('fields' => 'ids');
266
- $tag_ids = wp_get_object_terms(ppl_current_post_id(), 'post_tag', $args);
267
- if ( is_array($tag_ids) && count($tag_ids) > 0 ) {
268
- if ($match_tags === 'any') {
269
- $ids = get_objects_in_term($tag_ids, 'post_tag');
270
- } else {
271
- $ids = array();
272
- foreach ($tag_ids as $tag_id){
273
- if (count($ids) > 0) {
274
- $ids = array_intersect($ids, get_objects_in_term($tag_id, 'post_tag'));
275
- } else {
276
- $ids = get_objects_in_term($tag_id, 'post_tag');
277
- }
278
- }
279
- }
280
- if ( is_array($ids) && count($ids) > 0 ) {
281
- $ids = array_unique($ids);
282
- $out_posts = "'" . implode("', '", $ids) . "'";
283
- $sql = "$wpdb->posts.ID IN ($out_posts)";
284
- } else {
285
- $sql = "1 = 2";
286
- }
287
- } else {
288
- $sql = "1 = 2";
289
- }
290
- return $sql;
291
- }
292
-
293
- function where_show_pages($show_pages, $show_attachments='false') {
294
- if (function_exists('get_post_type')) {
295
- $typelist = array();
296
- if ($show_attachments === 'true') {$typelist[] = "'attachment'";};
297
- if ($show_pages === 'true') {$typelist[] = "'page'"; $typelist[] = "'post'";}
298
- else if ($show_pages === 'false') {$typelist[] = "'post'";}
299
- else if ($show_pages === 'but') {$typelist[] = "'page'";};
300
- if (count($typelist)===1) {
301
- $sql = "post_type=$typelist[0]";
302
- } else {
303
- $sql = "post_type IN (" . implode(',',$typelist) . ")";
304
- }
305
- } else {
306
- if ($show_pages === 'true') $sql = "post_status IN ('publish', 'static')";
307
- else if ($show_pages === 'false') $sql = "post_status = 'publish'";
308
- else if ($show_pages === 'but') $sql = "post_status = 'static'";
309
- }
310
- return $sql;
311
- }
312
-
313
- function where_show_status($status, $include_inherit='false') {
314
- $set = array();
315
- $status = (array) $status;
316
- // a quick way of allowing for attachments having status=inherit
317
- if ($include_inherit === 'true') $status['inherit'] = 'true';
318
- foreach ($status as $name => $state) {
319
- if ($state === 'true') $set[] = "'$name'";
320
- }
321
- if ($set) {
322
- $result = implode(',', $set);
323
- return "post_status IN ($result)";
324
- } else {
325
- return "1 = 2";
326
- }
327
- }
328
-
329
- // a replacement, for WP < 2.3, ONLY category children
330
- if (!function_exists('get_term_children')) {
331
- function get_term_children($term, $taxonomy) {
332
- if ($taxonomies !== 'category') return array();
333
- return get_categories('child_of='.$term);
334
- }
335
- }
336
-
337
-
338
- // a replacement, for WP < 2.3, ONLY to get posts with given category IDs
339
- if (!function_exists('get_objects_in_term')) {
340
- function get_objects_in_term($terms, $taxonomies) {
341
- global $wpdb;
342
- if ($taxonomies !== 'category') return array();
343
- $terms = "'" . implode("', '", $terms) . "'";
344
- $object_ids = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE category_id IN ($terms)");
345
- if (!$object_ids) return array();
346
- return $object_ids;
347
- }
348
- }
349
-
350
- function where_match_category() {
351
- global $wpdb, $wp_version;
352
- $cat_ids = '';
353
- foreach(get_the_category() as $cat) {
354
- if ($cat->cat_ID) $cat_ids .= $cat->cat_ID . ',';
355
- }
356
- $cat_ids = rtrim($cat_ids, ',');
357
- $catarray = explode(',', $cat_ids);
358
- foreach ( $catarray as $cat ) {
359
- $catarray = array_merge($catarray, get_term_children($cat, 'category'));
360
- }
361
- $catarray = array_unique($catarray);
362
- $ids = get_objects_in_term($catarray, 'category');
363
- $ids = array_unique($ids);
364
- if ( is_array($ids) && count($ids) > 0 ) {
365
- $out_posts = "'" . implode("', '", $ids) . "'";
366
- $sql = "$wpdb->posts.ID IN ($out_posts)";
367
- } else {
368
- $sql = "1 = 2";
369
- }
370
- return $sql;
371
- }
372
-
373
- function where_included_cats($included_cats) {
374
- global $wpdb, $wp_version;
375
- $catarray = explode(',', $included_cats);
376
- foreach ( $catarray as $cat ) {
377
- $catarray = array_merge($catarray, get_term_children($cat, 'category'));
378
- }
379
- $catarray = array_unique($catarray);
380
- $ids = get_objects_in_term($catarray, 'category');
381
- if ( is_array($ids) && count($ids) > 0 ) {
382
- $ids = array_unique($ids);
383
- $in_posts = "'" . implode("', '", $ids) . "'";
384
- $sql = "ID IN ($in_posts)";
385
- } else {
386
- $sql = "1 = 2";
387
- }
388
- return $sql;
389
- }
390
-
391
- function where_excluded_cats($excluded_cats) {
392
- global $wpdb, $wp_version;
393
- $catarray = explode(',', $excluded_cats);
394
- foreach ( $catarray as $cat ) {
395
- $catarray = array_merge($catarray, get_term_children($cat, 'category'));
396
- }
397
- $catarray = array_unique($catarray);
398
- $ids = get_objects_in_term($catarray, 'category');
399
- if ( is_array($ids) && count($ids) > 0 ) {
400
- $out_posts = "'" . implode("', '", $ids) . "'";
401
- $sql = "$wpdb->posts.ID NOT IN ($out_posts)";
402
- } else {
403
- $sql = "1 = 1";
404
- }
405
- return $sql;
406
- }
407
-
408
- function where_excluded_authors($excluded_authors){
409
- return "post_author NOT IN ( $excluded_authors )";
410
- }
411
-
412
- function where_included_authors($included_authors){
413
- return "post_author IN ( $included_authors )";
414
- }
415
-
416
- function where_excluded_posts($excluded_posts) {
417
- return "ID NOT IN ( $excluded_posts )";
418
- }
419
-
420
- function where_included_posts($included_posts) {
421
- return "ID IN ( $included_posts )";
422
- }
423
-
424
- function where_tag_str($tag_str) {
425
- global $wpdb;
426
- if ( strpos($tag_str, ',') !== false ) {
427
- $intags = explode(',', $tag_str);
428
- foreach ( (array) $intags as $tag ) {
429
- $tags[] = sanitize_term_field('name', $tag, 0, 'post_tag', 'db');
430
- }
431
- $tag_type = 'any';
432
- } else if ( strpos($tag_str, '+') !== false ) {
433
- $intags = explode('+', $tag_str);
434
- foreach ( (array) $intags as $tag ) {
435
- $tags[] = sanitize_term_field('name', $tag, 0, 'post_tag', 'db');
436
- }
437
- $tag_type = 'all';
438
- } else {
439
- $tags[] = sanitize_term_field('name', $tag_str, 0, 'post_tag', 'db');
440
- $tag_type = 'any';
441
- }
442
- $ids = array();
443
- if ($tag_type == 'any') {
444
- foreach ($tags as $tag){
445
- if (is_term($tag, 'post_tag')) {
446
- $t = get_term_by('name', $tag, 'post_tag');
447
- $ids = array_merge($ids, get_objects_in_term($t->term_id, 'post_tag'));
448
- }
449
- }
450
- } else {
451
- foreach ($tags as $tag){
452
- if (is_term($tag, 'post_tag')) {
453
- $t = get_term_by('name', $tag, 'post_tag');
454
- if (count($ids) > 0) {
455
- $ids = array_intersect($ids, get_objects_in_term($t->term_id, 'post_tag'));
456
- } else {
457
- $ids = get_objects_in_term($t->term_id, 'post_tag');
458
- }
459
- }
460
- }
461
- }
462
- if ( is_array($ids) && count($ids) > 0 ) {
463
- $ids = array_unique($ids);
464
- $out_posts = "'" . implode("', '", $ids) . "'";
465
- $sql .= "$wpdb->posts.ID IN ($out_posts)";
466
- } else $sql .= "1 = 2";
467
- return $sql;
468
- }
469
-
470
- // note the addition of a 'manual overide' allowing the current posts to me marked by similar_posts_mark_current for example
471
- function where_omit_post($manual_current_ID = -1) {
472
- $postid = ppl_current_post_id($manual_current_ID);
473
- if ($postid <= 1) $postid = -1;
474
- return "ID != $postid";
475
- }
476
-
477
- function where_just_post() {
478
- $postid = ppl_current_post_id();
479
- if ($postid <= 1) $postid = -1;
480
- return "ID = $postid";
481
- }
482
-
483
- function where_hide_pass() {
484
- return "post_password =''";
485
- }
486
-
487
- function where_hide_future() {
488
- // from wp 2.1 future posts are taken care of by post status
489
- $time_difference = get_option('gmt_offset');
490
- $now = gmdate("Y-m-d H:i:s",(time()+($time_difference*3600)));
491
- $sql = "post_date <= '$now'";
492
- return $sql;
493
- }
494
-
495
- function where_fulltext_match($weight_title, $titleterms, $weight_content, $contentterms, $weight_tags, $tagterms) {
496
- $wsql = array();
497
- if ($weight_title) $wsql[] = "MATCH (`title`) AGAINST ( \"$titleterms\" )";
498
- if ($weight_content) $wsql[] = "MATCH (`content`) AGAINST ( \"$contentterms\" )";
499
- if ($weight_tags) $wsql[] = "MATCH (`tags`) AGAINST ( \"$tagterms\" )";
500
- return '(' . implode(' OR ', $wsql) . ') ' ;
501
- }
502
-
503
- function where_author_comments() {
504
- $author_email = get_the_author_email();
505
- return "'$author_email' != comment_author_email";
506
- }
507
-
508
- function where_user_comments() {
509
- return "user_id = 0";
510
- }
511
-
512
- function score_fulltext_match($table_name, $weight_title, $titleterms, $weight_content, $contentterms, $weight_tags, $tagterms, $forced_ids='') {
513
- global $wpdb;
514
- $wsql = array();
515
- if ($weight_title) $wsql[] = "(".number_format($weight_title, 4, '.', '')." * (MATCH (`title`) AGAINST ( \"$titleterms\" )))";
516
- if ($weight_content) $wsql[] = "(".number_format($weight_content, 4, '.', '')." * (MATCH (`content`) AGAINST ( \"$contentterms\" )))";
517
- if ($weight_tags) $wsql[] = "(".number_format($weight_tags, 4, '.', '')." * (MATCH (`tags`) AGAINST ( \"$tagterms\" )))";
518
- if ($forced_ids) {
519
- // apply a delta function to boost the score for certain IDs
520
- $fIDs = explode(',', $forced_ids);
521
- foreach($fIDs as $fID) {
522
- $wsql[] = "100 * (1 - SIGN(ID ^ $fID))"; // the previous delta was $wsql[] = "100*EXP(-10*POW((ID-$fID),2))";
523
-
524
- }
525
- }
526
- return '(' . implode(' + ', $wsql) . " ) as score FROM `$table_name` LEFT JOIN `$wpdb->posts` ON `pID` = `ID` ";
527
- }
528
-
529
- function where_comment_type($comment_type) {
530
- if ($comment_type === 'comments') $sql = "comment_type = ''";
531
- elseif ($comment_type === 'trackbacks') $sql = "comment_type != ''";
532
- return $sql;
533
- }
534
-
535
- function where_check_age($direction, $length, $duration) {
536
- global $wp_version;
537
- if ('none' === $direction) return '';
538
- $age = "DATE_SUB(CURDATE(), INTERVAL $length $duration)";
539
- // we only filter out posts based on age, not pages
540
- if ('before' === $direction) {
541
- if (function_exists('get_post_type')) {
542
- return "(post_date <= $age OR post_type='page')";
543
- } else {
544
- return "(post_date <= $age OR post_status='static')";
545
- }
546
- } else {
547
- if (function_exists('get_post_type')) {
548
- return "(post_date >= $age OR post_type='page')";
549
- } else {
550
- return "(post_date >= $age OR post_status='static')";
551
- }
552
- }
553
- }
554
-
555
- function where_check_custom($key, $op, $value) {
556
- if ($op === 'EXISTS') {
557
- return "meta_key = '$key'";
558
- } else {
559
- return "(meta_key = '$key' && meta_value $op '$value')";
560
- }
561
- }
562
-
563
- /*
564
-
565
- End of SQL functions
566
-
567
- */
568
-
569
- function ppl_microtime() {
570
- list($usec, $sec) = explode(" ", microtime());
571
- return ((float)$usec + (float)$sec);
572
- }
573
-
574
- /*
575
-
576
- Some routines to handle appending output
577
-
578
- */
579
-
580
- // array of what to append to posts
581
- global $ppl_filter_data;
582
- $ppl_filter_data = array();
583
-
584
- // each plugin calls this on startup to have content scanned for its own tag
585
- function ppl_register_post_filter($type, $key, $class, $condition='') {
586
- global $ppl_filter_data;
587
- $options = get_option($key);
588
- $priority = $options[$type . '_priority'];
589
- $parameters = stripslashes($options[$type . '_parameters']);
590
- $ppl_filter_data [] = array('type' => $type, 'priority' => $priority, 'class' => $class, 'parameters' => $parameters, 'key' => $key, 'condition' => stripslashes($condition));
591
- // we want them in decreasing priority
592
- sort($ppl_filter_data);
593
- }
594
-
595
- function ppl_post_filter($content) {
596
- global $ppl_filter_data;
597
- foreach ($ppl_filter_data as $data) {
598
- if (('append' === $data['type'] && !is_feed() && eval($data['condition'])) || ('feed' === $data['type'] && is_feed()) ){
599
- $content .= call_user_func_array(array($data['class'], 'execute'), array($data['parameters'], '<li>{link}</li>', $data['key']));
600
- }
601
- }
602
- return $content;
603
- }
604
-
605
- function ppl_post_filter_init() {
606
- global $ppl_filter_data;
607
- if (!$ppl_filter_data) return;
608
- add_filter('the_content', 'ppl_post_filter', 5);
609
- }
610
-
611
- // watch out that the registration functions are called earlier
612
- add_action ('init', 'ppl_post_filter_init');
613
-
614
- /*
615
-
616
- Now some routines to handle content filtering
617
-
618
- */
619
-
620
- // the '|'-separated list of valid content filter tags
621
- global $ppl_filter_tags;
622
-
623
- // each plugin calls this on startup to have content scanned for its own tag
624
- function ppl_register_content_filter($tag) {
625
- global $ppl_filter_tags;
626
- if (!$ppl_filter_tags) {
627
- $ppl_filter_tags = $tag;
628
- } else {
629
- $tags = explode('|', $ppl_filter_tags);
630
- $tags[] = $tag;
631
- $tags = array_unique($tags);
632
- $ppl_filter_tags = implode('|', $tags);
633
- }
634
- }
635
-
636
-
637
- function ppl_do_replace($matches) {
638
- return call_user_func(array($matches[1], 'execute'), $matches[2]);
639
- }
640
-
641
- function ppl_content_filter($content) {
642
- global $ppl_filter_tags;
643
- // replaces every instance of "<!--RecentPosts-->", for example, with the output of the plugin
644
- // the filter tag can be followed by text which will be used as a parameter string to change the behaviour of the plugin
645
- return preg_replace_callback("/<!--($ppl_filter_tags)\s*(.*)-->/", "ppl_do_replace", $content);
646
- }
647
-
648
- function ppl_content_filter_init() {
649
- global $ppl_filter_tags;
650
- if (!$ppl_filter_tags) return;
651
- add_filter( 'the_content', 'ppl_content_filter', 5 );
652
- add_filter( 'the_content_rss', 'ppl_content_filter', 5 );
653
- add_filter( 'the_excerpt', 'ppl_content_filter', 5 );
654
- add_filter( 'the_excerpt_rss', 'ppl_content_filter', 5 );
655
- add_filter( 'widget_text', 'ppl_content_filter', 5 );
656
- }
657
-
658
- // watch out that the registration functions are called earlier
659
- add_action ('init', 'ppl_content_filter_init');
660
- add_action ('init', 'ppl_post_filter_init');
1
+ <?php
2
+
3
+ /*
4
+ Library for the Recent Posts, Random Posts, Recent Comments, and Similar Posts plugins
5
+ -- provides the routines which the plugins share
6
+ */
7
+
8
+ define('CF_LIBRARY', true);
9
+
10
+ function ppl_parse_args($args) {
11
+ // $args is of the form 'key1=val1&key2=val2'
12
+ // The code copes with null values, e.g., 'key1=&key2=val2'
13
+ // and arguments with embedded '=', e.g. 'output_template=<li class="stuff">{...}</li>'.
14
+ $result = array();
15
+ if($args){
16
+ // the default separator is '&' but you may wish to include the character in a title, say,
17
+ // so you can specify an alternative separator by making the first character of $args
18
+ // '&' and the second character your new separator...
19
+ if (substr($args, 0, 1) === '&') {
20
+ $s = substr($args, 1, 1);
21
+ $args = substr($args, 2);
22
+ } else {
23
+ $s = '&';
24
+ }
25
+ // separate the arguments into key=value pairs
26
+ $arguments = explode($s, $args);
27
+ foreach($arguments as $arg){
28
+ if($arg){
29
+ // find the position of the first '='
30
+ $i = strpos($arg, '=');
31
+ // if not a valid format ('key=value) we ignore it
32
+ if ($i){
33
+ $key = substr($arg, 0, $i);
34
+ $val = substr($arg, $i+1);
35
+ $result[$key]=$val;
36
+ }
37
+ }
38
+ }
39
+ }
40
+ return $result;
41
+ }
42
+
43
+ function ppl_set_options($option_key, $arg, $default_output_template) {
44
+ $options = get_option($option_key);
45
+ // deal with compound options
46
+ if (isset($arg['custom-key'])) {$arg['custom']['key'] = $arg['custom-key']; unset($arg['custom-key']);}
47
+ if (isset($arg['custom-op'])) {$arg['custom']['op'] = $arg['custom-op']; unset($arg['custom-op']);}
48
+ if (isset($arg['custom-value'])) {$arg['custom']['value'] = $arg['custom-value']; unset($arg['custom-value']);}
49
+ if (isset($arg['age-direction'])) {$arg['age']['direction'] = $arg['age-direction']; unset($arg['age-direction']);}
50
+ if (isset($arg['age-length'])) {$arg['age']['length'] = $arg['age-length']; unset($arg['age-length']);}
51
+ if (isset($arg['age-duration'])) {$arg['age']['duration'] = $arg['age-duration']; unset($arg['age-duration']);}
52
+ if (isset($arg['sort-by1'])) {$arg['sort']['by1'] = $arg['sort-by1']; unset($arg['sort-by1']);}
53
+ if (isset($arg['sort-order1'])) {$arg['sort']['order1'] = $arg['sort-order1']; unset($arg['sort-order1']);}
54
+ if (isset($arg['sort-case1'])) {$arg['sort']['case1'] = $arg['sort-case1']; unset($arg['sort-case1']);}
55
+ if (isset($arg['sort-by2'])) {$arg['sort']['by2'] = $arg['sort-by2']; unset($arg['sort-by2']);}
56
+ if (isset($arg['sort-order2'])) {$arg['sort']['order2'] = $arg['sort-order2']; unset($arg['sort-order2']);}
57
+ if (isset($arg['sort-case2'])) {$arg['sort']['case2'] = $arg['sort-case2']; unset($arg['sort-case2']);}
58
+ if (isset($arg['status-publish'])) {$arg['status']['publish'] = $arg['status-publish']; unset($arg['status-publish']);}
59
+ if (isset($arg['status-private'])) {$arg['status']['private'] = $arg['status-private']; unset($arg['status-private']);}
60
+ if (isset($arg['status-draft'])) {$arg['status']['draft'] = $arg['status-draft']; unset($arg['status-draft']);}
61
+ if (isset($arg['status-future'])) {$arg['status']['future'] = $arg['status-future']; unset($arg['status-future']);}
62
+ // then fill in the defaults
63
+ if (!isset($arg['limit'])) $arg['limit'] = stripslashes(@$options['limit']);
64
+ if (!isset($arg['skip'])) $arg['skip'] = stripslashes(@$options['skip']);
65
+ if (!isset($arg['divider'])) $arg['divider'] = stripslashes(@$options['divider']);
66
+ if (!isset($arg['omit_current_post'])) $arg['omit_current_post'] = @$options['omit_current_post'];
67
+ if (!isset($arg['just_current_post'])) $arg['just_current_post'] = @$options['just_current_post'];
68
+ if (!isset($arg['show_private'])) $arg['show_private'] = @$options['show_private'];
69
+ if (!isset($arg['show_pages'])) $arg['show_pages'] = @$options['show_pages'];
70
+ if (!isset($arg['show_attachments'])) $arg['show_attachments'] = @$options['show_attachments'];
71
+ if (!isset($arg['none_text'])) $arg['none_text'] = stripslashes(@$options['none_text']);
72
+ if (!isset($arg['no_text'])) $arg['no_text'] = @$options['no_text'];
73
+ if (!isset($arg['tag_str'])) $arg['tag_str'] = stripslashes(@$options['tag_str']);
74
+ if (!isset($arg['excluded_cats'])) $arg['excluded_cats'] = stripslashes(@$options['excluded_cats']);
75
+ if (!isset($arg['included_cats'])) $arg['included_cats'] = stripslashes(@$options['included_cats']);
76
+ if (!isset($arg['excluded_authors'])) $arg['excluded_authors'] = stripslashes(@$options['excluded_authors']);
77
+ if (!isset($arg['included_authors'])) $arg['included_authors'] = stripslashes(@$options['included_authors']);
78
+ if (!isset($arg['excluded_posts'])) $arg['excluded_posts'] = stripslashes(@$options['excluded_posts']);
79
+ if (!isset($arg['included_posts'])) $arg['included_posts'] = stripslashes(@$options['included_posts']);
80
+ if (!isset($arg['stripcodes'])) $arg['stripcodes'] = @$options['stripcodes'];
81
+ if (!isset($arg['prefix'])) $arg['prefix'] = stripslashes(@$options['prefix']);
82
+ if (!isset($arg['suffix'])) $arg['suffix'] = stripslashes(@$options['suffix']);
83
+ if (!isset($arg['output_template'])) $arg['output_template'] = stripslashes(@$options['output_template']);
84
+ // an empty output_template makes no sense so we fall back to the default
85
+ if ($arg['output_template'] == '') $arg['output_template'] = $default_output_template;
86
+ if (!isset($arg['match_cat'])) $arg['match_cat'] = @$options['match_cat'];
87
+ if (!isset($arg['match_tags'])) $arg['match_tags'] = @$options['match_tags'];
88
+ if (!isset($arg['match_author'])) $arg['match_author'] = @$options['match_author'];
89
+ if (!isset($arg['age'])) $arg['age'] = @$options['age'];
90
+ if (!isset($arg['custom'])) $arg['custom'] = @$options['custom'];
91
+ if (!isset($arg['sort'])) $arg['sort'] = @$options['sort'];
92
+ if (!isset($arg['status'])) $arg['status'] = @$options['status'];
93
+
94
+ // just for recent_posts
95
+ if (!isset($arg['date_modified'])) $arg['date_modified'] = @$options['date_modified'];
96
+
97
+ // just for recent_comments
98
+ if (!isset($arg['group_by'])) $arg['group_by'] = @$options['group_by'];
99
+ if (!isset($arg['group_template'])) $arg['group_template'] = stripslashes(@$options['group_template']);
100
+ if (!isset($arg['show_type'])) $arg['show_type'] = @$options['show_type'];
101
+ if (!isset($arg['no_author_comments'])) $arg['no_author_comments'] = @$options['no_author_comments'];
102
+ if (!isset($arg['no_user_comments'])) $arg['no_user_comments'] = @$options['no_user_comments'];
103
+ if (!isset($arg['unique'])) $arg['unique'] = @$options['unique'];
104
+
105
+ // just for similar_posts[feed]
106
+ if (!isset($arg['combine'])) $arg['combine'] = @$options['crossmatch'];
107
+ if (!isset($arg['weight_content'])) $arg['weight_content'] = @$options['weight_content'];
108
+ if (!isset($arg['weight_title'])) $arg['weight_title'] = @$options['weight_title'];
109
+ if (!isset($arg['weight_tags'])) $arg['weight_tags'] = @$options['weight_tags'];
110
+ if (!isset($arg['num_terms'])) $arg['num_terms'] = stripslashes(@$options['num_terms']);
111
+ if (!isset($arg['term_extraction'])) $arg['term_extraction'] = @$options['term_extraction'];
112
+ if (!isset($arg['hand_links'])) $arg['hand_links'] = @$options['hand_links'];
113
+
114
+ // just for other_posts
115
+ if (!isset($arg['orderby'])) $arg['orderby'] = stripslashes(@$options['orderby']);
116
+ if (!isset($arg['orderby_order'])) $arg['orderby_order'] = @$options['orderby_order'];
117
+ if (!isset($arg['orderby_case'])) $arg['orderby_case'] = @$options['orderby_case'];
118
+
119
+ // the last options cannot be set via arguments
120
+ $arg['stripcodes'] = @$options['stripcodes'];
121
+ $arg['utf8'] = @$options['utf8'];
122
+ $arg['cjk'] = @$options['cjk'];
123
+ $arg['use_stemmer'] = @$options['use_stemmer'];
124
+ $arg['batch'] = @$options['batch'];
125
+ $arg['content_filter'] = @$options['content_filter'];
126
+ $arg['widget_parameters'] = stripslashes(@$options['widget_parameters']);
127
+ $arg['widget_condition'] = stripslashes(@$options['widget_condition']);
128
+ $arg['feed_on'] = @$options['feed_on'];
129
+ $arg['feed_priority'] = @$options['feed_priority'];
130
+ $arg['feed_parameters'] = stripslashes(@$options['feed_parameters']);
131
+ $arg['append_on'] = @$options['append_on'];
132
+ $arg['append_priority'] = @$options['append_priority'];
133
+ $arg['append_parameters'] = stripslashes(@$options['append_parameters']);
134
+ $arg['append_condition'] = stripslashes(@$options['append_condition']);
135
+ $arg['exclude_users'] = @$options['exclude_users'];
136
+ $arg['count_home'] = @$options['count_home'];
137
+ $arg['count_feed'] = @$options['count_feed'];
138
+ $arg['count_single'] = @$options['count_single'];
139
+ $arg['count_archive'] = @$options['count_archive'];
140
+ $arg['count_category'] = @$options['count_category'];
141
+ $arg['count_page'] = @$options['count_page'];
142
+ $arg['count_search'] = @$options['count_search'];
143
+
144
+ return $arg;
145
+ }
146
+
147
+ function ppl_prepare_template($template) {
148
+ // Now we process the output_template to find the embedded tags which are to be replaced
149
+ // with values taken from the database.
150
+ // A tag is of the form, {tag:ext}, where the tag part will be evaluated and replaced
151
+ // and the optional ext part provides extra data pertinent to that tag
152
+
153
+
154
+ preg_match_all('/{((?:[^{}]|{[^{}]*})*)}/', $template, $matches);
155
+ $translations = array();
156
+ if(is_array($matches)){
157
+
158
+ foreach($matches[1] as $match) {
159
+ if(strpos($match,':')!==false){
160
+ list($tag, $ext) = explode(':', $match, 2);
161
+ } else {
162
+ $tag = $match;
163
+ $ext = false;
164
+ }
165
+ $action = output_tag_action($tag);
166
+ if (function_exists($action)) {
167
+ // store the action that instantiates the tag
168
+ $translations['acts'][] = $action;
169
+ // add the tag in a form ready to use in translation later
170
+ $translations['fulltags'][] = '{'.$match.'}';
171
+ // the extra data if any
172
+ $translations['exts'][] = $ext;
173
+ }
174
+ }
175
+ }
176
+ return $translations;
177
+ }
178
+
179
+ function ppl_expand_template($result, $template, $translations, $option_key) {
180
+ global $wpdb, $wp_version;
181
+ $replacements = array();
182
+
183
+ if(array_key_exists('fulltags',$translations)){
184
+ $numtags = count($translations['fulltags']);
185
+ for ($i = 0; $i < $numtags; $i++) {
186
+ $fulltag = $translations['fulltags'][$i];
187
+ $act = $translations['acts'][$i];
188
+ $ext = $translations['exts'][$i];
189
+ $replacements[$fulltag] = $act($option_key, $result, $ext);
190
+ }
191
+ }
192
+ // Replace every valid tag with its value
193
+ $tmp = strtr($template, $replacements)."\n";
194
+ return $tmp;
195
+ }
196
+
197
+
198
+ function ppl_sort_items($sort, $results, $option_key, $group_template, $items) {
199
+ $translations1 = ppl_prepare_template($sort['by1']);
200
+ foreach ($results as $result) {
201
+ $key1 = ppl_expand_template($result, $sort['by1'], $translations1, $option_key);
202
+ if ($sort['case1'] !== 'false') $key1 = strtolower($key1);
203
+ $keys1[] = $key1;
204
+ }
205
+ if ($sort['by2'] !== '') {
206
+ $translations2 = ppl_prepare_template($sort['by2']);
207
+ foreach ($results as $result) {
208
+ $key2 = ppl_expand_template($result, $sort['by2'], $translations2, $option_key);
209
+ if ($sort['case2'] !== 'false') $key2 = strtolower($key2);
210
+ $keys2[] = $key2;
211
+ }
212
+ }
213
+ if (!empty($keys2)) {
214
+ array_multisort($keys1, intval($sort['order1']), $keys2, intval($sort['order2']), $results, $items);
215
+ } else {
216
+ array_multisort($keys1, intval($sort['order1']), $results, $items);
217
+ }
218
+ // merge the group titles into the items
219
+ if ($group_template) {
220
+ $group_translations = ppl_prepare_template($group_template);
221
+ $prev_key = '';
222
+ $insertions = 0;
223
+ foreach ($keys1 as $n => $key) {
224
+ if ($prev_key !== $key) {
225
+ array_splice($items, $n+$insertions, 0, ppl_expand_template($results[$n], $group_template, $group_translations, $option_key));
226
+ $insertions++;
227
+ }
228
+ $prev_key = $key;
229
+ }
230
+ }
231
+ return $items;
232
+ }
233
+
234
+ // the $post global can be overwritten by the use of $wp_query so we go back to the source
235
+ // note the addition of a 'manual overide' allowing the current posts to me marked by similar_posts_mark_current for example
236
+ function ppl_current_post_id ($manual_current_ID = -1) {
237
+ $the_ID = -1;
238
+ if ($manual_current_ID > 0) {
239
+ $the_ID = $manual_current_ID;
240
+ } else if (isset($GLOBALS['wp_the_query'])) {
241
+ $the_ID = $GLOBALS['wp_the_query']->post->ID;
242
+ if (!$the_ID) {
243
+ $the_ID = $GLOBALS['wp_the_query']->posts[0]->ID;
244
+ }
245
+ } else {
246
+ $the_ID = $GLOBALS['post']->ID;
247
+ }
248
+ return $the_ID;
249
+ }
250
+
251
+
252
+ /*
253
+
254
+ Functions to fill in the WHERE part of the workhorse SQL
255
+
256
+ */
257
+
258
+ function where_match_author() {
259
+ $current_author = $GLOBALS['wp_the_query']->post->post_author;
260
+ return "post_author = $current_author";
261
+ }
262
+
263
+ function where_match_tags($match_tags) {
264
+ global $wpdb, $wp_version;
265
+ $args = array('fields' => 'ids');
266
+ $tag_ids = wp_get_object_terms(ppl_current_post_id(), 'post_tag', $args);
267
+ if ( is_array($tag_ids) && count($tag_ids) > 0 ) {
268
+ if ($match_tags === 'any') {
269
+ $ids = get_objects_in_term($tag_ids, 'post_tag');
270
+ } else {
271
+ $ids = array();
272
+ foreach ($tag_ids as $tag_id){
273
+ if (count($ids) > 0) {
274
+ $ids = array_intersect($ids, get_objects_in_term($tag_id, 'post_tag'));
275
+ } else {
276
+ $ids = get_objects_in_term($tag_id, 'post_tag');
277
+ }
278
+ }
279
+ }
280
+ if ( is_array($ids) && count($ids) > 0 ) {
281
+ $ids = array_unique($ids);
282
+ $out_posts = "'" . implode("', '", $ids) . "'";
283
+ $sql = "$wpdb->posts.ID IN ($out_posts)";
284
+ } else {
285
+ $sql = "1 = 2";
286
+ }
287
+ } else {
288
+ $sql = "1 = 2";
289
+ }
290
+ return $sql;
291
+ }
292
+
293
+ function where_show_pages($show_pages, $show_attachments='false') {
294
+ if (function_exists('get_post_type')) {
295
+ $typelist = array();
296
+ if ($show_attachments === 'true') {$typelist[] = "'attachment'";};
297
+ if ($show_pages === 'true') {$typelist[] = "'page'"; $typelist[] = "'post'";}
298
+ else if ($show_pages === 'false') {$typelist[] = "'post'";}
299
+ else if ($show_pages === 'but') {$typelist[] = "'page'";};
300
+ if (count($typelist)===1) {
301
+ $sql = "post_type=$typelist[0]";
302
+ } else {
303
+ $sql = "post_type IN (" . implode(',',$typelist) . ")";
304
+ }
305
+ } else {
306
+ if ($show_pages === 'true') $sql = "post_status IN ('publish', 'static')";
307
+ else if ($show_pages === 'false') $sql = "post_status = 'publish'";
308
+ else if ($show_pages === 'but') $sql = "post_status = 'static'";
309
+ }
310
+ return $sql;
311
+ }
312
+
313
+ function where_show_status($status, $include_inherit='false') {
314
+ $set = array();
315
+ $status = (array) $status;
316
+ // a quick way of allowing for attachments having status=inherit
317
+ if ($include_inherit === 'true') $status['inherit'] = 'true';
318
+ foreach ($status as $name => $state) {
319
+ if ($state === 'true') $set[] = "'$name'";
320
+ }
321
+ if ($set) {
322
+ $result = implode(',', $set);
323
+ return "post_status IN ($result)";
324
+ } else {
325
+ return "1 = 2";
326
+ }
327
+ }
328
+
329
+ // a replacement, for WP < 2.3, ONLY category children
330
+ if (!function_exists('get_term_children')) {
331
+ function get_term_children($term, $taxonomy) {
332
+ if ($taxonomies !== 'category') return array();
333
+ return get_categories('child_of='.$term);
334
+ }
335
+ }
336
+
337
+
338
+ // a replacement, for WP < 2.3, ONLY to get posts with given category IDs
339
+ if (!function_exists('get_objects_in_term')) {
340
+ function get_objects_in_term($terms, $taxonomies) {
341
+ global $wpdb;
342
+ if ($taxonomies !== 'category') return array();
343
+ $terms = "'" . implode("', '", $terms) . "'";
344
+ $object_ids = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE category_id IN ($terms)");
345
+ if (!$object_ids) return array();
346
+ return $object_ids;
347
+ }
348
+ }
349
+
350
+ function where_match_category() {
351
+ global $wpdb, $wp_version;
352
+ $cat_ids = '';
353
+ foreach(get_the_category() as $cat) {
354
+ if ($cat->cat_ID) $cat_ids .= $cat->cat_ID . ',';
355
+ }
356
+ $cat_ids = rtrim($cat_ids, ',');
357
+ $catarray = explode(',', $cat_ids);
358
+ foreach ( $catarray as $cat ) {
359
+ $catarray = array_merge($catarray, get_term_children($cat, 'category'));
360
+ }
361
+ $catarray = array_unique($catarray);
362
+ $ids = get_objects_in_term($catarray, 'category');
363
+ $ids = array_unique($ids);
364
+ if ( is_array($ids) && count($ids) > 0 ) {
365
+ $out_posts = "'" . implode("', '", $ids) . "'";
366
+ $sql = "$wpdb->posts.ID IN ($out_posts)";
367
+ } else {
368
+ $sql = "1 = 2";
369
+ }
370
+ return $sql;
371
+ }
372
+
373
+ function where_included_cats($included_cats) {
374
+ global $wpdb, $wp_version;
375
+ $catarray = explode(',', $included_cats);
376
+ foreach ( $catarray as $cat ) {
377
+ $catarray = array_merge($catarray, get_term_children($cat, 'category'));
378
+ }
379
+ $catarray = array_unique($catarray);
380
+ $ids = get_objects_in_term($catarray, 'category');
381
+ if ( is_array($ids) && count($ids) > 0 ) {
382
+ $ids = array_unique($ids);
383
+ $in_posts = "'" . implode("', '", $ids) . "'";
384
+ $sql = "ID IN ($in_posts)";
385
+ } else {
386
+ $sql = "1 = 2";
387
+ }
388
+ return $sql;
389
+ }
390
+
391
+ function where_excluded_cats($excluded_cats) {
392
+ global $wpdb, $wp_version;
393
+ $catarray = explode(',', $excluded_cats);
394
+ foreach ( $catarray as $cat ) {
395
+ $catarray = array_merge($catarray, get_term_children($cat, 'category'));
396
+ }
397
+ $catarray = array_unique($catarray);
398
+ $ids = get_objects_in_term($catarray, 'category');
399
+ if ( is_array($ids) && count($ids) > 0 ) {
400
+ $out_posts = "'" . implode("', '", $ids) . "'";
401
+ $sql = "$wpdb->posts.ID NOT IN ($out_posts)";
402
+ } else {
403
+ $sql = "1 = 1";
404
+ }
405
+ return $sql;
406
+ }
407
+
408
+ function where_excluded_authors($excluded_authors){
409
+ return "post_author NOT IN ( $excluded_authors )";
410
+ }
411
+
412
+ function where_included_authors($included_authors){
413
+ return "post_author IN ( $included_authors )";
414
+ }
415
+
416
+ function where_excluded_posts($excluded_posts) {
417
+ return "ID NOT IN ( $excluded_posts )";
418
+ }
419
+
420
+ function where_included_posts($included_posts) {
421
+ return "ID IN ( $included_posts )";
422
+ }
423
+
424
+ function where_tag_str($tag_str) {
425
+ global $wpdb;
426
+ if ( strpos($tag_str, ',') !== false ) {
427
+ $intags = explode(',', $tag_str);
428
+ foreach ( (array) $intags as $tag ) {
429
+ $tags[] = sanitize_term_field('name', $tag, 0, 'post_tag', 'db');
430
+ }
431
+ $tag_type = 'any';
432
+ } else if ( strpos($tag_str, '+') !== false ) {
433
+ $intags = explode('+', $tag_str);
434
+ foreach ( (array) $intags as $tag ) {
435
+ $tags[] = sanitize_term_field('name', $tag, 0, 'post_tag', 'db');
436
+ }
437
+ $tag_type = 'all';
438
+ } else {
439
+ $tags[] = sanitize_term_field('name', $tag_str, 0, 'post_tag', 'db');
440
+ $tag_type = 'any';
441
+ }
442
+ $ids = array();
443
+ if ($tag_type == 'any') {
444
+ foreach ($tags as $tag){
445
+ if (is_term($tag, 'post_tag')) {
446
+ $t = get_term_by('name', $tag, 'post_tag');
447
+ $ids = array_merge($ids, get_objects_in_term($t->term_id, 'post_tag'));
448
+ }
449
+ }
450
+ } else {
451
+ foreach ($tags as $tag){
452
+ if (is_term($tag, 'post_tag')) {
453
+ $t = get_term_by('name', $tag, 'post_tag');
454
+ if (count($ids) > 0) {
455
+ $ids = array_intersect($ids, get_objects_in_term($t->term_id, 'post_tag'));
456
+ } else {
457
+ $ids = get_objects_in_term($t->term_id, 'post_tag');
458
+ }
459
+ }
460
+ }
461
+ }
462
+ if ( is_array($ids) && count($ids) > 0 ) {
463
+ $ids = array_unique($ids);
464
+ $out_posts = "'" . implode("', '", $ids) . "'";
465
+ $sql .= "$wpdb->posts.ID IN ($out_posts)";
466
+ } else $sql .= "1 = 2";
467
+ return $sql;
468
+ }
469
+
470
+ // note the addition of a 'manual overide' allowing the current posts to me marked by similar_posts_mark_current for example
471
+ function where_omit_post($manual_current_ID = -1) {
472
+ $postid = ppl_current_post_id($manual_current_ID);
473
+ if ($postid <= 1) $postid = -1;
474
+ return "ID != $postid";
475
+ }
476
+
477
+ function where_just_post() {
478
+ $postid = ppl_current_post_id();
479
+ if ($postid <= 1) $postid = -1;
480
+ return "ID = $postid";
481
+ }
482
+
483
+ function where_hide_pass() {
484
+ return "post_password =''";
485
+ }
486
+
487
+ function where_hide_future() {
488
+ // from wp 2.1 future posts are taken care of by post status
489
+ $time_difference = get_option('gmt_offset');
490
+ $now = gmdate("Y-m-d H:i:s",(time()+($time_difference*3600)));
491
+ $sql = "post_date <= '$now'";
492
+ return $sql;
493
+ }
494
+
495
+ function where_fulltext_match($weight_title, $titleterms, $weight_content, $contentterms, $weight_tags, $tagterms) {
496
+ $wsql = array();
497
+ if ($weight_title) $wsql[] = "MATCH (`title`) AGAINST ( \"$titleterms\" )";
498
+ if ($weight_content) $wsql[] = "MATCH (`content`) AGAINST ( \"$contentterms\" )";
499
+ if ($weight_tags) $wsql[] = "MATCH (`tags`) AGAINST ( \"$tagterms\" )";
500
+ return '(' . implode(' OR ', $wsql) . ') ' ;
501
+ }
502
+
503
+ function where_author_comments() {
504
+ $author_email = get_the_author_email();
505
+ return "'$author_email' != comment_author_email";
506
+ }
507
+
508
+ function where_user_comments() {
509
+ return "user_id = 0";
510
+ }
511
+
512
+ function score_fulltext_match($table_name, $weight_title, $titleterms, $weight_content, $contentterms, $weight_tags, $tagterms, $forced_ids='') {
513
+ global $wpdb;
514
+ $wsql = array();
515
+ if ($weight_title) $wsql[] = "(".number_format($weight_title, 4, '.', '')." * (MATCH (`title`) AGAINST ( \"$titleterms\" )))";
516
+ if ($weight_content) $wsql[] = "(".number_format($weight_content, 4, '.', '')." * (MATCH (`content`) AGAINST ( \"$contentterms\" )))";
517
+ if ($weight_tags) $wsql[] = "(".number_format($weight_tags, 4, '.', '')." * (MATCH (`tags`) AGAINST ( \"$tagterms\" )))";
518
+ if ($forced_ids) {
519
+ // apply a delta function to boost the score for certain IDs
520
+ $fIDs = explode(',', $forced_ids);
521
+ foreach($fIDs as $fID) {
522
+ $wsql[] = "100 * (1 - SIGN(ID ^ $fID))"; // the previous delta was $wsql[] = "100*EXP(-10*POW((ID-$fID),2))";
523
+
524
+ }
525
+ }
526
+ return '(' . implode(' + ', $wsql) . " ) as score FROM `$table_name` LEFT JOIN `$wpdb->posts` ON `pID` = `ID` ";
527
+ }
528
+
529
+ function where_comment_type($comment_type) {
530
+ if ($comment_type === 'comments') $sql = "comment_type = ''";
531
+ elseif ($comment_type === 'trackbacks') $sql = "comment_type != ''";
532
+ return $sql;
533
+ }
534
+
535
+ function where_check_age($direction, $length, $duration) {
536
+ global $wp_version;
537
+ if ('none' === $direction) return '';
538
+ $age = "DATE_SUB(CURDATE(), INTERVAL $length $duration)";
539
+ // we only filter out posts based on age, not pages
540
+ if ('before' === $direction) {
541
+ if (function_exists('get_post_type')) {
542
+ return "(post_date <= $age OR post_type='page')";
543
+ } else {
544
+ return "(post_date <= $age OR post_status='static')";
545
+ }
546
+ } else {
547
+ if (function_exists('get_post_type')) {
548
+ return "(post_date >= $age OR post_type='page')";
549
+ } else {
550
+ return "(post_date >= $age OR post_status='static')";
551
+ }
552
+ }
553
+ }
554
+
555
+ function where_check_custom($key, $op, $value) {
556
+ if ($op === 'EXISTS') {
557
+ return "meta_key = '$key'";
558
+ } else {
559
+ return "(meta_key = '$key' && meta_value $op '$value')";
560
+ }
561
+ }
562
+
563
+ /*
564
+
565
+ End of SQL functions
566
+
567
+ */
568
+
569
+ function ppl_microtime() {
570
+ list($usec, $sec) = explode(" ", microtime());
571
+ return ((float)$usec + (float)$sec);
572
+ }
573
+
574
+ /*
575
+
576
+ Some routines to handle appending output
577
+
578
+ */
579
+
580
+ // array of what to append to posts
581
+ global $ppl_filter_data;
582
+ $ppl_filter_data = array();
583
+
584
+ // each plugin calls this on startup to have content scanned for its own tag
585
+ function ppl_register_post_filter($type, $key, $class, $condition='') {
586
+ global $ppl_filter_data;
587
+ $options = get_option($key);
588
+ $priority = $options[$type . '_priority'];
589
+ $parameters = stripslashes($options[$type . '_parameters']);
590
+ $ppl_filter_data [] = array('type' => $type, 'priority' => $priority, 'class' => $class, 'parameters' => $parameters, 'key' => $key, 'condition' => stripslashes($condition));
591
+ // we want them in decreasing priority
592
+ sort($ppl_filter_data);
593
+ }
594
+
595
+ function ppl_post_filter($content) {
596
+ global $ppl_filter_data;
597
+ foreach ($ppl_filter_data as $data) {
598
+ if (('append' === $data['type'] && !is_feed() && eval($data['condition'])) || ('feed' === $data['type'] && is_feed()) ){
599
+ $content .= call_user_func_array(array($data['class'], 'execute'), array($data['parameters'], '<li>{link}</li>', $data['key']));
600
+ }
601
+ }
602
+ return $content;
603
+ }
604
+
605
+ function ppl_post_filter_init() {
606
+ global $ppl_filter_data;
607
+ if (!$ppl_filter_data) return;
608
+ add_filter('the_content', 'ppl_post_filter', 5);
609
+ }
610
+
611
+ // watch out that the registration functions are called earlier
612
+ add_action ('init', 'ppl_post_filter_init');
613
+
614
+ /*
615
+
616
+ Now some routines to handle content filtering
617
+
618
+ */
619
+
620
+ // the '|'-separated list of valid content filter tags
621
+ global $ppl_filter_tags;
622
+
623
+ // each plugin calls this on startup to have content scanned for its own tag
624
+ function ppl_register_content_filter($tag) {
625
+ global $ppl_filter_tags;
626
+ if (!$ppl_filter_tags) {
627
+ $ppl_filter_tags = $tag;
628
+ } else {
629
+ $tags = explode('|', $ppl_filter_tags);
630
+ $tags[] = $tag;
631
+ $tags = array_unique($tags);
632
+ $ppl_filter_tags = implode('|', $tags);
633
+ }
634
+ }
635
+
636
+
637
+ function ppl_do_replace($matches) {
638
+ return call_user_func(array($matches[1], 'execute'), $matches[2]);
639
+ }
640
+
641
+ function ppl_content_filter($content) {
642
+ global $ppl_filter_tags;
643
+ // replaces every instance of "<!--RecentPosts-->", for example, with the output of the plugin
644
+ // the filter tag can be followed by text which will be used as a parameter string to change the behaviour of the plugin
645
+ return preg_replace_callback("/<!--($ppl_filter_tags)\s*(.*)-->/", "ppl_do_replace", $content);
646
+ }
647
+
648
+ function ppl_content_filter_init() {
649
+ global $ppl_filter_tags;
650
+ if (!$ppl_filter_tags) return;
651
+ add_filter( 'the_content', 'ppl_content_filter', 5 );
652
+ add_filter( 'the_content_rss', 'ppl_content_filter', 5 );
653
+ add_filter( 'the_excerpt', 'ppl_content_filter', 5 );
654
+ add_filter( 'the_excerpt_rss', 'ppl_content_filter', 5 );
655
+ add_filter( 'widget_text', 'ppl_content_filter', 5 );
656
+ }
657
+
658
+ // watch out that the registration functions are called earlier
659
+ add_action ('init', 'ppl_content_filter_init');
660
+ add_action ('init', 'ppl_post_filter_init');
index.php CHANGED
@@ -1,2 +1,2 @@
1
- <?php
2
- // silence is golden
1
+ <?php
2
+ // silence is golden
languages/de/stemmer.php CHANGED
@@ -84,7 +84,7 @@ function de_stemmer_help($section = 'admin/help#search') {
84
  /*
85
  * Function gets as text (parameter) and splits the text into words.
86
  * Then each word is stemmed and the word together with its stem is
87
- * stored in an array (hash).
88
  * As a result the hash is returned and can be used as a lookup table
89
  * to identify words which transform to the same stem.
90
  * For details please compare 'search.module-stem.patch'
@@ -128,7 +128,7 @@ function _de_stemmer_postprocess($wort) {
128
  if (!_de_stemmer_ausnahme($wort)) // check for exceptions
129
  {
130
  $wort = strtr($wort, array('ä' => 'a', 'á' => 'a',
131
- 'ë' => 'e', 'é' => 'e',
132
  'ï' => 'i', 'í' => 'i',
133
  'ö' => 'o', 'ó' => 'o',
134
  'ü' => "u", 'ú' => 'u'
@@ -142,9 +142,9 @@ function _de_stemmer_wortstamm($wort) {
142
  $stamm = de_stemmer_preprocess($wort);
143
 
144
  /*
145
- * R1 is the region after the first non-vowel following a vowel,
146
  or is the null region at the end of the word if there is no such non-vowel.
147
- * R2 is the region after the first non-vowel following a vowel in R1,
148
  or is the null region at the end of the word if there is no such non-vowel.
149
  */
150
 
@@ -156,12 +156,12 @@ function _de_stemmer_wortstamm($wort) {
156
  if ($r1 < 3) {
157
  $r1 = 3;
158
  }
159
-
160
  /* Step 1
161
  Search for the longest among the following suffixes,
162
  (a) e em en ern er es
163
- (b) s (preceded by a valid s-ending)
164
- and delete if in R1.
165
  (Of course the letter of the valid s-ending is not necessarily in R1)
166
  */
167
 
@@ -177,8 +177,8 @@ function _de_stemmer_wortstamm($wort) {
177
  Step 2
178
  Search for the longest among the following suffixes,
179
  (a) en er est
180
- (b) st (preceded by a valid st-ending, itself preceded by at least 3 letters)
181
- and delete if in R1.
182
  */
183
 
184
  if (preg_match('/(en|er|est)$/u', $stamm, $hits, PREG_OFFSET_CAPTURE, $r1)) {
@@ -193,16 +193,16 @@ function _de_stemmer_wortstamm($wort) {
193
  Step 3: d-suffixes ( see http://snowball.tartarus.org/texts/glossary.html )
194
  Search for the longest among the following suffixes, and perform the action indicated.
195
  end ung
196
- delete if in R2
197
  if preceded by ig, delete if in R2 and not preceded by e
198
  ig ik isch
199
  delete if in R2 and not preceded by e
200
  lich heit
201
- delete if in R2
202
  if preceded by er or en, delete if in R1
203
  keit
204
- delete if in R2
205
- if preceded by lich or ig, delete if in R2
206
  ^ means R1 ?
207
  */
208
 
@@ -244,7 +244,7 @@ function _de_stemmer_stoppwort($wort) {
244
  static $stoppworte = array(
245
  'ab', 'aber', 'aber', 'ach', 'acht', 'achte', 'achten', 'achter', 'achtes', 'ag', 'alle', 'allein', 'allem', 'allen', 'aller', 'allerdings', 'alles', 'allgemeinen', 'als', 'als', 'also', 'am', 'an', 'andere', 'anderen', 'andern', 'anders', 'au', 'auch', 'auch', 'auf', 'aus', 'ausser', 'außer', 'ausserdem', 'außerdem',
246
  'bald', 'bei', 'beide', 'beiden', 'beim', 'bekannt', 'bereits', 'besonders', 'besser', 'besten', 'bin', 'bis', 'bisher', 'bist',
247
- 'da', 'dabei', 'dadurch', 'dafür', 'dagegen', 'daher', 'dahin', 'dahinter', 'damals', 'damit', 'danach', 'daneben', 'dank', 'dann', 'daran', 'darauf', 'daraus', 'darf', 'darfst', 'darin', 'darüber', 'darum', 'darunter', 'das', 'das', 'dasein', 'daselbst', 'dass', 'daß', 'dasselbe', 'davon', 'davor', 'dazu', 'dazwischen', 'dein', 'deine', 'deinem', 'deiner', 'dem', 'dementsprechend', 'demgegenüber', 'demgemäss', 'demgemäß', 'demselben', 'demzufolge', 'den', 'denen', 'denn', 'denn', 'denselben', 'der', 'deren', 'derjenige', 'derjenigen', 'dermassen', 'dermaßen', 'derselbe', 'derselben', 'des', 'deshalb', 'desselben', 'dessen', 'deswegen', 'd.h', 'dich', 'die', 'diejenige', 'diejenigen', 'dies', 'diese', 'dieselbe', 'dieselben', 'diesem', 'diesen', 'dieser', 'dieses', 'dir', 'doch', 'dort', 'drei', 'drin', 'dritte', 'dritten', 'dritter', 'drittes', 'du', 'durch', 'durchaus',
248
  'eben', 'ebenso', 'eigen', 'eigene', 'eigenen', 'eigener', 'eigenes', 'ein', 'einander', 'eine', 'einem', 'einen', 'einer', 'eines', 'einige', 'einigen', 'einiger', 'einiges', 'einmal', 'einmal', 'eins', 'elf', 'en', 'ende', 'endlich', 'entweder', 'entweder', 'er', 'ernst', 'erst', 'erste', 'ersten', 'erster', 'erstes', 'es', 'etwa', 'etwas', 'euch',
249
  'früher', 'fünf', 'fünfte', 'fünften', 'fünfter', 'fünftes', 'für',
250
  'gab', 'ganz', 'ganze', 'ganzen', 'ganzer', 'ganzes', 'gar', 'gedurft', 'gegen', 'gegenüber', 'gehabt', 'gehen', 'geht', 'gekannt', 'gekonnt', 'gemacht', 'gemocht', 'gemusst', 'genug', 'gerade', 'gern', 'gesagt', 'gesagt', 'geschweige', 'gewesen', 'gewollt', 'geworden', 'gibt', 'ging', 'gleich', 'gott', 'gross', 'groß', 'grosse', 'große', 'grossen', 'großen', 'grosser', 'großer', 'grosses', 'großes', 'gut', 'gute', 'guter', 'gutes',
@@ -255,14 +255,14 @@ function _de_stemmer_stoppwort($wort) {
255
  'lang', 'lange', 'lange', 'leicht', 'leide', 'lieber', 'los',
256
  'machen', 'macht', 'machte', 'mag', 'magst', 'mahn', 'man', 'manche', 'manchem', 'manchen', 'mancher', 'manches', 'mann', 'mehr', 'mein', 'meine', 'meinem', 'meinen', 'meiner', 'meines', 'mich', 'mir', 'mit', 'mittel', 'mochte', 'möchte', 'mochten', 'mögen', 'möglich', 'mögt', 'morgen', 'muss', 'muß', 'müssen', 'musst', 'müsst', 'musste', 'mussten',
257
  'na', 'nach', 'nachdem', 'nahm', 'natürlich', 'neben', 'nein', 'neue', 'neuen', 'neun', 'neunte', 'neunten', 'neunter', 'neuntes', 'nicht', 'nicht', 'nichts', 'nie', 'niemand', 'niemandem', 'niemanden', 'noch', 'nun', 'nun', 'nur',
258
- 'ob', 'oben', 'oder', 'oder', 'offen', 'oft', 'oft', 'ohne',
259
  'recht', 'rechte', 'rechten', 'rechter', 'rechtes', 'richtig', 'rund',
260
  'sa', 'sache', 'sagt', 'sagte', 'sah', 'satt', 'schon', 'sechs', 'sechste', 'sechsten', 'sechster', 'sechstes', 'sehr', 'sei', 'sei', 'seid', 'seien', 'sein', 'seine', 'seinem', 'seinen', 'seiner', 'seines', 'seit', 'seitdem', 'selbst', 'selbst', 'sich', 'sie', 'sieben', 'siebente', 'siebenten', 'siebenter', 'siebentes', 'sind', 'so', 'solang', 'solche', 'solchem', 'solchen', 'solcher', 'solches', 'soll', 'sollen', 'sollte', 'sollten', 'sondern', 'sonst', 'sowie', 'später', 'statt',
261
  'tat', 'teil', 'tel', 'tritt', 'trotzdem', 'tun',
262
  'über', 'überhaupt', 'übrigens', 'uhr', 'um', 'und', 'und?', 'uns', 'unser', 'unsere', 'unserer', 'unter',
263
  'vergangenen', 'viel', 'viele', 'vielem', 'vielen', 'vielleicht', 'vier', 'vierte', 'vierten', 'vierter', 'viertes', 'vom', 'von', 'vor',
264
  'wahr?', 'während', 'währenddem', 'währenddessen', 'wann', 'war', 'wäre', 'waren', 'wart', 'warum', 'was', 'wegen', 'weil', 'weit', 'weiter', 'weitere', 'weiteren', 'weiteres', 'welche', 'welchem', 'welchen', 'welcher', 'welches', 'wem', 'wen', 'wenig', 'wenig', 'wenige', 'weniger', 'weniges', 'wenigstens', 'wenn', 'wenn', 'wer', 'werde', 'werden', 'werdet', 'wessen', 'wie', 'wie', 'wieder', 'will', 'willst', 'wir', 'wird', 'wirklich', 'wirst', 'wo', 'wohl', 'wollen', 'wollt', 'wollte', 'wollten', 'worden', 'wurde', 'würde', 'wurden', 'würden',
265
- 'z.b', 'zehn', 'zehnte', 'zehnten', 'zehnter', 'zehntes', 'zeit', 'zu', 'zuerst', 'zugleich', 'zum', 'zum', 'zunächst', 'zur', 'zurück', 'zusammen', 'zwanzig', 'zwar', 'zwar', 'zwei', 'zweite', 'zweiten', 'zweiter', 'zweites', 'zwischen', 'zwölf'
266
  );
267
 
268
  return in_array($wort, $stoppworte);
@@ -273,7 +273,7 @@ function _de_stemmer_stoppwort($wort) {
273
  first try to set up a list of exceptions
274
  */
275
  function _de_stemmer_ausnahme(&$wort)
276
- { static $de_stemmer_ausnahmen = array (
277
  'schön' => 'schön', // !schon
278
  'blüt' => 'blüt', // Blüte (NICHT Blut)
279
  'kannt' => 'kenn',
@@ -304,11 +304,11 @@ $StemCache = array();
304
 
305
  function stem($word) {
306
  global $StemCache;
307
- if (!isset($StemCache[$word])) {
308
  $stemmedword = _de_stemmer_wortstamm($word);
309
- $StemCache[$word] = $stemmedword;
310
  }
311
- else {
312
  $stemmedword = $StemCache[$word] ;
313
  }
314
  return $stemmedword;
84
  /*
85
  * Function gets as text (parameter) and splits the text into words.
86
  * Then each word is stemmed and the word together with its stem is
87
+ * stored in an array (hash).
88
  * As a result the hash is returned and can be used as a lookup table
89
  * to identify words which transform to the same stem.
90
  * For details please compare 'search.module-stem.patch'
128
  if (!_de_stemmer_ausnahme($wort)) // check for exceptions
129
  {
130
  $wort = strtr($wort, array('ä' => 'a', 'á' => 'a',
131
+ 'ë' => 'e', 'é' => 'e',
132
  'ï' => 'i', 'í' => 'i',
133
  'ö' => 'o', 'ó' => 'o',
134
  'ü' => "u", 'ú' => 'u'
142
  $stamm = de_stemmer_preprocess($wort);
143
 
144
  /*
145
+ * R1 is the region after the first non-vowel following a vowel,
146
  or is the null region at the end of the word if there is no such non-vowel.
147
+ * R2 is the region after the first non-vowel following a vowel in R1,
148
  or is the null region at the end of the word if there is no such non-vowel.
149
  */
150
 
156
  if ($r1 < 3) {
157
  $r1 = 3;
158
  }
159
+
160
  /* Step 1
161
  Search for the longest among the following suffixes,
162
  (a) e em en ern er es
163
+ (b) s (preceded by a valid s-ending)
164
+ and delete if in R1.
165
  (Of course the letter of the valid s-ending is not necessarily in R1)
166
  */
167
 
177
  Step 2
178
  Search for the longest among the following suffixes,
179
  (a) en er est
180
+ (b) st (preceded by a valid st-ending, itself preceded by at least 3 letters)
181
+ and delete if in R1.
182
  */
183
 
184
  if (preg_match('/(en|er|est)$/u', $stamm, $hits, PREG_OFFSET_CAPTURE, $r1)) {
193
  Step 3: d-suffixes ( see http://snowball.tartarus.org/texts/glossary.html )
194
  Search for the longest among the following suffixes, and perform the action indicated.
195
  end ung
196
+ delete if in R2
197
  if preceded by ig, delete if in R2 and not preceded by e
198
  ig ik isch
199
  delete if in R2 and not preceded by e
200
  lich heit
201
+ delete if in R2
202
  if preceded by er or en, delete if in R1
203
  keit
204
+ delete if in R2
205
+ if preceded by lich or ig, delete if in R2
206
  ^ means R1 ?
207
  */
208
 
244
  static $stoppworte = array(
245
  'ab', 'aber', 'aber', 'ach', 'acht', 'achte', 'achten', 'achter', 'achtes', 'ag', 'alle', 'allein', 'allem', 'allen', 'aller', 'allerdings', 'alles', 'allgemeinen', 'als', 'als', 'also', 'am', 'an', 'andere', 'anderen', 'andern', 'anders', 'au', 'auch', 'auch', 'auf', 'aus', 'ausser', 'außer', 'ausserdem', 'außerdem',
246
  'bald', 'bei', 'beide', 'beiden', 'beim', 'bekannt', 'bereits', 'besonders', 'besser', 'besten', 'bin', 'bis', 'bisher', 'bist',
247
+ 'da', 'dabei', 'dadurch', 'dafür', 'dagegen', 'daher', 'dahin', 'dahinter', 'damals', 'damit', 'danach', 'daneben', 'dank', 'dann', 'daran', 'darauf', 'daraus', 'darf', 'darfst', 'darin', 'darüber', 'darum', 'darunter', 'das', 'das', 'dasein', 'daselbst', 'dass', 'daß', 'dasselbe', 'davon', 'davor', 'dazu', 'dazwischen', 'dein', 'deine', 'deinem', 'deiner', 'dem', 'dementsprechend', 'demgegenüber', 'demgemäss', 'demgemäß', 'demselben', 'demzufolge', 'den', 'denen', 'denn', 'denn', 'denselben', 'der', 'deren', 'derjenige', 'derjenigen', 'dermassen', 'dermaßen', 'derselbe', 'derselben', 'des', 'deshalb', 'desselben', 'dessen', 'deswegen', 'd.h', 'dich', 'die', 'diejenige', 'diejenigen', 'dies', 'diese', 'dieselbe', 'dieselben', 'diesem', 'diesen', 'dieser', 'dieses', 'dir', 'doch', 'dort', 'drei', 'drin', 'dritte', 'dritten', 'dritter', 'drittes', 'du', 'durch', 'durchaus',
248
  'eben', 'ebenso', 'eigen', 'eigene', 'eigenen', 'eigener', 'eigenes', 'ein', 'einander', 'eine', 'einem', 'einen', 'einer', 'eines', 'einige', 'einigen', 'einiger', 'einiges', 'einmal', 'einmal', 'eins', 'elf', 'en', 'ende', 'endlich', 'entweder', 'entweder', 'er', 'ernst', 'erst', 'erste', 'ersten', 'erster', 'erstes', 'es', 'etwa', 'etwas', 'euch',
249
  'früher', 'fünf', 'fünfte', 'fünften', 'fünfter', 'fünftes', 'für',
250
  'gab', 'ganz', 'ganze', 'ganzen', 'ganzer', 'ganzes', 'gar', 'gedurft', 'gegen', 'gegenüber', 'gehabt', 'gehen', 'geht', 'gekannt', 'gekonnt', 'gemacht', 'gemocht', 'gemusst', 'genug', 'gerade', 'gern', 'gesagt', 'gesagt', 'geschweige', 'gewesen', 'gewollt', 'geworden', 'gibt', 'ging', 'gleich', 'gott', 'gross', 'groß', 'grosse', 'große', 'grossen', 'großen', 'grosser', 'großer', 'grosses', 'großes', 'gut', 'gute', 'guter', 'gutes',
255
  'lang', 'lange', 'lange', 'leicht', 'leide', 'lieber', 'los',
256
  'machen', 'macht', 'machte', 'mag', 'magst', 'mahn', 'man', 'manche', 'manchem', 'manchen', 'mancher', 'manches', 'mann', 'mehr', 'mein', 'meine', 'meinem', 'meinen', 'meiner', 'meines', 'mich', 'mir', 'mit', 'mittel', 'mochte', 'möchte', 'mochten', 'mögen', 'möglich', 'mögt', 'morgen', 'muss', 'muß', 'müssen', 'musst', 'müsst', 'musste', 'mussten',
257
  'na', 'nach', 'nachdem', 'nahm', 'natürlich', 'neben', 'nein', 'neue', 'neuen', 'neun', 'neunte', 'neunten', 'neunter', 'neuntes', 'nicht', 'nicht', 'nichts', 'nie', 'niemand', 'niemandem', 'niemanden', 'noch', 'nun', 'nun', 'nur',
258
+ 'ob', 'oben', 'oder', 'oder', 'offen', 'oft', 'oft', 'ohne',
259
  'recht', 'rechte', 'rechten', 'rechter', 'rechtes', 'richtig', 'rund',
260
  'sa', 'sache', 'sagt', 'sagte', 'sah', 'satt', 'schon', 'sechs', 'sechste', 'sechsten', 'sechster', 'sechstes', 'sehr', 'sei', 'sei', 'seid', 'seien', 'sein', 'seine', 'seinem', 'seinen', 'seiner', 'seines', 'seit', 'seitdem', 'selbst', 'selbst', 'sich', 'sie', 'sieben', 'siebente', 'siebenten', 'siebenter', 'siebentes', 'sind', 'so', 'solang', 'solche', 'solchem', 'solchen', 'solcher', 'solches', 'soll', 'sollen', 'sollte', 'sollten', 'sondern', 'sonst', 'sowie', 'später', 'statt',
261
  'tat', 'teil', 'tel', 'tritt', 'trotzdem', 'tun',
262
  'über', 'überhaupt', 'übrigens', 'uhr', 'um', 'und', 'und?', 'uns', 'unser', 'unsere', 'unserer', 'unter',
263
  'vergangenen', 'viel', 'viele', 'vielem', 'vielen', 'vielleicht', 'vier', 'vierte', 'vierten', 'vierter', 'viertes', 'vom', 'von', 'vor',
264
  'wahr?', 'während', 'währenddem', 'währenddessen', 'wann', 'war', 'wäre', 'waren', 'wart', 'warum', 'was', 'wegen', 'weil', 'weit', 'weiter', 'weitere', 'weiteren', 'weiteres', 'welche', 'welchem', 'welchen', 'welcher', 'welches', 'wem', 'wen', 'wenig', 'wenig', 'wenige', 'weniger', 'weniges', 'wenigstens', 'wenn', 'wenn', 'wer', 'werde', 'werden', 'werdet', 'wessen', 'wie', 'wie', 'wieder', 'will', 'willst', 'wir', 'wird', 'wirklich', 'wirst', 'wo', 'wohl', 'wollen', 'wollt', 'wollte', 'wollten', 'worden', 'wurde', 'würde', 'wurden', 'würden',
265
+ 'z.b', 'zehn', 'zehnte', 'zehnten', 'zehnter', 'zehntes', 'zeit', 'zu', 'zuerst', 'zugleich', 'zum', 'zum', 'zunächst', 'zur', 'zurück', 'zusammen', 'zwanzig', 'zwar', 'zwar', 'zwei', 'zweite', 'zweiten', 'zweiter', 'zweites', 'zwischen', 'zwölf'
266
  );
267
 
268
  return in_array($wort, $stoppworte);
273
  first try to set up a list of exceptions
274
  */
275
  function _de_stemmer_ausnahme(&$wort)
276
+ { static $de_stemmer_ausnahmen = array (
277
  'schön' => 'schön', // !schon
278
  'blüt' => 'blüt', // Blüte (NICHT Blut)
279
  'kannt' => 'kenn',
304
 
305
  function stem($word) {
306
  global $StemCache;
307
+ if (!isset($StemCache[$word])) {
308
  $stemmedword = _de_stemmer_wortstamm($word);
309
+ $StemCache[$word] = $stemmedword;
310
  }
311
+ else {
312
  $stemmedword = $StemCache[$word] ;
313
  }
314
  return $stemmedword;
languages/de/stopwords.php CHANGED
@@ -1,4 +1,4 @@
1
  <?php
2
  // the list of common words we want to ignore. NB anything shorter than 4 characters is knocked by the plugin and doesn't need to figure here
3
- $overusedwords = array("aber", "alle", "allem", "allen", "aller", "alles", "also", "ander", "andere", "anderem", "anderen", "anderer", "anderes", "anderm", "andern", "anderr", "anders", "auch", "bist", "damit", "dann", "derselbe", "derselben", "denselben", "desselben", "demselben", "dieselbe", "dieselben", "dasselbe", "dazu", "dein", "deine", "deinem", "deinen", "deiner", "deines", "denn", "derer", "dessen", "dich", "dies", "diese", "diesem", "diesen", "dieser", "dieses", "doch", "dort", "durch", "eine", "einem", "einen", "einer", "eines", "einig", "einige", "einigem", "einigen", "einiger", "einiges", "einmal", "etwas", "euer", "eure", "eurem", "euren", "eurer", "eures", "gegen", "gewesen", "habe", "haben", "hatte", "hatten", "hier", "hinter", "mich", "ihre", "ihrem", "ihren", "ihrer", "ihres", "euch", "indem", "jede", "jedem", "jeden", "jeder", "jedes", "jene", "jenem", "jenen", "jener", "jenes", "jetzt", "kann", "kein", "keine", "keinem", "keinen", "keiner", "keines", "k�nnen", "k�nnte", "machen", "manche", "manchem", "manchen", "mancher", "manches", "mein", "meine", "meinem", "meinen", "meiner", "meines", "muss", "musste", "nach", "nicht", "nichts", "noch", "oder", "ohne", "sehr", "sein", "seine", "seinem", "seinen", "seiner", "seines", "selbst", "sich", "ihnen", "sind", "solche", "solchem", "solchen", "solcher", "solches", "soll", "sollte", "sondern", "sonst", "�ber", "unse", "unsem", "unsen", "unser", "unses", "unter", "viel", "w�hrend", "waren", "warst", "weil", "weiter", "welche", "welchem", "welchen", "welcher", "welches", "wenn", "werde", "werden", "wieder", "will", "wird", "wirst", "wollen", "wollte", "w�rde", "w�rden", "zwar", "zwischen");
4
- ?>
1
  <?php
2
  // the list of common words we want to ignore. NB anything shorter than 4 characters is knocked by the plugin and doesn't need to figure here
3
+ $overusedwords = array("aber", "alle", "allem", "allen", "aller", "alles", "also", "ander", "andere", "anderem", "anderen", "anderer", "anderes", "anderm", "andern", "anderr", "anders", "auch", "bist", "damit", "dann", "derselbe", "derselben", "denselben", "desselben", "demselben", "dieselbe", "dieselben", "dasselbe", "dazu", "dein", "deine", "deinem", "deinen", "deiner", "deines", "denn", "derer", "dessen", "dich", "dies", "diese", "diesem", "diesen", "dieser", "dieses", "doch", "dort", "durch", "eine", "einem", "einen", "einer", "eines", "einig", "einige", "einigem", "einigen", "einiger", "einiges", "einmal", "etwas", "euer", "eure", "eurem", "euren", "eurer", "eures", "gegen", "gewesen", "habe", "haben", "hatte", "hatten", "hier", "hinter", "mich", "ihre", "ihrem", "ihren", "ihrer", "ihres", "euch", "indem", "jede", "jedem", "jeden", "jeder", "jedes", "jene", "jenem", "jenen", "jener", "jenes", "jetzt", "kann", "kein", "keine", "keinem", "keinen", "keiner", "keines", "können", "könnte", "machen", "manche", "manchem", "manchen", "mancher", "manches", "mein", "meine", "meinem", "meinen", "meiner", "meines", "muss", "musste", "nach", "nicht", "nichts", "noch", "oder", "ohne", "sehr", "sein", "seine", "seinem", "seinen", "seiner", "seines", "selbst", "sich", "ihnen", "sind", "solche", "solchem", "solchen", "solcher", "solches", "soll", "sollte", "sondern", "sonst", "über", "unse", "unsem", "unsen", "unser", "unses", "unter", "viel", "während", "waren", "warst", "weil", "weiter", "welche", "welchem", "welchen", "welcher", "welches", "wenn", "werde", "werden", "wieder", "will", "wird", "wirst", "wollen", "wollte", "würde", "würden", "zwar", "zwischen");
4
+ ?>
languages/en/stemmer.php CHANGED
@@ -1,333 +1,333 @@
1
- <?php
2
- /*
3
- Creado por Cesar Rodas para el proyecto Saddor.com
4
- Este Stemmer esta basado en el argoritmo de Snowball Stemmer.
5
- saddor@gmail.com
6
- Este programa esta bajo licencia GNU
7
- */
8
- if (!defined("ENGLISHSTEMMER"))
9
- {
10
- define("ENGLISHSTEMMER",1,false);
11
- class EnglishStemmer
12
- {
13
- var $regex_consonant = '(?:[bcdfghjklmnpqrstvwxz]|(?<=[aeiou])y|^y)';
14
- var $regex_vowel = '(?:[aeiou]|(?<![aeiou])y)';
15
-
16
- function Stem($word)
17
- {
18
- if (strlen($word) <= 2) {
19
- return $word;
20
- }
21
-
22
- $word = $this->step1ab($word);
23
- $word = $this->step1c($word);
24
- $word = $this->step2($word);
25
- $word = $this->step3($word);
26
- $word = $this->step4($word);
27
- $word = $this->step5($word);
28
- /*
29
- Esta parte esta editado por cesar rodas,
30
- no quiero que me muestre ' (apostrofe) al final
31
- */
32
- if (substr($word,-1,1) == "'")
33
- $word = substr($word,0,strlen($word) -1 );
34
- return $word;
35
- }
36
-
37
-
38
- function step1ab($word)
39
- {
40
- if (substr($word, -1) == 's') {
41
-
42
- $this->replace($word, 'sses', 'ss')
43
- OR $this->replace($word, 'ies', 'i')
44
- OR $this->replace($word, 'ss', 'ss')
45
- OR $this->replace($word, 's', '');
46
- }
47
-
48
- if (substr($word, -2, 1) != 'e' OR !$this->replace($word, 'eed', 'ee', 0)) { // First rule
49
- $v = $this->regex_vowel;
50
-
51
- if ( preg_match("#$v+#", substr($word, 0, -3)) && $this->replace($word, 'ing', '')
52
- OR preg_match("#$v+#", substr($word, 0, -2)) && $this->replace($word, 'ed', '')) {
53
- if ( !$this->replace($word, 'at', 'ate')
54
- AND !$this->replace($word, 'bl', 'ble')
55
- AND !$this->replace($word, 'iz', 'ize')) {
56
-
57
- if ( $this->doubleConsonant($word)
58
- AND substr($word, -2) != 'll'
59
- AND substr($word, -2) != 'ss'
60
- AND substr($word, -2) != 'zz') {
61
-
62
- $word = substr($word, 0, -1);
63
-
64
- } else if ($this->m($word) == 1 AND $this->cvc($word)) {
65
- $word .= 'e';
66
- }
67
- }
68
- }
69
- }
70
-
71
- return $word;
72
- }
73
-
74
- function step1c($word)
75
- {
76
- $v = $this->regex_vowel;
77
-
78
- if (substr($word, -1) == 'y' && preg_match("#$v+#", substr($word, 0, -1))) {
79
- $this->replace($word, 'y', 'i');
80
- }
81
-
82
- return $word;
83
- }
84
-
85
-
86
- function step2($word)
87
- {
88
- switch (substr($word, -2, 1)) {
89
- case 'a':
90
- $this->replace($word, 'ational', 'ate', 0)
91
- OR $this->replace($word, 'tional', 'tion', 0);
92
- break;
93
-
94
- case 'c':
95
- $this->replace($word, 'enci', 'ence', 0)
96
- OR $this->replace($word, 'anci', 'ance', 0);
97
- break;
98
-
99
- case 'e':
100
- $this->replace($word, 'izer', 'ize', 0);
101
- break;
102
-
103
- case 'g':
104
- $this->replace($word, 'logi', 'log', 0);
105
- break;
106
-
107
- case 'l':
108
- $this->replace($word, 'entli', 'ent', 0)
109
- OR $this->replace($word, 'ousli', 'ous', 0)
110
- OR $this->replace($word, 'alli', 'al', 0)
111
- OR $this->replace($word, 'bli', 'ble', 0)
112
- OR $this->replace($word, 'eli', 'e', 0);
113
- break;
114
-
115
- case 'o':
116
- $this->replace($word, 'ization', 'ize', 0)
117
- OR $this->replace($word, 'ation', 'ate', 0)
118
- OR $this->replace($word, 'ator', 'ate', 0);
119
- break;
120
-
121
- case 's':
122
- $this->replace($word, 'iveness', 'ive', 0)
123
- OR $this->replace($word, 'fulness', 'ful', 0)
124
- OR $this->replace($word, 'ousness', 'ous', 0)
125
- OR $this->replace($word, 'alism', 'al', 0);
126
- break;
127
-
128
- case 't':
129
- $this->replace($word, 'biliti', 'ble', 0)
130
- OR $this->replace($word, 'aliti', 'al', 0)
131
- OR $this->replace($word, 'iviti', 'ive', 0);
132
- break;
133
- }
134
-
135
- return $word;
136
- }
137
-
138
-
139
- function step3($word)
140
- {
141
- switch (substr($word, -2, 1)) {
142
- case 'a':
143
- $this->replace($word, 'ical', 'ic', 0);
144
- break;
145
-
146
- case 's':
147
- $this->replace($word, 'ness', '', 0);
148
- break;
149
-
150
- case 't':
151
- $this->replace($word, 'icate', 'ic', 0)
152
- OR $this->replace($word, 'iciti', 'ic', 0);
153
- break;
154
-
155
- case 'u':
156
- $this->replace($word, 'ful', '', 0);
157
- break;
158
-
159
- case 'v':
160
- $this->replace($word, 'ative', '', 0);
161
- break;
162
-
163
- case 'z':
164
- $this->replace($word, 'alize', 'al', 0);
165
- break;
166
- }
167
-
168
- return $word;
169
- }
170
-
171
-
172
- function step4($word)
173
- {
174
- switch (substr($word, -2, 1)) {
175
- case 'a':
176
- $this->replace($word, 'al', '', 1);
177
- break;
178
-
179
- case 'c':
180
- $this->replace($word, 'ance', '', 1)
181
- OR $this->replace($word, 'ence', '', 1);
182
- break;
183
-
184
- case 'e':
185
- $this->replace($word, 'er', '', 1);
186
- break;
187
-
188
- case 'i':
189
- $this->replace($word, 'ic', '', 1);
190
- break;
191
-
192
- case 'l':
193
- $this->replace($word, 'able', '', 1)
194
- OR $this->replace($word, 'ible', '', 1);
195
- break;
196
-
197
- case 'n':
198
- $this->replace($word, 'ant', '', 1)
199
- OR $this->replace($word, 'ement', '', 1)
200
- OR $this->replace($word, 'ment', '', 1)
201
- OR $this->replace($word, 'ent', '', 1);
202
- break;
203
-
204
- case 'o':
205
- if (substr($word, -4) == 'tion' OR substr($word, -4) == 'sion') {
206
- $this->replace($word, 'ion', '', 1);
207
- } else {
208
- $this->replace($word, 'ou', '', 1);
209
- }
210
- break;
211
-
212
- case 's':
213
- $this->replace($word, 'ism', '', 1);
214
- break;
215
-
216
- case 't':
217
- $this->replace($word, 'ate', '', 1)
218
- OR $this->replace($word, 'iti', '', 1);
219
- break;
220
-
221
- case 'u':
222
- $this->replace($word, 'ous', '', 1);
223
- break;
224
-
225
- case 'v':
226
- $this->replace($word, 'ive', '', 1);
227
- break;
228
-
229
- case 'z':
230
- $this->replace($word, 'ize', '', 1);
231
- break;
232
- }
233
-
234
- return $word;
235
- }
236
-
237
- function step5($word)
238
- {
239
- if (substr($word, -1) == 'e') {
240
- if ($this->m(substr($word, 0, -1)) > 1) {
241
- $this->replace($word, 'e', '');
242
-
243
- } else if ($this->m(substr($word, 0, -1)) == 1) {
244
-
245
- if (!$this->cvc(substr($word, 0, -1))) {
246
- $this->replace($word, 'e', '');
247
- }
248
- }
249
- }
250
-
251
- // Part b
252
- if ($this->m($word) > 1 AND $this->doubleConsonant($word) AND substr($word, -1) == 'l') {
253
- $word = substr($word, 0, -1);
254
- }
255
-
256
- return $word;
257
- }
258
-
259
- function replace(&$str, $check, $repl, $m = null)
260
- {
261
- $len = 0 - strlen($check);
262
-
263
- if (substr($str, $len) == $check) {
264
- $substr = substr($str, 0, $len);
265
- if (is_null($m) OR $this->m($substr) > $m) {
266
- $str = $substr . $repl;
267
- }
268
-
269
- return true;
270
- }
271
-
272
- return false;
273
- }
274
-
275
-
276
-
277
- function m($str)
278
- {
279
- $c = $this->regex_consonant;
280
- $v = $this->regex_vowel;
281
-
282
- $str = preg_replace("#^$c+#", '', $str);
283
- $str = preg_replace("#$v+$#", '', $str);
284
-
285
- preg_match_all("#($v+$c+)#", $str, $matches);
286
-
287
- return count($matches[1]);
288
- }
289
-
290
-
291
-
292
- function doubleConsonant($str)
293
- {
294
- $c = $this->regex_consonant;
295
-
296
- return preg_match("#$c[2]$#", $str, $matches) AND $matches[0][0] == $matches[0][1];
297
- }
298
-
299
-
300
-
301
- function cvc($str)
302
- {
303
- $c = $this->regex_consonant;
304
- $v = $this->regex_vowel;
305
-
306
- return preg_match("#($c$v$c)$#", $str, $matches)
307
- AND strlen($matches[1]) == 3
308
- AND $matches[1][2] != 'w'
309
- AND $matches[1][2] != 'x'
310
- AND $matches[1][2] != 'y';
311
- }
312
- }
313
- }
314
-
315
- /*
316
- Stem caching added by Rob Marsh, SJ
317
- http://rmarsh.com
318
- */
319
-
320
- $Stemmer = new EnglishStemmer();
321
- $StemCache = array();
322
-
323
- function stem($word) {
324
- global $Stemmer, $StemCache;
325
- if (!isset($StemCache[$word])) {
326
- $stemmedword = $Stemmer->Stem($word);
327
- $StemCache[$word] = $stemmedword;
328
- }
329
- else {
330
- $stemmedword = $StemCache[$word] ;
331
- }
332
- return $stemmedword;
333
- }
1
+ <?php
2
+ /*
3
+ Creado por Cesar Rodas para el proyecto Saddor.com
4
+ Este Stemmer esta basado en el argoritmo de Snowball Stemmer.
5
+ saddor@gmail.com
6
+ Este programa esta bajo licencia GNU
7
+ */
8
+ if (!defined("ENGLISHSTEMMER"))
9
+ {
10
+ define("ENGLISHSTEMMER",1,false);
11
+ class EnglishStemmer
12
+ {
13
+ var $regex_consonant = '(?:[bcdfghjklmnpqrstvwxz]|(?<=[aeiou])y|^y)';
14
+ var $regex_vowel = '(?:[aeiou]|(?<![aeiou])y)';
15
+
16
+ function Stem($word)
17
+ {
18
+ if (strlen($word) <= 2) {
19
+ return $word;
20
+ }
21
+
22
+ $word = $this->step1ab($word);
23
+ $word = $this->step1c($word);
24
+ $word = $this->step2($word);
25
+ $word = $this->step3($word);
26
+ $word = $this->step4($word);
27
+ $word = $this->step5($word);
28
+ /*
29
+ Esta parte esta editado por cesar rodas,
30
+ no quiero que me muestre ' (apostrofe) al final
31
+ */
32
+ if (substr($word,-1,1) == "'")
33
+ $word = substr($word,0,strlen($word) -1 );
34
+ return $word;
35
+ }
36
+
37
+
38
+ function step1ab($word)
39
+ {
40
+ if (substr($word, -1) == 's') {
41
+
42
+ $this->replace($word, 'sses', 'ss')
43
+ OR $this->replace($word, 'ies', 'i')
44
+ OR $this->replace($word, 'ss', 'ss')
45
+ OR $this->replace($word, 's', '');
46
+ }
47
+
48
+ if (substr($word, -2, 1) != 'e' OR !$this->replace($word, 'eed', 'ee', 0)) { // First rule
49
+ $v = $this->regex_vowel;
50
+
51
+ if ( preg_match("#$v+#", substr($word, 0, -3)) && $this->replace($word, 'ing', '')
52
+ OR preg_match("#$v+#", substr($word, 0, -2)) && $this->replace($word, 'ed', '')) {
53
+ if ( !$this->replace($word, 'at', 'ate')
54
+ AND !$this->replace($word, 'bl', 'ble')
55
+ AND !$this->replace($word, 'iz', 'ize')) {
56
+
57
+ if ( $this->doubleConsonant($word)
58
+ AND substr($word, -2) != 'll'
59
+ AND substr($word, -2) != 'ss'
60
+ AND substr($word, -2) != 'zz') {
61
+
62
+ $word = substr($word, 0, -1);
63
+
64
+ } else if ($this->m($word) == 1 AND $this->cvc($word)) {
65
+ $word .= 'e';
66
+ }
67
+ }
68
+ }
69
+ }
70
+
71
+ return $word;
72
+ }
73
+
74
+ function step1c($word)
75
+ {
76
+ $v = $this->regex_vowel;
77
+
78
+ if (substr($word, -1) == 'y' && preg_match("#$v+#", substr($word, 0, -1))) {
79
+ $this->replace($word, 'y', 'i');
80
+ }
81
+
82
+ return $word;
83
+ }
84
+
85
+
86
+ function step2($word)
87
+ {
88
+ switch (substr($word, -2, 1)) {
89
+ case 'a':
90
+ $this->replace($word, 'ational', 'ate', 0)
91
+ OR $this->replace($word, 'tional', 'tion', 0);
92
+ break;
93
+
94
+ case 'c':
95
+ $this->replace($word, 'enci', 'ence', 0)
96
+ OR $this->replace($word, 'anci', 'ance', 0);
97
+ break;
98
+
99
+ case 'e':
100
+ $this->replace($word, 'izer', 'ize', 0);
101
+ break;
102
+
103
+ case 'g':
104
+ $this->replace($word, 'logi', 'log', 0);
105
+ break;
106
+
107
+ case 'l':
108
+ $this->replace($word, 'entli', 'ent', 0)
109
+ OR $this->replace($word, 'ousli', 'ous', 0)
110
+ OR $this->replace($word, 'alli', 'al', 0)
111
+ OR $this->replace($word, 'bli', 'ble', 0)
112
+ OR $this->replace($word, 'eli', 'e', 0);
113
+ break;
114
+
115
+ case 'o':
116
+ $this->replace($word, 'ization', 'ize', 0)
117
+ OR $this->replace($word, 'ation', 'ate', 0)
118
+ OR $this->replace($word, 'ator', 'ate', 0);
119
+ break;
120
+
121
+ case 's':
122
+ $this->replace($word, 'iveness', 'ive', 0)
123
+ OR $this->replace($word, 'fulness', 'ful', 0)
124
+ OR $this->replace($word, 'ousness', 'ous', 0)
125
+ OR $this->replace($word, 'alism', 'al', 0);
126
+ break;
127
+
128
+ case 't':
129
+ $this->replace($word, 'biliti', 'ble', 0)
130
+ OR $this->replace($word, 'aliti', 'al', 0)
131
+ OR $this->replace($word, 'iviti', 'ive', 0);
132
+ break;
133
+ }
134
+
135
+ return $word;
136
+ }
137
+
138
+
139
+ function step3($word)
140
+ {
141
+ switch (substr($word, -2, 1)) {
142
+ case 'a':
143
+ $this->replace($word, 'ical', 'ic', 0);
144
+ break;
145
+
146
+ case 's':
147
+ $this->replace($word, 'ness', '', 0);
148
+ break;
149
+
150
+ case 't':
151
+ $this->replace($word, 'icate', 'ic', 0)
152
+ OR $this->replace($word, 'iciti', 'ic', 0);
153
+ break;
154
+
155
+ case 'u':
156
+ $this->replace($word, 'ful', '', 0);
157
+ break;
158
+
159
+ case 'v':
160
+ $this->replace($word, 'ative', '', 0);
161
+ break;
162
+
163
+ case 'z':
164
+ $this->replace($word, 'alize', 'al', 0);
165
+ break;
166
+ }
167
+
168
+ return $word;
169
+ }
170
+
171
+
172
+ function step4($word)
173
+ {
174
+ switch (substr($word, -2, 1)) {
175
+ case 'a':
176
+ $this->replace($word, 'al', '', 1);
177
+ break;
178
+
179
+ case 'c':
180
+ $this->replace($word, 'ance', '', 1)
181
+ OR $this->replace($word, 'ence', '', 1);
182
+ break;
183
+
184
+ case 'e':
185
+ $this->replace($word, 'er', '', 1);
186
+ break;
187
+
188
+ case 'i':
189
+ $this->replace($word, 'ic', '', 1);
190
+ break;
191
+
192
+ case 'l':
193
+ $this->replace($word, 'able', '', 1)
194
+ OR $this->replace($word, 'ible', '', 1);
195
+ break;
196
+
197
+ case 'n':
198
+ $this->replace($word, 'ant', '', 1)
199
+ OR $this->replace($word, 'ement', '', 1)
200
+ OR $this->replace($word, 'ment', '', 1)
201
+ OR $this->replace($word, 'ent', '', 1);
202
+ break;
203
+
204
+ case 'o':
205
+ if (substr($word, -4) == 'tion' OR substr($word, -4) == 'sion') {
206
+ $this->replace($word, 'ion', '', 1);
207
+ } else {
208
+ $this->replace($word, 'ou', '', 1);
209
+ }
210
+ break;
211
+
212
+ case 's':
213
+ $this->replace($word, 'ism', '', 1);
214
+ break;
215
+
216
+ case 't':
217
+ $this->replace($word, 'ate', '', 1)
218
+ OR $this->replace($word, 'iti', '', 1);
219
+ break;
220
+
221
+ case 'u':
222
+ $this->replace($word, 'ous', '', 1);
223
+ break;
224
+
225
+ case 'v':
226
+ $this->replace($word, 'ive', '', 1);
227
+ break;
228
+
229
+ case 'z':
230
+ $this->replace($word, 'ize', '', 1);
231
+ break;
232
+ }
233
+
234
+ return $word;
235
+ }
236
+
237
+ function step5($word)
238
+ {
239
+ if (substr($word, -1) == 'e') {
240
+ if ($this->m(substr($word, 0, -1)) > 1) {
241
+ $this->replace($word, 'e', '');
242
+
243
+ } else if ($this->m(substr($word, 0, -1)) == 1) {
244
+
245
+ if (!$this->cvc(substr($word, 0, -1))) {
246
+ $this->replace($word, 'e', '');
247
+ }
248
+ }
249
+ }
250
+
251
+ // Part b
252
+ if ($this->m($word) > 1 AND $this->doubleConsonant($word) AND substr($word, -1) == 'l') {
253
+ $word = substr($word, 0, -1);
254
+ }
255
+
256
+ return $word;
257
+ }
258
+
259
+ function replace(&$str, $check, $repl, $m = null)
260
+ {
261
+ $len = 0 - strlen($check);
262
+
263
+ if (substr($str, $len) == $check) {
264
+ $substr = substr($str, 0, $len);
265
+ if (is_null($m) OR $this->m($substr) > $m) {
266
+ $str = $substr . $repl;
267
+ }
268
+
269
+ return true;
270
+ }
271
+
272
+ return false;
273
+ }
274
+
275
+
276
+
277
+ function m($str)
278
+ {
279
+ $c = $this->regex_consonant;
280
+ $v = $this->regex_vowel;
281
+
282
+ $str = preg_replace("#^$c+#", '', $str);
283
+ $str = preg_replace("#$v+$#", '', $str);
284
+
285
+ preg_match_all("#($v+$c+)#", $str, $matches);
286
+
287
+ return count($matches[1]);
288
+ }
289
+
290
+
291
+
292
+ function doubleConsonant($str)
293
+ {
294
+ $c = $this->regex_consonant;
295
+
296
+ return preg_match("#$c[2]$#", $str, $matches) AND $matches[0][0] == $matches[0][1];
297
+ }
298
+
299
+
300
+
301
+ function cvc($str)
302
+ {
303
+ $c = $this->regex_consonant;
304
+ $v = $this->regex_vowel;
305
+
306
+ return preg_match("#($c$v$c)$#", $str, $matches)
307
+ AND strlen($matches[1]) == 3
308
+ AND $matches[1][2] != 'w'
309
+ AND $matches[1][2] != 'x'
310
+ AND $matches[1][2] != 'y';
311
+ }
312
+ }
313
+ }
314
+
315
+ /*
316
+ Stem caching added by Rob Marsh, SJ
317
+ http://rmarsh.com
318
+ */
319
+
320
+ $Stemmer = new EnglishStemmer();
321
+ $StemCache = array();
322
+
323
+ function stem($word) {
324
+ global $Stemmer, $StemCache;
325
+ if (!isset($StemCache[$word])) {
326
+ $stemmedword = $Stemmer->Stem($word);
327
+ $StemCache[$word] = $stemmedword;
328
+ }
329
+ else {
330
+ $stemmedword = $StemCache[$word] ;
331
+ }
332
+ return $stemmedword;
333
+ }
languages/en/stopwords.php CHANGED
@@ -1,3 +1,3 @@
1
- <?php
2
- // the list of common words we want to ignore. NB anything shorter than 4 characters is knocked by the plugin and doesn't need to figure here
3
- $overusedwords = array("able", "about", "above", "according", "accordingly", "across", "actually", "after", "afterwards", "again", "against", "ain't", "allow", "allows", "almost", "alone", "along", "already", "also", "although", "always", "among", "amongst", "another", "anybody", "anyhow", "anyone", "anything", "anyway", "anyways", "anywhere", "apart", "appear", "appreciate", "appropriate", "aren't", "around", "aside", "asking", "associated", "available", "away", "awfully", "became", "because", "become", "becomes", "becoming", "been", "before", "beforehand", "behind", "being", "believe", "below", "beside", "besides", "best", "better", "between", "beyond", "both", "brief", "came", "cannot", "can't", "cause", "causes", "certain", "certainly", "changes", "clearly", "come", "comes", "concerning", "conse'uently", "consider", "considering", "contain", "containing", "contains", "corresponding", "could", "couldn't", "course", "currently", "definitely", "described", "despite", "didn't", "different", "does", "doesn't", "doing", "done", "don't", "down", "downwards", "during", "each", "eight", "either", "else", "elsewhere", "enough", "entirely", "especially", "even", "ever", "every", "everybody", "everyone", "everything", "everywhere", "exactly", "example", "except", "fifth", "first", "five", "followed", "following", "follows", "former", "formerly", "forth", "four", "from", "further", "furthermore", "gets", "getting", "given", "gives", "goes", "going", "gone", "gotten", "greetings", "hadn't", "happens", "hardly", "hasn't", "have", "haven't", "having", "hello", "help", "hence", "here", "hereafter", "hereby", "herein", "hereupon", "he's", "hers", "herself", "himself", "hither", "hopefully", "howbeit", "however", "ignored", "i'll", "it'd", "it's", "i've", "immediate", "inasmuch", "indeed", "indicate", "indicated", "indicates", "inner", "insofar", "instead", "into", "inward", "isn't", "itself", "just", "keep", "keeps", "kept", "know", "known", "knows", "last", "lately", "later", "latter", "latterly", "least", "less", "lest", "like", "liked", "likely", "little", "look", "looking", "looks", "mainly", "many", "maybe", "mean", "meanwhile", "merely", "might", "more", "moreover", "most", "mostly", "much", "must", "mustn't", "myself", "name", "namely", "near", "nearly", "necessary", "need", "needs", "neither", "never", "nevertheless", "next", "nine", "nobody", "none", "noone", "normally", "nothing", "novel", "nowhere", "obviously", "often", "okay", "once", "ones", "one's", "only", "onto", "other", "others", "otherwise", "ought", "ours", "ourselves", "outside", "over", "overall", "particular", "particularly", "perhaps", "placed", "please", "plus", "possible", "presumably", "probably", "provides", "'uite", "rather", "really", "reasonably", "regarding", "regardless", "regards", "relatively", "respectively", "right", "said", "same", "saying", "says", "second", "secondly", "seeing", "seem", "seemed", "seeming", "seems", "seen", "self", "selves", "sensible", "sent", "serious", "seriously", "seven", "several", "shall", "should", "shouldn't", "since", "some", "somebody", "somehow", "someone", "something", "sometime", "sometimes", "somewhat", "somewhere", "soon", "sorry", "specified", "specify", "specifying", "still", "such", "sure", "take", "taken", "tell", "tends", "than", "thank", "thanks", "that", "that's", "their", "theirs", "them", "themselves", "then", "thence", "there", "thereafter", "thereby", "therefore", "therein", "there's", "thereupon", "these", "they", "think", "third", "this", "thorough", "thoroughly", "those", "though", "three", "through", "throughout", "thru", "thus", "together", "took", "toward", "towards", "tried", "tries", "truly", "trying", "twice", "under", "unfortunately", "unless", "unlikely", "until", "unto", "upon", "used", "useful", "uses", "using", "usually", "value", "various", "very", "want", "wants", "wasn't", "welcome", "we'd", "well", "went", "were", "weren't", "what", "whatever", "when", "whence", "whenever", "where", "whereafter", "whereas", "whereby", "wherein", "whereupon", "wherever", "whether", "which", "while", "whither", "whoever", "whole", "whom", "whose", "will", "willing", "wish", "with", "within", "without", "wonder", "would", "wouldn't", "your", "yours", "yourself", "yourselves", "zero");
1
+ <?php
2
+ // the list of common words we want to ignore. NB anything shorter than 4 characters is knocked by the plugin and doesn't need to figure here
3
+ $overusedwords = array("able", "about", "above", "according", "accordingly", "across", "actually", "after", "afterwards", "again", "against", "ain't", "allow", "allows", "almost", "alone", "along", "already", "also", "although", "always", "among", "amongst", "another", "anybody", "anyhow", "anyone", "anything", "anyway", "anyways", "anywhere", "apart", "appear", "appreciate", "appropriate", "aren't", "around", "aside", "asking", "associated", "available", "away", "awfully", "became", "because", "become", "becomes", "becoming", "been", "before", "beforehand", "behind", "being", "believe", "below", "beside", "besides", "best", "better", "between", "beyond", "both", "brief", "came", "cannot", "can't", "cause", "causes", "certain", "certainly", "changes", "clearly", "come", "comes", "concerning", "conse'uently", "consider", "considering", "contain", "containing", "contains", "corresponding", "could", "couldn't", "course", "currently", "definitely", "described", "despite", "didn't", "different", "does", "doesn't", "doing", "done", "don't", "down", "downwards", "during", "each", "eight", "either", "else", "elsewhere", "enough", "entirely", "especially", "even", "ever", "every", "everybody", "everyone", "everything", "everywhere", "exactly", "example", "except", "fifth", "first", "five", "followed", "following", "follows", "former", "formerly", "forth", "four", "from", "further", "furthermore", "gets", "getting", "given", "gives", "goes", "going", "gone", "gotten", "greetings", "hadn't", "happens", "hardly", "hasn't", "have", "haven't", "having", "hello", "help", "hence", "here", "hereafter", "hereby", "herein", "hereupon", "he's", "hers", "herself", "himself", "hither", "hopefully", "howbeit", "however", "ignored", "i'll", "it'd", "it's", "i've", "immediate", "inasmuch", "indeed", "indicate", "indicated", "indicates", "inner", "insofar", "instead", "into", "inward", "isn't", "itself", "just", "keep", "keeps", "kept", "know", "known", "knows", "last", "lately", "later", "latter", "latterly", "least", "less", "lest", "like", "liked", "likely", "little", "look", "looking", "looks", "mainly", "many", "maybe", "mean", "meanwhile", "merely", "might", "more", "moreover", "most", "mostly", "much", "must", "mustn't", "myself", "name", "namely", "near", "nearly", "necessary", "need", "needs", "neither", "never", "nevertheless", "next", "nine", "nobody", "none", "noone", "normally", "nothing", "novel", "nowhere", "obviously", "often", "okay", "once", "ones", "one's", "only", "onto", "other", "others", "otherwise", "ought", "ours", "ourselves", "outside", "over", "overall", "particular", "particularly", "perhaps", "placed", "please", "plus", "possible", "presumably", "probably", "provides", "'uite", "rather", "really", "reasonably", "regarding", "regardless", "regards", "relatively", "respectively", "right", "said", "same", "saying", "says", "second", "secondly", "seeing", "seem", "seemed", "seeming", "seems", "seen", "self", "selves", "sensible", "sent", "serious", "seriously", "seven", "several", "shall", "should", "shouldn't", "since", "some", "somebody", "somehow", "someone", "something", "sometime", "sometimes", "somewhat", "somewhere", "soon", "sorry", "specified", "specify", "specifying", "still", "such", "sure", "take", "taken", "tell", "tends", "than", "thank", "thanks", "that", "that's", "their", "theirs", "them", "themselves", "then", "thence", "there", "thereafter", "thereby", "therefore", "therein", "there's", "thereupon", "these", "they", "think", "third", "this", "thorough", "thoroughly", "those", "though", "three", "through", "throughout", "thru", "thus", "together", "took", "toward", "towards", "tried", "tries", "truly", "trying", "twice", "under", "unfortunately", "unless", "unlikely", "until", "unto", "upon", "used", "useful", "uses", "using", "usually", "value", "various", "very", "want", "wants", "wasn't", "welcome", "we'd", "well", "went", "were", "weren't", "what", "whatever", "when", "whence", "whenever", "where", "whereafter", "whereas", "whereby", "wherein", "whereupon", "wherever", "whether", "which", "while", "whither", "whoever", "whole", "whom", "whose", "will", "willing", "wish", "with", "within", "without", "wonder", "would", "wouldn't", "your", "yours", "yourself", "yourselves", "zero");
languages/es/stemmer.php CHANGED
@@ -1,381 +1,381 @@
1
- <?php
2
- /*
3
- Creado por Cesar Rodas para el proyecto Saddor.com
4
- Este Stemmer esta basado en el argoritmo de Snowball Stemmer.
5
- saddor@gmail.com
6
- Este programa esta bajo licencia GNU
7
- */
8
- if (!defined("SPANISHSTEMMER"))
9
- {
10
- define("vocal",1,false);
11
- define("consonante",2,false);
12
- define("SPANISHSTEMMER",1,false);
13
-
14
- class PorterStemmer
15
- {
16
- var $R1;
17
- var $R2;
18
- var $RV;
19
- var $word;
20
- function Stem($word)
21
- {
22
-
23
- $this->word = $word;
24
- if (strlen($word) < 2)
25
- return;
26
-
27
-
28
- $this->step_0();
29
- while($this->step_1());
30
- $this->step_2();
31
- $this->step_3();
32
- return $this->word;
33
- }
34
-
35
- function step_0()
36
- {
37
- $this->splitword();
38
- $search = array(
39
- "me","se","sela","selo","selas","selos","la","le","lo","les",
40
- "los","nos"
41
- );
42
-
43
- $prefix = array(
44
- "i�ndo","�ndo","�r","�r","�r", /* primer caso */
45
- "iendo","ando","ar","er","ir", /* segundo caso*/
46
- "yendo"
47
- );
48
-
49
- foreach ($prefix as $id => $pref)
50
- {
51
- $return = false;
52
- if ( (strstr($this->RV,$pref) != NULL) or
53
- /* caso para yendo */
54
- ($pref == "yendo" && strstr($this->word,"uyendo")) )
55
- {
56
-
57
- /*
58
- El prefijo fue encontrado, ahora buscar para borrar
59
- el pronombre.
60
- */
61
- foreach ($search as $word)
62
- {
63
- $len = strlen($word);
64
-
65
- switch ($id)
66
- {
67
-
68
- case $id < 5: /* primer Caso*/
69
- if ($word == substr($this->RV,-1 * $len,$len) )
70
- {
71
- $this->word = substr($this->word,0, strlen($this->word) - $len);
72
- $this->word = str_replace($prefix[$id],$prefix[$id+5],$this->word);
73
- $return = true;
74
- }
75
- break;
76
- case $id < 10: /* segundo caso*/
77
- if ($word == substr($this->RV,-1 * $len,$len) )
78
- {
79
- $this->word = substr($this->word,0, strlen($this->word) - $len);
80
- $return = true;
81
- }
82
- break;
83
- case $id >= 10: /* tercer caso*/
84
- if ($word == substr($this->RV,-1 * $len,$len) )
85
- {
86
-
87
- $this->word = substr($this->word,0, strlen($this->word) - $len);
88
- $return = true;
89
- }
90
- break;
91
- }
92
- }
93
- }
94
-
95
- }
96
- unset($prefix,$search,$word,$id,$pref,$len);
97
- return $return;
98
- }
99
-
100
- function step_1()
101
- {
102
- $return = false;
103
- $this->splitword();
104
-
105
- /* borrado de R2 */
106
- $search = array(
107
- "abilidades","iblemente","icaciones","ablemente","antemente","ivamente","atamente",
108
- "amientos","icadoras","icadores","icancias","imientos","icamente",
109
- "osamente","abilidad","icidades","ividades","adamente","icantes",
110
- "icancia","imiemto","icadora","icaci�n","amiento","imiento","aciones",
111
- "ativos","ativas","ividad","idades","icidad","icante",
112
- "icador","adoras","adores","ancias","mente","ables",
113
- "ismos","anzas","ativa","ativo","istas","ibles",
114
- "aci�n","antes","adora","ancia","ismo","anza",
115
- "icos","ivas","osos","ivos","ante","osas",
116
- "ador","ible","ista","idad","able","ico",
117
- "osa","oso","iva","ica","ica","ivo",
118
- );
119
-
120
- for ($i = 0; $i < count($search); $i++)
121
- if (substr($this->R2,strlen($search[$i]) * (-1),strlen($search[$i])) == $search[$i])
122
- {
123
- $this->word = substr($this->word,0,strlen($this->word) - strlen($search[$i]) );
124
- $return = true;
125
- break;
126
- }
127
- /* creo que esta mal, creo que hay que buscar en R1*/
128
- if ($this->R1 == "amente")
129
- {
130
- $this->word = str_replace("amente","",$this->word);
131
- }
132
-
133
- $search = array
134
- (
135
- "log�a","log�as",/**/"uci�n","uciones",/**/"encia","encias"
136
- );
137
- $replace = array
138
- (
139
- "log","log","u","u","entre","entre"
140
- );
141
- for ($i = 0; $i < count($search); $i++)
142
- if (substr($this->R2,strlen($search[$i]) * (-1),strlen($search[$i])) == $search[$i])
143
- {
144
- $this->word = str_replace($search[$i],$replace[$i],$this->word);
145
- $return = true;
146
- break;
147
- }
148
- unset($i,$search,$replace);
149
- return $return;
150
- }
151
-
152
- function step_2()
153
- {
154
- $this->splitword();
155
- $return = false;
156
- $search = array(
157
- "ya","ye","yan","yen","yeron","yendo","yo","y�","yas","yes","yais","yamos"
158
- );
159
- foreach ($search as $word)
160
- {
161
- if (substr($this->RV,strlen($word) * (-1),strlen($word)) == $word)
162
- if (substr($this->word,-1*(strlen($word) + 1), strlen($word) + 1) == "u".$word)
163
- {
164
- $this->word = substr($this->word,0, strlen($this->word) -(strlen($word) + 1));
165
- $return = true;
166
- }
167
- }
168
-
169
- if ($return == false)
170
- $this->step_2b();
171
- unset($return,$search,$word);
172
- }
173
-
174
- function step_2b()
175
- {
176
- $this->splitword();
177
- $search = array(
178
- "en","es","�is","emos"
179
- );
180
-
181
- foreach ($search as $word)
182
- {
183
- if (substr($this->RV,strlen($word) * (-1),strlen($word)) == $word)
184
- if (substr($this->word,(-1)*(strlen($word) + 2), strlen($word) + 2) == "gu".$word)
185
- {
186
- $this->word = substr($this->word,0, strlen($this->word) -(strlen($word) + 1) );
187
- $return = true;
188
- }
189
- /*
190
- This part was fix by Diego Enrique Finol <dfinol at cantv dot net>
191
- This was the email that Diego sent to me:
192
- Epa saludos, gracias por la clase de spanish stemmer, hab�a visto lo mismo
193
- en snowball pero me ahorraste el trabajo de convertirlo a php. S�lo not�
194
- que en las partes en la que hab�a que borrar cierto sufijo y, adem�s,
195
- borrar la "u" de si est� precedido por "gu" creo que no borra el sufijo si
196
- no est� precedido por esto. O sea, hay que borrar el afijo en ambos casos,
197
- y de paso si est� precedido por gu, tambi�n borrar la u, pero el algoritmo
198
- s�lo lo hace si est� precedido por gu, sino, no borra nada.
199
-
200
- Thanks Diego!.
201
- */
202
- else
203
- {
204
- $this->word = substr($this->word,0, strlen($this->word) -(strlen($word)) );
205
- $return = true;
206
- }
207
- /*End of Diego fix*/
208
- }
209
-
210
- $search = array(
211
- "i�ramos","ar�amos","ir�amos","i�semos","er�amos","er�ais","eremos",
212
- "isteis","ir�ais","ierais","iremos","�bamos","ieseis",
213
- "asteis","�ramos","�semos","aremos","ar�ais","abais",
214
- "�amos","arais","ieses","ar�an","iesen","ieron",
215
- "iendo","ieras","ir�is","ar�as","er�as","aseis",
216
- "er�is","er�an","ir�an","ar�is","ir�as","ieran",
217
- "ando","amos","aron","asen","aras","ados",
218
- "�ais","ases","imos","adas","idas","abas",
219
- "iste","ir�n","er�n","ar�a","er�a","iera",
220
- "ir�s","ir�a","aran","ar�s","er�s","aste",
221
- "iese","aban","ar�n","�is","ada","ir�",
222
- "�an","ir�","er�","aba","ara","ido",
223
- "ar�","ar�","ado","er�","ase","�as",
224
- "ida","�a","er","ar","i�","an",
225
- "ir","as","ad","ed","id","�s",
226
-
227
-
228
- );
229
-
230
- foreach ($search as $word)
231
- if (substr($this->RV,strlen($word) * (-1),strlen($word)) == $word)
232
- {
233
- $this->word = substr($this->word,0, strlen($this->word) -(strlen($word)));
234
- $this->splitword();
235
- }
236
- unset($search,$word);
237
-
238
- }
239
-
240
- function step_3()
241
- {
242
- $this->splitword();
243
- $return = false;
244
- $search = array(
245
- "os","a","o","","",""
246
- );
247
-
248
-
249
- foreach ($search as $word)
250
- if (substr($this->RV,strlen($word) * (-1),strlen($word)) == $word)
251
- {
252
- $this->word = substr($this->word,0, strlen($this->word) -(strlen($word)));
253
- $return = true;
254
- }
255
-
256
- $search = array(
257
- "e",""
258
- );
259
-
260
- foreach ($search as $word)
261
- {
262
- if (substr($this->RV,strlen($word) * (-1),strlen($word)) == $word)
263
- if (substr($this->RV,-1*(strlen($word) + 2), strlen($word) + 2) == "gu".$word)
264
- {
265
- $this->word = substr($this->word,0, strlen($this->word) -(strlen($word) + 1) );
266
- $return = true;
267
- }
268
- else
269
- {
270
- $this->word = substr($this->word,0, strlen($this->word) -(strlen($word)) );
271
- $return = true;
272
- }
273
- }
274
- unset($search,$word);
275
- $this->word = str_replace("","a",$this->word);
276
- $this->word = str_replace("","e",$this->word);
277
- $this->word = str_replace("","i",$this->word);
278
- $this->word = str_replace("","o",$this->word);
279
- $this->word = str_replace("","u",$this->word);
280
- $this->word = str_replace("","u",$this->word);
281
- return $return;
282
- }
283
-
284
-
285
- /* funciones utilizadas*/
286
- function saddorsort($a, $b)
287
- {
288
- if (strlen($a) == strlen($b)) {
289
- return 0;
290
- }
291
- return (strlen($a) < strlen($b)) ? 1 : -1;
292
- }
293
- function splitword()
294
- {
295
- $flag1=false;
296
- $flag2=false;
297
- $this->R1="";
298
- $this->R2="";
299
- $this->RV="";
300
- for ($i = 1; $i < strlen($this->word); $i++)
301
- {
302
- if ($flag1)
303
- $this->R1.=$this->word[$i];
304
- if ($flag2)
305
- $this->R2.=$this->word[$i];
306
-
307
- if ($i+1 >= strlen($this->word))
308
- break;
309
-
310
- if ($this->char_is($this->word[$i]) == consonante &&
311
- $this->char_is(@$this->word[$i+1]) == vocal &&
312
- $flag1 == true && $flag2 == false)
313
- $flag2=true;
314
-
315
- if ($this->char_is($this->word[$i]) == consonante &&
316
- $this->char_is($this->word[$i+1]) == vocal &&
317
- $flag1 == false)
318
- $flag1=true;
319
- }
320
-
321
-
322
- /* Buscando RV*/
323
- $flag1=false;
324
- if ($this->char_is($this->word[1]) == consonante)
325
- {
326
- for ($i = 2; $i < strlen($this->word); $i++)
327
- if ($this->char_is($this->word[$i]) == vocal)
328
- break;
329
- $i++;
330
- $this->RV = substr($this->word,$i);
331
- }
332
- else if ($this->char_is($this->word[1]) == vocal && $this->char_is($this->word[0]) == vocal)
333
- {
334
- for ($i = 2; $i < strlen($this->word); $i++)
335
- if ($this->char_is($this->word[$i]) == consonante)
336
- break;
337
- $i++;
338
- $this->RV = substr($this->word,$i);
339
- }
340
- else if (strlen($this->word) > 2)
341
- $this->RV = substr($this->word,3);
342
-
343
- unset($flag1,$flag2,$i);
344
- }
345
-
346
- function char_is($char)
347
- {
348
- $char = strtolower($char);
349
- if ($char == "")
350
- return;
351
- $vowel = "aeiou������";
352
- $consonant = "bcdfghijklmn�opqrsvtxwyz";
353
- if (strstr($vowel,$char))
354
- return vocal;
355
- if (strstr($consonant,$char))
356
- return consonante;
357
- }
358
- }
359
- }
360
-
361
- /*
362
- Stem caching added by Rob Marsh, SJ
363
- http://rmarsh.com
364
- */
365
-
366
- $Stemmer = new PorterStemmer();
367
- $StemCache = array();
368
-
369
- function stem($word) {
370
- global $Stemmer, $StemCache;
371
- if (!isset($StemCache[$word])) {
372
- $stemmedword = $Stemmer->Stem($word);
373
- $StemCache[$word] = $stemmedword;
374
- }
375
- else {
376
- $stemmedword = $StemCache[$word] ;
377
- }
378
- return $stemmedword;
379
- }
380
-
381
- ?>
1
+ <?php
2
+ /*
3
+ Creado por Cesar Rodas para el proyecto Saddor.com
4
+ Este Stemmer esta basado en el argoritmo de Snowball Stemmer.
5
+ saddor@gmail.com
6
+ Este programa esta bajo licencia GNU
7
+ */
8
+ if (!defined("SPANISHSTEMMER"))
9
+ {
10
+ define("vocal",1,false);
11
+ define("consonante",2,false);
12
+ define("SPANISHSTEMMER",1,false);
13
+
14
+ class PorterStemmer
15
+ {
16
+ var $R1;
17
+ var $R2;
18
+ var $RV;
19
+ var $word;
20
+ function Stem($word)
21
+ {
22
+
23
+ $this->word = $word;
24
+ if (strlen($word) < 2)
25
+ return;
26
+
27
+
28
+ $this->step_0();
29
+ while($this->step_1());
30
+ $this->step_2();
31
+ $this->step_3();
32
+ return $this->word;
33
+ }
34
+
35
+ function step_0()
36
+ {
37
+ $this->splitword();
38
+ $search = array(
39
+ "me","se","sela","selo","selas","selos","la","le","lo","les",
40
+ "los","nos"
41
+ );
42
+
43
+ $prefix = array(
44
+ "iéndo","ándo","ár","ér","ír", /* primer caso */
45
+ "iendo","ando","ar","er","ir", /* segundo caso*/
46
+ "yendo"
47
+ );
48
+
49
+ foreach ($prefix as $id => $pref)
50
+ {
51
+ $return = false;
52
+ if ( (strstr($this->RV,$pref) != NULL) or
53
+ /* caso para yendo */
54
+ ($pref == "yendo" && strstr($this->word,"uyendo")) )
55
+ {
56
+
57
+ /*
58
+ El prefijo fue encontrado, ahora buscar para borrar
59
+ el pronombre.
60
+ */
61
+ foreach ($search as $word)
62
+ {
63
+ $len = strlen($word);
64
+
65
+ switch ($id)
66
+ {
67
+
68
+ case $id < 5: /* primer Caso*/
69
+ if ($word == substr($this->RV,-1 * $len,$len) )
70
+ {
71
+ $this->word = substr($this->word,0, strlen($this->word) - $len);
72
+ $this->word = str_replace($prefix[$id],$prefix[$id+5],$this->word);
73
+ $return = true;
74
+ }
75
+ break;
76
+ case $id < 10: /* segundo caso*/
77
+ if ($word == substr($this->RV,-1 * $len,$len) )
78
+ {
79
+ $this->word = substr($this->word,0, strlen($this->word) - $len);
80
+ $return = true;
81
+ }
82
+ break;
83
+ case $id >= 10: /* tercer caso*/
84
+ if ($word == substr($this->RV,-1 * $len,$len) )
85
+ {
86
+
87
+ $this->word = substr($this->word,0, strlen($this->word) - $len);
88
+ $return = true;
89
+ }
90
+ break;
91
+ }
92
+ }
93
+ }
94
+
95
+ }
96
+ unset($prefix,$search,$word,$id,$pref,$len);
97
+ return $return;
98
+ }
99
+
100
+ function step_1()
101
+ {
102
+ $return = false;
103
+ $this->splitword();
104
+
105
+ /* borrado de R2 */
106
+ $search = array(
107
+ "abilidades","iblemente","icaciones","ablemente","antemente","ivamente","atamente",
108
+ "amientos","icadoras","icadores","icancias","imientos","icamente",
109
+ "osamente","abilidad","icidades","ividades","adamente","icantes",
110
+ "icancia","imiemto","icadora","icación","amiento","imiento","aciones",
111
+ "ativos","ativas","ividad","idades","icidad","icante",
112
+ "icador","adoras","adores","ancias","mente","ables",
113
+ "ismos","anzas","ativa","ativo","istas","ibles",
114
+ "ación","antes","adora","ancia","ismo","anza",
115
+ "icos","ivas","osos","ivos","ante","osas",
116
+ "ador","ible","ista","idad","able","ico",
117
+ "osa","oso","iva","ica","ica","ivo",
118
+ );
119
+
120
+ for ($i = 0; $i < count($search); $i++)
121
+ if (substr($this->R2,strlen($search[$i]) * (-1),strlen($search[$i])) == $search[$i])
122
+ {
123
+ $this->word = substr($this->word,0,strlen($this->word) - strlen($search[$i]) );
124
+ $return = true;
125
+ break;
126
+ }
127
+ /* creo que esta mal, creo que hay que buscar en R1*/
128
+ if ($this->R1 == "amente")
129
+ {
130
+ $this->word = str_replace("amente","",$this->word);
131
+ }
132
+
133
+ $search = array
134
+ (
135
+ "logía","logías",/**/"ución","uciones",/**/"encia","encias"
136
+ );
137
+ $replace = array
138
+ (
139
+ "log","log","u","u","entre","entre"
140
+ );
141
+ for ($i = 0; $i < count($search); $i++)
142
+ if (substr($this->R2,strlen($search[$i]) * (-1),strlen($search[$i])) == $search[$i])
143
+ {
144
+ $this->word = str_replace($search[$i],$replace[$i],$this->word);
145
+ $return = true;
146
+ break;
147
+ }
148
+ unset($i,$search,$replace);
149
+ return $return;
150
+ }
151
+
152
+ function step_2()
153
+ {
154
+ $this->splitword();
155
+ $return = false;
156
+ $search = array(
157
+ "ya","ye","yan","yen","yeron","yendo","yo","","yas","yes","yais","yamos"
158
+ );
159
+ foreach ($search as $word)
160
+ {
161
+ if (substr($this->RV,strlen($word) * (-1),strlen($word)) == $word)
162
+ if (substr($this->word,-1*(strlen($word) + 1), strlen($word) + 1) == "u".$word)
163
+ {
164
+ $this->word = substr($this->word,0, strlen($this->word) -(strlen($word) + 1));
165
+ $return = true;
166
+ }
167
+ }
168
+
169
+ if ($return == false)
170
+ $this->step_2b();
171
+ unset($return,$search,$word);
172
+ }
173
+
174
+ function step_2b()
175
+ {
176
+ $this->splitword();
177
+ $search = array(
178
+ "en","es","éis","emos"
179
+ );
180
+
181
+ foreach ($search as $word)
182
+ {
183
+ if (substr($this->RV,strlen($word) * (-1),strlen($word)) == $word)
184
+ if (substr($this->word,(-1)*(strlen($word) + 2), strlen($word) + 2) == "gu".$word)
185
+ {
186
+ $this->word = substr($this->word,0, strlen($this->word) -(strlen($word) + 1) );
187
+ $return = true;
188
+ }
189
+ /*
190
+ This part was fix by Diego Enrique Finol <dfinol at cantv dot net>
191
+ This was the email that Diego sent to me:
192
+ Epa saludos, gracias por la clase de spanish stemmer, había visto lo mismo
193
+ en snowball pero me ahorraste el trabajo de convertirlo a php. Sólo noté
194
+ que en las partes en la que había que borrar cierto sufijo y, además,
195
+ borrar la "u" de si está precedido por "gu" creo que no borra el sufijo si
196
+ no está precedido por esto. O sea, hay que borrar el afijo en ambos casos,
197
+ y de paso si está precedido por gu, también borrar la u, pero el algoritmo
198
+ sólo lo hace si está precedido por gu, sino, no borra nada.
199
+
200
+ Thanks Diego!.
201
+ */
202
+ else
203
+ {
204
+ $this->word = substr($this->word,0, strlen($this->word) -(strlen($word)) );
205
+ $return = true;
206
+ }
207
+ /*End of Diego fix*/
208
+ }
209
+
210
+ $search = array(
211
+ "iéramos","aríamos","iríamos","iésemos","eríamos","eríais","eremos",
212
+ "isteis","iríais","ierais","iremos","ábamos","ieseis",
213
+ "asteis","áramos","ásemos","aremos","aríais","abais",
214
+ "íamos","arais","ieses","arían","iesen","ieron",
215
+ "iendo","ieras","iréis","arías","erías","aseis",
216
+ "eréis","erían","irían","aréis","irías","ieran",
217
+ "ando","amos","aron","asen","aras","ados",
218
+ "íais","ases","imos","adas","idas","abas",
219
+ "iste","irán","erán","aría","ería","iera",
220
+ "irás","iría","aran","arás","erás","aste",
221
+ "iese","aban","arán","áis","ada","iré",
222
+ "ían","irá","eré","aba","ara","ido",
223
+ "aré","ará","ado","erá","ase","ías",
224
+ "ida","ía","er","ar","","an",
225
+ "ir","as","ad","ed","id","ís",
226
+
227
+
228
+ );
229
+
230
+ foreach ($search as $word)
231
+ if (substr($this->RV,strlen($word) * (-1),strlen($word)) == $word)
232
+ {
233
+ $this->word = substr($this->word,0, strlen($this->word) -(strlen($word)));
234
+ $this->splitword();
235
+ }
236
+ unset($search,$word);
237
+
238
+ }
239
+
240
+ function step_3()
241
+ {
242
+ $this->splitword();
243
+ $return = false;
244
+ $search = array(
245
+ "os","a","o","á","í","ó"
246
+ );
247
+
248
+
249
+ foreach ($search as $word)
250
+ if (substr($this->RV,strlen($word) * (-1),strlen($word)) == $word)
251
+ {
252
+ $this->word = substr($this->word,0, strlen($this->word) -(strlen($word)));
253
+ $return = true;
254
+ }
255
+
256
+ $search = array(
257
+ "e","é"
258
+ );
259
+
260
+ foreach ($search as $word)
261
+ {
262
+ if (substr($this->RV,strlen($word) * (-1),strlen($word)) == $word)
263
+ if (substr($this->RV,-1*(strlen($word) + 2), strlen($word) + 2) == "gu".$word)
264
+ {
265
+ $this->word = substr($this->word,0, strlen($this->word) -(strlen($word) + 1) );
266
+ $return = true;
267
+ }
268
+ else
269
+ {
270
+ $this->word = substr($this->word,0, strlen($this->word) -(strlen($word)) );
271
+ $return = true;
272
+ }
273
+ }
274
+ unset($search,$word);
275
+ $this->word = str_replace("á","a",$this->word);
276
+ $this->word = str_replace("é","e",$this->word);
277
+ $this->word = str_replace("í","i",$this->word);
278
+ $this->word = str_replace("ó","o",$this->word);
279
+ $this->word = str_replace("ú","u",$this->word);
280
+ $this->word = str_replace("ü","u",$this->word);
281
+ return $return;
282
+ }
283
+
284
+
285
+ /* funciones utilizadas*/
286
+ function saddorsort($a, $b)
287
+ {
288
+ if (strlen($a) == strlen($b)) {
289
+ return 0;
290
+ }
291
+ return (strlen($a) < strlen($b)) ? 1 : -1;
292
+ }
293
+ function splitword()
294
+ {
295
+ $flag1=false;
296
+ $flag2=false;
297
+ $this->R1="";
298
+ $this->R2="";
299
+ $this->RV="";
300
+ for ($i = 1; $i < strlen($this->word); $i++)
301
+ {
302
+ if ($flag1)
303
+ $this->R1.=$this->word[$i];
304
+ if ($flag2)
305
+ $this->R2.=$this->word[$i];
306
+
307
+ if ($i+1 >= strlen($this->word))
308
+ break;
309
+
310
+ if ($this->char_is($this->word[$i]) == consonante &&
311
+ $this->char_is(@$this->word[$i+1]) == vocal &&
312
+ $flag1 == true && $flag2 == false)
313
+ $flag2=true;
314
+
315
+ if ($this->char_is($this->word[$i]) == consonante &&
316
+ $this->char_is($this->word[$i+1]) == vocal &&
317
+ $flag1 == false)
318
+ $flag1=true;
319
+ }
320
+
321
+
322
+ /* Buscando RV*/
323
+ $flag1=false;
324
+ if ($this->char_is($this->word[1]) == consonante)
325
+ {
326
+ for ($i = 2; $i < strlen($this->word); $i++)
327
+ if ($this->char_is($this->word[$i]) == vocal)
328
+ break;
329
+ $i++;
330
+ $this->RV = substr($this->word,$i);
331
+ }
332
+ else if ($this->char_is($this->word[1]) == vocal && $this->char_is($this->word[0]) == vocal)
333
+ {
334
+ for ($i = 2; $i < strlen($this->word); $i++)
335
+ if ($this->char_is($this->word[$i]) == consonante)
336
+ break;
337
+ $i++;
338
+ $this->RV = substr($this->word,$i);
339
+ }
340
+ else if (strlen($this->word) > 2)
341
+ $this->RV = substr($this->word,3);
342
+
343
+ unset($flag1,$flag2,$i);
344
+ }
345
+
346
+ function char_is($char)
347
+ {
348
+ $char = strtolower($char);
349
+ if ($char == "")
350
+ return;
351
+ $vowel = "aeiouáéíóúü";
352
+ $consonant = "bcdfghijklmnñopqrsvtxwyz";
353
+ if (strstr($vowel,$char))
354
+ return vocal;
355
+ if (strstr($consonant,$char))
356
+ return consonante;
357
+ }
358
+ }
359
+ }
360
+
361
+ /*
362
+ Stem caching added by Rob Marsh, SJ
363
+ http://rmarsh.com
364
+ */
365
+
366
+ $Stemmer = new PorterStemmer();
367
+ $StemCache = array();
368
+
369
+ function stem($word) {
370
+ global $Stemmer, $StemCache;
371
+ if (!isset($StemCache[$word])) {
372
+ $stemmedword = $Stemmer->Stem($word);
373
+ $StemCache[$word] = $stemmedword;
374
+ }
375
+ else {
376
+ $stemmedword = $StemCache[$word] ;
377
+ }
378
+ return $stemmedword;
379
+ }
380
+
381
+ ?>
languages/es/stopwords.php CHANGED
@@ -1,4 +1,4 @@
1
  <?php
2
  // the list of common words we want to ignore. NB anything shorter than 4 characters is knocked by the plugin and doesn't need to figure here
3
- $overusedwords = array("algo", "alguna", "algunas", "alguno", "algunos", "alg�n", "ambos", "ampleamos", "ante", "antes", "aquel", "aquellas", "aquellos", "aqui", "arriba", "atras", "bajo", "bastante", "bien", "cada", "cierta", "ciertas", "ciertos", "como", "conseguimos", "conseguir", "consigo", "consigue", "consiguen", "consigues", "contra", "cual", "cuando", "dentro", "desde", "donde", "durante", "ella", "ellas", "ellos", "empleais", "emplean", "emplear", "empleas", "empleo", "encima", "entonces", "entre", "erais", "eramos", "eran", "eras", "eres", "esas", "esos", "esta", "estaba", "estabais", "estaban", "estabas", "estad", "estada", "estadas", "estado", "estados", "estais", "estamos", "estan", "estando", "estar", "estaremos", "estar�", "estar�n", "estar�s", "estar�", "estar�is", "estar�a", "estar�ais", "estar�amos", "estar�an", "estar�as", "estas", "este", "estemos", "esto", "estos", "estoy", "estuve", "estuviera", "estuvierais", "estuvieran", "estuvieras", "estuvieron", "estuviese", "estuvieseis", "estuviesen", "estuvieses", "estuvimos", "estuviste", "estuvisteis", "estuvi�ramos", "estuvi�semos", "estuvo", "est�", "est�bamos", "est�is", "est�n", "est�s", "est�", "est�is", "est�n", "est�s", "fuera", "fuerais", "fueran", "fueras", "fueron", "fuese", "fueseis", "fuesen", "fueses", "fuimos", "fuiste", "fuisteis", "fu�ramos", "fu�semos", "gueno", "habida", "habidas", "habido", "habidos", "habiendo", "habremos", "habr�", "habr�n", "habr�s", "habr�", "habr�is", "habr�a", "habr�ais", "habr�amos", "habr�an", "habr�as", "hab�is", "hab�a", "hab�ais", "hab�amos", "hab�an", "hab�as", "hace", "haceis", "hacemos", "hacen", "hacer", "haces", "hago", "hasta", "haya", "hayamos", "hayan", "hayas", "hay�is", "hemos", "hube", "hubiera", "hubierais", "hubieran", "hubieras", "hubieron", "hubiese", "hubieseis", "hubiesen", "hubieses", "hubimos", "hubiste", "hubisteis", "hubi�ramos", "hubi�semos", "hubo", "incluso", "intenta", "intentais", "intentamos", "intentan", "intentar", "intentas", "intento", "largo", "mientras", "modo", "mucho", "muchos", "m�as", "m�os", "nada", "nosotras", "nosotros", "nuestra", "nuestras", "nuestro", "nuestros", "otra", "otras", "otro", "otros", "para", "pero", "poco", "podeis", "podemos", "poder", "podria", "podriais", "podriamos", "podrian", "podrias", "porque", "primero desde", "puede", "pueden", "puedo", "quien", "quienes", "sabe", "sabeis", "sabemos", "saben", "saber", "sabes", "seamos", "sean", "seas", "sentid", "sentida", "sentidas", "sentido", "sentidos", "seremos", "ser�", "ser�n", "ser�s", "ser�", "ser�is", "ser�a", "ser�ais", "ser�amos", "ser�an", "ser�as", "se�is", "siendo", "siente", "sintiendo", "sobre", "sois", "solamente", "solo", "somos", "suya", "suyas", "suyo", "suyos", "tambi�n", "tanto", "tendremos", "tendr�", "tendr�n", "tendr�s", "tendr�", "tendr�is", "tendr�a", "tendr�ais", "tendr�amos", "tendr�an", "tendr�as", "tened", "teneis", "tenemos", "tener", "tenga", "tengamos", "tengan", "tengas", "tengo", "teng�is", "tenida", "tenidas", "tenido", "tenidos", "teniendo", "ten�is", "ten�a", "ten�ais", "ten�amos", "ten�an", "ten�as", "tiempo", "tiene", "tienen", "tienes", "todo", "todos", "trabaja", "trabajais", "trabajamos", "trabajan", "trabajar", "trabajas", "trabajo", "tras", "tuve", "tuviera", "tuvierais", "tuvieran", "tuvieras", "tuvieron", "tuviese", "tuvieseis", "tuviesen", "tuvieses", "tuvimos", "tuviste", "tuvisteis", "tuvi�ramos", "tuvi�semos", "tuvo", "tuya", "tuyas", "tuyo", "tuyos", "ultimo", "unas", "unos", "usais", "usamos", "usan", "usar", "usas", "vais", "valor", "vamos", "vaya", "verdad", "verdadera cierto", "verdadero", "vosostras", "vosostros", "vosotras", "vosotros", "vuestra", "vuestras", "vuestro", "vuestros", "�ramos");
4
- ?>
1
  <?php
2
  // the list of common words we want to ignore. NB anything shorter than 4 characters is knocked by the plugin and doesn't need to figure here
3
+ $overusedwords = array("algo", "alguna", "algunas", "alguno", "algunos", "algún", "ambos", "ampleamos", "ante", "antes", "aquel", "aquellas", "aquellos", "aqui", "arriba", "atras", "bajo", "bastante", "bien", "cada", "cierta", "ciertas", "ciertos", "como", "conseguimos", "conseguir", "consigo", "consigue", "consiguen", "consigues", "contra", "cual", "cuando", "dentro", "desde", "donde", "durante", "ella", "ellas", "ellos", "empleais", "emplean", "emplear", "empleas", "empleo", "encima", "entonces", "entre", "erais", "eramos", "eran", "eras", "eres", "esas", "esos", "esta", "estaba", "estabais", "estaban", "estabas", "estad", "estada", "estadas", "estado", "estados", "estais", "estamos", "estan", "estando", "estar", "estaremos", "estará", "estarán", "estarás", "estaré", "estaréis", "estaría", "estaríais", "estaríamos", "estarían", "estarías", "estas", "este", "estemos", "esto", "estos", "estoy", "estuve", "estuviera", "estuvierais", "estuvieran", "estuvieras", "estuvieron", "estuviese", "estuvieseis", "estuviesen", "estuvieses", "estuvimos", "estuviste", "estuvisteis", "estuviéramos", "estuviésemos", "estuvo", "está", "estábamos", "estáis", "están", "estás", "esté", "estéis", "estén", "estés", "fuera", "fuerais", "fueran", "fueras", "fueron", "fuese", "fueseis", "fuesen", "fueses", "fuimos", "fuiste", "fuisteis", "fuéramos", "fuésemos", "gueno", "habida", "habidas", "habido", "habidos", "habiendo", "habremos", "habrá", "habrán", "habrás", "habré", "habréis", "habría", "habríais", "habríamos", "habrían", "habrías", "habéis", "había", "habíais", "habíamos", "habían", "habías", "hace", "haceis", "hacemos", "hacen", "hacer", "haces", "hago", "hasta", "haya", "hayamos", "hayan", "hayas", "hayáis", "hemos", "hube", "hubiera", "hubierais", "hubieran", "hubieras", "hubieron", "hubiese", "hubieseis", "hubiesen", "hubieses", "hubimos", "hubiste", "hubisteis", "hubiéramos", "hubiésemos", "hubo", "incluso", "intenta", "intentais", "intentamos", "intentan", "intentar", "intentas", "intento", "largo", "mientras", "modo", "mucho", "muchos", "mías", "míos", "nada", "nosotras", "nosotros", "nuestra", "nuestras", "nuestro", "nuestros", "otra", "otras", "otro", "otros", "para", "pero", "poco", "podeis", "podemos", "poder", "podria", "podriais", "podriamos", "podrian", "podrias", "porque", "primero desde", "puede", "pueden", "puedo", "quien", "quienes", "sabe", "sabeis", "sabemos", "saben", "saber", "sabes", "seamos", "sean", "seas", "sentid", "sentida", "sentidas", "sentido", "sentidos", "seremos", "será", "serán", "serás", "seré", "seréis", "sería", "seríais", "seríamos", "serían", "serías", "seáis", "siendo", "siente", "sintiendo", "sobre", "sois", "solamente", "solo", "somos", "suya", "suyas", "suyo", "suyos", "también", "tanto", "tendremos", "tendrá", "tendrán", "tendrás", "tendré", "tendréis", "tendría", "tendríais", "tendríamos", "tendrían", "tendrías", "tened", "teneis", "tenemos", "tener", "tenga", "tengamos", "tengan", "tengas", "tengo", "tengáis", "tenida", "tenidas", "tenido", "tenidos", "teniendo", "tenéis", "tenía", "teníais", "teníamos", "tenían", "tenías", "tiempo", "tiene", "tienen", "tienes", "todo", "todos", "trabaja", "trabajais", "trabajamos", "trabajan", "trabajar", "trabajas", "trabajo", "tras", "tuve", "tuviera", "tuvierais", "tuvieran", "tuvieras", "tuvieron", "tuviese", "tuvieseis", "tuviesen", "tuvieses", "tuvimos", "tuviste", "tuvisteis", "tuviéramos", "tuviésemos", "tuvo", "tuya", "tuyas", "tuyo", "tuyos", "ultimo", "unas", "unos", "usais", "usamos", "usan", "usar", "usas", "vais", "valor", "vamos", "vaya", "verdad", "verdadera cierto", "verdadero", "vosostras", "vosostros", "vosotras", "vosotros", "vuestra", "vuestras", "vuestro", "vuestros", "éramos");
4
+ ?>
languages/fr/stemmer.php CHANGED
@@ -10,7 +10,7 @@
10
 
11
 
12
  // the rule patterns include all accented forms for a given language
13
- $rule_pattern = "/^([a-z������������]*)(\*){0,1}(\d)([a-z������������]*)([.|>])/";
14
 
15
  $PaiceHuskStemmerRules_fr = array(
16
  'esre1>', # { -erse > -ers }
@@ -23,9 +23,9 @@ $PaiceHuskStemmerRules_fr = array(
23
  'sf1>', # { -fs > -f }
24
  'sle1>', # { -els > -el }
25
  'slo1>', # { -ols > -ol }
26
- 's�1>', # { -�s > -� }
27
- 'tuae5.', # { -eaut� > - }
28
- 'tuae2.', # { -eaut� > -eau }
29
  'tnia0.', # { -aint > -aint }
30
  'tniv1.', # { -vint > -vin }
31
  'tni3>', # { -int > - }
@@ -33,19 +33,19 @@ $PaiceHuskStemmerRules_fr = array(
33
  'suo0.', # { -ous > -ous }
34
  'sdrail5.', # { -liards > -l }
35
  'sdrai4.', # { -iards > -i }
36
- 'er�i1>', # { -i�re > -ier }
37
  'sesue3x>', # { -euses > -euse }
38
  'esuey5i.', # { -yeuse > -i }
39
  'esue2x>', # { -euse > -eux }
40
  'se1>', # { -es > -e }
41
- 'er�g3.', # { -g�re > -g }
42
  'eca1>', # { -ace > -ac }
43
  'esiah0.', # { -haise > - }
44
  'esi1>', # { -ise > -is }
45
  'siss2.', # { -ssis > -ss }
46
  'sir2>', # { -ris > -r }
47
  'sit2>', # { -tis > -t }
48
- 'egan�1.', # { -�nage > -�nag }
49
  'egalli6>', # { -illage > - }
50
  'egass1.', # { -ssage > -sag }
51
  'egas0.', # { -sage > - }
@@ -54,7 +54,7 @@ $PaiceHuskStemmerRules_fr = array(
54
  'ette4>', # { -ette > - }
55
  'ett2>', # { -tte > -t }
56
  'etio1.', # { -oite > -oit }
57
- 'tio�4c.', # { -�oit > -c }
58
  'tio0.', # { -oit > -oit }
59
  'et1>', # { -te > -t }
60
  'eb1>', # { -be > -b }
@@ -64,19 +64,19 @@ $PaiceHuskStemmerRules_fr = array(
64
  'enia1>', # { -aine > -ain }
65
  'niatnio3.', # { -ointain > -oint }
66
  'niatg3.', # { -gtain > -gt }
67
- 'e�1>', # { -�e > -� }
68
- 'hcat1.', # { -tach� > -tach }
69
- 'hca4.', # { -ach� > - }
70
- 'tila5>', # { -alit� > - }
71
- 'tici5.', # { -icit� > - }
72
- 'tir1.', # { -rit� > -rit }
73
- 'ti3>', # { -it� > - }
74
- 'gan1.', # { -nag� > -nag }
75
- 'ga3>', # { -ag� > - }
76
- 'tehc1.', # { -chet� > -chet }
77
- 'te3>', # { -et� > - }
78
- 'it0.', # { -ti� > -ti� }
79
- '1>', # { -� > - }
80
  'eire4.', # { -erie > - }
81
  'eirue5.', # { -eurie > - }
82
  'eio1.', # { -oie > -oi }
@@ -93,11 +93,11 @@ $PaiceHuskStemmerRules_fr = array(
93
  'ela1>', # { -ale > -al }
94
  'lart2.', # { -tral > -tr }
95
  'lani2>', # { -inal > -in }
96
- 'la�2>', # { -�al > -� }
97
- 'siay4i.', # { -yais > -i }
98
- 'siassia7.', # { -aissais > - }
99
- 'siarv1*.', # { -vrais > -vrai if intact }
100
- 'sia1>', # { -ais > -ai }
101
  'tneiayo6i.', # { -oyaient > -oi }
102
  'tneiay6i.', # { -yaient > -i }
103
  'tneiassia9.', # { -aissaient > - }
@@ -113,16 +113,16 @@ $PaiceHuskStemmerRules_fr = array(
113
  'tiare5>', # { -erait > - }
114
  'iare4>', # { -erai > - }
115
  'are3>', # { -era > - }
116
- 'tiay4i.', # { -yait > -i }
117
  'tia3>', # { -ait > - }
118
- 'tnay4i.', # { -yant > -i }
119
- 'em�iu5>', # { -ui�me > - }
120
- 'em�i4>', # { -i�me > - }
121
  'tnaun3.', # { -nuant > -nu }
122
  'tnauqo3.', # { -oquant > -oqu }
123
  'tnau4>', # { -uant > - }
124
  'tnaf0.', # { -fant > -fant }
125
- 'tnat�2>', # { -�tant > -�t }
126
  'tna3>', # { -ant > - }
127
  'tno3>', # { -ont > - }
128
  'zeiy4i.', # { -yiez > -i }
@@ -142,19 +142,19 @@ $PaiceHuskStemmerRules_fr = array(
142
  'tnemessi8.', # { -issement > - }
143
  'tneme5>', # { -ement > - }
144
  'tnemia4.', # { -aiment > -ai }
145
- 'tnem�5>', # { -�ment > - }
146
  'el2l>', # { -le > -l }
147
  'lle3le>', # { -ell > -el }
148
- 'let�0.', # { -�tel > -�tel }
149
  'lepp0.', # { -ppel > -ppel }
150
  'le2>', # { -el > - }
151
  'srei1>', # { -iers > -ier }
152
  'reit3.', # { -tier > -t }
153
  'reila2.', # { -alier > -ali }
154
  'rei3>', # { -ier > - }
155
- 'ert�e5.', # { -e�tre > - }
156
- 'ert��1.', # { -��tre > -��tr }
157
- 'ert�4.', # { -�tre > - }
158
  'drai4.', # { -iard > - }
159
  'erdro0.', # { -ordre > -ordre }
160
  'erute5.', # { -eture > - }
@@ -166,7 +166,7 @@ $PaiceHuskStemmerRules_fr = array(
166
  'erul3.', # { -lure > -l }
167
  'er2r>', # { -re > -r }
168
  'nn1>', # { -nn > -n }
169
- 'r�i3.', # { -i�r > - }
170
  'srev0.', # { -vers > -vers }
171
  'sr1>', # { -rs > -r }
172
  'rid2>', # { -dir > -d }
@@ -201,15 +201,15 @@ $PaiceHuskStemmerRules_fr = array(
201
  'esso1>', # { -osse > -oss }
202
  'ess2>', # { -sse > -s }
203
  'tio3.', # { -oit > - }
204
- 'r�s2re.', # { -s�r > -ser }
205
- 'r�0e.', # { -�r > -�re }
206
- 'esn1.', # { -nse > -�ns }
207
  'eu1>', # { -ue > -u }
208
  'sua0.', # { -aus > -aus }
209
  'su1>', # { -us > -u }
210
  'utt1>', # { -utt > -tt }
211
- 'tu�3c.', # { -�ut > -c }
212
- 'u�2c.', # { -�u > -c }
213
  'ur1.', # { -ru > -r }
214
  'ehcn2>', # { -nche > -nc }
215
  'ehcu1>', # { -uche > -uch }
@@ -221,7 +221,7 @@ $PaiceHuskStemmerRules_fr = array(
221
  'snori5.', # { -irons > - }
222
  'snore5>', # { -erons > - }
223
  'snortt4>', # { -ttrons > -tt }
224
- 'snort�a7.', # { -a�trons > - }
225
  'snort3.', # { -trons > -tr }
226
  'snor4.', # { -rons > - }
227
  'snossi6.', # { -issons > - }
@@ -239,8 +239,8 @@ $PaiceHuskStemmerRules_fr = array(
239
  'noi3>', # { -ion > - }
240
  'snoya0.', # { -ayons > -ayons }
241
  'snoy4i.', # { -yons > -i }
242
- 'sno�a1.', # { -a�ons > -a�on }
243
- 'sno�r1.', # { -r�ons > -r�on }
244
  'snoe4.', # { -eons > - }
245
  'snosiar1>', # { -raisons > - }
246
  'snola1.', # { -alons > -alon }
@@ -250,9 +250,9 @@ $PaiceHuskStemmerRules_fr = array(
250
  'tnennei4.', # { -iennent > -ien }
251
  'ennei2>', # { -ienne > -ien }
252
  'snei1>', # { -iens > -ien }
253
- 'sne�1>', # { -�ens > -�en }
254
- 'enne�5e.', # { -�enne > -e }
255
- 'ne�3e.', # { -�en > -e }
256
  'neic0.', # { -cien > -cien }
257
  'neiv0.', # { -vien > -vien }
258
  'nei3.', # { -ien > - }
@@ -278,10 +278,10 @@ $PaiceHuskStemmerRules_fr = array(
278
  'tnerim3.', # { -mirent > -mir }
279
  'tneris3>', # { -sirent > -sir }
280
  'tneri5.', # { -irent > - }
281
- 't�a3.', # { -a�t > - }
282
  'riss2.', # { -ssir > -ss }
283
- 't�2.', # { -�t > - }
284
- 't�2>', # { -�t > - }
285
  'ario2.', # { -oira > -oi }
286
  'arim1.', # { -mira > -m }
287
  'ara1.', # { -ara > -ar }
@@ -319,7 +319,7 @@ $PaiceHuskStemmerRules_fr = array(
319
  'ai2>', # { -ia > - }
320
  'a1>', # { -a > - }
321
  'adr1.', # { -rda > -rd }
322
- 'tner�5>', # { -�rent > - }
323
  'evir1.', # { -rive > -riv }
324
  'evio4>', # { -oive > - }
325
  'evi3.', # { -ive > - }
@@ -356,14 +356,14 @@ $PaiceHuskStemmerRules_fr = array(
356
  'eg1>', # { -ge > -g }
357
  'tuo0.', # { -out > -out }
358
  'tul2>', # { -lut > -l }
359
- 't�2>', # { -�t > - }
360
  'ev1>', # { -ve > -v }
361
- 'v�2ve>', # { -�v > -ev }
362
  'rtt1>', # { -ttr > -tt }
363
  'emissi6.', # { -issime > - }
364
  'em1.', # { -me > -m }
365
  'ehc1.', # { -che > -ch }
366
- 'c�i2c�.', # { -i�c > -i�c }
367
  'libi2l.', # { -ibil > -ibl }
368
  'llie1.', # { -eill > -eil }
369
  'liei4i.', # { -ieil > -i }
@@ -373,28 +373,28 @@ $PaiceHuskStemmerRules_fr = array(
373
  'xuell4.', # { -lleux > -l }
374
  'xuere5.', # { -ereux > - }
375
  'xue3>', # { -eux > - }
376
- 'rb�3rb�.', # { -�br > -�br }
377
  'tur2.', # { -rut > -r }
378
- 'rir�4re.', # { -�rir > -er }
379
  'rir2.', # { -rir > -r }
380
- 'c�2ca.', # { -�c > -ac }
381
  'snu1.', # { -uns > -un }
382
- 'rt�a4.', # { -a�tr > - }
383
  'long2.', # { -gnol > -gn }
384
  'vec2.', # { -cev > -c }
385
- '1c>', # { -� > -c }
386
  'ssilp3.', # { -pliss > -pl }
387
  'silp2.', # { -plis > -pl }
388
- 't�hc2te.', # { -ch�t > -chet }
389
- 'n�m2ne.', # { -m�n > -men }
390
  'llepp1.', # { -ppell > -ppel }
391
  'tan2.', # { -nat > -n }
392
- 'rv�3rve.', # { -�vr > -evr }
393
- 'rv�3rve.', # { -�vr > -evr }
394
- 'r�2re.', # { -�r > -er }
395
- 'r�2re.', # { -�r > -er }
396
- 't�2te.', # { -�t > -et }
397
- 't�2te.', # { -�t > -et }
398
  'epp1.', # { -ppe > -pp }
399
  'eya2i.', # { -aye > -ai }
400
  'ya1i.', # { -ay > -ai }
@@ -407,7 +407,7 @@ $PaiceHuskStemmerRules_fr = array(
407
  'end0.'
408
  );
409
 
410
- // returns the number of the first rule from the rule number $rule_number
411
  // that can be applied to the given reversed form
412
  // returns -1 if no rule can be applied, ie the stem has been found
413
  function getFirstRule($reversed_form, $rule_number) {
@@ -426,14 +426,14 @@ function getFirstRule($reversed_form, $rule_number) {
426
 
427
 
428
  /*
429
- * Check the acceptability of a stem
430
  *
431
  * $reversed_stem: the stem to check in reverse form
432
  */
433
  function checkAcceptability($reversed_stem) {
434
- //if (preg_match("/[a��e����i��o�u��y]$/",utf8_encode($reversed_stem))) {
435
- if (preg_match("/[a��e����i��o�u��y]$/",$reversed_stem)) {
436
- // if the form starts with a vowel then at least two letters must remain after stemming (e.g.: "�taient" --> "�t")
437
  return (strlen($reversed_stem) > 2);
438
  }
439
  else {
@@ -442,8 +442,8 @@ function checkAcceptability($reversed_stem) {
442
  return False;
443
  }
444
  // and at least one of these must be a vowel or "y"
445
- //return (preg_match("/[a��e����i��o�u��y]/",utf8_encode($reversed_stem)));
446
- return (preg_match("/[a��e����i��o�u��y]/", $reversed_stem));
447
  }
448
  }
449
 
@@ -486,7 +486,7 @@ function PaiceHuskStemmer($form) {
486
  $rule_number++;
487
  }
488
  }
489
-
490
  return utf8_encode(strrev($reversed_form));
491
 
492
  }
@@ -500,11 +500,11 @@ $StemCache = array();
500
 
501
  function stem($word) {
502
  global $StemCache;
503
- if (!isset($StemCache[$word])) {
504
  $stemmedword = PaiceHuskStemmer($word);
505
- $StemCache[$word] = $stemmedword;
506
  }
507
- else {
508
  $stemmedword = $StemCache[$word] ;
509
  }
510
  return $stemmedword;
10
 
11
 
12
  // the rule patterns include all accented forms for a given language
13
+ $rule_pattern = "/^([a-zàâèéêëîïôûùç]*)(\*){0,1}(\d)([a-zàâèéêëîïôûùç]*)([.|>])/";
14
 
15
  $PaiceHuskStemmerRules_fr = array(
16
  'esre1>', # { -erse > -ers }
23
  'sf1>', # { -fs > -f }
24
  'sle1>', # { -els > -el }
25
  'slo1>', # { -ols > -ol }
26
+ '1>', # { s > }
27
+ 'étuae5.', # { -eauté > - }
28
+ 'étuae2.', # { -eauté > -eau }
29
  'tnia0.', # { -aint > -aint }
30
  'tniv1.', # { -vint > -vin }
31
  'tni3>', # { -int > - }
33
  'suo0.', # { -ous > -ous }
34
  'sdrail5.', # { -liards > -l }
35
  'sdrai4.', # { -iards > -i }
36
+ 'erèi1>', # { -ière > -ier }
37
  'sesue3x>', # { -euses > -euse }
38
  'esuey5i.', # { -yeuse > -i }
39
  'esue2x>', # { -euse > -eux }
40
  'se1>', # { -es > -e }
41
+ 'erèg3.', # { -gère > -g }
42
  'eca1>', # { -ace > -ac }
43
  'esiah0.', # { -haise > - }
44
  'esi1>', # { -ise > -is }
45
  'siss2.', # { -ssis > -ss }
46
  'sir2>', # { -ris > -r }
47
  'sit2>', # { -tis > -t }
48
+ 'egané1.', # { nage > nag }
49
  'egalli6>', # { -illage > - }
50
  'egass1.', # { -ssage > -sag }
51
  'egas0.', # { -sage > - }
54
  'ette4>', # { -ette > - }
55
  'ett2>', # { -tte > -t }
56
  'etio1.', # { -oite > -oit }
57
+ 'tioç4c.', # { oit > -c }
58
  'tio0.', # { -oit > -oit }
59
  'et1>', # { -te > -t }
60
  'eb1>', # { -be > -b }
64
  'enia1>', # { -aine > -ain }
65
  'niatnio3.', # { -ointain > -oint }
66
  'niatg3.', # { -gtain > -gt }
67
+ '1>', # { e > }
68
+ 'éhcat1.', # { -taché > -tach }
69
+ 'éhca4.', # { -aché > - }
70
+ 'étila5>', # { -alité > - }
71
+ 'étici5.', # { -icité > - }
72
+ 'étir1.', # { -rité > -rit }
73
+ 'éti3>', # { -ité > - }
74
+ 'égan1.', # { -nagé > -nag }
75
+ 'éga3>', # { -agé > - }
76
+ 'étehc1.', # { -cheté > -chet }
77
+ 'éte3>', # { -eté > - }
78
+ 'éit0.', # { -tié > -tié }
79
+ 'é1>', # { > - }
80
  'eire4.', # { -erie > - }
81
  'eirue5.', # { -eurie > - }
82
  'eio1.', # { -oie > -oi }
93
  'ela1>', # { -ale > -al }
94
  'lart2.', # { -tral > -tr }
95
  'lani2>', # { -inal > -in }
96
+ 'laé2>', # { al > }
97
+ 'siay4i.', # { -yais > -i }
98
+ 'siassia7.', # { -aissais > - }
99
+ 'siarv1*.', # { -vrais > -vrai if intact }
100
+ 'sia1>', # { -ais > -ai }
101
  'tneiayo6i.', # { -oyaient > -oi }
102
  'tneiay6i.', # { -yaient > -i }
103
  'tneiassia9.', # { -aissaient > - }
113
  'tiare5>', # { -erait > - }
114
  'iare4>', # { -erai > - }
115
  'are3>', # { -era > - }
116
+ 'tiay4i.', # { -yait > -i }
117
  'tia3>', # { -ait > - }
118
+ 'tnay4i.', # { -yant > -i }
119
+ 'emèiu5>', # { -uième > - }
120
+ 'emèi4>', # { -ième > - }
121
  'tnaun3.', # { -nuant > -nu }
122
  'tnauqo3.', # { -oquant > -oqu }
123
  'tnau4>', # { -uant > - }
124
  'tnaf0.', # { -fant > -fant }
125
+ 'tnaté2>', # { tant > t }
126
  'tna3>', # { -ant > - }
127
  'tno3>', # { -ont > - }
128
  'zeiy4i.', # { -yiez > -i }
142
  'tnemessi8.', # { -issement > - }
143
  'tneme5>', # { -ement > - }
144
  'tnemia4.', # { -aiment > -ai }
145
+ 'tnemé5>', # { ment > - }
146
  'el2l>', # { -le > -l }
147
  'lle3le>', # { -ell > -el }
148
+ 'letô0.', # { tel > tel }
149
  'lepp0.', # { -ppel > -ppel }
150
  'le2>', # { -el > - }
151
  'srei1>', # { -iers > -ier }
152
  'reit3.', # { -tier > -t }
153
  'reila2.', # { -alier > -ali }
154
  'rei3>', # { -ier > - }
155
+ 'ertâe5.', # { -eâtre > - }
156
+ 'ertâé1.', # { -éâtre > -éâtr }
157
+ 'ertâ4.', # { tre > - }
158
  'drai4.', # { -iard > - }
159
  'erdro0.', # { -ordre > -ordre }
160
  'erute5.', # { -eture > - }
166
  'erul3.', # { -lure > -l }
167
  'er2r>', # { -re > -r }
168
  'nn1>', # { -nn > -n }
169
+ 'i3.', # { -ièr > - }
170
  'srev0.', # { -vers > -vers }
171
  'sr1>', # { -rs > -r }
172
  'rid2>', # { -dir > -d }
201
  'esso1>', # { -osse > -oss }
202
  'ess2>', # { -sse > -s }
203
  'tio3.', # { -oit > - }
204
+ 's2re.', # { -sèr > -ser }
205
+ '0e.', # { r > re }
206
+ 'esn1.', # { -nse > ns }
207
  'eu1>', # { -ue > -u }
208
  'sua0.', # { -aus > -aus }
209
  'su1>', # { -us > -u }
210
  'utt1>', # { -utt > -tt }
211
+ 'tuç3c.', # { ut > -c }
212
+ '2c.', # { u > -c }
213
  'ur1.', # { -ru > -r }
214
  'ehcn2>', # { -nche > -nc }
215
  'ehcu1>', # { -uche > -uch }
221
  'snori5.', # { -irons > - }
222
  'snore5>', # { -erons > - }
223
  'snortt4>', # { -ttrons > -tt }
224
+ 'snortîa7.', # { -aîtrons > - }
225
  'snort3.', # { -trons > -tr }
226
  'snor4.', # { -rons > - }
227
  'snossi6.', # { -issons > - }
239
  'noi3>', # { -ion > - }
240
  'snoya0.', # { -ayons > -ayons }
241
  'snoy4i.', # { -yons > -i }
242
+ 'snoça1.', # { -açons > -açon }
243
+ 'snoçr1.', # { -rçons > -rçon }
244
  'snoe4.', # { -eons > - }
245
  'snosiar1>', # { -raisons > - }
246
  'snola1.', # { -alons > -alon }
250
  'tnennei4.', # { -iennent > -ien }
251
  'ennei2>', # { -ienne > -ien }
252
  'snei1>', # { -iens > -ien }
253
+ 'sneé1>', # { ens > en }
254
+ 'enneé5e.', # { enne > -e }
255
+ 'neé3e.', # { en > -e }
256
  'neic0.', # { -cien > -cien }
257
  'neiv0.', # { -vien > -vien }
258
  'nei3.', # { -ien > - }
278
  'tnerim3.', # { -mirent > -mir }
279
  'tneris3>', # { -sirent > -sir }
280
  'tneri5.', # { -irent > - }
281
+ 'a3.', # { -aît > - }
282
  'riss2.', # { -ssir > -ss }
283
+ '2.', # { t > - }
284
+ '2>', # { t > - }
285
  'ario2.', # { -oira > -oi }
286
  'arim1.', # { -mira > -m }
287
  'ara1.', # { -ara > -ar }
319
  'ai2>', # { -ia > - }
320
  'a1>', # { -a > - }
321
  'adr1.', # { -rda > -rd }
322
+ 'tnerè5>', # { rent > - }
323
  'evir1.', # { -rive > -riv }
324
  'evio4>', # { -oive > - }
325
  'evi3.', # { -ive > - }
356
  'eg1>', # { -ge > -g }
357
  'tuo0.', # { -out > -out }
358
  'tul2>', # { -lut > -l }
359
+ '2>', # { t > - }
360
  'ev1>', # { -ve > -v }
361
+ '2ve>', # { v > -ev }
362
  'rtt1>', # { -ttr > -tt }
363
  'emissi6.', # { -issime > - }
364
  'em1.', # { -me > -m }
365
  'ehc1.', # { -che > -ch }
366
+ 'i2cè.', # { -iéc > -ièc }
367
  'libi2l.', # { -ibil > -ibl }
368
  'llie1.', # { -eill > -eil }
369
  'liei4i.', # { -ieil > -i }
373
  'xuell4.', # { -lleux > -l }
374
  'xuere5.', # { -ereux > - }
375
  'xue3>', # { -eux > - }
376
+ 'rbé3rbè.', # { br > br }
377
  'tur2.', # { -rut > -r }
378
+ 'riré4re.', # { rir > -er }
379
  'rir2.', # { -rir > -r }
380
+ '2ca.', # { c > -ac }
381
  'snu1.', # { -uns > -un }
382
+ 'rtîa4.', # { -aîtr > - }
383
  'long2.', # { -gnol > -gn }
384
  'vec2.', # { -cev > -c }
385
+ 'ç1c>', # { > -c }
386
  'ssilp3.', # { -pliss > -pl }
387
  'silp2.', # { -plis > -pl }
388
+ 'hc2te.', # { -chèt > -chet }
389
+ 'm2ne.', # { -mèn > -men }
390
  'llepp1.', # { -ppell > -ppel }
391
  'tan2.', # { -nat > -n }
392
+ 'rvè3rve.', # { vr > -evr }
393
+ 'rvé3rve.', # { vr > -evr }
394
+ '2re.', # { r > -er }
395
+ '2re.', # { r > -er }
396
+ '2te.', # { t > -et }
397
+ '2te.', # { t > -et }
398
  'epp1.', # { -ppe > -pp }
399
  'eya2i.', # { -aye > -ai }
400
  'ya1i.', # { -ay > -ai }
407
  'end0.'
408
  );
409
 
410
+ // returns the number of the first rule from the rule number $rule_number
411
  // that can be applied to the given reversed form
412
  // returns -1 if no rule can be applied, ie the stem has been found
413
  function getFirstRule($reversed_form, $rule_number) {
426
 
427
 
428
  /*
429
+ * Check the acceptability of a stem
430
  *
431
  * $reversed_stem: the stem to check in reverse form
432
  */
433
  function checkAcceptability($reversed_stem) {
434
+ //if (preg_match("/[aàâeèéêëiîïoôuûùy]$/",utf8_encode($reversed_stem))) {
435
+ if (preg_match("/[aàâeèéêëiîïoôuûùy]$/",$reversed_stem)) {
436
+ // if the form starts with a vowel then at least two letters must remain after stemming (e.g.: "étaient" --> "ét")
437
  return (strlen($reversed_stem) > 2);
438
  }
439
  else {
442
  return False;
443
  }
444
  // and at least one of these must be a vowel or "y"
445
+ //return (preg_match("/[aàâeèéêëiîïoôuûùy]/",utf8_encode($reversed_stem)));
446
+ return (preg_match("/[aàâeèéêëiîïoôuûùy]/", $reversed_stem));
447
  }
448
  }
449
 
486
  $rule_number++;
487
  }
488
  }
489
+
490
  return utf8_encode(strrev($reversed_form));
491
 
492
  }
500
 
501
  function stem($word) {
502
  global $StemCache;
503
+ if (!isset($StemCache[$word])) {
504
  $stemmedword = PaiceHuskStemmer($word);
505
+ $StemCache[$word] = $stemmedword;
506
  }
507
+ else {
508
  $stemmedword = $StemCache[$word] ;
509
  }
510
  return $stemmedword;
languages/fr/stopwords.php CHANGED
@@ -1,4 +1,4 @@
1
  <?php
2
  // the list of common words we want to ignore. NB anything shorter than 4 characters is knocked by the plugin and doesn't need to figure here
3
- $overusedwords = array("afin", "aient", "aies", "ailleurs", "ainsi", "alentour", "alias", "allaient", "allais", "allait", "allez", "allons", "alors", "apr�s", "apr�s-demain", "arri�re", "assez", "attendu", "au-dedans", "au-dehors", "au-del�", "au-dessous", "au-dessus", "au-devant", "aucun", "aucune", "audit", "aujourd'", "aujourd'hui", "auparavant", "aupr�s", "auquel", "aura", "aurai", "auraient", "aurais", "aurait", "auras", "aurez", "auriez", "aurions", "aurons", "auront", "aussi", "aussit�t", "autant", "autour", "autre", "autrefois", "autres", "autrui", "auxdites", "auxdits", "auxquelles", "auxquels", "avaient", "avais", "avait", "avant", "avant-hier", "avec", "avez", "aviez", "avions", "avoir", "avons", "ayant", "ayante", "ayantes", "ayants", "ayez", "ayons", "banco", "beaucoup", "bien", "bient�t", "c'est-�-dire", "c.-�-d.", "cahin-caha", "ceci", "cela", "celle", "celle-ci", "celle-l�", "celles", "celles-ci", "celles-l�", "celui", "celui-ci", "celui-l�", "cent", "cents", "cependant", "certain", "certaine", "certaines", "certains", "certes", "cette", "ceux", "ceux-ci", "ceux-l�", "chacun", "chacune", "chaque", "cher", "chez", "chose", "ci-apr�s", "ci-dessous", "ci-dessus", "cinq", "cinquante", "cinquante-cinq", "cinquante-deux", "cinquante-et-un", "cinquante-huit", "cinquante-neuf", "cinquante-quatre", "cinquante-sept", "cinquante-six", "cinquante-trois", "combien", "comme", "comment", "contrario", "contre", "cours", "crescendo", "c�ans", "d'abord", "d'accord", "d'affil�e", "d'ailleurs", "d'apr�s", "d'arrache-pied", "d'embl�e", "d'un", "d'une", "dans", "davantage", "debout", "dedans", "dehors", "del�", "demain", "depuis", "derechef", "derri�re", "desdites", "desdits", "desquelles", "desquels", "dessous", "dessus", "deux", "devant", "devers", "de��", "diff�rentes", "diff�rents", "dire", "disent", "dito", "divers", "diverses", "dix-huit", "dix-neuf", "dix-sept", "donc", "dont", "dor�navant", "douze", "dudit", "duquel", "durant", "d�j�", "d�pit", "d�sormais", "elle", "elles", "en-dehors", "encore", "enfin", "ensemble", "ensuite", "entre", "entre-temps", "envers", "environ", "et/ou", "eues", "eurent", "eusse", "eussent", "eusses", "eussiez", "eussions", "expr�s", "extenso", "extremis", "e�mes", "e�tes", "facto", "faire", "fais", "faisaient", "faisais", "faisait", "faisons", "fait", "faites", "fallait", "faudrait", "faut", "faveur", "flac", "fors", "fort", "forte", "fortiori", "frais", "furent", "fusse", "fussent", "fusses", "fussiez", "fussions", "f�mes", "f�tes", "grand-chose", "grosso", "gr�ce", "gu�re", "haut", "hein", "hier", "hol�", "hormis", "hors", "huit", "ibidem", "ici-bas", "idem", "illico", "ipso", "item", "jadis", "jamais", "jusqu'", "jusqu'au", "jusqu'aux", "jusqu'", "jusque", "juste", "l'autre", "l'encontre", "l'instar", "l'insu", "l'issue", "l'occasion", "l'on", "l'un", "l'une", "l'�gard", "ladite", "laquelle", "lequel", "lesquelles", "lesquels", "leur", "leurs", "loin", "longtemps", "lors", "lorsqu'", "lorsque", "l�-bas", "l�-dedans", "l�-dehors", "l�-derri�re", "l�-dessous", "l�-dessus", "l�-devant", "l�-haut", "maint", "mainte", "maintenant", "maintes", "maints", "mais", "malgr�", "marge", "mati�re", "mien", "mienne", "miennes", "miens", "mieux", "mille", "milliards", "millions", "minima", "modo", "moins", "moult", "moyennant", "m�me", "m�mes", "nagu�re", "neuf", "nonante", "nonobstant", "notre", "nous", "nulle", "n�anmoins", "n�tre", "n�tres", "octante", "onze", "ouais", "outre", "par-ci", "par-del�", "par-derri�re", "par-dessous", "par-dessus", "par-devant", "par-l�", "parbleu", "parce", "parfois", "parmi", "part", "partir", "partout", "passim", "pass�", "pendant", "personne", "petto", "peur", "peut", "peut-�tre", "peuvent", "peux", "plus", "plusieurs", "plut�t", "point", "posteriori", "pour", "pourquoi", "pourtant", "pourvu", "presqu'", "presque", "primo", "priori", "prou", "pr�s", "pr�alable", "puis", "puisqu'", "puisque", "quand", "quant", "quarante", "quarante-cinq", "quarante-deux", "quarante-et-un", "quarante-huit", "quarante-neuf", "quarante-quatre", "quarante-sept", "quarante-six", "quarante-trois", "quasi", "quatorze", "quatre", "quatre-vingt", "quatre-vingt-cinq", "quatre-vingt-deux", "quatre-vingt-dix", "quatre-vingt-dix-huit", "quatre-vingt-dix-neuf", "quatre-vingt-dix-sept", "quatre-vingt-douze", "quatre-vingt-huit", "quatre-vingt-neuf", "quatre-vingt-onze", "quatre-vingt-quatorze", "quatre-vingt-quatre", "quatre-vingt-quinze", "quatre-vingt-seize", "quatre-vingt-sept", "quatre-vingt-six", "quatre-vingt-treize", "quatre-vingt-trois", "quatre-vingt-un", "quatre-vingt-une", "quatre-vingts", "quel", "quelle", "quelles", "quelqu'", "quelqu'un", "quelqu'une", "quelque", "quelquefois", "quelques", "quelques-unes", "quelques-uns", "quels", "quiconque", "quinze", "quoi", "quoiqu'", "quoique", "raison", "rapport", "regard", "revoici", "revoil�", "rien", "sans", "sauf", "secundo", "sein", "seize", "selon", "sensu", "sept", "septante", "sera", "serai", "seraient", "serais", "serait", "seras", "serez", "seriez", "serions", "serons", "seront", "sien", "sienne", "siennes", "siens", "sine", "sinon", "situ", "sit�t", "soient", "sois", "soit", "soixante", "soixante-cinq", "soixante-deux", "soixante-dix", "soixante-dix-huit", "soixante-dix-neuf", "soixante-dix-sept", "soixante-douze", "soixante-et-onze", "soixante-et-un", "soixante-et-une", "soixante-huit", "soixante-neuf", "soixante-quatorze", "soixante-quatre", "soixante-quinze", "soixante-seize", "soixante-sept", "soixante-six", "soixante-treize", "soixante-trois", "sommes", "sont", "soudain", "sous", "souvent", "soyez", "soyons", "stricto", "suis", "suite", "sujet", "sur-le-champ", "surtout", "tacatac", "tandis", "tant", "tant�t", "tard", "telle", "telles", "tels", "tien", "tienne", "tiennes", "tiens", "toujours", "tous", "tout", "toute", "toutefois", "toutes", "travers", "treize", "trente", "trente-cinq", "trente-deux", "trente-et-un", "trente-huit", "trente-neuf", "trente-quatre", "trente-sept", "trente-six", "trente-trois", "trois", "trop", "tr�s", "unes", "vais", "vers", "vertu", "veut", "veux", "vice-versa", "vingt", "vingt-cinq", "vingt-deux", "vingt-huit", "vingt-neuf", "vingt-quatre", "vingt-sept", "vingt-six", "vingt-trois", "vis-�-vis", "vite", "vitro", "vivo", "voici", "voil�", "voire", "volontiers", "votre", "vous", "v�tre", "v�tres", "z�ro", "�gard", "�taient", "�tais", "�tait", "�tant", "�tante", "�tantes", "�tants", "�tiez", "�tions", "�t�e", "�t�es", "�t�s", "�tes", "�tre");
4
- ?>
1
  <?php
2
  // the list of common words we want to ignore. NB anything shorter than 4 characters is knocked by the plugin and doesn't need to figure here
3
+ $overusedwords = array("afin", "aient", "aies", "ailleurs", "ainsi", "alentour", "alias", "allaient", "allais", "allait", "allez", "allons", "alors", "après", "après-demain", "arrière", "assez", "attendu", "au-dedans", "au-dehors", "au-delà", "au-dessous", "au-dessus", "au-devant", "aucun", "aucune", "audit", "aujourd'", "aujourd'hui", "auparavant", "auprès", "auquel", "aura", "aurai", "auraient", "aurais", "aurait", "auras", "aurez", "auriez", "aurions", "aurons", "auront", "aussi", "aussitôt", "autant", "autour", "autre", "autrefois", "autres", "autrui", "auxdites", "auxdits", "auxquelles", "auxquels", "avaient", "avais", "avait", "avant", "avant-hier", "avec", "avez", "aviez", "avions", "avoir", "avons", "ayant", "ayante", "ayantes", "ayants", "ayez", "ayons", "banco", "beaucoup", "bien", "bientôt", "c'est-à-dire", "c.-à-d.", "cahin-caha", "ceci", "cela", "celle", "celle-ci", "celle-", "celles", "celles-ci", "celles-", "celui", "celui-ci", "celui-", "cent", "cents", "cependant", "certain", "certaine", "certaines", "certains", "certes", "cette", "ceux", "ceux-ci", "ceux-", "chacun", "chacune", "chaque", "cher", "chez", "chose", "ci-après", "ci-dessous", "ci-dessus", "cinq", "cinquante", "cinquante-cinq", "cinquante-deux", "cinquante-et-un", "cinquante-huit", "cinquante-neuf", "cinquante-quatre", "cinquante-sept", "cinquante-six", "cinquante-trois", "combien", "comme", "comment", "contrario", "contre", "cours", "crescendo", "céans", "d'abord", "d'accord", "d'affilée", "d'ailleurs", "d'après", "d'arrache-pied", "d'emblée", "d'un", "d'une", "dans", "davantage", "debout", "dedans", "dehors", "delà", "demain", "depuis", "derechef", "derrière", "desdites", "desdits", "desquelles", "desquels", "dessous", "dessus", "deux", "devant", "devers", "deçà", "différentes", "différents", "dire", "disent", "dito", "divers", "diverses", "dix-huit", "dix-neuf", "dix-sept", "donc", "dont", "dorénavant", "douze", "dudit", "duquel", "durant", "déjà", "dépit", "désormais", "elle", "elles", "en-dehors", "encore", "enfin", "ensemble", "ensuite", "entre", "entre-temps", "envers", "environ", "et/ou", "eues", "eurent", "eusse", "eussent", "eusses", "eussiez", "eussions", "exprès", "extenso", "extremis", "eûmes", "eûtes", "facto", "faire", "fais", "faisaient", "faisais", "faisait", "faisons", "fait", "faites", "fallait", "faudrait", "faut", "faveur", "flac", "fors", "fort", "forte", "fortiori", "frais", "furent", "fusse", "fussent", "fusses", "fussiez", "fussions", "fûmes", "fûtes", "grand-chose", "grosso", "grâce", "guère", "haut", "hein", "hier", "holà", "hormis", "hors", "huit", "ibidem", "ici-bas", "idem", "illico", "ipso", "item", "jadis", "jamais", "jusqu'", "jusqu'au", "jusqu'aux", "jusqu'à", "jusque", "juste", "l'autre", "l'encontre", "l'instar", "l'insu", "l'issue", "l'occasion", "l'on", "l'un", "l'une", "l'égard", "ladite", "laquelle", "lequel", "lesquelles", "lesquels", "leur", "leurs", "loin", "longtemps", "lors", "lorsqu'", "lorsque", "là-bas", "là-dedans", "là-dehors", "là-derrière", "là-dessous", "là-dessus", "là-devant", "là-haut", "maint", "mainte", "maintenant", "maintes", "maints", "mais", "malgré", "marge", "matière", "mien", "mienne", "miennes", "miens", "mieux", "mille", "milliards", "millions", "minima", "modo", "moins", "moult", "moyennant", "même", "mêmes", "naguère", "neuf", "nonante", "nonobstant", "notre", "nous", "nulle", "néanmoins", "nôtre", "nôtres", "octante", "onze", "ouais", "outre", "par-ci", "par-delà", "par-derrière", "par-dessous", "par-dessus", "par-devant", "par-", "parbleu", "parce", "parfois", "parmi", "part", "partir", "partout", "passim", "passé", "pendant", "personne", "petto", "peur", "peut", "peuttre", "peuvent", "peux", "plus", "plusieurs", "plutôt", "point", "posteriori", "pour", "pourquoi", "pourtant", "pourvu", "presqu'", "presque", "primo", "priori", "prou", "près", "préalable", "puis", "puisqu'", "puisque", "quand", "quant", "quarante", "quarante-cinq", "quarante-deux", "quarante-et-un", "quarante-huit", "quarante-neuf", "quarante-quatre", "quarante-sept", "quarante-six", "quarante-trois", "quasi", "quatorze", "quatre", "quatre-vingt", "quatre-vingt-cinq", "quatre-vingt-deux", "quatre-vingt-dix", "quatre-vingt-dix-huit", "quatre-vingt-dix-neuf", "quatre-vingt-dix-sept", "quatre-vingt-douze", "quatre-vingt-huit", "quatre-vingt-neuf", "quatre-vingt-onze", "quatre-vingt-quatorze", "quatre-vingt-quatre", "quatre-vingt-quinze", "quatre-vingt-seize", "quatre-vingt-sept", "quatre-vingt-six", "quatre-vingt-treize", "quatre-vingt-trois", "quatre-vingt-un", "quatre-vingt-une", "quatre-vingts", "quel", "quelle", "quelles", "quelqu'", "quelqu'un", "quelqu'une", "quelque", "quelquefois", "quelques", "quelques-unes", "quelques-uns", "quels", "quiconque", "quinze", "quoi", "quoiqu'", "quoique", "raison", "rapport", "regard", "revoici", "revoilà", "rien", "sans", "sauf", "secundo", "sein", "seize", "selon", "sensu", "sept", "septante", "sera", "serai", "seraient", "serais", "serait", "seras", "serez", "seriez", "serions", "serons", "seront", "sien", "sienne", "siennes", "siens", "sine", "sinon", "situ", "sitôt", "soient", "sois", "soit", "soixante", "soixante-cinq", "soixante-deux", "soixante-dix", "soixante-dix-huit", "soixante-dix-neuf", "soixante-dix-sept", "soixante-douze", "soixante-et-onze", "soixante-et-un", "soixante-et-une", "soixante-huit", "soixante-neuf", "soixante-quatorze", "soixante-quatre", "soixante-quinze", "soixante-seize", "soixante-sept", "soixante-six", "soixante-treize", "soixante-trois", "sommes", "sont", "soudain", "sous", "souvent", "soyez", "soyons", "stricto", "suis", "suite", "sujet", "sur-le-champ", "surtout", "tacatac", "tandis", "tant", "tantôt", "tard", "telle", "telles", "tels", "tien", "tienne", "tiennes", "tiens", "toujours", "tous", "tout", "toute", "toutefois", "toutes", "travers", "treize", "trente", "trente-cinq", "trente-deux", "trente-et-un", "trente-huit", "trente-neuf", "trente-quatre", "trente-sept", "trente-six", "trente-trois", "trois", "trop", "très", "unes", "vais", "vers", "vertu", "veut", "veux", "vice-versa", "vingt", "vingt-cinq", "vingt-deux", "vingt-huit", "vingt-neuf", "vingt-quatre", "vingt-sept", "vingt-six", "vingt-trois", "vis-à-vis", "vite", "vitro", "vivo", "voici", "voilà", "voire", "volontiers", "votre", "vous", "vôtre", "vôtres", "zéro", "égard", "étaient", "étais", "était", "étant", "étante", "étantes", "étants", "étiez", "étions", "étée", "étées", "étés", "êtes", "être");
4
+ ?>
languages/index.php CHANGED
@@ -1,2 +1,2 @@
1
- <?php
2
- // silence is golden
1
+ <?php
2
+ // silence is golden
languages/it/stemmer.php CHANGED
@@ -1,362 +1,362 @@
1
- <?php
2
-
3
- /*
4
-
5
- Con=verted to PHP 4 by Rob Marsh, SJ
6
-
7
- */
8
-
9
-
10
- /*
11
- *
12
- * This script as been written by Roberto Mirizzi (rob4you at vodafone dot it) in February 2007.
13
- *
14
- * It is the PHP5 implementation of Martin Porter's stemming algorithm for Italian language.
15
- *
16
- * This algorithm can be found at address: http://snowball.tartarus.org/algorithms/italian/stemmer.html.
17
- *
18
- * Use the code freely. I'm not responsible for any problems.
19
- *
20
- * Usage:
21
- *
22
- * $stemmer = new ItalianStemmer();
23
- * $stemmed_word = $stemmer->stem($word);
24
- *
25
- * All Italian characters are (originally) in latin1 (ISO-8859-1).
26
- *
27
- */
28
- class ItalianStemmer {
29
- var $vocali = array('a','e','i','o','u','','','','','');
30
- var $consonanti = array('b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','y','z','I','U');
31
- var $accenti_acuti = array('','','','','');
32
- var $accenti_gravi = array('','','','','');
33
-
34
- var $suffissi_step_0 = array('ci','gli','la','le','li','lo','mi','ne','si','ti','vi','sene','gliela','gliele','glieli','glielo','gliene','mela','mele','meli','melo','mene','tela','tele','teli','telo','tene','cela','cele','celi','celo','cene','vela','vele','veli','velo','vene');
35
-
36
- var $suffissi_step_1_a = array('anza','anze','ico','ici','ica','ice','iche','ichi','ismo','ismi','abile','abili','ibile','ibili','ista','iste','isti','ist�','ist�','ist�','oso','osi','osa','ose','mente','atrice','atrici','ante','anti');
37
- var $suffissi_step_1_b = array('azione','azioni','atore','atori');
38
- var $suffissi_step_1_c = array('logia','logie');
39
- var $suffissi_step_1_d = array('uzione','uzioni','usione','usioni');
40
- var $suffissi_step_1_e = array('enza','enze');
41
- var $suffissi_step_1_f = array('amento','amenti','imento','imenti');
42
- var $suffissi_step_1_g = array('amente');
43
- var $suffissi_step_1_h = array('it�');
44
- var $suffissi_step_1_i = array('ivo','ivi','iva','ive');
45
-
46
- var $suffissi_step_2 = array('ammo','ando','ano','are','arono','asse','assero','assi','assimo','ata','ate','ati','ato','ava','avamo','avano','avate','avi','avo','emmo','enda','ende','endi','endo','er�','erai','eranno','ere','erebbe','erebbero','erei','eremmo','eremo','ereste','eresti','erete','er�','erono','essero','ete','eva','evamo','evano','evate','evi','evo','Yamo','iamo','immo','ir�','irai','iranno','ire','irebbe','irebbero','irei','iremmo','iremo','ireste','iresti','irete','ir�','irono','isca','iscano','isce','isci','isco','iscono','issero','ita','ite','iti','ito','iva','ivamo','ivano','ivate','ivi','ivo','ono','uta','ute','uti','uto','ar','ir');
47
-
48
- var $ante_suff_a = array('ando','endo');
49
- var $ante_suff_b = array('ar','er','ir');
50
-
51
- function __construct() {
52
- usort($this->suffissi_step_0,create_function('$a,$b','return strlen($a)>strlen($b) ? -1 : 1;'));
53
- usort($this->suffissi_step_1_a,create_function('$a,$b','return strlen($a)>strlen($b) ? -1 : 1;'));
54
- usort($this->suffissi_step_2,create_function('$a,$b','return strlen($a)>strlen($b) ? -1 : 1;'));
55
- }
56
-
57
- function trim($str) {
58
- return trim($str);
59
- }
60
-
61
- function to_lower($str) {
62
- return strtolower($str);
63
- }
64
-
65
- function replace_acc_acuti($str) {
66
- return str_replace($this->accenti_acuti, $this->accenti_gravi, $str); //strtr
67
- }
68
-
69
- function put_u_after_q_to_upper($str) {
70
- return str_replace("qu", "qU", $str);
71
- }
72
-
73
- function i_u_between_vow_to_upper($str) {
74
- $pattern = '/([aeiou�����])([iu])([aeiou�����])/e';
75
- $replacement = "'$1'.strtoupper('$2').'$3'";
76
- return preg_replace($pattern, $replacement, $str);
77
- }
78
-
79
- function return_RV($str) {
80
- /*
81
- If the second letter is a consonant, RV is the region after the next following vowel,
82
- or if the first two letters are vowels, RV is the region after the next consonant, and otherwise
83
- (consonant-vowel case) RV is the region after the third letter. But RV is the end of the word if these positions cannot be found.
84
- example,
85
- m a c h o [ho] o l i v a [va] t r a b a j o [bajo] u r e o [eo] prezzo sprezzante
86
- */
87
-
88
- if(strlen($str)<2) return '';//$str;
89
-
90
- if(in_array($str[1],$this->consonanti)) {
91
- $str = substr($str,2);
92
- $str = strpbrk($str, implode($this->vocali));
93
- return substr($str,1); //secondo me devo mettere 1
94
- }
95
- else if(in_array($str[0],$this->vocali) && in_array($str[1],$this->vocali)) {
96
- $str = strpbrk($str, implode($this->consonanti));
97
- return substr($str,1);
98
- }
99
- else if(in_array($str[0],$this->consonanti) && in_array($str[1],$this->vocali)) {
100
- return substr($str,3);
101
- }
102
-
103
- }
104
-
105
- function return_R1($str){
106
- /*
107
- R1 is the region after the first non-vowel following a vowel, or is the null region at the end of the word if there is no such non-vowel.
108
- example:
109
- beautiful [iful] beauty [y] beau [NULL] animadversion [imadversion] sprinkled [kled] eucharist [harist]
110
- */
111
-
112
- $pattern = '/['.implode($this->vocali).']+'.'['.implode($this->consonanti).']'.'(.*)/';
113
- preg_match($pattern,$str,$matches);
114
-
115
- return count($matches)>=1 ? $matches[1] : '';
116
- }
117
-
118
- function return_R2($str) {
119
- /*
120
- R2 is the region after the first non-vowel following a vowel in R1, or is the null region at the end of the word if there is no such non-vowel.
121
- example:
122
- beautiful [ul] beauty [NULL] beau [NULL] animadversion [adversion] sprinkled [NULL] eucharist [ist]
123
- */
124
-
125
- $R1 = $this->return_R1($str);
126
-
127
- $pattern = '/['.implode($this->vocali).']+'.'['.implode($this->consonanti).']'.'(.*)/';
128
- preg_match($pattern,$R1,$matches);
129
-
130
- return count($matches)>=1 ? $matches[1] : '';
131
- }
132
-
133
-
134
- function step_0($str) {
135
- //Step 0: Attached pronoun
136
- //Always do steps 0
137
-
138
- $str_len = strlen($str);
139
- $rv = $this->return_RV($str);
140
- $rv_len = strlen($rv);
141
-
142
- $pos = 0;
143
- foreach($this->suffissi_step_0 as $suff) {
144
- if($rv_len-strlen($suff) < 0) continue;
145
- $pos = strpos($rv,$suff,$rv_len-strlen($suff));
146
- if($pos !== false) break;
147
- }
148
-
149
- $ante_suff = substr($rv,0,$pos);
150
- $ante_suff_len = strlen($ante_suff);
151
-
152
- foreach($this->ante_suff_a as $ante_a) {
153
- if($ante_suff_len-strlen($ante_a) < 0) continue;
154
- $pos_a = strpos($ante_suff,$ante_a,$ante_suff_len-strlen($ante_a));
155
- if($pos_a !== false) {
156
- return substr($str,0,$pos+$str_len-$rv_len);
157
- }
158
- }
159
-
160
- foreach($this->ante_suff_b as $ante_b) {
161
- if($ante_suff_len-strlen($ante_b) < 0) continue;
162
- $pos_b = strpos($ante_suff,$ante_b,$ante_suff_len-strlen($ante_b));
163
- if($pos_b !== false) {
164
- return substr($str,0,$pos+$str_len-$rv_len).'e';
165
- }
166
- }
167
-
168
- return $str;
169
- }
170
-
171
- function delete_suff($arr_suff,$str,$str_len,$where,$ovunque=false) {
172
- if($where==='r2') $r = $this->return_R2($str);
173
- else if($where==='rv') $r = $this->return_RV($str);
174
- else if($where==='r1') $r = $this->return_R1($str);
175
-
176
- $r_len = strlen($r);
177
-
178
- if($ovunque) {
179
- foreach($arr_suff as $suff) {
180
- if($str_len-strlen($suff) < 0) continue;
181
- $pos = strpos($str,$suff,$str_len-strlen($suff));
182
- if($pos !== false) {
183
- $pattern = '/'.$suff.'$/';
184
- $ret_str = preg_match($pattern,$r) ? substr($str,0,$pos) : '';
185
- if($ret_str !== '') return $ret_str;
186
- break;
187
- }
188
- }
189
- }
190
- else {
191
- foreach($arr_suff as $suff) {
192
- if($r_len-strlen($suff) < 0) continue;
193
- $pos = strpos($r,$suff,$r_len-strlen($suff));
194
- if($pos !== false) return substr($str,0,$pos+$str_len-$r_len);
195
- }
196
- }
197
- }
198
-
199
-
200
- function step_1($str) {
201
- //Step 1: Standard suffix removal
202
- //Always do steps 1
203
-
204
- $str_len = strlen($str);
205
-
206
- //delete if in R1, if preceded by 'iv', delete if in R2 (and if further preceded by 'at', delete if in R2), otherwise, if preceded by 'os', 'ic' or 'abil', delete if in R2
207
- if(count($ret_str = $this->delete_suff($this->suffissi_step_1_g,$str,$str_len,'r1'))) {
208
- if(count($ret_str1 = $this->delete_suff(array('iv'),$ret_str,strlen($ret_str),'r2'))) {
209
- if(count($ret_str2 = $this->delete_suff(array('at'),$ret_str1,strlen($ret_str1),'r2'))) return $ret_str2;
210
- else return $ret_str1;
211
- }
212
- else if(count($ret_str1 = $this->delete_suff(array('os','ic','abil'),$ret_str,strlen($ret_str),'r2'))) {
213
- return $ret_str1;
214
- }
215
- else return $ret_str;
216
- }
217
- //delete if in R2
218
- if(count($ret_str = $this->delete_suff($this->suffissi_step_1_a,$str,$str_len,'r2',true))) return $ret_str;
219
- //delete if in R2, if preceded by 'ic', delete if in R2
220
- if(count($ret_str = $this->delete_suff($this->suffissi_step_1_b,$str,$str_len,'r2'))) {
221
- if(count($ret_str1 = $this->delete_suff(array('ic'),$ret_str,strlen($ret_str),'r2'))) {
222
- return $ret_str1;
223
- }
224
- else return $ret_str;
225
- }
226
- //replace with 'log' if in R2
227
- if(count($ret_str = $this->delete_suff($this->suffissi_step_1_c,$str,$str_len,'r2'))) return $ret_str.'log';
228
- //replace with 'u' if in R2
229
- if(count($ret_str = $this->delete_suff($this->suffissi_step_1_d,$str,$str_len,'r2'))) return $ret_str.'u';
230
- //replace with 'ente' if in R2
231
- if(count($ret_str = $this->delete_suff($this->suffissi_step_1_e,$str,$str_len,'r2'))) return $ret_str.'ente';
232
- //delete if in RV
233
- if(count($ret_str = $this->delete_suff($this->suffissi_step_1_f,$str,$str_len,'rv'))) return $ret_str;
234
- //delete if in R2, if preceded by 'abil', 'ic' or 'iv', delete if in R2
235
- if(count($ret_str = $this->delete_suff($this->suffissi_step_1_h,$str,$str_len,'r2'))) {
236
- if(count($ret_str1 = $this->delete_suff(array('abil','ic','iv'),$ret_str,strlen($ret_str),'r2'))) {
237
- return $ret_str1;
238
- }
239
- else return $ret_str;
240
- }
241
- //delete if in R2, if preceded by 'at', delete if in R2 (and if further preceded by 'ic', delete if in R2)
242
- if(count($ret_str = $this->delete_suff($this->suffissi_step_1_i,$str,$str_len,'r2'))) {
243
- if(count($ret_str1 = $this->delete_suff(array('at'),$ret_str,strlen($ret_str),'r2'))) {
244
- if(count($ret_str2 = $this->delete_suff(array('ic'),$ret_str1,strlen($ret_str1),'r2'))) return $ret_str2;
245
- else return $ret_str1;
246
- }
247
- else return $ret_str;
248
- }
249
-
250
- return $str;
251
- }
252
-
253
- function step_2($str,$str_step_1) {
254
- //Step 2: Verb suffixes
255
- //Do step 2 if no ending was removed by step 1
256
-
257
- if($str != $str_step_1) return $str_step_1;
258
-
259
- $str_len = strlen($str);
260
-
261
- if(count($ret_str = $this->delete_suff($this->suffissi_step_2,$str,$str_len,'rv'))) return $ret_str;
262
-
263
- return $str;
264
- }
265
-
266
- function step_3a($str) {
267
- //Step 3a: Delete a final 'a', 'e', 'i', 'o',' ', '', '' or '' if it is in RV, and a preceding 'i' if it is in RV ('crocchi' -> 'crocch', 'crocchio' -> 'crocch')
268
- //Always do steps 3a
269
-
270
- $vocale_finale = array('a','e','i','o','','','','');
271
-
272
- $str_len = strlen($str);
273
-
274
- if(count($ret_str = $this->delete_suff($vocale_finale,$str,$str_len,'rv'))) {
275
- if(count($ret_str1 = $this->delete_suff(array('i'),$ret_str,strlen($ret_str),'rv'))) {
276
- return $ret_str1;
277
- }
278
- else return $ret_str;
279
- }
280
-
281
- return $str;
282
- }
283
-
284
- function step_3b($str) {
285
- //Step 3b: Replace final 'ch' (or 'gh') with 'c' (or 'g') if in 'RV' ('crocch' -> 'crocc')
286
- //Always do steps 3b
287
-
288
- $rv = $this->return_RV($str);
289
-
290
- $pattern = '/([cg])h$/';
291
- $replacement = '${1}';
292
- return substr($str,0,strlen($str)-strlen($rv)).preg_replace($pattern,$replacement,$rv);
293
- }
294
-
295
- function step_4($str) {
296
- //Step 4: Finally, turn I and U back into lower case
297
-
298
- return strtolower($str);
299
- }
300
-
301
- function stem($str){
302
- $str = $this->trim($str);
303
- $str = $this->to_lower($str);
304
- $str = $this->replace_acc_acuti($str);
305
- $str = $this->put_u_after_q_to_upper($str);
306
- $str = $this->i_u_between_vow_to_upper($str);
307
- $step0 = $this->step_0($str);
308
- $step1 = $this->step_1($step0);
309
- $step2 = $this->step_2($step0,$step1);
310
- $step3a = $this->step_3a($step2);
311
- $step3b = $this->step_3b($step3a);
312
- $step4 = $this->step_4($step3b);
313
-
314
- return $step4;
315
- }
316
-
317
-
318
- }
319
-
320
-
321
- /*
322
- Stem caching added by Rob Marsh, SJ
323
- http://rmarsh.com
324
- */
325
-
326
- if (!function_exists('strpbrk')) {
327
- function strpbrk( $haystack, $char_list ) {
328
- $strlen = strlen($char_list);
329
- $found = false;
330
- for( $i=0; $i<$strlen; $i++ ) {
331
- if( ($tmp = strpos($haystack, $char_list{$i})) !== false ) {
332
- if(!$found) {
333
- $pos = $tmp;
334
- $found = true;
335
- continue;
336
- }
337
- $pos = min($pos, $tmp);
338
- }
339
- }
340
- if(!$found) {
341
- return false;
342
- }
343
- return substr($haystack, $pos);
344
- }
345
- }
346
-
347
- $Stemmer = new ItalianStemmer();
348
- $StemCache = array();
349
-
350
- function stem($word) {
351
- global $Stemmer, $StemCache;
352
- if (!isset($StemCache[$word])) {
353
- $stemmedword = $Stemmer->Stem($word);
354
- $StemCache[$word] = $stemmedword;
355
- }
356
- else {
357
- $stemmedword = $StemCache[$word] ;
358
- }
359
- return $stemmedword;
360
- }
361
-
362
- ?>
1
+ <?php
2
+
3
+ /*
4
+
5
+ Con=verted to PHP 4 by Rob Marsh, SJ
6
+
7
+ */
8
+
9
+
10
+ /*
11
+ *
12
+ * This script as been written by Roberto Mirizzi (rob4you at vodafone dot it) in February 2007.
13
+ *
14
+ * It is the PHP5 implementation of Martin Porter's stemming algorithm for Italian language.
15
+ *
16
+ * This algorithm can be found at address: http://snowball.tartarus.org/algorithms/italian/stemmer.html.
17
+ *
18
+ * Use the code freely. I'm not responsible for any problems.
19
+ *
20
+ * Usage:
21
+ *
22
+ * $stemmer = new ItalianStemmer();
23
+ * $stemmed_word = $stemmer->stem($word);
24
+ *
25
+ * All Italian characters are (originally) in latin1 (ISO-8859-1).
26
+ *
27
+ */
28
+ class ItalianStemmer {
29
+ var $vocali = array('a','e','i','o','u','à','è','ì','ò','ù');
30
+ var $consonanti = array('b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','y','z','I','U');
31
+ var $accenti_acuti = array('á','é','í','ó','ú');
32
+ var $accenti_gravi = array('à','è','ì','ò','ù');
33
+
34
+ var $suffissi_step_0 = array('ci','gli','la','le','li','lo','mi','ne','si','ti','vi','sene','gliela','gliele','glieli','glielo','gliene','mela','mele','meli','melo','mene','tela','tele','teli','telo','tene','cela','cele','celi','celo','cene','vela','vele','veli','velo','vene');
35
+
36
+ var $suffissi_step_1_a = array('anza','anze','ico','ici','ica','ice','iche','ichi','ismo','ismi','abile','abili','ibile','ibili','ista','iste','isti','istà','istè','istì','oso','osi','osa','ose','mente','atrice','atrici','ante','anti');
37
+ var $suffissi_step_1_b = array('azione','azioni','atore','atori');
38
+ var $suffissi_step_1_c = array('logia','logie');
39
+ var $suffissi_step_1_d = array('uzione','uzioni','usione','usioni');
40
+ var $suffissi_step_1_e = array('enza','enze');
41
+ var $suffissi_step_1_f = array('amento','amenti','imento','imenti');
42
+ var $suffissi_step_1_g = array('amente');
43
+ var $suffissi_step_1_h = array('ità');
44
+ var $suffissi_step_1_i = array('ivo','ivi','iva','ive');
45
+
46
+ var $suffissi_step_2 = array('ammo','ando','ano','are','arono','asse','assero','assi','assimo','ata','ate','ati','ato','ava','avamo','avano','avate','avi','avo','emmo','enda','ende','endi','endo','erà','erai','eranno','ere','erebbe','erebbero','erei','eremmo','eremo','ereste','eresti','erete','erò','erono','essero','ete','eva','evamo','evano','evate','evi','evo','Yamo','iamo','immo','irà','irai','iranno','ire','irebbe','irebbero','irei','iremmo','iremo','ireste','iresti','irete','irò','irono','isca','iscano','isce','isci','isco','iscono','issero','ita','ite','iti','ito','iva','ivamo','ivano','ivate','ivi','ivo','ono','uta','ute','uti','uto','ar','ir');
47
+
48
+ var $ante_suff_a = array('ando','endo');
49
+ var $ante_suff_b = array('ar','er','ir');
50
+
51
+ function __construct() {
52
+ usort($this->suffissi_step_0,create_function('$a,$b','return strlen($a)>strlen($b) ? -1 : 1;'));
53
+ usort($this->suffissi_step_1_a,create_function('$a,$b','return strlen($a)>strlen($b) ? -1 : 1;'));
54
+ usort($this->suffissi_step_2,create_function('$a,$b','return strlen($a)>strlen($b) ? -1 : 1;'));
55
+ }
56
+
57
+ function trim($str) {
58
+ return trim($str);
59
+ }
60
+
61
+ function to_lower($str) {
62
+ return strtolower($str);
63
+ }
64
+
65
+ function replace_acc_acuti($str) {
66
+ return str_replace($this->accenti_acuti, $this->accenti_gravi, $str); //strtr
67
+ }
68
+
69
+ function put_u_after_q_to_upper($str) {
70
+ return str_replace("qu", "qU", $str);
71
+ }
72
+
73
+ function i_u_between_vow_to_upper($str) {
74
+ $pattern = '/([aeiouàèìòù])([iu])([aeiouàèìòù])/e';
75
+ $replacement = "'$1'.strtoupper('$2').'$3'";
76
+ return preg_replace($pattern, $replacement, $str);
77
+ }
78
+
79
+ function return_RV($str) {
80
+ /*
81
+ If the second letter is a consonant, RV is the region after the next following vowel,
82
+ or if the first two letters are vowels, RV is the region after the next consonant, and otherwise
83
+ (consonant-vowel case) RV is the region after the third letter. But RV is the end of the word if these positions cannot be found.
84
+ example,
85
+ m a c h o [ho] o l i v a [va] t r a b a j o [bajo] á u r e o [eo] prezzo sprezzante
86
+ */
87
+
88
+ if(strlen($str)<2) return '';//$str;
89
+
90
+ if(in_array($str[1],$this->consonanti)) {
91
+ $str = substr($str,2);
92
+ $str = strpbrk($str, implode($this->vocali));
93
+ return substr($str,1); //secondo me devo mettere 1
94
+ }
95
+ else if(in_array($str[0],$this->vocali) && in_array($str[1],$this->vocali)) {
96
+ $str = strpbrk($str, implode($this->consonanti));
97
+ return substr($str,1);
98
+ }
99
+ else if(in_array($str[0],$this->consonanti) && in_array($str[1],$this->vocali)) {
100
+ return substr($str,3);
101
+ }
102
+
103
+ }
104
+
105
+ function return_R1($str){
106
+ /*
107
+ R1 is the region after the first non-vowel following a vowel, or is the null region at the end of the word if there is no such non-vowel.
108
+ example:
109
+ beautiful [iful] beauty [y] beau [NULL] animadversion [imadversion] sprinkled [kled] eucharist [harist]
110
+ */
111
+
112
+ $pattern = '/['.implode($this->vocali).']+'.'['.implode($this->consonanti).']'.'(.*)/';
113
+ preg_match($pattern,$str,$matches);
114
+
115
+ return count($matches)>=1 ? $matches[1] : '';
116
+ }
117
+
118
+ function return_R2($str) {
119
+ /*
120
+ R2 is the region after the first non-vowel following a vowel in R1, or is the null region at the end of the word if there is no such non-vowel.
121
+ example:
122
+ beautiful [ul] beauty [NULL] beau [NULL] animadversion [adversion] sprinkled [NULL] eucharist [ist]
123
+ */
124
+
125
+ $R1 = $this->return_R1($str);
126
+
127
+ $pattern = '/['.implode($this->vocali).']+'.'['.implode($this->consonanti).']'.'(.*)/';
128
+ preg_match($pattern,$R1,$matches);
129
+
130
+ return count($matches)>=1 ? $matches[1] : '';
131
+ }
132
+
133
+
134
+ function step_0($str) {
135
+ //Step 0: Attached pronoun
136
+ //Always do steps 0
137
+
138
+ $str_len = strlen($str);
139
+ $rv = $this->return_RV($str);
140
+ $rv_len = strlen($rv);
141
+
142
+ $pos = 0;
143
+ foreach($this->suffissi_step_0 as $suff) {
144
+ if($rv_len-strlen($suff) < 0) continue;
145
+ $pos = strpos($rv,$suff,$rv_len-strlen($suff));
146
+ if($pos !== false) break;
147
+ }
148
+
149
+ $ante_suff = substr($rv,0,$pos);
150
+ $ante_suff_len = strlen($ante_suff);
151
+
152
+ foreach($this->ante_suff_a as $ante_a) {
153
+ if($ante_suff_len-strlen($ante_a) < 0) continue;
154
+ $pos_a = strpos($ante_suff,$ante_a,$ante_suff_len-strlen($ante_a));
155
+ if($pos_a !== false) {
156
+ return substr($str,0,$pos+$str_len-$rv_len);
157
+ }
158
+ }
159
+
160
+ foreach($this->ante_suff_b as $ante_b) {
161
+ if($ante_suff_len-strlen($ante_b) < 0) continue;
162
+ $pos_b = strpos($ante_suff,$ante_b,$ante_suff_len-strlen($ante_b));
163
+ if($pos_b !== false) {
164
+ return substr($str,0,$pos+$str_len-$rv_len).'e';
165
+ }
166
+ }
167
+
168
+ return $str;
169
+ }
170
+
171
+ function delete_suff($arr_suff,$str,$str_len,$where,$ovunque=false) {
172
+ if($where==='r2') $r = $this->return_R2($str);
173
+ else if($where==='rv') $r = $this->return_RV($str);
174
+ else if($where==='r1') $r = $this->return_R1($str);
175
+
176
+ $r_len = strlen($r);
177
+
178
+ if($ovunque) {
179
+ foreach($arr_suff as $suff) {
180
+ if($str_len-strlen($suff) < 0) continue;
181
+ $pos = strpos($str,$suff,$str_len-strlen($suff));
182
+ if($pos !== false) {
183
+ $pattern = '/'.$suff.'$/';
184
+ $ret_str = preg_match($pattern,$r) ? substr($str,0,$pos) : '';
185
+ if($ret_str !== '') return $ret_str;
186
+ break;
187
+ }
188
+ }
189
+ }
190
+ else {
191
+ foreach($arr_suff as $suff) {
192
+ if($r_len-strlen($suff) < 0) continue;
193
+ $pos = strpos($r,$suff,$r_len-strlen($suff));
194
+ if($pos !== false) return substr($str,0,$pos+$str_len-$r_len);
195
+ }
196
+ }
197
+ }
198
+
199
+
200
+ function step_1($str) {
201
+ //Step 1: Standard suffix removal
202
+ //Always do steps 1
203
+
204
+ $str_len = strlen($str);
205
+
206
+ //delete if in R1, if preceded by 'iv', delete if in R2 (and if further preceded by 'at', delete if in R2), otherwise, if preceded by 'os', 'ic' or 'abil', delete if in R2
207
+ if(count($ret_str = $this->delete_suff($this->suffissi_step_1_g,$str,$str_len,'r1'))) {
208
+ if(count($ret_str1 = $this->delete_suff(array('iv'),$ret_str,strlen($ret_str),'r2'))) {
209
+ if(count($ret_str2 = $this->delete_suff(array('at'),$ret_str1,strlen($ret_str1),'r2'))) return $ret_str2;
210
+ else return $ret_str1;
211
+ }
212
+ else if(count($ret_str1 = $this->delete_suff(array('os','ic','abil'),$ret_str,strlen($ret_str),'r2'))) {
213
+ return $ret_str1;
214
+ }
215
+ else return $ret_str;
216
+ }
217
+ //delete if in R2
218
+ if(count($ret_str = $this->delete_suff($this->suffissi_step_1_a,$str,$str_len,'r2',true))) return $ret_str;
219
+ //delete if in R2, if preceded by 'ic', delete if in R2
220
+ if(count($ret_str = $this->delete_suff($this->suffissi_step_1_b,$str,$str_len,'r2'))) {
221
+ if(count($ret_str1 = $this->delete_suff(array('ic'),$ret_str,strlen($ret_str),'r2'))) {
222
+ return $ret_str1;
223
+ }
224
+ else return $ret_str;
225
+ }
226
+ //replace with 'log' if in R2
227
+ if(count($ret_str = $this->delete_suff($this->suffissi_step_1_c,$str,$str_len,'r2'))) return $ret_str.'log';
228
+ //replace with 'u' if in R2
229
+ if(count($ret_str = $this->delete_suff($this->suffissi_step_1_d,$str,$str_len,'r2'))) return $ret_str.'u';
230
+ //replace with 'ente' if in R2
231
+ if(count($ret_str = $this->delete_suff($this->suffissi_step_1_e,$str,$str_len,'r2'))) return $ret_str.'ente';
232
+ //delete if in RV
233
+ if(count($ret_str = $this->delete_suff($this->suffissi_step_1_f,$str,$str_len,'rv'))) return $ret_str;
234
+ //delete if in R2, if preceded by 'abil', 'ic' or 'iv', delete if in R2
235
+ if(count($ret_str = $this->delete_suff($this->suffissi_step_1_h,$str,$str_len,'r2'))) {
236
+ if(count($ret_str1 = $this->delete_suff(array('abil','ic','iv'),$ret_str,strlen($ret_str),'r2'))) {
237
+ return $ret_str1;
238
+ }
239
+ else return $ret_str;
240
+ }
241
+ //delete if in R2, if preceded by 'at', delete if in R2 (and if further preceded by 'ic', delete if in R2)
242
+ if(count($ret_str = $this->delete_suff($this->suffissi_step_1_i,$str,$str_len,'r2'))) {
243
+ if(count($ret_str1 = $this->delete_suff(array('at'),$ret_str,strlen($ret_str),'r2'))) {
244
+ if(count($ret_str2 = $this->delete_suff(array('ic'),$ret_str1,strlen($ret_str1),'r2'))) return $ret_str2;
245
+ else return $ret_str1;
246
+ }
247
+ else return $ret_str;
248
+ }
249
+
250
+ return $str;
251
+ }
252
+
253
+ function step_2($str,$str_step_1) {
254
+ //Step 2: Verb suffixes
255
+ //Do step 2 if no ending was removed by step 1
256
+
257
+ if($str != $str_step_1) return $str_step_1;
258
+
259
+ $str_len = strlen($str);
260
+
261
+ if(count($ret_str = $this->delete_suff($this->suffissi_step_2,$str,$str_len,'rv'))) return $ret_str;
262
+
263
+ return $str;
264
+ }
265
+
266
+ function step_3a($str) {
267
+ //Step 3a: Delete a final 'a', 'e', 'i', 'o',' à', 'è', 'ì' or 'ò' if it is in RV, and a preceding 'i' if it is in RV ('crocchi' -> 'crocch', 'crocchio' -> 'crocch')
268
+ //Always do steps 3a
269
+
270
+ $vocale_finale = array('a','e','i','o','à','è','ì','ò');
271
+
272
+ $str_len = strlen($str);
273
+
274
+ if(count($ret_str = $this->delete_suff($vocale_finale,$str,$str_len,'rv'))) {
275
+ if(count($ret_str1 = $this->delete_suff(array('i'),$ret_str,strlen($ret_str),'rv'))) {
276
+ return $ret_str1;
277
+ }
278
+ else return $ret_str;
279
+ }
280
+
281
+ return $str;
282
+ }
283
+
284
+ function step_3b($str) {
285
+ //Step 3b: Replace final 'ch' (or 'gh') with 'c' (or 'g') if in 'RV' ('crocch' -> 'crocc')
286
+ //Always do steps 3b
287
+
288
+ $rv = $this->return_RV($str);
289
+
290
+ $pattern = '/([cg])h$/';
291
+ $replacement = '${1}';
292
+ return substr($str,0,strlen($str)-strlen($rv)).preg_replace($pattern,$replacement,$rv);
293
+ }
294
+
295
+ function step_4($str) {
296
+ //Step 4: Finally, turn I and U back into lower case
297
+
298
+ return strtolower($str);
299
+ }
300
+
301
+ function stem($str){
302
+ $str = $this->trim($str);
303
+ $str = $this->to_lower($str);
304
+ $str = $this->replace_acc_acuti($str);
305
+ $str = $this->put_u_after_q_to_upper($str);
306
+ $str = $this->i_u_between_vow_to_upper($str);
307
+ $step0 = $this->step_0($str);
308
+ $step1 = $this->step_1($step0);
309
+ $step2 = $this->step_2($step0,$step1);
310
+ $step3a = $this->step_3a($step2);
311
+ $step3b = $this->step_3b($step3a);
312
+ $step4 = $this->step_4($step3b);
313
+
314
+ return $step4;
315
+ }
316
+
317
+
318
+ }
319
+
320
+
321
+ /*
322
+ Stem caching added by Rob Marsh, SJ
323
+ http://rmarsh.com
324
+ */
325
+
326
+ if (!function_exists('strpbrk')) {
327
+ function strpbrk( $haystack, $char_list ) {
328
+ $strlen = strlen($char_list);
329
+ $found = false;
330
+ for( $i=0; $i<$strlen; $i++ ) {
331
+ if( ($tmp = strpos($haystack, $char_list{$i})) !== false ) {
332
+ if(!$found) {
333
+ $pos = $tmp;
334
+ $found = true;
335
+ continue;
336
+ }
337
+ $pos = min($pos, $tmp);
338
+ }
339
+ }
340
+ if(!$found) {
341
+ return false;
342
+ }
343
+ return substr($haystack, $pos);
344
+ }
345
+ }
346
+
347
+ $Stemmer = new ItalianStemmer();
348
+ $StemCache = array();
349
+
350
+ function stem($word) {
351
+ global $Stemmer, $StemCache;
352
+ if (!isset($StemCache[$word])) {
353
+ $stemmedword = $Stemmer->Stem($word);
354
+ $StemCache[$word] = $stemmedword;
355
+ }
356
+ else {
357
+ $stemmedword = $StemCache[$word] ;
358
+ }
359
+ return $stemmedword;
360
+ }
361
+
362
+ ?>
languages/it/stopwords.php CHANGED
@@ -1,4 +1,4 @@
1
  <?php
2
  // the list of common words we want to ignore. NB anything shorter than 4 characters is knocked by the plugin and doesn't need to figure here
3
- $overusedwords = array("abbia", "abbiamo", "abbiano", "abbiate", "agli", "alla", "alle", "allo", "anche", "avemmo", "avendo", "avesse", "avessero", "avessi", "avessimo", "aveste", "avesti", "avete", "aveva", "avevamo", "avevano", "avevate", "avevi", "avevo", "avrai", "avranno", "avrebbe", "avrebbero", "avrei", "avremmo", "avremo", "avreste", "avresti", "avrete", "avr�", "avr�", "avuta", "avute", "avuti", "avuto", "come", "contro", "dagl", "dagli", "dall", "dalla", "dalle", "dallo", "degl", "degli", "dell", "della", "delle", "dello", "dove", "ebbe", "ebbero", "ebbi", "erano", "eravamo", "eravate", "essendo", "faccia", "facciamo", "facciano", "facciate", "faccio", "facemmo", "facendo", "facesse", "facessero", "facessi", "facessimo", "faceste", "facesti", "faceva", "facevamo", "facevano", "facevate", "facevi", "facevo", "fanno", "farai", "faranno", "farebbe", "farebbero", "farei", "faremmo", "faremo", "fareste", "faresti", "farete", "far�", "far�", "fece", "fecero", "feci", "fosse", "fossero", "fossi", "fossimo", "foste", "fosti", "fummo", "furono", "hanno", "loro", "miei", "negl", "negli", "nell", "nella", "nelle", "nello", "nostra", "nostre", "nostri", "nostro", "perch�", "quale", "quanta", "quante", "quanti", "quanto", "quella", "quelle", "quelli", "quello", "questa", "queste", "questi", "questo", "sarai", "saranno", "sarebbe", "sarebbero", "sarei", "saremmo", "saremo", "sareste", "saresti", "sarete", "sar�", "sar�", "siamo", "siano", "siate", "siete", "sono", "stai", "stando", "stanno", "starai", "staranno", "starebbe", "starebbero", "starei", "staremmo", "staremo", "stareste", "staresti", "starete", "star�", "star�", "stava", "stavamo", "stavano", "stavate", "stavi", "stavo", "stemmo", "stesse", "stessero", "stessi", "stessimo", "steste", "stesti", "stette", "stettero", "stetti", "stia", "stiamo", "stiano", "stiate", "sugl", "sugli", "sull", "sulla", "sulle", "sullo", "suoi", "tuoi", "tutti", "tutto", "vostra", "vostre", "vostri", "vostro");
4
- ?>
1
  <?php
2
  // the list of common words we want to ignore. NB anything shorter than 4 characters is knocked by the plugin and doesn't need to figure here
3
+ $overusedwords = array("abbia", "abbiamo", "abbiano", "abbiate", "agli", "alla", "alle", "allo", "anche", "avemmo", "avendo", "avesse", "avessero", "avessi", "avessimo", "aveste", "avesti", "avete", "aveva", "avevamo", "avevano", "avevate", "avevi", "avevo", "avrai", "avranno", "avrebbe", "avrebbero", "avrei", "avremmo", "avremo", "avreste", "avresti", "avrete", "avrà", "avrò", "avuta", "avute", "avuti", "avuto", "come", "contro", "dagl", "dagli", "dall", "dalla", "dalle", "dallo", "degl", "degli", "dell", "della", "delle", "dello", "dove", "ebbe", "ebbero", "ebbi", "erano", "eravamo", "eravate", "essendo", "faccia", "facciamo", "facciano", "facciate", "faccio", "facemmo", "facendo", "facesse", "facessero", "facessi", "facessimo", "faceste", "facesti", "faceva", "facevamo", "facevano", "facevate", "facevi", "facevo", "fanno", "farai", "faranno", "farebbe", "farebbero", "farei", "faremmo", "faremo", "fareste", "faresti", "farete", "farà", "farò", "fece", "fecero", "feci", "fosse", "fossero", "fossi", "fossimo", "foste", "fosti", "fummo", "furono", "hanno", "loro", "miei", "negl", "negli", "nell", "nella", "nelle", "nello", "nostra", "nostre", "nostri", "nostro", "perché", "quale", "quanta", "quante", "quanti", "quanto", "quella", "quelle", "quelli", "quello", "questa", "queste", "questi", "questo", "sarai", "saranno", "sarebbe", "sarebbero", "sarei", "saremmo", "saremo", "sareste", "saresti", "sarete", "sarà", "sarò", "siamo", "siano", "siate", "siete", "sono", "stai", "stando", "stanno", "starai", "staranno", "starebbe", "starebbero", "starei", "staremmo", "staremo", "stareste", "staresti", "starete", "starà", "starò", "stava", "stavamo", "stavano", "stavate", "stavi", "stavo", "stemmo", "stesse", "stessero", "stessi", "stessimo", "steste", "stesti", "stette", "stettero", "stetti", "stia", "stiamo", "stiano", "stiate", "sugl", "sugli", "sull", "sulla", "sulle", "sullo", "suoi", "tuoi", "tutti", "tutto", "vostra", "vostre", "vostri", "vostro");
4
+ ?>
output_tags.php CHANGED
@@ -1,1174 +1,1174 @@
1
- <?php
2
-
3
- /*
4
- Library for the Recent Posts, Random Posts, Recent Comments, and Similar Posts plugins
5
- -- provides the routines which evaluate output template tags
6
- */
7
-
8
- define('OT_LIBRARY', true);
9
-
10
- // Called by the post plugins to match output tags to the actions that evaluate them
11
- function output_tag_action($tag) {
12
- return 'otf_'.$tag;
13
- }
14
-
15
- /*
16
- innards
17
- */
18
-
19
- // To add a new output template tag all you need to do is write a tag function like those below.
20
-
21
- // All the tag functions must follow the pattern of 'otf_title' below.
22
- // the name is the tag name prefixed by 'otf_'
23
- // the arguments are always $option_key, $result and $ext
24
- // $option_key the key to the plugin's options
25
- // $result the particular row of the query result
26
- // $ext some extra data which a tag may use
27
- // the return value is the value of the tag as a string
28
-
29
- function otf_postid ($option_key, $result, $ext) {
30
- return $result->ID;
31
- }
32
-
33
- function otf_title ($option_key, $result, $ext) {
34
- $value = oth_truncate_text($result->post_title, $ext);
35
- return apply_filters('the_title', $value);
36
- }
37
-
38
- function otf_url($option_key, $result, $ext) {
39
- $value = apply_filters('the_permalink', get_permalink($result->ID));
40
- return oth_truncate_text($value, $ext);
41
- }
42
-
43
- function otf_author($option_key, $result, $ext) {
44
- $type = false;
45
- if ($ext) {
46
- $s = explode(':', $ext);
47
- if (count($s) == 1) {
48
- $type = $s[0];
49
- }
50
- }
51
- switch ($type) {
52
- case 'display':
53
- $author = get_the_author_meta('display_name',$result->post_author);
54
- break;
55
- case 'full':
56
- $auth = get_userdata($result->post_author);
57
- $author = $auth->first_name.' '.$auth->last_name;
58
- break;
59
- case 'reverse':
60
- $auth = get_userdata($result->post_author);
61
- $author = $auth->last_name.', '.$auth->first_name;
62
- break;
63
- case 'first':
64
- $auth = get_userdata($result->post_author);
65
- $author = $auth->first_name;
66
- break;
67
- case 'last':
68
- $auth = get_userdata($result->post_author);
69
- $author = $auth->last_name;
70
- break;
71
- default:
72
- $author = get_the_author_meta('display_name',$result->post_author);
73
- }
74
- return $author;
75
- }
76
-
77
- function otf_authorurl($option_key, $result, $ext) {
78
- return get_author_posts_url($result->post_author);
79
- }
80
-
81
- function otf_date($option_key, $result, $ext) {
82
- if ($ext === 'raw') return $result->post_date;
83
- else return oth_format_date($result->post_date, $ext);
84
- }
85
-
86
- function otf_dateedited($option_key, $result, $ext) {
87
- if ($ext === 'raw') return $result->post_modified;
88
- else return oth_format_date($result->post_modified, $ext);
89
- }
90
-
91
- function otf_time($option_key, $result, $ext) {
92
- return oth_format_time($result->post_date, $ext);
93
- }
94
-
95
- function otf_timeedited($option_key, $result, $ext) {
96
- return oth_format_time($result->post_modified, $ext);
97
- }
98
-
99
- function otf_excerpt($option_key, $result, $ext) {
100
- if (!$ext) {
101
- $len = 55;
102
- $type = 'a';
103
- } else {
104
- $s = explode(':', $ext);
105
- if (count($s) == 1) {
106
- $s[] = 'a';
107
- }
108
- $len = $s[0];
109
- $type = $s[1];
110
- if ($type === 'b') {
111
- if (count($s) > 2) {
112
- $more = $s[2];
113
- } else {
114
- $more = ' &hellip;';
115
- }
116
- if (count($s) > 3) {
117
- if ($s[3] === 'link') {
118
- $url = otf_url($option_key, $result, '');
119
- $more = '<a href="'.$url.'">'.$more.'</a>';
120
- }
121
- }
122
- if (count($s) > 4) {
123
- $numsent = $s[4];
124
- }
125
- }
126
- }
127
- switch ($type) {
128
- case 'a':
129
- $value = trim($result->post_excerpt);
130
- if ($value == '') $value = $result->post_content;
131
- $value = oth_trim_excerpt($value, $ext);
132
- break;
133
- case 'b':
134
- $value = trim($result->post_excerpt);
135
- if ($value === '') {
136
- $value = $result->post_content;
137
- $value = convert_smilies($value);
138
- $value = oth_trim_extract($value, $len, $more, $numsent);
139
- $value = apply_filters('get_the_content', $value);
140
- remove_filter('the_content', 'ppl_content_filter', 5);
141
- remove_filter('the_content', 'ppl_post_filter', 5);
142
- $value = apply_filters('the_content', $value);
143
- add_filter('the_content', 'ppl_content_filter', 5);
144
- add_filter('the_content', 'ppl_post_filter', 5);
145
-
146
- } else {
147
- $value = convert_smilies($value);
148
- $value = apply_filters('get_the_excerpt', $value);
149
- remove_filter('the_excerpt', 'ppl_content_filter', 5);
150
- $value = apply_filters('the_excerpt', $value);
151
- add_filter('the_excerpt', 'ppl_content_filter', 5);
152
- }
153
- break;
154
- default:
155
- $value = trim($result->post_excerpt);
156
- if ($value == '') $value = $result->post_content;
157
- $value = oth_trim_excerpt($value, $len);
158
- break;
159
- }
160
- return $value;
161
- }
162
-
163
- function otf_snippet($option_key, $result, $ext) {
164
- $len = 100;
165
- $type = 'char';
166
- $more = '';
167
- $link = 'nolink';
168
- if ($ext) {
169
- $s = explode(':', $ext);
170
- if (isset($s[0]) && $s[0]) $len = $s[0];
171
- if (isset($s[1]) && $s[1]) $type = $s[1];
172
- if (isset($s[2]) && $s[2]) $more = $s[2];
173
- if (isset($s[3]) && $s[3]) $link = $s[3];
174
- }
175
- if ($link === 'link') {
176
- $url = otf_url($option_key, $result, '');
177
- $more = '<a href="'.$url.'">'.$more.'</a>';
178
- }
179
- return oth_format_snippet($result->post_content, $option_key, $type, $len, $more);
180
- }
181
-
182
- function otf_snippetword($option_key, $result, $ext) {
183
- $len = 100;
184
- $more = '';
185
- $link = 'nolink';
186
- if ($ext) {
187
- $s = explode(':', $ext);
188
- if (isset($s[0]) && $s[0]) $len = $s[0];
189
- if (isset($s[1]) && $s[1]) $more = $s[1];
190
- if (isset($s[2]) && $s[2]) $link = $s[2];
191
- }
192
- if ($link === 'link') {
193
- $url = otf_url($option_key, $result, '');
194
- $more = '<a href="'.$url.'">'.$more.'</a>';
195
- }
196
- return oth_format_snippet($result->post_content, $option_key, 'word', $len, $more);
197
- }
198
-
199
- function otf_fullpost($option_key, $result, $ext) {
200
- remove_filter( 'the_content', 'ppl_content_filter', 5 );
201
- remove_filter( 'the_content', 'ppl_post_filter', 5 );
202
- $value = apply_filters('the_content', $result->post_content);
203
- add_filter( 'the_content', 'ppl_content_filter', 5 );
204
- add_filter( 'the_content', 'ppl_post_filter', 5 );
205
- return str_replace(']]>', ']]&gt;', $value);
206
- }
207
-
208
- function otf_commentcount($option_key, $result, $ext) {
209
- $value = $result->comment_count;
210
- if ($ext) {
211
- $s = explode(':', $ext);
212
- if (count($s) == 3) {
213
- if ($value == 0) $value = $s[0];
214
- elseif ($value == 1) $value .= ' ' . $s[1];
215
- else $value .= ' ' . $s[2];
216
- }
217
- }
218
- return $value;
219
- }
220
-
221
- function otf_commentexcerpt($option_key, $result, $ext) {
222
- if (!$ext) {
223
- $len = 55;
224
- $type = 'a';
225
- } else {
226
- $s = explode(':', $ext);
227
- if (count($s) == 1) {
228
- $s[] = 'a';
229
- }
230
- $len = $s[0];
231
- $type = $s[1];
232
- if ($type === 'b') {
233
- if (count($s) > 2) {
234
- $more = $s[2];
235
- } else {
236
- $more = ' &hellip;';
237
- }
238
- if (count($s) > 3) {
239
- if ($s[3] === 'link') {
240
- $url = otf_commenturl($option_key, $result, '');
241
- $more = '<a href="'.$url.'">'.$more.'</a>';
242
- }
243
- }
244
- }
245
- }
246
- switch ($type) {
247
- case 'a':
248
- $value = oth_trim_comment_excerpt($result->comment_content, $ext);
249
- break;
250
- case 'b':
251
- $value = $result->comment_content;
252
- $value = convert_smilies($value);
253
-
254
- $text = str_replace(']]>', ']]&gt;', $value);
255
- if ($len <= count(preg_split('/[\s]+/', strip_tags($text), -1))) {
256
- // remove html entities for now
257
- $text = str_replace("\x06", "", $text);
258
- preg_match_all("/&([a-z\d]{2,7}|#\d{2,5});/i", $text, $ents);
259
- $text = preg_replace("/&([a-z\d]{2,7}|#\d{2,5});/i", "\x06", $text);
260
- // now we start counting
261
- $parts = preg_split('/([\s]+)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
262
- $in_tag = false;
263
- $num_words = 0;
264
- $text = '';
265
- foreach($parts as $part) {
266
- if(0 < preg_match('/<[^>]*$/s', $part)) {
267
- $in_tag = true;
268
- } else if(0 < preg_match('/>[^<]*$/s', $part)) {
269
- $in_tag = false;
270
- }
271
- if(!$in_tag && '' != trim($part) && substr($part, -1, 1) != '>') {
272
- $num_words++;
273
- }
274
- $text .= $part;
275
- if($num_words >= $len && !$in_tag) break;
276
- }
277
- // put back the missing html entities
278
- foreach ($ents[0] as $ent) $text = preg_replace("/\x06/", $ent, $text, 1);
279
- $text = balanceTags($text, true);
280
- $value = $text . $more;
281
- }
282
- $value = apply_filters('get_comment_text', $value);
283
- break;
284
- default:
285
- $value = oth_trim_comment_excerpt($result->comment_content, $ext);
286
- break;
287
- }
288
- return $value;
289
- }
290
-
291
- function otf_commentsnippet($option_key, $result, $ext) {
292
- $len = 100;
293
- $type = 'char';
294
- $more = '';
295
- $link = 'nolink';
296
- if ($ext) {
297
- $s = explode(':', $ext);
298
- if (isset($s[0]) && $s[0]) $len = $s[0];
299
- if (isset($s[1]) && $s[1]) $type = $s[1];
300
- if (isset($s[2]) && $s[2]) $more = $s[2];
301
- if (isset($s[3]) && $s[3]) $link = $s[3];
302
- }
303
- if ($link === 'link') {
304
- $url = otf_commenturl($option_key, $result, '');
305
- $more = '<a href="'.$url.'">'.$more.'</a>';
306
- }
307
- return oth_format_snippet($result->comment_content, $option_key, $type, $len, $more);
308
- }
309
-
310
- function otf_commentsnippetword($option_key, $result, $ext) {
311
- $len = 100;
312
- $more = '';
313
- $link = 'nolink';
314
- if ($ext) {
315
- $s = explode(':', $ext);
316
- if (isset($s[0]) && $s[0]) $len = $s[0];
317
- if (isset($s[1]) && $s[1]) $more = $s[1];
318
- if (isset($s[2]) && $s[2]) $link = $s[2];
319
- }
320
- if ($link === 'link') {
321
- $url = otf_commenturl($option_key, $result, '');
322
- $more = '<a href="'.$url.'">'.$more.'</a>';
323
- }
324
- return oth_format_snippet($result->comment_content, $option_key, 'word', $len, $more);
325
- }
326
-
327
- function otf_commentdate($option_key, $result, $ext) {
328
- if ($ext === 'raw') return $result->comment_date;
329
- return oth_format_date($result->comment_date, $ext);
330
- }
331
-
332
- function otf_commenttime($option_key, $result, $ext) {
333
- return oth_format_time($result->comment_date, $ext);
334
- }
335
-
336
- function otf_commentdategmt($option_key, $result, $ext) {
337
- if ($ext === 'raw') return $result->comment_date_gmt;
338
- return oth_format_date($result->comment_date_gmt, $ext);
339
- }
340
-
341
- function otf_commenttimegmt($option_key, $result, $ext) {
342
- return oth_format_time($result->comment_date_gmt, $ext);
343
- }
344
-
345
- function otf_commenter($option_key, $result, $ext) {
346
- $value = $result->comment_author;
347
- $value = apply_filters('get_comment_author', $value);
348
- $value = apply_filters('comment_author', $value);
349
- return oth_truncate_text($value, $ext);
350
- }
351
-
352
- function otf_commenterurl($option_key, $result, $ext) {
353
- $value = $result->comment_author_url;
354
- $value = apply_filters('get_comment_author_url', $value);
355
- return oth_truncate_text($value, $ext);
356
- }
357
-
358
- function otf_commenterlink($option_key, $result, $ext) {
359
- $url = otf_commenterurl($option_key, $result, '');
360
- $author = otf_commenter($option_key, $result, $ext);
361
- if (empty($url) || $url == 'http://') $value = $author;
362
- else $value = "<a href='$url' rel='external nofollow'>$author</a>";
363
- return $value;
364
- }
365
-
366
- function otf_commenterip($option_key, $result, $ext) {
367
- return $result->comment_author_IP;
368
- }
369
-
370
- function otf_commenturl($option_key, $result, $ext) {
371
- $value = apply_filters('the_permalink', get_permalink($result->ID)) . '#comment-' . $result->comment_ID;
372
- return oth_truncate_text($value, $ext);
373
- }
374
-
375
- function otf_commentlink($option_key, $result, $ext) {
376
- $ttl = otf_commenter($option_key, $result, '');
377
- $ttl = '<span class="rc-commenter">' . $ttl . '</span>';
378
- if (!$ext) $ext = ' commented on ';
379
- $ttl .= $ext;
380
- $ttl .= '<span class="rc-title">'.otf_title($option_key, $result, '').'</span>';
381
- $pml = otf_commenturl($option_key, $result, '');
382
- $pdt = oth_format_date($result->comment_date_gmt, '');
383
- $pdt .= __(' at ', 'post_plugin_library');
384
- $pdt .= oth_format_time($result->comment_date_gmt, '');
385
- return "<a href=\"$pml\" rel=\"bookmark\" title=\"$pdt\">$ttl</a>";
386
- }
387
-
388
- function otf_commentlink2($option_key, $result, $ext) {
389
- $commenturl = otf_commenturl($option_key, $result, '');
390
- $commentdate = otf_commentdate($option_key, $result, '');
391
- $commenttime = otf_commenttime($option_key, $result, '');
392
- $title = otf_title($option_key, $result, '');
393
- $commenter = otf_commenter($option_key, $result, '');
394
- $commentexcerpt = otf_commentexcerpt($option_key, $result, '10');
395
- return "<a href=\"$commenturl\" rel=\"bookmark\" title=\"$commentdate at $commenttime on '$title'\">$commenter</a> - $commentexcerpt&hellip;";
396
- }
397
-
398
- function otf_commentpopupurl($option_key, $result, $ext) {
399
- global $wpcommentspopupfile, $wpcommentsjavascript;
400
- $output = '';
401
- if ( $wpcommentsjavascript ) {
402
- if ( empty( $wpcommentspopupfile ) )
403
- $home = get_option('home');
404
- else
405
- $home = get_option('siteurl');
406
- $output .= $home . '/' . $wpcommentspopupfile . '?comments_popup=' . $result->ID;
407
- $output .= '#comment-' . $result->comment_ID;
408
- $output .= '" onclick="wpopen(this.href); return false';
409
- }
410
- return $output;
411
- }
412
-
413
- function otf_catlinks($option_key, $result, $ext) {
414
- return otf_categorylinks($option_key, $result, $ext);
415
- }
416
-
417
- function otf_categorylinks($option_key, $result, $ext) {
418
- $cats = get_the_category($result->ID);
419
- $value = '';
420
- $n = 0;
421
- foreach ($cats as $cat) {
422
- if ($n > 0) $value .= $ext;
423
- $catname = apply_filters('single_cat_title', $cat->cat_name);
424
- $value .= '<a href="' . get_category_link($cat->cat_ID) . '" title="' . sprintf(__("View all posts in %s", 'post_plugin_library'), $catname) . '" rel="category tag">'.$catname.'</a> ';
425
- ++$n;
426
- }
427
- return $value;
428
- }
429
-
430
- function otf_catnames($option_key, $result, $ext) {
431
- return otf_categorynames($option_key, $result, $ext);
432
- }
433
-
434
- function otf_categorynames($option_key, $result, $ext) {
435
- $cats = get_the_category($result->ID);
436
- $value = '';
437
- $n = 0;
438
- foreach ($cats as $cat) {
439
- if ($n > 0) $value .= $ext;
440
- $value .= apply_filters('single_cat_title', $cat->cat_name);
441
- ++$n;
442
- }
443
- return $value;
444
- }
445
-
446
- function otf_custom($option_key, $result, $ext) {
447
- $custom = get_post_custom($result->ID);
448
- return $custom[$ext][0];
449
- }
450
-
451
- function otf_tags($option_key, $result, $ext) {
452
- $tags = (array) get_the_tags($result->ID);
453
- $tag_list = array();
454
- foreach ( $tags as $tag ) {
455
- if (isset($tag->name)) {
456
- $tag_list[] = $tag->name;
457
- }
458
- }
459
- if (!$ext) $ext = ', ';
460
- $tag_list = join( $ext, $tag_list );
461
- return $tag_list;
462
- }
463
-
464
- function otf_taglinks($option_key, $result, $ext) {
465
- $tags = (array) get_the_tags($result->ID);
466
- $tag_list = '';
467
- $tag_links = array();
468
- foreach ( $tags as $tag ) {
469
- $link = get_tag_link($tag->term_id);
470
- if ( is_wp_error( $link ) )
471
- return $link;
472
- $tag_links[] = '<a href="' . $link . '" rel="tag">' . $tag->name . '</a>';
473
- }
474
- if (!$ext) $ext = ' ';
475
- $tag_links = join( $ext, $tag_links );
476
- $tag_links = apply_filters( 'the_tags', $tag_links );
477
- $tag_list .= $tag_links;
478
- return $tag_list;
479
- }
480
-
481
- function otf_totalposts($option_key, $result, $ext) {
482
- global $wpdb;
483
- $value = '';
484
- if (function_exists('get_post_type')) {
485
- $value = (int) $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish'");
486
- } else {
487
- $value = (int) $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'");
488
- }
489
- return $value;
490
- }
491
-
492
- function otf_totalpages($option_key, $result, $ext) {
493
- global $wpdb;
494
- $value = '';
495
- if (function_exists('get_post_type')) {
496
- $value = (int) $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish'");
497
- } else {
498
- $value = (int) $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'static'");
499
- }
500
- return $value;
501
- }
502
-
503
- function otf_link($option_key, $result, $ext) {
504
- $ttl = otf_title($option_key, $result, $ext);
505
- $pml = otf_url($option_key, $result, null);
506
- $pdt = otf_date($option_key, $result, null);
507
- return "<a href=\"$pml\" rel=\"bookmark\" title=\"$ttl\">$ttl</a>";
508
- }
509
-
510
- function otf_score($option_key, $result, $ext) {
511
- return sprintf("%.0f", $result->score);
512
- }
513
-
514
- // tries to get the number of post views from a few popular plugins if the are installed
515
- function otf_postviews($option_key, $result, $ext) {
516
- global $wpdb;
517
- $count = 0;
518
- // alex king's popularity contest
519
- if (class_exists('ak_popularity_contest')) $count = $akpc->get_post_total($result->ID);
520
- // my own post view count
521
- else if (function_exists('popular_posts_views')) $count = popular_posts_views($result->ID);
522
- // lester chan's postviews
523
- else if (function_exists('the_views')) {
524
- $count = get_post_custom($result->ID);
525
- $count = intval($count['views'][0]);
526
- }
527
- // mark ghosh's top10
528
- else if (function_exists('show_post_count')) {$id = $result->ID; $count = $wpdb->get_var("select cntaccess from mostAccessed WHERE postnumber = $id");}
529
- // Ivan Djurdjevac's CountPosts
530
- else if (function_exists('HitThisPost')) {$id = $result->ID; $count = $wpdb->get_var("SELECT post_hits FROM $wpdb->posts WHERE ID=$id");}
531
-
532
- return $count;
533
- }
534
-
535
- function oth_get_actual_size($imgtag) {
536
- // first try extracting the width and height attributes
537
- if (preg_match('/\s+width\s*=\s*[\'|\"](.*?)[\'|\"]/is', $imgtag, $matches)) {
538
- $current_width = $matches[1];
539
- if (preg_match('/\s+height\s*=\s*[\'|\"](.*?)[\'|\"]/is', $imgtag, $matches)) {
540
- $current_height = $matches[1];
541
- }
542
- }
543
- // then try using the GD library
544
- if (!(($current_width) && ($current_height))) {
545
- // extract the image src url
546
- preg_match('/\s+src\s*=\s*[\'|\"](.*?)[\'|\"]/is', $imgtag, $matches);
547
- $error_level = error_reporting(0);
548
- if (function_exists('getimagesize') && $imagesize = getimagesize($matches[1])) {
549
- $current_width = $imagesize['0'];
550
- $current_height = $imagesize['1'];
551
- } else {
552
- // if all else fails...
553
- $current_width = $current_height = 0;
554
- }
555
- error_reporting($error_level);
556
- }
557
- return array($current_width, $current_height);
558
- }
559
-
560
- function oth_image_size_full($w, $h, $imgtag){
561
- return array(1, 1);
562
- }
563
-
564
- function oth_image_size_scale($w, $h, $imgtag){
565
- $maxsize = max($w, $h);
566
- list($current_width, $current_height) = oth_get_actual_size($imgtag);
567
- $width_ratio = $height_ratio = 1.0;
568
- if ($current_width > $maxsize)
569
- $width_ratio = $maxsize / $current_width;
570
- if ($current_height > $maxsize)
571
- $height_ratio = $maxsize / $current_height;
572
- // the smaller ratio is the one we need to fit it to the constraining box
573
- $ratio = min( $width_ratio, $height_ratio );
574
- $w = intval($current_width * $ratio);
575
- $h = intval($current_height * $ratio);
576
- return array($w, $h);
577
- }
578
-
579
- function oth_image_size_blank($w, $h, $imgtag){
580
- return array(0, 0);
581
- }
582
-
583
- function oth_image_size_exact($w, $h, $imgtag){
584
- return array($w, $h);
585
- }
586
-
587
- function oth_image_size_fixedw($w, $h, $imgtag){
588
- list($current_width, $current_height) = oth_get_actual_size($imgtag);
589
- $h = intval($w * ($current_height / $current_width));
590
- return array($w, $h);
591
- }
592
-
593
- function oth_image_size_fixedh($w, $h, $imgtag){
594
- list($current_width, $current_height) = oth_get_actual_size($imgtag);
595
- $w = intval($h * ($current_width / $current_height));
596
- return array($w, $h);
597
- }
598
-
599
- function oth_test($x) {
600
- if (empty($x)) return 'a';
601
- if (is_numeric($x)) return 'b';
602
- return 'c';
603
- }
604
-
605
- function oth_process($w, $h) {
606
- static $table = array( 'a' => array('a' => 'full', 'b' => 'scale', 'c' => 'blank'),
607
- 'b' => array('a' => 'scale', 'b' => 'exact', 'c' => 'fixedw'),
608
- 'c' => array('a' => 'blank', 'b' => 'fixedh', 'c' => 'blank'));
609
- return 'oth_image_size_' . $table[oth_test($w)][oth_test($h)];
610
- }
611
-
612
- function otf_image($option_key, $result, $ext) {
613
- // extract any image tags
614
- $content = $result->post_content;
615
- $i = 0;
616
- $imgtag = '';
617
- if ($ext) {
618
- $s = explode(':', $ext);
619
- if (isset($s[3]) && $s[3] === 'post') {
620
- $content = apply_filters('the_content', $content);
621
- }
622
- }
623
-
624
- if (isset($s[4]) && $s[4] === 'link') {
625
- $pattern = '/<a.+?<img.+?>.+?a>/i';
626
- $pattern2 = '#(<a.+?<img.+?)(/>|>)#is';
627
- } else {
628
- $pattern = '/<img.+?>/i';
629
- $pattern2 = '#(<img.+?)(/>|>)#is';
630
- }
631
- if (!preg_match_all($pattern, $content, $matches)) {
632
- // no <img> tags in content
633
- if ((isset($s[5]) && $s[5]) && (isset($s[6]) && $s[6])) {
634
- // a default <img> tag has been given
635
- return $s[5].':'.$s[6];
636
- } else {
637
- return '';
638
- }
639
- }
640
- if (isset($s[0])) {
641
- $i = $s[0];
642
- }
643
-
644
- if (isset($matches[0][$i])){
645
- $imgtag = $matches[0][$i];
646
- }
647
-
648
- if (!isset($s[1])) {
649
- $s[1] = null;
650
- }
651
-
652
- if (!isset($s[2])) {
653
- $s[2] = null;
654
- }
655
-
656
- $process = oth_process($s[1],$s[2]);
657
- list($w, $h) = $process(intval($s[1]), intval($s[2]), $imgtag);
658
- if ($w === 0) return '';
659
- if ($w === 1) return $imgtag;
660
- // remove height or width if present
661
- $imgtag = preg_replace('/(width|height)\s*=\s*[\'|\"](.*?)[\'|\"]/is', '', $imgtag);
662
- // insert the new size
663
- $imgtag = preg_replace($pattern2, "$1 height=\"$h\" width=\"$w\" $2", $imgtag);
664
- return $imgtag;
665
- }
666
-
667
- function otf_imagesrc($option_key, $result, $ext) {
668
- // extract any image tags
669
- $content = $result->post_content;
670
- $i = 0;
671
- $imgsrc = '';
672
- if ($ext) {
673
- $s = explode(':', $ext);
674
- if (isset($s[1]) && $s[1] === 'post') {
675
- $content = apply_filters('the_content', $content);
676
- }
677
- if (isset($s[2]) && $s[2]) $suffix = $s[2];
678
- }
679
- if (isset($s[0])) {
680
- $i = $s[0];
681
- }
682
- $pattern = '/<img.+?src\s*=\s*[\'|\"](.*?)[\'|\"].+?>/i';
683
-
684
- if (!preg_match_all($pattern, $content, $matches)) return '';
685
-
686
- if (isset($matches[1][$i])){
687
- $imgsrc = $matches[1][$i];
688
- }
689
-
690
- if (isset($suffix) && $suffix) {
691
- if ($suffix === '?m') $suffix = '-' . get_option('medium_size_w') . 'x' . get_option('medium_size_h');
692
- if ($suffix === '?t') $suffix = '-' . get_option('thumbnail_size_w') . 'x' . get_option('thumbnail_size_h');
693
- $pathinfo = pathinfo($imgsrc);
694
- $extension = $pathinfo['extension'];
695
- $imgsrc = str_replace(".$extension", "$suffix.$extension", $imgsrc);
696
- }
697
- return $imgsrc;
698
- }
699
-
700
- function otf_imagesrc_shareaholic($option_key, $result, $ext) {
701
-
702
- $thumbnail_src = '';
703
-
704
- if (is_attachment($result->ID)) {
705
- $thumbnail_src = wp_get_attachment_thumb_url($result->ID);
706
- }
707
-
708
- $thumbnail_src = oth_post_featured_image($result->ID);
709
-
710
- if ($thumbnail_src == NULL) {
711
- $thumbnail_src = oth_post_first_image($result->ID);
712
- }
713
-
714
- if ($thumbnail_src != NULL) {
715
- return $thumbnail_src;
716
- } else {
717
- return null;
718
- }
719
- }
720
-
721
- function otf_imagealt($option_key, $result, $ext) {
722
- // extract any image tags
723
- $content = $result->post_content;
724
- $i = 0;
725
- if ($ext) {
726
- $s = explode(':', $ext);
727
- if (isset($s[1]) && $s[1] === 'post') {
728
- $content = apply_filters('the_content', $content);
729
- }
730
- if (isset($s[2]) && $s[2]) $suffix = $s[2];
731
- }
732
- $pattern = '/<img.+?alt\s*=\s*[\'|\"](.*?)[\'|\"].+?>/i';
733
- if (!preg_match_all($pattern, $content, $matches)) return '';
734
- if (isset($s[0])) {
735
- $i = $s[0];
736
- }
737
- if (isset($matches[1][$i])) {
738
- return $matches[1][$i];
739
- }
740
- }
741
-
742
- function otf_gravatar($option_key, $result, $ext) {
743
- $size = 96;
744
- $rating = '';
745
- $default = "http://www.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=$size"; // ad516503a11cd5ca435acc9bb6523536 == md5('unknown@gravatar.com')
746
- if ($ext) {
747
- $s = explode(':', $ext);
748
- if (isset($s[0])) $size = $s[0];
749
- if (isset($s[1])) $rating = $s[1];
750
- if (isset($s[3])) {
751
- $default = 'http:'.$s[3];
752
- } else {
753
- if (isset($s[2])) $default = $s[2];
754
- }
755
- }
756
- $email = '';
757
- if (isset($result->comment_author_email)) {
758
- $email = $result->comment_author_email;
759
- } else {
760
- $user = get_userdata($result->post_author);
761
- if ($user) $email = $user->user_email;
762
- }
763
- if (!empty($email)) {
764
- $out = 'http://www.gravatar.com/avatar/';
765
- $out .= md5(strtolower($email));
766
- $out .= '?s='.$size;
767
- $out .= '&amp;d=' . urlencode( $default );
768
- if ('' !== $rating)
769
- $out .= "&amp;r={$rating}";
770
- $avatar = "<img alt='' src='{$out}' class='avatar avatar-{$size}' height='{$size}' width='{$size}' />";
771
- } else {
772
- $avatar = "<img alt='' src='{$default}' class='avatar avatar-{$size} avatar-default' height='{$size}' width='{$size}' />";
773
- }
774
- return apply_filters('get_avatar', $avatar, $email, $size, $default);
775
- }
776
-
777
- // returns the principal category id of a post -- if a cats are hierarchical chooses the most specific -- if multiple cats chooses the first (numerically smallest)
778
- function otf_categoryid($option_key, $result, $ext) {
779
- $cats = get_the_category($result->ID);
780
- foreach ($cats as $cat) {
781
- $parents[] = $cat->category_parent;
782
- }
783
- foreach ($cats as $cat) {
784
- if (!in_array($cat->cat_ID, $parents)) $categories[] = $cat->cat_ID;
785
- }
786
- return $categories[0];
787
- }
788
-
789
- // fails if parentheses are out of order or nested
790
- function oth_splitapart($subject) {
791
- $bits = explode(':', $subject);
792
- $inside = false;
793
- $newbits = array();
794
- $acc = '';
795
- foreach ($bits as $bit) {
796
- if (false !== strpos($bit, '{')) {
797
- $inside = true;
798
- $acc = '';
799
- }
800
- if (false !== strpos($bit, '}')) {
801
- $inside = false;
802
- if ($acc !== '') {
803
- $acc .= ':' . $bit;
804
- } else {
805
- $acc = $bit;
806
- }
807
- }
808
- if ($inside) {
809
- if ($acc !== '') {
810
- $acc .= ':' . $bit;
811
- } else {
812
- $acc = $bit;
813
- }
814
- } else {
815
- if ($acc !== '') {
816
- $newbits[] = $acc;
817
- $acc = '';
818
- } else {
819
- $newbits[] = $bit;
820
- }
821
- }
822
- }
823
- return $newbits;
824
- }
825
-
826
- function otf_if($option_key, $result, $ext) {
827
- global $post;
828
- $ID = ppl_current_post_id();
829
- $condition = 'true';
830
- $true = '';
831
- $false = '';
832
- if ($ext) {
833
- $s = oth_splitapart($ext);
834
- if (isset($s[0])) $condition = $s[0];
835
- if (isset($s[1])) $true = $s[1];
836
- if (isset($s[2])) $false = $s[2];
837
- }
838
- if (strpos($condition, '{')!==false) {
839
- $condition = ppl_expand_template($result, $condition, ppl_prepare_template($condition), $option_key);
840
- }
841
- if (eval("return ($condition);")) $tag = $true; else $tag = $false;
842
- // if the replacement tag contains pseudotags expand them
843
- if (strpos($tag, '}')!==false) {
844
- $tag = ppl_expand_template($result, $tag, ppl_prepare_template($tag), $option_key);
845
- }
846
- return $tag;
847
- }
848
-
849
- function otf_php($option_key, $result, $ext) {
850
- global $post;
851
- $ID = ppl_current_post_id();
852
- $value = '';
853
- if ($ext) {
854
- if (strpos($ext, '{')!==false) {
855
- $ext = ppl_expand_template($result, $ext, ppl_prepare_template($ext), $option_key);
856
- }
857
- ob_start();
858
- eval($ext);
859
- $value = ob_get_contents();
860
- ob_end_clean();
861
- }
862
- return $value;
863
- }
864
-
865
-
866
- // ****************************** Helper Functions *********************************************
867
-
868
- function oth_post_first_image($id) {
869
- $first_img = '';
870
- if ($id == NULL)
871
- return false;
872
- else {
873
- $post = get_post($id);
874
- $output = preg_match_all('/<img.*?src=[\'"](.*?)[\'"].*?>/i', $post->post_content, $matches);
875
- if (isset($matches[1][0])) {
876
- // Exclude base64 images; meta tags require full URLs
877
- if (strpos($matches[1][0], 'data:') === false) {
878
- $first_img = $matches[1][0];
879
- }
880
- } else {
881
- return false;
882
- }
883
- return $first_img;
884
- }
885
- }
886
-
887
- /**
888
- * This function returns the URL of the featured image for a given post
889
- *
890
- * @return returns `false` or a string of the image src
891
- */
892
- function oth_post_featured_image($id, $size = "thumbnail") {
893
- $featured_img = '';
894
- if ($id == NULL)
895
- return false;
896
- else {
897
- $post = get_post($id);
898
- if (function_exists('has_post_thumbnail') && has_post_thumbnail($post->ID)) {
899
- $thumbnail_shareaholic = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'thumbnail');
900
- $thumbnail_full = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
901
-
902
- if (($size == "thumbnail") && ($thumbnail_shareaholic[0] !== $thumbnail_full[0])) {
903
- $featured_img = esc_attr($thumbnail_shareaholic[0]);
904
- } else {
905
- if ($size == "thumbnail") {
906
- $thumbnail_large = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'large');
907
- } else {
908
- $thumbnail_large = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), $size);
909
- }
910
- $featured_img = esc_attr($thumbnail_large[0]);
911
- }
912
- } else {
913
- return false;
914
- }
915
- }
916
- return $featured_img;
917
- }
918
-
919
- function oth_truncate_text($text, $ext) {
920
- if (!$ext) {
921
- return $text;
922
- }
923
- $s = explode(':', $ext);
924
- if (count($s) > 2) {
925
- return $text;
926
- }
927
- if (count($s) == 1) {
928
- $s[] = 'wrap';
929
- }
930
- $length = $s[0];
931
- $type = $s[1];
932
- switch ($type) {
933
- case 'wrap':
934
- $length += strlen('<br />');
935
- if (!function_exists('mb_detect_encoding')) {
936
- return wordwrap($text, $length, '<br />', true);
937
- } else {
938
- $e = mb_detect_encoding($text);
939
- $formatted = '';
940
- $position = -1;
941
- $prev_position = 0;
942
- $last_line = -1;
943
- while($position = mb_strpos($text, " ", ++$position, $e)) {
944
- if($position > $last_line + $length + 1) {
945
- $formatted.= mb_substr($text, $last_line + 1, $prev_position - $last_line - 1, $e).'<br />';
946
- $last_line = $prev_position;
947
- }
948
- $prev_position = $position;
949
- }
950
- $formatted.= mb_substr($text, $last_line + 1, mb_strlen( $text ), $e);
951
- return $formatted;
952
- }
953
- case 'chop':
954
- if (!function_exists('mb_detect_encoding')) {
955
- return substr($text, 0, $length);
956
- } else {
957
- $e = mb_detect_encoding($text);
958
- return mb_substr($text, 0, $length, $e);
959
- }
960
- case 'trim':
961
- if (strlen($text) > $length) {
962
- } else {
963
- return $text;
964
- }
965
- if (!function_exists('mb_detect_encoding')) {
966
- $textlen = strlen($text);
967
- if ($textlen > $length) {
968
- $text = substr($text, 0, $length-2);
969
- return rtrim($text,".").'&hellip;';
970
- } else {
971
- return $text;
972
- }
973
- } else {
974
- $e = mb_detect_encoding($text);
975
- $textlen = mb_strlen($text, $e);
976
- if ($textlen > $length) {
977
- $text = mb_substr($text, 0, $length-2, $e);
978
- return rtrim($text,".").'&hellip;';
979
- } else {
980
- return $text;
981
- }
982
- }
983
- case 'snip':
984
- if (!function_exists('mb_detect_encoding')) {
985
- $textlen = strlen($text);
986
- if ($textlen > $length) {
987
- $b = floor(($length - 2)/2);
988
- $l = $textlen - $b - 1;
989
- return substr($text, 0, $b).'&hellip;'.substr($text, $l);
990
- } else {
991
- return $text;
992
- }
993
- } else {
994
- $e = mb_detect_encoding($text);
995
- $textlen = mb_strlen($text, $e);
996
- if ($textlen > $length) {
997
- $b = floor(($length - 2)/2);
998
- $l = $textlen - $b - 1;
999
- return mb_substr($text, 0, $b, $e).'&hellip;'.mb_substr($text, $l, 1000, $e);
1000
- } else {
1001
- return $text;
1002
- }
1003
- }
1004
- default:
1005
- return wordwrap($t, $length, '<br />', true);
1006
- }
1007
- }
1008
-
1009
- function oth_trim_extract($text, $len, $more, $numsent) {
1010
- $text = str_replace(']]>', ']]&gt;', $text);
1011
- if(strpos($text, '<!--more-->')) {
1012
- $parts = explode('<!--more-->', $text, 2);
1013
- $text = $parts[0];
1014
- } else {
1015
- if ($len > count(preg_split('/[\s]+/', strip_tags($text), -1))) return $text;
1016
- // remove html entities for now
1017
- $text = str_replace("\x06", "", $text);
1018
- preg_match_all("/&([a-z\d]{2,7}|#\d{2,5});/i", $text, $ents);
1019
- $text = preg_replace("/&([a-z\d]{2,7}|#\d{2,5});/i", "\x06", $text);
1020
- // now we start counting
1021
- $parts = preg_split('/([\s]+)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
1022
- $in_tag = false;
1023
- $num_words = 0;
1024
- $sentences = array();
1025
- $words = '';
1026
- foreach($parts as $part) {
1027
- if(0 < preg_match('/<[^>]*$/s', $part)) {
1028
- $in_tag = true;
1029
- } else if(0 < preg_match('/>[^<]*$/s', $part)) {
1030
- $in_tag = false;
1031
- }
1032
- if(!$in_tag && '' != trim($part) && substr($part, -1, 1) != '>') {
1033
- $num_words++;
1034
- }
1035
- if(!$in_tag && '' != trim($part) && false !== strpos('.?!', substr($part, -1, 1))) {
1036
- $sentences [] = $words . $part;
1037
- $words = '';
1038
- } else {
1039
- $words .= $part;
1040
- }
1041
- if($num_words >= $len && !$in_tag) break;
1042
- }
1043
- if (!isset($numsent)) {
1044
- $text = implode('', $sentences) . $words;
1045
- } else {
1046
- $numsent = abs($numsent);
1047
- if ($numsent == 0) {
1048
- $text = implode('', $sentences);
1049
- } else {
1050
- $text = implode('', array_slice($sentences, 0, $numsent));
1051
- }
1052
- }
1053
- // put back the missing html entities
1054
- foreach ($ents[0] as $ent) $text = preg_replace("/\x06/", $ent, $text, 1);
1055
- }
1056
- $text = balanceTags($text, true);
1057
- $text = $text . $more;
1058
- return $text;
1059
- }
1060
-
1061
- function oth_format_snippet($content, $option_key, $trim, $len, $more) {
1062
- $content = strip_tags($content);
1063
- $p = get_option($option_key);
1064
- if ($p['stripcodes']) $content = oth_strip_special_tags($content, $p['stripcodes']);
1065
- // strip extra whitespace
1066
- $content = preg_replace('/\s+/u', ' ', $content);
1067
- $content = stripslashes($content);
1068
- if (function_exists('mb_detect_encoding')) $enc = mb_detect_encoding($content);
1069
- // grab a maximum number of characters
1070
- if ($enc) {
1071
- mb_internal_encoding($enc);
1072
- if (mb_strlen($content) >= $len) {
1073
- $snippet = mb_substr($content, 0, $len);
1074
- if ($trim == 'word' && mb_strlen($snippet) == $len) {
1075
- // trim back to the last full word--NB if our snippet ends on a word
1076
- // boundary we still have to trim back to the non-word character
1077
- // (the final 's' in the pattern makes sure we match newlines)
1078
- preg_match('/^(.*)\W/su', $snippet, $matches);
1079
- //if we can't get a single full word we use the full snippet
1080
- // (we use $matches[1] because we don't want the white-space)
1081
- if ($matches[1]) $snippet = $matches[1];
1082
- }
1083
- $snippet .= $more;
1084
- } else {
1085
- $snippet = $content;
1086
- }
1087
- } else {
1088
- if (strlen($content) >= $len) {
1089
- $snippet = substr($content, 0, $len);
1090
- if ($trim == 'word' && strlen($snippet) == $len) {
1091
- // trim back to the last full word--NB if our snippet ends on a word
1092
- // boundary we still have to trim back to the non-word character
1093
- // (the final 's' in the pattern makes sure we match newlines)
1094
- preg_match('/^(.*)\W/s', $snippet, $matches);
1095
- //if we can't get a single full word we use the full snippet
1096
- // (we use $matches[1] because we don't want the white-space)
1097
- if ($matches[1]) $snippet = $matches[1];
1098
- }
1099
- $snippet .= $more;
1100
- } else {
1101
- $snippet = $content;
1102
- }
1103
- }
1104
- return $snippet;
1105
- }
1106
-
1107
- function oth_strip_special_tags($text, $stripcodes) {
1108
- $numtags = count($stripcodes);
1109
- for ($i = 0; $i < $numtags; $i++) {
1110
- if (!$stripcodes[$i]['start'] || !$stripcodes[$i]['end']) return $text;
1111
- $pattern = '/('. oth_regescape($stripcodes[$i]['start']) . '(.*?)' . oth_regescape($stripcodes[$i]['end']) . ')/i';
1112
- $text = preg_replace($pattern, '', $text);
1113
- }
1114
- return $text;
1115
- }
1116
-
1117
- function oth_trim_excerpt($content, $len) {
1118
- // taken from the wp_trim_excerpt filter
1119
- remove_filter( 'the_content', 'ppl_content_filter', 5 );
1120
- remove_filter( 'the_content', 'ppl_post_filter', 5 );
1121
- $text = apply_filters('the_content', $content);
1122
- add_filter( 'the_content', 'ppl_content_filter', 5 );
1123
- add_filter( 'the_content', 'ppl_post_filter', 5 );
1124
- $text = str_replace(']]>', ']]&gt;', $text);
1125
- $text = strip_tags($text);
1126
- if (!$len) $len = 55;
1127
- $excerpt_length = $len;
1128
- $words = explode(' ', $text, $excerpt_length + 1);
1129
- if (count($words) > $excerpt_length) {
1130
- array_pop($words);
1131
- $text = implode(' ', $words);
1132
- }
1133
- $text = convert_smilies($text);
1134
- return $text;
1135
- }
1136
-
1137
- function oth_trim_comment_excerpt($content, $len) {
1138
- // adapted from the wp_trim_excerpt filter
1139
- $text = $content;
1140
- $text = apply_filters('get_comment_text', $text);
1141
- $text = str_replace(']]>', ']]&gt;', $text);
1142
- $text = strip_tags($text);
1143
- if (!$len) $len = 55;
1144
- $excerpt_length = $len;
1145
- $words = explode(' ', $text, $excerpt_length + 1);
1146
- if (count($words) > $excerpt_length) {
1147
- array_pop($words);
1148
- $text = implode(' ', $words);
1149
- }
1150
- $text = convert_smilies($text);
1151
- return $text;
1152
- }
1153
-
1154
- function oth_format_date($date, $fmt) {
1155
- if (!$fmt) $fmt = get_option('date_format');
1156
- $d = mysql2date($fmt, $date);
1157
- $d = apply_filters('get_the_time', $d, $fmt);
1158
- return apply_filters('the_time', $d, $fmt);
1159
- }
1160
-
1161
- function oth_format_time($time, $fmt) {
1162
- if (!$fmt) $fmt = get_option('time_format');
1163
- $d = mysql2date($fmt, $time);
1164
- $d = apply_filters('get_the_time', $d, $fmt);
1165
- return apply_filters('the_time', $d, $fmt);
1166
- }
1167
-
1168
- function oth_regescape($s) {
1169
- $s = str_replace('\\', '\\\\', $s);
1170
- $s = str_replace('/', '\\/', $s);
1171
- $s = str_replace('[', '\\[', $s);
1172
- $s = str_replace(']', '\\]', $s);
1173
- return $s;
1174
- }
1
+ <?php
2
+
3
+ /*
4
+ Library for the Recent Posts, Random Posts, Recent Comments, and Similar Posts plugins
5
+ -- provides the routines which evaluate output template tags
6
+ */
7
+
8
+ define('OT_LIBRARY', true);
9
+
10
+ // Called by the post plugins to match output tags to the actions that evaluate them
11
+ function output_tag_action($tag) {
12
+ return 'otf_'.$tag;
13
+ }
14
+
15
+ /*
16
+ innards
17
+ */
18
+
19
+ // To add a new output template tag all you need to do is write a tag function like those below.
20
+
21
+ // All the tag functions must follow the pattern of 'otf_title' below.
22
+ // the name is the tag name prefixed by 'otf_'
23
+ // the arguments are always $option_key, $result and $ext
24
+ // $option_key the key to the plugin's options
25
+ // $result the particular row of the query result
26
+ // $ext some extra data which a tag may use
27
+ // the return value is the value of the tag as a string
28
+
29
+ function otf_postid ($option_key, $result, $ext) {
30
+ return $result->ID;
31
+ }
32
+
33
+ function otf_title ($option_key, $result, $ext) {
34
+ $value = oth_truncate_text($result->post_title, $ext);
35
+ return apply_filters('the_title', $value);
36
+ }
37
+
38
+ function otf_url($option_key, $result, $ext) {
39
+ $value = apply_filters('the_permalink', get_permalink($result->ID));
40
+ return oth_truncate_text($value, $ext);
41
+ }
42
+
43
+ function otf_author($option_key, $result, $ext) {
44
+ $type = false;
45
+ if ($ext) {
46
+ $s = explode(':', $ext);
47
+ if (count($s) == 1) {
48
+ $type = $s[0];
49
+ }
50
+ }
51
+ switch ($type) {
52
+ case 'display':
53
+ $author = get_the_author_meta('display_name',$result->post_author);
54
+ break;
55
+ case 'full':
56
+ $auth = get_userdata($result->post_author);
57
+ $author = $auth->first_name.' '.$auth->last_name;
58
+ break;
59
+ case 'reverse':
60
+ $auth = get_userdata($result->post_author);
61
+ $author = $auth->last_name.', '.$auth->first_name;
62
+ break;
63
+ case 'first':
64
+ $auth = get_userdata($result->post_author);
65
+ $author = $auth->first_name;
66
+ break;
67
+ case 'last':
68
+ $auth = get_userdata($result->post_author);
69
+ $author = $auth->last_name;
70
+ break;
71
+ default:
72
+ $author = get_the_author_meta('display_name',$result->post_author);
73
+ }
74
+ return $author;
75
+ }
76
+
77
+ function otf_authorurl($option_key, $result, $ext) {
78
+ return get_author_posts_url($result->post_author);
79
+ }
80
+
81
+ function otf_date($option_key, $result, $ext) {
82
+ if ($ext === 'raw') return $result->post_date;
83
+ else return oth_format_date($result->post_date, $ext);
84
+ }
85
+
86
+ function otf_dateedited($option_key, $result, $ext) {
87
+ if ($ext === 'raw') return $result->post_modified;
88
+ else return oth_format_date($result->post_modified, $ext);
89
+ }
90
+
91
+ function otf_time($option_key, $result, $ext) {
92
+ return oth_format_time($result->post_date, $ext);
93
+ }
94
+
95
+ function otf_timeedited($option_key, $result, $ext) {
96
+ return oth_format_time($result->post_modified, $ext);
97
+ }
98
+
99
+ function otf_excerpt($option_key, $result, $ext) {
100
+ if (!$ext) {
101
+ $len = 55;
102
+ $type = 'a';
103
+ } else {
104
+ $s = explode(':', $ext);
105
+ if (count($s) == 1) {
106
+ $s[] = 'a';
107
+ }
108
+ $len = $s[0];
109
+ $type = $s[1];
110
+ if ($type === 'b') {
111
+ if (count($s) > 2) {
112
+ $more = $s[2];
113
+ } else {
114
+ $more = ' &hellip;';
115
+ }
116
+ if (count($s) > 3) {
117
+ if ($s[3] === 'link') {
118
+ $url = otf_url($option_key, $result, '');
119
+ $more = '<a href="'.$url.'">'.$more.'</a>';
120
+ }
121
+ }
122
+ if (count($s) > 4) {
123
+ $numsent = $s[4];
124
+ }
125
+ }
126
+ }
127
+ switch ($type) {
128
+ case 'a':
129
+ $value = trim($result->post_excerpt);
130
+ if ($value == '') $value = $result->post_content;
131
+ $value = oth_trim_excerpt($value, $ext);
132
+ break;
133
+ case 'b':
134
+ $value = trim($result->post_excerpt);
135
+ if ($value === '') {
136
+ $value = $result->post_content;
137
+ $value = convert_smilies($value);
138
+ $value = oth_trim_extract($value, $len, $more, $numsent);
139
+ $value = apply_filters('get_the_content', $value);
140
+ remove_filter('the_content', 'ppl_content_filter', 5);
141
+ remove_filter('the_content', 'ppl_post_filter', 5);
142
+ $value = apply_filters('the_content', $value);
143
+ add_filter('the_content', 'ppl_content_filter', 5);
144
+ add_filter('the_content', 'ppl_post_filter', 5);
145
+
146
+ } else {
147
+ $value = convert_smilies($value);
148
+ $value = apply_filters('get_the_excerpt', $value);
149
+ remove_filter('the_excerpt', 'ppl_content_filter', 5);
150
+ $value = apply_filters('the_excerpt', $value);
151
+ add_filter('the_excerpt', 'ppl_content_filter', 5);
152
+ }
153
+ break;
154
+ default:
155
+ $value = trim($result->post_excerpt);
156
+ if ($value == '') $value = $result->post_content;
157
+ $value = oth_trim_excerpt($value, $len);
158
+ break;
159
+ }
160
+ return $value;
161
+ }
162
+
163
+ function otf_snippet($option_key, $result, $ext) {
164
+ $len = 100;
165
+ $type = 'char';
166
+ $more = '';
167
+ $link = 'nolink';
168
+ if ($ext) {
169
+ $s = explode(':', $ext);
170
+ if (isset($s[0]) && $s[0]) $len = $s[0];
171
+ if (isset($s[1]) && $s[1]) $type = $s[1];
172
+ if (isset($s[2]) && $s[2]) $more = $s[2];
173
+ if (isset($s[3]) && $s[3]) $link = $s[3];
174
+ }
175
+ if ($link === 'link') {
176
+ $url = otf_url($option_key, $result, '');
177
+ $more = '<a href="'.$url.'">'.$more.'</a>';
178
+ }
179
+ return oth_format_snippet($result->post_content, $option_key, $type, $len, $more);
180
+ }
181
+
182
+ function otf_snippetword($option_key, $result, $ext) {
183
+ $len = 100;
184
+ $more = '';
185
+ $link = 'nolink';
186
+ if ($ext) {
187
+ $s = explode(':', $ext);
188
+ if (isset($s[0]) && $s[0]) $len = $s[0];
189
+ if (isset($s[1]) && $s[1]) $more = $s[1];
190
+ if (isset($s[2]) && $s[2]) $link = $s[2];
191
+ }
192
+ if ($link === 'link') {
193
+ $url = otf_url($option_key, $result, '');
194
+ $more = '<a href="'.$url.'">'.$more.'</a>';
195
+ }
196
+ return oth_format_snippet($result->post_content, $option_key, 'word', $len, $more);
197
+ }
198
+
199
+ function otf_fullpost($option_key, $result, $ext) {
200
+ remove_filter( 'the_content', 'ppl_content_filter', 5 );
201
+ remove_filter( 'the_content', 'ppl_post_filter', 5 );
202
+ $value = apply_filters('the_content', $result->post_content);
203
+ add_filter( 'the_content', 'ppl_content_filter', 5 );
204
+ add_filter( 'the_content', 'ppl_post_filter', 5 );
205
+ return str_replace(']]>', ']]&gt;', $value);
206
+ }
207
+
208
+ function otf_commentcount($option_key, $result, $ext) {
209
+ $value = $result->comment_count;
210
+ if ($ext) {
211
+ $s = explode(':', $ext);
212
+ if (count($s) == 3) {
213
+ if ($value == 0) $value = $s[0];
214
+ elseif ($value == 1) $value .= ' ' . $s[1];
215
+ else $value .= ' ' . $s[2];
216
+ }
217
+ }
218
+ return $value;
219
+ }
220
+
221
+ function otf_commentexcerpt($option_key, $result, $ext) {
222
+ if (!$ext) {
223
+ $len = 55;
224
+ $type = 'a';
225
+ } else {
226
+ $s = explode(':', $ext);
227
+ if (count($s) == 1) {
228
+ $s[] = 'a';
229
+ }
230
+ $len = $s[0];
231
+ $type = $s[1];
232
+ if ($type === 'b') {
233
+ if (count($s) > 2) {
234
+ $more = $s[2];
235
+ } else {
236
+ $more = ' &hellip;';
237
+ }
238
+ if (count($s) > 3) {
239
+ if ($s[3] === 'link') {
240
+ $url = otf_commenturl($option_key, $result, '');
241
+ $more = '<a href="'.$url.'">'.$more.'</a>';
242
+ }
243
+ }
244
+ }
245
+ }
246
+ switch ($type) {
247
+ case 'a':
248
+ $value = oth_trim_comment_excerpt($result->comment_content, $ext);
249
+ break;
250
+ case 'b':
251
+ $value = $result->comment_content;
252
+ $value = convert_smilies($value);
253
+
254
+ $text = str_replace(']]>', ']]&gt;', $value);
255
+ if ($len <= count(preg_split('/[\s]+/', strip_tags($text), -1))) {
256
+ // remove html entities for now
257
+ $text = str_replace("\x06", "", $text);
258
+ preg_match_all("/&([a-z\d]{2,7}|#\d{2,5});/i", $text, $ents);
259
+ $text = preg_replace("/&([a-z\d]{2,7}|#\d{2,5});/i", "\x06", $text);
260
+ // now we start counting
261
+ $parts = preg_split('/([\s]+)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
262
+ $in_tag = false;
263
+ $num_words = 0;
264
+ $text = '';
265
+ foreach($parts as $part) {
266
+ if(0 < preg_match('/<[^>]*$/s', $part)) {
267
+ $in_tag = true;
268
+ } else if(0 < preg_match('/>[^<]*$/s', $part)) {
269
+ $in_tag = false;
270
+ }
271
+ if(!$in_tag && '' != trim($part) && substr($part, -1, 1) != '>') {
272
+ $num_words++;
273
+ }
274
+ $text .= $part;
275
+ if($num_words >= $len && !$in_tag) break;
276
+ }
277
+ // put back the missing html entities
278
+ foreach ($ents[0] as $ent) $text = preg_replace("/\x06/", $ent, $text, 1);
279
+ $text = balanceTags($text, true);
280
+ $value = $text . $more;
281
+ }
282
+ $value = apply_filters('get_comment_text', $value);
283
+ break;
284
+ default:
285
+ $value = oth_trim_comment_excerpt($result->comment_content, $ext);
286
+ break;
287
+ }
288
+ return $value;
289
+ }
290
+
291
+ function otf_commentsnippet($option_key, $result, $ext) {
292
+ $len = 100;
293
+ $type = 'char';
294
+ $more = '';
295
+ $link = 'nolink';
296
+ if ($ext) {
297
+ $s = explode(':', $ext);
298
+ if (isset($s[0]) && $s[0]) $len = $s[0];
299
+ if (isset($s[1]) && $s[1]) $type = $s[1];
300
+ if (isset($s[2]) && $s[2]) $more = $s[2];
301
+ if (isset($s[3]) && $s[3]) $link = $s[3];
302
+ }
303
+ if ($link === 'link') {
304
+ $url = otf_commenturl($option_key, $result, '');
305
+ $more = '<a href="'.$url.'">'.$more.'</a>';
306
+ }
307
+ return oth_format_snippet($result->comment_content, $option_key, $type, $len, $more);
308
+ }
309
+
310
+ function otf_commentsnippetword($option_key, $result, $ext) {
311
+ $len = 100;
312
+ $more = '';
313
+ $link = 'nolink';
314
+ if ($ext) {
315
+ $s = explode(':', $ext);
316
+ if (isset($s[0]) && $s[0]) $len = $s[0];
317
+ if (isset($s[1]) && $s[1]) $more = $s[1];
318
+ if (isset($s[2]) && $s[2]) $link = $s[2];
319
+ }
320
+ if ($link === 'link') {
321
+ $url = otf_commenturl($option_key, $result, '');
322
+ $more = '<a href="'.$url.'">'.$more.'</a>';
323
+ }
324
+ return oth_format_snippet($result->comment_content, $option_key, 'word', $len, $more);
325
+ }
326
+
327
+ function otf_commentdate($option_key, $result, $ext) {
328
+ if ($ext === 'raw') return $result->comment_date;
329
+ return oth_format_date($result->comment_date, $ext);
330
+ }
331
+
332
+ function otf_commenttime($option_key, $result, $ext) {
333
+ return oth_format_time($result->comment_date, $ext);
334
+ }
335
+
336
+ function otf_commentdategmt($option_key, $result, $ext) {
337
+ if ($ext === 'raw') return $result->comment_date_gmt;
338
+ return oth_format_date($result->comment_date_gmt, $ext);
339
+ }
340
+
341
+ function otf_commenttimegmt($option_key, $result, $ext) {
342
+ return oth_format_time($result->comment_date_gmt, $ext);
343
+ }
344
+
345
+ function otf_commenter($option_key, $result, $ext) {
346
+ $value = $result->comment_author;
347
+ $value = apply_filters('get_comment_author', $value);
348
+ $value = apply_filters('comment_author', $value);
349
+ return oth_truncate_text($value, $ext);
350
+ }
351
+
352
+ function otf_commenterurl($option_key, $result, $ext) {
353
+ $value = $result->comment_author_url;
354
+ $value = apply_filters('get_comment_author_url', $value);
355
+ return oth_truncate_text($value, $ext);
356
+ }
357
+
358
+ function otf_commenterlink($option_key, $result, $ext) {
359
+ $url = otf_commenterurl($option_key, $result, '');
360
+ $author = otf_commenter($option_key, $result, $ext);
361
+ if (empty($url) || $url == 'http://') $value = $author;
362
+ else $value = "<a href='$url' rel='external nofollow'>$author</a>";
363
+ return $value;
364
+ }
365
+
366
+ function otf_commenterip($option_key, $result, $ext) {
367
+ return $result->comment_author_IP;
368
+ }
369
+
370
+ function otf_commenturl($option_key, $result, $ext) {
371
+ $value = apply_filters('the_permalink', get_permalink($result->ID)) . '#comment-' . $result->comment_ID;
372
+ return oth_truncate_text($value, $ext);
373
+ }
374
+
375
+ function otf_commentlink($option_key, $result, $ext) {
376
+ $ttl = otf_commenter($option_key, $result, '');
377
+ $ttl = '<span class="rc-commenter">' . $ttl . '</span>';
378
+ if (!$ext) $ext = ' commented on ';
379
+ $ttl .= $ext;
380
+ $ttl .= '<span class="rc-title">'.otf_title($option_key, $result, '').'</span>';
381
+ $pml = otf_commenturl($option_key, $result, '');
382
+ $pdt = oth_format_date($result->comment_date_gmt, '');
383
+ $pdt .= __(' at ', 'post_plugin_library');
384
+ $pdt .= oth_format_time($result->comment_date_gmt, '');
385
+ return "<a href=\"$pml\" rel=\"bookmark\" title=\"$pdt\">$ttl</a>";
386
+ }
387
+
388
+ function otf_commentlink2($option_key, $result, $ext) {
389
+ $commenturl = otf_commenturl($option_key, $result, '');
390
+ $commentdate = otf_commentdate($option_key, $result, '');
391
+ $commenttime = otf_commenttime($option_key, $result, '');
392
+ $title = otf_title($option_key, $result, '');
393
+ $commenter = otf_commenter($option_key, $result, '');
394
+ $commentexcerpt = otf_commentexcerpt($option_key, $result, '10');
395
+ return "<a href=\"$commenturl\" rel=\"bookmark\" title=\"$commentdate at $commenttime on '$title'\">$commenter</a> - $commentexcerpt&hellip;";
396
+ }
397
+
398
+ function otf_commentpopupurl($option_key, $result, $ext) {
399
+ global $wpcommentspopupfile, $wpcommentsjavascript;
400
+ $output = '';
401
+ if ( $wpcommentsjavascript ) {
402
+ if ( empty( $wpcommentspopupfile ) )
403
+ $home = get_option('home');
404
+ else
405
+ $home = get_option('siteurl');
406
+ $output .= $home . '/' . $wpcommentspopupfile . '?comments_popup=' . $result->ID;
407
+ $output .= '#comment-' . $result->comment_ID;
408
+ $output .= '" onclick="wpopen(this.href); return false';
409
+ }
410
+ return $output;
411
+ }
412
+
413
+ function otf_catlinks($option_key, $result, $ext) {
414
+ return otf_categorylinks($option_key, $result, $ext);
415
+ }
416
+
417
+ function otf_categorylinks($option_key, $result, $ext) {
418
+ $cats = get_the_category($result->ID);
419
+ $value = '';
420
+ $n = 0;
421
+ foreach ($cats as $cat) {
422
+ if ($n > 0) $value .= $ext;
423
+ $catname = apply_filters('single_cat_title', $cat->cat_name);
424
+ $value .= '<a href="' . get_category_link($cat->cat_ID) . '" title="' . sprintf(__("View all posts in %s", 'post_plugin_library'), $catname) . '" rel="category tag">'.$catname.'</a> ';
425
+ ++$n;
426
+ }
427
+ return $value;
428
+ }
429
+
430
+ function otf_catnames($option_key, $result, $ext) {
431
+ return otf_categorynames($option_key, $result, $ext);
432
+ }
433
+
434
+ function otf_categorynames($option_key, $result, $ext) {
435
+ $cats = get_the_category($result->ID);
436
+ $value = '';
437
+ $n = 0;
438
+ foreach ($cats as $cat) {
439
+ if ($n > 0) $value .= $ext;
440
+ $value .= apply_filters('single_cat_title', $cat->cat_name);
441
+ ++$n;
442
+ }
443
+ return $value;
444
+ }
445
+
446
+ function otf_custom($option_key, $result, $ext) {
447
+ $custom = get_post_custom($result->ID);
448
+ return $custom[$ext][0];
449
+ }
450
+
451
+ function otf_tags($option_key, $result, $ext) {
452
+ $tags = (array) get_the_tags($result->ID);
453
+ $tag_list = array();
454
+ foreach ( $tags as $tag ) {
455
+ if (isset($tag->name)) {
456
+ $tag_list[] = $tag->name;
457
+ }
458
+ }
459
+ if (!$ext) $ext = ', ';
460
+ $tag_list = join( $ext, $tag_list );
461
+ return $tag_list;
462
+ }
463
+
464
+ function otf_taglinks($option_key, $result, $ext) {
465
+ $tags = (array) get_the_tags($result->ID);
466
+ $tag_list = '';
467
+ $tag_links = array();
468
+ foreach ( $tags as $tag ) {
469
+ $link = get_tag_link($tag->term_id);
470
+ if ( is_wp_error( $link ) )
471
+ return $link;
472
+ $tag_links[] = '<a href="' . $link . '" rel="tag">' . $tag->name . '</a>';
473
+ }
474
+ if (!$ext) $ext = ' ';
475
+ $tag_links = join( $ext, $tag_links );
476
+ $tag_links = apply_filters( 'the_tags', $tag_links );
477
+ $tag_list .= $tag_links;
478
+ return $tag_list;
479
+ }
480
+
481
+ function otf_totalposts($option_key, $result, $ext) {
482
+ global $wpdb;
483
+ $value = '';
484
+ if (function_exists('get_post_type')) {
485
+ $value = (int) $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish'");
486
+ } else {
487
+ $value = (int) $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'");
488
+ }
489
+ return $value;
490
+ }
491
+
492
+ function otf_totalpages($option_key, $result, $ext) {
493
+ global $wpdb;
494
+ $value = '';
495
+ if (function_exists('get_post_type')) {
496
+ $value = (int) $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish'");
497
+ } else {
498
+ $value = (int) $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'static'");
499
+ }
500
+ return $value;
501
+ }
502
+
503
+ function otf_link($option_key, $result, $ext) {
504
+ $ttl = otf_title($option_key, $result, $ext);
505
+ $pml = otf_url($option_key, $result, null);
506
+ $pdt = otf_date($option_key, $result, null);
507
+ return "<a href=\"$pml\" rel=\"bookmark\" title=\"$ttl\">$ttl</a>";
508
+ }
509
+
510
+ function otf_score($option_key, $result, $ext) {
511
+ return sprintf("%.0f", $result->score);
512
+ }
513
+
514
+ // tries to get the number of post views from a few popular plugins if the are installed
515
+ function otf_postviews($option_key, $result, $ext) {
516
+ global $wpdb;
517
+ $count = 0;
518
+ // alex king's popularity contest
519
+ if (class_exists('ak_popularity_contest')) $count = $akpc->get_post_total($result->ID);
520
+ // my own post view count
521
+ else if (function_exists('popular_posts_views')) $count = popular_posts_views($result->ID);
522
+ // lester chan's postviews
523
+ else if (function_exists('the_views')) {
524
+ $count = get_post_custom($result->ID);
525
+ $count = intval($count['views'][0]);
526
+ }
527
+ // mark ghosh's top10
528
+ else if (function_exists('show_post_count')) {$id = $result->ID; $count = $wpdb->get_var("select cntaccess from mostAccessed WHERE postnumber = $id");}
529
+ // Ivan Djurdjevac's CountPosts
530
+ else if (function_exists('HitThisPost')) {$id = $result->ID; $count = $wpdb->get_var("SELECT post_hits FROM $wpdb->posts WHERE ID=$id");}
531
+
532
+ return $count;
533
+ }
534
+
535
+ function oth_get_actual_size($imgtag) {
536
+ // first try extracting the width and height attributes
537
+ if (preg_match('/\s+width\s*=\s*[\'|\"](.*?)[\'|\"]/is', $imgtag, $matches)) {
538
+ $current_width = $matches[1];
539
+ if (preg_match('/\s+height\s*=\s*[\'|\"](.*?)[\'|\"]/is', $imgtag, $matches)) {
540
+ $current_height = $matches[1];
541
+ }
542
+ }
543
+ // then try using the GD library
544
+ if (!(($current_width) && ($current_height))) {
545
+ // extract the image src url
546
+ preg_match('/\s+src\s*=\s*[\'|\"](.*?)[\'|\"]/is', $imgtag, $matches);
547
+ $error_level = error_reporting(0);
548
+ if (function_exists('getimagesize') && $imagesize = getimagesize($matches[1])) {
549
+ $current_width = $imagesize['0'];
550
+ $current_height = $imagesize['1'];
551
+ } else {
552
+ // if all else fails...
553
+ $current_width = $current_height = 0;
554
+ }
555
+ error_reporting($error_level);
556
+ }
557
+ return array($current_width, $current_height);
558
+ }
559
+
560
+ function oth_image_size_full($w, $h, $imgtag){
561
+ return array(1, 1);
562
+ }
563
+
564
+ function oth_image_size_scale($w, $h, $imgtag){
565
+ $maxsize = max($w, $h);
566
+ list($current_width, $current_height) = oth_get_actual_size($imgtag);
567
+ $width_ratio = $height_ratio = 1.0;
568
+ if ($current_width > $maxsize)
569
+ $width_ratio = $maxsize / $current_width;
570
+ if ($current_height > $maxsize)
571
+ $height_ratio = $maxsize / $current_height;
572
+ // the smaller ratio is the one we need to fit it to the constraining box
573
+ $ratio = min( $width_ratio, $height_ratio );
574
+ $w = intval($current_width * $ratio);
575
+ $h = intval($current_height * $ratio);
576
+ return array($w, $h);
577
+ }
578
+
579
+ function oth_image_size_blank($w, $h, $imgtag){
580
+ return array(0, 0);
581
+ }
582
+
583
+ function oth_image_size_exact($w, $h, $imgtag){
584
+ return array($w, $h);
585
+ }
586
+
587
+ function oth_image_size_fixedw($w, $h, $imgtag){
588
+ list($current_width, $current_height) = oth_get_actual_size($imgtag);
589
+ $h = intval($w * ($current_height / $current_width));
590
+ return array($w, $h);
591
+ }
592
+
593
+ function oth_image_size_fixedh($w, $h, $imgtag){
594
+ list($current_width, $current_height) = oth_get_actual_size($imgtag);
595
+ $w = intval($h * ($current_width / $current_height));
596
+ return array($w, $h);
597
+ }
598
+
599
+ function oth_test($x) {
600
+ if (empty($x)) return 'a';
601
+ if (is_numeric($x)) return 'b';
602
+ return 'c';
603
+ }
604
+
605
+ function oth_process($w, $h) {
606
+ static $table = array( 'a' => array('a' => 'full', 'b' => 'scale', 'c' => 'blank'),
607
+ 'b' => array('a' => 'scale', 'b' => 'exact', 'c' => 'fixedw'),
608
+ 'c' => array('a' => 'blank', 'b' => 'fixedh', 'c' => 'blank'));
609
+ return 'oth_image_size_' . $table[oth_test($w)][oth_test($h)];
610
+ }
611
+
612
+ function otf_image($option_key, $result, $ext) {
613
+ // extract any image tags
614
+ $content = $result->post_content;
615
+ $i = 0;
616
+ $imgtag = '';
617
+ if ($ext) {
618
+ $s = explode(':', $ext);
619
+ if (isset($s[3]) && $s[3] === 'post') {
620
+ $content = apply_filters('the_content', $content);
621
+ }
622
+ }
623
+
624
+ if (isset($s[4]) && $s[4] === 'link') {
625
+ $pattern = '/<a.+?<img.+?>.+?a>/i';
626
+ $pattern2 = '#(<a.+?<img.+?)(/>|>)#is';
627
+ } else {
628
+ $pattern = '/<img.+?>/i';
629
+ $pattern2 = '#(<img.+?)(/>|>)#is';
630
+ }
631
+ if (!preg_match_all($pattern, $content, $matches)) {
632
+ // no <img> tags in content
633
+ if ((isset($s[5]) && $s[5]) && (isset($s[6]) && $s[6])) {
634
+ // a default <img> tag has been given
635
+ return $s[5].':'.$s[6];
636
+ } else {
637
+ return '';
638
+ }
639
+ }
640
+ if (isset($s[0])) {
641
+ $i = $s[0];
642
+ }
643
+
644
+ if (isset($matches[0][$i])){
645
+ $imgtag = $matches[0][$i];
646
+ }
647
+
648
+ if (!isset($s[1])) {
649
+ $s[1] = null;
650
+ }
651
+
652
+ if (!isset($s[2])) {
653
+ $s[2] = null;
654
+ }
655
+
656
+ $process = oth_process($s[1],$s[2]);
657
+ list($w, $h) = $process(intval($s[1]), intval($s[2]), $imgtag);
658
+ if ($w === 0) return '';
659
+ if ($w === 1) return $imgtag;
660
+ // remove height or width if present
661
+ $imgtag = preg_replace('/(width|height)\s*=\s*[\'|\"](.*?)[\'|\"]/is', '', $imgtag);
662
+ // insert the new size
663
+ $imgtag = preg_replace($pattern2, "$1 height=\"$h\" width=\"$w\" $2", $imgtag);
664
+ return $imgtag;
665
+ }
666
+
667
+ function otf_imagesrc($option_key, $result, $ext) {
668
+ // extract any image tags
669
+ $content = $result->post_content;
670
+ $i = 0;
671
+ $imgsrc = '';
672
+ if ($ext) {
673
+ $s = explode(':', $ext);
674
+ if (isset($s[1]) && $s[1] === 'post') {
675
+ $content = apply_filters('the_content', $content);
676
+ }
677
+ if (isset($s[2]) && $s[2]) $suffix = $s[2];
678
+ }
679
+ if (isset($s[0])) {
680
+ $i = $s[0];
681
+ }
682
+ $pattern = '/<img.+?src\s*=\s*[\'|\"](.*?)[\'|\"].+?>/i';
683
+
684
+ if (!preg_match_all($pattern, $content, $matches)) return '';
685
+
686
+ if (isset($matches[1][$i])){
687
+ $imgsrc = $matches[1][$i];
688
+ }
689
+
690
+ if (isset($suffix) && $suffix) {
691
+ if ($suffix === '?m') $suffix = '-' . get_option('medium_size_w') . 'x' . get_option('medium_size_h');
692
+ if ($suffix === '?t') $suffix = '-' . get_option('thumbnail_size_w') . 'x' . get_option('thumbnail_size_h');
693
+ $pathinfo = pathinfo($imgsrc);
694
+ $extension = $pathinfo['extension'];
695
+ $imgsrc = str_replace(".$extension", "$suffix.$extension", $imgsrc);
696
+ }
697
+ return $imgsrc;
698
+ }
699
+
700
+ function otf_imagesrc_shareaholic($option_key, $result, $ext) {
701
+
702
+ $thumbnail_src = '';
703
+
704
+ if (is_attachment($result->ID)) {
705
+ $thumbnail_src = wp_get_attachment_thumb_url($result->ID);
706
+ }
707
+
708
+ $thumbnail_src = oth_post_featured_image($result->ID);
709
+
710
+ if ($thumbnail_src == NULL) {
711
+ $thumbnail_src = oth_post_first_image($result->ID);
712
+ }
713
+
714
+ if ($thumbnail_src != NULL) {
715
+ return $thumbnail_src;
716
+ } else {
717
+ return null;
718
+ }
719
+ }
720
+
721
+ function otf_imagealt($option_key, $result, $ext) {
722
+ // extract any image tags
723
+ $content = $result->post_content;
724
+ $i = 0;
725
+ if ($ext) {
726
+ $s = explode(':', $ext);
727
+ if (isset($s[1]) && $s[1] === 'post') {
728
+ $content = apply_filters('the_content', $content);
729
+ }
730
+ if (isset($s[2]) && $s[2]) $suffix = $s[2];
731
+ }
732
+ $pattern = '/<img.+?alt\s*=\s*[\'|\"](.*?)[\'|\"].+?>/i';
733
+ if (!preg_match_all($pattern, $content, $matches)) return '';
734
+ if (isset($s[0])) {
735
+ $i = $s[0];
736
+ }
737
+ if (isset($matches[1][$i])) {
738
+ return $matches[1][$i];
739
+ }
740
+ }
741
+
742
+ function otf_gravatar($option_key, $result, $ext) {
743
+ $size = 96;
744
+ $rating = '';
745
+ $default = "http://www.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=$size"; // ad516503a11cd5ca435acc9bb6523536 == md5('unknown@gravatar.com')
746
+ if ($ext) {
747
+ $s = explode(':', $ext);
748
+ if (isset($s[0])) $size = $s[0];
749
+ if (isset($s[1])) $rating = $s[1];
750
+ if (isset($s[3])) {
751
+ $default = 'http:'.$s[3];
752
+ } else {
753
+ if (isset($s[2])) $default = $s[2];
754
+ }
755
+ }
756
+ $email = '';
757
+ if (isset($result->comment_author_email)) {
758
+ $email = $result->comment_author_email;
759
+ } else {
760
+ $user = get_userdata($result->post_author);
761
+ if ($user) $email = $user->user_email;
762
+ }
763
+ if (!empty($email)) {
764
+ $out = 'http://www.gravatar.com/avatar/';
765
+ $out .= md5(strtolower($email));
766
+ $out .= '?s='.$size;
767
+ $out .= '&amp;d=' . urlencode( $default );
768
+ if ('' !== $rating)
769
+ $out .= "&amp;r={$rating}";
770
+ $avatar = "<img alt='' src='{$out}' class='avatar avatar-{$size}' height='{$size}' width='{$size}' />";
771
+ } else {
772
+ $avatar = "<img alt='' src='{$default}' class='avatar avatar-{$size} avatar-default' height='{$size}' width='{$size}' />";
773
+ }
774
+ return apply_filters('get_avatar', $avatar, $email, $size, $default);
775
+ }
776
+
777
+ // returns the principal category id of a post -- if a cats are hierarchical chooses the most specific -- if multiple cats chooses the first (numerically smallest)
778
+ function otf_categoryid($option_key, $result, $ext) {
779
+ $cats = get_the_category($result->ID);
780
+ foreach ($cats as $cat) {
781
+ $parents[] = $cat->category_parent;
782
+ }
783
+ foreach ($cats as $cat) {
784
+ if (!in_array($cat->cat_ID, $parents)) $categories[] = $cat->cat_ID;
785
+ }
786
+ return $categories[0];
787
+ }
788
+
789
+ // fails if parentheses are out of order or nested
790
+ function oth_splitapart($subject) {
791
+ $bits = explode(':', $subject);
792
+ $inside = false;
793
+ $newbits = array();
794
+ $acc = '';
795
+ foreach ($bits as $bit) {
796
+ if (false !== strpos($bit, '{')) {
797
+ $inside = true;
798
+ $acc = '';
799
+ }
800
+ if (false !== strpos($bit, '}')) {
801
+ $inside = false;
802
+ if ($acc !== '') {
803
+ $acc .= ':' . $bit;
804
+ } else {
805
+ $acc = $bit;
806
+ }
807
+ }
808
+ if ($inside) {
809
+ if ($acc !== '') {
810
+ $acc .= ':' . $bit;
811
+ } else {
812
+ $acc = $bit;
813
+ }
814
+ } else {
815
+ if ($acc !== '') {
816
+ $newbits[] = $acc;
817
+ $acc = '';
818
+ } else {
819
+ $newbits[] = $bit;
820
+ }
821
+ }
822
+ }
823
+ return $newbits;
824
+ }
825
+
826
+ function otf_if($option_key, $result, $ext) {
827
+ global $post;
828
+ $ID = ppl_current_post_id();
829
+ $condition = 'true';
830
+ $true = '';
831
+ $false = '';
832
+ if ($ext) {
833
+ $s = oth_splitapart($ext);
834
+ if (isset($s[0])) $condition = $s[0];
835
+ if (isset($s[1])) $true = $s[1];
836
+ if (isset($s[2])) $false = $s[2];
837
+ }
838
+ if (strpos($condition, '{')!==false) {
839
+ $condition = ppl_expand_template($result, $condition, ppl_prepare_template($condition), $option_key);
840
+ }
841
+ if (eval("return ($condition);")) $tag = $true; else $tag = $false;
842
+ // if the replacement tag contains pseudotags expand them
843
+ if (strpos($tag, '}')!==false) {
844
+ $tag = ppl_expand_template($result, $tag, ppl_prepare_template($tag), $option_key);
845
+ }
846
+ return $tag;
847
+ }
848
+
849
+ function otf_php($option_key, $result, $ext) {
850
+ global $post;
851
+ $ID = ppl_current_post_id();
852
+ $value = '';
853
+ if ($ext) {
854
+ if (strpos($ext, '{')!==false) {
855
+ $ext = ppl_expand_template($result, $ext, ppl_prepare_template($ext), $option_key);
856
+ }
857
+ ob_start();
858
+ eval($ext);
859
+ $value = ob_get_contents();
860
+ ob_end_clean();
861
+ }
862
+ return $value;
863
+ }
864
+
865
+
866
+ // ****************************** Helper Functions *********************************************
867
+
868
+ function oth_post_first_image($id) {
869
+ $first_img = '';
870
+ if ($id == NULL)
871
+ return false;
872
+ else {
873
+ $post = get_post($id);
874
+ $output = preg_match_all('/<img.*?src=[\'"](.*?)[\'"].*?>/i', $post->post_content, $matches);
875
+ if (isset($matches[1][0])) {
876
+ // Exclude base64 images; meta tags require full URLs
877
+ if (strpos($matches[1][0], 'data:') === false) {
878
+ $first_img = $matches[1][0];
879
+ }
880
+ } else {
881
+ return false;
882
+ }
883
+ return $first_img;
884
+ }
885
+ }
886
+
887
+ /**
888
+ * This function returns the URL of the featured image for a given post
889
+ *
890
+ * @return returns `false` or a string of the image src
891
+ */
892
+ function oth_post_featured_image($id, $size = "thumbnail") {
893
+ $featured_img = '';
894
+ if ($id == NULL)
895
+ return false;
896
+ else {
897
+ $post = get_post($id);
898
+ if (function_exists('has_post_thumbnail') && has_post_thumbnail($post->ID)) {
899
+ $thumbnail_shareaholic = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'thumbnail');
900
+ $thumbnail_full = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
901
+
902
+ if (($size == "thumbnail") && ($thumbnail_shareaholic[0] !== $thumbnail_full[0])) {
903
+ $featured_img = esc_attr($thumbnail_shareaholic[0]);
904
+ } else {
905
+ if ($size == "thumbnail") {
906
+ $thumbnail_large = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'large');
907
+ } else {
908
+ $thumbnail_large = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), $size);
909
+ }
910
+ $featured_img = esc_attr($thumbnail_large[0]);
911
+ }
912
+ } else {
913
+ return false;
914
+ }
915
+ }
916
+ return $featured_img;
917
+ }
918
+
919
+ function oth_truncate_text($text, $ext) {
920
+ if (!$ext) {
921
+ return $text;
922
+ }
923
+ $s = explode(':', $ext);
924
+ if (count($s) > 2) {
925
+ return $text;
926
+ }
927
+ if (count($s) == 1) {
928
+ $s[] = 'wrap';
929
+ }
930
+ $length = $s[0];
931
+ $type = $s[1];
932
+ switch ($type) {
933
+ case 'wrap':
934
+ $length += strlen('<br />');
935
+ if (!function_exists('mb_detect_encoding')) {
936
+ return wordwrap($text, $length, '<br />', true);
937
+ } else {
938
+ $e = mb_detect_encoding($text);
939
+ $formatted = '';
940
+ $position = -1;
941
+ $prev_position = 0;
942
+ $last_line = -1;
943
+ while($position = mb_strpos($text, " ", ++$position, $e)) {
944
+ if($position > $last_line + $length + 1) {
945
+ $formatted.= mb_substr($text, $last_line + 1, $prev_position - $last_line - 1, $e).'<br />';
946
+ $last_line = $prev_position;
947
+ }
948
+ $prev_position = $position;
949
+ }
950
+ $formatted.= mb_substr($text, $last_line + 1, mb_strlen( $text ), $e);
951
+ return $formatted;
952
+ }
953
+ case 'chop':
954
+ if (!function_exists('mb_detect_encoding')) {
955
+ return substr($text, 0, $length);
956
+ } else {
957
+ $e = mb_detect_encoding($text);
958
+ return mb_substr($text, 0, $length, $e);
959
+ }
960
+ case 'trim':
961
+ if (strlen($text) > $length) {
962
+ } else {
963
+ return $text;
964
+ }
965
+ if (!function_exists('mb_detect_encoding')) {
966
+ $textlen = strlen($text);
967
+ if ($textlen > $length) {
968
+ $text = substr($text, 0, $length-2);
969
+ return rtrim($text,".").'&hellip;';
970
+ } else {
971
+ return $text;
972
+ }
973
+ } else {
974
+ $e = mb_detect_encoding($text);
975
+ $textlen = mb_strlen($text, $e);
976
+ if ($textlen > $length) {
977
+ $text = mb_substr($text, 0, $length-2, $e);
978
+ return rtrim($text,".").'&hellip;';
979
+ } else {
980
+ return $text;
981
+ }
982
+ }
983
+ case 'snip':
984
+ if (!function_exists('mb_detect_encoding')) {
985
+ $textlen = strlen($text);
986
+ if ($textlen > $length) {
987
+ $b = floor(($length - 2)/2);
988
+ $l = $textlen - $b - 1;
989
+ return substr($text, 0, $b).'&hellip;'.substr($text, $l);
990
+ } else {
991
+ return $text;
992
+ }
993
+ } else {
994
+ $e = mb_detect_encoding($text);
995
+ $textlen = mb_strlen($text, $e);
996
+ if ($textlen > $length) {
997
+ $b = floor(($length - 2)/2);
998
+ $l = $textlen - $b - 1;
999
+ return mb_substr($text, 0, $b, $e).'&hellip;'.mb_substr($text, $l, 1000, $e);
1000
+ } else {
1001
+ return $text;
1002
+ }
1003
+ }
1004
+ default:
1005
+ return wordwrap($t, $length, '<br />', true);
1006
+ }
1007
+ }
1008
+
1009
+ function oth_trim_extract($text, $len, $more, $numsent) {
1010
+ $text = str_replace(']]>', ']]&gt;', $text);
1011
+ if(strpos($text, '<!--more-->')) {
1012
+ $parts = explode('<!--more-->', $text, 2);
1013
+ $text = $parts[0];
1014
+ } else {
1015
+ if ($len > count(preg_split('/[\s]+/', strip_tags($text), -1))) return $text;
1016
+ // remove html entities for now
1017
+ $text = str_replace("\x06", "", $text);
1018
+ preg_match_all("/&([a-z\d]{2,7}|#\d{2,5});/i", $text, $ents);
1019
+ $text = preg_replace("/&([a-z\d]{2,7}|#\d{2,5});/i", "\x06", $text);
1020
+ // now we start counting
1021
+ $parts = preg_split('/([\s]+)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
1022
+ $in_tag = false;
1023
+ $num_words = 0;
1024
+ $sentences = array();
1025
+ $words = '';
1026
+ foreach($parts as $part) {
1027
+ if(0 < preg_match('/<[^>]*$/s', $part)) {
1028
+ $in_tag = true;
1029
+ } else if(0 < preg_match('/>[^<]*$/s', $part)) {
1030
+ $in_tag = false;
1031
+ }
1032
+ if(!$in_tag && '' != trim($part) && substr($part, -1, 1) != '>') {
1033
+ $num_words++;
1034
+ }
1035
+ if(!$in_tag && '' != trim($part) && false !== strpos('.?!', substr($part, -1, 1))) {
1036
+ $sentences [] = $words . $part;
1037
+ $words = '';
1038
+ } else {
1039
+ $words .= $part;
1040
+ }
1041
+ if($num_words >= $len && !$in_tag) break;
1042
+ }
1043
+ if (!isset($numsent)) {
1044
+ $text = implode('', $sentences) . $words;
1045
+ } else {
1046
+ $numsent = abs($numsent);
1047
+ if ($numsent == 0) {
1048
+ $text = implode('', $sentences);
1049
+ } else {
1050
+ $text = implode('', array_slice($sentences, 0, $numsent));
1051
+ }
1052
+ }
1053
+ // put back the missing html entities
1054
+ foreach ($ents[0] as $ent) $text = preg_replace("/\x06/", $ent, $text, 1);
1055
+ }
1056
+ $text = balanceTags($text, true);
1057
+ $text = $text . $more;
1058
+ return $text;
1059
+ }
1060
+
1061
+ function oth_format_snippet($content, $option_key, $trim, $len, $more) {
1062
+ $content = strip_tags($content);
1063
+ $p = get_option($option_key);
1064
+ if ($p['stripcodes']) $content = oth_strip_special_tags($content, $p['stripcodes']);
1065
+ // strip extra whitespace
1066
+ $content = preg_replace('/\s+/u', ' ', $content);
1067
+ $content = stripslashes($content);
1068
+ if (function_exists('mb_detect_encoding')) $enc = mb_detect_encoding($content);
1069
+ // grab a maximum number of characters
1070
+ if ($enc) {
1071
+ mb_internal_encoding($enc);
1072
+ if (mb_strlen($content) >= $len) {
1073
+ $snippet = mb_substr($content, 0, $len);
1074
+ if ($trim == 'word' && mb_strlen($snippet) == $len) {
1075
+ // trim back to the last full word--NB if our snippet ends on a word
1076
+ // boundary we still have to trim back to the non-word character
1077
+ // (the final 's' in the pattern makes sure we match newlines)
1078
+ preg_match('/^(.*)\W/su', $snippet, $matches);
1079
+ //if we can't get a single full word we use the full snippet
1080
+ // (we use $matches[1] because we don't want the white-space)
1081
+ if ($matches[1]) $snippet = $matches[1];
1082
+ }
1083
+ $snippet .= $more;
1084
+ } else {
1085
+ $snippet = $content;
1086
+ }
1087
+ } else {
1088
+ if (strlen($content) >= $len) {
1089
+ $snippet = substr($content, 0, $len);
1090
+ if ($trim == 'word' && strlen($snippet) == $len) {
1091
+ // trim back to the last full word--NB if our snippet ends on a word
1092
+ // boundary we still have to trim back to the non-word character
1093
+ // (the final 's' in the pattern makes sure we match newlines)
1094
+ preg_match('/^(.*)\W/s', $snippet, $matches);
1095
+ //if we can't get a single full word we use the full snippet
1096
+ // (we use $matches[1] because we don't want the white-space)
1097
+ if ($matches[1]) $snippet = $matches[1];
1098
+ }
1099
+ $snippet .= $more;
1100
+ } else {
1101
+ $snippet = $content;
1102
+ }
1103
+ }
1104
+ return $snippet;
1105
+ }
1106
+
1107
+ function oth_strip_special_tags($text, $stripcodes) {
1108
+ $numtags = count($stripcodes);
1109
+ for ($i = 0; $i < $numtags; $i++) {
1110
+ if (!$stripcodes[$i]['start'] || !$stripcodes[$i]['end']) return $text;
1111
+ $pattern = '/('. oth_regescape($stripcodes[$i]['start']) . '(.*?)' . oth_regescape($stripcodes[$i]['end']) . ')/i';
1112
+ $text = preg_replace($pattern, '', $text);
1113
+ }
1114
+ return $text;
1115
+ }
1116
+
1117
+ function oth_trim_excerpt($content, $len) {
1118
+ // taken from the wp_trim_excerpt filter
1119
+ remove_filter( 'the_content', 'ppl_content_filter', 5 );
1120
+ remove_filter( 'the_content', 'ppl_post_filter', 5 );
1121
+ $text = apply_filters('the_content', $content);
1122
+ add_filter( 'the_content', 'ppl_content_filter', 5 );
1123
+ add_filter( 'the_content', 'ppl_post_filter', 5 );
1124
+ $text = str_replace(']]>', ']]&gt;', $text);
1125
+ $text = strip_tags($text);
1126
+ if (!$len) $len = 55;
1127
+ $excerpt_length = $len;
1128
+ $words = explode(' ', $text, $excerpt_length + 1);
1129
+ if (count($words) > $excerpt_length) {
1130
+ array_pop($words);
1131
+ $text = implode(' ', $words);
1132
+ }
1133
+ $text = convert_smilies($text);
1134
+ return $text;
1135
+ }
1136
+
1137
+ function oth_trim_comment_excerpt($content, $len) {
1138
+ // adapted from the wp_trim_excerpt filter
1139
+ $text = $content;
1140
+ $text = apply_filters('get_comment_text', $text);
1141
+ $text = str_replace(']]>', ']]&gt;', $text);
1142
+ $text = strip_tags($text);
1143
+ if (!$len) $len = 55;
1144
+ $excerpt_length = $len;
1145
+ $words = explode(' ', $text, $excerpt_length + 1);
1146
+ if (count($words) > $excerpt_length) {
1147
+ array_pop($words);
1148
+ $text = implode(' ', $words);
1149
+ }
1150
+ $text = convert_smilies($text);
1151
+ return $text;
1152
+ }
1153
+
1154
+ function oth_format_date($date, $fmt) {
1155
+ if (!$fmt) $fmt = get_option('date_format');
1156
+ $d = mysql2date($fmt, $date);
1157
+ $d = apply_filters('get_the_time', $d, $fmt);
1158
+ return apply_filters('the_time', $d, $fmt);
1159
+ }
1160
+
1161
+ function oth_format_time($time, $fmt) {
1162
+ if (!$fmt) $fmt = get_option('time_format');
1163
+ $d = mysql2date($fmt, $time);
1164
+ $d = apply_filters('get_the_time', $d, $fmt);
1165
+ return apply_filters('the_time', $d, $fmt);
1166
+ }
1167
+
1168
+ function oth_regescape($s) {
1169
+ $s = str_replace('\\', '\\\\', $s);
1170
+ $s = str_replace('/', '\\/', $s);
1171
+ $s = str_replace('[', '\\[', $s);
1172
+ $s = str_replace(']', '\\]', $s);
1173
+ return $s;
1174
+ }
readme.txt CHANGED
@@ -1,250 +1,256 @@
1
- === Similar Posts - Best Related Posts Plugin for WordPress ===
2
- Contributors: shareaholic
3
- Tags: related posts, similar posts, connected posts, related posts widget, linked posts
4
- Requires at least: 4.0
5
- Tested up to: 5.8
6
- Requires PHP: 5.2
7
- Stable tag: 3.1.5
8
-
9
- 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!
10
-
11
-
12
- == Description ==
13
-
14
- Similar Posts displays a list of posts that are similar or related to the current posts. The list can be customised in **many ways**. Similarity is judged according to a post's title, content, and tags and you can adjust the balance of factors to fit your own site.
15
-
16
- **Few Notable Options**
17
-
18
- * complete control over the display & layout of displayed posts
19
- * over 30 tags for display template customization
20
- * matching of current post's category, tags, content and author
21
- * post excluding by author, ID, category, tags and custom fields
22
- * output in posts, widgets and RSS
23
- * over 50 options available
24
-
25
- If you need a plugin that does all the Related Posts compute processing in the cloud, please check out our other [Related Posts & Products WordPress plugin](https://shrlc.com/yPInQlI).
26
-
27
- [Shareaholic Blog](https://www.shareaholic.com/blog) | [Privacy](https://www.shareaholic.com/privacy/) | [Terms](https://www.shareaholic.com/terms/)
28
-
29
- == Installation ==
30
-
31
- Follow the usual routine;
32
-
33
- 1. Open WordPress admin, go to Plugins, click Add New
34
- 2. Enter "Similar Posts" in search and hit Enter
35
- 3. Plugin will show up as the first on the list, click "Install Now"
36
- 4. Activate & go to Settings - Similar Posts to configure
37
-
38
- Or if needed, upload manually;
39
-
40
- 1. Download the plugin.
41
- 2. Unzip it and upload to _wp-content/plugin/_
42
- 3. Open WordPress admin - Plugins and click "Activate" next to the plugin
43
- 4. Activate & go to Settings - Similar Posts to configure
44
-
45
-
46
- == Frequently Asked Questions ==
47
-
48
- = Who is this plugin for? =
49
-
50
- For anyone who want to keep visitors longer on their site by giving them more quality, related content when and where they need it - below the article they're currently reading.
51
-
52
- = It's not working!!! Arrrrrrrrr =
53
-
54
- Read the <a href="https://wordpress.org/support/plugin/similar-posts/">support forum</a> rules (no seriously, read them) and then if needed open new a thread.
55
-
56
-
57
- == Screenshots ==
58
-
59
- 1. General options screen
60
- 2. Output options screen
61
- 3. Filter options screen
62
- 4. Placement options screen
63
- 5. Miscellaneous options screen
64
- 6. Index options secreen
65
-
66
-
67
- == ChangeLog ==
68
- = 3.1.5 (20-JULY-2021) =
69
- * Support for WordPress 5.8+
70
- * Fixed compatibility issues with PHP 7.4
71
-
72
- = 3.1.4 (15-MARCH-2021) =
73
- * Support for WordPress 5.7+
74
-
75
- = 3.1.3 (07-April-2020) =
76
- * Support for WordPress 5.4+
77
-
78
- = 3.1.2 (06-November-2019) =
79
- * Support for WordPress 5.3+
80
-
81
- = 3.1.1 (02-May-2019) =
82
- * Support for WordPress 5.2
83
-
84
- = 3.1.0 (16-February-2019) =
85
- * Fixed compatibility issues with PHP 7.2
86
- * Addressed PHP warnings
87
- * Algorithm updated to prefer newer posts over older ones
88
- * General admin panel cleanup
89
-
90
- = 3.0.2 (15-February-2019) =
91
- * Support for WordPress 5.1
92
-
93
- = 3.0.1 (06-December-2018) =
94
- * Support for WordPress WordPress 5.0
95
-
96
- = 3.0.0 (03-May-2018) =
97
- * Minor update
98
-
99
- = 2.8.1 (03-May-2018) =
100
- * Minor update
101
-
102
- = 2.8 (03-May-2018) =
103
- * Minor update
104
-
105
- = 2.75 (27-July-2017) =
106
- * Minor update
107
-
108
- = 2.71 (02-April-2017) =
109
- * Minor update
110
-
111
- = 2.71 (13-September-2016) =
112
- * no longer requires any additional plugins
113
- * fixed all notices and errors
114
- * fully compatible with the latest version of WP
115
-
116
- = 2.6.2.0 =
117
- * fixed a problem with the stemming algorithm and overused words
118
- * introduced a first stab at fuzzy matching
119
- * new {imagealt} output tag -- rather like {imagesrc}
120
- * {excerpt} can now trim to whole sentences
121
- * content filter can now take parameter string
122
- * widget can now take parameter string
123
- * output can be appended to posts & feeds
124
-
125
- = 2.6.1.3 =
126
- * fix - german language stemmer was crashing if mb_string fucntions not available
127
-
128
- = 2.6.1.2 =
129
- * fix - german language stemmer file now in utf8
130
-
131
- = 2.6.1.1 =
132
- * fix to italian language stemmer for PHP4
133
-
134
- = 2.6.1.0 =
135
- * the current post can be marked manually
136
- * widgets now honour the option to show no output if list is empty
137
- * fixed a bug with finding the right language files
138
-
139
- = 2.6.0.1 =
140
- * bug fix: installation code was failing on some systems
141
-
142
- = 2.6.0.0 =
143
- * version bump to indicate compatibility with WP 2.6
144
- * fix to really include attachments
145
- * new parameter for {imagesrc} to append a suffix to the image name, e.g. to get the thumbnail for attachments
146
-
147
- = 2.5.0.11 =
148
- * new option to include attachments
149
- * {php} tag now accepts nested tags
150
- * new output tag {authorurl} -- permalink to archive of author's posts
151
- * fix for numeric locale issue
152
-
153
- = 2.5.0.10 =
154
- * new option to select algorithm for term extraction
155
- * new manual links option
156
- * fix for page selection in old versions of WP
157
- * fix for faulty tags in Cyrillic
158
-
159
- = 2.5.0.9 =
160
- * new option to match the current post's author
161
- * extended options for snippet and excerpt output tags
162
-
163
- = 2.5.0.7 =
164
- * new option to show by status, i.e., published/private/draft/future
165
- * {categorynames} and {categorylinks} apply 'single_cat_name' filter
166
- * fixes bug in WP pre-2.2 causing installation to fail
167
-
168
- = 2.5.0 =
169
- * CJK digrams
170
- * {image} has new post, link, and default parameters
171
- * new {imagesrc} tag
172
- * fix to empty category bug
173
- * excluded posts bug fix
174
- * fix for intermittent bug with 'omit current post' option
175
-
176
- = 2.5b28 =
177
- * improvements to Similar Posts matching
178
- * experiment with Chinese/Korean/Japanese matching
179
-
180
- = 2.5b27 =
181
- * fixed bug with bulk indexing of tags
182
-
183
- = 2.5b26 =
184
- * reverted thumbnail serving (speed)
185
- * fix current post after extra query
186
-
187
- = 2.5b25 =
188
- * option to sort output, group templates
189
- * removed 'trim_before' option added more logical 'divider'
190
- * {date:raw}, {commentdate:raw}, etc.
191
- * fix for {image} resizing when <img > and not <img />
192
- * {image} now serves real thumbnails
193
-
194
- = 2.5b24 =
195
- * fix for recursive replacement by content filter
196
- * fix to {gravatar} to allow for 'identicon' etc.
197
- * fix to {commenter} to allow trimming
198
- * fix a warning in safe mode
199
- * fix for unsanitised WP tags
200
-
201
- = 2.5b23 =
202
- * new option to filter on custom fields
203
- * nested braces in {if}; condition now taggable
204
- * improved bug report feature
205
- * better way to omit user comments
206
-
207
- = 2.5b22 =
208
- * restored automatic indexing on installation
209
- * moved indexing menu under settings
210
- * show_pages option can now show only pages
211
- * fix for upgraders who had utf8 selected but no mbstring
212
-
213
- = 2.5b20 =
214
- * optimised indexing for speed and memory use
215
-
216
- = 2.5b19 =
217
- * fixing some extended character issues
218
-
219
- = 2.5b18 =
220
- * fix output filter bug
221
- * add conditional tag {if:condition:yes:no}
222
-
223
- = 2.5b16 =
224
- * fix for {php}
225
-
226
- = 2.5b15 =
227
- * fix more or less obscure bugs, add 'include posts' setting
228
-
229
- = 2.5b14 =
230
- * fix file-encoding, installation error, etc.
231
-
232
- = 2.5b12 =
233
- * fix serious bug for WP < 2.3
234
-
235
- = 2.5b11 =
236
- * some widget fixes
237
-
238
- = 2.5b10 =
239
- * fix for non-creation of table
240
-
241
- = 2.5b9 =
242
- * clarifying installation instructions
243
-
244
-
245
- == Upgrade Notice ==
246
-
247
- = 3.1.5 =
248
- We update this plugin regularly so we can make it better for you. Update to the latest version for all of the available features and improvements. Thanks for using Shareaholic!
249
-
250
- The plugin **no longer requires** the latest version of the Post-Plugin Library. If you are upgrading from a version older than v2.6.2.0 first deactivate the plugin, then delete the plugin folder from your server. If you have the Similar Posts Feed plugin installed you must deactivate it before installing Similar Posts (which now does the same job).
 
 
 
 
 
 
1
+ === Similar Posts - Best Related Posts Plugin for WordPress ===
2
+ Contributors: shareaholic
3
+ Tags: related posts, similar posts, connected posts, related posts widget, linked posts
4
+ Requires at least: 4.0
5
+ Tested up to: 5.9
6
+ Requires PHP: 5.2
7
+ Stable tag: 3.1.6
8
+
9
+ 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!
10
+
11
+
12
+ == Description ==
13
+
14
+ Similar Posts displays a list of posts that are similar or related to the current posts. The list can be customised in **many ways**. Similarity is judged according to a post's title, content, and tags and you can adjust the balance of factors to fit your own site.
15
+
16
+ **Few Notable Options**
17
+
18
+ * complete control over the display & layout of displayed posts
19
+ * over 30 tags for display template customization
20
+ * matching of current post's category, tags, content and author
21
+ * post excluding by author, ID, category, tags and custom fields
22
+ * output in posts, widgets and RSS
23
+ * over 50 options available
24
+
25
+ If you need a plugin that does all the Related Posts compute processing in the cloud, please check out our other [Related Posts & Products WordPress plugin](https://shrlc.com/yPInQlI).
26
+
27
+ [Shareaholic Blog](https://www.shareaholic.com/blog) | [Privacy](https://www.shareaholic.com/privacy/) | [Terms](https://www.shareaholic.com/terms/)
28
+
29
+ == Installation ==
30
+
31
+ Follow the usual routine;
32
+
33
+ 1. Open WordPress admin, go to Plugins, click Add New
34
+ 2. Enter "Similar Posts" in search and hit Enter
35
+ 3. Plugin will show up as the first on the list, click "Install Now"
36
+ 4. Activate & go to Settings - Similar Posts to configure
37
+
38
+ Or if needed, upload manually;
39
+
40
+ 1. Download the plugin.
41
+ 2. Unzip it and upload to _wp-content/plugin/_
42
+ 3. Open WordPress admin - Plugins and click "Activate" next to the plugin
43
+ 4. Activate & go to Settings - Similar Posts to configure
44
+
45
+
46
+ == Frequently Asked Questions ==
47
+
48
+ = Who is this plugin for? =
49
+
50
+ For anyone who want to keep visitors longer on their site by giving them more quality, related content when and where they need it - below the article they're currently reading.
51
+
52
+ = It's not working!!! Arrrrrrrrr =
53
+
54
+ Read the <a href="https://wordpress.org/support/plugin/similar-posts/">support forum</a> rules (no seriously, read them) and then if needed open new a thread.
55
+
56
+
57
+ == Screenshots ==
58
+
59
+ 1. General options screen
60
+ 2. Output options screen
61
+ 3. Filter options screen
62
+ 4. Placement options screen
63
+ 5. Miscellaneous options screen
64
+ 6. Index options secreen
65
+
66
+
67
+ == ChangeLog ==
68
+ = 3.1.6 (13-October-2021) =
69
+ * To use WP Template Conditionals in Similar Posts widget settings or Admin:
70
+ + Require `manage_options` and `unfiltered_html` user capability. Note: In WordPress Multisite, only Super Admins have the `unfiltered_html` capability.
71
+ + Check whether file editing is allowed per `DISALLOW_FILE_EDIT` constant
72
+ * Show educational warning before allowing use of WP Template Conditionals
73
+
74
+ = 3.1.5 (20-JULY-2021) =
75
+ * Support for WordPress 5.8+
76
+ * Fixed compatibility issues with PHP 7.4
77
+
78
+ = 3.1.4 (15-MARCH-2021) =
79
+ * Support for WordPress 5.7+
80
+
81
+ = 3.1.3 (07-April-2020) =
82
+ * Support for WordPress 5.4+
83
+
84
+ = 3.1.2 (06-November-2019) =
85
+ * Support for WordPress 5.3+
86
+
87
+ = 3.1.1 (02-May-2019) =
88
+ * Support for WordPress 5.2
89
+
90
+ = 3.1.0 (16-February-2019) =
91
+ * Fixed compatibility issues with PHP 7.2
92
+ * Addressed PHP warnings
93
+ * Algorithm updated to prefer newer posts over older ones
94
+ * General admin panel cleanup
95
+
96
+ = 3.0.2 (15-February-2019) =
97
+ * Support for WordPress 5.1
98
+
99
+ = 3.0.1 (06-December-2018) =
100
+ * Support for WordPress WordPress 5.0
101
+
102
+ = 3.0.0 (03-May-2018) =
103
+ * Minor update
104
+
105
+ = 2.8.1 (03-May-2018) =
106
+ * Minor update
107
+
108
+ = 2.8 (03-May-2018) =
109
+ * Minor update
110
+
111
+ = 2.75 (27-July-2017) =
112
+ * Minor update
113
+
114
+ = 2.71 (02-April-2017) =
115
+ * Minor update
116
+
117
+ = 2.71 (13-September-2016) =
118
+ * no longer requires any additional plugins
119
+ * fixed all notices and errors
120
+ * fully compatible with the latest version of WP
121
+
122
+ = 2.6.2.0 =
123
+ * fixed a problem with the stemming algorithm and overused words
124
+ * introduced a first stab at fuzzy matching
125
+ * new {imagealt} output tag -- rather like {imagesrc}
126
+ * {excerpt} can now trim to whole sentences
127
+ * content filter can now take parameter string
128
+ * widget can now take parameter string
129
+ * output can be appended to posts & feeds
130
+
131
+ = 2.6.1.3 =
132
+ * fix - german language stemmer was crashing if mb_string fucntions not available
133
+
134
+ = 2.6.1.2 =
135
+ * fix - german language stemmer file now in utf8
136
+
137
+ = 2.6.1.1 =
138
+ * fix to italian language stemmer for PHP4
139
+
140
+ = 2.6.1.0 =
141
+ * the current post can be marked manually
142
+ * widgets now honour the option to show no output if list is empty
143
+ * fixed a bug with finding the right language files
144
+
145
+ = 2.6.0.1 =
146
+ * bug fix: installation code was failing on some systems
147
+
148
+ = 2.6.0.0 =
149
+ * version bump to indicate compatibility with WP 2.6
150
+ * fix to really include attachments
151
+ * new parameter for {imagesrc} to append a suffix to the image name, e.g. to get the thumbnail for attachments
152
+
153
+ = 2.5.0.11 =
154
+ * new option to include attachments
155
+ * {php} tag now accepts nested tags
156
+ * new output tag {authorurl} -- permalink to archive of author's posts
157
+ * fix for numeric locale issue
158
+
159
+ = 2.5.0.10 =
160
+ * new option to select algorithm for term extraction
161
+ * new manual links option
162
+ * fix for page selection in old versions of WP
163
+ * fix for faulty tags in Cyrillic
164
+
165
+ = 2.5.0.9 =
166
+ * new option to match the current post's author
167
+ * extended options for snippet and excerpt output tags
168
+
169
+ = 2.5.0.7 =
170
+ * new option to show by status, i.e., published/private/draft/future
171
+ * {categorynames} and {categorylinks} apply 'single_cat_name' filter
172
+ * fixes bug in WP pre-2.2 causing installation to fail
173
+
174
+ = 2.5.0 =
175
+ * CJK digrams
176
+ * {image} has new post, link, and default parameters
177
+ * new {imagesrc} tag
178
+ * fix to empty category bug
179
+ * excluded posts bug fix
180
+ * fix for intermittent bug with 'omit current post' option
181
+
182
+ = 2.5b28 =
183
+ * improvements to Similar Posts matching
184
+ * experiment with Chinese/Korean/Japanese matching
185
+
186
+ = 2.5b27 =
187
+ * fixed bug with bulk indexing of tags
188
+
189
+ = 2.5b26 =
190
+ * reverted thumbnail serving (speed)
191
+ * fix current post after extra query
192
+
193
+ = 2.5b25 =
194
+ * option to sort output, group templates
195
+ * removed 'trim_before' option added more logical 'divider'
196
+ * {date:raw}, {commentdate:raw}, etc.
197
+ * fix for {image} resizing when <img > and not <img />
198
+ * {image} now serves real thumbnails
199
+
200
+ = 2.5b24 =
201
+ * fix for recursive replacement by content filter
202
+ * fix to {gravatar} to allow for 'identicon' etc.
203
+ * fix to {commenter} to allow trimming
204
+ * fix a warning in safe mode
205
+ * fix for unsanitised WP tags
206
+
207
+ = 2.5b23 =
208
+ * new option to filter on custom fields
209
+ * nested braces in {if}; condition now taggable
210
+ * improved bug report feature
211
+ * better way to omit user comments
212
+
213
+ = 2.5b22 =
214
+ * restored automatic indexing on installation
215
+ * moved indexing menu under settings
216
+ * show_pages option can now show only pages
217
+ * fix for upgraders who had utf8 selected but no mbstring
218
+
219
+ = 2.5b20 =
220
+ * optimised indexing for speed and memory use
221
+
222
+ = 2.5b19 =
223
+ * fixing some extended character issues
224
+
225
+ = 2.5b18 =
226
+ * fix output filter bug
227
+ * add conditional tag {if:condition:yes:no}
228
+
229
+ = 2.5b16 =
230
+ * fix for {php}
231
+
232
+ = 2.5b15 =
233
+ * fix more or less obscure bugs, add 'include posts' setting
234
+
235
+ = 2.5b14 =
236
+ * fix file-encoding, installation error, etc.
237
+
238
+ = 2.5b12 =
239
+ * fix serious bug for WP < 2.3
240
+
241
+ = 2.5b11 =
242
+ * some widget fixes
243
+
244
+ = 2.5b10 =
245
+ * fix for non-creation of table
246
+
247
+ = 2.5b9 =
248
+ * clarifying installation instructions
249
+
250
+
251
+ == Upgrade Notice ==
252
+
253
+ = 3.1.6 =
254
+ We update this plugin regularly so we can make it better for you. Update to the latest version for all of the available features and improvements. Thank you for using the Similar Posts plugin!
255
+
256
+ The plugin **no longer requires** the latest version of the Post-Plugin Library. If you are upgrading from a version older than v2.6.2.0 first deactivate the plugin, then delete the plugin folder from your server. If you have the Similar Posts Feed plugin installed you must deactivate it before installing Similar Posts (which now does the same job).
similar-posts-admin.php CHANGED
@@ -1,721 +1,765 @@
1
- <?php
2
-
3
- // Admin stuff for Similar Posts Plugin, Version 2.6.2.0
4
-
5
- function similar_posts_option_menu() {
6
- add_options_page(__('Similar Posts Options', 'similar_posts'), __('Similar Posts', 'similar_posts'), 'edit_theme_options', 'similar-posts', 'similar_posts_options_page');
7
- }
8
-
9
- add_action('admin_menu', 'similar_posts_option_menu', 1);
10
-
11
- function similar_posts_for_feed_option_menu() {
12
- add_options_page(__('Similar Posts Feed Options', 'similar_posts'), __('Similar Posts Feed', 'similar_posts'), 'edit_theme_options', 'similar-posts-feed', 'similar_posts_for_feed_options_page');
13
- }
14
-
15
- // this sneaky piece of work lets the similar posts feed menu appear and disappear
16
- function juggle_similar_posts_menus() {
17
- if (isset($_POST['feed_active'])) {
18
- $active = ($_POST['feed_active'] === 'true');
19
- } else {
20
- $options = get_option('similar-posts');
21
- $active = ($options['feed_active'] === 'true');
22
- }
23
- if ($active) {
24
- add_action('admin_menu', 'similar_posts_for_feed_option_menu', 2);
25
- } else {
26
- remove_action('admin_menu', 'similar_posts_for_feed_option_menu');
27
- }
28
- }
29
-
30
- add_action('plugins_loaded', 'juggle_similar_posts_menus');
31
-
32
- function similar_posts_options_page(){
33
- echo '<div class="wrap"><h2>';
34
- _e('Similar Posts ', 'similar_posts');
35
- echo '</h2></div>';
36
-
37
-
38
- $m = new admin_subpages();
39
- $m->add_subpage('General', 'general', 'similar_posts_general_options_subpage');
40
- $m->add_subpage('Output', 'output', 'similar_posts_output_options_subpage');
41
- $m->add_subpage('Filter', 'filter', 'similar_posts_filter_options_subpage');
42
- $m->add_subpage('Placement', 'placement', 'similar_posts_placement_options_subpage');
43
- $m->add_subpage('Misc', 'other', 'similar_posts_other_options_subpage');
44
- $m->add_subpage('Manage the Index', 'index', 'similar_posts_index_options_subpage');
45
- $m->display();
46
-
47
- //echo '<div class="wrap"><a target="_blank" href="http://rmarsh.com/plugins/post-options/">';
48
- //_e('Detailed help &amp; instructions');
49
- //echo '</a></div>';
50
-
51
- add_action('in_admin_footer', 'similar_posts_admin_footer');
52
- }
53
-
54
- function similar_posts_admin_footer() {
55
- ppl_admin_footer(str_replace('-admin', '', __FILE__), "similar-posts");
56
-
57
- }
58
-
59
- function similar_posts_general_options_subpage(){
60
- global $wpdb, $wp_version;
61
- $options = get_option('similar-posts');
62
- if (isset($_POST['update_options'])) {
63
- check_admin_referer('similar-posts-update-options');
64
- if (defined('POC_CACHE_4')) poc_cache_flush();
65
- // Fill up the options with the values chosen...
66
- $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'));
67
- update_option('similar-posts', $options);
68
- // Show a message to say we've done something
69
- echo '<div class="updated settings-error notice"><p>' . __('<b>Settings saved.</b>', 'similar_posts') . '</p></div>';
70
- }
71
- //now we drop into html to display the option page form
72
- ?>
73
- <div class="wrap similarposts-tab-content">
74
-
75
- <form method="post" action="">
76
-
77
- <table class="optiontable form-table">
78
- <?php
79
- ppl_display_limit($options['limit']);
80
- ppl_display_skip($options['skip']);
81
- ppl_display_show_private($options['show_private']);
82
- ppl_display_show_pages($options['show_pages']);
83
- ppl_display_show_attachments($options['show_attachments']);
84
- ppl_display_status($options['status']);
85
- ppl_display_age($options['age']);
86
- ppl_display_omit_current_post($options['omit_current_post']);
87
- ppl_display_match_cat($options['match_cat']);
88
- ppl_display_match_tags($options['match_tags']);
89
- ppl_display_match_author($options['match_author']);
90
- ?>
91
- </table>
92
- <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Settings', 'similar_posts') ?>" /></div>
93
- <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-update-options'); ?>
94
- </form>
95
- </div>
96
- <?php
97
- }
98
-
99
- function similar_posts_output_options_subpage(){
100
- global $wpdb, $wp_version;
101
- $options = get_option('similar-posts');
102
- if (isset($_POST['update_options'])) {
103
- check_admin_referer('similar-posts-update-options');
104
- if (defined('POC_CACHE_4')) poc_cache_flush();
105
- // Fill up the options with the values chosen...
106
- $options = ppl_options_from_post($options, array('output_template', 'prefix', 'suffix', 'none_text', 'no_text', 'divider', 'sort', 'group_template'));
107
- update_option('similar-posts', $options);
108
- // Show a message to say we've done something
109
- echo '<div class="updated settings-error notice"><p>' . __('<b>Settings saved.</b>', 'similar_posts') . '</p></div>';
110
- }
111
- //now we drop into html to display the option page form
112
- ?>
113
- <div class="wrap similarposts-tab-content">
114
-
115
- <form method="post" action="">
116
-
117
- <table class="optiontable form-table">
118
- <tr>
119
- <td style="padding-top: 0; vertical-align: top;">
120
- <table>
121
- <?php
122
- ppl_display_output_template($options['output_template']);
123
- ppl_display_prefix($options['prefix']);
124
- ppl_display_suffix($options['suffix']);
125
- ppl_display_none_text($options['none_text']);
126
- ppl_display_no_text($options['no_text']);
127
- ppl_display_divider($options['divider']);
128
- ppl_display_sort($options['sort']);
129
- ppl_display_group_template($options['group_template']);
130
- ?>
131
- </table>
132
- </td>
133
- <td>
134
- <?php ppl_display_available_tags('similar-posts'); ?>
135
- </td></tr>
136
- </table>
137
- <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Settings', 'similar_posts') ?>" /></div>
138
- <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-update-options'); ?>
139
- </form>
140
- </div>
141
- <?php
142
- }
143
-
144
- function similar_posts_filter_options_subpage(){
145
- global $wpdb, $wp_version;
146
- $options = get_option('similar-posts');
147
- if (isset($_POST['update_options'])) {
148
- check_admin_referer('similar-posts-update-options');
149
- if (defined('POC_CACHE_4')) poc_cache_flush();
150
- // Fill up the options with the values chosen...
151
- $options = ppl_options_from_post($options, array('excluded_posts', 'included_posts', 'excluded_authors', 'included_authors', 'excluded_cats', 'included_cats', 'tag_str', 'custom'));
152
- update_option('similar-posts', $options);
153
- // Show a message to say we've done something
154
- echo '<div class="updated settings-error notice"><p>' . __('<b>Settings saved.</b>', 'similar_posts') . '</p></div>';
155
- }
156
- //now we drop into html to display the option page form
157
- ?>
158
- <div class="wrap similarposts-tab-content">
159
-
160
- <form method="post" action="">
161
-
162
- <table class="optiontable form-table">
163
- <?php
164
- ppl_display_excluded_posts($options['excluded_posts']);
165
- ppl_display_included_posts($options['included_posts']);
166
- ppl_display_authors($options['excluded_authors'], $options['included_authors']);
167
- ppl_display_cats($options['excluded_cats'], $options['included_cats']);
168
- ppl_display_tag_str($options['tag_str']);
169
- ppl_display_custom($options['custom']);
170
- ?>
171
- </table>
172
- <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Settings', 'similar_posts') ?>" /></div>
173
- <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-update-options'); ?>
174
- </form>
175
- </div>
176
- <?php
177
- }
178
-
179
- function similar_posts_placement_options_subpage(){
180
- global $wpdb, $wp_version;
181
- $options = get_option('similar-posts');
182
- if (isset($_POST['update_options'])) {
183
- check_admin_referer('similar-posts-update-options');
184
- if (defined('POC_CACHE_4')) poc_cache_flush();
185
- // Fill up the options with the values chosen...
186
- $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'));
187
- update_option('similar-posts', $options);
188
- // Show a message to say we've done something
189
- echo '<div class="updated settings-error notice"><p>' . __('<b>Settings saved.</b>', 'similar_posts') . '</p></div>';
190
- }
191
- //now we drop into html to display the option page form
192
- ?>
193
- <div class="wrap similarposts-tab-content">
194
-
195
- <form method="post" action="">
196
-
197
- <table class="optiontable form-table">
198
- <?php
199
- ppl_display_append($options);
200
- ppl_display_feed($options);
201
- ppl_display_widget($options);
202
- ppl_display_content_filter($options['content_filter']);
203
- ?>
204
- </table>
205
- <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Settings', 'similar_posts') ?>" /></div>
206
- <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-update-options'); ?>
207
- </form>
208
- </div>
209
- <?php
210
- }
211
-
212
- function similar_posts_other_options_subpage(){
213
- global $wpdb, $wp_version;
214
- $options = get_option('similar-posts');
215
- if (isset($_POST['update_options'])) {
216
- check_admin_referer('similar-posts-update-options');
217
- if (defined('POC_CACHE_4')) poc_cache_flush();
218
- // Fill up the options with the values chosen...
219
- $options = ppl_options_from_post($options, array('stripcodes', 'feed_active', 'term_extraction', 'num_terms', 'weight_title', 'weight_content', 'weight_tags', 'hand_links'));
220
- $wcontent = $options['weight_content'] + 0.0001;
221
- $wtitle = $options['weight_title'] + 0.0001;
222
- $wtags = $options['weight_tags'] + 0.0001;
223
- $wcombined = $wcontent + $wtitle + $wtags;
224
- $options['weight_content'] = $wcontent / $wcombined;
225
- $options['weight_title'] = $wtitle / $wcombined;
226
- $options['weight_tags'] = $wtags / $wcombined;
227
- update_option('similar-posts', $options);
228
- // Show a message to say we've done something
229
- echo '<div class="updated settings-error notice"><p>' . __('<b>Settings saved.</b>', 'similar_posts') . '</p></div>';
230
- }
231
- //now we drop into html to display the option page form
232
- ?>
233
- <div class="wrap similarposts-tab-content">
234
-
235
- <form method="post" action="">
236
-
237
- <table class="optiontable form-table">
238
- <?php
239
- ppl_display_weights($options);
240
- ppl_display_num_terms($options['num_terms']);
241
- ppl_display_term_extraction($options['term_extraction']);
242
- ppl_display_hand_links($options['hand_links']);
243
- ppl_display_feed_active($options['feed_active']);
244
- ppl_display_stripcodes($options['stripcodes']);
245
- ?>
246
- </table>
247
- <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Settings', 'similar_posts') ?>" /></div>
248
- <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-update-options'); ?>
249
- </form>
250
- </div>
251
- <?php
252
- }
253
-
254
- function similar_posts_index_options_subpage(){
255
- if (isset($_POST['reindex_all'])) {
256
- check_admin_referer('similar-posts-manage-update-options');
257
- if (defined('POC_CACHE_4')) poc_cache_flush();
258
- $options = get_option('similar-posts');
259
- $options['utf8'] = $_POST['utf8'];
260
- if (!function_exists('mb_split')) {
261
- $options['utf8'] = 'false';
262
- }
263
- $options['cjk'] = $_POST['cjk'];
264
- if (!function_exists('mb_internal_encoding')) {
265
- $options['cjk'] = 'false';
266
- }
267
- if ($options['cjk'] === 'true') $options['utf8'] = 'true';
268
- $options['use_stemmer'] = $_POST['use_stemmer'];
269
- $options['batch'] = ppl_check_cardinal($_POST['batch']);
270
- if ($options['batch'] === 0) $options['batch'] = 100;
271
- flush();
272
- $termcount = save_index_entries (($options['utf8']==='true'), $options['use_stemmer'], $options['batch'], ($options['cjk']==='true'));
273
- update_option('similar-posts', $options);
274
- //show a message
275
- printf('<div class="updated fade"><p>'.__('Indexed %d posts.').'</p></div>', $termcount);
276
- } else {
277
- $options = get_option('similar-posts');
278
- }
279
- ?>
280
- <div class="wrap similarposts-tab-content">
281
- <?php
282
- 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>';
283
- echo '<p>'.__('The options that affect the index can be set below.', 'similar_posts').'</p>';
284
- 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>';
285
- 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>';
286
- 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>';
287
- 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>';
288
- 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>';
289
- ?>
290
- <form method="post" action="">
291
- <table class="optiontable form-table">
292
- <tr valign="top">
293
- <th scope="row"><label for="utf8"><?php _e('Handle extended characters?', 'similar_posts') ?></label></th>
294
- <td>
295
- <select name="utf8" id="utf8" <?php if (!function_exists('mb_split')) echo 'disabled="true"'; ?> >
296
- <option <?php if($options['utf8'] == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
297
- <option <?php if($options['utf8'] == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
298
- </select>
299
- </td>
300
- </tr>
301
- <tr valign="top">
302
- <th scope="row"><label for="cjk"><?php _e('Treat as Chinese, Korean, or Japanese?', 'similar_posts') ?></label></th>
303
- <td>
304
- <select name="cjk" id="cjk" <?php if (!function_exists('mb_split')) echo 'disabled="true"'; ?> >
305
- <option <?php if($options['cjk'] == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
306
- <option <?php if($options['cjk'] == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
307
- </select>
308
- </td>
309
- </tr>
310
- <tr valign="top">
311
- <th scope="row"><label for="use_stemmer"><?php _e('Treat Related Word Variations:', 'similar_posts') ?></label></th>
312
- <td>
313
- <select name="use_stemmer" id="use_stemmer">
314
- <option <?php if($options['use_stemmer'] == 'false') { echo 'selected="selected"'; } ?> value="false">Strictly</option>
315
- <option <?php if($options['use_stemmer'] == 'true') { echo 'selected="selected"'; } ?> value="true">By Stem</option>
316
- <option <?php if($options['use_stemmer'] == 'fuzzy') { echo 'selected="selected"'; } ?> value="fuzzy">Fuzzily</option>
317
- </select>
318
- </td>
319
- </tr>
320
- <tr valign="top">
321
- <th scope="row"><label for="batch"><?php _e('Batch size:', 'similar_posts') ?></label></th>
322
- <td><input name="batch" type="number" style="width: 60px;" id="batch" value="<?php echo $options['batch']; ?>" size="3" /></td>
323
- </tr>
324
- </table>
325
- <div class="submit">
326
- <input type="submit" class="button button-primary" name="reindex_all" value="<?php _e('Recreate Index', 'similar_posts') ?>" />
327
- <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-manage-update-options'); ?>
328
- </div>
329
- </form>
330
- </div>
331
- <?php
332
- }
333
-
334
-
335
-
336
- function similar_posts_for_feed_options_page(){
337
- echo '<div class="wrap"><h2>';
338
- _e('Similar Posts Feed ', 'similar_posts');
339
- echo '<a href="http://rmarsh.com/plugins/post-options/" style="font-size: 0.8em;">';
340
- _e('help and instructions');
341
- echo '</a></h2></div>';
342
- $m = new admin_subpages();
343
- $m->add_subpage('General', 'general', 'similar_posts_feed_general_options_subpage');
344
- $m->add_subpage('Output', 'output', 'similar_posts_feed_output_options_subpage');
345
- $m->add_subpage('Filter', 'filter', 'similar_posts_feed_filter_options_subpage');
346
- $m->add_subpage('Other', 'other', 'similar_posts_feed_other_options_subpage');
347
- $m->display();
348
- }
349
-
350
- function similar_posts_feed_general_options_subpage(){
351
- global $wpdb, $wp_version;
352
- $options = get_option('similar-posts-feed');
353
- if (isset($_POST['update_options'])) {
354
- check_admin_referer('similar-posts-feed-update-options');
355
- if (defined('POC_CACHE_4')) poc_cache_flush();
356
- // Fill up the options with the values chosen...
357
- $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'));
358
- update_option('similar-posts-feed', $options);
359
- // Show a message to say we've done something
360
- echo '<div class="updated fade similarposts-settings-saved"><p>' . __('Settings saved', 'similar_posts') . '</p></div>';
361
- }
362
- //now we drop into html to display the option page form
363
- ?>
364
- <div class="wrap similarposts-tab-content">
365
- <h2><?php _e('General Settings', 'similar_posts'); ?></h2>
366
- <form method="post" action="">
367
- <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save General Settings', 'similar_posts') ?>" /></div>
368
- <table class="optiontable form-table">
369
- <?php
370
- ppl_display_limit($options['limit']);
371
- ppl_display_skip($options['skip']);
372
- ppl_display_show_private($options['show_private']);
373
- ppl_display_show_pages($options['show_pages']);
374
- ppl_display_show_attachments($options['show_attachments']);
375
- ppl_display_status($options['status']);
376
- ppl_display_age($options['age']);
377
- ppl_display_omit_current_post($options['omit_current_post']);
378
- ppl_display_match_cat($options['match_cat']);
379
- ppl_display_match_tags($options['match_tags']);
380
- ppl_display_match_author($options['match_author']);
381
- ?>
382
- </table>
383
- <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save General Settings', 'similar_posts') ?>" /></div>
384
- <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-feed-update-options'); ?>
385
- </form>
386
- </div>
387
- <?php
388
- }
389
-
390
- function similar_posts_feed_output_options_subpage(){
391
- global $wpdb, $wp_version;
392
- $options = get_option('similar-posts-feed');
393
- if (isset($_POST['update_options'])) {
394
- check_admin_referer('similar-posts-feed-update-options');
395
- if (defined('POC_CACHE_4')) poc_cache_flush();
396
- // Fill up the options with the values chosen...
397
- $options = ppl_options_from_post($options, array('output_template', 'prefix', 'suffix', 'none_text', 'no_text', 'divider', 'sort', 'group_template'));
398
- update_option('similar-posts-feed', $options);
399
- // Show a message to say we've done something
400
- echo '<div class="updated fade similarposts-settings-saved"><p>' . __('Settings saved', 'similar_posts') . '</p></div>';
401
- }
402
- //now we drop into html to display the option page form
403
- ?>
404
- <div class="wrap similarposts-tab-content">
405
- <h2><?php _e('Output Settings', 'similar_posts'); ?></h2>
406
- <form method="post" action="">
407
- <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Output Settings', 'similar_posts') ?>" /></div>
408
- <table class="optiontable form-table">
409
- <tr>
410
- <td>
411
- <table>
412
- <?php
413
- ppl_display_output_template($options['output_template']);
414
- ppl_display_prefix($options['prefix']);
415
- ppl_display_suffix($options['suffix']);
416
- ppl_display_none_text($options['none_text']);
417
- ppl_display_no_text($options['no_text']);
418
- ppl_display_divider($options['divider']);
419
- ppl_display_sort($options['sort']);
420
- ppl_display_group_template($options['group_template']);
421
- ?>
422
- </table>
423
- </td>
424
- <td>
425
- <?php ppl_display_available_tags('similar-posts'); ?>
426
- </td></tr>
427
- </table>
428
- <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Output Settings', 'similar_posts') ?>" /></div>
429
- <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-feed-update-options'); ?>
430
- </form>
431
- </div>
432
- <?php
433
- }
434
-
435
- function similar_posts_feed_filter_options_subpage(){
436
- global $wpdb, $wp_version;
437
- $options = get_option('similar-posts-feed');
438
- if (isset($_POST['update_options'])) {
439
- check_admin_referer('similar-posts-feed-update-options');
440
- if (defined('POC_CACHE_4')) poc_cache_flush();
441
- // Fill up the options with the values chosen...
442
- $options = ppl_options_from_post($options, array('excluded_posts', 'included_posts', 'excluded_authors', 'included_authors', 'excluded_cats', 'included_cats', 'tag_str', 'custom'));
443
- update_option('similar-posts-feed', $options);
444
- // Show a message to say we've done something
445
- echo '<div class="updated fade similarposts-settings-saved"><p>' . __('Settings saved', 'similar_posts') . '</p></div>';
446
- }
447
- //now we drop into html to display the option page form
448
- ?>
449
- <div class="wrap similarposts-tab-content">
450
- <h2><?php _e('Filter Settings', 'similar_posts'); ?></h2>
451
- <form method="post" action="">
452
- <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Filter Settings', 'similar_posts') ?>" /></div>
453
- <table class="optiontable form-table">
454
- <?php
455
- ppl_display_excluded_posts($options['excluded_posts']);
456
- ppl_display_included_posts($options['included_posts']);
457
- ppl_display_authors($options['excluded_authors'], $options['included_authors']);
458
- ppl_display_cats($options['excluded_cats'], $options['included_cats']);
459
- ppl_display_tag_str($options['tag_str']);
460
- ppl_display_custom($options['custom']);
461
- ?>
462
- </table>
463
- <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Filter Settings', 'similar_posts') ?>" /></div>
464
- <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-feed-update-options'); ?>
465
- </form>
466
- </div>
467
- <?php
468
- }
469
-
470
- function similar_posts_feed_other_options_subpage(){
471
- global $wpdb, $wp_version;
472
- $options = get_option('similar-posts-feed');
473
- if (isset($_POST['update_options'])) {
474
- check_admin_referer('similar-posts-feed-update-options');
475
- if (defined('POC_CACHE_4')) poc_cache_flush();
476
- // Fill up the options with the values chosen...
477
- $options = ppl_options_from_post($options, array('stripcodes', 'term_extraction', 'num_terms', 'weight_title', 'weight_content', 'weight_tags', 'hand_links'));
478
- $wcontent = $options['weight_content'] + 0.0001;
479
- $wtitle = $options['weight_title'] + 0.0001;
480
- $wtags = $options['weight_tags'] + 0.0001;
481
- $wcombined = $wcontent + $wtitle + $wtags;
482
- $options['weight_content'] = $wcontent / $wcombined;
483
- $options['weight_title'] = $wtitle / $wcombined;
484
- $options['weight_tags'] = $wtags / $wcombined;
485
- update_option('similar-posts-feed', $options);
486
- // Show a message to say we've done something
487
- echo '<div class="updated fade similarposts-settings-saved"><p>' . __('Settings saved', 'similar_posts') . '</p></div>';
488
- }
489
- //now we drop into html to display the option page form
490
- ?>
491
- <div class="wrap similarposts-tab-content">
492
- <h2><?php _e('Other Settings', 'similar_posts'); ?></h2>
493
- <form method="post" action="">
494
- <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Other Settings', 'similar_posts') ?>" /></div>
495
- <table class="optiontable form-table">
496
- <?php
497
- ppl_display_weights($options);
498
- ppl_display_num_terms($options['num_terms']);
499
- ppl_display_term_extraction($options['term_extraction']);
500
- ppl_display_hand_links($options['hand_links']);
501
- ppl_display_stripcodes($options['stripcodes']);
502
- ?>
503
- </table>
504
- <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Other Settings', 'similar_posts') ?>" /></div>
505
- <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-feed-update-options'); ?>
506
- </form>
507
- </div>
508
- <?php
509
- }
510
-
511
-
512
- // sets up the index for the blog
513
- function save_index_entries ($utf8=false, $use_stemmer='false', $batch=100, $cjk=false) {
514
- global $wpdb, $table_prefix;
515
- //$t0 = microtime(true);
516
- $table_name = $table_prefix.'similar_posts';
517
- $wpdb->query("TRUNCATE `$table_name`");
518
- $termcount = 0;
519
- $start = 0;
520
- // in batches to conserve memory
521
- while ($posts = $wpdb->get_results("SELECT `ID`, `post_title`, `post_content`, `post_type` FROM $wpdb->posts LIMIT $start, $batch", ARRAY_A)) {
522
- foreach ($posts as $post) {
523
- if ($post['post_type'] === 'revision') continue;
524
- $content = sp_get_post_terms($post['post_content'], $utf8, $use_stemmer, $cjk);
525
- $title = sp_get_title_terms($post['post_title'], $utf8, $use_stemmer, $cjk);
526
- $postID = $post['ID'];
527
- $tags = sp_get_tag_terms($postID, $utf8);
528
- $wpdb->query("INSERT INTO `$table_name` (pID, content, title, tags) VALUES ($postID, \"$content\", \"$title\", \"$tags\")");
529
- $termcount = $termcount + 1;
530
- }
531
- $start += $batch;
532
- if (!ini_get('safe_mode')) set_time_limit(30);
533
- }
534
- unset($posts);
535
- //$t = microtime(true) - $t0; echo "t = $t<br>";
536
- return $termcount;
537
- }
538
-
539
- // this function gets called when the plugin is installed to set up the index and default options
540
- function similar_posts_install() {
541
- global $wpdb, $table_prefix;
542
-
543
- $table_name = $table_prefix . 'similar_posts';
544
- $errorlevel = error_reporting(0);
545
- $suppress = $wpdb->hide_errors();
546
- $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
547
- `pID` bigint( 20 ) unsigned NOT NULL ,
548
- `content` longtext NOT NULL ,
549
- `title` text NOT NULL ,
550
- `tags` text NOT NULL ,
551
- FULLTEXT KEY `title` ( `title` ) ,
552
- FULLTEXT KEY `content` ( `content` ) ,
553
- FULLTEXT KEY `tags` ( `tags` )
554
- ) ENGINE = MyISAM CHARSET = utf8;";
555
- $wpdb->query($sql);
556
- // MySQL before 4.1 doesn't recognise the character set properly, so if there's an error we can try without
557
- if ($wpdb->last_error !== '') {
558
- $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
559
- `pID` bigint( 20 ) unsigned NOT NULL ,
560
- `content` longtext NOT NULL ,
561
- `title` text NOT NULL ,
562
- `tags` text NOT NULL ,
563
- FULLTEXT KEY `title` ( `title` ) ,
564
- FULLTEXT KEY `content` ( `content` ) ,
565
- FULLTEXT KEY `tags` ( `tags` )
566
- ) ENGINE = MyISAM;";
567
- $wpdb->query($sql);
568
- }
569
- $options = (array) get_option('similar-posts-feed');
570
- // check each of the option values and, if empty, assign a default (doing it this long way
571
- // lets us add new options in later versions)
572
- if (!isset($options['limit'])) $options['limit'] = 5;
573
- if (!isset($options['skip'])) $options['skip'] = 0;
574
- if (!isset($options['age'])) {$options['age']['direction'] = 'none'; $options['age']['length'] = '0'; $options['age']['duration'] = 'month';}
575
- if (!isset($options['divider'])) $options['divider'] = '';
576
- if (!isset($options['omit_current_post'])) $options['omit_current_post'] = 'true';
577
- if (!isset($options['show_private'])) $options['show_private'] = 'false';
578
- if (!isset($options['show_pages'])) $options['show_pages'] = 'false';
579
- if (!isset($options['show_attachments'])) $options['show_attachments'] = 'false';
580
- // show_static is now show_pages
581
- if ( isset($options['show_static'])) {$options['show_pages'] = $options['show_static']; unset($options['show_static']);};
582
- if (!isset($options['none_text'])) $options['none_text'] = __('None Found', 'similar_posts');
583
- if (!isset($options['no_text'])) $options['no_text'] = 'false';
584
- if (!isset($options['tag_str'])) $options['tag_str'] = '';
585
- if (!isset($options['excluded_cats'])) $options['excluded_cats'] = '';
586
- if ($options['excluded_cats'] === '9999') $options['excluded_cats'] = '';
587
- if (!isset($options['included_cats'])) $options['included_cats'] = '';
588
- if ($options['included_cats'] === '9999') $options['included_cats'] = '';
589
- if (!isset($options['excluded_authors'])) $options['excluded_authors'] = '';
590
- if ($options['excluded_authors'] === '9999') $options['excluded_authors'] = '';
591
- if (!isset($options['included_authors'])) $options['included_authors'] = '';
592
- if ($options['included_authors'] === '9999') $options['included_authors'] = '';
593
- if (!isset($options['included_posts'])) $options['included_posts'] = '';
594
- if (!isset($options['excluded_posts'])) $options['excluded_posts'] = '';
595
- if ($options['excluded_posts'] === '9999') $options['excluded_posts'] = '';
596
- if (!isset($options['stripcodes'])) $options['stripcodes'] = array(array());
597
- if (!isset($options['prefix'])) $options['prefix'] = 'Similar Posts:<ul>';
598
- if (!isset($options['suffix'])) $options['suffix'] = '</ul>';
599
- if (!isset($options['output_template'])) $options['output_template'] = '<li>{link}</li>';
600
- if (!isset($options['match_cat'])) $options['match_cat'] = 'false';
601
- if (!isset($options['match_tags'])) $options['match_tags'] = 'false';
602
- if (!isset($options['match_author'])) $options['match_author'] = 'false';
603
- if (!isset($options['custom'])) {$options['custom']['key'] = ''; $options['custom']['op'] = '='; $options['custom']['value'] = '';}
604
- if (!isset($options['sort'])) {$options['sort']['by1'] = ''; $options['sort']['order1'] = SORT_ASC; $options['sort']['case1'] = 'false';$options['sort']['by2'] = ''; $options['sort']['order2'] = SORT_ASC; $options['sort']['case2'] = 'false';}
605
- if (!isset($options['status'])) {$options['status']['publish'] = 'true'; $options['status']['private'] = 'false'; $options['status']['draft'] = 'false'; $options['status']['future'] = 'false';}
606
- if (!isset($options['group_template'])) $options['group_template'] = '';
607
- if (!isset($options['weight_content'])) $options['weight_content'] = 0.9;
608
- if (!isset($options['weight_title'])) $options['weight_title'] = 0.1;
609
- if (!isset($options['weight_tags'])) $options['weight_tags'] = 0.0;
610
- if (!isset($options['num_terms'])) $options['num_terms'] = 20;
611
- if (!isset($options['term_extraction'])) $options['term_extraction'] = 'frequency';
612
- if (!isset($options['hand_links'])) $options['hand_links'] = 'false';
613
- update_option('similar-posts-feed', $options);
614
-
615
- $options = (array) get_option('similar-posts');
616
- // check each of the option values and, if empty, assign a default (doing it this long way
617
- // lets us add new options in later versions)
618
- if (!isset($options['feed_active'])) $options['feed_active'] = 'false'; // deprecated
619
- if (!isset($options['widget_condition'])) $options['widget_condition'] = '';
620
- if (!isset($options['widget_parameters'])) $options['widget_parameters'] = '';
621
- if (!isset($options['feed_on'])) $options['feed_on'] = 'false';
622
- if (!isset($options['feed_priority'])) $options['feed_priority'] = '10';
623
- if (!isset($options['feed_parameters'])) $options['feed_parameters'] = 'prefix=<strong>'.__('Similar Posts', 'similar-posts').':</strong><ul class="similar-posts">&suffix=</ul>';
624
- if (!isset($options['append_on'])) $options['append_on'] = 'false';
625
- if (!isset($options['append_priority'])) $options['append_priority'] = '10';
626
- if (!isset($options['append_parameters'])) $options['append_parameters'] = 'prefix=<h3>'.__('Similar Posts', 'similar-posts').':</h3><ul class="similar-posts">&suffix=</ul>';
627
- if (!isset($options['append_condition'])) $options['append_condition'] = 'is_single()';
628
- if (!isset($options['limit'])) $options['limit'] = 5;
629
- if (!isset($options['skip'])) $options['skip'] = 0;
630
- if (!isset($options['age'])) {$options['age']['direction'] = 'none'; $options['age']['length'] = '0'; $options['age']['duration'] = 'month';}
631
- if (!isset($options['divider'])) $options['divider'] = '';
632
- if (!isset($options['omit_current_post'])) $options['omit_current_post'] = 'true';
633
- if (!isset($options['show_private'])) $options['show_private'] = 'false';
634
- if (!isset($options['show_pages'])) $options['show_pages'] = 'false';
635
- if (!isset($options['show_attachments'])) $options['show_attachments'] = 'false';
636
- // show_static is now show_pages
637
- if ( isset($options['show_static'])) {$options['show_pages'] = $options['show_static']; unset($options['show_static']);};
638
- if (!isset($options['none_text'])) $options['none_text'] = __('None Found', 'similar_posts');
639
- if (!isset($options['no_text'])) $options['no_text'] = 'false';
640
- if (!isset($options['tag_str'])) $options['tag_str'] = '';
641
- if (!isset($options['excluded_cats'])) $options['excluded_cats'] = '';
642
- if ($options['excluded_cats'] === '9999') $options['excluded_cats'] = '';
643
- if (!isset($options['included_cats'])) $options['included_cats'] = '';
644
- if ($options['included_cats'] === '9999') $options['included_cats'] = '';
645
- if (!isset($options['excluded_authors'])) $options['excluded_authors'] = '';
646
- if ($options['excluded_authors'] === '9999') $options['excluded_authors'] = '';
647
- if (!isset($options['included_authors'])) $options['included_authors'] = '';
648
- if ($options['included_authors'] === '9999') $options['included_authors'] = '';
649
- if (!isset($options['included_posts'])) $options['included_posts'] = '';
650
- if (!isset($options['excluded_posts'])) $options['excluded_posts'] = '';
651
- if ($options['excluded_posts'] === '9999') $options['excluded_posts'] = '';
652
- if (!isset($options['stripcodes'])) $options['stripcodes'] = array(array());
653
- if (!isset($options['prefix'])) $options['prefix'] = '<ul>';
654
- if (!isset($options['suffix'])) $options['suffix'] = '</ul>';
655
- if (!isset($options['output_template'])) $options['output_template'] = '<li>{link}</li>';
656
- if (!isset($options['match_cat'])) $options['match_cat'] = 'false';
657
- if (!isset($options['match_tags'])) $options['match_tags'] = 'false';
658
- if (!isset($options['match_author'])) $options['match_author'] = 'false';
659
- if (!isset($options['content_filter'])) $options['content_filter'] = 'false';
660
- if (!isset($options['custom'])) {$options['custom']['key'] = ''; $options['custom']['op'] = '='; $options['custom']['value'] = '';}
661
- if (!isset($options['sort'])) {$options['sort']['by1'] = ''; $options['sort']['order1'] = SORT_ASC; $options['sort']['case1'] = 'false';$options['sort']['by2'] = ''; $options['sort']['order2'] = SORT_ASC; $options['sort']['case2'] = 'false';}
662
- if (!isset($options['status'])) {$options['status']['publish'] = 'true'; $options['status']['private'] = 'false'; $options['status']['draft'] = 'false'; $options['status']['future'] = 'false';}
663
- if (!isset($options['group_template'])) $options['group_template'] = '';
664
- if (!isset($options['weight_content'])) $options['weight_content'] = 0.9;
665
- if (!isset($options['weight_title'])) $options['weight_title'] = 0.1;
666
- if (!isset($options['weight_tags'])) $options['weight_tags'] = 0.0;
667
- if (!isset($options['num_terms'])) $options['num_terms'] = 20;
668
- if (!isset($options['term_extraction'])) $options['term_extraction'] = 'frequency';
669
- if (!isset($options['hand_links'])) $options['hand_links'] = 'false';
670
- if (!isset($options['utf8'])) $options['utf8'] = 'false';
671
- if (!function_exists('mb_internal_encoding')) $options['utf8'] = 'false';
672
- if (!isset($options['cjk'])) $options['cjk'] = 'false';
673
- if (!function_exists('mb_internal_encoding')) $options['cjk'] = 'false';
674
- if (!isset($options['use_stemmer'])) $options['use_stemmer'] = 'false';
675
- if (!isset($options['batch'])) $options['batch'] = '100';
676
-
677
- update_option('similar-posts', $options);
678
-
679
- // initial creation of the index, if the table is empty
680
- $num_index_posts = $wpdb->get_var("SELECT COUNT(*) FROM `$table_name`");
681
- if ($num_index_posts == 0) save_index_entries (($options['utf8'] === 'true'), 'false', $options['batch'], ($options['cjk'] === 'true'));
682
-
683
- // deactivate legacy Similar Posts Feed if present
684
- $current = get_option('active_plugins');
685
- if (in_array('Similar_Posts_Feed/similar-posts-feed.php', $current)) {
686
- array_splice($current, array_search('Similar_Posts_Feed/similar-posts-feed.php', $current), 1);
687
- update_option('active_plugins', $current);
688
- }
689
- unset($current);
690
-
691
- // clear legacy custom fields
692
- $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_key = 'similarterms'");
693
-
694
- // clear legacy index
695
- $indices = $wpdb->get_results("SHOW INDEX FROM $wpdb->posts", ARRAY_A);
696
- foreach ($indices as $index) {
697
- if ($index['Key_name'] === 'post_similar') {
698
- $wpdb->query("ALTER TABLE $wpdb->posts DROP INDEX post_similar");
699
- break;
700
- }
701
- }
702
-
703
- $wpdb->show_errors($suppress);
704
- error_reporting($errorlevel);
705
- }
706
-
707
-
708
-
709
- if (!function_exists('ppl_plugin_basename')) {
710
- if ( !defined('WP_PLUGIN_DIR') ) define( 'WP_PLUGIN_DIR', ABSPATH . 'wp-content/plugins' );
711
- function ppl_plugin_basename($file) {
712
- $file = str_replace('\\','/',$file); // sanitize for Win32 installs
713
- $file = preg_replace('|/+|','/', $file); // remove any duplicate slash
714
- $plugin_dir = str_replace('\\','/',WP_PLUGIN_DIR); // sanitize for Win32 installs
715
- $plugin_dir = preg_replace('|/+|','/', $plugin_dir); // remove any duplicate slash
716
- $file = preg_replace('|^' . preg_quote($plugin_dir, '|') . '/|','',$file); // get relative path from plugins dir
717
- return $file;
718
- }
719
- }
720
-
721
- add_action('activate_'.str_replace('-admin', '', ppl_plugin_basename(__FILE__)), 'similar_posts_install');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // Admin stuff for Similar Posts Plugin, Version 2.6.2.0
4
+
5
+ function similar_posts_option_menu() {
6
+ add_options_page(__('Similar Posts Options', 'similar_posts'), __('Similar Posts', 'similar_posts'), 'edit_theme_options', 'similar-posts', 'similar_posts_options_page');
7
+ }
8
+
9
+ add_action('admin_menu', 'similar_posts_option_menu', 1);
10
+
11
+ function similar_posts_for_feed_option_menu() {
12
+ add_options_page(__('Similar Posts Feed Options', 'similar_posts'), __('Similar Posts Feed', 'similar_posts'), 'edit_theme_options', 'similar-posts-feed', 'similar_posts_for_feed_options_page');
13
+ }
14
+
15
+ // this sneaky piece of work lets the similar posts feed menu appear and disappear
16
+ function juggle_similar_posts_menus() {
17
+ if (isset($_POST['feed_active'])) {
18
+ $active = ($_POST['feed_active'] === 'true');
19
+ } else {
20
+ $options = get_option('similar-posts');
21
+ $active = ($options['feed_active'] === 'true');
22
+ }
23
+ if ($active) {
24
+ add_action('admin_menu', 'similar_posts_for_feed_option_menu', 2);
25
+ } else {
26
+ remove_action('admin_menu', 'similar_posts_for_feed_option_menu');
27
+ }
28
+ }
29
+
30
+ add_action('plugins_loaded', 'juggle_similar_posts_menus');
31
+
32
+ function similar_posts_options_page(){
33
+ echo '<div class="wrap"><h2>';
34
+ _e('Similar Posts ', 'similar_posts');
35
+ echo '</h2></div>';
36
+
37
+
38
+ $m = new admin_subpages();
39
+ $m->add_subpage('General', 'general', 'similar_posts_general_options_subpage');
40
+ $m->add_subpage('Output', 'output', 'similar_posts_output_options_subpage');
41
+ $m->add_subpage('Filter', 'filter', 'similar_posts_filter_options_subpage');
42
+ $m->add_subpage('Placement', 'placement', 'similar_posts_placement_options_subpage');
43
+ $m->add_subpage('Misc', 'other', 'similar_posts_other_options_subpage');
44
+ $m->add_subpage('Manage the Index', 'index', 'similar_posts_index_options_subpage');
45
+ $m->display();
46
+
47
+ //echo '<div class="wrap"><a target="_blank" href="http://rmarsh.com/plugins/post-options/">';
48
+ //_e('Detailed help &amp; instructions');
49
+ //echo '</a></div>';
50
+ }
51
+ add_action( 'admin_footer', 'similar_posts_admin_footer' );
52
+ function similar_posts_admin_footer() {
53
+ $current_screen = get_current_screen();
54
+ if ( 'settings_page_similar-posts' !== $current_screen->id && 'widgets' !== $current_screen->id ) {
55
+ return;
56
+ }
57
+ ?>
58
+ <div id="file-editor-warning" class="notification-dialog-wrap file-editor-warning rrm-file-editor-warning" style="display:none;">
59
+ <div class="notification-dialog-background"></div>
60
+ <div class="notification-dialog">
61
+ <div class="file-editor-warning-content">
62
+ <div class="file-editor-warning-message">
63
+ <h1><?php esc_html_e( 'Heads up!', 'similar-posts' )?></h1>
64
+ <p><?php esc_html_e( 'Editing this field can introduce issues that could break your site. Please proceed with great care.', 'similar-posts' )?></p>
65
+ </div>
66
+ <p>
67
+ <a id="file-editor-warning-go-back" class="button file-editor-warning-go-back" href="#"><?php esc_html_e( 'Go back', 'similar-posts' )?></a>
68
+ <button type="button" id="rrm-file-editor-warning-dismiss" class="file-editor-warning-dismiss button button-primary"><?php esc_html_e( 'I understand', 'similar-posts' )?></button>
69
+ </p>
70
+ </div>
71
+ </div>
72
+ </div>
73
+ <script>
74
+ jQuery(document).ready(function(){
75
+ var field_id;
76
+ var current_obj;
77
+ jQuery('body').on('click', '#widget_rrm_similar_posts_condition, #append_condition, #widget_condition', function() {
78
+ if ( ! jQuery(this).hasClass("needs_file_editor_warning") && jQuery(this).is('[readonly]') ) {
79
+ jQuery(this).addClass("needs_file_editor_warning");
80
+ jQuery('.rrm-file-editor-warning').show();
81
+ field_id = jQuery(this).attr('id');
82
+ current_obj = this;
83
+ }
84
+ });
85
+ jQuery('#file-editor-warning-go-back').click(function(){
86
+ jQuery(current_obj).removeClass("needs_file_editor_warning");
87
+ jQuery("#file-editor-warning").hide();
88
+
89
+ });
90
+ jQuery('#rrm-file-editor-warning-dismiss').click(function(){
91
+ jQuery(current_obj).removeAttr("readonly");
92
+ jQuery("#file-editor-warning").hide();
93
+ });
94
+ });
95
+ </script>
96
+ <?php
97
+ }
98
+ function similar_posts_general_options_subpage(){
99
+ global $wpdb, $wp_version;
100
+ $options = get_option('similar-posts');
101
+ if (isset($_POST['update_options'])) {
102
+ check_admin_referer('similar-posts-update-options');
103
+ if (defined('POC_CACHE_4')) poc_cache_flush();
104
+ // Fill up the options with the values chosen...
105
+ $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'));
106
+ update_option('similar-posts', $options);
107
+ // Show a message to say we've done something
108
+ echo '<div class="updated settings-error notice"><p>' . __('<b>Settings saved.</b>', 'similar_posts') . '</p></div>';
109
+ }
110
+ //now we drop into html to display the option page form
111
+ ?>
112
+ <div class="wrap similarposts-tab-content">
113
+
114
+ <form method="post" action="">
115
+
116
+ <table class="optiontable form-table">
117
+ <?php
118
+ ppl_display_limit($options['limit']);
119
+ ppl_display_skip($options['skip']);
120
+ ppl_display_show_private($options['show_private']);
121
+ ppl_display_show_pages($options['show_pages']);
122
+ ppl_display_show_attachments($options['show_attachments']);
123
+ ppl_display_status($options['status']);
124
+ ppl_display_age($options['age']);
125
+ ppl_display_omit_current_post($options['omit_current_post']);
126
+ ppl_display_match_cat($options['match_cat']);
127
+ ppl_display_match_tags($options['match_tags']);
128
+ ppl_display_match_author($options['match_author']);
129
+ ?>
130
+ </table>
131
+ <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Settings', 'similar_posts') ?>" /></div>
132
+ <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-update-options'); ?>
133
+ </form>
134
+ </div>
135
+ <?php
136
+ }
137
+
138
+ function similar_posts_output_options_subpage(){
139
+ global $wpdb, $wp_version;
140
+ $options = get_option('similar-posts');
141
+ if (isset($_POST['update_options'])) {
142
+ check_admin_referer('similar-posts-update-options');
143
+ if (defined('POC_CACHE_4')) poc_cache_flush();
144
+ // Fill up the options with the values chosen...
145
+ $options = ppl_options_from_post($options, array('output_template', 'prefix', 'suffix', 'none_text', 'no_text', 'divider', 'sort', 'group_template'));
146
+ update_option('similar-posts', $options);
147
+ // Show a message to say we've done something
148
+ echo '<div class="updated settings-error notice"><p>' . __('<b>Settings saved.</b>', 'similar_posts') . '</p></div>';
149
+ }
150
+ //now we drop into html to display the option page form
151
+ ?>
152
+ <div class="wrap similarposts-tab-content">
153
+
154
+ <form method="post" action="">
155
+
156
+ <table class="optiontable form-table">
157
+ <tr>
158
+ <td style="padding-top: 0; vertical-align: top;">
159
+ <table>
160
+ <?php
161
+ ppl_display_output_template($options['output_template']);
162
+ ppl_display_prefix($options['prefix']);
163
+ ppl_display_suffix($options['suffix']);
164
+ ppl_display_none_text($options['none_text']);
165
+ ppl_display_no_text($options['no_text']);
166
+ ppl_display_divider($options['divider']);
167
+ ppl_display_sort($options['sort']);
168
+ ppl_display_group_template($options['group_template']);
169
+ ?>
170
+ </table>
171
+ </td>
172
+ <td>
173
+ <?php ppl_display_available_tags('similar-posts'); ?>
174
+ </td></tr>
175
+ </table>
176
+ <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Settings', 'similar_posts') ?>" /></div>
177
+ <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-update-options'); ?>
178
+ </form>
179
+ </div>
180
+ <?php
181
+ }
182
+
183
+ function similar_posts_filter_options_subpage(){
184
+ global $wpdb, $wp_version;
185
+ $options = get_option('similar-posts');
186
+ if (isset($_POST['update_options'])) {
187
+ check_admin_referer('similar-posts-update-options');
188
+ if (defined('POC_CACHE_4')) poc_cache_flush();
189
+ // Fill up the options with the values chosen...
190
+ $options = ppl_options_from_post($options, array('excluded_posts', 'included_posts', 'excluded_authors', 'included_authors', 'excluded_cats', 'included_cats', 'tag_str', 'custom'));
191
+ update_option('similar-posts', $options);
192
+ // Show a message to say we've done something
193
+ echo '<div class="updated settings-error notice"><p>' . __('<b>Settings saved.</b>', 'similar_posts') . '</p></div>';
194
+ }
195
+ //now we drop into html to display the option page form
196
+ ?>
197
+ <div class="wrap similarposts-tab-content">
198
+
199
+ <form method="post" action="">
200
+
201
+ <table class="optiontable form-table">
202
+ <?php
203
+ ppl_display_excluded_posts($options['excluded_posts']);
204
+ ppl_display_included_posts($options['included_posts']);
205
+ ppl_display_authors($options['excluded_authors'], $options['included_authors']);
206
+ ppl_display_cats($options['excluded_cats'], $options['included_cats']);
207
+ ppl_display_tag_str($options['tag_str']);
208
+ ppl_display_custom($options['custom']);
209
+ ?>
210
+ </table>
211
+ <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Settings', 'similar_posts') ?>" /></div>
212
+ <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-update-options'); ?>
213
+ </form>
214
+ </div>
215
+ <?php
216
+ }
217
+
218
+ function similar_posts_placement_options_subpage(){
219
+ global $wpdb, $wp_version;
220
+ $options = get_option('similar-posts');
221
+ if (isset($_POST['update_options'])) {
222
+ check_admin_referer('similar-posts-update-options');
223
+ if (defined('POC_CACHE_4')) poc_cache_flush();
224
+ // Fill up the options with the values chosen...
225
+ $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'));
226
+ if ( false === sp_is_user_allowed_to_add_php_code() ) {
227
+ $get_options = get_option('similar-posts');
228
+ $options['append_condition'] = $get_options['append_condition'];
229
+ $options['widget_condition'] = $get_options['widget_condition'];
230
+ }
231
+ update_option('similar-posts', $options);
232
+ // Show a message to say we've done something
233
+ echo '<div class="updated settings-error notice"><p>' . __('<b>Settings saved.</b>', 'similar_posts') . '</p></div>';
234
+ }
235
+ //now we drop into html to display the option page form
236
+ ?>
237
+ <div class="wrap similarposts-tab-content">
238
+
239
+ <form method="post" action="">
240
+
241
+ <table class="optiontable form-table">
242
+ <?php
243
+ ppl_display_append($options);
244
+ ppl_display_feed($options);
245
+ ppl_display_widget($options);
246
+ ppl_display_content_filter($options['content_filter']);
247
+ ?>
248
+ </table>
249
+ <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Settings', 'similar_posts') ?>" /></div>
250
+ <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-update-options'); ?>
251
+ </form>
252
+ </div>
253
+ <?php
254
+ }
255
+
256
+ function similar_posts_other_options_subpage(){
257
+ global $wpdb, $wp_version;
258
+ $options = get_option('similar-posts');
259
+ if (isset($_POST['update_options'])) {
260
+ check_admin_referer('similar-posts-update-options');
261
+ if (defined('POC_CACHE_4')) poc_cache_flush();
262
+ // Fill up the options with the values chosen...
263
+ $options = ppl_options_from_post($options, array('stripcodes', 'feed_active', 'term_extraction', 'num_terms', 'weight_title', 'weight_content', 'weight_tags', 'hand_links'));
264
+ $wcontent = $options['weight_content'] + 0.0001;
265
+ $wtitle = $options['weight_title'] + 0.0001;
266
+ $wtags = $options['weight_tags'] + 0.0001;
267
+ $wcombined = $wcontent + $wtitle + $wtags;
268
+ $options['weight_content'] = $wcontent / $wcombined;
269
+ $options['weight_title'] = $wtitle / $wcombined;
270
+ $options['weight_tags'] = $wtags / $wcombined;
271
+ update_option('similar-posts', $options);
272
+ // Show a message to say we've done something
273
+ echo '<div class="updated settings-error notice"><p>' . __('<b>Settings saved.</b>', 'similar_posts') . '</p></div>';
274
+ }
275
+ //now we drop into html to display the option page form
276
+ ?>
277
+ <div class="wrap similarposts-tab-content">
278
+
279
+ <form method="post" action="">
280
+
281
+ <table class="optiontable form-table">
282
+ <?php
283
+ ppl_display_weights($options);
284
+ ppl_display_num_terms($options['num_terms']);
285
+ ppl_display_term_extraction($options['term_extraction']);
286
+ ppl_display_hand_links($options['hand_links']);
287
+ ppl_display_feed_active($options['feed_active']);
288
+ ppl_display_stripcodes($options['stripcodes']);
289
+ ?>
290
+ </table>
291
+ <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Settings', 'similar_posts') ?>" /></div>
292
+ <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-update-options'); ?>
293
+ </form>
294
+ </div>
295
+ <?php
296
+ }
297
+
298
+ function similar_posts_index_options_subpage(){
299
+ if (isset($_POST['reindex_all'])) {
300
+ check_admin_referer('similar-posts-manage-update-options');
301
+ if (defined('POC_CACHE_4')) poc_cache_flush();
302
+ $options = get_option('similar-posts');
303
+ $options['utf8'] = $_POST['utf8'];
304
+ if (!function_exists('mb_split')) {
305
+ $options['utf8'] = 'false';
306
+ }
307
+ $options['cjk'] = $_POST['cjk'];
308
+ if (!function_exists('mb_internal_encoding')) {
309
+ $options['cjk'] = 'false';
310
+ }
311
+ if ($options['cjk'] === 'true') $options['utf8'] = 'true';
312
+ $options['use_stemmer'] = $_POST['use_stemmer'];
313
+ $options['batch'] = ppl_check_cardinal($_POST['batch']);
314
+ if ($options['batch'] === 0) $options['batch'] = 100;
315
+ flush();
316
+ $termcount = save_index_entries (($options['utf8']==='true'), $options['use_stemmer'], $options['batch'], ($options['cjk']==='true'));
317
+ update_option('similar-posts', $options);
318
+ //show a message
319
+ printf('<div class="updated fade"><p>'.__('Indexed %d posts.').'</p></div>', $termcount);
320
+ } else {
321
+ $options = get_option('similar-posts');
322
+ }
323
+ ?>
324
+ <div class="wrap similarposts-tab-content">
325
+ <?php
326
+ 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>';
327
+ echo '<p>'.__('The options that affect the index can be set below.', 'similar_posts').'</p>';
328
+ 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>';
329
+ 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>';
330
+ 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>';
331
+ 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>';
332
+ 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>';
333
+ ?>
334
+ <form method="post" action="">
335
+ <table class="optiontable form-table">
336
+ <tr valign="top">
337
+ <th scope="row"><label for="utf8"><?php _e('Handle extended characters?', 'similar_posts') ?></label></th>
338
+ <td>
339
+ <select name="utf8" id="utf8" <?php if (!function_exists('mb_split')) echo 'disabled="true"'; ?> >
340
+ <option <?php if($options['utf8'] == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
341
+ <option <?php if($options['utf8'] == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
342
+ </select>
343
+ </td>
344
+ </tr>
345
+ <tr valign="top">
346
+ <th scope="row"><label for="cjk"><?php _e('Treat as Chinese, Korean, or Japanese?', 'similar_posts') ?></label></th>
347
+ <td>
348
+ <select name="cjk" id="cjk" <?php if (!function_exists('mb_split')) echo 'disabled="true"'; ?> >
349
+ <option <?php if($options['cjk'] == 'false') { echo 'selected="selected"'; } ?> value="false">No</option>
350
+ <option <?php if($options['cjk'] == 'true') { echo 'selected="selected"'; } ?> value="true">Yes</option>
351
+ </select>
352
+ </td>
353
+ </tr>
354
+ <tr valign="top">
355
+ <th scope="row"><label for="use_stemmer"><?php _e('Treat Related Word Variations:', 'similar_posts') ?></label></th>
356
+ <td>
357
+ <select name="use_stemmer" id="use_stemmer">
358
+ <option <?php if($options['use_stemmer'] == 'false') { echo 'selected="selected"'; } ?> value="false">Strictly</option>
359
+ <option <?php if($options['use_stemmer'] == 'true') { echo 'selected="selected"'; } ?> value="true">By Stem</option>
360
+ <option <?php if($options['use_stemmer'] == 'fuzzy') { echo 'selected="selected"'; } ?> value="fuzzy">Fuzzily</option>
361
+ </select>
362
+ </td>
363
+ </tr>
364
+ <tr valign="top">
365
+ <th scope="row"><label for="batch"><?php _e('Batch size:', 'similar_posts') ?></label></th>
366
+ <td><input name="batch" type="number" style="width: 60px;" id="batch" value="<?php echo $options['batch']; ?>" size="3" /></td>
367
+ </tr>
368
+ </table>
369
+ <div class="submit">
370
+ <input type="submit" class="button button-primary" name="reindex_all" value="<?php _e('Recreate Index', 'similar_posts') ?>" />
371
+ <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-manage-update-options'); ?>
372
+ </div>
373
+ </form>
374
+ </div>
375
+ <?php
376
+ }
377
+
378
+
379
+
380
+ function similar_posts_for_feed_options_page(){
381
+ echo '<div class="wrap"><h2>';
382
+ _e('Similar Posts Feed ', 'similar_posts');
383
+ echo '<a href="http://rmarsh.com/plugins/post-options/" style="font-size: 0.8em;">';
384
+ _e('help and instructions');
385
+ echo '</a></h2></div>';
386
+ $m = new admin_subpages();
387
+ $m->add_subpage('General', 'general', 'similar_posts_feed_general_options_subpage');
388
+ $m->add_subpage('Output', 'output', 'similar_posts_feed_output_options_subpage');
389
+ $m->add_subpage('Filter', 'filter', 'similar_posts_feed_filter_options_subpage');
390
+ $m->add_subpage('Other', 'other', 'similar_posts_feed_other_options_subpage');
391
+ $m->display();
392
+ }
393
+
394
+ function similar_posts_feed_general_options_subpage(){
395
+ global $wpdb, $wp_version;
396
+ $options = get_option('similar-posts-feed');
397
+ if (isset($_POST['update_options'])) {
398
+ check_admin_referer('similar-posts-feed-update-options');
399
+ if (defined('POC_CACHE_4')) poc_cache_flush();
400
+ // Fill up the options with the values chosen...
401
+ $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'));
402
+ update_option('similar-posts-feed', $options);
403
+ // Show a message to say we've done something
404
+ echo '<div class="updated fade similarposts-settings-saved"><p>' . __('Settings saved', 'similar_posts') . '</p></div>';
405
+ }
406
+ //now we drop into html to display the option page form
407
+ ?>
408
+ <div class="wrap similarposts-tab-content">
409
+ <h2><?php _e('General Settings', 'similar_posts'); ?></h2>
410
+ <form method="post" action="">
411
+ <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save General Settings', 'similar_posts') ?>" /></div>
412
+ <table class="optiontable form-table">
413
+ <?php
414
+ ppl_display_limit($options['limit']);
415
+ ppl_display_skip($options['skip']);
416
+ ppl_display_show_private($options['show_private']);
417
+ ppl_display_show_pages($options['show_pages']);
418
+ ppl_display_show_attachments($options['show_attachments']);
419
+ ppl_display_status($options['status']);
420
+ ppl_display_age($options['age']);
421
+ ppl_display_omit_current_post($options['omit_current_post']);
422
+ ppl_display_match_cat($options['match_cat']);
423
+ ppl_display_match_tags($options['match_tags']);
424
+ ppl_display_match_author($options['match_author']);
425
+ ?>
426
+ </table>
427
+ <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save General Settings', 'similar_posts') ?>" /></div>
428
+ <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-feed-update-options'); ?>
429
+ </form>
430
+ </div>
431
+ <?php
432
+ }
433
+
434
+ function similar_posts_feed_output_options_subpage(){
435
+ global $wpdb, $wp_version;
436
+ $options = get_option('similar-posts-feed');
437
+ if (isset($_POST['update_options'])) {
438
+ check_admin_referer('similar-posts-feed-update-options');
439
+ if (defined('POC_CACHE_4')) poc_cache_flush();
440
+ // Fill up the options with the values chosen...
441
+ $options = ppl_options_from_post($options, array('output_template', 'prefix', 'suffix', 'none_text', 'no_text', 'divider', 'sort', 'group_template'));
442
+ update_option('similar-posts-feed', $options);
443
+ // Show a message to say we've done something
444
+ echo '<div class="updated fade similarposts-settings-saved"><p>' . __('Settings saved', 'similar_posts') . '</p></div>';
445
+ }
446
+ //now we drop into html to display the option page form
447
+ ?>
448
+ <div class="wrap similarposts-tab-content">
449
+ <h2><?php _e('Output Settings', 'similar_posts'); ?></h2>
450
+ <form method="post" action="">
451
+ <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Output Settings', 'similar_posts') ?>" /></div>
452
+ <table class="optiontable form-table">
453
+ <tr>
454
+ <td>
455
+ <table>
456
+ <?php
457
+ ppl_display_output_template($options['output_template']);
458
+ ppl_display_prefix($options['prefix']);
459
+ ppl_display_suffix($options['suffix']);
460
+ ppl_display_none_text($options['none_text']);
461
+ ppl_display_no_text($options['no_text']);
462
+ ppl_display_divider($options['divider']);
463
+ ppl_display_sort($options['sort']);
464
+ ppl_display_group_template($options['group_template']);
465
+ ?>
466
+ </table>
467
+ </td>
468
+ <td>
469
+ <?php ppl_display_available_tags('similar-posts'); ?>
470
+ </td></tr>
471
+ </table>
472
+ <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Output Settings', 'similar_posts') ?>" /></div>
473
+ <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-feed-update-options'); ?>
474
+ </form>
475
+ </div>
476
+ <?php
477
+ }
478
+
479
+ function similar_posts_feed_filter_options_subpage(){
480
+ global $wpdb, $wp_version;
481
+ $options = get_option('similar-posts-feed');
482
+ if (isset($_POST['update_options'])) {
483
+ check_admin_referer('similar-posts-feed-update-options');
484
+ if (defined('POC_CACHE_4')) poc_cache_flush();
485
+ // Fill up the options with the values chosen...
486
+ $options = ppl_options_from_post($options, array('excluded_posts', 'included_posts', 'excluded_authors', 'included_authors', 'excluded_cats', 'included_cats', 'tag_str', 'custom'));
487
+ update_option('similar-posts-feed', $options);
488
+ // Show a message to say we've done something
489
+ echo '<div class="updated fade similarposts-settings-saved"><p>' . __('Settings saved', 'similar_posts') . '</p></div>';
490
+ }
491
+ //now we drop into html to display the option page form
492
+ ?>
493
+ <div class="wrap similarposts-tab-content">
494
+ <h2><?php _e('Filter Settings', 'similar_posts'); ?></h2>
495
+ <form method="post" action="">
496
+ <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Filter Settings', 'similar_posts') ?>" /></div>
497
+ <table class="optiontable form-table">
498
+ <?php
499
+ ppl_display_excluded_posts($options['excluded_posts']);
500
+ ppl_display_included_posts($options['included_posts']);
501
+ ppl_display_authors($options['excluded_authors'], $options['included_authors']);
502
+ ppl_display_cats($options['excluded_cats'], $options['included_cats']);
503
+ ppl_display_tag_str($options['tag_str']);
504
+ ppl_display_custom($options['custom']);
505
+ ?>
506
+ </table>
507
+ <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Filter Settings', 'similar_posts') ?>" /></div>
508
+ <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-feed-update-options'); ?>
509
+ </form>
510
+ </div>
511
+ <?php
512
+ }
513
+
514
+ function similar_posts_feed_other_options_subpage(){
515
+ global $wpdb, $wp_version;
516
+ $options = get_option('similar-posts-feed');
517
+ if (isset($_POST['update_options'])) {
518
+ check_admin_referer('similar-posts-feed-update-options');
519
+ if (defined('POC_CACHE_4')) poc_cache_flush();
520
+ // Fill up the options with the values chosen...
521
+ $options = ppl_options_from_post($options, array('stripcodes', 'term_extraction', 'num_terms', 'weight_title', 'weight_content', 'weight_tags', 'hand_links'));
522
+ $wcontent = $options['weight_content'] + 0.0001;
523
+ $wtitle = $options['weight_title'] + 0.0001;
524
+ $wtags = $options['weight_tags'] + 0.0001;
525
+ $wcombined = $wcontent + $wtitle + $wtags;
526
+ $options['weight_content'] = $wcontent / $wcombined;
527
+ $options['weight_title'] = $wtitle / $wcombined;
528
+ $options['weight_tags'] = $wtags / $wcombined;
529
+ update_option('similar-posts-feed', $options);
530
+ // Show a message to say we've done something
531
+ echo '<div class="updated fade similarposts-settings-saved"><p>' . __('Settings saved', 'similar_posts') . '</p></div>';
532
+ }
533
+ //now we drop into html to display the option page form
534
+ ?>
535
+ <div class="wrap similarposts-tab-content">
536
+ <h2><?php _e('Other Settings', 'similar_posts'); ?></h2>
537
+ <form method="post" action="">
538
+ <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Other Settings', 'similar_posts') ?>" /></div>
539
+ <table class="optiontable form-table">
540
+ <?php
541
+ ppl_display_weights($options);
542
+ ppl_display_num_terms($options['num_terms']);
543
+ ppl_display_term_extraction($options['term_extraction']);
544
+ ppl_display_hand_links($options['hand_links']);
545
+ ppl_display_stripcodes($options['stripcodes']);
546
+ ?>
547
+ </table>
548
+ <div class="submit"><input type="submit" class="button button-primary" name="update_options" value="<?php _e('Save Other Settings', 'similar_posts') ?>" /></div>
549
+ <?php if (function_exists('wp_nonce_field')) wp_nonce_field('similar-posts-feed-update-options'); ?>
550
+ </form>
551
+ </div>
552
+ <?php
553
+ }
554
+
555
+
556
+ // sets up the index for the blog
557
+ function save_index_entries ($utf8=false, $use_stemmer='false', $batch=100, $cjk=false) {
558
+ global $wpdb, $table_prefix;
559
+ //$t0 = microtime(true);
560
+ $table_name = $table_prefix.'similar_posts';
561
+ $wpdb->query("TRUNCATE `$table_name`");
562
+ $termcount = 0;
563
+ $start = 0;
564
+ // in batches to conserve memory
565
+ while ($posts = $wpdb->get_results("SELECT `ID`, `post_title`, `post_content`, `post_type` FROM $wpdb->posts LIMIT $start, $batch", ARRAY_A)) {
566
+ foreach ($posts as $post) {
567
+ if ($post['post_type'] === 'revision') continue;
568
+ $content = sp_get_post_terms($post['post_content'], $utf8, $use_stemmer, $cjk);
569
+ $title = sp_get_title_terms($post['post_title'], $utf8, $use_stemmer, $cjk);
570
+ $postID = $post['ID'];
571
+ $tags = sp_get_tag_terms($postID, $utf8);
572
+ $wpdb->query("INSERT INTO `$table_name` (pID, content, title, tags) VALUES ($postID, \"$content\", \"$title\", \"$tags\")");
573
+ $termcount = $termcount + 1;
574
+ }
575
+ $start += $batch;
576
+ if (!ini_get('safe_mode')) set_time_limit(30);
577
+ }
578
+ unset($posts);
579
+ //$t = microtime(true) - $t0; echo "t = $t<br>";
580
+ return $termcount;
581
+ }
582
+
583
+ // this function gets called when the plugin is installed to set up the index and default options
584
+ function similar_posts_install() {
585
+ global $wpdb, $table_prefix;
586
+
587
+ $table_name = $table_prefix . 'similar_posts';
588
+ $errorlevel = error_reporting(0);
589
+ $suppress = $wpdb->hide_errors();
590
+ $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
591
+ `pID` bigint( 20 ) unsigned NOT NULL ,
592
+ `content` longtext NOT NULL ,
593
+ `title` text NOT NULL ,
594
+ `tags` text NOT NULL ,
595
+ FULLTEXT KEY `title` ( `title` ) ,
596
+ FULLTEXT KEY `content` ( `content` ) ,
597
+ FULLTEXT KEY `tags` ( `tags` )
598
+ ) ENGINE = MyISAM CHARSET = utf8;";
599
+ $wpdb->query($sql);
600
+ // MySQL before 4.1 doesn't recognise the character set properly, so if there's an error we can try without
601
+ if ($wpdb->last_error !== '') {
602
+ $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
603
+ `pID` bigint( 20 ) unsigned NOT NULL ,
604
+ `content` longtext NOT NULL ,
605
+ `title` text NOT NULL ,
606
+ `tags` text NOT NULL ,
607
+ FULLTEXT KEY `title` ( `title` ) ,
608
+ FULLTEXT KEY `content` ( `content` ) ,
609
+ FULLTEXT KEY `tags` ( `tags` )
610
+ ) ENGINE = MyISAM;";
611
+ $wpdb->query($sql);
612
+ }
613
+ $options = (array) get_option('similar-posts-feed');
614
+ // check each of the option values and, if empty, assign a default (doing it this long way
615
+ // lets us add new options in later versions)
616
+ if (!isset($options['limit'])) $options['limit'] = 5;
617
+ if (!isset($options['skip'])) $options['skip'] = 0;
618
+ if (!isset($options['age'])) {$options['age']['direction'] = 'none'; $options['age']['length'] = '0'; $options['age']['duration'] = 'month';}
619
+ if (!isset($options['divider'])) $options['divider'] = '';
620
+ if (!isset($options['omit_current_post'])) $options['omit_current_post'] = 'true';
621
+ if (!isset($options['show_private'])) $options['show_private'] = 'false';
622
+ if (!isset($options['show_pages'])) $options['show_pages'] = 'false';
623
+ if (!isset($options['show_attachments'])) $options['show_attachments'] = 'false';
624
+ // show_static is now show_pages
625
+ if ( isset($options['show_static'])) {$options['show_pages'] = $options['show_static']; unset($options['show_static']);};
626
+ if (!isset($options['none_text'])) $options['none_text'] = __('None Found', 'similar_posts');
627
+ if (!isset($options['no_text'])) $options['no_text'] = 'false';
628
+ if (!isset($options['tag_str'])) $options['tag_str'] = '';
629
+ if (!isset($options['excluded_cats'])) $options['excluded_cats'] = '';
630
+ if ($options['excluded_cats'] === '9999') $options['excluded_cats'] = '';
631
+ if (!isset($options['included_cats'])) $options['included_cats'] = '';
632
+ if ($options['included_cats'] === '9999') $options['included_cats'] = '';
633
+ if (!isset($options['excluded_authors'])) $options['excluded_authors'] = '';
634
+ if ($options['excluded_authors'] === '9999') $options['excluded_authors'] = '';
635
+ if (!isset($options['included_authors'])) $options['included_authors'] = '';
636
+ if ($options['included_authors'] === '9999') $options['included_authors'] = '';
637
+ if (!isset($options['included_posts'])) $options['included_posts'] = '';
638
+ if (!isset($options['excluded_posts'])) $options['excluded_posts'] = '';
639
+ if ($options['excluded_posts'] === '9999') $options['excluded_posts'] = '';
640
+ if (!isset($options['stripcodes'])) $options['stripcodes'] = array(array());
641
+ if (!isset($options['prefix'])) $options['prefix'] = 'Similar Posts:<ul>';
642
+ if (!isset($options['suffix'])) $options['suffix'] = '</ul>';
643
+ if (!isset($options['output_template'])) $options['output_template'] = '<li>{link}</li>';
644
+ if (!isset($options['match_cat'])) $options['match_cat'] = 'false';
645
+ if (!isset($options['match_tags'])) $options['match_tags'] = 'false';
646
+ if (!isset($options['match_author'])) $options['match_author'] = 'false';
647
+ if (!isset($options['custom'])) {$options['custom']['key'] = ''; $options['custom']['op'] = '='; $options['custom']['value'] = '';}
648
+ if (!isset($options['sort'])) {$options['sort']['by1'] = ''; $options['sort']['order1'] = SORT_ASC; $options['sort']['case1'] = 'false';$options['sort']['by2'] = ''; $options['sort']['order2'] = SORT_ASC; $options['sort']['case2'] = 'false';}
649
+ if (!isset($options['status'])) {$options['status']['publish'] = 'true'; $options['status']['private'] = 'false'; $options['status']['draft'] = 'false'; $options['status']['future'] = 'false';}
650
+ if (!isset($options['group_template'])) $options['group_template'] = '';
651
+ if (!isset($options['weight_content'])) $options['weight_content'] = 0.9;
652
+ if (!isset($options['weight_title'])) $options['weight_title'] = 0.1;
653
+ if (!isset($options['weight_tags'])) $options['weight_tags'] = 0.0;
654
+ if (!isset($options['num_terms'])) $options['num_terms'] = 20;
655
+ if (!isset($options['term_extraction'])) $options['term_extraction'] = 'frequency';
656
+ if (!isset($options['hand_links'])) $options['hand_links'] = 'false';
657
+ update_option('similar-posts-feed', $options);
658
+
659
+ $options = (array) get_option('similar-posts');
660
+ // check each of the option values and, if empty, assign a default (doing it this long way
661
+ // lets us add new options in later versions)
662
+ if (!isset($options['feed_active'])) $options['feed_active'] = 'false'; // deprecated
663
+ if (!isset($options['widget_condition'])) $options['widget_condition'] = '';
664
+ if (!isset($options['widget_parameters'])) $options['widget_parameters'] = '';
665
+ if (!isset($options['feed_on'])) $options['feed_on'] = 'false';
666
+ if (!isset($options['feed_priority'])) $options['feed_priority'] = '10';
667
+ if (!isset($options['feed_parameters'])) $options['feed_parameters'] = 'prefix=<strong>'.__('Similar Posts', 'similar-posts').':</strong><ul class="similar-posts">&suffix=</ul>';
668
+ if (!isset($options['append_on'])) $options['append_on'] = 'false';
669
+ if (!isset($options['append_priority'])) $options['append_priority'] = '10';
670
+ if (!isset($options['append_parameters'])) $options['append_parameters'] = 'prefix=<h3>'.__('Similar Posts', 'similar-posts').':</h3><ul class="similar-posts">&suffix=</ul>';
671
+ if (!isset($options['append_condition'])) $options['append_condition'] = 'is_single()';
672
+ if (!isset($options['limit'])) $options['limit'] = 5;
673
+ if (!isset($options['skip'])) $options['skip'] = 0;
674
+ if (!isset($options['age'])) {$options['age']['direction'] = 'none'; $options['age']['length'] = '0'; $options['age']['duration'] = 'month';}
675
+ if (!isset($options['divider'])) $options['divider'] = '';
676
+ if (!isset($options['omit_current_post'])) $options['omit_current_post'] = 'true';
677
+ if (!isset($options['show_private'])) $options['show_private'] = 'false';
678
+ if (!isset($options['show_pages'])) $options['show_pages'] = 'false';
679
+ if (!isset($options['show_attachments'])) $options['show_attachments'] = 'false';
680
+ // show_static is now show_pages
681
+ if ( isset($options['show_static'])) {$options['show_pages'] = $options['show_static']; unset($options['show_static']);};
682
+ if (!isset($options['none_text'])) $options['none_text'] = __('None Found', 'similar_posts');
683
+ if (!isset($options['no_text'])) $options['no_text'] = 'false';
684
+ if (!isset($options['tag_str'])) $options['tag_str'] = '';
685
+ if (!isset($options['excluded_cats'])) $options['excluded_cats'] = '';
686
+ if ($options['excluded_cats'] === '9999') $options['excluded_cats'] = '';
687
+ if (!isset($options['included_cats'])) $options['included_cats'] = '';
688
+ if ($options['included_cats'] === '9999') $options['included_cats'] = '';
689
+ if (!isset($options['excluded_authors'])) $options['excluded_authors'] = '';
690
+ if ($options['excluded_authors'] === '9999') $options['excluded_authors'] = '';
691
+ if (!isset($options['included_authors'])) $options['included_authors'] = '';
692
+ if ($options['included_authors'] === '9999') $options['included_authors'] = '';
693
+ if (!isset($options['included_posts'])) $options['included_posts'] = '';
694
+ if (!isset($options['excluded_posts'])) $options['excluded_posts'] = '';
695
+ if ($options['excluded_posts'] === '9999') $options['excluded_posts'] = '';
696
+ if (!isset($options['stripcodes'])) $options['stripcodes'] = array(array());
697
+ if (!isset($options['prefix'])) $options['prefix'] = '<ul>';
698
+ if (!isset($options['suffix'])) $options['suffix'] = '</ul>';
699
+ if (!isset($options['output_template'])) $options['output_template'] = '<li>{link}</li>';
700
+ if (!isset($options['match_cat'])) $options['match_cat'] = 'false';
701
+ if (!isset($options['match_tags'])) $options['match_tags'] = 'false';
702
+ if (!isset($options['match_author'])) $options['match_author'] = 'false';
703
+ if (!isset($options['content_filter'])) $options['content_filter'] = 'false';
704
+ if (!isset($options['custom'])) {$options['custom']['key'] = ''; $options['custom']['op'] = '='; $options['custom']['value'] = '';}
705
+ if (!isset($options['sort'])) {$options['sort']['by1'] = ''; $options['sort']['order1'] = SORT_ASC; $options['sort']['case1'] = 'false';$options['sort']['by2'] = ''; $options['sort']['order2'] = SORT_ASC; $options['sort']['case2'] = 'false';}
706
+ if (!isset($options['status'])) {$options['status']['publish'] = 'true'; $options['status']['private'] = 'false'; $options['status']['draft'] = 'false'; $options['status']['future'] = 'false';}
707
+ if (!isset($options['group_template'])) $options['group_template'] = '';
708
+ if (!isset($options['weight_content'])) $options['weight_content'] = 0.9;
709
+ if (!isset($options['weight_title'])) $options['weight_title'] = 0.1;
710
+ if (!isset($options['weight_tags'])) $options['weight_tags'] = 0.0;
711
+ if (!isset($options['num_terms'])) $options['num_terms'] = 20;
712
+ if (!isset($options['term_extraction'])) $options['term_extraction'] = 'frequency';
713
+ if (!isset($options['hand_links'])) $options['hand_links'] = 'false';
714
+ if (!isset($options['utf8'])) $options['utf8'] = 'false';
715
+ if (!function_exists('mb_internal_encoding')) $options['utf8'] = 'false';
716
+ if (!isset($options['cjk'])) $options['cjk'] = 'false';
717
+ if (!function_exists('mb_internal_encoding')) $options['cjk'] = 'false';
718
+ if (!isset($options['use_stemmer'])) $options['use_stemmer'] = 'false';
719
+ if (!isset($options['batch'])) $options['batch'] = '100';
720
+
721
+ update_option('similar-posts', $options);
722
+
723
+ // initial creation of the index, if the table is empty
724
+ $num_index_posts = $wpdb->get_var("SELECT COUNT(*) FROM `$table_name`");
725
+ if ($num_index_posts == 0) save_index_entries (($options['utf8'] === 'true'), 'false', $options['batch'], ($options['cjk'] === 'true'));
726
+
727
+ // deactivate legacy Similar Posts Feed if present
728
+ $current = get_option('active_plugins');
729
+ if (in_array('Similar_Posts_Feed/similar-posts-feed.php', $current)) {
730
+ array_splice($current, array_search('Similar_Posts_Feed/similar-posts-feed.php', $current), 1);
731
+ update_option('active_plugins', $current);
732
+ }
733
+ unset($current);
734
+
735
+ // clear legacy custom fields
736
+ $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_key = 'similarterms'");
737
+
738
+ // clear legacy index
739
+ $indices = $wpdb->get_results("SHOW INDEX FROM $wpdb->posts", ARRAY_A);
740
+ foreach ($indices as $index) {
741
+ if ($index['Key_name'] === 'post_similar') {
742
+ $wpdb->query("ALTER TABLE $wpdb->posts DROP INDEX post_similar");
743
+ break;
744
+ }
745
+ }
746
+
747
+ $wpdb->show_errors($suppress);
748
+ error_reporting($errorlevel);
749
+ }
750
+
751
+
752
+
753
+ if (!function_exists('ppl_plugin_basename')) {
754
+ if ( !defined('WP_PLUGIN_DIR') ) define( 'WP_PLUGIN_DIR', ABSPATH . 'wp-content/plugins' );
755
+ function ppl_plugin_basename($file) {
756
+ $file = str_replace('\\','/',$file); // sanitize for Win32 installs
757
+ $file = preg_replace('|/+|','/', $file); // remove any duplicate slash
758
+ $plugin_dir = str_replace('\\','/',WP_PLUGIN_DIR); // sanitize for Win32 installs
759
+ $plugin_dir = preg_replace('|/+|','/', $plugin_dir); // remove any duplicate slash
760
+ $file = preg_replace('|^' . preg_quote($plugin_dir, '|') . '/|','',$file); // get relative path from plugins dir
761
+ return $file;
762
+ }
763
+ }
764
+
765
+ add_action('activate_'.str_replace('-admin', '', ppl_plugin_basename(__FILE__)), 'similar_posts_install');
similar-posts.php CHANGED
@@ -1,646 +1,665 @@
1
- <?php
2
- /*
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: 3.1.5
7
- Author: Shareaholic
8
- Author URI: https://www.shareaholic.com
9
- Text Domain: similar-posts
10
- */
11
-
12
-
13
- /*
14
- Template Tag: Displays the posts most similar to the current post.
15
- e.g.: <?php similar_posts(); ?>
16
- */
17
-
18
- function similar_posts($args = '') {
19
- echo SimilarPosts::execute($args);
20
- }
21
-
22
- function similar_posts_mark_current(){
23
- global $post, $similar_posts_current_ID;
24
- $similar_posts_current_ID = $post->ID;
25
- }
26
-
27
- define ('POST_PLUGIN_LIBRARY', true);
28
-
29
- if ( ! defined( 'WP_CONTENT_URL' ) )
30
- define( 'WP_CONTENT_URL', get_option( 'siteurl' ) . '/wp-content' );
31
- if ( ! defined( 'WP_CONTENT_DIR' ) )
32
- define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
33
- if ( ! defined( 'WP_PLUGIN_URL' ) )
34
- define( 'WP_PLUGIN_URL', WP_CONTENT_URL. '/plugins' );
35
- if ( ! defined( 'WP_PLUGIN_DIR' ) )
36
- define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
37
-
38
- if (!defined('CF_LIBRARY')) require(WP_PLUGIN_DIR.'/similar-posts/common_functions.php');
39
- if (!defined('ACF_LIBRARY')) require(WP_PLUGIN_DIR.'/similar-posts/admin_common_functions.php');
40
- if (!defined('OT_LIBRARY')) require(WP_PLUGIN_DIR.'/similar-posts/output_tags.php');
41
- if (!defined('ADMIN_SUBPAGES_LIBRARY')) require(WP_PLUGIN_DIR.'/similar-posts/admin-subpages.php');
42
-
43
- if (!defined('DSEP')) define('DSEP', DIRECTORY_SEPARATOR);
44
- if (!defined('POST_PLUGIN_LIBRARY')) SimilarPosts::install_post_plugin_library();
45
-
46
- $similar_posts_current_ID = -1;
47
-
48
- class SimilarPosts {
49
- static $version = 0;
50
-
51
- static function get_plugin_version() {
52
- $plugin_data = get_file_data(__FILE__, array('version' => 'Version'), 'plugin');
53
- SimilarPosts::$version = $plugin_data['version'];
54
-
55
- return $plugin_data['version'];
56
- } // get_plugin_version
57
-
58
- // check if plugin's admin page is shown
59
- static function is_plugin_admin_page($page = 'settings') {
60
- $current_screen = get_current_screen();
61
-
62
- if ($page == 'settings' && $current_screen->id == 'settings_page_similar-posts') {
63
- return true;
64
- }
65
-
66
- return false;
67
- } // is_plugin_admin_page
68
-
69
- // add settings link to plugins page
70
- static function plugin_action_links($links) {
71
- $settings_link = '<a href="' . admin_url('options-general.php?page=similar-posts') . '" title="Settings for Similar Posts">Settings</a>';
72
-
73
- array_unshift($links, $settings_link);
74
-
75
- return $links;
76
- } // plugin_action_links
77
-
78
-
79
- static function execute($args='', $default_output_template='<li>{link}</li>', $option_key='similar-posts'){
80
- global $table_prefix, $wpdb, $wp_version, $similar_posts_current_ID;
81
- $start_time = ppl_microtime();
82
- $postid = ppl_current_post_id($similar_posts_current_ID);
83
- if (defined('POC_CACHE_4')) {
84
- $cache_key = $option_key.$postid.$args;
85
- $result = poc_cache_fetch($cache_key);
86
- if ($result !== false) return $result . sprintf("<!-- Similar Posts took %.3f ms (cached) -->", 1000 * (ppl_microtime() - $start_time));
87
- }
88
- $table_name = $table_prefix . 'similar_posts';
89
- // First we process any arguments to see if any defaults have been overridden
90
- $options = ppl_parse_args($args);
91
- // Next we retrieve the stored options and use them unless a value has been overridden via the arguments
92
- $options = ppl_set_options($option_key, $options, $default_output_template);
93
- if (0 < $options['limit']) {
94
- $match_tags = ($options['match_tags'] !== 'false' && $wp_version >= 2.3);
95
- $exclude_cats = ($options['excluded_cats'] !== '');
96
- $include_cats = ($options['included_cats'] !== '');
97
- $exclude_authors = ($options['excluded_authors'] !== '');
98
- $include_authors = ($options['included_authors'] !== '');
99
- $exclude_posts = (trim($options['excluded_posts']) !== '');
100
- $include_posts = (trim($options['included_posts']) !== '');
101
- $match_category = ($options['match_cat'] === 'true');
102
- $match_author = ($options['match_author'] === 'true');
103
- $use_tag_str = ('' != trim($options['tag_str']) && $wp_version >= 2.3);
104
- $omit_current_post = ($options['omit_current_post'] !== 'false');
105
- $hide_pass = ($options['show_private'] === 'false');
106
- $check_age = ('none' !== $options['age']['direction']);
107
- $check_custom = (trim($options['custom']['key']) !== '');
108
- $limit = $options['skip'].', '.$options['limit'];
109
-
110
- //get the terms to do the matching
111
- if ($options['term_extraction'] === 'pagerank') {
112
- list( $contentterms, $titleterms, $tagterms) = sp_terms_by_textrank($postid, $options['num_terms']);
113
- } else {
114
- list( $contentterms, $titleterms, $tagterms) = sp_terms_by_freq($postid, $options['num_terms']);
115
- }
116
- // these should add up to 1.0
117
- $weight_content = $options['weight_content'];
118
- $weight_title = $options['weight_title'];
119
- $weight_tags = $options['weight_tags'];
120
- // below a threshold we ignore the weight completely and save some effort
121
- if ($weight_content < 0.001) $weight_content = (int) 0;
122
- if ($weight_title < 0.001) $weight_title = (int) 0;
123
- if ($weight_tags < 0.001) $weight_tags = (int) 0;
124
-
125
- $count_content = substr_count($contentterms, ' ') + 1;
126
- $count_title = substr_count($titleterms, ' ') + 1;
127
- $count_tags = substr_count($tagterms, ' ') + 1;
128
- if ($weight_content) $weight_content = 57.0 * $weight_content / $count_content;
129
- if ($weight_title) $weight_title = 18.0 * $weight_title / $count_title;
130
- if ($weight_tags) $weight_tags = 24.0 * $weight_tags / $count_tags;
131
- if ($options['hand_links'] === 'true') {
132
- // check custom field for manual links
133
- $forced_ids = $wpdb->get_var("SELECT meta_value FROM $wpdb->postmeta WHERE post_id = $postid AND meta_key = 'sp_similar' ") ;
134
- } else {
135
- $forced_ids = '';
136
- }
137
- // the workhorse...
138
- $sql = "SELECT *, ";
139
- $sql .= score_fulltext_match($table_name, $weight_title, $titleterms, $weight_content, $contentterms, $weight_tags, $tagterms, $forced_ids);
140
-
141
- if ($check_custom) $sql .= "LEFT JOIN $wpdb->postmeta ON post_id = ID ";
142
-
143
- // build the 'WHERE' clause
144
- $where = array();
145
- $where[] = where_fulltext_match($weight_title, $titleterms, $weight_content, $contentterms, $weight_tags, $tagterms);
146
- if (!function_exists('get_post_type')) {
147
- $where[] = where_hide_future();
148
- } else {
149
- $where[] = where_show_status($options['status'], $options['show_attachments']);
150
- }
151
- if ($match_category) $where[] = where_match_category();
152
- if ($match_tags) $where[] = where_match_tags($options['match_tags']);
153
- if ($match_author) $where[] = where_match_author();
154
- $where[] = where_show_pages($options['show_pages'], $options['show_attachments']);
155
- if ($include_cats) $where[] = where_included_cats($options['included_cats']);
156
- if ($exclude_cats) $where[] = where_excluded_cats($options['excluded_cats']);
157
- if ($exclude_authors) $where[] = where_excluded_authors($options['excluded_authors']);
158
- if ($include_authors) $where[] = where_included_authors($options['included_authors']);
159
- if ($exclude_posts) $where[] = where_excluded_posts(trim($options['excluded_posts']));
160
- if ($include_posts) $where[] = where_included_posts(trim($options['included_posts']));
161
- if ($use_tag_str) $where[] = where_tag_str($options['tag_str']);
162
- if ($omit_current_post) $where[] = where_omit_post($similar_posts_current_ID);
163
- if ($hide_pass) $where[] = where_hide_pass();
164
- if ($check_age) $where[] = where_check_age($options['age']['direction'], $options['age']['length'], $options['age']['duration']);
165
- if ($check_custom) $where[] = where_check_custom($options['custom']['key'], $options['custom']['op'], $options['custom']['value']);
166
- $sql .= "WHERE ".implode(' AND ', $where);
167
- if ($check_custom) $sql .= " GROUP BY $wpdb->posts.ID";
168
- $sql .= " ORDER BY score DESC, post_date DESC LIMIT $limit";
169
- //echo $sql;
170
- $results = $wpdb->get_results($sql);
171
- } else {
172
- $results = false;
173
- }
174
- if ($results) {
175
- $translations = ppl_prepare_template($options['output_template']);
176
- foreach ($results as $result) {
177
- $items[] = ppl_expand_template($result, $options['output_template'], $translations, $option_key);
178
- }
179
- if ($options['sort']['by1'] !== '') $items = ppl_sort_items($options['sort'], $results, $option_key, $options['group_template'], $items);
180
- $output = implode(($options['divider']) ? $options['divider'] : "\n", $items);
181
- $output = $options['prefix'] . $output . $options['suffix'];
182
- } else {
183
- // if we reach here our query has produced no output ... so what next?
184
- if ($options['no_text'] !== 'false') {
185
- $output = ''; // we display nothing at all
186
- } else {
187
- // we display the blank message, with tags expanded if necessary
188
- $translations = ppl_prepare_template($options['none_text']);
189
- $output = $options['prefix'] . ppl_expand_template(array(), $options['none_text'], $translations, $option_key) . $options['suffix'];
190
- }
191
- }
192
- if (defined('POC_CACHE_4')) poc_cache_store($cache_key, $output);
193
- return ($output) ? $output . sprintf("<!-- Similar Posts took %.3f ms -->", 1000 * (ppl_microtime() - $start_time)) : '';
194
- }
195
-
196
- // save some info
197
- static function activate() {
198
- $options = get_option('similar_posts_meta', array());
199
-
200
- if (empty($options['first_version'])) {
201
- $options['first_version'] = SimilarPosts::get_plugin_version();
202
- $options['first_install'] = current_time('timestamp');
203
- update_option('similar_posts_meta', $options);
204
- }
205
- } // activate
206
-
207
- } // similarposts class
208
-
209
- function sp_terms_by_freq($ID, $num_terms = 20) {
210
- if (!$ID) return array('', '', '');
211
- global $wpdb, $table_prefix;
212
- $table_name = $table_prefix . 'similar_posts';
213
- $terms = '';
214
- $results = $wpdb->get_results("SELECT title, content, tags FROM $table_name WHERE pID=$ID LIMIT 1", ARRAY_A);
215
- if ($results) {
216
- $word = strtok($results[0]['content'], ' ');
217
- $n = 0;
218
- $wordtable = array();
219
- while ($word !== false) {
220
- if(!array_key_exists($word,$wordtable)){
221
- $wordtable[$word]=0;
222
- }
223
- $wordtable[$word] += 1;
224
- $word = strtok(' ');
225
- }
226
- arsort($wordtable);
227
- if ($num_terms < 1) $num_terms = 1;
228
- $wordtable = array_slice($wordtable, 0, $num_terms);
229
-
230
- foreach ($wordtable as $word => $count) {
231
- $terms .= ' ' . $word;
232
- }
233
-
234
- $res[] = $terms;
235
- $res[] = $results[0]['title'];
236
- $res[] = $results[0]['tags'];
237
- }
238
- return $res;
239
- }
240
-
241
-
242
- // adapted PageRank algorithm see http://www.cs.unt.edu/~rada/papers/mihalcea.emnlp04.pdf
243
- // and the weighted version http://www.cs.unt.edu/~rada/papers/hassan.ieee07.pdf
244
- function sp_terms_by_textrank($ID, $num_terms = 20) {
245
- global $wpdb, $table_prefix;
246
- $table_name = $table_prefix . 'similar_posts';
247
- $terms = '';
248
- $results = $wpdb->get_results("SELECT title, content, tags FROM $table_name WHERE pID=$ID LIMIT 1", ARRAY_A);
249
- if ($results) {
250
- // build a directed graph with words as vertices and, as edges, the words which precede them
251
- $prev_word = 'aaaaa';
252
- $graph = array();
253
- $word = strtok($results[0]['content'], ' ');
254
- while ($word !== false) {
255
- $graph[$word][$prev_word] += 1; // list the incoming words and keep a tally of how many times words co-occur
256
- $out_edges[$prev_word] += 1; // count the number of different words that follow each word
257
- $prev_word = $word;
258
- $word = strtok(' ');
259
- }
260
- // initialise the list of PageRanks-- one for each unique word
261
- foreach($graph as $vertex => $in_edges) {
262
- $oldrank[$vertex] = 0.25;
263
- }
264
- $n = count($graph);
265
- if ($n > 0) {
266
- $base = 0.15 / $n;
267
- $error_margin = $n * 0.005;
268
- do {
269
- $error = 0.0;
270
- // the edge-weighted PageRank calculation
271
- foreach($graph as $vertex => $in_edges) {
272
- $r = 0;
273
- foreach($in_edges as $edge => $weight) {
274
- $r += ($weight * $oldrank[$edge]) / $out_edges[$edge];
275
- }
276
- $rank[$vertex] = $base + 0.95 * $r;
277
- $error += abs($rank[$vertex] - $oldrank[$vertex]);
278
- }
279
- $oldrank = $rank;
280
- //echo $error . '<br>';
281
- } while ($error > $error_margin);
282
- arsort($rank);
283
- if ($num_terms < 1) $num_terms = 1;
284
- $rank = array_slice($rank, 0, $num_terms);
285
- foreach ($rank as $vertex => $score) {
286
- $terms .= ' ' . $vertex;
287
- }
288
- }
289
- $res[] = $terms;
290
- $res[] = $results[0]['title'];
291
- $res[] = $results[0]['tags'];
292
- }
293
- return $res;
294
- }
295
-
296
- function sp_save_index_entry($postID) {
297
- global $wpdb, $table_prefix;
298
- $table_name = $table_prefix . 'similar_posts';
299
- $post = $wpdb->get_row("SELECT post_content, post_title, post_type FROM $wpdb->posts WHERE ID = $postID", ARRAY_A);
300
- if ($post['post_type'] === 'revision') return $postID;
301
- //extract its terms
302
- $options = get_option('similar-posts');
303
- $utf8 = ($options['utf8'] === 'true');
304
- $cjk = ($options['cjk'] === 'true');
305
- $content = sp_get_post_terms($post['post_content'], $utf8, $options['use_stemmer'], $cjk);
306
- $title = sp_get_title_terms($post['post_title'], $utf8, $options['use_stemmer'], $cjk);
307
- $tags = sp_get_tag_terms($postID, $utf8);
308
- //check to see if the field is set
309
- $pid = $wpdb->get_var("SELECT pID FROM $table_name WHERE pID=$postID limit 1");
310
- //then insert if empty
311
- if (is_null($pid)) {
312
- $wpdb->query("INSERT INTO $table_name (pID, content, title, tags) VALUES ($postID, \"$content\", \"$title\", \"$tags\")");
313
- } else {
314
- $wpdb->query("UPDATE $table_name SET content=\"$content\", title=\"$title\", tags=\"$tags\" WHERE pID=$postID" );
315
- }
316
- return $postID;
317
- }
318
-
319
- function sp_delete_index_entry($postID) {
320
- global $wpdb, $table_prefix;
321
- $table_name = $table_prefix . 'similar_posts';
322
- $wpdb->query("DELETE FROM $table_name WHERE pID = $postID ");
323
- return $postID;
324
- }
325
-
326
- function sp_clean_words($text) {
327
- $text = strip_tags($text);
328
- $text = strtolower($text);
329
- $text = str_replace("’", "'", $text); // convert MSWord apostrophe
330
- $text = preg_replace(array('/\[(.*?)\]/', '/&[^\s;]+;/', '/‘|’|—|“|”|–|…/', "/'\W/"), ' ', $text); //anything in [..] or any entities or MS Word droppings
331
- return $text;
332
- }
333
-
334
- function sp_mb_clean_words($text) {
335
- mb_regex_encoding('UTF-8');
336
- mb_internal_encoding('UTF-8');
337
- $text = strip_tags($text);
338
- $text = mb_strtolower($text);
339
- $text = str_replace("’", "'", $text); // convert MSWord apostrophe
340
- $text = preg_replace(array('/\[(.*?)\]/u', '/&[^\s;]+;/u', '/‘|’|—|“|”|–|…/u', "/'\W/u"), ' ', $text); //anything in [..] or any entities
341
- return $text;
342
- }
343
-
344
- function sp_mb_str_pad($text, $n, $c) {
345
- mb_internal_encoding('UTF-8');
346
- $l = mb_strlen($text);
347
- if ($l > 0 && $l < $n) {
348
- $text .= str_repeat($c, $n-$l);
349
- }
350
- return $text;
351
- }
352
-
353
- function sp_cjk_digrams($string) {
354
- mb_internal_encoding("UTF-8");
355
- $strlen = mb_strlen($string);
356
- $ascii = '';
357
- $prev = '';
358
- $result = array();
359
- for ($i = 0; $i < $strlen; $i++) {
360
- $c = mb_substr($string, $i, 1);
361
- // single-byte chars get combined
362
- if (strlen($c) > 1) {
363
- if ($ascii) {
364
- $result[] = $ascii;
365
- $ascii = '';
366
- $prev = $c;
367
- } else {
368
- $result[] = sp_mb_str_pad($prev.$c, 4, '_');
369
- $prev = $c;
370
- }
371
- } else {
372
- $ascii .= $c;
373
- }
374
- }
375
- if ($ascii) $result[] = $ascii;
376
- return implode(' ', $result);
377
- }
378
-
379
- function sp_get_post_terms($text, $utf8, $use_stemmer, $cjk) {
380
- global $overusedwords;
381
- if ($utf8) {
382
- mb_regex_encoding('UTF-8');
383
- mb_internal_encoding('UTF-8');
384
- $wordlist = mb_split("\W+", sp_mb_clean_words($text));
385
- $words = '';
386
- foreach ($wordlist as $word) {
387
- if ( mb_strlen($word) > 3 && !isset($overusedwords[$word])) {
388
- switch ($use_stemmer) {
389
- case 'true':
390
- $words .= sp_mb_str_pad(stem($word), 4, '_') . ' ';
391
- break;
392
- case 'fuzzy':
393
- $words .= sp_mb_str_pad(metaphone($word), 4, '_') . ' ';
394
- break;
395
- case 'false':
396
- default:
397
- $words .= $word . ' ';
398
- }
399
- }
400
- }
401
- } else {
402
- $wordlist = str_word_count(sp_clean_words($text), 1);
403
- $words = '';
404
- foreach ($wordlist as $word) {
405
- if ( strlen($word) > 3 && !isset($overusedwords[$word])) {
406
- switch ($use_stemmer) {
407
- case 'true':
408
- $words .= str_pad(stem($word), 4, '_') . ' ';
409
- break;
410
- case 'fuzzy':
411
- $words .= str_pad(metaphone($word), 4, '_') . ' ';
412
- break;
413
- case 'false':
414
- default:
415
- $words .= $word . ' ';
416
- }
417
- }
418
- }
419
- }
420
- if ($cjk) $words = sp_cjk_digrams($words);
421
- return $words;
422
- }
423
-
424
- $tinywords = array('the' => 1, 'and' => 1, 'of' => 1, 'a' => 1, 'for' => 1, 'on' => 1);
425
-
426
- function sp_get_title_terms($text, $utf8, $use_stemmer, $cjk) {
427
- global $tinywords;
428
- if ($utf8) {
429
- mb_regex_encoding('UTF-8');
430
- mb_internal_encoding('UTF-8');
431
- $wordlist = mb_split("\W+", sp_mb_clean_words($text));
432
- $words = '';
433
- foreach ($wordlist as $word) {
434
- if (!isset($tinywords[$word])) {
435
- switch ($use_stemmer) {
436
- case 'true':
437
- $words .= sp_mb_str_pad(stem($word), 4, '_') . ' ';
438
- break;
439
- case 'fuzzy':
440
- $words .= sp_mb_str_pad(metaphone($word), 4, '_') . ' ';
441
- break;
442
- case 'false':
443
- default:
444
- $words .= sp_mb_str_pad($word, 4, '_') . ' ';
445
- }
446
- }
447
- }
448
- } else {
449
- $wordlist = str_word_count(sp_clean_words($text), 1);
450
- $words = '';
451
- foreach ($wordlist as $word) {
452
- if (!isset($tinywords[$word])) {
453
- switch ($use_stemmer) {
454
- case 'true':
455
- $words .= str_pad(stem($word), 4, '_') . ' ';
456
- break;
457
- case 'fuzzy':
458
- $words .= str_pad(metaphone($word), 4, '_') . ' ';
459
- break;
460
- case 'false':
461
- default:
462
- $words .= str_pad($word, 4, '_') . ' ';
463
- }
464
- }
465
- }
466
- }
467
- if ($cjk) $words = sp_cjk_digrams($words);
468
- return $words;
469
- }
470
-
471
- function sp_get_tag_terms($ID, $utf8) {
472
- global $wpdb;
473
- if (!function_exists('get_object_term_cache')) return '';
474
- $tags = array();
475
- $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'";
476
- $tags = $wpdb->get_col($query);
477
- if (!empty ($tags)) {
478
- if ($utf8) {
479
- mb_internal_encoding('UTF-8');
480
- foreach ($tags as $tag) {
481
- $newtags[] = sp_mb_str_pad(mb_strtolower(str_replace('"', "'", $tag)), 4, '_');
482
- }
483
- } else {
484
- foreach ($tags as $tag) {
485
- $newtags[] = str_pad(strtolower(str_replace('"', "'", $tag)), 4, '_');
486
- }
487
- }
488
- $newtags = str_replace(' ', '_', $newtags);
489
- $tags = implode (' ', $newtags);
490
- } else {
491
- $tags = '';
492
- }
493
- return $tags;
494
- }
495
-
496
- if ( is_admin() ) {
497
- require(dirname(__FILE__).'/similar-posts-admin.php');
498
- }
499
-
500
- function widget_rrm_similar_posts_init() {
501
- if (! function_exists("register_sidebar_widget")) {
502
- return;
503
- }
504
- function widget_rrm_similar_posts($args) {
505
- extract($args);
506
- $options = get_option('widget_rrm_similar_posts');
507
- $opt = get_option('similar-posts');
508
- $widget_condition = $opt['widget_condition'];
509
- // the condition specified in the widget control overrides the placement setting screen
510
- if ($options['condition']) {
511
- $condition = $options['condition'];
512
- } else {
513
- if ($widget_condition) {
514
- $condition = $widget_condition;
515
- } else {
516
- $condition = 'true';
517
- }
518
- }
519
- $condition = (stristr($condition, "return")) ? $condition : "return ".$condition;
520
- $condition = rtrim($condition, '; ') . ' || is_admin();';
521
- if (eval($condition)) {
522
- $title = empty($options['title']) ? __('Similar Posts', 'similar_posts') : $options['title'];
523
- if ( !$number = (int) $options['number'] )
524
- $number = 10;
525
- else if ( $number < 1 )
526
- $number = 1;
527
- else if ( $number > 15 )
528
- $number = 15;
529
- $options = get_option('recent-posts');
530
- $widget_parameters = $options['widget_parameters'];
531
- $output = SimilarPosts::execute('limit='.$number.'&'.$widget_parameters);
532
- if ($output) {
533
- echo $before_widget;
534
- echo $before_title.$title.$after_title;
535
- echo $output;
536
- echo $after_widget;
537
- }
538
- }
539
- }
540
- function widget_rrm_similar_posts_control() {
541
- if ( isset($_POST['widget_rrm_similar_posts_submit']) ) {
542
- $options['title'] = strip_tags(stripslashes($_POST['widget_rrm_similar_posts_title']));
543
- $options['number'] = (int) $_POST["widget_rrm_similar_posts_number"];
544
- $options['condition'] = stripslashes(trim($_POST["widget_rrm_similar_posts_condition"], '; '));
545
- update_option("widget_rrm_similar_posts", $options);
546
- } else {
547
- $options = get_option('widget_rrm_similar_posts');
548
- }
549
- $title = esc_attr($options['title']);
550
- if ( !$number = (int) $options['number'] )
551
- $number = 5;
552
- $condition = esc_attr($options['condition']);
553
- ?>
554
- <p><label for="widget_rrm_similar_posts_title"> <?php _e('Title:', 'similar_posts'); ?> <input style="width: 200px;" id="widget_rrm_similar_posts_title" name="widget_rrm_similar_posts_title" type="text" value="<?php echo $title; ?>" /></label></p>
555
- <p><label for="widget_rrm_similar_posts_number"> <?php _e('Number of posts to show:', 'similar_posts'); ?> <input style="width: 50px; text-align: center;" id="widget_rrm_similar_posts_number" name="widget_rrm_similar_posts_number" type="number" value="<?php echo $number; ?>" /></label> <?php _e('(at most 15)', 'similar_posts'); ?> </p>
556
- <p><label for="widget_rrm_similar_posts_condition"> <?php echo sprintf(__('Show only if page: (e.g., %sis_single()%s)', 'similar_posts'), '<a href="http://codex.wordpress.org/Conditional_Tags" title="help">', '</a>'); ?> <input style="width: 200px;" id="widget_rrm_similar_posts_condition" name="widget_rrm_similar_posts_condition" type="text" value="<?php echo $condition; ?>" /></label></p>
557
- <input type="hidden" id="widget_rrm_similar_posts_submit" name="widget_rrm_similar_posts_submit" value="1" />
558
- There are many more <a href="options-general.php?page=similar-posts.php">options</a> available.
559
- <?php
560
- }
561
- wp_register_sidebar_widget('similar_posts_widget', __('Similar Posts', 'similar_posts'), 'widget_rrm_similar_posts');
562
- wp_register_widget_control('similar_posts_widget', __('Similar Posts', 'similar_posts'), 'widget_rrm_similar_posts_control', 300, 100);
563
- }
564
-
565
- add_action('plugins_loaded', 'widget_rrm_similar_posts_init');
566
-
567
-
568
- /*
569
- now some language specific stuff
570
- */
571
-
572
- //the next lines find the language WordPress is using
573
- if(defined('WPLANG')){
574
- $language = substr(WPLANG, 0, 2);
575
- } else {
576
- $language = '';
577
- }
578
- //if no language is specified make it the default which is 'en'
579
- if ($language == '') {
580
- $language = 'en';
581
- }
582
- $languagedir = dirname(__FILE__).DSEP.'languages'.DSEP.$language.DSEP;
583
- //see if the directory exists and if not revert to the default English dir
584
- if (!file_exists($languagedir)) {
585
- $languagedir = dirname(__FILE__).DSEP.'languages'.DSEP.'en'.DSEP;
586
- }
587
-
588
- // import the stemming algorithm ... a single function called 'stem'
589
- require_once($languagedir.'stemmer.php');
590
- require_once($languagedir.'stopwords.php');
591
-
592
-
593
- global $overusedwords;
594
- if(is_array($overusedwords)) {
595
- $overusedwords = array_flip($overusedwords);
596
- }
597
-
598
- // do not try and use this function directly -- it is automatically installed when the option is set to show similar posts in feeds // moreover it is deprecated and going soon
599
- function similar_posts_for_feed($content) {
600
- return (is_feed()) ? $content . SimilarPosts::execute('', '<li>{link}</li>', 'similar-posts-feed') : $content;
601
- }
602
-
603
- function similar_posts_wp_admin_style() {
604
- if (SimilarPosts::is_plugin_admin_page('settings')) {
605
- wp_register_style( 'similar-posts-admin', plugins_url('', __FILE__) . '/css/similar-posts-admin.css', false, SimilarPosts::$version );
606
- wp_enqueue_style( 'similar-posts-admin' );
607
- }
608
- }
609
-
610
-
611
-
612
- function similar_posts_init () {
613
- global $overusedwords, $wp_db_version;
614
- load_plugin_textdomain('similar_posts');
615
-
616
- SimilarPosts::get_plugin_version();
617
-
618
- $options = get_option('similar-posts');
619
- if ($options['feed_active'] === 'true') add_filter('the_content', 'similar_posts_for_feed');
620
- if ($options['content_filter'] === 'true' && function_exists('ppl_register_content_filter')) ppl_register_content_filter('SimilarPosts');
621
- if ($options['feed_on'] === 'true' && function_exists('ppl_register_post_filter')) ppl_register_post_filter('feed', 'similar-posts', 'SimilarPosts');
622
- if ($options['append_condition']) {
623
- $condition = $options['append_condition'];
624
- } else {
625
- $condition = 'true';
626
- }
627
- $condition = (stristr($condition, "return")) ? $condition : "return ".$condition;
628
- $condition = rtrim($condition, '; ') . ';';
629
- if ($options['append_on'] === 'true' && function_exists('ppl_register_post_filter')) ppl_register_post_filter('append', 'similar-posts', 'SimilarPosts', $condition);
630
-
631
- //install the actions to keep the index up to date
632
- add_action('save_post', 'sp_save_index_entry', 1);
633
- add_action('delete_post', 'sp_delete_index_entry', 1);
634
- if ($wp_db_version < 3308 ) {
635
- add_action('edit_post', 'sp_save_index_entry', 1);
636
- add_action('publish_post', 'sp_save_index_entry', 1);
637
- }
638
- add_action( 'admin_enqueue_scripts', 'similar_posts_wp_admin_style' );
639
-
640
- // aditional links in plugin description
641
- add_filter('plugin_action_links_' . basename(dirname(__FILE__)) . '/' . basename(__FILE__),
642
- array('SimilarPosts', 'plugin_action_links'));
643
- } // init
644
-
645
- add_action ('init', 'similar_posts_init', 1);
646
- register_activation_hook(__FILE__, array('SimilarPosts', 'activate'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
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: 3.1.6
7
+ Author: Shareaholic
8
+ Author URI: https://www.shareaholic.com
9
+ Text Domain: similar-posts
10
+ */
11
+
12
+
13
+ /*
14
+ Template Tag: Displays the posts most similar to the current post.
15
+ e.g.: <?php similar_posts(); ?>
16
+ */
17
+
18
+ function similar_posts($args = '') {
19
+ echo SimilarPosts::execute($args);
20
+ }
21
+
22
+ function similar_posts_mark_current(){
23
+ global $post, $similar_posts_current_ID;
24
+ $similar_posts_current_ID = $post->ID;
25
+ }
26
+
27
+ define ('POST_PLUGIN_LIBRARY', true);
28
+
29
+ if ( ! defined( 'WP_CONTENT_URL' ) )
30
+ define( 'WP_CONTENT_URL', get_option( 'siteurl' ) . '/wp-content' );
31
+ if ( ! defined( 'WP_CONTENT_DIR' ) )
32
+ define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
33
+ if ( ! defined( 'WP_PLUGIN_URL' ) )
34
+ define( 'WP_PLUGIN_URL', WP_CONTENT_URL. '/plugins' );
35
+ if ( ! defined( 'WP_PLUGIN_DIR' ) )
36
+ define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
37
+
38
+ if (!defined('CF_LIBRARY')) require(WP_PLUGIN_DIR.'/similar-posts/common_functions.php');
39
+ if (!defined('ACF_LIBRARY')) require(WP_PLUGIN_DIR.'/similar-posts/admin_common_functions.php');
40
+ if (!defined('OT_LIBRARY')) require(WP_PLUGIN_DIR.'/similar-posts/output_tags.php');
41
+ if (!defined('ADMIN_SUBPAGES_LIBRARY')) require(WP_PLUGIN_DIR.'/similar-posts/admin-subpages.php');
42
+
43
+ if (!defined('DSEP')) define('DSEP', DIRECTORY_SEPARATOR);
44
+ if (!defined('POST_PLUGIN_LIBRARY')) SimilarPosts::install_post_plugin_library();
45
+
46
+ $similar_posts_current_ID = -1;
47
+
48
+ class SimilarPosts {
49
+ static $version = 0;
50
+
51
+ static function get_plugin_version() {
52
+ $plugin_data = get_file_data(__FILE__, array('version' => 'Version'), 'plugin');
53
+ SimilarPosts::$version = $plugin_data['version'];
54
+
55
+ return $plugin_data['version'];
56
+ } // get_plugin_version
57
+
58
+ // check if plugin's admin page is shown
59
+ static function is_plugin_admin_page($page = 'settings') {
60
+ $current_screen = get_current_screen();
61
+
62
+ if ($page == 'settings' && $current_screen->id == 'settings_page_similar-posts') {
63
+ return true;
64
+ }
65
+
66
+ return false;
67
+ } // is_plugin_admin_page
68
+
69
+ // add settings link to plugins page
70
+ static function plugin_action_links($links) {
71
+ $settings_link = '<a href="' . admin_url('options-general.php?page=similar-posts') . '" title="Settings for Similar Posts">Settings</a>';
72
+
73
+ array_unshift($links, $settings_link);
74
+
75
+ return $links;
76
+ } // plugin_action_links
77
+
78
+
79
+ static function execute($args='', $default_output_template='<li>{link}</li>', $option_key='similar-posts'){
80
+ global $table_prefix, $wpdb, $wp_version, $similar_posts_current_ID;
81
+ $start_time = ppl_microtime();
82
+ $postid = ppl_current_post_id($similar_posts_current_ID);
83
+ if (defined('POC_CACHE_4')) {
84
+ $cache_key = $option_key.$postid.$args;
85
+ $result = poc_cache_fetch($cache_key);
86
+ if ($result !== false) return $result . sprintf("<!-- Similar Posts took %.3f ms (cached) -->", 1000 * (ppl_microtime() - $start_time));
87
+ }
88
+ $table_name = $table_prefix . 'similar_posts';
89
+ // First we process any arguments to see if any defaults have been overridden
90
+ $options = ppl_parse_args($args);
91
+ // Next we retrieve the stored options and use them unless a value has been overridden via the arguments
92
+ $options = ppl_set_options($option_key, $options, $default_output_template);
93
+ if (0 < $options['limit']) {
94
+ $match_tags = ($options['match_tags'] !== 'false' && $wp_version >= 2.3);
95
+ $exclude_cats = ($options['excluded_cats'] !== '');
96
+ $include_cats = ($options['included_cats'] !== '');
97
+ $exclude_authors = ($options['excluded_authors'] !== '');
98
+ $include_authors = ($options['included_authors'] !== '');
99
+ $exclude_posts = (trim($options['excluded_posts']) !== '');
100
+ $include_posts = (trim($options['included_posts']) !== '');
101
+ $match_category = ($options['match_cat'] === 'true');
102
+ $match_author = ($options['match_author'] === 'true');
103
+ $use_tag_str = ('' != trim($options['tag_str']) && $wp_version >= 2.3);
104
+ $omit_current_post = ($options['omit_current_post'] !== 'false');
105
+ $hide_pass = ($options['show_private'] === 'false');
106
+ $check_age = ('none' !== $options['age']['direction']);
107
+ $check_custom = (trim($options['custom']['key']) !== '');
108
+ $limit = $options['skip'].', '.$options['limit'];
109
+
110
+ //get the terms to do the matching
111
+ if ($options['term_extraction'] === 'pagerank') {
112
+ list( $contentterms, $titleterms, $tagterms) = sp_terms_by_textrank($postid, $options['num_terms']);
113
+ } else {
114
+ list( $contentterms, $titleterms, $tagterms) = sp_terms_by_freq($postid, $options['num_terms']);
115
+ }
116
+ // these should add up to 1.0
117
+ $weight_content = $options['weight_content'];
118
+ $weight_title = $options['weight_title'];
119
+ $weight_tags = $options['weight_tags'];
120
+ // below a threshold we ignore the weight completely and save some effort
121
+ if ($weight_content < 0.001) $weight_content = (int) 0;
122
+ if ($weight_title < 0.001) $weight_title = (int) 0;
123
+ if ($weight_tags < 0.001) $weight_tags = (int) 0;
124
+
125
+ $count_content = substr_count($contentterms, ' ') + 1;
126
+ $count_title = substr_count($titleterms, ' ') + 1;
127
+ $count_tags = substr_count($tagterms, ' ') + 1;
128
+ if ($weight_content) $weight_content = 57.0 * $weight_content / $count_content;
129
+ if ($weight_title) $weight_title = 18.0 * $weight_title / $count_title;
130
+ if ($weight_tags) $weight_tags = 24.0 * $weight_tags / $count_tags;
131
+ if ($options['hand_links'] === 'true') {
132
+ // check custom field for manual links
133
+ $forced_ids = $wpdb->get_var("SELECT meta_value FROM $wpdb->postmeta WHERE post_id = $postid AND meta_key = 'sp_similar' ") ;
134
+ } else {
135
+ $forced_ids = '';
136
+ }
137
+ // the workhorse...
138
+ $sql = "SELECT *, ";
139
+ $sql .= score_fulltext_match($table_name, $weight_title, $titleterms, $weight_content, $contentterms, $weight_tags, $tagterms, $forced_ids);
140
+
141
+ if ($check_custom) $sql .= "LEFT JOIN $wpdb->postmeta ON post_id = ID ";
142
+
143
+ // build the 'WHERE' clause
144
+ $where = array();
145
+ $where[] = where_fulltext_match($weight_title, $titleterms, $weight_content, $contentterms, $weight_tags, $tagterms);
146
+ if (!function_exists('get_post_type')) {
147
+ $where[] = where_hide_future();
148
+ } else {
149
+ $where[] = where_show_status($options['status'], $options['show_attachments']);
150
+ }
151
+ if ($match_category) $where[] = where_match_category();
152
+ if ($match_tags) $where[] = where_match_tags($options['match_tags']);
153
+ if ($match_author) $where[] = where_match_author();
154
+ $where[] = where_show_pages($options['show_pages'], $options['show_attachments']);
155
+ if ($include_cats) $where[] = where_included_cats($options['included_cats']);
156
+ if ($exclude_cats) $where[] = where_excluded_cats($options['excluded_cats']);
157
+ if ($exclude_authors) $where[] = where_excluded_authors($options['excluded_authors']);
158
+ if ($include_authors) $where[] = where_included_authors($options['included_authors']);
159
+ if ($exclude_posts) $where[] = where_excluded_posts(trim($options['excluded_posts']));
160
+ if ($include_posts) $where[] = where_included_posts(trim($options['included_posts']));
161
+ if ($use_tag_str) $where[] = where_tag_str($options['tag_str']);
162
+ if ($omit_current_post) $where[] = where_omit_post($similar_posts_current_ID);
163
+ if ($hide_pass) $where[] = where_hide_pass();
164
+ if ($check_age) $where[] = where_check_age($options['age']['direction'], $options['age']['length'], $options['age']['duration']);
165
+ if ($check_custom) $where[] = where_check_custom($options['custom']['key'], $options['custom']['op'], $options['custom']['value']);
166
+ $sql .= "WHERE ".implode(' AND ', $where);
167
+ if ($check_custom) $sql .= " GROUP BY $wpdb->posts.ID";
168
+ $sql .= " ORDER BY score DESC, post_date DESC LIMIT $limit";
169
+ //echo $sql;
170
+ $results = $wpdb->get_results($sql);
171
+ } else {
172
+ $results = false;
173
+ }
174
+ if ($results) {
175
+ $translations = ppl_prepare_template($options['output_template']);
176
+ foreach ($results as $result) {
177
+ $items[] = ppl_expand_template($result, $options['output_template'], $translations, $option_key);
178
+ }
179
+ if ($options['sort']['by1'] !== '') $items = ppl_sort_items($options['sort'], $results, $option_key, $options['group_template'], $items);
180
+ $output = implode(($options['divider']) ? $options['divider'] : "\n", $items);
181
+ $output = $options['prefix'] . $output . $options['suffix'];
182
+ } else {
183
+ // if we reach here our query has produced no output ... so what next?
184
+ if ($options['no_text'] !== 'false') {
185
+ $output = ''; // we display nothing at all
186
+ } else {
187
+ // we display the blank message, with tags expanded if necessary
188
+ $translations = ppl_prepare_template($options['none_text']);
189
+ $output = $options['prefix'] . ppl_expand_template(array(), $options['none_text'], $translations, $option_key) . $options['suffix'];
190
+ }
191
+ }
192
+ if (defined('POC_CACHE_4')) poc_cache_store($cache_key, $output);
193
+ return ($output) ? $output . sprintf("<!-- Similar Posts took %.3f ms -->", 1000 * (ppl_microtime() - $start_time)) : '';
194
+ }
195
+
196
+ // save some info
197
+ static function activate() {
198
+ $options = get_option('similar_posts_meta', array());
199
+
200
+ if (empty($options['first_version'])) {
201
+ $options['first_version'] = SimilarPosts::get_plugin_version();
202
+ $options['first_install'] = current_time('timestamp');
203
+ update_option('similar_posts_meta', $options);
204
+ }
205
+ } // activate
206
+
207
+ } // similarposts class
208
+
209
+ function sp_terms_by_freq($ID, $num_terms = 20) {
210
+ if (!$ID) return array('', '', '');
211
+ global $wpdb, $table_prefix;
212
+ $table_name = $table_prefix . 'similar_posts';
213
+ $terms = '';
214
+ $results = $wpdb->get_results("SELECT title, content, tags FROM $table_name WHERE pID=$ID LIMIT 1", ARRAY_A);
215
+ if ($results) {
216
+ $word = strtok($results[0]['content'], ' ');
217
+ $n = 0;
218
+ $wordtable = array();
219
+ while ($word !== false) {
220
+ if(!array_key_exists($word,$wordtable)){
221
+ $wordtable[$word]=0;
222
+ }
223
+ $wordtable[$word] += 1;
224
+ $word = strtok(' ');
225
+ }
226
+ arsort($wordtable);
227
+ if ($num_terms < 1) $num_terms = 1;
228
+ $wordtable = array_slice($wordtable, 0, $num_terms);
229
+
230
+ foreach ($wordtable as $word => $count) {
231
+ $terms .= ' ' . $word;
232
+ }
233
+
234
+ $res[] = $terms;
235
+ $res[] = $results[0]['title'];
236
+ $res[] = $results[0]['tags'];
237
+ }
238
+ return $res;
239
+ }
240
+
241
+
242
+ // adapted PageRank algorithm see http://www.cs.unt.edu/~rada/papers/mihalcea.emnlp04.pdf
243
+ // and the weighted version http://www.cs.unt.edu/~rada/papers/hassan.ieee07.pdf
244
+ function sp_terms_by_textrank($ID, $num_terms = 20) {
245
+ global $wpdb, $table_prefix;
246
+ $table_name = $table_prefix . 'similar_posts';
247
+ $terms = '';
248
+ $results = $wpdb->get_results("SELECT title, content, tags FROM $table_name WHERE pID=$ID LIMIT 1", ARRAY_A);
249
+ if ($results) {
250
+ // build a directed graph with words as vertices and, as edges, the words which precede them
251
+ $prev_word = 'aaaaa';
252
+ $graph = array();
253
+ $word = strtok($results[0]['content'], ' ');
254
+ while ($word !== false) {
255
+ $graph[$word][$prev_word] += 1; // list the incoming words and keep a tally of how many times words co-occur
256
+ $out_edges[$prev_word] += 1; // count the number of different words that follow each word
257
+ $prev_word = $word;
258
+ $word = strtok(' ');
259
+ }
260
+ // initialise the list of PageRanks-- one for each unique word
261
+ foreach($graph as $vertex => $in_edges) {
262
+ $oldrank[$vertex] = 0.25;
263
+ }
264
+ $n = count($graph);
265
+ if ($n > 0) {
266
+ $base = 0.15 / $n;
267
+ $error_margin = $n * 0.005;
268
+ do {
269
+ $error = 0.0;
270
+ // the edge-weighted PageRank calculation
271
+ foreach($graph as $vertex => $in_edges) {
272
+ $r = 0;
273
+ foreach($in_edges as $edge => $weight) {
274
+ $r += ($weight * $oldrank[$edge]) / $out_edges[$edge];
275
+ }
276
+ $rank[$vertex] = $base + 0.95 * $r;
277
+ $error += abs($rank[$vertex] - $oldrank[$vertex]);
278
+ }
279
+ $oldrank = $rank;
280
+ //echo $error . '<br>';
281
+ } while ($error > $error_margin);
282
+ arsort($rank);
283
+ if ($num_terms < 1) $num_terms = 1;
284
+ $rank = array_slice($rank, 0, $num_terms);
285
+ foreach ($rank as $vertex => $score) {
286
+ $terms .= ' ' . $vertex;
287
+ }
288
+ }
289
+ $res[] = $terms;
290
+ $res[] = $results[0]['title'];
291
+ $res[] = $results[0]['tags'];
292
+ }
293
+ return $res;
294
+ }
295
+
296
+ function sp_save_index_entry($postID) {
297
+ global $wpdb, $table_prefix;
298
+ $table_name = $table_prefix . 'similar_posts';
299
+ $post = $wpdb->get_row("SELECT post_content, post_title, post_type FROM $wpdb->posts WHERE ID = $postID", ARRAY_A);
300
+ if ($post['post_type'] === 'revision') return $postID;
301
+ //extract its terms
302
+ $options = get_option('similar-posts');
303
+ $utf8 = ($options['utf8'] === 'true');
304
+ $cjk = ($options['cjk'] === 'true');
305
+ $content = sp_get_post_terms($post['post_content'], $utf8, $options['use_stemmer'], $cjk);
306
+ $title = sp_get_title_terms($post['post_title'], $utf8, $options['use_stemmer'], $cjk);
307
+ $tags = sp_get_tag_terms($postID, $utf8);
308
+ //check to see if the field is set
309
+ $pid = $wpdb->get_var("SELECT pID FROM $table_name WHERE pID=$postID limit 1");
310
+ //then insert if empty
311
+ if (is_null($pid)) {
312
+ $wpdb->query("INSERT INTO $table_name (pID, content, title, tags) VALUES ($postID, \"$content\", \"$title\", \"$tags\")");
313
+ } else {
314
+ $wpdb->query("UPDATE $table_name SET content=\"$content\", title=\"$title\", tags=\"$tags\" WHERE pID=$postID" );
315
+ }
316
+ return $postID;
317
+ }
318
+
319
+ function sp_delete_index_entry($postID) {
320
+ global $wpdb, $table_prefix;
321
+ $table_name = $table_prefix . 'similar_posts';
322
+ $wpdb->query("DELETE FROM $table_name WHERE pID = $postID ");
323
+ return $postID;
324
+ }
325
+
326
+ function sp_clean_words($text) {
327
+ $text = strip_tags($text);
328
+ $text = strtolower($text);
329
+ $text = str_replace("’", "'", $text); // convert MSWord apostrophe
330
+ $text = preg_replace(array('/\[(.*?)\]/', '/&[^\s;]+;/', '/‘|’|—|“|”|–|…/', "/'\W/"), ' ', $text); //anything in [..] or any entities or MS Word droppings
331
+ return $text;
332
+ }
333
+
334
+ function sp_mb_clean_words($text) {
335
+ mb_regex_encoding('UTF-8');
336
+ mb_internal_encoding('UTF-8');
337
+ $text = strip_tags($text);
338
+ $text = mb_strtolower($text);
339
+ $text = str_replace("’", "'", $text); // convert MSWord apostrophe
340
+ $text = preg_replace(array('/\[(.*?)\]/u', '/&[^\s;]+;/u', '/‘|’|—|“|”|–|…/u', "/'\W/u"), ' ', $text); //anything in [..] or any entities
341
+ return $text;
342
+ }
343
+
344
+ function sp_mb_str_pad($text, $n, $c) {
345
+ mb_internal_encoding('UTF-8');
346
+ $l = mb_strlen($text);
347
+ if ($l > 0 && $l < $n) {
348
+ $text .= str_repeat($c, $n-$l);
349
+ }
350
+ return $text;
351
+ }
352
+
353
+ function sp_cjk_digrams($string) {
354
+ mb_internal_encoding("UTF-8");
355
+ $strlen = mb_strlen($string);
356
+ $ascii = '';
357
+ $prev = '';
358
+ $result = array();
359
+ for ($i = 0; $i < $strlen; $i++) {
360
+ $c = mb_substr($string, $i, 1);
361
+ // single-byte chars get combined
362
+ if (strlen($c) > 1) {
363
+ if ($ascii) {
364
+ $result[] = $ascii;
365
+ $ascii = '';
366
+ $prev = $c;
367
+ } else {
368
+ $result[] = sp_mb_str_pad($prev.$c, 4, '_');
369
+ $prev = $c;
370
+ }
371
+ } else {
372
+ $ascii .= $c;
373
+ }
374
+ }
375
+ if ($ascii) $result[] = $ascii;
376
+ return implode(' ', $result);
377
+ }
378
+
379
+ function sp_get_post_terms($text, $utf8, $use_stemmer, $cjk) {
380
+ global $overusedwords;
381
+ if ($utf8) {
382
+ mb_regex_encoding('UTF-8');
383
+ mb_internal_encoding('UTF-8');
384
+ $wordlist = mb_split("\W+", sp_mb_clean_words($text));
385
+ $words = '';
386
+ foreach ($wordlist as $word) {
387
+ if ( mb_strlen($word) > 3 && !isset($overusedwords[$word])) {
388
+ switch ($use_stemmer) {
389
+ case 'true':
390
+ $words .= sp_mb_str_pad(stem($word), 4, '_') . ' ';
391
+ break;
392
+ case 'fuzzy':
393
+ $words .= sp_mb_str_pad(metaphone($word), 4, '_') . ' ';
394
+ break;
395
+ case 'false':
396
+ default:
397
+ $words .= $word . ' ';
398
+ }
399
+ }
400
+ }
401
+ } else {
402
+ $wordlist = str_word_count(sp_clean_words($text), 1);
403
+ $words = '';
404
+ foreach ($wordlist as $word) {
405
+ if ( strlen($word) > 3 && !isset($overusedwords[$word])) {
406
+ switch ($use_stemmer) {
407
+ case 'true':
408
+ $words .= str_pad(stem($word), 4, '_') . ' ';
409
+ break;
410
+ case 'fuzzy':
411
+ $words .= str_pad(metaphone($word), 4, '_') . ' ';
412
+ break;
413
+ case 'false':
414
+ default:
415
+ $words .= $word . ' ';
416
+ }
417
+ }
418
+ }
419
+ }
420
+ if ($cjk) $words = sp_cjk_digrams($words);
421
+ return $words;
422
+ }
423
+
424
+ $tinywords = array('the' => 1, 'and' => 1, 'of' => 1, 'a' => 1, 'for' => 1, 'on' => 1);
425
+
426
+ function sp_get_title_terms($text, $utf8, $use_stemmer, $cjk) {
427
+ global $tinywords;
428
+ if ($utf8) {
429
+ mb_regex_encoding('UTF-8');
430
+ mb_internal_encoding('UTF-8');
431
+ $wordlist = mb_split("\W+", sp_mb_clean_words($text));
432
+ $words = '';
433
+ foreach ($wordlist as $word) {
434
+ if (!isset($tinywords[$word])) {
435
+ switch ($use_stemmer) {
436
+ case 'true':
437
+ $words .= sp_mb_str_pad(stem($word), 4, '_') . ' ';
438
+ break;
439
+ case 'fuzzy':
440
+ $words .= sp_mb_str_pad(metaphone($word), 4, '_') . ' ';
441
+ break;
442
+ case 'false':
443
+ default:
444
+ $words .= sp_mb_str_pad($word, 4, '_') . ' ';
445
+ }
446
+ }
447
+ }
448
+ } else {
449
+ $wordlist = str_word_count(sp_clean_words($text), 1);
450
+ $words = '';
451
+ foreach ($wordlist as $word) {
452
+ if (!isset($tinywords[$word])) {
453
+ switch ($use_stemmer) {
454
+ case 'true':
455
+ $words .= str_pad(stem($word), 4, '_') . ' ';
456
+ break;
457
+ case 'fuzzy':
458
+ $words .= str_pad(metaphone($word), 4, '_') . ' ';
459
+ break;
460
+ case 'false':
461
+ default:
462
+ $words .= str_pad($word, 4, '_') . ' ';
463
+ }
464
+ }
465
+ }
466
+ }
467
+ if ($cjk) $words = sp_cjk_digrams($words);
468
+ return $words;
469
+ }
470
+
471
+ function sp_get_tag_terms($ID, $utf8) {
472
+ global $wpdb;
473
+ if (!function_exists('get_object_term_cache')) return '';
474
+ $tags = array();
475
+ $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'";
476
+ $tags = $wpdb->get_col($query);
477
+ if (!empty ($tags)) {
478
+ if ($utf8) {
479
+ mb_internal_encoding('UTF-8');
480
+ foreach ($tags as $tag) {
481
+ $newtags[] = sp_mb_str_pad(mb_strtolower(str_replace('"', "'", $tag)), 4, '_');
482
+ }
483
+ } else {
484
+ foreach ($tags as $tag) {
485
+ $newtags[] = str_pad(strtolower(str_replace('"', "'", $tag)), 4, '_');
486
+ }
487
+ }
488
+ $newtags = str_replace(' ', '_', $newtags);
489
+ $tags = implode (' ', $newtags);
490
+ } else {
491
+ $tags = '';
492
+ }
493
+ return $tags;
494
+ }
495
+
496
+ if ( is_admin() ) {
497
+ require(dirname(__FILE__).'/similar-posts-admin.php');
498
+ }
499
+
500
+ function widget_rrm_similar_posts_init() {
501
+ if (! function_exists("register_sidebar_widget")) {
502
+ return;
503
+ }
504
+ function widget_rrm_similar_posts($args) {
505
+ extract($args);
506
+ $options = get_option('widget_rrm_similar_posts');
507
+ $opt = get_option('similar-posts');
508
+ $widget_condition = $opt['widget_condition'];
509
+ // the condition specified in the widget control overrides the placement setting screen
510
+ if ($options['condition']) {
511
+ $condition = $options['condition'];
512
+ } else {
513
+ if ($widget_condition) {
514
+ $condition = $widget_condition;
515
+ } else {
516
+ $condition = 'true';
517
+ }
518
+ }
519
+ $condition = (stristr($condition, "return")) ? $condition : "return ".$condition;
520
+ $condition = rtrim($condition, '; ') . ' || is_admin();';
521
+ if (eval($condition)) {
522
+ $title = empty($options['title']) ? __('Similar Posts', 'similar_posts') : $options['title'];
523
+ if ( !$number = (int) $options['number'] )
524
+ $number = 10;
525
+ else if ( $number < 1 )
526
+ $number = 1;
527
+ else if ( $number > 15 )
528
+ $number = 15;
529
+ $options = get_option('recent-posts');
530
+ $widget_parameters = $options['widget_parameters'];
531
+ $output = SimilarPosts::execute('limit='.$number.'&'.$widget_parameters);
532
+ if ($output) {
533
+ echo $before_widget;
534
+ echo $before_title.$title.$after_title;
535
+ echo $output;
536
+ echo $after_widget;
537
+ }
538
+ }
539
+ }
540
+ function widget_rrm_similar_posts_control() {
541
+ if ( isset($_POST['widget_rrm_similar_posts_submit']) ) {
542
+ $options['title'] = strip_tags(stripslashes($_POST['widget_rrm_similar_posts_title']));
543
+ $options['number'] = (int) $_POST["widget_rrm_similar_posts_number"];
544
+ if ( true === sp_is_user_allowed_to_add_php_code() ) {
545
+ $options['condition'] = stripslashes(trim($_POST["widget_rrm_similar_posts_condition"], '; '));
546
+ }
547
+ update_option("widget_rrm_similar_posts", $options);
548
+ } else {
549
+ $options = get_option('widget_rrm_similar_posts');
550
+ }
551
+ $title = esc_attr($options['title']);
552
+ if ( !$number = (int) $options['number'] )
553
+ $number = 5;
554
+ $condition = esc_attr($options['condition']);
555
+ ?>
556
+ <p><label for="widget_rrm_similar_posts_title"> <?php _e('Title:', 'similar_posts'); ?> <input style="width: 200px;" id="widget_rrm_similar_posts_title" name="widget_rrm_similar_posts_title" type="text" value="<?php echo $title; ?>" /></label></p>
557
+ <p><label for="widget_rrm_similar_posts_number"> <?php _e('Number of posts to show:', 'similar_posts'); ?> <input style="width: 50px; text-align: center;" id="widget_rrm_similar_posts_number" name="widget_rrm_similar_posts_number" type="number" value="<?php echo $number; ?>" /></label> <label><?php _e('(at most 15)', 'similar_posts'); ?></label></p>
558
+ <?php if ( true === sp_is_user_allowed_to_add_php_code() ) { ?>
559
+ <p><label for="widget_rrm_similar_posts_condition"> <?php echo sprintf(__('Show only if page: (e.g., %sis_single()%s)', 'similar_posts'), '<a href="http://codex.wordpress.org/Conditional_Tags" title="help">', '</a>'); ?>
560
+ <input style="width: 200px;" readonly id="widget_rrm_similar_posts_condition" name="widget_rrm_similar_posts_condition" type="text" value="<?php echo $condition; ?>" /></label></p>
561
+ <?php } ?>
562
+ <input type="hidden" id="widget_rrm_similar_posts_submit" name="widget_rrm_similar_posts_submit" value="1" />
563
+ There are many more <a href="options-general.php?page=similar-posts.php">options</a> available.
564
+ <?php
565
+ }
566
+ wp_register_sidebar_widget('similar_posts_widget', __('Similar Posts', 'similar_posts'), 'widget_rrm_similar_posts');
567
+ wp_register_widget_control('similar_posts_widget', __('Similar Posts', 'similar_posts'), 'widget_rrm_similar_posts_control', 300, 100);
568
+ }
569
+
570
+ add_action('plugins_loaded', 'widget_rrm_similar_posts_init');
571
+
572
+ function sp_is_user_allowed_to_add_php_code() {
573
+ // If File Editing in Admin Area is disabled via override
574
+ if ( defined( 'DISALLOW_FILE_EDIT' ) && true === DISALLOW_FILE_EDIT) {
575
+ return false;
576
+ }
577
+
578
+ // If current user has been given adequate permission
579
+ if ( current_user_can( 'unfiltered_html' ) && current_user_can( 'edit_plugins' ) ) {
580
+ return true;
581
+ }
582
+
583
+ // Default to no edit
584
+ return false;
585
+ }
586
+
587
+ /*
588
+ now some language specific stuff
589
+ */
590
+
591
+ //the next lines find the language WordPress is using
592
+ if(defined('WPLANG')){
593
+ $language = substr(WPLANG, 0, 2);
594
+ } else {
595
+ $language = '';
596
+ }
597
+ //if no language is specified make it the default which is 'en'
598
+ if ($language == '') {
599
+ $language = 'en';
600
+ }
601
+ $languagedir = dirname(__FILE__).DSEP.'languages'.DSEP.$language.DSEP;
602
+ //see if the directory exists and if not revert to the default English dir
603
+ if (!file_exists($languagedir)) {
604
+ $languagedir = dirname(__FILE__).DSEP.'languages'.DSEP.'en'.DSEP;
605
+ }
606
+
607
+ // import the stemming algorithm ... a single function called 'stem'
608
+ require_once($languagedir.'stemmer.php');
609
+ require_once($languagedir.'stopwords.php');
610
+
611
+
612
+ global $overusedwords;
613
+ if(is_array($overusedwords)) {
614
+ $overusedwords = array_flip($overusedwords);
615
+ }
616
+
617
+ // do not try and use this function directly -- it is automatically installed when the option is set to show similar posts in feeds // moreover it is deprecated and going soon
618
+ function similar_posts_for_feed($content) {
619
+ return (is_feed()) ? $content . SimilarPosts::execute('', '<li>{link}</li>', 'similar-posts-feed') : $content;
620
+ }
621
+
622
+ function similar_posts_wp_admin_style() {
623
+ if (SimilarPosts::is_plugin_admin_page('settings')) {
624
+ wp_register_style( 'similar-posts-admin', plugins_url('', __FILE__) . '/css/similar-posts-admin.css', false, SimilarPosts::$version );
625
+ wp_enqueue_style( 'similar-posts-admin' );
626
+ }
627
+ }
628
+
629
+
630
+
631
+ function similar_posts_init () {
632
+ global $overusedwords, $wp_db_version;
633
+ load_plugin_textdomain('similar_posts');
634
+
635
+ SimilarPosts::get_plugin_version();
636
+
637
+ $options = get_option('similar-posts');
638
+ if ($options['feed_active'] === 'true') add_filter('the_content', 'similar_posts_for_feed');
639
+ if ($options['content_filter'] === 'true' && function_exists('ppl_register_content_filter')) ppl_register_content_filter('SimilarPosts');
640
+ if ($options['feed_on'] === 'true' && function_exists('ppl_register_post_filter')) ppl_register_post_filter('feed', 'similar-posts', 'SimilarPosts');
641
+ if ($options['append_condition']) {
642
+ $condition = $options['append_condition'];
643
+ } else {
644
+ $condition = 'true';
645
+ }
646
+ $condition = (stristr($condition, "return")) ? $condition : "return ".$condition;
647
+ $condition = rtrim($condition, '; ') . ';';
648
+ if ($options['append_on'] === 'true' && function_exists('ppl_register_post_filter')) ppl_register_post_filter('append', 'similar-posts', 'SimilarPosts', $condition);
649
+
650
+ //install the actions to keep the index up to date
651
+ add_action('save_post', 'sp_save_index_entry', 1);
652
+ add_action('delete_post', 'sp_delete_index_entry', 1);
653
+ if ($wp_db_version < 3308 ) {
654
+ add_action('edit_post', 'sp_save_index_entry', 1);
655
+ add_action('publish_post', 'sp_save_index_entry', 1);
656
+ }
657
+ add_action( 'admin_enqueue_scripts', 'similar_posts_wp_admin_style' );
658
+
659
+ // aditional links in plugin description
660
+ add_filter('plugin_action_links_' . basename(dirname(__FILE__)) . '/' . basename(__FILE__),
661
+ array('SimilarPosts', 'plugin_action_links'));
662
+ } // init
663
+
664
+ add_action ('init', 'similar_posts_init', 1);
665
+ register_activation_hook(__FILE__, array('SimilarPosts', 'activate'));
uninstall.php CHANGED
@@ -1,12 +1,12 @@
1
- <?php
2
-
3
- if (defined('ABSPATH') && defined('WP_UNINSTALL_PLUGIN')) {
4
- global $wpdb, $table_prefix;
5
-
6
- delete_option('similar-posts');
7
- delete_option('similar-posts-feed');
8
- delete_option('widget_rrm_similar_posts');
9
-
10
- $table_name = $table_prefix . 'similar_posts';
11
- $wpdb->query("DROP TABLE `$table_name`");
12
- }
1
+ <?php
2
+
3
+ if (defined('ABSPATH') && defined('WP_UNINSTALL_PLUGIN')) {
4
+ global $wpdb, $table_prefix;
5
+
6
+ delete_option('similar-posts');
7
+ delete_option('similar-posts-feed');
8
+ delete_option('widget_rrm_similar_posts');
9
+
10
+ $table_name = $table_prefix . 'similar_posts';
11
+ $wpdb->query("DROP TABLE `$table_name`");
12
+ }