Advertisement
iGreenie

Untitled

Mar 17th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.45 KB | None | 0 0
  1. <?php
  2. /* Plugin Name: MZ - RSS v2
  3. Version: 2.0
  4. Author: Marek Železný
  5. */
  6. class mz_RSS_onepost extends WP_Widget
  7. {
  8.   function mz_RSS_onepost()
  9.   {
  10.     $widget_ops = array('classname' => 'mz_RSS_onepost', 'description' => 'jako na Ekonomicky Denik' );
  11.     $this->WP_Widget('mz_RSS_onepost', 'RSS', $widget_ops);
  12.   }
  13.  
  14.   function widget( $args, $instance )
  15.   {
  16.     extract($args);
  17.     $title = apply_filters( 'widget_title', empty($instance['title']) ? '' : $instance['title'], $instance );
  18.     $content = apply_filters( 'content', empty( $instance['content'] ) ? '' : $instance['content'], $instance );
  19.     ?>
  20.  
  21.     <div class="box rss">
  22.  
  23.     <?php if(function_exists('fetch_feed')) {  
  24.  
  25.         include_once(ABSPATH . WPINC . '/feed.php'); // the file to rss feed generator  
  26.        
  27.         $feed = fetch_feed( $content ); // specify the rss feed  
  28.         if (!is_wp_error( $feed ) ) {
  29.         $limit = $feed->get_item_quantity(1);
  30.         $items = $feed->get_items(0, $limit); // create an array of items  
  31.         $feed->set_timeout(60);
  32.         }else{
  33.             echo $feed->get_error_message();
  34.         }
  35.      
  36.     }  
  37.     ?>
  38.  
  39.         <?php if($limit) :
  40.         foreach ($items as $item) :
  41.         ?>
  42.            
  43.         <?php if($title == "justice") : ?>
  44.  
  45.         <h1><img src="<?php echo plugin_dir_url (__FILE__); ?>rss/justice.png" alt="justice"><span><?php echo $item->get_date('d.m.Y'); ?></span></h1>
  46.  
  47.         <?php elseif($title == "zdravotnicky") : ?>
  48.  
  49.         <h1><img src="<?php echo plugin_dir_url (__FILE__); ?>rss/zdravotnicky.png" alt="zdravotnicky"><span><?php echo $item->get_date('d.m.Y'); ?></span></h1>
  50.  
  51.         <?php elseif($title == "ekonomicky") : ?>
  52.  
  53.         <h1><img src="<?php echo plugin_dir_url (__FILE__); ?>rss/ekonomicky.png" alt="ekonomicky"><span><?php echo $item->get_date('d.m.Y'); ?></span></h1>
  54.  
  55.         <?php else : ?>
  56.  
  57.         <h1><?php echo !empty( $instance['filter'] ) ? wpautop( $title ) : $title; ?></h1>
  58.  
  59.         <?php endif; ?>
  60.  
  61.         <?php endforeach; endif; ?>  
  62.        
  63.         <div id="latest">
  64.  
  65.         <?php
  66.         if ($limit == 0) echo '<div>RSS není momentálně k dispozici.</div>';  
  67.         else foreach ($items as $item) : ?>  
  68.        
  69.             <div class="data">
  70.                 <a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a>
  71.             </div>
  72.            
  73.         <?php endforeach; ?>  
  74.        
  75.         </div>
  76.  
  77.         </div>
  78.    
  79.     <?php
  80.   }
  81.  
  82.   function update( $new_instance, $old_instance ) {
  83.         $instance = $old_instance;
  84.         $instance['title'] = $new_instance['title'];
  85.         if ( current_user_can('unfiltered_html') )
  86.             $instance['content'] =  $new_instance['content'];
  87.         else
  88.             $instance['content'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['content']) ) );
  89.         $instance['filter'] = isset($new_instance['filter']);
  90.         return $instance;
  91.     }
  92.  
  93.   function form( $instance )
  94.   {
  95.  
  96.         $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'content' => '' ) );
  97.         $title = $instance['title'];
  98.         $content = esc_textarea($instance['content']);?>
  99.         <label for="<?php echo $this->get_field_id('title'); ?>">Titulek: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label>
  100.         <p>URL RSS kanálu:</p>
  101.         <input id="<?php echo $this->get_field_id('content'); ?>" name="<?php echo $this->get_field_name('content'); ?>" value="<?php echo $content; ?>" />
  102.  
  103. <?php
  104.   }
  105.  
  106. }
  107. add_action( 'widgets_init', create_function('', 'return register_widget("mz_RSS_onepost");') );
  108. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement