/**
  * If a gallery is detected, then get all the images from it.
  */
 static function from_gallery($post_id)
 {
     $images = array();
     $post = get_post($post_id);
     if (!empty($post->post_password)) {
         return $images;
     }
     $permalink = get_permalink($post->ID);
     $gallery_images = get_post_galleries_images($post->ID, false);
     foreach ($gallery_images as $galleries) {
         foreach ($galleries as $src) {
             list($raw_src) = explode('?', $src);
             // pull off any Query string (?w=250)
             $raw_src = wp_specialchars_decode($raw_src);
             // rawify it
             $raw_src = esc_url_raw($raw_src);
             // clean it
             $images[] = array('type' => 'image', 'from' => 'gallery', 'src' => $raw_src, 'href' => $permalink);
         }
     }
     return $images;
 }
Exemplo n.º 2
0
	/**
	 * @ticket 22960
	 */
	function test_post_galleries_images() {
		$ids1 = array();
		$ids1_srcs = array();
		foreach ( range( 1, 3 ) as $i ) {
			$attachment_id = $this->factory->attachment->create_object( "image$i.jpg", 0, array(
				'post_mime_type' => 'image/jpeg',
				'post_type' => 'attachment'
			) );
			wp_update_attachment_metadata( $attachment_id, $this->img_dimensions );
			$ids1[] = $attachment_id;
			$ids1_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg";
		}

		$ids2 = array();
		$ids2_srcs = array();
		foreach ( range( 4, 6 ) as $i ) {
			$attachment_id = $this->factory->attachment->create_object( "image$i.jpg", 0, array(
				'post_mime_type' => 'image/jpeg',
				'post_type' => 'attachment'
			) );
			wp_update_attachment_metadata( $attachment_id, $this->img_dimensions );
			$ids2[] = $attachment_id;
			$ids2_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg";
		}

		$ids1_joined = join( ',', $ids1 );
		$ids2_joined = join( ',', $ids2 );

		$blob =<<<BLOB
[gallery ids="$ids1_joined"]

[gallery ids="$ids2_joined"]
BLOB;
		$post_id = $this->factory->post->create( array( 'post_content' => $blob ) );
		$srcs = get_post_galleries_images( $post_id );
		$this->assertEquals( $srcs, array( $ids1_srcs, $ids2_srcs ) );
	}
Exemplo n.º 3
0
/**
 * Returns the number of images displayed by the gallery or galleries in a post.
 *
 * @since  1.6.0
 * @access public
 * @return int
 */
function hybrid_get_gallery_image_count()
{
    /* Set up an empty array for images. */
    $images = array();
    /* Get the images from all post galleries. */
    $galleries = get_post_galleries_images();
    /* Merge each gallery image into a single array. */
    foreach ($galleries as $gallery_images) {
        $images = array_merge($images, $gallery_images);
    }
    /* If there are no images in the array, just grab the attached images. */
    if (empty($images)) {
        $images = get_posts(array('fields' => 'ids', 'post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image', 'numberposts' => -1));
    }
    /* Return the count of the images. */
    return count($images);
}
function wpmc_get_galleries_images($force = false)
{
    if ($force) {
        delete_transient("galleries_images");
        $galleries_images = null;
    } else {
        $galleries_images = get_transient("galleries_images");
    }
    if (!$galleries_images) {
        global $wpdb;
        $galleries_images = array();
        $posts = $wpdb->get_col("SELECT id FROM {$wpdb->posts} WHERE post_type != 'attachment' AND post_status != 'inherit'");
        foreach ($posts as $post) {
            $galleries = get_post_galleries_images($post);
            foreach ($galleries as $gallery) {
                foreach ($gallery as $image) {
                    array_push($galleries_images, $image);
                }
            }
        }
        set_transient("galleries_images", $galleries_images, 60 * 60 * 2);
    }
    return $galleries_images;
}
Exemplo n.º 5
0
/**
 * Post Format: Gallery (Count)
 * 
 * Count the number of images in the Gallery (or Galleries)
 */
