array( 'title' => _a('Recent'), 'post_type' => 'post', 'mode' => 'full', 'order_by' => 'date', 'category' => 0, 'number' => 4, 'word_count' => 20, 'thumb_size' => 48, 'more' => true, 'related' => false, 'template' => atom_widget_posts::template('full'), 'allowed_tags' => 'abbr,acronym,b,cite,code,del,dfn,em,i,ins,q,strong,sub,sup', 'content_filter_more' => '[…]', ), 3 => array( 'title' => _a('Popular'), 'post_type' => 'post', 'mode' => 'full', 'order_by' => 'comment_count', 'category' => 0, 'number' => 4, 'word_count' => 20, 'thumb_size' => 48, 'more' => true, 'related' => false, 'template' => atom_widget_posts::template('full'), 'allowed_tags' => 'abbr,acronym,b,cite,code,del,dfn,em,i,ins,q,strong,sub,sup', 'content_filter_more' => '[…]', ), 4 => array( 'title' => _a('Random'), 'post_type' => 'post', 'mode' => 'full', 'order_by' => 'rand', 'category' => 0, 'number' => 4, 'word_count' => 20, 'thumb_size' => 48, 'more' => true, 'related' => false, 'template' => atom_widget_posts::template('full'), 'allowed_tags' => 'abbr,acronym,b,cite,code,del,dfn,em,i,ins,q,strong,sub,sup', 'content_filter_more' => '[…]', ), '_multiwidget' => 1)); $widgets_arbitrary = array('atom-posts-2', 'atom-posts-3', 'atom-posts-4'); $tabs = array(); foreach($widgets_arbitrary as $widget) $tabs[] = $widget; // search update_option('widget_search', array( 2 => array( 'title' => '', ), '_multiwidget' => 1)); // tabs update_option('widget_atom-tabs', array( 2 => array( 'widgets' => $tabs, 'effect' => 'fade', 'easing' => 'easeOutExpo', ), '_multiwidget' => 1)); // login update_option('widget_atom-login', array( 2 => array( 'title' =>_a('Log in'), 'text' => _a("Hello Guest. Login below if you have a account"), 'dashboard' => 1, 'profile' => 1, 'write' => 1, 'comments' => 0, ), '_multiwidget' => 1)); // authors (we add it only if the blog has more than 5 authors) if(count(explode(',', wp_list_authors(array('echo' => 0, 'style' => 'none', 'html' => 0)))) > 5): update_option('widget_atom-authors', array( 2 => array( 'title' => _a("Authors"), 'mode' => 'full', 'avatar_size' => 48, 'sort_by' => 'post_count', 'hide_empty' => true, 'exclude_admin' => false, ), '_multiwidget' => 1)); // otherwise add a blogroll else: update_option('widget_atom-links', array( 2 => array( 'title' => _a("Blogroll"), 'category' => '', 'order_by' => 'name', 'hide_invisible' => true, 'image' => false, 'rating' => true, 'description' => true, 'limit' => 24, ), '_multiwidget' => 1)); endif; // twitter update_option('widget_atom-twitter', array( 2 => array( 'title' => _a('My latest tweets'), 'user' => 'tweetnorris', 'count' => 4, 'info' => true, 'cache' => 90, ), '_multiwidget' => 1)); $gallery_page_visibility_settings = array(); foreach(get_all_page_ids() as $page_id) $gallery_page_visibility_settings["page-{$page_id}"] = false; // featured-galery update_option('widget_atom-featured-gallery', array( 2 => array_merge( array( 'source' => 'marked', 'nextgen' => 0, 'number' => 6, 'caption' => true, 'navigation' => false, 'timeframe' => 60, 'delay' => 10, 'effect' => 'fade', 'easing' => 'easeOutCirc', // hidden options 'order' => 'rand', // visibility settings -- only on the homepage 'page-home' => 1, 'page-single' => 0, 'page-category' => 0, 'page-tag' => 0, 'page-author' => 0, 'page-date' => 0, 'page-search' => 0, ), $gallery_page_visibility_settings ), '_multiwidget' => 1)); $widgets_sidebar1 = array('search-2', 'atom-tabs-2', 'atom-login-2', 'atom-authors-2', 'atom-links-2', 'atom-twitter-2'); $widgets_featured = array('atom-featured-gallery-2'); // update sidebars update_option('sidebars_widgets', array( 'sidebar-1' => $widgets_sidebar1, 'arbitrary' => $widgets_arbitrary, 'featured' => $widgets_featured, 'wp_inactive_widgets' => array(), )); endif; } /** * Echo the widget form class (only used by Atom's widgets) * * @since 1.3 * * @param object $widget Widget object */ function atom_widget_form_class($widget){ // hide widget if it doesn't appear initialized echo 'class="'.(is_numeric($widget->number) ? "atom-block {$widget->id}" : "hidden").'"'; } /** * Add extra fields in the widget settings form * based on "Display Widgets" plugin by Stephanie Wells - http://blog.strategy11.com/display-widgets * * @since 1.0 * * @param object $widget Widget object * @param string $return widget form (html output) * @param array $instance Instance options */ function atom_widget_visibility_options($widget, $return, $instance){ if(!isset($instance['visibility'])) $instance['visibility'] = 0; $nonce = wp_create_nonce('visibility-options'); if(get_class($widget) == 'atom_widget_splitter') return; // no options on splitters ?>
> number)): ?> " />
id, $instance); ?> number)): ?>
_a('Blog Homepage'), 'single' => _a('Single Post Pages'), 'category' => _a('Category Archives'), 'tag' => _a('Tag Archives'), 'author' => _a('Author Archives'), 'date' => _a('Date-based Archives'), 'search' => _a('Search Results')); $widget = $wp_registered_widgets[$widget_id]['callback'][0]; $widget_settings = atom_get_options($widget->option_name); $instance = ($instance ? $instance : $widget_settings[$widget->number]); if(isset($widget->control_options['width'])) $widget_width = $widget->control_options['width']; else $widget_width = 0; // get the active widgets from all sidebars $sidebars_widgets = wp_get_sidebars_widgets(); // prepare matches $matches = array(); foreach($wp_registered_widgets as $i => $w) if($w['name'] == $widget->name) $matches[] = $w['id']; /*/ exclude widgets from the "inactive widgets" area? -- @todo, maybe $is_inactive = false; if(!empty($sidebars_widgets['wp_inactive_widgets'])) foreach($sidebars_widgets['wp_inactive_widgets'] as $i => $value) if($value == $widget->id) $is_inactive = true; // stop, if it is (we don't add these options in inactive widgets to save bandwidth) if($is_inactive) return; //*/ // find out if the widget is in the arbitrary area, and it's position (number) $number = 0; $is_arbitrary = false; if(!empty($sidebars_widgets['arbitrary'])) foreach($sidebars_widgets['arbitrary'] as $i => $value): if(in_array($value, $matches) && !$is_arbitrary) $number = $number +1; if($value == $widget->id) $is_arbitrary = true; endforeach; ?>

