Lorenzo Orlando Caum
|
September 8, 2020 at 12:20 pm
__( 'Toon Letslunch bijeenkomsten via een widget.', 'event_espresso' )),
array(
'width' => 300,
'height' => 350,
'id_base' => 'ee-upcoming-events-widget'
)
);
}
/**
* Back-end widget form.
*
* @see WP_Widget::form()
* @param array $instance Previously saved values from database.
* @return string|void
*/
public function form( $instance ) {
EE_Registry::instance()->load_helper( 'Form_Fields' );
EE_Registry::instance()->load_class( 'Question_Option', array(), FALSE, FALSE, TRUE );
// Set up some default widget settings.
$defaults = array(
'title' => __('Upcoming Events', 'event_espresso'),
'category_name' => '',
'show_expired' => FALSE,
'show_desc' => TRUE,
'show_dates' => TRUE,
'show_everywhere' => FALSE,
'date_limit' => 2,
'limit' => 10,
'date_range' => FALSE,
'image_size' => 'medium'
);
$instance = wp_parse_args( (array) $instance, $defaults );
// don't add HTML labels for EE_Form_Fields generated inputs
add_filter( 'FHEE__EEH_Form_Fields__label_html', '__return_empty_string' );
$yes_no_values = array(
EE_Question_Option::new_instance( array( 'QSO_value' => FALSE, 'QSO_desc' => __('No', 'event_espresso'))),
EE_Question_Option::new_instance( array( 'QSO_value' => TRUE, 'QSO_desc' => __('Yes', 'event_espresso')))
);
?>
<label for="get_field_id('title'); ?>">
<input id="get_field_id('title'); ?>" class="widefat" name="get_field_name('title'); ?>" value="" type="text" />
<label for="get_field_id('category_name'); ?>">
load_model( 'Term' );
$categories = $EEM_Term->get_all_ee_categories( TRUE );
if ( $categories ) {
foreach ( $categories as $category ) {
if ( $category instanceof EE_Term ) {
$event_categories[] = EE_Question_Option::new_instance( array( 'QSO_value' => $category->get( 'slug' ), 'QSO_desc' => $category->get( 'name' )));
}
}
}
array_unshift( $event_categories, EE_Question_Option::new_instance( array( 'QSO_value' => '', 'QSO_desc' => __(' - display all - ', 'event_espresso'))));
echo EEH_Form_Fields::select(
__('Event Category:', 'event_espresso'),
$instance['category_name'],
$event_categories,
$this->get_field_name('category_name'),
$this->get_field_id('category_name')
);
?>
<label for="get_field_id('limit'); ?>">
<input id="get_field_id('limit'); ?>" name="get_field_name('limit'); ?>" value="" size="3" type="text" />
<label for="get_field_id('show_expired'); ?>">
get_field_name('show_expired'),
$this->get_field_id('show_expired')
);
?>
<label for="get_field_id('image_size'); ?>">
$image_size, 'QSO_desc' => $image_size ));
}
}
$image_sizes[] = EE_Question_Option::new_instance( array( 'QSO_value' => 'none', 'QSO_desc' => __('don\'t show images', 'event_espresso') ));
}
echo EEH_Form_Fields::select(
__('Image Size:', 'event_espresso'),
$instance['image_size'],
$image_sizes,
$this->get_field_name('image_size'),
$this->get_field_id('image_size')
);
?>
<label for="get_field_id('show_desc'); ?>">
get_field_name('show_desc'),
$this->get_field_id('show_desc')
);
?>
<label for="get_field_id('show_dates'); ?>">
get_field_name('show_dates'),
$this->get_field_id('show_dates')
);
?>
<label for="get_field_id('show_everywhere'); ?>">
get_field_name('show_everywhere'),
$this->get_field_id('show_everywhere')
);
?>
<label for="get_field_id('date_limit'); ?>">
<input id="get_field_id('date_limit'); ?>" name="get_field_name('date_limit'); ?>" value="" size="3" type="text" />
<label for="get_field_id('date_range'); ?>">
get_field_name('date_range'),
$this->get_field_id('date_range')
);
?>
post_type == 'espresso_events' && is_archive() )) {
// let's use some of the event helper functions'
EE_Registry::instance()->load_helper( 'Event_View' );
// make separate vars out of attributes
extract($args);
// add function to make the title a link
add_filter('widget_title', array($this, 'make_the_title_a_link'), 15);
// filter the title
$title = apply_filters('widget_title', $instance['title']);
// remove the function from the filter, so it does not affect other widgets
remove_filter('widget_title', array($this, 'make_the_title_a_link'), 15);
// Before widget (defined by themes).
echo $before_widget;
// Display the widget title if one was input (before and after defined by themes).
if ( ! empty( $title )) {
echo $before_title . $title . $after_title;
}
// grab widget settings
$category = isset( $instance['category_name'] ) && ! empty( $instance['category_name'] ) ? $instance['category_name'] : FALSE;
$show_expired = isset( $instance['show_expired'] ) ? (bool) absint( $instance['show_expired'] ) : FALSE;
$image_size = isset( $instance['image_size'] ) && ! empty( $instance['image_size'] ) ? $instance['image_size'] : 'medium';
$show_desc = isset( $instance['show_desc'] ) ? (bool) absint( $instance['show_desc'] ) : TRUE;
$show_dates = isset( $instance['show_dates'] ) ? (bool) absint( $instance['show_dates'] ) : TRUE;
$date_limit = isset( $instance['date_limit'] ) && ! empty( $instance['date_limit'] ) ? $instance['date_limit'] : NULL;
$date_range = isset( $instance['date_range'] ) && ! empty( $instance['date_range'] ) ? $instance['date_range'] : FALSE;
// start to build our where clause
$where = array(
// 'Datetime.DTT_is_primary' => 1,
'status' => 'publish'
);
// add category
if ( $category ) {
$where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
$where['Term_Taxonomy.Term.slug'] = $category;
}
// if NOT expired then we want events that start today or in the future
if ( ! $show_expired ) {
$where['Datetime.DTT_EVT_end'] = array( '>=', current_time( 'mysql' ));
}
// run the query
$events = EE_Registry::instance()->load_model( 'Event' )->get_all( array(
$where,
'limit' => $instance['limit'] > 0 ? '0,' . $instance['limit'] : '0,10',
'order_by' => 'Datetime.DTT_EVT_start',
'order' => 'ASC',
'group_by' => 'EVT_ID'
));
if ( ! empty( $events )) {
echo '';
}
// After widget (defined by themes).
echo $after_widget;
}
}
}
/**
* make_the_title_a_link
* callback for widget_title filter
*
* @param $title
* @return string
*/
public function make_the_title_a_link($title) {
return '' . $title . '';
}
}
// End of file EEW_Upcoming_Events.widget.php
// Location: /widgets/upcoming_events/EEW_Upcoming_Events.widget.php
|