<?php
/**
 * Google Fonts
 *
 * @param null
 * @return array
 *
 * @since Event Listing 1.0.0
 *
 */
if (!function_exists('event_listing_google_fonts')) :
    function event_listing_google_fonts()
    {
        $event_listing_google_fonts = array(
            'ABeeZee:400,400italic' => 'ABeeZee',
            'Abel' => 'Abel',
            'Abril+Fatface' => 'Abril Fatface',
            'Aldrich' => 'Aldrich',
            'Alegreya:400,400italic,700,900' => 'Alegreya',
            'Alex+Brush' => 'Alex Brush',
            'Alfa+Slab+One' => 'Alfa Slab One',
            'Amaranth:400,400italic,700' => 'Amaranth',
            'Andada' => 'Andada',
            'Anton' => 'Anton',
            'Archivo+Black' => 'Archivo Black',
            'Archivo+Narrow:400,400italic,700' => 'Archivo Narrow',
            'Arimo:400,400italic,700' => 'Arimo',
            'Arvo:400,400italic,700' => 'Arvo',
            'Asap:400,400italic,700' => 'Asap',
            'Bangers' => 'Bangers',
            'BenchNine:400,700' => 'BenchNine',
            'Bevan' => 'Bevan',
            'Bitter:400,400italic,700' => 'Bitter',
            'Bree+Serif' => 'Bree Serif',
            'Cabin:400,400italic,500,600,700' => 'Cabin',
            'Cabin+Condensed:400,500,600,700' => 'Cabin Condensed',
            'Cantarell:400,400italic,700' => 'Cantarell',
            'Carme' => 'Carme',
            'Cherry+Cream+Soda' => 'Cherry Cream Soda',
            'Cinzel:400,700,900' => 'Cinzel',
            'Comfortaa:400,300,700' => 'Comfortaa',
            'Cookie' => 'Cookie',
            'Covered+By+Your+Grace' => 'Covered By Your Grace',
            'Crete+Round:400,400italic' => 'Crete Round',
            'Crimson+Text:400,400italic,600,700' => 'Crimson Text',
            'Cuprum:400,400italic' => 'Cuprum',
            'Dancing+Script:400,700' => 'Dancing Script',
            'Didact+Gothic' => 'Didact Gothic',
            'Droid+Sans:400,700' => 'Droid Sans',
            'Domine' => 'Domine',
            'Dosis:400,300,600,800' => 'Dosis',
            'Droid+Serif:400,400italic,700' => 'Droid Serif',
            'Economica:400,700,400italic' => 'Economica',
            'EB+Garamond' => 'EB Garamond',
            'Exo:400,300,400italic,600,800' => 'Exo',
            'Exo +2:400,300,400italic,600,700,900' => 'Exo 2',
            'Fira+Sans:400,500' => 'Fira Sans',
            'Fjalla+One' => 'Fjalla One',
            'Francois+One' => 'Francois One',
            'Fredericka+the+Great' => 'Fredericka the Great',
            'Fredoka+One' => 'Fredoka One',
            'Fugaz+One' => 'Fugaz One',
            'Great+Vibes' => 'Great Vibes',
            'Handlee' => 'Handlee',
            'Hammersmith+One' => 'Hammersmith One',
            'Hind:400,300,600,700' => 'Hind',
            'Inconsolata:400,700' => 'Inconsolata',
            'Indie+Flower' => 'Indie Flower',
            'Istok+Web:400,400italic,700' => 'Istok Web',
            'Josefin+Sans:400,600,700,400italic' => 'Josefin Sans',
            'Josefin+Slab:400,400italic,700,600' => 'Josefin Slab',
            'Jura:400,300,500,600' => 'Jura',
            'Karla:400,400italic,700' => 'Karla',
            'Kaushan+Script' => 'Kaushan Script',
            'Kreon:400,300,700' => 'Kreon',
            'Lateef' => 'Lateef',
            'Lato:400,300,400italic,900,700' => 'Lato',
            'Libre+Baskerville:400,400italic,700' => 'Libre Baskerville',
            'Limelight' => 'Limelight',
            'Lobster' => 'Lobster',
            'Lobster+Two:400,700,700italic' => 'Lobster Two',
            'Lora:400,400i' => 'Lora',
            'Maven+Pro:400,500,700,900' => 'Maven Pro',
            'Merriweather:400,400italic,300,900,700' => 'Merriweather',
            'Merriweather+Sans:400,400italic,700,800' => 'Merriweather Sans',
            'Monda:400,700' => 'Monda',
            'Montserrat:400,700' => 'Montserrat',
            'Muli:400,600' => 'Muli',
            'News+Cycle:400,700' => 'News Cycle',
            'Noticia+Text:400,400italic,700' => 'Noticia Text',
            'Noto +Sans:400,400italic,700' => 'Noto Sans',
            'Noto +Serif:400,400italic,700' => 'Noto Serif',
            'Nunito:400,300,700' => 'Nunito',
            'Old+Standard +TT:400,400italic,700' => 'Old Standard TT',
            'Open+Sans:400,400italic,600,700' => 'Open Sans',
            'Open+Sans+Condensed:300,300italic,700' => 'Open Sans Condensed',
            'Oswald:400,300,700' => 'Oswald',
            'Oxygen:400,300,700' => 'Oxygen',
            'Pacifico' => 'Pacifico',
            'Passion+One:400,700,900' => 'Passion One',
            'Pathway+Gothic+One' => 'Pathway Gothic One',
            'Patua+One' => 'Patua One',
            'Poiret+One' => 'Poiret One',
            'Pontano+Sans' => 'Pontano Sans',
            'Play:400,700' => 'Play',
            'Playball' => 'Playball',
            'Playfair+Display:400,400italic,700,900' => 'Playfair Display',
            'Prata' => 'Prata',
            'PT+Sans:400,400italic,700' => 'PT Sans',
            'PT+Sans+Caption:400,700' => 'PT Sans Caption',
            'PT+Sans+Narrow:400,700' => 'PT Sans Narrow',
            'PT+Serif:400,400italic,700' => 'PT Serif',
            'Quattrocento+Sans:400,700,400italic' => 'Quattrocento Sans',
            'Questrial' => 'Questrial',
            'Quicksand:400,700' => 'Quicksand',
            'Raleway:400,300,500,600,700,900' => 'Raleway',
            'Righteous' => 'Righteous',
            'Roboto:400,500,300,700,400italic' => 'Roboto',
            'Roboto+Condensed:400,300,400italic,700' => 'Roboto Condensed',
            'Roboto+Slab:400,300,700' => 'Roboto Slab',
            'Rokkitt:400,700' => 'Rokkitt',
            'Ropa+Sans:400,400italic' => 'Ropa Sans',
            'Russo+One' => 'Russo One',
            'Sanchez:400,400italic' => 'Sanchez',
            'Satisfy' => 'Satisfy',
            'Shadows+Into+Light' => 'Shadows Into Light',
            'Sigmar+One' => 'Sigmar One',
            'Signika:400,300,700' => 'Signika',
            'Six+Caps' => 'Six Caps',
            'Slabo+27px' => 'Slabo 27px',
            'Source+Sans+Pro:400,400italic,600,900,300' => 'Source Sans Pro',
            'Squada+One' => 'Squada One',
            'Tangerine:400,700' => 'Tangerine',
            'Tinos:400,400italic,700' => 'Tinos',
            'Titillium+Web:400,300,400italic,700,900' => 'Titillium Web',
            'Ubuntu:400,400italic,500,700' => 'Ubuntu',
            'Ubuntu+Condensed' => 'Ubuntu Condensed',
            'Varela+Round' => 'Varela Round',
            'Vollkorn:400,400italic,700' => 'Vollkorn',
            'Voltaire' => 'Voltaire',
            'Yanone+Kaffeesatz:400,300,700' => 'Yanone Kaffeesatz'
        );
        return apply_filters('event_listing_google_fonts', $event_listing_google_fonts);
    }
