feat: Add Facebook Ads settings management with API integration and UI support
This commit is contained in:
@@ -123,3 +123,7 @@ symbol_info_budget:
|
||||
# Note: the backend is fixed at startup. If a project with a different backend
|
||||
# is activated post-init, an error will be returned.
|
||||
language_backend:
|
||||
|
||||
# list of regex patterns which, when matched, mark a memory entry as read‑only.
|
||||
# Extends the list from the global configuration, merging the two lists.
|
||||
read_only_memory_patterns: []
|
||||
|
||||
4
.vscode/ftp-kr.sync.cache.json
vendored
4
.vscode/ftp-kr.sync.cache.json
vendored
@@ -9,8 +9,8 @@
|
||||
},
|
||||
"api.php": {
|
||||
"type": "-",
|
||||
"size": 4040,
|
||||
"lmtime": 1772671706766,
|
||||
"size": 5529,
|
||||
"lmtime": 1772790264251,
|
||||
"modified": false
|
||||
},
|
||||
"autoload": {
|
||||
|
||||
@@ -4438,7 +4438,8 @@ class Cron
|
||||
{
|
||||
global $settings;
|
||||
|
||||
$token = trim( (string) ( $settings['facebook_ads_token'] ?? '' ) );
|
||||
$token_db = trim( (string) \services\FacebookAdsApi::get_setting( 'facebook_ads_token' ) );
|
||||
$token = $token_db !== '' ? $token_db : trim( (string) ( $settings['facebook_ads_token'] ?? '' ) );
|
||||
$api_version = trim( (string) ( $settings['facebook_ads_api_version'] ?? 'v25.0' ) ) ?: 'v25.0';
|
||||
$requested_client_id = (int) $requested_client_id;
|
||||
$client_id = $requested_client_id;
|
||||
@@ -4461,7 +4462,7 @@ class Cron
|
||||
if ( $token === '' )
|
||||
{
|
||||
return [
|
||||
'result' => 'Brak facebook_ads_token w config.php.',
|
||||
'result' => 'Brak tokenu Facebook Ads. Skonfiguruj go w Ustawieniach.',
|
||||
'success' => false
|
||||
];
|
||||
}
|
||||
|
||||
@@ -160,6 +160,16 @@ class Users
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function settings_save_facebook_ads()
|
||||
{
|
||||
\services\FacebookAdsApi::set_setting( 'facebook_ads_token', \S::get( 'facebook_ads_token' ) );
|
||||
\services\FacebookAdsApi::set_setting( 'facebook_ads_conversion_window_days', (string) max( 1, (int) \S::get( 'facebook_ads_conversion_window_days' ) ) );
|
||||
|
||||
\S::alert( 'Ustawienia Facebook Ads zostały zapisane.' );
|
||||
header( 'Location: /settings' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function settings_save_ai_prompts()
|
||||
{
|
||||
\services\GoogleAdsApi::set_setting( 'ai_prompt_title_template', trim( (string) \S::get( 'ai_prompt_title_template' ) ) );
|
||||
|
||||
@@ -13,8 +13,4 @@ $settings['email_password'] = 'ProjectPro2025!';
|
||||
$settings['cron_products_clients_per_run'] = 1;
|
||||
$settings['cron_campaigns_clients_per_run'] = 1;
|
||||
$settings['cron_products_urls_limit_per_client'] = 100;
|
||||
$settings['google_ads_conversion_window_days'] = 7;
|
||||
|
||||
|
||||
$settings['facebook_ads_token'] = 'EAAVtpObUlr8BQ4sZBbRNOMFTMrSF2PhzOT9vZAFJZAX0xDz5NLlJxECbNmUT5cYLOM0UtH6QhH0OjmkYZAdJgYZBTUZA3tSw2KD9cjsDFMRUB7ReZBVcJBZCbwG8H51sckgfDIWaFRn2Hp2VdddC7hjDP5oY50krI0lUFxwcN08axIr3XUrxpydYZBfvlJl40cwZDZD';
|
||||
$settings['facebook_ads_conversion_window_days'] = 7;
|
||||
$settings['google_ads_conversion_window_days'] = 7;
|
||||
@@ -48,7 +48,8 @@ $route_aliases = [
|
||||
'settings/save_openai' => ['users', 'settings_save_openai'],
|
||||
'settings/save_claude' => ['users', 'settings_save_claude'],
|
||||
'settings/save_gemini' => ['users', 'settings_save_gemini'],
|
||||
'settings/save_ai_prompts' => ['users', 'settings_save_ai_prompts'],
|
||||
'settings/save_ai_prompts' => ['users', 'settings_save_ai_prompts'],
|
||||
'settings/save_facebook_ads' => ['users', 'settings_save_facebook_ads'],
|
||||
'products/ai_suggest' => ['products', 'ai_suggest'],
|
||||
'clients/save' => ['clients', 'save'],
|
||||
'feeds' => ['feeds', 'main_view'],
|
||||
|
||||
@@ -198,6 +198,60 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row" style="margin-top: 25px;">
|
||||
<div class="col-12">
|
||||
<div class="settings-card">
|
||||
<div class="settings-card-header">
|
||||
<div class="settings-card-icon"><i class="fa-brands fa-facebook"></i></div>
|
||||
<div>
|
||||
<h3>Facebook Ads API</h3>
|
||||
<small>Token dostępu i konfiguracja synchronizacji kampanii Facebook Ads</small>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
$fb_last_error = \services\FacebookAdsApi::get_setting( 'facebook_ads_last_error' );
|
||||
$fb_last_error_at_raw = \services\FacebookAdsApi::get_setting( 'facebook_ads_last_error_at' );
|
||||
$fb_last_error_at = '';
|
||||
if ( $fb_last_error_at_raw )
|
||||
{
|
||||
$fb_ts = strtotime( (string) $fb_last_error_at_raw );
|
||||
if ( $fb_ts )
|
||||
{
|
||||
$fb_last_error_at = date( 'Y-m-d H:i:s', $fb_ts );
|
||||
}
|
||||
}
|
||||
if ( $fb_last_error ): ?>
|
||||
<div class="settings-alert-error">
|
||||
<i class="fa-solid fa-triangle-exclamation"></i>
|
||||
<div style="min-width:0;">
|
||||
<div><strong>Ostatni błąd API:</strong></div>
|
||||
<div><strong>Data wystąpienia:</strong> <?= htmlspecialchars( $fb_last_error_at !== '' ? $fb_last_error_at : 'Brak danych' ); ?></div>
|
||||
<div style="margin-top:6px;white-space:pre-wrap;word-break:break-word;"><?= htmlspecialchars( $fb_last_error ); ?></div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<form method="POST" id="facebook-ads-settings" action="/settings/save_facebook_ads">
|
||||
<div class="settings-fields-grid">
|
||||
<div class="settings-field">
|
||||
<label for="facebook_ads_token">Access Token</label>
|
||||
<div class="settings-input-wrap">
|
||||
<input type="password" id="facebook_ads_token" name="facebook_ads_token" class="form-control" value="<?= htmlspecialchars( (string) \services\FacebookAdsApi::get_setting( 'facebook_ads_token' ) ); ?>" placeholder="EAAVtp..." />
|
||||
<button type="button" class="settings-toggle-pw" onclick="password_toggle( this, 'facebook_ads_token' )">
|
||||
<i class="fa-solid fa-eye"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="settings-field">
|
||||
<label for="facebook_ads_conversion_window_days">Okno konwersji (dni)</label>
|
||||
<input type="number" id="facebook_ads_conversion_window_days" name="facebook_ads_conversion_window_days" class="form-control" min="1" max="90" value="<?= (int) ( \services\FacebookAdsApi::get_setting( 'facebook_ads_conversion_window_days' ) ?: 7 ); ?>" />
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" class="btn btn-success" onclick="$( '#facebook-ads-settings' ).submit();"><i class="fa-solid fa-check mr5"></i>Zapisz ustawienia Facebook Ads</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row" style="margin-top: 25px;">
|
||||
<div class="col-12">
|
||||
<div class="settings-card">
|
||||
|
||||
Reference in New Issue
Block a user