$label): ?> " value="0" /> id="get_field_id("page-{$key}"); ?>" name="get_field_name("page-{$key}"); ?>" />

"; foreach ($pages as $page): // determine if widget is visible on selected page; we consider it visible if the visibility option is not set $instance["page-{$page->ID}"] = isset($instance["page-{$page->ID}"]) ? ($instance["page-{$page->ID}"] ? true : false) : true; if(!isset($instance["page-{$page->ID}"])) $instance["page-{$page->ID}"] = 1; ?> ID}"); ?>" value="0"> ID}"]) ?> id="get_field_id("page-{$page->ID}"); ?>" name="get_field_name("page-{$page->ID}"); ?>" value="1" />
"; endif; ?>

" value="0" /> id="get_field_id('user-visitor'); ?>" name="get_field_name('user-visitor'); ?>" />
" value="0" /> id="get_field_id('user-registered'); ?>" name="get_field_name('user-registered'); ?>" />

[widget '.substr(md5($widget->id), 0, 8).'][widget "'.$widget->name.'"'.(($number > 1) ? ' number='.$number : '').']'); ?>
ID}"] = (!isset($new_instance["page-{$page->ID}"]) ? 1 : intval($new_instance["page-{$page->ID}"])); $instance['user-visitor'] = (!isset($new_instance['user-visitor']) ? 1 : intval($new_instance['user-visitor'])); $instance['user-registered'] = (!isset($new_instance['user-registered']) ? 1 : intval($new_instance['user-registered'])); return $instance; } /** * Hide widget based on the current context * based on "Display Widgets" plugin by Stephanie Wells - http://blog.strategy11.com/display-widgets * * @since 1.0 * * @param array $instance Instance options * @return array|bool returns instance options if widget should be visible on the current page, false otherwise */ function atom_widget_visibility_check($instance){ if (is_home()) $show = isset($instance['page-home']) ? ($instance['page-home']) : true; else if (is_single()) $show = isset($instance['page-single']) ? ($instance['page-single']) : true; else if (is_category()) $show = isset($instance['page-category']) ? ($instance['page-category']) : true; else if (is_tag()) $show = isset($instance['page-tag']) ? ($instance['page-tag']) : true; else if (is_author()) $show = isset($instance['page-author']) ? ($instance['page-author']) : true; else if (is_date()) $show = isset($instance['page-date']) ? ($instance['page-date']) : true; else if (is_search()) $show = isset($instance['page-search']) ? ($instance['page-search']) : true; else $show = true; if (is_page()): global $wp_query; $post_id = $wp_query->get_queried_object_id(); $show = isset($instance["page-{$post_id}"]) ? ($instance["page-{$post_id}"]) : true; endif; if (!is_user_logged_in() && isset($instance['user-visitor']) && !$instance['user-visitor']) $show = false; if (is_user_logged_in() && isset($instance['user-registered']) && !$instance['user-registered']) $show = false; return $show ? $instance : false; } /** * Get the status of a widgetized area (replaces wp's is_active_sidebar) * This function also verifies if the widgets inside the sidebar are visible to the current user or not (splitters are ignored too) * Note: If we're in preview mode areas are always considered to be active, but the returned widget count may be 0 (boolean false). * (we use type equivalence checking to avoid confusions) * * @since 1.0 * * @global $wp_registered_widgets Stored registered widgets. * @global $post Current post object * @global $atom_area Sidebar output * * @param string $index Area (sidebar) ID * @return int|bool false or the visible widget count, based on widget visibility settings and current user status */ function atom_is_active_area($index){ global $wp_registered_widgets, $post, $atom_area; // always return true if the layout options are not enabled. obviously, the css designer wants to handle this if(!atom_is_option_enabled('layout')) return true; // -- same as atom_get_layout_type() -- if(is_404()): $layout = 'col-1'; // 404 pages have 1 column layout else: // the "layout" custom field - highest priority if(isset($post->ID)) $layout = get_post_meta($post->ID, 'layout', true); // custom page templates - lower priority if (empty($layout) && (is_single() || is_page()) && ($page_template = sanitize_html_class(str_replace(array('page-', '.php'), '', get_post_meta($post->ID, '_wp_page_template', true))))) if(in_array($page_template, atom_available_layout_types())) $layout = $page_template; // if no template is defined so far, revert to the global layout option from the theme settings - lowest priority if(empty($layout)) $layout = atom_get_options('layout'); endif; // -- /same as atom_get_layout_type() -- $index = (is_int($index)) ? "sidebar-{$index}" : sanitize_title($index); $sidebars_widgets = wp_get_sidebars_widgets(); $visible_widgets = 0; // only check widget settings if we have widgets in this sidebar if(!empty($sidebars_widgets[$index])) foreach($sidebars_widgets[$index] as $i => $w): if(isset($wp_registered_widgets[$w])): $number = $wp_registered_widgets[$w]['params'][0]['number']; // widget settings if(empty($wp_registered_widgets[$w]['callback'][0]->option_name)) $s = atom_get_options($wp_registered_widgets[$w]['callback_wl_redirect'][0]->option_name); // ugly for widget logic fix; need to look what's really going on there else $s = atom_get_options($wp_registered_widgets[$w]['callback'][0]->option_name); // widget instance settings $s = $s[$number]; // count only visible widgets that are not "splitters" if((strpos($w, 'atom-splitter') === false) && atom_widget_visibility_check($s)) $visible_widgets++; endif; endforeach; // always show active if we're in preview mode (eg. theme setting site preview), regardless of the contents if(atom_preview_mode()) return $visible_widgets; // check free column(s) for sidebar(s) if($index == 'sidebar-1' && $layout == 'col-1') return false; if($index == 'sidebar-2' && in_array($layout, array('col-1', 'col-2-left', 'col-2-right'))) return false; // get sidebar contents $first_check = false; if(!isset($atom_area[$index])): ob_start(); dynamic_sidebar($index); $atom_area[$index] = ob_get_clean(); $first_check = true; endif; // filter cannot be applied to the global variable because the column splitter can make irreversible changes $area_contents = apply_filters('atom_area_check', $atom_area[$index], $index); if(empty($area_contents) && $first_check) atom_add_debug_message("No active widgets in {$index}. Area disabled."); if((!empty($sidebars_widgets[$index]) && ($visible_widgets > 0)) && !empty($area_contents)) return $visible_widgets; return false; } /** * Capture the output of a widget area (sidebar); uses output buffering to allow content filtering. * Certain design types (like "Arclite") might need this to correct widget HTML. * This function also checks if the number of widget splitters present in the sidebars are even, and adds the closing splitter tags if necessary. * * @since 1.3 * * @param string $area Sidebar ID * @param bool $echo Echo result, true by default * * @return string|bool HTML output/true, or false if sidebar is empty */ function atom_widget_area($area, $echo = true){ global $atom_area; // get sidebar contents (this shouldn't run because cache should be set by is_active_area above which is called early) if(!isset($atom_area[$area])): ob_start(); dynamic_sidebar($area); $atom_area[$area] = ob_get_clean(); endif; $atom_area[$area] = apply_filters('atom_widget_area', $atom_area[$area], $area); if(!$echo) return $atom_area[$area]; if($echo && !empty($atom_area[$area])): echo $atom_area[$area]; return true; // echoed something endif; // echoed nothing return false; } /** * Get the output of a widget instance * * @since 1.3 * @global array $wp_registered_widgets * @global array $wp_registered_sidebars * * @param string $widget_id The widget instance ID * @param string $area Use this sidebar parameters to render the widget (default is 'arbitrary') * @param bool|string $remove_title Display or hide the title (eg. remove 'h2', 'h3' or false to keep the title) * * @return string Widget HTML output */ function atom_get_widget($widget_id, $area = 'arbitrary', $remove_title = 'h3'){ global $wp_registered_widgets, $wp_registered_sidebars; $widget_contents = wp_cache_get("arbitrary_{$widget_id}"); if($widget_contents === false): // does the instance exist? if(!isset($wp_registered_widgets[$widget_id]['callback'])) return atom_add_debug_message("Requested widget doesn't exist: {$widget_id}"); $callback = $wp_registered_widgets[$widget_id]['callback']; ob_start(); // catch the echo output, so we can control where it appears in the text $params = array_merge(array(array_merge($wp_registered_sidebars[$area], array('widget_id' => $widget_id, 'widget_name' => $wp_registered_widgets[$widget_id]['name']))), (array)$wp_registered_widgets[$widget_id]['params']); // align classes? //if($align) $params[0]['before_widget'] = str_replace('block', 'block align'.$align, $params[0]['before_widget']); // Substitute HTML id and class attributes into before_widget $classname_ = ''; foreach ((array)$wp_registered_widgets[$widget_id]['classname'] as $cn) if (is_string($cn)) $classname_ .= '_'.$cn; elseif (is_object($cn)) $classname_ .= '_'.get_class($cn); $classname_ = ltrim($classname_, '_'); $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $widget_id, $classname_); $params = apply_filters('dynamic_sidebar_params', $params); if (is_callable($callback)) call_user_func_array($callback, $params); // remove h3? $widget_contents = $remove_title ? preg_replace('#<'.$remove_title.' class="title">(.*?)#', '', ob_get_clean()) : ob_get_clean(); wp_cache_set("arbitrary_{$area}", $widget_contents); endif; return apply_filters("atom_widget", $widget_contents, $widget_id); // probably useless filter } /** * This is a widget form helper class. * Its only purpose is to decrease the overall code length and make widget forms easier to work with * -- Not used in the current version -- @todo when I have the time... * * @since 1.3 */ class AtomWidgetForm{ var $widget = null; var $instance = null; function AtomWidgetForm($widget, $instance){ // we should use php 5's public function __construct but WP doesn't so we do the same :( $this->widget = $widget; $this->instance = wp_parse_args($instance, $this->widget->defaults()); } function add_select($name, $label = '', $options, $args = array()){ ob_start(); $args = wp_parse_args($args, array( 'size' => false, 'class' => '', 'disabled' => false, 'rules' => '', 'after' => '', 'echo' => true, )); extract($args, EXTR_SKIP); if($rules): $rules = $rules ? "rules=\"{$rules}\"" : ''; // @todo endif; $field_id = $this->widget->get_field_id($name); $field_name = $this->widget->get_field_name($name); $field_class = $class ? "class=\"{$class}\"": ''; ?>