endif;


/**
 * Enqueue the list of fonts.
 */
function event_listing_customizer_fonts()
{
    wp_enqueue_style('event_listing_customizer_fonts', 'https://fonts.googleapis.com/css?family=ABeeZee|Abel|Abril+Fatface|Aldrich|Alegreya|Alex+Brush|Alfa+Slab+One|Amaranth|Andada|Anton|Archivo+Black|Archivo+Narrow|Arimo|Arimo|Arvo|Asap|Bangers|BenchNine|Bevan|Bitter|Bree+Serif|Cabin|Cabin+Condensed|Cantarell|Carme|Cherry+Cream+Soda|Cinzel|Comfortaa|Cookie|Covered+By+Your+Grace|Crete+Round|Crimson+Text|Cuprum|Dancing+Script|Didact+Gothic|Droid+Sans|Domine|Dosis|Droid+Serif|Economica|EB+Garamond|Exo|Exo|Fira+Sans|Fjalla+One|Francois+One|Fredericka+the+Great|Fredoka+One|Fugaz+One|Great+Vibes|Handlee|Hammersmith+One|Hind|Inconsolata|Indie+Flower|Istok+Web|Josefin+Sans|Josefin+Slab|Jura|Karla|Kaushan+Script|Kreon|Lateef|Lato|Lato|Libre+Baskerville|Limelight|Lobster|Lobster+Two|Lora|Maven+Pro|Merriweather|Merriweather+Sans|Monda|Montserrat|Muli|News+Cycle|Noticia+Text|Noto+Sans|Noto+Serif|Nunito|Old+Standard +TT|Open+Sans|Open+Sans+Condensed|Oswald|Oxygen|Pacifico|Passion+One|Passion One|Pathway+Gothic+One|Patua+One|Poiret+One|Pontano+Sans|Play|Playball|Playfair+Display|Prata|PT+Sans|PT+Sans+Caption|PT+Sans+Narrow|PT+Serif|Quattrocento+Sans|Questrial|Quicksand|Raleway|Righteous|Roboto|Roboto+Condensed|Roboto+Slab|Rokkitt|Ropa+Sans|Russo+One|Sanchez|Satisfy|Shadows+Into+Light|Sigmar+One|Signika|Six+Caps|Slabo+27px|Source+Sans+Pro|Squada+One|Tangerine|Tinos|Titillium+Web|Ubuntu|Ubuntu+Condensed|Varela+Round|Vollkorn|Voltaire|Yanone+Kaffeesatz', array(), null);
}

