add campaign tracking plugin

This commit is contained in:
Tony Volpe
2024-09-17 10:50:03 -04:00
parent b7c8882c8c
commit 8dd84d12e6
21 changed files with 1252 additions and 0 deletions

View File

@@ -0,0 +1,350 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
include_once "lib/CptCampaign.php";
if(!class_exists('CampaignController')){
define("kCampaignPath", dirname(__FILE__));
define("kPLUGIN_DIR_URL", plugin_dir_url(__FILE__));
define ("kPLUGIN_DIR_PATH", plugin_dir_path(__FILE__));
class CampaignController {
const kREST_ACTION = "GetWebCampaigns";
const kCOOKIE_ID = "SESScampaignid";
const kCOOKIE_CAMPAIGN_NAME = "SESScampaignname";
const kCOOKIE_ID_FIVE9 = "SESSfive9";
const kCOOKIE_WEB_PROMOTION_TEXT = "SESSpromotion";
const kCOOKIE_PHONE = "SESScampaignphone";
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'));
add_filter('option_assistance_phone', array($this, 'check_campaign_active_ass_phone'));
add_shortcode('phone_number', array($this, 'get_phone_number'));
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 ) ) {
self::$instance = new self();
}
return self::$instance;
}
// Start PHP session
public function start_session() {
if (!session_id()) {
session_start();
}
}
public function plugins_loaded() {
// 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']);
$campaign = get_posts(
array(
"post_type" => CptCampaign::POST_TYPE,
"posts_per_page" => 1,
"meta_key" => CptCampaign::kMETA_CAMPAIGN_ID,
"meta_value" => $utm_campaign
)
);
if (!empty($campaign)) {
$campaign = $campaign[0];
$campaignID = get_post_meta($campaign->ID, CptCampaign::kMETA_CAMPAIGN_ID, true);
$campaignName = get_post_meta($campaign->ID, CptCampaign::kMETA_CAMPAIGN_NAME, true);
$campaignPhone = get_post_meta($campaign->ID, CptCampaign::kMETA_CAMPAIGN_PHONE, true);
$this->setCampaignCookies($campaignID, $campaignName, $campaignPhone);
if (!session_id()) {
session_start();
}
$_SESSION[self::kCOOKIE_ID] = $campaignID;
$_SESSION[self::kCOOKIE_PHONE] = $campaignPhone;
}
}
}
// 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]);
if (!empty($campaign)) {
return $campaign;
}
}
if (!empty($_SESSION[self::kCOOKIE_ID])) {
$campaign = $this->getActiveCampaignPhoneByID($_SESSION[self::kCOOKIE_ID]);
if (!empty($campaign)) {
return $campaign;
}
}
return $phonenumber;
}
public function check_campaign_active_ass_phone($phonenumber) {
if (!empty($_COOKIE[self::kCOOKIE_ID])) {
$campaign = $this->getActiveCampaignPhoneByID($_COOKIE[self::kCOOKIE_ID]);
if (!empty($campaign)) {
return $campaign;
}
}
if (!empty($_SESSION[self::kCOOKIE_ID])) {
$campaign = $this->getActiveCampaignPhoneByID($_SESSION[self::kCOOKIE_ID]);
if (!empty($campaign)) {
return $campaign;
}
}
return $phonenumber;
}
// Retrieve campaign-related information from cookies/sessions
public static function getCampaignID() {
if (!empty($_COOKIE[self::kCOOKIE_ID])) {
return $_COOKIE[self::kCOOKIE_ID];
}
if (!empty($_SESSION[self::kCOOKIE_ID])) {
return $_SESSION[self::kCOOKIE_ID];
}
return null;
}
public static function getCampaignFive9() {
if (!empty($_COOKIE[self::kCOOKIE_ID_FIVE9])) {
return $_COOKIE[self::kCOOKIE_ID_FIVE9];
}
if (!empty($_SESSION[self::kCOOKIE_ID_FIVE9])) {
return $_SESSION[self::kCOOKIE_ID_FIVE9];
}
return null;
}
public static function getCampaignSO() {
if (!empty($_COOKIE[self::KCOOKIE_WEB_TOP_BAR])) {
return $_COOKIE[self::KCOOKIE_WEB_TOP_BAR];
}
if (!empty($_SESSION[self::KCOOKIE_WEB_TOP_BAR])) {
return $_SESSION[self::KCOOKIE_WEB_TOP_BAR];
}
return null;
}
public function get_phone_number() {
$phoneNumber = get_option('cta_tel', true);
return $phoneNumber;
}
public function getActiveCampaignPhoneByID($campaignID = "-1") {
$campaign = get_posts(
array(
"post_type" => CptCampaign::POST_TYPE,
"posts_per_page" => 1,
"meta_key" => CptCampaign::kMETA_CAMPAIGN_ID,
"meta_value" => $campaignID
)
);
if (!empty($campaign)) {
$campaign = $campaign[0];
$campaignStart = get_post_meta($campaign->ID, CptCampaign::kMETA_CAMPAIGN_START_DATE, true);
$campaignEnd = get_post_meta($campaign->ID, CptCampaign::kMETA_CAMPAIGN_END_DATE, true);
$campaignStart .= " 00:00:00";
$campaignEnd .= " 23:59:59";
$campaignStart = strtotime($campaignStart);
$campaignEnd = strtotime($campaignEnd);
$now = time();
if ($now >= $campaignStart && $now <= $campaignEnd) {
$campaignPhone = get_post_meta($campaign->ID, CptCampaign::kMETA_CAMPAIGN_PHONE, true);
return $campaignPhone;
} else {
return false;
}
}
return false;
}
public function setCampaign($id = "", $CampaignName = "", $phone = "", $id_five_9 = "") {
setcookie(self::kCOOKIE_ID, $id, 0, '/');
setcookie(self::kCOOKIE_CAMPAIGN_NAME, $CampaignName, 0, '/');
setcookie(self::kCOOKIE_PHONE, $phone, 0, '/');
setcookie(self::kCOOKIE_ID_FIVE9, $id_five_9, 0, '/');
if (!session_id()) {
session_start();
}
$_SESSION[self::kCOOKIE_ID] = $id;
$_SESSION[self::kCOOKIE_PHONE] = $phone;
$_SESSION[self::kCOOKIE_ID_FIVE9] = $id_five_9;
}
public function activate() {
$cpt = new CptCampaign();
$cpt->rewrite_flush();
}
public function cronJob($data){
if(!empty($data->ResponseBody)){
$existings = get_posts(
array(
"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);
}
}
unset($existings);
foreach ($data->ResponseBody as $single):
$CampaignID = $single->CampaignID;
$StartDate = $single->StartDate;
$PhoneNumber = $single->PhoneNumber;
$LandingURL = $single->LandingURL;
$FriendlyURL = $single->FriendlyURL;
$EndDate = $single->EndDate;
$CampaignName = $single->CampaignName;
$Five9CallbackCampaign = $single->Five9CallbackCampaign;
$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
)
);
if(!empty($post)){
$post = $post[0];
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(
CptCampaign::kMETA_CAMPAIGN_ID => $CampaignID,
CptCampaign::kMETA_CAMPAIGN_START_DATE => $StartDate,
CptCampaign::kMETA_CAMPAIGN_PHONE => $PhoneNumber,
CptCampaign::kMETA_CAMPAIGN_LANDING_URL => $LandingURL,
CptCampaign::kMETA_CAMPAIGN_SHORT_URL => $FriendlyURL,
CptCampaign::kMETA_CAMPAIGN_END_DATE => $EndDate,
CptCampaign::kMETA_CAMPAIGN_NAME => $CampaignName,
CptCampaign::kMETA_FIVE9 => $Five9CallbackCampaign,
)
);
wp_update_post($my_post);
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(
CptCampaign::kMETA_CAMPAIGN_ID => $CampaignID,
CptCampaign::kMETA_CAMPAIGN_START_DATE => $StartDate,
CptCampaign::kMETA_CAMPAIGN_PHONE => $PhoneNumber,
CptCampaign::kMETA_CAMPAIGN_LANDING_URL => $LandingURL,
CptCampaign::kMETA_CAMPAIGN_SHORT_URL => $FriendlyURL,
CptCampaign::kMETA_CAMPAIGN_END_DATE => $EndDate,
CptCampaign::kMETA_CAMPAIGN_NAME => $CampaignName,
CptCampaign::kMETA_FIVE9 => $Five9CallbackCampaign,
)
);
wp_insert_post($my_post);
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
)
);
if(!empty($todelete)){
echo "\n\n*** CAMPAIGN DELETE ***";
foreach ($todelete as $post){
echo "\n".$post->post_title;
wp_trash_post($post->ID);
}
}
unset($todelete);
}
}
// 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) {
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'));
}
}
}
}
// Initialize the controller
if (class_exists('CampaignController')) {
register_activation_hook(__FILE__, array('CampaignController', 'activate'));
CampaignController::instance();
}

