| @@ -6,8 +6,12 @@ | ||
| 6 | 6 | * |
| 7 | 7 | * @package automattic/jetpack |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 11 | + exit( 0 ); | |
| 12 | +} | |
| 13 | + | |
| 10 | 14 | // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files. |
| 11 | 15 | |
| 12 | 16 | /** |
| 13 | 17 | * Register the widget. |
| @@ -59,9 +63,9 @@ | ||
| 59 | 63 | * Displays the form for this widget on the Widgets page of the WP Admin area. |
| 60 | 64 | * |
| 61 | 65 | * @param array $instance Instance configuration. |
| 62 | 66 | * |
| 63 | - * @return void | |
| 67 | + * @return string|void | |
| 64 | 68 | */ |
| 65 | 69 | public function form( $instance ) { |
| 66 | 70 | $defaults = array( |
| 67 | 71 | 'title' => __( 'Upcoming Events', 'jetpack' ), |
| @@ -84,9 +88,9 @@ | ||
| 84 | 88 | <p> |
| 85 | 89 | <label for="<?php echo esc_attr( $this->get_field_id( 'count' ) ); ?>"><?php esc_html_e( 'Items to show:', 'jetpack' ); ?></label> |
| 86 | 90 | <select id="<?php echo esc_attr( $this->get_field_id( 'count' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'count' ) ); ?>"> |
| 87 | 91 | <?php for ( $i = 1; $i <= 10; $i++ ) { ?> |
| 88 | - <option <?php selected( $instance['count'], $i ); ?>><?php echo (int) $i; ?></option> | |
| 92 | + <option <?php selected( $instance['count'], $i ); ?>><?php echo esc_html( (string) $i ); ?></option> | |
| 89 | 93 | <?php } ?> |
| 90 | 94 | <option value="0" <?php selected( $instance['count'], 0 ); ?>><?php esc_html_e( 'All', 'jetpack' ); ?></option> |
| 91 | 95 | </select> |
| 92 | 96 | </p> |
| @@ -119,11 +123,14 @@ | ||
| 119 | 123 | */ |
| 120 | 124 | public function widget( $args, $instance ) { |
| 121 | 125 | require_once JETPACK__PLUGIN_DIR . '/_inc/lib/icalendar-reader.php'; |
| 122 | 126 | |
| 123 | - $ical = new iCalendarReader(); | |
| 124 | - $events = $ical->get_events( $instance['feed-url'], $instance['count'] ); | |
| 125 | - $events = $this->apply_timezone_offset( $events ); | |
| 127 | + $ical = new iCalendarReader(); | |
| 128 | + $events = array(); | |
| 129 | + if ( ! empty( $instance['feed-url'] ) ) { | |
| 130 | + $events = $ical->get_events( $instance['feed-url'], $instance['count'] ); | |
| 131 | + $events = $this->apply_timezone_offset( $events ); | |
| 132 | + } | |
| 126 | 133 | $ical->timezone = null; |
| 127 | 134 | |
| 128 | 135 | echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 129 | 136 | if ( ! empty( $instance['title'] ) ) { |
| @@ -131,20 +138,26 @@ | ||
| 131 | 138 | echo esc_html( $instance['title'] ); |
| 132 | 139 | echo $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 133 | 140 | } |
| 134 | 141 | |
| 135 | - if ( ! $events ) : // nothing to display? | |
| 142 | + if ( empty( $instance['feed-url'] ) ) { | |
| 143 | + if ( current_user_can( 'manage_options' ) ) { | |
| 144 | + echo '<div class="error-message">'; | |
| 145 | + esc_html_e( 'The events feed URL is not properly set up in this widget.', 'jetpack' ); | |
| 146 | + echo '</div>'; | |
| 147 | + } | |
| 148 | + } elseif ( ! $events ) { | |
| 149 | + echo '<p>'; | |
| 150 | + esc_html_e( 'No upcoming events', 'jetpack' ); | |
| 151 | + echo '</p>'; | |
| 152 | + } else { | |
| 136 | 153 | ?> |
| 137 | - <p><?php esc_html_e( 'No upcoming events', 'jetpack' ); ?></p> | |
| 138 | - <?php | |
| 139 | - else : | |
| 140 | - ?> | |
| 141 | 154 | <ul class="upcoming-events"> |
| 142 | 155 | <?php foreach ( $events as $event ) : ?> |
| 143 | 156 | <li> |
| 144 | 157 | <strong class="event-summary"> |
| 145 | 158 | <?php |
| 146 | - echo $ical->escape( stripslashes( $event['SUMMARY'] ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- this method is built to escape. | |
| 159 | + echo $ical->escape( stripslashes( $event['SUMMARY'] ?? '' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- this method is built to escape. | |
| 147 | 160 | ?> |
| 148 | 161 | </strong> |
| 149 | 162 | <span class="event-when"><?php echo esc_html( $ical->formatted_date( $event ) ); ?></span> |
| 150 | 163 | <?php if ( ! empty( $event['LOCATION'] ) ) : ?> |
| @@ -164,9 +177,9 @@ | ||
| 164 | 177 | </li> |
| 165 | 178 | <?php endforeach; ?> |
| 166 | 179 | </ul> |
| 167 | 180 | <?php |
| 168 | - endif; | |
| 181 | + } | |
| 169 | 182 | |
| 170 | 183 | echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 171 | 184 | |
| 172 | 185 | /** This action is documented in modules/widgets/gravatar-profile.php */ |