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."'"; $t=$this->db->getFetchMode(); $this->db->setFetchMode(Zend_Db::FETCH_ASSOC); $rs = $this->db->query($sql); $this->db->setFetchMode($t); $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($this->tmpinfo['subject'])) { $this->getinfo(); } 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); $this->tmpinfo['subject'] = preg_replace($patterns, $replacements, $this->tmpinfo['subject']); 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']; } }