74 lines
1.4 KiB
PHP
74 lines
1.4 KiB
PHP
<?php
|
|
class EmailText{
|
|
private $tmpid;
|
|
private $db;
|
|
private $data;
|
|
protected $tmpinfo;
|
|
|
|
function __construct($db,$id,$replace)
|
|
{
|
|
$this->db=$db;
|
|
$this->tmpid=$id;
|
|
$this->data=$replace;
|
|
$this->load();
|
|
}
|
|
|
|
protected function getinfo(){
|
|
|
|
if(is_numeric($this->tmpid))
|
|
$sql = "select * from emailtext where id='".$this->tmpid."'";
|
|
else
|
|
$sql = "select * from emailtext where template='".$this->tmpid."'";
|
|
|
|
$rs = $this->db->query($sql);
|
|
|
|
$this->tmpinfo = $rs->fetch();
|
|
|
|
}
|
|
|
|
public function load($body=''){
|
|
|
|
if(empty($this->tmpid))
|
|
{
|
|
return false;
|
|
}else{
|
|
if (empty($body))
|
|
{
|
|
$this->getinfo();
|
|
$body=$this->tmpinfo['body'];
|
|
}
|
|
|
|
if(!empty($body))
|
|
{
|
|
if(count($this->data)==0)
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
$patterns = array();
|
|
$replacements = array();
|
|
foreach($this->data as $k=>$v)
|
|
{
|
|
$patterns[]='/{'.$k.'}/i';
|
|
$replacements[]=$v;
|
|
}
|
|
ksort($patterns);
|
|
ksort($replacements);
|
|
$this->tmpinfo['body']=preg_replace($patterns, $replacements, $body);
|
|
return true;
|
|
}//count($this->data)
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}//empty($this->tmpid)
|
|
}//function loadtmp
|
|
public function getBody() {
|
|
return $this->tmpinfo['body'];
|
|
}
|
|
public function getSubject() {
|
|
return $this->tmpinfo['subject'];
|
|
}
|
|
} |