| Server IP : 172.67.201.108 / Your IP : 216.73.216.11 Web Server : Apache/2.4.68 (Amazon Linux) OpenSSL/3.5.5 System : Linux ip-172-31-69-123.ec2.internal 6.1.176-223.369.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Jul 24 13:34:27 UTC 2026 x86_64 User : ec2-user ( 1000) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/tgnew/wp-content/plugins/em-sidebar/ |
Upload File : |
<?php
/**
* @author Sam Later
* Event categories in sidebar widget
*/
class EM_Widget_Category extends WP_Widget {
var $defaults;
/** constructor */
function __construct() {
$this->defaults = array(
'title' => __('Event Categories','dbem'),
'scope' => 'future',
'order' => 'ASC',
'limit' => 5,
'category' => 0,
'format' => '#_EVENTLINK<ul><li>#_EVENTDATES</li><li>#_LOCATIONTOWN</li></ul>',
'nolistwrap' => false,
'orderby' => 'event_start_date,event_start_time,event_name',
'bottom_link' => 0,
'bottom_link_text' => __('bottom link text', 'dbem'),
'bottom_link_url' => __('bottom link url', 'dbem'),
'no_events_text' => __('No events', 'dbem')
);
$this->em_orderby_options = apply_filters('em_settings_events_default_orderby_ddm', array(
'event_start_date,event_start_time,event_name' => __('start date, start time, event name','dbem'),
'event_name,event_start_date,event_start_time' => __('name, start date, start time','dbem'),
'event_name,event_end_date,event_end_time' => __('name, end date, end time','dbem'),
'event_end_date,event_end_time,event_name' => __('end date, end time, event name','dbem'),
));
$widget_ops = array('description' => __( "Display a list of event categories on Events Manager.", 'dbem') );
//parent::WP_Widget(false, $name = 'Event Categories', $widget_ops);
parent::__construct(false, 'Event Categories', $widget_ops);
}
/** @see WP_Widget::widget */
function widget($args, $instance) {
$instance = array_merge($this->defaults, $instance);
$instance = $this->fix_scope($instance); // depcreciate
echo $args['before_widget'];
if( !empty($instance['title']) ){
echo $args['before_title'];
echo apply_filters('widget_title',$instance['title'], $instance, $this->id_base);
echo $args['after_title'];
}
//echo EM_Categories::output(array('scope'=>'future', 'limit'=>10, 'pagination'=>1, 'country'=>'US', 'eventful'=>1));
$categories = EM_Categories::get(array('orderby'=>'name'));
echo '<ul>';
if (count($categories) > 0) :
foreach($categories as $category) :
//var_dump($category);
$events = EM_Events::get(array('scope'=>'future', 'limit'=>99999, 'category'=>$category->id));
$count = count($events);
if ($count > 0) :
echo '<li><a href="'.get_bloginfo('url').'/events/categories/'.$category->slug.'/">'.$category->name.'</a> ('.$count.')</li>';
//echo '<li><a href="'.get_category_link($category->id).'">'.$category->name.' - '.$category->id.'</a> ('.$count.')</li>';
//echo '<li>'.$category->output($instance['format']).' ('.$count.')</li>';
endif;
endforeach;
endif;
//echo '</ul>';
$instance['owner'] = false;
//orderby fix for previous versions with old orderby values
if( !array_key_exists($instance['orderby'], $this->em_orderby_options) ){
//replace old values
$old_vals = array(
'name' => 'event_name',
'end_date' => 'event_end_date',
'start_date' => 'event_start_date',
'end_time' => 'event_end_time',
'start_time' => 'event_start_time'
);
foreach($old_vals as $old_val => $new_val){
$instance['orderby'] = str_replace($old_val, $new_val, $instance['orderby']);
}
}
/*
$events = EM_Events::get(apply_filters('em_widget_events_get_args',$instance));
echo "<ul>";
$li_wrap = !preg_match('/^<li>/i', trim($instance['format']));
if ( count($events) > 0 ){
foreach($events as $event){
if( $li_wrap ){
echo '<li>'. $event->output($instance['format']) .'</li>';
}else{
echo $event->output($instance['format']);
}
}
}else{
echo '<li>'.$instance['no_events_text'].'</li>';
}
*/
if ( !empty($instance['bottom_link']) ):
$bottom_text = (!empty($instance['bottom_link_text']) ? $instance['bottom_link_text'] : '');
$bottom_link = (!empty($instance['bottom_link_url']) ? $instance['bottom_link_url'] : '');
echo '<li><a href="'.get_bloginfo('url').'/'.$bottom_link.'">'.$bottom_text.'</a></li>';
endif;
echo "</ul>";
echo $args['after_widget'];
}
/** @see WP_Widget::update */
function update($new_instance, $old_instance) {
foreach($this->defaults as $key => $value){
if( !isset($new_instance[$key]) ){
$new_instance[$key] = $value;
}
}
return $new_instance;
}
/** @see WP_Widget::form */
function form($instance) {
$instance = array_merge($this->defaults, $instance);
$instance = $this->fix_scope($instance); // depcreciate
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title', 'dbem'); ?>: </label>
<input type="text" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr($instance['title']); ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('bottom_link'); ?>"><?php _e('Show extra link at bottom?','dbem'); ?>: </label>
<input type="checkbox" id="<?php echo $this->get_field_id('bottom_link'); ?>" name="<?php echo $this->get_field_name('bottom_link'); ?>" <?php echo (!empty($instance['bottom_link']) && $instance['bottom_link']) ? 'checked':''; ?> >
</p>
<p>
<label for="<?php echo $this->get_field_id('bottom_link_url'); ?>"><?php _e('Bottom link URL','dbem'); ?>: </label>
<input type="text" id="<?php echo $this->get_field_id('bottom_link_url'); ?>" name="<?php echo $this->get_field_name('bottom_link_url'); ?>" value="<?php echo (!empty($instance['bottom_link_url'])) ? $instance['bottom_link_url']:__('bottom link','dbem'); ?>" >
</p>
<p>
<label for="<?php echo $this->get_field_id('bottom_link_text'); ?>"><?php _e('Bottom link text','dbem'); ?>: </label>
<input type="text" id="<?php echo $this->get_field_id('bottom_link_text'); ?>" name="<?php echo $this->get_field_name('bottom_link_text'); ?>" value="<?php echo (!empty($instance['bottom_link_text'])) ? $instance['bottom_link_text']:__('bottom link','dbem'); ?>" >
</p>
<p>
<label for="<?php echo $this->get_field_id('no_events_text'); ?>"><?php _e('No events text','dbem'); ?>: </label>
<input type="text" id="<?php echo $this->get_field_id('no_events_text'); ?>" name="<?php echo $this->get_field_name('no_events_text'); ?>" value="<?php echo (!empty($instance['no_events_text'])) ? $instance['no_events_text']:__('No events', 'dbem'); ?>" >
</p>
<?php
}
/**
* Backwards compatability for an old setting which is now just another scope.
* @param unknown_type $instance
* @return string
*/
function fix_scope($instance){
if( !empty($instance['time_limit']) && is_numeric($instance['time_limit']) && $instance['time_limit'] > 1 ){
$instance['scope'] = $instance['time_limit'].'-months';
}elseif( !empty($instance['time_limit']) && $instance['time_limit'] == 1){
$instance['scope'] = 'month';
}elseif( !empty($instance['time_limit']) && $instance['time_limit'] == 'no-limit'){
$instance['scope'] = 'all';
}
return $instance;
}
}
//add_action('widgets_init', create_function('', 'return register_widget("EM_Widget_Category");'));
add_action('widgets_init',
function() {
register_widget('EM_Widget_Category');
}
);