403Webshell
Server IP : 104.21.21.239  /  Your IP : 216.73.217.123
Web Server : Apache/2.4.68 (Amazon Linux) OpenSSL/3.5.5
System : Linux ip-172-31-69-123.ec2.internal 6.1.176-223.369.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Jul 24 13:34:27 UTC 2026 x86_64
User : ec2-user ( 1000)
PHP Version : 8.4.23
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/mitzvahm/public_html/wp-content/plugins/amp-optin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/mitzvahm/public_html/wp-content/plugins/amp-optin/amp-optin.php
<?php /*
Plugin Name: AMP Opt-in Forms 
Plugin URI: http://ampforwp.com/optin-form
Description: Opt-in forms for AMP in WordPress. Most easiest and the best way to include opt-in forms in AMP
Version: 1.9.40
Author: AMPforWP Team
Author URI: http://ampforwp.com/
Donate link: https://www.paypal.me/Kaludi/5
License: GPL2
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) exit;

define('AMP_OPTIN_DATA_VERSION', '1.9.40');
if ( ! defined( 'AMP_OPTIN_DATA_VERSION' ) ) {
  define( 'AMP_OPTIN_DATA_VERSION', '1.9.40');
}

// this is the URL our updater / license checker pings. This should be the URL of the site with EDD installed
define( 'AMP_OPTIN_DATA_STORE_URL', 'https://accounts.ampforwp.com/' );

// the name of your product. This should match the download name in EDD exactly
define( 'AMP_OPTIN_DATA_ITEM_NAME', 'Opt-in-Forms for AMP' );

// the download ID. This is the ID of your product in EDD and should match the download ID visible in your Downloads list (see example below)
//define( 'AMPFORWP_ITEM_ID', 2502 );
// the name of the settings page for the license input to be displayed
define( 'AMP_OPTIN_LICENSE_PAGE', 'opt-in-forms-for-amp' );
if(! defined('AMP_OPTIN_ITEM_FOLDER_NAME')){
    $folderName = basename(__DIR__);
    define( 'AMP_OPTIN_ITEM_FOLDER_NAME', $folderName );
}


// globals defiend below
define('AMPOPTIN_PLUGIN_DIR', trailingslashit( plugin_dir_path( __FILE__ ) ) );
define('AMPOPTIN_PLUGIN_URL', trailingslashit( plugin_dir_url( __FILE__ ) ) );
define('AMPOPTIN_METABOX_DIR', trailingslashit( plugin_dir_path( __FILE__ ) . 'include/cmb2/' ) );
//*************************************//
// Plugin activation check starts here //
//*************************************//
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if ( is_plugin_active( 'accelerated-mobile-pages/accelerated-moblie-pages.php' ) ||is_plugin_active( 'amp/amp.php' )) {
add_filter( 'plugin_action_links', 'ampforwp_optin_settings_link', 10, 5 );

} else {
add_filter( 'plugin_action_links', 'ampforwp_optin_plugin_activation_link', 10, 5 );
// Return if Parent plugin is not active, and don't load the below code.
return;
}

#include redux
if(is_plugin_active( 'amp/amp.php' )){
          if ( !class_exists( 'ReduxFramework' ) ) {
              require_once dirname( __FILE__ ).'/include/extensions/loader.php';
              require_once dirname( __FILE__ ).'/include/redux-core/framework.php';
          }
          
        }

// Add Activate Parent Plugin button in settings page
function ampforwp_optin_plugin_activation_link( $actions, $plugin_file ) {
  static $plugin;
  if (!isset($plugin))
    $plugin = plugin_basename(__FILE__);
    if ($plugin == $plugin_file) {
        $settings = array('settings' => '<a href="plugin-install.php?s=accelerated+mobile+pages&tab=search&type=term">' . __('Please Activate the Parent Plugin.', 'ampforwp_optin') . '</a>');
        $actions = array_merge($settings , $actions );
      }
    return $actions;
}

// Add settings Icon in the plugin activation page
function ampforwp_optin_settings_link( $actions, $plugin_file )  {
  static $plugin;
  if (!isset($plugin))
    $plugin = plugin_basename(__FILE__);
    if ($plugin == $plugin_file) {
        $settings = array('settings' => '<a href="admin.php?page=amp_options&tab=0">' . __('Settings', 'ampforwp_optin') . '</a>');
        $actions = array_merge( $actions , $settings);
      }
    return $actions;
}

//***********************************//
// Plugin activation check ends here //
//***********************************//

// all Post edit page related code here
require_once AMPOPTIN_PLUGIN_DIR . 'optin-post-type.php';

require_once AMPOPTIN_PLUGIN_DIR. '/include/settings-handle/amp-optin-apikey-handles.php';

// Addign controls file for Metabox
require_once AMPOPTIN_PLUGIN_DIR . 'controls.php';

/*add_action('amp_post_template_head', 'ampforwp_optin_required_mustach_js');
function ampforwp_optin_required_mustach_js($amp_template) {
  $amp_mustache = $amp_template->amp_component_scripts;
 
    if ( empty($amp_mustache['amp-mustache']) && (is_singular() || is_home() )   ) { 

        $amp_mustache['amp-mustache']="https://cdn.ampproject.org/v0/amp-mustache-0.1.js";
         
    } 
   return $amp_mustache['amp-mustache'];    
}*/

add_filter('ampforwp_tree_shaking_white_list_selector','amp_optin_tree_shaking_whitelists',20);
function amp_optin_tree_shaking_whitelists($white_list){
  $white_list[] = 'body #my-notification.amp-active';
  return $white_list;
}

add_filter('amp_post_template_data','amp_optin_form_script',11);
function amp_optin_form_script( $data ){

  if(empty($data['amp_component_scripts']['amp-form'])){
    $data['amp_component_scripts']['amp-form']='https://cdn.ampproject.org/v0/amp-form-0.1.js';
  }

  if(empty($data['amp_component_scripts']['amp-mustache'])){
    $data['amp_component_scripts']['amp-mustache']='https://cdn.ampproject.org/v0/amp-mustache-latest.js';
  } 

 return $data;
}

  function amp_optin_form_output( $atts ) {
    global $post;

    $atts[] = shortcode_atts( array(
        'src'  => $atts['id'],
    ), $atts );

    $form_class        = "";
    $form_class_output = "";

    if ( isset( $atts['class'] ) && $atts['class'] ) {
        $atts['class']    =  $atts['class'];
        $form_class       = $atts['class'];
    }
    $id                   = $atts['id'];
    $form_num             = get_post_meta( $atts['id'], 'amp_optin_select_form_company', true );
    $submit_button        = get_post_meta( $id, 'amp_option_submit_button_text', true);
    global $forms;

    switch ($form_num) {
                        case '1':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-1.php' );
                                    break;
                        case '2':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-2.php' );
                                    break;
                        case '3':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-3.php' );
                                    break;
                        case '4':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-4.php' );
                                    break;
                        case '5':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-5.php' );
                                    break;
                        case '6':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-6.php' );
                                    break;
                        case '7':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-7.php' );
                                    break;
                        case '8':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-8.php' );
                                    break;
                       case '9':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-9.php' );                            
                                    break;
                       case '10':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-10.php' );
                                    break;
                       case '11':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-11.php' );
                                    break;
                      case '12':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-12.php' );
                                    break;
                      case '13':
                                    require_once(AMPOPTIN_PLUGIN_DIR .'forms/form-13.php');
                                    break;
                      case '14':
                                    require_once(AMPOPTIN_PLUGIN_DIR .'forms/form-14.php');
                                    break;
                      case '15':
                                    require_once(AMPOPTIN_PLUGIN_DIR .'forms/form-15.php');
                                    break;

                      case '16':
                                    require_once(AMPOPTIN_PLUGIN_DIR .'forms/form-16.php');
                                    break;

                      case '17':
                                    require_once(AMPOPTIN_PLUGIN_DIR .'forms/form-17.php');
                                    break;
                      case '18':
                                    require_once(AMPOPTIN_PLUGIN_DIR .'forms/form-18.php');
                                    break;
                      case '19':
                                    require_once(AMPOPTIN_PLUGIN_DIR .'forms/form-19.php');
                                    break; 
                     case '20':
                                    require_once(AMPOPTIN_PLUGIN_DIR .'forms/form-20.php');
                                    break;
                    case '21':
                                    require_once(AMPOPTIN_PLUGIN_DIR .'forms/form-21.php');
                                    break;
                    case '22':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-22.php' ); 
                                    break;

                    case '23':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-23.php' ); 
                                    break; 
                    case '24':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-24.php' ); 
                                    break;  
                    case '25':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-25.php' ); 
                                    break;  
                    case '26':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-26.php' ); 
                                    break;     
                    case '27':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-27.php' ); 
                                    break;
                    case '28':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-28.php' ); 
                                    break;  
                    case '29':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-29.php' ); 
                                    break;
                    case '30':
                                   require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-30.php' ); 
                                    break;        
                    case '31':
                                   require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-31.php' ); 
                                    break; 
                    case '32':
                                   require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-32.php' ); 
                                    break;
                    case '33':
                                   require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-33.php' ); 
                                    break;
    }

    if ( $form_class ) {
      $form_class_output  = $form_class;
    }

    if($form_num){
      $amp_optin_data = 'amp_optin_form_'. $form_num; 
      $output = '<div class="amp-optin-form-wrapper form-'. $form_num .' '. $form_class_output .' optin-'. $atts['id'] .'">';
      $output .= $amp_optin_data($id);
      $output .= '</div>';
      #out optin form with AMP(official) plugin
      if( function_exists('ampforwp_is_amp_endpoint') && ampforwp_is_amp_endpoint()||
          function_exists('amp_activate') && function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ){
        return $output;
      }
    }
    return '';
}



  add_action( 'wp_ajax_nopriv_amp_optin_mailchimp_api_key_validate', 'amp_optin_mailchimp_api_key_validate' );
            add_action( 'wp_ajax_amp_optin_mailchimp_api_key_validate',  'amp_optin_mailchimp_api_key_validate'  );

function amp_optin_mailchimp_api_key_validate(){
          add_option('amp_optin_mailchimp_v2_key_status',false);
          add_option('amp_optin_mailchimp_v2_lists',false);
          add_option('amp_optin_mailchimp_v2_apikey',false);
          add_option('amp_optin_mailchimp_v2_interests',false);

            if(!wp_verify_nonce($_POST['amp_optin_api_settings_nonce'],'amp_optin_api_settings_nonce')){
                  $res['success'] = 2;
                  $res['message'] = "Sorry, your nonce did not verify.";
                  echo json_encode($res);
                  exit;
            }

            if(isset($_POST['api_key']) && $_POST['api_key']!=""){

              $apiKey  = $_POST['api_key'];
              update_option('amp_optin_mailchimp_v2_apikey',$apiKey);
              $dataCenter = substr($apiKey,strpos($apiKey,'-')+1);
              $url = 'https://' . $dataCenter . '.api.mailchimp.com/3.0/lists/';
              $auth = base64_encode( 'user:' . $apiKey );
            //process post request
            $response = wp_remote_get( 
                                        $url, 
                                        array('headers' => array('Content-Type' => 'application/json','Authorization' => 'Basic '.$auth.''),
                                      ));
            $response_code = wp_remote_retrieve_response_code($response);
                if($response_code == 200 ){
                 update_option('amp_optin_mailchimp_v2_key_status',true);
                  if(isset($response['body'])){
                  $lists = json_decode($response['body']);
                    if(isset($lists->lists)){

                         $list_array = array();
                         foreach ($lists->lists as $list_key => $list_value) {
                          $list_array[$list_value->id] = $list_value->name;
                         }
                      update_option('amp_optin_mailchimp_v2_lists',$list_array);

                     // Interests Code starts here
                     $list_id = $list_value->id;
                     ampforwp_amp_optin_interests_v2($apiKey,$list_id);
                     // end
                    }
                  }
                  $res['success'] = 1;
                  $res['message'] = "Activated";
                  echo json_encode($res);
                   exit;
                 }else{
                  update_option('amp_optin_mailchimp_v2_key_status',false);
                  update_option('amp_optin_mailchimp_v2_lists',false);
                  update_option('amp_optin_mailchimp_v2_interests',false);

                   $res['success'] = 2;
                $res['message'] = "Please enter valid API key";
                echo json_encode($res);
                 exit;
                }
            }else{
                $res['success'] = 2;
                $res['message'] = "Please enter a valid license key";
                echo json_encode($res);
                exit;
            }
    }

add_action( 'wp_ajax_nopriv_amp_optin_mailchimp_api_key_devalidate', 'amp_optin_mailchimp_api_key_devalidate' );
add_action( 'wp_ajax_amp_optin_mailchimp_api_key_devalidate',  'amp_optin_mailchimp_api_key_devalidate'  );

function amp_optin_mailchimp_api_key_devalidate(){
    if(!wp_verify_nonce($_POST['amp_optin_api_settings_nonce'],'amp_optin_api_settings_nonce')){
          $res['success'] = 2;
          $res['message'] = "Sorry, your nonce did not verify.";
          echo json_encode($res);
          exit;
    }
    update_option('amp_optin_mailchimp_v2_key_status',false);
    update_option('amp_optin_mailchimp_v2_lists',false);
    update_option('amp_optin_mailchimp_v2_interests',false);
    update_option('amp_optin_mailchimp_v2_apikey', '');
    $res['success'] = 1;
    $res['message'] = "The Key has been deactivated.";
    echo json_encode($res);
    exit;
}    

