__('You can feature a certain post in this widget and display it, where and however you want, in your widget areas. A backup post can be given to avoid dubble content. Define, on what pages the widget will show.', self::language_file) );
$control_opts = array( 'width' => 400 );
parent::WP_Widget(false, $name = 'Advanced Featured Post', $widget_opts, $control_opts);
}
function form($instance) {
// setup some default settings
$defaults = array( 'homepage' => 1, 'category' => 1 );
$instance = wp_parse_args( (array) $instance, $defaults );
$title = esc_attr($instance['title']);
$thumb = esc_attr($instance['thumb']);
$image = esc_attr($instance['image']);
$article = esc_attr($instance['article']);
$backup = esc_attr($instance['backup']);
$width = esc_attr($instance['width']);
$headline = esc_attr($instance['headline']);
$excerpt = esc_attr($instance['excerpt']);
$linespace = esc_attr($instance['linespace']);
$notext = esc_attr($instance['notext']);
$noshorts = esc_attr($instance['noshorts']);
$readmore = esc_attr($instance['readmore']);
$rmtext = esc_attr($instance['rmtext']);
$adsense = esc_attr($instance['adsense']);
$style = esc_attr($instance['style']);
$homepage=esc_attr($instance['homepage']);
$frontpage=esc_attr($instance['frontpage']);
$page=esc_attr($instance['page']);
$category=esc_attr($instance['category']);
$single=esc_attr($instance['single']);
$date=esc_attr($instance['date']);
$tag=esc_attr($instance['tag']);
$attachment=esc_attr($instance['attachment']);
$taxonomy=esc_attr($instance['taxonomy']);
$author=esc_attr($instance['author']);
$search=esc_attr($instance['search']);
$not_found=esc_attr($instance['not_found']);
$h=esc_attr($instance['h']);
$class=esc_attr($instance['class']);
$features = get_posts('numberposts=-1');
foreach ( $features as $feature ) :
$posts[] = array($feature->ID, $feature->post_title );
endforeach;
$base_id = 'widget-'.$this->id_base.'-'.$this->number.'-';
$base_name = 'widget-'.$this->id_base.'['.$this->number.']';
$pages = array (
array($base_id.'homepage', $base_name.'[homepage]', $homepage, __('Homepage', self::language_file)),
array($base_id.'frontpage', $base_name.'[frontpage]', $frontpage, __('Frontpage (e.g. a static page as homepage)', self::language_file)),
array($base_id.'page', $base_name.'[page]', $page, __('"Page" pages', self::language_file)),
array($base_id.'category', $base_name.'[category]', $category, __('Category pages', self::language_file)),
array($base_id.'single', $base_name.'[single]', $single, __('Single post pages', self::language_file)),
array($base_id.'date', $base_name.'[date]', $date, __('Archive pages', self::language_file)),
array($base_id.'tag', $base_name.'[tag]', $tag, __('Tag pages', self::language_file)),
array($base_id.'attachment', $base_name.'[attachment]', $attachment, __('Attachments', self::language_file)),
array($base_id.'taxonomy', $base_name.'[taxonomy]', $taxonomy, __('Custom Taxonomy pages (only available, if having a plugin)', self::language_file)),
array($base_id.'author', $base_name.'[author]', $author, __('Author pages', self::language_file)),
array($base_id.'search', $base_name.'[search]', $search, __('Search Results', self::language_file)),
array($base_id.'not_found', $base_name.'[not_found]', $not_found, __('"Not Found"', self::language_file))
);
$checkall = array($base_id.'checkall', $base_name.'[checkall]', __('Check all', self::language_file));
$headings = array(array('1', 'h1'), array('2', 'h2'), array('3', 'h3'), array('4', 'h4'), array('5', 'h5'), array('6', 'h6'));
$options = array (array('top', __('Above thumbnail', self::language_file)) , array('bottom', __('Under thumbnail', self::language_file)), array('none', __('Don't show title', self::language_file)));
a5_text_field($base_id.'title', $base_name.'[title]', $title, __('Title:', self::language_file), array('space' => true, 'class' => 'widefat'));
a5_select($base_id.'article', $base_name.'[article]', $posts, $article, __('Choose here the post, you want to appear in the widget.', self::language_file), __('Take a random post', self::language_file), array('space' => true, 'class' => 'widefat'));
a5_select($base_id.'backup', $base_name.'[backup]',$posts, $backup, __('Choose here the backup post. It will appear, when a single post page shows the featured article.', self::language_file), __('Take a random post', self::language_file), array('space' => true, 'class' => 'widefat'));
a5_checkbox($base_id.'image', $base_name.'[image]', $image, __('Check to get the first image of the post as thumbnail.', self::language_file), array('space' => true));
a5_number_field($base_id.'width', $base_name.'[width]', $width, __('Width of the thumbnail (in px):', self::language_file), array('space' => true, 'size' => 4, 'step' => 1));
a5_checkbox($base_id.'thumb', $base_name.'[thumb]', $thumb, sprintf(__('Check to %snot%s display the thumbnail of the post.', self::language_file), '', ''), array('space' => true));
a5_select($base_id.'headline', $base_name.'[headline]', $options, $headline, __('Choose, whether or not to display the title and whether it comes above or under the thumbnail.', self::language_file), false, array('space' => true));
a5_select($base_id.'h', $base_name.'[h]', $headings, $h, __('Weight of the Post Title:', self::language_file), __('none', self::language_file), array('space' => true));
a5_textarea($base_id.'excerpt', $base_name.'[excerpt]', $excerpt, __('If the excerpt of the post is not defined, by default the first 3 sentences of the post are showed. You can enter your own excerpt here, if you want.', self::language_file), array('space' => true, 'class' => 'widefat', 'style' => 'height: 60px;'));
a5_checkbox($base_id.'linespace', $base_name.'[linespace]', $linespace, __('Check to have each sentence in a new line.', self::language_file), array('space' => true));
a5_checkbox($base_id.'notext', $base_name.'[notext]', $notext, sprintf(__('Check to %snot%s display the excerpt.', self::language_file), '', ''), array('space' => true));
a5_checkbox($base_id.'noshorts', $base_name.'[noshorts]', $noshorts, __('Check to suppress shortcodes in the widget (in case the content is showing).', self::language_file), array('space' => true));
a5_checkbox($base_id.'readmore', $base_name.'[readmore]', $readmore, __('Check to have an additional 'read more' link at the end of the excerpt.', self::language_file), array('space' => true));
a5_text_field($base_id.'rmtext', $base_name.'[rmtext]', $rmtext, sprintf(__('Write here some text for the 'read more' link. By default, it is %s:', self::language_file), '[…]'), array('space' => true, 'class' => 'widefat'));
a5_text_field($base_id.'class', $base_name.'[class]', $class, __('If you want to style the 'read more' link, you can enter a class here.', self::language_file), array('space' => true, 'class' => 'widefat'));
a5_checkgroup(false, false, $pages, __('Check, where you want to show the widget. By default, it is showing on the homepage and the category pages:', self::language_file), $checkall);
a5_textarea($base_id.'style', $base_name.'[style]', $style, sprintf(__('Here you can finally style the widget. Simply type something like%1$s%2$sborder: 2px solid;%2$sborder-color: #cccccc;%2$spadding: 10px;%3$s%2$sto get just a gray outline and a padding of 10 px. If you leave that section empty, your theme will style the widget.', self::language_file), '', '
', ''), array('space' => true, 'class' => 'widefat', 'style' => 'height: 60px;'));
a5_resize_textarea(array($base_id.'excerpt', $base_id.'style'), true);
}
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['article'] = strip_tags($new_instance['article']);
$instance['backup'] = strip_tags($new_instance['backup']);
$instance['thumb'] = strip_tags($new_instance['thumb']);
$instance['image'] = strip_tags($new_instance['image']);
$instance['width'] = strip_tags($new_instance['width']);
$instance['headline'] = strip_tags($new_instance['headline']);
$instance['excerpt'] = strip_tags($new_instance['excerpt']);
$instance['linespace'] = strip_tags($new_instance['linespace']);
$instance['notext'] = strip_tags($new_instance['notext']);
$instance['noshorts'] = strip_tags($new_instance['noshorts']);
$instance['readmore'] = strip_tags($new_instance['readmore']);
$instance['rmtext'] = strip_tags($new_instance['rmtext']);
$instance['adsense'] = strip_tags($new_instance['adsense']);
$instance['style'] = strip_tags($new_instance['style']);
$instance['homepage'] = strip_tags($new_instance['homepage']);
$instance['frontpage'] = strip_tags($new_instance['frontpage']);
$instance['page'] = strip_tags($new_instance['page']);
$instance['category'] = strip_tags($new_instance['category']);
$instance['single'] = strip_tags($new_instance['single']);
$instance['date'] = strip_tags($new_instance['date']);
$instance['tag'] = strip_tags($new_instance['tag']);
$instance['attachment'] = strip_tags($new_instance['attachment']);
$instance['taxonomy'] = strip_tags($new_instance['taxonomy']);
$instance['author'] = strip_tags($new_instance['author']);
$instance['search'] = strip_tags($new_instance['search']);
$instance['not_found'] = strip_tags($new_instance['not_found']);
$instance['h'] = strip_tags($new_instance['h']);
$instance['class'] = strip_tags($new_instance['class']);
return $instance;
}
function widget($args, $instance) {
// get the type of page, we're actually on
if (is_front_page()) $afpw_pagetype='frontpage';
if (is_home()) $afpw_pagetype='homepage';
if (is_page()) $afpw_pagetype='page';
if (is_category()) $afpw_pagetype='category';
if (is_single()) $afpw_pagetype='single';
if (is_date()) $afpw_pagetype='date';
if (is_tag()) $afpw_pagetype='tag';
if (is_attachment()) $afpw_pagetype='attachment';
if (is_tax()) $afpw_pagetype='taxonomy';
if (is_author()) $afpw_pagetype='author';
if (is_search()) $afpw_pagetype='search';
if (is_404()) $afpw_pagetype='not_found';
// display only, if said so in the settings of the widget
if ($instance[$afpw_pagetype]) :
$eol = "\r\n";
// the widget is displayed
extract( $args );
$title = apply_filters('widget_title', $instance['title']);
if (empty($instance['style'])) :
$afpw_before_widget=$before_widget;
$afpw_after_widget=$after_widget;
else :
$style=str_replace(array("\r\n", "\n", "\r"), ' ', $instance['style']);
$afpw_before_widget='
'.$eol.''.get_the_title().''.$eol.'
'; $afpw_headline = ($instance['h']) ? '