Version Description
(2019-02-16) = * Fixed compatability issues with PHP 7.2 * Addressed PHP warnings * Algorithm updated to prefer newer posts over older ones * General admin panel cleanup
Download this release
Release Info
Developer | shareaholic |
Plugin | Similar Posts – Best Related Posts Plugin for WordPress |
Version | 3.1.0 |
Comparing to | |
See all releases |
Code changes from version 3.0.2 to 3.1.0
- admin-subpages.php +0 -1
- common_functions.php +4 -2
- css/similar-posts-admin.css +0 -6
- output_tags.php +144 -39
- readme.txt +14 -8
- similar-posts-admin.php +1 -2
- similar-posts.php +8 -13
admin-subpages.php
CHANGED
@@ -49,7 +49,6 @@ class admin_subpages {
|
|
49 |
}
|
50 |
|
51 |
function display_menu() {
|
52 |
-
echo '<a title="Test your site\'s security with Security Ninja" id="ninja" href="https://wpsecurityninja.com/?utm_source=WP%20admin&utm_medium=banner&utm_campaign=Similar%20Posts&utm_content=ninja" target="_blank"><img title="Test your site\'s security with Security Ninja" alt="Test your site\'s security with Security Ninja" src="' . WP_PLUGIN_URL . '/similar-posts/images/ninja.png"></a>';
|
53 |
echo "\n<ul id=\"submenu\" class=\"similarposts-tabs-menu\" style=\"display: block\">\n";
|
54 |
// for compatibility with WP mu
|
55 |
$base = (isset($_SERVER['REDIRECT_URL'])) ? $_SERVER['REDIRECT_URL'] : $_SERVER['PHP_SELF'];
|
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'];
|
common_functions.php
CHANGED
@@ -233,13 +233,15 @@ function ppl_sort_items($sort, $results, $option_key, $group_template, $items) {
|
|
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 |
} else {
|
244 |
$the_ID = $GLOBALS['post']->ID;
|
245 |
}
|
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 |
}
|
css/similar-posts-admin.css
CHANGED
@@ -51,9 +51,3 @@
|
|
51 |
.similarposts-inner-table tr td{
|
52 |
border:1px solid #CCC;
|
53 |
}
|
54 |
-
|
55 |
-
#ninja {
|
56 |
-
position: absolute;
|
57 |
-
right: 100px;
|
58 |
-
top: 67px;
|
59 |
-
}
|
51 |
.similarposts-inner-table tr td{
|
52 |
border:1px solid #CCC;
|
53 |
}
|
|
|
|
|
|
|
|
|
|
|
|
output_tags.php
CHANGED
@@ -167,10 +167,10 @@ function otf_snippet($option_key, $result, $ext) {
|
|
167 |
$link = 'nolink';
|
168 |
if ($ext) {
|
169 |
$s = explode(':', $ext);
|
170 |
-
if ($s[0]) $len = $s[0];
|
171 |
-
if ($s[1]) $type = $s[1];
|
172 |
-
if ($s[2]) $more = $s[2];
|
173 |
-
if ($s[3]) $link = $s[3];
|
174 |
}
|
175 |
if ($link === 'link') {
|
176 |
$url = otf_url($option_key, $result, '');
|
@@ -185,9 +185,9 @@ function otf_snippetword($option_key, $result, $ext) {
|
|
185 |
$link = 'nolink';
|
186 |
if ($ext) {
|
187 |
$s = explode(':', $ext);
|
188 |
-
if ($s[0]) $len = $s[0];
|
189 |
-
if ($s[1]) $more = $s[1];
|
190 |
-
if ($s[2]) $link = $s[2];
|
191 |
}
|
192 |
if ($link === 'link') {
|
193 |
$url = otf_url($option_key, $result, '');
|
@@ -295,10 +295,10 @@ function otf_commentsnippet($option_key, $result, $ext) {
|
|
295 |
$link = 'nolink';
|
296 |
if ($ext) {
|
297 |
$s = explode(':', $ext);
|
298 |
-
if ($s[0]) $len = $s[0];
|
299 |
-
if ($s[1]) $type = $s[1];
|
300 |
-
if ($s[2]) $more = $s[2];
|
301 |
-
if ($s[3]) $link = $s[3];
|
302 |
}
|
303 |
if ($link === 'link') {
|
304 |
$url = otf_commenturl($option_key, $result, '');
|
@@ -313,9 +313,9 @@ function otf_commentsnippetword($option_key, $result, $ext) {
|
|
313 |
$link = 'nolink';
|
314 |
if ($ext) {
|
315 |
$s = explode(':', $ext);
|
316 |
-
if ($s[0]) $len = $s[0];
|
317 |
-
if ($s[1]) $more = $s[1];
|
318 |
-
if ($s[2]) $link = $s[2];
|
319 |
}
|
320 |
if ($link === 'link') {
|
321 |
$url = otf_commenturl($option_key, $result, '');
|
@@ -416,7 +416,8 @@ function otf_catlinks($option_key, $result, $ext) {
|
|
416 |
|
417 |
function otf_categorylinks($option_key, $result, $ext) {
|
418 |
$cats = get_the_category($result->ID);
|
419 |
-
$value = '';
|
|
|
420 |
foreach ($cats as $cat) {
|
421 |
if ($n > 0) $value .= $ext;
|
422 |
$catname = apply_filters('single_cat_title', $cat->cat_name);
|
@@ -432,7 +433,8 @@ function otf_catnames($option_key, $result, $ext) {
|
|
432 |
|
433 |
function otf_categorynames($option_key, $result, $ext) {
|
434 |
$cats = get_the_category($result->ID);
|
435 |
-
$value = '';
|
|
|
436 |
foreach ($cats as $cat) {
|
437 |
if ($n > 0) $value .= $ext;
|
438 |
$value .= apply_filters('single_cat_title', $cat->cat_name);
|
@@ -450,7 +452,9 @@ function otf_tags($option_key, $result, $ext) {
|
|
450 |
$tags = (array) get_the_tags($result->ID);
|
451 |
$tag_list = array();
|
452 |
foreach ( $tags as $tag ) {
|
453 |
-
|
|
|
|
|
454 |
}
|
455 |
if (!$ext) $ext = ', ';
|
456 |
$tag_list = join( $ext, $tag_list );
|
@@ -500,7 +504,7 @@ function otf_link($option_key, $result, $ext) {
|
|
500 |
$ttl = otf_title($option_key, $result, $ext);
|
501 |
$pml = otf_url($option_key, $result, null);
|
502 |
$pdt = otf_date($option_key, $result, null);
|
503 |
-
return "<a href=\"$pml\" rel=\"bookmark\" title=\"$
|
504 |
}
|
505 |
|
506 |
function otf_score($option_key, $result, $ext) {
|
@@ -510,6 +514,7 @@ function otf_score($option_key, $result, $ext) {
|
|
510 |
// tries to get the number of post views from a few popular plugins if the are installed
|
511 |
function otf_postviews($option_key, $result, $ext) {
|
512 |
global $wpdb;
|
|
|
513 |
// alex king's popularity contest
|
514 |
if (class_exists('ak_popularity_contest')) $count = $akpc->get_post_total($result->ID);
|
515 |
// my own post view count
|
@@ -523,7 +528,7 @@ function otf_postviews($option_key, $result, $ext) {
|
|
523 |
else if (function_exists('show_post_count')) {$id = $result->ID; $count = $wpdb->get_var("select cntaccess from mostAccessed WHERE postnumber = $id");}
|
524 |
// Ivan Djurdjevac's CountPosts
|
525 |
else if (function_exists('HitThisPost')) {$id = $result->ID; $count = $wpdb->get_var("SELECT post_hits FROM $wpdb->posts WHERE ID=$id");}
|
526 |
-
|
527 |
return $count;
|
528 |
}
|
529 |
|
@@ -607,13 +612,16 @@ function oth_process($w, $h) {
|
|
607 |
function otf_image($option_key, $result, $ext) {
|
608 |
// extract any image tags
|
609 |
$content = $result->post_content;
|
610 |
-
|
|
|
|
|
611 |
$s = explode(':', $ext);
|
612 |
-
if ($s[3] === 'post') {
|
613 |
$content = apply_filters('the_content', $content);
|
614 |
-
}
|
615 |
}
|
616 |
-
|
|
|
617 |
$pattern = '/<a.+?<img.+?>.+?a>/i';
|
618 |
$pattern2 = '#(<a.+?<img.+?)(/>|>)#is';
|
619 |
} else {
|
@@ -622,16 +630,29 @@ function otf_image($option_key, $result, $ext) {
|
|
622 |
}
|
623 |
if (!preg_match_all($pattern, $content, $matches)) {
|
624 |
// no <img> tags in content
|
625 |
-
if (($s[5]) && ($s[6])) {
|
626 |
// a default <img> tag has been given
|
627 |
return $s[5].':'.$s[6];
|
628 |
} else {
|
629 |
return '';
|
630 |
}
|
631 |
-
}
|
632 |
-
|
633 |
-
|
634 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
635 |
$process = oth_process($s[1],$s[2]);
|
636 |
list($w, $h) = $process(intval($s[1]), intval($s[2]), $imgtag);
|
637 |
if ($w === 0) return '';
|
@@ -646,19 +667,27 @@ function otf_image($option_key, $result, $ext) {
|
|
646 |
function otf_imagesrc($option_key, $result, $ext) {
|
647 |
// extract any image tags
|
648 |
$content = $result->post_content;
|
|
|
|
|
649 |
if ($ext) {
|
650 |
$s = explode(':', $ext);
|
651 |
-
if ($s[1] === 'post') {
|
652 |
$content = apply_filters('the_content', $content);
|
653 |
}
|
654 |
-
if ($s[2]) $suffix = $s[2];
|
|
|
|
|
|
|
655 |
}
|
656 |
$pattern = '/<img.+?src\s*=\s*[\'|\"](.*?)[\'|\"].+?>/i';
|
|
|
657 |
if (!preg_match_all($pattern, $content, $matches)) return '';
|
658 |
-
|
659 |
-
if (
|
660 |
-
|
661 |
-
|
|
|
|
|
662 |
if ($suffix === '?m') $suffix = '-' . get_option('medium_size_w') . 'x' . get_option('medium_size_h');
|
663 |
if ($suffix === '?t') $suffix = '-' . get_option('thumbnail_size_w') . 'x' . get_option('thumbnail_size_h');
|
664 |
$pathinfo = pathinfo($imgsrc);
|
@@ -667,22 +696,47 @@ function otf_imagesrc($option_key, $result, $ext) {
|
|
667 |
}
|
668 |
return $imgsrc;
|
669 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
670 |
|
671 |
function otf_imagealt($option_key, $result, $ext) {
|
672 |
// extract any image tags
|
673 |
$content = $result->post_content;
|
|
|
674 |
if ($ext) {
|
675 |
$s = explode(':', $ext);
|
676 |
-
if ($s[1] === 'post') {
|
677 |
$content = apply_filters('the_content', $content);
|
678 |
}
|
679 |
-
if ($s[2]) $suffix = $s[2];
|
680 |
}
|
681 |
$pattern = '/<img.+?alt\s*=\s*[\'|\"](.*?)[\'|\"].+?>/i';
|
682 |
if (!preg_match_all($pattern, $content, $matches)) return '';
|
683 |
-
|
684 |
-
|
685 |
-
|
|
|
|
|
|
|
686 |
}
|
687 |
|
688 |
function otf_gravatar($option_key, $result, $ext) {
|
@@ -811,6 +865,57 @@ function otf_php($option_key, $result, $ext) {
|
|
811 |
|
812 |
// ****************************** Helper Functions *********************************************
|
813 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
814 |
function oth_truncate_text($text, $ext) {
|
815 |
if (!$ext) {
|
816 |
return $text;
|
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, '');
|
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, '');
|
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, '');
|
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, '');
|
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);
|
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);
|
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 );
|
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) {
|
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
|
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 |
|
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 {
|
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 '';
|
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);
|
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) {
|
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;
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ 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.1
|
6 |
-
Stable tag: 3.0
|
7 |
|
8 |
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!
|
9 |
|
@@ -67,26 +67,32 @@ Read the <a href="http://wordpress.org/support/plugin/similar-posts">support for
|
|
67 |
|
68 |
== ChangeLog ==
|
69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
= 3.0.2 (2019-02-15) =
|
71 |
-
*
|
72 |
|
73 |
= 3.0.1 (2018-12-06) =
|
74 |
-
*
|
75 |
|
76 |
= 3.0.0 (2018-05-03) =
|
77 |
-
*
|
78 |
|
79 |
= 2.8.1 (2018-05-03) =
|
80 |
-
*
|
81 |
|
82 |
= 2.8 (2018-05-03) =
|
83 |
-
*
|
84 |
|
85 |
= 2.75 (2017-07-27) =
|
86 |
-
*
|
87 |
|
88 |
= 2.71 (2017-04-02) =
|
89 |
-
*
|
90 |
|
91 |
= 2.71 (2016-09-13) =
|
92 |
* no longer requires any additional plugins
|
3 |
Tags: related posts, similar posts, connected posts, related posts widget, linked posts
|
4 |
Requires at least: 4.0
|
5 |
Tested up to: 5.1
|
6 |
+
Stable tag: 3.1.0
|
7 |
|
8 |
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!
|
9 |
|
67 |
|
68 |
== ChangeLog ==
|
69 |
|
70 |
+
= 3.1.0 (2019-02-16) =
|
71 |
+
* Fixed compatability issues with PHP 7.2
|
72 |
+
* Addressed PHP warnings
|
73 |
+
* Algorithm updated to prefer newer posts over older ones
|
74 |
+
* General admin panel cleanup
|
75 |
+
|
76 |
= 3.0.2 (2019-02-15) =
|
77 |
+
* Compatability with WordPress 5.1
|
78 |
|
79 |
= 3.0.1 (2018-12-06) =
|
80 |
+
* Compatability with WordPress 5
|
81 |
|
82 |
= 3.0.0 (2018-05-03) =
|
83 |
+
* Minor update
|
84 |
|
85 |
= 2.8.1 (2018-05-03) =
|
86 |
+
* Minor update
|
87 |
|
88 |
= 2.8 (2018-05-03) =
|
89 |
+
* Minor update
|
90 |
|
91 |
= 2.75 (2017-07-27) =
|
92 |
+
* Minor update
|
93 |
|
94 |
= 2.71 (2017-04-02) =
|
95 |
+
* Minor update
|
96 |
|
97 |
= 2.71 (2016-09-13) =
|
98 |
* no longer requires any additional plugins
|
similar-posts-admin.php
CHANGED
@@ -519,8 +519,7 @@ function save_index_entries ($utf8=false, $use_stemmer='false', $batch=100, $cjk
|
|
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 |
-
|
523 |
-
while (list($dummy, $post) = each($posts)) {
|
524 |
if ($post['post_type'] === 'revision') continue;
|
525 |
$content = sp_get_post_terms($post['post_content'], $utf8, $use_stemmer, $cjk);
|
526 |
$title = sp_get_title_terms($post['post_title'], $utf8, $use_stemmer, $cjk);
|
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);
|
similar-posts.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Similar Posts
|
4 |
Plugin URI: https://wordpress.org/plugins/similar-posts/
|
5 |
Description: Displays a highly configurable list of related posts. Similarity can be based on any combination of word usage in the content, title, or tags.
|
6 |
-
Version: 3.0
|
7 |
Author: Shareaholic
|
8 |
Author URI: https://www.shareaholic.com
|
9 |
Text Domain: similar-posts
|
@@ -165,7 +165,7 @@ class SimilarPosts {
|
|
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 LIMIT $limit";
|
169 |
//echo $sql;
|
170 |
$results = $wpdb->get_results($sql);
|
171 |
} else {
|
@@ -258,8 +258,7 @@ function sp_terms_by_textrank($ID, $num_terms = 20) {
|
|
258 |
$word = strtok(' ');
|
259 |
}
|
260 |
// initialise the list of PageRanks-- one for each unique word
|
261 |
-
|
262 |
-
while (list($vertex, $in_edges) = each($graph)) {
|
263 |
$oldrank[$vertex] = 0.25;
|
264 |
}
|
265 |
$n = count($graph);
|
@@ -269,11 +268,9 @@ function sp_terms_by_textrank($ID, $num_terms = 20) {
|
|
269 |
do {
|
270 |
$error = 0.0;
|
271 |
// the edge-weighted PageRank calculation
|
272 |
-
|
273 |
-
while (list($vertex, $in_edges) = each($graph)) {
|
274 |
$r = 0;
|
275 |
-
|
276 |
-
while (list($edge, $weight) = each($in_edges)) {
|
277 |
$r += ($weight * $oldrank[$edge]) / $out_edges[$edge];
|
278 |
}
|
279 |
$rank[$vertex] = $base + 0.95 * $r;
|
@@ -300,7 +297,7 @@ function sp_save_index_entry($postID) {
|
|
300 |
global $wpdb, $table_prefix;
|
301 |
$table_name = $table_prefix . 'similar_posts';
|
302 |
$post = $wpdb->get_row("SELECT post_content, post_title, post_type FROM $wpdb->posts WHERE ID = $postID", ARRAY_A);
|
303 |
-
if ($post['post_type'] === 'revision') return $
|
304 |
//extract its terms
|
305 |
$options = get_option('similar-posts');
|
306 |
$utf8 = ($options['utf8'] === 'true');
|
@@ -386,8 +383,7 @@ function sp_get_post_terms($text, $utf8, $use_stemmer, $cjk) {
|
|
386 |
mb_internal_encoding('UTF-8');
|
387 |
$wordlist = mb_split("\W+", sp_mb_clean_words($text));
|
388 |
$words = '';
|
389 |
-
|
390 |
-
while (list($n, $word) = each($wordlist)) {
|
391 |
if ( mb_strlen($word) > 3 && !isset($overusedwords[$word])) {
|
392 |
switch ($use_stemmer) {
|
393 |
case 'true':
|
@@ -405,8 +401,7 @@ function sp_get_post_terms($text, $utf8, $use_stemmer, $cjk) {
|
|
405 |
} else {
|
406 |
$wordlist = str_word_count(sp_clean_words($text), 1);
|
407 |
$words = '';
|
408 |
-
|
409 |
-
while (list($n, $word) = each($wordlist)) {
|
410 |
if ( strlen($word) > 3 && !isset($overusedwords[$word])) {
|
411 |
switch ($use_stemmer) {
|
412 |
case 'true':
|
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.0
|
7 |
Author: Shareaholic
|
8 |
Author URI: https://www.shareaholic.com
|
9 |
Text Domain: similar-posts
|
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 {
|
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);
|
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;
|
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');
|
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':
|
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':
|