function jkl_get_gallery_count()
{
    $images = get_post_galleries_images();
    // from WordPress 3.6.0
    $total_galleries[] = count($images);
    $total_galleries[] = count($images, COUNT_RECURSIVE) - $total_galleries[0];
    $image = reset($images);
    return $total_galleries;
}
Exemplo n.º 6
0
function wpmc_get_galleries_images($force = false)
{
    if ($force) {
        delete_transient("wpmc_galleries_images");
        $galleries_images = null;
    } else {
        $galleries_images = get_transient("wpmc_galleries_images");
    }
    if (!$galleries_images) {
        global $wpdb;
        $galleries_images = array();
        $posts = $wpdb->get_col("SELECT id FROM {$wpdb->posts} WHERE post_type != 'attachment' AND post_status != 'inherit'");
        foreach ($posts as $post) {
            $galleries = get_post_galleries_images($post);
            foreach ($galleries as $gallery) {
                foreach ($gallery as $image) {
                    array_push($galleries_images, $image);
                }
            }
        }
        $post_galleries = get_posts(array('tax_query' => array(array('taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array('post-format-gallery'), 'operator' => 'IN'))));
        foreach ((array) $post_galleries as $gallery_post) {
            $arrImages = get_children('post_type=attachment&post_mime_type=image&post_parent=' . $gallery_post->ID);
            if ($arrImages) {
                foreach ((array) $arrImages as $image_post) {
                    array_push($galleries_images, $image_post->guid);
                }
            }
        }
        wp_reset_postdata();
        set_transient("wpmc_galleries_images", $galleries_images, 60 * 60 * 2);
    }
    return $galleries_images;
}
Exemplo n.º 7
0
 */
?>

<article id="post-<?php 
the_ID();
?>
" <?php 
post_class("fullpage");
?>
>


	<div class="entry-content section">
		<?php 
// Retrieve all galleries of this post
$galleries = get_post_galleries_images($post);
// Loop through all galleries found
foreach ($galleries as $gallery) {
    ?>
			  	<div class="slide">

			    <?php 
    // Loop through each image in each gallery
    foreach ($gallery as $image) {
        echo '<div class="single-img">';
        echo '<img src="';
        echo $image;
        echo '">';
        echo '</div>';
    }
    ?>
Exemplo n.º 8
0
function courage_ui_gallery_carousel($content)
{
    global $post;
    // Only do this on singular items
    if (!is_singular()) {
        return $content;
    }
    // Make sure the post has a gallery in it
    if (!has_shortcode($post->post_content, 'gallery')) {
        return $content;
    }
    $find_gallery = substr($content, strpos($content, "[gallery"));
    // Get our new content without the gallery
    $new_content = str_replace($find_gallery, '', $content);
    // Remove the gallery
    unset($content);
    // Now replace it with our new content
    $output = $new_content;
    // Retrieve all galleries of this post
    $galleries = get_post_galleries_images($post);
    $item = 0;
    $output .= '<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">';
    // Remove the previous gallery
    //   unset($content);
    $output .= '<div class="carousel-inner" role="listbox">';
    // Loop through all galleries found
    $output .= '<ol class="carousel-indicators">';
    foreach ($galleries as $gallery) {
        for ($i = 0; $i < count($gallery); $i++) {
            if ($i == 0) {
                $output .= '<li data-target="#carousel-example-generic" data-slide-to="' . $i . '" class="active"></li>';
            } else {
                $output .= '<li data-target="#carousel-example-generic" data-slide-to="' . $i . '"></li>';
            }
        }
        $output .= '</ol>';
        // Loop through each image in each gallery
        foreach ($gallery as $image) {
            if ($item == 0) {
                $output .= '<div class="item active">';
                $output .= '<img src="' . $image . '" alt="...">';
                $output .= '<div class="carousel-caption">';
                $output .= '';
                $output .= '</div>';
                $output .= '</div>';
            } else {
                $output .= '<div class="item">';
                $output .= '<img src="' . $image . '" alt="...">';
                $output .= '<div class="carousel-caption">';
                $output .= '';
                $output .= '</div>';
                $output .= '</div>';
            }
            $item++;
        }
    }
    $output .= '</div>';
    $output .= '<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">';
    $output .= '<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>';
    $output .= '<span class="sr-only">Previous</span>';
    $output .= '</a>';
    $output .= '<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">';
    $output .= '<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>';
    $output .= '<span class="sr-only">Next</span>';
    $output .= '</a>';
    $output .= '</div>';
    // Append our image list to the content of our post
    $content .= $output;
    return $content;
}