HEX
Server: LiteSpeed
System: Linux premium221.web-hosting.com 4.18.0-553.45.1.lve.el8.x86_64 #1 SMP Wed Mar 26 12:08:09 UTC 2025 x86_64
User: madepabj (2566)
PHP: 8.3.26
Disabled: NONE
Upload Files
File: /home/madepabj/hc-cosmetics.com/wp-content/themes/dbea/framework/sns-functions.php
<?php
/*
 * Get theme option
 */
function dbea_themeoption($option, $default = '', $key = ''){
	global $dbea_opt;
	$value = '';
	// Get config via theme option
	if($key !== ''){
		if ( isset($dbea_opt[$option][$key]) && $dbea_opt[$option][$key] ) $value = $dbea_opt[$option][$key];
	}else{
		if ( isset($dbea_opt[$option]) && $dbea_opt[$option] ) $value = $dbea_opt[$option];
	}
	// Get config via cookie
	if ( isset($_COOKIE['dbea_'.$option]) && $_COOKIE['dbea_'.$option] != '' ) {
		$value = $_COOKIE['dbea_'.$option];
	}
	// Return value when exists ReduxFramework
	if($value || class_exists( 'ReduxFramework' ))
		return $value; 
	// Return default value
	return $default;
}
/*
 * Set theme option
 */
function dbea_set_themeoption($key, $value){
	global $dbea_opt;
	if ( $key != '' && $value != '' )
		$dbea_opt[$key] = $value;
}
/*
 * Get theme & post/page option
 */
function dbea_getoption($option, $default = '', $type = null){
	global $post;
    $value = ''; $value1 = '';
    $value = dbea_themeoption($option, $default); 
    if ( $type == 'image' && is_array($value) ){
    	if ( $value['url'] == '' ) {
    		$value = $default;
    	}else{
    		$value = $value['url'];
    	}
    }
    // Get config via page/product config
    if ( function_exists('rwmb_meta') ){
    	// Just page/product have rwmb_meta 
    	if( class_exists('WooCommerce') && is_woocommerce() || is_page() ){
    		$value1 = rwmb_meta('dbea_'.$option);
	    	if ( ( !is_array($value1) && trim($value1) == '' ) || ( is_array($value1) && empty($value1) ) ) {
	    		if ( class_exists('WooCommerce') ) {
		    		if ( is_product() ){
		    			$value1 = rwmb_meta('dbea_'.$option, array(), $post->ID);
		    		}elseif( is_shop() ) { // for shop page
		    			$value1 = rwmb_meta('dbea_'.$option, array(), get_option('woocommerce_shop_page_id'));
		    		}
		    	}
	    	}
    		if ( is_array($value1) && !empty($value1) && $type == 'image' ){
		    	foreach ( $value1 as $img ) {
		    		$value1 = $img['full_url'];
		    	}
		    }
    	}
	}
	if ( ( !is_array($value1) && trim($value1) == '' ) || ( is_array($value1) && empty($value1) ) ) {
		if ( $value != '' ) {
			return $value;
		}else{
			return $default;
		}
	}
    if ( $value1 != '' ) return $value1;
    if ( $value != '' ) return $value;
	return $default;
}
/*
 * Get theme & post/page option
 */
function dbea_woo_cat_option($option, $default = '', $type = null){
    $value = ''; $value1 = '';
    $value = dbea_themeoption($option, $default);
    if ( $type == 'image' ){
    	if ( isset($value['url']) ){
    		if ($value['url'] == '' ) {
	    		$value = $default;
	    	}else{
	    		$value = $value['url'];
	    	}
	    }
    }
    if( class_exists('WooCommerce') && is_woocommerce() && is_product_category() ){
        $cate = get_queried_object();
        if ( is_object($cate) && isset($cate->term_id) ) { 
        	$value1 = dbea_get_term_byid($cate->term_id, 'dbea_'.$option, '');
    	}
    }
    if ( trim($value1) == '' ) {
		if ( $value != '' ) {
			return $value;
		}else{
			return $default;
		}
	}
    if ( $value1 != '' ) return $value1;
    if ( $value != '' ) return $value;
	return $default;
}
/*
 * Get meta box data
 */
