]> git.agnieray.net Git - galette.git/commitdiff
Ensure logo is send in emails; closes #1783
authorJohan Cwiklinski <johan@x-tnd.be>
Wed, 14 Feb 2024 17:36:58 +0000 (18:36 +0100)
committerJohan Cwiklinski <johan@x-tnd.be>
Thu, 15 Feb 2024 07:27:34 +0000 (08:27 +0100)
galette/lib/Galette/Core/GaletteMail.php
galette/lib/Galette/Core/Preferences.php
galette/lib/Galette/Features/Replacements.php
tests/Galette/Core/tests/units/Preferences.php
tests/Galette/Entity/tests/units/PdfModel.php

index 18517c8dd2b0b521df3755b566d480c2da49613c..db30634db12587906d2b9a17d8e8f4a6b0f8e779 100644 (file)
@@ -294,7 +294,7 @@ class GaletteMail
             );
         }
 
-        $signature = $this->preferences->getMailSignature();
+        $signature = $this->preferences->getMailSignature($this->mail);
         if ($signature != '') {
             if ($this->html) {
                 //we are sending html message
index 504486573f499a55462d0fddeeb65456c595d031..03c4f17c93c8352878672a92f1bec045d18b8583 100644 (file)
@@ -39,6 +39,7 @@ use Galette\Entity\PaymentType;
 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;
@@ -1228,9 +1229,11 @@ class Preferences
     /**
      * Get email signature
      *
+     * @param PHPMailer $mail PHPMailer instance
+     *
      * @return string
      */
-    public function getMailSignature(): string
+    public function getMailSignature(PHPMailer $mail): string
     {
         global $routeparser;
 
@@ -1245,6 +1248,7 @@ class Preferences
             $this->getMainPatterns() + $this->getSignaturePatterns()
         );
         $this
+            ->setMail($mail)
             ->setMain()
             ->setSocialReplacements();
 
index 767c52cdf7c268e20de1c3b45e502d673e16adac..8f25d717138c20b578edc2dff161b25cf4520217 100644 (file)
@@ -51,6 +51,7 @@ use Galette\Repository\DynamicFieldsSet;
 use Galette\DynamicFields\DynamicField;
 use Analog\Analog;
 use NumberFormatter;
+use PHPMailer\PHPMailer\PHPMailer;
 use Slim\Routing\RouteParser;
 
 /**
@@ -71,6 +72,7 @@ trait Replacements
     private $patterns = [];
     private $replaces = [];
     private $dynamic_patterns = [];
+    private ?PHPMailer $mail = null;
 
     /**
      * @var Db
@@ -466,6 +468,19 @@ trait Replacements
         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
      *
@@ -483,10 +498,14 @@ trait 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()
         );
@@ -913,7 +932,7 @@ trait Replacements
             $replaced
         );
 
-        return $replaced;
+        return trim($replaced);
     }
 
     /**
index afe9f5b63a989eb6c09ab0fb68c50b22e0939117..f5a492cc030b14206529dc7910abaa70beb8d556 100644 (file)
@@ -36,6 +36,7 @@
 
 namespace Galette\Core\test\units;
 
+use PHPMailer\PHPMailer\PHPMailer;
 use PHPUnit\Framework\TestCase;
 
 /**
@@ -563,14 +564,21 @@ class Preferences extends 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(
@@ -586,7 +594,10 @@ class Preferences extends TestCase
         );
 
         $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(
@@ -600,7 +611,10 @@ class Preferences extends TestCase
             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)
+        );
     }
 
     /**
index 07d097a5ca3ca18ba4e0f4565368ec0363870749..9221379cd1f79bb3750beb22395f0781fdcbe735 100644 (file)
@@ -334,7 +334,7 @@ class PdfModel extends GaletteTestCase
         );
 
         $this->assertMatchesRegularExpression(
-            '/<td id="pdf_logo"><img src="@.+" width="129" height="60" \/><\/td>/',
+            '/<td id="pdf_logo"><img src="@.+" width="129" height="60" alt="" \/><\/td>/',
             $model->hheader
         );