function parse_value($sv, $name, $info) { global $Conf, $Me, $Now, $Opt; if (!isset($sv->req[$name])) { $xname = str_replace(".", "_", $name); if (isset($sv->req[$xname])) { $sv->req[$name] = $sv->req[$xname]; } else { if ($info->type === "checkbox" || $info->type === "cdate") { return 0; } else { return null; } } } $v = trim($sv->req[$name]); if ($info->placeholder && $info->placeholder === $v || $info->invalid_value && $info->invalid_value === $v) { $v = ""; } if ($info->type === "checkbox") { return $v != "" ? 1 : 0; } else { if ($info->type === "cdate" && $v == "1") { return 1; } else { if ($info->type === "date" || $info->type === "cdate" || $info->type === "ndate") { if ($v == "" || !strcasecmp($v, "N/A") || !strcasecmp($v, "same as PC") || $v == "0" || $info->type !== "ndate" && !strcasecmp($v, "none")) { return -1; } else { if (!strcasecmp($v, "none")) { return 0; } else { if (($v = $Conf->parse_time($v)) !== false) { return $v; } else { $err = unparse_setting_error($info, "Invalid date."); } } } } else { if ($info->type === "grace") { if (($v = parseGrace($v)) !== null) { return intval($v); } else { $err = unparse_setting_error($info, "Invalid grace period."); } } else { if ($info->type === "int" || $info->type === "zint") { if (preg_match("/\\A[-+]?[0-9]+\\z/", $v)) { return intval($v); } else { $err = unparse_setting_error($info, "Should be a number."); } } else { if ($info->type === "string") { // Avoid storing the default message in the database if (substr($name, 0, 9) == "mailbody_") { $t = expandMailTemplate(substr($name, 9), true); $v = cleannl($v); if ($t["body"] == $v) { return ""; } } return $v; } else { if ($info->type === "simplestring") { return simplify_whitespace($v); } else { if ($info->type === "tag" || $info->type === "tagbase") { $tagger = new Tagger($Me); $v = trim($v); if ($v === "" && $info->optional) { return $v; } $v = $tagger->check($v, $info->type === "tagbase" ? Tagger::NOVALUE : 0); if ($v) { return $v; } $err = unparse_setting_error($info, $tagger->error_html); } else { if ($info->type === "emailheader") { $v = MimeText::encode_email_header("", $v); if ($v !== false) { return $v == "" ? "" : MimeText::decode_header($v); } $err = unparse_setting_error($info, "Invalid email header."); } else { if ($info->type === "emailstring") { $v = trim($v); if ($v === "" && $info->optional) { return ""; } else { if (validate_email($v) || $v === $v_active) { return $v; } else { $err = unparse_setting_error($info, "Invalid email."); } } } else { if ($info->type === "urlstring") { $v = trim($v); if ($v === "" && $info->optional || preg_match(',\\A(?:https?|ftp)://\\S+\\z,', $v)) { return $v; } else { $err = unparse_setting_error($info, "Invalid URL."); } } else { if ($info->type === "htmlstring") { if (($v = CleanHTML::basic_clean($v, $err)) === false) { $err = unparse_setting_error($info, $err); } else { if ($info->message_default && $v === $Conf->message_default_html($info->message_default)) { return ""; } else { return $v; } } } else { if ($info->type === "radio") { foreach ($info->values as $allowedv) { if ((string) $allowedv === $v) { return $allowedv; } } $err = unparse_setting_error($info, "Parse error (unexpected value)."); } else { return $v; } } } } } } } } } } } } } $sv->set_error($name, $err); return null; }
static function send_preparation($prep) { global $Conf, $Opt; if (!isset($Opt["internalMailer"])) { $Opt["internalMailer"] = strncasecmp(PHP_OS, "WIN", 3) != 0; } $headers = $prep->headers; // create valid To: header $to = $prep->to; if (is_array($to)) { $to = join(", ", $to); } $to = MimeText::encode_email_header("To: ", $to); $headers["to"] = $to . MAILER_EOL; // set sendmail parameters $extra = get_s($Opt, "sendmailParam"); if (isset($Opt["emailSender"])) { @ini_set("sendmail_from", $Opt["emailSender"]); if (!isset($Opt["sendmailParam"])) { $extra = "-f" . escapeshellarg($Opt["emailSender"]); } } if ($prep->sendable && $Opt["internalMailer"] && ($sendmail = ini_get("sendmail_path"))) { $htext = join("", $headers); $f = popen($extra ? "{$sendmail} {$extra}" : $sendmail, "wb"); fwrite($f, $htext . MAILER_EOL . $prep->body); $status = pclose($f); if (pcntl_wifexited($status) && pcntl_wexitstatus($status) == 0) { return true; } else { $Opt["internalMailer"] = false; error_log("Mail " . $headers["to"] . " failed to send, falling back (status {$status})"); } } if ($prep->sendable) { if (strpos($to, MAILER_EOL) === false) { unset($headers["to"]); $to = substr($to, 4); // skip "To: " } else { $to = ""; } unset($headers["subject"]); $htext = substr(join("", $headers), 0, -2); return mail($to, $prep->subject, $prep->body, $htext, $extra); } else { if (!$Opt["sendEmail"] && !preg_match('/\\Aanonymous\\d*\\z/', $to)) { unset($headers["mime-version"], $headers["content-type"]); $text = join("", $headers) . MAILER_EOL . $prep->body; if (PHP_SAPI == "cli" && !get($Opt, "disablePrintEmail")) { fwrite(STDERR, "========================================\n" . str_replace("\r\n", "\n", $text) . "========================================\n"); } else { $Conf->infoMsg("<pre>" . htmlspecialchars($text) . "</pre>"); } return null; } } }