implementing #29 (WIP)

This commit is contained in:
B. Endres 2019-11-26 16:15:52 +01:00
parent 6478762b74
commit f10f67d6cf
2 changed files with 31 additions and 12 deletions

View File

@ -57,6 +57,7 @@ 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);
$value = preg_replace("#{$system_base}civicrm/mosaico/img\?method=placeholder(&|&)params=#i", $proxy_base.'/mosaico.php?ph=', $value);
// Mailing related functions
$value = preg_replace("#{$system_base}civicrm/mailing/view#i", $proxy_base.'/mailing/mail.php', $value);

View File

@ -17,16 +17,26 @@ 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', 'ph' => 'string');
$parameters = civiproxy_get_parameters($valid_parameters);
// check if id specified
if (empty($parameters['id'])) civiproxy_http_error("Resource not found");
// check if id or ph
if (!empty($parameters['id'])) {
// that's a regular image resource
$type = 'image';
$reqd = $parameters['id'];
} elseif (!empty($parameters['ph'])) {
// that's a placeholder
$type = 'placeholder';
$reqd = $parameters['ph'];
} else {
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 (preg_match($pattern, $reqd)) {
civiproxy_http_error("Invalid Resource", 403);
}
}
@ -34,7 +44,7 @@ if (!empty($file_cache_exclude)) {
if (!empty($file_cache_include)) {
$accept_id = FALSE;
foreach ($file_cache_include as $pattern) {
if (preg_match($pattern, $parameters['id'])) {
if (preg_match($pattern, $reqd)) {
$accept_id = TRUE;
}
}
@ -50,8 +60,8 @@ 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_key = 'header&' . $reqd;
$data_key = 'data&' . $reqd;
$header = $file_cache->get($header_key);
$data = $file_cache->get($data_key);
@ -68,8 +78,16 @@ if ($header && $data) {
}
// if we get here, we have a cache miss => load
$url = $target_mosaico . $parameters['id'];
if ($type == 'image') {
// that's a regular image resource
$url = $target_mosaico . $reqd;
} else {
// that's a placeholder
$target_placeholder = str_replace('img?src=', 'img?method=placeholder&params=', $target_mosaico);
$url = $target_placeholder . $reqd;
}
// run the query
$curlSession = curl_init();
curl_setopt($curlSession, CURLOPT_URL, $url);
curl_setopt($curlSession, CURLOPT_HEADER, 1);