<?php
require get_template_directory() . '/inc/helpers.php';
require get_template_directory() . '/inc/sanitization.php';
require get_template_directory() . '/inc/functions.php';
require get_template_directory() . '/inc/helpers-post-meta.php';
require get_template_directory() . '/inc/customizer.php';
require get_template_directory() . '/inc/customizer-styles.php';
require get_template_directory() . '/inc/user-meta.php';

add_action( 'after_setup_theme', 'roxima_content_width', 0 );
function roxima_content_width() {
	$GLOBALS['content_width'] = apply_filters( 'roxima_content_width', 850 );
}

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

	if ( ! defined( 'CI_THEME_NAME' ) ) {
		define( 'CI_THEME_NAME', 'roxima' );
	}
	if ( ! defined( 'CI_WHITELABEL' ) ) {
		// Set the following to true, if you want to remove any user-facing CSSIgniter traces.
		define( 'CI_WHITELABEL', false );
	}

	load_theme_textdomain( 'roxima', get_template_directory() . '/languages' );

	/*
	 * Theme supports.
	 */
	add_theme_support( 'automatic-feed-links' );
	add_theme_support( 'title-tag' );
	add_theme_support( 'post-thumbnails' );
	add_theme_support( 'html5', array(
		'search-form',
		'comment-form',
		'comment-list',
		'gallery',
		'caption',
	) );
	add_theme_support( 'custom-background', array(
		'wp-head-callback' => 'roxima_custom_background_cb',
	) );


	/*
	 * Image sizes.
	 */
	set_post_thumbnail_size( 850, 400, true );
	add_image_size( 'roxima_hero', 750, 450, true );
	add_image_size( 'roxima_square_small', 165, 165, true );
	add_image_size( 'roxima_slider', 1920, 800, true );
	add_image_size( 'roxima_square', 400, 400, true );
	add_image_size( 'roxima_client', 0, 80, false );


	/*
	 * Navigation menus.
	 */
	register_nav_menus( array(
		'main_menu' => esc_html__( 'Main Menu', 'roxima' ),
	) );



	/*
	 * Default hooks
	 */
	// Prints the inline JS scripts that are registered for printing, and removes them from the queue.
	add_action( 'admin_footer', 'roxima_print_inline_js' );
	add_action( 'wp_footer', 'roxima_print_inline_js' );

	// Handle the dismissible sample content notice.
	add_action( 'admin_notices', 'roxima_admin_notice_sample_content' );
	add_action( 'wp_ajax_roxima_dismiss_sample_content', 'roxima_ajax_dismiss_sample_content' );

	// Wraps post counts in span.ci-count
	// Needed for the default widgets, however more appropriate filters don't exist.
	add_filter( 'get_archives_link', 'roxima_wrap_archive_widget_post_counts_in_span', 10, 2 );
	add_filter( 'wp_list_categories', 'roxima_wrap_category_widget_post_counts_in_span', 10, 2 );
}
endif;

