breznflow/includes/Features/InfoBoxBuilder.php
Michael fd83e4810b BreznFlow 1.0.0 — WordPress.org submission
Initial public release of BreznFlow, an n8n workflow renderer for WordPress.
Fully PHPCS-compliant (WordPress Coding Standards), security-hardened,
and ready for WordPress.org plugin review.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-30 11:27:36 +00:00

87 lines
1.9 KiB
PHP

<?php
/**
* Builds the node summary InfoBox HTML.
*
* @package BreznFlow
* @since 1.0.0
*/
namespace BreznFlow\Features;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Builds the HTML info box summarizing workflow node statistics.
*
* @since 1.0.0
*/
class InfoBoxBuilder {
/**
* Builds the InfoBox HTML for display in frontend.
*
* @param array $categorized Result from NodeCategorizer::categorize().
* @return string Safe HTML string.
*/
public static function build( array $categorized ): string {
$counts = $categorized['counts'] ?? array();
$has_ai = $categorized['has_ai'] ?? false;
$total = $categorized['total'] ?? 0;
$display = array();
$more = 0;
$i = 0;
foreach ( $counts as $label => $count ) {
if ( $i < 6 ) {
$display[] = array(
'label' => $label,
'count' => $count,
);
} else {
++$more;
}
++$i;
}
$html = '<div class="breznflow-infobox">';
$html .= '<div class="breznflow-infobox-nodes">';
foreach ( $display as $item ) {
$html .= sprintf(
'<span class="breznflow-infobox-node"><strong>%dx</strong> %s</span>',
(int) $item['count'],
esc_html( $item['label'] )
);
}
if ( $more > 0 ) {
$html .= sprintf(
'<span class="breznflow-infobox-more">+ %s %s</span>',
(int) $more,
/* translators: %d: number of additional node types */
esc_html( _n( 'more type', 'more types', $more, 'breznflow' ) )
);
}
$html .= '</div>';
if ( $has_ai ) {
$html .= '<div class="breznflow-infobox-ai">';
$html .= '<span class="breznflow-ai-badge">' . esc_html__( 'AI-powered', 'breznflow' ) . '</span>';
$html .= '</div>';
}
$html .= sprintf(
'<div class="breznflow-infobox-total">%s</div>',
sprintf(
/* translators: %d: total node count */
esc_html( _n( '%d node', '%d nodes', $total, 'breznflow' ) ),
(int) $total
)
);
$html .= '</div>';
return $html;
}
}