C:\xampp\htdocs\landing\wp-content\plugins\penci-pennews-amp\includes\amp-post-template-actions.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<?php
// Callbacks for adding content to an AMP template

function penci_amp_post_template_init_hooks() {
    
add_action'penci_amp_post_template_head''penci_amp_post_template_add_title' );
    
add_action'penci_amp_post_template_head''penci_amp_post_template_add_enqueue_static' );
    
add_action'penci_amp_post_template_head''penci_amp_post_template_add_canonical' );
    
add_action'penci_amp_post_template_head''penci_amp_post_template_add_scripts' );
    
add_action'penci_amp_post_template_head''penci_amp_post_template_add_fonts' );
    
add_action'penci_amp_post_template_head''penci_amp_post_template_add_boilerplate_css' );
    
add_action'penci_amp_post_template_head''penci_amp_post_template_add_schemaorg_metadata' );
    
add_action'penci_amp_post_template_css''penci_amp_post_template_add_styles'99 );
    
add_action'penci_amp_post_template_css''penci_amp_post_template_add_slider_styles'99 );
    
add_action'penci_amp_post_template_data''penci_amp_post_template_add_analytics_script' );
    
add_action'penci_amp_post_template_footer''penci_amp_post_template_add_analytics_data' );
}

function 
penci_amp_post_template_add_slider_styles() {

    
$featured_args = array(
        
'post_type'           => 'post',
        
'posts_per_page'      => 3,
        
'ignore_sticky_posts' => TRUE,
        
'meta_query'          => array( // only posts with thumbnail
            
'key' => '_thumbnail_id'
        
)
    );

    
$featured_slider_query = new WP_Query$featured_args );
    if ( 
$featured_slider_query->have_posts() ) {
        while ( 
$featured_slider_query->have_posts() ) {
            
$featured_slider_query->the_post();

            
$src penci_amp_post_thumbnail( array(
                    
'post' => get_the_ID(),
                    
'size' => 'penci-thumb-760-570',
                    
'return_url' => true
                
)
            );

            echo 
'#penci-slider-img-holder' get_the_ID() . '{ background-image:url(' $src '); }';
        }

        
wp_reset_postdata();
    }
}

function 
penci_amp_post_template_add_enqueue_static$penci_amp_template ){

    if( 
get_theme_mod'penci_enable_cookie_law' ) ){
        echo 
'<script async custom-element="amp-user-notification" src="https://cdn.ampproject.org/v0/amp-user-notification-0.1.js"></script>';
    }

    if ( 
is_search() ) {
        echo 
'<script async custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>';
    }

    if ( 
$ga_code penci_amp_get_setting'penci-amp-analytics' ) ) {
        echo 
'<script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>';
    }

    if( 
is_singular() ){
        echo 
'<script async custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>';
        echo 
'<script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-0.2.js"></script>';
    }

    
// Show script support ad
    
$ad_home_below_slider       penci_amp_get_setting'penci_amp_ad_home_below_slider' );
    
$ad_home_below_latest_posts penci_amp_get_setting'penci_amp_ad_home_below_latest_posts' );
    
$ad_archive_above_posts     penci_amp_get_setting'penci_amp_ad_archive_above_posts' );
    
$ad_archive_below_posts     penci_amp_get_setting'penci_amp_ad_archive_below_posts' );
    
$ad_single_above_cat        penci_amp_get_setting'penci_amp_ad_single_above_cat' );
    
$ad_single_below_img        penci_amp_get_setting'penci_amp_ad_single_below_img' );
    
