improved widget loading architecture

This commit is contained in:
John Bintz 2009-12-20 16:00:17 -05:00
parent f7e91dd397
commit 0bca4d94be
6 changed files with 50 additions and 19 deletions

View File

@ -6,18 +6,36 @@ if (function_exists('add_theme_support')) {
}
function __comicpress_widgets_init() {
$available_widgets = array();
if (($dh = opendir(dirname(__FILE__) . '/widgets')) !== false) {
while (($file = readdir($dh)) !== false) {
if (strpos($file, '.inc') !== false) {
$class_name = preg_replace('#\..*$#', '', $file);
require_once(dirname(__FILE__) . '/widgets/' . $file);
register_widget($class_name);
$widget = new $class_name();
if (method_exists($widget, 'init')) { $widget->init(); }
$widget = new $class_name(true);
if (method_exists($widget, 'init')) {
$widget->init();
}
$available_widgets[strtolower($class_name)] = $widget;
}
}
closedir($dh);
}
foreach (wp_get_sidebars_widgets() as $type => $widgets) {
if ($type != 'wp_inactive_widgets') {
foreach ($widgets as $widget_id) {
foreach ($available_widgets as $key => $widget) {
if (strpos(strtolower($widget_id), $key) === 0) {
$widget->is_active();
}
}
}
}
}
}
function __comicpress_init() {

View File

@ -12,9 +12,11 @@ Author URI: http://frumph.net/
class ArchiveDropdownWidget extends WP_Widget {
var $modes;
function ArchiveDropdownWidget() {
$widget_ops = array('classname' => 'ArchiveDropdownWidget', 'description' => __('Display a dropdown list of your archives, styled.','comicpress') );
$this->WP_Widget('archive_dropdown', __('ComicPress Archive Dropdown','comicpress'), $widget_ops);
function ArchiveDropdownWidget($skip_widget_init = false) {
if (!$skip_widget_init) {
$widget_ops = array('classname' => __CLASS__, 'description' => __('Display a dropdown list of your archives, styled.','comicpress') );
$this->WP_Widget(__CLASS__, __('ComicPress Archive Dropdown','comicpress'), $widget_ops);
}
$this->modes = array(
'monthly_archive' => __('Monthly archive', 'comicpress'),

View File

@ -1,13 +1,18 @@
<?php
class BookmarkWidget extends WP_Widget {
function BookmarkWidget() {
$widget_ops = array('classname' => __CLASS__, 'description' => __('Allow the user to bookmark a page and then jump to it upon return.','comicpress') );
$this->WP_Widget('comicpress-bookmark', __('ComicPress Bookmark','comicpress'), $widget_ops);
function BookmarkWidget($skip_widget_init = false) {
if (!$skip_widget_init) {
$widget_ops = array('classname' => __CLASS__, 'description' => __('Allow the user to bookmark a page and then jump to it upon return.','comicpress') );
$this->WP_Widget(__CLASS__, __('ComicPress Bookmark','comicpress'), $widget_ops);
}
}
function init() {
add_action('wp_head', array(&$this, 'wp_head'));
}
function is_active() {
add_action('template_redirect', array(&$this, 'template_redirect'));
}

View File

@ -10,9 +10,11 @@ Author URI: http://frumph.net/
*/
class BuyThisPrintWidget extends WP_Widget {
function BuyThisPrintWidget() {
$widget_ops = array('classname' => 'ComicPressBuyThisPrint', 'description' => __('Adds a button that goes to the buy print template page.','comicpress') );
$this->WP_Widget('comicpress_buyprint', __('Buy This Print','comicpress'), $widget_ops);
function BuyThisPrintWidget($skip_widget_init = false) {
if (!$skip_widget_init) {
$widget_ops = array('classname' => __CLASS__, 'description' => __('Adds a button that goes to the buy print template page.','comicpress') );
$this->WP_Widget(__CLASS__, __('Buy This Print','comicpress'), $widget_ops);
}
}
function init() {
@ -21,7 +23,7 @@ class BuyThisPrintWidget extends WP_Widget {
function widget($args, $instance) {
extract($args, EXTR_SKIP);
echo $before_widget;
$title = apply_filters('widget_title', $instance['title']);
if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };

View File

@ -10,9 +10,11 @@ Author URI: http://frumph.net/
class CalendarWidget extends WP_Widget {
function CalendarWidget() {
$widget_ops = array('classname' => 'CalendarWidget', 'description' => __('Display a calendar showing this months posts. (this calendar does not drop lines if there is no title given.)','comicpress') );
$this->WP_Widget('comicpress_calendar', __('ComicPress Calendar','comicpress'), $widget_ops);
function CalendarWidget($skip_widget_init = false) {
if (!$skip_widget_init) {
$widget_ops = array('classname' => __CLASS__, 'description' => __('Display a calendar showing this months posts. (this calendar does not drop lines if there is no title given.)','comicpress') );
$this->WP_Widget(__CLASS__, __('ComicPress Calendar','comicpress'), $widget_ops);
}
}
function widget($args, $instance) {

View File

@ -11,16 +11,18 @@ Author URI: http://frumph.net/
require_once(dirname(__FILE__) . '/../classes/ComicPressNavigation.inc');
class GraphicalNavigationWidget extends WP_Widget {
function GraphicalNavigationWidget() {
$widget_ops = array('classname' => 'WidgetComicPressGraphicalStorylineNavigation', 'description' => __('Displays Graphical Navigation Buttons. (used in comic sidebars)','comicpress') );
$this->WP_Widget('graphicalstorylinenavigation', __('Comic Navigation','comicpress'), $widget_ops);
function GraphicalNavigationWidget($skip_widget_init = false) {
if (!$skip_widget_init) {
$widget_ops = array('classname' => __CLASS__, 'description' => __('Displays Graphical Navigation Buttons. (used in comic sidebars)','comicpress') );
$this->WP_Widget(__CLASS__, __('Comic Navigation','comicpress'), $widget_ops);
}
}
/**
* Initialize the widget class.
*/
function init() {
add_filter('comicpress_display_navigation_order', array(&$this, 'comicpress_display_navigation_order'));
add_filter('comicpress_display_navigation_order', array($this, 'comicpress_display_navigation_order'));
add_filter('comicpress_display_navigation_link', array(&$this, 'comicpress_display_navigation_link'), 10, 5);
add_filter('comicpress_wrap_navigation_buttons', array(&$this, 'comicpress_wrap_navigation_buttons'), 10, 2);
add_filter('comicpress_navigation_grouping_details', array(&$this, 'comicpress_navigation_grouping_details'));