?AlkantarClanX12

Your IP : 216.73.216.177


Current Path : /home/rankinh/leblogauto/wp-content/plugins/rubik-extension/widgets/
Upload File :
Current File : /home/rankinh/leblogauto/wp-content/plugins/rubik-extension/widgets/widget_youtube_playlist.php

<?php
/**
 * Add function to widgets_init that'll load our widget.
 */
add_action( 'widgets_init', 'bk_register_youtube_playlist_widget' );

function bk_register_youtube_playlist_widget() {
	register_widget( 'bk_youtube_playlist' );
}

/**
 * This class handles everything that needs to be handled with the widget:
 * the settings, form, display, and update.  Nice!
 *
 */
class bk_youtube_playlist extends WP_Widget {

	/**
	 * Widget setup.
	 */
	function __construct() {
		/* Widget settings. */
		$widget_ops = array( 'classname' => 'bk_youtube_playlist', 'description' => esc_html__('Displays Youtube Playlist in Sidebar.', 'rubik') );

		/* Create the widget. */
		parent::__construct( 'bk_youtube_playlist', esc_html__('BK: Widget Youtube Playlist', 'rubik'), $widget_ops);
	}
    
	/**
	 *display the widget on the screen.
	 */
	function widget( $args, $instance ) {
		extract( $args );
        
        global $rubik_dynamic_css;
        
        $uid = uniqid('youtube_playlist_widget-');
        
        $title = apply_filters('widget_title', $instance['title'] );
		
        $YTplaylist_URL = esc_attr($instance['youtube_url']) ;
        $playing_title_bg = esc_attr($instance['playing_title_bg']) ;
        $playing_title_color = esc_attr($instance['playing_title_color']) ;
        
        $bk_color_opt = array();
        
        $bk_color_opt['title_bg_class'] = '';
        $bk_color_opt['title_color_class'] = '';

        if($playing_title_bg != '') {
            $bk_color_opt['title_bg_class'] = 'bk-title-inline-bg';
        }
        if($playing_title_color != '') {
            $bk_color_opt['title_color_class'] = 'bk-title-color-bg';
        }
        
        $rubik_dynamic_css[$uid]['module_bg'] = '';
        $rubik_dynamic_css[$uid]['playing_title_bg'] = $playing_title_bg;
        $rubik_dynamic_css[$uid]['playing_title_color'] = $playing_title_color;
        
        echo $before_widget;
		if ( $title ) {?>
            <div class="widget-title-wrap">
                <?php echo $before_title . esc_html($title) . $after_title;?>
            </div>
        <?php }?>

        <div id="<?php echo esc_attr($uid);?>" class="module-youtube-playlist playlist-layout2">
        <?php
            $YTplaylist = '';
            if ($YTplaylist_URL == '') {
                echo '<div class="bk-notice">Playlist URL is empty. Please insert the necessary data to the setting fields.</div>';
            }else {
                $YTplaylist = rubik_youtube::rubik_get_playlist($YTplaylist_URL);
                if (!( $YTplaylist && ! empty( $YTplaylist['videos'] ) )) :
                    echo '<div class="bk-notice">Cannot fetch URL, please check and correct it.</div>';
                else:
                    echo rubik_youtube::rubik_youtube_playlist_render($YTplaylist, $bk_color_opt, 'layout-2');
                endif;
            }
        ?>
        
        </div><!-- Close module -->

    <?php
		
		/* 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['youtube_url'] = strip_tags($new_instance['youtube_url']);
        $instance['playing_title_bg'] = $new_instance['playing_title_bg'];
        $instance['playing_title_color'] = $new_instance['playing_title_color'];
		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' => 'Video Playlist','youtube_url' => '', 'playing_title_bg' => '#000', 'playing_title_color' => '#fff');
		$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 $this->get_field_id( 'youtube_url' ); ?>"><strong><?php esc_html_e('Youtube Playlist URL:', 'rubik'); ?></strong></label>
			<input type="text-area" id="<?php echo $this->get_field_id('youtube_url'); ?>" name="<?php echo $this->get_field_name('youtube_url'); ?>" value="<?php echo $instance['youtube_url']; ?>" style="width:100%;" />
		</p>     
        
        <p>
			<label for="<?php echo $this->get_field_id( 'playing_title_bg' ); ?>"><strong><?php esc_html_e('Playing Title Background:', 'rubik'); ?></strong></label>
			<input type="text" id="<?php echo $this->get_field_id('playing_title_bg'); ?>" name="<?php echo $this->get_field_name('playing_title_bg'); ?>" value="<?php echo $instance['playing_title_bg']; ?>" style="width:100%;" />
		</p>   
        <p>
			<label for="<?php echo $this->get_field_id( 'playing_title_color' ); ?>"><strong><?php esc_html_e('Playing Title Color:', 'rubik'); ?></strong></label>
			<input type="text" id="<?php echo $this->get_field_id('playing_title_color'); ?>" name="<?php echo $this->get_field_name('playing_title_color'); ?>" value="<?php echo $instance['playing_title_color']; ?>" style="width:100%;" />
		</p>          
        
<?php
	}
}
?>