// Interests Code starts here
function ampforwp_amp_optin_interests_v2($api_key,$list_id){
$data_center = substr( $api_key, strpos( $api_key, '-' ) + 1 ); 
$args = array(
  'headers' => array(
    'Authorization' => 'Basic ' . base64_encode( 'user:'. $api_key )
  )
);
 
$response = wp_remote_get( 'https://'.$data_center.'.api.mailchimp.com/3.0/lists/'.$list_id . '/interest-categories', $args );
$body = json_decode( wp_remote_retrieve_body( $response ) );
                      foreach ( $body->categories as $group ) :
 
    // we can skip hidden interests
    if( $group->type == 'hidden')
      continue;
 
    // heading, name of the Interest Category
    $output = array();
 
    // connect to API to get interests from each category
    $response = wp_remote_get( 'https://'.$data_center.'.api.mailchimp.com/3.0/lists/'.$list_id . '/interest-categories/' . $group->id . '/interests', $args );
    $body = json_decode( wp_remote_retrieve_body( $response ) );
 
    if ( wp_remote_retrieve_response_code( $response ) == 200 && $body->total_items > 0 ) {
      /* type of the interest group which can be set in MailChimp dashboard */
      switch( $group->type ) :
        case 'checkboxes':{
          foreach( $body->interests as $interest ){
            $output[$interest->id]= $interest->name;
            //$output .= (array)$output;
          }
          break;
        }
        case 'radio':{
          foreach( $body->interests as $interest ){
            $output .= '<label><input value="' . $interest->id . '" name="' . $group->id . '" type="radio" /> ' . $interest->name . '</label><br />';
          }
          break;
        }
        
        case 'dropdown':{
          $output .= '<select name="' . $group->id . '"><option value="">Please select...</option>';
          foreach( $body->interests as $interest ){
            $output .= '<option value="' . $interest->id . '">' . $interest->name . '</option>';
 
          }
          $output .= '</select>';
          break;
        }
        default:
        break;
      endswitch;
 
    } else {
      $output .= '<b>' . wp_remote_retrieve_response_code( $response ) . wp_remote_retrieve_response_message( $response ) . ':</b> ' . $body->detail;
    }
 //echo "yesmailchimpV2"; print_r( $interest );
  endforeach;

  update_option('amp_optin_mailchimp_v2_interests',$output);
}

// Interests Code ends here

if(function_exists('amp_activate')){
remove_filter( 'amp_content_sanitizers', 'ampforwp_custom_form_sanitizer', 20);
}
if( function_exists('ampforwp_is_amp_endpoint') ){
add_filter( 'amp_content_sanitizers', 'ampforwp_custom_form_sanitizer', 20); 
}
add_filter( 'ampforwp_content_sanitizers', 'ampforwp_custom_form_sanitizer', 20);
function ampforwp_custom_form_sanitizer( $sanitizer_classes ) {
  require_once( AMPOPTIN_PLUGIN_DIR .  'class/class-blacklist-sanitizer.php');
    unset( $sanitizer_classes[ 'AMP_Blacklist_Sanitizer' ] );
  $sanitizer_classes[ 'AMPFORWP_Blacklist_Sanitizer' ] = array();
  return $sanitizer_classes;
}


// Generating Short code for Optin
function amp_optin_shortcode() {
  add_shortcode('amp-optin', 'amp_optin_form_output');
  //amp redux settings updation.
  amp_optin_migrate_redux_settings();
}
add_action( 'init', 'amp_optin_shortcode');

// optin styling for standard & transitional mode.
if(function_exists('amp_activate') || is_plugin_active('amp/amp.php')){
  $getOption = get_option('amp-options');
  if ( $getOption['theme_support'] == 'standard' || $getOption['theme_support'] == 'transitional'){
  
   add_action('wp_head', 'amp_modal_optin_styling');
  }

  function amp_modal_optin_styling(){
    ob_start();
    ampforwp_option_styling();
    $ob = ob_get_contents();
    ob_get_clean();
    echo'<style>'.$ob.'</style>';
  }
}


// optin styling
add_action('amp_post_template_css','ampforwp_option_styling',20 );
function ampforwp_option_styling() {   
  global $redux_builder_amp;
/*global $shortcode_ids;
  $unique_ids =  array_unique($shortcode_ids);
foreach ($unique_ids as $id_key => $id_value) {*/
    $argument = array(
      'post_type'        => 'amp-optin',
      'post_status'      => 'publish',
      'posts_per_page' => -1,
    );
    $optin_posts_array = get_posts( $argument );
    $opt_in_cont = array('cont'      => '',
                         'script'   => '',
                    );
     $top_css = '';
    if(function_exists('amp_activate')){
      $top_css = 'top:0;';
    }
    $between_cont = $top_cont = $bottom_cont = $below_cont = $pop_up = '';
$modal_lt_inc = $modal_rt_inc = $modal_bt_inc = $modal_btrt_inc = 0;
    foreach ($optin_posts_array as $id_key => $id_val) {

    $id_value = $id_val->ID;
    $bg_color   = get_post_meta( $id_value, 'amp_option_form_bg_color', true );
    $headline_color         = get_post_meta( $id_value, 'amp_option_form_headline_color', true);
    $text_color    = get_post_meta( $id_value, 'amp_option_form_text_color', true );
    $button_bg_color    = get_post_meta( $id_value, 'amp_option_button_bg_color', true );
    $button_text_color    = get_post_meta( $id_value, 'amp_option_button_text_color', true );
    $pop_up    = get_post_meta( $id_value, 'ampforwp_optin_form_popup', true );
    $pop_up_sec    = get_post_meta( $id_value, 'ampforwp_optin_popup_sec', true );
    ?>
    .optin-<?php echo $id_value; ?> .optin-description{color:<?php echo $text_color;?>;}
    .optin-<?php echo $id_value; ?>{background-color: <?php echo $bg_color; ?>;color:<?php echo $text_color; ?>;}
    .optin-<?php echo $id_value; ?> .form-submit{background-color: <?php echo $button_bg_color; ?>; color: <?php echo $button_text_color; ?>;}
    .optin-<?php echo $id_value; ?> #sg-form-button{background-color: <?php echo $button_bg_color; ?>; color: <?php echo $button_text_color; ?>;}
    .optin-<?php echo $id_value; ?> .optin-headline-title{color:<?php echo $headline_color; ?>}

    <?php if(isset($pop_up) && ($pop_up == 'on' || $pop_up == true)){?>
    body #my-notification-<?php echo $id_value;  ?>.amp-active { background: hsla(0, 2%, 14%, 0.7); border-color: #242323b3; z-index: 10000; height: -webkit-fill-available; height: -moz-fill-available; top:0; visibility: hidden; animation: 0s linear <?php if( isset($pop_up_sec)) { echo $pop_up_sec; } else {?> 3s <?php } ?> forwards Pop-up-delay;
     }
       <?php if(function_exists('amp_activate')){ ?>
       body #my-notification-atp-<?php echo $id_value;  ?> { background: hsla(0, 2%, 14%, 0.7); border-color: #242323b3; z-index: 10000; height: -webkit-fill-available; height: -moz-fill-available; top:0; visibility: hidden; animation: 0s linear <?php if( isset($pop_up_sec) ) { echo $pop_up_sec; } else {?> 3s <?php } ?> forwards Pop-up-delay;
       }
     <?php } }//amp codn closes } // Pop up Closes
     // Modal Form
$modal_close_btn =  get_post_meta( $id_value, 'ampforwp_optin_modal_form_close_btn', true );
$modal_bg_color =  get_post_meta( $id_value, 'amp_optin_modal_button_bg_color', true );
$modal_text_color =  get_post_meta( $id_value, 'amp_optin_modal_button_text_color', true );
$modal_button_position =  get_post_meta( $id_value, 'ampforwp_optin_modal_button_position', true );
$modal_button_timer =  get_post_meta( $id_value, 'ampforwp_optin_modal_button_timer', true );
 $modal_form   = get_post_meta( $id_value, 'ampforwp_optin_modal_form', true );

if(isset($modal_form)  && ($modal_form == 'on' || $modal_form == true) ){
    if(isset($modal_close_btn) && ($modal_close_btn == '' || $modal_close_btn == false)){ ?>

    button.lightClick-<?php echo $id_value; ?> {
        background: <?php echo $modal_bg_color; ?>;
        border: 1px solid <?php echo $modal_bg_color; ?>;
        min-height: 40px;
        line-height: 40px;
        color: <?php echo $modal_text_color; ?>;
        font-size: 20px;
        <?php if(isset($modal_button_position) && $modal_button_position == 1 ) { $modal_left = $modal_lt_inc * (48) -48; ?>
               transform: rotate(90deg);left: 0;margin-left: <?php echo $modal_left; ?>px;margin-top: 200px;<?php echo $top_css; ?>
        <?php $modal_lt_inc++; } 
              elseif (isset($modal_button_position) && $modal_button_position == 2  ) { $modal_btm_rt = $modal_btrt_inc * (48);
                ?>
                  transform: rotate(0deg);bottom: 0px;left: 0;margin-bottom: <?php echo $modal_btm_rt; ?>px;margin-top: 0px;
        <?php $modal_btrt_inc++; } 
              elseif (isset($modal_button_position) && $modal_button_position == 3) { $modal_right = $modal_rt_inc * (48) -48; ?>
                   transform: rotate(90deg);right: 0;margin-right: <?php echo $modal_right; ?>px;margin-top: 200px;<?php echo $top_css; ?>
        <?php $modal_rt_inc++; }
              elseif (isset($modal_button_position) && $modal_button_position == 4) {  $modal_bottom = $modal_bt_inc * (48);?>
                  transform: rotate(0deg);bottom: 0px;right: 0;margin-bottom: <?php echo $modal_bottom; ?>px;margin-top: 0px;
       <?php $modal_bt_inc++; } ?>
        position: fixed;text-transform:uppercase;cursor:pointer;z-index: 9999; font-weight: bold;
    }
    <?php } ?>
      <?php if(isset($modal_close_btn) && ($modal_close_btn == 'on' || $modal_close_btn == true)){ ?>
      amp-user-notification#opt-mod-wrpr-<?php echo $id_value; ?> {
          background: transparent;
          bottom: 0;
          top: 0;
          display: contents;
          
      }
      #my-lightbox-<?php echo $id_value; ?> { z-index: 10000; }  
      button.lightClick-<?php echo $id_value; ?> {
          background: <?php echo $modal_bg_color; ?>;
          border: 1px solid <?php echo $modal_bg_color; ?>;
          min-height: 40px;
          line-height: 40px;
          color: <?php echo $modal_text_color; ?>;
          font-size: 20px;
          position: relative;text-transform:uppercase;cursor:pointer;z-index: 9999; font-weight: bold;
      }
      .optmod-wrp-<?php echo $id_value; ?> {
          position: fixed;
          z-index: 9999;
              <?php if(isset($modal_button_position) && $modal_button_position == 1 ) { ?>
                transform: rotate(90deg);left: 0;margin-top: 179px;margin-left: -25px;
          <?php } 
                elseif (isset($modal_button_position) && $modal_button_position == 2  ) { 
                  ?>
                  bottom: 0;left: 0;
          <?php  } 
                elseif (isset($modal_button_position) && $modal_button_position == 3) { ?>
                  transform: rotate(90deg);right: 0;margin-top: 179px;margin-right: -25px;
          <?php }
                elseif (isset($modal_button_position) && $modal_button_position == 4) { ?>
                    bottom: 0;right: 0;
         <?php } ?>
      }
      .optmod-wrp-<?php echo $id_value; ?> .cncl {
          background: <?php echo $modal_bg_color; ?>;
          border: 1px solid <?php echo $modal_bg_color; ?>;
          color: <?php echo $modal_text_color; ?>;
          position: absolute;
          cursor: pointer;
          font-weight: bold;
          <?php if(isset($modal_button_position) && $modal_button_position == 1 ) { ?>
                 top:-19px;
          <?php }
                elseif (isset($modal_button_position) && $modal_button_position == 2  ) { 
                  ?>
                  top: 12px;right: -25px;
          <?php  }
                elseif (isset($modal_button_position) && $modal_button_position == 3  ) { 
                  ?>
                  top:12px;
          <?php  } 
                elseif (isset($modal_button_position) && $modal_button_position == 4) { ?>
                  top: 10px;left: -25px;
         <?php } ?>
      }
      <?php } 
      if(function_exists('amp_activate')){
        ?> 
        button.lightClick-<?php echo $id_value;  ?>,.optmod-wrp-<?php echo $id_value;  ?> button{padding: 4px;}
        <?php
      }

    } // Modal Form Closes


  
    }
?>
}.gdpr-chxbox{position: relative;left: -9em;}
  .gdpr-chxbox-form5{position:relative;left:-9em;}
  .gdpr-lablel{font-size: 17px;display: flex;position: relative;top: -30px;left: 30px;}
.amp-optin-form-wrapper fieldset{border:0;margin:0;padding:0}
.amp-optin-form-wrapper .optin-headline-title{font-size: 20px; margin: 0;}
select#mce-MMERGE9-tov {
    display: none;
}
select.mailmunchselect {appearance: none;font-size: 14px;padding: 8px;width: 100%;border: 1px solid rgba(0,0,0,.13);
}
.submit_message p.show {font-size: 18px;}
.amp-optin-form-wrapper .optin-description{font-size: 13px; margin: 4px 0 8px 0;line-height: 18px;}
.amp-optin-form-wrapper{width: 300px;margin: 0 auto 15px auto;padding: 20px 25px;}
.amp-optin-form-wrapper .form-submit{padding: 10px;width: 100%;border: 0;border-radius: 60px;margin:5px 0px 0px 0px}
.amp-optin-form-wrapper #sg-form-button{padding: 10px;width: 100%;border: 0;border-radius: 60px;margin:5px 0px 0px 0px}
.amp-optin-form-wrapper label{width: 100%;display: inline-block;}
.amp-optin-form-wrapper input{padding: 10px;width: 100%;margin: 3px 0px;font-size:13px;border: 1px solid rgba(0, 0, 0, 0.13)}
html { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box;}
*, *:before, *:after { -webkit-box-sizing: inherit; -moz-box-sizing: inherit; box-sizing: inherit;
  }
