first commit all files

This commit is contained in:
dwindown
2026-01-28 00:26:00 +07:00
parent 65dd207a74
commit 97426d5ab1
72 changed files with 91484 additions and 0 deletions

View File

@@ -0,0 +1,315 @@
<?php
/**
* Settings Tab: General
*
* @package WP_Agentic_Writer
* @var string $api_key
* @var float $monthly_budget
* @var float $monthly_used
* @var float $budget_percent
* @var string $budget_status
* @var bool $cost_tracking_enabled
* @var bool $web_search_enabled
* @var string $search_engine
* @var string $search_depth
* @var bool $enable_clarification_quiz
* @var string $clarity_confidence_threshold
* @var array $required_context_categories
* @var int $chat_history_limit
* @var array $preferred_languages
* @var array $custom_languages
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$settings_instance = WP_Agentic_Writer_Settings_V2::get_instance();
$available_languages = $settings_instance->get_available_languages();
?>
<div class="row g-4">
<!-- API Configuration -->
<div class="col-12">
<div class="card border-0 shadow-sm">
<div class="card-header bg-white border-bottom-0 pt-3">
<div class="d-flex align-items-center">
<div>
<h5 class="card-title mb-1 d-flex align-items-center gap-2"><i class="bi bi-key-fill text-warning"></i><?php esc_html_e( 'API Configuration', 'wp-agentic-writer' ); ?></h5>
<p class="text-muted small mb-0"><?php esc_html_e( 'Connect to OpenRouter to access AI models', 'wp-agentic-writer' ); ?></p>
</div>
</div>
</div>
<div class="card-body">
<div class="row align-items-end">
<div class="col-md-8">
<label for="openrouter_api_key" class="form-label fw-semibold">
<?php esc_html_e( 'OpenRouter API Key', 'wp-agentic-writer' ); ?>
<span class="text-danger ms-2">*</span>
</label>
<div class="form-text">
<?php printf( wp_kses_post( __( 'Get your API key from <a href="%s" target="_blank" class="text-decoration-none">OpenRouter <i class="bi bi-box-arrow-up-right"></i></a>', 'wp-agentic-writer' ) ), 'https://openrouter.ai/keys' ); ?>
</div>
<div class="input-group">
<span class="input-group-text"><span class="dashicons dashicons-admin-network"></span></span>
<input type="password" class="form-control" id="openrouter_api_key" name="wp_agentic_writer_settings[openrouter_api_key]" value="<?php echo esc_attr( $api_key ); ?>" placeholder="sk-or-v1-..." />
<button class="btn" type="button" id="wpaw-toggle-api-key" style="border-color:#3a4a5e !important">
<span class="bi bi-eye"></span>
</button>
</div>
</div>
<div class="col-md-4">
<button type="button" class="btn btn-outline-primary w-100" id="wpaw-test-api-key">
<i class="bi bi-check-circle-fill"></i>
<?php esc_html_e( 'Test Connection', 'wp-agentic-writer' ); ?>
</button>
</div>
</div>
</div>
</div>
</div>
<!-- Budget & Cost Tracking -->
<div class="col-12">
<div class="card border-0 shadow-sm">
<div class="card-header bg-white border-bottom-0 pt-3">
<div class="d-flex align-items-center">
<div>
<h5 class="card-title mb-1 d-flex align-items-center gap-2"><i class="bi bi-currency-dollar text-warning"></i><?php esc_html_e( 'Budget & Cost Tracking', 'wp-agentic-writer' ); ?></h5>
<p class="text-muted small mb-0"><?php esc_html_e( 'Monitor and control your API spending', 'wp-agentic-writer' ); ?></p>
</div>
</div>
</div>
<div class="card-body">
<!-- Budget Overview -->
<div class="row mb-4">
<div class="col-md-4">
<div class="p-3 rounded bg-light text-center">
<div class="fs-3 fw-bold text-primary">$<?php echo number_format( $monthly_used, 2 ); ?></div>
<div class="text-muted small"><?php esc_html_e( 'Used This Month', 'wp-agentic-writer' ); ?></div>
</div>
</div>
<div class="col-md-4">
<div class="p-3">
<div class="d-flex justify-content-between mb-1">
<span class="small text-muted"><?php esc_html_e( 'Budget Usage', 'wp-agentic-writer' ); ?></span>
<span class="small fw-semibold"><?php echo number_format( $budget_percent, 1 ); ?>%</span>
</div>
<div class="progress" style="height: 10px;">
<div class="progress-bar bg-<?php echo esc_attr( $budget_status ); ?>" role="progressbar" style="width: <?php echo min( $budget_percent, 100 ); ?>%"></div>
</div>
<div class="small text-muted mt-1">
$<?php echo number_format( $monthly_used, 2 ); ?> / $<?php echo number_format( $monthly_budget, 2 ); ?>
</div>
</div>
</div>
<div class="col-md-4">
<div class="p-3 rounded bg-light text-center">
<div class="fs-3 fw-bold text-success">$<?php echo number_format( max( 0, $monthly_budget - $monthly_used ), 2 ); ?></div>
<div class="text-muted small"><?php esc_html_e( 'Remaining', 'wp-agentic-writer' ); ?></div>
</div>
</div>
</div>
<!-- Budget Input -->
<div class="row g-3">
<div class="col-md-6">
<label for="monthly_budget" class="form-label fw-semibold"><?php esc_html_e( 'Monthly Budget (USD)', 'wp-agentic-writer' ); ?></label>
<div class="input-group">
<span class="input-group-text">$</span>
<input type="number" class="form-control" id="monthly_budget" name="wp_agentic_writer_settings[monthly_budget]" value="<?php echo esc_attr( $monthly_budget ); ?>" min="0" step="0.01" />
</div>
<div class="form-text"><?php esc_html_e( 'Maximum spend per month. Set to 0 for unlimited.', 'wp-agentic-writer' ); ?></div>
</div>
<div class="col-md-6">
<label class="form-label fw-semibold"><?php esc_html_e( 'Cost Tracking', 'wp-agentic-writer' ); ?></label>
<div class="form-check form-switch d-flex align-items-center gap-2">
<input class="form-check-input" type="checkbox" id="cost_tracking_enabled" name="wp_agentic_writer_settings[cost_tracking_enabled]" value="1" <?php checked( $cost_tracking_enabled ); ?> />
<label class="form-check-label" for="cost_tracking_enabled">
<?php esc_html_e( 'Enable cost tracking in editor sidebar', 'wp-agentic-writer' ); ?>
</label>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Research & Web Search -->
<div class="col-12">
<div class="card border-0 shadow-sm">
<div class="card-header bg-white border-bottom-0 pt-3">
<div class="d-flex align-items-center">
<div>
<h5 class="card-title mb-1 d-flex align-items-center gap-2"><i class="bi bi-search text-warning"></i><?php esc_html_e( 'Research & Web Search', 'wp-agentic-writer' ); ?></h5>
<p class="text-muted small mb-0"><?php esc_html_e( 'Configure web search for up-to-date content', 'wp-agentic-writer' ); ?></p>
</div>
</div>
</div>
<div class="card-body">
<div class="row g-3">
<div class="col-12">
<div class="form-check form-switch d-flex align-items-center gap-2">
<input class="form-check-input" type="checkbox" id="web_search_enabled" name="wp_agentic_writer_settings[web_search_enabled]" value="1" <?php checked( $web_search_enabled ); ?> />
<label class="form-check-label" for="web_search_enabled">
<?php esc_html_e( 'Enable Web Search', 'wp-agentic-writer' ); ?>
<span class="badge text-bg-warning ms-2">~$0.02 per search</span>
</label>
</div>
<div class="form-text"><?php esc_html_e( 'Search the web for current information. Can be toggled per-request in sidebar.', 'wp-agentic-writer' ); ?></div>
</div>
<div class="col-md-6">
<label for="search_engine" class="form-label fw-semibold"><?php esc_html_e( 'Search Engine', 'wp-agentic-writer' ); ?></label>
<select class="form-select" id="search_engine" name="wp_agentic_writer_settings[search_engine]">
<option value="auto" <?php selected( $search_engine, 'auto' ); ?>><?php esc_html_e( 'Auto (Native if available, Exa fallback)', 'wp-agentic-writer' ); ?></option>
<option value="native" <?php selected( $search_engine, 'native' ); ?>><?php esc_html_e( 'Native (Provider\'s built-in search)', 'wp-agentic-writer' ); ?></option>
<option value="exa" <?php selected( $search_engine, 'exa' ); ?>><?php esc_html_e( 'Exa (Always use Exa search)', 'wp-agentic-writer' ); ?></option>
</select>
</div>
<div class="col-md-6">
<label for="search_depth" class="form-label fw-semibold"><?php esc_html_e( 'Search Depth', 'wp-agentic-writer' ); ?></label>
<select class="form-select" id="search_depth" name="wp_agentic_writer_settings[search_depth]">
<option value="low" <?php selected( $search_depth, 'low' ); ?>><?php esc_html_e( 'Low (Basic queries)', 'wp-agentic-writer' ); ?></option>
<option value="medium" <?php selected( $search_depth, 'medium' ); ?>><?php esc_html_e( 'Medium (General queries)', 'wp-agentic-writer' ); ?></option>
<option value="high" <?php selected( $search_depth, 'high' ); ?>><?php esc_html_e( 'High (Detailed research)', 'wp-agentic-writer' ); ?></option>
</select>
</div>
</div>
</div>
</div>
</div>
<!-- Clarification Quiz -->
<div class="col-12">
<div class="card border-0 shadow-sm">
<div class="card-header bg-white border-bottom-0 pt-3">
<div class="d-flex align-items-center">
<div>
<h5 class="card-title mb-1 d-flex align-items-center gap-2"><i class="bi bi-question-circle text-warning"></i><?php esc_html_e( 'Clarification Quiz', 'wp-agentic-writer' ); ?></h5>
<p class="text-muted small mb-0"><?php esc_html_e( 'Gather context before writing for better results', 'wp-agentic-writer' ); ?></p>
</div>
</div>
</div>
<div class="card-body">
<div class="row g-3">
<div class="col-12">
<div class="form-check form-switch d-flex align-items-center gap-2">
<input class="form-check-input" type="checkbox" id="enable_clarification_quiz" name="wp_agentic_writer_settings[enable_clarification_quiz]" value="1" <?php checked( $enable_clarification_quiz ); ?> />
<label class="form-check-label" for="enable_clarification_quiz">
<?php esc_html_e( 'Ask clarifying questions when context is missing', 'wp-agentic-writer' ); ?>
</label>
</div>
</div>
<div class="col-md-6">
<label for="clarity_confidence_threshold" class="form-label fw-semibold"><?php esc_html_e( 'Confidence Threshold', 'wp-agentic-writer' ); ?></label>
<select class="form-select" id="clarity_confidence_threshold" name="wp_agentic_writer_settings[clarity_confidence_threshold]">
<option value="0.5" <?php selected( $clarity_confidence_threshold, '0.5' ); ?>><?php esc_html_e( 'Very Sensitive (50%)', 'wp-agentic-writer' ); ?></option>
<option value="0.6" <?php selected( $clarity_confidence_threshold, '0.6' ); ?>><?php esc_html_e( 'Sensitive (60%) - Recommended', 'wp-agentic-writer' ); ?></option>
<option value="0.7" <?php selected( $clarity_confidence_threshold, '0.7' ); ?>><?php esc_html_e( 'Balanced (70%)', 'wp-agentic-writer' ); ?></option>
<option value="0.8" <?php selected( $clarity_confidence_threshold, '0.8' ); ?>><?php esc_html_e( 'Strict (80%)', 'wp-agentic-writer' ); ?></option>
<option value="0.9" <?php selected( $clarity_confidence_threshold, '0.9' ); ?>><?php esc_html_e( 'Very Strict (90%)', 'wp-agentic-writer' ); ?></option>
</select>
<div class="form-text"><?php esc_html_e( 'When to trigger the clarification quiz', 'wp-agentic-writer' ); ?></div>
</div>
<div class="col-md-6">
<label class="form-label fw-semibold"><?php esc_html_e( 'Context Categories', 'wp-agentic-writer' ); ?></label>
<div class="border rounded p-3" style="max-height: 200px; overflow-y: auto;">
<?php
$categories = array(
'target_outcome' => __( 'Target Outcome', 'wp-agentic-writer' ),
'target_audience' => __( 'Target Audience', 'wp-agentic-writer' ),
'tone' => __( 'Tone of Voice', 'wp-agentic-writer' ),
'content_depth' => __( 'Content Depth', 'wp-agentic-writer' ),
'expertise_level' => __( 'Expertise Level', 'wp-agentic-writer' ),
'content_type' => __( 'Content Type', 'wp-agentic-writer' ),
'pov' => __( 'Point of View', 'wp-agentic-writer' ),
);
foreach ( $categories as $value => $label ) :
?>
<div class="form-check d-flex align-items-center gap-2">
<input class="form-check-input" type="checkbox" id="cat_<?php echo esc_attr( $value ); ?>" name="wp_agentic_writer_settings[required_context_categories][]" value="<?php echo esc_attr( $value ); ?>" <?php checked( in_array( $value, $required_context_categories, true ) ); ?> />
<label class="form-check-label" for="cat_<?php echo esc_attr( $value ); ?>"><?php echo esc_html( $label ); ?></label>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Content Settings / Language -->
<div class="col-12">
<div class="card border-0 shadow-sm">
<div class="card-header bg-white border-bottom-0 pt-3">
<div class="d-flex align-items-center">
<div>
<h5 class="card-title mb-1 d-flex align-items-center gap-2"><i class="bi bi-globe text-warning"></i><?php esc_html_e( 'Content Settings', 'wp-agentic-writer' ); ?></h5>
<p class="text-muted small mb-0"><?php esc_html_e( 'Configure language preferences for your content', 'wp-agentic-writer' ); ?></p>
</div>
</div>
</div>
<div class="card-body">
<div class="row g-3">
<div class="col-12">
<label class="form-label fw-semibold"><?php esc_html_e( 'Preferred Languages', 'wp-agentic-writer' ); ?></label>
<div class="row row-cols-2 row-cols-md-4 g-2">
<?php foreach ( $available_languages as $code => $label ) : ?>
<div class="col">
<div class="form-check d-flex align-items-center gap-2">
<input class="form-check-input" type="checkbox" id="lang_<?php echo esc_attr( $code ); ?>" name="wp_agentic_writer_settings[preferred_languages][]" value="<?php echo esc_attr( $code ); ?>" <?php checked( in_array( $code, $preferred_languages, true ) ); ?> />
<label class="form-check-label small" for="lang_<?php echo esc_attr( $code ); ?>"><?php echo esc_html( $label ); ?></label>
</div>
</div>
<?php endforeach; ?>
</div>
<div class="form-text mt-2"><?php esc_html_e( 'Select which languages will appear in the language selector when creating articles.', 'wp-agentic-writer' ); ?></div>
</div>
<div class="col-12">
<label class="form-label fw-semibold"><?php esc_html_e( 'Custom Languages', 'wp-agentic-writer' ); ?></label>
<div id="wpaw-custom-languages-list">
<?php if ( ! empty( $custom_languages ) ) : ?>
<?php foreach ( $custom_languages as $lang ) : ?>
<div class="input-group mb-2 wpaw-custom-language-item">
<input type="text" class="form-control" name="wp_agentic_writer_settings[custom_languages][]" value="<?php echo esc_attr( $lang ); ?>" placeholder="<?php esc_attr_e( 'e.g., Betawi, Minangkabau', 'wp-agentic-writer' ); ?>" />
<button type="button" class="btn btn-outline-danger wpaw-remove-language">
<span class="dashicons dashicons-no-alt"></span>
</button>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
<button type="button" id="wpaw-add-custom-language" class="btn btn-outline-secondary btn-sm">
<span class="dashicons dashicons-plus-alt2 me-1"></span>
<?php esc_html_e( 'Add Custom Language', 'wp-agentic-writer' ); ?>
</button>
<div class="form-text mt-2"><?php esc_html_e( 'Add any language not listed above (e.g., regional dialects, minority languages).', 'wp-agentic-writer' ); ?></div>
</div>
</div>
</div>
</div>
</div>
<!-- Advanced Settings -->
<div class="col-12">
<div class="card border-0 shadow-sm">
<div class="card-header bg-white border-bottom-0 pt-3">
<div class="d-flex align-items-center">
<div>
<h5 class="card-title mb-1 d-flex align-items-center gap-2"><i class="bi bi-gear text-warning"></i><?php esc_html_e( 'Advanced Settings', 'wp-agentic-writer' ); ?></h5>
<p class="text-muted small mb-0"><?php esc_html_e( 'Additional configuration options', 'wp-agentic-writer' ); ?></p>
</div>
</div>
</div>
<div class="card-body">
<div class="row g-3">
<div class="col-md-6">
<label for="chat_history_limit" class="form-label fw-semibold"><?php esc_html_e( 'Chat History Limit', 'wp-agentic-writer' ); ?></label>
<input type="number" class="form-control" id="chat_history_limit" name="wp_agentic_writer_settings[chat_history_limit]" value="<?php echo esc_attr( $chat_history_limit ); ?>" min="0" max="200" style="max-width: 120px;" />
<div class="form-text"><?php esc_html_e( 'Messages stored per post. Set to 0 to disable chat history.', 'wp-agentic-writer' ); ?></div>
</div>
</div>
</div>
</div>
</div>
</div>