Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- **************
- * Random text widget
- **************
- */
- class Random_Text extends WP_Widget {
- function Random_Text() {
- $widget_ops = array('classname' => 'custom_text', 'description' => __('Displays one of 5 text blocks at random on page refresh.'));
- $control_ops = array('width' => 400, 'height' => 350);
- $this->WP_Widget('random_text', __('Random Text'), $widget_ops, $control_ops);
- }
- function widget( $args, $instance ) {
- extract($args);
- $title = apply_filters( 'widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
- $text1 = apply_filters( 'widget_text1', $instance['text1'], $instance );
- $text2 = apply_filters( 'widget_text2', $instance['text2'], $instance );
- $text3 = apply_filters( 'widget_text3', $instance['text3'], $instance );
- $text4 = apply_filters( 'widget_text4', $instance['text4'], $instance );
- $text5 = apply_filters( 'widget_text5', $instance['text5'], $instance );
- $text1 = apply_filters( 'widget_text6', $instance['text6'], $instance );
- $text2 = apply_filters( 'widget_text7', $instance['text7'], $instance );
- $text3 = apply_filters( 'widget_text8', $instance['text8'], $instance );
- $text4 = apply_filters( 'widget_text9', $instance['text9'], $instance );
- $text5 = apply_filters( 'widget_text10', $instance['text10'], $instance );
- echo $before_widget; ?>
- <div class="widgetWrap">
- <?php if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?>
- <script type="text/javascript">//<![CDATA[
- var txtList = new Array()
- <?php if (!empty ($text1)) { ?>txtList[txtList.length]="<?php echo $instance['filter'] ? wpautop($text1) : $text1; ?>";<?php } ?>
- <?php if (!empty ($text2)) { ?>txtList[txtList.length]="<?php echo $instance['filter'] ? wpautop($text2) : $text2; ?>";<?php } ?>
- <?php if (!empty ($text3)) { ?>txtList[txtList.length]="<?php echo $instance['filter'] ? wpautop($text3) : $text3; ?>";<?php } ?>
- <?php if (!empty ($text4)) { ?>txtList[txtList.length]="<?php echo $instance['filter'] ? wpautop($text4) : $text4; ?>";<?php } ?>
- <?php if (!empty ($text5)) { ?>txtList[txtList.length]="<?php echo $instance['filter'] ? wpautop($text5) : $text5; ?>";<?php } ?>
- <?php if (!empty ($text6)) { ?>txtList[txtList.length]="<?php echo $instance['filter'] ? wpautop($text6) : $text6; ?>";<?php } ?>
- <?php if (!empty ($text7)) { ?>txtList[txtList.length]="<?php echo $instance['filter'] ? wpautop($text7) : $text7; ?>";<?php } ?>
- <?php if (!empty ($text8)) { ?>txtList[txtList.length]="<?php echo $instance['filter'] ? wpautop($text8) : $text8; ?>";<?php } ?>
- <?php if (!empty ($text9)) { ?>txtList[txtList.length]="<?php echo $instance['filter'] ? wpautop($text9) : $text9; ?>";<?php } ?>
- <?php if (!empty ($text10)) { ?>txtList[txtList.length]="<?php echo $instance['filter'] ? wpautop($text10) : $text10; ?>";<?php } ?>
- j=parseInt(Math.random()*txtList.length);
- j=(isNaN(j))?0:j;
- document.write(unescape(txtList[j]));
- //]]></script>
- </div>
- <?php
- echo $after_widget;
- }
- function update( $new_instance, $old_instance ) {
- $instance = $old_instance;
- $instance['title'] = strip_tags($new_instance['title']);
- //text1
- if ( current_user_can('unfiltered_html') )
- $instance['text1'] = $new_instance['text1'];
- else
- $instance['text1'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text1']) ) ); // wp_filter_post_kses() expects slashed
- //text2
- if ( current_user_can('unfiltered_html') )
- $instance['text2'] = $new_instance['text2'];
- else
- $instance['text2'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text2']) ) ); // wp_filter_post_kses() expects slashed
- //text3
- if ( current_user_can('unfiltered_html') )
- $instance['text3'] = $new_instance['text3'];
- else
- $instance['text3'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text3']) ) ); // wp_filter_post_kses() expects slashed
- //text4
- if ( current_user_can('unfiltered_html') )
- $instance['text4'] = $new_instance['text4'];
- else
- $instance['text4'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text4']) ) ); // wp_filter_post_kses() expects slashed
- //text5
- if ( current_user_can('unfiltered_html') )
- $instance['text5'] = $new_instance['text5'];
- else
- $instance['text5'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text5']) ) ); // wp_filter_post_kses() expects slashed
- //text6
- if ( current_user_can('unfiltered_html') )
- $instance['text6'] = $new_instance['text6'];
- else
- $instance['text6'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text6']) ) ); // wp_filter_post_kses() expects slashed
- //text7
- if ( current_user_can('unfiltered_html') )
- $instance['text7'] = $new_instance['text7'];
- else
- $instance['text7'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text7']) ) ); // wp_filter_post_kses() expects slashed
- //text8
- if ( current_user_can('unfiltered_html') )
- $instance['text8'] = $new_instance['text8'];
- else
- $instance['text8'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text8']) ) ); // wp_filter_post_kses() expects slashed
- //text9
- if ( current_user_can('unfiltered_html') )
- $instance['text9'] = $new_instance['text9'];
- else
- $instance['text9'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text9']) ) ); // wp_filter_post_kses() expects slashed
- //text10
- if ( current_user_can('unfiltered_html') )
- $instance['text10'] = $new_instance['text10'];
- else
- $instance['text10'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text10']) ) ); // 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' => '', 'text1' => '', 'text2' => '', 'text3' => '', 'text4' => '', 'text5' => '', ) );
- $title = strip_tags($instance['title']);
- $text1 = esc_textarea($instance['text1']);
- $text2 = esc_textarea($instance['text2']);
- $text3 = esc_textarea($instance['text3']);
- $text4 = esc_textarea($instance['text4']);
- $text5 = esc_textarea($instance['text5']);
- $text6 = esc_textarea($instance['text6']);
- $text7 = esc_textarea($instance['text7']);
- $text8 = esc_textarea($instance['text8']);
- $text9 = esc_textarea($instance['text9']);
- $text10 = esc_textarea($instance['text10']);
- ?>
- <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>
- <p><label for="<?php echo $this->get_field_id('text1'); ?>"><?php _e('Text 1:'); ?></label>
- <textarea class="widefat" rows="3" cols="20" id="<?php echo $this->get_field_id('text1'); ?>" name="<?php echo $this->get_field_name('text1'); ?>"><?php echo $text1; ?></textarea></p>
- <p><label for="<?php echo $this->get_field_id('text2'); ?>"><?php _e('Text 2:'); ?></label>
- <textarea class="widefat" rows="3" cols="20" id="<?php echo $this->get_field_id('text2'); ?>" name="<?php echo $this->get_field_name('text2'); ?>"><?php echo $text2; ?></textarea></p>
- <p><label for="<?php echo $this->get_field_id('text3'); ?>"><?php _e('Text 3:'); ?></label>
- <textarea class="widefat" rows="3" cols="20" id="<?php echo $this->get_field_id('text3'); ?>" name="<?php echo $this->get_field_name('text3'); ?>"><?php echo $text3; ?></textarea></p>
- <p><label for="<?php echo $this->get_field_id('text4'); ?>"><?php _e('Text 4:'); ?></label>
- <textarea class="widefat" rows="3" cols="20" id="<?php echo $this->get_field_id('text4'); ?>" name="<?php echo $this->get_field_name('text4'); ?>"><?php echo $text4; ?></textarea></p>
- <p><label for="<?php echo $this->get_field_id('text5'); ?>"><?php _e('Text 5:'); ?></label>
- <textarea class="widefat" rows="3" cols="20" id="<?php echo $this->get_field_id('text5'); ?>" name="<?php echo $this->get_field_name('text5'); ?>"><?php echo $text5; ?></textarea></p>
- <p><label for="<?php echo $this->get_field_id('text6'); ?>"><?php _e('Text 6:'); ?></label>
- <textarea class="widefat" rows="3" cols="20" id="<?php echo $this->get_field_id('text6'); ?>" name="<?php echo $this->get_field_name('text6'); ?>"><?php echo $text6; ?></textarea></p>
- <p><label for="<?php echo $this->get_field_id('text7'); ?>"><?php _e('Text 7:'); ?></label>
- <textarea class="widefat" rows="3" cols="20" id="<?php echo $this->get_field_id('text7'); ?>" name="<?php echo $this->get_field_name('text7'); ?>"><?php echo $text7; ?></textarea></p>
- <p><label for="<?php echo $this->get_field_id('text8'); ?>"><?php _e('Text 8:'); ?></label>
- <textarea class="widefat" rows="3" cols="20" id="<?php echo $this->get_field_id('text8'); ?>" name="<?php echo $this->get_field_name('text8'); ?>"><?php echo $text8; ?></textarea></p>
- <p><label for="<?php echo $this->get_field_id('text9'); ?>"><?php _e('Text 9:'); ?></label>
- <textarea class="widefat" rows="3" cols="20" id="<?php echo $this->get_field_id('text9'); ?>" name="<?php echo $this->get_field_name('text9'); ?>"><?php echo $text9; ?></textarea></p>
- <p><label for="<?php echo $this->get_field_id('text10'); ?>"><?php _e('Text 10:'); ?></label>
- <textarea class="widefat" rows="3" cols="20" id="<?php echo $this->get_field_id('text10'); ?>" name="<?php echo $this->get_field_name('text10'); ?>"><?php echo $text10; ?></textarea></p>
- <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); ?> /> <label for="<?php echo $this->get_field_id('filter'); ?>"><?php _e('Automatically add paragraphs'); ?></label></p>
- <?php
- }
- }
- add_action('widgets_init', create_function('', 'return register_widget("Random_Text");'));
- /*
- **************
- * Random image widget
- **************
- */
- class Random_Image extends WP_Widget {
- function Random_Image() {
- $widget_ops = array('classname' => 'random_image', 'description' => __('Displays one of 5 images at random on page refresh.'));
- $control_ops = array('width' => 400, 'height' => 350);
- $this->WP_Widget('random_image', __('Random Image'), $widget_ops, $control_ops);
- }
- function widget( $args, $instance ) {
- extract($args);
- $title = apply_filters( 'widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
- $img1 = apply_filters( 'widget_img1', $instance['img1'], $instance );
- $img2 = apply_filters( 'widget_img2', $instance['img2'], $instance );
- $img3 = apply_filters( 'widget_img3', $instance['img3'], $instance );
- $img4 = apply_filters( 'widget_img4', $instance['img4'], $instance );
- $img5 = apply_filters( 'widget_img5', $instance['img5'], $instance );
- echo $before_widget; ?>
- <div class="widgetWrap">
- <?php if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?>
- <script type="text/javascript">//<![CDATA[
- var j,d="",l="",m="",p="",q="",z="",KW_ARI= new Array()
- <?php if ( !empty($img1) ) { ?>KW_ARI[KW_ARI.length]='<?php echo $img1 ?>';<?php } ?>
- <?php if ( !empty($img2) ) { ?>KW_ARI[KW_ARI.length]='<?php echo $img2 ?>';<?php } ?>
- <?php if ( !empty($img3) ) { ?>KW_ARI[KW_ARI.length]='<?php echo $img3 ?>';<?php } ?>
- <?php if ( !empty($img4) ) { ?>KW_ARI[KW_ARI.length]='<?php echo $img4 ?>';<?php } ?>
- <?php if ( !empty($img5) ) { ?>KW_ARI[KW_ARI.length]='<?php echo $img5 ?>';<?php } ?>
- j=parseInt(Math.random()*KW_ARI.length);
- j=(isNaN(j))?0:j;
- if (KW_ARI[j].indexOf('?')==-1) {
- document.write("<img src='"+KW_ARI[j]+"'>");
- }
- else {
- nvp=KW_ARI[j].substring(KW_ARI[j].indexOf('?')+2).split('&');
- for(var i=0;i<nvp.length;i++) {
- sub=nvp[i].split('=');
- switch(sub[0]) {
- case 'link':
- l="<a href='"+unescape(sub[1])+"'>";
- p="</a>";
- break;
- case 'target':
- q=" target='"+unescape(sub[1])+"'";
- break;
- default:
- m+=" "+sub[0]+"='"+unescape(sub[1])+"'";
- break;
- }
- }
- z=(l!="")?((q!="")?l.substring(0,l.length-1)+q+">":l):"";
- z+="<img src='"+KW_ARI[j].substring(0,KW_ARI[j].indexOf('?'))+"'"+m+">"+p;
- document.write(z);
- }
- //]]></script>
- </div>
- <?php
- echo $after_widget;
- }
- function update( $new_instance, $old_instance ) {
- $instance = $old_instance;
- $instance['title'] = strip_tags($new_instance['title']);
- // Images
- $instance['img1'] = strip_tags($new_instance['img1']);
- $instance['img2'] = strip_tags($new_instance['img2']);
- $instance['img3'] = strip_tags($new_instance['img3']);
- $instance['img4'] = strip_tags($new_instance['img4']);
- $instance['img5'] = strip_tags($new_instance['img5']);
- return $instance;
- }
- function form( $instance ) {
- $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text1' => '', 'text2' => '', 'text3' => '', 'text4' => '', 'text5' => '', ) );
- $title = strip_tags($instance['title']);
- $img1 = strip_tags($instance['img1']);
- $img2 = strip_tags($instance['img2']);
- $img3 = strip_tags($instance['img3']);
- $img4 = strip_tags($instance['img4']);
- $img5 = strip_tags($instance['img5']);
- ?>
- <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>
- <p><label for="<?php echo $this->get_field_id('img1'); ?>"><?php _e('Image 1 URL:'); ?></label>
- <input class="widefat" id="<?php echo $this->get_field_id('img1'); ?>" name="<?php echo $this->get_field_name('img1'); ?>" type="text" value="<?php echo esc_attr($img1); ?>" /></p>
- <p><label for="<?php echo $this->get_field_id('img2'); ?>"><?php _e('Image 2 URL:'); ?></label>
- <input class="widefat" id="<?php echo $this->get_field_id('img2'); ?>" name="<?php echo $this->get_field_name('img2'); ?>" type="text" value="<?php echo esc_attr($img2); ?>" /></p>
- <p><label for="<?php echo $this->get_field_id('img3'); ?>"><?php _e('Image 3 URL:'); ?></label>
- <input class="widefat" id="<?php echo $this->get_field_id('img3'); ?>" name="<?php echo $this->get_field_name('img3'); ?>" type="text" value="<?php echo esc_attr($img3); ?>" /></p>
- <p><label for="<?php echo $this->get_field_id('img4'); ?>"><?php _e('Image 4 URL:'); ?></label>
- <input class="widefat" id="<?php echo $this->get_field_id('img4'); ?>" name="<?php echo $this->get_field_name('img4'); ?>" type="text" value="<?php echo esc_attr($img4); ?>" /></p>
- <p><label for="<?php echo $this->get_field_id('img5'); ?>"><?php _e('Image 5 URL:'); ?></label>
- <input class="widefat" id="<?php echo $this->get_field_id('img5'); ?>" name="<?php echo $this->get_field_name('img5'); ?>" type="text" value="<?php echo esc_attr($img5); ?>" /></p>
- <?php
- }
- }
- add_action('widgets_init', create_function('', 'return register_widget("Random_Image");'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement