Skip to content

Commit

Permalink
Widget revisions
Browse files Browse the repository at this point in the history
Signed-off-by: M.Satrya <[email protected]>
  • Loading branch information
M.Satrya committed Aug 15, 2013
1 parent 850525f commit e0fde5a
Showing 1 changed file with 18 additions and 28 deletions.
46 changes: 18 additions & 28 deletions includes/widget-tokokoo-instagram.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Tokokoo_Instagram_Widget extends WP_Widget {
/**
* Widget setup
*/
function Tokokoo_Instagram_Widget() {
function __construct() {
$widget_ops = array(
'classname' => 'tokokoo-instagram-widget',
'description' => __('Show Instagram photos in your sidebar easily.', 'koo-instagram')
Expand All @@ -24,7 +24,8 @@ function Tokokoo_Instagram_Widget() {
'id_base' => 'tokokoo_instagram_widget'
);

$this->WP_Widget('tokokoo_instagram_widget', __('&raquo; Tokokoo Instagram', 'koo-instagram'), $widget_ops, $control_ops);
parent::__construct('tokokoo_instagram_widget', __('&raquo; Tokokoo Instagram', 'koo-instagram'), $widget_ops, $control_ops);

}

/**
Expand All @@ -33,10 +34,9 @@ function Tokokoo_Instagram_Widget() {
function widget($args, $instance) {
extract($args, EXTR_SKIP);

$title = apply_filters('widget_title', $instance['title']);
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
$show = $instance['show'];
$count = $instance['count'];
$cache_time = (int) $instance['cache_time'];
$count = (int)( $instance['count'] );

$settings = get_option( 'tokokoo-instagram' );
$no_result = ( !empty( $settings['no_result_text'] ) ) ? $settings['no_result_text'] : __( 'There is no images found.', 'koo-instagram' );
Expand Down Expand Up @@ -94,12 +94,9 @@ function widget($args, $instance) {
function update( $new_instance, $old_instance ) {

$instance = $old_instance;
$instance['title'] = esc_attr( $new_instance['title'] );
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['show'] = $new_instance['show'];
$instance['count'] = $new_instance['count'];
$instance['cache_time'] = $new_instance['cache_time'];

//delete_transient('rpwewidget_' . $this->id);
$instance['count'] = (int)( $new_instance['count'] );

return $instance;
}
Expand All @@ -112,40 +109,33 @@ function form( $instance ) {
/* Set up some default widget settings. */
$defaults = array(
'title' => '',
'show' => 'self',
'count' => 8,
'cache_time' => 1800
'show' => 'recent',
'count' => 8
);

$instance = wp_parse_args( (array) $instance, $defaults);
$title = esc_attr( $instance['title'] );
$title = strip_tags( $instance['title'] );
$show = $instance['show'];
$count = $instance['count'];
$cache_time = $instance['cache_time'];
$count = (int)( $instance['count'] );
?>

<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title:', 'rpwe' ); ?></label>
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title:', 'koo-instagram' ); ?></label>
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo $title; ?>">
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'show') ); ?>"><?php _e( 'Show Feed:', 'rpwe' ); ?></label>
<label for="<?php echo esc_attr( $this->get_field_id( 'show') ); ?>"><?php _e( 'Show Feed:', 'koo-instagram' ); ?></label>
<select class="widefat" name="<?php echo $this->get_field_name( 'show' ); ?>" id="<?php echo $this->get_field_id( 'show' ); ?>">
<option value="recent" <?php if ( 'recent' == $instance['show'] ) echo 'selected="selected"'; ?>><?php _e( 'Recent Uploads', 'koo-instagram' ); ?></option>
<option value="feed" <?php if ( 'feed' == $instance['show'] ) echo 'selected="selected"'; ?>><?php _e( 'Following', 'koo-instagram' ); ?></option>
<option value="liked" <?php if ( 'liked' == $instance['show'] ) echo 'selected="selected"'; ?>><?php _e( 'Liked Images', 'koo-instagram' ); ?></option>
<option value="popular" <?php if ( 'popular' == $instance['show'] ) echo 'selected="selected"'; ?>><?php _e( 'Popular Images', 'koo-instagram' ); ?></option>
<option value="recent" <?php selected( $show, 'recent' ); ?>><?php _e( 'Recent Uploads', 'koo-instagram' ); ?></option>
<option value="feed" <?php selected( $show, 'feed' ); ?>><?php _e( 'Following', 'koo-instagram' ); ?></option>
<option value="liked" <?php selected( $show, 'liked' ); ?>><?php _e( 'Liked Images', 'koo-instagram' ); ?></option>
<option value="popular" <?php selected( $show, 'popular' ); ?>><?php _e( 'Popular Images', 'koo-instagram' ); ?></option>
</select>
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'count' ) ); ?>"><?php _e( 'Counts:', 'rpwe' ); ?></label>
<label for="<?php echo esc_attr( $this->get_field_id( 'count' ) ); ?>"><?php _e( 'Counts:', 'koo-instagram' ); ?></label>
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'count') ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'count' ) ); ?>" type="text" value="<?php echo $count; ?>">
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'cache_time' ) ); ?>"><?php _e( 'Cache Time:', 'rpwe' ); ?></label>
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'cache_time' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'cache_time' ) ); ?>" type="text" value="<?php echo $cache_time; ?>"><br>
<span><?php _e( 'in seconds, 0 to disable cache.', 'koo-instagram' ); ?></span>
</p>
<?php
}

Expand Down

0 comments on commit e0fde5a

Please sign in to comment.