add_action('customize_controls_print_styles', 'event_listing_customizer_fonts');
add_action('customize_preview_init', 'event_listing_customizer_fonts');

add_action( 'customize_controls_print_styles', 'event_listing_customize_controls_print_styles');
if (!function_exists('event_listing_customize_controls_print_styles')) :
    function event_listing_customize_controls_print_styles() {
        ?>
        <style>
            <?php
            $arr = array( 'ABeeZee','Abel','Abril+Fatface','Aldrich','Alegreya','Alex+Brush','Alfa+Slab+One','Amaranth','Andada','Anton','Archivo+Black','Archivo+Narrow','Arimo','Arimo','Arvo','Asap','Bangers','BenchNine','Bevan','Bitter','Bree+Serif','Cabin','Cabin+Condensed','Cantarell','Carme','Cherry+Cream+Soda','Cinzel','Comfortaa','Cookie','Covered+By+Your+Grace','Crete+Round','Crimson+Text','Cuprum','Dancing+Script','Didact+Gothic','Droid+Sans','Domine','Dosis','Droid+Serif','Economica','EB+Garamond','Exo','Exo','Fira+Sans','Fjalla+One','Francois+One','Fredericka+the+Great','Fredoka+One','Fugaz+One','Great+Vibes','Handlee','Hammersmith+One','Hind','Inconsolata','Indie+Flower','Istok+Web','Josefin+Sans','Josefin+Slab','Jura','Karla','Kaushan+Script','Kreon','Lateef','Lato','Lato','Libre+Baskerville','Limelight','Lobster','Lobster+Two','Lora','Maven+Pro','Merriweather','Merriweather+Sans','Monda','Montserrat','Muli','News+Cycle','Noticia+Text','Noto+Sans','Noto+Serif','Nunito','Old+Standard +TT','Open+Sans','Open+Sans+Condensed','Oswald','Oxygen','Pacifico','Passion+One','Passion One','Pathway+Gothic+One','Patua+One','Poiret+One','Pontano+Sans','Play','Playball','Playfair+Display','Prata','PT+Sans','PT+Sans+Caption','PT+Sans+Narrow','PT+Serif','Quattrocento+Sans','Questrial','Quicksand','Raleway','Righteous','Roboto','Roboto+Condensed','Roboto+Slab','Rokkitt','Ropa+Sans','Russo+One','Sanchez','Satisfy','Shadows+Into+Light','Sigmar+One','Signika','Six+Caps','Slabo+27px','Source+Sans+Pro','Squada+One','Tangerine','Tinos','Titillium+Web','Ubuntu','Ubuntu+Condensed','Varela+Round','Vollkorn','Voltaire','Yanone+Kaffeesatz');

            foreach ( $arr as $font ) {
                $font_family = str_replace("+", " ", $font);
                echo '.customize-control select option[value*="' . $font . '"] {font-family: ' . $font_family . '; font-size: 22px;}';
            }
            ?>
        </style>
        <?php
    }
