XPressME Integration Kit

Trac

source: trunk/xpressme_integration_kit/wp-content/plugins/xpressme/include/dashboard_feed.php @ 376

Last change on this file since 376 was 376, checked in by toemon, 15 years ago

ダッシュボードにXPressME Integration Kit のブログとフォーラムのfeed を追加 #206 #207
言語ファイルはまだ

File size: 3.5 KB
Line 
1<?php
2
3// Register Dashboard Widget
4add_action('wp_dashboard_setup', 'xpress_register_dashboard_widget');
5
6function xpress_register_dashboard_widget() {
7        global $wp_registered_widgets, $wp_registered_widget_controls, $wp_dashboard_control_callbacks;
8
9        $widget_options = get_option( 'xpress_dashboard_widget_options' );
10        if ( !$widget_options || !is_array($widget_options) )
11                $widget_options = array();
12       
13        if ( !isset( $widget_options['xpress_dashboard_primary'] ) ) {
14                $update = true;
15                $widget_options['xpress_dashboard_primary'] = array(
16                        'link' => 'http://ja.xpressme.info/blog/' ,
17                        'url' => 'http://ja.xpressme.info/feed/',
18                        'title' =>  __( 'XPressME Integration Kit Blog' , 'xpressme') ,
19                        'items' => 2,
20                        'show_summary' => 1,
21                        'show_author' => 0,
22                        'show_date' => 1
23                );
24        }
25
26        if ( !isset( $widget_options['xpress_dashboard_secondary'] ) ) {
27                $update = true;
28                $widget_options['xpress_dashboard_secondary'] = array(
29                        'link' => 'http://forum.xpressme.info/' ,
30                        'url' => 'http://forum.xpressme.info/rss.php?topics=1',
31                        'title' =>  __( 'XPressME Integration Kit Folum' , 'xpressme') ,
32                        'items' => 5,
33                        'show_summary' => 0,
34                        'show_author' => 0,
35                        'show_date' => 0
36                );
37        }
38        update_option( 'xpress_dashboard_widget_options', $widget_options );
39       
40        wp_add_dashboard_widget( 'xpress_dashboard_primary', $widget_options['xpress_dashboard_primary']['title'], 'xpress_dashboard_primary', 'xpress_dashboard_primary_control' );
41        wp_add_dashboard_widget( 'xpress_dashboard_secondary', $widget_options['xpress_dashboard_secondary']['title'], 'xpress_dashboard_secondary', 'xpress_dashboard_secondary_control');
42}
43
44
45
46function xpress_dashboard_primary() {
47        xpress_dashboard_rss_output('xpress_dashboard_primary');
48}
49
50function xpress_dashboard_primary_control() {
51        xpress_dashboard_rss_control( 'xpress_dashboard_primary' );
52}
53
54function xpress_dashboard_secondary() {
55        xpress_dashboard_rss_output('xpress_dashboard_secondary');
56}
57
58function xpress_dashboard_secondary_control() {
59        xpress_dashboard_rss_control( 'xpress_dashboard_secondary' );
60}
61
62function xpress_dashboard_rss_output( $widget_id ) {
63        $widgets = get_option( 'xpress_dashboard_widget_options' );
64        echo "<div class='rss-widget'>";
65        wp_widget_rss_output( $widgets[$widget_id] );
66        echo "</div>";
67}
68
69function xpress_dashboard_rss_control( $widget_id, $form_inputs = array() ) {
70        if ( !$widget_options = get_option( 'xpress_dashboard_widget_options' ) )
71                $widget_options = array();
72
73        if ( !isset($widget_options[$widget_id]) )
74                $widget_options[$widget_id] = array();
75
76        $number = 1; // Hack to use wp_widget_rss_form()
77        $widget_options[$widget_id]['number'] = $number;
78
79        if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget-rss'][$number]) ) {
80                $_POST['widget-rss'][$number] = stripslashes_deep( $_POST['widget-rss'][$number] );
81                $widget_options[$widget_id] = wp_widget_rss_process( $_POST['widget-rss'][$number] );
82                // title is optional.  If black, fill it if possible
83                if ( !$widget_options[$widget_id]['title'] && isset($_POST['widget-rss'][$number]['title']) ) {
84                        $rss = fetch_feed($widget_options[$widget_id]['url']);
85                        if ( ! is_wp_error($rss) )
86                                $widget_options[$widget_id]['title'] = htmlentities(strip_tags($rss->get_title()));
87                        else
88                                $widget_options[$widget_id]['title'] = htmlentities(__('Unknown Feed'));
89                }
90                update_option( 'xpress_dashboard_widget_options', $widget_options );
91        }
92
93        wp_widget_rss_form( $widget_options[$widget_id], $form_inputs );
94}
95
96?>
Note: See TracBrowser for help on using the repository browser.