Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.60 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Programista- okładka
  4. Version: 0.1
  5. Description: Wyświetla aktualną okładkę "Programisty"
  6. Author: michak
  7.  */  
  8.  
  9.  class Programista_Widget extends WP_Widget {
  10.      function __construct() {
  11.          parent::__construct('programista_widget', __( 'Programista- okładka', 'text_domain' ),
  12.                              array( 'description' => __( 'Okładka aktualnego "Programisty"', 'text_domain' ), ));
  13.      }
  14.  
  15.      private function widget_content($instance) {
  16.          $src = "http://programistamag.pl/wp-content/uploads/magazines/covers/" . $instance['latest_number'] . "_okladka.jpg";
  17.          $content = "<img width='" . $instance['scale'] . "' height='" . $instance['scale'] . "' src='" . $src . "'></img>";
  18.          return $content;
  19.      }
  20.  
  21.      public function widget($args, $instance) {
  22.          echo $args['before_widget'];
  23.  
  24.          if (!empty( $instance['title'])) {
  25.              echo $args['before_title'] .
  26.                  apply_filters('widget_title', $instance['title']) .
  27.                  $args['after_title'];
  28.          }
  29.  
  30.          echo __($this->widget_content($instance), 'text_domain' );
  31.          echo $args['after_widget'];
  32.      }
  33.  
  34.      public function form($instance) {
  35.          $title = !empty($instance['title']) ? $instance['title'] : "";
  36.          $latest_number = !empty($instance['latest_number']) ? $instance['latest_number'] : __('36', 'text_domain');
  37.          $scale = !empty($instance['scale']) ? $instance['scale'] : __('100%', 'text_domain');
  38.         ?>
  39.  
  40.         <p>
  41.         <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Tytuł:'); ?></label>
  42.         <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); ?>">
  43.        
  44.         <label for="<?php echo $this->get_field_id('latest_number'); ?>"><?php _e('Ostatni numer:'); ?></label>
  45.         <input class="widefat" id="<?php echo $this->get_field_id('latest_number'); ?>" name="<?php echo $this->get_field_name('latest_number'); ?>" type="text" value="<?php echo esc_attr($latest_number); ?>">
  46.  
  47.         <label for="<?php echo $this->get_field_id('scale'); ?>"><?php _e('Skalowanie (wartość % lub piksele):'); ?></label>
  48.         <input class="widefat" id="<?php echo $this->get_field_id('scale'); ?>" name="<?php echo $this->get_field_name('scale'); ?>" type="text" value="<?php echo esc_attr($scale); ?>">
  49.         </p>
  50.         <?php
  51.      }
  52.  };
  53.  
  54.  function register_programista_widget() {
  55.      register_widget('Programista_Widget');
  56.  }
  57.  add_action('widgets_init', 'register_programista_widget');
  58.  
  59. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement