/**
  * Run the query and build an array of results
  *
  * @global type $wp_locale
  * @global type $wp_query
  * @param type    $wpQueryResults
  * @param type    $displayPostMeta
  */
 private function populate($wpQueryResults, $displayPostMeta)
 {
     global $wp_locale;
     global $wp_query;
     global $post;
     $dateFormat = get_option('date_format');
     // Get the search terms to include in the AJAX response
     $this->searchTerms = $_GET['s'];
     $wpQueryResults = $wp_query->get_posts();
     $wpQueryResults = apply_filters('dwls_alter_results', $wpQueryResults, -1, $this);
     while ($wp_query->have_posts()) {
         $wp_query->the_post();
         // Add author names & permalinks
         if ($displayPostMeta) {
             $authorName = get_the_author_meta('user_nicename', $post->post_author);
             $authorName = apply_filters('dwls_author_name', $authorName);
             $post->post_author_nicename = $authorName;
         }
         $post->permalink = get_permalink($post->ID);
         if (function_exists('get_post_thumbnail_id')) {
             // Support for WP 2.9 post thumbnails
             $postImageID = get_post_thumbnail_id($post->ID);
             $postImageData = wp_get_attachment_image_src($postImageID, apply_filters('post_image_size', 'thumbnail'));
             $hasThumbnailSet = $postImageData !== false;
         } else {
             // No support for post thumbnails
             $hasThumbnailSet = false;
         }
         if ($hasThumbnailSet) {
             $post->attachment_thumbnail = $postImageData[0];
         } else {
             $firstImageMeta = get_post_meta($post->ID, '_dwls_first_image', true);
             if ($firstImageMeta) {
                 $post->attachment_thumbnail = $firstImageMeta;
             } else {
                 // If no post thumbnail, grab the first image from the post_date
                 $post->attachment_thumbnail = DWLS_Util::updateFirstImagePostmeta($post->ID, $post);
             }
         }
         $post->attachment_thumbnail = apply_filters('dwls_attachment_thumbnail', $post->attachment_thumbnail);
         $post->post_excerpt = $this->excerpt($post);
         $post->post_date = date_i18n($dateFormat, strtotime($post->post_date));
         $post->post_date = apply_filters('dwls_post_date', $post->post_date);
         // We don't want to send all this content to the browser
         unset($post->post_content);
         // xLocalization
         $post->post_title = apply_filters("localization", $post->post_title);
         $post->post_title = apply_filters('dwls_post_title', $post->post_title);
         $post->show_more = true;
         // Let plugins & themes define their own template variables
         $post = apply_filters('dwls_post_custom', $post);
         $this->results[] = $post;
     }
 }
    /**
     * Test a single "img src" embedded in a block of content
     * @author Dave Ross <*****@*****.**>
     */
    function test_first_image_single_quotes()
    {
        $test_content = <<<TEST
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam at erat posuere, convallis velit a, molestie urna. Morbi vel lectus sit amet orci consequat suscipit. Mauris vulputate viverra congue. Morbi vitae malesuada dolor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis dignissim tempus lectus, non lobortis tortor varius non. Morbi malesuada vel enim id ultrices. Quisque vitae mattis lectus. Cras at risus commodo, sollicitudin diam ac, pharetra libero. Vivamus convallis, sem at ullamcorper consequat, elit eros porttitor dui, vitae viverra lectus diam eget augue. Nullam ipsum nisi, tempor nec sollicitudin in, auctor a tortor. Vivamus eu leo varius, semper erat hendrerit, tincidunt ante. Morbi molestie leo et pulvinar luctus. Mauris nibh sapien, molestie at justo ut, sagittis elementum tellus. Sed vestibulum convallis dapibus.

Donec justo neque, imperdiet eu suscipit quis, suscipit sit amet nisi. Vestibulum <img src='test.jpg' width='100' height='100' /> ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aliquam feugiat tincidunt condimentum. Nulla vel elit arcu. Interdum et malesuada fames ac ante ipsum primis in faucibus. Quisque accumsan nisl ac euismod vulputate. Aliquam cursus semper ligula, in iaculis neque vulputate quis. Proin sed felis condimentum, pellentesque risus sit amet, cursus eros.

Maecenas tincidunt a augue vel sodales. Donec placerat purus et euismod rhoncus. Aenean augue elit, pharetra sit amet massa eu, rhoncus congue ligula. Sed feugiat turpis semper elementum condimentum. Cras dapibus turpis in odio sodales sagittis. Sed malesuada commodo mauris, vel luctus turpis mollis nec. Maecenas pharetra congue dolor, in volutpat neque gravida vel. Sed vestibulum, elit non elementum interdum, purus lacus lacinia erat, ac sagittis elit odio a turpis. Phasellus ornare consequat imperdiet. Cras tempus a metus sit amet convallis. Etiam sit amet nulla purus.
TEST;
        $first_image = DWLS_Util::firstImg($test_content);
        $this->assertEquals($first_image, 'test.jpg');
    }