Here’s the more complete patch to 1.7.6. Start with admin.inc.php and after the line 40, which is
$tptn_settings[scan_images] = (($_POST['scan_images']) ? true : false);
add the line
$tptn_settings[thumb_default_show] = (($_POST['thumb_default_show']) ? true : false);
and find line 273, which used to be 272 and is
<p><?php _e('The plugin will first check if the post contains a thumbnail. If it doesn\'t then it will check the meta field. If this is not available, then it will show the default image as specified below:',TPTN_LOCAL_NAME); ?>
and replace it with
<p><label><input type="checkbox" name="thumb_default_show" id="thumb_default_show" <?php if ($tptn_settings[thumb_default_show]) echo 'checked="checked"' ?> /> <?php _e('If checked, when no thumbnail is found, show a default one from the URL below. If not checked and no thumbnail is found, no image will be shown.',TPTN_LOCAL_NAME); ?></label><br />
In top10.php, find starting from line 317:
'thumb_height' => '100', // Height of thumbnails
'thumb_width' => '100', // Width of thumbnails
'thumb_meta' => 'post-image', // Meta field that is used to store the location of default thumbnail image
'thumb_default' => $thumb_default, // Default thumbnail image
'scan_images' => false, // Scan post for images
and replace it with
'thumb_height' => '100', // Max height of thumbnails
'thumb_width' => '100', // Max width of thumbnails
'thumb_meta' => 'post-image', // Meta field that is used to store the location of default thumbnail image
'thumb_default' => $thumb_default, // Default thumbnail image
'scan_images' => false, // Scan post for images
'thumb_default_show' => true, // Show default thumb if none found (if false, don't show thumb at all)
and find from line 167:
if (($tptn_settings['post_thumb_op']=='inline')||($tptn_settings['post_thumb_op']=='thumbs_only')) {
$output .= '<a href="'.get_permalink($result->postnumber).'" rel="bookmark">';
if ((function_exists('has_post_thumbnail')) && (has_post_thumbnail($result->postnumber))) {
$output .= get_the_post_thumbnail( $result->postnumber, array($tptn_settings[thumb_width],$tptn_settings[thumb_height]), array('title' => $title,'alt' => $title, 'class' => 'tptn_thumb', 'border' => '0'));
} else {
$postimage = get_post_meta($result->postnumber, $tptn_settings[thumb_meta], true); // Check
if ((!$postimage)&&($tptn_settings['scan_images'])) {
preg_match_all( '|<img.*?src=[\'"](.*?)[\'"].*?>|i', $result->post_content, $matches );
// any image there?
if( isset( $matches ) && $matches[1][0] ) {
$postimage = $matches[1][0]; // we need the first one only!
}
}
if (!$postimage) $postimage = $tptn_settings[thumb_default];
$output .= '<img src="'.$postimage.'" alt="'.$title.'" title="'.$title.'" width="'.$tptn_settings[thumb_width].'" height="'.$tptn_settings[thumb_height].'" border="0" class="tptn_thumb" />';
}
$output .= '</a> ';
}
if (($tptn_settings['post_thumb_op']=='inline')||($tptn_settings['post_thumb_op']=='text_only')) {
$output .= '<a href="'.get_permalink($result->postnumber).'" rel="bookmark">'.$title.'</a>';
}
if ($tptn_settings['show_excerpt']) {
$output .= '<span class="tptn_excerpt"> '.tptn_excerpt($result->post_content,$tptn_settings['excerpt_length']).'</span>';
}
if ($tptn_settings['disp_list_count']) $output .= ' ('.$result->sumCount.')';
and replace it with
$output .= '<a href="'.get_permalink($result->postnumber).'" rel="bookmark">'; // Add beginning of link
if ($tptn_settings['post_thumb_op']=='inline' || $tptn_settings['post_thumb_op']=='thumbs_only') {
if (function_exists('has_post_thumbnail') && has_post_thumbnail($result->postnumber)) {
$output .= get_the_post_thumbnail($result->postnumber, array($tptn_settings[thumb_width],$tptn_settings[thumb_height]), array('title' => $title,'alt' => $title, 'class' => 'tptn_thumb', 'border' => '0'));
} else {
$postimage = get_post_meta($result->postnumber, $tptn_settings[thumb_meta], true); // Check
if (!$postimage && $tptn_settings['scan_images']) {
preg_match_all( '|<img.*?src=[\'"](.*?)[\'"].*?>|i', $result->post_content, $matches );
// any image there?
if (isset($matches) && $matches[1][0]) {
$postimage = $matches[1][0]; // we need the first one only!
}
}
if (!$postimage) $postimage = get_post_meta($result->postnumber, '_video_thumbnail', true); // If no other thumbnail set, try to get the custom video thumbnail set by the Video Thumbnails plugin
if ($tptn_settings['thumb_default_show'] && !$postimage) $postimage = $tptn_settings[thumb_default]; // If no thumb found and settings permit, use default thumb
if ($postimage) {
$output .= '<img src="'.$postimage.'" alt="'.$title.'" title="'.$title.'" style="max-width:'.$tptn_settings[thumb_width].'px;max-height:'.$tptn_settings[thumb_height].'px;" border="0" class="tptn_thumb" />';
}
}
}
if ($tptn_settings['post_thumb_op']=='inline' || $tptn_settings['post_thumb_op']=='text_only') {
$output .= $title; // Add title when required by settings
}
$output .= '</a>'; // Close the link
if ($tptn_settings['show_excerpt']) {
$output .= '<span class="tptn_excerpt"> '.tptn_excerpt($result->post_content,$tptn_settings['excerpt_length']).'</span>';
}
if ($tptn_settings['disp_list_count']) {
$output .= ' ('.$result->sumCount.')';
}
The performance increase is very slight and comes from removing redundant ifs and duplicate HTML output. Now regardless of thumb and title settings, both will be wrapped in one <a>. Also all the ifs in this part of code are now formatted in the same way and redundant brackets have been removed for better readability.
Functional improvements, as mentioned in the first post, are: fix max width and max height; support Video Thumbnails; add option for displaying no thumbnail when none is found. This patch may need to be replicated to the .js.php files which replicate code, or better yet, the replicated code should be put to its own function.