Proyectos de Subversion LeadersLinked - Services

Rev

Rev 156 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Library;
6
 
7
use Laminas\Db\Adapter\AdapterInterface;
8
 
9
use LeadersLinked\Model\EmailTemplate;
10
use LeadersLinked\Model\Email;
11
use LeadersLinked\Mapper\EmailMapper;
12
 
13
class QueueEmail
14
{
15
 
16
    /**
17
     *
18
     * @var AdapterInterface
19
     */
20
    private $adapter;
21
 
22
 
23
    /**
24
     *
25
     * @param AdapterInterface $adapter
26
     */
27
    public function __construct($adapter)
28
    {
29
        $this->adapter = $adapter;
30
    }
31
 
32
    /**
33
     *
34
     * @param EmailTemplate $emailTemplate
35
     * @param array $arrayCont
36
     * @param string $to_address
37
     * @param string $to_name
38
     * @return boolean
39
     */
40
    public function processEmailTemplate($emailTemplate, $arrayCont, $to_address, $to_name)
41
    {
42
 
43
        $subject = trim(stripslashes($emailTemplate->subject));
44
        $message = trim(stripslashes($emailTemplate->content));
45
 
46
 
47
 
48
        foreach($arrayCont as $key => $val)
49
        {
156 efrain 50
 
51
            if('link' == $key) {
52
 
53
 
54
                $from_hostname = empty($_SERVER['HTTP_HOST']) ?  '' : $_SERVER['HTTP_HOST'];
182 efrain 55
                $from_hostname = str_replace('https://', '', $from_hostname);
56
 
57
 
156 efrain 58
                $to_hostname = empty($_SERVER['HTTP_ORIGIN']) ? '' : $_SERVER['HTTP_ORIGIN'];
182 efrain 59
 
156 efrain 60
 
61
                if(empty($to_hostname)) {
62
 
63
                    $to_hostname = empty($_SERVER['HTTP_REFERER']) ?  '' : $_SERVER['HTTP_REFERER'];
64
 
65
                }
182 efrain 66
                $to_hostname = str_replace('https://', '', $to_hostname);
156 efrain 67
 
68
                if($from_hostname && $to_hostname) {
69
                    $val = str_replace($from_hostname, $to_hostname, $val);
70
                }
71
 
72
 
182 efrain 73
 
156 efrain 74
            }
75
 
76
 
77
 
1 efrain 78
            $message = str_replace('[' . $key .']', $val, $message);
79
            $subject = str_replace('[' . $key .']', $val, $subject);
80
        }
81
 
82
        $email = new Email();
83
        $email->content = json_encode([
84
            'to_address' => $to_address,
85
            'to_name' => $to_name,
86
            'cc' => [],
87
            'bcc' => [],
88
            'subject' => $subject,
89
            'message' => $message,
90
        ]);
91
        $email->status = Email::STATUS_PENDING;
92
        $email->tried = 0;
93
 
94
        $emailMapper = EmailMapper::getInstance($this->adapter);
95
        return $emailMapper->insert($email);
96
 
97
 
98
    }
99
 
100
 
101
}