View File

@@ -0,0 +1,24 @@
<?php
?>
<br><br><br>
<div>
<h1>Sync Campaigns</h1>
<button id="btSendCronC" class="button button-primary">Sync now</button> <span style="line-height: 28px; margin-left: 15px;" id="cronMSGC"></span><br><br>
<textarea id="campaign_print_debug_cronC" rows="10" style="width: 80%;"></textarea>
</div>
<script type="text/javascript">
jQuery(function(){
jQuery("#btSendCronC").click(function(e){
jQuery("#cronMSGC").html("Waiting, sync in progress...");
jQuery("#btSendCronC").attr("disabled","disabled");
e.preventDefault();
jQuery.get("<?php echo get_bloginfo('wpurl');?>/campaign_cron?t=c",{},function(data){
jQuery("#campaign_print_debug_cronC").val(data).html(data);
jQuery("#btSendCronC").removeAttr("disabled");
jQuery("#cronMSGC").html("");
});
});
});
</script>

View File

@@ -0,0 +1,65 @@
<?php
/*
Plugin Name: Campaign Tracking
Plugin URI: https://www.connectamerica.com
Description: Retrieve campaigns from Salesforce to track conversions
Author: Anthony Volpe
Version: 2.0
Author URI: https://www.connectamerica.com
Email: anthony.volpe@connectamerica.com
*/
if (!defined('ABSPATH')) die("Access denied!");
$sfdc = get_option('select-environment');
if ($sfdc == 'full') {
include_once "encryption/config-full.php";
} else {
include_once "encryption/config.php";
}
include_once('CampaignController.php');
include_once('functions.php');
function campaign_activate(){
}
register_activation_hook(__FILE__,'campaign_activate');
function campaign_deactivate(){
}
register_deactivation_hook(__FILE__,'campaign_deactivate');
function campaign_cron_loaded(){
if ( empty( $GLOBALS['wp']->query_vars['campaign_backend_route'] ) )
return;
include_once(plugin_dir_path(__FILE__).'sync.php');
die();
}
function campaign_cron_init(){
campaign_backend_register_rewrites();
global $wp;
$wp->add_query_var( 'campaign_backend_route' );
}
function campaign_backend_register_rewrites(){
$pre='campaign_cron';
$pre=str_replace("/","",$pre);
add_rewrite_rule( '^' . $pre . '/?$','index.php?campaign_backend_route=/','top' );
add_rewrite_rule( '^' . $pre . '(.*)?','index.php?campaign_backend_route=$matches[1]','top' );
}
add_action( 'template_redirect', 'campaign_cron_loaded', -100 );
add_action( 'init', 'campaign_cron_init' );

