From c86213dcc96de0d3adabc6036ab1ba2402f9d2e3 Mon Sep 17 00:00:00 2001 From: systopia Date: Thu, 19 Mar 2015 09:29:54 +0100 Subject: [PATCH] work in progress - email subscription --- proxy/error.php | 5 +- proxy/mailing/subscribe.php | 121 +++++++++++++++++++++++++++++++++--- proxy/proxy.php | 40 +++++++++++- 3 files changed, 154 insertions(+), 12 deletions(-) diff --git a/proxy/error.php b/proxy/error.php index 5f42c3b..f5ca37d 100644 --- a/proxy/error.php +++ b/proxy/error.php @@ -7,8 +7,7 @@ | http://www.systopia.de/ | +---------------------------------------------------------*/ -require_once "config.php"; -require_once "proxy.php"; +require "proxy.php"; ?> @@ -116,7 +115,7 @@ require_once "proxy.php";
- SYSTOPIA Organisationsberatung +

CiviProxy Version

diff --git a/proxy/mailing/subscribe.php b/proxy/mailing/subscribe.php index 903eda3..bd07c49 100644 --- a/proxy/mailing/subscribe.php +++ b/proxy/mailing/subscribe.php @@ -7,15 +7,120 @@ | 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-subscribe'); +// 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, + )); -// just forward, no parameters -civiproxy_redirect($target_mail_base . '/subscribe', array()); +if (!empty($group_query['is_error'])) { + civiproxy_http_error($group_query['error_message'], 500); +} else { + $groups = $group_query['values']; +} +error_log(print_r($groups,1)); +?> + + + + + CiviProxy Version <?php echo $civiproxy_version;?> + + + + +
+
+ +

Subscribe to Newsletters

+
+
+ $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 + + print " +
+ + +

Select the newsletter you would like to subscribe to:

+
    + "; + foreach ($groups as $group_id => $group) { + print " +
  • + {$group['name']} +

    {$group['description']}

    +
  • "; + } + print " +
+
"; + +} else { + + + print_r($_REQUEST); + +} + +?> +
+
+ + diff --git a/proxy/proxy.php b/proxy/proxy.php index 1fa10f1..90c7973 100644 --- a/proxy/proxy.php +++ b/proxy/proxy.php @@ -7,8 +7,9 @@ | http://www.systopia.de/ | +---------------------------------------------------------*/ +require "config.php"; $civiproxy_version = '0.3'; -require_once "config.php"; +$civiproxy_logo = "SYSTOPIA Organisationsberatung"; /** * this will redirect the request to another URL, @@ -204,3 +205,40 @@ function civiproxy_http_error($message, $code = 404) { exit(); } + + +/** + * call the CiviCRM REST API via CURL + */ +function civicrm_api3($entity, $action, $data) { + global $target_rest, $sys_key_map; + + // extract site key + $site_keys = array_values($sys_key_map); + if (empty($site_keys)) civiproxy_http_error('No site key set.'); + + $query = $data; // array copy(!) + $query['key'] = $site_keys[0]; + $query['json'] = 1; + $query['version'] = 3; + $query['entity'] = $entity; + $query['action'] = $action; + + $curl = curl_init(); + curl_setopt($curl, CURLOPT_POST, 1); + curl_setopt($curl, CURLOPT_POSTFIELDS, $query); + curl_setopt($curl, CURLOPT_URL, $target_rest); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($curl, CURLOPT_SSLVERSION, 1); + + $response = curl_exec($curl); + + if (curl_error($curl)){ + civiproxy_http_error(curl_error($curl)); + } else { + return json_decode($response, true); + } +} +