commit a2ab138939f7c12e9170a63bd1560fd84e597c2d Author: ruben Date: Thu Dec 26 12:33:40 2024 -0600 Initial commit diff --git a/footer.php b/footer.php new file mode 100644 index 0000000..684321d --- /dev/null +++ b/footer.php @@ -0,0 +1,89 @@ + + + + + + + +
> + +
+ + + + + diff --git a/functions.php b/functions.php new file mode 100644 index 0000000..99d33ad --- /dev/null +++ b/functions.php @@ -0,0 +1,33 @@ +format("Y/m/d h:i:s"); + + // Convert arrays and objects to JSON format + if (is_array($data) || is_object($data)) { + $data = json_encode($data); + $message = $message . " " . $data; + } else if ($data) { + $message = $message . " " . $data; + } + + error_log("[$date] " . $message ."\r\n",3,$log_File); + } +} +*/ diff --git a/page-campaigns.php b/page-campaigns.php new file mode 100644 index 0000000..9593c25 --- /dev/null +++ b/page-campaigns.php @@ -0,0 +1,186 @@ + + +
> +
> + +
> +
+ +
> + + + +
+
+
+ + $value) { + if ($key !== 'per_page' && $key !== 'paged') { + echo ''; + } + } + ?> +
+
+
+ + +
+ + +
> + 'My Campaigns', + 'no_items' => 'You haven\'t added any campaigns yet.', + 'delete_confirm' => 'Are you sure you want to delete this campaign? This action cannot be undone.' + ]); + $list->render(); + + // the_content(); + + // wp_link_pages( + // array( + // 'before' => '', + // ) + // ); + ?> +
+ + +
+
+ +
+
+ + It looks like you haven\'t set up your CloudFlare API info yet. Click here to save that in your profile and get started!'; +} + +$domain_count = count(get_posts([ + 'post_type' => 'domain', + 'posts_per_page' => -1, + 'meta_query' => [['key' => 'owner_id', 'value' => $current_user_id]] +])); + +$campaign_count = count(get_posts([ + 'post_type' => 'campaign', + 'posts_per_page' => -1, + 'meta_query' => [['key' => 'owner_id', 'value' => $current_user_id]] +])); + +$email_count = count(get_posts([ + 'post_type' => 'email-account', + 'posts_per_page' => -1, + 'meta_query' => [['key' => 'owner_id', 'value' => $current_user_id]] +])); + +get_header(); ?> + +
> +
> + + + + + +
+
+ + + +
> +
> + +
> +
+ +
> + + + +
+
+
+ + $value) { + if ($key !== 'per_page' && $key !== 'paged') { + echo ''; + } + } + ?> +
+
+
+ + +
+ + +
> + 'My Domains', + 'no_items' => 'You haven\'t added any domains yet.', + 'delete_confirm' => 'Are you sure you want to delete this domain? This action cannot be undone.' + ]); + $list->render(); + + // the_content(); + + // wp_link_pages( + // array( + // 'before' => '', + // ) + // ); + ?> +
+ + +
+
+ +
+
+ + sanitize_text_field($_POST['campaign_name']), + 'post_type' => 'campaign', + 'post_status' => 'publish' + ); + + if (isset($_POST['post_id']) && !empty($_POST['post_id'])) { + + // log_to_file("Campaign Edit template - Updating campaign"); + $post_data['ID'] = intval($_POST['post_id']); + $post_id = wp_update_post($post_data); + $new_post = false; + $message = ['status' => 'success', 'message' => 'Campaign updated successfully.']; + } else { + // log_to_file("Campaign Edit template - Creating new campaign"); + $post_id = wp_insert_post($post_data); + $message = ['status' => 'success', 'message' => 'Campaign added successfully.']; + } + + if (!is_wp_error($post_id)) { + + // log_to_file("Campaign Edit template - Create/update successful!"); + + $acf_fields = [ + 'domain_id', + 'email_accounts', + // 'num_additional_emails', + 'start_date', + 'warmup_period', + 'starting_volume', + 'target_volume', + 'target_profession', + 'target_profession_other', + 'campaign_conversation_topics' + ]; + + foreach ($acf_fields as $field) { + if (isset($_POST[$field])) { + // log_to_file("Campaign Edit template - Checking for $field in POST: ", $_POST[$field]); + switch ($field) { + case 'email_accounts': + // log_to_file("Campaign Edit template - Found email_accounts in POST", $_POST[$field]); + update_field($field, $_POST[$field], $post_id); + break; + + case 'domain_id': + // log_to_file("Campaign Edit template - Found domain in POST", $_POST['domain_id']); + try { + update_field('domain', $_POST['domain_id'], $post_id); + } catch (Exception $e) { + throw new Exception(__('fetch_dns_records - Campaign Edit template: Unable to update domain field for Campaign', 'rl-mailwarmer') . $e->getMessage()); + } + + break; + + default: + update_field($field, sanitize_text_field($_POST[$field]), $post_id); + break; + } + } + } + + // log_to_file("Campaign Edit template - Setting campaign owner_id to $current_user_id"); + update_post_meta($post_id, 'owner_id', $current_user_id); + + // Run a domain health check + $campaign_timeline = RL_MailWarmer_Campaign_Helper::calculate_campaign_timeline($post_id); + + log_to_file("Campaign Edit template - Campaign timeline: ", $campaign_timeline); + + } else { + $message = ['status' => 'error', 'message' => 'Error: ' . $post_id->get_error_message()]; + } + + if ( !(isset($_POST['stay_on_page']) && ($_POST['stay_on_page'] === 'on')) ) { + // log_to_file("Domain Edit template - stay_on_page not set; redirecting!"); + wp_redirect( get_permalink( $post_id ) ); + exit; + } + +} else { + // log_to_file("Campaign Edit template - Post request not set"); +} + +// Get existing post data if editing +if (isset($_GET['edit'])) { + $post_id = intval($_GET['edit']); + $new_post = false; +} else { + $post_id = 0; +} +$campaign_data = [ + 'campaign_name' => '', + 'domain_id' => '', + 'email_accounts' => [], + 'num_additional_emails' => '', + 'start_date' => '', + 'warmup_period' => '8', + 'starting_volume' => '5', + 'target_volume' => '50', + 'target_profession' => '', + 'target_profession_other' => '', + 'campaign_conversation_topics' => '' +]; + +if ($post_id > 0) { + $post_item = get_post($post_id); + if ($post_item && $post_item->post_type === 'campaign') { + $campaign_data['campaign_name'] = $post_item->post_title; + foreach ($campaign_data as $key => $value) { + if ($key !== 'campaign_name') { + + switch ($key) { + case 'domain_id': + $domain_id = get_field('domain', $post_id); + $campaign_data[$key] = $domain_id->ID; + break; + + case 'email_accounts': + $email_accounts = get_field($key, $post_id); + // log_to_file("Campaign Edit template - Email accounts: ", $email_accounts); + $campaign_data[$key] = $email_accounts; + break; + + case 'start_date': + $start_date = get_field($key, $post_id); + $campaign_data[$key] = date('Y-m-d', strtotime($start_date)); + break; + + default: + $campaign_data[$key] = get_field($key, $post_id); + break; + } + // if ($key === 'domain_id') { + // $domain_id = get_field('domain', $post_id); + // $campaign_data[$key] = $domain_id->ID; + // } else { + // $campaign_data[$key] = get_field($key, $post_id); + // } + + } + } + } +} + +// Get domains for current user +$domains = get_posts([ + 'orderby' => 'title', + 'order' => 'ASC', + 'post_type' => 'domain', + 'posts_per_page' => -1, + 'meta_query' => [ + [ + 'key' => 'owner_id', + 'value' => $current_user_id + ] + ] +]); +// log_to_file("Campaign Edit template - Domains: ", $domains); + +// Get the list of default professions +$professions = rl_get_textarea_meta_as_array('option', 'default_profession_pool'); +// log_to_file("Campaign Edit template - Professions: ", $professions); + +get_header(); ?> + +
> +
> + +
> +
+
> + +
+

+ +
+ +
+ +
+
+

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+
+ +

+ +

+ + + +
+ + +
+ + + +
+
+
+
+
+ +
+
+ + $post_title, + 'post_type' => 'domain', + 'post_status' => 'publish' + ); + + // Check if editing existing post + if (isset($_POST['post_id']) && !empty($_POST['post_id'])) { + $post_data['ID'] = intval($_POST['post_id']); + $post_id = wp_update_post($post_data); + $new_post = false; + $message = ['status' => 'success', 'message' => 'Domain updated successfully.']; + } else { + $post_id = wp_insert_post($post_data); + $message = ['status' => 'success', 'message' => 'Domain added successfully.']; + } + + if (!is_wp_error($post_id)) { + update_post_meta($post_id, 'cloudflare_api_email', $cloudflare_email); + update_post_meta($post_id, 'cloudflare_api_key', $cloudflare_key); + update_post_meta($post_id, 'domain_in_use', $domain_in_use); + if ($new_post) { + // set the owner_id to the creator of the post if this is a new domain + update_post_meta($post_id, 'owner_id', $current_user_id); + + // Run a domain health check + $domain_report_id = RL_MailWarmer_Domain_Helper::save_domain_health_report($post_id); + } + } else { + $message = ['status' => 'error', 'message' => 'Error: ' . $post_id->get_error_message()]; + // $message = 'Error: ' . $post_id->get_error_message(); + } + + if (isset($_POST['update_dns']) && !empty($_POST['update_dns'])) { + log_to_file("Domain Edit template - Running Fix Domain"); + $results = RL_MailWarmer_Domain_Helper::fix_deliverability_dns_issues($post_id); + log_to_file("Domain Edit template - Results: ", $results); + } + + if ( !(isset($_POST['stay_on_page']) && ($_POST['stay_on_page'] === 'on')) ) { + // log_to_file("Domain Edit template - stay_on_page not set; redirecting!"); + wp_redirect( get_permalink( $post_id ) ); + exit; + } +} + +// Get existing post data if editing +if (isset($_GET['edit'])) { + $post_id = intval($_GET['edit']); + $new_post = false; +} else { + $post_id = 0; +} +$domain_name = ''; +$cloudflare_email = ''; +$cloudflare_key = ''; +$domain_in_use = ''; + +if ($post_id > 0) { + $post_item = get_post($post_id); + if ($post_item && $post_item->post_type === 'domain') { + $domain_name = $post_item->post_title; + $cloudflare_email = get_post_meta($post_id, 'cloudflare_api_email', true) ?: ''; + $cloudflare_key = get_post_meta($post_id, 'cloudflare_api_key', true) ?: ''; + $domain_in_use = get_post_meta($post_id, 'domain_in_use', true) ?: ''; + } +} + +get_header(); ?> + +
> +
> + +
> +
+ +
> + +
+

