|
1 | 1 | <?php |
2 | 2 |
|
3 | | -/** |
4 | | - * Core Framework - SMTP |
5 | | - * |
6 | | - * @author LaswitchTech <support@laswitchtech.com> |
7 | | - */ |
8 | | - |
9 | 3 | // Declaring namespace |
10 | 4 | namespace LaswitchTech\Core; |
11 | 5 |
|
@@ -40,6 +34,7 @@ class SMTP { |
40 | 34 | private $templates = []; |
41 | 35 | private $template; |
42 | 36 | private $path; |
| 37 | + private $vars = []; |
43 | 38 |
|
44 | 39 | /** |
45 | 40 | * Constructor |
@@ -84,6 +79,10 @@ public function __construct() |
84 | 79 | } |
85 | 80 | } |
86 | 81 | } |
| 82 | + |
| 83 | + // Add default vars |
| 84 | + $this->var('logo', 'data:'.mime_content_type($this->Config->root() . $this->logo()).';base64,' . base64_encode(file_get_contents($this->Config->root() . $this->logo()))); |
| 85 | + $this->var('brand', $this->Config->get('application','name')); |
87 | 86 | } |
88 | 87 |
|
89 | 88 | /** |
@@ -382,15 +381,77 @@ public function set(string $name): self |
382 | 381 | return $this; |
383 | 382 | } |
384 | 383 |
|
| 384 | + /** |
| 385 | + * Set a variable to be replaced in the template. |
| 386 | + * |
| 387 | + * @param string $key |
| 388 | + * @param mixed $value |
| 389 | + * @return self |
| 390 | + */ |
| 391 | + public function var(string $key, mixed $value): self |
| 392 | + { |
| 393 | + $this->vars[$key] = $value; |
| 394 | + return $this; |
| 395 | + } |
| 396 | + |
| 397 | + /** |
| 398 | + * Create a new message instance. |
| 399 | + * |
| 400 | + * @return Message |
| 401 | + */ |
385 | 402 | public function message(): Message |
386 | 403 | { |
387 | 404 | if(!$this->isAuthenticated()){ $this->authenticate(); } |
388 | 405 | $message = new Message($this->connection); |
389 | 406 | $message->template(file_get_contents($this->templates[$this->template])); |
390 | 407 | $message->from($this->username); |
| 408 | + foreach($this->vars as $key => $value){ |
| 409 | + $message->var($key, $value); |
| 410 | + } |
391 | 411 | return $message; |
392 | 412 | } |
393 | 413 |
|
| 414 | + /** |
| 415 | + * Get the logo path |
| 416 | + * |
| 417 | + * @return string |
| 418 | + */ |
| 419 | + private function logo(): string |
| 420 | + { |
| 421 | + // Import Global Variables |
| 422 | + global $CONFIG; |
| 423 | + |
| 424 | + $src = '/assets/img/logo.svg'; |
| 425 | + if(!is_file($CONFIG->root() . $src)){ |
| 426 | + $src = '/assets/img/logo.png'; |
| 427 | + } |
| 428 | + if(!is_file($CONFIG->root() . $src)){ |
| 429 | + $src = '/assets/img/logo.jpg'; |
| 430 | + } |
| 431 | + if(!is_file($CONFIG->root() . $src)){ |
| 432 | + $src = '/assets/img/logo.gif'; |
| 433 | + } |
| 434 | + if(!is_file($CONFIG->root() . $src)){ |
| 435 | + $src = '/assets/img/logo.webp'; |
| 436 | + } |
| 437 | + if(!is_file($CONFIG->root() . $src)){ |
| 438 | + $src = '/vendor/laswitchtech/core/img/logo.svg'; |
| 439 | + } |
| 440 | + if(!is_file($CONFIG->root() . $src)){ |
| 441 | + $src = '/vendor/laswitchtech/core/img/logo.png'; |
| 442 | + } |
| 443 | + if(!is_file($CONFIG->root() . $src)){ |
| 444 | + $src = '/vendor/laswitchtech/core/img/logo.jpg'; |
| 445 | + } |
| 446 | + if(!is_file($CONFIG->root() . $src)){ |
| 447 | + $src = '/vendor/laswitchtech/core/img/logo.gif'; |
| 448 | + } |
| 449 | + if(!is_file($CONFIG->root() . $src)){ |
| 450 | + $src = '/vendor/laswitchtech/core/img/logo.webp'; |
| 451 | + } |
| 452 | + return $src; |
| 453 | + } |
| 454 | + |
394 | 455 | /** |
395 | 456 | * Install the module |
396 | 457 | * |
|
0 commit comments