Commit 6653c862 authored by jaapjansma's avatar jaapjansma
Browse files

added handling of social media icons from mosaico template

parent fee760e2
......@@ -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;
......@@ -58,8 +60,12 @@ class CRM_Civiproxy_Mailer {
$value = preg_replace("#{$system_base}civicrm/mailing/open#i", $proxy_base.'/open.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);
$value = preg_replace("#{$system_base}civicrm/mosaico/img\?src=#i", $proxy_base.'/mosaico.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("#{$system_base}civicrm/mosaico/img\?src=#i", $proxy_base . '/mosaico.php?id=', $value);
$value = preg_replace("#{$system_base}civicrm/mosaico/img/\?src=#i", $proxy_base . '/mosaico.php?id=', $value);
$value = preg_replace("#({$mosaico->getMosaicoExtensionUrl()}/packages/mosaico/templates/)(\S*)[\"']#i", $proxy_base . '/mosaico.php?template_url=$2', $value);
$regex = "({$mosaico->getMosaicoExtensionUrl()}/packages/mosaico/templates/)(\S*)[\"']";
}
// Mailing related functions
$value = preg_replace("#{$system_base}civicrm/mailing/view#i", $proxy_base.'/mailing/mail.php', $value);
......
<?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;
}
}
\ No newline at end of file
......@@ -35,6 +35,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,96 @@ if (!$target_mosaico) civiproxy_http_error("Feature disabled", 405);
civiproxy_security_check('file');
// basic restraints
$valid_parameters = array( 'id' => 'string', 'method' => 'string', 'amp;method' => 'string', 'params' => 'string', 'amp;params' => 'string' );
$valid_parameters = array(
'id' => 'string',
'method' => 'string',
'amp;method' => 'string',
'params' => 'string',
'amp;params' => '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'];
if (isset($parameters['method'])) {
$header_key .= $parameters['method'];
$data_key .= $parameters['method'];
}
if (isset($parameters['amp;method'])) {
$header_key .= $parameters['amp;method'];
$data_key .= $parameters['amp;method'];
}
if (isset($parameters['params'])) {
$header_key .= $parameters['params'];
$data_key .= $parameters['params'];
}
if (isset($parameters['amp;params'])) {
$header_key .= $parameters['amp;params'];
$data_key .= $parameters['amp;params'];
}
$url = $target_mosaico . $parameters['id'];
if (isset($parameters['method'])) {
$url .= '&method='.$parameters['method'];
}
if (isset($parameters['amp;method'])) {
$url .= '&method='.$parameters['amp;method'];
}
if (isset($parameters['params'])) {
$url .= '&params='.$parameters['params'];
}
if (isset($parameters['amp;params'])) {
$url .= '&params='.$parameters['amp;params'];
}
} 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,27 +115,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'];
if (isset($parameters['method'])) {
$header_key .= $parameters['method'];
$data_key .= $parameters['method'];
}
if (isset($parameters['amp;method'])) {
$header_key .= $parameters['amp;method'];
$data_key .= $parameters['amp;method'];
}
if (isset($parameters['params'])) {
$header_key .= $parameters['params'];
$data_key .= $parameters['params'];
}
if (isset($parameters['amp;params'])) {
$header_key .= $parameters['amp;params'];
$data_key .= $parameters['amp;params'];
}
$header = $file_cache->get($header_key);
$data = $file_cache->get($data_key);
......@@ -85,20 +130,6 @@ if ($header && $data) {
}
// if we get here, we have a cache miss => load
$url = $target_mosaico . $parameters['id'];
if (isset($parameters['method'])) {
$url .= '&method='.$parameters['method'];
}
if (isset($parameters['amp;method'])) {
$url .= '&method='.$parameters['amp;method'];
}
if (isset($parameters['params'])) {
$url .= '&params='.$parameters['params'];
}
if (isset($parameters['amp;params'])) {
$url .= '&params='.$parameters['amp;params'];
}
$curlSession = curl_init();
curl_setopt($curlSession, CURLOPT_URL, $url);
curl_setopt($curlSession, CURLOPT_HEADER, 1);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment