/**
 * Create a 'srcset' attribute.
 *
 * @param int $id 			Image attacment ID.
 * @param string $size	Optional. Name of image size. Default value: 'thumbnail'.
 * @return string|bool 	A full 'srcset' string or false.
 */
function tevkori_get_srcset_string($id, $size)
{
    $srcset_array = tevkori_get_srcset_array($id, $size);
    if (empty($srcset_array)) {
        return false;
    }
    return 'srcset="' . implode(', ', $srcset_array) . '"';
}
/**
 * Returns the value for a 'srcset' attribute.
 *
 * @since 2.3.0
 * @deprecated 3.0.0 Use 'wp_get_attachment_image_srcset()'
 *
 * @see wp_get_attachment_image_srcset()
 *
 * @param int          $id   Image attachment ID.
 * @param array|string $size Image size. Accepts any valid image size, or an array of width and height
 *                           values in pixels (in that order). Default 'medium'.
 * @return string|bool A 'srcset' value string or false.
 */
function tevkori_get_srcset($id, $size = 'medium')
{
    _deprecated_function(__FUNCTION__, '3.0.0', 'wp_get_attachment_image_srcset()');
    if (has_filter('tevkori_srcset_array')) {
        $srcset_array = tevkori_get_srcset_array($id, $size);
        return $scrset_array ? implode(', ', $srcset_array) : false;
    } else {
        return wp_get_attachment_image_srcset($id, $size);
    }
}
/**
 * Get the value for the 'srcset' attribute.
 *
 * @since 2.3.0
 *
 * @param int    $id   Image attachment ID.
 * @param string $size Optional. Name of image size. Default value: 'thumbnail'.
 * @return string|bool A 'srcset' value string or false.
 */
function tevkori_get_srcset($id, $size = 'thumbnail')
{
    $srcset_array = tevkori_get_srcset_array($id, $size);
    if (empty($srcset_array)) {
        return false;
    }
    return implode(', ', $srcset_array);
}
 /**
  * @expectedDeprecated tevkori_get_srcset_array
  */
 function test_tevkori_get_srcset_array_no_width()
 {
     // Filter image_downsize() output.
     add_filter('image_downsize', array($this, '_filter_image_downsize'), 10, 3);
     // Make our attachment.
     $id = self::create_upload_object(self::$test_file_name);
     $srcset = tevkori_get_srcset_array($id, 'medium');
     // The srcset should be false.
     $this->assertFalse($srcset);
     // Remove filter.
     remove_filter('image_downsize', array($this, '_filter_image_downsize'));
 }
/**
 * Get the value for the 'srcset' attribute.
 *
 * @since 2.3.0
 *
 * @param int    $id   Image attachment ID.
 * @param string $size Optional. Name of image size. Default value: 'medium'.
 * @return string|bool A 'srcset' value string or false.
 */
function tevkori_get_srcset($id, $size = 'medium')
{
    $srcset_array = tevkori_get_srcset_array($id, $size);
    if (count($srcset_array) <= 1) {
        return false;
    }
    return implode(', ', $srcset_array);
}
Esempio n. 6
0
/**
 * Show Full Width Featured Image on single pages if post has full width featured image selected
 * or if Auto-Set Featured Image as Post Cover option is enabled
 */
