Replace php4 style constructor with php5 constructor

This fixes a deprecation error
This commit is contained in:
David Fuhr 2019-10-12 14:08:25 +02:00
parent e38a8b76c2
commit 6a59d80963

View file

@ -1,4 +1,4 @@
<?php <?php
//Alle Bildgrößen Verfügbar machen //Alle Bildgrößen Verfügbar machen
add_filter( 'image_size_names_choose', 'sir_image_sizes_choose' ); add_filter( 'image_size_names_choose', 'sir_image_sizes_choose' );
@ -14,7 +14,7 @@ function sir_image_sizes_choose( $Sizes ) {
return array_merge( $CustomSizes, $Sizes ); return array_merge( $CustomSizes, $Sizes );
} }
// sidebars // sidebars
if ( function_exists('register_sidebars') ) if ( function_exists('register_sidebars') )
register_sidebars(0); register_sidebars(0);
@ -33,7 +33,7 @@ if (!function_exists('kr8_register_sidebars')) {
'after_title' => '</h3>', 'after_title' => '</h3>',
)); ));
register_sidebar(array( register_sidebar(array(
'name' => 'Startseite - Artikel', 'name' => 'Startseite - Artikel',
'description' => 'Artikel auf der Startseite', 'description' => 'Artikel auf der Startseite',
@ -43,9 +43,9 @@ if (!function_exists('kr8_register_sidebars')) {
'before_title' => "\n\t" . '<h1>', 'before_title' => "\n\t" . '<h1>',
'after_title' => '</h1>', 'after_title' => '</h1>',
)); ));
register_sidebar(array( register_sidebar(array(
'name' => 'Kampagnenseite - Actionbox', 'name' => 'Kampagnenseite - Actionbox',
'description' => 'Drei Widgets: Werde aktiv', 'description' => 'Drei Widgets: Werde aktiv',
@ -54,8 +54,8 @@ if (!function_exists('kr8_register_sidebars')) {
'after_widget' => '</div>', 'after_widget' => '</div>',
'before_title' => "\n\t" . '<h3>', 'before_title' => "\n\t" . '<h3>',
'after_title' => '</h3>', 'after_title' => '</h3>',
)); ));
register_sidebar(array( register_sidebar(array(
'name' => 'Kampagnenseite - Infobox', 'name' => 'Kampagnenseite - Infobox',
'description' => 'Drei Widgets: Erfahre mehr', 'description' => 'Drei Widgets: Erfahre mehr',
@ -64,9 +64,9 @@ if (!function_exists('kr8_register_sidebars')) {
'after_widget' => '</div>', 'after_widget' => '</div>',
'before_title' => "\n\t" . '<h3>', 'before_title' => "\n\t" . '<h3>',
'after_title' => '</h3>', 'after_title' => '</h3>',
)); ));
register_sidebar(array( register_sidebar(array(
'name' => 'Startseite - Infoleiste', 'name' => 'Startseite - Infoleiste',
'description' => 'Infospalte der Startseite', 'description' => 'Infospalte der Startseite',
@ -75,9 +75,9 @@ if (!function_exists('kr8_register_sidebars')) {
'after_widget' => '</div>', 'after_widget' => '</div>',
'before_title' => "\n\t" . '<h3>', 'before_title' => "\n\t" . '<h3>',
'after_title' => '</h3>', 'after_title' => '</h3>',
)); ));
register_sidebar(array( register_sidebar(array(
'name' => 'Presse', 'name' => 'Presse',
'description' => 'Widgets in der Kategory Presse', 'description' => 'Widgets in der Kategory Presse',
@ -87,7 +87,7 @@ if (!function_exists('kr8_register_sidebars')) {
'before_title' => "\n\t" . '<h3 class="widgettitle">', 'before_title' => "\n\t" . '<h3 class="widgettitle">',
'after_title' => '</h3>', 'after_title' => '</h3>',
)); ));
register_sidebar(array( register_sidebar(array(
'name' => 'Fussleiste', 'name' => 'Fussleiste',
'description' => 'Platz für Widgets in der Fußleiste.', 'description' => 'Platz für Widgets in der Fußleiste.',
@ -98,12 +98,12 @@ if (!function_exists('kr8_register_sidebars')) {
'after_title' => '</h3>', 'after_title' => '</h3>',
)); ));
} }
} }
} }
@ -118,19 +118,19 @@ function kr8_wpsearch($form) {
</button> </button>
</form></section>'; </form></section>';
return $form; return $form;
} }
/************* SOCIAL MEDIA WIDGET *****************/ /************* SOCIAL MEDIA WIDGET *****************/
class kr8_socialmedia extends WP_Widget { class kr8_socialmedia extends WP_Widget {
function kr8_socialmedia() { function __construct() {
$widget_ops = array('description' => 'Links zu deinen Profilen in den Sozialen Netzwerken.'); $widget_ops = array('description' => 'Links zu deinen Profilen in den Sozialen Netzwerken.');
parent::WP_Widget(false, __('Social Media Links'),$widget_ops); parent::__construct(false, __('Social Media Links'),$widget_ops);
} }
function widget($args, $instance) { function widget($args, $instance) {
extract( $args ); extract( $args );
$title = $instance['title']; $title = $instance['title'];
$twitter = $instance['twitter']; $twitter = $instance['twitter'];
@ -147,26 +147,26 @@ function kr8_wpsearch($form) {
$tumblr = $instance['tumblr']; $tumblr = $instance['tumblr'];
$rss = $instance['rss']; $rss = $instance['rss'];
$rsscomments = $instance['rsscomments']; $rsscomments = $instance['rsscomments'];
echo $before_widget; ?> echo $before_widget; ?>
<?php if($title != '') <?php if($title != '')
echo '<h3 class="widgettitle">'.$title.'</h3>'; ?> echo '<h3 class="widgettitle">'.$title.'</h3>'; ?>
<ul class="sociallinks"> <ul class="sociallinks">
<?php <?php
if($twitter != '') { if($twitter != '') {
echo '<li><a href="https://twitter.com/'.$twitter.'" title="Twitter"><span class="fa fa-fw fa-twitter"></span><span class="hidden">Twitter</span></a></li>'; echo '<li><a href="https://twitter.com/'.$twitter.'" title="Twitter"><span class="fa fa-fw fa-twitter"></span><span class="hidden">Twitter</span></a></li>';
} }
?> ?>
<?php <?php
if($facebook != '') { if($facebook != '') {
echo '<li><a href="'.$facebook.'"title="Facebook"><span class="fa fa-fw fa-facebook"></span><span class="hidden">Facebook</span></a></li>'; echo '<li><a href="'.$facebook.'"title="Facebook"><span class="fa fa-fw fa-facebook"></span><span class="hidden">Facebook</span></a></li>';
} }
?> ?>
<?php <?php
if($googleplus != '') { if($googleplus != '') {
echo '<li><a href="'.$googleplus.'" title="Google+"><span class="fa fa-fw fa-google-plus"></span><span class="hidden">Google+</span></a></li>'; echo '<li><a href="'.$googleplus.'" title="Google+"><span class="fa fa-fw fa-google-plus"></span><span class="hidden">Google+</span></a></li>';
} }
@ -176,7 +176,7 @@ function kr8_wpsearch($form) {
echo '<li><a href="'.$flickr.'" title="Flickr"><span class="fa fa-fw fa-flickr"></span><span class="hidden">Flickr</span></a></li>'; echo '<li><a href="'.$flickr.'" title="Flickr"><span class="fa fa-fw fa-flickr"></span><span class="hidden">Flickr</span></a></li>';
} }
?> ?>
<?php if($instagram != '') { <?php if($instagram != '') {
echo '<li><a href="'.$instagram.'" title="Instagram"><span class="fa fa-fw fa-instagram"></span><span class="hidden">Instagram</span></a></li>'; echo '<li><a href="'.$instagram.'" title="Instagram"><span class="fa fa-fw fa-instagram"></span><span class="hidden">Instagram</span></a></li>';
} }
@ -201,7 +201,7 @@ function kr8_wpsearch($form) {
echo '<li><a href="'.$foursquare.'" title="Foursquare"><span class="fa fa-fw fa-foursquare"></span><span class="hidden">Foursquare</span></a></li>'; echo '<li><a href="'.$foursquare.'" title="Foursquare"><span class="fa fa-fw fa-foursquare"></span><span class="hidden">Foursquare</span></a></li>';
} }
?> ?>
<?php if($pinterest != '') { <?php if($pinterest != '') {
echo '<li><a href="'.$pinterest.'" title="Pinterst"><span class="fa fa-fw fa-pinterest"></span><span class="hidden">Pinterest</span></a></li>'; echo '<li><a href="'.$pinterest.'" title="Pinterst"><span class="fa fa-fw fa-pinterest"></span><span class="hidden">Pinterest</span></a></li>';
} }
@ -211,12 +211,12 @@ function kr8_wpsearch($form) {
echo '<li><a href="'.$xing.'" title="Xing"><span class="fa fa-fw fa-xing"></span><span class="hidden">Xing</span></a></li>'; echo '<li><a href="'.$xing.'" title="Xing"><span class="fa fa-fw fa-xing"></span><span class="hidden">Xing</span></a></li>';
} }
?> ?>
<?php if($tumblr != '') { <?php if($tumblr != '') {
echo '<li><a href="'.$tumblr.'" title="Tumblr"><span class="fa fa-fw fa-tumblr"></span><span class="hidden">Tumblr</span></a></li>'; echo '<li><a href="'.$tumblr.'" title="Tumblr"><span class="fa fa-fw fa-tumblr"></span><span class="hidden">Tumblr</span></a></li>';
} }
?> ?>
<?php if($rss != '') { <?php if($rss != '') {
echo '<li><a href="'.$rss.'" title="RSS Feed"><span class="fa fa-fw fa-rss"></span><span class="hidden">RSS Feed</span></a></li>'; echo '<li><a href="'.$rss.'" title="RSS Feed"><span class="fa fa-fw fa-rss"></span><span class="hidden">RSS Feed</span></a></li>';
} }
@ -229,15 +229,15 @@ function kr8_wpsearch($form) {
</ul><!-- end .sociallinks --> </ul><!-- end .sociallinks -->
<?php <?php
echo $after_widget; echo $after_widget;
} }
function update($new_instance, $old_instance) { function update($new_instance, $old_instance) {
return $new_instance; return $new_instance;
} }
function form($instance) { function form($instance) {
$title = esc_attr($instance['title']); $title = esc_attr($instance['title']);
$twitter = esc_attr($instance['twitter']); $twitter = esc_attr($instance['twitter']);
$facebook = esc_attr($instance['facebook']); $facebook = esc_attr($instance['facebook']);
@ -254,7 +254,7 @@ function kr8_wpsearch($form) {
$rss = esc_attr($instance['rss']); $rss = esc_attr($instance['rss']);
$rsscomments = esc_attr($instance['rsscomments']); $rsscomments = esc_attr($instance['rsscomments']);
?> ?>
<p> <p>
@ -271,17 +271,17 @@ function kr8_wpsearch($form) {
<label for="<?php echo $this->get_field_id('facebook'); ?>"><?php _e('Facebook URL:'); ?></label> <label for="<?php echo $this->get_field_id('facebook'); ?>"><?php _e('Facebook URL:'); ?></label>
<input type="text" name="<?php echo $this->get_field_name('facebook'); ?>" value="<?php echo $facebook; ?>" class="widefat" id="<?php echo $this->get_field_id('facebook'); ?>" /> <input type="text" name="<?php echo $this->get_field_name('facebook'); ?>" value="<?php echo $facebook; ?>" class="widefat" id="<?php echo $this->get_field_id('facebook'); ?>" />
</p> </p>
<p> <p>
<label for="<?php echo $this->get_field_id('googleplus'); ?>"><?php _e('Google+ URL:'); ?></label> <label for="<?php echo $this->get_field_id('googleplus'); ?>"><?php _e('Google+ URL:'); ?></label>
<input type="text" name="<?php echo $this->get_field_name('googleplus'); ?>" value="<?php echo $googleplus; ?>" class="widefat" id="<?php echo $this->get_field_id('googleplus'); ?>" /> <input type="text" name="<?php echo $this->get_field_name('googleplus'); ?>" value="<?php echo $googleplus; ?>" class="widefat" id="<?php echo $this->get_field_id('googleplus'); ?>" />
</p> </p>
<p> <p>
<label for="<?php echo $this->get_field_id('flickr'); ?>"><?php _e('Flickr URL:'); ?></label> <label for="<?php echo $this->get_field_id('flickr'); ?>"><?php _e('Flickr URL:'); ?></label>
<input type="text" name="<?php echo $this->get_field_name('flickr'); ?>" value="<?php echo $flickr; ?>" class="widefat" id="<?php echo $this->get_field_id('flickr'); ?>" /> <input type="text" name="<?php echo $this->get_field_name('flickr'); ?>" value="<?php echo $flickr; ?>" class="widefat" id="<?php echo $this->get_field_id('flickr'); ?>" />
</p> </p>
<p> <p>
<label for="<?php echo $this->get_field_id('instagram'); ?>"><?php _e('Instagram URL:'); ?></label> <label for="<?php echo $this->get_field_id('instagram'); ?>"><?php _e('Instagram URL:'); ?></label>
<input type="text" name="<?php echo $this->get_field_name('instagram'); ?>" value="<?php echo $instagram; ?>" class="widefat" id="<?php echo $this->get_field_id('instagram'); ?>" /> <input type="text" name="<?php echo $this->get_field_name('instagram'); ?>" value="<?php echo $instagram; ?>" class="widefat" id="<?php echo $this->get_field_id('instagram'); ?>" />
@ -291,12 +291,12 @@ function kr8_wpsearch($form) {
<label for="<?php echo $this->get_field_id('youtube'); ?>"><?php _e('YouTube URL:'); ?></label> <label for="<?php echo $this->get_field_id('youtube'); ?>"><?php _e('YouTube URL:'); ?></label>
<input type="text" name="<?php echo $this->get_field_name('youtube'); ?>" value="<?php echo $youtube; ?>" class="widefat" id="<?php echo $this->get_field_id('youtube'); ?>" /> <input type="text" name="<?php echo $this->get_field_name('youtube'); ?>" value="<?php echo $youtube; ?>" class="widefat" id="<?php echo $this->get_field_id('youtube'); ?>" />
</p> </p>
<p> <p>
<label for="<?php echo $this->get_field_id('vimeo'); ?>"><?php _e('Vimeo URL:'); ?></label> <label for="<?php echo $this->get_field_id('vimeo'); ?>"><?php _e('Vimeo URL:'); ?></label>
<input type="text" name="<?php echo $this->get_field_name('vimeo'); ?>" value="<?php echo $vimeo; ?>" class="widefat" id="<?php echo $this->get_field_id('vimeo'); ?>" /> <input type="text" name="<?php echo $this->get_field_name('vimeo'); ?>" value="<?php echo $vimeo; ?>" class="widefat" id="<?php echo $this->get_field_id('vimeo'); ?>" />
</p> </p>
<p> <p>
<label for="<?php echo $this->get_field_id('pinterest'); ?>"><?php _e('Pinterest URL:'); ?></label> <label for="<?php echo $this->get_field_id('pinterest'); ?>"><?php _e('Pinterest URL:'); ?></label>
<input type="text" name="<?php echo $this->get_field_name('pinterest'); ?>" value="<?php echo $pinterest; ?>" class="widefat" id="<?php echo $this->get_field_id('pinterest'); ?>" /> <input type="text" name="<?php echo $this->get_field_name('pinterest'); ?>" value="<?php echo $pinterest; ?>" class="widefat" id="<?php echo $this->get_field_id('pinterest'); ?>" />
@ -322,34 +322,34 @@ function kr8_wpsearch($form) {
<label for="<?php echo $this->get_field_id('tumblr'); ?>"><?php _e('Tumblr URL:'); ?></label> <label for="<?php echo $this->get_field_id('tumblr'); ?>"><?php _e('Tumblr URL:'); ?></label>
<input type="text" name="<?php echo $this->get_field_name('tumblr'); ?>" value="<?php echo $xing; ?>" class="widefat" id="<?php echo $this->get_field_id('tumblr'); ?>" /> <input type="text" name="<?php echo $this->get_field_name('tumblr'); ?>" value="<?php echo $xing; ?>" class="widefat" id="<?php echo $this->get_field_id('tumblr'); ?>" />
</p> </p>
<p> <p>
<label for="<?php echo $this->get_field_id('rss'); ?>"><?php _e('RSS-Feed URL:'); ?></label> <label for="<?php echo $this->get_field_id('rss'); ?>"><?php _e('RSS-Feed URL:'); ?></label>
<input type="text" name="<?php echo $this->get_field_name('rss'); ?>" value="<?php echo $rss; ?>" class="widefat" id="<?php echo $this->get_field_id('rss'); ?>" /> <input type="text" name="<?php echo $this->get_field_name('rss'); ?>" value="<?php echo $rss; ?>" class="widefat" id="<?php echo $this->get_field_id('rss'); ?>" />
</p> </p>
<p> <p>
<label for="<?php echo $this->get_field_id('rsscomments'); ?>"><?php _e('RSS for Comments URL:'); ?></label> <label for="<?php echo $this->get_field_id('rsscomments'); ?>"><?php _e('RSS for Comments URL:'); ?></label>
<input type="text" name="<?php echo $this->get_field_name('rsscomments'); ?>" value="<?php echo $rsscomments; ?>" class="widefat" id="<?php echo $this->get_field_id('rsscomments'); ?>" /> <input type="text" name="<?php echo $this->get_field_name('rsscomments'); ?>" value="<?php echo $rsscomments; ?>" class="widefat" id="<?php echo $this->get_field_id('rsscomments'); ?>" />
</p> </p>
<?php <?php
} }
} }
/************* TEASER ARTIKEL WIDGET *****************/ /************* TEASER ARTIKEL WIDGET *****************/
class kr8_teaserarticle extends WP_Widget class kr8_teaserarticle extends WP_Widget
{ {
//Einstellungen //Einstellungen
public function __construct() public function __construct()
{ {
parent::__construct( parent::__construct(
'kr8_teaserarticle', 'kr8_teaserarticle',
@ -361,15 +361,15 @@ class kr8_teaserarticle extends WP_Widget
} }
//Admin Area //Admin Area
public function form($instance) public function form($instance)
{ {
$defaults = array( $defaults = array(
'title' => '', 'title' => '',
'day_interval' => '30', 'day_interval' => '30',
'limit' => '5' 'limit' => '5'
); );
$instance = wp_parse_args((array)$instance, $defaults); $instance = wp_parse_args((array)$instance, $defaults);
$title = $instance['title']; $title = $instance['title'];
$url = $instance['url']; $url = $instance['url'];
$subhead = $instance['subhead']; $subhead = $instance['subhead'];
@ -377,37 +377,37 @@ class kr8_teaserarticle extends WP_Widget
$image_id = $instance['image_id']; $image_id = $instance['image_id'];
$image_size = $instance['image_size']; $image_size = $instance['image_size'];
$image_url = $instance['image_url']; $image_url = $instance['image_url'];
?> ?>
<p> <p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php echo 'Titel:'; ?></label> <label for="<?php echo $this->get_field_id('title'); ?>"><?php echo 'Titel:'; ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
</p> </p>
<p> <p>
<label for="<?php echo $this->get_field_id('url'); ?>"><?php echo 'URL:'; ?></label> <label for="<?php echo $this->get_field_id('url'); ?>"><?php echo 'URL:'; ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('url'); ?>" name="<?php echo $this->get_field_name('url'); ?>" type="text" value="<?php echo esc_attr($url); ?>" /> <input class="widefat" id="<?php echo $this->get_field_id('url'); ?>" name="<?php echo $this->get_field_name('url'); ?>" type="text" value="<?php echo esc_attr($url); ?>" />
</p> </p>
<p> <p>
<label for="<?php echo $this->get_field_id('subhead'); ?>"><?php echo 'Dachzeile:'; ?></label> <label for="<?php echo $this->get_field_id('subhead'); ?>"><?php echo 'Dachzeile:'; ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('subhead'); ?>" name="<?php echo $this->get_field_name('subhead'); ?>" type="text" value="<?php echo esc_attr($subhead); ?>" /> <input class="widefat" id="<?php echo $this->get_field_id('subhead'); ?>" name="<?php echo $this->get_field_name('subhead'); ?>" type="text" value="<?php echo esc_attr($subhead); ?>" />
</p> </p>
<p> <p>
<label for="<?php echo $this->get_field_id('desc'); ?>"><?php echo 'Beschreibung:'; ?></label> <label for="<?php echo $this->get_field_id('desc'); ?>"><?php echo 'Beschreibung:'; ?></label>
<textarea class="widefat" id="<?php echo $this->get_field_id('desc'); ?>" name="<?php echo $this->get_field_name('desc'); ?>"><?php echo esc_attr($desc); ?></textarea> <textarea class="widefat" id="<?php echo $this->get_field_id('desc'); ?>" name="<?php echo $this->get_field_name('desc'); ?>"><?php echo esc_attr($desc); ?></textarea>
</p> </p>
<p> <p>
<label for="<?php echo $this->get_field_id( 'image_id' ); ?>"><?php echo 'Bild:'; ?></label> <label for="<?php echo $this->get_field_id( 'image_id' ); ?>"><?php echo 'Bild:'; ?></label>
<input class="title_image" id="<?php echo $this->get_field_id( 'image_id' ); ?>" name="<?php echo $this->get_field_name( 'image_id' ); ?>" value="<?php echo $image_id ?>" type="hidden"> <input class="title_image" id="<?php echo $this->get_field_id( 'image_id' ); ?>" name="<?php echo $this->get_field_name( 'image_id' ); ?>" value="<?php echo $image_id ?>" type="hidden">
<button id="title_image_button" class="button" onclick="image_button_click('Bild auswählen','Bild wählen','image','image_id_preview','<?php echo $this->get_field_id( 'image_id' ); ?>');">Aus Medien-DB wählen</button> <button id="title_image_button" class="button" onclick="image_button_click('Bild auswählen','Bild wählen','image','image_id_preview','<?php echo $this->get_field_id( 'image_id' ); ?>');">Aus Medien-DB wählen</button>
</p> </p>
<p><label for="<?php echo $this->get_field_id('image_size'); ?>">Größe:</label> <p><label for="<?php echo $this->get_field_id('image_size'); ?>">Größe:</label>
<select name="<?php echo $this->get_field_name('image_size'); ?>" id="<?php echo $this->get_field_id('image_size'); ?>" onChange="imageWidget.toggleSizes( '<?php echo $this->id; ?>', '<?php echo $id_prefix; ?>' );"> <select name="<?php echo $this->get_field_name('image_size'); ?>" id="<?php echo $this->get_field_id('image_size'); ?>" onChange="imageWidget.toggleSizes( '<?php echo $this->id; ?>', '<?php echo $id_prefix; ?>' );">
<?php <?php
@ -419,105 +419,105 @@ class kr8_teaserarticle extends WP_Widget
'large' => __('Large', 'image_widget'), 'large' => __('Large', 'image_widget'),
) ); ) );
foreach( $possible_sizes as $size_key => $size_label ) { ?> foreach( $possible_sizes as $size_key => $size_label ) { ?>
<option value="<?php echo $size_key; ?>"<?php selected( $instance['image_size'], $size_key ); ?>><?php echo $size_label; ?></option> <option value="<?php echo $size_key; ?>"<?php selected( $instance['image_size'], $size_key ); ?>><?php echo $size_label; ?></option>
<?php } ?> <?php } ?>
</select> </select>
<?php $imgparse= wp_get_attachment_image_src( $image_id, $image_size, false); <?php $imgparse= wp_get_attachment_image_src( $image_id, $image_size, false);
$img_url = $imgparse[0]; $img_url = $imgparse[0];
?> ?>
<input class="widefat" id="<?php echo $this->get_field_id('image_url'); ?>" name="<?php echo $this->get_field_name('image_url'); ?>" type="hidden" value="<?php echo $img_url; ?>" /> <input class="widefat" id="<?php echo $this->get_field_id('image_url'); ?>" name="<?php echo $this->get_field_name('image_url'); ?>" type="hidden" value="<?php echo $img_url; ?>" />
</p> </p>
<p> <p>
<?php <?php
if ($image_id!='') echo '<img src="' . $imgparse[0] . '" style="max-width:100%;height:auto;">'; if ($image_id!='') echo '<img src="' . $imgparse[0] . '" style="max-width:100%;height:auto;">';
?> ?>
</p> </p>
<p> <p>
<input class="checkbox" type="checkbox" <?php checked($instance['show_desc'], 'on'); ?> id="<?php echo $this->get_field_id('show_desc'); ?>" name="<?php echo $this->get_field_name('show_desc'); ?>" /> <input class="checkbox" type="checkbox" <?php checked($instance['show_desc'], 'on'); ?> id="<?php echo $this->get_field_id('show_desc'); ?>" name="<?php echo $this->get_field_name('show_desc'); ?>" />
<label for="<?php echo $this->get_field_id('show_desc'); ?>">Überschrift in Desktop-Version ausblenden.</label> <label for="<?php echo $this->get_field_id('show_desc'); ?>">Überschrift in Desktop-Version ausblenden.</label>
</p> </p>
<script> <script>
var frame; var frame;
function image_button_click(dialog_title, button_text, library_type, preview_id, control_id) { function image_button_click(dialog_title, button_text, library_type, preview_id, control_id) {
event.preventDefault(); event.preventDefault();
//If the uploader object has already been created, reopen the dialog //If the uploader object has already been created, reopen the dialog
//if (custom_uploader) { //if (custom_uploader) {
// custom_uploader.open(); // custom_uploader.open();
// return; // return;
//} //}
//Extend the wp.media object //Extend the wp.media object
frame = wp.media.frames.file_frame = wp.media({ frame = wp.media.frames.file_frame = wp.media({
title: dialog_title, title: dialog_title,
button: { button: {
text: button_text text: button_text
}, },
//library : { type : library_type }, //library : { type : library_type },
library : { type : 'image' }, library : { type : 'image' },
//frame: 'post', //frame: 'post',
multiple: false multiple: false
}); });
//When a file is selected, grab the URL and set it as the text field's value //When a file is selected, grab the URL and set it as the text field's value
frame.on('close', function() { frame.on('close', function() {
attachment = frame.state().get('selection').first().toJSON(); attachment = frame.state().get('selection').first().toJSON();
//attachment = custom_uploader.state().get('selection').toJSON(); //attachment = custom_uploader.state().get('selection').toJSON();
jQuery('#' + control_id).val(attachment.id); jQuery('#' + control_id).val(attachment.id);
var html = ''; var html = '';
if (library_type=='image') { if (library_type=='image') {
html = '<img src="' + attachment.url + '">'; html = '<img src="' + attachment.url + '">';
} }
if (library_type=='video') { if (library_type=='video') {
html = '<video autoplay loop><source src="' + attachment.url + '" type="video/' + get_extension( attachment.url ) + '" /></video>'; html = '<video autoplay loop><source src="' + attachment.url + '" type="video/' + get_extension( attachment.url ) + '" /></video>';
} }
jQuery('#' + preview_id).empty(); jQuery('#' + preview_id).empty();
jQuery('#' + preview_id).append(html); jQuery('#' + preview_id).append(html);
}); });
//Open the uploader dialog //Open the uploader dialog
frame.open(); frame.open();
return false; return false;
} }
function get_extension( url ){ function get_extension( url ){
return url.substr((url.lastIndexOf('.') + 1)); return url.substr((url.lastIndexOf('.') + 1));
} }
</script> </script>
<?php <?php
} }
//Save Data //Save Data
public function update($new_instance, $old_instance) public function update($new_instance, $old_instance)
{ {
$instance = array(); $instance = array();
$instance['title'] = strip_tags($new_instance['title']); $instance['title'] = strip_tags($new_instance['title']);
$instance['url'] = strip_tags($new_instance['url']); $instance['url'] = strip_tags($new_instance['url']);
$instance['subhead'] = strip_tags($new_instance['subhead']); $instance['subhead'] = strip_tags($new_instance['subhead']);
@ -526,13 +526,13 @@ class kr8_teaserarticle extends WP_Widget
$instance['image_size'] = strip_tags($new_instance['image_size']); $instance['image_size'] = strip_tags($new_instance['image_size']);
$instance['image_url'] = strip_tags($new_instance['image_url']); $instance['image_url'] = strip_tags($new_instance['image_url']);
$instance['show_desc'] = $new_instance['show_desc']; $instance['show_desc'] = $new_instance['show_desc'];
return $instance; return $instance;
} }
//Frontend Output //Frontend Output
public function widget($args, $instance) public function widget($args, $instance)
{ {
extract($args); extract($args);
$title = apply_filters('widget_title', $instance['title']); $title = apply_filters('widget_title', $instance['title']);
@ -541,29 +541,29 @@ class kr8_teaserarticle extends WP_Widget
$desc = $instance['desc']; $desc = $instance['desc'];
$img = $instance['image_url']; $img = $instance['image_url'];
$show_desc = $instance['show_desc'] ? 'true' : 'false'; $show_desc = $instance['show_desc'] ? 'true' : 'false';
echo $before_widget; echo $before_widget;
if('on' == $instance['show_desc'] ) { if('on' == $instance['show_desc'] ) {
echo '<div class="nodesc">'; echo '<div class="nodesc">';
} }
if(!empty($img)) if(!empty($img))
{ {
if(!empty($url)) { echo '<a href="'. $url .'" title="'.$title.'" class="postimglist">';} if(!empty($url)) { echo '<a href="'. $url .'" title="'.$title.'" class="postimglist">';}
echo '<img src="'. $img .'" alt="'. $title .'" class="wp-post-image">'; echo '<img src="'. $img .'" alt="'. $title .'" class="wp-post-image">';
if(!empty($url)) { echo '</a>';} if(!empty($url)) { echo '</a>';}
} }
if(!empty($subhead)) if(!empty($subhead))
{ {
echo '<p class="subhead">'. $subhead .'</p>'; echo '<p class="subhead">'. $subhead .'</p>';
} }
if(!empty($title)) if(!empty($title))
{ {
echo $before_title; echo $before_title;
@ -572,20 +572,20 @@ class kr8_teaserarticle extends WP_Widget
if(!empty($url)) { echo '</a>';} if(!empty($url)) { echo '</a>';}
echo $after_title; echo $after_title;
} }
if(!empty($desc)) if(!empty($desc))
{ {
echo '<p>'. $desc .'</p>'; echo '<p>'. $desc .'</p>';
} }
if('on' == $instance['show_desc'] ) { if('on' == $instance['show_desc'] ) {
echo '</div>'; echo '</div>';
} }
echo $after_widget; echo $after_widget;
} }
} }
@ -600,4 +600,4 @@ add_action( 'widgets_init', function(){
?> ?>