Ejemplo n.º 1
0
 /**
  * Return the HTML output for first image found for a post.
  *
  * @param int $post_id ID for parent post
  * @param string $the_content
  * @param string $before Optional before string
  * @param string $after Optional after string
  * @return string HTML output or false if no match
  */
 function next_saturday_image_grabber($post_id, $the_content = '', $before = '', $after = '')
 {
     preg_match(WPCOM_THEMES_IMAGE_REGEX, get_the_post_format_image(), $matches);
     $image = isset($matches[0]) ? $matches[0] : '';
     // Add wrapper markup, if specified
     if (!empty($before)) {
         $image = $before . $image;
     }
     if (!empty($after)) {
         $image = $image . $after;
     }
     return $image;
 }
Ejemplo n.º 2
0
/**
 * Parse post content for pagination
 *
 * @since 3.6.0
 *
 * @uses paginate_content()
 *
 * @param object $post The post object.
 * @param bool $remaining Whether to parse post formats from the content. Defaults to false.
 * @return array An array of values used for paginating the parsed content.
 */
function wp_parse_post_content($post, $remaining = false)
{
    $numpages = 1;
    if ($remaining) {
        $format = get_post_format($post);
        if ($format && in_array($format, array('image', 'audio', 'video', 'quote'))) {
            // Call get_the_post_format_*() to set $post->split_content
            switch ($format) {
                case 'image':
                    get_the_post_format_image('full', $post);
                    break;
                case 'audio':
                    get_the_post_format_media('audio', $post, 1);
                    break;
                case 'video':
                    get_the_post_format_media('video', $post, 1);
                    break;
                case 'quote':
                    get_the_post_format_quote($post);
                    break;
            }
        }
    }
    if (strpos($post->post_content, '<!--nextpage-->')) {
        $multipage = 1;
        if ($remaining && isset($post->split_content)) {
            $pages = paginate_content($post->split_content);
        } else {
            $pages = paginate_content($post->post_content);
        }
        $numpages = count($pages);
    } else {
        if ($remaining && isset($post->split_content)) {
            $pages = array($post->split_content);
        } else {
            $pages = array($post->post_content);
        }
        $multipage = 0;
    }
    return compact('multipage', 'pages', 'numpages');
}
Ejemplo n.º 3
0
/**
 * Output the first image in the current (@global) post's content
 *
 * @since 3.6.0
 *
 * @param string $attached_size If an attached image is found, the size to display it.
 */
function the_post_format_image($attached_size = 'full')
{
    echo get_the_post_format_image($attached_size);
}
Ejemplo n.º 4
0
		<a href="<?php 
    the_permalink();
    ?>
" title="<?php 
    echo esc_attr(sprintf(__('Permalink to %s', 'forever'), the_title_attribute('echo=0')));
    ?>
" rel="bookmark">
			<img class="featured-image" src="<?php 
    echo esc_url($thumbnail[0]);
    ?>
" alt="">
		</a>
	</div>
	<?php 
} else {
    $image_content = function_exists('get_the_post_format_image') ? get_the_post_format_image() : get_the_content();
    $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $image_content, $matches);
    $first_image = isset($matches[1][0]) ? $matches[1][0] : '';
    if (!empty($first_image)) {
        ?>
	<figure class="entry-image">
		<a href="<?php 
        the_permalink();
        ?>
"><img class="featured-image" src="<?php 
        echo esc_url($first_image);
        ?>
" alt="<?php 
        echo esc_attr(the_title_attribute('echo=0'));
        ?>
" /></a>
Ejemplo n.º 5
0
/**
 * Set up global post data.
 *
 * @since 1.5.0
 *
 * @param object $post Post data.
 * @uses do_action_ref_array() Calls 'the_post'
 * @return bool True when finished.
 */
function setup_postdata($post)
{
    global $id, $authordata, $currentday, $currentmonth, $page, $pages, $format_pages, $multipage, $more, $numpages;
    $id = (int) $post->ID;
    $authordata = get_userdata($post->post_author);
    $currentday = mysql2date('d.m.y', $post->post_date, false);
    $currentmonth = mysql2date('m', $post->post_date, false);
    $numpages = 1;
    $page = get_query_var('page');
    if (!$page) {
        $page = 1;
    }
    if (is_single() || is_page() || is_feed()) {
        $more = 1;
    }
    $split_content = $content = $post->post_content;
    $format = get_post_format($post);
    if ($format && in_array($format, array('image', 'audio', 'video', 'quote'))) {
        switch ($format) {
            case 'image':
                get_the_post_format_image('full', $post);
                if (isset($post->split_content)) {
                    $split_content = $post->split_content;
                }
                break;
            case 'audio':
                get_the_post_format_media('audio', $post, 1);
                if (isset($post->split_content)) {
                    $split_content = $post->split_content;
                }
                break;
            case 'video':
                get_the_post_format_media('video', $post, 1);
                if (isset($post->split_content)) {
                    $split_content = $post->split_content;
                }
                break;
            case 'quote':
                get_the_post_format_quote($post);
                if (isset($post->split_content)) {
                    $split_content = $post->split_content;
                }
                break;
        }
    }
    if (strpos($content, '<!--nextpage-->')) {
        if ($page > 1) {
            $more = 1;
        }
        $multipage = 1;
        $pages = paginate_content($content);
        $format_pages = paginate_content($split_content);
        $numpages = count($pages);
    } else {
        $pages = array($post->post_content);
        $format_pages = array($split_content);
        $multipage = 0;
    }
    do_action_ref_array('the_post', array(&$post));
    return true;
}
Ejemplo n.º 6
0
    /**
     * the_post_format_*() alias
     */
    public function format($format, $params = null)
    {
        $output = '';
        $this->setupData();
        $null = null;
        // variable pass by reference
        global $wp_version;
        if (version_compare($wp_version, "3.6beta", ">=")) {
            // wp-includes/post-formats.php:599
            if ($format == 'chat') {
                $output = '<dl class="chat">';
                $stanzas = get_the_post_format_chat();
                foreach ($stanzas as $stanza) {
                    foreach ($stanza as $row) {
                        $time = '';
                        if (!empty($row['time'])) {
                            $time = sprintf('<time class="chat-timestamp">%s</time>', esc_html($row['time']));
                        }
                        $output .= sprintf('<dt class="chat-author chat-author-%1$s vcard">%2$s <cite class="fn">%3$s</cite>: </dt>
								<dd class="chat-text">%4$s</dd>
							', esc_attr(sanitize_title_with_dashes($row['author'])), $time, esc_html($row['author']), $row['message']);
                    }
                }
                $output .= '</dl><!-- .chat -->';
            } elseif ($format == 'video') {
                $output = get_the_post_format_media('video', $null, 1);
            } elseif ($format == 'audio') {
                $output = get_the_post_format_media('audio', $null, 1);
            } elseif ($format == 'image') {
                $output = get_the_post_format_image($params, $null);
            } elseif ($format == 'gallery') {
                $output = get_post_gallery();
            } elseif ($format == 'link') {
                $has_url = get_the_post_format_url();
                return $has_url ? $has_url : apply_filters('the_permalink', get_permalink());
            }
        } else {
            $output = $this->content();
        }
        return $output;
    }