'', 'rules' => '', 'disabled' => false, 'echo' => true, )); extract($args, EXTR_SKIP); if($rules): $rules = $rules ? "rules=\"{$rules}\"" : ''; // @todo endif; $field_id = $this->widget->get_field_id($name); $field_name = $this->widget->get_field_name($name); $field_class = $class ? "class=\"{$class}\"": ''; ?>

instance[$name]); ?> disabled="disabled" />

'', 'class' => '', 'after' => '', 'rules' => '', 'disabled' => false, 'echo' => true, )); extract($args, EXTR_SKIP); if($rules): $rules = $rules ? "rules=\"{$rules}\"" : ''; // @todo endif; $field_id = $this->widget->get_field_id($name); $field_name = $this->widget->get_field_name($name); $field_class = $class ? "class=\"{$class}\"": ''; $field_size = $size ? "size=\"{$size}\"" : ''; ?>

id="" name="" value="" disabled="disabled" />

'8,24', 'class' => 'widefat code', 'after' => '', 'rules' => '', 'disabled' => false, 'echo' => true, )); extract($args, EXTR_SKIP); if($rules): $rules = $rules ? "rules=\"{$rules}\"" : ''; // @todo endif; $field_id = $this->widget->get_field_id($name); $field_name = $this->widget->get_field_name($name); $field_class = $class ? "class=\"{$class}\"": ''; $field_size = $size ? "size=\"{$size}\"" : ''; $size = explode(',', $size); $size = isset($size[0]) && isset($size[1]) ? "rows=\"{$size[0]}\" cols=\"{$size[1]}\"" : ''; ?>

add_textfield('title', _a('Title:'), array('class' => 'widefat'); $form->add_textfield('number', _a('Number:')); $form->add_select('effect', _a('Transition effect:'), unserialize(EFFECTS)); ... */