C:\xampp\htdocs\landing\wp-content\updraft\plugins-old\amp\src\Embed\HandlesGalleryEmbed.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
 * Trait HandlesGalleryEmbed.
 *
 * @package AmpProject\AmpWP
 */

namespace AmpProject\AmpWP\Embed;

use 
AmpProject\AmpWP\Component\Carousel;
use 
AmpProject\AmpWP\Dom\ElementList;
use 
AmpProject\Attribute;
use 
AmpProject\Dom\Document;
use 
AmpProject\Tag;
use 
DOMElement;
use 
DOMNodeList;

/**
 * Trait HandlesGalleryEmbed.
 *
 * Contains logic related to both gallery shortcodes and blocks.
 *
 * @since 2.0
 * @internal
 */
trait HandlesGalleryEmbed {

    
/**
     * Transforms the raw gallery embed to become AMP compatible.
     *
     * @param bool        $is_carousel     Whether the embed should be transformed into an <amp-carousel>.
     * @param bool        $is_lightbox     Whether the gallery images should be shown in a lightbox.
     * @param DOMElement  $gallery_element Gallery element.
     * @param DOMNodeList $img_elements    List of image elements in gallery.
     */
    
protected function process_gallery_embed$is_carousel$is_lightboxDOMElement $gallery_elementDOMNodeList $img_elements ) {
        
// Bail if the embed does not support carousel or lightbox.
        
if ( ! $is_carousel && ! $is_lightbox ) {
            return;
        }

        
// Bail if there are no images.
        
if ( === $img_elements->length ) {
            return;
        }

        
// If the carousel is not required but the lightbox is, add the `lightbox` attribute to each image and return.
        
if ( ! $is_carousel && $is_lightbox ) {
            
$this->add_lightbox_attribute_to_img_nodes$img_elements );
            return;
        }

        if ( 
$is_carousel ) {
            
$amp_carousel     $this->generate_amp_carousel$img_elements$is_lightbox );
            
$carousel_element $amp_carousel->get_dom_element();

            if ( 
$is_lightbox ) {
                
$carousel_element->setAttributeAttribute::LIGHTBOX'' );
            }

            
$gallery_element->parentNode->replaceChild$carousel_element$gallery_element );
        }
    }

    
/**
     * Create an AMP carousel component from the list of images specified.
     *
     * @param DOMNodeList $img_elements    List of images in the gallery.
     * @param boolean     $is_amp_lightbox Whether the gallery should have a lightbox.
     * @return Carousel An object containing markup for <amp-carousel>.
     */
    
protected function generate_amp_carouselDOMNodeList $img_elements$is_amp_lightbox ) {
        
$images = new ElementList();

        foreach ( 
$img_elements as $img_element ) {
            
$element             $img_element;
            
$parent_element_name $img_element->parentNode->nodeName;

            if ( 
Tag::=== $parent_element_name && ! $is_amp_lightbox ) {
                
$element $img_element->parentNode;
            }

            
$images $images->add$element$this->get_caption_element$img_element ) );
        }

        
$node $img_elements->item);
        return new 
CarouselDocument::fromNode$node ), $images );
    }

    
/**
     * Sets the `lightbox` attribute to each image in the specified list.
     *
     * @param DOMNodeList $img_elements List of image elements.
     */
    
protected function add_lightbox_attribute_to_img_nodesDOMNodeList $img_elements ) {
        
/** @var DOMElement $img_element */
        
foreach ( $img_elements as $img_element ) {
            
$img_element->setAttributeAttribute::LIGHTBOX'' );
        }
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586