3 require_once(__DIR__.'/'.'wfpl/email.php');
5 # call this when you have class="unix_time" or class="unix_date"
6 function render_timestamps() {
7 $GLOBALS['wfpl_main_template']->set('$render_timestamps');
10 # helper for email_with_template() below
11 function get_email_template($slug, $template_variables, $to_addr) {
14 'subject' => $GLOBALS['email_templates'][$slug]['subject'],
15 'content' => $GLOBALS['email_templates'][$slug]['content'],
16 'from_addr' => $GLOBALS['email_templates'][$slug]['from_addr'],
21 if (isset($GLOBALS['email_templates'][$slug]['to_addr'])) {
22 $out['to_addr'] = $GLOBALS['email_templates'][$slug]['to_addr'];
24 if ($to_addr == null) {
25 die("ERROR: email_with_template(\"$slug\") needs a to_addr (put in \$GLOBALS['email_templates']['$slug'] or pass as argument)");
28 # override with DB (if it exists)
29 $row = db_get_assoc('email_templates', 'from_addr,to_addr,cc_addr,bcc_addr,subject,content', 'where slug=%"', $slug);
31 foreach($row as $key => $value) {
35 # argument wins no matter what
36 if ($to_addr !== null) {
37 $out['to_addr'] = $to_addr;
39 if (strpos($out['content'], '~') !== false) {
41 $tem->load_str($out['content']);
42 $tem->sets($template_variables);
43 $out['content'] = $tem->run();
45 if (strpos($out['subject'], '~') !== false) {
47 $tem->load_str($out['subject']);
48 $tem->sets($template_variables);
49 $out['subject'] = $tem->run();
54 # pass null as first arg if "to_addr" should come from the DB
55 function email_with_template($to_addr, $template_slug, $template_vars, $reply_to = '') {
56 $t = get_email_template($template_slug, $template_vars, $to_addr);
57 return email($t['from_addr'], $t['to_addr'], $t['subject'], $t['content'], $reply_to, $t['cc_addr'], $t['bcc_addr']);