STW: add checkbox to subscribe to newsletter (#1061)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -2,16 +2,53 @@
|
||||
// This script signs up an email address with other (partly optional) data
|
||||
// to the community database (occasional emails) and the newsletter
|
||||
|
||||
// Available POST params: list, mail, name, language, address, zip, city, country
|
||||
// parse data from POST or cli arg
|
||||
if (php_sapi_name() === 'cli') {
|
||||
$data = json_decode($argv[1], true);
|
||||
} else {
|
||||
$data = $_POST;
|
||||
}
|
||||
|
||||
$list = isset($_POST['list']) ? $_POST['list'] : false;
|
||||
$mail = isset($_POST['mail']) ? $_POST['mail'] : false;
|
||||
$name = isset($_POST['name']) ? $_POST['name'] : false;
|
||||
$language = isset($_POST['language']) ? $_POST['language'] : false;
|
||||
$address = isset($_POST['address']) ? $_POST['address'] : false;
|
||||
$zip = isset($_POST['zip']) ? $_POST['zip'] : false;
|
||||
$city = isset($_POST['city']) ? $_POST['city'] : false;
|
||||
$country = isset($_POST['country']) ? $_POST['country'] : false;
|
||||
$list = $data['list'] ?? false;
|
||||
$mail = $data['mail'] ?? false;
|
||||
$name = $data['name'] ?? false;
|
||||
$lang = $data['lang'] ?? false;
|
||||
$address = $data['address'] ?? false;
|
||||
$zip = $data['zip'] ?? false;
|
||||
$city = $data['city'] ?? false;
|
||||
$country = $data['country'] ?? false;
|
||||
|
||||
# Generic function to make POST request
|
||||
function mail_signup($url, $data) {
|
||||
$context = stream_context_create(
|
||||
array(
|
||||
'http' => array(
|
||||
'method' => 'POST',
|
||||
'header' => 'Content-type: application/x-www-form-urlencoded',
|
||||
'user_agent' => 'FSFE mail-signup.php',
|
||||
'content' => http_build_query($data),
|
||||
'timeout' => 10
|
||||
)
|
||||
)
|
||||
);
|
||||
// DEBUG: set a local URL here to catch the requests
|
||||
file_get_contents($url, FALSE, $context);
|
||||
}
|
||||
|
||||
# Function to scrape the subscribe token from newsletter signup forms
|
||||
function get_token($url) {
|
||||
$file = file_get_contents($url);
|
||||
$html = new DOMDocument();
|
||||
libxml_use_internal_errors(true);
|
||||
$html->loadHTML($file);
|
||||
libxml_clear_errors();
|
||||
$xpath = new DOMXPath($html);
|
||||
|
||||
$results = $xpath->query("//form/input[@name='sub_form_token']/@value");
|
||||
foreach ($results as $result) {
|
||||
return $result->nodeValue;
|
||||
}
|
||||
}
|
||||
|
||||
# Check required variables
|
||||
if (empty($list) ||
|
||||
@@ -20,7 +57,15 @@ if (empty($list) ||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ($list == 'community' ) {
|
||||
# Check whether language is available as newsletter
|
||||
$nllangs = array("be", "de", "el", "en", "es", "fi", "fr", "it", "nl", "pt", "ro", "ru", "sq", "sv");
|
||||
if (in_array($lang, $nllangs)) {
|
||||
$nllang = $lang;
|
||||
} else {
|
||||
$nllang = "en";
|
||||
}
|
||||
|
||||
if ($list == 'community' ) { // COMMUNITY
|
||||
# "name" is also required for Community Database
|
||||
if (empty($name)) {
|
||||
echo "Missing parameters. Required: name";
|
||||
@@ -34,27 +79,22 @@ if ($list == 'community' ) {
|
||||
'city' => $city,
|
||||
'country' => $country
|
||||
);
|
||||
print_r($signupdata);
|
||||
mail_signup('https://my.fsfe.org/subscribe', $signupdata);
|
||||
} elseif ($list == 'newsletter') {
|
||||
echo "";
|
||||
} elseif ($list == 'newsletter') { // NEWSLETTER
|
||||
$token = get_token('https://lists.fsfe.org/mailman/listinfo/newsletter-' . $nllang);
|
||||
// Wait a few seconds because mailman requests it in SUBSCRIBE_FORM_MIN_TIME
|
||||
sleep(10);
|
||||
$signupdata = array(
|
||||
'sub_form_token' => $token,
|
||||
'fullname' => $name,
|
||||
'email' => $mail,
|
||||
'digest' => 0,
|
||||
'email-button' => 'Subscribe'
|
||||
);
|
||||
mail_signup('https://lists.fsfe.org/mailman/subscribe/newsletter-' . $nllang, $signupdata);
|
||||
} else {
|
||||
echo "List to sign up email to is unknown. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
function mail_signup($url, $data) {
|
||||
$context = stream_context_create(
|
||||
array(
|
||||
'http' => array(
|
||||
'method' => 'POST',
|
||||
'header' => 'Content-type: application/x-www-form-urlencoded',
|
||||
'content' => http_build_query($data),
|
||||
'timeout' => 10
|
||||
)
|
||||
)
|
||||
);
|
||||
file_get_contents($url, FALSE, $context);
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -111,20 +111,22 @@ function send_mail ( $to, $from, $subject, $msg, $bcc = NULL, $att = NULL, $att_
|
||||
return mail( $to, $subject, $message, $headers );
|
||||
}
|
||||
|
||||
# send information to mail-signup.php if user wished to sign up to community mails or newsletter
|
||||
function mail_signup($data) {
|
||||
$url = $_SERVER['REQUEST_SCHEME']. '://' . $_SERVER['HTTP_HOST'] . '/cgi-bin/mail-signup.php';
|
||||
$context = stream_context_create(
|
||||
array(
|
||||
'http' => array(
|
||||
'method' => 'POST',
|
||||
'header' => 'Content-type: application/x-www-form-urlencoded',
|
||||
'content' => http_build_query($data),
|
||||
'timeout' => 10
|
||||
)
|
||||
)
|
||||
/**
|
||||
* Calls the "mail-signup" script with the data.
|
||||
*
|
||||
* Sends the script into the background to
|
||||
* handle the request asynchronously.
|
||||
*
|
||||
* @param array $data
|
||||
* @see mail-signup.php
|
||||
*/
|
||||
function mail_signup(array $data) {
|
||||
$cmd = sprintf(
|
||||
'php %s %s > /dev/null &',
|
||||
__DIR__ . '/mail-signup.php',
|
||||
escapeshellarg(json_encode($data))
|
||||
);
|
||||
file_get_contents($url, FALSE, $context);
|
||||
exec($cmd);
|
||||
}
|
||||
|
||||
$lang = $_POST['language'];
|
||||
@@ -208,12 +210,21 @@ if (!empty($_POST['org'])) {
|
||||
$address .= $_POST['street'] . "\\n" .
|
||||
$_POST['zip'] . " " . $_POST['city'] . "\\n" .
|
||||
$countryname;
|
||||
$name = escapeshellarg($name);
|
||||
$address = escapeshellarg($address);
|
||||
shell_exec("$odtfill $template $outfile Name=$name Address=$address Name=$name");
|
||||
$cmd = sprintf(
|
||||
'%s %s %s %s %s %s',
|
||||
$odtfill,
|
||||
$template,
|
||||
$outfile,
|
||||
'Name=' . escapeshellarg($name),
|
||||
'Address=' . escapeshellarg($address),
|
||||
'Name=' . escapeshellarg($name)
|
||||
);
|
||||
shell_exec($cmd);
|
||||
|
||||
# Make subscriptions to newsletter/community mails
|
||||
if ($_POST['subcd'] == "y") {
|
||||
$subcd = isset($_POST['subcd']) ? $_POST['subcd'] : false;
|
||||
$subnl = isset($_POST['subnl']) ? $_POST['subnl'] : false;
|
||||
if ($subcd == "y") {
|
||||
$signupdata = array(
|
||||
'list' => 'community',
|
||||
'name' => $_POST['firstname'] . " " . $_POST['lastname'],
|
||||
@@ -225,6 +236,15 @@ if ($_POST['subcd'] == "y") {
|
||||
);
|
||||
mail_signup($signupdata);
|
||||
}
|
||||
if ($subnl == "y") {
|
||||
$signupdata = array(
|
||||
'list' => 'newsletter',
|
||||
'name' => $_POST['firstname'] . " " . $_POST['lastname'],
|
||||
'mail' => $_POST['mail'],
|
||||
'lang' => $_POST['language']
|
||||
);
|
||||
mail_signup($signupdata);
|
||||
}
|
||||
|
||||
$test = send_mail ("contact@fsfe.org", $_POST['firstname'] . " " . $_POST['lastname'] . " <" . $_POST['mail'] . ">", $subject, $msg, NULL, file_get_contents($outfile), "application/vnd.oasis.opendocument.text", "letter.odt");
|
||||
|
||||
@@ -234,6 +254,7 @@ $test = send_mail ("contact@fsfe.org", $_POST['firstname'] . " " . $_POST['lastn
|
||||
if (isset($_POST['donate']) && ((int) $_POST['donate']) >= 5) {
|
||||
relay_donation($_POST['donationID']);
|
||||
} else {
|
||||
// DEBUG: Comment out next line to be able to see errors and printed info
|
||||
header("Location: http://fsfe.org/contribute/spreadtheword-orderthanks.$lang.html");
|
||||
}
|
||||
|
||||
|
@@ -141,6 +141,7 @@
|
||||
<div>
|
||||
<span class="formlabel">Receive the latest Free Software news:</span>
|
||||
<label for="subcd"><input name="subcd" id="subcd" value="y" type="checkbox" />I want to receive occasional information about the FSFE's activities</label>
|
||||
<label for="subnl"><input name="subnl" id="subnl" value="y" type="checkbox" />I want to receive the FSFE's monthly newsletter</label>
|
||||
</div>
|
||||
<div
|
||||
id="donate-group"
|
||||
|
Reference in New Issue
Block a user