__('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']);
$features = get_posts('numberposts=-1');
foreach ( $features as $feature ) :
$posts[] = array($feature->ID, $feature->post_title );
endforeach;
$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)));
$pages = array (array('homepage', $homepage, __('Homepage', self::$language_file)), array('frontpage', $frontpage, __('Frontpage (e.g. a static page as homepage)', self::$language_file)), array('page', $page, __('"Page" pages', self::$language_file)), array('category', $category, __('Category pages', self::$language_file)), array('single', $single, __('Single post pages', self::$language_file)), array('date', $date, __('Archive pages', self::$language_file)), array('tag', $tag, __('Tag pages', self::$language_file)), array('attachment', $attachment, __('Attachments', self::$language_file)), array('taxonomy', $taxonomy, __('Custom Taxonomy pages (only available, if having a plugin)', self::$language_file)), array('author', $author, __('Author pages', self::$language_file)), array('search', $search, __('Search Results', self::$language_file)), array('not_found', $not_found, __('"Not Found"', self::$language_file)));
$base_id = 'widget-'.$this->id_base.'-'.$this->number.'-';
$base_name = 'widget-'.$this->id_base.'['.$this->number.']';
$field[] = array ('type' => 'text', 'id_base' => $base_id, 'name_base' => $base_name, 'field_name' => 'title', 'label' => __('Title:', self::$language_file), 'value' => $title, 'class' => 'widefat', 'space' => 1);
$field[] = array ('type' => 'select', 'id_base' => $base_id, 'name_base' => $base_name, 'field_name' => 'article', 'label' => __('Choose here the post, you want to appear in the widget.', self::$language_file), 'value' => $article, 'options' => $posts, 'default' => __('Take a random post', self::$language_file), 'class' => 'widefat', 'style' => 'width:100%', 'space' => 1);
$field[] = array ('type' => 'select', 'id_base' => $base_id, 'name_base' => $base_name, 'field_name' => 'backup', 'label' => __('Choose here the backup post. It will appear, when a single post page shows the featured article.', self::$language_file), 'value' => $backup, 'options' => $posts, 'default' => __('Take a random post', self::$language_file), 'class' => 'widefat', 'style' => 'width:100%', 'space' => 1);
$field[] = array ('type' => 'checkbox', 'id_base' => $base_id, 'name_base' => $base_name, 'field_name' => 'image', 'label' => __('Check to get the first image of the post as thumbnail.', self::$language_file), 'value' => $image, 'space' => 1);
$field[] = array ('type' => 'number', 'id_base' => $base_id, 'name_base' => $base_name, 'field_name' => 'width', 'label' => __('This is the width in px of the thumbnail (if choosing an image):', self::$language_file), 'value' => $width, 'size' => 4, 'step' => 1, 'space' => 1);
$field[] = array ('type' => 'checkbox', 'id_base' => $base_id, 'name_base' => $base_name, 'field_name' => 'thumb', 'label' => sprintf(__('Check to %snot%s display the thumbnail of the post.', self::$language_file), '', ''), 'value' => $thumb, 'space' => 1);
$field[] = array ('type' => 'select', 'id_base' => $base_id, 'name_base' => $base_name, 'field_name' => 'headline', 'label' => __('Choose, whether or not to display the title and whether it comes above or under the thumbnail.', self::$language_file), 'value' => $headline, 'options' => $options, 'class' => 'widefat', 'style' => 'width:100%', 'space' => 1);
$field[] = array ('type' => 'textarea', 'id_base' => $base_id, 'name_base' => $base_name, 'field_name' => 'excerpt', 'class' => 'widefat', 'label' => __('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), 'value' => $excerpt, 'space' => 1);
$field[] = array ('type' => 'checkbox', 'id_base' => $base_id, 'name_base' => $base_name, 'field_name' => 'linespace', 'label' => __('Check to have each sentence in a new line.', self::$language_file), 'value' => $linespace, 'space' => 1);
$field[] = array ('type' => 'checkbox', 'id_base' => $base_id, 'name_base' => $base_name, 'field_name' => 'noshorts', 'label' => __('Check to suppress shortcodes in the widget (in case the content is showing).', self::$language_file), 'value' => $noshorts, 'space' => 1);
$field[] = array ('type' => 'checkbox', 'id_base' => $base_id, 'name_base' => $base_name, 'field_name' => 'readmore', 'label' => __('Check to have an additional 'read more' link at the end of the excerpt.', self::$language_file), 'value' => $readmore, 'space' => 1);
$field[] = array ('type' => 'text', 'id_base' => $base_id, 'name_base' => $base_name, 'field_name' => 'rmtext', 'label' => __('Write here some text for the 'read more' link. By default, it is', self::$language_file).' […]:', 'value' => $rmtext, 'class' => 'widefat', 'space' => 1);
if (defined('AE_AD_TAGS') && AE_AD_TAGS==1) :
$field[] = array ('type' => 'checkbox', 'id_base' => $base_id, 'name_base' => $base_name, 'field_name' => 'adsense', 'label' => __('Check if you want to invert the Google AdSense Tags that are defined with the Ads Easy Plugin. E.g. when they are turned off for the sidebar, they will appear in the widget.', self::$language_file), 'value' => $adsense, 'space' => 1);
endif;
$field[] = array ('type' => 'checkgroup', 'id_base' => $base_id, 'name_base' => $base_name, 'label' => __('Check, where you want to show the widget. By default, it is showing on the homepage and the category pages:', self::$language_file), 'options' => $pages, 'checkall' => __('Check all', self::$language_file));
$field[] = array ('type' => 'textarea', 'id_base' => $base_id, 'name_base' => $base_name, 'field_name' => 'style', 'class' => 'widefat', 'label' => 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), '', '
', ''), 'value' => $style, 'space' => 1);
$field[] = array ('type' => 'resize', 'id_base' => $base_id, 'field_name' => array('excerpt', 'style'));
foreach ($field as $args) :
$menu_item = new A5_WidgetControlClass($args);
endforeach;
}
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']);
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]) :
// 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.'
'; endif; // thumbnail, if wanted if (!$instance['thumb']) : if ($instance['image']) : $args = array ( 'content' => $post->post_content, 'width' => $instance['width'], 'option' => 'afpw_options' ); $afpw_image = new A5_Thumbnail; $afpw_image_info = $afpw_image->get_thumbnail($args); $afpw_thumb = $afpw_image_info['thumb']; $afpw_width = $afpw_image_info['thumb_width']; $afpw_height = $afpw_image_info['thumb_height']; if ($afpw_thumb) : if ($afpw_width) $afpw_img_tag = ''.do_shortcode($afpw_text).'
'.$eol; endforeach; // hooking into ads easy for the google tags echo $afpw_after_widget; if (AE_AD_TAGS == 1 && $instance['adsense']) : $ae_options = get_option('ae_options'); do_action('google_end_tag'); if ($ae_options['ae_sidebar']==1) do_action('google_start_tag'); else do_action('google_ignore_tag'); endif; endif; } // widget } // Advanced Featured Post Widget add_action('widgets_init', create_function('', 'return register_widget("Advanced_Featured_Post_Widget");')); ?>