diff --git a/de.systopia.civiproxy/CRM/Civiproxy/Mailer.php b/de.systopia.civiproxy/CRM/Civiproxy/Mailer.php new file mode 100644 index 0000000..fcbe3fa --- /dev/null +++ b/de.systopia.civiproxy/CRM/Civiproxy/Mailer.php @@ -0,0 +1,71 @@ +mailer = $mailer; + } + + /** + * Send an email via the wrapped mailer, + * mending the URLs contained + */ + function send($recipients, $headers, $body) { + CRM_CiviProxy_Mailer::mendURLs($headers); + CRM_CiviProxy_Mailer::mendURLs($body); + $this->mailer->send($recipients, $headers, $body); + } + + + /** + * This function will manipulate the URLs in Emails, so they point + * to the correct proxy addresses + */ + static function mendURLs(&$value) { + // check if the proxy is enabled + $enabled = CRM_Core_BAO_Setting::getItem('CiviProxy Settings', 'proxy_enabled'); + if (!$enabled) return; + + // get the URLs + $config = CRM_Core_Config::singleton(); + $system_base = $config->userFrameworkBaseURL; + $proxy_base = CRM_Core_BAO_Setting::getItem('CiviProxy Settings', 'proxy_url'); + + // General external functions + $value = preg_replace("#{$system_base}sites/all/modules/civicrm/extern/url.php#i", $proxy_base.'/url.php', $value); + $value = preg_replace("#{$system_base}sites/all/modules/civicrm/extern/open.php#i", $proxy_base.'/open.php', $value); + $value = preg_replace("#{$system_base}sites/default/files/civicrm/persist/#i", $proxy_base.'/file.php?id=', $value); + + // Mailing related functions + $value = preg_replace("#{$system_base}civicrm/mailing/view#i", $proxy_base.'/mailing/mail.php', $value); + $custom_mailing_base = CRM_Core_BAO_Setting::getItem('CiviProxy Settings', 'custom_mailing_base'); + $other_mailing_functions = array('subscribe', 'confirm', 'unsubscribe', 'resubscribe', 'optout'); + foreach ($other_mailing_functions as $function) { + if (empty($custom_mailing_base)) { + $new_url = "{$proxy_base}/mailing/{$function}.php"; + } else { + $new_url = "{$custom_mailing_base}/{$function}.php"; + } + $value = preg_replace("#{$system_base}civicrm/mailing/{$function}#i", $new_url, $value); + } + } +} diff --git a/de.systopia.civiproxy/civiproxy.php b/de.systopia.civiproxy/civiproxy.php index f77b589..7676eaa 100644 --- a/de.systopia.civiproxy/civiproxy.php +++ b/de.systopia.civiproxy/civiproxy.php @@ -1,44 +1,21 @@ userFrameworkBaseURL; - $proxy_base = CRM_Core_BAO_Setting::getItem('CiviProxy Settings', 'proxy_url'); - - // fields to replace: - $fields2replace = array('html', 'text'); - foreach ($fields2replace as $field) { - $value = $params[$field]; - - // General external functions - $value = preg_replace("#{$system_base}sites/all/modules/civicrm/extern/url.php#i", $proxy_base.'/url.php', $value); - $value = preg_replace("#{$system_base}sites/all/modules/civicrm/extern/open.php#i", $proxy_base.'/open.php', $value); - $value = preg_replace("#{$system_base}sites/default/files/civicrm/persist/#i", $proxy_base.'/file.php?id=', $value); - - // Mailing related functions - $value = preg_replace("#{$system_base}civicrm/mailing/view#i", $proxy_base.'/mailing/mail.php', $value); - $custom_mailing_base = CRM_Core_BAO_Setting::getItem('CiviProxy Settings', 'custom_mailing_base'); - foreach ($other_mailing_functions as $function) { - if (empty($custom_mailing_base)) { - $new_url = "{$proxy_base}/mailing/{$function}.php"; - } else { - $new_url = "{$custom_mailing_base}/{$function}.php"; - } - $value = preg_replace("#{$system_base}civicrm/mailing/{$function}#i", $new_url, $value); - } - - $params[$field] = $value; - } +function civiproxy_civicrm_alterMailer(&$mailer, $driver, $params) { + $mailer = new CRM_Civiproxy_Mailer($mailer); } /** diff --git a/proxy/mailing/optout.php b/proxy/mailing/optout.php new file mode 100644 index 0000000..587610e --- /dev/null +++ b/proxy/mailing/optout.php @@ -0,0 +1,19 @@ +