endif;

/**
 * Recommended plugins
 *
 * @package Event Listing
 */

if (!function_exists('event_listing_recommended_plugins')) :

    /**
     * Recommend plugins.
     *
     * @since 1.0.0
     */
    function event_listing_recommended_plugins()
    {

        $plugins = array(
            array(
                'name' => __('WP Event Manager', 'event-listing'),
                'slug' => 'wp-event-manager',
                'required' => false,
            ),
        );

        tgmpa($plugins);

    }

endif;

add_action('tgmpa_register', 'event_listing_recommended_plugins');


/**
 * Checkbox sanitization callback example.
 *
 * Sanitization callback for 'checkbox' type controls. This callback sanitizes `$checked`
 * as a boolean value, either TRUE or FALSE.
 *
 * @param bool $checked Whether the checkbox is checked.
 * @return bool Whether the checkbox is checked.
 */
function event_listing_sanitize_checkbox($checked)
{
    // Boolean check.
    return ((isset($checked) && true == $checked) ? true : false);
}

/**
 * Select sanitization callback example.
 *
 * - Sanitization: select
 * - Control: select, radio
 *
 * Sanitization callback for 'select' and 'radio' type controls. This callback sanitizes `$input`
 * as a slug, and then validates `$input` against the choices defined for the control.
 *
 * @see sanitize_key()               https://developer.wordpress.org/reference/functions/sanitize_key/
 * @see $wp_customize->get_control() https://developer.wordpress.org/reference/classes/wp_customize_manager/get_control/
 *
 * @param string $input Slug to sanitize.
 * @param WP_Customize_Setting $setting Setting instance.
 * @return string Sanitized slug if it is a valid choice; otherwise, the setting default.
 */
function event_listing_sanitize_select($input, $setting)
{

    // Ensure input is a slug.
    $input = sanitize_key($input);

    // Get list of choices from the control associated with the setting.
    $choices = $setting->manager->get_control($setting->id)->choices;

    // If the input is a valid key, return it; otherwise, return the default.
    return (array_key_exists($input, $choices) ? $input : $setting->default);

}

/**
 * Select sanitization callback  for fonts example.
 *
 * - Sanitization: select
 * - Control: select, radio
 *
 * Sanitization callback for 'select' and 'radio' type controls. This callback sanitizes `$input`
 * as a slug, and then validates `$input` against the choices defined for the control.
 *
 * @see sanitize_key()               https://developer.wordpress.org/reference/functions/sanitize_key/
 * @see $wp_customize->get_control() https://developer.wordpress.org/reference/classes/wp_customize_manager/get_control/
 *
 * @param string $input Slug to sanitize.
 * @param WP_Customize_Setting $setting Setting instance.
 * @return string Sanitized slug if it is a valid choice; otherwise, the setting default.
 */
function event_listing_font_select($input, $setting)
{

    // Get list of choices from the control associated with the setting.
    $choices = $setting->manager->get_control($setting->id)->choices;

    // If the input is a valid key, return it; otherwise, return the default.
    return (array_key_exists($input, $choices) ? $input : $setting->default);

}