.amp-optin-form-wrapper.form-8 { margin: 0 auto 0px auto; padding: 20px 0px; }
.amp-optin-form-wrapper.form-8 .optin-msg { text-align: center; }
.form-16 .optin-msg { text-align: center; }
.form-18 .optin-msg { text-align: center; }
.amp-optin-form-wrapper.form-18 { margin: 0 auto 0px auto; padding: 20px 0px; }   
@keyframes Pop-up-delay {
  to {
    visibility: visible;
  }
}

.amp-form-submit-success .optin-msg, .amp-form-submit-success fieldset {
    display: none;
}

.optin-popup { position: fixed; -webkit-overflow-scrolling: touch; top: 0; right: 0; bottom: 0; left: 0; padding: 1rem; display: flex; align-items: center; justify-content: center; }
.pop-up-form { position: relative; }
.ampforwp-pop-up-close-btn { background-color: #525252; border: 1px solid #525252; top: 0; position: absolute; font-size: 12px; padding: 7px 13px; right: 0; }
.optin-msg amp-img { max-width: 100%; }
.ampforwp_type_hidden_form_15 { display:none; }
.lightbox { background: rgba(0,0,0,0.5);width: 100%;height: 100%;position: absolute;text-align: center;top: 0;align-items: center;justify-content: center;display: flex; }
.setUpForm { position: relative; } 
.cansle {top: 0;position: absolute;font-size: 12px;padding: 7px 13px;right: 0;background-color: #525252;border: 1px solid #525252;font-family: sans-serif;cursor: pointer; } 
.ampforwp_ajax_loading_msg{ display:none; }
.ampforwp_ajax_loading_msg p{text-align: center;margin: 0;font-size: 100%;}form.amp-form-submitting .ampforwp_ajax_loading_msg{display:block;}
.amp-form-submit-success span.optin-headline-title, .amp-form-submit-success input.user-valid.valid, .amp-form-submit-success .dropdown-field-wrapper{
  display: none;
}
.pop-form.close {
    visibility: hidden;
    opacity: 0;
    transition: visibility 0s 4s, opacity 4s linear;
}


<?php }
//**********************************************//
// AMP optin COntent manipulation Code Start here //
//**********************************************//

  function get_amp_optin_form_output( $atts ) {
    
      global $post;

      $atts[] = shortcode_atts( array(
          'src' => $atts['id'],
      ), $atts ); 

      $form_class        = "";
      $form_class_output = "";
      if ( isset( $atts['class'] ) && $atts['class'] ) {
          $atts['class']    =  $atts['class'];
          $form_class       =  $atts['class'];
      }

      $id                = $atts['id'];
      $form_num          = get_post_meta( $atts['id'], 'amp_optin_select_form_company', true );
      $submit_button     = get_post_meta( $id, 'amp_option_submit_button_text', true);

      global $forms;
      switch ($form_num) {
                          case '1':
                                      require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-1.php' );
                                      break;
                          case '2':
                                      require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-2.php' );
                                      break;
                          case '3':
                                      require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-3.php' );
                                      break;
                          case '4':
                                      require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-4.php' );
                                      break;
                          case '5':
                                      require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-5.php' );
                                      break;
                          case '6':
                                      require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-6.php' );
                                      break;
                          case '7':
                                      require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-7.php' );
                                      break;
                          case '8':
                                      require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-8.php' );
                                      break;
                          case '9':
                                      require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-9.php' );
                                      break; 
                          case '10':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-10.php' );
                                    break;   
                          case '11':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-11.php' ); 
                                    break;
                          case '12':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-12.php' );
                                    break;
                                                              break; 
                          case '13':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-13.php' );
                                    break;
                          case '14':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-14.php' );
                                    break; 
                          case '15':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-15.php' );
                                    break;
                         case '16':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-16.php' );
                                    break;  
                         case '17':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-17.php' );
                                    break;
                         case '18':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-18.php' ); 
                                    break;
                         case '19':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-19.php' ); 
                                    break;   
                         case '20':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-20.php' ); 
                                    break;
                        case '21':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-21.php' ); 
                                    break;
                        case '22':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-22.php' ); 
                                    break;

                        case '23':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-23.php' ); 
                                    break;  
                        case '24':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-24.php' ); 
                                    break;
                        case '25':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-25.php' ); 
                                    break;
                        case '26':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-26.php' ); 
                                    break;   
                        case '27':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-27.php' ); 
                                    break;
                        case '28':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-28.php' ); 
                                    break;  
                       case '29':
                                    require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-29.php' ); 
                                    break; 
                      case '30':
                      require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-30.php' ); 
                      break;                     
                      case '31':
                                      require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-31.php' ); 
                                      break; 
                      case '32':
                                      require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-32.php' ); 
                                      break;       
                      case '33':
                                   require_once( AMPOPTIN_PLUGIN_DIR . 'forms/form-33.php' ); 
                                    break;             
      }

      if ( $form_class ) {
         $form_class_output  = $form_class;
      }

      if($form_num){
        $amp_optin_data = 'amp_optin_form_'. $form_num; 
        $output = '<div class="amp-optin-form-wrapper form-'. $form_num .' '. $form_class_output .' optin-'. $atts['id'] .'">';
        $output .= $amp_optin_data($id);
        $output .= '</div>';
        $output = apply_filters('amp_optin_form_output_content',$output,$id);
        return $output;
      }
      return '';
  }


  add_action( 'pre_amp_render_post','ampforwp_optin_content_manipulation');
  function ampforwp_optin_content_manipulation() {

    add_filter( 'the_content', 'ampforwp_content_optin_insertion_top', 15 );
    add_filter( 'the_content', 'ampforwp_content_optin_insertion_bottom', 14 );
    add_filter( 'the_content', 'ampforwp_insert_incontent_optin_code' );
  }
  $getOption = get_option('amp-options');
   $getamp = filter_input(INPUT_SERVER, 'REQUEST_URI');
   $amp  = explode('/', $getamp);
  if ( isset($getOption['theme_support']) && ($getOption['theme_support'] == 'standard' || $getOption['theme_support'] == 'transitional' && in_array('?amp', $amp))){
    add_filter( 'the_content', 'ampforwp_content_optin_insertion_top', 15 );
    add_filter( 'the_content', 'ampforwp_content_optin_insertion_bottom', 14 );
    add_filter( 'the_content', 'ampforwp_insert_incontent_optin_code', 14 );
  }
  function ampforwp_insert_between_content_transient($content){
    global $redux_builder_amp;
    $arg = array( 'id' => $redux_builder_amp['ampforwp-optin-box-selected-optin'] );
    $insertion = get_amp_optin_form_output($arg);

    // to show optin after below number of paragraph.
    $paragraph_id = '50-percent';
    if ( ( is_single() || is_page() || is_front_page() )  && ! is_admin() ) {
      return ampforwp_insert_after_paragraph_optin_code( $insertion, $paragraph_id, $content );
    }
    return $content;
  }
  function ampforwp_content_optin_insertion_top( $content ) {
   $test = amp_optin_content_insertion_top_bottom('top');
   $content = $test . '  '. $content;
   return $content;
  }



// Migrate Function Code


  function amp_optin_content_insertion_top_bottom($type){
  global $post;
  $argument = array(
      'post_type'        => 'amp-optin',
      'post_status'      => 'publish',
      'posts_per_page' => -1,
    );
    $optin_posts_array = get_posts( $argument );
    $opt_in_cont = array('top'      => '',
                         'bottom'   => '',
                         'between'  => '',
                    );
    $between_cont = $top_cont = $bottom_cont = $below_cont = $cont = '';

    foreach ($optin_posts_array as $id_key => $id_value) {

    $id = $id_value->ID;


    $box_position   = get_post_meta( $id, 'ampforwp_optin_box_position', true );
    $category_enable   = get_post_meta( $id, 'ampforwp_optin_form_for_specific_categories', true );    
      
    $posttype_support        = get_post_meta( $id, 'amp_opt_in_posttype_support', true);
    $content_top    = get_post_meta( $id, 'ampforwp_optin_box_content_top', true );
    $content_bottom    = get_post_meta( $id, 'ampforwp_optin_box_content_bottom', true );

    $in_between_content = get_post_meta( $id, 'ampforwp_optin_box_content', true );


    $exclude_post_id = (array) get_post_meta( $id, 'ampforwp_exclude_optin_box_for_spec_post', true );
    $excluder_c = get_post_meta( $id, 'ampforwp_exclude_optin_box_for_spec_cats', true );
    $exclude_post_id = explode(',', $exclude_post_id[0]);
    $exclude_page_id = (array) get_post_meta( $id, 'ampforwp_exclude_optin_box_for_spec_page', true );
    $exclude_page_id = explode(',', $exclude_page_id[0]);

    $exclude_id = array_merge( $exclude_post_id, $exclude_page_id );

    $include_cat_id = (array) get_post_meta( $id, 'ampforwp_optin_all_categories_text', true );
    $include_cat_id = explode(',', $include_cat_id[0]);
    //print_r($include_cat_id);die;


/*    if(isset($box_position) && $box_position == 'on' && isset($content_top) && $content_top == 'on' && !in_array($post->ID, $exclude_id )){
        $arg = array( 'id' => $id ); 
        $cont = get_amp_optin_form_output( $arg );
        $top_cont .= $cont;
    }

    if(isset($box_position) && $box_position == 'on' && isset($content_bottom) && $content_bottom == 'on' && !in_array($post->ID, $exclude_id )){
        $args = array( 'id' => $id ); 
        $below_cont = get_amp_optin_form_output( $args );
        $bottom_cont .= $below_cont;
    }

    if(isset($box_position) && $box_position == 'on' && isset($in_between_content) && $in_between_content == 'on' && !in_array($post->ID, $exclude_id )){
        $args_bn = array( 'id' => $id ); 
        $btwn_cont = get_amp_optin_form_output( $args_bn );
        $between_cont .= $btwn_cont;
    }*/
    
   
    $is_post_type = $is_page_type = $is_product_type = '';
    
    if( isset($posttype_support) && is_array($posttype_support)&& in_array('product',$posttype_support)){
        if(function_exists('is_product')){
        $is_product_type = is_product();
      }
    }else{
      if(is_plugin_active('amp/amp.php')){
        if(function_exists('is_product')){
          $is_product_type = is_product();
        }
      }
    }
    if( isset($posttype_support) && is_array($posttype_support) && in_array('post',$posttype_support)){
        if(function_exists('is_product')){
          $is_post_type = (is_single() && !is_product());
        }else{
          $is_post_type = is_single();
        }
    }else{
        if(is_plugin_active('amp/amp.php')){
          if(function_exists('is_product')){
            $is_post_type = (is_single() && !is_product());
          }else{
            $is_post_type = is_single();
          }
        }
    }

    if(isset($posttype_support) && is_array($posttype_support) && in_array('page',$posttype_support)){
        $is_page_type = is_page();
    }else{
      if(is_plugin_active('amp/amp.php')){
        $is_page_type = is_page();
      }
    }
    /*if(isset($redux_builder_amp['amp-opt-in-posttype-support']) && in_array('category', $redux_builder_amp['amp-opt-in-posttype-support']) ){
      $category = is_category();
    }*/

      if( isset($content_top) &&  ($content_top == 'on' || $content_top == true) && isset($box_position) && ($box_position == 'on' || $box_position == true) && !in_array($post->ID, $exclude_id ) ){
        $category_active = false;
        if (isset($category_enable) && ($category_enable == 'on' || $category_enable == true)) {
          $categories = get_the_category( $post->ID );
          foreach($categories as $category) {
            if (in_array($category->cat_ID,  $include_cat_id)) {
              $category_active  = true;
            }
          }
        }

      if( $is_post_type || $is_page_type || $is_product_type || $category_active ){
        $arg = array( 'id' => $id ); 
        $cont = get_amp_optin_form_output( $arg ); 
        $top_cont .= $cont;
        $opt_in_cont['top'] = $top_cont;
      }
    }

      if( isset($content_bottom) && ($content_bottom == 'on' ||  $content_bottom == true) && isset($box_position) && ($box_position == 'on' || $box_position == true ) && !in_array($post->ID, $exclude_id )){
        $category_active = false;
        if (isset($category_enable) && ($category_enable == 'on' || $category_enable == true)) {
          $categories = get_the_category( $post->ID );
          foreach($categories as $category) {
            if (in_array($category->cat_ID,  $include_cat_id)) {
              $category_active  = true;
            }
          }
        }

        if( $is_post_type || $is_page_type || $is_product_type  || $category_active ){
          $args = array( 'id' => $id ); 
          $below_cont = get_amp_optin_form_output( $args );
          $bottom_cont .= $below_cont;
        $opt_in_cont['bottom'] = $bottom_cont;
       }
      }

      if( isset($in_between_content) && ($in_between_content == 'on' || $in_between_content == true) && isset($box_position) && ($box_position == 'on' || $box_position == true) && !in_array($post->ID, $exclude_id )){
        $category_active = false;
        if (isset($category_enable) && ($category_enable == 'on' || $category_enable == true)) {
          $categories = get_the_category( $post->ID );
          foreach($categories as $category) {
            if (in_array($category->cat_ID,  $include_cat_id)) {
              $category_active  = true;
            }
          }
        }
        if( $is_post_type || $is_page_type || $is_product_type || $category_active ){
          $args_bn = array( 'id' => $id ); 
          $btwn_cont = get_amp_optin_form_output( $args_bn );
          $between_cont .= $btwn_cont;
        $opt_in_cont['between'] = $between_cont;
       }
      }

  } // foreach
return $opt_in_cont[$type];
  }


  function ampforwp_content_optin_insertion_bottom( $content ) {
      $bottom_content = amp_optin_content_insertion_top_bottom('bottom');
       $content = $content . '  '. $bottom_content;
       return $content;
  }



if ( ! function_exists( 'ampforwp_insert_incontent_optin_code' ) ) {
  function ampforwp_insert_incontent_optin_code( $content ) {

    $insertion = amp_optin_content_insertion_top_bottom('between');
    // to show optin after below number of paragraph.
    $paragraph_id = '50-percent';
    if ( ( is_single() || is_page() || is_front_page() )  && ! is_admin() ) {
      return ampforwp_insert_after_paragraph_optin_code( $insertion, $paragraph_id, $content );
    }
    return $content;
  }
}

//add_action('pre_amp_render_post', 'exclude_optin_from_spec_post', 9);
function exclude_optin_from_spec_post() {

 // amp_optin_content_insertion_top_bottom('exclude');
/*    global $post, $redux_builder_amp;

    $exclude_post_id = (array) $redux_builder_amp['ampforwp-exclude-optin-box-for-spec-post'];
    $exclude_post_id = explode(',', $exclude_post_id[0]);
    $exclude_page_id = (array) $redux_builder_amp['ampforwp-exclude-optin-box-for-spec-page'];
    $exclude_page_id = explode(',', $exclude_page_id[0]);

    $exclude_id = array_merge( $exclude_post_id, $exclude_page_id );
    
    if (in_array($post->ID, $exclude_id  )) {
        remove_action( 'pre_amp_render_post','ampforwp_optin_content_manipulation');
        remove_action( 'pre_amp_render_post', 'ampforwp_incontent_optin_code' );
     }*/
}


// Parent Function that makes the magic happen
if ( ! function_exists( 'ampforwp_insert_after_paragraph_optin_code' ) ) {
  function ampforwp_insert_after_paragraph_optin_code( $insertion, $paragraph_id, $content ) {
    global $redux_builder_amp;
    // add placeholder
    $pattern = '@<table(?>(?!</?table).)*</table>@s';
    preg_match_all($pattern, $content, $tables);
    if(!empty($tables)){
               $bId = 0;
               foreach($tables[0] as $table){
                  $replace = '#ampoptin'.$bId.'#';
                  $content = str_replace(trim($table), $replace, $content);
                  $bId++;
               }
    }
    $closing_p = '</p>';
    $paragraphs = explode( $closing_p, $content );
    $paragraphs = array_filter($paragraphs);
    if(!empty($paragraphs)){
        if ( $paragraph_id == '50-percent' ) {
          $paragraph_id =  count($paragraphs);
          $paragraph_id = $paragraph_id / 2 ;
          $paragraph_id = round($paragraph_id);
        }
        
        foreach ($paragraphs as $index => $paragraph) {
          if ( trim( $paragraph ) ) {
            $paragraphs[$index] .= $closing_p;
          }
          $pos = strpos($paragraph, '<p>');
          if ( $paragraph_id == $index + 1 && $pos !== false ) {
            $paragraphs[$index] .= $insertion;
          }
        }
        $content = implode( '', $paragraphs );
    }else{
        $content .= $insertion;
    }
    
    //add table content back
    if(!empty($tables)){
               $bId = 0;
               foreach($tables[0] as $table){
                  $search = '#ampoptin'.$bId.'#'; 
                  $content = str_replace($search, trim($table), $content);
                  $bId++;
               }
    }
    return $content;
  }
}
#pop-up for AMP by automatic plugin
 
if(is_plugin_active('amp/amp.php')){
  add_action('amp_post_template_footer','ampforwp_optin_popup');
  if( ! function_exists('ampforwp_optin_popup') ){
  function ampforwp_optin_popup() {
 amp_optin_pop_up_content('cont');

  } } }

// opt-in Modal Feature for amp.

$getOption = get_option('amp-options');
   $getamp = filter_input(INPUT_SERVER, 'REQUEST_URI');
   $amp  = explode('/', $getamp);
  if ( isset($getOption['theme_support']) && ($getOption['theme_support'] == 'standard' || $getOption['theme_support'] == 'transitional' && in_array('?amp', $amp))){
    global $redux_builder_amp;
    add_action('wp_footer','ampforwp_optin_popup');
  if( ! function_exists('ampforwp_optin_popup_trans') ){
  function ampforwp_optin_popup_trans() {

      $argument = array(
      'post_type'        => 'amp-optin',
      'post_status'      => 'publish',
      'posts_per_page' => -1,
    );
    $optin_posts_array = get_posts( $argument );

    $between_cont = $top_cont = $bottom_cont = $below_cont = $pop_up = '';
$atp_inc = 1;
    foreach ($optin_posts_array as $id_key => $id_value) {

    $id = $id_value->ID;


    $pop_up   = get_post_meta( $id, 'ampforwp_optin_form_popup', true );

       if(isset($pop_up)  && ($pop_up == 'on' || $pop_up == true) ){

         $popup_reload = get_post_meta( $id, 'ampforwp_optin_popup_reloads', true );
         $dismissal = '';
          if(isset($popup_reload)  && ($popup_reload == 'on' || $popup_reload == true) ){
            $dismissal = 'data-persist-dismissal="false"';
          }

if($atp_inc == 1){
$hdn_name = 'firststate';
}elseif($atp_inc == 2){
$hdn_name = 'secndstate';
}elseif($atp_inc == 3){
$hdn_name = 'thirdstate';
}else{
$hdn_name = 'ShowState'.$id.'';
}
        ?>
    <amp-user-notification id="my-notification-atp-<?php echo $id;  ?>"
  layout="nodisplay"  [hidden]="<?php echo $hdn_name;  ?>" <?php echo $dismissal; ?> >
      <div class="optin-popup"> 
    <?php 
            $arg = array( 'id' => $id ); 
            $pop_up_cont = get_amp_optin_form_output( $arg );

              ?>
              <div class ="pop-up-form"> <?php
                  // echo $pop_up_cont; 

        $sanitized_pop_up =  $pop_up_cont;

        echo $sanitized_pop_up;
                  ?>  <button on="tap:AMP.setState({<?php echo $hdn_name;  ?>: true})"
      class="ampforwp-pop-up-close-btn">X</button> </div><?php
            $atp_inc++;
       ?>  
    </div>
  </amp-user-notification>
<?php



       }

   } // foreach closes 

    }
  }
}

if(is_plugin_active('amp/amp.php')){
   $getOption = get_option('amp-options');
   $getamp = filter_input(INPUT_SERVER, 'REQUEST_URI');
   $amp  = explode('/', $getamp);
  if ( $getOption['theme_support'] == 'standard' || $getOption['theme_support'] == 'transitional' && in_array('?amp', $amp)){
   add_filter('wp_footer', 'ampforwp_optin_modal_for_amp');
  }else{
   add_action('amp_post_template_footer','ampforwp_optin_modal_for_amp');

  }
}

if(!function_exists('ampforwp_optin_modal_for_amp')) { 
  function ampforwp_optin_modal_for_amp(){  
amp_optin_modal_content('cont');
 }
  
}

// Pop-up Feature

  add_action('ampforwp_body_beginning','ampforwp_optin_popup');
  if( ! function_exists('ampforwp_optin_popup') ){
  function ampforwp_optin_popup() {
    amp_optin_pop_up_content('cont');
} } 





// Pop up Individual support


  function amp_optin_pop_up_content($type){
  global $post;
  $argument = array(
      'post_type'        => 'amp-optin',
      'post_status'      => 'publish',
      'posts_per_page' => -1,
    );
    $optin_posts_array = get_posts( $argument );
    $opt_in_cont = array('cont'      => '',
                         'script'   => '',
                    );
    $between_cont = $top_cont = $bottom_cont = $below_cont = $pop_up = '';

    foreach ($optin_posts_array as $id_key => $id_value) {

    $id = $id_value->ID;


    $pop_up   = get_post_meta( $id, 'ampforwp_optin_form_popup', true );
    $category_enable   = get_post_meta( $id, 'ampforwp_optin_form_for_specific_categories', true );
    $include_cat_id = (array) get_post_meta( $id, 'ampforwp_optin_all_categories_text', true );
    $include_cat_id = explode(',', $include_cat_id[0]);
    
    $category_active = false;
        if (isset($category_enable) && ($category_enable == 'on' || $category_enable == true)) {
          $categories = get_the_category( $post->ID );
          foreach($categories as $category) {
            if (in_array($category->cat_ID,  $include_cat_id)) {
              $category_active  = true;
            }
          }
        }

       if(isset($pop_up)  && ($pop_up == 'on' || $pop_up == true) && $type == 'cont'){
 
     $popup_reload = get_post_meta( $id, 'ampforwp_optin_popup_reloads', true );
     $dismissal = '';
          if(isset($popup_reload)  && ($popup_reload == 'on' || $popup_reload == true) ){
            $dismissal = 'data-persist-dismissal="false"';
          }

        ?>
    <?php if ( isset($category_enable) && $category_enable == 'on' && $category_active 
      ||  $category_enable == false &&  $pop_up == 'on' )    { ?>  
    <amp-user-notification id="my-notification-<?php echo $id;  ?>"
  layout="nodisplay" class="pop-form" [class]="closepop" <?php echo $dismissal; ?> >

      <div class="optin-popup"> 
    <?php 
            $arg = array( 'id' => $id ); 
            $pop_up_cont = get_amp_optin_form_output( $arg );

              ?>
              <div class ="pop-up-form"> <?php
                  // echo $pop_up_cont; 
        if(class_exists('AMPFORWP_Content')){  
        $sanitizer_obj = new AMPFORWP_Content( $pop_up_cont, array(), apply_filters( 'ampforwp_content_sanitizers', array( 
          'AMP_Img_Sanitizer' => array(), 
          'AMP_Style_Sanitizer' => array(),
          'AMP_Iframe_Sanitizer' => array(
             'add_placeholder' => true,
           ), 
        ) 
      ) );
        $sanitized_pop_up =  $sanitizer_obj->get_amp_content();
      }elseif(class_exists('AMP_Content')){

        $sanitized_pop_up =  $pop_up_cont;

      } 
        echo $sanitized_pop_up;
                  ?> 
                    <button on="tap:my-notification-<?php echo $id;  ?>.dismiss"
      class="ampforwp-pop-up-close-btn">X</button> </div>
      <?php }?>
       <span class="amp-active"> </span><?php
            
       ?>  
    </div>
  </amp-user-notification>
<?php



       }
      if(isset($pop_up)  && $pop_up == 'on' && $type == 'script'){

        $opt_in_cont['script'] = true;
      }


   } // foreach
 return $opt_in_cont[$type];
}



// adding amp-user-notification script for pop-up feature
add_filter( 'amp_post_template_data', 'ampforwp_pop_up_notification_scripts', 75 );
function ampforwp_pop_up_notification_scripts( $data ) {
  $pop_up_check = amp_optin_pop_up_content('script');
  if ( isset($pop_up_check) && $pop_up_check == true ) {
          if ( empty( $data['amp_component_scripts']['amp-user-notification'] ) ) {
            $data['amp_component_scripts']['amp-user-notification'] = 'https://cdn.ampproject.org/v0/amp-user-notification-0.1.js';
          }
          if ( empty( $data['amp_component_scripts']['amp-iframe'] ) ) {
          $data['amp_component_scripts']['amp-iframe'] = 'https://cdn.ampproject.org/v0/amp-iframe-0.1.js';
          }
  }  
  return $data;
}

add_filter('ampforwp_the_content_last_filter','close_popup_on_success');
function close_popup_on_success($content){
  $content = preg_replace('/<div\sclass="optin-popup"(.*?)class\s="pop-up-form">(.*?)<form(.*?)>/s', '<div class="optin-popup"$1class ="pop-up-form">$2<form$3 on="submit-success:AMP.setState({ closepop: \'pop-form close\' })">', $content);
  return $content;
}

// opt-in module for pb

add_filter('ampforwp_pagebuilder_modules_filter', 'ampforwp_module_templates_opt_in_pb');
if(!function_exists("ampforwp_module_templates_opt_in_pb")){
  function ampforwp_module_templates_opt_in_pb($moduleTemplate){
     
    global $moduleTemplate;
        $dir = ABSPATH . 'wp-content/plugins/amp-optin/';    

    if (is_dir($dir)) {
        if ($dh = opendir($dir)) {
            while (($file = readdir($dh)) !== false) {
              if(is_file($dir.$file) && strpos($file, '-pb-module.php') == true){
                $moduleTemplate[str_replace("-pb-module.php", "", $file)] = include $dir.$file;
              }
            } 
            closedir($dh);
        }
    }     
   return $moduleTemplate;    
  }
}

// Modal Individual support


  function amp_optin_modal_content($type){
  global $post;
  $argument = array(
      'post_type'        => 'amp-optin',
      'post_status'      => 'publish',
      'posts_per_page' => -1,
    );
    $optin_posts_array = get_posts( $argument );
    $opt_in_cont = array('cont'      => '',
                         'script'   => '',
                    );
    $between_cont = $top_cont = $bottom_cont = $below_cont = $modal_form = '';

    foreach ($optin_posts_array as $id_key => $id_value) {

    $id = $id_value->ID;


    $modal_form   = get_post_meta( $id, 'ampforwp_optin_modal_form', true );

       if(isset($modal_form)  && ($modal_form == 'on' || $modal_form == true) && $type == 'cont'){
   
    $opt_mod_close_opener = $opt_mod_close_closer = '';
    $modal_btn =  get_post_meta( $id, 'ampforwp_optin_modal_form_close_btn', true );
    $modal_timer =  get_post_meta( $id, 'ampforwp_optin_modal_button_timer', true );

    if(isset($modal_btn) && ($modal_btn == 'on' || $modal_btn == true)){
    $modal_cls_btn_text =  get_post_meta( $id, 'ampforwp_optin_modal_close_butn_text', true );
    $modal_timer =  get_post_meta( $id, 'ampforwp_optin_modal_button_timer', true );
    if(isset($modal_timer) && $modal_timer!=''){
    $modal_form_url   = admin_url('admin-ajax.php?action=amp_optin_disable_modal_form');
    $modal_form_url   = preg_replace('#^https?:#', '', $modal_form_url);  
    $modal_t_append = '<form class="amp_modal_t" action-xhr="'.esc_url($modal_form_url).'" method="post" target="_top"><input type="hidden" name="dismiss_hidden" value="'.$id.'"/>';
    $modal_t_halt = '</form>';
    }
    
    $opt_mod_close_opener = '<amp-user-notification id="opt-mod-wrpr-'.$id.'" layout="nodisplay" data-persist-dismissal="false"><div class="optmod-wrp-'.$id.'">';    
    $opt_mod_close_closer = $modal_t_append.'<button class="cncl" on="tap:opt-mod-wrpr-'.$id.'.dismiss" role="button" tabindex="0">'.$modal_cls_btn_text.'</button></div></amp-user-notification>'.$modal_t_halt;
    }?>
    <?php echo $opt_mod_close_opener ?>
    <button class="lightClick-<?php echo $id; ?>" on="tap:my-lightbox-<?php echo $id; ?>"
     role="button"
     tabindex="0">
    <?php $modal_btn_text =  get_post_meta( $id, 'ampforwp_optin_modal_button_text', true );
          echo $modal_btn_text; ?>
  </button>  
  <?php echo $opt_mod_close_closer ?>
  <amp-lightbox id="my-lightbox-<?php echo $id; ?>"
     layout="nodisplay">
    <div class="lightbox">  
       <?php   
        $arg = array( 'id' => $id ); 
        $modal_cont = get_amp_optin_form_output( $arg ); ?>
        <div class="setUpForm">   <?php 
        if(class_exists('AMPFORWP_Content')){
        $sanitizer_modal_obj = new AMPFORWP_Content( $modal_cont, array(), apply_filters( 'ampforwp_content_sanitizers', array( 
                        'AMP_Img_Sanitizer' => array(), 
                        'AMP_Style_Sanitizer' => array(),
                        'AMP_Iframe_Sanitizer' => array(
                           'add_placeholder' => true,
                             ), 
                         ) 
                      ) 
        );
        $sanitized_modal_optin =  $sanitizer_modal_obj->get_amp_content();
      }elseif(class_exists('AMP_Content')){

        $sanitized_modal_optin =  $modal_cont;

      }
        echo $sanitized_modal_optin;
      ?>
       <button class="cansle" on="tap:my-lightbox-<?php echo $id; ?>.close"
       role="button"
       tabindex="0">X</button> </div>
    </div>
  </amp-lightbox>

  <?php



       }
      if(isset($modal_form)  && ($modal_form == 'on' || $modal_form == true) && $type == 'script'){

        $opt_in_cont['script'] = true;
      }


   } // foreach
 return $opt_in_cont[$type];
}


// opt-in Modal Feature
if(!isset($_COOKIE['enable_modalform'])){     
add_action('ampforwp_body_beginning','ampforwp_optin_modal');
}
if(!function_exists('ampforwp_optin_modal')) { 
  function ampforwp_optin_modal(){

      amp_optin_modal_content('cont');
    }
  }


// Optin with AMP CTA Bar 

if( isset($redux_builder_amp['ampforwp-cta-bar-with-amp-optin']) && $redux_builder_amp['ampforwp-cta-bar-with-amp-optin'] == 1 ){
add_action('ampforwp_body_beginning','ampforwp_optin_with_cta');
if(!function_exists('ampforwp_optin_with_cta')) { 
  function ampforwp_optin_with_cta(){  global $redux_builder_amp;
    ?> 
  <amp-lightbox id="cta-optin-lightbox"
     layout="nodisplay">
    <div class="lightbox">  
       <?php   
        global $redux_builder_amp;
        $id = $redux_builder_amp['ampforwp-cta-bar-with-amp-optin-select'];
        $arg = array( 'id' => $id ); 
        $modal_cont = get_amp_optin_form_output( $arg ); ?>
        <div class="setUpForm">   <?php      
        $sanitizer_modal_obj = new AMPFORWP_Content( $modal_cont, array(), apply_filters( 'ampforwp_content_sanitizers', array( 
                        'AMP_Img_Sanitizer' => array(), 
                        'AMP_Style_Sanitizer' => array(),
                        'AMP_Iframe_Sanitizer' => array(
                           'add_placeholder' => true,
                             ), 
                         ) 
                      ) 
        );
        $sanitized_modal_optin =  $sanitizer_modal_obj->get_amp_content();
        echo $sanitized_modal_optin;
      ?>
       <button class="cansle" on="tap:cta-optin-lightbox.close"
       role="button"
       tabindex="0">X</button> </div>
    </div>
  </amp-lightbox>

  <?php }
  }
}

add_filter( 'amp_post_template_data', 'ampforwp_optin_modal_lightbox_scripts' );
function ampforwp_optin_modal_lightbox_scripts( $data ) {
  global $redux_builder_amp;
  $modal_form = amp_optin_modal_content('script');
if ( (isset($modal_form) && $modal_form == true) || (isset($redux_builder_amp['ampforwp-cta-bar-with-amp-optin']) && $redux_builder_amp['ampforwp-cta-bar-with-amp-optin'] == true) ) {
          if ( empty( $data['amp_component_scripts']['amp-lightbox'] ) ) {
            $data['amp_component_scripts']['amp-lightbox'] = 'https://cdn.ampproject.org/v0/amp-lightbox-0.1.js';
          }
  }  
  return $data;
} 

// Form submission code start here
add_action('wp_ajax_optin_form_submission','optin_form_submission');
add_action('wp_ajax_nopriv_optin_form_submission','optin_form_submission');

function optin_form_submission (){
    $form_id = $_POST['ampforwp_form_id'];
    unset($_POST['ampforwp_form_id']);
    // foreach ($_POST as $key => $value) { 
    //   $key_and_value   .= ''.$key.'='.$value.'&';
    // }
    //$key  = rtrim($key_and_value,"&"); 
    $key = http_build_query($_POST);
    $form_num = get_post_meta( $form_id, 'amp_optin_select_form_company', true );


# campaign monitor code start here.
if( $form_num == 3){
          if(!wp_verify_nonce($_POST['amp_optin_nonce'],'amp_optin_nonce') && ((!strpos($_SERVER['HTTP_ORIGIN'], 'cdn.ampproject.org')) && (!strpos($_SERVER['HTTP_ORIGIN'], 'amp.cloudflare.com')) && (!strpos($_SERVER['HTTP_REFERER'], 'google.com/amp/s/')) ) ){
                  header('HTTP/1.1 500 FORBIDDEN');
                  echo wp_json_encode( 'Sorry, your nonce did not verify.' );
                  die;
          }
          # Get the user api key and list id.
          global  $form_3_api_key,$form_3_list_id;
          $form_3_api_key  = get_post_meta( $form_id, 'amp_optin_form_3_api_key', true );
          $form_3_list_id  = get_post_meta( $form_id, 'amp_optin_form_3_List_ID', true );
          # include campaign monitor libarary.
          require_once dirname( __FILE__ ) .'/cm-libraries/campaignmonitor/csrest_subscribers.php';

            function Get_user_data($name,$email) {
                global $form_3_api_key;
                global $form_3_list_id;    
                $wrap = new CS_REST_Subscribers($form_3_list_id, $form_3_api_key);
                $response = $wrap->add(array(
                  'EmailAddress' => $email,
                  'Name' => $name,
                  /*'CustomFields' => array(
                    array(
                        'Key' => 'phone',
                        'Value' => '7507090906'
                    ),
                    array(
                        'Key' => 'date',
                        'Value' => '2019/11/03'
                    ),
                    array(
                        'Key' => 'Multi Option Field 1',
                        'Value' => 'Option 1'
                    ),
                    array(
                        'Key' => 'Multi Option Field 1',
                        'Value' => 'Option 2'
                    )
                  ),*/
                  'Resubscribe' => true,
                ));
            }

            function campaign_monitor_newsletter_response () {
              if ($_SERVER['REQUEST_METHOD'] != 'POST') return;
              Get_user_data($_POST['cm-name'],$_POST['cm-email']);
            }
            campaign_monitor_newsletter_response();
            $redirectCheck = get_post_meta($form_id, 'amp_optin_checkbox_redirect', true);
            if($redirectCheck == true){
              $redirectUrl = get_post_meta( $form_id, 'ampforwp_optin_redirection', true );
              
            } 
            if( empty($redirectUrl)){
                header('AMP-Access-Control-Allow-Source-Origin: '.$amp_optin_Site.'');
                # form was not working through cdn.
                header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
                header('Access-Control-Allow-Credentials: true');
            }
            else{
                  header('AMP-Access-Control-Allow-Source-Origin: '.$amp_optin_Site.'');
                  header("AMP-Redirect-To: ".$redirectUrl);
                  header("Access-Control-Expose-Headers: AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin"); 
            }
            echo json_encode(array('successmsg'=>'Form submit successfull.'));
            die();
} #campagin monitor code end here.

// AC code starts here.
if( $form_num == 5 ){
    if(!wp_verify_nonce($_POST['amp_optin_nonce'],'amp_optin_nonce') && ((!strpos($_SERVER['HTTP_ORIGIN'], 'cdn.ampproject.org')) && (!strpos($_SERVER['HTTP_ORIGIN'], 'amp.cloudflare.com')) && (!strpos($_SERVER['HTTP_REFERER'], 'google.com/amp/s/')) ) ){
          header('HTTP/1.1 500 FORBIDDEN');
          echo wp_json_encode( 'Sorry, your nonce did not verify.' );
          die;
    }
    
    $ac_keystatus = get_option('amp_optin_ac_key_status');
    if( (empty($ac_keystatus) || !isset($ac_keystatus) || $ac_keystatus == false ) ){
          header('HTTP/1.1 500 FORBIDDEN');
          echo wp_json_encode( 'Active Campaign API token is Invalid or Not connected in the AMP Optin settings.' );
          die;
    }

    # Collect the data to process.
    $first_name = $_POST['firstname'];
    $last_name = $_POST['lastname'];
    $email = $_POST['email'];
    $phone = isset($_POST['phone'])? $_POST['phone'] : '';

    $ac_apiKey  = get_option( 'amp_optin_ac_apikey');

    //API Url to process request
    $ac_apiurl = get_option( 'amp_optin_ac_api_url');
    $api_url =  $ac_apiurl."/api/3/contacts";

    $header = array(
      'Api-Token' => $ac_apiKey,
      'Content-Type'  => 'application/json',
    );
    $data =  array(
                  'contact'=>array(
                              "email"=>  $email,
                              "firstName"=> $first_name,
                              "lastName"=> $last_name,
                              "phone"=> $phone,
                            ),
                );
    $args = array(
              'method' => 'POST',
              'httpversion' => '1.1',
              'headers'=> $header,
              'body'=> json_encode($data),
              'sslverify'=>false,
            ); 
    $cont_resp = wp_remote_post( $api_url, $args);

    $cont_resp_code = wp_remote_retrieve_response_code($cont_resp);

    if( $cont_resp_code < 300 || $cont_resp_code == 422 ){
        $current_id = '';
        if( $cont_resp_code < 300 ){
            $get_id = json_decode($cont_resp['body']);
            $current_id = $get_id->contact->id;
        }
        if( empty($current_id) && $cont_resp_code == 422 ){
            $api_url =  $ac_apiurl."/api/3/contacts?email=".$email."";
            $header = array(
              'Api-Token' => $ac_apiKey,
              'Content-Type'  => 'application/json',
            );
            $args = array(
                      'method' => 'GET',
                      'httpversion' => '1.1',
                      'headers'=> $header,
                      'sslverify'=>false,
                    ); 
            $cont_resp_in = wp_remote_get( $api_url, $args);
            $get_id = json_decode($cont_resp_in['body']);
            $current_id = $get_id->contacts[0]->id;
        }

        $api_tag_url =  $ac_apiurl."/api/3/contactTags";

        $header = array(
          'Api-Token' => $ac_apiKey,
          'Content-Type'  => 'application/json',
        );
        
        $ac_tag  = $_POST['amp_optin_ac_tag'];

        $data =  array(
                      'contactTag'=>array(
                                  "contact"=> $current_id,
                                  "tag"=> $ac_tag,
                                ),
                    );

        $args = array(
                  'method' => 'POST',
                  'httpversion' => '1.1',
                  'headers'=> $header,
                  'body'=> json_encode($data),
                  'sslverify'=>false,
                ); 

        $tag_resp = wp_remote_post( $api_tag_url, $args);

        $tag_resp_code = wp_remote_retrieve_response_code($tag_resp);

        $redirectCheck = get_post_meta($form_id, 'amp_optin_checkbox_redirect', true);
        if($redirectCheck == true){
          $redirectUrl = get_post_meta( $form_id, 'ampforwp_optin_redirection', true );
        } 
        if( empty($redirectUrl)){
            header('AMP-Access-Control-Allow-Source-Origin: '.$amp_optin_Site.'');
            # form was not working through cdn.
            header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
            header('Access-Control-Allow-Credentials: true');
        }
        else{
            header('AMP-Access-Control-Allow-Source-Origin: '.$amp_optin_Site.'');
            header("AMP-Redirect-To: ".$redirectUrl);
            header("Access-Control-Expose-Headers: AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin"); 
        }
        echo json_encode(array('status'=>200, 'successmsg'=>'Form submit successfull. '.wp_remote_retrieve_response_message($response)));
    }else{
      header("HTTP/1.1 404 BAD request"); 
      echo json_encode(array('status'=>400, 'msg'=>"wrong side=> ".wp_remote_retrieve_response_message($response) ));
    }
    die();
}
// AC code ends here.

// Drip code starts here.
if( $form_num == 12){
    if(!wp_verify_nonce($_POST['amp_optin_nonce'],'amp_optin_nonce') && ((!strpos($_SERVER['HTTP_ORIGIN'], 'cdn.ampproject.org')) && (!strpos($_SERVER['HTTP_ORIGIN'], 'amp.cloudflare.com')) && (!strpos($_SERVER['HTTP_REFERER'], 'google.com/amp/s/')) ) ){
            header('HTTP/1.1 500 FORBIDDEN');
            echo wp_json_encode( 'Sorry, your nonce did not verify.' );
            die;
    }

    $drip_keystatus = get_option('amp_optin_drip_key_status');
    if( (empty($drip_keystatus) || !isset($drip_keystatus) || $drip_keystatus == false ) ){
            header('HTTP/1.1 500 FORBIDDEN');
            echo wp_json_encode( 'Drip API token is Invalid or Not connected in the AMP Optin settings.' );
            die;
    }
    
    $account_id = get_option( 'amp_optin_drip_account_id');

    # Collect the data to process.
    $name = $_POST['drip-name'];
    $email = $_POST['drip-email'];

    $form_12_api_key  = get_option( 'amp_optin_drip_api_key');;

    //API Url to process request
    $api_url = "https://api.getdrip.com/v2/{$account_id}/subscribers";

    //form data.
    $subscribers = array( array(
                              'email'      => $email,
                              'first_name' => $name,
                                ));
    $jsondata = array( 'subscribers' => $subscribers);

    //process post request
    $response = wp_remote_post( $api_url, 
                                array(
                                      'timeout'   => 30,
                                      'sslverify' => false,
                                      'headers'   => array(
                                        'Authorization' => "Basic " . base64_encode( "{$form_12_api_key}:" ),
                                        'User-Agent'    => 'AMP Opt-in Forms (http://ampforwp.com/optin-form)',
                                        'Content-Type'  => 'application/vnd.api+json'
                                      ),
                                      'body'      => json_encode( $jsondata )
                                ));

    $response_code = wp_remote_retrieve_response_code($response);
    if($response_code == 200 ){
        $redirectCheck = get_post_meta($form_id, 'amp_optin_checkbox_redirect', true);
        if($redirectCheck == true){
          $redirectUrl = get_post_meta( $form_id, 'ampforwp_optin_redirection', true );
          
        } 
        if( empty($redirectUrl)){
            header('AMP-Access-Control-Allow-Source-Origin: '.$amp_optin_Site.'');
            # form was not working through cdn.
            header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
            header('Access-Control-Allow-Credentials: true');
        }
        else{
              header('AMP-Access-Control-Allow-Source-Origin: '.$amp_optin_Site.'');
              header("AMP-Redirect-To: ".$redirectUrl);
              header("Access-Control-Expose-Headers: AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin"); 
        }
        $resp = json_encode(array('[]successmsg'=>'Form submit successfull.'));
        echo str_replace('[]{"successmsg":"Form submit successfull."}', '{"successmsg":"Form submit successfull."}', $resp);
        die();
    }
}
// Drip code ends here.

# klaviyo integration code start here.
if( $form_num == 28){
            if(!wp_verify_nonce($_POST['amp_optin_nonce'],'amp_optin_nonce') && ((!strpos($_SERVER['HTTP_ORIGIN'], 'cdn.ampproject.org')) && (!strpos($_SERVER['HTTP_ORIGIN'], 'amp.cloudflare.com')) && (!strpos($_SERVER['HTTP_REFERER'], 'google.com/amp/s/')) ) ){
                    header('HTTP/1.1 500 FORBIDDEN');
                    echo wp_json_encode( 'Sorry, your nonce did not verify.' );
                    die;
            }
            # Collect the data to process.
            $FirstName = $_POST['klaviyo-fname'];
            $LastName = $_POST['klaviyo-lname'];
            $email = $_POST['klaviyo-email'];

            $consent  = get_post_meta( $form_id, 'ampforwp_optin_Gdpr_name', true );
            if(isset($_POST[$consent])){
                $check_consent = true;
                $consent = $_POST[$consent];
            }

            $form_28_api_key  = get_post_meta( $form_id, 'amp_optin_form_28_API_URL', true );
            $form_28_list_id  = get_post_meta( $form_id, 'amp_optin_form_28_list_id', true );
            //API Url to process request
            $api_url = 'https://a.klaviyo.com/api/v2/list/'.$form_28_list_id .'/subscribe';
            
            //form JSON data.
            $jsonData = array(
                'api_key' => $form_28_api_key,
                'profiles' => array(
                  'First Name'=> $FirstName,
                  'Last Name'=>  $LastName,
                  'email' =>     $email
                ),
            );

            if($check_consent){
                $jsonData['profiles']['$consent'] = $consent;
            }

            //process post request
            $response = wp_remote_post( 
                                        $api_url, 
                                        array('headers' => array('Content-Type' => 'application/json;charset=utf-8'),
                                            'body'        => json_encode($jsonData),
                                      ));
            $response_code = wp_remote_retrieve_response_code($response);
            if($response_code == 200 ){
                $redirectCheck = get_post_meta($form_id, 'amp_optin_checkbox_redirect', true);
                if($redirectCheck == true){
                  $redirectUrl = get_post_meta( $form_id, 'ampforwp_optin_redirection', true );
                  
                } 
                if( empty($redirectUrl)){
                    header('AMP-Access-Control-Allow-Source-Origin: '.$amp_optin_Site.'');
                    # form was not working through cdn.
                    header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
                    header('Access-Control-Allow-Credentials: true');
                }
                else{
                      header('AMP-Access-Control-Allow-Source-Origin: '.$amp_optin_Site.'');
                      header("AMP-Redirect-To: ".$redirectUrl);
                      header("Access-Control-Expose-Headers: AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin"); 
                }
                $resp = json_encode(array('[]successmsg'=>'Form submit successfull.'));
                echo str_replace('[]{"successmsg":"Form submit successfull."}', '{"successmsg":"Form submit successfull."}', $resp);
                die();
            }
}#klaviyo code end here.

// mailchimp api key...
if( $form_num == 30){
        if(!wp_verify_nonce($_POST['amp_optin_nonce'],'amp_optin_nonce') && ((!strpos($_SERVER['HTTP_ORIGIN'], 'cdn.ampproject.org')) && (!strpos($_SERVER['HTTP_ORIGIN'], 'amp.cloudflare.com')) && (!strpos($_SERVER['HTTP_REFERER'], 'google.com/amp/s/')) ) ){
                  header('HTTP/1.1 500 FORBIDDEN');
                  echo wp_json_encode( 'Sorry, your nonce did not verify.' );
                  die;
          }

          $key_status  = get_option( 'amp_optin_mailchimp_v2_key_status');
          $apiKey = get_option( 'amp_optin_mailchimp_v2_apikey');
          if($key_status == false){
                   header('HTTP/1.1 500 FORBIDDEN');
                  echo wp_json_encode( 'MailChimp API is Invalid or Not connected in AMP Optin settings.' );
                  die;
          }
         //$apiKey = get_post_meta( $form_id, 'amp_optin_form_1_API_URL', true ); 
        
         $listId = get_post_meta( $form_id, 'amp_optin_select_mailchimp_list', true );
         $interest_v2 = get_post_meta( $form_id, 'amp_optin_select_mailchimp_interest', true );

         $memberId = md5(strtolower($_POST['EMAIL']));

          $dataCenter = substr($apiKey,strpos($apiKey,'-')+1);
          $url = 'https://' . $dataCenter . '.api.mailchimp.com/3.0/lists/' . $listId . '/members/' . $memberId;

          $auth = base64_encode( 'user:' . $apiKey );

// get Interests VALUES

          $mc_interests = array();
          if(!empty($interest_v2) && is_array($interest_v2)){
          foreach ($interest_v2 as $key => $value) {
            $mc_interests[$value] = true;
          }
         }

         $json = array(
              'email_address' => $_POST['EMAIL'],
              'status'        => 'subscribed', // "subscribed","unsubscribed","cleaned","pending"
              'merge_fields'  => array(
                                  'FNAME'     => $_POST['FNAME'],
                                  'LNAME'     => $_POST['LNAME'],
                                 ), 
              );
         if(!empty($mc_interests)){
          $json['interests'] = $mc_interests;
        }

        $response = wp_remote_request( 
                                      $url, 
                                      array('headers' => array('Content-Type' => 'application/json','Authorization' => 'Basic '.$auth.''),
                                          'body'        => json_encode($json),
                                          'method'    => 'PUT',
                                    ));
          $response_code = wp_remote_retrieve_response_code($response);
          if ( is_wp_error( $response ) ) {
             wp_remote_retrieve_body( $response );
             echo json_encode(array('error_message'=>$response ));
          }else{

            $redirect_check = get_post_meta($form_id, 'amp_optin_checkbox_redirect', true);
          if($redirect_check == true){
             $redirect_url = get_post_meta( $form_id, 'ampforwp_optin_redirection', true );
          } 
          if( empty($redirect_url)){
            header('AMP-Access-Control-Allow-Source-Origin: '.$amp_optin_Site.'');
          // form was not working through cdn.
            header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
            header('Access-Control-Allow-Credentials: true');
          }
          else{
            header('AMP-Access-Control-Allow-Source-Origin: '.$amp_optin_Site.'');
            header("AMP-Redirect-To: ".esc_url($redirect_url));
            header("Access-Control-Expose-Headers: AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin"); 
          }
            echo json_encode(array('successmsg'=>'Form submit successfull.'));
          die();
          }
}
// mailchimp api methods ends here..

// Revue code starts here.
if( $form_num == 31){
    if(!wp_verify_nonce($_POST['amp_optin_nonce'],'amp_optin_nonce') && ((!strpos($_SERVER['HTTP_ORIGIN'], 'cdn.ampproject.org')) && (!strpos($_SERVER['HTTP_ORIGIN'], 'amp.cloudflare.com')) && (!strpos($_SERVER['HTTP_REFERER'], 'google.com/amp/s/')) ) ){
            header('HTTP/1.1 500 FORBIDDEN');
            echo wp_json_encode( 'Sorry, your nonce did not verify.' );
            die;
    }
    $revue_keystatus = get_option('amp_optin_revue_key_status');
    if( (empty($revue_keystatus) || !isset($revue_keystatus) || $revue_keystatus == false ) ){
            header('HTTP/1.1 500 FORBIDDEN');
            echo wp_json_encode( 'Revue API key is Invalid or Not connected in the AMP Optin settings.' );
            die;
    }  
    # Collect the data to process.
    $first_name = $_POST['revue-fname'];
    $last_name = $_POST['revue-lname'];
    $email = $_POST['revue-email'];

    $form_31_api_key  = get_option('amp_optin_revue_api_key');

    //API Url to process request
    $api_url = "https://www.getrevue.co/api/v2/subscribers";

    //form data.
    $jsondata = array(
        'email'      => $email,
        'first_name' => $first_name,
        'last_name' => $last_name,
        'double_opt_in' => false
    );

    //process post request
    $response = wp_remote_post( $api_url, 
                                array(
                                      'headers' => array(
                                          'Content-Type' => 'application/json',
                                          'Authorization' => 'Token token="' . $form_31_api_key . '"'
                                      ),
                                      'body' => json_encode( $jsondata )
                                    ));

    $response_code = wp_remote_retrieve_response_code($response);
    if($response_code == 200 ){
        $redirectCheck = get_post_meta($form_id, 'amp_optin_checkbox_redirect', true);
        if($redirectCheck == true){
          $redirectUrl = get_post_meta( $form_id, 'ampforwp_optin_redirection', true );
          
        } 
        if( empty($redirectUrl)){
            header('AMP-Access-Control-Allow-Source-Origin: '.$amp_optin_Site.'');
            # form was not working through cdn.
            header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
            header('Access-Control-Allow-Credentials: true');
        }
        else{
              header('AMP-Access-Control-Allow-Source-Origin: '.$amp_optin_Site.'');
              header("AMP-Redirect-To: ".$redirectUrl);
              header("Access-Control-Expose-Headers: AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin"); 
        }
        $resp = json_encode(array('[]successmsg'=>'Form submit successfull.'));
        echo str_replace('[]{"successmsg":"Form submit successfull."}', '{"successmsg":"Form submit successfull."}', $resp);
        die();
    }
}

if( $form_num == 33){

    if(!wp_verify_nonce($_POST['amp_optin_nonce'],'amp_optin_nonce') && ((!strpos($_SERVER['HTTP_ORIGIN'], 'cdn.ampproject.org')) && (!strpos($_SERVER['HTTP_ORIGIN'], 'amp.cloudflare.com')) && (!strpos($_SERVER['HTTP_REFERER'], 'google.com/amp/s/')) ) ){
            header('HTTP/1.1 500 FORBIDDEN');
            echo wp_json_encode( 'Sorry, your nonce did not verify.' );
            die;
    }
      
    $form_33_api_key  = get_post_meta( $form_id, 'amp_optin_form_33_API_URL', true );
    $form_33_list_id  = get_post_meta( $form_id, 'amp_optin_form_33_list_id', true );
    $form_33_brand_id  = get_post_meta( $form_id, 'amp_optin_form_33_brand_id', true );

    # Get the Form Data-> name,email
    $curl = curl_init();
    $name = $_POST['bigmailer_fname'];
    $email = $_POST['bigmailer_email'];

    curl_setopt_array($curl, [
    CURLOPT_URL => "https://api.bigmailer.io/v1/brands/".$form_33_brand_id."/contacts",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => "{\"field_values\":[{\"string\":\"$name\",\"name\":\"name\"}],\"list_ids\":[\"$form_33_list_id\"],\"unsubscribe_all\":false,\"email\":\"$email\"}",
    CURLOPT_HTTPHEADER => [
      "Accept: application/json",
      "Content-Type: application/json",
      "X-API-Key: ".$form_33_api_key.""
    ],
  ]);

    $response = curl_exec($curl);
    if($form_id ){
        $redirectCheck = get_post_meta($form_id, 'amp_optin_checkbox_redirect', true);
        if($redirectCheck == true){
          $redirectUrl = get_post_meta( $form_id, 'ampforwp_optin_redirection', true );
          
        } 
        if( empty($redirectUrl)){
            header('AMP-Access-Control-Allow-Source-Origin: '.$amp_optin_Site.'');
            # form was not working through cdn.
            header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
            header('Access-Control-Allow-Credentials: true');
        }
        else{
              header('AMP-Access-Control-Allow-Source-Origin: '.$amp_optin_Site.'');
              header("AMP-Redirect-To: ".$redirectUrl);
              header("Access-Control-Expose-Headers: AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin"); 
        }
        $resp = json_encode(array('[]successmsg'=>'Form submit successfull.'));
        echo str_replace('[]{"successmsg":"Form submit successfull."}', '{"successmsg":"Form submit successfull."}', $resp);
        die();
    }
    curl_close($curl);
     
}
// Revue code ends here.

// Revue code starts here.
if( $form_num == 32){
    if(!wp_verify_nonce($_POST['amp_optin_nonce'],'amp_optin_nonce') && ((!strpos($_SERVER['HTTP_ORIGIN'], 'cdn.ampproject.org')) && (!strpos($_SERVER['HTTP_ORIGIN'], 'amp.cloudflare.com')) && (!strpos($_SERVER['HTTP_REFERER'], 'google.com/amp/s/')) ) ){
            header('HTTP/1.1 500 FORBIDDEN');
            echo wp_json_encode( 'Sorry, your nonce did not verify.' );
            die;
    }
          $zoho_key_status  = get_option( 'amp_optin_zoho_crm_token_status');
          $access_token = get_option( 'amp_optin_zoho_crm_oauth_token');
          $zoho_all_tokens = get_option( 'amp_optin_zoho_crm_all_tokens');
          $account_domain = $zoho_all_tokens['domain'];
          if($zoho_key_status == false){
                   header('HTTP/1.1 500 FORBIDDEN');
                  echo wp_json_encode( 'Zoho aouth token is Invalid or Not connected in AMP Optin settings.' );
                  die;
          }

          # Collect the data to process.
          $zoho_fname = isset($_POST['zoho-fname']) ? $_POST['zoho-fname'] : '';
          $zoho_lname = isset($_POST['zoho-lname']) ? $_POST['zoho-lname'] : '';
          $zoho_email = $_POST['zoho-email'];

          //API Url to process request
          $zoho_api_url = "https://www.zohoapis".$account_domain."/crm/v2/Leads";


          $zoho_data = '{
                "data": [
                    {
                        "Last_Name": "'.$zoho_lname.'",
                        "First_Name": "'.$zoho_fname.'",
                        "Email": "'.$zoho_email.'",
                    },
                ],
                "trigger": [
                    "approval",
                    "workflow",
                    "blueprint"
                ]
            }';


      //process post request
      $response = wp_remote_post( $zoho_api_url, 
                                  array(
                                        'headers' => array(
                                            'Authorization' => 'Zoho-oauthtoken ' . $access_token . ''
                                        ),
                                        'body' => $zoho_data
                                      ));

      $response_code = wp_remote_retrieve_response_code($response);

      if($response_code == 200 ||  $response_code == 201){
          $redirectCheck = get_post_meta($form_id, 'amp_optin_checkbox_redirect', true);
          if($redirectCheck == true){
            $redirectUrl = get_post_meta( $form_id, 'ampforwp_optin_redirection', true );
            
          } 
          $siteUrl = parse_url(
                      get_site_url()
                    );
          $amp_opt_in_Site = $siteUrl['scheme'] . '://' . $siteUrl['host'];
          if( empty($redirectUrl)){
              header('AMP-Access-Control-Allow-Source-Origin: '.esc_url_raw($amp_opt_in_Site).'');
              # form was not working through cdn.
              header('Access-Control-Allow-Origin: ' .$_SERVER['HTTP_ORIGIN']);
              header('Access-Control-Allow-Credentials: true');
          }
          else{
                header('AMP-Access-Control-Allow-Source-Origin: '.$amp_opt_in_Site.'');
                header("AMP-Redirect-To: ".esc_url_raw($redirectUrl));
                header("Access-Control-Expose-Headers: AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin"); 
          }
          echo json_encode(array('successmsg'=>'Form submit successfull.'));
          die;
          
      }else{
         header('HTTP/1.1 500 FORBIDDEN');
         die;
      }

}

if( $form_num == 6){

     if(!wp_verify_nonce($_POST['amp_optin_nonce'],'amp_optin_nonce') && ((!strpos($_SERVER['HTTP_ORIGIN'], 'cdn.ampproject.org')) && (!strpos($_SERVER['HTTP_ORIGIN'], 'amp.cloudflare.com')) && (!strpos($_SERVER['HTTP_REFERER'], 'google.com/amp/s/')) ) ){
            header('HTTP/1.1 500 FORBIDDEN');
            echo wp_json_encode( 'Sorry, your nonce did not verify.' );
            die;
    }
        $amp_sendy_status        = get_option( 'amp_optin_sendy_key_status');
        if($amp_sendy_status == false){
                 header('HTTP/1.1 500 FORBIDDEN');
                echo wp_json_encode( 'Sendy API key is Invalid or Not connected in AMP Optin settings.' );
                die;
        }

           $sendy_details = get_option( 'amp_optin_sendy_api_details');
            $amp_sendy_apikey = isset($sendy_details['apiKey']) ? $sendy_details['apiKey'] : '';
            $amp_sendy_url = isset($sendy_details['sendy_url']) ? $sendy_details['sendy_url'] : '';
              $_POST['api_key'] = $amp_sendy_apikey;
              $_POST['boolean'] = 'true';
              $sendy_data = http_build_query($_POST);
                
              $sendy_curl = $amp_sendy_url.'subscribe';
              $response = wp_remote_post(
                            esc_url_raw($sendy_curl),
                            array(
                                'body' => $sendy_data
                            )
                        );

             // print_r($response);die;

      $response_code = wp_remote_retrieve_response_code($response);

      if($response_code == 200){
          $redirectCheck = get_post_meta($form_id, 'amp_optin_checkbox_redirect', true);
          if($redirectCheck == true){
            $redirectUrl = get_post_meta( $form_id, 'ampforwp_optin_redirection', true );
            
          } 
          $siteUrl = parse_url(
                      get_site_url()
                    );
          $amp_opt_in_Site = $siteUrl['scheme'] . '://' . $siteUrl['host'];
          if( empty($redirectUrl)){
              header('AMP-Access-Control-Allow-Source-Origin: '.esc_url_raw($amp_opt_in_Site).'');
              # form was not working through cdn.
              header('Access-Control-Allow-Origin: ' .$_SERVER['HTTP_ORIGIN']);
              header('Access-Control-Allow-Credentials: true');
          }
          else{
                header('AMP-Access-Control-Allow-Source-Origin: '.$amp_opt_in_Site.'');
                header("AMP-Redirect-To: ".esc_url_raw($redirectUrl));
                header("Access-Control-Expose-Headers: AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin"); 
          }
          echo json_encode(array('successmsg'=>'Form submit successfull.'));
          die;
          
      }else{
         header('HTTP/1.1 500 FORBIDDEN');
         echo wp_json_encode( 'response code is not 200' );
         die;
      }
}


// constant contact code starts here.
if( $form_num == 21){
     require_once dirname( __FILE__ ).'/include/constant-contact/constant-contact.php';
}
//constant contact end here

// mailpoet3
if( $form_num == 23){
  require_once dirname( __FILE__ ).'/include/mailpoet3/mailpoet3.php';  
}
      switch ($form_num) {
          case '1':
                    $form_url = get_post_meta( $form_id, 'amp_optin_form_1_API_URL', true ); 
                    $form_url = str_replace('subscribe/post?', 'subscribe/post-json?', $form_url);
                     break;
          case '2':
                    $form_url = "https://app.getresponse.com/add_subscriber.html"; 
                    break;
          // case '3':
          //           $form_3_feild_one  = get_post_meta( $form_id, 'amp_optin_form_3_feild_one', true );
          //           $form_3_feild_two  = get_post_meta( $form_id, 'amp_optin_form_3_feild_two', true );

          //           $form_url = "https://". $form_3_feild_two .".createsend.com/t/d/s/". $form_3_feild_one .""; 
          //           break;
          case '4':
                    $form_url = get_post_meta( $form_id, 'amp_optin_form_4_feild_one', true );
                    break;
/*          case '6':
                    $form_url = get_post_meta( $form_id, 'amp_optin_form_6_URL', true );
                      break;*/
          case '7': 
                    $list_id_form_7  = get_post_meta( $form_id, 'amp_optin_form_7_LIST_ID', true );
                    $form_url = "https://app.convertkit.com/forms/". $list_id_form_7 ."/subscriptions";
                      break;
          case '9':
                    $form_url = "https://www.rdstation.com.br/api/1.2/conversions";
                      break;                         
          case '13':
                    $form_url = get_post_meta($form_id, 'amp_optin_form_13_mautic_url',true );
                      break;
          case '15':
                    $form_url ="https://forms.ontraport.com/v2.4/form_processor.php?";
                      break;
         case '17':
                    $form_url = get_post_meta( $form_id, 'amp_optin_form_17_form_URL', true ); 
                      break;
         case '19':
                    $form_url = get_post_meta( $form_id, 'amp_optin_form_19_form_action', true );
                      break; 
          case '20':
                     $form_url = get_post_meta( $form_id, 'amp_optin_form_20_form_url', true );
                      break;
          case '24':
                     $form_url ="//sg-autorepondeur.com/public/subscribe.php";
                      break;
          case '26':
                    $form_url = get_post_meta( $form_id, 'amp_optin_form_26_API_URL', true ); 
                     break;
         case '27':
                    $form_url = get_post_meta( $form_id, 'amp_optin_form_27_API_URL', true ); 
                     break;
         case '29':
                    $form_url = get_post_meta( $form_id, 'amp_optin_form_29_API_URL', true ); 
                     break;
                     
          
      }
      
$cookie="sdcookie.txt";
$curl = curl_init();
$curlopt_url = '';
if($form_num == '7'){
    $curlopt_url = $form_url.'?'.$key;
}
else{ 
    $curlopt_url = $form_url;
}

$response = wp_remote_post(
              $curlopt_url,
              array(
                  'body' => $key
              )
);
// $curl_array = array( 
//                 CURLOPT_RETURNTRANSFER => true,
//                 CURLOPT_URL => $curlopt_url,
//                 CURLOPT_HEADER => 0,
//                 CURLOPT_ENCODING => "",
//                 CURLOPT_SSL_VERIFYPEER => false,
//                 CURLOPT_COOKIEJAR => $cookie,
//                 CURLOPT_COOKIEFILE => $cookie,
//                 CURLOPT_MAXREDIRS => 10,
//                 CURLOPT_TIMEOUT => 30,
//                 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
//                 CURLOPT_FOLLOWLOCATION => 1,
//                 CURLOPT_CUSTOMREQUEST => "POST",
//                 CURLOPT_POSTFIELDS => $key,
//                 CURLOPT_HTTPHEADER => array(
//                   "cache-control: no-cache",
//                   "content-type: application/x-www-form-urlencoded",
//                 ),
//               ); 
//   curl_setopt_array($curl,$curl_array);
//   $response = curl_exec($curl);
//   $err = curl_error($curl);
//   $redirectURL = curl_getinfo($curl );
//   curl_close($curl);  
//   $amp_optin_Site = '';
//   if ($err) {
//     echo "cURL Error #:" . $err;
//   } else {
//     $siteUrl = parse_url(
//       get_site_url()
//     );
//     $amp_optin_Site = $siteUrl['scheme'] . '://' . $siteUrl['host'];
//   }
//   if( is_array($redirectURL) ) {
//     $redirect_check = get_post_meta($form_id, 'amp_optin_checkbox_redirect', true);
//     if($redirect_check == true){
//       $redirect_url = get_post_meta( $form_id, 'ampforwp_optin_redirection', true );
//     } 
//      if( empty($redirect_url))
//         {
//             header('AMP-Access-Control-Allow-Source-Origin: '.$amp_optin_Site.'');
//         }
//         else
//         {
//           header('AMP-Access-Control-Allow-Source-Origin: '.$amp_optin_Site.'');
//           header("AMP-Redirect-To: ".$redirect_url);
//           header("Access-Control-Expose-Headers: AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin"); 
//         }
//       echo json_encode(array('successmsg'=>$_POST['name'].'Optin Form submit successfull.'));
//       die();
//   } 
//   die;

//checking nonce.
  if(!wp_verify_nonce($_POST['amp_optin_nonce'],'amp_optin_nonce') && ((!strpos($_SERVER['HTTP_ORIGIN'], 'cdn.ampproject.org')) && (!strpos($_SERVER['HTTP_ORIGIN'], 'amp.cloudflare.com')) && (!strpos($_SERVER['HTTP_REFERER'], 'google.com/amp/s/')) ) ){
          header('HTTP/1.1 500 FORBIDDEN');
          echo wp_json_encode( 'Sorry, your nonce did not verify.' );
          die;
  }

    if ( is_wp_error( $response ) ) {
      wp_remote_retrieve_body( $response );
       echo json_encode(array('error_message'=>$response ));
    }else{

        $redirect_check = get_post_meta($form_id, 'amp_optin_checkbox_redirect', true);
        if($redirect_check == true){
          $redirect_url = get_post_meta( $form_id, 'ampforwp_optin_redirection', true );
        } 
        if( empty($redirect_url)){
                header('AMP-Access-Control-Allow-Source-Origin: '.$amp_optin_Site.'');
              // form was not working through cdn.
                header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
                header('Access-Control-Allow-Credentials: true');
        }
        else{
              header('AMP-Access-Control-Allow-Source-Origin: '.$amp_optin_Site.'');
              header("AMP-Redirect-To: ".$redirect_url);
              header("Access-Control-Expose-Headers: AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin"); 
        }
        echo json_encode(array('successmsg'=>'Form submit successfull.'));
        die();
    }  
}

