-
Notifications
You must be signed in to change notification settings - Fork 0
/
wppt-admin-widget.php
121 lines (103 loc) · 3.5 KB
/
wppt-admin-widget.php
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
115
116
117
118
119
120
121
<?php
/**
* Plugin Name: WordPress Portugal Admin Widget
* Plugin URI: http://vanilla-lounge.pt
* Description: Adds a widget to your dashboard screen, with the latest news from http://wp-portugal.com/
* Contributors: vanillalounge
* Author: vanillalounge
* Author URI: http://wordpress.org/support/profile/vanillalounge
* Tags: dashboard, widget, rss, Portugal
* Requires at least: 3.0
* Tested up to: 3.5.1
* Stable tag: 1.0.1
* Version: 1.0
* License: GPL2
* Copyright 2013 vanillalounge (email : info AT vanilla-lounge DOT pt)
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2, as
* published by the Free Software Foundation.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* The plugin base class - the root of it all
*
* @author vanillalounge
*
*/
class VL_WPPTAW_Plugin_Base {
/**
* Assign everything as a call from within the constructor
*/
function __construct() {
$this->add_rss_panel();
}
/**
* Hook into wp_dashboard_setup to add the widget
*
* @since 1.0
*
*/
function add_rss_panel() {
add_action( 'wp_dashboard_setup', array( $this, 'add_rss_panel_callback' ) );
}
/**
* Add the actual widget
*
* @since 1.0
*
*/
function add_rss_panel_callback() {
wp_add_dashboard_widget( 'wpptrss_news_list', 'Notícias WordPress Portugal', array( $this, 'add_rss_widget' ) );
}
/**
* Widget display code
*
* @since 1.0
*
*/
function add_rss_widget() {
$rss = fetch_feed( 'http://wp-portugal.com/feed/' );
if ( is_wp_error( $rss ) ) : // Checks that the object is created correctly
echo '<div class="rss-widget"><p>';
printf( '<strong>Erro RSS</strong>: %s', $rss->get_error_message() );
echo '</p></div>';
return;
endif;
echo '<div class="rss-widget">';
echo '<ul>';
$maxitems = $rss->get_item_quantity( 5 );
$rss_items = $rss->get_items( 0, $maxitems );
if ( $maxitems == 0 )
echo '<li>Nenhuma entrada.</li>';
else
foreach ( $rss_items as $item ) :
$desc = str_replace( array( "\n", "\r" ), ' ', esc_attr( strip_tags( @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) ) ) ) );
$desc = wp_html_excerpt( $desc, 360 );
// Append ellipsis. Change existing [...] to […].
if ( '[...]' == substr( $desc, -5 ) )
$desc = substr( $desc, 0, -5 ) . '[…]';
elseif ( '[…]' != substr( $desc, -10 ) )
$desc .= ' […]';
$desc = esc_html( $desc );
echo '<li>';
// feed title
echo '<a class="rsswidget" target="_blank" href="'.esc_url ( $item->get_permalink() ).'" title="Posted '.$item->get_date( 'j F Y | g:i a' ).'">'.esc_html( $item->get_title() ).'</a>';
echo '<span class="rss-date">'.$item->get_date( 'F j, Y' ).'</span>';
// feed summary
echo '<div class="rssSummary">';
echo $desc;
echo '</div>';
echo '</li>';
endforeach;
echo '</ul>';
echo '</div>';
}
}
// Initialize everything
$wpptaw_plugin_base = new VL_WPPTAW_Plugin_Base();