rhandom

Untitled

Feb 22nd, 2012
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.58 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Accompany Text Widget
  4. Plugin URI: http://egetway.com/
  5. Description: Accompany Post Widget grabs a Accompany post and the associated thumbnail to display on your sidebar
  6. Author: Egetway
  7. Version: 2
  8. Author URI: http://egetway.com/
  9. */
  10.  
  11.  
  12. class AccompanyPostWidget extends WP_Widget
  13. {
  14.    
  15.    
  16.    
  17.   function AccompanyPostWidget()
  18.   {
  19.     $widget_ops = array('classname' => 'AccompanyPostWidget', 'description' => 'Displays a Accompany post with thumbnail' );
  20.     $this->WP_Widget('AccompanyPostWidget', 'Accompany Text Widget', $widget_ops);
  21.     $plugin_dir = basename(dirname(__FILE__));
  22.     load_plugin_textdomain( 'accompany-text', false, $plugin_dir );
  23.   }
  24.  
  25.   function form($instance)
  26.   {
  27.     $instance = wp_parse_args( (array) $instance, array( 'number' => '','text' => '', 'imagesPath' => '','cssClass' => '') );
  28.     $title = $instance['number'];
  29.     $text = $instance['text'];
  30.     $widgetNo="widgetname".mt_rand(); //.substr(md5('widgetname'), 0, 4);
  31.     icl_register_string('Accompany Text',$widgetNo, $text);
  32.     $imagesPath= $instance['imagesPath'];
  33.     $cssClass= $instance['cssClass'];
  34.    
  35. ?>
  36.   <p><label for="<?php echo $this->get_field_id('number'); ?>">Number : <input class="widefat" id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo attribute_escape($number); ?>" /></label></p>
  37.    <p><label for="<?php echo $this->get_field_id('text'); ?>">Text :
  38.    <textarea class="widefat" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>"><?php echo attribute_escape (icl_t('Accompany Text', $widgetNo, $text));?></textarea>
  39.    </label></p>
  40.    <p><label for="<?php echo $this->get_field_id('imagesPath'); ?>">images path : <input class="widefat" id="<?php echo $this->get_field_id('imagesPath'); ?>" name="<?php echo $this->get_field_name('imagesPath'); ?>" type="text" value="<?php echo attribute_escape($imagesPath); ?>" /></label></p>
  41.    
  42.       <p><label for="<?php echo $this->get_field_id('cssClass'); ?>">Css Class : <input class="widefat" id="<?php echo $this->get_field_id('cssClass'); ?>" name="<?php echo $this->get_field_name('cssClass'); ?>" type="text" value="<?php echo attribute_escape($cssClass); ?>" /></label></p>
  43.    
  44. <?php
  45.   }
  46.  
  47.   function update($new_instance, $old_instance)
  48.   {
  49.     $instance = $old_instance;
  50.     $instance['number'] = $new_instance['number'];
  51.     $instance['text'] = $new_instance['text'];
  52.     $instance['imagesPath'] = $new_instance['imagesPath'];
  53.     $instance['cssClass'] = $new_instance['cssClass'];
  54.      
  55.     return $instance;
  56.   }
  57.  
  58.   function widget($args, $instance)
  59.   {
  60.     extract($args, EXTR_SKIP);
  61.  
  62.     echo $before_widget;
  63.     $number = empty($instance['number']) ? ' ' : apply_filters('widget_number', $instance['number']);
  64.     $text = empty($instance['text']) ? ' ' : apply_filters('widget_text', $instance['text']);
  65.     $imagesPath = empty($instance['imagesPath']) ? ' ' : apply_filters('widget_imagesPath', $instance['imagesPath']);
  66.     $cssClass = empty($instance['cssClass']) ? ' ' : apply_filters('widget_cssClass', $instance['cssClass']);
  67.    
  68.    
  69.    
  70.     // WIDGET CODE GOES HERE
  71.     echo '<div class="box '.$cssClass.'">
  72.  <div class="round">
  73.     <div class="con">';
  74.          if (!empty($number)){ echo ' <span class="num">'.$number.'</span>';}
  75.         echo $text;
  76.     if (!empty($imagesPath)){ echo '<div class="iconBox"><img src="'.$imagesPath.'" class="icon" /> </div>';}
  77.     echo ' </div>
  78.  </div>
  79. </div>';
  80.  
  81.     echo $after_widget;
  82.   }
  83.  
  84.  
  85.  
  86. }
  87.  
  88. add_action( 'widgets_init', create_function('', 'return register_widget("AccompanyPostWidget");') );?>
Advertisement
Add Comment
Please, Sign In to add comment