__('Configure the output and looks of the widget. Then display thumbnails and excerpts of posts in your sidebars and define, on what kind of pages they will show.', 'advanced-cc') );
$control_opts = array( 'width' => 400 );
parent::__construct(false, $name = 'Advanced Category Column', $widget_opts, $control_opts);
self::$options = get_option('acc_options');
}
function form($instance) {
// setup some default settings
$defaults = array(
'title' => NULL,
'postcount' => 5,
'offset' => 3,
'home' => 1,
'list' => NULL,
'showcat' => NULL,
'showcat_txt' => NULL,
'wordcount' => 3,
'linespace' => NULL,
'width' => get_option('thumbnail_size_w'),
'words' => NULL,
'readmore' => false,
'rmtext' => NULL,
'rmclass' => NULL,
'line' => 1,
'line_color' => '#dddddd',
'style' => NULL,
'homepage' => 1,
'frontpage' => NULL,
'page' => NULL,
'category' => 1,
'single' => NULL,
'date' => NULL,
'archive' => NULL,
'tag' => NULL,
'attachment' => NULL,
'taxonomy' => NULL,
'author' => NULL,
'search' => NULL,
'not_found' => NULL,
'login_page' => NULL,
'h' => 3,
'imgborder' => NULL,
'filter' => NULL
);
$instance = wp_parse_args( (array) $instance, $defaults );
$title = esc_attr($instance['title']);
$postcount = esc_attr($instance['postcount']);
$offset = esc_attr($instance['offset']);
$home = esc_attr($instance['home']);
$list = esc_attr($instance['list']);
$showcat = esc_attr($instance['showcat']);
$showcat_txt = esc_attr($instance['showcat_txt']);
$wordcount = esc_attr($instance['wordcount']);
$linespace = esc_attr($instance['linespace']);
$width = esc_attr($instance['width']);
$words = esc_attr($instance['words']);
$readmore = $instance['readmore'];
$rmtext = esc_attr($instance['rmtext']);
$rmclass = esc_attr($instance['rmclass']);
$line=esc_attr($instance['line']);
$line_color=esc_attr($instance['line_color']);
$style=esc_attr($instance['style']);
$homepage = $instance['homepage'];
$frontpage = $instance['frontpage'];
$page = $instance['page'];
$category = $instance['category'];
$single = $instance['single'];
$date = $instance['date'];
$archive = $instance['archive'];
$tag = $instance['tag'];
$attachment = $instance['attachment'];
$taxonomy = $instance['taxonomy'];
$author = $instance['author'];
$search = $instance['search'];
$not_found = $instance['not_found'];
$login_page = $instance['login_page'];
$h = esc_attr($instance['h']);
$filter = esc_attr($instance['filter']);
$imgborder=esc_attr($instance['imgborder']);
$base_id = 'widget-'.$this->id_base.'-'.$this->number.'-';
$base_name = 'widget-'.$this->id_base.'['.$this->number.']';
a5_text_field($base_id.'title', $base_name.'[title]', $title, __('Title:', 'advanced-cc'), array('space' => true, 'class' => 'widefat'));
a5_text_field($base_id.'list', $base_name.'[list]', $list, sprintf(__('To exclude certain categories or to show just a special category, simply write their ID's separated by comma (e.g. %s-5, 2, 4%s will show categories 2 and 4 and will exclude category 5):', 'advanced-cc'), '', ''), array('space' => true, 'class' => 'widefat'));
a5_checkbox($base_id.'showcat', $base_name.'[showcat]', $showcat, __('Check to show the categories in which the post is filed.', 'advanced-cc'), array('space' => true));
a5_text_field($base_id.'showcat_txt', $base_name.'[showcat_txt]', $showcat_txt, __('Give some text that you want in front of the post's categtories (i.e 'filed under':', 'advanced-cc'), array('space' => true, 'class' => 'widefat'));
a5_number_field($base_id.'postcount', $base_name.'[postcount]', $postcount, __('How many posts will be displayed in the sidebar:', 'advanced-cc'), array('space' => true, 'size' => 4, 'step' => 1));
a5_number_field($base_id.'offset', $base_name.'[offset]', $offset, __('Offset (how many posts are spared out in the beginning):', 'advanced-cc'), array('space' => true, 'size' => 4, 'step' => 1));
a5_checkbox($base_id.'home', $base_name.'[home]', $home, __('Check to have the offset only on your homepage.', 'advanced-cc'), array('space' => true));
a5_number_field($base_id.'width', $base_name.'[width]', $width, __('Width of the thumbnail (in px):', 'advanced-cc'), array('space' => true, 'size' => 4, 'step' => 1));
a5_text_field($base_id.'imgborder', $base_name.'[imgborder]', $imgborder, sprintf(__('If wanting a border around the image, write the style here. %s would make it a black border, 1px wide.', 'advanced-cc'), '1px solid #000000'), array('space' => true, 'class' => 'widefat'));
parent::select_heading($instance);
a5_number_field($base_id.'wordcount', $base_name.'[wordcount]', $wordcount, __('In case there is no excerpt defined, how many sentences are displayed:', 'advanced-cc'), array('space' => true, 'size' => 4, 'step' => 1));
a5_checkbox($base_id.'words', $base_name.'[words]', $words, __('Check to display words instead of sentences.', 'advanced-cc'), array('space' => true));
a5_checkbox($base_id.'linespace', $base_name.'[linespace]', $linespace, __('Check to have each sentense in a new line.', 'advanced-cc'), array('space' => true));
parent::read_more($instance);
a5_checkbox($base_id.'filter', $base_name.'[filter]', $filter, __('Check to return the excerpt unfiltered (might avoid interferences with other plugins).', 'advanced-cc'), array('space' => true));
a5_number_field($base_id.'line', $base_name.'[line]', $line, __('If you want a line between the posts, this is the height in px (if not wanting a line, leave emtpy):', 'advanced-cc'), array('space' => true, 'size' => 4, 'step' => 1));
a5_color_field($base_id.'line_color', $base_name.'[line_color]', $line_color, __('The color of the line (e.g. #cccccc):', 'advanced-cc'), array('space' => true, 'size' => 13));
parent::page_checkgroup($instance);
a5_textarea($base_id.'style', $base_name.'[style]', $style, sprintf(__('Here you can finally style the widget. Simply type something like%sto get just a gray outline and a padding of 10 px. If you leave that section empty, your theme will style the widget.', 'a5-recent-posts'), '
border: 2px solid;
border-color: #cccccc;
padding: 10px;
'), array('space' => true, 'class' => 'widefat', 'style' => 'height: 60px;'));
a5_resize_textarea($base_id.'style');
} // form
function update($new_instance, $old_instance) {
unset(self::$options['cache'][$this->number]);
global $wpdb;
$update_args = array('option_value' => serialize(self::$options));
$result = $wpdb->update( $wpdb->options, $update_args, array( 'option_name' => 'acc_options' ) );
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['postcount'] = strip_tags($new_instance['postcount']);
$instance['offset'] = strip_tags($new_instance['offset']);
$instance['home'] = @$new_instance['home'];
$instance['list'] = strip_tags($new_instance['list']);
$instance['showcat'] = @$new_instance['showcat'];
$instance['showcat_txt'] = strip_tags($new_instance['showcat_txt']);
$instance['wordcount'] = strip_tags($new_instance['wordcount']);
$instance['width'] = strip_tags($new_instance['width']);
$instance['words'] = @$new_instance['words'];
$instance['linespace'] = @$new_instance['linespace'];
$instance['readmore'] = @$new_instance['readmore'];
$instance['rmtext'] = strip_tags($new_instance['rmtext']);
$instance['rmclass'] = strip_tags($new_instance['rmclass']);
$instance['line'] = strip_tags($new_instance['line']);
$instance['line_color'] = strip_tags($new_instance['line_color']);
$instance['style'] = strip_tags($new_instance['style']);
$instance['homepage'] = @$new_instance['homepage'];
$instance['frontpage'] = @$new_instance['frontpage'];
$instance['page'] = @$new_instance['page'];
$instance['category'] = @$new_instance['category'];
$instance['single'] = @$new_instance['single'];
$instance['date'] = @$new_instance['date'];
$instance['archive'] = @$new_instance['archive'];
$instance['tag'] = @$new_instance['tag'];
$instance['attachment'] = @$new_instance['attachment'];
$instance['taxonomy'] = @$new_instance['taxonomy'];
$instance['author'] = @$new_instance['author'];
$instance['search'] = @$new_instance['search'];
$instance['not_found'] = @$new_instance['not_found'];
$instance['login_page'] = @$new_instance['login_page'];
$instance['h'] = strip_tags($new_instance['h']);
$instance['filter'] = @$new_instance['filter'];
$instance['imgborder'] = strip_tags($new_instance['imgborder']);
return $instance;
} // update
function widget($args, $instance) {
$eol = "\n";
$show_widget = parent::check_output($instance);
if ($show_widget) :
// the widget is displayed
extract( $args );
$title = apply_filters('widget_title', $instance['title']);
if (!empty($instance['style'])) :
$style=str_replace(array("\r\n", "\n", "\r"), '', $instance['style']);
$before_widget = str_replace('>', 'style="'.$style.'">', $before_widget);
endif;
echo $before_widget;
if ( $title ) echo $before_title . $title . $after_title;
/* This is the actual function of the widget, it fills the sidebar with the customized posts */
$i=1;
global $wp_query, $post;
$acc_setup['posts_per_page'] = $instance['postcount'];
if (is_category() || is_home() || empty($instance['home'])) :
$acc_page = $wp_query->get( 'paged' );
$acc_numberposts = $wp_query->get( 'posts_per_page' );
$acc_offset = (empty($acc_page)) ? $acc_offset=$instance['offset'] : $acc_offset=(($acc_page-1)*$acc_numberposts)+$instance['offset'];
$acc_setup['offset'] = $acc_offset;
endif;
$acc_cat = (is_category()) ? ',-'.get_query_var('cat') : '';
if ($instance['list'] || !empty($acc_cat)) $acc_setup['cat'] = $instance['list'].$acc_cat;
if (is_single()) :
$acc_setup['post__not_in'] = array($wp_query->get_queried_object_id());
endif;
$acc_posts = new WP_Query($acc_setup);
$count = 0;
while($acc_posts->have_posts()) :
$acc_posts->the_post();
setup_postdata($post);
if ($instance['showcat']) :
$post_byline = ($instance['showcat_txt']) ? $eol.'
'.$eol.$instance['showcat_txt'].' ' : $eol.'
'; echo $post_byline; the_category(', '); echo $eol.'
'.$eol; endif; if (isset(self::$options['cache'][$this->number][$post->ID]['tags'])) : $acc_tags = self::$options['cache'][$this->number][$post->ID]['tags']; else : $acc_tags = A5_Image::tags(); self::$options['cache'][$this->number][$post->ID]['tags'] = $acc_tags; update_option('acc_options', self::$options); endif; $acc_image_alt = $acc_tags['image_alt']; $acc_image_title = $acc_tags['image_title']; $acc_title_tag = $acc_tags['title_tag']; $acc_headline = '