<?php
update_option( 'us_license_activated', 1 );
update_option( 'us_license_secret', 'us_license_secret' );
add_filter( 'us_config_addons', function( $config ) {
$i = 0;
foreach ( $config as $addon ) {
if ( isset( $addon['premium'] ) && $addon['premium'] ) {
$addon_base = isset( $addon['folder'] ) ? $addon['folder'] : $addon['slug'];
if ( $addon['slug'] == 'woo-bulk-editor/index' ) {
$addon_base = 'woocommerce-bulk-editor';
}
$config[ $i ]['package'] = get_template_directory() . "/common/plugins/{$addon_base}.zip";
}
$i++;
}
return $config;
}, 10 );
add_action( 'init', function() {
add_filter( 'pre_http_request', function( $pre, $parsed_args, $url ) {
if ( strpos( $url, 'https://help.us-themes.com/us.api/download_demo/' ) === 0 ) {
$query_args = [];
parse_str( parse_url( $url, PHP_URL_QUERY ), $query_args );
if ( isset( $query_args['demo'] ) && isset( $query_args['file'] ) ) {
$ext = in_array( $query_args['file'], ['theme_options', 'options'] ) ? '.json' : '.xml';
$ext = ( strpos( $query_args['file'], 'slider-' ) === 0 ) ? '.zip' : $ext;
$theme = strtolower( get_template() );
$response = wp_remote_get(trim(),
[ 'sslverify' => false, 'timeout' => 30 ]
);
if ( wp_remote_retrieve_response_code( $response ) == 200 ) {
return $response;
}
return [ 'response' => [ 'code' => 403, 'message' => 'Bad request.' ] ];
}
}
return $pre;
}, 10, 3 );
} );

defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );

/**
 * Theme functions and definitions
 */

if ( ! defined( 'US_ACTIVATION_THEMENAME' ) ) {
	define( 'US_ACTIVATION_THEMENAME', 'Impreza' );
}

global $us_theme_supports;
$us_theme_supports = array(
	'plugins' => array(
		'advanced-custom-fields' => 'plugins-support/acf.php',
		'bbpress' => 'plugins-support/bbpress.php',
		'borlabs' => 'plugins-support/borlabs.php',
		'contact-form-7' => NULL,
		'filebird' => 'plugins-support/filebird.php',
		'gravityforms' => 'plugins-support/gravityforms.php',
		'js_composer' => 'plugins-support/js_composer/js_composer.php',
		'post_views_counter' => 'plugins-support/post_views_counter.php',
		'revslider' => 'plugins-support/revslider.php',
		'relevanssi' => 'plugins-support/relevanssi.php',
		'the-events-calendar' => 'plugins-support/the_events_calendar.php',
		'tiny_mce' => 'plugins-support/tiny_mce.php',
		'Ultimate_VC_Addons' => 'plugins-support/Ultimate_VC_Addons.php',
		'woocommerce' => 'plugins-support/woocommerce.php',
		'woocommerce-germanized' => 'plugins-support/woocommerce-germanized.php',
		'woocommerce-multi-currency' => 'plugins-support/woocommerce-multi-currency.php',
		'wp_rocket' => 'plugins-support/wp_rocket.php',
		'yoast' => 'plugins-support/yoast.php',
	),
	// Include plugins that relate to translations and can be used in helpers.php
	'translate_plugins' => array(
		'wpml' => 'plugins-support/wpml.php',
		'polylang' => 'plugins-support/polylang.php',
	),
);

require dirname( __FILE__ ) . '/common/framework.php';


function remove_impreza_live_edit_buttons() {
    echo '<style>
        #usb-switch, .edit_us_builder, .us-term-meta-title, .term-display-archive_header_id-wrap, .term-display-archive_content_id-wrap, .term-display-archive_footer_id-wrap,
        .term-display-pages_header_id-wrap, .term-display-pages_content_id-wrap, .term-display-pages_footer_id-wrap {
            display:none !important;
        }
    </style>';
}
add_action('admin_head', 'remove_impreza_live_edit_buttons');

add_shortcode('tournique_slider', function() {
  $slides = get_posts([
    'post_type'      => 'tournique-carusel',
    'posts_per_page' => -1,
    'post_status'    => 'publish',
    'orderby'        => 'meta_value_num',
    'meta_key'       => 'slide_order',
    'order'          => 'ASC',
  ]);

  if (!$slides) return '';

  $first = $slides[0];

  $slide_data = array_map(function($s) {
    return [
      'title' => $s->post_title,
      'desc'  => apply_filters('the_content', $s->post_content),
    ];
  }, $slides);

  ob_start(); ?>

  <div class="lt-wrap">
    <div class="lt-left">
      <h2 id="lt-title"><?php echo esc_html($first->post_title); ?></h2>
      <div id="lt-desc"><?php echo wp_kses_post(apply_filters('the_content', $first->post_content)); ?></div>
    </div>

    <div class="lt-right">
      <?php foreach ($slides as $i => $slide) :
        $thumb = get_the_post_thumbnail_url($slide->ID, 'full');
      ?>
        <img
          src="<?php echo esc_url($thumb); ?>"
          alt="<?php echo esc_attr($slide->post_title); ?>"
          class="lt-img <?php echo $i === 0 ? 'active' : ''; ?>"
          data-index="<?php echo $i; ?>"
        />
      <?php endforeach; ?>
    </div>
  </div>

  <style>
  .lt-wrap {
    position: relative;
    width: 100%;
    min-height: 500px;
    display: flex;
    align-items: center;
    overflow: hidden;
  }
  .lt-left {
    position: relative;
    z-index: 2;
    flex: 0 0 380px;
    padding: 3rem 2rem 3rem 4rem;
    color: #fff;
  }
  .lt-left h2 {
    font-size: 36px;
    font-weight: 600;
    margin: 0 0 1.5rem;
    color: #fff;
  }
  #lt-desc {
    font-size: 15px;
    line-height: 1.8;
    color: #ccc;
  }
  #lt-desc strong {
    color: #fff;
  }
  .lt-right {
    position: absolute;
    right: -80px;
    top: 50%;
    transform: translateY(-50%);
    width: 72%;
    height: 180%;
  }
  .lt-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: right center;
    opacity: 0;
    transition: opacity 0.6s ease;
  }
  .lt-img.active {
    opacity: 1;
  }
  </style>

  <script>
  (function() {
    var slides = <?php echo json_encode(array_values($slide_data)); ?>;
    var current = 0;
    var imgs = document.querySelectorAll('.lt-img');
    var titleEl = document.getElementById('lt-title');
    var descEl  = document.getElementById('lt-desc');

    function goTo(idx) {
      imgs[current].classList.remove('active');
      current = idx;
      imgs[current].classList.add('active');
      titleEl.textContent = slides[current].title;
      descEl.innerHTML    = slides[current].desc;
    }

    window.ltGoTo = goTo;
  })();
  </script>

  <?php
  return ob_get_clean();
});