$ad_single_below_content    penci_amp_get_setting'penci_amp_ad_single_below_content' );

    if( ( !  
function_exists'is_woocommerce' ) || ( function_exists'is_woocommerce' ) && ! is_woocommerce() ) ) ) {
        if ( ( ( 
is_home() || is_front_page() ) && ( $ad_home_below_slider || $ad_home_below_latest_posts ) ) ||
             ( ( 
is_archive() || is_tax() ) && ( $ad_archive_above_posts || $ad_archive_below_posts ) ) ||
             ( ( 
is_single() || is_page() ) && ( $ad_single_above_cat || $ad_single_below_img || $ad_single_below_content ) )
        ) {

            echo 
'<script async custom-element="amp-ad" src="https://cdn.ampproject.org/v0/amp-ad-0.1.js"></script>';
        }
    }
    if( 
is_front_page() || is_home() ) {
        echo 
'<script async custom-element="amp-carousel" src="https://cdn.ampproject.org/v0/amp-carousel-0.1.js"></script>';
    }

    
$theme_location '';
    if ( 
has_nav_menu'penci-amp-sidebar-nav' ) ) :
        
$theme_location 'penci-amp-sidebar-nav';
    elseif( 
has_nav_menu'menu-1' ) ):
        
$theme_location 'menu-1';
    endif;

    
$menu_items_has_children false;
    if( 
$theme_location ) {
        if ( ( 
$locations get_nav_menu_locations() ) && isset( $locations$theme_location ] ) ) {
            
$menu wp_get_nav_menu_object$locations$theme_location ] );

            if ( 
$menu && ! is_wp_error$menu ) && ! isset( $menu_items ) ) {
                
$menu_items wp_get_nav_menu_items$menu->term_id, array( 'update_post_term_cache' => false ) );

                foreach ( (array) 
$menu_items as $menu_item ) {
                    if ( 
$menu_item->menu_item_parent ) {
                        
$menu_items_has_children true;
                    }
                }
            }
        }
    }

    if ( 
$menu_items_has_children || is_singular'product' ) ) {
        echo 
'<script async custom-element="amp-accordion" src="https://cdn.ampproject.org/v0/amp-accordion-0.1.js"></script>';
    }
    
?>
    <link rel="stylesheet" id="font-awesome-css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" type="text/css" media="all">
    <script async custom-element="amp-sidebar" src="https://cdn.ampproject.org/v0/amp-sidebar-0.1.js"></script>
    <?php
}

function 
penci_amp_post_template_add_title$penci_amp_template ) {
    
?>
    <title><?php echo esc_html$penci_amp_template->get'document_title' ) ); ?></title>
    <?php
}

function 
penci_amp_post_template_add_canonical$penci_amp_template ) {
    
?>
    <link rel="canonical" href="<?php echo esc_url$penci_amp_template->get'canonical_url' ) ); ?>" />
    <?php
}

function 
penci_amp_post_template_add_scripts$penci_amp_template ) {
    
$scripts $penci_amp_template->get'penci_amp_component_scripts', array() );
    
$video_amp_scripts = array();
    if ( 
is_single() && has_post_format'video' ) ) {

        
$post_id           get_the_ID();
        
$penci_video       get_post_meta$post_id'_format_video_embed'true );
        
$penci_amp_content = new Penci_AMP_Content$penci_video,
            
apply_filters'penci_amp_content_embed_handlers', array(
                
'Penci_AMP_Twitter_Embed_Handler'     => array(),
                
'Penci_AMP_YouTube_Embed_Handler'     => array(),
                
'Penci_AMP_DailyMotion_Embed_Handler' => array(),
                
'Penci_AMP_Vimeo_Embed_Handler'       => array(),
                
'Penci_AMP_SoundCloud_Embed_Handler'  => array(),
                
'Penci_AMP_Instagram_Embed_Handler'   => array(),
                
'Penci_AMP_Vine_Embed_Handler'        => array(),
                
'Penci_AMP_Facebook_Embed_Handler'    => array(),
                
'Penci_AMP_Pinterest_Embed_Handler'   => array(),
                
'Penci_AMP_Gallery_Embed_Handler'     => array(),
            ), 
$penci_video ),
            
apply_filters'penci_amp_content_sanitizers', array(
                
'Penci_AMP_Style_Sanitizer'       => array(),
                
'Penci_AMP_Img_Sanitizer'         => array(),
                
'Penci_AMP_Video_Sanitizer'       => array(),
                
'Penci_AMP_Audio_Sanitizer'       => array(),
                
'Penci_AMP_Form_Sanitizer'        => array(),
                
//'Penci_AMP_Playbuzz_Sanitizer'    => array(),
                
'Penci_AMP_Iframe_Sanitizer'      => array(
                    
'add_placeholder' => true,
                ),
                
'AMP_Tag_And_Attribute_Sanitizer' => array(),
            ), 