function dbea_metabox($field_id, $args = array()){
	if( !function_exists('rwmb_meta') ){
		return '';
	}
	$field_id = 'dbea_'.$field_id;
	if( function_exists('is_shop') && is_shop() ) {
		return rwmb_meta($field_id, $args, get_option('woocommerce_shop_page_id'));
	}
	return rwmb_meta($field_id, $args);
}
function dbea_get_term_byid($term_id, $key, $default = ''){
	$value = get_term_meta( $term_id, $key );
    $value = ( is_array($value) && isset($value[0]) && $value[0] != '' ) ? $value[0] : $default;
    return $value;
}
/*
 * Css file
 */
function dbea_css_file(){
	$compile_obj = new DBeaCompileSass();
	$theme_color = dbea_getoption('theme_color', '#ec2d9e');
	// Get page meta data
	if ( is_page() && function_exists('rwmb_meta') && rwmb_meta('dbea_page_themecolor') == 1) {
		$theme_color = rwmb_meta('dbea_theme_color') != '' ? rwmb_meta('dbea_theme_color') : $theme_color;
	}
	$body_color = dbea_themeoption('body_font', '#555555', 'color');
	$scss_compile = dbea_themeoption('advance_scss_compile', '1');
	$scss_format = dbea_themeoption('advance_scss_format', 'scss_formatter_compressed');
	// Compile scss and get css file name
	$css_file = $compile_obj->dbea_getstyle(
		$scss_compile,
		array('dir' => DBEA_THEME_DIR . '/assets/scss/', 'name' => 'theme'),
		array('dir' => DBEA_THEME_DIR . '/assets/css/', 'name' => 'theme'),
		$scss_format,
		array(
			'$color1' => $theme_color,
			'$color' => $body_color,
		)
	);
	return $css_file;
}
/**
 * Layout type
**/
function dbea_layouttype($option='layouttype', $default=''){
	$layouttype = dbea_getoption($option, $default);
	if( class_exists('WooCommerce') && is_woocommerce() ){
		if( is_product_category() ){
			$cate = get_queried_object();
			$layouttype = dbea_get_term_byid($cate->term_id, 'dbea_product_cat_layout', 'l-m');
		}
		if ( trim($layouttype) == '' ) $layouttype = 'l-m';
		if( is_product_tag() ){
			$layouttype = 'l-m';
		}
		if( is_product() ){ 
			if ( dbea_getoption('single_product_sidebar') == 1 ) {
				$layouttype = 'm-r';
			}else{
				$layouttype = 'm';
			}
		}
	}
	if ( is_404() ) $layouttype = 'm';
	if ( trim($layouttype) == '' ) $layouttype = 'm-r';
	return $layouttype;
}
function dbea_get_sb($sidebar='rightsidebar'){
	$rsb_name = '';
	if( class_exists('WooCommerce') && is_woocommerce() ){
    	if( is_active_sidebar( 'woo-sidebar' ) ) {
        	$rsb_name = 'woo-sidebar'; 
        }else{
        	$rsb_name = 'blog-sidebar';
        }
    }else{
        if( dbea_getoption($sidebar) != '' ) {
        	$rsb_name = dbea_getoption($sidebar); 
        }else{
        	$rsb_name = 'blog-sidebar';
        }
    }
    if ( is_active_sidebar($rsb_name) ){
    	return $rsb_name;
    }
    return '';
}
/**
 * Left Column
**/
function dbea_leftcol(){
	$layouttype = dbea_layouttype('layouttype', 'm-r');
	if ( $layouttype == '' || $layouttype == 'm-r' || $layouttype == 'm' ) 
		return '';
	$left_sb = dbea_get_sb('leftsidebar');
	if ( $left_sb == '' ) return '';
	?>
	<div class="col-md-3 sns-left">
		<?php
		dynamic_sidebar($left_sb);
	    ?>
	</div>
	<?php
 }