View File

@@ -0,0 +1,26 @@
<?php
/** Salesforce Api Url */
define("SALESFORCE_API_URL","https://connectamerica--full.sandbox.my.salesforce-sites.com/RestServices/services/apexrest");
/** Salesforce Brand ID */
define("SALESFORCE_BRAND","MedicalAlert");
/** Encryption key */
define("ENCRYPTION_KEY","potEgc8+5f32y+jpXSz/NqFEPuVWoT95V7aYiyRNjpQ=");
/** Signature */
define("SIGNATURE_KEY","-----BEGIN PRIVATE KEY-----
MIICcgIBADANBgkqhkiG9w0BAQEFAASCAlwwggJYAgEAAoGAwCSPvGdoZsC1Q4btJETb9fnkM/ne
zBA4F4f0bX3JymVZ83H9F1CTykhQWjZ8WiAuPFGHNaUESGtfr0pWF113KrY5ei910WcvcBKd1w6w
JrpUdhWC5bAgoXfLoS0itbX7TvIKrvoXcHbtAPMEDyMNv/Dy/RstNTqUBzF2fLKTwTkCAwEAAQKB
gAZuct0554sLnPBOCOFePgVFaw0OVRXRiSnIeYxcry92Ja+ku3WsqHXB5pFOd5UbX1DSOHYO4vjQ
QfCqdVKXj1CGF+5snE8elE8uuN4Y7OgZ9PBdTJ/V2gevtkYQsjtjteZn3ay3Eic1ItVWSXL4NjZh
4eso3QN+yQsfUhFAOD59AkD1W58VDN8vHWymyJebIGPwKFf6bQpUCeEJVCR5gBvz0wGEQWaLoiyJ
HGSenfpDTo9eiKWvGOnlB11wLvvatqATAkDIeg5jQvj2M6aQRr1k+UETGtjz9BN5vwwpJt+qnVbR
hypoSsBtqBMxTSbWizNzMen1JaOw/Vck8Iei4FoatrsDAkAnSZp5hmweYTnKowgToOYfyHX99YPX
3RUZp02H3wmay0jM4qQG69rxwYgjFezC5ktyubK+DOE2+SzvD7boWKHdAkBup+B1LaxZyRyxGjrE
F0iyEOmbjieJ1cgSluByPjKDqMXhlxEr9c/SMLG1TlRxyyVGKSZ3NP765sEXSBq0EBSdAkCX8h79
z9mezZxyRcdod2Sk4t1hWUf0AnLhkzfAgdQoNwY692uBYXsyKXGufLNkb+RznASmn5Lr6NanIL4c
6S9P
-----END PRIVATE KEY-----");

View File

@@ -0,0 +1,26 @@
<?php
/** Salesforce Api Url */
define("SALESFORCE_API_URL","https://connectamerica.my.salesforce-sites.com/RestServices/services/apexrest/");
/** Salesforce Brand ID */
define("SALESFORCE_BRAND","MedicalAlert");
/** Encryption key */
define("ENCRYPTION_KEY","SDaT8NmuVsEGmqlR813gmk366z9QMe6vCVqVBadqht8=");
/** Signature */
define("SIGNATURE_KEY","-----BEGIN PRIVATE KEY-----
MIICcgIBADANBgkqhkiG9w0BAQEFAASCAlwwggJYAgEAAoGAnXhO2+NRVYLOZM430aUTBSz6soc4
tJfXGaggwn8u55//K2mVkSW+jD3ofHH3YRpyPIzIs9oX1Umyz7TJQJORSBKK/qcHO2trA8yy+v7h
913Y0VPuLfLxnxvaHc1fWSAMj0zKpmR2COZ9BdfxgpIAZOUy7NfAA0Guv8r7cKEMsnkCAwEAAQKB
gAHvrJnj5H2hLfQrsaBYdRs/WivKIYaIRsL61Wr0JmRUYXkBWNn1NVptw8c38ts/oypJxDQAmVds
NbsmasJqWMMdpxia2OaPOvWDmfVp2v7pQC8d1EiqkTjlGPNQ/dJD4ngNemfTg4NL20URJ70s9Nbq
sFaaUUWgvtJKMOs7YilJAkDZsZL2Ecb9vxGpeCXKjVOZf2luavqK8SjNTNXYy52oBhg66WkfgUGU
a4OOaKy0ibx5dPfLFAaFjemLs8O8it11AkC5Lde4vYToBuJyLs8fIKqtf60Km3O7RTMfAFzjU1Hh
KDZilbFa+vsXb02FzBRH4fgmgwpI6aKc9VskDT775Ax1AkBXkCa11ba98DHxgcNpsukSj/5fjKZU
ZuZrleFaf6Rdpn3ujF5dbsdrJMfY61+0isaF8DePtvFcnRV4vQkZeJ3VAkCVp/PwrNHNx0qZJzVj
Hb5yi33o1atZjNp80ok/eyXwRtR1Ji94rN/il6RaXo2BbqFjVoIoXRF7slsfLslZP3vFAkB8FrpQ
XEvLYwhQ7OEwOinMvXK8vb37PAKXMp3pa3uPAK3pQmapmrfWC5LRweHdjeAqArbZmgGWtovRTHVo
s5qc
-----END PRIVATE KEY-----");

View File

@@ -0,0 +1,7 @@
<?php
if(!class_exists("EncryptedContent")){
class EncryptedContent{
public $IV;
public $Data;
}
}

View File

@@ -0,0 +1,7 @@
<?php
if(!class_exists("MessageContentSigned")){
class MessageContentSigned{
public $Content;
public $Signature;
}
}

View File

@@ -0,0 +1,8 @@
<?php
if (!class_exists("MessageContent")){
class MessageContent{
public $Body;
public $Timestamp;
public $Uid;
}
}

View File

@@ -0,0 +1,88 @@
<?php
include_once ('message-content.php');
include_once ('message-content-signed.php');
include_once ('encrypted-content.php');
if(!class_exists("SecuredContent")){
date_default_timezone_set('UTC');
class SecuredContent {
protected $encrption_key;
protected $signature_key;
protected $cipher;
public function __construct() {
/*$this->encrption_key = get_option("encrption_key");
$this->signature_key = get_option("signature_key");*/
$this->encrption_key = ENCRYPTION_KEY;
$this->signature_key = SIGNATURE_KEY;
$this->cipher = 'AES-256-CBC';
}
public function encode_content($raw_content)
{
$message_content = new MessageContent();
$message_content->Body = $raw_content;
$message_content->Timestamp = date('Y-m-d H:i:s', time());
$message_content->Uid = self::guid();
// create signature & pack message
$signed_message = new MessageContentSigned();
$signed_message->Content = json_encode($message_content);
$signed_message->Signature = $this->generate_signature($signed_message->Content);
// create initialization vector & encode data
$iv_size = 16;
$iv = openssl_random_pseudo_bytes($iv_size);
$key = base64_decode($this->encrption_key);
$data = json_encode($signed_message);
$padding = 16 - (strlen($data) % 16);
$data .= str_repeat(chr($padding), $padding);
$cipher_text = openssl_encrypt($data, $this->cipher, $key, OPENSSL_RAW_DATA, $iv);
// store content inside an encrypted container
$encrypted_content = new EncryptedContent();
$encrypted_content->IV = base64_encode($iv);
$encrypted_content->Data = base64_encode($cipher_text);
return $encrypted_content;
}
public function decode_content($encrypted_string)
{
$encrypted_content = json_decode($encrypted_string);
// decode data
$key = base64_decode($this->encrption_key);
$iv = base64_decode($encrypted_content->IV);
$message = openssl_decrypt(base64_decode($encrypted_content->Data), $this->cipher, $key, OPENSSL_RAW_DATA, $iv);
$message = json_decode(substr($message, 0));
$signature = $this->generate_signature($message->Content);
return json_decode($message->Content)->Body;
}
private function generate_signature($message_content)
{
$private_key = openssl_get_privatekey($this->signature_key);
openssl_sign($message_content, $signature, $this->signature_key, 'SHA256');
openssl_free_key($private_key);
return base64_encode($signature);
}
public static function guid()
{
if (function_exists('com_create_guid') === true)
{
return trim(com_create_guid(), '{}');
}
return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
}
}
}

View File

@@ -0,0 +1,161 @@
<?php
// encryption classes
include_once("encryption/message-content.php");
include_once("encryption/message-content-signed.php");
include_once("encryption/encrypted-content.php");
include_once("encryption/secured-content.php");
global $id_setting, $config, $id_version;
$home = get_option("id_medical_home");
$config = array();
$config['id_medical_home'] = $home;
$config['id_version'] = $id_version;
$id_setting = array(
array( 'name' => 'SFDC Environment', 'option_name' => 'select-environment', 'type' => 'select-environment', 'description' => '', 'default' => ''),
//array( 'name' => 'API', 'option_name' => 'id_api_salesforce', 'type' => 'input', 'description' => '', 'default' => ''),
array( 'name' => 'Version', 'option_name' => 'id_version', 'type' => 'input', 'description' => '', 'default' => ''),
array( 'name' => 'API', 'option_name' => 'select-api', 'type' => 'select-api', 'description' => '', 'default' => ''),
array( 'name' => 'Brand ID', 'option_name' => 'id_brand', 'type' => 'select-brand', 'description' => '', 'default' => ''),
array( 'name' => 'Call to Action Tel ', 'option_name' => 'cta_tel', 'type' => 'select-phone', 'description' => 'Telephone', 'default' => '1.800.800.2537')
);
add_action( 'wp_enqueue_scripts', 'load_css' );
function load_css() {
$plugin_url = plugin_dir_url( __FILE__ );
wp_enqueue_style( 'style', $plugin_url . 'style.css' );
}
add_action('admin_menu', 'campaign_menu_page');
function campaign_menu_page() {
$themename = "Campaign Tracking";
$shortname = "campaign_tracking";
$menu_slug="edit_posts";
add_object_page($themename, $themename, $menu_slug, $shortname,'id_main_admin');
}
function id_main_admin(){
$i=0;
global $themename, $shortname,$id_setting;
$themename = "Campaign Tracking";
$save=false;
if ( 'save' == $_POST['action'] ) {
$save=true;
foreach($id_setting as $id_single) {
update_option( sanitize_text_field($id_single['option_name']), sanitize_text_field($_POST[$id_single['option_name']]) );
$i++;
}
}
if ( $save ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' Settings save..</strong></p></div>';
?>
<div id="main_admin">
<?php $admin_header = "<h1>".$themename." </h1>";
echo $admin_header;
?>
<form method="post">
<table>
<?php
$i=0;
foreach($id_setting as $id_single) {?><tr><?php
switch($id_single['type'])
{
case 'input':
{
?>
<td><?=$id_single['name'] ?></td>
<td><input type="text" name="<?=$id_single['option_name'];?>" id="<?=$id_single['option_name'];?>" value="<?php if ( get_option( $id_single['option_name'] ) != "") { echo stripslashes(get_option( $id_single['option_name'] ) ); } ?>" />
<?php if(strpos($id_single['option_name'], 'color')){echo '<div style ="width:20px; height: 20px; margin-top: -25px;margin-left: 170px;position: absolute; background-color:'.get_option($id_single['option_name']).';" class="choosen_color"></div>';}?>
</td>
<td><p class="description"><?=$id_single['description']?></p></td>
<?php
break;
}
case 'select-environment':
{
?>
<td><?=$id_single['name'] ?></td>
<td>
<?php $selectEnv = get_option('select-environment'); ?>
<select name="select-environment">
<option value="full" <?php if($selectEnv=="full") echo 'selected="selected"'; ?>>Full</option>
<option value="production" <?php if($selectEnv=="production") echo 'selected="selected"'; ?>>Production</option>
</select>
</td>
<td><p class="description"><?=$id_single['description']?></p></td>
<?php
break;
}
case 'select-api':
{
?>
<td><?=$id_single['name'] ?></td>
<?php
$sfdcEnv = get_option('select-environment');
if ($sfdcEnv == 'full') {
update_option( 'id_api_salesforce', 'https://connectamerica--full.sandbox.my.salesforce-sites.com/RestServices/services/apexrest/' );
} else {
update_option( 'id_api_salesforce', 'https://connectamerica.my.salesforce-sites.com/RestServices/services/apexrest/' );
}
?>
<td>
<?php echo get_option('id_api_salesforce'); ?>
</td>
<td><p class="description"><?=$id_single['description']?></p></td>
<?php
break;
}
case 'select-phone':
{
update_option('telephone_num', '800-800-2537');
$phoneNumber = get_option('telephone_num',true);
?>
<td><?=$id_single['name']?></td>
<td><?php echo $phoneNumber;?></td>
<?php
break;
}
case 'select-brand':
{
update_option('id_brand', 'Medicalalert');
$brand = get_option('id_brand',true);
?>
<td><?=$id_single['name']?></td>
<td><?php echo $brand;?></td>
<?php
break;
}
}
$i++;?></tr><?php
}
?>
</table>
<div id="inputs">
<input type="submit" value="save options" class="button-primary" />
<input type="hidden" name="action" value="save" />
</form>
</div>
</div>
<?php include_once "admin-cron.php"; ?>
<?php }

View File

@@ -0,0 +1,142 @@
<?php
if(!class_exists('CptCampaign')) {
class CptCampaign
{
//cpt info
const POST_TYPE = "campaign";
const NAME = "Campaign";
const SINGLE_NAME = "Campaign";
const DESCRIPTION = "Post type for Campaign";
const QUERY_VAR = "campaign";
//meta key
const kMETA_CAMPAIGN_ID = "campaign_id";
const kMETA_CAMPAIGN_START_DATE = "campaign_start_date";
const kMETA_CAMPAIGN_END_DATE = "campaign_end_date";
const kMETA_CAMPAIGN_PHONE = "campaign_phone_number";
const kMETA_CAMPAIGN_SHORT_URL = "campaign_short_url";
const kMETA_CAMPAIGN_LANDING_URL = "campaign_landing_url";
const kMETA_CAMPAIGN_NAME = "campaign_name";
const kMETA_DELETE = "to_delete";
const kMETA_FIVE9 = "Five9CallbackCampaign";
//meta array
private $_meta = array(
array('name'=>self::kMETA_CAMPAIGN_ID,'type'=>'input-text','title'=>'Campaign ID'),
array('name'=>self::kMETA_CAMPAIGN_NAME,'type'=>'input-text','title'=>'Campaign name'),
array('name'=>self::kMETA_CAMPAIGN_START_DATE,'type'=>'input-date','title'=>'Start date'),
array('name'=>self::kMETA_CAMPAIGN_END_DATE,'type'=>'input-date','title'=>'End date'),
array('name'=>self::kMETA_CAMPAIGN_PHONE,'type'=>'input-text','title'=>'Phone number'),
array('name'=>self::kMETA_CAMPAIGN_SHORT_URL,'type'=>'input-text','title'=>'Friendly URL'),
array('name'=>self::kMETA_CAMPAIGN_LANDING_URL,'type'=>'input-text','title'=>'Landing URL'),
array('name'=>self::kMETA_FIVE9,'type'=>'input-text','title'=>'Five9 Callback Campaign'),
);
public function __construct(){
add_action('init', array(&$this, 'init'));
add_action('admin_init', array(&$this, 'admin_init'));
//add_action('admin_print_scripts', array(&$this,'load_custom_wp_admin_script') );
add_filter('single_template',array(&$this,'single_template'));
}
public function init(){
$this->create_post_type();
add_action('save_post', array(&$this, 'save_post'));
}
public function admin_init(){
add_action('add_meta_boxes', array(&$this, 'add_meta_boxes'));
}
public function add_meta_boxes(){
add_meta_box(
sprintf('campaign_plugin_%s_section', self::POST_TYPE),
'Info',
array(&$this, 'add_inner_meta_boxes'),
self::POST_TYPE
);
}
public function add_inner_meta_boxes($post){
include(sprintf("%s/templates/%s-metabox.php",kCampaignPath, self::POST_TYPE));
}
public function create_post_type(){
$labels = array(
'name' => __("Campaigns"),
'singular_name' => __("Campaign"),
'menu_name' => __("Campaigns"),
'name_admin_bar' => __("Campaign"),
'add_new_item' => __( 'Add New Campaign'),
'new_item' => __( 'New Campaign'),
'edit_item' => __( 'Edit Campaign' ),
'view_item' => __( 'View Campaign' ),
'all_items' => __( 'All Campaigns' ),
'search_items' => __( 'Search Campaigns'),
'parent_item_colon' => __( 'Parent Campaigns:' ),
'not_found' => __( 'No campaigns found.'),
'not_found_in_trash' => __( 'No campaigns found in Trash.' )
);
register_post_type(self::POST_TYPE,
array(
'labels' =>$labels,
'public' => true,
'has_archive' => false,
'description' => self::DESCRIPTION,
'supports' => array(
'title', 'editor',
),
'hierarchical' => false,
'menu_position'=> 9,
'query_var' => self::QUERY_VAR,
'rewrite' => array( 'slug' => '/'.self::POST_TYPE, 'with_front' => false )
// 'rewrite' => array( 'slug' => self::POST_TYPE )
)
);
}
public function single_template($single_template){
global $post;
$found = locate_template('single-'.self::POST_TYPE.'.php');
if($post->post_type == self::POST_TYPE && $found == ''){
$single_template = kCampaignPath.'/templates/single-'.self::POST_TYPE.'.php';
}
return $single_template;
}
public function rewrite_flush() {
$this->create_post_type();
flush_rewrite_rules();
}
public function save_post($post_id){
if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
if(isset($_POST['post_type']) && $_POST['post_type'] == self::POST_TYPE && current_user_can('edit_post', $post_id))
{
foreach($this->_meta as $field)
{
// Update the post's meta field
if (isset($_POST[$field['name']]))
update_post_meta($post_id, $field['name'], $_POST[$field['name']]);
}
}
}
}
}

View File

@@ -0,0 +1,40 @@
<div class="product-name product-id" data-id="<?php echo $post->ID; ?>"><i class="fa fa-wifi" ></i> <?php echo get_the_title(); ?></div>
<div class="clearfix"></div>
<div id="slider-product">
<div class="" role="listbox">
<div class="item active">
<div class="row no-pad">
<div class="p_img col-md-7">
<?php if(isset($feat_image)&&(!empty($feat_image)))
{
echo '<img src="'.$feat_image.'" alt="slide">';
}?>
</div>
<div class="col-md-5 no-pad" style="padding-left:0;">
<a class="disclaimer" title="Slide name">
<div class="testimonial_"><span><?php echo get_post_meta($post->ID, 'campaign_product_testimonial_description',true); ?></span></div>
<div class="testimonial_name"><span class="testimonial_name_s"><?php echo get_post_meta($post->ID, 'campaign_product_testimonial_name',true); ?></span></div>
</a>
</div>
</div>
</div>
</div>
</div>
<div class="content-product">
<?php $content=$post->post_content; $content=apply_filters('the_content',$content); ?>
<?php echo $content;?>
<div class="clearfix"></div>
</div>

View File

@@ -0,0 +1,50 @@
<?php
function custom_post_type(){
foreach ($posts_type as $type) {
$slug = strtolower($type[0]);
$labels = array(
'name' => _x($type[0], 'Post Type ' . $type[0], 'campaign'),
'singular_name' => _x($type[0], 'Post Type ' . $type[0], 'campaign'),
'menu_name' => __($type[1], 'campaign'),
'parent_item_colon' => __('Parent ' . $type[1], 'campaign'),
'all_items' => __('All ' . $type[1], 'campaign'),
'view_item' => __('View ' . $type[1], 'campaign'),
'add_new_item' => __('Add New ' . $type[0], 'campaign'),
'add_new' => __('Add New', 'campaign'),
'edit_item' => __('Edit ' . $type[0], 'campaign'),
'update_item' => __('Update ' . $type[0], 'campaign'),
'search_items' => __('Search ' . $type[1], 'campaign'),
'not_found' => __('Not Found', 'campaign'),
'not_found_in_trash' => __('Not found in Trash', 'campaign'),
);
$args = array(
'label' => __($type[0], ''),
'description' => __($type[0], ''),
'labels' => $labels,
'supports' => $type[3],
'taxonomies' => array(),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'can_export' => true,
'has_archive' => $type[2],
'rewrite' => array('slug' => $slug),
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type($type[0], $args);
}
}
add_action( 'init', 'custom_post_type', 0 );

View File

@@ -0,0 +1,36 @@
function initMetabox(){
console.log("** initMetabox **");
var dateFormat = "yy-mm-dd",
from = $( "#campaign_start_date" )
.datepicker({
dateFormat: dateFormat
})
.on( "change", function() {
to.datepicker( "option", "minDate", getDate( this ) );
}),
to = $( "#campaign_end_date" ).datepicker({
dateFormat: dateFormat
}).on( "change", function() {
from.datepicker( "option", "maxDate", getDate( this ) );
});
function getDate( element ) {
var date;
try {
date = $.datepicker.parseDate( dateFormat, element.value );
} catch( error ) {
date = null;
}
return date;
}
}
if($ == undefined){
window.$ = jQuery.noConflict();
}
$(function(){
initMetabox();
});

View File

@@ -0,0 +1 @@
function initMetabox(){console.log("** initMetabox **");var a="yy-mm-dd",d=$("#campaign_start_date").datepicker({dateFormat:a}).on("change",function(){c.datepicker("option","minDate",b(this))}),c=$("#campaign_end_date").datepicker({dateFormat:a}).on("change",function(){d.datepicker("option","maxDate",b(this))});function b(g){var f;try{f=$.datepicker.parseDate(a,g.value)}catch(e){f=null}return f}}if($==undefined){window.$=jQuery.noConflict()}$(function(){initMetabox()});

View File

@@ -0,0 +1,97 @@
.s-button-wrapper {
position: fixed;
bottom: 3em;
right: 3em;
text-align: right;
}
.s-button {
opacity: .6;
height: 5em;
width: 5em;
font-size: 14px;
border-radius: 50%;
border: 0 none;
color: #fff;
cursor: pointer;
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.26);
-webkit-transform: scale(1);
transform: scale(1);
-webkit-transition: all 200ms ease;
transition: all 200ms ease;
}
.s-button:hover,
.s-button:focus,
.s-button:active {
box-shadow: 0 8px 17px 0 rgba(0, 0, 0, 0.2);
outline: 0;
}
.s-button span {
display: block;
font-size: 2em;
-webkit-transform: scale(1);
transform: scale(1);
-webkit-transition: -webkit-transform 100ms ease;
transition: -webkit-transform 100ms ease;
transition: transform 100ms ease;
transition: transform 100ms ease, -webkit-transform 100ms ease;
}
.s-button:hover span,
.expanded .s-button span,
.expanded .s-button span {
-webkit-transform: scale(1.25);
transform: scale(1.25);
}
.expanded .s-button {
-webkit-transform: scale(0.7);
transform: scale(0.7);
color: rgba(255, 255, 255, 0.5);
background: #9e9e9e;
}
.s-list {
list-style: none;
padding: 0;
margin: 0;
-webkit-transition: all 200ms ease;
transition: all 200ms ease;
-webkit-transform: translate(0, 90px) scale(0.5);
transform: translate(0, 90px) scale(0.5);
-webkit-transform-origin: bottom center;
transform-origin: bottom center;
opacity: 0;
}
.expanded .s-list {
text-align: left;
font-size: 14px;
-webkit-transform: translate(0px, 20px) scale(1);
transform: translate(0px, 20px) scale(1);
opacity: 1;
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.26);
background-color: #7f5ca3;
padding: 20px !important;
border-radius: 20px;
/* width: 315px;
height: 235px;*/
overflow: hidden;
opacity: 0.8;
}
.s-list li {
color: #F5F5F5;
}
.s-list li:last-child {
margin-bottom: 0;
}
.s-list li:hover {
color: black;
}

View File

@@ -0,0 +1,47 @@
<?php
$log = "";
$crypto = new SecuredContent();
//CAMPAIGN SYNC
echo "\n\n***** CAMPAIGN SYNC *****\n";
$api_uri = get_option("id_api_salesforce");
$api_rest=CampaignController::kREST_ACTION;
$api_param="?Brand=";
$api_brand= get_option("id_brand");
$url = $api_uri .$api_rest . $api_param . $api_brand;
echo "URL: ".$url;
$request_campaign = curl_init($url);
curl_setopt($request_campaign, CURLOPT_CUSTOMREQUEST,'GET');
curl_setopt($request_campaign, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request_campaign, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($request_campaign, CURLOPT_COOKIE, 'debug_logs=debug_logs,domain=.force.com');
$auth_header = json_encode($crypto->encode_content(urldecode($url)));
curl_setopt($request_campaign, CURLOPT_HTTPHEADER, array('CA-Authorization: ' . $auth_header));
$result = curl_exec($request_campaign);
curl_close($request_campaign);
echo $result;
$data = stripslashes($result);
if(!empty($data)){
$data = substr($data,1);
$data = substr($data,0,-1);
$data = (OBJECT)json_decode($crypto->decode_content($data));
if(!empty($data) && !empty($data->ResponseBody)){
echo "\nCampaign Updates:";
$campaignController = CampaignController::instance();
$campaignController->cronJob($data);
}else{
echo "\nNo data";
}
}else{
echo "\n** FAILED **\n";
}
echo "\n\n***** END CAMPAIGN SYNC *****";

View File

@@ -0,0 +1,18 @@
<?php
?>
<p><b>Campaign details info</b></p>
<table>
<?php
foreach($this->_meta as $meta):
$value=get_post_meta($post->ID, $meta['name'], true);
$field=$meta['name'];
$title=$meta['title'];
if($meta['type']=='input-text') :
include(sprintf("%s/metabox/input-text.php", dirname(__FILE__))) ;
elseif($meta['type']=='input-date') :
include(sprintf("%s/metabox/input-date.php", dirname(__FILE__))) ;
endif ;
endforeach;
?>
</table>

View File

@@ -0,0 +1,9 @@
<?php
?>
<tr>
<td><?php echo $title;?></td>
<td>
<input data-datepicker type="date" id="<?php echo $field;?>" name="<?php echo $field;?>" value="<?php echo $value;?>">
</td>
</tr>

View File

@@ -0,0 +1,12 @@
<?php
if (empty($value)){
$value="";
}
?>
<tr>
<td><?php echo $title;?></td>
<td>
<input type="text" id="<?php echo $field;?>" name="<?php echo $field;?>" value="<?php echo $value;?>">
</td>
</tr>

View File

@@ -0,0 +1,38 @@
<?php
session_start();
$now=time();
$campaignTitle = get_the_title();
$campaignID = get_post_meta(get_the_ID(),CptCampaign::kMETA_CAMPAIGN_ID,true);
$campaignName = get_post_meta(get_the_ID(),CptCampaign::kMETA_CAMPAIGN_NAME,true);
$campaignPhone = get_post_meta(get_the_ID(),CptCampaign::kMETA_CAMPAIGN_PHONE,true);
$campaignStart = get_post_meta(get_the_ID(),CptCampaign::kMETA_CAMPAIGN_START_DATE,true);
$campaignEnd = get_post_meta(get_the_ID(),CptCampaign::kMETA_CAMPAIGN_END_DATE,true);
$campaignLink = get_post_meta(get_the_ID(),CptCampaign::kMETA_CAMPAIGN_LANDING_URL,true);
$campaignFive9CallbackCampaign = get_post_meta(get_the_ID(),CptCampaign::kMETA_FIVE9,true);
$campaignStart.=" 00:00:00";
$campaignEnd.=" 23:59:59";
$campaignStart = strtotime($campaignStart);
$campaignEnd = strtotime($campaignEnd);
if($now>=$campaignStart && $now<=$campaignEnd){
//campaign active
$controller = CampaignController::instance();
$controller->setCampaign($campaignID,$campaignName,$campaignPhone,$campaignFive9CallbackCampaign);
}else{
//campaign expired or not yet started
}
function append_query_string($url) {
return add_query_arg($_GET, $url);
}
add_filter('the_permalink', 'append_query_string');
$permalink = append_query_string($url);
$url = (empty($campaignLink)) ? get_home_url() : $campaignLink;
$myurl = get_option('siteurl');