parent
3e0cf56c0d
commit
6828950f9c
|
|
@ -47,6 +47,8 @@ class CRM_Civiproxy_Mailer {
|
|||
$enabled = CRM_Core_BAO_Setting::getItem('CiviProxy Settings', 'proxy_enabled');
|
||||
if (!$enabled) return;
|
||||
|
||||
$mosaico = CRM_Civiproxy_Mosaico::singleton();
|
||||
|
||||
// get the URLs
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$system_base = $config->userFrameworkBaseURL;
|
||||
|
|
@ -59,6 +61,9 @@ class CRM_Civiproxy_Mailer {
|
|||
$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);
|
||||
$value = preg_replace("#{$system_base}civicrm/mosaico/img\?src=#i", $proxy_base.'/mosaico.php?id=', $value);
|
||||
if ($mosaico->isMosaicoInstalled()) {
|
||||
$value = preg_replace("#({$mosaico->getMosaicoExtensionUrl()}/packages/mosaico/templates/)(\S*)([\"'])#i", $proxy_base . '/mosaico.php?template_url=$2$3', $value);
|
||||
}
|
||||
|
||||
// Mailing related functions
|
||||
$value = preg_replace("#{$system_base}civicrm/mailing/view#i", $proxy_base.'/mailing/mail.php', $value);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (C) 2021 Jaap Jansma (jaap.jansma@civicoop.org)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
class CRM_Civiproxy_Mosaico {
|
||||
|
||||
/**
|
||||
* @var CRM_Civiproxy_Mosaico
|
||||
*/
|
||||
private static $singleton;
|
||||
|
||||
/**
|
||||
* @var String
|
||||
*/
|
||||
private $mosiacoExtenionUrl;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $isMosaicoInstalled = false;
|
||||
|
||||
private function __construct() {
|
||||
try {
|
||||
$mosaicoExt = civicrm_api3('Extension', 'getsingle', ['full_name' => "uk.co.vedaconsulting.mosaico"]);
|
||||
$this->isMosaicoInstalled = true;
|
||||
$this->mosiacoExtenionUrl = CRM_Mosaico_ExtensionUtil::url();
|
||||
} catch (\Exception $ex) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CRM_Civiproxy_Mosaico
|
||||
*/
|
||||
public static function singleton() {
|
||||
if (!self::$singleton) {
|
||||
self::$singleton = new CRM_Civiproxy_Mosaico();
|
||||
}
|
||||
return self::$singleton;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isMosaicoInstalled() {
|
||||
return $this->isMosaicoInstalled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMosaicoExtensionUrl() {
|
||||
return $this->mosiacoExtenionUrl;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -43,6 +43,7 @@ $target_civicrm = 'https://your.civicrm.installation.org';
|
|||
$target_rest = $target_civicrm . '/sites/all/modules/civicrm/extern/rest.php';
|
||||
$target_file = $target_civicrm . '/sites/default/files/civicrm/persist/';
|
||||
$target_mosaico = NULL; // (disabled by default): $target_civicrm . '/civicrm/mosaico/img?src=';
|
||||
$target_mosaico_template_url = NULL; // (disabled by default): $target_civicrm . '/wp-content/uploads/civicrm/ext/uk.co.vedaconsulting.mosaico/packages/mosaico/templates/';
|
||||
$target_mail_view = $target_civicrm . '/civicrm/mailing/view';
|
||||
$target_url = $target_civicrm . '/civicrm/mailing/url';
|
||||
$target_open = $target_civicrm . '/civicrm/mailing/open';
|
||||
|
|
|
|||
|
|
@ -17,30 +17,61 @@ if (!$target_mosaico) civiproxy_http_error("Feature disabled", 405);
|
|||
civiproxy_security_check('file');
|
||||
|
||||
// basic restraints
|
||||
$valid_parameters = array( 'id' => 'string' );
|
||||
$valid_parameters = array( 'id' => 'string', 'template_url' => 'string' );
|
||||
$parameters = civiproxy_get_parameters($valid_parameters);
|
||||
|
||||
// check if id specified
|
||||
if (empty($parameters['id'])) civiproxy_http_error("Resource not found");
|
||||
|
||||
// check restrictions
|
||||
if (!empty($file_cache_exclude)) {
|
||||
foreach ($file_cache_exclude as $pattern) {
|
||||
if (preg_match($pattern, $parameters['id'])) {
|
||||
if (!empty($parameters['id'])) {
|
||||
// check restrictions
|
||||
if (!empty($file_cache_exclude)) {
|
||||
foreach ($file_cache_exclude as $pattern) {
|
||||
if (preg_match($pattern, $parameters['id'])) {
|
||||
civiproxy_http_error("Invalid Resource", 403);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($file_cache_include)) {
|
||||
$accept_id = FALSE;
|
||||
foreach ($file_cache_include as $pattern) {
|
||||
if (preg_match($pattern, $parameters['id'])) {
|
||||
$accept_id = TRUE;
|
||||
}
|
||||
}
|
||||
if (!$accept_id) {
|
||||
civiproxy_http_error("Invalid Resource", 403);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($file_cache_include)) {
|
||||
$accept_id = FALSE;
|
||||
foreach ($file_cache_include as $pattern) {
|
||||
if (preg_match($pattern, $parameters['id'])) {
|
||||
$accept_id = TRUE;
|
||||
|
||||
// look up the required resource
|
||||
$header_key = 'header&' . $parameters['id'];
|
||||
$data_key = 'data&' . $parameters['id'];
|
||||
$url = $target_mosaico . $parameters['id'];
|
||||
} elseif (!empty($parameters['template_url'])) {
|
||||
// check restrictions
|
||||
if (!empty($file_cache_exclude)) {
|
||||
foreach ($file_cache_exclude as $pattern) {
|
||||
if (preg_match($pattern, $parameters['template_url'])) {
|
||||
civiproxy_http_error("Invalid Resource", 403);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$accept_id) {
|
||||
civiproxy_http_error("Invalid Resource", 403);
|
||||
if (!empty($file_cache_include)) {
|
||||
$accept_id = FALSE;
|
||||
foreach ($file_cache_include as $pattern) {
|
||||
if (preg_match($pattern, $parameters['template_url'])) {
|
||||
$accept_id = TRUE;
|
||||
}
|
||||
}
|
||||
if (!$accept_id) {
|
||||
civiproxy_http_error("Invalid Resource", 403);
|
||||
}
|
||||
}
|
||||
|
||||
// look up the required resource
|
||||
$header_key = 'header&' . $parameters['template_url'];
|
||||
$data_key = 'data&' . $parameters['template_url'];
|
||||
$url = $target_mosaico_template_url . $parameters['template_url'];
|
||||
} else {
|
||||
civiproxy_http_error("Resource not found");
|
||||
}
|
||||
|
||||
// load PEAR file cache
|
||||
|
|
@ -49,9 +80,6 @@ if (!file_exists($file_cache_options['cacheDir'])) mkdir($file_cache_options['ca
|
|||
require_once('Cache/Lite.php');
|
||||
$file_cache = new Cache_Lite($file_cache_options);
|
||||
|
||||
// look up the required resource
|
||||
$header_key = 'header&' . $parameters['id'];
|
||||
$data_key = 'data&' . $parameters['id'];
|
||||
|
||||
$header = $file_cache->get($header_key);
|
||||
$data = $file_cache->get($data_key);
|
||||
|
|
@ -68,8 +96,6 @@ if ($header && $data) {
|
|||
}
|
||||
|
||||
// if we get here, we have a cache miss => load
|
||||
$url = $target_mosaico . $parameters['id'];
|
||||
|
||||
$curlSession = curl_init();
|
||||
curl_setopt($curlSession, CURLOPT_URL, $url);
|
||||
curl_setopt($curlSession, CURLOPT_HEADER, 1);
|
||||
|
|
|
|||
Loading…
Reference in New Issue