/**
 * Right Column
**/
 function dbea_rightcol(){
 	$layouttype = dbea_layouttype('layouttype', 'm-r');
	if ( $layouttype == '' || $layouttype == 'l-m' || $layouttype == 'm' ) 
		return '';
	$right_sb = dbea_get_sb('rightsidebar');
	if ( $right_sb == '' ) return '';
	?>
	<div class="col-md-3 sns-right">
		<?php
		dynamic_sidebar($right_sb);
	    ?>
	</div>
	<?php
 }
/**
 * Main class
**/
function dbea_maincolclass(){
	$layouttype = dbea_layouttype('layouttype', 'm-r');
	$mclass = 'sns-main';
	if ( $layouttype == 'l-m' ) {
		if ( '' == dbea_get_sb('leftsidebar') ){
			$mclass .= ' col-md-12 main-left';
		}else{
			$mclass .= ' col-md-9 main-left';
		}
	}elseif( $layouttype == 'm-r' ){
		if ( '' == dbea_get_sb('rightsidebar') ){
			$mclass .= ' col-md-12 main-right';
		}else{
			$mclass .= ' col-md-9 main-right';
		}
	}elseif ( $layouttype == 'l-m-r' ) {
		if ( '' == dbea_get_sb('leftsidebar') && '' == dbea_get_sb('rightsidebar') ){
			$mclass .= ' col-md-12 main-center';
		}elseif( '' != dbea_get_sb('leftsidebar') && '' != dbea_get_sb('rightsidebar') ){
			$mclass .= ' col-md-6 main-center';
		}else{
			$mclass .= ' col-md-9 main-center';
		}
	}else{
		$mclass .= ' col-md-12';
	}
	return $mclass;
}
/**
 * Return number of published sticky posts
**/
function dbea_get_sticky_posts_count(){
	global $wpdb;
	$sticky_posts = array_map('absint', (array)get_option('sticky_posts') );
	return count($sticky_posts) > 0 ? $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( 1 ) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' AND ID IN (".implode(',', $sticky_posts).")" ) ) : 0;
}

/**
 * Display Ajax loading
 */
function dbea_paging_nav_ajax( $content_div = '#snsmain', $template = '' ){
	// Don't print empty markup if there is only one page.
	if( $GLOBALS['wp_query']->max_num_pages < 2 ){
		return;
	}
	$label1 = esc_html__('Load more', 'dbea');
	$label2 = esc_html__('Loading', 'dbea');
	if ( dbea_themeoption('pagination') == 'ajax2' ){
		$class = 'load-more auto-load';
		$label1 = $label2;
	}else{
		$class = 'load-more click-load';
	}
	?>
	<nav class="navigation-ajax" role="navigation">
		<a href="<?php echo esc_url('javascript:void(0)'); ?>" 
			data-target="<?php echo esc_attr($content_div);?>" 
			data-template="<?php echo esc_attr($template); ?>" 
			data-numload="<?php echo esc_attr(dbea_themeoption('masonry_numload', 3))?>" 
			data-numexcerpt="<?php echo esc_attr(dbea_themeoption('excerpt_length', 25))?>" 
			data-label="<?php echo esc_attr($label1); ?>"
			data-labelload="<?php echo esc_attr($label2); ?>"
			id="navigation-ajax" 
			class="<?php echo esc_attr($class); ?>">
			<?php echo esc_html($label1); ?>
		</a>
	</nav>
	<?php
}
/*
 * Ajax page navigation
 */
