Exemplo n.º 1
0
if (isset($param["city"])) {
    $geonameid = hebcal_city_to_geoname($param["city"]);
    unset($param["city"]);
    if ($geonameid !== false) {
        $param["geonameid"] = $geonameid;
    }
}
if (isset($param["geonameid"]) && is_numeric($param["geonameid"])) {
    $geonameid = $param["geonameid"];
    $geo = "geoname";
    $city_descr = my_geoname_city_descr($geonameid);
    $geo_link = "geonameid={$geonameid}";
} elseif (isset($param["zip"]) && is_numeric($param["zip"])) {
    $zip = $param["zip"];
    $geo = "zip";
    list($city, $state, $tzid, $latitude, $longitude, $lat_deg, $lat_min, $long_deg, $long_min) = hebcal_get_zipcode_fields($zip);
    $city_descr = "{$city}, {$state} {$zip}";
    $geo_link = "zip={$zip}";
} else {
    $geonameid = 281184;
    $geo = "geoname";
    $city_descr = my_geoname_city_descr($geonameid);
    $geo_link = "geonameid={$geonameid}";
}
if (empty($param["city-typeahead"])) {
    $param["city-typeahead"] = $city_descr;
}
if (isset($param["a"]) && ($param["a"] == "1" || $param["a"] == "on")) {
    $geo_link .= "&a=on";
    $ashk = " checked";
} else {
Exemplo n.º 2
0
function subscribe($param)
{
    global $sender;
    if (preg_match('/\\@hebcal.com$/', $param["em"])) {
        form($param, "Sorry, can't use a <strong>hebcal.com</strong> email address.");
    }
    if ($param["geo"] == "zip") {
        if (!$param["zip"]) {
            form($param, "Please enter your zip code for candle lighting times.");
        }
        if (!preg_match('/^\\d{5}$/', $param["zip"])) {
            form($param, "Sorry, <strong>" . htmlspecialchars($param["zip"]) . "</strong> does\n" . "not appear to be a 5-digit zip code.");
        }
        list($city, $state, $tzid, $latitude, $longitude, $lat_deg, $lat_min, $long_deg, $long_min) = hebcal_get_zipcode_fields($param["zip"]);
        if (!$state) {
            form($param, "Sorry, can't find\n" . "<strong>" . htmlspecialchars($param["zip"]) . "</strong> in the zip code database.\n", "<ul><li>Please try a nearby zip code</li></ul>");
        }
        $city_descr = "{$city}, {$state} " . $param["zip"];
        unset($param["city"]);
        unset($param["geonameid"]);
    } elseif ($param["geo"] == "geoname") {
        if (!$param["geonameid"]) {
            form($param, "Please search for your city for candle lighting times.");
        }
        if (!preg_match('/^\\d+$/', $param["geonameid"])) {
            form($param, "Sorry, <strong>" . htmlspecialchars($param["geonameid"]) . "</strong> does\n" . "not appear to be a valid geonameid.");
        }
        list($name, $asciiname, $country, $admin1, $latitude, $longitude, $tzid) = hebcal_get_geoname($param["geonameid"]);
        if (!isset($tzid)) {
            form($param, "Sorry, <strong>" . htmlspecialchars($param["geonameid"]) . "</strong> is\n" . "not a recoginized geonameid.");
        }
        $city_descr = geoname_city_descr($name, $admin1, $country);
        unset($param["zip"]);
        unset($param["city"]);
    } else {
        $param["geo"] = "geoname";
        form($param, "Sorry, missing location (zip, geonameid) field.");
    }
    // check for old sub
    if (isset($param["prev"]) && $param["prev"] != $param["em"]) {
        $info = get_sub_info($param["prev"], false);
        if (isset($info["status"]) && $info["status"] == "active") {
            sql_unsub($param["prev"]);
        }
    }
    // check if email address already verified
    $info = get_sub_info($param["em"], false);
    if (isset($info["status"]) && $info["status"] == "active") {
        write_sub_info($param);
        $from_name = "Hebcal";
        $from_addr = "*****@*****.**";
        $reply_to = "*****@*****.**";
        $subject = "Your subscription is updated";
        global $remoteAddr;
        $ip = $remoteAddr;
        $unsub_addr = "shabbat-unsubscribe+" . $info["id"] . "@hebcal.com";
        $headers = array("From" => "\"{$from_name}\" <{$from_addr}>", "To" => $param["em"], "Reply-To" => $reply_to, "List-Unsubscribe" => "<mailto:{$unsub_addr}>", "MIME-Version" => "1.0", "Content-Type" => "text/html; charset=UTF-8", "X-Sender" => $sender, "X-Mailer" => "hebcal web", "Message-ID" => "<Hebcal.Web." . time() . "." . posix_getpid() . "@hebcal.com>", "X-Originating-IP" => "[{$ip}]", "Subject" => $subject);
        $body = <<<EOD
<div dir="ltr">
<div>Hello,</div>
<div><br></div>
<div>We have updated your weekly Shabbat candle lighting time
subscription for {$city_descr}.</div>
<div><br></div>
<div>Regards,
<br>hebcal.com</div>
<div><br></div>
<div>To unsubscribe from this list, send an email to:
<br><a href="mailto:shabbat-unsubscribe@hebcal.com">shabbat-unsubscribe@hebcal.com</a></div>
</div>
EOD;
        $err = smtp_send(get_return_path($param["em"]), $param["em"], $headers, $body);
        $html_email = htmlentities($param["em"]);
        $html = <<<EOD
<div class="alert alert-success">
<strong>Success!</strong> Your subsciption information has been updated.
<p>Email: <strong>{$html_email}</strong>
<br>Location: {$city_descr}</p>
</div>
EOD;
        echo $html;
        return true;
    }
    if (isset($info["status"]) && $info["status"] == "pending" && isset($info["id"])) {
        $old_encoded = $info["id"];
    } else {
        $old_encoded = null;
    }
    $encoded = write_staging_info($param, $old_encoded);
    $from_name = "Hebcal";
    $from_addr = "*****@*****.**";
    $subject = "Please confirm your request to subscribe to hebcal";
    global $remoteAddr;
    $ip = $remoteAddr;
    $headers = array("From" => "\"{$from_name}\" <{$from_addr}>", "To" => $param["em"], "MIME-Version" => "1.0", "Content-Type" => "text/html; charset=UTF-8", "X-Sender" => $sender, "X-Mailer" => "hebcal web", "Message-ID" => "<Hebcal.Web." . time() . "." . posix_getpid() . "@hebcal.com>", "X-Originating-IP" => "[{$ip}]", "Subject" => $subject);
    $url_prefix = "https://" . $_SERVER["HTTP_HOST"];
    $body = <<<EOD
<div dir="ltr">
<div>Hello,</div>
<div><br></div>
<div>We have received your request to receive weekly Shabbat
candle lighting time information from hebcal.com for
{$city_descr}.</div>
<div><br></div>
<div>Please confirm your request by clicking on this link:</div>
<div><br></div>
<div><a href="{$url_prefix}/email/verify.php?{$encoded}">{$url_prefix}/email/verify.php?{$encoded}</a></div>
<div><br></div>
<div>If you did not request (or do not want) weekly Shabbat
candle lighting time information, please accept our
apologies and ignore this message.</div>
<div><br></div>
<div>Regards,
<br>hebcal.com</div>
<div><br></div>
<div>[{$remoteAddr}]</div>
</div>
EOD;
    $err = smtp_send(get_return_path($param["em"]), $param["em"], $headers, $body);
    $html_email = htmlentities($param["em"]);
    if ($err === true) {
        $html = <<<EOD
<div class="alert alert-success">
<strong>Thank you!</strong>
A confirmation message has been sent
to <strong>{$html_email}</strong> for {$city_descr}.<br>
Click the link within that message to confirm your subscription.
</div>
<p>If you do not receive this acknowledgment message within an hour
or two, then the most likely problem is that you made a typo
in your email address.  If you do not get the confirmation message,
please return to the subscription page and try again, taking care
to avoid typos.</p>
EOD;
    } else {
        $html = <<<EOD
<div class="alert alert-danger">
<h4>Server Error</h4>
Sorry, we are temporarily unable to send email
to <strong>{$html_email}</strong>.
</div>
<p>Please try again in a few minutes.</p>
<p>If the problem persists, please send email to
<a href="mailto:webmaster&#64;hebcal.com">webmaster&#64;hebcal.com</a>.</p>
EOD;
    }
    echo $html;
}