'0.4.2' ) { return require AMPFORWP_PLUGIN_DIR .'templates/customizer/customizer-new.php' ; } else { return require AMPFORWP_PLUGIN_DIR .'templates/customizer/customizer.php' ; } } else { return require AMPFORWP_PLUGIN_DIR .'templates/customizer/customizer.php' ; } } } ampforwp_include_customizer_files(); //0. define('AMPFORWP_COMMENTS_PER_PAGE', ampforwp_define_comments_number() ); // Define number of comments function ampforwp_define_comments_number(){ global $redux_builder_amp; $number_of_comments = ''; if(isset($redux_builder_amp['ampforwp-number-of-comments'])){ $number_of_comments = $redux_builder_amp['ampforwp-number-of-comments']; } return $number_of_comments; } // 1. Add Home REL canonical // Add AMP rel-canonical for home and archive pages add_action('amp_init','ampforwp_allow_homepage'); function ampforwp_allow_homepage() { add_action( 'wp', 'ampforwp_add_endpoint_actions' ); } function ampforwp_add_endpoint_actions() { $ampforwp_is_amp_endpoint = ampforwp_is_amp_endpoint(); if ( $ampforwp_is_amp_endpoint ) { amp_prepare_render(); } else { add_action( 'wp_head', 'ampforwp_home_archive_rel_canonical', 1 ); } $cpage_var = get_query_var('cpage'); if ( $cpage_var >= 1) : remove_action( 'wp_head', 'ampforwp_home_archive_rel_canonical', 1 ); endif; } function ampforwp_amphtml_generator(){ global $redux_builder_amp; global $wp, $post; $endpoint_check = false; $endpoint_check = $redux_builder_amp['amp-core-end-point']; if( is_attachment() ) { return; } if( is_home() && is_front_page() && !$redux_builder_amp['ampforwp-homepage-on-off-support'] ) { return; } if( is_front_page() && ! $redux_builder_amp['ampforwp-homepage-on-off-support'] ) { return; } if ( is_archive() && !$redux_builder_amp['ampforwp-archive-support'] ) { return; } // #1192 Password Protected posts exclusion if(post_password_required( $post )){ return; } // #1443 AMP should be skip on the check out page if(class_exists( 'WooCommerce' )){ if(function_exists('is_checkout') && is_checkout()){ return; } } // #872 no-amphtml if selected as hide from settings if(is_archive() && $redux_builder_amp['ampforwp-archive-support']){ $selected_cats = array(); $categories = get_the_category(); if ( $categories ) { $category_id = $categories[0]->cat_ID; $get_categories_from_checkbox = $redux_builder_amp['hide-amp-categories']; // Check if $get_categories_from_checkbox has some cats then only show if ( $get_categories_from_checkbox ) { $get_selected_cats = array_filter($get_categories_from_checkbox); foreach ($get_selected_cats as $key => $value) { $selected_cats[] = $key; } if($selected_cats && $category_id){ if(in_array($category_id, $selected_cats)){ return; } } } } } if ( is_page() && ! $redux_builder_amp['amp-on-off-for-all-pages'] && ! is_home() && ! is_front_page() ) { return; } if ( is_home() && ! ampforwp_is_blog() && !$redux_builder_amp['ampforwp-homepage-on-off-support'] ) { return; } $query_arg_array = $wp->query_vars; if( in_array( "cpage" , $query_arg_array ) ) { if( is_front_page() && $wp->query_vars['cpage'] >= '2' ) { return; } if( is_singular() && $wp->query_vars['cpage'] >= '2' ) { return; } } if ( is_home() || is_front_page() || is_archive() ){ global $wp; $current_archive_url = home_url( $wp->request ); $amp_url = trailingslashit($current_archive_url); } else { $amp_url = amp_get_permalink( get_queried_object_id() ); } global $post; $ampforwp_amp_post_on_off_meta = get_post_meta( get_the_ID(),'ampforwp-amp-on-off',true); if ( is_singular() && $ampforwp_amp_post_on_off_meta === 'hide-amp' ) { //dont Echo anything } else { $supported_types = ampforwp_get_all_post_types(); $supported_types = apply_filters('get_amp_supported_post_types',$supported_types); $type = get_post_type(); $supported_amp_post_types = in_array( $type , $supported_types ); $query_arg_array = $wp->query_vars; if( array_key_exists( 'paged' , $query_arg_array ) ) { if ( (is_home() || is_archive()) && $wp->query_vars['paged'] >= '2' ) { $new_url = home_url('/'); $category_path = $wp->request; if ( null != $category_path && true != $endpoint_check) { $explode_path = explode("/",$category_path); $inserted = array(AMPFORWP_AMP_QUERY_VAR); array_splice( $explode_path, -2, 0, $inserted ); $impode_url = implode('/', $explode_path); $amp_url = $new_url . $impode_url ; } } if( is_search() && $wp->query_vars['paged'] >= '2' ) { $current_search_url =trailingslashit(get_home_url()) . $wp->request .'/'."?amp=1&s=".get_search_query(); } } $amp_url = user_trailingslashit($amp_url); if( is_search() ) { $current_search_url =trailingslashit(get_home_url())."?amp=1&s=".get_search_query(); $amp_url = untrailingslashit($current_search_url); } $amp_url = ampforwp_url_purifier($amp_url); include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); if( get_option('permalink_structure') && is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' )){ global $sitepress_settings, $wp; if($sitepress_settings[ 'language_negotiation_type' ] == 3){ if( is_singular() ){ $wpml_url =get_permalink( get_queried_object_id() ); $explode_url = explode('/', $wpml_url); $append_amp = 'amp'; array_splice( $explode_url, 5, 0, $append_amp ); $impode_url = implode('/', $explode_url); $amp_url = untrailingslashit($impode_url); } if ( is_home() || is_archive() ){ global $wp; $current_archive_url = home_url( $wp->request ); $explode_path = explode("/",$current_archive_url); $inserted = array(AMPFORWP_AMP_QUERY_VAR); $query_arg_array = $wp->query_vars; if( array_key_exists( 'paged' , $query_arg_array ) ) { array_splice( $explode_path, -3, 0, $inserted ); } else{ array_splice( $explode_path, -1, 0, $inserted ); } $impode_url = implode('/', $explode_path); $amp_url = $impode_url; } } } $amp_url = apply_filters('ampforwp_modify_rel_canonical',$amp_url); if( $supported_amp_post_types) { return $amp_url; } } return; } function ampforwp_home_archive_rel_canonical() { $amp_url = ""; $amp_url = ampforwp_amphtml_generator(); if ( $amp_url ) { printf('', esc_url($amp_url)); } } //end of ampforwp_home_archive_rel_canonical() // Remove default wordpress rel canonical add_filter('amp_frontend_show_canonical','ampforwp_remove_default_canonical'); if (! function_exists('ampforwp_remove_default_canonical') ) { function ampforwp_remove_default_canonical() { return false; } } // 2. Custom Design // Add Homepage AMP file code add_filter( 'amp_post_template_file', 'ampforwp_custom_template', 10, 3 ); function ampforwp_custom_template( $file, $type, $post ) { global $redux_builder_amp; // Custom Homepage and Archive file $slug = array(); $current_url_in_pieces = array(); $ampforwp_custom_post_page = ampforwp_custom_post_page(); if ( 'single' === $type ) { // Homepage and FrontPage if ( is_home() ) { $file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/index.php'; if ( ampforwp_is_blog() ) { $file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/index.php'; } } if ( ampforwp_is_front_page() || ( true == $redux_builder_amp['ampforwp-amp-takeover'] && is_front_page()) ) { $file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/frontpage.php'; } // Archive Pages if ( is_archive() && $redux_builder_amp['ampforwp-archive-support'] && 'single' === $type ) { $file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/archive.php'; } // Search pages if ( is_search() && ( $redux_builder_amp['amp-design-1-search-feature'] || $redux_builder_amp['amp-design-2-search-feature'] || $redux_builder_amp['amp-design-3-search-feature'] ) ) { $file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/search.php'; } } // Custom Single file /*if ( is_single() || is_page() ) { if('single' === $type ) { $file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/single.php'; } }*/ // Polylang compatibility // For Frontpage if ( 'single' === $type && ampforwp_polylang_front_page() && true == $redux_builder_amp['amp-frontpage-select-option'] ) { $file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/frontpage.php'; } return $file; } // 3. Custom Style files //add_filter( 'amp_post_template_file', 'ampforwp_set_custom_style', 10, 3 ); function ampforwp_set_custom_style( $file, $type, $post ) { if ( 'style' === $type ) { $file = ''; } return $file; } add_filter('amp_post_template_dir','ampforwp_new_dir'); function ampforwp_new_dir( $dir ) { global $redux_builder_amp; if ( 1 == $redux_builder_amp['amp-design-selector'] || 2 == $redux_builder_amp['amp-design-selector'] || 3 == $redux_builder_amp['amp-design-selector'] ) { $dir = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector(); } else { $dir = AMPFORWP_CUSTOM_THEME; } return $dir; } //3.5 add_filter( 'amp_post_template_file', 'ampforwp_empty_filter', 10, 3 ); function ampforwp_empty_filter( $file, $type, $post ) { if ( 'empty-filter' === $type ) { $file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/empty-filter.php'; } return $file; } // 4. Custom Header files add_filter( 'amp_post_template_file', 'ampforwp_custom_header', 10, 3 ); function ampforwp_custom_header( $file, $type, $post ) { if ( 'header-bar' === $type ) { $file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/header-bar.php'; } return $file; } // 4.1 Custom Meta-Author files add_filter( 'amp_post_template_file', 'ampforwp_set_custom_meta_author', 10, 3 ); function ampforwp_set_custom_meta_author( $file, $type, $post ) { if ( 'meta-author' === $type ) { $file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/empty-filter.php'; } return $file; } // 4.2 Custom Meta-Taxonomy files add_filter( 'amp_post_template_file', 'ampforwp_set_custom_meta_taxonomy', 10, 3 ); function ampforwp_set_custom_meta_taxonomy( $file, $type, $post ) { if ( 'meta-taxonomy' === $type ) { $file = AMPFORWP_PLUGIN_DIR . 'templates/design-manager/empty-filter.php'; } return $file; } // 4.5 Added hook to add more layout. do_action('ampforwp_after_features_include'); // 5. Customize with Width of the site add_filter( 'amp_content_max_width', 'ampforwp_change_content_width' ); function ampforwp_change_content_width( $content_max_width ) { return 1000; } // 6. Add required Javascripts for extra AMP features // Code updated and added the JS proper way #336 add_filter('amp_post_template_data','ampforwp_add_amp_social_share_script', 20); function ampforwp_add_amp_social_share_script( $data ){ global $redux_builder_amp; if( $redux_builder_amp['enable-single-social-icons'] == true || defined('AMPFORWP_DM_SOCIAL_CHECK') && AMPFORWP_DM_SOCIAL_CHECK === 'true' ) { if( is_single() && is_socialshare_or_socialsticky_enabled_in_ampforwp() ) { if ( empty( $data['amp_component_scripts']['amp-social-share'] ) ) { $data['amp_component_scripts']['amp-social-share'] = 'https://cdn.ampproject.org/v0/amp-social-share-0.1.js'; } } } // Facebook Like Script if( true == $redux_builder_amp['ampforwp-facebook-like-button'] && is_single() && defined('AMPFORWP_DM_SOCIAL_CHECK') && 'true' === AMPFORWP_DM_SOCIAL_CHECK && (! checkAMPforPageBuilderStatus( get_the_ID() ) ) ){ if(empty($data['amp_component_scripts']['amp-facebook-like'])){ $data['amp_component_scripts']['amp-facebook-like'] = 'https://cdn.ampproject.org/v0/amp-facebook-like-0.1.js'; } } return $data; } // 6.1 Adding Analytics Scripts add_filter('amp_post_template_data','ampforwp_register_analytics_script', 20); function ampforwp_register_analytics_script( $data ){ global $redux_builder_amp; if( true == $redux_builder_amp['ampforwp-ga-switch'] || true == $redux_builder_amp['ampforwp-Segment-switch'] || true == $redux_builder_amp['ampforwp-Quantcast-switch'] || true == $redux_builder_amp['ampforwp-comScore-switch'] || true == $redux_builder_amp['ampforwp-Yandex-switch'] || true == $redux_builder_amp['ampforwp-Chartbeat-switch']|| true == $redux_builder_amp['ampforwp-Alexa-switch'] || true == $redux_builder_amp['ampforwp-afs-analytics-switch'] ) { if ( empty( $data['amp_component_scripts']['amp-analytics'] ) ) { $data['amp_component_scripts']['amp-analytics'] = 'https://cdn.ampproject.org/v0/amp-analytics-0.1.js'; } } return $data; } add_filter( 'amp_post_template_data', 'ampforwp_add_amp_related_scripts', 20 ); function ampforwp_add_amp_related_scripts( $data ) { global $redux_builder_amp; // Adding Sidebar Script if ( isset($redux_builder_amp['ampforwp-amp-menu']) && $redux_builder_amp['ampforwp-amp-menu'] && 4 != $redux_builder_amp['amp-design-selector'] ) { if ( empty( $data['amp_component_scripts']['amp-sidebar'] ) ) { $data['amp_component_scripts']['amp-sidebar'] = 'https://cdn.ampproject.org/v0/amp-sidebar-0.1.js'; } } return $data; } // 7. Footer for AMP Pages //add_filter( 'amp_post_template_file', 'ampforwp_custom_footer', 10, 3 ); function ampforwp_custom_footer( $file, $type, $post ) { if ( 'footer' === $type ) { if ( 1 == $redux_builder_amp['amp-design-selector'] || 2 == $redux_builder_amp['amp-design-selector'] || 3 == $redux_builder_amp['amp-design-selector'] ) { $file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/footer.php'; } else { $file = AMPFORWP_CUSTOM_THEME .'/footer.php'; } //$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/footer.php'; } return $file; } add_action('ampforwp_global_after_footer','ampforwp_footer'); function ampforwp_footer() { global $redux_builder_amp; ?>

