X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=inc%2Fmisc.php;h=5244635ef7cea04a83adb8514e5c6bf91910c0b7;hb=01c953a17babb9d6fedb751671d7e05bc6f33a92;hp=429482d9fc7fd90a877ac08e070791536a92f131;hpb=15f391c463f08014a2af7b80920c4832877ad09f;p=wfpl-cms.git diff --git a/inc/misc.php b/inc/misc.php index 429482d..5244635 100644 --- a/inc/misc.php +++ b/inc/misc.php @@ -1,6 +1,58 @@ set('$render_timestamps'); + $GLOBALS['wfpl_main_template']->set('$render_timestamps'); +} + +# helper for email_with_template() below +function get_email_template($slug, $template_variables, $to_addr) { + # defaults + $out = array( + 'subject' => $GLOBALS['email_templates'][$slug]['subject'], + 'content' => $GLOBALS['email_templates'][$slug]['content'], + 'from_addr' => $GLOBALS['email_templates'][$slug]['from_addr'], + 'to_addr' => '', + 'cc_addr' => '', + 'bcc_addr' => '' + ); + if (isset($GLOBALS['email_templates'][$slug]['to_addr'])) { + $out['to_addr'] = $GLOBALS['email_templates'][$slug]['to_addr']; + } else { + if ($to_addr == null) { + die("ERROR: email_with_template(\"$slug\") needs a to_addr (put in \$GLOBALS['email_templates']['$slug'] or pass as argument)"); + } + } + # override with DB (if it exists) + $row = db_get_assoc('email_templates', 'from_addr,to_addr,cc_addr,bcc_addr,subject,content', 'where slug=%"', $slug); + if ($row) { + foreach($row as $key => $value) { + $out[$key] = $value; + } + } + # argument wins no matter what + if ($to_addr !== null) { + $out['to_addr'] = $to_addr; + } + if (strpos($out['content'], '~') !== false) { + $tem = new tem(); + $tem->load_str($out['content']); + $tem->sets($template_variables); + $out['content'] = $tem->run(); + } + if (strpos($out['subject'], '~') !== false) { + $tem = new tem(); + $tem->load_str($out['subject']); + $tem->sets($template_variables); + $out['subject'] = $tem->run(); + } + return $out; +} + +# pass null as first arg if "to_addr" should come from the DB +function email_with_template($to_addr, $template_slug, $template_vars, $reply_to = '') { + $t = get_email_template($template_slug, $template_vars, $to_addr); + return email($t['from_addr'], $t['to_addr'], $t['subject'], $t['content'], $reply_to, $t['cc_addr'], $t['bcc_addr']); }