Permalink
Browse files

added advertisment widget

  • Loading branch information...
1 parent 1d24d52 commit 8a83bac371ac3655aa2b96789facab9b7eb536f4 @madalinungureanu committed Oct 12, 2011
@@ -46,7 +46,7 @@ function constants() {
define( 'BARESKIN_ADMIN', trailingslashit( BARESKIN_DIR ) . 'admin' );
/* Sets the path to the core framework classes directory. */
- define( 'BARESKIN_CLASSES', trailingslashit( BARESKIN_DIR ) . 'classes' );
+ define( 'BARESKIN_WIDGETS', trailingslashit( BARESKIN_DIR ) . 'widgets' );
/* Sets the path to the core framework extensions directory. */
define( 'BARESKIN_EXTENSIONS', trailingslashit( BARESKIN_DIR ) . 'extensions' );
@@ -174,6 +174,9 @@ function functions() {
/* Load breadcrumb trail functions if supported. */
require_if_theme_supports( 'bareskin-breadcrumb', trailingslashit( BARESKIN_FUNCTIONS ) . 'breadcrumb-trail.php' );
+
+ /* Load widgets functions if supported. */
+ require_if_theme_supports( 'bareskin-widgets', trailingslashit( BARESKIN_FUNCTIONS ) . 'widgets.php' );
}
}
@@ -0,0 +1,38 @@
+<?php
+/**
+ * Sets up the themes widgets. A theme must register support for the
+ * 'bareskin-widgets' feature to use the themes widgets.
+ *
+ * @package BareSkin
+ * @subpackage Functions
+ */
+
+
+/* Register BareSkin widgets. */
+add_action( 'widgets_init', 'bareskin_register_widgets' );
+
+/**
+ * Registers the themes widgets.
+ *
+ * @since 1.0.0
+ * @uses register_widget() Registers individual widgets with WordPress
+ * @link http://codex.wordpress.org/Function_Reference/register_widget
+ */
+function bareskin_register_widgets() {
+
+ /* Get themes supported widgets. */
+ $supports = get_theme_support( 'bareskin-widgets' );
+
+ /* If there are any supported widgets, load them. */
+ if ( is_array( $supports[0] ) ) {
+
+ /* Load the 'Advertisment' widget if it is supported, and register it. */
+ if ( in_array( 'advertisment', $supports[0] ) ){
+ require_once( trailingslashit( BARESKIN_WIDGETS ) . 'widget_advertisment.php' );
+
+ /* Register the advertisment widget. */
+ register_widget( 'BareSkin_Widget_Advertisment' );
+ }
+
+ }
+}
@@ -0,0 +1,51 @@
+<?php
+/**
+ * Advertisment widget class
+ *
+ * @since 1.0.0
+ */
+class BareSkin_Widget_Advertisment extends WP_Widget {
+
+ function __construct() {
+ $widget_ops = array('classname' => 'widget_advertisment', 'description' => __('Advertisment Script'));
+ $control_ops = array('width' => 400, 'height' => 350);
+ parent::__construct('advertisment', __('Advertiment'), $widget_ops, $control_ops);
+ }
+
+ function widget( $args, $instance ) {
+ extract($args);
+ $title = apply_filters( 'widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
+ $text = apply_filters( 'widget_text', $instance['text'], $instance );
+ echo $before_widget;
+ if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?>
+ <div class="advertisment"><?php echo $instance['filter'] ? wpautop($text) : $text; ?></div>
+ <?php
+ echo $after_widget;
+ }
+
+ function update( $new_instance, $old_instance ) {
+ $instance = $old_instance;
+ $instance['title'] = strip_tags($new_instance['title']);
+ if ( current_user_can('unfiltered_html') )
+ $instance['text'] = $new_instance['text'];
+ else
+ $instance['text'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text']) ) ); // wp_filter_post_kses() expects slashed
+ $instance['filter'] = isset($new_instance['filter']);
+ return $instance;
+ }
+
+ function form( $instance ) {
+ $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );
+ $title = strip_tags($instance['title']);
+ $text = esc_textarea($instance['text']);
+?>
+ <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
+ <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
+
+ <textarea class="widefat" rows="16" cols="20" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>"><?php echo $text; ?></textarea>
+
+ <p><input id="<?php echo $this->get_field_id('filter'); ?>" name="<?php echo $this->get_field_name('filter'); ?>" type="checkbox" <?php checked(isset($instance['filter']) ? $instance['filter'] : 0); ?> />&nbsp;<label for="<?php echo $this->get_field_id('filter'); ?>"><?php _e('Automatically add paragraphs'); ?></label></p>
+<?php
+ }
+}
+?>

0 comments on commit 8a83bac

Please sign in to comment.