-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpluginrss.php
More file actions
114 lines (106 loc) · 4.15 KB
/
pluginrss.php
File metadata and controls
114 lines (106 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/*
Plugin Name: Plugin Rss with thumbnails
Plugin URI:
Description: Esse plugin é um feed-reader como outro qualquer, porém, ele apresenta também os thumbnails presentes no feed
Author: Rodrigo Morbach
Version: 1
*/
class PluginRssThumb extends WP_Widget
{
function PluginRssThumb()
{
$widget_ops = array(
'classname' => 'RssWithThumbnails',
'description' => 'Apresenta Feed Rss com Thumbnails'
);
$this->WP_Widget('RssWithThumbnails', 'Rss With Thumbnail', $widget_ops);
}
function form($instance)
{
$instance = wp_parse_args((array) $instance, array(
'quantidade' => '',
'titulo' => '',
'xml' => ''
));
$title = $instance['quantidade'];
$titulo = $instance['titulo'];
$xml = $instance['xml'];
?>
<p><label for="<?php
echo $this->get_field_id('quantidade');
?>">Quantidade de Feeds: <input class="widefat" id="<?php
echo $this->get_field_id('quantidade');
?>" name="<?php
echo $this->get_field_name('quantidade');
?>" type="text" value="<?php
echo attribute_escape($title);
?>" /></label></p>
<p><label for="<?php
echo $this->get_field_id('titulo');
?>">Titulo (opcional): <input class="widefat" id="<?php
echo $this->get_field_id('titulo');
?>" name="<?php
echo $this->get_field_name('titulo');
?>" type="text" value="<?php
echo attribute_escape($titulo);
?>" /></label></p>
<p><label for="<?php
echo $this->get_field_id('xml');
?>">Informe a URL do Feed: <input class="widefat" id="<?php
echo $this->get_field_id('xml');
?>" name="<?php
echo $this->get_field_name('xml');
?>" type="text" value="<?php
echo attribute_escape($xml);
?>" /></label></p>
<?php
}
function update($new_instance, $old_instance)
{
$instance = $old_instance;
$instance['quantidade'] = $new_instance['quantidade'];
$instance['titulo'] = $new_instance['titulo'];
$instance['xml'] = $new_instance['xml'];
return $instance;
}
function widget($args, $instance)
{
extract($args, EXTR_SKIP);
$titulo = $instance['titulo'];
$xml = $instance['xml'];
echo $before_widget;
$title = empty($instance['quantidade']) ? ' ' : apply_filters('widget_title', $instance['quantidade']);
if (!empty($title))
echo $before_title . $titulo . $after_title;
if (empty($xml)) {
echo 'Nenhum Feed Encontrado';
} else {
$xmlDoc = new DOMDocument();
$xmlDoc->load($xml);
$x = $xmlDoc->getElementsByTagName('item');
for ($i = 0; $i < $instance['quantidade']; $i++) //Define quantas noticias aparecer o na pagina
{
$item_date = $x->item($i)->getElementsByTagName('pubDate')->item(0)->childNodes->item(0)->nodeValue;
$item_title = $x->item($i)->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;
$item_link = $x->item($i)->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue;
$item_desc = $x->item($i)->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue;
echo "<div class='noticia'>";
echo ("<p><a href='" . $item_link . "' target='_blank'>" . $item_title . "</a>");
$item_date = strftime("%d-%m-%Y %H:%M", strtotime($item_date));
echo "<br /><b>" . $item_date . "</b>";
echo "<div class='imagemrss'>";
if (strstr($item_desc, 'img')) {
$item_desc = str_replace('<br />', '', $item_desc);
echo ($item_desc . "</div></p>");
} else {
echo ("<a href='" . $item_link . "' target='_blank'><img src='' /></a>" . $item_desc . "</div></p>");
}
echo "</div>";
}
}
echo $after_widget;
}
}
add_action('widgets_init', create_function('', 'return register_widget("PluginRssThumb");'));
?>