AMP for WP – Accelerated Mobile Pages - Version 0.9.97.60

Version Description

(22th June 2019) = * Feature: Need to add template-mode #3252 * Fixed: Options panel loading issue after 0.9.97.59 * Fixed: Single post main title should be H1 and sub title should be H2 or H3 in design-1 #3350

Download this release

Release Info

Developer mohammed_kaludi
Plugin Icon 128x128 AMP for WP – Accelerated Mobile Pages
Version 0.9.97.60
Comparing to
See all releases

Code changes from version 0.9.97.59 to 0.9.97.60

README.md CHANGED
@@ -4,7 +4,7 @@ Tags: AMP, accelerated mobile pages, mobile, amp project, google amp, amp wp, go
4
  Donate link: https://www.paypal.me/Kaludi/25
5
  Requires at least: 3.0
6
  Tested up to: 5.2.1
7
- Stable tag: 0.9.97.59
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -188,6 +188,11 @@ Device testing done through [BrowserStack](https://www.browserstack.com)
188
 
189
  == Changelog ==
190
 
 
 
 
 
 
191
  = 0.9.97.59 (21th June 2019) =
192
  * Improvements: WP Recipe Maker & WP Recipe Maker PRO Schema compatibility added #3043
193
  * Improvements: Impreza Theme's lazyLoad Option compatibility integrated #3259
4
  Donate link: https://www.paypal.me/Kaludi/25
5
  Requires at least: 3.0
6
  Tested up to: 5.2.1
7
+ Stable tag: 0.9.97.60
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
188
 
189
  == Changelog ==
190
 
191
+ = 0.9.97.60 (22th June 2019) =
192
+ * Feature: Need to add template-mode #3252
193
+ * Fixed: Options panel loading issue after 0.9.97.59
194
+ * Fixed: Single post main title should be H1 and sub title should be H2 or H3 in design-1 #3350
195
+
196
  = 0.9.97.59 (21th June 2019) =
197
  * Improvements: WP Recipe Maker & WP Recipe Maker PRO Schema compatibility added #3043
198
  * Improvements: Impreza Theme's lazyLoad Option compatibility integrated #3259
accelerated-moblie-pages.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Accelerated Mobile Pages
4
  Plugin URI: https://wordpress.org/plugins/accelerated-mobile-pages/
5
  Description: AMP for WP - Accelerated Mobile Pages for WordPress
6
- Version: 0.9.97.59
7
  Author: Ahmed Kaludi, Mohammed Kaludi
8
  Author URI: https://ampforwp.com/
9
  Donate link: https://www.paypal.me/Kaludi/25
@@ -20,7 +20,7 @@ define('AMPFORWP_PLUGIN_DIR_URI', plugin_dir_url(__FILE__));
20
  define('AMPFORWP_DISQUS_URL',plugin_dir_url(__FILE__).'includes/disqus.html');
21
  define('AMPFORWP_IMAGE_DIR',plugin_dir_url(__FILE__).'images');
22
  define('AMPFORWP_MAIN_PLUGIN_DIR', plugin_dir_path( __DIR__ ) );
23
- define('AMPFORWP_VERSION','0.9.97.59');
24
  define('AMPFORWP_EXTENSION_DIR',plugin_dir_path(__FILE__).'includes/options/extensions');
25
  // any changes to AMP_QUERY_VAR should be refelected here
26
  function ampforwp_generate_endpoint(){
@@ -627,6 +627,7 @@ ampforwp_require_file( AMPFORWP_PLUGIN_DIR.'/templates/woo-widget.php' );
627
  function ampforwp_bundle_core_amp_files(){
628
  // Bundling Default plugin
629
  require_once AMPFORWP_PLUGIN_DIR .'/includes/vendor/amp/amp.php';
 
630
 
631
  define( 'AMPFORWP__FILE__', __FILE__ );
632
  if ( ! defined('AMP__VENDOR__DIR__') ) {
3
  Plugin Name: Accelerated Mobile Pages
4
  Plugin URI: https://wordpress.org/plugins/accelerated-mobile-pages/
5
  Description: AMP for WP - Accelerated Mobile Pages for WordPress
6
+ Version: 0.9.97.60
7
  Author: Ahmed Kaludi, Mohammed Kaludi
8
  Author URI: https://ampforwp.com/
9
  Donate link: https://www.paypal.me/Kaludi/25
20
  define('AMPFORWP_DISQUS_URL',plugin_dir_url(__FILE__).'includes/disqus.html');
21
  define('AMPFORWP_IMAGE_DIR',plugin_dir_url(__FILE__).'images');
22
  define('AMPFORWP_MAIN_PLUGIN_DIR', plugin_dir_path( __DIR__ ) );
23
+ define('AMPFORWP_VERSION','0.9.97.60');
24
  define('AMPFORWP_EXTENSION_DIR',plugin_dir_path(__FILE__).'includes/options/extensions');
25
  // any changes to AMP_QUERY_VAR should be refelected here
26
  function ampforwp_generate_endpoint(){
627
  function ampforwp_bundle_core_amp_files(){
628
  // Bundling Default plugin
629
  require_once AMPFORWP_PLUGIN_DIR .'/includes/vendor/amp/amp.php';
630
+ ampforwp_require_file( AMPFORWP_PLUGIN_DIR .'/templates/template-mode/template-mode.php' );
631
 
632
  define( 'AMPFORWP__FILE__', __FILE__ );
633
  if ( ! defined('AMP__VENDOR__DIR__') ) {
changelog.txt CHANGED
@@ -1,5 +1,10 @@
1
  == Changelog ==
2
 
 
 
 
 
 
3
  = 0.9.97.59 (21th June 2019) =
4
  * Improvements: WP Recipe Maker & WP Recipe Maker PRO Schema compatibility added #3043
5
  * Improvements: Impreza Theme's lazyLoad Option compatibility integrated #3259
1
  == Changelog ==
2
 
3
+ = 0.9.97.60 (22th June 2019) =
4
+ * Feature: Need to add template-mode #3252
5
+ * Fixed: Options panel loading issue after 0.9.97.59
6
+ * Fixed: Single post main title should be H1 and sub title should be H2 or H3 in design-1 #3350
7
+
8
  = 0.9.97.59 (21th June 2019) =
9
  * Improvements: WP Recipe Maker & WP Recipe Maker PRO Schema compatibility added #3043
10
  * Improvements: Impreza Theme's lazyLoad Option compatibility integrated #3259
includes/admin-script.js CHANGED
@@ -465,11 +465,6 @@ var reduxOptionTab = function(){
465
  }
466
  //reduxOptionTab();
467
 
468
- $( '.redux-action_bar input' ).on('click', function( e ) {
469
- var license = $(".amp-ls-solve").val();
470
- license = window.atob(license);
471
- $(".amp-ls-solve").val(license);
472
- });
473
  $(".redux-ampforwp-ext-activate").click(function(){
474
  var currentThis = $(this);
475
  var plugin_id = currentThis.attr("id");
@@ -478,7 +473,7 @@ $(".redux-ampforwp-ext-activate").click(function(){
478
  var license = $('input[name="redux_builder_amp[amp-license]['+plugin_id+'][license]"]').val();
479
 
480
  if(newlicense!='' && newlicense.indexOf("**")<0){
481
- license = window.btoa(newlicense);
482
  $('input[name="redux_builder_amp[amp-license]['+plugin_id+'][license]"]').val(license);
483
  }
484
 
@@ -491,7 +486,7 @@ $(".redux-ampforwp-ext-activate").click(function(){
491
  method: 'post',
492
  data: {action: 'ampforwp_get_licence_activate_update',
493
  ampforwp_license_activate:plugin_id,
494
- license:window.atob(license),
495
  item_name:item_name,
496
  store_url:store_url,
497
  plugin_active_path:plugin_active_path,
465
  }
466
  //reduxOptionTab();
467
 
 
 
 
 
 
468
  $(".redux-ampforwp-ext-activate").click(function(){
469
  var currentThis = $(this);
470
  var plugin_id = currentThis.attr("id");
473
  var license = $('input[name="redux_builder_amp[amp-license]['+plugin_id+'][license]"]').val();
474
 
475
  if(newlicense!='' && newlicense.indexOf("**")<0){
476
+ license = newlicense;
477
  $('input[name="redux_builder_amp[amp-license]['+plugin_id+'][license]"]').val(license);
478
  }
479
 
486
  method: 'post',
487
  data: {action: 'ampforwp_get_licence_activate_update',
488
  ampforwp_license_activate:plugin_id,
489
+ license:license,
490
  item_name:item_name,
491
  store_url:store_url,
492
  plugin_active_path:plugin_active_path,
includes/admin-style.css CHANGED
@@ -927,4 +927,12 @@ div#section-ampforwp-ads-section h3:before{
927
  border-radius: 70px;
928
  padding: 6px 15px 8px 16px;
929
 
930
- }
 
 
 
 
 
 
 
 
927
  border-radius: 70px;
928
  padding: 6px 15px 8px 16px;
929
 
930
+ }
931
+ .redux-group-menu .template-mode-amp .el+.group_title:after{
932
+ content: "Template Mode";
933
+ display: inline-block;
934
+ font-size: 10px;
935
+ text-transform: none;
936
+ width: 100%;
937
+ font-weight: normal;
938
+ }
includes/features/analytics/analytics-options.php CHANGED
@@ -209,7 +209,7 @@ function ampforwp_analytics_options($opt_name){
209
  'desc' => '',
210
  'default' => ('{
211
  "vars": {
212
- "account": "UA-xxxxxxx-x" /*Replace this with your Tracking ID*/
213
  },
214
  "triggers": {
215
  "trackPageview": {
209
  'desc' => '',
210
  'default' => ('{
211
  "vars": {
212
+ "account": "UA-xxxxxxx-x" //Replace this with your Tracking ID
213
  },
214
  "triggers": {
215
  "trackPageview": {
includes/options/redux-core/framework.php CHANGED
@@ -3237,6 +3237,7 @@
3237
  $current_screen = get_current_screen();
3238
  if(is_object($current_screen) && $current_screen->parent_base=='amp_options'){
3239
  $enabledOptions = array('automatic-amp-features','basic', 'design', 'opt-go-premium','opt-choose','ampforwp-theme-subsection');
 
3240
  if(!in_array($section['id'], $enabledOptions)){
3241
  $addClass = 'otherSectionFields';
3242
  $style="style='display:none;'";
3237
  $current_screen = get_current_screen();
3238
  if(is_object($current_screen) && $current_screen->parent_base=='amp_options'){
3239
  $enabledOptions = array('automatic-amp-features','basic', 'design', 'opt-go-premium','opt-choose','ampforwp-theme-subsection');
3240
+ $enabledOptions = apply_filters('ampforwp_enabled_setting_options', $enabledOptions);
3241
  if(!in_array($section['id'], $enabledOptions)){
3242
  $addClass = 'otherSectionFields';
3243
  $style="style='display:none;'";
includes/welcome.php CHANGED
@@ -49,12 +49,14 @@ function ampforwp_welcome_screen_content() {
49
  <p><?php echo esc_html__('Our team works really hard to deliver good user experience to you.','accelerated-mobile-pages') ?></p></div>
50
  <div class="getstarted_wrapper">
51
  <div class="amp_user_onboarding">
 
52
  <div class="amp_new_user amp_user_onboarding_choose">
53
  <div class="amp_user_avatar"></div>
54
  <h3><?php echo esc_html__("I'm a New User!","accelerated-mobile-pages") ?></h3>
55
  <p><?php echo esc_html__("We have recommend you to go through AMP installation wizard which helps setup the Basic AMP and get started immediatly.","accelerated-mobile-pages") ?></p>
56
  <a href="<?php echo esc_url(wp_nonce_url(admin_url('plugins.php?page=ampforwptourinstaller&ampforwp_install=1'), '_wpnonce'));?>"><?php echo esc_html__("Run Installation Wizard","accelerated-mobile-pages") ?></a>
57
  </div>
 
58
  <div class="amp_expert_user amp_user_onboarding_choose">
59
  <div class="amp_user_avatar"></div>
60
  <h3><?php echo esc_html__("I'm an Experienced User!","accelerated-mobile-pages") ?></h3>
@@ -66,11 +68,13 @@ function ampforwp_welcome_screen_content() {
66
  </div>
67
  </div>
68
  <div style="float:right; height: 640px;overflow:auto;">
 
69
  <div class="amp_expert_user amp_user_onboarding_choose">
70
  <!--<div class="amp_user_avatar"></div>-->
71
  <!--<h3>Change log</h3>-->
72
  <?php require AMPFORWP_PLUGIN_DIR.'includes/change-log.php';?>
73
  </div>
 
74
  </div>
75
 
76
 
@@ -80,6 +84,7 @@ function ampforwp_welcome_screen_content() {
80
  <i class="dashicons dashicons-editor-help" style="font-size: 34px;margin-right: 18px;margin-top: -1px;"></i><?php echo esc_html__('Need Help?','accelerated-mobile-pages') ?>
81
  </h1>
82
  <div class="amp_installed_text"><p><?php echo esc_html__('We\'re bunch of passionate people that are dedicated towards helping our users. We will be happy to help you!','accelerated-mobile-pages') ?></p></div>
 
83
  <div class="getstarted_options">
84
  <p><b><?php echo esc_html__("Getting Started","accelerated-mobile-pages") ?></b></p>
85
  <ul class="getstarted_ul">
@@ -98,6 +103,7 @@ function ampforwp_welcome_screen_content() {
98
  <li><a href="https://ampforwp.com/tutorials/article-categories/how-to/" target="_blank"><?php echo esc_html__("General How To's","accelerated-mobile-pages") ?></a></li>
99
  </ul>
100
  </div>
 
101
  <div class="clear"></div>
102
  </div>
103
 
49
  <p><?php echo esc_html__('Our team works really hard to deliver good user experience to you.','accelerated-mobile-pages') ?></p></div>
50
  <div class="getstarted_wrapper">
51
  <div class="amp_user_onboarding">
52
+ <?php if(!get_theme_support('amp-template-mode')){ ?>
53
  <div class="amp_new_user amp_user_onboarding_choose">
54
  <div class="amp_user_avatar"></div>
55
  <h3><?php echo esc_html__("I'm a New User!","accelerated-mobile-pages") ?></h3>
56
  <p><?php echo esc_html__("We have recommend you to go through AMP installation wizard which helps setup the Basic AMP and get started immediatly.","accelerated-mobile-pages") ?></p>
57
  <a href="<?php echo esc_url(wp_nonce_url(admin_url('plugins.php?page=ampforwptourinstaller&ampforwp_install=1'), '_wpnonce'));?>"><?php echo esc_html__("Run Installation Wizard","accelerated-mobile-pages") ?></a>
58
  </div>
59
+ <?php } ?>
60
  <div class="amp_expert_user amp_user_onboarding_choose">
61
  <div class="amp_user_avatar"></div>
62
  <h3><?php echo esc_html__("I'm an Experienced User!","accelerated-mobile-pages") ?></h3>
68
  </div>
69
  </div>
70
  <div style="float:right; height: 640px;overflow:auto;">
71
+ <?php if(!get_theme_support('amp-template-mode')){ ?>
72
  <div class="amp_expert_user amp_user_onboarding_choose">
73
  <!--<div class="amp_user_avatar"></div>-->
74
  <!--<h3>Change log</h3>-->
75
  <?php require AMPFORWP_PLUGIN_DIR.'includes/change-log.php';?>
76
  </div>
77
+ <?php } ?>
78
  </div>
79
 
80
 
84
  <i class="dashicons dashicons-editor-help" style="font-size: 34px;margin-right: 18px;margin-top: -1px;"></i><?php echo esc_html__('Need Help?','accelerated-mobile-pages') ?>
85
  </h1>
86
  <div class="amp_installed_text"><p><?php echo esc_html__('We\'re bunch of passionate people that are dedicated towards helping our users. We will be happy to help you!','accelerated-mobile-pages') ?></p></div>
87
+ <?php if(!get_theme_support('amp-template-mode')){ ?>
88
  <div class="getstarted_options">
89
  <p><b><?php echo esc_html__("Getting Started","accelerated-mobile-pages") ?></b></p>
90
  <ul class="getstarted_ul">
103
  <li><a href="https://ampforwp.com/tutorials/article-categories/how-to/" target="_blank"><?php echo esc_html__("General How To's","accelerated-mobile-pages") ?></a></li>
104
  </ul>
105
  </div>
106
+ <?php } ?>
107
  <div class="clear"></div>
108
  </div>
109
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: AMP, accelerated mobile pages, mobile, amp project, google amp, amp wp, go
4
  Donate link: https://www.paypal.me/Kaludi/25
5
  Requires at least: 3.0
6
  Tested up to: 5.2.1
7
- Stable tag: 0.9.97.59
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -190,6 +190,11 @@ You can contact us from [here](https://ampforwp.com/contact/)
190
 
191
  == Changelog ==
192
 
 
 
 
 
 
193
  = 0.9.97.59 (21th June 2019) =
194
  * Improvements: WP Recipe Maker & WP Recipe Maker PRO Schema compatibility added #3043
195
  * Improvements: Impreza Theme's lazyLoad Option compatibility integrated #3259
4
  Donate link: https://www.paypal.me/Kaludi/25
5
  Requires at least: 3.0
6
  Tested up to: 5.2.1
7
+ Stable tag: 0.9.97.60
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
190
 
191
  == Changelog ==
192
 
193
+ = 0.9.97.60 (22th June 2019) =
194
+ * Feature: Need to add template-mode #3252
195
+ * Fixed: Options panel loading issue after 0.9.97.59
196
+ * Fixed: Single post main title should be H1 and sub title should be H2 or H3 in design-1 #3350
197
+
198
  = 0.9.97.59 (21th June 2019) =
199
  * Improvements: WP Recipe Maker & WP Recipe Maker PRO Schema compatibility added #3043
200
  * Improvements: Impreza Theme's lazyLoad Option compatibility integrated #3259
templates/design-manager/design-1/404.php CHANGED
@@ -11,25 +11,24 @@
11
  </style>
12
  </head>
13
 
14
-
15
  <body <?php ampforwp_body_class('single-post design_1_wrapper');?>>
16
  <?php do_action('ampforwp_body_beginning', $this); ?>
17
  <?php $this->load_parts( array( 'header-bar' ) ); ?>
18
  <?php do_action( 'below_the_header_design_1', $this ); ?>
19
 
20
- <article class="amp-wp-article amp-wp-article-header">
21
- <?php do_action('ampforwp_post_before_design_elements') ?>
22
- <h2 class="amp-wp-title">
23
- <?php global $redux_builder_amp;
24
- $allowed_tags = '<p><a><b><strong><i><u><ul><ol><li><h1><h2><h3><h4><h5><h6><table><tr><th><td><em><span>';
25
- echo strip_tags(ampforwp_translation($redux_builder_amp['amp-translator-fourohfour'],'Oops! That page can’t be found.'),$allowed_tags); ?></h2>
26
- <?php do_action('ampforwp_post_after_design_elements') ?>
27
- </article>
 
28
 
29
  <?php do_action( 'amp_post_template_above_footer', $this ); ?>
30
  <?php $this->load_parts( array( 'footer' ) ); ?>
31
  <?php do_action( 'amp_post_template_footer', $this ); ?>
32
 
33
  </body>
34
- </html>
35
-
11
  </style>
12
  </head>
13
 
 
14
  <body <?php ampforwp_body_class('single-post design_1_wrapper');?>>
15
  <?php do_action('ampforwp_body_beginning', $this); ?>
16
  <?php $this->load_parts( array( 'header-bar' ) ); ?>
17
  <?php do_action( 'below_the_header_design_1', $this ); ?>
18
 
19
+ <div class="amp-wp-article">
20
+ <article class="amp-wp-article-header">
21
+ <?php do_action('ampforwp_post_before_design_elements') ?>
22
+ <h2 class="amp-wp-title"><?php global $redux_builder_amp;
23
+ $allowed_tags = '<p><a><b><strong><i><u><ul><ol><li><h1><h2><h3><h4><h5><h6><table><tr><th><td><em><span>';
24
+ echo strip_tags(ampforwp_translation($redux_builder_amp['amp-translator-fourohfour'],'Oops! That page can’t be found.'),$allowed_tags); ?></h2>
25
+ <?php do_action('ampforwp_post_after_design_elements') ?>
26
+ </article>
27
+ </div>
28
 
29
  <?php do_action( 'amp_post_template_above_footer', $this ); ?>
30
  <?php $this->load_parts( array( 'footer' ) ); ?>
31
  <?php do_action( 'amp_post_template_footer', $this ); ?>
32
 
33
  </body>
34
+ </html>
 
templates/design-manager/design-1/archive.php CHANGED
@@ -58,7 +58,7 @@ global $redux_builder_amp, $wp; ?>
58
  <?php }
59
  }
60
  }
61
- the_archive_title( '<h1 class="page-title">', '</h1>' );
62
 
63
  $arch_desc = $sanitizer->get_amp_content();
64
  if( $arch_desc ) {
@@ -104,7 +104,7 @@ global $redux_builder_amp, $wp; ?>
104
  } ?>
105
  <div class="amp-wp-content amp-wp-article-header amp-loop-list">
106
 
107
- <h1 class="amp-wp-title"><a href="<?php echo esc_url( $ampforwp_amp_post_url ); ?>"><?php the_title() ?></a></h1>
108
 
109
  <div class="amp-wp-content-loop">
110
 
58
  <?php }
59
  }
60
  }
61
+ the_archive_title( '<h2 class="page-title">', '</h2>' );
62
 
63
  $arch_desc = $sanitizer->get_amp_content();
64
  if( $arch_desc ) {
104
  } ?>
105
  <div class="amp-wp-content amp-wp-article-header amp-loop-list">
106
 
107
+ <h3 class="amp-wp-title"><a href="<?php echo esc_url( $ampforwp_amp_post_url ); ?>"><?php the_title() ?></a></h3>
108
 
109
  <div class="amp-wp-content-loop">
110
 
templates/design-manager/design-1/search.php CHANGED
@@ -56,13 +56,13 @@
56
  relevanssi_do_query( $q );
57
  };?>
58
 
59
- <h1 class="amp-wp-content page-title"><?php echo esc_attr(ampforwp_translation($redux_builder_amp['amp-translator-search-text'], 'You searched for:' )) . ' ' . get_search_query();?></h1>
60
 
61
  <?php if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post();?>
62
 
63
  <div class="amp-wp-content amp-wp-article-header amp-loop-list">
64
 
65
- <h1 class="amp-wp-title"><a href="<?php echo ampforwp_url_controller( get_permalink());?>"><?php the_title() ?></a></h1>
66
 
67
  <div class="amp-wp-content-loop">
68
 
56
  relevanssi_do_query( $q );
57
  };?>
58
 
59
+ <h2 class="amp-wp-content page-title"><?php echo esc_attr(ampforwp_translation($redux_builder_amp['amp-translator-search-text'], 'You searched for:' )) . ' ' . get_search_query();?></h2>
60
 
61
  <?php if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post();?>
62
 
63
  <div class="amp-wp-content amp-wp-article-header amp-loop-list">
64
 
65
+ <h3 class="amp-wp-title"><a href="<?php echo ampforwp_url_controller( get_permalink());?>"><?php the_title() ?></a></h3>
66
 
67
  <div class="amp-wp-content-loop">
68
 
templates/design-manager/design-1/style.php CHANGED
@@ -67,7 +67,7 @@ blockquote {color: <?php echo sanitize_hex_color( $text_color ); ?>;background:
67
  .amp-wp-header {background-color: <?php echo sanitize_hex_color( $header_background_color ); ?>;}
68
  .amp-wp-header .ampforwp-logo-area {color: <?php echo sanitize_hex_color( $header_color ); ?>;font-size: 1em;font-weight: 400;margin: 0 auto;max-width: calc(840px - 32px);padding: .875em 16px;position: relative;} .amp-wp-header .amp-wp-site-icon {background-color: <?php echo sanitize_hex_color( $header_color ); ?>;border: 1px solid <?php echo sanitize_hex_color( $header_color ); ?>;border-radius: 50%;position: absolute;right: 18px;top: 10px;}
69
  .amp-wp-article {color: <?php echo sanitize_hex_color( $text_color ); ?>;font-weight: 400;margin: 1.5em auto;max-width: 840px;overflow-wrap: break-word;word-wrap: break-word;} .amp-wp-article-header {align-items: center;align-content: stretch;display: flex;flex-wrap: wrap;justify-content: space-between;margin: 1.5em 16px 1.5em;}
70
- .amp-wp-title {color: <?php echo sanitize_hex_color( $text_color ); ?>;display: block;flex: 1 0 100%;font-weight: 900;margin: 0;width: 100%;}.amp-wp-meta {color: <?php echo sanitize_hex_color( $muted_text_color ); ?>;display: inline-block;flex: 2 1 50%;font-size: .875em;line-height: 1.7em;margin: 0;padding: 0;}.ampforwp-meta-info{margin-top: 0px;}.amp-wp-article-header .amp-wp-meta:last-of-type {text-align: right;float:right;display:initial}.amp-wp-article-header .amp-wp-meta:first-of-type {text-align: left;}.amp-wp-byline amp-img,.amp-wp-byline .amp-wp-author {display: inline-block;vertical-align: middle;}.amp-wp-byline amp-img {border: 1px solid <?php echo sanitize_hex_color( $link_color ); ?>;border-radius: 50%;position: relative;margin-right: 6px;}.amp-wp-posted-on {text-align: right;}.hide-meta-info{ display: none; }
71
  .amp-wp-article-featured-image {margin: 1.5em 16px 1.5em;}.amp-wp-article-featured-image amp-img {margin: 0 auto;}.amp-wp-article-featured-image.wp-caption .wp-caption-text, .ampforwp-gallery-item .wp-caption-text {margin: 0 18px;}.amp-wp-frontpage .the_content {padding: 10px;}
72
  .ampforwp-gallery-item.amp-carousel-slide { padding-bottom: 20px;}
73
  .amp-wp-frontpage .ampforwp-title {margin-left:10px;}.amp-wp-article a{text-decoration:none}.amp-wp-article-content {margin: 0 16px;}.amp-wp-article-content ul,.amp-wp-article-content ol {margin-left: 1em;}.amp-wp-article-content amp-img {margin: 0 auto;}.amp-wp-article-content amp-img.alignright {margin: 0 0 1em 16px;}.amp-wp-article-content amp-img.alignleft {margin: 0 16px 1em 0;}
67
  .amp-wp-header {background-color: <?php echo sanitize_hex_color( $header_background_color ); ?>;}
68
  .amp-wp-header .ampforwp-logo-area {color: <?php echo sanitize_hex_color( $header_color ); ?>;font-size: 1em;font-weight: 400;margin: 0 auto;max-width: calc(840px - 32px);padding: .875em 16px;position: relative;} .amp-wp-header .amp-wp-site-icon {background-color: <?php echo sanitize_hex_color( $header_color ); ?>;border: 1px solid <?php echo sanitize_hex_color( $header_color ); ?>;border-radius: 50%;position: absolute;right: 18px;top: 10px;}
69
  .amp-wp-article {color: <?php echo sanitize_hex_color( $text_color ); ?>;font-weight: 400;margin: 1.5em auto;max-width: 840px;overflow-wrap: break-word;word-wrap: break-word;} .amp-wp-article-header {align-items: center;align-content: stretch;display: flex;flex-wrap: wrap;justify-content: space-between;margin: 1.5em 16px 1.5em;}
70
+ .amp-wp-title {color: <?php echo sanitize_hex_color( $text_color ); ?>;display: block;flex: 1 0 100%;font-weight: 900;font-size:1.5em;margin: 0;width: 100%;}.amp-wp-meta {color: <?php echo sanitize_hex_color( $muted_text_color ); ?>;display: inline-block;flex: 2 1 50%;font-size: .875em;line-height: 1.7em;margin: 0;padding: 0;}.ampforwp-meta-info{margin-top: 0px;}.amp-wp-article-header .amp-wp-meta:last-of-type {text-align: right;float:right;display:initial}.amp-wp-article-header .amp-wp-meta:first-of-type {text-align: left;}.amp-wp-byline amp-img,.amp-wp-byline .amp-wp-author {display: inline-block;vertical-align: middle;}.amp-wp-byline amp-img {border: 1px solid <?php echo sanitize_hex_color( $link_color ); ?>;border-radius: 50%;position: relative;margin-right: 6px;}.amp-wp-posted-on {text-align: right;}.hide-meta-info{ display: none; }
71
  .amp-wp-article-featured-image {margin: 1.5em 16px 1.5em;}.amp-wp-article-featured-image amp-img {margin: 0 auto;}.amp-wp-article-featured-image.wp-caption .wp-caption-text, .ampforwp-gallery-item .wp-caption-text {margin: 0 18px;}.amp-wp-frontpage .the_content {padding: 10px;}
72
  .ampforwp-gallery-item.amp-carousel-slide { padding-bottom: 20px;}
73
  .amp-wp-frontpage .ampforwp-title {margin-left:10px;}.amp-wp-article a{text-decoration:none}.amp-wp-article-content {margin: 0 16px;}.amp-wp-article-content ul,.amp-wp-article-content ol {margin-left: 1em;}.amp-wp-article-content amp-img {margin: 0 auto;}.amp-wp-article-content amp-img.alignright {margin: 0 0 1em 16px;}.amp-wp-article-content amp-img.alignleft {margin: 0 16px 1em 0;}
templates/frontpage-elements.php CHANGED
@@ -41,7 +41,7 @@ function ampforwp_design_1_frontpage_content( $template, $post_id ){
41
 
42
  <?php if( $redux_builder_amp['ampforwp-title-on-front-page'] ) { ?>
43
  <header class="amp-wp-article-header ampforwp-title">
44
- <h1 class="amp-wp-title"><?php echo get_the_title( $post_id );?></h1>
45
  </header>
46
 
47
  <?php }
41
 
42
  <?php if( $redux_builder_amp['ampforwp-title-on-front-page'] ) { ?>
43
  <header class="amp-wp-article-header ampforwp-title">
44
+ <h2 class="amp-wp-title"><?php echo get_the_title( $post_id );?></h2>
45
  </header>
46
 
47
  <?php }
templates/template-mode/admin-settings.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ add_filter('ampforwp_enabled_setting_options', 'add_theme_mode_support');
3
+ add_filter("redux/options/redux_builder_amp/sections", 'ampforwp_settings_to_cache');
4
+ function add_theme_mode_support($modesArray){
5
+ $modesArray[] ='template-mode-amp';
6
+ return $modesArray;
7
+ }
8
+ if ( ! function_exists( 'ampforwp_settings_to_cache' ) ) {
9
+ function ampforwp_settings_to_cache($sections){
10
+ $seoSection = array();
11
+ $unsetArray = array('basic','design', 'opt-structured-data', 'amp-notifications', 'ampforwp-push-notifications', 'disqus-comments', 'fb-instant-article', 'hide-amp-section', 'amp-advance', 'amp-translator', 'amp-theme-settings', 'amp-theme-global-subsection', 'amp-theme-header-settings', 'amp-theme-homepage-settings', 'amp-single', 'amp-theme-footer-settings', 'amp-theme-page-settings', 'amp-social', 'ampforwp-date-section', 'amp-design', 'opt-text-subsection', 'amp-content-builder', 'amp-contact', 'amp-e-commerce', 'opt-go-premium', 'opt-choose', 'opt-plugins-manager');
12
+ $backupArray = array( 'amp-ads', 'analytics', 'pwa-for-wp', 'amp-performance', 'amp-seo');
13
+
14
+ $pwaField = array();
15
+ foreach($sections as $key => $sec){
16
+ if( in_array($sec['id'], $backupArray) ){
17
+ if($sec['id']=='pwa-for-wp'){
18
+ $pwaField = $sec['fields'];
19
+ unset($sections[$key]);
20
+ }if($sec['id']=='amp-performance'){
21
+ $sections[$key]['fields'] = array_merge($sec['fields'], $pwaField);
22
+ }else{
23
+ $seoSection[] = $sec;
24
+ unset($sections[$key]);
25
+ }
26
+ }
27
+ if( in_array($sec['id'], $unsetArray) ){
28
+ unset($sections[$key]);
29
+ }
30
+ }
31
+ $template_mode = array(array(
32
+ 'id' => 'template-mode-amp',
33
+ 'title' => 'Settings',
34
+ 'icon' => 'el el-cogs',
35
+ 'priority' => 1,
36
+ 'fields' => array()
37
+ )
38
+ );
39
+ $template_mode = array_merge($template_mode, $seoSection);
40
+ $sections = array_merge($template_mode, $sections);
41
+
42
+ return $sections;
43
+ }
44
+ }
templates/template-mode/template-helpers.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ function ampforwp_head(){
3
+ do_action('levelup_head');
4
+ do_action('levelup_css');
5
+ }
templates/template-mode/template-mode.php ADDED
@@ -0,0 +1,596 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ Class AMPforWP_theme_mode{
3
+ public function __construct(){
4
+ }
5
+ public function init(){
6
+
7
+ add_action( 'init', array("AMPforWP_theme_mode", 'removeUnusedAction'));
8
+ add_action( 'init', array("AMPforWP_theme_mode", 'removeUnusedMenuWidgets'), 11);
9
+
10
+ if(!is_admin() && $GLOBALS['pagenow'] !== 'wp-login.php' ){
11
+ add_action( 'init', array($this, 'rm_wp_core'), 20 );
12
+ add_filter("ampforwp_is_amp_endpoint", array($this, 'ampforwp_theme_mode_enable'));
13
+ add_action( 'init', array($this, 'dynamic_sidebar_callback_bkp') );
14
+ add_filter( 'amp_post_template_dir', array($this, 'template_mode_new_dir') );
15
+ add_filter( 'amp_post_template_file', array($this, 'custom_template_file_name'), 11, 3 );
16
+ add_filter( "post_thumbnail_html", array($this, 'featured_image_html'), 11, 5 );
17
+ add_filter("language_attributes", array($this, 'add_amp_html_attr'), 10, 2);
18
+ add_filter( "the_content", array($this, 'amp_the_content') );
19
+ add_action( "levelup_head", array($this, 'amp_head_content') );
20
+ add_action( "levelup_css", array($this, 'amp_head_css') );
21
+ add_filter( "get_search_form", array($this, 'search_form') );
22
+ add_filter( "get_custom_logo", array($this, 'get_custom_logo'), 10, 2 );
23
+ add_action( "levelup_footer", array($this, 'amp_footer_content') );
24
+ add_action( "get_avatar", array($this,'get_avatar'), 11,6);
25
+ add_filter( "the_author_description", array($this, 'author_meta_desctiption_amp'),10, 2 );
26
+ add_filter("ampforwp_the_content_last_filter", array($this, "comment_form_conversion") );
27
+ add_filter("amp_post_template_data", array($this, 'amp_comment_mustache_script') );
28
+
29
+ }else{
30
+ require_once AMPFORWP_PLUGIN_DIR.'/templates/template-mode/admin-settings.php';
31
+ add_filter( 'plugin_action_links_accelerated-mobile-pages/accelerated-moblie-pages.php', array($this, 'ampforwp_plugin_settings_link'), 999, 4 );
32
+ }
33
+ add_action( 'wp_ajax_amp_theme_ajaxcomments', array($this, 'amp_theme_ajaxcomments') );
34
+ add_action( 'wp_ajax_nopriv_amp_theme_ajaxcomments', array($this, 'amp_theme_ajaxcomments') );
35
+ }
36
+ static function removeUnusedMenuWidgets(){
37
+ unregister_nav_menu( 'amp-menu' );
38
+ unregister_nav_menu( 'amp-footer-menu' );
39
+ unregister_sidebar('ampforwp-above-loop');
40
+ unregister_sidebar('ampforwp-below-loop');
41
+ unregister_sidebar('ampforwp-below-header');
42
+ unregister_sidebar('ampforwp-above-footer');
43
+ unregister_sidebar('swift-footer-widget-area');
44
+ unregister_sidebar('swift-sidebar');
45
+ }
46
+ public static function removeUnusedAction(){
47
+ //redirect.php
48
+ remove_action( 'init', 'ampforwp_menu', 10 );
49
+ remove_action( 'init', 'ampforwp_footermenu', 10 );
50
+ remove_action( 'init', 'swifttheme_footer_widgets_init', 10 );
51
+ remove_action( 'init', 'ampforwp_add_widget_support', 10);
52
+
53
+ remove_action( 'template_redirect', 'ampforwp_redirection', 10 );
54
+ remove_action( 'template_redirect', 'ampforwp_check_amp_page_status', 10 );
55
+ remove_action( 'template_redirect', 'ampforwp_page_template_redirect', 10 );
56
+ remove_action( 'template_redirect', 'ampforwp_page_template_redirect_archive', 10 );
57
+ remove_filter( 'query_vars', 'ampforwp_custom_query_var' );
58
+ remove_action( 'template_redirect', 'ampforwp_redirect_to_orginal_url' );
59
+ remove_action('template_redirect', 'ampforwp_redirect_proper_qendpoint' );
60
+ //Main files
61
+ remove_action( 'init', 'ampforwp_add_custom_post_support',11);
62
+ remove_action( 'init', 'ampforwp_add_custom_rewrite_rules', 25 );
63
+ remove_action( 'init', 'ampforwp_custom_rewrite_rules_for_product_category' );
64
+ }
65
+ function ampforwp_theme_mode_enable($opt){
66
+ return true;
67
+ }
68
+
69
+ function ampforwp_plugin_settings_link( $actions, $plugin_file, $plugin_data, $context ) {
70
+ $amp_activate = '';
71
+ $amp_activate = array('<span style="color:black;">'.esc_html__("Status: Template Mode", "accelerated-mobile-pages").'</span> |');
72
+ $actions = array_merge( $actions, $amp_activate );
73
+ return $actions;
74
+ }
75
+ function amp_comment_mustache_script($data){
76
+ if(isset($data['amp_component_scripts']['amp-next-page'])){
77
+ unset($data['amp_component_scripts']['amp-next-page']);
78
+ }
79
+ if ( comments_open()){
80
+ if ( empty( $data['amp_component_scripts']['amp-mustache'] ) ) {
81
+ $data['amp_component_scripts']['amp-mustache'] = 'https://cdn.ampproject.org/v0/amp-mustache-latest.js';
82
+ }
83
+ if ( empty( $data['amp_component_scripts']['amp-form'] ) ) {
84
+ $data['amp_component_scripts']['amp-form'] = 'https://cdn.ampproject.org/v0/amp-form-latest.js';
85
+ }
86
+ }
87
+ return $data;
88
+ }
89
+ function amp_theme_ajaxcomments(){
90
+ global $redux_builder_amp;
91
+ header("access-control-allow-credentials:true");
92
+ header("access-control-allow-headers:Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token");
93
+ header("Access-Control-Allow-Origin:".esc_attr($_SERVER['HTTP_ORIGIN']) );
94
+ $siteUrl = parse_url( get_site_url() );
95
+ header("AMP-Access-Control-Allow-Source-Origin:".esc_attr($siteUrl['scheme']) . '://' . esc_attr($siteUrl['host']) );
96
+ header("access-control-expose-headers:AMP-Access-Control-Allow-Source-Origin");
97
+ header("Content-Type:application/json;charset=utf-8");
98
+ if(wp_verify_nonce($_POST['amp_comment_form_nonce'], 'commentform_submission')){
99
+ $comment_status = array('response' => 'Nonce not verified' );
100
+ echo json_encode($comment_status);
101
+ die;
102
+ }
103
+ $comment = wp_handle_comment_submission( wp_unslash( $_POST ) );
104
+ $text_data = 'Comment Successfully submitted';
105
+ if ($redux_builder_amp['amp-comments-Successful-message']){
106
+ $text_data = esc_html__( $redux_builder_amp['amp-comments-Successful-message'], 'accelerated-mobile-pages');
107
+ }
108
+
109
+ if ( is_wp_error( $comment ) ) {
110
+ $error_data = intval( $comment->get_error_data() );
111
+ if ( ! empty( $error_data ) ) {
112
+ $comment_html = $comment->get_error_message();
113
+ $comment_html = str_replace("&#8217;","'",$comment_html);
114
+ $comment_status = array('response' => $comment_html );
115
+ echo json_encode($comment_status);
116
+ die;
117
+ } else {
118
+ wp_die( 'Unknown error' );
119
+ }
120
+ }
121
+
122
+ $user = wp_get_current_user();
123
+ do_action('set_comment_cookies', $comment, $user);
124
+
125
+ $comment_depth = 1;
126
+ $comment_parent = $comment->comment_parent;
127
+ while( $comment_parent ){
128
+ $comment_depth++;
129
+ $parent_comment = get_comment( $comment_parent );
130
+ $comment_parent = $parent_comment->comment_parent;
131
+ }
132
+
133
+ $GLOBALS['comment'] = $comment;
134
+ $GLOBALS['comment_depth'] = $comment_depth;
135
+ $comment_html = $text_data;
136
+ $comment_status = array('response' => $comment_html );
137
+ echo json_encode($comment_status);
138
+ die;
139
+ }
140
+ function comment_form_conversion($content){
141
+
142
+ if(strpos($content, 'id="commentform"')!==false){
143
+ $submit_url = admin_url('admin-ajax.php?action=amp_theme_ajaxcomments');
144
+ $submit_url = str_replace("http:", "", $submit_url);
145
+ $comment_nonce = wp_create_nonce( 'commentform_submission' );
146
+ $mustache = '<input type="hidden" name="amp_comment_form_nonce" value="'.esc_attr($comment_nonce).'"><div submit-success>
147
+ <template type="amp-mustache">
148
+ {{response}}
149
+ </template>
150
+ </div>
151
+ <div submit-error>
152
+ <template type="amp-mustache">
153
+ {{response}}
154
+ </template>
155
+ </div>';
156
+ $content = preg_replace("/<form(.*?)action=[\"|'](.*?)[\"|'](.*?)id=[\"|']commentform[\"|'](.*?)>/s", '<form$1action-xhr="'.esc_url_raw($submit_url).'"$3id="commentform" $4 on="submit-success:commentform.reset()">'.$mustache, $content);
157
+ }
158
+ return $content;
159
+ }
160
+ /**
161
+ * Remove Unwanted hooks from template
162
+ **/
163
+ public function rm_wp_core(){
164
+ remove_all_actions( 'wp_head' );
165
+ remove_all_actions( 'wp_print_styles' );
166
+ remove_all_actions( 'wp_print_head_scripts' );
167
+ remove_all_actions( 'wp_footer' );
168
+ remove_all_actions( 'wp_enqueue_scripts' );
169
+ remove_all_actions( 'after_wp_tiny_mce' );
170
+ remove_all_actions( 'comment_form' );
171
+ remove_action( 'amp_post_template_head','ampforwp_add_meta_viewport', 9);
172
+ remove_filter( 'amp_post_template_file', 'ampforwp_custom_template', 10, 3 );
173
+ remove_filter( 'ampforwp_post_template_data', 'ampforwp_backtotop' );
174
+ remove_filter( 'amp_post_template_data', 'ampforwp_backtotop' );
175
+ remove_filter('amp_post_template_dir','ampforwp_new_dir');
176
+ remove_filter( 'amp_post_template_file', 'ampforwp_empty_filter', 10, 3 );
177
+ }
178
+ /**
179
+ * Replacing callback of widgets for conversion
180
+ **/
181
+ public function dynamic_sidebar_callback_bkp(){
182
+ global $wp_registered_widgets, $ampforwp_wp_registered_widgets;
183
+ if(count($wp_registered_widgets)){
184
+ foreach ($wp_registered_widgets as $key => $value) {
185
+ $wp_registered_widgets[$key]['amp_callback'] = $value['callback'];
186
+ $wp_registered_widgets[$key]['amp_params'] = $value['params'];
187
+ $wp_registered_widgets[$key]['params'] = array(array('public function_name'=> $value['id'] ));
188
+ $wp_registered_widgets[$key]['callback'] = array($this, 'ampforwp_template_mode_reg_callback_widgets');
189
+ }
190
+ }
191
+ }
192
+ /**
193
+ * Change Templates directory for AMP theme
194
+ **/
195
+ public function template_mode_new_dir( $dir ) {
196
+ global $redux_builder_amp;
197
+ $dir = get_template_directory()."/";
198
+ return $dir;
199
+ }
200
+ /**
201
+ * Calling name of template from theme directory
202
+ **/
203
+ // Custom Template Files
204
+ public function custom_template_file_name( $file, $type, $post ) {
205
+ global $redux_builder_amp;
206
+ // 404 Template
207
+ if( 'single' === $type && is_404() ) {
208
+ $file = get_template_directory() . '/404.php';
209
+ }
210
+ // single Template
211
+ if ( is_page() ) {
212
+ if( 'single' === $type && ! ('product' === $post->post_type) ) {
213
+ $file = get_template_directory() . '/page.php';
214
+ }
215
+ }
216
+ // Loop Template
217
+ if ( 'loop' === $type ) {
218
+ $file = get_template_directory() . '/loop.php';
219
+ }
220
+ // Archive
221
+ if ( is_archive() ) {
222
+ if ( 'single' === $type ) {
223
+ $file = get_template_directory() . '/archive.php';
224
+ }
225
+ }
226
+ $ampforwp_custom_post_page = ampforwp_custom_post_page();
227
+ // Homepage
228
+ if ( is_home() ) {
229
+ if ( 'single' === $type ) {
230
+ $file = get_template_directory() . '/index.php';
231
+
232
+ if ( $redux_builder_amp['amp-frontpage-select-option'] == 1 ) {
233
+ $file = get_template_directory() . '/page.php';
234
+ }
235
+ if ( ampforwp_is_blog() ) {
236
+ $file = get_template_directory() . '/index.php';
237
+ }
238
+ }
239
+ }
240
+ // is_search
241
+ if ( is_search() ) {
242
+ if ( 'single' === $type ) {
243
+ $file = get_template_directory() . '/search.php';
244
+ }
245
+ }
246
+ //For template pages
247
+ switch ( true ) {
248
+ case (is_tax()):
249
+ $term = get_queried_object();
250
+ $templates = array();
251
+ if ( ! empty( $term->slug ) ) {
252
+ $taxonomy = $term->taxonomy;
253
+ $slug_decoded = urldecode( $term->slug );
254
+ if ( $slug_decoded !== $term->slug ) {
255
+ $templates[] = get_template_directory() . "/taxonomy-$taxonomy-{$slug_decoded}.php";
256
+ }
257
+ $templates[] = get_template_directory() . "/taxonomy-$taxonomy-{$term->slug}.php";
258
+ $templates[] = get_template_directory() . "/taxonomy-$taxonomy.php";
259
+ }
260
+ $templates[] = get_template_directory() . "/taxonomy.php";
261
+ foreach ( $templates as $key => $value ) {
262
+ if ( 'single' === $type && file_exists($value) ) {
263
+ $file = $value;
264
+ break;
265
+ }
266
+ }
267
+ break;
268
+ case (is_category()):
269
+ $category = get_queried_object();
270
+ $templates = array();
271
+ if ( ! empty( $category->slug ) ) {
272
+ $slug_decoded = urldecode( $category->slug );
273
+ if ( $slug_decoded !== $category->slug ) {
274
+ $templates[] = get_template_directory() . "/category-{$slug_decoded}.php";
275
+ }
276
+ $templates[] = get_template_directory() . "/category-{$category->slug}.php";
277
+ $templates[] = get_template_directory() . "/category-{$category->term_id}.php";
278
+ }
279
+ $templates[] = get_template_directory() . '/category.php';
280
+ foreach ( $templates as $key => $value ) {
281
+ if ( 'single' === $type && file_exists($value) ) {
282
+ $file = $value;
283
+ break;
284
+ }
285
+ }
286
+ break;
287
+ case (is_tag()):
288
+ $tag = get_queried_object();
289
+ $templates = array();
290
+ if ( ! empty( $tag->slug ) ) {
291
+ $slug_decoded = urldecode( $tag->slug );
292
+ if ( $slug_decoded !== $tag->slug ) {
293
+ $templates[] = get_template_directory() . "/tag-{$slug_decoded}.php";
294
+ }
295
+ $templates[] = get_template_directory() . "/tag-{$tag->slug}.php";
296
+ $templates[] = get_template_directory() . "/tag-{$tag->term_id}.php";
297
+ }
298
+ $templates[] = get_template_directory() . '/tag.php';
299
+ foreach ( $templates as $key => $value ) {
300
+ if ( 'single' === $type && file_exists($value) ) {
301
+ $file = $value;
302
+ break;
303
+ }
304
+ }
305
+ break;
306
+ case is_author():
307
+ $author = get_queried_object();
308
+ $templates = array();
309
+ if ( $author instanceof WP_User ) {
310
+ $templates[] = get_template_directory() . "/author-{$author->user_nicename}.php";
311
+ $templates[] = get_template_directory() . "/author-{$author->ID}.php";
312
+ }
313
+ $templates[] = get_template_directory() . "/author.php";
314
+ foreach ( $templates as $key => $value ) {
315
+ if ( 'single' === $type && file_exists($value) ) {
316
+ $file = $value;
317
+ break;
318
+ }
319
+ }
320
+ break;
321
+ case (is_archive()):
322
+ $post_types = array_filter( (array) get_query_var( 'post_type' ) );
323
+ $templates = array();
324
+ if ( count( $post_types ) == 1 ) {
325
+ $post_type = reset( $post_types );
326
+ $templates[] = get_template_directory() . "/archive-{$post_type}.php";
327
+ }
328
+ $templates[] = get_template_directory() . '/archive.php';
329
+ foreach ( $templates as $key => $value ) {
330
+ if ( 'single' === $type && file_exists($value) ) {
331
+ $file = $value;
332
+ break;
333
+ }
334
+ }
335
+ break;
336
+ case (is_post_type_archive()):
337
+ $post_type = get_query_var( 'post_type' );
338
+ if ( is_array( $post_type ) )
339
+ $post_type = reset( $post_type );
340
+ $obj = get_post_type_object( $post_type );
341
+ if ( ! ($obj instanceof WP_Post_Type) || ! $obj->has_archive ) {
342
+ //return '';
343
+ break;
344
+ }
345
+ $post_types = array_filter( (array) get_query_var( 'post_type' ) );
346
+ $templates = array();
347
+ if ( count( $post_types ) == 1 ) {
348
+ $post_type = reset( $post_types );
349
+ $templates[] = get_template_directory() . "/archive-{$post_type}.php";
350
+ }
351
+ $templates[] = get_template_directory() . '/archive.php';
352
+ foreach ( $templates as $key => $value ) {
353
+ if ( 'single' === $type && file_exists($value) ) {
354
+ $file = $value;
355
+ break;
356
+ }
357
+ }
358
+ break;
359
+ case is_single():
360
+ $object = get_queried_object();
361
+ $templates = array();
362
+ if ( ! empty( $object->post_type ) ) {
363
+ $template = get_page_template_slug( $object );
364
+ if ( $template && 0 === validate_file( $template ) ) {
365
+ $templates[] = get_template_directory().'/'.$template;
366
+ }
367
+ $name_decoded = urldecode( $object->post_name );
368
+ if ( $name_decoded !== $object->post_name ) {
369
+ $templates[] = get_template_directory() . "/single-{$object->post_type}-{$name_decoded}.php";
370
+ }
371
+ $templates[] = get_template_directory() . "/single-{$object->post_type}-{$object->post_name}.php";
372
+ $templates[] = get_template_directory() . "/single-{$object->post_type}.php";
373
+ }
374
+ $templates[] = get_template_directory() . "/single.php";
375
+
376
+ foreach ( $templates as $key => $value ) {
377
+ if ( 'single' === $type && file_exists($value) ) {
378
+ $file = $value;
379
+ break;
380
+ }
381
+ }
382
+ break;
383
+ case is_page():
384
+ $id = get_queried_object_id();
385
+ $template = get_page_template_slug();
386
+ $pagename = get_query_var('pagename');
387
+ if ( ! $pagename && $id ) {
388
+ // If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object
389
+ $post = get_queried_object();
390
+ if ( $post )
391
+ $pagename = $post->post_name;
392
+ }
393
+ $templates = array();
394
+ if ( $template && 0 === validate_file( $template ) )
395
+ $templates[] = get_template_directory().'/'.$template;
396
+ if ( $pagename ) {
397
+ $pagename_decoded = urldecode( $pagename );
398
+ if ( $pagename_decoded !== $pagename ) {
399
+ $templates[] = get_template_directory() . "/page-{$pagename_decoded}.php";
400
+ }
401
+ $templates[] = get_template_directory() . "/page-{$pagename}.php";
402
+ }
403
+ if ( $id )
404
+ $templates[] = get_template_directory() . "/page-{$id}.php";
405
+ $templates[] = get_template_directory() . "/page.php";
406
+ foreach ( $templates as $key => $value ) {
407
+ if ( 'single' === $type && file_exists($value) ) {
408
+ $file = $value;
409
+ break;
410
+ }
411
+ }
412
+ break;
413
+ }
414
+ // Polylang Frontpage #1779
415
+ if ( 'single' === $type && ampforwp_polylang_front_page() && true == $redux_builder_amp['amp-frontpage-select-option'] ) {
416
+ $file = get_template_directory() . '/page.php';
417
+ }
418
+ return $file;
419
+ }
420
+ /**
421
+ * Sanitize featured image
422
+ **/
423
+ //For featured image
424
+ public function featured_image_html($html, $post_id, $post_thumbnail_id, $size, $attr ){
425
+ $html = $this->ampforwp_template_mode_cnt_sanitizer($html);
426
+ return $html;
427
+ }
428
+ public function add_amp_html_attr($output, $doctype){
429
+ $output .= ' amp ';
430
+ return $output;
431
+ }
432
+ public function amp_the_content($content){
433
+ global $ampforwpTemplate;
434
+ if(empty($ampforwpTemplate)){ return $content; }
435
+ $new_content = $ampforwpTemplate->get( 'post_amp_content' );
436
+ $new_content = apply_filters("ampforwp_template_mode_the_content", $new_content);
437
+ return $new_content;
438
+ }
439
+ public function amp_head_content(){
440
+ global $ampforwpTemplate;
441
+ $amp_url = get_permalink( get_queried_object_id() );
442
+ printf( '<link rel="amphtml" href="%s" />', esc_url( $amp_url ) );
443
+ do_action( 'amp_meta', $ampforwpTemplate );
444
+ do_action( 'amp_post_template_head', $ampforwpTemplate );
445
+ }
446
+ public function amp_head_css(){
447
+ global $ampforwpTemplate, $redux_builder_amp;
448
+ $stylesheetUri = get_stylesheet_uri();
449
+ $css = "";
450
+ echo "<style amp-custom>";
451
+ do_action( 'amp_post_template_css', $ampforwpTemplate );
452
+ do_action( 'amp_css', $ampforwpTemplate );
453
+
454
+ $stylesheetCss = $this->ampforwp_get_remote_content($stylesheetUri);
455
+ $stylesheetCss = str_replace(" img", 'amp-img', $stylesheetCss);
456
+ $valuesrc = get_stylesheet_directory_uri();
457
+ $stylesheetCss = preg_replace_callback('/url[(](.*?)[)]/', function($matches)use($valuesrc){
458
+ $matches[1] = str_replace(array('"', "'"), array('', ''), $matches[1]);
459
+ if(!wp_http_validate_url($matches[1]) && strpos($matches[1],"data:")===false){
460
+ return 'url('.$valuesrc."/".$matches[1].")";
461
+ }else{
462
+ return $matches[0];
463
+ }
464
+ }, $stylesheetCss);
465
+ $css .= $stylesheetCss;
466
+ $css .= $redux_builder_amp['css_editor'];
467
+ echo $this->css_sanitizer($css);
468
+ echo "</style>";
469
+ }
470
+ private function css_sanitizer($css){
471
+ $css = preg_replace( '/\s*!important/', '', $css, -1, $important_count );
472
+ $css = preg_replace( '/overflow(-[xy])?\s*:\s*(auto|scroll)\s*;?\s*/', '', $css, -1, $overlow_count );
473
+ $css = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $css);
474
+ $css = str_replace(array (chr(10), ' {', '{ ', ' }', '} ', '( ', ' )', ' :', ': ', ' ;', '; ', ' ,', ', ', ';}', '::-' ), array('', '{', '{', '}', '}', '(', ')', ':', ':', ';', ';', ',', ', ', '}', ' ::-'), $css);
475
+ return $css;
476
+ }
477
+ public function search_form($form){
478
+ $form = preg_replace_callback("/<form(.*?)action=[\"|'](.*?)[\"|'](.*?)>/", function($matches){
479
+ $tag = '<form'.$matches[1].' target="_top" action="'.$matches[2].'"'.$matches[3].'>';
480
+ return $tag;
481
+ }, $form);
482
+ return $form;
483
+ }
484
+ public function get_custom_logo($html, $blog_id){
485
+ $html = $this->ampforwp_template_mode_cnt_sanitizer($html);
486
+ return $html;
487
+ }
488
+ public function amp_footer_content(){
489
+ global $ampforwpTemplate;
490
+ do_action( 'amp_post_template_footer', $ampforwpTemplate );
491
+ do_action('ampforwp_global_after_footer');
492
+ do_action('amp_end',$ampforwpTemplate);
493
+ amp_back_to_top_link();
494
+ }
495
+ public function get_avatar($avatar, $id_or_email, $args_size, $args_default, $args_alt, $args){
496
+ return $this->ampforwp_template_mode_cnt_sanitizer($avatar);
497
+ }
498
+ public function ampforwp_get_remote_content($src){
499
+ if($src){
500
+ $arg = array( "sslverify" => false, "timeout" => 60 ) ;
501
+ $response = wp_remote_get( $src, $arg );
502
+ if ( wp_remote_retrieve_response_code($response) == 200 && is_array( $response ) ) {
503
+ $header = wp_remote_retrieve_headers($response); // array of http header lines
504
+ $contentData = wp_remote_retrieve_body($response); // use the content
505
+ return $contentData;
506
+ }
507
+ }else{
508
+ return $contentData = file_get_contents( $src );
509
+ }
510
+ return '';
511
+ }
512
+ /**
513
+ * Calling Actual callback of registered widgets
514
+ **/
515
+ public function ampforwp_template_mode_reg_callback_widgets($indexData){
516
+ global $wp_registered_widgets;
517
+ $index = $indexData['widget_id'];
518
+ $callback = $wp_registered_widgets[$index]['amp_callback'];
519
+ $params = $wp_registered_widgets[$index]['amp_params'];
520
+ $params = array_merge(
521
+ array($indexData),
522
+ $params
523
+ );
524
+ if ( is_callable($callback) ) {
525
+ if($callback[0]->id_base=='search'){
526
+ add_filter("amp_blacklisted_tags", array($this,'allow_search_form_widget'));
527
+ }
528
+ ob_start();
529
+ call_user_func_array($callback, $params);
530
+ $data = ob_get_clean();
531
+ if($callback[0]->id_base=='search'){
532
+ $data = preg_replace("/http?[s]?:/", "", $data);
533
+ $data = str_replace(" action=", 'target="_top" action=', $data);
534
+ }
535
+ echo $this->ampforwp_template_mode_cnt_sanitizer($data);
536
+ }
537
+ }
538
+ /**
539
+ * Remove Sanitize any content
540
+ **/
541
+ public function ampforwp_template_mode_cnt_sanitizer($content){
542
+ $sanitizer_obj = new AMPFORWP_Content( $content,
543
+ apply_filters( 'amp_content_embed_handlers_template_mode', array(
544
+ 'AMP_Core_Block_Handler' => array(),
545
+ 'AMP_Twitter_Embed_Handler' => array(),
546
+ 'AMP_YouTube_Embed_Handler' => array(),
547
+ 'AMP_DailyMotion_Embed_Handler' => array(),
548
+ 'AMP_Vimeo_Embed_Handler' => array(),
549
+ 'AMP_SoundCloud_Embed_Handler' => array(),
550
+ 'AMP_Instagram_Embed_Handler' => array(),
551
+ 'AMP_Vine_Embed_Handler' => array(),
552
+ 'AMP_Facebook_Embed_Handler' => array(),
553
+ 'AMP_Pinterest_Embed_Handler' => array(),
554
+ 'AMP_Gallery_Embed_Handler' => array(),
555
+ 'AMP_Playlist_Embed_Handler' => array(),
556
+ 'AMP_Wistia_Embed_Handler' => array(),
557
+ ) ),
558
+ apply_filters( 'amp_content_sanitizers_template_mode', array(
559
+ 'AMP_Style_Sanitizer' => array(),
560
+ 'AMP_Blacklist_Sanitizer' => array(),
561
+ 'AMP_Img_Sanitizer' => array(),
562
+ 'AMP_Gallery_Block_Sanitizer' => array(),
563
+ 'AMP_Video_Sanitizer' => array(),
564
+ 'AMP_Audio_Sanitizer' => array(),
565
+ 'AMP_Playbuzz_Sanitizer' => array(),
566
+ 'AMP_Iframe_Sanitizer' => array(
567
+ 'add_placeholder' => true,
568
+ ),
569
+ 'AMP_Block_Sanitizer' => array(),
570
+ ) ),
571
+ array(
572
+ 'content_max_width' => 990,
573
+ )
574
+ );
575
+ return $sanitizer_obj->get_amp_content();
576
+ }
577
+ public function allow_search_form_widget($allowedArray){
578
+ $allowedArray = array_flip($allowedArray);
579
+ unset($allowedArray['form']);
580
+ unset($allowedArray['label']);
581
+ unset($allowedArray['input']);
582
+ $allowedArray = array_flip($allowedArray);
583
+ return $allowedArray;
584
+ }
585
+ public function author_meta_desctiption_amp($field, $user_id){
586
+ return $this->ampforwp_template_mode_cnt_sanitizer($field);
587
+ }
588
+ }//Class Closed
589
+ add_action('after_setup_theme', 'ampforwp_template_mode_is_activate', 999);
590
+ function ampforwp_template_mode_is_activate(){
591
+ if(get_theme_support('amp-template-mode') && !is_customize_preview()){
592
+ $ampforwp_theme_mode = new AMPforWP_theme_mode();
593
+ $ampforwp_theme_mode->init();
594
+ }
595
+ require_once AMPFORWP_PLUGIN_DIR.'/templates/template-mode/template-helpers.php';
596
+ }