Upload folder via GUI - integrations
This commit is contained in:
299
integrations/classes/class-integrations-page-controller.php
Normal file
299
integrations/classes/class-integrations-page-controller.php
Normal file
@@ -0,0 +1,299 @@
|
||||
<?php
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class WMF_Integrations_Page_Controller {
|
||||
|
||||
private static $instance = null;
|
||||
|
||||
public static function instance() {
|
||||
if(is_null(self::$instance)) self::$instance = new self();
|
||||
self::$instance->hook();
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function hook() {
|
||||
add_action('admin_menu', array($this, 'register_menu'));
|
||||
add_action('admin_post_wmf_save_global_settings', array($this, 'save_global_settings'));
|
||||
}
|
||||
|
||||
public function register_menu() {
|
||||
$hook = add_submenu_page(
|
||||
'wp-multi-formular',
|
||||
'Integrationen',
|
||||
'Integrationen',
|
||||
'manage_options',
|
||||
'wmf-integrations',
|
||||
array($this, 'page')
|
||||
);
|
||||
if($hook) {
|
||||
add_action('load-' . $hook, array($this, 'on_load'));
|
||||
}
|
||||
}
|
||||
|
||||
public function on_load() {
|
||||
// Metaboxen direkt hier registrieren (nicht ueber add_meta_boxes Hook)
|
||||
$this->register_metaboxes();
|
||||
wp_enqueue_script('postbox');
|
||||
wp_enqueue_style('wmf-int', WMF_URL . 'integrations/assets/css/admin.css', array(), WMF_VERSION);
|
||||
wp_enqueue_script('wmf-int', WMF_URL . 'integrations/assets/js/dashboard.js', array('jquery'), WMF_VERSION, true);
|
||||
wp_enqueue_style('wmf-admin', WMF_URL . 'assets/css/admin.css', array(), WMF_VERSION);
|
||||
}
|
||||
|
||||
private function register_metaboxes() {
|
||||
$screen = get_current_screen();
|
||||
if(!$screen) return;
|
||||
$sid = $screen->id;
|
||||
$int = wmf_get_integrations();
|
||||
|
||||
// Dienste nach Gruppe
|
||||
$groups = array(
|
||||
'email' => 'normal',
|
||||
'antispam' => 'side',
|
||||
'address' => 'side',
|
||||
'payments' => 'side',
|
||||
'automation' => 'column3',
|
||||
'analytics' => 'column4',
|
||||
);
|
||||
|
||||
foreach($groups as $group => $context) {
|
||||
$services = $int->get_service_group($group);
|
||||
foreach($services as $svc) {
|
||||
$id = 'wmf-int-widget-' . $svc->id;
|
||||
add_meta_box(
|
||||
$id,
|
||||
esc_html($svc->label),
|
||||
array($this, 'metabox_callback'),
|
||||
$sid,
|
||||
$context,
|
||||
'default',
|
||||
array('service' => $svc)
|
||||
);
|
||||
add_filter("postbox_classes_{$sid}_{$id}", function($classes) use($svc) {
|
||||
$classes[] = 'wmf-integrations-widget';
|
||||
$classes[] = 'wmf-integrations-widget-group-' . $svc->group;
|
||||
return $classes;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function metabox_callback($post, $metabox) {
|
||||
$metabox['args']['service']->admin_widget();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
SEITEN-AUSGABE
|
||||
------------------------------------------------------------------ */
|
||||
public function page() {
|
||||
// Test-Mail
|
||||
if(!empty($_GET['wmf_test_mail']) && wp_verify_nonce($_GET['_wpnonce'] ?? '', 'wmf_test_mail')) {
|
||||
$this->handle_test_mail();
|
||||
}
|
||||
$screen = get_current_screen();
|
||||
$sid = $screen ? $screen->id : '';
|
||||
require WMF_INT_DIR . 'templates/admin-integrations.php';
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
GLOBALE E-MAIL-EINSTELLUNGEN (als eigener Abschnitt, nicht als Meta-Box)
|
||||
------------------------------------------------------------------ */
|
||||
public function render_global_email_settings() {
|
||||
$opts = get_option('wmf_global_settings', array());
|
||||
$from_name = $opts['from_name'] ?? get_bloginfo('name');
|
||||
$from_email = $opts['from_email'] ?? get_option('admin_email');
|
||||
$smtp_on = $opts['smtp_enabled'] ?? '0';
|
||||
$smtp_host = $opts['smtp_host'] ?? '';
|
||||
$smtp_port = $opts['smtp_port'] ?? '587';
|
||||
$smtp_enc = $opts['smtp_enc'] ?? 'tls';
|
||||
$smtp_user = $opts['smtp_user'] ?? '';
|
||||
$smtp_pass = $opts['smtp_pass'] ?? '';
|
||||
?>
|
||||
<div class="wmf-global-settings-box">
|
||||
<h2 class="wmf-global-settings-title">
|
||||
<span class="dashicons dashicons-email-alt"></span>
|
||||
Globale E-Mail-Einstellungen
|
||||
</h2>
|
||||
|
||||
<form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>">
|
||||
<?php wp_nonce_field('wmf_global_settings_save', 'wmf_global_nonce'); ?>
|
||||
<input type="hidden" name="action" value="wmf_save_global_settings">
|
||||
|
||||
<div class="wmf-global-settings-grid">
|
||||
|
||||
<!-- Absender -->
|
||||
<div class="wmf-settings-section">
|
||||
<h3>Standard-Absender</h3>
|
||||
<p class="description">Gilt fuer alle Formulare. Im einzelnen Formular kann dies ueberschrieben werden.</p>
|
||||
|
||||
<div class="wmf-setting-row">
|
||||
<label for="wmf_from_name">Absendername</label>
|
||||
<input type="text" id="wmf_from_name" name="wmf_from_name"
|
||||
value="<?php echo esc_attr($from_name); ?>"
|
||||
class="regular-text" placeholder="<?php echo esc_attr(get_bloginfo('name')); ?>">
|
||||
</div>
|
||||
|
||||
<div class="wmf-setting-row">
|
||||
<label for="wmf_from_email">Absender-E-Mail</label>
|
||||
<input type="email" id="wmf_from_email" name="wmf_from_email"
|
||||
value="<?php echo esc_attr($from_email); ?>"
|
||||
class="regular-text" placeholder="noreply@ihredomain.de">
|
||||
<p class="description">
|
||||
Tipp: Nutzen Sie eine Adresse Ihrer Domain um Spam-Filter zu vermeiden.<br>
|
||||
z.B. <code>noreply@viper-network.de</code>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SMTP -->
|
||||
<div class="wmf-settings-section">
|
||||
<h3>SMTP <span style="font-weight:normal;font-size:13px;color:#646970;">(optional)</span></h3>
|
||||
<p class="description">Eigenen Mailserver verwenden statt WordPress-Standard (wp_mail).</p>
|
||||
|
||||
<div class="wmf-setting-row">
|
||||
<label class="wmf-toggle-label">
|
||||
<input type="checkbox" name="wmf_smtp_enabled" value="1" id="wmf_smtp_toggle" <?php checked($smtp_on,'1'); ?>>
|
||||
<span class="wmf-toggle-slider"></span>
|
||||
SMTP aktivieren
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div id="wmf-smtp-fields" style="<?php echo $smtp_on==='1'?'':'display:none;'; ?>">
|
||||
<div class="wmf-setting-row">
|
||||
<label for="wmf_smtp_host">SMTP-Host</label>
|
||||
<input type="text" id="wmf_smtp_host" name="wmf_smtp_host"
|
||||
value="<?php echo esc_attr($smtp_host); ?>"
|
||||
class="regular-text" placeholder="smtp.gmail.com">
|
||||
</div>
|
||||
<div class="wmf-setting-row wmf-setting-row-inline">
|
||||
<div>
|
||||
<label for="wmf_smtp_port">Port</label>
|
||||
<input type="number" id="wmf_smtp_port" name="wmf_smtp_port"
|
||||
value="<?php echo esc_attr($smtp_port); ?>"
|
||||
class="small-text">
|
||||
<span class="description">587=TLS 465=SSL 25=keins</span>
|
||||
</div>
|
||||
<div>
|
||||
<label for="wmf_smtp_enc">Verschluesselung</label>
|
||||
<select id="wmf_smtp_enc" name="wmf_smtp_enc">
|
||||
<option value="tls" <?php selected($smtp_enc,'tls'); ?>>TLS (empfohlen)</option>
|
||||
<option value="ssl" <?php selected($smtp_enc,'ssl'); ?>>SSL</option>
|
||||
<option value="" <?php selected($smtp_enc,''); ?>>Keine</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="wmf-setting-row">
|
||||
<label for="wmf_smtp_user">Benutzername / E-Mail</label>
|
||||
<input type="text" id="wmf_smtp_user" name="wmf_smtp_user"
|
||||
value="<?php echo esc_attr($smtp_user); ?>"
|
||||
class="regular-text" autocomplete="off">
|
||||
</div>
|
||||
<div class="wmf-setting-row">
|
||||
<label for="wmf_smtp_pass">Passwort</label>
|
||||
<input type="password" id="wmf_smtp_pass" name="wmf_smtp_pass"
|
||||
value="<?php echo esc_attr($smtp_pass); ?>"
|
||||
class="regular-text" autocomplete="new-password">
|
||||
<p class="description">Bei Gmail: App-Passwort verwenden (kein normales Konto-Passwort).</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div><!-- .wmf-global-settings-grid -->
|
||||
|
||||
<div class="wmf-global-settings-footer">
|
||||
<button type="submit" class="button button-primary button-large">
|
||||
Einstellungen speichern
|
||||
</button>
|
||||
<?php if(!empty($from_email)): ?>
|
||||
<a href="<?php echo esc_url(wp_nonce_url(
|
||||
add_query_arg(array('wmf_test_mail'=>'1','page'=>'wmf-integrations'), admin_url('admin.php')),
|
||||
'wmf_test_mail'
|
||||
)); ?>" class="button button-secondary button-large">
|
||||
✉ Test-Mail an <?php echo esc_html(get_option('admin_email')); ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<span class="wmf-smtp-status <?php echo ($smtp_on==='1'&&!empty($smtp_host))?'active':''; ?>">
|
||||
<?php echo ($smtp_on==='1'&&!empty($smtp_host)) ? '✓ SMTP aktiv' : 'SMTP nicht aktiv'; ?>
|
||||
</span>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
jQuery(document).ready(function($){
|
||||
$('#wmf_smtp_toggle').on('change', function(){
|
||||
$('#wmf-smtp-fields').toggle(this.checked);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.wmf-global-settings-box{background:#fff;border:1px solid #dcdcde;border-radius:4px;margin-bottom:20px;overflow:hidden;}
|
||||
.wmf-global-settings-title{display:flex;align-items:center;gap:8px;margin:0;padding:14px 20px;background:#f6f7f7;border-bottom:1px solid #dcdcde;font-size:15px;}
|
||||
.wmf-global-settings-title .dashicons{color:#2271b1;font-size:20px;width:20px;height:20px;}
|
||||
.wmf-global-settings-grid{display:grid;grid-template-columns:1fr 1fr;gap:0;border-bottom:1px solid #dcdcde;}
|
||||
.wmf-settings-section{padding:20px 24px;border-right:1px solid #dcdcde;}
|
||||
.wmf-settings-section:last-child{border-right:none;}
|
||||
.wmf-settings-section h3{margin:0 0 4px;font-size:13px;}
|
||||
.wmf-setting-row{margin-bottom:14px;}
|
||||
.wmf-setting-row label{display:block;font-weight:600;font-size:13px;margin-bottom:5px;}
|
||||
.wmf-setting-row .regular-text{width:100%;max-width:360px;box-sizing:border-box;}
|
||||
.wmf-setting-row .description{font-size:12px;color:#646970;margin-top:4px;}
|
||||
.wmf-setting-row-inline{display:flex;gap:20px;flex-wrap:wrap;}
|
||||
.wmf-toggle-label{display:flex!important;align-items:center;gap:10px;cursor:pointer;font-weight:normal!important;}
|
||||
.wmf-global-settings-footer{display:flex;align-items:center;gap:12px;padding:16px 24px;background:#f6f7f7;flex-wrap:wrap;}
|
||||
.wmf-smtp-status{font-size:12px;color:#646970;margin-left:auto;}
|
||||
.wmf-smtp-status.active{color:#46b450;font-weight:600;}
|
||||
@media(max-width:900px){.wmf-global-settings-grid{grid-template-columns:1fr;}.wmf-settings-section{border-right:none;border-bottom:1px solid #dcdcde;}}
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
GLOBALE EINSTELLUNGEN SPEICHERN
|
||||
------------------------------------------------------------------ */
|
||||
public function save_global_settings() {
|
||||
if(!wp_verify_nonce($_POST['wmf_global_nonce'] ?? '', 'wmf_global_settings_save') || !current_user_can('manage_options')) {
|
||||
wp_die('Sicherheitsfehler.');
|
||||
}
|
||||
update_option('wmf_global_settings', array(
|
||||
'from_name' => sanitize_text_field($_POST['wmf_from_name'] ?? ''),
|
||||
'from_email' => sanitize_email( $_POST['wmf_from_email'] ?? ''),
|
||||
'smtp_enabled' => !empty($_POST['wmf_smtp_enabled']) ? '1' : '0',
|
||||
'smtp_host' => sanitize_text_field($_POST['wmf_smtp_host'] ?? ''),
|
||||
'smtp_port' => intval( $_POST['wmf_smtp_port'] ?? 587),
|
||||
'smtp_enc' => sanitize_text_field($_POST['wmf_smtp_enc'] ?? 'tls'),
|
||||
'smtp_user' => sanitize_text_field($_POST['wmf_smtp_user'] ?? ''),
|
||||
'smtp_pass' => $_POST['wmf_smtp_pass'] ?? '',
|
||||
));
|
||||
wmf_safe_redirect(add_query_arg(array('page'=>'wmf-integrations','wmf_notice'=>'global_saved'), admin_url('admin.php')));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
TEST-MAIL
|
||||
------------------------------------------------------------------ */
|
||||
private function handle_test_mail() {
|
||||
$opts = get_option('wmf_global_settings', array());
|
||||
$from_name = $opts['from_name'] ?? get_bloginfo('name');
|
||||
$from_mail = $opts['from_email'] ?? get_option('admin_email');
|
||||
$to = get_option('admin_email');
|
||||
$headers = array('Content-Type: text/html; charset=UTF-8', 'From: '.$from_name.' <'.$from_mail.'>');
|
||||
$body = '<html><body style="font-family:sans-serif;padding:20px;">
|
||||
<h2 style="color:#2271b1;">WP Multi Formular – Test-E-Mail</h2>
|
||||
<p>Diese Test-E-Mail wurde erfolgreich gesendet.</p>
|
||||
<table style="border-collapse:collapse;margin-top:16px;">
|
||||
<tr><td style="padding:6px 12px;background:#f6f7f7;font-weight:600;">Von:</td><td style="padding:6px 12px;">' . esc_html($from_name) . ' <' . esc_html($from_mail) . '></td></tr>
|
||||
<tr><td style="padding:6px 12px;background:#f6f7f7;font-weight:600;">An:</td><td style="padding:6px 12px;">' . esc_html($to) . '</td></tr>
|
||||
<tr><td style="padding:6px 12px;background:#f6f7f7;font-weight:600;">Datum:</td><td style="padding:6px 12px;">' . current_time('d.m.Y H:i') . '</td></tr>
|
||||
</table>
|
||||
</body></html>';
|
||||
$sent = wp_mail($to, 'Test-E-Mail – WP Multi Formular', $body, $headers);
|
||||
$msg = $sent
|
||||
? '<div class="notice notice-success is-dismissible"><p>✓ Test-E-Mail gesendet an <strong>' . esc_html($to) . '</strong>.</p></div>'
|
||||
: '<div class="notice notice-error is-dismissible"><p>✗ Fehler beim Senden. Bitte SMTP-Einstellungen pruefen.</p></div>';
|
||||
add_action('admin_notices', function() use($msg){ echo $msg; });
|
||||
}
|
||||
}
|
||||
|
||||
function wmf_get_integrations_page_controller() {
|
||||
return WMF_Integrations_Page_Controller::instance();
|
||||
}
|
||||
Reference in New Issue
Block a user