Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions assets/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
* OpenTrust admin styles.
*/

/* Server-rendered visibility toggle. jQuery .show()/.hide() override via inline style. */
.ot-hidden {
display: none;
}

/* Accent contrast warning */
.ot-accent-warning {
display: flex;
Expand Down
4 changes: 2 additions & 2 deletions includes/class-opentrust-admin-ai.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public function render_ai_tab(array $settings): void {
<?php
printf(
/* translators: %s: provider label, e.g. OpenAI */
esc_html__('You are currently using %s. Only Anthropic uses a structural Citations API — every other provider relies on prompted citation tags the model can ignore or fabricate. For a published trust center, switch to Anthropic below.', 'opentrust'),
'<strong>' . esc_html(ucfirst($active_provider)) . '</strong>' // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
wp_kses(__('You are currently using <strong>%s</strong>. Only Anthropic uses a structural Citations API — every other provider relies on prompted citation tags the model can ignore or fabricate. For a published trust center, switch to Anthropic below.', 'opentrust'), ['strong' => []]),
esc_html(ucfirst($active_provider))
);
?>
</p>
Expand Down
12 changes: 8 additions & 4 deletions includes/class-opentrust-admin-questions.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function render_page(): void {
<?php esc_html_e('Questions visitors have asked your trust center chat. Identifiers are hashed and rows auto-purge after 90 days.', 'opentrust'); ?>
</p>

<div style="display:flex;align-items:center;gap:16px;margin:16px 0;padding:12px 16px;background:<?php echo !empty($settings['ai_logging_enabled']) ? '#dcfce7' : '#fef2f2'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>;border-radius:6px">
<div style="<?php echo esc_attr('display:flex;align-items:center;gap:16px;margin:16px 0;padding:12px 16px;background:' . (!empty($settings['ai_logging_enabled']) ? '#dcfce7' : '#fef2f2') . ';border-radius:6px'); ?>">
<strong>
<?php if (!empty($settings['ai_logging_enabled'])): ?>
✓ <?php esc_html_e('Logging is ON', 'opentrust'); ?>
Expand Down Expand Up @@ -187,15 +187,19 @@ public function render_page(): void {
<div class="tablenav" style="margin-top:16px">
<div class="tablenav-pages">
<?php
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- paginate_links returns safe HTML
echo paginate_links([
// Allow-list mirrors the markup paginate_links() emits.
$pagination_allowed = [
'a' => ['href' => true, 'class' => true, 'title' => true, 'aria-current' => true, 'aria-label' => true],
'span' => ['class' => true, 'aria-current' => true],
];
echo wp_kses((string) paginate_links([
'base' => add_query_arg('paged', '%#%', $base),
'format' => '',
'current' => $filters['page'],
'total' => $pages,
'prev_text' => '‹',
'next_text' => '›',
]);
]), $pagination_allowed);
?>
</div>
</div>
Expand Down
42 changes: 17 additions & 25 deletions includes/class-opentrust-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,30 +188,22 @@ private function render_input_field(string $type, array $args, array $extra_attr
$key = $args['key'];
$value = $settings[$key] ?? '';

$attr_html = '';
foreach ($extra_attrs as $name => $val) {
$attr_html .= ' ' . $name . '="' . esc_attr($val) . '"';
if ($type === 'textarea') {
echo '<textarea id="opentrust_' . esc_attr($key) . '" name="opentrust_settings[' . esc_attr($key) . ']" rows="3" class="large-text"';
} else {
echo '<input type="' . esc_attr($type) . '" id="opentrust_' . esc_attr($key) . '" name="opentrust_settings[' . esc_attr($key) . ']" value="' . esc_attr($value) . '" class="regular-text"';
}
foreach ($extra_attrs as $attr_name => $attr_val) {
echo ' ' . esc_attr($attr_name) . '="' . esc_attr($attr_val) . '"';
}

if ($type === 'textarea') {
printf(
'<textarea id="opentrust_%1$s" name="opentrust_settings[%1$s]" rows="3" class="large-text"%3$s>%2$s</textarea>',
esc_attr($key),
esc_textarea($value),
$attr_html // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- attribute values escaped above; names are hardcoded
);
echo '>' . esc_textarea($value) . '</textarea>';
} else {
printf(
'<input type="%4$s" id="opentrust_%1$s" name="opentrust_settings[%1$s]" value="%2$s" class="regular-text"%3$s>',
esc_attr($key),
esc_attr($value),
$attr_html, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- attribute values escaped above; names are hardcoded
esc_attr($type)
);
echo '>';
}

if (!empty($args['description'])) {
printf('<p class="description">%s</p>', esc_html($args['description']));
echo '<p class="description">' . esc_html($args['description']) . '</p>';
}
}

Expand All @@ -224,7 +216,7 @@ public function render_color_field(array $args): void {
esc_attr($value)
);
?>
<div id="opentrust-accent-warning" class="ot-accent-warning<?php echo $force_exact ? ' ot-accent-warning--override' : ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Hardcoded class ?>" hidden>
<div id="opentrust-accent-warning" class="ot-accent-warning<?php echo esc_attr($force_exact ? ' ot-accent-warning--override' : ''); ?>" hidden>
<svg class="ot-accent-warning__icon" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0Z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>
<div class="ot-accent-warning__body">
<strong class="ot-accent-warning__heading ot-accent-warning__heading--auto"><?php esc_html_e('Low contrast on white backgrounds', 'opentrust'); ?></strong>
Expand Down Expand Up @@ -289,12 +281,12 @@ private function render_media_field(string $key, string $button_label, string $d
$media_url = $media_id ? wp_get_attachment_image_url($media_id, 'medium') : '';
?>
<div class="ot-logo-upload" data-ot-media-field>
<div class="ot-logo-preview" <?php echo $media_url ? '' : 'style="display:none"'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Hardcoded string ?>>
<div class="ot-logo-preview<?php echo esc_attr($media_url ? '' : ' ot-hidden'); ?>">
<img src="<?php echo esc_url($media_url); ?>" alt="" style="max-width:200px;max-height:80px">
</div>
<input type="hidden" name="opentrust_settings[<?php echo esc_attr($key); ?>]" value="<?php echo esc_attr((string) $media_id); ?>" data-ot-media-input>
<button type="button" class="button" data-ot-media-upload><?php echo esc_html($button_label); ?></button>
<button type="button" class="button" data-ot-media-remove <?php echo $media_id ? '' : 'style="display:none"'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Hardcoded string ?>><?php esc_html_e('Remove', 'opentrust'); ?></button>
<button type="button" class="button<?php echo esc_attr($media_id ? '' : ' ot-hidden'); ?>" data-ot-media-remove><?php esc_html_e('Remove', 'opentrust'); ?></button>
<p class="description"><?php echo esc_html($description); ?></p>
</div>
<?php
Expand Down Expand Up @@ -597,15 +589,15 @@ public function render_settings_page(): void {

<h2 class="nav-tab-wrapper">
<a href="<?php echo esc_url($base_url); ?>"
class="nav-tab <?php echo $tab === 'general' ? 'nav-tab-active' : ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Hardcoded string ?>">
class="nav-tab <?php echo esc_attr($tab === 'general' ? 'nav-tab-active' : ''); ?>">
<?php esc_html_e('General', 'opentrust'); ?>
</a>
<a href="<?php echo esc_url(add_query_arg('tab', 'contact', $base_url)); ?>"
class="nav-tab <?php echo $tab === 'contact' ? 'nav-tab-active' : ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Hardcoded string ?>">
class="nav-tab <?php echo esc_attr($tab === 'contact' ? 'nav-tab-active' : ''); ?>">
<?php esc_html_e('Contact', 'opentrust'); ?>
</a>
<a href="<?php echo esc_url(add_query_arg('tab', 'ai', $base_url)); ?>"
class="nav-tab <?php echo $tab === 'ai' ? 'nav-tab-active' : ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Hardcoded string ?>">
class="nav-tab <?php echo esc_attr($tab === 'ai' ? 'nav-tab-active' : ''); ?>">
<?php esc_html_e('AI Chat', 'opentrust'); ?>
<?php if (!empty($settings['ai_enabled'])): ?>
<span class="ot-pill ot-pill--live" style="margin-left:6px;padding:2px 8px;background:#dcfce7;color:#166534;border-radius:10px;font-size:11px;font-weight:600;vertical-align:middle">
Expand All @@ -614,7 +606,7 @@ class="nav-tab <?php echo $tab === 'ai' ? 'nav-tab-active' : ''; // phpcs:ignore
<?php endif; ?>
</a>
<a href="<?php echo esc_url(add_query_arg('tab', 'io', $base_url)); ?>"
class="nav-tab <?php echo $tab === 'io' ? 'nav-tab-active' : ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Hardcoded string ?>">
class="nav-tab <?php echo esc_attr($tab === 'io' ? 'nav-tab-active' : ''); ?>">
<?php esc_html_e('Import & Export', 'opentrust'); ?>
</a>
</h2>
Expand Down
13 changes: 7 additions & 6 deletions includes/class-opentrust-chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,16 +493,17 @@ private function run_chat(
// ──────────────────────────────────────────────

public static function send_sse(string $event, mixed $data): void {
$json = wp_json_encode($data);
// JSON_HEX_* flags hex-escape <>&'" so the encoded text carries no
// HTML-active characters — esc_html below is then byte-identical and
// satisfies "escape everything echoed" even though SSE is text/event-stream.
$json = wp_json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT);
if ($json === false) {
$json = '{}';
}
// Event name is an internal token (start|progress|complete|error|…); strip to [A-Za-z0-9_-].
$event = preg_replace('/[^A-Za-z0-9_-]/', '', $event);
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $event sanitized above; $json produced by wp_json_encode().
echo 'event: ' . $event . "\n";
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $json produced by wp_json_encode().
echo 'data: ' . $json . "\n\n";
$event = (string) preg_replace('/[^A-Za-z0-9_-]/', '', $event);
echo esc_html('event: ' . $event) . "\n";
echo esc_html('data: ' . $json) . "\n\n";
if (function_exists('flush')) {
flush();
}
Expand Down
12 changes: 6 additions & 6 deletions includes/class-opentrust-cpt.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,22 +385,22 @@ public function render_cert_meta_box(\WP_Post $post): void {

<div class="ot-meta-field">
<label><?php esc_html_e('Framework Logo', 'opentrust'); ?></label>
<img class="ot-badge-preview" src="<?php echo esc_url($badge_url); ?>" alt="" <?php echo $badge_url ? '' : 'style="display:none"'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Hardcoded string ?>>
<img class="ot-badge-preview<?php echo esc_attr($badge_url ? '' : ' ot-hidden'); ?>" src="<?php echo esc_url($badge_url); ?>" alt="">
<input type="hidden" class="ot-badge-input" name="ot_cert_badge_id" value="<?php echo esc_attr((string) $badge_id); ?>">
<button type="button" class="button ot-upload-badge"><?php esc_html_e('Select Logo', 'opentrust'); ?></button>
<button type="button" class="button ot-remove-badge" <?php echo $badge_id ? '' : 'style="display:none"'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Hardcoded string ?>><?php esc_html_e('Remove', 'opentrust'); ?></button>
<button type="button" class="button ot-remove-badge<?php echo esc_attr($badge_id ? '' : ' ot-hidden'); ?>"><?php esc_html_e('Remove', 'opentrust'); ?></button>
<p class="description"><?php esc_html_e('Use the official framework mark where licensing allows (SOC 2, ISO, GDPR shield). Square images work best at 44×44.', 'opentrust'); ?></p>
</div>

<div class="ot-meta-field" data-ot-cert-artifact>
<label><?php esc_html_e('Proof Artifact', 'opentrust'); ?></label>
<div class="ot-artifact-preview" <?php echo $artifact_id ? '' : 'style="display:none"'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Hardcoded string ?>>
<div class="ot-artifact-preview<?php echo esc_attr($artifact_id ? '' : ' ot-hidden'); ?>">
<span class="ot-artifact-preview__icon" aria-hidden="true">📄</span>
<a class="ot-artifact-preview__link" href="<?php echo esc_url($artifact_url); ?>" target="_blank" rel="noopener"><?php echo esc_html($artifact_name ?: __('View file', 'opentrust')); ?></a>
</div>
<input type="hidden" class="ot-artifact-input" name="ot_cert_artifact_id" value="<?php echo esc_attr((string) $artifact_id); ?>">
<button type="button" class="button ot-upload-artifact"><?php echo $artifact_id ? esc_html__('Replace File', 'opentrust') : esc_html__('Upload File', 'opentrust'); ?></button>
<button type="button" class="button ot-remove-artifact" <?php echo $artifact_id ? '' : 'style="display:none"'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Hardcoded string ?>><?php esc_html_e('Remove', 'opentrust'); ?></button>
<button type="button" class="button ot-remove-artifact<?php echo esc_attr($artifact_id ? '' : ' ot-hidden'); ?>"><?php esc_html_e('Remove', 'opentrust'); ?></button>
<p class="description"><?php esc_html_e('Optional PDF the trust center can link to — e.g. the audit report, certificate, or policy mapping document. Shown as a download button on the card.', 'opentrust'); ?></p>
</div>

Expand Down Expand Up @@ -541,13 +541,13 @@ public function render_policy_meta_box(\WP_Post $post): void {

<div class="ot-meta-field" data-ot-policy-attachment>
<label><?php esc_html_e('PDF Attachment', 'opentrust'); ?></label>
<div class="ot-artifact-preview" <?php echo $attachment_id ? '' : 'style="display:none"'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Hardcoded string ?>>
<div class="ot-artifact-preview<?php echo esc_attr($attachment_id ? '' : ' ot-hidden'); ?>">
<span class="ot-artifact-preview__icon" aria-hidden="true">📄</span>
<a class="ot-artifact-preview__link" href="<?php echo esc_url($attachment_url); ?>" target="_blank" rel="noopener"><?php echo esc_html($attachment_name ?: __('View file', 'opentrust')); ?></a>
</div>
<input type="hidden" class="ot-policy-attachment-input" name="ot_policy_attachment_id" value="<?php echo esc_attr((string) $attachment_id); ?>">
<button type="button" class="button ot-upload-policy-attachment"><?php echo $attachment_id ? esc_html__('Replace PDF', 'opentrust') : esc_html__('Upload PDF', 'opentrust'); ?></button>
<button type="button" class="button ot-remove-policy-attachment" <?php echo $attachment_id ? '' : 'style="display:none"'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Hardcoded string ?>><?php esc_html_e('Remove', 'opentrust'); ?></button>
<button type="button" class="button ot-remove-policy-attachment<?php echo esc_attr($attachment_id ? '' : ' ot-hidden'); ?>"><?php esc_html_e('Remove', 'opentrust'); ?></button>
<p class="description"><?php esc_html_e('Upload the signed PDF. Visitors see a "Download PDF" button only when a file is attached.', 'opentrust'); ?></p>
</div>

Expand Down
13 changes: 6 additions & 7 deletions includes/class-opentrust-render.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,14 @@ private function get_policy_versions(\WP_Post $policy): array {
// ──────────────────────────────────────────────

/**
* Render an "Updated X ago" pill. Returns HTML string.
* Echo an "Updated X ago" pill. Void return so the SVG markup never
* round-trips through wp_kses (which lowercases attribute names and
* would mangle viewBox). Dynamic text is esc_html'd inline.
*/
public static function updated_pill(string $section_key, array $data): string {
public static function updated_pill(string $section_key, array $data): void {
$timestamp = $data['section_updated'][$section_key] ?? '';
if (!$timestamp) {
return '';
return;
}

$diff = time() - (int) $timestamp;
Expand Down Expand Up @@ -467,10 +469,7 @@ public static function updated_pill(string $section_key, array $data): string {
);
}

return '<span class="ot-updated-pill">'
. '<svg width="14" height="14" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd"/></svg>'
. '<span>' . esc_html($text) . '</span>'
. '</span>';
?><span class="ot-updated-pill"><svg width="14" height="14" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd"/></svg><span><?php echo esc_html($text); ?></span></span><?php
}

// ──────────────────────────────────────────────
Expand Down
2 changes: 1 addition & 1 deletion includes/class-opentrust-version.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function render_version_history(\WP_Post $post): void {
printf(
'<p>%s <strong>v%d</strong></p>',
esc_html__('Current version:', 'opentrust'),
intval( $current_version ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Integer cast via %d format specifier and intval()
(int) $current_version
);
echo '<p class="description">' . esc_html__('Version history will appear after the first update.', 'opentrust') . '</p>';
return;
Expand Down
5 changes: 5 additions & 0 deletions includes/class-opentrust.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ public function maybe_upgrade(): void {
self::backfill_model_snapshot();
}

// v3 → v4: no schema change. Bump exists so the unconditional
// invalidate_cache() at the bottom of this method fires on plugin
// update — escape-output rework can change wp_kses_post() output
// for policy content with unsupported HTML.

update_option('opentrust_db_version', OPENTRUST_DB_VERSION, false);
set_transient('opentrust_flush_rewrite', true);
$this->invalidate_cache();
Expand Down
Binary file modified languages/opentrust-nl_NL.mo
Binary file not shown.
Loading
Loading