*/ class MEC_MEC_widget extends WP_Widget { /** * @var MEC_render */ public $render; /** * @var MEC_main */ public $main; /** * Constructor method * @author Webnus */ public function __construct() { // MEC Render Class $this->render = MEC::getInstance('app.libraries.render'); // MEC Main Class $this->main = MEC::getInstance('app.libraries.main'); parent::__construct('MEC_MEC_widget', esc_html__('Modern Events Calendar', 'modern-events-calendar-lite'), array('description'=>__('Show events based on created shortcodes.', 'modern-events-calendar-lite'))); } /** * How to display the widget on the screen. * @param array $args * @param array $instance * @author Webnus * @return void */ public function widget($args, $instance) { // Include OWL Assets. It's needed if Widget is set to load grid view $this->main->load_owl_assets(); // Before Widget echo $args['before_widget'] ?? ''; // Print the widget title if(!empty($instance['title'])) { echo ($args['before_title'] ?? '').apply_filters('widget_title', $instance['title']).($args['after_title'] ?? ''); } $calendar_id = $instance['calendar_id'] ?? 0; // Get Skin Options $sk_options = get_post_meta($calendar_id, 'sk-options', true); $sk_options_list_style = (isset($sk_options['list']) and isset($sk_options['list']['style'])) ? trim($sk_options['list']['style']) : 'classic'; $current_hide = $instance['current_hide'] ?? ''; $autoplay = $instance['autoplay'] ?? 1; $autoplay_time = $instance['autoplay_time'] ?? 3000; $loop = $instance['loop'] ?? 1; // Print the skin output echo MEC_kses::full($this->render->widget($calendar_id, array( 'html-class'=>'mec-widget '.$current_hide, 'style'=>$sk_options_list_style, 'widget'=>true, 'widget_autoplay'=>$autoplay, 'widget_loop'=>$loop, 'widget_autoplay_time'=>$autoplay_time, ))); // After Widget echo $args['after_widget'] ?? ''; } /** * Displays the widget settings controls on the widget panel. * @param array $instance * @author Webnus * @return void */ public function form($instance) { $calendars = get_posts(array('post_type'=>'mec_calendars', 'posts_per_page'=>'-1', 'meta_query'=>array(array('key'=>'skin', 'value'=>array('list', 'grid', 'monthly_view'), 'compare'=>'IN')))); $current_hide = $instance['current_hide'] ?? ''; $autoplay = $instance['autoplay'] ?? 1; $autoplay_time = $instance['autoplay_time'] ?? 3000; $loop = $instance['loop'] ?? 1; $monthly_view_options = false; $grid_view_options = false; echo '

' .'' .'' .'

'; if(count($calendars)) { echo '

' .'' .'

'; // Monthly View Options echo '

'; // Grid Options echo '

'; } else { echo '

'.esc_html__('Create some calendars first.').'

'; } } /** * Update the widget settings. * @author Webnus * @param array $new_instance * @param array $old_instance * @return array */ public function update($new_instance, $old_instance) { $instance = []; $instance['title'] = isset($new_instance['title']) ? strip_tags($new_instance['title']) : ''; $instance['calendar_id'] = isset($new_instance['calendar_id']) ? intval($new_instance['calendar_id']) : 0; $instance['current_hide'] = isset($new_instance['current_hide']) ? strip_tags($new_instance['current_hide']) : ''; $instance['autoplay'] = isset($new_instance['autoplay']) ? sanitize_text_field($new_instance['autoplay']) : 0; $instance['autoplay_time'] = isset($new_instance['autoplay_time']) ? sanitize_text_field($new_instance['autoplay_time']) : 3000; $instance['loop'] = isset($new_instance['loop']) ? sanitize_text_field($new_instance['loop']) : 0; return $instance; } }