XPressME Integration Kit

Trac

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

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

表示設定ページに ダッシュボードのフィードにXPressMEブログとフォーラムの表示有無設定を追加
および関連言語ファイル修正
fixed #206 #207

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