Your IP : 216.73.216.196


Current Path : /home/icmq6107/clients/naddaf/wp-content/themes/crowdngo/inc/vendors/simple-event/
Upload File :
Current File : /home/icmq6107/clients/naddaf/wp-content/themes/crowdngo/inc/vendors/simple-event/functions.php

<?php

if ( !function_exists('crowdngo_get_events') ) {
    function crowdngo_get_events( $args = array() ) {

        $args = wp_parse_args( $args, array(
            'categories' => array(),
            'event_type' => 'recent',
            'paged' => 1,
            'limit' => -1,
            'orderby' => '',
            'order' => '',
            'includes' => array(),
            'excludes' => array(),
            'author' => '',
            'fields' => '', // ids
            'name' => ''
        ));
        extract($args);
        
        $query_args = array(
            'post_type' => 'simple_event',
            'posts_per_page' => $limit,
            'post_status' => 'publish',
            'paged' => $paged,
            'orderby'   => $orderby,
            'order' => $order
        );

        switch ($event_type) {
            case 'recent':
                $query_args['orderby'] = 'date';
                $query_args['order'] = 'DESC';
                break;
             case 'upcoming':
                $timezone  = get_option('gmt_offset');
                $time = current_time( 'mysql' );
                $query_args['meta_query'] = array(
                    array(
                        'key' => 'apussimpleevent_event_startdate',
                        'value' => $time,
                        'compare' => '>=',
                        'type' => 'DATE'
                    )
                );
                $query_args['meta_key'] = 'apussimpleevent_event_startdate';
                $query_args['orderby'] = 'meta_value';
                $query_args['order'] = 'ASC';
                break;
            case 'rand':
                $query_args['orderby'] = 'rand';
                break;
        }

        if ( !empty($categories) && is_array($categories) ) {
            $query_args['tax_query'][] = array(
                'taxonomy'      => 'simple_event_category',
                'field'         => 'slug',
                'terms'         => $categories,
                'operator'      => 'IN'
            );
        }

        if (!empty($name) ) {
            $query_args['name'] = $name;
        }
        
        if (!empty($includes) && is_array($includes)) {
            $query_args['post__in'] = $includes;
        }
        
        if ( !empty($excludes) && is_array($excludes) ) {
            $query_args['post__not_in'] = $excludes;
        }

        if ( !empty($author) ) {
            $query_args['author'] = $author;
        }

        if ( !empty($fields) ) {
            $query_args['fields'] = $fields;
        }
        $loop = new WP_Query($query_args);
        
        return $loop;
    }
}

function crowdngo_event_theme_folder($folder) {
    return "templates-event";
}
add_filter( 'apus-simple-event-theme-folder-name', 'crowdngo_event_theme_folder', 10 );

if ( !function_exists('crowdngo_event_content_class') ) {
    function crowdngo_event_content_class( $class ) {
        $prefix = 'events';
        if ( is_singular( 'simple_event' ) ) {
            $prefix = 'event';
        }
        if ( crowdngo_get_config($prefix.'_fullwidth') ) {
            return 'container-fluid';
        }
        return $class;
    }
}
add_filter( 'crowdngo_event_content_class', 'crowdngo_event_content_class', 1 , 1  );


if ( !function_exists('crowdngo_get_event_layout_configs') ) {
    function crowdngo_get_event_layout_configs() {
        $prefix = 'events';
        if ( is_singular( 'simple_event' ) ) {
            $prefix = 'event';
        }
        $left = crowdngo_get_config($prefix.'_left_sidebar');
        $right = crowdngo_get_config($prefix.'_right_sidebar');

        switch ( crowdngo_get_config($prefix.'_layout') ) {
            case 'left-main':
                if ( is_active_sidebar( $left ) ) {
                    $configs['left'] = array( 'sidebar' => $left, 'class' => 'col-md-4 col-sm-12 col-xs-12'  );
                    $configs['main'] = array( 'class' => 'col-md-8 col-sm-12 col-xs-12 pull-right' );
                }
                break;
            case 'main-right':
                if ( is_active_sidebar( $right ) ) {
                    $configs['right'] = array( 'sidebar' => $right,  'class' => 'col-md-4 col-sm-12 col-xs-12 pull-right' ); 
                    $configs['main'] = array( 'class' => 'col-md-8 col-sm-12 col-xs-12' );
                }
                break;
            case 'main':
                $configs['main'] = array( 'class' => 'col-md-12 col-sm-12 col-xs-12' );
                break;
            default:
                $configs['right'] = array( 'sidebar' => 'sidebar-default',  'class' => 'col-md-3 col-xs-12' ); 
                $configs['main'] = array( 'class' => 'col-md-9 col-xs-12' );
                break;
        }
        if ( empty($configs) ) {
            $configs['right'] = array( 'sidebar' => 'sidebar-default',  'class' => 'col-md-3 col-xs-12' ); 
            $configs['main'] = array( 'class' => 'col-md-9 col-xs-12' );
        }
        return $configs; 
    }
}

function crowdngo_event_metaboxes($fields, $prefix) {
    $fields[] = array(
        'name' => esc_html__( 'Price', 'crowdngo' ),
        'id'   => $prefix.'price',
        'type' => 'text',
        'desc'    => esc_html__('e.g. $100', 'crowdngo')
    );

    return $fields;
}
add_filter('apussimpleevent_postype_event_metaboxes_fields_management', 'crowdngo_event_metaboxes', 10, 2);

function crowdngo_event_map_api_key($key) {
    $key = crowdngo_get_config('google_map_api_key');
    return $key;
}
add_filter('apussimpleevent_map_api_key', 'crowdngo_event_map_api_key');


add_action( 'pre_get_posts', 'crowdngo_event_archive' );
add_action( 'pre_get_posts', 'crowdngo_event_taxonomy' );
function crowdngo_event_archive($query) {
    $suppress_filters = ! empty( $query->query_vars['suppress_filters'] ) ? $query->query_vars['suppress_filters'] : '';

    if ( ! is_post_type_archive( 'simple_event' ) || ! $query->is_main_query() || is_admin() || $query->query_vars['post_type'] != 'simple_event' || $suppress_filters ) {
        return;
    }

    $limit = crowdngo_get_config('number_events_per_page', 10);
    $query_vars = &$query->query_vars;
    $query_vars['posts_per_page'] = $limit;
    $query->query_vars = $query_vars;
    
    return $query;
}

function crowdngo_event_taxonomy($query) {
    $is_correct_taxonomy = false;
    if ( is_tax( 'simple_event_category' ) || is_tax( 'simple_event_tags' ) || apply_filters( 'wp-job-board-job-query-taxonomy', false ) ) {
        $is_correct_taxonomy = true;
    }

    if ( ! $is_correct_taxonomy  || ! $query->is_main_query() || is_admin() ) {
        return;
    }

    $limit = crowdngo_get_config('number_events_per_page', 10);
    $query_vars = $query->query_vars;
    $query_vars['posts_per_page'] = $limit;
    $query->query_vars = $query_vars;

    return $query;
}