add_action('wp_loaded','ampforwp_optin_loader_with_wpml');
function ampforwp_optin_loader_with_wpml(){
  if(class_exists('SitePress')){    
add_filter('amp_optin_form_output_content','ampforwp_show_or_hide_language_based',10,2);
  }
}

// code to exclude optin based on language selection
function ampforwp_show_or_hide_language_based ($output,$attr_id) {
  global $post;
  if ( defined( 'ICL_LANGUAGE_CODE' ) ) {
    $current_lang = ICL_LANGUAGE_CODE;
  }
  $exclude_optin_on_languages =  get_post_meta( $attr_id, 'ampforwp_exclude_optin_box_for_spec_langs', true );  
  $excluder = explode(',', $exclude_optin_on_languages);
  if ( in_array ( $current_lang, $excluder ) ) {
    $output = '';
  }
  return $output;
}


function ampforwp_get_all_lang_categories ($output,$id) {
  global $post, $sitepress;  
  remove_filter('terms_clauses', array($sitepress, 'terms_clauses'), 10, 3);
  $final_output = array();
  $categories = get_categories(array('search'=> esc_html($_GET['q']),'number'=>500,'hide_empty' => 0));
  add_filter('terms_clauses', array($sitepress, 'terms_clauses'), 11, 4);
  $categories_array = array();
  if ( $categories ) :
    foreach ($categories as $cat ) {
      $final_output[$cat->cat_ID] = $cat->name;
    }
  endif;
  //wp_send_json( $final_output );
  return $final_output;
}


