Вход Регистрация
Файл: adultscript-2.0.3-pro/files/libraries/framework/email.php
Строк: 54
<?php
defined
('_VALID') or die('Restricted Access!');
VF::load('phpmailer.phpmailer');
class 
VEmail extends PHPMailer
{
    private 
$cfg    = array();
    private 
$emails = array();
    public function 
__construct()
    {
        
$this->cfg VF::cfg('core.config');
        if (
$this->cfg['mailer'] == 'mail') {
            
$this->Mailer   'mail';
        } elseif (
$this->cfg['mailer'] == 'sendmail') {
            
$this->Mailer   'sendmail';
            
$this->Sendmail $this->cfg['sendmail_path'];
        } elseif (
$this->cfg['mailer'] == 'smtp') {
            
$this->Mailer       'smtp';
            
$this->Host         $this->cfg['smtp_host'];
            
$this->Port         $this->cfg['smtp_port'];
            
$this->SMTPSecure   $this->cfg['smtp_prefix'];
            if (
$this->cfg['smtp_auth'] == '1') {
                
$this->SMTPAuth TRUE;
                
$this->Username $this->cfg['smtp_username'];
                
$this->Password $this->cfg['smtp_password'];
            }
        } else {
            
$this->Mailer 'mail';
        }

        
$this->WordWrap 75;
        
$this->IsHTML(TRUE);
    }
    
    public function 
predefined($id$email$search=array(), $replace = array(), $type='noreply')
    {
        if (!
$this->emails) {
            
$this->emails $this->get_emails();
        }
    
        if (isset(
$this->emails[$id])) {
            
$subject    $this->emails[$id];
            
$cache        VF::factory('cache');
            
$cache_id    'email_'.$id;
            if (!
$message $cache->get($cache_id0)) {
                
$db =& VF::factory('database');
                
$db->query("SELECT message
                            FROM #__email
                            WHERE name = '"
.$db->escape($id)."'
                            LIMIT 1"
);
                if (!
$db->affected_rows()) {
                    return;
                }
                
                
$message $db->fetch_field('message');
                
$cache->store($cache_id$message0);
            }
            
            if (
$search && $replace) {
                
$subject     str_replace($search$replace$subject);
                
$message    str_replace($search$replace$message);
            }

            if (
$type == 'noreply') {
                
$this->setNoReply();
            } elseif (
$type 'admin') {
                
$this->setAdmin();
            } elseif (
$type 'site') {
                
$this->setSite();
            }
            
            
$this->Subject    $subject;
            
$this->AltBody    $message;
            
$this->Body        nl2br($message);
            if (
is_array($email)) {
                foreach (
$email as $address) {
                    
$this->AddAddress($address);
                    
$this->Send();
                    
$this->ClearAddresses();
                }
            } else {
                
$this->AddAddress($email);
                if (
$this->Send()) {
                    return 
TRUE;
                }
                
                return 
FALSE;
            }
        }
    }

    public function 
setNoReply()
    {
        
$this->From     $this->cfg['email_noreply'];
        
$this->FromName $this->cfg['site_name'];
        
$this->Sender   $this->cfg['email_noreply'];
        
$this->AddReplyTo($this->cfg['email_noreply'], $this->cfg['site_name']);
    }
    
    public function 
setAdmin()
    {
        
$this->From     $this->cfg['email_admin'];
        
$this->FromName $this->cfg['site_name'];
        
$this->Sender   $this->cfg['email_admin'];
        
$this->AddReplyTo($this->cfg['email_admin'], $this->cfg['site_name']);    
    }
    
    public function 
setSite()
    {
        
$this->From     $this->cfg['email_site'];
        
$this->FromName $this->cfg['site_name'];
        
$this->Sender   $this->cfg['email_site'];
        
$this->AddReplyTo($this->cfg['email_site'], $this->cfg['site_name']);    
    }
    
    private function 
get_emails()
    {
        
$cache VF::factory('cache');
        if (!
$emails $cache->get('email_ids')) {
            
$db VF::factory('database');
            
$db->query("SELECT name, subject FROM #__email WHERE status = '1'");
            if (
$db->affected_rows()) {
                
$rows   $db->fetch_rows();
                
$emails = array();
                foreach (
$rows as $row) {
                    
$emails[$row['name']] = $row['subject'];
                }
                
                
$cache->store('emails'$emails0);
            } else {
                die(
'Failed to cache email ids!');
            }
        }
        
        return 
$emails;
    }
}
?>
Онлайн: 0
Реклама