breznflow/includes/Admin/views/wizard-step-2.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

212 lines
8.5 KiB
PHP

<?php
/**
* Template: Wizard step 2 — configure workflow display settings.
*
* @package BreznFlow
* @since 1.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- template file, not global scope
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.WP.GlobalVariablesOverride.Prohibited
$post_id = isset( $_GET['post_id'] ) ? (int) $_GET['post_id'] : 0;
$workflow = $post_id > 0 ? get_post( $post_id ) : null;
if ( ! $workflow || 'breznflow_workflow' !== $workflow->post_type ) {
wp_die( esc_html__( 'Invalid workflow.', 'breznflow' ) );
}
$meta_mode = get_post_meta( $post_id, '_breznflow_default_mode', true );
$display_mode = $meta_mode ? $meta_mode : 'visual';
$meta_zoom = (int) get_post_meta( $post_id, '_breznflow_default_zoom', true );
$zoom = $meta_zoom ? $meta_zoom : 100;
$show_title = (int) get_post_meta( $post_id, '_breznflow_show_title', true );
$show_infobox = (int) get_post_meta( $post_id, '_breznflow_show_infobox', true );
$show_download = (int) get_post_meta( $post_id, '_breznflow_show_download', true );
$show_embed = (int) get_post_meta( $post_id, '_breznflow_show_embed', true );
$saved_theme_raw = get_post_meta( $post_id, '_breznflow_default_theme', true );
$saved_theme = $saved_theme_raw ? $saved_theme_raw : 'dark';
$show_minimap = get_post_meta( $post_id, '_breznflow_show_minimap', true );
$show_minimap = '' === $show_minimap ? 1 : (int) $show_minimap;
$mask_log_raw = get_post_meta( $post_id, '_breznflow_mask_log', true );
$mask_log = json_decode( $mask_log_raw ? $mask_log_raw : '[]', true );
$has_ai = (int) get_post_meta( $post_id, '_breznflow_has_ai_nodes', true );
$node_count = (int) get_post_meta( $post_id, '_breznflow_node_count', true );
$categories = get_terms(
array(
'taxonomy' => 'breznflow_category',
'hide_empty' => false,
)
);
$current_cats = wp_get_post_terms( $post_id, 'breznflow_category', array( 'fields' => 'ids' ) );
?>
<div class="wrap breznflow-wizard">
<h1 class="wp-heading-inline">
<?php esc_html_e( 'Configure Workflow', 'breznflow' ); ?>
</h1>
<div class="breznflow-wizard-steps">
<span class="breznflow-step done"><?php esc_html_e( '1. Import JSON', 'breznflow' ); ?></span>
<span class="breznflow-step active"><?php esc_html_e( '2. Configure', 'breznflow' ); ?></span>
<span class="breznflow-step"><?php esc_html_e( '3. Preview & Publish', 'breznflow' ); ?></span>
</div>
<div class="breznflow-step2-meta">
<span>
<?php
/* translators: %d: number of workflow nodes */
printf( esc_html__( '%d nodes', 'breznflow' ), absint( $node_count ) );
?>
</span>
<?php if ( $has_ai ) : ?>
<span class="breznflow-badge-ai"><?php esc_html_e( 'AI-powered', 'breznflow' ); ?></span>
<?php endif; ?>
</div>
<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
<input type="hidden" name="action" value="breznflow_save_step2" />
<input type="hidden" name="breznflow_post_id" value="<?php echo esc_attr( (string) $post_id ); ?>" />
<?php wp_nonce_field( 'breznflow_step2', 'breznflow_nonce' ); ?>
<div class="breznflow-card">
<h2><?php esc_html_e( 'Basic Settings', 'breznflow' ); ?></h2>
<table class="form-table">
<tr>
<th><label for="post_title"><?php esc_html_e( 'Workflow Title', 'breznflow' ); ?></label></th>
<td>
<input type="text" name="post_title" id="post_title" class="regular-text"
value="<?php echo esc_attr( $workflow->post_title ); ?>" required />
</td>
</tr>
<?php if ( ! is_wp_error( $categories ) && ! empty( $categories ) ) : ?>
<tr>
<th><label><?php esc_html_e( 'Categories', 'breznflow' ); ?></label></th>
<td>
<select name="breznflow_categories[]" multiple class="breznflow-multiselect">
<?php foreach ( $categories as $bf_cat ) : ?>
<option value="<?php echo esc_attr( (string) $bf_cat->term_id ); ?>"
<?php selected( in_array( $bf_cat->term_id, (array) $current_cats, true ) ); ?>>
<?php echo esc_html( $bf_cat->name ); ?>
</option>
<?php endforeach; ?>
</select>
</td>
</tr>
<?php endif; ?>
<tr>
<th><label><?php esc_html_e( 'Display Mode', 'breznflow' ); ?></label></th>
<td>
<label><input type="radio" name="default_mode" value="visual" <?php checked( 'visual', $display_mode ); ?> />
<?php esc_html_e( 'Visual (diagram + infobox)', 'breznflow' ); ?></label><br />
<label><input type="radio" name="default_mode" value="info" <?php checked( 'info', $display_mode ); ?> />
<?php esc_html_e( 'Info only (infobox, no diagram)', 'breznflow' ); ?></label><br />
<label><input type="radio" name="default_mode" value="compact" <?php checked( 'compact', $display_mode ); ?> />
<?php esc_html_e( 'Compact (diagram only, no toolbar)', 'breznflow' ); ?></label>
</td>
</tr>
<tr>
<th><label for="default_zoom"><?php esc_html_e( 'Default Zoom', 'breznflow' ); ?></label></th>
<td>
<input type="range" name="default_zoom" id="default_zoom"
min="10" max="200" value="<?php echo esc_attr( (string) $zoom ); ?>"
oninput="document.getElementById('zoom-label').textContent=this.value+'%'" />
<span id="zoom-label"><?php echo esc_html( $zoom . '%' ); ?></span>
</td>
</tr>
<tr>
<th><?php esc_html_e( 'Display Options', 'breznflow' ); ?></th>
<td>
<label><input type="checkbox" name="show_title" <?php checked( 1, $show_title ); ?> />
<?php esc_html_e( 'Show title above diagram', 'breznflow' ); ?></label><br />
<label><input type="checkbox" name="show_infobox" <?php checked( 1, $show_infobox ); ?> />
<?php esc_html_e( 'Show node info box', 'breznflow' ); ?></label><br />
<label><input type="checkbox" name="show_download" <?php checked( 1, $show_download ); ?> />
<?php esc_html_e( 'Allow JSON download', 'breznflow' ); ?></label><br />
<label><input type="checkbox" name="show_embed" <?php checked( 1, $show_embed ); ?> />
<?php esc_html_e( 'Allow iframe embed', 'breznflow' ); ?></label><br />
<label><input type="checkbox" name="show_minimap" <?php checked( 1, $show_minimap ); ?> />
<?php esc_html_e( 'Show minimap button', 'breznflow' ); ?></label>
</td>
</tr>
<tr>
<th><label for="bf-wiz-theme"><?php esc_html_e( 'Viewer Theme', 'breznflow' ); ?></label></th>
<td>
<select name="default_theme" id="bf-wiz-theme">
<?php foreach ( \BreznFlow\Features\ThemeRegistry::discover() as $bf_theme_id => $bf_theme_meta ) : ?>
<option value="<?php echo esc_attr( $bf_theme_id ); ?>" <?php selected( $bf_theme_id, $saved_theme ); ?>>
<?php echo esc_html( $bf_theme_meta['name'] ); ?>
</option>
<?php endforeach; ?>
</select>
</td>
</tr>
</table>
</div>
<div class="breznflow-card">
<h2><?php esc_html_e( 'Shortcode Preview', 'breznflow' ); ?></h2>
<div class="breznflow-shortcode-preview">
<code id="breznflow-shortcode-live">[breznflow id="<?php echo esc_html( (string) $post_id ); ?>"]</code>
<button type="button" class="button button-small breznflow-copy-sc"
data-sc='[breznflow id="<?php echo esc_attr( (string) $post_id ); ?>"]'>
<?php esc_html_e( 'Copy', 'breznflow' ); ?>
</button>
</div>
</div>
<?php if ( ! empty( $mask_log ) ) : ?>
<div class="breznflow-card">
<h2><?php esc_html_e( 'Security Masking Log', 'breznflow' ); ?></h2>
<details>
<summary>
<?php
printf(
/* translators: %d: number of masked items */
esc_html( _n( '%d item was sanitized', '%d items were sanitized', count( $mask_log ), 'breznflow' ) ),
(int) count( $mask_log )
);
?>
</summary>
<ul class="breznflow-mask-log">
<?php foreach ( $mask_log as $entry ) : ?>
<li>
<code><?php echo esc_html( $entry['key'] ?? '' ); ?></code>
— <?php echo esc_html( $entry['note'] ?? '' ); ?>
<em>(<?php echo esc_html( $entry['reason'] ?? '' ); ?>)</em>
</li>
<?php endforeach; ?>
</ul>
</details>
</div>
<?php endif; ?>
<p class="submit">
<a href="
<?php
echo esc_url(
add_query_arg(
array(
'page' => 'breznflow-add',
'step' => '1',
),
admin_url( 'admin.php' )
)
);
?>
"
class="button button-secondary"><?php esc_html_e( '← Back', 'breznflow' ); ?></a>
<button type="submit" class="button button-primary">
<?php esc_html_e( 'Continue to Preview', 'breznflow' ); ?>
</button>
</p>
</form>
</div>