From 2797e34645d59f6648366bf08d21b30c41ee5272 Mon Sep 17 00:00:00 2001 From: Jon Bishop Date: Thu, 30 Aug 2012 17:03:58 -0400 Subject: [PATCH 1/3] added feed-redirect plugin --- feed-redirect/feed-redirect.php | 64 +++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 feed-redirect/feed-redirect.php diff --git a/feed-redirect/feed-redirect.php b/feed-redirect/feed-redirect.php new file mode 100644 index 0000000..5daa052 --- /dev/null +++ b/feed-redirect/feed-redirect.php @@ -0,0 +1,64 @@ + 'http://wordpress.org/news/feed/', + 'whitelist' => array( + 'feedburner', + 'googlebot' + ) + ); + return apply_filters('bwp_feed_settings', $feed_settings); +} + +function bwp_feed_redirect() { + global $feed; + // Do nothing if not a feed + if (!is_feed()) { + return; + } + + // Grab our feed settings + $feed_settings = bwp_feed_settings(); + + // Do nothing if whitelisted user-agent + foreach ($feed_settings['whitelist'] as $whitelist){ + if (preg_match('/'.$whitelist.'/i', $_SERVER['HTTP_USER_AGENT'])) + return; + } + + // Redirect to our feed + if ($feed != 'comments-rss2' && trim($feed_settings['feed']) != '') { + do_action('bwp_feed_redirect'); + if (function_exists('status_header')) + status_header(302); + header("Location:" . trim($feed_settings['feed'])); + header("HTTP/1.1 302 Temporary Redirect"); + exit(); + } +} +add_action('template_redirect', &$this, 'bwp_feed_redirect'); + +function bwp_feedburner_feed_link($output, $feed) { + // Grab our feed settings + $feed_settings = bwp_feed_settings(); + $feed_url = $feed_settings['feed']; + + // Replace feeds + if (trim($feed_url) != '' && $feed != 'comments-rss2') { + $feed_array = array('rss' => $feed_url, 'rss2' => $feed_url, 'atom' => $feed_url, 'rdf' => $feed_url, 'comments_rss2' => ''); + $feed_array[$feed] = $feed_url; + $output = $feed_array[$feed]; + } + return apply_filters('bwp_feedburner_feed_link', $output); +} +add_filter('feed_link', &$this, 'bwp_feedburner_feed_link', 1, 2); +?> \ No newline at end of file From 41e28057040b8a22d666ce0358892e8726a72abd Mon Sep 17 00:00:00 2001 From: Jon Bishop Date: Fri, 31 Aug 2012 21:54:50 -0400 Subject: [PATCH 2/3] added post thumbnail fallback plugin --- .../post-thumbnail-fallback.php | 138 ++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 post-thumbnail-fallback/post-thumbnail-fallback.php diff --git a/post-thumbnail-fallback/post-thumbnail-fallback.php b/post-thumbnail-fallback/post-thumbnail-fallback.php new file mode 100644 index 0000000..fb92960 --- /dev/null +++ b/post-thumbnail-fallback/post-thumbnail-fallback.php @@ -0,0 +1,138 @@ +protect your blog from comment and trackback spam. It keeps your site protected from spam even while you sleep. To get started: 1) Click the "Activate" link to the left of this description, 2) Sign up for an Akismet API key, and 3) Go to your Akismet configuration page, and save your API key. + Version: 2.5.6 + Author: Automattic + Author URI: http://automattic.com/wordpress-plugins/ + License: GPLv2 or later + */ +function bwp_get_image_html($post_thumbnail_url, $size = 'thumbnail', $attr = '') { + $src = $post_thumbnail_url; + if (is_array($size)) { + $width = $size[0]; + $height = $size[1]; + } + $hwstring = image_hwstring($width, $height); + if (is_array($size)) + $size = join('x', $size); + $default_attr = array( + 'src' => $src, + 'class' => "attachment-$size" + ); + + $attr = wp_parse_args($attr, $default_attr); + $attr = apply_filters('wp_get_attachment_image_attributes', $attr); + $attr = array_map('esc_attr', $attr); + $html = rtrim(" $value) { + $html .= " $name=" . '"' . $value . '"'; + } + $html .= ' />'; + return $html; +} + + +/** + * Returns image HTML for a post with multiple fallbacks + * + * This function generates HTML for a posts thumbnail using multiple methods to + * find an image. + * + * First the function checks to see if there are any images attached the post. + * If there is an image, we can use built core functions to generate the html. + * + * Next the function checks to see if there are any images in the post's content. + * If an image is found, the function resizes the image using the images.weserv.nl + * web service. + * + * Finally the function uses flickholdr.com to generate a relavent image using the + * specifed dimensions. + * + * Filters: + * bwp_get_image_default - Define an alternative default image to flickholdr.com + * bwp_get_image_html - Filter HTML generated by bwp_get_image() + * + * @param string $html Image HTML. + * @param int $post_id The current post's ID + * @param string|array $size Size of what the result image should be. + * @return string Image HTML. + */ +function bwp_get_image($html = "", $post_id = null, $size = 'featured-image', $attr) { + global $post, $_wp_additional_image_sizes; + if ($html == "") { + + // First let's check for any attachments + $attachments = get_children(array( + 'post_parent' => $post_id, + 'post_type' => 'attachment', + 'numberposts' => 1, + 'post_status' => 'inherit', + 'post_mime_type' => 'image', + 'order' => 'ASC', + 'orderby' => 'menu_order ASC' + )); + if (!empty($attachments)) { + foreach ($attachments as $attachment_id => $attachment) { + if (wp_get_attachment_image($attachment_id) != ""): + $post_thumbnail_url = wp_get_attachment_url($attachment_id); + $html = wp_get_attachment_image($attachment_id, $size, false, $attr); + endif; + } + } else { + // Create image dimensions for our custom image + if (is_array($size)) { + $width = $size[0]; + $height = $size[1]; + } else { + if (isset($_wp_additional_image_sizes) && count($_wp_additional_image_sizes) && in_array($size, array_keys($_wp_additional_image_sizes))) { + $width = intval($_wp_additional_image_sizes[$size]['width']); + $height = intval($_wp_additional_image_sizes[$size]['height']); + } + } + + // Check for any images in the posts + $output = preg_match_all('//i', $post->post_content, $matches); + if (!empty($matches[1][0])) { + $post_thumbnail_url = $matches[1][0]; + $post_thumbnail_url = 'http://images.weserv.nl/?url=' . $post_thumbnail_url . '&h=' . $width . '&h=' . $height . '&t=fit'; + + // Fall back image URL + } else { + $f_tags = array(); + $query_tags = ""; + // Check for tags or categories to grab relevant images + $categories = get_the_category(); + foreach ($categories as $category) { + $f_tags[] = $category->slug; + break; + } + $tags = get_the_tags(); + foreach ($tags as $tag) { + $f_tags[] = $tag->slug; + break; + } + $f_tags = array_diff($f_tags, array('uncategorized')); + if(!empty($f_tags)){ + $query_tags = implode(",", $f_tags); + } + $post_thumbnail_url = "http://flickholdr.com/" . $width . "/" . $height . "/" . $query_tags; + $post_thumbnail_url = apply_filters('bwp_get_image_default', $post_thumbnail_url); + } + + // Create image html with our custom image urls + $html = apply_filters('bwp_get_image_html', bwp_get_image_html($post_thumbnail_url, array($width, $height), $attr)); + } + } + + return $html; +} + +function bwp_filter_post_thumbnail($html, $post_id, $post_thumbnail_id, $size, $attr) { + return apply_filters('bwp_filter_post_thumbnail', bwp_get_image($html, $post_id, $size, $attr)); +} + +add_filter('post_thumbnail_html', 'bwp_filter_post_thumbnail', 10, 5); +?> From 3829299e9ae64c94107476d9e2e461908fbc03fd Mon Sep 17 00:00:00 2001 From: Jon Bishop Date: Fri, 31 Aug 2012 21:57:28 -0400 Subject: [PATCH 3/3] Changed plugin header --- post-thumbnail-fallback/post-thumbnail-fallback.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/post-thumbnail-fallback/post-thumbnail-fallback.php b/post-thumbnail-fallback/post-thumbnail-fallback.php index fb92960..b190aa3 100644 --- a/post-thumbnail-fallback/post-thumbnail-fallback.php +++ b/post-thumbnail-fallback/post-thumbnail-fallback.php @@ -2,13 +2,14 @@ /** Plugin Name: Post Thumbnail Fallback - Plugin URI: http://akismet.com/?return=true - Description: Used by millions, Akismet is quite possibly the best way in the world to protect your blog from comment and trackback spam. It keeps your site protected from spam even while you sleep. To get started: 1) Click the "Activate" link to the left of this description, 2) Sign up for an Akismet API key, and 3) Go to your Akismet configuration page, and save your API key. - Version: 2.5.6 - Author: Automattic - Author URI: http://automattic.com/wordpress-plugins/ + Plugin URI: https://github.com/BostonWP/functionality-plugins + Description: Generates HTML for a posts thumbnail using multiple fallbacks to find an image. + Version: .1 + Author: Jon Bishop + Author URI: http://www.jonbishop.com License: GPLv2 or later */ + function bwp_get_image_html($post_thumbnail_url, $size = 'thumbnail', $attr = '') { $src = $post_thumbnail_url; if (is_array($size)) {