add_action( 'wp_enqueue_scripts', 'roxima_enqueue_scripts' );
function roxima_enqueue_scripts() {

	/*
	 * Styles
	 */
	$theme = wp_get_theme();

	$font_url = '';
	/* translators: If there are characters in your language that are not supported by Montserrat and Lato, translate this to 'off'. Do not translate into your own language. */
	if ( 'off' !== _x( 'on', 'Montserrat and Lato fonts: on or off', 'roxima' ) ) {
		$font_url = add_query_arg( 'family', urlencode( 'Montserrat:700|Lato:400,400italic,700' ), '//fonts.googleapis.com/css' );
	}
	wp_register_style( 'roxima-google-font', esc_url( $font_url ) );

	wp_register_style( 'roxima-base', get_template_directory_uri() . '/css/base.css', array(), $theme->get( 'Version' ) );
	wp_register_style( 'flexslider', get_template_directory_uri() . '/css/flexslider.css', array(), '2.5.0' );
	wp_register_style( 'mmenu', get_template_directory_uri() . '/css/mmenu.css', array(), '5.2.0' );
	wp_register_style( 'font-awesome', get_template_directory_uri() . '/css/font-awesome.css', array(), '4.6.1' );
	wp_register_style( 'magnific-popup', get_template_directory_uri() . '/css/magnific.css', array(), '1.0.0' );
	wp_register_style( 'animate', get_template_directory_uri() . '/css/animate.min.css', array(), '3.4.0' );

	wp_register_style( 'roxima-style', get_template_directory_uri() . '/style.css', array(
		'roxima-google-font',
		'roxima-base',
		'flexslider',
		'mmenu',
		'font-awesome',
		'magnific-popup',
		'animate',
	), $theme->get( 'Version' ) );

	if ( is_child_theme() ) {
		wp_register_style( 'roxima-style-child', get_stylesheet_directory_uri() . '/style.css', array(
			'roxima-style',
		), $theme->get( 'Version' ) );
	}


	/*
	 * Scripts
	 */
	wp_register_script( 'roxima-google-maps', roxima_get_google_maps_api_url(), array(), null, false );

	wp_register_script( 'superfish', get_template_directory_uri() . '/js/superfish.js', array( 'jquery' ), '1.7.5', true );
	wp_register_script( 'mmenu', get_template_directory_uri() . '/js/jquery.mmenu.min.all.js', array( 'jquery' ), '5.2.0', true );
	wp_register_script( 'flexslider', get_template_directory_uri() . '/js/jquery.flexslider.js', array( 'jquery' ), '2.5.0', true );
	wp_register_script( 'fitVids', get_template_directory_uri() . '/js/jquery.fitvids.js', array( 'jquery' ), '1.1', true );
	wp_register_script( 'magnific-popup', get_template_directory_uri() . '/js/jquery.magnific-popup.js', array( 'jquery' ), '1.0.0', true );
	wp_register_script( 'waypoints', get_template_directory_uri() . '/js/jquery.waypoints.min.js', array( 'jquery' ), '4.0.0', true );
	wp_register_script( 'waypoints-sticky', get_template_directory_uri() . '/js/sticky.min.js', array( 'jquery' ), '4.0.0', true );
	wp_register_script( 'wow', get_template_directory_uri() . '/js/wow.min.js', array( 'jquery' ), '1.1.2', true );
	wp_register_script( 'parallax', get_template_directory_uri() . '/js/parallax.min.js', array( 'jquery' ), '1.3.1', true );
	wp_register_script( 'matchHeight', get_template_directory_uri() . '/js/jquery.matchHeight.js', array( 'jquery' ), '1.0.0', true );

	wp_register_script( 'roxima-front-scripts', get_template_directory_uri() . '/js/scripts.js', array(
		'jquery',
		'superfish',
		'mmenu',
		'flexslider',
		'fitVids',
		'magnific-popup',
		'waypoints',
		'waypoints-sticky',
		'wow',
		'parallax',
		'matchHeight'
	), $theme->get( 'Version' ), true );


	/*
	 * Enqueue
	 */
	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}

	if ( get_theme_mod( 'google_maps_api_enable', 1 ) ) {
		wp_enqueue_script( 'roxima-google-maps' );
	}

	wp_enqueue_style( 'roxima-style' );
	if ( is_child_theme() ) {
		wp_enqueue_style( 'roxima-style-child' );
	}

	wp_enqueue_script( 'roxima-front-scripts' );


}

add_action( 'admin_enqueue_scripts', 'roxima_admin_enqueue_scripts' );
function roxima_admin_enqueue_scripts( $hook ) {
	$theme = wp_get_theme();

	/*
	 * Styles
	 */
	wp_register_style( 'alpha-color-picker', get_template_directory_uri() . '/css/admin/alpha-color-picker.css', array(), $theme->get( 'Version' ) );
	wp_register_style( 'roxima-repeating-fields', get_template_directory_uri() . '/css/admin/repeating-fields.css', array(), $theme->get( 'Version' ) );
	wp_register_style( 'roxima-widgets', get_template_directory_uri() . '/css/admin/widgets.css', array(
		'wp-color-picker',
		'alpha-color-picker',
		'roxima-repeating-fields',
		'roxima-post-meta'
	), $theme->get( 'Version' ) );
	wp_register_style( 'roxima-nav-menus', get_template_directory_uri() . '/css/admin/nav-menus.css', array(), $theme->get( 'Version' ) );


	/*
	 * Scripts
	 */
	wp_register_script( 'roxima-google-maps', roxima_get_google_maps_api_url(), array(), null, false );

	wp_register_script( 'alpha-color-picker', get_template_directory_uri() . '/js/admin/alpha-color-picker.js', array( 'jquery' ), $theme->get( 'Version' ), true );
	wp_register_script( 'roxima-repeating-fields', get_template_directory_uri() . '/js/admin/repeating-fields.js', array(
		'jquery',
		'jquery-ui-sortable'
	), $theme->get( 'Version' ), true );
	wp_register_script( 'roxima-widgets', get_template_directory_uri() . '/js/admin/widgets.js', array(
		'jquery',
		'wp-color-picker',
		'alpha-color-picker',
		'roxima-repeating-fields',
		'roxima-post-meta',
	), $theme->get( 'Version' ), true );

	wp_register_script( 'roxima-nav-menus', get_template_directory_uri() . '/js/admin/nav-menus.js', array(
		'jquery',
	), $theme->get( 'Version' ), true );

	$params = array(
		'ajaxurl' => admin_url( 'admin-ajax.php' ),
	);
	wp_localize_script( 'roxima-nav-menus', 'roxima_NavMenus', $params );

	/*
	 * Enqueue
	 */
	if ( in_array( $hook, array( 'widgets.php', 'customize.php' ) ) ) {
		if ( get_theme_mod( 'google_maps_api_enable', 1 ) ) {
			wp_enqueue_script( 'roxima-google-maps' );
		}

		wp_enqueue_media();
		wp_enqueue_style( 'roxima-widgets' );
		wp_enqueue_script( 'roxima-widgets' );
	}

	if ( in_array( $hook, array( 'nav-menus.php', 'customize.php' ) ) ) {
		wp_enqueue_script( 'roxima-nav-menus' );
	}
}

