X-Git-Url: https://jasonwoof.com/gitweb/?p=wfpl-cms.git;a=blobdiff_plain;f=inc%2Fmisc.php;fp=inc%2Fmisc.php;h=5244635ef7cea04a83adb8514e5c6bf91910c0b7;hp=0f3d23d936ce4b8909b6081292f5a368fa71f3d8;hb=01c953a17babb9d6fedb751671d7e05bc6f33a92;hpb=9cd73aa3d18a76feb8fe640071c9e7e90abf4f8f diff --git a/inc/misc.php b/inc/misc.php index 0f3d23d..5244635 100644 --- a/inc/misc.php +++ b/inc/misc.php @@ -4,55 +4,55 @@ require_once(__DIR__.'/'.'wfpl/email.php'); # call this when you have class="unix_time" or class="unix_date" function render_timestamps() { - $GLOBALS['wfpl_main_template']->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; + # 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']); + $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']); }