Browse Source

STW: ability to subscribe to community mails (#760)

tags/contribute2018
Max Mehl 8 months ago
parent
commit
9ea8901777
4 changed files with 93 additions and 4 deletions
  1. 60
    0
      cgi-bin/mail-signup.php
  2. 30
    0
      cgi-bin/promotion.php
  3. 2
    3
      contribute/spreadtheword.en.xhtml
  4. 1
    1
      contribute/spreadtheword.xsl

+ 60
- 0
cgi-bin/mail-signup.php View File

@@ -0,0 +1,60 @@
<?php
// 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

$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;

# Check required variables
if (empty($list) ||
empty($mail) ) {
echo "Missing parameters. Required: list, mail";
exit(1);
}

if ($list == 'community' ) {
# "name" is also required for Community Database
if (empty($name)) {
echo "Missing parameters. Required: name";
exit(1);
}
$signupdata = array(
'name' => $name,
'email1' => $mail,
'address' => $address,
'zip' => $zip,
'city' => $city,
'country' => $country
);
print_r($signupdata);
mail_signup('https://my.fsfe.org/subscribe', $signupdata);
} elseif ($list == 'newsletter') {
echo "";
} 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);
}

?>

+ 30
- 0
cgi-bin/promotion.php View File

@@ -111,6 +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
)
)
);
file_get_contents($url, FALSE, $context);
}

$lang = $_POST['language'];

# Sanity checks (*very* sloppy input validation)
@@ -196,6 +212,20 @@ $name = escapeshellarg($name);
$address = escapeshellarg($address);
shell_exec("$odtfill $template $outfile Name=$name Address=$address Name=$name");

# Make subscriptions to newsletter/community mails
if ($_POST['subcd'] == "y") {
$signupdata = array(
'list' => 'community',
'name' => $_POST['firstname'] . " " . $_POST['lastname'],
'mail' => $_POST['mail'],
'address' => $_POST['street'],
'zip' => $_POST['zip'],
'city' => $_POST['city'],
'country' => $countrycode
);
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");

if (isset($_POST['donate']) && ($_POST['donate'] > 0)) {

+ 2
- 3
contribute/spreadtheword.en.xhtml View File

@@ -237,11 +237,10 @@
<div>
<input type="text" name="address" placeholder="Which address shall be used?" size="20" class="special" />
</div>
<!-- hide newsletter field for once as it requires some extra backend work
<div>
<span class="formlabel">Receive the latest Free Software news:</span>
<label for="wantinfo"><input name="wantinfo" id="wantinfo" type="checkbox" />I want to receive occasional information about FSFE's activities (less than one email a week on average)</label>
</div> -->
<label for="subcd"><input name="subcd" id="subcd" value="y" type="checkbox" />I want to receive occasional information about the FSFE's activities</label>
</div>
<div>
<span class="formlabel">Support our work with a voluntary donation*:</span>
<input type="number" name="donate" value="" min="0" step="5" placeholder="0 or ≥ 10 €" required="required" />€

+ 1
- 1
contribute/spreadtheword.xsl View File

@@ -241,7 +241,7 @@
<xsl:attribute name="type">hidden</xsl:attribute>
<xsl:attribute name="name">language</xsl:attribute>
<xsl:attribute name="value">
<xsl:value-of select="/buildinfo/document/@language" />
<xsl:value-of select="/buildinfo/@language" />
</xsl:attribute>
</xsl:element>
</xsl:template>

Loading…
Cancel
Save