email subscription ready for testing
This commit is contained in:
parent
c86213dcc9
commit
6a8d44548f
|
|
@ -31,12 +31,12 @@ $target_open = $target_civicrm . '/sites/all/modules/civicrm/extern/open.ph
|
|||
$target_file = $target_civicrm . '/sites/default/files/civicrm/persist/';
|
||||
$target_mail_view = $target_civicrm . '/civicrm/mailing/view';
|
||||
|
||||
// target_mail_base CANNOT be "$target_civicrm . '/civicrm/mailing'",
|
||||
// since these pages cannot be easily proxied.
|
||||
$target_mail_base = NULL;
|
||||
// Set api-key for mail subscribe/unsubscribe user
|
||||
// Set to NULL/FALSE to disable the feature
|
||||
$mail_subscription_user_key = NULL;
|
||||
|
||||
// CAREFUL: only enable temporarily on debug systems. Will log all queries to given PUBLIC file
|
||||
$debug = NULL; //'debug.log';
|
||||
$debug = NULL; //'debug.log';
|
||||
|
||||
|
||||
/****************************************************************
|
||||
|
|
|
|||
|
|
@ -7,11 +7,10 @@
|
|||
| http://www.systopia.de/ |
|
||||
+---------------------------------------------------------*/
|
||||
|
||||
require_once "../config.php";
|
||||
require_once "../proxy.php";
|
||||
|
||||
// see if mail open tracking is enabled
|
||||
if (!$target_mail_base) civiproxy_http_error("Feature disabled", 405);
|
||||
if (!$mail_subscription_user_key) civiproxy_http_error("Feature disabled", 405);
|
||||
|
||||
// basic check
|
||||
civiproxy_security_check('mail-confirm');
|
||||
|
|
@ -27,4 +26,65 @@ if (empty($parameters['sid'])) civiproxy_http_error("Missing/invalid parameter '
|
|||
if (empty($parameters['cid'])) civiproxy_http_error("Missing/invalid parameter 'cid'.");
|
||||
if (empty($parameters['h'])) civiproxy_http_error("Missing/invalid parameter 'h'.");
|
||||
|
||||
civiproxy_redirect($target_mail_base . '/confirm', $parameters);
|
||||
// PERFORM UNSUBSCRIBE
|
||||
$group_query = civicrm_api3('MailingEventConfirm', 'create',
|
||||
array( 'subscribe_id' => $parameters['sid'],
|
||||
'contact_id' => $parameters['cid'],
|
||||
'hash' => $parameters['h'],
|
||||
'api_key' => $mail_subscription_user_key,
|
||||
));
|
||||
if (!empty($group_query['is_error'])) {
|
||||
civiproxy_http_error($group_query['error_message'], 500);
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>CiviProxy Version <?php echo $civiproxy_version;?></title>
|
||||
<link href="http://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" type="text/css">
|
||||
<style type="text/css">
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.container {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.center {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
width: 970px;
|
||||
}
|
||||
|
||||
p {
|
||||
font-family: "Open Sans", sans-serif;
|
||||
font-size: 160%;
|
||||
}
|
||||
|
||||
#info {
|
||||
padding-top: 20px;
|
||||
vertical-align: top;
|
||||
text-align: center;
|
||||
width: 462px;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
<div id="info" class="center">
|
||||
<a href="https://www.systopia.de/"><?php echo $civiproxy_logo;?></a>
|
||||
<p id="version">Subscribe to Newsletters</p>
|
||||
</div>
|
||||
<div id="content" class="center">
|
||||
<p>Thank you. You are now subscribed to the newsletter.</a>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -7,11 +7,10 @@
|
|||
| http://www.systopia.de/ |
|
||||
+---------------------------------------------------------*/
|
||||
|
||||
require_once "../config.php";
|
||||
require_once "../proxy.php";
|
||||
|
||||
// see if mail open tracking is enabled
|
||||
if (!$target_mail_base) civiproxy_http_error("Feature disabled", 405);
|
||||
if (!$mail_subscription_user_key) civiproxy_http_error("Feature disabled", 405);
|
||||
|
||||
// basic check
|
||||
civiproxy_security_check('mail-resubscribe');
|
||||
|
|
@ -27,4 +26,65 @@ if (empty($parameters['jid'])) civiproxy_http_error("Missing/invalid parameter '
|
|||
if (empty($parameters['qid'])) civiproxy_http_error("Missing/invalid parameter 'qid'.");
|
||||
if (empty($parameters['h'])) civiproxy_http_error("Missing/invalid parameter 'h'.");
|
||||
|
||||
civiproxy_redirect($target_mail_base . '/resubscribe', $parameters);
|
||||
// PERFORM UNSUBSCRIBE
|
||||
$group_query = civicrm_api3('MailingEventResubscribe', 'create',
|
||||
array( 'job_id' => $parameters['jid'],
|
||||
'event_queue_id' => $parameters['qid'],
|
||||
'hash' => $parameters['h'],
|
||||
'api_key' => $mail_subscription_user_key,
|
||||
));
|
||||
if (!empty($group_query['is_error'])) {
|
||||
civiproxy_http_error($group_query['error_message'], 500);
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>CiviProxy Version <?php echo $civiproxy_version;?></title>
|
||||
<link href="http://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" type="text/css">
|
||||
<style type="text/css">
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.container {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.center {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
width: 970px;
|
||||
}
|
||||
|
||||
p {
|
||||
font-family: "Open Sans", sans-serif;
|
||||
font-size: 160%;
|
||||
}
|
||||
|
||||
#info {
|
||||
padding-top: 20px;
|
||||
vertical-align: top;
|
||||
text-align: center;
|
||||
width: 462px;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
<div id="info" class="center">
|
||||
<a href="https://www.systopia.de/"><?php echo $civiproxy_logo;?></a>
|
||||
<p id="version">Subscribe to Newsletters</p>
|
||||
</div>
|
||||
<div id="content" class="center">
|
||||
<p>Thank you. You've been re-subscribed to the newsletter.</a>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -12,21 +12,71 @@ require "../proxy.php";
|
|||
// see if mailing subscribe feature is enabled
|
||||
if (empty($mail_subscription_user_key)) civiproxy_http_error("Feature disabled", 405);
|
||||
|
||||
// get the groups you could subscribe to
|
||||
$group_query = civicrm_api3('Group', 'get', array( 'visibility' => 'Public Pages',
|
||||
'is_hidden' => 0,
|
||||
'is_active' => 1,
|
||||
'api_key' => $mail_subscription_user_key,
|
||||
));
|
||||
// basic check
|
||||
civiproxy_security_check('mail-subscribe');
|
||||
|
||||
// LOAD VISIBLE GROUPS
|
||||
$group_query = civicrm_api3('Group', 'get',
|
||||
array( 'visibility' => 'Public Pages',
|
||||
'is_hidden' => 0,
|
||||
'is_active' => 1,
|
||||
'api_key' => $mail_subscription_user_key,
|
||||
));
|
||||
if (!empty($group_query['is_error'])) {
|
||||
civiproxy_http_error($group_query['error_message'], 500);
|
||||
} else {
|
||||
$groups = $group_query['values'];
|
||||
if (empty($groups)) {
|
||||
civiproxy_http_error("No newsletter groups found!", 500);
|
||||
}
|
||||
}
|
||||
|
||||
// VERIFY / CHECK PARAMETERS
|
||||
$parameter_errors = array();
|
||||
if (!empty($_REQUEST['email'])) {
|
||||
// get parameters
|
||||
$email = $_REQUEST['email'];
|
||||
if (!preg_match("#^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$#i", $email)) civiproxy_http_error("'$email' is not a valid email address.", 500);
|
||||
|
||||
if (empty($_REQUEST['group_id'])) civiproxy_http_error("No newsletter group selected!", 500);
|
||||
$group_id = $_REQUEST['group_id'];
|
||||
|
||||
// ALL FINE. SUBSCRIBE USER!
|
||||
// first, get/create the contact
|
||||
$contact_query = civicrm_api3('Contact', 'create',
|
||||
array( 'email' => $email,
|
||||
'contact_type' => 'Individual',
|
||||
'dupe_check' => 1,
|
||||
'api_key' => $mail_subscription_user_key,
|
||||
));
|
||||
if (!empty($contact_query['is_error'])) {
|
||||
// an error occured during contact generation/identification
|
||||
if ($contact_query['error_code'] == 'duplicate') {
|
||||
// there have been multiple duplicates found
|
||||
$contact_id = $contact_query['ids'][0];
|
||||
} else {
|
||||
civiproxy_http_error($contact_query['error_message'], 500);
|
||||
}
|
||||
} else {
|
||||
$contact_id = $contact_query['id'];
|
||||
}
|
||||
|
||||
// then: subscribe
|
||||
$subscribe_query = civicrm_api3('MailingEventSubscribe', 'create',
|
||||
array( 'email' => $email,
|
||||
'contact_id' => $contact_id,
|
||||
'group_id' => $group_id,
|
||||
'api_key' => $mail_subscription_user_key,
|
||||
));
|
||||
if (!empty($subscribe_query['is_error'])) {
|
||||
// an error occured during the actual subscription
|
||||
civiproxy_http_error($subscribe_query['error_message'], 500);
|
||||
}
|
||||
|
||||
}
|
||||
error_log(print_r($groups,1));
|
||||
?>
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
|
|
@ -72,53 +122,27 @@ error_log(print_r($groups,1));
|
|||
</div>
|
||||
<div id="content" class="center">
|
||||
<?php
|
||||
/*********************************************
|
||||
** main processing routine **
|
||||
********************************************/
|
||||
$parameter_errors = array();
|
||||
if (!empty($_REQUEST['email'])) {
|
||||
// get parameters
|
||||
$email = $_REQUEST['email'];
|
||||
$group_ids = array();
|
||||
foreach ($_REQUEST as $key => $value) {
|
||||
error_log(substr($key, 0, 6));
|
||||
if (substr($key, 0, 6) == 'group_') {
|
||||
$group_ids[] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: verify email is valid, otherwise set $parameter_errors['email']
|
||||
// TODO: verify at least one group is selected, otherwise set $parameter_errors['group_id']
|
||||
}
|
||||
|
||||
if (empty($_REQUEST['email']) || !empty($parameter_errors)) {
|
||||
// TODO: if
|
||||
|
||||
// TODO: show error if no group found
|
||||
// TODO: show error if email not valid
|
||||
print "
|
||||
<form id='subscribe' method='POST'>
|
||||
<label for='email'>Your email Address:</label>
|
||||
<input type='text' name='email'></input>
|
||||
<h3>Select the newsletter you would like to subscribe to:</h3>
|
||||
<ul>
|
||||
<select name='group_id'>
|
||||
";
|
||||
foreach ($groups as $group_id => $group) {
|
||||
print "
|
||||
<li>
|
||||
<input type='checkbox' name='group_{$group_id}' value='{$group_id}'>{$group['name']}</input>
|
||||
<p>{$group['description']}</p>
|
||||
</li>";
|
||||
print "<option value='{$group_id}'>{$group['name']}</input>";
|
||||
}
|
||||
print "
|
||||
</ul>
|
||||
</select>
|
||||
<input type='submit' value='Subscribe' />
|
||||
</form>";
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
print_r($_REQUEST);
|
||||
|
||||
// the subscription was complete
|
||||
print "<p>Thank you. You will receive an email asking you to confirm your subscription.</p>";
|
||||
}
|
||||
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -7,11 +7,10 @@
|
|||
| http://www.systopia.de/ |
|
||||
+---------------------------------------------------------*/
|
||||
|
||||
require_once "../config.php";
|
||||
require_once "../proxy.php";
|
||||
require "../proxy.php";
|
||||
|
||||
// see if mail open tracking is enabled
|
||||
if (!$target_mail_base) civiproxy_http_error("Feature disabled", 405);
|
||||
// see if mailing subscribe feature is enabled
|
||||
if (empty($mail_subscription_user_key)) civiproxy_http_error("Feature disabled", 405);
|
||||
|
||||
// basic check
|
||||
civiproxy_security_check('mail-unsubscribe');
|
||||
|
|
@ -27,4 +26,65 @@ if (empty($parameters['jid'])) civiproxy_http_error("Missing/invalid parameter '
|
|||
if (empty($parameters['qid'])) civiproxy_http_error("Missing/invalid parameter 'qid'.");
|
||||
if (empty($parameters['h'])) civiproxy_http_error("Missing/invalid parameter 'h'.");
|
||||
|
||||
civiproxy_redirect($target_mail_base . '/unsubscribe', $parameters);
|
||||
// PERFORM UNSUBSCRIBE
|
||||
$group_query = civicrm_api3('MailingEventUnsubscribe', 'create',
|
||||
array( 'job_id' => $parameters['jid'],
|
||||
'event_queue_id' => $parameters['qid'],
|
||||
'hash' => $parameters['h'],
|
||||
'api_key' => $mail_subscription_user_key,
|
||||
));
|
||||
if (!empty($group_query['is_error'])) {
|
||||
civiproxy_http_error($group_query['error_message'], 500);
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>CiviProxy Version <?php echo $civiproxy_version;?></title>
|
||||
<link href="http://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" type="text/css">
|
||||
<style type="text/css">
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.container {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.center {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
width: 970px;
|
||||
}
|
||||
|
||||
p {
|
||||
font-family: "Open Sans", sans-serif;
|
||||
font-size: 160%;
|
||||
}
|
||||
|
||||
#info {
|
||||
padding-top: 20px;
|
||||
vertical-align: top;
|
||||
text-align: center;
|
||||
width: 462px;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
<div id="info" class="center">
|
||||
<a href="https://www.systopia.de/"><?php echo $civiproxy_logo;?></a>
|
||||
<p id="version">Subscribe to Newsletters</p>
|
||||
</div>
|
||||
<div id="content" class="center">
|
||||
<p>Thank you. You have been successfully unsubscribed.</a>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -21,9 +21,6 @@ $civiproxy_logo = "<img src='{$proxy_base}/static/images/proxy-logo.png' alt=
|
|||
* where type can be 'int', 'string' (unchecked),
|
||||
*/
|
||||
function civiproxy_redirect($url_requested, $parameters) {
|
||||
// error_log('CALLING: '.$url_requested);
|
||||
// error_log(print_r($parameters,1));
|
||||
|
||||
$url = $url_requested;
|
||||
$curlSession = curl_init();
|
||||
|
||||
|
|
@ -158,17 +155,16 @@ function civiproxy_get_parameters($valid_parameters) {
|
|||
$value = number_format($value, 2, '.', '');
|
||||
} elseif ($type == 'hex') {
|
||||
// hex code
|
||||
if (!preg_match("#^[0-9a-f]*$#gi", $value)) {
|
||||
error_log("CiviProxy: removed invalid hex parameter");
|
||||
if (!preg_match("#^[0-9a-f]*$#i", $value)) {
|
||||
error_log("CiviProxy: removed invalid hex parameter: " . $value);
|
||||
$value = '';
|
||||
}
|
||||
} elseif ($type == 'email') {
|
||||
// valid email
|
||||
// TODO: regex email address
|
||||
// if (!preg_match("#^[0-9a-f]*$#gi", $value)) {
|
||||
// error_log("CiviProxy: removed invalid hex parameter");
|
||||
// $value = '';
|
||||
// }
|
||||
if (!preg_match("#^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$#i", $value)) {
|
||||
error_log("CiviProxy: removed invalid email parameter: " . $value);
|
||||
$value = '';
|
||||
}
|
||||
} elseif (is_array($type)) {
|
||||
// this is a list of valid options
|
||||
$requested_value = $value;
|
||||
|
|
|
|||
Loading…
Reference in New Issue