function independent_publisher_full_width_featured_image()
{
    if (true || independent_publisher_has_full_width_featured_image()) {
        while (have_posts()) {
            the_post();
            if (true || has_post_thumbnail()) {
                if (true || independent_publisher_post_has_post_cover_title()) {
                    //tevkori_get_srcset_array( $id, $size = 'thumbnail' ) {
                    //global $wpdb;
                    $postCoverTitleWrapperExtraClass = "postCoverTitleAlwaysBelow";
                    $showPostCover = false;
                    echo "<style>\n";
                    if (independent_publisher_has_full_width_featured_image() && has_post_thumbnail()) {
                        $showPostCover = true;
                        $tempSources = tevkori_get_srcset_array(get_post_thumbnail_id(), 'full');
                        //sources aren't automatically in numeric order.  ksort does the trick.
                        ksort($tempSources);
                        $counter = 0;
                        $prevWidth = 0;
                        // Let's prevent any images with width > 1200px from being an output as part of responsive post cover
                        foreach ($tempSources as $key => $tempSource) {
                            if ($key > 1900) {
                                unset($tempSources[$key]);
                            }
                        }
                        foreach ($tempSources as $key => $tempSource) {
                            //we're working with an array of sourceset entries ... gotta get rid of the width part
                            $counter++;
                            $tempSource = preg_replace('/(.*)\\s(.*)/', '$1', $tempSource);
                            if ($counter == 1) {
                                echo "\t.postCoverResponsive { background-image: url({$tempSource}) !important; }\n";
                            } elseif ($counter < count($tempSources)) {
                                echo "\t@media (min-width: " . ($prevWidth + 1) . "px) and (max-width: " . $key . "px) {\n";
                                echo "\t\t.postCoverResponsive { background-image: url({$tempSource}) !important; }\n";
                                echo "\t}\n";
                            } else {
                                echo "\t@media (min-width: " . ($prevWidth + 1) . "px) {\n";
                                echo "\t\t.postCoverResponsive { background-image: url({$tempSource}) !important; }\n";
                                echo "\t}\n";
                            }
                            $prevWidth = $key;
                        }
                        $featured_image_url = wp_get_attachment_image_src(get_post_thumbnail_id(), apply_filters('independent_publisher_full_width_featured_image_size', 'independent_publisher_post_thumbnail'));
                        $featured_image_url = $featured_image_url[0];
                        $post_has_cover_title_rize = get_post_meta(get_the_ID(), 'post_cover_overlay_post_title_rize', true);
                        if ($post_has_cover_title_rize === '1' || $post_has_cover_title_rize === 'true') {
                            $postCoverTitleWrapperExtraClass = "";
                        }
                    }
                    echo "</style>\n";
                    $featuredImageCaptionRaw = "";
                    $featuredImageCaption = "";
                    $featuredImageAltCaption = "";
                    $featuredImageCredit = "";
                    $featuredImageCreditLink = "";
                    $featured_image_data = get_post(get_post_thumbnail_id());
                    /* var_dump($featured_image_data); */
                    if ($featured_image_data) {
                        $featuredImageCaptionRaw = $featured_image_data->post_excerpt;
                        $featuredImageCredit = get_post_meta(get_post_thumbnail_id(), '_wp_attachment_source_name', true);
                        $featuredImageCreditLink = get_post_meta(get_post_thumbnail_id(), '_wp_attachment_source_url', true);
                        /** if we have either a caption or a credit, we're going to show the <p> **/
                        if ($featuredImageCaptionRaw != "" || $featuredImageCredit != "") {
                            $featuredImageCaption = "<p id='featuredCutline' class='wp-caption-text'>";
                            $featuredImageAltCaption = "<p id='featuredAltCutline' class='wp-caption-text'>";
                            if ($featuredImageCaptionRaw != "") {
                                $featuredImageCaption .= $featuredImageCaptionRaw;
                                $featuredImageAltCaption .= $featuredImageCaptionRaw;
                            }
                            if ($featuredImageCredit != "") {
                                if ($featuredImageCreditLink != "") {
                                    $featuredImageCaption .= " <a class='featuredCutlineCredit' href='{$featuredImageCreditLink}'>{$featuredImageCredit}</a>";
                                    $featuredImageAltCaption .= " <a class='featuredAltCutlineCredit' href='{$featuredImageCreditLink}'>{$featuredImageCredit}</a>";
                                } else {
                                    $featuredImageCaption .= " <span class='featuredCutlineCredit'>{$featuredImageCredit}</span>";
                                    $featuredImageAltCaption .= " <span class='featuredAltCutlineCredit'>{$featuredImageCredit}</span>";
                                }
                            }
                            $featuredImageCaption .= "</p>";
                            $featuredImageAltCaption .= "</p>";
                        }
                    }
                    /*** PREPARE TWITTER AND FB SHARE URLS ****/
                    $shareLink = get_permalink();
                    global $pageBodyID;
                    if ($pageBodyID == "newsletter") {
                        global $newsletterPostPermalink;
                        $shareLink = $newsletterPostPermalink;
                    }
                    /* remove html tags, smart quotes and trailing ellipses from description */
                    $ogDescription = independent_publisher_first_sentence_excerpt();
                    $ogDescription = wp_strip_all_tags($ogDescription);
                    $ogDescription = iconv('UTF-8', 'ASCII//TRANSLIT', $ogDescription);
                    //smart quotes
                    $ogDescription = str_replace("[&hellip;]", "...", $ogDescription);
                    //the title/headline field, followed by the URL and the author's twitter handle
                    $twitterText = "";
                    $twitterText .= html_entity_decode(get_the_title());
                    $twitterHandle = get_the_author_meta('twitterHandle');
                    $twitterHandle = str_replace("@", "", $twitterHandle);
                    if ($twitterHandle && $twitterHandle != '') {
                        $twitterText .= " by @" . $twitterHandle;
                    } else {
                        $authorDisplayName = get_the_author();
                        if ($authorDisplayName && $authorDisplayName != '') {
                            $twitterText .= " by " . $authorDisplayName;
                        }
                    }
                    $twitterText .= " " . $shareLink;
                    $hashtags = "";
                    //$hashtags="testhashtag1,testhashtag2";
                    ///$twitterURL="//twitter.com/intent/tweet?url=" . urlencode(get_permalink()) . "&text=" . urlencode($ogDescription) . "&hashtags=" . urlencode($hashtags);
                    $twitterURL = "//twitter.com/intent/tweet?text=" . rawurlencode($twitterText);
                    $fbUrl = "//www.facebook.com/sharer/sharer.php?u=" . urlencode($shareLink);
                    ?>
						<div class="post-cover-title-wrapper <?php 
                    echo $postCoverTitleWrapperExtraClass;
                    ?>
">
							<?php 
                    if ($showPostCover) {
                        ?>
							<div class="post-cover-title-image postCoverResponsive" ></div>
							<?php 
                    }
                    ?>

							<?php 
                    if (independent_publisher_categorized_blog()) {
                        echo independent_publisher_series_category('', false);
                    }
                    ?>
								<div class="post-cover-title-head">
									<header class="post-cover-title">
										<?php 
                    if (independent_publisher_categorized_blog()) {
                        ?>
										
										<?php 
                        if (independent_publisher_has_full_width_featured_image()) {
                            echo $featuredImageCaption;
                        }
                        ?>

		
										<?php 
                        if (true || $pageBodyID != "newsletter") {
                            ?>
											<?php 
                            echo independent_publisher_post_categories('', false);
                            ?>
										<?php 
                        }
                        ?>

										<div id='socialPost'>
											<ul>
												<li class='facebook'><a class="share" id="facebook" href="<?php 
                        echo $fbUrl;
                        ?>
"></a></li>
												<li class='twitter'><a class="share" id="twitter" href="<?php 
                        echo $twitterURL;
                        ?>
"></a></li>
											</ul>
										</div>

										<?php 
                    }
                    ?>

										<?php 
                    if (true || $pageBodyID != "newsletter") {
                        ?>
											<h1 class="entry-title" itemprop="name">
												<?php 
                        echo get_the_title();
                        ?>
											</h1>
										<?php 
                    }
                    ?>
										
										<?php 
                    $subtitle = get_post_meta(get_the_id(), 'independent_publisher_post_cover_subtitle', true);
                    ?>
										<?php 
                    if ($subtitle) {
                        ?>
											<h2 class="entry-subtitle">
												<?php 
                        echo $subtitle;
                        ?>
											</h2>
										<?php 
                    }
                    ?>
										<?php 
                    if ($pageBodyID == "newsletter" || !is_page()) {
                        ?>
											<h3 class="entry-title-meta">
												<span class="entry-title-meta-author">
													<a class="author-avatar" href="<?php 
                        echo get_author_posts_url(get_the_author_meta('ID'));
                        ?>
">
														<?php 
                        echo get_avatar(get_the_author_meta('ID'), 32);
                        ?>
													</a>
													<?php 
                        if (!independent_publisher_categorized_blog()) {
                            echo independent_publisher_entry_meta_author_prefix() . ' ';
                        }
                        independent_publisher_posted_author();
                        ?>
												</span>
												<?php 
                        /* if ( independent_publisher_categorized_blog() ) {
                        				echo independent_publisher_entry_meta_category_prefix() . ' ' . independent_publisher_post_categories( '', true );
                        			} */
                        ?>
												<span class="entry-title-meta-post-date">
													<span class="sep"> <?php 
                        echo apply_filters('independent_publisher_entry_meta_separator', '|');
                        ?>
 </span>
													<?php 
                        independent_publisher_posted_on_date();
                        ?>
 
												</span>
												<?php 
                        do_action('independent_publisher_entry_title_meta', $separator = ' | ');
                        ?>
											</h3>
										<?php 
                    }
                    ?>
									</header>
								</div>

							</div>
							<?php 
                    /*Add second caption below the header div for tablet 500 - 1200px widths  views*/
                    if (independent_publisher_has_full_width_featured_image() && $postCoverTitleWrapperExtraClass != "postCoverTitleAlwaysBelow") {
                        echo $featuredImageAltCaption;
                    }
                    ?>
					<?php 
                } else {
                    the_post_thumbnail(apply_filters('independent_publisher_full_width_featured_image_size', 'independent_publisher_post_thumbnail'), array('class' => 'full-width-featured-image'));
                }
            }
        }
        // end of the loop.
    }
}
/**
 * Filter for extending image tag to include srcset attribute.
 *
 * @see images_send_to_editor
 * @return string HTML for image.
 */
