C:\xampp\htdocs\landing\wp-content\plugins\amp\includes\sanitizers\class-amp-playbuzz-sanitizer.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
/**
 * Class AMP_Playbuzz_Sanitizer
 *
 * @package AMP
 */

/**
 * Class AMP_Playbuzz_Sanitizer
 *
 * Converts Playbuzz embed to <amp-playbuzz>
 *
 * @see https://www.playbuzz.com/
 * @internal
 */
class AMP_Playbuzz_Sanitizer extends AMP_Base_Sanitizer {

    
/**
     * Tag.
     *
     * @var string HTML tag to identify and replace with AMP version.
     * @since 0.2
     */
    
public static $tag 'div';

    
/**
     * PlayBuzz class.
     *
     * @var string CSS class to identify Playbuzz <div> to replace with AMP version.
     *
     * @since 0.2
     */
    
public static $pb_class 'pb_feed';

    
/**
     * Hardcoded height to set for Playbuzz elements.
     *
     * @var string
     *
     * @since 0.2
     */
    
private static $height '500';

    
/**
     * Get mapping of HTML selectors to the AMP component selectors which they may be converted into.
     *
     * @return array Mapping.
     */
    
public function get_selector_conversion_mapping() {
        return [
            
'div.pb_feed' => [ 'amp-playbuzz.pb_feed' ],
        ];
    }

    
/**
     * Sanitize the Playbuzz elements from the HTML contained in this instance's Dom\Document.
     *
     * @since 0.2
     */
    
public function sanitize() {

        
$nodes     $this->dom->getElementsByTagNameself::$tag );
        
$num_nodes $nodes->length;

        if ( 
=== $num_nodes ) {
            return;
        }

        for ( 
$i $num_nodes 1$i >= 0$i-- ) {
            
$node $nodes->item$i );

            if ( 
self::$pb_class !== $node->getAttribute'class' ) ) {
                continue;
            }

            
$old_attributes AMP_DOM_Utils::get_node_attributes_as_assoc_array$node );

            
$new_attributes $this->filter_attributes$old_attributes );

            if ( ! isset( 
$new_attributes['data-item'] ) && ! isset( $new_attributes['src'] ) ) {
                continue;
            }

            
$new_node AMP_DOM_Utils::create_node$this->dom'amp-playbuzz'$new_attributes );

            
$node->parentNode->replaceChild$new_node$node );

            
$this->did_convert_elements true;

        }

    }

    
/**
     * "Filter" HTML attributes for <amp-audio> elements.
     *
     * @since 0.2
     *
     * @param string[] $attributes {
     *      Attributes.
     *
     *      @type string $data-item Playbuzz <div> attribute - Pass along if found and not empty.
     *      @type string $data-game Playbuzz <div> attribute - Assign to its value to $attributes['src'] if found and not empty.
     *      @type string $data-game-info Playbuzz <div> attribute - Assign to its value to $attributes['data-item-info'] if found.
     *      @type string $data-shares Playbuzz <div> attribute - Assign to its value to $attributes['data-share-buttons'] if found.
     *      @type string $data-comments Playbuzz <div> attribute - Pass along if found.
     *      @type int $height Playbuzz <div> attribute - Set to hardcoded value of 500.
     * }
     * @return array Returns HTML attributes; removes any not specifically declared above from input.
     */
    
private function filter_attributes$attributes ) {
        
$out = [];

        foreach ( 
$attributes as $name => $value ) {
            switch ( 
$name ) {
                case 
'data-item':
                    if ( ! empty( 
$value ) ) {
                        
$out['data-item'] = $value;
                    }
                    break;

                case 
'data-game':
                    if ( ! empty( 
$value ) ) {
                        
$out['src'] = $value;
                    }
                    break;

                case 
'data-shares':
                    
$out['data-share-buttons'] = $value;
                    break;

                case 
'data-game-info':
                case 
'data-comments':
                case 
'class':
                    
$out$name ] = $value;
                    break;

                default:
                    break;
            }
        }

        
$out['height'] = self::$height;

        return 
$out;
    }
}
x

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