/**
 * Number Range sanitization callback example.
 *
 * - Sanitization: number_range
 * - Control: number, tel
 *
 * Sanitization callback for 'number' or 'tel' type text inputs. This callback sanitizes
 * `$number` as an absolute integer within a defined min-max range.
 *
 * @see absint() https://developer.wordpress.org/reference/functions/absint/
 *
 * @param int $number Number to check within the numeric range defined by the setting.
 * @param WP_Customize_Setting $setting Setting instance.
 * @return int|string The number, if it is zero or greater and falls within the defined range; otherwise,
 *                    the setting default.
 */
function event_listing_sanitize_number_range($number, $setting)
{

    // Ensure input is an absolute integer.
    $number = absint($number);

    // Get the input attributes associated with the setting.
    $atts = $setting->manager->get_control($setting->id)->input_attrs;

    // Get minimum number in the range.
    $min = (isset($atts['min']) ? $atts['min'] : $number);

    // Get maximum number in the range.
    $max = (isset($atts['max']) ? $atts['max'] : $number);

    // Get step.
    $step = (isset($atts['step']) ? $atts['step'] : 1);

    // If the number is within the valid range, return it; otherwise, return the default
    return ($min <= $number && $number <= $max && is_int($number / $step) ? $number : $setting->default);
}

/**
 * Add custom class in body
 *
 * @since Event Listing 1.0.0
 *
 */

add_filter('body_class', 'event_listing_custom_class');
if (!function_exists('event_listing_custom_class')) :
    function event_listing_custom_class($classes)
    {
        global $event_listing_theme_options;
        if(empty($event_listing_theme_options))
            return;

        $layout = $event_listing_theme_options['event-listing-full-boxed'];
        $classes[] = esc_attr($event_listing_theme_options['event-listing-site-sidebar']);
        $classes[] = esc_attr($event_listing_theme_options['event-listing-mobile-sidebar']);
        if ($layout == 'boxed') {
            $classes[] = 'boxed-layout';
        }
        return $classes;
    }
endif;

/**
 * Add sidebar
 *
 * @since Event Listing 1.0.0
 *
 */

add_filter('event_listing_sidebar', 'event_listing_sidebar');
if (!function_exists('event_listing_sidebar')) :
    function event_listing_sidebar()
    {
        global $event_listing_theme_options;
        $sidebar = $event_listing_theme_options['event-listing-site-sidebar'];
        //displays sidebar only if it is left and right sidebar
        if ($sidebar != 'no-sidebar') {
            echo '<div class="column column-12 column-t-3 secondary-content-area">';
            get_sidebar();
            echo '</div>';
        }
    }

endif;

/**
 * Returns Class to Primary Column
 *
 * @since Event Listing 1.0.0
 *
 */

if (!function_exists('event_listing_primary_column_class')) :
    function event_listing_primary_column_class()
    {
        global $event_listing_theme_options;
        $sidebar = $event_listing_theme_options['event-listing-site-sidebar'];
        //displays sidebar only if it is left and right sidebar
        if ($sidebar != 'no-sidebar') {
            $primary_class = 'column column-12 column-t-9 primary-content-area';
        } else {
            $primary_class = 'column column-12 primary-content-area';
        }
        return $primary_class;
    }
endif;

/**
 * Function to modify tag clouds font size
 *
 * @param none
 * @return array $args
 *
 * @since 1.0.0
 *
 */
if (!function_exists('event_listing_tag_cloud_widget')) :
    function event_listing_tag_cloud_widget($args)
    {
        $args['largest'] = 14; //largest tag
        $args['smallest'] = 14; //smallest tag
        $args['unit'] = 'px'; //tag font unit
        return $args;
    }
endif;
add_filter('widget_tag_cloud_args', 'event_listing_tag_cloud_widget');


/**
 * Remove ... From Excerpt
 *
 * @since 1.0.0
 *
 */
if (!function_exists('event_listing_excerpt_more')) :
    function event_listing_excerpt_more($more)
    {
        if (!is_admin()) {
            return '';
        }
    }
endif;
add_filter('excerpt_more', 'event_listing_excerpt_more');
