define defaults
This commit is contained in:
@@ -1,18 +1,21 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
if (!defined('ABSPATH')) {
|
||||||
die( '-1' );
|
die('-1');
|
||||||
}
|
}
|
||||||
|
|
||||||
include_once "lib/CptCampaign.php";
|
include_once "lib/CptCampaign.php";
|
||||||
|
|
||||||
if(!class_exists('CampaignController')){
|
if (!class_exists('CampaignController')) {
|
||||||
|
|
||||||
define("kCampaignPath", dirname(__FILE__));
|
define("kCampaignPath", dirname(__FILE__));
|
||||||
define("kPLUGIN_DIR_URL", plugin_dir_url(__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 {
|
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 kREST_ACTION = "GetWebCampaigns";
|
||||||
const kCOOKIE_ID = "SESScampaignid";
|
const kCOOKIE_ID = "SESScampaignid";
|
||||||
@@ -24,10 +27,8 @@ if(!class_exists('CampaignController')){
|
|||||||
protected static $instance;
|
protected static $instance;
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
// Start session
|
|
||||||
add_action('init', array($this, 'start_session'), 1);
|
add_action('init', array($this, 'start_session'), 1);
|
||||||
|
|
||||||
// Other hooks
|
|
||||||
add_action('plugins_loaded', array($this, 'plugins_loaded'));
|
add_action('plugins_loaded', array($this, 'plugins_loaded'));
|
||||||
add_action('admin_enqueue_scripts', array($this, 'load_campaign_script'));
|
add_action('admin_enqueue_scripts', array($this, 'load_campaign_script'));
|
||||||
add_filter('option_cta_tel', array($this, 'check_campaign_active_tel'));
|
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_phone', array($this, 'check_campaign_active_tel'));
|
||||||
add_shortcode('campaign_id', array($this, 'getCampaignID'));
|
add_shortcode('campaign_id', array($this, 'getCampaignID'));
|
||||||
add_shortcode('campaign_five9', array($this, 'getCampaignFive9'));
|
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'));
|
add_action('init', array($this, 'check_utm_campaign'));
|
||||||
|
|
||||||
// Load the custom post type
|
|
||||||
$cpt = new CptCampaign();
|
$cpt = new CptCampaign();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function instance() {
|
public static function instance() {
|
||||||
if ( ! isset( self::$instance ) ) {
|
if (!isset(self::$instance)) {
|
||||||
self::$instance = new self();
|
self::$instance = new self();
|
||||||
}
|
}
|
||||||
return self::$instance;
|
return self::$instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start PHP session
|
|
||||||
public function start_session() {
|
public function start_session() {
|
||||||
if (!session_id()) {
|
if (!session_id()) {
|
||||||
session_start();
|
session_start();
|
||||||
@@ -63,7 +60,6 @@ if(!class_exists('CampaignController')){
|
|||||||
// Reserved for future actions
|
// Reserved for future actions
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for UTM campaign and set cookies/sessions
|
|
||||||
public function check_utm_campaign() {
|
public function check_utm_campaign() {
|
||||||
if (isset($_GET['utm_campaign'])) {
|
if (isset($_GET['utm_campaign'])) {
|
||||||
$utm_campaign = sanitize_text_field($_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) {
|
public function setCampaignCookies($id, $CampaignName, $phone) {
|
||||||
setcookie(self::kCOOKIE_ID, $id, 0, '/');
|
setcookie(self::kCOOKIE_ID, $id, 0, '/');
|
||||||
setcookie(self::kCOOKIE_CAMPAIGN_NAME, $CampaignName, 0, '/');
|
setcookie(self::kCOOKIE_CAMPAIGN_NAME, $CampaignName, 0, '/');
|
||||||
setcookie(self::kCOOKIE_PHONE, $phone, 0, '/');
|
setcookie(self::kCOOKIE_PHONE, $phone, 0, '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Functions to check and retrieve active campaign phone
|
|
||||||
public function check_campaign_active_tel($phonenumber) {
|
public function check_campaign_active_tel($phonenumber) {
|
||||||
if (!empty($_COOKIE[self::kCOOKIE_ID])) {
|
if (!empty($_COOKIE[self::kCOOKIE_ID])) {
|
||||||
$campaign = $this->getActiveCampaignPhoneByID($_COOKIE[self::kCOOKIE_ID]);
|
$campaign = $this->getActiveCampaignPhoneByID($_COOKIE[self::kCOOKIE_ID]);
|
||||||
@@ -114,7 +108,7 @@ if(!class_exists('CampaignController')){
|
|||||||
return $campaign;
|
return $campaign;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $phonenumber;
|
return self::DEFAULT_PHONE_NUMBER;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function check_campaign_active_ass_phone($phonenumber) {
|
public function check_campaign_active_ass_phone($phonenumber) {
|
||||||
@@ -130,7 +124,7 @@ if(!class_exists('CampaignController')){
|
|||||||
return $campaign;
|
return $campaign;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $phonenumber;
|
return self::DEFAULT_PHONE_NUMBER;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve campaign-related information from cookies/sessions
|
// Retrieve campaign-related information from cookies/sessions
|
||||||
@@ -141,7 +135,8 @@ if(!class_exists('CampaignController')){
|
|||||||
if (!empty($_SESSION[self::kCOOKIE_ID])) {
|
if (!empty($_SESSION[self::kCOOKIE_ID])) {
|
||||||
return $_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() {
|
public static function getCampaignFive9() {
|
||||||
@@ -151,7 +146,7 @@ if(!class_exists('CampaignController')){
|
|||||||
if (!empty($_SESSION[self::kCOOKIE_ID_FIVE9])) {
|
if (!empty($_SESSION[self::kCOOKIE_ID_FIVE9])) {
|
||||||
return $_SESSION[self::kCOOKIE_ID_FIVE9];
|
return $_SESSION[self::kCOOKIE_ID_FIVE9];
|
||||||
}
|
}
|
||||||
return null;
|
return self::DEFAULT_FIVE9;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getCampaignSO() {
|
public static function getCampaignSO() {
|
||||||
@@ -217,26 +212,26 @@ if(!class_exists('CampaignController')){
|
|||||||
$cpt->rewrite_flush();
|
$cpt->rewrite_flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function cronJob($data){
|
public function cronJob($data) {
|
||||||
|
|
||||||
if(!empty($data->ResponseBody)){
|
if (!empty($data->ResponseBody)) {
|
||||||
|
|
||||||
$existings = get_posts(
|
$existings = get_posts(
|
||||||
array(
|
array(
|
||||||
"post_type"=>CptCampaign::POST_TYPE,
|
"post_type" => CptCampaign::POST_TYPE,
|
||||||
"posts_per_page"=>-1,
|
"posts_per_page" => -1,
|
||||||
"post_status"=>"publish"
|
"post_status" => "publish"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if(!empty($existings)){
|
if (!empty($existings)) {
|
||||||
foreach ($existings as $post){
|
foreach ($existings as $post) {
|
||||||
update_post_meta($post->ID,CptCampaign::kMETA_DELETE,true);
|
update_post_meta($post->ID, CptCampaign::kMETA_DELETE, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unset($existings);
|
unset($existings);
|
||||||
|
|
||||||
foreach ($data->ResponseBody as $single):
|
foreach ($data->ResponseBody as $single) :
|
||||||
$CampaignID = $single->CampaignID;
|
$CampaignID = $single->CampaignID;
|
||||||
$StartDate = $single->StartDate;
|
$StartDate = $single->StartDate;
|
||||||
$PhoneNumber = $single->PhoneNumber;
|
$PhoneNumber = $single->PhoneNumber;
|
||||||
@@ -245,24 +240,24 @@ if(!class_exists('CampaignController')){
|
|||||||
$EndDate = $single->EndDate;
|
$EndDate = $single->EndDate;
|
||||||
$CampaignName = $single->CampaignName;
|
$CampaignName = $single->CampaignName;
|
||||||
$Five9CallbackCampaign = $single->Five9CallbackCampaign;
|
$Five9CallbackCampaign = $single->Five9CallbackCampaign;
|
||||||
$postname = str_replace(get_bloginfo('wpurl'),"",$FriendlyURL);
|
$postname = str_replace(get_bloginfo('wpurl'), "", $FriendlyURL);
|
||||||
|
|
||||||
$post = get_posts(
|
$post = get_posts(
|
||||||
array(
|
array(
|
||||||
"post_type"=>CptCampaign::POST_TYPE,
|
"post_type" => CptCampaign::POST_TYPE,
|
||||||
"posts_per_page"=>-1,
|
"posts_per_page" => -1,
|
||||||
"post_status"=>"publish",
|
"post_status" => "publish",
|
||||||
"meta_key"=>CptCampaign::kMETA_CAMPAIGN_ID,
|
"meta_key" => CptCampaign::kMETA_CAMPAIGN_ID,
|
||||||
"meta_value"=>$CampaignID
|
"meta_value" => $CampaignID
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if(!empty($post)){
|
if (!empty($post)) {
|
||||||
$post = $post[0];
|
$post = $post[0];
|
||||||
update_post_meta($post->ID,CptCampaign::kMETA_DELETE,false);
|
update_post_meta($post->ID, CptCampaign::kMETA_DELETE, false);
|
||||||
$my_post = array(
|
$my_post = array(
|
||||||
'ID'=> $post->ID,
|
'ID' => $post->ID,
|
||||||
'post_title' => wp_strip_all_tags( $CampaignName ),
|
'post_title' => wp_strip_all_tags($CampaignName),
|
||||||
'post_content' => "",
|
'post_content' => "",
|
||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
'post_author' => 1,
|
'post_author' => 1,
|
||||||
@@ -282,11 +277,11 @@ if(!class_exists('CampaignController')){
|
|||||||
|
|
||||||
wp_update_post($my_post);
|
wp_update_post($my_post);
|
||||||
|
|
||||||
echo "\nUPDATE CAMPAIGN ".$CampaignName;
|
echo "\nUPDATE CAMPAIGN " . $CampaignName;
|
||||||
}else{
|
} else {
|
||||||
|
|
||||||
$my_post = array(
|
$my_post = array(
|
||||||
'post_title' => wp_strip_all_tags( $CampaignName ),
|
'post_title' => wp_strip_all_tags($CampaignName),
|
||||||
'post_content' => "",
|
'post_content' => "",
|
||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
'post_author' => 1,
|
'post_author' => 1,
|
||||||
@@ -306,25 +301,25 @@ if(!class_exists('CampaignController')){
|
|||||||
|
|
||||||
wp_insert_post($my_post);
|
wp_insert_post($my_post);
|
||||||
|
|
||||||
echo "\nCreated Campaign: ".$CampaignName;
|
echo "\nCreated Campaign: " . $CampaignName;
|
||||||
}
|
}
|
||||||
|
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
$todelete = get_posts(
|
$todelete = get_posts(
|
||||||
array(
|
array(
|
||||||
"post_type"=>CptCampaign::POST_TYPE,
|
"post_type" => CptCampaign::POST_TYPE,
|
||||||
"posts_per_page"=>-1,
|
"posts_per_page" => -1,
|
||||||
"post_status"=>"publish",
|
"post_status" => "publish",
|
||||||
"meta_key"=>CptCampaign::kMETA_DELETE,
|
"meta_key" => CptCampaign::kMETA_DELETE,
|
||||||
"meta_value"=>true
|
"meta_value" => true
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if(!empty($todelete)){
|
if (!empty($todelete)) {
|
||||||
echo "\n\n*** CAMPAIGN DELETE ***";
|
echo "\n\n*** CAMPAIGN DELETE ***";
|
||||||
foreach ($todelete as $post){
|
foreach ($todelete as $post) {
|
||||||
echo "\n".$post->post_title;
|
echo "\n" . $post->post_title;
|
||||||
wp_trash_post($post->ID);
|
wp_trash_post($post->ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -332,9 +327,8 @@ if(!class_exists('CampaignController')){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enqueue admin scripts and styles
|
public function load_campaign_script($hook) {
|
||||||
public function load_campaign_script($hook){
|
if (('post.php' == $hook || 'post-new.php' == $hook) && get_post_type() == CptCampaign::POST_TYPE) {
|
||||||
if(('post.php' == $hook || 'post-new.php' == $hook) && get_post_type() == CptCampaign::POST_TYPE) {
|
|
||||||
wp_enqueue_style('jquery-ui');
|
wp_enqueue_style('jquery-ui');
|
||||||
wp_enqueue_script('jquery-ui-datepicker');
|
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'));
|
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,7 +337,6 @@ if(!class_exists('CampaignController')){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the controller
|
|
||||||
if (class_exists('CampaignController')) {
|
if (class_exists('CampaignController')) {
|
||||||
register_activation_hook(__FILE__, array('CampaignController', 'activate'));
|
register_activation_hook(__FILE__, array('CampaignController', 'activate'));
|
||||||
CampaignController::instance();
|
CampaignController::instance();
|
||||||
|
|||||||
@@ -19,50 +19,6 @@ function googleapi(){
|
|||||||
|
|
||||||
|
|
||||||
session_start();
|
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
|
# Imports all Composer packages
|
||||||
require __DIR__ . '/vendor/autoload.php';
|
require __DIR__ . '/vendor/autoload.php';
|
||||||
@@ -994,6 +950,7 @@ function aarp_form_notfound()
|
|||||||
global $aarp_member_notfound;
|
global $aarp_member_notfound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function get_phone
|
* Function get_phone
|
||||||
*
|
*
|
||||||
@@ -1003,8 +960,8 @@ function aarp_form_notfound()
|
|||||||
function get_phone()
|
function get_phone()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (isset($_SESSION['SESSphone_number'])) {
|
if (isset($_SESSION['SESScampaignphone'])) {
|
||||||
$num = $_SESSION["SESSphone_number"];
|
$num = $_SESSION["SESScampaignphone"];
|
||||||
|
|
||||||
$ufnum = preg_replace("/[^0-9]/", "", $num);
|
$ufnum = preg_replace("/[^0-9]/", "", $num);
|
||||||
$fnum = substr($ufnum, 0, 3) . "-" . substr($ufnum, 3, 3) . "-" . substr($ufnum, 6);
|
$fnum = substr($ufnum, 0, 3) . "-" . substr($ufnum, 3, 3) . "-" . substr($ufnum, 6);
|
||||||
|
|||||||
Reference in New Issue
Block a user