update Piwik to version 2.16 (fixes #91)
This commit is contained in:
parent
296343bf3b
commit
d885a4baa9
5833 changed files with 418860 additions and 226988 deletions
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -8,7 +8,9 @@
|
|||
*/
|
||||
namespace Piwik;
|
||||
|
||||
use Piwik\Container\StaticContainer;
|
||||
use Piwik\Plugins\CoreAdminHome\CustomLogo;
|
||||
use Piwik\Translation\Translator;
|
||||
use Zend_Mail;
|
||||
|
||||
/**
|
||||
|
|
@ -34,9 +36,18 @@ class Mail extends Zend_Mail
|
|||
public function setDefaultFromPiwik()
|
||||
{
|
||||
$customLogo = new CustomLogo();
|
||||
$fromEmailName = $customLogo->isEnabled()
|
||||
? Piwik::translate('CoreHome_WebAnalyticsReports')
|
||||
: Piwik::translate('ScheduledReports_PiwikReports');
|
||||
|
||||
/** @var Translator $translator */
|
||||
$translator = StaticContainer::get('Piwik\Translation\Translator');
|
||||
|
||||
$fromEmailName = Config::getInstance()->General['noreply_email_name'];
|
||||
|
||||
if (empty($fromEmailName) && $customLogo->isEnabled()) {
|
||||
$fromEmailName = $translator->translate('CoreHome_WebAnalyticsReports');
|
||||
} elseif (empty($fromEmailName)) {
|
||||
$fromEmailName = $translator->translate('ScheduledReports_PiwikReports');
|
||||
}
|
||||
|
||||
$fromEmailAddress = Config::getInstance()->General['noreply_email_address'];
|
||||
$this->setFrom($fromEmailAddress, $fromEmailName);
|
||||
}
|
||||
|
|
@ -50,20 +61,25 @@ class Mail extends Zend_Mail
|
|||
*/
|
||||
public function setFrom($email, $name = null)
|
||||
{
|
||||
$hostname = Config::getInstance()->mail['defaultHostnameIfEmpty'];
|
||||
$piwikHost = Url::getCurrentHost($hostname);
|
||||
return parent::setFrom(
|
||||
$this->parseDomainPlaceholderAsPiwikHostName($email),
|
||||
$name
|
||||
);
|
||||
}
|
||||
|
||||
// If known Piwik URL, use it instead of "localhost"
|
||||
$piwikUrl = SettingsPiwik::getPiwikUrl();
|
||||
$url = parse_url($piwikUrl);
|
||||
if (isset($url['host'])
|
||||
&& $url['host'] != 'localhost'
|
||||
&& $url['host'] != '127.0.0.1'
|
||||
) {
|
||||
$piwikHost = $url['host'];
|
||||
}
|
||||
$email = str_replace('{DOMAIN}', $piwikHost, $email);
|
||||
return parent::setFrom($email, $name);
|
||||
/**
|
||||
* Set Reply-To Header
|
||||
*
|
||||
* @param string $email
|
||||
* @param null|string $name
|
||||
* @return Zend_Mail
|
||||
*/
|
||||
public function setReplyTo($email, $name = null)
|
||||
{
|
||||
return parent::setReplyTo(
|
||||
$this->parseDomainPlaceholderAsPiwikHostName($email),
|
||||
$name
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -72,27 +88,37 @@ class Mail extends Zend_Mail
|
|||
private function initSmtpTransport()
|
||||
{
|
||||
$mailConfig = Config::getInstance()->mail;
|
||||
|
||||
if (empty($mailConfig['host'])
|
||||
|| $mailConfig['transport'] != 'smtp'
|
||||
) {
|
||||
return;
|
||||
}
|
||||
$smtpConfig = array();
|
||||
if (!empty($mailConfig['type']))
|
||||
$smtpConfig['auth'] = strtolower($mailConfig['type']);
|
||||
if (!empty($mailConfig['username']))
|
||||
$smtpConfig['username'] = $mailConfig['username'];
|
||||
if (!empty($mailConfig['password']))
|
||||
$smtpConfig['password'] = $mailConfig['password'];
|
||||
if (!empty($mailConfig['encryption']))
|
||||
$smtpConfig['ssl'] = $mailConfig['encryption'];
|
||||
|
||||
$tr = new \Zend_Mail_Transport_Smtp($mailConfig['host'], $smtpConfig);
|
||||
$smtpConfig = array();
|
||||
if (!empty($mailConfig['type'])) {
|
||||
$smtpConfig['auth'] = strtolower($mailConfig['type']);
|
||||
}
|
||||
|
||||
if (!empty($mailConfig['username'])) {
|
||||
$smtpConfig['username'] = $mailConfig['username'];
|
||||
}
|
||||
|
||||
if (!empty($mailConfig['password'])) {
|
||||
$smtpConfig['password'] = $mailConfig['password'];
|
||||
}
|
||||
|
||||
if (!empty($mailConfig['encryption'])) {
|
||||
$smtpConfig['ssl'] = $mailConfig['encryption'];
|
||||
}
|
||||
|
||||
$host = trim($mailConfig['host']);
|
||||
$tr = new \Zend_Mail_Transport_Smtp($host, $smtpConfig);
|
||||
Mail::setDefaultTransport($tr);
|
||||
ini_set("smtp_port", $mailConfig['port']);
|
||||
@ini_set("smtp_port", $mailConfig['port']);
|
||||
}
|
||||
|
||||
public function send($transport = NULL)
|
||||
public function send($transport = null)
|
||||
{
|
||||
if (defined('PIWIK_TEST_MODE')) { // hack
|
||||
Piwik::postTestEvent("Test.Mail.send", array($this));
|
||||
|
|
@ -100,4 +126,58 @@ class Mail extends Zend_Mail
|
|||
return parent::send($transport);
|
||||
}
|
||||
}
|
||||
|
||||
public function createAttachment($body, $mimeType = null, $disposition = null, $encoding = null, $filename = null)
|
||||
{
|
||||
$filename = $this->sanitiseString($filename);
|
||||
return parent::createAttachment($body, $mimeType, $disposition, $encoding, $filename);
|
||||
}
|
||||
|
||||
public function setSubject($subject)
|
||||
{
|
||||
$subject = $this->sanitiseString($subject);
|
||||
return parent::setSubject($subject);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
* @return string
|
||||
*/
|
||||
protected function parseDomainPlaceholderAsPiwikHostName($email)
|
||||
{
|
||||
$hostname = Config::getInstance()->mail['defaultHostnameIfEmpty'];
|
||||
$piwikHost = Url::getCurrentHost($hostname);
|
||||
|
||||
// If known Piwik URL, use it instead of "localhost"
|
||||
$piwikUrl = SettingsPiwik::getPiwikUrl();
|
||||
$url = parse_url($piwikUrl);
|
||||
if ($this->isHostDefinedAndNotLocal($url)) {
|
||||
$piwikHost = $url['host'];
|
||||
}
|
||||
|
||||
return str_replace('{DOMAIN}', $piwikHost, $email);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $url
|
||||
* @return bool
|
||||
*/
|
||||
protected function isHostDefinedAndNotLocal($url)
|
||||
{
|
||||
return isset($url['host']) && !Url::isLocalHost($url['host']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces characters known to appear incorrectly in some email clients
|
||||
*
|
||||
* @param $string
|
||||
* @return mixed
|
||||
*/
|
||||
function sanitiseString($string)
|
||||
{
|
||||
$search = array('–', '’');
|
||||
$replace = array('-', '\'');
|
||||
$string = str_replace($search, $replace, $string);
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue