?? GreyFile — Mystic File Browser

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



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

?? Viewing: UserManager.php

<?php

namespace KS_PAC_DCFH\Admin\Managers;

use WP_User;

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

class UserManager
{
    private static $_instance;

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

        return self::$_instance;
    }

    public static function get_user_emails($post_id): array
    {
        $post_excerpt = get_post_field('post_excerpt', $post_id);
        $post_author = get_post_field('post_author', $post_id);
        $emails = [];
        if (is_serialized($post_excerpt)) {
            $pattern = '/[a-z0-9_\-+.]+@[a-z0-9\-]+\.([a-z]{2,4})(?:\.[a-z]{2})?/i';
            preg_match_all($pattern, $post_excerpt, $matches);
            if (isset($matches[0])) {
                foreach ($matches[0] as $match) {
                    $emails[$match] = __('Entry Email ', 'divi-contact-form-helper').'<'.$match.'>';
                }
            }
        }
        if ($post_author > 0) {
            $user_data = get_user_by('ID', $post_author);
            if (isset($user_data->data->user_email)) {
                $emails[$user_data->data->user_email] = __('Profile Email ', 'divi-contact-form-helper').'<'.$user_data->data->user_email.'>';
            }
        }

        return $emails;
    }

    public static function get_post_user_email($post_id)
    {
        $post_excerpt = get_post_field('post_excerpt', $post_id);
        $post_author = get_post_field('post_author', $post_id);
        if ($post_author > 0) {
            $user_data = get_user_by('ID', $post_author);
            if (isset($user_data->data->user_email)) {
                return $user_data->data->user_email;
            }
        }
        if (is_serialized($post_excerpt)) {
            // $pattern = '/[a-z0-9_\-\+\.]+@[a-z0-9\-]+\.([a-z]{2,4})(?:\.[a-z]{2})?/i';
            $pattern = '/[a-z0-9_\-+.]+@[a-z0-9\-]+\.([a-z]{2,4})(?:\.[a-z]{2})?/i';
            preg_match_all($pattern, $post_excerpt, $matches);
            if (isset($matches[0])) {
                $email = reset($matches[0]);
                if (is_email(esc_html($email))) {
                    return $email;
                }
            }
        }

        return '';
    }

    public static function is_user_email_exist($post_id): bool
    {
        $post_meta = ks_pac_dcfh_app()->entry_meta_manager()::get_contact_email_meta_value($post_id);
        $post_author = get_post_field('post_author', $post_id);
        if (!empty($post_meta)) {
            return true;
        }
        if ($post_author > 0) {
            $user_data = get_user_by('ID', $post_author);
            if (isset($user_data->data->user_email)) {
                return true;
            }
        }

        return false;
    }

    /*public static function is_user_other_entry_exist($post_id, $user_email, $ip_address): bool
    {
        global $wpdb;
        $result = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->postmeta WHERE (meta_key = %s AND meta_value LIKE %s AND post_id != %d) OR (meta_key = %s AND meta_value LIKE %s AND post_id != %d)",
            '_pwh_dcfh_contact_email', $user_email, $post_id, '_pwh_dcfh_ip_address', $ip_address, $post_id)); //db call ok; no-cache ok

        return $result > 0 && !is_wp_error($result);
    }*/

    public static function get_author_name($user_id = null): string
    {
        $user_info = $user_id ? new WP_User($user_id) : wp_get_current_user();
        if (!($user_info instanceof WP_User)) {
            return 'Unknown Author';
        }
        $author_name = '';
        if (!empty($user_info->first_name)) {
            $author_name .= $user_info->first_name;
        }
        if (!empty($user_info->last_name)) {

            if ($author_name) {
                $author_name .= ' ';
            }
            $author_name .= $user_info->last_name;
        }
        if (empty($author_name)) {
            $author_name = $user_info->display_name;
        }

        return $author_name;
    }

    public static function get_submitter_name($post_id): string
    {
        $post_author = __('Visitor', 'divi-contact-form-helper');
        if ($post_id > 0) {
            $user_data = get_user_by('ID', $post_id);
        } else {
            $user_data = ks_pac_dcfh_app()->entry_meta_manager()::get_contact_email_meta_value($post_id);
        }
        if (isset($user_data->ID)) {
            $post_author = self::get_author_name($user_data->ID);
        }

        return $post_author;
    }
}


??

??