add_action( 'customize_controls_enqueue_scripts', 'roxima_customize_controls_enqueue_scripts' );
function roxima_customize_controls_enqueue_scripts() {
	wp_enqueue_style( 'roxima-nav-menus' );
	wp_enqueue_script( 'roxima-nav-menus' );
}

add_action( 'widgets_init', 'roxima_widgets_init' );
function roxima_widgets_init() {
	register_sidebar( array(
		'name'          => esc_html_x( 'Blog', 'widget area', 'roxima' ),
		'id'            => 'blog',
		'description'   => esc_html__( 'This is the main sidebar.', 'roxima' ),
		'before_widget' => '<aside id="%1$s" class="widget group %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );

	register_sidebar( array(
		'name'          => esc_html_x( 'Pages', 'widget area', 'roxima' ),
		'id'            => 'page',
		'description'   => esc_html__( 'This sidebar appears on your static pages. If empty, the Blog sidebar will be shown instead.', 'roxima' ),
		'before_widget' => '<aside id="%1$s" class="widget group %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );

	register_sidebar( array(
		'name'          => esc_html_x( 'Homepage', 'widget area', 'roxima' ),
		'id'            => 'frontpage',
		'description'   => esc_html__( 'This widget area appears on your front page template.', 'roxima' ),
		'before_widget' => '<section id="%1$s" class="widget group %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<h2 class="section-title">',
		'after_title'   => '</h2>',
	) );
}

add_action( 'widgets_init', 'roxima_load_widgets' );
function roxima_load_widgets() {
	require get_template_directory() . '/inc/widgets/slider.php';
	require get_template_directory() . '/inc/widgets/services.php';
	require get_template_directory() . '/inc/widgets/team.php';
	require get_template_directory() . '/inc/widgets/clients.php';
	require get_template_directory() . '/inc/widgets/testimonials.php';
	require get_template_directory() . '/inc/widgets/contact.php';
	require get_template_directory() . '/inc/widgets/latest-posts.php';
	require get_template_directory() . '/inc/widgets/custom-content.php';
	require get_template_directory() . '/inc/widgets/pricing-table.php';
}

function roxima_get_fullwidth_sidebars() {
	return array(
		'frontpage',
	);
}


add_filter( 'excerpt_length', 'roxima_excerpt_length' );
function roxima_excerpt_length( $length ) {
	return get_theme_mod( 'excerpt_length', 55 );
}


add_filter( 'wp_page_menu', 'roxima_wp_page_menu', 10, 2 );
function roxima_wp_page_menu( $menu, $args ) {
	preg_match( '#^<div class="(.*?)">(?:.*?)</div>$#', $menu, $matches );
	$menu = preg_replace( '#^<div class=".*?">#', '', $menu, 1 );
	$menu = preg_replace( '#</div>$#', '', $menu, 1 );
	$menu = preg_replace( '#^<ul>#', '<ul class="' . esc_attr( $args['menu_class'] ) . '">', $menu, 1 );
	return $menu;
}


add_filter( 'the_content', 'roxima_lightbox_rel', 12 );
add_filter( 'get_comment_text', 'roxima_lightbox_rel' );
add_filter( 'wp_get_attachment_link', 'roxima_lightbox_rel' );
if ( ! function_exists( 'roxima_lightbox_rel' ) ):
function roxima_lightbox_rel( $content ) {
	global $post;
	$pattern     = "/<a(.*?)href=('|\")([^>]*).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>(.*?)<\/a>/i";
	$replacement = '<a$1href=$2$3.$4$5 data-lightbox="gal[' . $post->ID . ']"$6>$7</a>';
	$content     = preg_replace( $pattern, $replacement, $content );

	return $content;
}
endif;


add_filter( 'wp_link_pages_args', 'roxima_wp_link_pages_args' );
function roxima_wp_link_pages_args( $params ) {
	$params = array_merge( $params, array(
		'before' => '<p class="link-pages">' . esc_html__( 'Pages:', 'roxima' ),
		'after'  => '</p>',
	) );

	return $params;
}

function roxima_get_google_maps_api_url() {
	$args = array();

	if ( get_theme_mod( 'google_maps_api_key' ) ) {
		$args['key'] = get_theme_mod( 'google_maps_api_key' );
	}

	return esc_url_raw( add_query_arg( $args, '//maps.googleapis.com/maps/api/js' ) );
}

add_action( 'wp_head', 'roxima_print_google_analytics_tracking' );
if ( ! function_exists( 'roxima_print_google_analytics_tracking' ) ):
function roxima_print_google_analytics_tracking() {
	if ( is_admin() || ! get_theme_mod( 'google_anaytics_tracking_id' ) ) {
		return;
	}
	?>
	<script>
		(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
		(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
		m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
		})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

		ga('create', '<?php echo get_theme_mod( 'google_anaytics_tracking_id' ); ?>', 'auto');
		ga('send', 'pageview');
	</script>
	<?php
}
endif;


if ( ! function_exists( 'roxima_get_social_networks' ) ):
function roxima_get_social_networks() {
	return array(
		array(
			'name'  => 'facebook',
			'label' => esc_html__( 'Facebook', 'roxima' ),
			'icon'  => 'fa-facebook'
		),
		array(
			'name'  => 'twitter',
			'label' => esc_html__( 'Twitter', 'roxima' ),
			'icon'  => 'fa-twitter'
		),
		array(
			'name'  => 'pinterest',
			'label' => esc_html__( 'Pinterest', 'roxima' ),
			'icon'  => 'fa-pinterest'
		),
		array(
			'name'  => 'instagram',
			'label' => esc_html__( 'Instagram', 'roxima' ),
			'icon'  => 'fa-instagram'
		),
		array(
			'name'  => 'gplus',
			'label' => esc_html__( 'Google Plus', 'roxima' ),
			'icon'  => 'fa-google-plus'
		),
		array(
			'name'  => 'linkedin',
			'label' => esc_html__( 'LinkedIn', 'roxima' ),
			'icon'  => 'fa-linkedin'
		),
		array(
			'name'  => 'tumblr',
			'label' => esc_html__( 'Tumblr', 'roxima' ),
			'icon'  => 'fa-tumblr'
		),
		array(
			'name'  => 'flickr',
			'label' => esc_html__( 'Flickr', 'roxima' ),
			'icon'  => 'fa-flickr'
		),
		array(
			'name'  => 'bloglovin',
			'label' => esc_html__( 'Bloglovin', 'roxima' ),
			'icon'  => 'fa-heart'
		),
		array(
			'name'  => 'youtube',
			'label' => esc_html__( 'YouTube', 'roxima' ),
			'icon'  => 'fa-youtube'
		),
		array(
			'name'  => 'vimeo',
			'label' => esc_html__( 'Vimeo', 'roxima' ),
			'icon'  => 'fa-vimeo'
		),
		array(
			'name'  => 'dribbble',
			'label' => esc_html__( 'Dribbble', 'roxima' ),
			'icon'  => 'fa-dribbble'
		),
		array(
			'name'  => 'wordpress',
			'label' => esc_html__( 'WordPress', 'roxima' ),
			'icon'  => 'fa-wordpress'
		),
		array(
			'name'  => '500px',
			'label' => esc_html__( '500px', 'roxima' ),
			'icon'  => 'fa-500px'
		),
		array(
			'name'  => 'soundcloud',
			'label' => esc_html__( 'Soundcloud', 'roxima' ),
			'icon'  => 'fa-soundcloud'
		),
		array(
			'name'  => 'spotify',
			'label' => esc_html__( 'Spotify', 'roxima' ),
			'icon'  => 'fa-spotify'
		),
		array(
			'name'  => 'vine',
			'label' => esc_html__( 'Vine', 'roxima' ),
			'icon'  => 'fa-vine'
		),
	);
}
endif;


function roxima_sanitize_footer_text( $text ) {
	$allowed_html = array(
		'a'      => array(
			'href'  => array(),
			'class' => array(),
		),
		'img'    => array(
			'src'   => array(),
			'class' => array(),
		),
		'span'   => array(
			'class' => array(),
		),
		'i'      => array(
			'class' => array(),
		),
		'b'      => array(),
		'em'     => array(),
		'strong' => array(),
	);

	return wp_kses( $text, $allowed_html );
}


function roxima_sanitize_rgba_color( $str, $return_hash = true, $return_fail = '' ) {
	if( $str === false || empty( $str ) || $str == 'false' ) {
		return $return_fail;
	}

	// Allow keywords and predefined colors
	if ( in_array( $str, array( 'transparent', 'initial', 'inherit', 'black', 'silver', 'gray', 'grey', 'white', 'maroon', 'red', 'purple', 'fuchsia', 'green', 'lime', 'olive', 'yellow', 'navy', 'blue', 'teal', 'aqua', 'orange', 'aliceblue', 'antiquewhite', 'aquamarine', 'azure', 'beige', 'bisque', 'blanchedalmond', 'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse', 'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'darkblue', 'darkcyan', 'darkgoldenrod', 'darkgray', 'darkgrey', 'darkgreen', 'darkkhaki', 'darkmagenta', 'darkolivegreen', 'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen', 'darkslateblue', 'darkslategray', 'darkslategrey', 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue', 'dimgray', 'dimgrey', 'dodgerblue', 'firebrick', 'floralwhite', 'forestgreen', 'gainsboro', 'ghostwhite', 'gold', 'goldenrod', 'greenyellow', 'grey', 'honeydew', 'hotpink', 'indianred', 'indigo', 'ivory', 'khaki', 'lavender', 'lavenderblush', 'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan', 'lightgoldenrodyellow', 'lightgray', 'lightgreen', 'lightgrey', 'lightpink', 'lightsalmon', 'lightseagreen', 'lightskyblue', 'lightslategray', 'lightslategrey', 'lightsteelblue', 'lightyellow', 'limegreen', 'linen', 'mediumaquamarine', 'mediumblue', 'mediumorchid', 'mediumpurple', 'mediumseagreen', 'mediumslateblue', 'mediumspringgreen', 'mediumturquoise', 'mediumvioletred', 'midnightblue', 'mintcream', 'mistyrose', 'moccasin', 'navajowhite', 'oldlace', 'olivedrab', 'orangered', 'orchid', 'palegoldenrod', 'palegreen', 'paleturquoise', 'palevioletred', 'papayawhip', 'peachpuff', 'peru', 'pink', 'plum', 'powderblue', 'rosybrown', 'royalblue', 'saddlebrown', 'salmon', 'sandybrown', 'seagreen', 'seashell', 'sienna', 'skyblue', 'slateblue', 'slategray', 'slategrey', 'snow', 'springgreen', 'steelblue', 'tan', 'thistle', 'tomato', 'turquoise', 'violet', 'wheat', 'whitesmoke', 'yellowgreen', 'rebeccapurple' ) ) ) {
		return $str;
	}

	preg_match( '/rgba\(\s*(\d{1,3}\.?\d*\%?)\s*,\s*(\d{1,3}\.?\d*\%?)\s*,\s*(\d{1,3}\.?\d*\%?)\s*,\s*(\d{1}\.?\d*\%?)\s*\)/', $str, $rgba_matches );
	if( !empty( $rgba_matches ) && count($rgba_matches) == 5 ) {
		for( $i = 1; $i < 4; $i++ ) {
			if ( strpos( $rgba_matches[ $i ], '%' ) !== false ) {
				$rgba_matches[ $i ] = roxima_sanitize_0_100_percent( $rgba_matches[ $i ] );
			} else {
				$rgba_matches[ $i ] = roxima_sanitize_0_255( $rgba_matches[ $i ] );
			}
		}
		$rgba_matches[4] = roxima_sanitize_0_1_opacity( $rgba_matches[ $i ] );
		return sprintf( 'rgba(%s, %s, %s, %s)', $rgba_matches[1], $rgba_matches[2], $rgba_matches[3], $rgba_matches[4] );
	}

	// Not a color function either. Let's see if it's a hex color.

	// Include the hash if not there.
	// The regex below depends on in.
	if ( substr( $str, 0, 1 ) != '#' ) {
		$str = '#' . $str;
	}

	preg_match( '/(#)([0-9a-fA-F]{6})/', $str, $matches );

	if ( count( $matches ) == 3 ) {
		if ( $return_hash ) {
			return $matches[1] . $matches[2];
		} else {
			return $matches[2];
		}
	}

	return $return_fail;
}

function roxima_sanitize_0_100_percent( $val ) {
	$val = str_replace( '%', '', $val );
	if ( floatval( $val ) > 100 ) {
		$val = 100;
	} elseif ( floatval( $val ) < 0 ) {
		$val = 0;
	}

	return floatval( $val ) . '%';
}

function roxima_sanitize_0_255( $val ) {
	if ( intval( $val ) > 255 ) {
		$val = 255;
	} elseif ( intval( $val ) < 0 ) {
		$val = 0;
	}

	return intval( $val );
}

function roxima_sanitize_0_1_opacity( $val ) {
	if ( floatval( $val ) > 1 ) {
		$val = 1;
	} elseif ( floatval( $val ) < 0 ) {
		$val = 0;
	}

	return floatval( $val );
}



function roxima_sanitize_blog_layout( $value ) {
	$valid = array( 'sidebar', 'fullwidth' );

	if( in_array( $value, $valid ) ) {
		return $value;
	}

	return 'sidebar';
}


function roxima_get_columns_classes( $columns ) {
	switch ( $columns ) {
		case 1:
			$classes = 'col-xs-12';
			break;
		case 2:
			$classes = 'col-sm-6 col-xs-12';
			break;
		case 3:
			$classes = 'col-md-4 col-sm-6 col-xs-12';
			break;
		case 4:
		default:
			$classes = 'col-md-3 col-sm-6 col-xs-12';
			break;
	}

	return $classes;
}

function roxima_best_number_of_columns( $count ) {
	$default = 4;
	if ( $count >= 1 && $count <= 4 ) {
		return intval( $count );
	} elseif ( $count > 4 ) {
		if ( ( $count % 4 ) == 0 ) {
			return 4;
		} elseif ( ( $count % 3 ) == 0 ) {
			return 3;
		} elseif ( ( $count % 2 ) == 0 ) {
			return 2;
		} else {
			return $default;
		}
	} else {
		return $default;
	}
}

add_action( 'wp_ajax_roxima_ajax_nav_menus_widgets_links', 'roxima_ajax_nav_menus_widgets_links' );
function roxima_ajax_nav_menus_widgets_links() {
	global $wp_registered_widgets;

	$sw = wp_get_sidebars_widgets();

	$html = '<h4 class="roxima-frontpage-widget-links-title">' . esc_html__( 'Front Page Widgets', 'roxima' ) . '</h4>';
	$html .= '<ul class="roxima-frontpage-widget-links">';
	if ( ! empty( $sw['frontpage'] ) ) {
		foreach ( $sw['frontpage'] as $widget_id ) {
			$found = preg_match( '/^(.*)-(\d+)$/', $widget_id, $matches );

			if ( $found ) {
				$base_id     = $matches[1];
				$instance_id = $matches[2];
				$options     = get_option( 'widget_' . $base_id );

				$widget_title   = ! empty( $wp_registered_widgets[ $widget_id ]['name'] ) ? $wp_registered_widgets[ $widget_id ]['name'] : '';
				$instance_title = ! empty( $options[ $instance_id ]['title'] ) ? $options[ $instance_id ]['title'] : '';
				if ( 'ci-slideshow' == $base_id ) {
					$instance_title = esc_html__( 'Slideshow', 'roxima' );
				}

				$html .= sprintf( '<li><a href="%s" data-title="%s">%s</a></li>',
					esc_url( home_url( '/' ) . '#' . esc_attr( $widget_id ) ),
					esc_attr( $instance_title ),
					! empty( $instance_title ) ? $instance_title : $widget_title
				);
			}
		}

	}
	$html .= '</ul>';

	echo $html;
	die;
}