__('You can show ads in your sidebars and other widgetareas with this widget. Define, on what kind of pages they will show up.', self::language_file) );
$control_opts = array ( 'width' => 400 );
parent::WP_Widget(false, $name = 'Ads Easy', $widget_opts, $control_opts);
self::$options = get_option('ae_options');
}
function form($instance) {
$defaults = array(
'title' => NULL,
'name' => NULL,
'adblock' => NULL,
'style' => NULL,
'homepage' => 1,
'frontpage' => false,
'page' => false,
'category' => 1,
'single' => false,
'date' => false,
'archive' => false,
'tag' => false,
'attachment' => false,
'taxonomy' => false,
'author' => false,
'search' => false,
'not_found' => false,
'login_page' => false,
'logged_in' => 1,
'search_engine' => 1,
'normal' => 1
);
$instance = wp_parse_args( (array) $instance, $defaults );
$title = esc_attr($instance['title']);
$name = esc_attr($instance['name']);
$adblock = $instance['adblock'];
$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']);
$archive=esc_attr($instance['archive']);
$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']);
$login_page=esc_attr($instance['login_page']);
$logged_in=esc_attr($instance['logged_in']);
$search_engine=esc_attr($instance['search_engine']);
$normal=esc_attr($instance['normal']);
$base_id = 'widget-'.$this->id_base.'-'.$this->number.'-';
$base_name = 'widget-'.$this->id_base.'['.$this->number.']';
$options = 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.'archive', $base_name.'[archive]', $archive, __('Post type archives', 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)),
array($base_id.'login_page', $base_name.'[login_page]', $login_page, __('Login Page (only available, if having a plugin)', self::language_file))
);
$checkall = array($base_id.'checkall', $base_name.'[checkall]', __('Check all', self::language_file));
a5_text_field($base_id.'name', $base_name.'[name]', $name, __('Title (will be displayed in blog):', self::language_file), array('space' => true, 'class' => 'widefat'));
a5_text_field($base_id.'title', $base_name.'[title]', $title, __('Adname (internal widgettitle):', self::language_file), array('space' => true, 'class' => 'widefat'));
a5_checkgroup(false, false, $options, __('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_checkbox($base_id.'logged_in', $base_name.'[logged_in]', $logged_in, __('Show to logged in users.', self::language_file), array('space' => true));
a5_checkbox($base_id.'search_engine', $base_name.'[search_engine]', $search_engine, __('Show to visitors, who come from search engines.', self::language_file), array('space' => true));
a5_checkbox($base_id.'normal', $base_name.'[normal]', $normal, __('Show to other visitors.', self::language_file), array('space' => true));
a5_textarea($base_id.'adblock', $base_name.'[adblock]', $adblock, __('Just paste the code of your ad here.', self::language_file), array('space' => true, 'style' => 'height: 60px;', 'class' => 'widefat'));
if (empty(self::$options['ae_css'])) 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: 1px solid;%1$sborder-color: #000000;%3$s%1$sto get just a black line around the widget. If you leave that section empty, your theme will style the widget.', self::language_file), '
', '', ''), array('space' => true, 'style' => 'height: 60px;', 'class' => 'widefat'));
a5_resize_textarea(array($base_id.'adblock', $base_id.'style'), true);
}
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['name'] = strip_tags($new_instance['name']);
$instance['adblock'] = trim($new_instance['adblock']);
$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['archive'] = strip_tags($new_instance['archive']);
$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['login_page'] = @$new_instance['login_page'];
$instance['logged_in'] = strip_tags($new_instance['logged_in']);
$instance['search_engine'] = strip_tags($new_instance['search_engine']);
$instance['normal'] = strip_tags($new_instance['normal']);
return $instance;
}
function widget($args, $instance) {
$visitor = $this->get_visitor();
if (!empty($instance[$visitor])) :
// get the type of page, we're actually on
if (is_front_page()) $ae_pagetype='frontpage';
if (is_home()) $ae_pagetype='homepage';
if (is_page()) $ae_pagetype='page';
if (is_category()) $ae_pagetype='category';
if (is_single()) $ae_pagetype='single';
if (is_date()) $ae_pagetype='date';
if (is_archive()) $ae_pagetype='archive';
if (is_tag()) $ae_pagetype='tag';
if (is_attachment()) $ae_pagetype='attachment';
if (is_tax()) $ae_pagetype='taxonomy';
if (is_author()) $ae_pagetype='author';
if (is_search()) $ae_pagetype='search';
if (is_404()) $ae_pagetype='not_found';
if (!isset($ae_pagetype)) $ae_pagetype = 'login_page';
// display only, if said so in the settings of the widget
if ($instance[$ae_pagetype]) :
// the widget is displayed
extract( $args );
$title = apply_filters('widget_title', $instance['name']);
if (empty($instance['style'])) :
$ae_before_widget=$before_widget;
$ae_after_widget=$after_widget;
else :
$ae_style=str_replace(array("\r\n", "\n", "\r"), '', $instance['style']);
$ae_before_widget='