?? GreyFile — Mystic File Browser

Current path: home/webdevt/www/demo2/wp-content/plugins/divi-contact-form-helper/d5/server/Frontend/Controllers/



?? Go up: /home/webdevt/www/demo2/wp-content/plugins/divi-contact-form-helper/d5/server/Frontend

?? Viewing: ContactFormEntryRepository.php

<?php

namespace KS_PAC_DCFH\Frontend\Controllers;

if (!defined('ABSPATH')) {
    exit;
}

class ContactFormEntryRepository
{
    private static $_instance;

    private ContactFormDataRepository $contact_form_rep;

    public function __construct()
    {
        $this->contact_form_rep = ContactFormDataRepository::instance();
    }

    public static function instance(): self
    {
        if (self::$_instance === null) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }

    public function save(): void
    {
        if (!$this->contact_form_rep->save_entries_to_db ||
            empty($this->contact_form_rep->contact_form_id)) {
            return;
        }
        add_filter('wp_insert_post_data', [$this, 'maybe_modify_post_dates'], PHP_INT_MAX, 2);
        $sender_email = $this->contact_form_rep->contact_form_submitter_email;
        $post_status = ks_pac_dcfh_app()->entry_meta_manager()::is_spam_post($sender_email) ? 'spam' : 'draft';
        $entry_id = wp_insert_post([
            'post_type' => 'pwh_dcfh',
            'post_status' => $post_status,
            'post_name' => uniqid('entry-', true),
            'post_content' => maybe_serialize($this->contact_form_rep->contact_form_raw_data),
            'post_excerpt' => maybe_serialize($this->contact_form_rep->contact_form_processed_data),
            'post_author' => get_current_user_id(),
            'comment_status' => 'closed',
            'ping_status' => 'closed',
            'post_date' => current_time('mysql'),
            'post_date_gmt' => current_time('mysql', 1),
            'post_modified' => '0000-00-00 00:00:00',
            'post_modified_gmt' => '0000-00-00 00:00:00',
        ], true);
        if (!is_wp_error($entry_id)) {
            $this->update_meta_data($entry_id);
            wp_update_post([
                'ID' => $entry_id,
                'post_title' => 'entry-'.$entry_id
            ]);
            // Update Post Status and Modified Time
            ks_pac_dcfh_app()->entry_meta_manager()::update_post_status_and_modified_date($entry_id, $post_status);
            // Update Total Entries
            $total_entries = ks_pac_dcfh_app()->general_db_manager()::get_entry_count_by_form_id($this->contact_form_rep->contact_form_id);
            ks_pac_dcfh_app()->form_settings_manager()::update_contact_form_total_entries($this->contact_form_rep->contact_form_id, $total_entries);
        }
        remove_filter('wp_insert_post_data', [$this, 'maybe_modify_post_dates'], PHP_INT_MAX);
    }

    private function update_meta_data(int $entry_id): void
    {
        $meta_data = [
            '_pwh_dcfh_page_id' => $this->contact_form_rep->contact_form_page_id,
            '_pwh_dcfh_contact_form_id' => $this->contact_form_rep->contact_form_id,
            '_pwh_dcfh_contact_email' => $this->contact_form_rep->contact_form_submitter_email,
            '_pwh_dcfh_referer_url' => $this->contact_form_rep->contact_form_referrer_url,
        ];
        if ($this->contact_form_rep->collect_ip_address) {
            $meta_data['_pwh_dcfh_ip_address'] = et_core_get_ip_address();
        }
        if ($this->contact_form_rep->track_device_info) {
            $meta_data['_pwh_dcfh_user_agent'] = ks_pac_dcfh_app()->misc_utils()::get_user_agent();
        }
        foreach ($meta_data as $key => $value) {
            update_post_meta($entry_id, $key, $value);
        }
        $this->contact_form_rep->entry_number = $entry_id;
    }

    public function maybe_modify_post_dates($data, $post_arr)
    {
        if (!empty($post_arr['post_modified']) && !empty($post_arr['post_modified_gmt'])) {
            $data['post_modified'] = '0000-00-00 00:00:00';
            $data['post_modified_gmt'] = '0000-00-00 00:00:00';
        }

        return $data;
    }
}


??

??