Ticket #42254: 42254.2.diff
File 42254.2.diff, 6.1 KB (added by , 3 years ago) |
---|
-
src/wp-admin/includes/dashboard.php
diff --git src/wp-admin/includes/dashboard.php src/wp-admin/includes/dashboard.php index 89047ba..8359b2f 100644
function wp_dashboard_primary() { 1365 1365 * @param array $feeds Array of RSS feeds. 1366 1366 */ 1367 1367 function wp_dashboard_primary_output( $widget_id, $feeds ) { 1368 1369 $displayed_links = array(); 1370 1368 1371 foreach ( $feeds as $type => $args ) { 1369 1372 $args['type'] = $type; 1370 1373 echo '<div class="rss-widget">'; 1371 wp_widget_rss_output( $args['url'], $args ); 1372 echo "</div>"; 1374 1375 $rss_entries = wp_widget_rss_get_entries( $args['url'], $args ); 1376 1377 if ( is_wp_error( $rss_entries ) ) { 1378 if ( is_admin() || current_user_can( 'manage_options' ) ) { 1379 echo '<p><strong>' . __( 'RSS Error:' ) . '</strong> ' . $rss->get_error_message() . '</p>'; 1380 } 1381 return; 1382 } 1383 1384 $items = (int) $args['items']; 1385 if ( $items < 1 || 20 < $items ) { 1386 $items = 10; 1387 } 1388 1389 $count = 0; 1390 1391 echo '<ul>'; 1392 foreach ( $rss_entries as $item ) { 1393 1394 // Skip duplicate links. 1395 if ( in_array( $item['link'], $displayed_links ) ) { 1396 continue; 1397 } 1398 1399 if ( '' === $item['link'] ) { 1400 echo "<li>{$item['title']}{$item['date']}{$item['summary']}{$item['author']}</li>"; 1401 } elseif ( $item['show_summary'] ) { 1402 echo "<li><a class='rsswidget' href='{$item['link']}'>{$item['title']}</a>{$item['date']}{$item['summary']}{$item['author']}</li>"; 1403 } else { 1404 echo "<li><a class='rsswidget' href='{$item['link']}'>{$item['title']}</a>{$item['date']}{$item['author']}</li>"; 1405 } 1406 1407 $displayed_links[] = $item['link']; 1408 $count++; 1409 if ( $items <= $count ) { 1410 break; 1411 } 1412 } 1413 echo '</ul>'; 1414 1415 echo '</div>'; 1373 1416 } 1374 1417 } 1375 1418 -
src/wp-includes/widgets.php
diff --git src/wp-includes/widgets.php src/wp-includes/widgets.php index 3db5fb8..d15bd61 100644
function _wp_remove_unregistered_widgets( $sidebars_widgets, $whitelist = array( 1373 1373 } 1374 1374 1375 1375 /** 1376 * Display the RSS entries in a list.1376 * Return the RSS entries in an array 1377 1377 * 1378 * @since 2.5.01378 * @since X.X.X 1379 1379 * 1380 1380 * @param string|array|object $rss RSS url. 1381 1381 * @param array $args Widget arguments. 1382 1382 */ 1383 function wp_widget_rss_output( $rss, $args = array() ) { 1383 function wp_widget_rss_get_entries( $rss, $args = array() ) { 1384 1384 1385 if ( is_string( $rss ) ) { 1385 $rss = fetch_feed( $rss);1386 } elseif ( is_array( $rss) && isset($rss['url']) ) {1386 $rss = fetch_feed( $rss ); 1387 } elseif ( is_array( $rss ) && isset( $rss['url'] ) ) { 1387 1388 $args = $rss; 1388 $rss = fetch_feed( $rss['url']);1389 } elseif ( ! is_object($rss) ) {1389 $rss = fetch_feed( $rss['url'] ); 1390 } elseif ( ! is_object( $rss ) ) { 1390 1391 return; 1391 1392 } 1392 1393 1393 if ( is_wp_error($rss) ) { 1394 if ( is_admin() || current_user_can('manage_options') ) 1395 echo '<p><strong>' . __( 'RSS Error:' ) . '</strong> ' . $rss->get_error_message() . '</p>'; 1396 return; 1394 if ( is_wp_error( $rss ) ) { 1395 return $rss; 1397 1396 } 1398 1397 1399 $default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0, 'items' => 0 ); 1398 $default_args = array( 1399 'show_author' => 0, 1400 'show_date' => 0, 1401 'show_summary' => 0, 1402 'items' => 0, 1403 ); 1400 1404 $args = wp_parse_args( $args, $default_args ); 1401 1405 1402 $items = (int) $args['items'];1403 if ( $items < 1 || 20 < $items )1404 $items = 10;1405 1406 $show_summary = (int) $args['show_summary']; 1406 1407 $show_author = (int) $args['show_author']; 1407 1408 $show_date = (int) $args['show_date']; 1408 1409 1409 if ( !$rss->get_item_quantity() ) { 1410 echo '<ul><li>' . __( 'An error has occurred, which probably means the feed is down. Try again later.' ) . '</li></ul>'; 1410 if ( ! $rss->get_item_quantity() ) { 1411 1411 $rss->__destruct(); 1412 unset($rss); 1413 return; 1412 unset( $rss ); 1413 return new WP_Error( 1414 'noitems', 1415 __( 'An error has occurred, which probably means the feed is down. Try again later.' ) 1416 ); 1414 1417 } 1415 1418 1416 echo '<ul>'; 1417 foreach ( $rss->get_items( 0, $items ) as $item ) { 1419 $maxitems = $rss->get_item_quantity(); 1420 $rss_entries = array(); 1421 1422 foreach ( $rss->get_items( 0, $maxitems ) as $item ) { 1418 1423 $link = $item->get_link(); 1419 1424 while ( stristr( $link, 'http' ) != $link ) { 1420 1425 $link = substr( $link, 1 ); … … function wp_widget_rss_output( $rss, $args = array() ) { 1453 1458 $author = ''; 1454 1459 if ( $show_author ) { 1455 1460 $author = $item->get_author(); 1456 if ( is_object( $author) ) {1461 if ( is_object( $author ) ) { 1457 1462 $author = $author->get_name(); 1458 1463 $author = ' <cite>' . esc_html( strip_tags( $author ) ) . '</cite>'; 1459 1464 } 1460 1465 } 1461 1466 1462 if ( $link == '' ) { 1463 echo "<li>$title{$date}{$summary}{$author}</li>"; 1464 } elseif ( $show_summary ) { 1465 echo "<li><a class='rsswidget' href='$link'>$title</a>{$date}{$summary}{$author}</li>"; 1467 $rss_entries[] = array( 1468 'title' => $title, 1469 'date' => $date, 1470 'summary' => $summary, 1471 'author' => $author, 1472 'link' => $link, 1473 ); 1474 1475 } 1476 1477 $rss->__destruct(); 1478 unset( $rss ); 1479 1480 return $rss_entries; 1481 1482 } 1483 1484 /** 1485 * Display the RSS entries in a list. 1486 * 1487 * @since 2.5.0 1488 * 1489 * @param string|array|object $rss RSS url. 1490 * @param array $args Widget arguments. 1491 */ 1492 function wp_widget_rss_output( $rss, $args = array() ) { 1493 1494 $rss_entries = wp_widget_rss_get_entries( $rss, $args ); 1495 1496 if ( is_wp_error( $rss_entries ) ) { 1497 if ( is_admin() || current_user_can( 'manage_options' ) ) { 1498 echo '<p><strong>' . __( 'RSS Error:' ) . '</strong> ' . $rss->get_error_message() . '</p>'; 1499 } 1500 return; 1501 } 1502 1503 $items = (int) $args['items']; 1504 if ( $items < 1 || 20 < $items ) { 1505 $items = 10; 1506 } 1507 1508 echo '<ul>'; 1509 foreach ( array_slice( $rss_entries, 0, $items ) as $item ) { 1510 1511 if ( '' === $item['link'] ) { 1512 echo "<li>{$item['title']}{$item['date']}{$item['summary']}{$item['author']}</li>"; 1513 } elseif ( $item['show_summary'] ) { 1514 echo "<li><a class='rsswidget' href='{$item['link']}'>{$item['title']}</a>{$item['date']}{$item['summary']}{$item['author']}</li>"; 1466 1515 } else { 1467 echo "<li><a class='rsswidget' href=' $link'>$title</a>{$date}{$author}</li>";1516 echo "<li><a class='rsswidget' href='{$item['link']}'>{$item['title']}</a>{$item['date']}{$item['author']}</li>"; 1468 1517 } 1469 1518 } 1470 1519 echo '</ul>'; 1471 $rss->__destruct(); 1472 unset($rss); 1520 1473 1521 } 1474 1522 1475 1523 /**