Skip to content

Commit

Permalink
Merge branch 'rc-v2.3.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
cjg89 committed Mar 18, 2021
2 parents 878680c + e2fa55c commit 8ad744b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 30 deletions.
19 changes: 13 additions & 6 deletions includes/ucf-news-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static function apply_default_options( $list, $list_keys_only=false ) {

if ( $list_keys_only ) {
foreach( $list as $key => $val ) {
$options[$key] = ! empty( $val ) ? $val : $defaults['key'];
$options[$key] = ! empty( $val ) ? $val : $defaults[$key];
}
} else {
$options = array_merge( $defaults, $list );
Expand Down Expand Up @@ -184,12 +184,19 @@ public static function add_settings_page() {
</tr>
<tr valign="top">
<th scope="row">Fallback Image</th>
<td>
<img class="ucf_news_fallback_image_preview" alt="Fallback Image Preview" src="<?php echo $ucf_news_fallback_image_src; ?>" style="max-width:150px;max-height:150px;<?php echo(empty($ucf_news_fallback_image_src)?"display:none;":""); ?>"><br/>
<p class="ucf_news_fallback_message" style="margin:-1em 0 1em 0;<?php echo(empty($ucf_news_fallback_image_src)?"":"display:none;");?>">No fallback image has been selected</p>
<td>
<img class="ucf_news_fallback_image_preview" alt="Fallback Image Preview" src="<?php echo $ucf_news_fallback_image_src; ?>" style="max-width: 150px; max-height: 150px; <?php echo empty( $ucf_news_fallback_image_src ) ? 'display: none;' : ''; ?>">
<br>
<p class="ucf_news_fallback_message" style="margin: -1em 0 1em 0; <?php echo empty( $ucf_news_fallback_image_src ) ? '' : 'display: none;';?>">
No fallback image has been selected
</p>
<input class="ucf_news_fallback_image" type="hidden" name="ucf_news_fallback_image" value="<?php echo $ucf_news_fallback_image; ?>">
<a href="#" class="ucf_news_clear_image_upload button button-primary" style="<?php echo(empty($ucf_news_fallback_image_src)?"display:none;":""); ?>">Remove Image</a>
<a href="#" class="ucf_news_fallback_image_upload button button-primary"><?php echo(empty($ucf_news_fallback_image_src)?"Add Image":"Change Image");?></a>
<a href="#" class="ucf_news_clear_image_upload button button-primary" style="<?php echo empty( $ucf_news_fallback_image_src ) ? 'display: none;' : ''; ?>">
Remove Image
</a>
<a href="#" class="ucf_news_fallback_image_upload button button-primary">
<?php echo empty( $ucf_news_fallback_image_src ) ? 'Add Image' : 'Change Image'; ?>
</a>
</td>
</tr>
</table>
Expand Down
4 changes: 2 additions & 2 deletions includes/ucf-news-feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public static function get_news_items( $args ) {
'url' => $url_override ? $url_override : UCF_News_Config::$default_plugin_options['ucf_news_feed_url'],
'limit' => isset( $args['limit'] ) ? (int) $args['limit'] : 3,
'offset' => isset( $args['offset'] ) ? (int) $args['offset'] : 0,
'categories' => isset( $args['sections'] ) ? explode( ',', $args['sections'] ) : null,
'tags' => isset( $args['topics'] ) ? explode( ',', $args['topics'] ) : null,
'categories' => isset( $args['sections'] ) ? array_map( 'trim', explode( ',', $args['sections'] ) ) : null,
'tags' => isset( $args['topics'] ) ? array_map( 'trim', explode( ',', $args['topics'] ) ) : null,
);

// Empty array of indexes with no value.
Expand Down
45 changes: 23 additions & 22 deletions includes/ucf-news-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,20 @@ public function __construct() {
* @param array $instance
**/
public function widget( $args, $instance ) {
$title = ! empty( $instance['title'] ) ? $instance['title'] : 'News';
$title = apply_filters( 'widget_title', $title, $this->id_base );
$title = $args['before_title'] . $title . $args['after_title'];
$sections = str_replace( ' ', '', $instance['sections'] );
$topics = str_replace( ' ', '', $instance['topics'] );
$limit = (int) $instance['limit'];
$per_row = (int) $instance['per_row'];
$offset = (int) $instance['offset'];
$layout = $instance['layout'];
$items_args = UCF_News_Config::apply_default_options( $instance );

$items_args = array(
'title' => $title,
'sections' => $sections,
'topics' => $topics,
'limit' => $limit,
'offset' => $offset,
'per_row' => $per_row
);
$items_args['title'] = apply_filters( 'widget_title', $items_args['title'], $this->id_base );
if ( isset( $args['before_title'] ) && isset( $args['after_title'] ) ) {
$items_args['title'] = $args['before_title'] . $items_args['title'] . $args['after_title'];
}

$items = UCF_News_Feed::get_news_items( $items_args );

ob_start();

if ( $items ) {
echo $args['before_widget'];
echo UCF_News_Common::display_news_items( $items, $layout, $items_args, 'widget' );
echo UCF_News_Common::display_news_items( $items, $items_args['layout'], $items_args, 'widget' );
echo $args['after_widget'];
}

Expand All @@ -64,6 +52,7 @@ public function form( $instance ) {
$limit = $options['limit'];
$offset = $options['offset'];
$per_row = $options['per_row'];
$show_image = $options['show_image'];
?>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php echo __( 'Title' ); ?></label>
Expand All @@ -90,18 +79,30 @@ public function form( $instance ) {
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'limit' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'limit' ) ); ?>" type="number" value="<?php echo esc_attr( $limit ); ?>" >
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'per_row' ) ); ?>"><?php echo __( 'No. of items per row (for card layout only)' ); ?></label>
<label for="<?php echo esc_attr( $this->get_field_id( 'offset' ) ); ?>"><?php echo __( 'Offset results' ); ?></label>
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'offset' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'offset' ) ); ?>" type="number" value="<?php echo esc_attr( $offset ); ?>" >
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'per_row' ) ); ?>"><?php echo __( 'No. of items per row*' ); ?></label>
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'per_row' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'per_row' ) ); ?>" type="number" value="<?php echo esc_attr( $per_row ); ?>" >
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'offset' ) ); ?>"><?php echo __( 'Offset results' ); ?></label>
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'offset' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'offset' ) ); ?>" type="number" value="<?php echo esc_attr( $offset ); ?>" >
<input id="<?php echo esc_attr( $this->get_field_id( 'show_image' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'show_image' ) ); ?>" type="checkbox" <?php checked( $show_image ); ?> >
<label for="<?php echo esc_attr( $this->get_field_id( 'show_image' ) ); ?>"><?php echo __( 'Show images*' ); ?></label>
</p>
<p><small>* only applied in layouts that support this feature</small></p>
<?php
}

public function update( $new_instance, $old_instance ) {
$instance = UCF_News_Config::apply_default_options( $new_instance );
// $new_instance may not contain all form input values,
// so we have to ensure all expected option keys are
// present before passing the instance along; otherwise
// UCF_News_Config::apply_default_options() may apply
// default values in unintended ways
$options_base = array_fill_keys( array_keys( UCF_News_Config::$default_options ), null );
$instance = array_merge( $options_base, $new_instance );
$instance = UCF_News_Config::format_options( $instance );

return $instance;
}
Expand Down

0 comments on commit 8ad744b

Please sign in to comment.