+ +
+ +
+ + +
> +
+

+ +
+ + + + + + +
+ + + + + + + + + + + + + +
+ +
+ + class=""> + Warning! This will attempt to update your DNS records! + +
+ + class=""> + If the domain is already in use we won't change the MX records + +
+
+ +
+

CloudFlare Settings

+

Only if different than the credentials in your profile

+ +
+ +

+ +

+ + + +
+ + +
+ + + +
+
+ '', + // ) + // ); + ?> +
+ + +
+
+ +
+
+ + sanitize_email($_POST['email_address']), + 'post_type' => 'email-account', + 'post_status' => 'publish' + ); + + $meta_fields = [ + 'domain_id', 'mail_password', 'full_name', 'email_signature', + 'email_provider', 'smtp_password', 'smtp_server', 'smtp_port', + 'imap_password', 'imap_server', 'imap_port' + ]; + + if (isset($_POST['post_id']) && !empty($_POST['post_id'])) { + $post_data['ID'] = intval($_POST['post_id']); + $post_id = wp_update_post($post_data); + $new_post = false; + $message = ['status' => 'success', 'message' => 'Email account updated successfully.']; + } else { + $post_id = wp_insert_post($post_data); + $message = ['status' => 'success', 'message' => 'Email account added successfully.']; + } + + if (!is_wp_error($post_id)) { + foreach ($meta_fields as $field) { + if (isset($_POST[$field])) { + update_post_meta($post_id, $field, sanitize_text_field($_POST[$field])); + } + } + // include new accounts in the warmup pool and set the owner_id to the creator of the post + if ($new_post) { + update_post_meta($post_id, 'owner_id', $current_user_id); + update_post_meta($post_id, 'include_in_warmup_pool', $current_user_id); + } + + } else { + $message = ['status' => 'error', 'message' => 'Error: ' . $post_id->get_error_message()]; + } + + if ( !(isset($_POST['stay_on_page']) && ($_POST['stay_on_page'] === 'on')) ) { + // log_to_file("Email Account Edit template - stay_on_page not set; redirecting!"); + wp_redirect( get_permalink( $post_id ) ); + exit; + } +} + +// Get existing post data if editing +if (isset($_GET['edit'])) { + $post_id = intval($_GET['edit']); + $new_post = false; +} else { + $post_id = 0; +} +$email_data = [ + 'email_address' => '', + 'domain_id' => '', + 'mail_password' => '', + 'full_name' => '', + 'email_signature' => '', + 'email_provider' => '', + 'smtp_password' => '', + 'smtp_server' => '', + 'smtp_port' => '', + 'imap_password' => '', + 'imap_server' => '', + 'imap_port' => '' +]; + +if ($post_id > 0) { + $post_item = get_post($post_id); + if ($post_item && $post_item->post_type === 'email-account') { + $email_data['email_address'] = $post_item->post_title; + foreach ($email_data as $key => $value) { + if ($key !== 'email_address') { + $email_data[$key] = get_post_meta($post_id, $key, true); + } + } + } +} + +// Get domains for current user +$domains = get_posts([ + 'orderby' => 'title', + 'order' => 'ASC', + 'post_type' => 'domain', + 'posts_per_page' => -1, + 'meta_query' => [ + [ + 'key' => 'owner_id', + 'value' => $current_user_id + ] + ] +]); + +// Get email providers +$providers = get_posts([ + 'orderby' => 'title', + 'order' => 'ASC', + 'post_type' => 'email-provider', + 'posts_per_page' => -1 +]); + +get_header(); ?> + +
> +
> + +
> +
+
> + +
+

+ +
+ +
+ +
+
+

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ +
+ +
+ +
+ +
+ +
+
+ +
+

Advanced Settings

+ +
+ +

+ +

+ + + +
+ + +
+ + +
+
+
+
+
+ +
+
+ + + + +
> +
> + +
> +
+ +
> + + + +
+
+
+ + $value) { + if ($key !== 'per_page' && $key !== 'paged') { + echo ''; + } + } + ?> +
+
+
+ + +
+ + +
> + 'Email Accounts', + 'no_items' => 'You haven\'t added any email accounts yet.', + 'delete_confirm' => 'Are you sure you want to delete this email-account? This action cannot be undone.' + ]); + $list->render(); + + // the_content(); + + // wp_link_pages( + // array( + // 'before' => '', + // ) + // ); + ?> +
+ + +
+
+ +
+
+ + +
> +
+ +
+
diff --git a/single-campaign.php b/single-campaign.php new file mode 100644 index 0000000..dd3b1c3 --- /dev/null +++ b/single-campaign.php @@ -0,0 +1,149 @@ + + +
> +
> + + +
> +
+ +
> + +
+ + +
> + '', + ) + ); + ?> +
+ + +
+
+ + +
+
+ + + +
> +
> + + +
> +
+ +
> + +
+ + +
> +
+ +
+ + + + + + + + + + + + + +
API EmailAPI KeyZone IDCloudFlare Connection
+
+ +
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ '', + // ) + // ); + ?> +
+ + +
+
+ + +
+
+ + + + +
> +
> + + +
> +
+ +
> + +
+ + +
> + Hi, Bob. + '', + ) + ); + ?> +
+ + +
+
+ + +
+
+ +