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
<?php
namespace KS_PAC_DCFH\Admin\Managers;
if (!defined('ABSPATH')) {
exit;
}
class EntryMetaManager
{
private static $_instance;
public static function instance(): self
{
if (self::$_instance === null) {
self::$_instance = new self();
}
return self::$_instance;
}
public static function get_post_meta($post_id, $meta_key, $single = true)
{
return get_post_meta($post_id, $meta_key, $single);
}
public static function get_page_id_meta_value($post_id)
{
return self::get_post_meta($post_id, '_pwh_dcfh_page_id');
}
public static function get_contact_form_id_meta_value($post_id)
{
return self::get_post_meta($post_id, '_pwh_dcfh_contact_form_id');
}
public static function get_contact_email_meta_value($post_id)
{
return self::get_post_meta($post_id, '_pwh_dcfh_contact_email');
}
public static function get_read_by_meta_value($post_id)
{
return self::get_post_meta($post_id, '_pwh_dcfh_read_by');
}
public static function get_ip_address_meta_value($post_id)
{
return self::get_post_meta($post_id, '_pwh_dcfh_ip_address');
}
public static function get_user_agent_meta_value($post_id)
{
return self::get_post_meta($post_id, '_pwh_dcfh_user_agent');
}
public static function get_referer_url_meta_value($post_id)
{
return self::get_post_meta($post_id, '_pwh_dcfh_referer_url');
}
public static function get_clones_meta_value($post_id)
{
return self::get_post_meta($post_id, '_pwh_dcfh_clone_log');
}
public static function get_contact_form_fields_meta_value($post_id): array
{
$post_excerpt = get_post_field('post_excerpt', $post_id);
if (empty($post_excerpt) || !is_serialized($post_excerpt)) {
return [];
}
$form_fields = ks_pac_dcfh_app()->misc_utils()::maybe_unserialize($post_excerpt);
if (!is_array($form_fields) || empty($form_fields)) {
return [];
}
return wp_list_pluck($form_fields, 'id');
}
public static function update_cloned_history($post_id, $cloned_post_id): void
{
if (!ks_pac_dcfh_app()->settings_rep()->is_setting_enabled('is_clone_logs_enabled')) {
return;
}
$old_meta = self::get_clones_meta_value($post_id);
if (empty($old_meta)) {
$old_meta = [];
}
$new_meta = [
'post_id' => $cloned_post_id,
'author' => get_current_user_id(),
'date' => current_time('mysql'),
];
$old_meta[] = $new_meta;
update_post_meta($post_id, '_pwh_dcfh_clone_log', $old_meta);
}
public static function is_post_read($post_id): string
{
$post_modified = get_post_field('post_modified', $post_id);
$output = '';
if ($post_modified === '0000-00-00 00:00:00') {
$output .= "<span class='dashicons dashicons-email'></span>";
} else {
$post_read_by = ks_pac_dcfh_app()->user_manager()::get_author_name(
ks_pac_dcfh_app()->entry_meta_manager()::get_read_by_meta_value($post_id)
);
$post_modified = ks_pac_dcfh_app()->misc_utils()::get_formatted_datetime($post_modified);
$output .= sprintf(
'<div><span>%1$s</span><span>%2$s</span></div>',
esc_html__("Read By: $post_read_by", 'divi-contact-form-helper'),
esc_html($post_modified)
);
}
return $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
public static function update_posts_status_to_not_spam($email, $post_status, $post_type = 'pwh_dcfh')
{
global $wpdb;
return $wpdb->query($wpdb->prepare("UPDATE $wpdb->posts AS p JOIN $wpdb->postmeta AS pm ON p.ID = pm.post_id SET p.post_status = %s WHERE pm.meta_key = '_pwh_dcfh_contact_email' AND pm.meta_value = %s AND p.post_type = %s AND p.post_status = 'spam'", $post_status, strtolower($email), $post_type)); // phpcs:ignore WordPress.DB.DirectDatabaseQuery
}
public static function update_posts_status_to_spam($email, $post_type = 'pwh_dcfh')
{
global $wpdb;
return $wpdb->query($wpdb->prepare("UPDATE $wpdb->posts SET post_status = %s WHERE ID IN (SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_pwh_dcfh_contact_email' AND meta_value = %s) AND post_type = %s AND post_status IN (%s, %s)", 'spam', strtolower($email), $post_type, 'private', 'draft')); // phpcs:ignore WordPress.DB.DirectDatabaseQuery
}
public static function is_spam_post($email): bool
{
global $wpdb;
return (bool)$wpdb->get_var($wpdb->prepare("SELECT EXISTS(SELECT 1 FROM $wpdb->posts p INNER JOIN $wpdb->postmeta pm ON p.ID = pm.post_id WHERE pm.meta_key = %s AND pm.meta_value = %s AND p.post_status = 'spam' LIMIT 1)", '_pwh_dcfh_contact_email', $email)); // phpcs:ignore WordPress.DB.DirectDatabaseQuery
}
public static function update_post_status_and_modified_date($post_id, $post_status = 'draft', $post_modified = '0000-00-00 00:00:00', $post_modified_gmt = '0000-00-00 00:00:00'): void
{
global $wpdb;
$wpdb->update($wpdb->posts, ['post_status' => $post_status, 'post_modified' => $post_modified, 'post_modified_gmt' => $post_modified_gmt], ['post_status' => 'pwh_dcfh', 'ID' => $post_id], ['%s', '%s', '%s'], ['%d']); // phpcs:ignore WordPress.DB.DirectDatabaseQuery
}
public static function is_user_ip_exists($contact_form_id, $ip_address): bool
{
global $wpdb;
$result = $wpdb->get_var($wpdb->prepare(" SELECT COUNT(*) AS count FROM $wpdb->postmeta AS pm1 INNER JOIN $wpdb->postmeta AS pm2 ON pm1.post_id = pm2.post_id WHERE (pm1.meta_key = '_pwh_dcfh_contact_form_id' AND pm1.meta_value = %s) AND (pm2.meta_key = '_pwh_dcfh_ip_address' AND pm2.meta_value = %s)", $contact_form_id, $ip_address)); // phpcs:ignore WordPress.DB.DirectDatabaseQuery
return (int)$result > 0;
}
}