Add "filter" argument

This commit is contained in:
Alexander Dietrich 2017-12-04 21:56:43 +01:00
parent a66ba3a361
commit b40f2878b7

View file

@ -95,6 +95,7 @@ function ff_hh_shortcode_versions( $atts, $content, $name ) {
$domain = 'ffhh'; $domain = 'ffhh';
$branch = 'stable'; $branch = 'stable';
$grep = false; $grep = false;
$filter = false;
if ( is_array( $atts ) ) { if ( is_array( $atts ) ) {
if ( array_key_exists( 'domain', $atts ) && ! empty( $atts['domain'] ) ) { if ( array_key_exists( 'domain', $atts ) && ! empty( $atts['domain'] ) ) {
$domain = $atts['domain']; $domain = $atts['domain'];
@ -105,6 +106,9 @@ function ff_hh_shortcode_versions( $atts, $content, $name ) {
if ( array_key_exists( 'grep', $atts ) && ! empty( $atts['grep'] ) ) { if ( array_key_exists( 'grep', $atts ) && ! empty( $atts['grep'] ) ) {
$grep = $atts['grep']; $grep = $atts['grep'];
} }
if ( array_key_exists( 'filter', $atts ) && ! empty( $atts['filter'] ) ) {
$filter = explode ( ',', $atts['filter'] );
}
} }
$branch_url = FF_HH_UPDATES_URL . $domain . '/' . $branch; $branch_url = FF_HH_UPDATES_URL . $domain . '/' . $branch;
@ -114,10 +118,24 @@ function ff_hh_shortcode_versions( $atts, $content, $name ) {
$outstr .= '<table><tr><th>Modell</th><th>Erstinstallation</th><th>Aktualisierung</th></tr>'; $outstr .= '<table><tr><th>Modell</th><th>Erstinstallation</th><th>Aktualisierung</th></tr>';
foreach ( $manifest as $hw => $versions ) { foreach ( $manifest as $hw => $versions ) {
// filter // select some models
if ( $grep && ( false === strpos( $hw, $grep ) ) ) { if ( $grep && ( false === strpos( $hw, $grep ) ) ) {
continue; continue;
} }
// filter others
if ( $filter ) {
$filtered = false;
foreach ( $filter as $flt ) {
if ( strpos ( $hw, $flt ) !== false ) {
$filtered = true;
break;
}
}
if ( $filtered ) {
continue;
}
}
$hw = ff_hh_beautify_hw_name( $hw, $grep ); $hw = ff_hh_beautify_hw_name( $hw, $grep );
$outstr .= sprintf( "\n<tr><td>%s</td>", $hw ); $outstr .= sprintf( "\n<tr><td>%s</td>", $hw );