'; $output .= ''.$redux_builder_amp['ampforwp-ads-sponsorship-label'].''; } } // Ads Optimize For Viewability if( !function_exists('ampforwp_ad_optimize')){ function ampforwp_ad_optimize(){ global $redux_builder_amp; $optimized_code = ''; if( isset( $redux_builder_amp['ampforwp-ads-data-loading-strategy'] ) && true == $redux_builder_amp['ampforwp-ads-data-loading-strategy']){ $optimized_code = 'data-loading-strategy="prefer-viewability-over-views"'; } return $optimized_code; } } // 10. Analytics Area add_action('amp_post_template_footer','ampforwp_analytics',11); function ampforwp_analytics() { // 10.1 Analytics Support added for Google Analytics global $redux_builder_amp; if ( true == $redux_builder_amp['ampforwp-ga-switch'] ){ $ga_fields = array(); $ampforwp_ga_fields = array(); $ga_account = ''; $ga_account = $redux_builder_amp['ga-feild']; $ga_account = str_replace(' ', '', $ga_account); $ga_fields = array( 'vars'=>array( 'account'=>$ga_account ), 'triggers'=> array( 'trackPageview'=> array( 'on'=>'visible', 'request'=>'pageview' ) ) ); $ampforwp_ga_fields = json_encode( $ga_fields); $ampforwp_ga_fields = apply_filters('ampforwp_advance_google_analytics', $ampforwp_ga_fields ); ?>
99999) $afs_server = 'www1'; if ($afs_account > 199999) $afs_server = 'www2'; if ($afs_account > 299999) $afs_server = 'www3'; if ($afs_account > 399999) $afs_server = 'www4'; if ($afs_account > 499999) $afs_server = 'www5'; if ($afs_account > 599999) $afs_server = 'www6'; if ($afs_account > 699999) $afs_server = 'www7'; if ($afs_account > 799999) $afs_server = 'www8'; if ($afs_account > 899999) $afs_server = 'www9'; if ($afs_account > 999999) $afs_server = 'www10'; ?> ]*/', '', $content); $content = preg_replace('/vocab=[^>]*/', '', $content); // $content = preg_replace('/type=[^>]*/', '', $content); $content = preg_replace('/(<[^>]+) value=[^>]*/', '$1', $content); // $content = preg_replace('/date=[^>]*/', '', $content); $content = preg_replace('/noshade=[^>]*/', '', $content); $content = preg_replace('/contenteditable=[^>]*/', '', $content); // $content = preg_replace('/time=[^>]*/', '', $content); $content = preg_replace('/non-refundable=[^>]*/', '', $content); $content = preg_replace('/security=[^>]*/', '', $content); $content = preg_replace('/deposit=[^>]*/', '', $content); $content = preg_replace('/for=[^>]*/', '', $content); $content = preg_replace('/nowrap="nowrap"/', '', $content); $content = preg_replace('#(.*?)#i', '', $content); /*$content = preg_replace('#(.*?)#i', '', $content);*/ $content = preg_replace('#(.*?)#i', '', $content); $content = preg_replace('#(.*?)#i', '', $content); $content = preg_replace('##i', '', $content); $content = preg_replace('##i', '', $content); /* Removed So Inline style can work $content = preg_replace('##i', '', $content); */ $content = preg_replace('/href="javascript:void*/', ' ', $content); $content = preg_replace('/]*>.*?<\/script>/i', '', $content); //for removing attributes within html tags $content = preg_replace('/(<[^>]+) onclick=".*?"/', '$1', $content); /* Removed So Inline style can work $content = preg_replace('/(<[^>]+) style=".*?"/', '$1', $content); */ $content = preg_replace('/(<[^>]+) rel="(.*?) noopener(.*?)"/', '$1 rel="$2$3"', $content); $content = preg_replace('/]+) ref=".*?"/', '$1', $content); /*$content = preg_replace('/(<[^>]+) date=".*?"/', '$1', $content); $content = preg_replace('/(<[^>]+) time=".*?"/', '$1', $content); $content = preg_replace('/(<[^>]+) date/', '$1', $content);*/ $content = preg_replace('/(<[^>]+) imap=".*?"/', '$1', $content); $content = preg_replace('/(<[^>]+) spellcheck/', '$1', $content); $content = preg_replace('/(.*?)<\/font>/', '$2', $content); //removing scripts and rel="nofollow" from Body and from divs //issue #268 //$content = str_replace(' rel="nofollow"',"",$content); $content = preg_replace('/]*>.*?<\/script>/i', '', $content); /// simpy add more elements to simply strip tag but not the content as so /// Array ("p","font"); $tags_to_strip = Array("thrive_headline","type","place","state","city" ); $tags_to_strip = apply_filters('ampforwp_strip_bad_tags', $tags_to_strip); foreach ($tags_to_strip as $tag) { $content = preg_replace("/<\\/?" . $tag . "(.|\\s)*?>/",'',$content); } // regex on steroids from here on // issue #420 $content = preg_replace("/(.*)<\/div>/i", '
$11
', $content); $content = preg_replace('/(.*)<\/like>/i', '', $content); $content = preg_replace('/(.*)<\/g:plusone>/i', '', $content); $content = preg_replace('/imageanchor="1"/i', '', $content); $content = preg_replace('/(.*?)<\/plusone>/', '', $content); $content = preg_replace('/xml:lang=[^>]*/', '', $content); // $content = preg_replace('/ (Improved after 0.9.63) $content = preg_replace('/ tag for itemtype and itemscope #1210 //$content = preg_replace('/)<\/blockquote>/s', "$1", $content); // Convert the Soundcloud embed into URL to build amp-soundcloud $content = preg_replace('/