function tevkori_extend_image_tag($html, $id, $caption, $title, $align, $url, $size, $alt)
{
    add_filter('editor_max_image_size', 'tevkori_editor_image_size');
    // Get the srcset attribute.
    $srcset = tevkori_get_srcset_string($id, $size);
    remove_filter('editor_max_image_size', 'tevkori_editor_image_size');
    if ($srcset) {
        // Build the data-sizes attribute if sizes were returned.
        $sizes = tevkori_get_sizes($id, $size);
        $sizes = $sizes ? 'data-sizes="' . $sizes . '"' : '';
        /*** BEGIN ODDI Custom: we want to always use the 300 src ***/
        $newImgSrc = "";
        $tempSources = tevkori_get_srcset_array($id, 'medium');
        foreach ($tempSources as $key => $tempSource) {
            if (strpos($tempSource, '300w')) {
                $newImgSrc = str_replace(' 300w', '', $tempSource);
            }
        }
        if ($newImgSrc != "") {
            $html = preg_replace('/(src\\s*=\\s*"(.+?)")/', 'src="' . $newImgSrc . '"', $html);
        }
        /*** END ODDI Custom ***/
        $html = preg_replace('/(src\\s*=\\s*"(.+?)")/', '$1 ' . $sizes . ' ' . $srcset, $html);
    }
    return $html;
}
 function test_tevkori_get_srcset_array_no_width()
 {
     // Filter image_downsize() output.
     add_filter('image_downsize', array($this, '_test_tevkori_get_srcset_array_no_width_filter'));
     // Make our attachement.
     $id = $this->_test_img();
     $srcset = tevkori_get_srcset_array($id, 'medium');
     // The srcset should be false
     $this->assertFalse($srcset);
     // Remove filter.
     remove_filter('image_downsize', array($this, '_test_tevkori_get_srcset_array_no_width_filter'));
 }