function dbea_ajax_load_next_page(){
	// Get current layout
	global $dbea_blog_layout;
	$dbea_blog_layout = isset($_POST['dbea_blog_layout']) ? esc_html($_POST['dbea_blog_layout']) : '';
	if( $dbea_blog_layout == '' ) $dbea_blog_layout = dbea_getoption('blog_type');
	// Get current page
	$page = $_POST['page'];
	// Number of published sticky posts
	$sticky_posts = dbea_get_sticky_posts_count();
	// Current query vars
	$vars = $_POST['vars'];
	// Convert string value into corresponding data types
	foreach ($vars as $key => $value){
		if( is_numeric($value) ) $vars[$key] = intval($value);
		if( $value == 'false' ) $vars[$key] = false;
		if( $value == 'true' ) $vars[$key] = true;
	}
	// Item template file 
	$template = $_POST['template'];
	// Return next page
	$page = intval($page) + 1;
	$posts_per_page = $_POST['numload'];
    if( $page == 2 && $vars['posts_per_page'] ){
        $offset = $vars['posts_per_page'];
    }else{
        $offset = $vars['posts_per_page'] + ($page - 2) * $posts_per_page;
    }
	// Get more posts per page than necessary to detect if there are more posts
	$args = array('post_status'=>'publish', 'posts_per_page'=>$posts_per_page + 1, 'offset'=>$offset);
	$args = array_merge($vars, $args);
	// Remove unnecessary variables
	unset($args['paged']);
	unset($args['p']);
	unset($args['page']);
	unset($args['pagename']); // This is necessary in case Posts Page is set to static page
	$query = new WP_Query($args);
	$idx = 0;
	if( $query->have_posts() ){
		while ( $query->have_posts() ){
			$query->the_post();
			$idx = $idx + 1;
			if( $idx < $posts_per_page + 1 )
				get_template_part($template, get_post_format());
		}
		if( $query->post_count <= $posts_per_page ){
			// There are no more posts
			// Print a flag to detect
			echo '<div id="sns-load-more-no-posts" class="no-posts"><!-- --></div>';
		}
	}else{
		// No posts found
	}
	/* Restore original Post Data*/
	wp_reset_postdata();
	die('');
}
// When the request action is "load_more", the dbea_ajax_load_next_page() will be called
add_action('wp_ajax_load_more', 'dbea_ajax_load_next_page');
add_action('wp_ajax_nopriv_load_more', 'dbea_ajax_load_next_page');

function remove_img_attr ($html)
{
    return preg_replace('/(sizes|width|height)="\d+"\s/', "", $html);
}
 

/**
 * Display navigation to next/previous post when applicable.
 */
function dbea_post_nav() {
	// Don't print empty markup if there's nowhere to navigate.
	$previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
	$next     = get_adjacent_post( false, '', false );
	if ( ! $next && ! $previous ) {
		return;
	}?>
	<div class="post-standard-navigation post-navigation" role="navigation">
    	<?php 
    	if( $previous ): ?>
        <div class="nav-previous">
        	<?php
        		previous_post_link( '<div class="nav-post-link">%link</div>', _x( 'Prev post', 'Previous post link', 'dbea' ) );
				previous_post_link( '<div class="nav-post-title">%link</div>', '<span class="icon"></span><span class="title">%title</span>');
			?>
        </div>
        <?php endif; ?>
        <?php if( $next ): ?>
        <div class="nav-next">
        	<?php
        		next_post_link( '<div class="nav-post-link">%link</div>', _x( 'Next post', 'Next post link', 'dbea' ) );
				next_post_link( '<div class="nav-post-title">%link</div>', '<span class="title">%title</span><span class="icon"></span>');
			?>
        </div>
        <?php endif; ?>
	</div>
	<?php
}

// Set cookie theme option
add_action( 'wp_ajax_sns_setcookies', 'dbea_setcookies' );
add_action( 'wp_ajax_nopriv_sns_setcookies', 'dbea_setcookies' );
// Reset cookie theme option
add_action( 'wp_ajax_sns_resetcookies', 'dbea_resetcookies' );
add_action( 'wp_ajax_nopriv_sns_resetcookies', 'dbea_resetcookies' );
function dbea_setcookies(){
	setcookie('dbea_'.$_POST['key'], $_POST['value'], time()+3600*24*1, '/'); // 1 day
}
function dbea_resetcookies(){
	setcookie('dbea_advance_scss_compile', '', 0, '/');
	setcookie('dbea_use_stickmenu', '', 0, '/');
}