Skip to content

Commit

Permalink
Use placeholder for unsubscribe link and place it near the normal ema…
Browse files Browse the repository at this point in the history
…il footer content. (#13421)

* Use placeholder for unsubscribe link and place it near the normal email footer content.

* padding tweak for whitelabel

* fix unsubscribe link escaping replace issue

* Move _htmlReportFooter contents to _htmlEmailFooter.twig.

* Remove stray 'c'
  • Loading branch information
diosmosis committed Oct 3, 2018
1 parent 902bd94 commit e6de421
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
5 changes: 4 additions & 1 deletion core/ReportRenderer/Html.php
Expand Up @@ -22,6 +22,7 @@ class Html extends ReportRenderer

const HTML_CONTENT_TYPE = 'text/html';
const HTML_FILE_EXTENSION = 'html';
const UNSUBSCRIBE_LINK_PLACEHOLDER = '__unsubscribeLink__';

protected $renderImageInline = false;

Expand Down Expand Up @@ -74,7 +75,9 @@ public function getRenderedReport()

private function epilogue()
{
$view = new View\HtmlEmailFooterView();
// the unsubscribe link is specific to the email address the report is sent to, so we can't generate it here.
// instead we use a placeholder value, and replace it with the correct value in ScheduledReports::sendReport().
$view = new View\HtmlEmailFooterView(self::UNSUBSCRIBE_LINK_PLACEHOLDER);
$this->rendering .= $view->render();
}

Expand Down
4 changes: 3 additions & 1 deletion core/View/HtmlEmailFooterView.php
Expand Up @@ -16,10 +16,12 @@ class HtmlEmailFooterView extends View
{
const TEMPLATE_FILE = '@CoreHome/ReportRenderer/_htmlReportFooter';

public function __construct()
public function __construct($unsubscribeLink = null)
{
parent::__construct(self::TEMPLATE_FILE);

HtmlReportEmailHeaderView::assignCommonParameters($this);

$this->unsubscribeLink = $unsubscribeLink;
}
}
16 changes: 13 additions & 3 deletions plugins/CoreHome/templates/_htmlEmailFooter.twig
@@ -1,16 +1,26 @@
{% set fontStyle %}color:{{ themeStyles.colorText|e('html_attr') }};font-family:{{ themeStyles.fontFamilyBase|e('html_attr') }};{% endset %}
{% set styleParagraph = 'font-size:15px;line-height:24px;margin:0 0 16px;' %}
{% set footerParagraphStyle %}{{styleParagraph}}{{fontStyle}}text-align:center;font-size:13px; color:#666;{% endset %}
{% set hasHorizontalRule = not hasWhiteLabel or unsubscribeLink|default is not empty %}

{% if not hasWhiteLabel %}
{% if hasHorizontalRule %}
<hr style=" border: 0; margin-top: 50px; height: 1px; background-image: linear-gradient(to right, rgba(231, 231, 231, 0), rgba(231, 231, 231, 1), rgba(2311, 2311, 231, 0));">
{% endif %}

<p style='{{styleParagraph|raw}}{{fontStyle|raw}}text-align:center;font-size:13px; color:#666; padding:30px'>
{% if not hasWhiteLabel %}
<p style='{{ footerParagraphStyle }}padding-top:30px;margin-bottom:0;'>
{{'General_PoweredBy'|translate}}
<a style="color:#439fe0; " href="https://matomo.org/" title="Matomo Analytics">Matomo Analytics</a>
<a style="color:#439fe0;" href="https://matomo.org/" title="Matomo Analytics">Matomo Analytics</a>
<br />
{{ 'CoreHome_LeadingAnalyticsPlatformRespectsYourPrivacy'|translate }}
</p>
{% endif %}

{% if unsubscribeLink|default is not empty %}
{% set unsubLink %}<a style="color:#439fe0;" href="{{ unsubscribeLink|e('html_attr') }}">{{ 'ScheduledReports_Unsubscribe'|translate }}</a>{% endset %}
<p style='{{ footerParagraphStyle }}{% if hasWhiteLabel %}padding-top:30px;{% endif %}'>{{ 'ScheduledReports_UnsubscribeFooter'|translate(unsubLink)|raw }}.</p>
{% endif %}

</div>
</body>
</html>
5 changes: 4 additions & 1 deletion plugins/ScheduledReports/ScheduledReports.php
Expand Up @@ -9,6 +9,7 @@
namespace Piwik\Plugins\ScheduledReports;

use Exception;
use Piwik\Common;
use Piwik\Config;
use Piwik\Container\StaticContainer;
use Piwik\Log;
Expand Down Expand Up @@ -365,7 +366,9 @@ public function sendReport($reportType, $report, $contents, $filename, $prettyDa
// add unsubscribe links to content
if ($htmlContent) {
$link = SettingsPiwik::getPiwikUrl() . 'index.php?module=ScheduledReports&action=unsubscribe&token=' . $tokens[$email];
$mail->setBodyHtml($htmlContent . '<br /><br /><hr /><br />'.Piwik::translate('ScheduledReports_UnsubscribeFooter', [' <a href="' . $link . '">' . Piwik::translate('ScheduledReports_Unsubscribe') . '</a>']));
$bodyContent = str_replace(ReportRenderer\Html::UNSUBSCRIBE_LINK_PLACEHOLDER, Common::sanitizeInputValue($link), $htmlContent);

$mail->setBodyHtml($bodyContent);
}

if ($textContent) {
Expand Down

0 comments on commit e6de421

Please sign in to comment.