| 1 | <?php
|
|---|
| 2 |
|
|---|
| 3 | // Register Dashboard Widget
|
|---|
| 4 | add_action('wp_dashboard_setup', 'xpress_register_dashboard_widget');
|
|---|
| 5 |
|
|---|
| 6 | function 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 | $blog_link = 'http://ja.xpressme.info/blog/feed/';
|
|---|
| 15 | $blog_url = 'http://ja.xpressme.info/blog/feed/';
|
|---|
| 16 | if ( !isset( $widget_options['xpress_dashboard_primary'] ) ) {
|
|---|
| 17 | $update = true;
|
|---|
| 18 | $widget_options['xpress_dashboard_primary'] = array(
|
|---|
| 19 | 'link' => $blog_link ,
|
|---|
| 20 | 'url' => $blog_url,
|
|---|
| 21 | 'title' => __( 'XPressME Integration Kit Blog' , 'xpressme') ,
|
|---|
| 22 | 'items' => 2,
|
|---|
| 23 | 'show_summary' => 1,
|
|---|
| 24 | 'show_author' => 0,
|
|---|
| 25 | 'show_date' => 1
|
|---|
| 26 | );
|
|---|
| 27 | }
|
|---|
| 28 | // Override Setting
|
|---|
| 29 | $widget_options['xpress_dashboard_primary']['link'] = $blog_link;
|
|---|
| 30 | $widget_options['xpress_dashboard_primary']['url'] = $blog_url;
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 | $forums_link = 'http://ja.xpressme.info/forums/';
|
|---|
| 34 | $forums_url = 'http://ja.xpressme.info/forums/feed/';
|
|---|
| 35 | if ( !isset( $widget_options['xpress_dashboard_secondary'] ) ) {
|
|---|
| 36 | $update = true;
|
|---|
| 37 | $widget_options['xpress_dashboard_secondary'] = array(
|
|---|
| 38 | 'link' => $forums_link ,
|
|---|
| 39 | 'url' => $forums_url,
|
|---|
| 40 | 'title' => __( 'XPressME Integration Kit Folum' , 'xpressme') ,
|
|---|
| 41 | 'items' => 5,
|
|---|
| 42 | 'show_summary' => 0,
|
|---|
| 43 | 'show_author' => 0,
|
|---|
| 44 | 'show_date' => 0
|
|---|
| 45 | );
|
|---|
| 46 | }
|
|---|
| 47 | // Override Setting
|
|---|
| 48 | $widget_options['xpress_dashboard_secondary']['link'] = $forums_link;
|
|---|
| 49 | $widget_options['xpress_dashboard_secondary']['url'] = $forums_url;
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 | update_option( 'xpress_dashboard_widget_options', $widget_options );
|
|---|
| 53 | if ($xpress_config->is_dashboard_blog_disp){
|
|---|
| 54 | wp_add_dashboard_widget( 'xpress_dashboard_primary', $widget_options['xpress_dashboard_primary']['title'], 'xpress_dashboard_primary', 'xpress_dashboard_primary_control' );
|
|---|
| 55 | }
|
|---|
| 56 | if ($xpress_config->is_dashboard_forum_disp){
|
|---|
| 57 | wp_add_dashboard_widget( 'xpress_dashboard_secondary', $widget_options['xpress_dashboard_secondary']['title'], 'xpress_dashboard_secondary', 'xpress_dashboard_secondary_control');
|
|---|
| 58 | }
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 | function xpress_dashboard_primary() {
|
|---|
| 64 | xpress_dashboard_rss_output('xpress_dashboard_primary');
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | function xpress_dashboard_primary_control() {
|
|---|
| 68 | xpress_dashboard_rss_control( 'xpress_dashboard_primary' );
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | function xpress_dashboard_secondary() {
|
|---|
| 72 | xpress_dashboard_rss_output('xpress_dashboard_secondary');
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | function xpress_dashboard_secondary_control() {
|
|---|
| 76 | xpress_dashboard_rss_control( 'xpress_dashboard_secondary' );
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | function xpress_dashboard_rss_output( $widget_id ) {
|
|---|
| 80 | $widgets = get_option( 'xpress_dashboard_widget_options' );
|
|---|
| 81 | echo "<div class='rss-widget'>";
|
|---|
| 82 | wp_widget_rss_output( $widgets[$widget_id] );
|
|---|
| 83 | echo "</div>";
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | function xpress_dashboard_rss_control( $widget_id, $form_inputs = array() ) {
|
|---|
| 87 | if ( !$widget_options = get_option( 'xpress_dashboard_widget_options' ) )
|
|---|
| 88 | $widget_options = array();
|
|---|
| 89 |
|
|---|
| 90 | if ( !isset($widget_options[$widget_id]) )
|
|---|
| 91 | $widget_options[$widget_id] = array();
|
|---|
| 92 |
|
|---|
| 93 | $number = 1; // Hack to use wp_widget_rss_form()
|
|---|
| 94 | $widget_options[$widget_id]['number'] = $number;
|
|---|
| 95 |
|
|---|
| 96 | if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget-rss'][$number]) ) {
|
|---|
| 97 | $_POST['widget-rss'][$number] = stripslashes_deep( $_POST['widget-rss'][$number] );
|
|---|
| 98 | $widget_options[$widget_id] = wp_widget_rss_process( $_POST['widget-rss'][$number] );
|
|---|
| 99 | // title is optional. If black, fill it if possible
|
|---|
| 100 | if ( !$widget_options[$widget_id]['title'] && isset($_POST['widget-rss'][$number]['title']) ) {
|
|---|
| 101 | $rss = fetch_feed($widget_options[$widget_id]['url']);
|
|---|
| 102 | if ( ! is_wp_error($rss) )
|
|---|
| 103 | $widget_options[$widget_id]['title'] = htmlentities(strip_tags($rss->get_title()));
|
|---|
| 104 | else
|
|---|
| 105 | $widget_options[$widget_id]['title'] = htmlentities(__('Unknown Feed'));
|
|---|
| 106 | }
|
|---|
| 107 | update_option( 'xpress_dashboard_widget_options', $widget_options );
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | wp_widget_rss_form( $widget_options[$widget_id], $form_inputs );
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | ?> |
|---|