?AlkantarClanX12
| Current Path : /home/r/a/n/rankinh/leblogauto/wp-content/plugins/rubik-extension/widgets/ |
| Current File : /home/r/a/n/rankinh/leblogauto/wp-content/plugins/rubik-extension/widgets/widget_index_posts.php |
<?php
/**
* Add function to widgets_init that'll load our widget.
*/
add_action( 'widgets_init', 'bk_register_index_posts_widget' );
function bk_register_index_posts_widget() {
register_widget( 'bk_index_posts' );
}
/**
* This class handles everything that needs to be handled with the widget:
* the settings, form, display, and update. Nice!
*
*/
class bk_index_posts extends WP_Widget {
/**
* Widget setup.
*/
function __construct() {
/* Widget settings. */
$widget_ops = array( 'classname' => 'widget_latest_posts widget_index_posts', 'description' => esc_html__('Displays index posts in sidebar.', 'rubik') );
/* Create the widget. */
parent::__construct( 'bk_index_posts', esc_html__('BK: Index Posts', 'rubik'), $widget_ops);
}
/**
*display the widget on the screen.
*/
function widget( $args, $instance ) {
extract( $args );
$title = apply_filters('widget_title', $instance['title'] );
$pagiButtons = esc_attr($instance['next_prev']);
$widgetLayout = !empty( $instance['layout'] ) ? $instance['layout'] : 1;
$uid = uniqid('index_'.$widgetLayout.'-');
$widget_opts['offset'] = !empty( $instance['offset'] ) ? $instance['offset'] : 0;
$widget_opts['category_id'] = !empty( $instance['category_id'] )? $instance['category_id'] : 0;
$widget_opts['category_ids'] = !empty( $instance['category_ids'] )? $instance['category_ids'] : '';
$widget_opts['tags'] = !empty( $instance['tags'] ) ? $instance['tags'] : '';
$widget_opts['entries'] = !empty( $instance['entries'] ) ? $instance['entries'] : 4;
$widget_opts['orderby'] = !empty( $instance['orderby'] ) ? $instance['orderby'] : 'date';
$widget_opts['editor_exclude'] = !empty( $instance['editor_exclude'] ) ? $instance['editor_exclude'] : '';
$widget_opts['editor_pick'] = !empty( $instance['editor_pick'] ) ? $instance['editor_pick'] : '';
$query_args = rubik_core::bk_widget_query_arg($widget_opts);
rubik_section_parent::$rubik_ajax_c[$uid]['args'] = $query_args;
rubik_section_parent::$rubik_ajax_c[$uid]['offset'] = $widget_opts['offset'] ;
rubik_section_parent::$rubik_ajax_c[$uid]['entries'] = $widget_opts['entries'];
rubik_section_parent::$rubik_ajax_c[$uid]['next'] = 0;
rubik_section_parent::$rubik_ajax_c[$uid]['prev'] = 0;
echo $before_widget;
echo '<div class="widget_latest_posts_'.$widgetLayout.'">';
if ( $title ) {?>
<div class="widget-title-wrap">
<?php echo $before_title . esc_html($title) . $after_title;?>
</div>
<?php }?>
<?php $the_query = new WP_Query( $query_args ); ?>
<?php if ( $the_query -> have_posts() ) : ?>
<div id="<?php echo esc_attr($uid);?>" class="bk-widget-wrap">
<?php echo rubik_core::bk_widget_index_layout($the_query, $widgetLayout);?>
</div>
<?php endif;?>
<?php
echo '</div>';
/* After widget (defined by themes). */
echo $after_widget;
}
/**
* update widget settings
*/
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = $new_instance['title'];
$instance['layout'] = intval(strip_tags($new_instance['layout']));
$instance['entries'] = intval(strip_tags($new_instance['entries']));
$instance['offset'] = intval(strip_tags($new_instance['offset']));
$instance['category_id']= strip_tags($new_instance['category_id']);
$instance['category_ids']= strip_tags($new_instance['category_ids']);
$instance['tags'] = strip_tags($new_instance['tags']);
$instance['orderby'] = strip_tags($new_instance['orderby']);
$instance['editor_exclude'] = strip_tags($new_instance['editor_exclude']);
$instance['editor_pick'] = strip_tags($new_instance['editor_pick']);
$instance['next_prev'] = $new_instance['next_prev'];
return $instance;
}
/**
* Displays the widget settings controls on the widget panel.
* Make use of the get_field_id() and get_field_name() function
* when creating your form elements. This handles the confusing stuff.
*/
function form( $instance ) {
$defaults = array('title' => 'Latest Posts', 'layout' => 1, 'entries' => 5, 'offset' => 0, 'category_id' => 'all', 'category_ids' => '', 'tags' => '', 'orderby' => 'date', 'editor_exclude' => '', 'editor_pick' => '', 'next_prev' => 'on');
$instance = wp_parse_args((array) $instance, $defaults);
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><strong><?php esc_html_e('Title:', 'rubik'); ?></strong></label>
<input type="text" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $instance['title']; ?>" style="width:100%;" />
</p>
<p>
<label for="<?php echo esc_attr($this->get_field_id( 'layout' )); ?>"><?php esc_attr_e('Layout:', 'rubik'); ?></label>
<select class="widefat" id="<?php echo esc_attr($this->get_field_id( 'layout' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'layout' )); ?>" >
<option value="1" <?php if( !empty($instance['layout']) && $instance['layout'] == '1' ) echo 'selected="selected"'; else echo ""; ?>><?php esc_attr_e('1', 'rubik'); ?></option>
<option value="2" <?php if( !empty($instance['layout']) && $instance['layout'] == '2' ) echo 'selected="selected"'; else echo ""; ?>><?php esc_attr_e('2', 'rubik'); ?></option>
<option value="4" <?php if( !empty($instance['layout']) && $instance['layout'] == '4' ) echo 'selected="selected"'; else echo ""; ?>><?php esc_attr_e('3', 'rubik'); ?></option>
<option value="6" <?php if( !empty($instance['layout']) && $instance['layout'] == '6' ) echo 'selected="selected"'; else echo ""; ?>><?php esc_attr_e('4', 'rubik'); ?></option>
</select>
</p>
<p><label for="<?php echo esc_attr($this->get_field_id( 'entries' )); ?>"><strong><?php esc_html_e('[Optional] Number of entries to display: ', 'rubik'); ?></strong></label>
<input class="widefat" type="text" id="<?php echo esc_attr($this->get_field_id('entries')); ?>" name="<?php echo esc_attr($this->get_field_name('entries')); ?>" value="<?php echo esc_attr($instance['entries']); ?>"/></p>
<p><label for="<?php echo esc_attr($this->get_field_id( 'offset' )); ?>"><strong><?php esc_html_e('[Optional] Offet Posts number: ', 'rubik'); ?></strong></label>
<input class="widefat" type="text" id="<?php echo esc_attr($this->get_field_id('offset')); ?>" name="<?php echo esc_attr($this->get_field_name('offset')); ?>" value="<?php echo esc_attr($instance['offset']); ?>" /></p>
<p>
<label for="<?php echo esc_attr($this->get_field_id('category_id')); ?>"><strong><?php esc_html_e('Filter by Category: ','rubik');?></strong></label>
<select id="<?php echo esc_attr($this->get_field_id('category_id')); ?>" name="<?php echo esc_attr($this->get_field_name('category_id')); ?>" class="widefat categories">
<option value='all' <?php if ('all' == $instance['category_id']) echo 'selected="selected"'; ?>><?php esc_html_e( 'All Categories', 'rubik' ); ?></option>
<?php $categories = get_categories('hide_empty=1&type=post'); ?>
<?php foreach($categories as $category) { ?>
<option value='<?php echo esc_attr($category->term_id); ?>' <?php if ($category->term_id == $instance['category_id']) echo 'selected="selected"'; ?>><?php echo esc_attr($category->cat_name); ?></option>
<?php } ?>
</select>
</p>
<p>
<label for="<?php echo esc_attr($this->get_field_id( 'category_ids' )); ?>"><?php esc_attr_e('[Optional] Multiple Category: (Separate category ids by the comma. e.g. 1,2):','rubik') ?></label>
<input type="text" class="widefat" id="<?php echo esc_attr($this->get_field_id( 'category_ids' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'category_ids' )); ?>" value="<?php if( !empty($instance['category_ids']) ) echo esc_attr($instance['category_ids']); ?>" />
</p>
<p>
<label for="<?php echo esc_attr($this->get_field_id( 'tags' )); ?>"><?php esc_attr_e('[Optional] Tags(Separate tags by the comma. e.g. ID1,ID2):','rubik') ?></label>
<input type="text" class="widefat" id="<?php echo esc_attr($this->get_field_id( 'tags' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'tags' )); ?>" value="<?php if( !empty($instance['tags']) ) echo esc_attr($instance['tags']); ?>" />
</p>
<p>
<label for="<?php echo esc_attr($this->get_field_id( 'orderby' )); ?>"><?php esc_attr_e('Order By:', 'rubik'); ?></label>
<select class="widefat" id="<?php echo esc_attr($this->get_field_id( 'orderby' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'orderby' )); ?>" >
<option value="date" <?php if( !empty($instance['orderby']) && $instance['orderby'] == 'date' ) echo 'selected="selected"'; else echo ""; ?>><?php esc_attr_e('Latest Posts', 'rubik'); ?></option>
<option value="comment_count" <?php if( !empty($instance['orderby']) && $instance['orderby'] == 'comment_count' ) echo 'selected="selected"'; else echo ""; ?>><?php esc_attr_e('Popular Post by Comments', 'rubik'); ?></option>
<option value="view_count" <?php if( !empty($instance['orderby']) && $instance['orderby'] == 'view_count' ) echo 'selected="selected"'; else echo ""; ?>><?php esc_attr_e('Popular Post by Views', 'rubik'); ?></option>
<option value="top_review" <?php if( !empty($instance['orderby']) && $instance['orderby'] == 'top_review' ) echo 'selected="selected"'; else echo ""; ?>><?php esc_attr_e('Best Review', 'rubik'); ?></option>
<option value="modified" <?php if( !empty($instance['orderby']) && $instance['orderby'] == 'modified' ) echo 'selected="selected"'; else echo ""; ?>><?php esc_attr_e('Modified', 'rubik'); ?></option>
<option value="rand" <?php if( !empty($instance['orderby']) && $instance['orderby'] == 'rand' ) echo 'selected="selected"'; else echo ""; ?>><?php esc_attr_e('Random Post', 'rubik'); ?></option>
<option value="alphabetical_asc" <?php if( !empty($instance['orderby']) && $instance['orderby'] == 'alphabetical_asc' ) echo 'selected="selected"'; else echo ""; ?>><?php esc_attr_e('Alphabetical A->Z', 'rubik'); ?></option>
<option value="alphabetical_decs" <?php if( !empty($instance['orderby']) && $instance['orderby'] == 'alphabetical_decs' ) echo 'selected="selected"'; else echo ""; ?>><?php esc_attr_e('Alphabetical Z->A', 'rubik'); ?></option>
</select>
</p>
<p>
<label for="<?php echo esc_attr($this->get_field_id( 'editor_exclude' )); ?>"><?php esc_attr_e('[Optional] Manually Exclude Posts (By Post IDs). e.g. id1,id2):','rubik') ?></label>
<input type="text" class="widefat" id="<?php echo esc_attr($this->get_field_id( 'editor_exclude' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'editor_exclude' )); ?>" value="<?php if( !empty($instance['editor_exclude']) ) echo esc_attr($instance['editor_exclude']); ?>" />
</p>
<p>
<label for="<?php echo esc_attr($this->get_field_id( 'editor_pick' )); ?>"><?php esc_attr_e('[Optional] Manually Pick Posts (By Post IDs). e.g. id1,id2):','rubik') ?></label>
<input type="text" class="widefat" id="<?php echo esc_attr($this->get_field_id( 'editor_pick' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'editor_pick' )); ?>" value="<?php if( !empty($instance['editor_pick']) ) echo esc_attr($instance['editor_pick']); ?>" />
</p>
<?php
}
}
?>