use Galette\Entity\Social;
use Galette\Features\Replacements;
use Galette\Features\Socials;
+use PHPMailer\PHPMailer\PHPMailer;
use Throwable;
use Analog\Analog;
use Galette\Entity\Adherent;
/**
* Get email signature
*
+ * @param PHPMailer $mail PHPMailer instance
+ *
* @return string
*/
- public function getMailSignature(): string
+ public function getMailSignature(PHPMailer $mail): string
{
global $routeparser;
$this->getMainPatterns() + $this->getSignaturePatterns()
);
$this
+ ->setMail($mail)
->setMain()
->setSocialReplacements();
use Galette\DynamicFields\DynamicField;
use Analog\Analog;
use NumberFormatter;
+use PHPMailer\PHPMailer\PHPMailer;
use Slim\Routing\RouteParser;
/**
private $patterns = [];
private $replaces = [];
private $dynamic_patterns = [];
+ private ?PHPMailer $mail = null;
/**
* @var Db
return $c_patterns + $dynamic_patterns;
}
+ /**
+ * Set mail instance
+ *
+ * @param PHPMailer $mail PHPMailer instance
+ *
+ * @return self
+ */
+ public function setMail(PHPMailer $mail): self
+ {
+ $this->mail = $mail;
+ return $this;
+ }
+
/**
* Set main replacements
*
}
$logo = new Logo();
-
+ if ($this->mail !== null) {
+ $logo_content = $this->preferences->getURL() . $this->routeparser->urlFor('logo');
+ } else {
+ $logo_content = '@' . base64_encode(file_get_contents($logo->getPath()));
+ }
$logo_elt = sprintf(
- '<img src="%1$s" width="%2$s" height="%3$s" />',
- '@' . base64_encode(file_get_contents($logo->getPath())),
+ '<img src="%1$s" width="%2$s" height="%3$s" alt="" />',
+ $logo_content,
$logo->getOptimalWidth(),
$logo->getOptimalHeight()
);
$replaced
);
- return $replaced;
+ return trim($replaced);
}
/**
namespace Galette\Core\test\units;
+use PHPMailer\PHPMailer\PHPMailer;
use PHPUnit\Framework\TestCase;
/**
*/
public function testGetMailSignature()
{
- $this->assertSame("\r\n-- \r\nGalette\r\n\r\n", $this->preferences->getMailSignature());
+ $mail = new PHPMailer();
+ $this->assertSame("\r\n-- \r\nGalette", $this->preferences->getMailSignature($mail));
$this->preferences->pref_website = 'https://galette.eu';
- $this->assertSame("\r\n-- \r\nGalette\r\n\r\nhttps://galette.eu", $this->preferences->getMailSignature());
+ $this->assertSame(
+ "\r\n-- \r\nGalette\r\n\r\nhttps://galette.eu",
+ $this->preferences->getMailSignature($mail)
+ );
//with legacy values
- $this->preferences->pref_mailsign = "NAME}\r\n\r\n{WEBSITE}\r\n{GOOGLEPLUS}\r\n{FACEBOOK}\r\n{TWITTER}\r\n{LINKEDIN}\r\n{VIADEO}";
- $this->assertSame("\r\n-- \r\nGalette\r\n\r\nhttps://galette.eu", $this->preferences->getMailSignature());
+ $this->preferences->pref_mail_sign = "{NAME}\r\n\r\n{WEBSITE}\r\n{FACEBOOK}\r\n{TWITTER}\r\n{LINKEDIN}\r\n{VIADEO}";
+ $this->assertSame(
+ "\r\n-- \r\nGalette\r\n\r\nhttps://galette.eu",
+ $this->preferences->getMailSignature($mail)
+ );
$social = new \Galette\Entity\Social($this->zdb);
$this->assertTrue(
);
$this->preferences->pref_mail_sign = "{ASSO_NAME}\r\n\r\n{ASSO_WEBSITE} - {ASSO_SOCIAL_MASTODON}";
- $this->assertSame("\r\n-- \r\nGalette\r\n\r\nhttps://galette.eu - https://framapiaf.org/@galette", $this->preferences->getMailSignature());
+ $this->assertSame(
+ "\r\n-- \r\nGalette\r\n\r\nhttps://galette.eu - https://framapiaf.org/@galette",
+ $this->preferences->getMailSignature($mail)
+ );
$social = new \Galette\Entity\Social($this->zdb);
$this->assertTrue(
2,
\Galette\Entity\Social::getListForMember(null, \Galette\Entity\Social::MASTODON)
);
- $this->assertSame("\r\n-- \r\nGalette\r\n\r\nhttps://galette.eu - https://framapiaf.org/@galette, Galette mastodon URL - the return", $this->preferences->getMailSignature());
+ $this->assertSame(
+ "\r\n-- \r\nGalette\r\n\r\nhttps://galette.eu - https://framapiaf.org/@galette, Galette mastodon URL - the return",
+ $this->preferences->getMailSignature($mail)
+ );
}
/**