function ampforwp_get_all_languages_data($lang='en'){
    global $wpdb;
    $lang_data = array();
    $languages = $wpdb->get_results( 
        $wpdb->prepare( 
            "SELECT code, english_name, active, tag, name
            FROM {$wpdb->prefix}icl_languages lang
            INNER JOIN {$wpdb->prefix}icl_languages_translations trans
            ON lang.code = trans.language_code
            AND trans.display_language_code=%s"
            ,
            $lang
            )
    );
    foreach($languages as $l){
        $lang_data[$l->code] = array(
            'english_name' => $l->english_name,
            'active' => $l->active,
            'tag' => $l->tag,
            'name' => $l->name,
        );
    }
    return $lang_data;
}

if(class_exists('MC4WP_Form_Output_Manager')){
add_action('pre_amp_render_post','removal');
}
function removal(){
$obj = new MC4WP_Form_Output_Manager();
//const SHORTCODE = 'mc4wp_form';
remove_shortcode( 'mc4wp_form', array( $obj, 'shortcode' ) );
add_shortcode( 'mc4wp_form','shortcode_amp');
}

 function shortcode_amp( $attributes = array(), $content = '' ) {
  $obj2 = new MC4WP_Form_Output_Manager();
    $default_attributes = array(
      'id'            => '',
      'lists'         => '',
      'email_type'    => '',
      'element_id'    => '',
      'element_class' => '',
    );

    $attributes = shortcode_atts(
      $default_attributes,
      $attributes,
      'mc4wp_form'
    );

    $config = array(
      'element_id'    => $attributes['element_id'],
      'lists'         => $attributes['lists'],
      'email_type'    => $attributes['email_type'],
      'element_class' => $attributes['element_class'],
    );

    return output_form_amp( $attributes['id'], $config, false );
  }


  function output_form_amp( $id = 0, $config = array(), $echo = true ) {
    //echo "string";die;
  $obj3 = new MC4WP_Form_Output_Manager();
    try {
      $form = mc4wp_get_form( $id );
    } catch ( Exception $e ) {
      if ( current_user_can( 'manage_options' ) ) {
        return sprintf( '<strong>Mailchimp for WordPress error:</strong> %s', $e->getMessage() );
      }

      return '';
    }

    $obj3->count++;

    // set a default element_id if none is given
    if ( empty( $config['element_id'] ) ) {
      $config['element_id'] = 'mc4wp-form-' . $obj3->count;
    }

    $form_html = $form->get_html( $config['element_id'], $config );

    try {
      // start new output buffer
      ob_start();

      /**
       * Runs just before a form element is outputted.
       *
       * @since 3.0
       *
       * @param MC4WP_Form $form
       */
      do_action( 'mc4wp_output_form', $form );

      // output the form (in output buffer)
      echo $form_html;

      // grab all contents in current output buffer & then clean + end it.
      $html = ob_get_clean();
    } catch ( Error $e ) {
      $html = $form_html;
    }

    // echo content if necessary
    if ( $echo ) {
      echo $html;
    }

    return $html;
  }
  
  if(is_plugin_active('mailchimp-for-wp/mailchimp-for-wp.php') || function_exists('MC4WP_Form_Manager') ){

add_filter('ampforwp_modify_the_content', 'AMPforWP_content_for_MC4WP' );
function AMPforWP_content_for_MC4WP($content){
  $do_shortcode_for_MC4WP =  do_shortcode( '[mc4wp_form id="(.*?)"]' );
  $content = preg_replace('/\[mc4wp_form id="(.*?)"\]/', ''.$do_shortcode_for_MC4WP.''  , $content);
  $content = preg_replace('/mc4wp-form-fields/', 'mc4wp-form mc4wp-form mc4wp-form-basic', $content);
  $content = preg_replace('/Leave this field empty if you\'re human:/', '', $content);
  return $content;
}
}
if(is_plugin_active('mailchimp-for-wp/mailchimp-for-wp.php') || function_exists('MC4WP_Form_Manager') ){
add_action('amp_post_template_css','ampforwp_css_forMC4WP');

function ampforwp_css_forMC4WP(){

   $srcs = array();
   $plugins_url = plugins_url();   
   $srcs[] = $plugins_url.'/mailchimp-for-wp/assets/css/form-basic.min.css';
   //print_r($srcs); die;
   foreach ($srcs as $key => $urlValue) {
      $cssData = amp_optin_remote_content($urlValue);
      $cssData = preg_replace("/\/\*(.*?)\*\//si", "", $cssData);
      $cssData = str_replace('img', 'amp-img', $cssData);
      echo $cssData;
    }
  }
}

function amp_optin_remote_content($src){
    if($src){
      $arg = array( "sslverify" => false, "timeout" => 60 ) ;
      $response = wp_remote_get( $src, $arg );
          if ( wp_remote_retrieve_response_code($response) == 200 && is_array( $response ) ) {
            $header = wp_remote_retrieve_headers($response); // array of http header lines
            $contentData =  wp_remote_retrieve_body($response); // use the content
            return $contentData;
          }else{
        $contentData = file_get_contents( $src );
        if(! $contentData ){
          $data = str_replace(get_site_url(), '', $src);//content_url()
          $data = getcwd().$data;
          if(file_exists($data)){
            $contentData = file_get_contents($data);
          }
        }
        return $contentData;
      }

    }
      return '';
}


// CODE TO ADD LICENSE ACTIVATION FATURE FOR NON AMPFORWP
if(!defined('AMPFORWP_PLUGIN_DIR')){
  $redux_builder_amp = get_option('redux_builder_amp',true);
  add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'amp_optin_up_ext_plugin_activation_link' );
  function amp_optin_up_ext_plugin_activation_link( $links ) {
      $_link = '<a href="admin.php?page=amp-optin-license-activation" target="_blank">License Activation</a>';
      $links[] = $_link;
      return $links;
  }
  if(file_exists(ABSPATH . 'wp-admin/includes/plugin.php')){
    include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
    }
  add_action('init', 'amp_optin_set_extension_license_key_page');
  function amp_optin_set_extension_license_key_page(){
    require_once(dirname( __FILE__ ) . '/license/license-activation.php');
    if(function_exists('add_submenu_page')){
      add_submenu_page(
          '',
          'License Activation',
          'License Activation',
          'manage_options',
          'amp-optin-license-activation',
          'amp_optin_license_activation'
      );
      }
  }
  function amp_optin_license_activation(){
    require_once(dirname( __FILE__ ) . '/license/license-activation-view.php');
  }
}



