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 diff --git a/post-thumbnail-fallback/post-thumbnail-fallback.php b/post-thumbnail-fallback/post-thumbnail-fallback.php new file mode 100644 index 0000000..b190aa3 --- /dev/null +++ b/post-thumbnail-fallback/post-thumbnail-fallback.php @@ -0,0 +1,139 @@ + $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); +?>