/
dashboard.php
103 lines (84 loc) · 2.93 KB
/
dashboard.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
<?php
/**
* WP Geo Dashboard
* Display the WP Geo Blog RSS feed in the dashboard.
*/
if ( ! class_exists( 'WPGeo_Dashboard' ) ) {
class WPGeo_Dashboard {
/**
* Constructor
*/
function __construct() {
add_action( 'wp_dashboard_setup', array( $this, 'register_widget' ) );
add_filter( 'wp_dashboard_widgets', array( $this, 'add_widget' ) );
}
/**
* Deprecated PHP 4 Constructor
*/
function WPGeo_Dashboard() {
$this->__construct();
}
/**
* Register the dashboard widget
*/
function register_widget() {
wp_add_dashboard_widget( 'wpgeo_dashboard', 'WP Geo',
array( $this, 'widget' ),
array(
'all_link' => 'http://www.wpgeo.com/',
'feed_link' => 'http://www.wpgeo.com/feed/'
)
);
}
/**
* Add the dashboard widget
*
* @param array $widgets Array of widgets.
* @return array Widgets.
*/
function add_widget( $widgets ) {
global $wp_registered_widgets;
if ( ! isset( $wp_registered_widgets['wpgeo_dashboard'] ) ) {
return $widgets;
}
array_splice( $widgets, sizeof( $widgets ) - 1, 0, 'wpgeo_dashboard' );
return $widgets;
}
/**
* Display the dashboard widget
*
* @param array $args Args.
*/
function widget( $args = null ) {
// Validate Args
$defaults = array(
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
'widget_name' => ''
);
extract( wp_parse_args( $args, $defaults ), EXTR_SKIP );
echo $before_widget . $before_title . $widget_name . $after_title;
echo '<div style="background-image:url(' . plugins_url( WPGEO_SUBDIR . 'img/logo/wp-geo.png' ) . '); background-repeat:no-repeat; background-position:right top; padding-right:80px;">';
$feed = fetch_feed( 'http://feeds2.feedburner.com/wpgeo' );
if ( is_wp_error( $feed ) || ! $feed->get_item_quantity() ) {
echo '<p>' . esc_html__( 'No recent updates.', 'wp-geo' ) . '</p>';
return;
}
$items = $feed->get_items( 0, 2 );
foreach ( $items as $item ) {
echo '<div style="margin-bottom:20px;">';
echo '<p style="margin-bottom:5px;"><a style="font-size: 1.2em; font-weight:bold;" href="' . esc_url( $item->get_link() ) . '" title="' . esc_attr( $item->get_title() ) . '">' . esc_html( $item->get_title() ) . '</a></p>';
echo '<p style="color: #aaa; margin-top:5px;">' . date( 'l, jS F Y', strtotime( strip_tags( $item->get_date() ) ) ) . '</p>';
echo '<p>' . esc_html( strip_tags( @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) ) ) ) .'</p>';
echo '</div>';
}
echo '<p><a href="http://www.wpgeo.com/">' . esc_html__( 'View all WP Geo news...', 'wp-geo' ) . '</a></p>';
echo '</div>';
echo $after_widget;
}
}
global $wpgeo_dashboard;
$wpgeo_dashboard = new WPGeo_Dashboard();
}