//Adding EDD_SL_Plugin_Updater file for update
require_once dirname( __FILE__ ) . '/updater/EDD_SL_Plugin_Updater.php';     
function ampforwp_optin_updater(){
   // retrieve our license key from the DB
  //$license_key = trim( get_option( 'amp_ads_license_key' ) );
        $selectedOption = get_option('redux_builder_amp',true);
        $license_key = '';//trim( get_option( 'amp_ads_license_key' ) );
        $pluginItemName = '';
        $pluginItemStoreUrl = '';
        $pluginstatus = '';
    if( isset($selectedOption['amp-license']) && "" != $selectedOption['amp-license'] && isset($selectedOption['amp-license'][AMP_OPTIN_ITEM_FOLDER_NAME])){
       $pluginsDetail = $selectedOption['amp-license'][AMP_OPTIN_ITEM_FOLDER_NAME];
       $license_key = $pluginsDetail['license'];
       //$pluginItemName = $pluginsDetail['item_name'];
       $pluginItemStoreUrl = $pluginsDetail['store_url'];
       $pluginstatus = $pluginsDetail['status'];

} 
// setup the updater
  $edd_updater = new Amp_Optin_Data_EDD_SL_Plugin_Updater( AMP_OPTIN_DATA_STORE_URL, __FILE__, array(
      'version'   => AMP_OPTIN_DATA_VERSION,      // current version number
      'license'   => $license_key,             // license key (used get_option above to retrieve from DB)
      'license_status'=>$pluginstatus,
      'item_name' => AMP_OPTIN_DATA_ITEM_NAME,      // name of this plugin
      'author'  => 'Mohammed Kaludi',           // author of this plugin
      'beta'    => false,
    )
  );      
}
add_action( 'admin_init', 'ampforwp_optin_updater', 0);
// Notice to enter license key once activate the plugin
$path = plugin_basename( __FILE__ );
  add_action("after_plugin_row_{$path}", function( $plugin_file, $plugin_data, $status ) {
    global $redux_builder_amp;
    if(! defined('AMP_OPTIN_ITEM_FOLDER_NAME')){
    $folderName = basename(__DIR__);
            define( 'AMP_OPTIN_ITEM_FOLDER_NAME', $folderName );
        }
        $pluginstatus= '';
        if(isset($redux_builder_amp['amp-license'][AMP_OPTIN_ITEM_FOLDER_NAME])){
        $pluginsDetail = $redux_builder_amp['amp-license'][AMP_OPTIN_ITEM_FOLDER_NAME];
        $pluginstatus = $pluginsDetail['status'];
      }

       $activation_link = 'amp_options&tabid=opt-go-premium';
          if(!defined('AMPFORWP_PLUGIN_DIR')){
            $activation_link = 'amp-optin-license-activation';
          }
        if(empty($redux_builder_amp['amp-license'][AMP_OPTIN_ITEM_FOLDER_NAME]['license'])){
      echo "<tr class='active'><td>&nbsp;</td><td colspan='2'><a href='".esc_url(  self_admin_url( 'admin.php?page='.$activation_link )  )."'>Please enter the license key</a> to get the <strong>latest features</strong> and <strong>stable updates</strong></td></tr>";
         }elseif($pluginstatus=="valid"){
          $update_cache = get_site_transient( 'update_plugins' );
            $update_cache = is_object( $update_cache ) ? $update_cache : new stdClass();
            if(isset($update_cache->response[ AMP_OPTIN_ITEM_FOLDER_NAME ]) 
                && empty($update_cache->response[ AMP_OPTIN_ITEM_FOLDER_NAME ]->download_link) 
             ){
               unset($update_cache->response[ AMP_OPTIN_ITEM_FOLDER_NAME ]);
            set_site_transient( 'update_plugins', $update_cache );
            }
            
        }
    }, 10, 3 );

//set cookies Submission
add_action('wp_ajax_amp_optin_disable_modal_form','amp_optin_disable_modal_form');
add_action('wp_ajax_nopriv_amp_optin_disable_modal_form','amp_optin_disable_modal_form');

function amp_optin_disable_modal_form(){
  $id = $_POST['dismiss_hidden'];
  $modal_timer =  get_post_meta( $id, 'ampforwp_optin_modal_button_timer', true );  
  $delay_time = $modal_timer * 3600;
  setcookie('enable_modalform','true', time() + $delay_time, "/");
  $cur_url = $site_url = $site_host = $amp_site = '';
  $cur_url  = wp_get_referer();
  $site_url     = parse_url( get_site_url() );
  $site_host    = $site_url['host'];
  $amp_site     = $site_url['scheme'] . '://' . $site_url['host'];
  header("AMP-Access-Control-Allow-Source-Origin: ".esc_url($amp_site));
  die();
}

Youez - 2016 - github.com/yon3zu
LinuXploit