define defaults

This commit is contained in:
Tony Volpe
2024-09-17 15:52:13 +00:00
parent 8dd84d12e6
commit 2a354bae60
2 changed files with 64 additions and 114 deletions

View File

@@ -1,18 +1,21 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
if (!defined('ABSPATH')) {
die('-1');
}
include_once "lib/CptCampaign.php";
if(!class_exists('CampaignController')){
if (!class_exists('CampaignController')) {
define("kCampaignPath", dirname(__FILE__));
define("kPLUGIN_DIR_URL", plugin_dir_url(__FILE__));
define ("kPLUGIN_DIR_PATH", plugin_dir_path(__FILE__));
define("kPLUGIN_DIR_PATH", plugin_dir_path(__FILE__));
class CampaignController {
const DEFAULT_PHONE_NUMBER = '800-800-2537';
const DEFAULT_CAMPAIGN_ID = '7011I000000dDwA';
const DEFAULT_FIVE9 = 'Web Form Submissions H';
const kREST_ACTION = "GetWebCampaigns";
const kCOOKIE_ID = "SESScampaignid";
@@ -24,10 +27,8 @@ if(!class_exists('CampaignController')){
protected static $instance;
public function __construct() {
// Start session
add_action('init', array($this, 'start_session'), 1);
// Other hooks
add_action('plugins_loaded', array($this, 'plugins_loaded'));
add_action('admin_enqueue_scripts', array($this, 'load_campaign_script'));
add_filter('option_cta_tel', array($this, 'check_campaign_active_tel'));
@@ -36,23 +37,19 @@ if(!class_exists('CampaignController')){
add_shortcode('campaign_phone', array($this, 'check_campaign_active_tel'));
add_shortcode('campaign_id', array($this, 'getCampaignID'));
add_shortcode('campaign_five9', array($this, 'getCampaignFive9'));
add_shortcode('campaign_special', array($this, 'getCampaignSO'));
// Hook to check UTM campaign
add_action('init', array($this, 'check_utm_campaign'));
// Load the custom post type
$cpt = new CptCampaign();
}
public static function instance() {
if ( ! isset( self::$instance ) ) {
if (!isset(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
// Start PHP session
public function start_session() {
if (!session_id()) {
session_start();
@@ -63,7 +60,6 @@ if(!class_exists('CampaignController')){
// Reserved for future actions
}
// Check for UTM campaign and set cookies/sessions
public function check_utm_campaign() {
if (isset($_GET['utm_campaign'])) {
$utm_campaign = sanitize_text_field($_GET['utm_campaign']);
@@ -93,14 +89,12 @@ if(!class_exists('CampaignController')){
}
}
// Set session cookies
public function setCampaignCookies($id, $CampaignName, $phone) {
setcookie(self::kCOOKIE_ID, $id, 0, '/');
setcookie(self::kCOOKIE_CAMPAIGN_NAME, $CampaignName, 0, '/');
setcookie(self::kCOOKIE_PHONE, $phone, 0, '/');
}
// Functions to check and retrieve active campaign phone
public function check_campaign_active_tel($phonenumber) {
if (!empty($_COOKIE[self::kCOOKIE_ID])) {
$campaign = $this->getActiveCampaignPhoneByID($_COOKIE[self::kCOOKIE_ID]);
@@ -114,7 +108,7 @@ if(!class_exists('CampaignController')){
return $campaign;
}
}
return $phonenumber;
return self::DEFAULT_PHONE_NUMBER;
}
public function check_campaign_active_ass_phone($phonenumber) {
@@ -130,7 +124,7 @@ if(!class_exists('CampaignController')){
return $campaign;
}
}
return $phonenumber;
return self::DEFAULT_PHONE_NUMBER;
}
// Retrieve campaign-related information from cookies/sessions
@@ -141,7 +135,8 @@ if(!class_exists('CampaignController')){
if (!empty($_SESSION[self::kCOOKIE_ID])) {
return $_SESSION[self::kCOOKIE_ID];
}
return null;
// Return the default campaign ID if no campaign ID is available
return self::DEFAULT_CAMPAIGN_ID;
}
public static function getCampaignFive9() {
@@ -151,7 +146,7 @@ if(!class_exists('CampaignController')){
if (!empty($_SESSION[self::kCOOKIE_ID_FIVE9])) {
return $_SESSION[self::kCOOKIE_ID_FIVE9];
}
return null;
return self::DEFAULT_FIVE9;
}
public static function getCampaignSO() {
@@ -217,26 +212,26 @@ if(!class_exists('CampaignController')){
$cpt->rewrite_flush();
}
public function cronJob($data){
public function cronJob($data) {
if(!empty($data->ResponseBody)){
if (!empty($data->ResponseBody)) {
$existings = get_posts(
array(
"post_type"=>CptCampaign::POST_TYPE,
"posts_per_page"=>-1,
"post_status"=>"publish"
"post_type" => CptCampaign::POST_TYPE,
"posts_per_page" => -1,
"post_status" => "publish"
)
);
if(!empty($existings)){
foreach ($existings as $post){
update_post_meta($post->ID,CptCampaign::kMETA_DELETE,true);
if (!empty($existings)) {
foreach ($existings as $post) {
update_post_meta($post->ID, CptCampaign::kMETA_DELETE, true);
}
}
unset($existings);
foreach ($data->ResponseBody as $single):
foreach ($data->ResponseBody as $single) :
$CampaignID = $single->CampaignID;
$StartDate = $single->StartDate;
$PhoneNumber = $single->PhoneNumber;
@@ -245,30 +240,30 @@ if(!class_exists('CampaignController')){
$EndDate = $single->EndDate;
$CampaignName = $single->CampaignName;
$Five9CallbackCampaign = $single->Five9CallbackCampaign;
$postname = str_replace(get_bloginfo('wpurl'),"",$FriendlyURL);
$postname = str_replace(get_bloginfo('wpurl'), "", $FriendlyURL);
$post = get_posts(
array(
"post_type"=>CptCampaign::POST_TYPE,
"posts_per_page"=>-1,
"post_status"=>"publish",
"meta_key"=>CptCampaign::kMETA_CAMPAIGN_ID,
"meta_value"=>$CampaignID
"post_type" => CptCampaign::POST_TYPE,
"posts_per_page" => -1,
"post_status" => "publish",
"meta_key" => CptCampaign::kMETA_CAMPAIGN_ID,
"meta_value" => $CampaignID
)
);
if(!empty($post)){
if (!empty($post)) {
$post = $post[0];
update_post_meta($post->ID,CptCampaign::kMETA_DELETE,false);
update_post_meta($post->ID, CptCampaign::kMETA_DELETE, false);
$my_post = array(
'ID'=> $post->ID,
'post_title' => wp_strip_all_tags( $CampaignName ),
'post_content' => "",
'post_status' => 'publish',
'post_author' => 1,
'post_type' => CptCampaign::POST_TYPE,
'post_name' => $postname,
'meta_input' => array(
'ID' => $post->ID,
'post_title' => wp_strip_all_tags($CampaignName),
'post_content' => "",
'post_status' => 'publish',
'post_author' => 1,
'post_type' => CptCampaign::POST_TYPE,
'post_name' => $postname,
'meta_input' => array(
CptCampaign::kMETA_CAMPAIGN_ID => $CampaignID,
CptCampaign::kMETA_CAMPAIGN_START_DATE => $StartDate,
CptCampaign::kMETA_CAMPAIGN_PHONE => $PhoneNumber,
@@ -282,17 +277,17 @@ if(!class_exists('CampaignController')){
wp_update_post($my_post);
echo "\nUPDATE CAMPAIGN ".$CampaignName;
}else{
echo "\nUPDATE CAMPAIGN " . $CampaignName;
} else {
$my_post = array(
'post_title' => wp_strip_all_tags( $CampaignName ),
'post_content' => "",
'post_status' => 'publish',
'post_author' => 1,
'post_type' => CptCampaign::POST_TYPE,
'post_name' => $postname,
'meta_input' => array(
'post_title' => wp_strip_all_tags($CampaignName),
'post_content' => "",
'post_status' => 'publish',
'post_author' => 1,
'post_type' => CptCampaign::POST_TYPE,
'post_name' => $postname,
'meta_input' => array(
CptCampaign::kMETA_CAMPAIGN_ID => $CampaignID,
CptCampaign::kMETA_CAMPAIGN_START_DATE => $StartDate,
CptCampaign::kMETA_CAMPAIGN_PHONE => $PhoneNumber,
@@ -306,25 +301,25 @@ if(!class_exists('CampaignController')){
wp_insert_post($my_post);
echo "\nCreated Campaign: ".$CampaignName;
echo "\nCreated Campaign: " . $CampaignName;
}
endforeach;
$todelete = get_posts(
array(
"post_type"=>CptCampaign::POST_TYPE,
"posts_per_page"=>-1,
"post_status"=>"publish",
"meta_key"=>CptCampaign::kMETA_DELETE,
"meta_value"=>true
"post_type" => CptCampaign::POST_TYPE,
"posts_per_page" => -1,
"post_status" => "publish",
"meta_key" => CptCampaign::kMETA_DELETE,
"meta_value" => true
)
);
if(!empty($todelete)){
if (!empty($todelete)) {
echo "\n\n*** CAMPAIGN DELETE ***";
foreach ($todelete as $post){
echo "\n".$post->post_title;
foreach ($todelete as $post) {
echo "\n" . $post->post_title;
wp_trash_post($post->ID);
}
}
@@ -332,9 +327,8 @@ if(!class_exists('CampaignController')){
}
}
// Enqueue admin scripts and styles
public function load_campaign_script($hook){
if(('post.php' == $hook || 'post-new.php' == $hook) && get_post_type() == CptCampaign::POST_TYPE) {
public function load_campaign_script($hook) {
if (('post.php' == $hook || 'post-new.php' == $hook) && get_post_type() == CptCampaign::POST_TYPE) {
wp_enqueue_style('jquery-ui');
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_script("campaign.metabox", kPLUGIN_DIR_URL . 'res/js/campaign.metabox.min.js', false, filemtime(kPLUGIN_DIR_PATH . 'res/js/campaign.metabox.min.js'));
@@ -343,8 +337,7 @@ if(!class_exists('CampaignController')){
}
}
// Initialize the controller
if (class_exists('CampaignController')) {
register_activation_hook(__FILE__, array('CampaignController', 'activate'));
CampaignController::instance();
}
}

View File

@@ -19,50 +19,6 @@ function googleapi(){
session_start();
$utm_campaign = $_GET['promotion_id'];
if( have_rows('promotions', 'option') ) {
while( have_rows('promotions', 'option') ): the_row();
$date = date('Y-m-d');
$date = date('Y-m-d', strtotime($date));
$promo_id = get_sub_field('promotion_id');
$promotion_description = get_sub_field('promotion_description');
$promophone_number = get_sub_field('phone_number');
$promocoupon_code = get_sub_field('promocoupon_code');
$start_date = get_sub_field('start_date');
$end_date = get_sub_field('end_date');
$lldefault_descr = "Lifeline.com Default";
$lldefault_phone = "8556815351";
if ($utm_campaign === $promo_id) {
if (($date >= $start_date) && ($date <= $end_date)) :
setcookie('SESSpromoid', $promo_id, 0,'/');
setcookie('SESSpromotion_description', $promotion_description, 0,'/');
setcookie('SESSphone_number', $promophone_number, 0,'/');
setcookie('SESScoupon_code', $promocoupon_code , 0,'/');
//setcookie('SESSstart_date', $start_date , 0,'/');
//setcookie('SESSend_date', $end_date , 0,'/');
$_SESSION['SESSpromoid']=$promo_id;
$_SESSION['SESSpromotion_description']=$promotion_description;
$_SESSION['SESSphone_number']=$promophone_number;
$_SESSION['SESScoupon_code']=$promocoupon_code;
$_SESSION['SESSstart_date']=$start_date;
$_SESSION['SESSend_date']=$end_date;
endif;
}
endwhile;
}
if (!isset($_SESSION["SESSpromoid"])) {
setcookie('SESSpromoid', 'WEB_ORG_0001', 0,'/');
setcookie('SESSpromotion_description', $lldefault_descr, 0,'/');
setcookie('SESSphone_number', $lldefault_phone, 0,'/');
$_SESSION['SESSpromoid']="WEB_ORG_0001";
$_SESSION['SESSpromotion_description']=$lldefault_descr;
$_SESSION['SESSphone_number']=$lldefault_phone;
}
# Imports all Composer packages
require __DIR__ . '/vendor/autoload.php';
@@ -994,6 +950,7 @@ function aarp_form_notfound()
global $aarp_member_notfound;
}
/**
* Function get_phone
*
@@ -1003,15 +960,15 @@ function aarp_form_notfound()
function get_phone()
{
if (isset($_SESSION['SESSphone_number'])) {
$num = $_SESSION["SESSphone_number"];
if (isset($_SESSION['SESScampaignphone'])) {
$num = $_SESSION["SESScampaignphone"];
$ufnum = preg_replace("/[^0-9]/", "", $num);
$fnum = substr($ufnum, 0, 3) . "-" . substr($ufnum, 3, 3) . "-" . substr($ufnum, 6);
return $fnum;
global $fnum;
} else {
$num = get_option('cta_tel', true);
$ufnum = preg_replace("/[^0-9]/", "", $num);