/**
 * Show Full Width Featured Image on single pages if post has full width featured image selected
 * or if Auto-Set Featured Image as Post Cover option is enabled
 */
function independent_publisher_full_width_featured_image()
{
    if (independent_publisher_has_full_width_featured_image()) {
        while (have_posts()) {
            the_post();
            if (has_post_thumbnail()) {
                if (independent_publisher_post_has_post_cover_title()) {
                    //tevkori_get_srcset_array( $id, $size = 'thumbnail' ) {
                    //global $wpdb;
                    $tempSources = tevkori_get_srcset_array(get_post_thumbnail_id(), 'full');
                    //sources aren't automatically in numeric order.  ksort does the trick.
                    ksort($tempSources);
                    echo "<style>\n";
                    $counter = 0;
                    $prevWidth = 0;
                    foreach ($tempSources as $key => $tempSource) {
                        //we're workign with an array of sourceset entries ... gotta get rid of the width part
                        $counter++;
                        $tempSource = preg_replace('/(.*)\\s(.*)/', '$1', $tempSource);
                        if ($counter == 1) {
                            echo "\t.postCoverResponsive { background-image: url({$tempSource}) !important; }\n";
                        } elseif ($counter < count($tempSources)) {
                            echo "\t@media (min-width: " . ($prevWidth + 1) . "px) and (max-width: " . $key . "px) {\n";
                            echo "\t\t.postCoverResponsive { background-image: url({$tempSource}) !important; }\n";
                            echo "\t}\n";
                        } else {
                            echo "\t@media (min-width: " . ($prevWidth + 1) . "px) {\n";
                            echo "\t\t.postCoverResponsive { background-image: url({$tempSource}) !important; }\n";
                            echo "\t}\n";
                        }
                        $prevWidth = $key;
                    }
                    echo "</style>\n";
                    $featured_image_url = wp_get_attachment_image_src(get_post_thumbnail_id(), apply_filters('independent_publisher_full_width_featured_image_size', 'independent_publisher_post_thumbnail'));
                    $featured_image_url = $featured_image_url[0];
                    ?>
						<div class="post-cover-title-wrapper">
							<div class="post-cover-title-image postCoverResponsive" ></div>
								<div class="post-cover-title-head">
									<header class="post-cover-title">
										<h1 class="entry-title" itemprop="name">
											<?php 
                    echo get_the_title();
                    ?>
										</h1>
										<?php 
                    $subtitle = get_post_meta(get_the_id(), 'independent_publisher_post_cover_subtitle', true);
                    ?>
										<?php 
                    if ($subtitle) {
                        ?>
											<h2 class="entry-subtitle">
												<?php 
                        echo $subtitle;
                        ?>
											</h2>
										<?php 
                    }
                    ?>
										<?php 
                    if (!is_page()) {
                        ?>
											<h3 class="entry-title-meta">
												<span class="entry-title-meta-author">
													<a class="author-avatar" href="<?php 
                        echo get_author_posts_url(get_the_author_meta('ID'));
                        ?>
">
														<?php 
                        echo get_avatar(get_the_author_meta('ID'), 32);
                        ?>
													</a>
													<?php 
                        if (!independent_publisher_categorized_blog()) {
                            echo independent_publisher_entry_meta_author_prefix() . ' ';
                        }
                        independent_publisher_posted_author();
                        ?>
												</span>
												<?php 
                        if (independent_publisher_categorized_blog()) {
                            echo independent_publisher_entry_meta_category_prefix() . ' ' . independent_publisher_post_categories('', true);
                        }
                        ?>
												<span class="entry-title-meta-post-date">
													<span class="sep"> <?php 
                        echo apply_filters('independent_publisher_entry_meta_separator', '|');
                        ?>
 </span>
													<?php 
                        independent_publisher_posted_on_date();
                        ?>
												</span>
												<?php 
                        do_action('independent_publisher_entry_title_meta', $separator = ' | ');
                        ?>
											</h3>
										<?php 
                    }
                    ?>
									</header>
								</div>
							</div>
					<?php 
                } else {
                    the_post_thumbnail(apply_filters('independent_publisher_full_width_featured_image_size', 'independent_publisher_post_thumbnail'), array('class' => 'full-width-featured-image'));
                }
            }
        }
        // end of the loop.
    }
}