From 390343fafe3727ef22068af3d262bcc7b8107573 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Thu, 16 Apr 2015 23:02:05 +1000 Subject: [PATCH] Add widget alignment --- assets/css/sportspress.css | 17 +++ .../widgets/class-sp-widget-countdown.php | 4 + .../widgets/class-sp-widget-event-blocks.php | 4 + .../class-sp-widget-event-calendar.php | 4 + .../widgets/class-sp-widget-event-list.php | 4 + .../widgets/class-sp-widget-league-table.php | 4 + .../class-sp-widget-player-gallery.php | 4 + .../widgets/class-sp-widget-player-list.php | 4 + includes/widgets/class-sp-widget-staff.php | 4 + modules/sportspress-widget-alignment.php | 123 ++++++++++++++++++ 10 files changed, 172 insertions(+) create mode 100644 modules/sportspress-widget-alignment.php diff --git a/assets/css/sportspress.css b/assets/css/sportspress.css index 306efb5f..3b0875fc 100644 --- a/assets/css/sportspress.css +++ b/assets/css/sportspress.css @@ -105,6 +105,23 @@ cursor: default; } +/* Widget Alignment */ +.sp-widget-align-none { + clear: both; + overflow: auto; + zoom: 1; +} +.sp-widget-align-left { + width: 48.387%; + float: left; + clear: left; +} +.sp-widget-align-right { + width: 48.387%; + float: right; + clear: right; +} + /* League Table */ .sp-league-table td { line-height: 2em; diff --git a/includes/widgets/class-sp-widget-countdown.php b/includes/widgets/class-sp-widget-countdown.php index a42ba733..68541828 100644 --- a/includes/widgets/class-sp-widget-countdown.php +++ b/includes/widgets/class-sp-widget-countdown.php @@ -13,7 +13,10 @@ class SP_Widget_Countdown extends WP_Widget { $id = empty($instance['id']) ? null : $instance['id']; $show_venue = empty($instance['show_venue']) ? false : $instance['show_venue']; $show_league = empty($instance['show_league']) ? false : $instance['show_league']; + + do_action( 'sportspress_before_widget', $args, $instance, 'countdown' ); echo $before_widget; + if ( $title ) echo $before_title . $title . $after_title; @@ -26,6 +29,7 @@ class SP_Widget_Countdown extends WP_Widget { do_action( 'sportspress_after_widget_template', $args, $instance, 'countdown' ); echo $after_widget; + do_action( 'sportspress_after_widget', $args, $instance, 'countdown' ); } function update( $new_instance, $old_instance ) { diff --git a/includes/widgets/class-sp-widget-event-blocks.php b/includes/widgets/class-sp-widget-event-blocks.php index ea592e15..0cfb30fd 100644 --- a/includes/widgets/class-sp-widget-event-blocks.php +++ b/includes/widgets/class-sp-widget-event-blocks.php @@ -17,7 +17,10 @@ class SP_Widget_Event_Blocks extends WP_Widget { $number = empty($instance['number']) ? null : $instance['number']; $order = empty($instance['order']) ? 'default' : $instance['order']; $show_all_events_link = empty($instance['show_all_events_link']) ? false : $instance['show_all_events_link']; + + do_action( 'sportspress_before_widget', $args, $instance, 'event-blocks' ); echo $before_widget; + if ( $title ) echo $before_title . $title . $after_title; @@ -30,6 +33,7 @@ class SP_Widget_Event_Blocks extends WP_Widget { do_action( 'sportspress_after_widget_template', $args, $instance, 'event-blocks' ); echo $after_widget; + do_action( 'sportspress_after_widget', $args, $instance, 'event-blocks' ); } function update( $new_instance, $old_instance ) { diff --git a/includes/widgets/class-sp-widget-event-calendar.php b/includes/widgets/class-sp-widget-event-calendar.php index bca6e9e1..ad9607f2 100644 --- a/includes/widgets/class-sp-widget-event-calendar.php +++ b/includes/widgets/class-sp-widget-event-calendar.php @@ -15,7 +15,10 @@ class SP_Widget_Event_Calendar extends WP_Widget { $date_from = empty($instance['date_from']) ? 'default' : $instance['date_from']; $date_to = empty($instance['date_to']) ? 'default' : $instance['date_to']; $show_all_events_link = empty($instance['show_all_events_link']) ? false : $instance['show_all_events_link']; + + do_action( 'sportspress_before_widget', $args, $instance, 'event-calendar' ); echo $before_widget; + if ( $title ) echo $before_title . $title . $after_title; @@ -28,6 +31,7 @@ class SP_Widget_Event_Calendar extends WP_Widget { do_action( 'sportspress_after_widget_template', $args, $instance, 'event-calendar' ); echo $after_widget; + do_action( 'sportspress_after_widget', $args, $instance, 'event-calendar' ); } function update( $new_instance, $old_instance ) { diff --git a/includes/widgets/class-sp-widget-event-list.php b/includes/widgets/class-sp-widget-event-list.php index 277080bd..4f530825 100644 --- a/includes/widgets/class-sp-widget-event-list.php +++ b/includes/widgets/class-sp-widget-event-list.php @@ -18,7 +18,10 @@ class SP_Widget_Event_List extends WP_Widget { $columns = empty($instance['columns']) ? null : $instance['columns']; $order = empty($instance['order']) ? 'default' : $instance['order']; $show_all_events_link = empty($instance['show_all_events_link']) ? false : $instance['show_all_events_link']; + + do_action( 'sportspress_before_widget', $args, $instance, 'event-list' ); echo $before_widget; + if ( $title ) echo $before_title . $title . $after_title; @@ -31,6 +34,7 @@ class SP_Widget_Event_List extends WP_Widget { do_action( 'sportspress_after_widget_template', $args, $instance, 'event-list' ); echo $after_widget; + do_action( 'sportspress_after_widget', $args, $instance, 'event-list' ); } function update( $new_instance, $old_instance ) { diff --git a/includes/widgets/class-sp-widget-league-table.php b/includes/widgets/class-sp-widget-league-table.php index c0674ca4..5a84b08c 100644 --- a/includes/widgets/class-sp-widget-league-table.php +++ b/includes/widgets/class-sp-widget-league-table.php @@ -15,7 +15,10 @@ class SP_Widget_League_Table extends WP_Widget { $columns = empty($instance['columns']) ? array() : $instance['columns']; $show_team_logo = empty($instance['show_team_logo']) ? false : $instance['show_team_logo']; $show_full_table_link = empty($instance['show_full_table_link']) ? false : $instance['show_full_table_link']; + + do_action( 'sportspress_before_widget', $args, $instance, 'league-table' ); echo $before_widget; + if ( $title ) echo $before_title . $title . $after_title; @@ -28,6 +31,7 @@ class SP_Widget_League_Table extends WP_Widget { do_action( 'sportspress_after_widget_template', $args, $instance, 'league-table' ); echo $after_widget; + do_action( 'sportspress_after_widget', $args, $instance, 'league-table' ); } function update( $new_instance, $old_instance ) { diff --git a/includes/widgets/class-sp-widget-player-gallery.php b/includes/widgets/class-sp-widget-player-gallery.php index bb7c6c81..a19f87cb 100644 --- a/includes/widgets/class-sp-widget-player-gallery.php +++ b/includes/widgets/class-sp-widget-player-gallery.php @@ -17,7 +17,10 @@ class SP_Widget_Player_Gallery extends WP_Widget { $order = empty($instance['order']) ? 'ASC' : $instance['order']; $show_all_players_link = empty($instance['show_all_players_link']) ? false : $instance['show_all_players_link']; $show_names_on_hover = empty($instance['show_names_on_hover']) ? false : $instance['show_names_on_hover']; + + do_action( 'sportspress_before_widget', $args, $instance, 'player-gallery' ); echo $before_widget; + if ( $title ) echo $before_title . $title . $after_title; @@ -30,6 +33,7 @@ class SP_Widget_Player_Gallery extends WP_Widget { do_action( 'sportspress_after_widget_template', $args, $instance, 'player-gallery' ); echo $after_widget; + do_action( 'sportspress_after_widget', $args, $instance, 'player-gallery' ); } function update( $new_instance, $old_instance ) { diff --git a/includes/widgets/class-sp-widget-player-list.php b/includes/widgets/class-sp-widget-player-list.php index fa0ac509..bfaaf64a 100644 --- a/includes/widgets/class-sp-widget-player-list.php +++ b/includes/widgets/class-sp-widget-player-list.php @@ -16,7 +16,10 @@ class SP_Widget_Player_list extends WP_Widget { $orderby = empty($instance['orderby']) ? 'default' : $instance['orderby']; $order = empty($instance['order']) ? 'ASC' : $instance['order']; $show_all_players_link = empty($instance['show_all_players_link']) ? false : $instance['show_all_players_link']; + + do_action( 'sportspress_before_widget', $args, $instance, 'player-list' ); echo $before_widget; + if ( $title ) echo $before_title . $title . $after_title; @@ -29,6 +32,7 @@ class SP_Widget_Player_list extends WP_Widget { do_action( 'sportspress_after_widget_template', $args, $instance, 'player-list' ); echo $after_widget; + do_action( 'sportspress_after_widget', $args, $instance, 'player-list' ); } function update( $new_instance, $old_instance ) { diff --git a/includes/widgets/class-sp-widget-staff.php b/includes/widgets/class-sp-widget-staff.php index 8ce6e2a3..864fa114 100644 --- a/includes/widgets/class-sp-widget-staff.php +++ b/includes/widgets/class-sp-widget-staff.php @@ -10,7 +10,10 @@ class SP_Widget_Staff extends WP_Widget { extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? null : $instance['title'], $instance, $this->id_base); $id = empty($instance['id']) ? null : $instance['id']; + + do_action( 'sportspress_before_widget', $args, $instance, 'staff' ); echo $before_widget; + if ( $title ) echo $before_title . $title . $after_title; @@ -24,6 +27,7 @@ class SP_Widget_Staff extends WP_Widget { do_action( 'sportspress_after_widget_template', $args, $instance, 'staff' ); echo $after_widget; + do_action( 'sportspress_after_widget', $args, $instance, 'staff' ); } function update( $new_instance, $old_instance ) { diff --git a/modules/sportspress-widget-alignment.php b/modules/sportspress-widget-alignment.php new file mode 100644 index 00000000..01c4e884 --- /dev/null +++ b/modules/sportspress-widget-alignment.php @@ -0,0 +1,123 @@ +define_constants(); + + // Initialize + add_action( 'init', array( $this, 'init' ) ); + + // Widgets + add_filter( 'sportspress_widget_update', array( $this, 'widget_update' ), 10, 2 ); + add_filter( 'sportspress_widget_defaults', array( $this, 'widget_defaults' ) ); + add_action( 'sportspress_before_widget_template_form', array( $this, 'before_widget_form' ), 10, 2 ); + add_action( 'sportspress_before_widget', array( $this, 'before_widget'), 10, 2 ); + add_action( 'sportspress_after_widget', array( $this, 'after_widget') ); + } + + /** + * Define constants + */ + private function define_constants() { + if ( !defined( 'SP_WIDGET_ALIGNMENT_VERSION' ) ) + define( 'SP_WIDGET_ALIGNMENT_VERSION', '1.8' ); + + if ( !defined( 'SP_WIDGET_ALIGNMENT_URL' ) ) + define( 'SP_WIDGET_ALIGNMENT_URL', plugin_dir_url( __FILE__ ) ); + + if ( !defined( 'SP_WIDGET_ALIGNMENT_DIR' ) ) + define( 'SP_WIDGET_ALIGNMENT_DIR', plugin_dir_path( __FILE__ ) ); + } + + /** + * Initialize + */ + public function init() { + $this->options = array( + 'none' => __( 'None', 'sportspress' ), + 'left' => __( 'Left', 'sportspress' ), + 'right' => __( 'Right', 'sportspress' ), + ); + } + + /** + * Widget update + */ + function widget_update( $instance, $new_instance ) { + $instance['align'] = strip_tags( $new_instance['align'] ); + return $instance; + } + + /** + * Widget defaults + */ + function widget_defaults( $defaults ) { + $defaults['align'] = 'none'; + return $defaults; + } + + /** + * Before widget forms + */ + function before_widget_form( $object, $instance ) { + ?> +

+ +

+ '; + } + + /** + * After widget + */ + function after_widget() { + echo ''; + } +} + +endif; + +new SportsPress_Widget_Alignment();