$penci_video )
        );

        
$video_amp_scripts $penci_amp_content->get_penci_amp_scripts();
    }

    if ( 
$video_amp_scripts && is_array$video_amp_scripts ) ) {
        
$scripts array_merge$scripts$video_amp_scripts );
    }

    if ( ! empty( 
$scripts ) ) {
        foreach ( (array) 
$scripts as $element => $script ) :
            
$custom_type = ( $element == 'amp-mustache' ) ? 'template' 'element'?>
            <script custom-<?php echo esc_attr$custom_type ); ?>="<?php echo esc_attr$element ); ?>" src="<?php echo esc_url$script ); ?>" async></script>
        <?php endforeach;
    }
    
?>
    <script src="<?php echo esc_url$penci_amp_template->get'penci_amp_runtime_script' ) ); ?>" async></script>
    <?php
}

function 
penci_amp_post_template_add_fonts$penci_amp_template ) {
    
$font_urls $penci_amp_template->get'font_urls', array() );
    foreach ( 
$font_urls as $slug => $url ) : ?>
        <link rel="stylesheet" href="<?php echo esc_url$url ); ?>">
    <?php endforeach;
}

function 
penci_amp_post_template_add_boilerplate_css$penci_amp_template ) {
    
?>
    <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
    <?php
}

function 
penci_amp_post_template_add_schemaorg_metadata$penci_amp_template ) {
    
$metadata $penci_amp_template->get'metadata' );
    if ( empty( 
$metadata ) ) {
        return;
    }
    
?>
    <script type="application/ld+json"><?php echo wp_json_encode$metadata ); ?></script>
    <?php
}

function 
penci_amp_post_template_add_styles$penci_amp_template ) {

    
$styles $penci_amp_template->get'post_penci_amp_styles' );
    if ( ! empty( 
$styles ) ) {
        echo 
'/* Inline styles */' PHP_EOL;
        foreach ( 
$styles as $selector => $declarations ) {
            
$declarations implode';'$declarations ) . ';';
            
printf'%1$s{%2$s}'$selector$declarations );
        }
    }
}

function 
penci_amp_post_template_add_analytics_script$data ) {
    if ( ! empty( 
$data['penci_amp_analytics'] ) ) {
        
$data['penci_amp_component_scripts']['amp-analytics'] = 'https://cdn.ampproject.org/v0/amp-analytics-0.1.js';
    }
    return 
$data;
}

function 
penci_amp_post_template_add_analytics_data$penci_amp_template ) {
    
$analytics_entries $penci_amp_template->get'penci_amp_analytics' );
    if ( empty( 
$analytics_entries ) ) {
        return;
    }

    foreach ( 
$analytics_entries as $id => $analytics_entry ) {
        if ( ! isset( 
$analytics_entry['type'], $analytics_entry['attributes'], $analytics_entry['config_data'] ) ) {
            
_doing_it_wrong__FUNCTION__sprintfesc_html__'Analytics entry for %s is missing one of the following keys: `type`, `attributes`, or `config_data` (array keys: %s)''penci-amp' ), esc_html$id ), esc_htmlimplode', 'array_keys$analytics_entry ) ) ) ), '0.3.2' );
            continue;
        }
        
$script_element Penci_AMP_HTML_Utils::build_tag'script', array(
            
'type' => 'application/json',
        ), 
wp_json_encode$analytics_entry['config_data'] ) );

        
$penci_amp_analytics_attr array_merge( array(
            
'id' => $id,
            
'type' => $analytics_entry['type'],
        ), 
$analytics_entry['attributes'] );

        echo 
Penci_AMP_HTML_Utils::build_tag'amp-analytics'$penci_amp_analytics_attr$script_element );
    }
}
x

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