$type, 'language' => $atts['language'] ?? 'en', 'timezone' => $atts['timezone'] ?? 0, 'showLink' => array_key_exists('showlink', $atts) ? (int)icalendrier_is_on($atts['showlink']) : 1, 'showMoon' => array_key_exists('moonphases', $atts) ? (int)icalendrier_is_on($atts['moonphases']) : 1, 'showNameDay' => array_key_exists('namedays', $atts) ? (int)icalendrier_is_on($atts['namedays']) : 1, 'bgColor' => $atts['bgcolor'] ?? false, 'style' => $atts['style'] ?? 'default', 'widgetTitle' => $atts['widgettitle'] ?? '', ]; } /** * Legacy name (with its typo) kept for third parties that may call it. * * @deprecated 1.9 Use icalendrier_get_attributes(). */ function getAttibutes($atts) { return icalendrier_get_attributes($atts); } /** * Reads a checkbox or shortcode flag: "on", "1", "true", "yes" and true mean on; everything else off. * * @param mixed $value */ function icalendrier_is_on($value): bool { if (is_bool($value)) { return $value; } return in_array(strtolower(trim((string)$value)), ['on', '1', 'true', 'yes'], true); } /** * Render the calendar for parsed attributes (see icalendrier_get_attributes()). */ function icalendrier_render(array $attributes): string { $iCalendrier = new Icalendrier($attributes['language'], $attributes['timezone']); if ('modern' === $attributes['calType']) { wp_enqueue_style('icalendrier-modern', plugins_url('/css/icalendrier-modern.css', __FILE__), array(), ICALENDRIER_VERSION, 'all'); return $iCalendrier->iCalendrierModern($attributes); } if ('wide300' === $attributes['calType']) { return $iCalendrier->iCalendrierWide($attributes); } return $iCalendrier->iCalendrierComp($attributes); } // Shortcode add_shortcode('icalendrier', 'icalendrier_shortcode'); function icalendrier_shortcode($atts) { return icalendrier_render(icalendrier_get_attributes($atts)); } /** * Class ICalendrier */ class ICalendrierWidget extends WP_Widget { /** * ICalendrierWidget constructor. */ public function __construct() { parent::__construct('icalendrier_widget', 'iCalendrier Widget', [ 'classname' => 'calendar', 'description' => 'Simple daily calendar' ]); } /** * @param $args * @param $instance */ public function widget($args, $instance) { $attributes = icalendrier_get_attributes($instance); $title = apply_filters('widget_title', $attributes['widgetTitle'], $instance, $this->id_base); echo $args['before_widget'] ?? ''; if ('' !== $title) { echo ($args['before_title'] ?? '') . $title . ($args['after_title'] ?? ''); } echo icalendrier_render($attributes); echo $args['after_widget'] ?? ''; } /** * @param $new_instance * @param $old_instance * * @return mixed */ public function update($new_instance, $old_instance) { $instance = $old_instance; foreach (['type', 'language', 'timezone', 'widgetTitle', 'bgColor', 'style'] as $key) { $instance[$key] = wp_strip_all_tags((string)($new_instance[$key] ?? '')); } // An unchecked checkbox is absent from the submitted form: that means off. $instance['showLink'] = (int)icalendrier_is_on($new_instance['showLink'] ?? ''); $instance['moonphases'] = (int)icalendrier_is_on($new_instance['moonphases'] ?? ''); $instance['namedays'] = (int)icalendrier_is_on($new_instance['namedays'] ?? ''); return $instance; } /** * @param $instance */ public function form($instance) { $type = isset($instance['type']) ? esc_attr($instance['type']) : "modern"; // new widgets get the modern layout $language = isset($instance['language']) ? esc_attr($instance['language']) : "en"; $timezone = isset($instance['timezone']) ? esc_attr((string)$instance['timezone']) : '0'; $widgetTitle = isset($instance['widgetTitle']) ? esc_attr($instance['widgetTitle']) : ""; $showLink = isset($instance['showLink']) ? icalendrier_is_on($instance['showLink']) : true; $showMoon = isset($instance['moonphases']) ? icalendrier_is_on($instance['moonphases']) : true; $showNameDay = isset($instance['namedays']) ? icalendrier_is_on($instance['namedays']) : true; $bgColor = isset($instance['bgColor']) ? esc_attr($instance['bgColor']) : ""; $style = isset($instance['style']) ? esc_attr($instance['style']) : "default"; ?>
/>
/>
/>