feat/php-linter (#5321)
All checks were successful
continuous-integration/drone/push Build is passing

At least helps with #5297

Co-authored-by: Darragh Elliott <me@delliott.net>
Reviewed-on: #5321
Co-authored-by: delliott <delliott@fsfe.org>
Co-committed-by: delliott <delliott@fsfe.org>
This commit is contained in:
2025-09-24 18:13:46 +00:00
committed by tobiasd
parent fc303e213f
commit b390c5472e
11 changed files with 530 additions and 499 deletions

View File

@@ -1,29 +1,31 @@
<?php
// This script signs up an email address with other (partly optional) data
// to the community database (occasional emails and the newsletter)
// parse data from POST or cli arg
if (php_sapi_name() === 'cli') {
$data = json_decode($argv[1], true);
$data = json_decode($argv[1], true);
} else {
$data = $_POST;
$data = $_POST;
}
# 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
)
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);
);
// DEBUG: set a local URL here to catch the requests
file_get_contents($url, false, $context);
}
# Check expected/required variables are set
@@ -32,15 +34,13 @@ if (empty($data['email1']) ||
empty($data['address']) ||
empty($data['zip']) ||
empty($data['city'])) {
echo "Missing parameters. Some required parameters are missing (name, address, mail)";
exit(1);
echo "Missing parameters. Some required parameters are missing (name, address, mail)";
exit(1);
}
if ($data['wants_info'] or $data['wants_newsletter_info']) {
mail_signup('https://my.fsfe.org/subscribe-api', $signupdata);
mail_signup('https://my.fsfe.org/subscribe-api', $signupdata);
} else {
echo "List to sign up email to is unknown. Exiting.";
exit(1);
echo "List to sign up email to is unknown. Exiting.";
exit(1);
}
?>

View File

@@ -1,4 +1,5 @@
<?php
/*
* SPDX-FileCopyrightText: 2020 Free Software Foundation Europe <https://fsfe.org>
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -51,58 +52,66 @@ $who_empnumber = explode('||', $who)[2];
$who = explode('||', $who)[1];
// FUNCTIONS
function errexit($msg) {
exit("Error: " . $msg . "<br/><br/>To avoid losing your data, press the back button in your browser");
function errexit($msg)
{
exit("Error: " . $msg . "<br/><br/>To avoid losing your data, press the back button in your browser");
}
function replace_page($temp, $content){
$vars = array(':RESULT:'=>$content);
function replace_page($temp, $content)
{
$vars = array(':RESULT:' => $content);
return str_replace(array_keys($vars), $vars, $temp);
}
/* Snippet Begin:
* SPDX-SnippetLicenseConcluded: CC-BY-SA-4.0
* SPDX-SnippetCopyrightText: mgutt <https://stackoverflow.com/users/318765/mgutt>
*/
function filter_filename($filename, $beautify=true) {
// sanitize filename
$filename = preg_replace(
'~
function filter_filename($filename, $beautify = true)
{
// sanitize filename
$filename = preg_replace(
'~
[<>:"/\\|?*]| # file system reserved https://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
[\x00-\x1F]| # control characters http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx
[\x7F\xA0\xAD]| # non-printing characters DEL, NO-BREAK SPACE, SOFT HYPHEN
[#\[\]@!$&\'()+,;=]| # URI reserved https://tools.ietf.org/html/rfc3986#section-2.2
[{}^\~`] # URL unsafe characters https://www.ietf.org/rfc/rfc1738.txt
~x',
'-', $filename);
// avoids ".", ".." or ".hiddenFiles"
$filename = ltrim($filename, '.-');
// optional beautification
if ($beautify) $filename = beautify_filename($filename);
// maximize filename length to 255 bytes http://serverfault.com/a/9548/44086
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$filename = mb_strcut(pathinfo($filename, PATHINFO_FILENAME), 0, 255 - ($ext ? strlen($ext) + 1 : 0), mb_detect_encoding($filename)) . ($ext ? '.' . $ext : '');
return $filename;
'-',
$filename
);
// avoids ".", ".." or ".hiddenFiles"
$filename = ltrim($filename, '.-');
// optional beautification
if ($beautify) {
$filename = beautify_filename($filename);
}
// maximize filename length to 255 bytes http://serverfault.com/a/9548/44086
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$filename = mb_strcut(pathinfo($filename, PATHINFO_FILENAME), 0, 255 - ($ext ? strlen($ext) + 1 : 0), mb_detect_encoding($filename)) . ($ext ? '.' . $ext : '');
return $filename;
}
function beautify_filename($filename) {
// reduce consecutive characters
$filename = preg_replace(array(
// "file name.zip" becomes "file-name.zip"
'/ +/',
// "file___name.zip" becomes "file-name.zip"
'/_+/',
// "file---name.zip" becomes "file-name.zip"
'/-+/'
), '-', $filename);
$filename = preg_replace(array(
// "file--.--.-.--name.zip" becomes "file.name.zip"
'/-*\.-*/',
// "file...name..zip" becomes "file.name.zip"
'/\.{2,}/'
), '.', $filename);
// lowercase for windows/unix interoperability http://support.microsoft.com/kb/100625
$filename = mb_strtolower($filename, mb_detect_encoding($filename));
// ".file-name.-" becomes "file-name"
$filename = trim($filename, '.-');
return $filename;
function beautify_filename($filename)
{
// reduce consecutive characters
$filename = preg_replace(array(
// "file name.zip" becomes "file-name.zip"
'/ +/',
// "file___name.zip" becomes "file-name.zip"
'/_+/',
// "file---name.zip" becomes "file-name.zip"
'/-+/'
), '-', $filename);
$filename = preg_replace(array(
// "file--.--.-.--name.zip" becomes "file.name.zip"
'/-*\.-*/',
// "file...name..zip" becomes "file.name.zip"
'/\.{2,}/'
), '.', $filename);
// lowercase for windows/unix interoperability http://support.microsoft.com/kb/100625
$filename = mb_strtolower($filename, mb_detect_encoding($filename));
// ".file-name.-" becomes "file-name"
$filename = trim($filename, '.-');
return $filename;
}
/* Snippet End */
@@ -116,11 +125,11 @@ $rate_dinner = floatval($defaults[3]); // dinner rate
// eligible amount per day
if ($dest === 'other') {
$dest = $dest_other; // if other destination, just take this value
$dest = $dest_other; // if other destination, just take this value
} else {
$pattern = "/([0-9.]+)?\/([0-9.]+)?/"; // define pattern something like "/12/24/"
$dest = preg_match($pattern, $dest, $match, PREG_OFFSET_CAPTURE); // actually search for it
$dest = $match[0][0]; // matches are on 2nd level in an array
$pattern = "/([0-9.]+)?\/([0-9.]+)?/"; // define pattern something like "/12/24/"
$dest = preg_match($pattern, $dest, $match, PREG_OFFSET_CAPTURE); // actually search for it
$dest = $match[0][0]; // matches are on 2nd level in an array
}
// dest -> epd (half/full amount)
@@ -130,9 +139,9 @@ $maxamount_full = floatval($maxamount[1]); // second half
// Prepare output table
if ($mailopt === "onlyme") {
$html .= "<p><strong>ATTENTION: The email has only been sent to you, not to the financial team!</strong></p>";
} else if ($mailopt === "none") {
$html .= "<p><strong>ATTENTION: You have configured to not send any email!</strong></p>";
$html .= "<p><strong>ATTENTION: The email has only been sent to you, not to the financial team!</strong></p>";
} elseif ($mailopt === "none") {
$html .= "<p><strong>ATTENTION: You have configured to not send any email!</strong></p>";
}
$html .= "<p>This per diem statement is made by <strong>$who_verbose</strong>.</p>
<table class='table table-striped'>
@@ -165,86 +174,86 @@ $email->SetFrom($who . "@fsfe.org", $who_verbose);
$email->CharSet = "UTF-8";
$email->Subject = "=?UTF-8?B?" . base64_encode("per diem statement by $who_verbose for $activity_text") . "?=";
if ($mailopt === "normal") {
$email->addAddress("finance@lists.fsfe.org");
$email->addAddress("finance@lists.fsfe.org");
}
$email->addAddress($who . "@fsfe.org");
foreach ($use as $d => $day) { // calculate for each day
// set "no" as value for day's variable if empty
$use[$d] = $use[$d] ?? 'no';
$date[$d] = $date[$d] ?? 'no';
$break[$d] = $break[$d] ?? 'no';
$lunch[$d] = $lunch[$d] ?? 'no';
$dinner[$d] = $dinner[$d] ?? 'no';
// set "no" as value for day's variable if empty
$use[$d] = $use[$d] ?? 'no';
$date[$d] = $date[$d] ?? 'no';
$break[$d] = $break[$d] ?? 'no';
$lunch[$d] = $lunch[$d] ?? 'no';
$dinner[$d] = $dinner[$d] ?? 'no';
// increase $d by 1 if numeric, for $csv array number
if (is_numeric($d)) {
$key = $d + 1;
} else {
$key = $d;
}
if ($use[$d] === 'yes') { // only calculate if checkbox has been activated (day in use)
if ($d === 'out' || $d === 'return') { // set amount of € for travel or full day
$reimb_day[$d] = $maxamount_trav; // total max. reimburseable amount for this half day
// increase $d by 1 if numeric, for $csv array number
if (is_numeric($d)) {
$key = $d + 1;
} else {
$reimb_day[$d] = $maxamount_full; // total max. reimburseable amount for this full day
$key = $d;
}
// date
if ($date[$d] === '' ) {
$date[$d] = "Day " . $d;
}
// breakfast
if ($break[$d] !== "yes") {
// if meal paid by someone else: total amount for today =
// MINUS total possible amount for a FULL day * rate for this meal
// no matter whether today is a full or a half day
$reimb_day[$d] = $reimb_day[$d] - $maxamount_full * $rate_breakf;
}
// lunch
if ($lunch[$d] !== "yes") {
$reimb_day[$d] = $reimb_day[$d] - $maxamount_full * $rate_lunch;
}
// dinner
if ($dinner[$d] !== "yes") {
$reimb_day[$d] = $reimb_day[$d] - $maxamount_full * $rate_dinner;
}
if ($use[$d] === 'yes') { // only calculate if checkbox has been activated (day in use)
if ($d === 'out' || $d === 'return') { // set amount of € for travel or full day
$reimb_day[$d] = $maxamount_trav; // total max. reimburseable amount for this half day
} else {
$reimb_day[$d] = $maxamount_full; // total max. reimburseable amount for this full day
}
// Avoid negative amounts
if ($reimb_day[$d] < 0) {
$reimb_day[$d] = 0;
}
// date
if ($date[$d] === '') {
$date[$d] = "Day " . $d;
}
// breakfast
if ($break[$d] !== "yes") {
// if meal paid by someone else: total amount for today =
// MINUS total possible amount for a FULL day * rate for this meal
// no matter whether today is a full or a half day
$reimb_day[$d] = $reimb_day[$d] - $maxamount_full * $rate_breakf;
}
// lunch
if ($lunch[$d] !== "yes") {
$reimb_day[$d] = $reimb_day[$d] - $maxamount_full * $rate_lunch;
}
// dinner
if ($dinner[$d] !== "yes") {
$reimb_day[$d] = $reimb_day[$d] - $maxamount_full * $rate_dinner;
}
// add on top of total reimbursement
$reimb_total = $reimb_total + $reimb_day[$d];
// Avoid negative amounts
if ($reimb_day[$d] < 0) {
$reimb_day[$d] = 0;
}
// change number format of this day's amount to German (comma)
$reimb_day[$d] = number_format($reimb_day[$d], 2, ',', '');
// add on top of total reimbursement
$reimb_total = $reimb_total + $reimb_day[$d];
// Remarks, explanation what has been self-paid
$remarks[$d] = "";
if ($break[$d] === "yes") {
$remarks[$d] .= "breakfast+";
}
if ($lunch[$d] === "yes") {
$remarks[$d] .= "lunch+";
}
if ($dinner[$d] === "yes") {
$remarks[$d] .= "dinner";
}
if ($break[$d] != "yes" && $lunch[$d] != "yes" && $dinner[$d] != "yes") {
$remarks[$d] = "nothing";
}
if ($break[$d] === "yes" && $lunch[$d] === "yes" && $dinner[$d] === "yes") {
$remarks[$d] = "everything";
}
$remarks[$d] = preg_replace("/\+$/", "", $remarks[$d]);
$remarks[$d] .= " self-paid";
// change number format of this day's amount to German (comma)
$reimb_day[$d] = number_format($reimb_day[$d], 2, ',', '');
// HTML output for this day
$html .= "
// Remarks, explanation what has been self-paid
$remarks[$d] = "";
if ($break[$d] === "yes") {
$remarks[$d] .= "breakfast+";
}
if ($lunch[$d] === "yes") {
$remarks[$d] .= "lunch+";
}
if ($dinner[$d] === "yes") {
$remarks[$d] .= "dinner";
}
if ($break[$d] != "yes" && $lunch[$d] != "yes" && $dinner[$d] != "yes") {
$remarks[$d] = "nothing";
}
if ($break[$d] === "yes" && $lunch[$d] === "yes" && $dinner[$d] === "yes") {
$remarks[$d] = "everything";
}
$remarks[$d] = preg_replace("/\+$/", "", $remarks[$d]);
$remarks[$d] .= " self-paid";
// HTML output for this day
$html .= "
<tr>
<td>$date[$d]</td>
<td>$reimb_day[$d]</td>
@@ -257,15 +266,15 @@ foreach ($use as $d => $day) { // calculate for each day
<td>$remarks[$d]</td>
</tr>";
// CSV for this receipt
$csv[$key] = array($who_empnumber, $who_verbose, $date[$d], $reimb_day[$d], $who_verbose, $activity_tag, $activity_text, $category_id, $category_text, $event, $remarks[$d], "");
// CSV for this receipt
$csv[$key] = array($who_empnumber, $who_verbose, $date[$d], $reimb_day[$d], $who_verbose, $activity_tag, $activity_text, $category_id, $category_text, $event, $remarks[$d], "");
} // if day is used
} // if day is used
} // foreach
// Write and attach temporary CSV file
foreach ($csv as $fields) {
fputcsv($csvfile, $fields, ';', '"', '"');
fputcsv($csvfile, $fields, ';', '"', '"');
}
$email->addAttachment($csvfile_path, filter_filename($date[$d]."-"."pd" ."-". $who ."-". $activity_tag ."-". $event . ".csv"));
@@ -286,9 +295,9 @@ $html .= "<tr><td><strong>Total:</strong></td><td><strong>$reimb_total $currency
$html .= "<td colspan='8'></td></tr>";
$html .= "</table>";
if ($extra) {
$html .= "<p>Extra remarks: <br />$extra</p>";
$html .= "<p>Extra remarks: <br />$extra</p>";
$email_body .= "
$email_body .= "
The sender added the following comment:
@@ -298,8 +307,8 @@ $extra";
// Send email, and delete attachments
$email->Body = $email_body;
if ($mailopt === "normal" || $mailopt === "onlyme") {
$email->send();
$html .= $email->ErrorInfo;
$email->send();
$html .= $email->ErrorInfo;
}
fclose($csvfile);
@@ -308,5 +317,3 @@ fclose($csvfile);
$template = file_get_contents('../internal/pd-result.en.html', true);
echo replace_page($template, $html);
?>

View File

@@ -2,114 +2,116 @@
function eval_xml_template($template, $data)
{
$dir = dirname(__FILE__) . '/../templates';
$result = file_get_contents("$dir/$template");
foreach ($data as $key => $value)
$result = preg_replace("/<tpl name=\"$key\"><\/tpl>/", $value, $result);
$result = preg_replace("/<tpl name=\"[^\"]*\"><\/tpl>/", '', $result);
return $result;
$dir = dirname(__FILE__) . '/../templates';
$result = file_get_contents("$dir/$template");
foreach ($data as $key => $value) {
$result = preg_replace("/<tpl name=\"$key\"><\/tpl>/", $value, $result);
}
$result = preg_replace("/<tpl name=\"[^\"]*\"><\/tpl>/", '', $result);
return $result;
}
function eval_template($template, $data) {
extract($data);
$dir = realpath(dirname(__FILE__) . '/../templates');
ob_start();
include("$dir/$template");
$result = ob_get_contents();
ob_end_clean();
return $result;
function eval_template($template, $data)
{
extract($data);
$dir = realpath(dirname(__FILE__) . '/../templates');
ob_start();
include("$dir/$template");
$result = ob_get_contents();
ob_end_clean();
return $result;
}
function gen_alnum($digits)
{
$alphabet = '0123456789abcdefghijklmnopqrstuvwxyz';
$ret = '';
for ($digits; $digits > 0; $digits--) {
$ret .= substr($alphabet, rand(0, 35), 1);
}
return $ret;
$alphabet = '0123456789abcdefghijklmnopqrstuvwxyz';
$ret = '';
for ($digits; $digits > 0; $digits--) {
$ret .= substr($alphabet, rand(0, 35), 1);
}
return $ret;
}
function relay_donation($orderID)
{
$name = $_POST['name'];
$email = $_POST['mail'];
$amount100 = $_POST['donate'] * 100;
$language = $_POST['language'];
$lang = substr($language, 0, 2);
$name = $_POST['name'];
$email = $_POST['mail'];
$amount100 = $_POST['donate'] * 100;
$language = $_POST['language'];
$lang = substr($language, 0, 2);
$PSPID = "40F00871";
$TP = "payment-without-bank.html";
$acceptURL = "https://fsfe.org/donate/thankyou.$lang.html";
$cancelURL = "https://fsfe.org/donate/cancel.$lang.html";
$PSPID = "40F00871";
$TP = "payment-without-bank.html";
$acceptURL = "https://fsfe.org/donate/thankyou.$lang.html";
$cancelURL = "https://fsfe.org/donate/cancel.$lang.html";
$salt = "Only4TestingPurposes";
$shasum = strtoupper(sha1(
"ACCEPTURL=$acceptURL$salt" .
"AMOUNT=$amount100$salt" .
"CANCELURL=$cancelURL$salt" .
//"CN=$name$salt".
//"COM=Donation$salt".
"CURRENCY=EUR$salt" .
"EMAIL=$email$salt" .
"LANGUAGE=$language$salt" .
"ORDERID=$orderID$salt" .
"PMLISTTYPE=2$salt" .
"PSPID=$PSPID$salt" .
"TP=$TP$salt"
));
$salt = "Only4TestingPurposes";
$shasum = strtoupper(sha1(
"ACCEPTURL=$acceptURL$salt" .
"AMOUNT=$amount100$salt" .
"CANCELURL=$cancelURL$salt" .
//"CN=$name$salt".
//"COM=Donation$salt".
"CURRENCY=EUR$salt" .
"EMAIL=$email$salt" .
"LANGUAGE=$language$salt" .
"ORDERID=$orderID$salt" .
"PMLISTTYPE=2$salt" .
"PSPID=$PSPID$salt" .
"TP=$TP$salt"
));
echo eval_xml_template('concardis_relay.en.html', array(
'PSPID' => '<input type="hidden" name="PSPID" value="' . $PSPID . '">',
'orderID' => '<input type="hidden" name="orderID" value="' . $orderID . '">',
'amount' => '<input type="hidden" name="amount" value="' . $amount100 . '">',
//'currency' => '<input type="hidden" name="currency" value="EUR">',
'language' => '<input type="hidden" name="language" value="' . $language . '">',
//'CN' => '<input type="hidden" name="CN" value="'.$name.'">',
'EMAIL' => '<input type="hidden" name="EMAIL" value="' . $email . '">',
'TP' => '<input type="hidden" name="TP" value="' . $TP . '">',
//'PMListType' => '<input type="hidden" name="PMListType" value="2">',
'accepturl' => '<input type="hidden" name="accepturl" value="' . $acceptURL . '">',
'cancelurl' => '<input type="hidden" name="cancelurl" value="' . $cancelURL . '">',
'SHASign' => '<input type="hidden" name="SHASign" value="' . $shasum . '">'
));
echo eval_xml_template('concardis_relay.en.html', array(
'PSPID' => '<input type="hidden" name="PSPID" value="' . $PSPID . '">',
'orderID' => '<input type="hidden" name="orderID" value="' . $orderID . '">',
'amount' => '<input type="hidden" name="amount" value="' . $amount100 . '">',
//'currency' => '<input type="hidden" name="currency" value="EUR">',
'language' => '<input type="hidden" name="language" value="' . $language . '">',
//'CN' => '<input type="hidden" name="CN" value="'.$name.'">',
'EMAIL' => '<input type="hidden" name="EMAIL" value="' . $email . '">',
'TP' => '<input type="hidden" name="TP" value="' . $TP . '">',
//'PMListType' => '<input type="hidden" name="PMListType" value="2">',
'accepturl' => '<input type="hidden" name="accepturl" value="' . $acceptURL . '">',
'cancelurl' => '<input type="hidden" name="cancelurl" value="' . $cancelURL . '">',
'SHASign' => '<input type="hidden" name="SHASign" value="' . $shasum . '">'
));
}
/**
* 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))
);
exec($cmd);
$cmd = sprintf(
'php %s %s > /dev/null &',
__DIR__ . '/mail-signup.php',
escapeshellarg(json_encode($data))
);
exec($cmd);
}
$lang = $_POST['language'];
# Sanity checks (*very* sloppy input validation)
if (
empty($_POST['lastname']) ||
empty($_POST['mail']) ||
stripos($_POST['mail'], 'example') ||
stripos($_POST['mail'], '@@') ||
empty($_POST['street']) ||
empty($_POST['zip']) ||
empty($_POST['city']) ||
empty($_POST['country']) ||
empty($_POST['packagetype']) ||
!empty($_POST['address'])
empty($_POST['lastname']) ||
empty($_POST['mail']) ||
stripos($_POST['mail'], 'example') ||
stripos($_POST['mail'], '@@') ||
empty($_POST['street']) ||
empty($_POST['zip']) ||
empty($_POST['city']) ||
empty($_POST['country']) ||
empty($_POST['packagetype']) ||
!empty($_POST['address'])
) {
header("Location: https://fsfe.org/contribute/spreadtheword-ordererror.$lang.html");
exit();
header("Location: https://fsfe.org/contribute/spreadtheword-ordererror.$lang.html");
exit();
}
# Without this, escapeshellarg() will eat non-ASCII characters.
@@ -129,7 +131,7 @@ $msg_to_staff = "Please send me promotional material:\n" .
"{$_POST['firstname']} " . "{$_POST['lastname']}\n";
if (!empty($_POST['org'])) {
$msg_to_staff .= "{$_POST['org']}\n";
$msg_to_staff .= "{$_POST['org']}\n";
}
$msg_to_staff .= "{$_POST['street']}\n" .
"{$_POST['zip']} " . "{$_POST['city']}\n" .
@@ -138,18 +140,18 @@ $msg_to_staff .= "{$_POST['street']}\n" .
"Specifics of the Order:\n";
# Default or custom package?
if ($_POST['packagetype'] == 'basic_sticker') {
$msg_to_staff .= "My Laptop: Basic Set of Stickers.\n";
} else if ($_POST['packagetype'] == 'basicpostcard') {
$msg_to_staff .= "Postcards and Stickers.\n";
} else if ($_POST['packagetype'] == 'basicsticker') {
$msg_to_staff .= "Small package with stickers.\n";
} else if ($_POST['packagetype'] == 'morestickers') {
$msg_to_staff .= "Stickers for me and my friend: Twice the amount of our most popular stickers.\n";
} else if ($_POST['packagetype'] == 'standard') {
$msg_to_staff .= "Standard Package.\n";
$msg_to_staff .= "My Laptop: Basic Set of Stickers.\n";
} elseif ($_POST['packagetype'] == 'basicpostcard') {
$msg_to_staff .= "Postcards and Stickers.\n";
} elseif ($_POST['packagetype'] == 'basicsticker') {
$msg_to_staff .= "Small package with stickers.\n";
} elseif ($_POST['packagetype'] == 'morestickers') {
$msg_to_staff .= "Stickers for me and my friend: Twice the amount of our most popular stickers.\n";
} elseif ($_POST['packagetype'] == 'standard') {
$msg_to_staff .= "Standard Package.\n";
} else {
$msg_to_staff .= "Custom package:\n" .
"{$_POST['specifics']}\n";
$msg_to_staff .= "Custom package:\n" .
"{$_POST['specifics']}\n";
}
$languages = implode(',', $_POST['languages']);
$msg_to_staff .= "\n" .
@@ -164,11 +166,11 @@ $msg_to_staff .= "\n" .
$_POST['donationID'] = "";
if (isset($_POST['donate']) && ($_POST['donate'] > 0)) {
$_POST['donationID'] = "DAFSPCK" . gen_alnum(5);
$subject .= ": " . $_POST['donationID'];
$msg_to_staff .= "\n\nThe orderer choose to make a Donation of {$_POST['donate']} Euro.\n" .
"Please do not assume that this donation has been made until you receive\n" .
"confirmation from Concardis for the order: {$_POST['donationID']}";
$_POST['donationID'] = "DAFSPCK" . gen_alnum(5);
$subject .= ": " . $_POST['donationID'];
$msg_to_staff .= "\n\nThe orderer choose to make a Donation of {$_POST['donate']} Euro.\n" .
"Please do not assume that this donation has been made until you receive\n" .
"confirmation from Concardis for the order: {$_POST['donationID']}";
}
# Generate letter to be sent along with the material
@@ -178,19 +180,19 @@ $outfile = "/tmp/promotionorder.odt";
$name = $_POST['firstname'] . " " . $_POST['lastname'];
$address = "";
if (!empty($_POST['org'])) {
$address .= $_POST['org'] . "\\n";
$address .= $_POST['org'] . "\\n";
}
$address .= $_POST['street'] . "\\n" .
$_POST['zip'] . " " . $_POST['city'] . "\\n" .
$countryname;
$cmd = sprintf(
'%s %s %s %s %s %s',
$odtfill,
$template,
$outfile,
'Name=' . escapeshellarg($name),
'Address=' . escapeshellarg($address),
'Name=' . escapeshellarg($name)
'%s %s %s %s %s %s',
$odtfill,
$template,
$outfile,
'Name=' . escapeshellarg($name),
'Address=' . escapeshellarg($address),
'Name=' . escapeshellarg($name)
);
shell_exec($cmd);
@@ -198,22 +200,22 @@ shell_exec($cmd);
$subcd = isset($_POST['subcd']) ? $_POST['subcd'] : false;
$subnl = isset($_POST['subnl']) ? $_POST['subnl'] : false;
if ($subcd == "y" or $subnl == "y") {
$signupdata = array(
'name' => $_POST['firstname'] . " " . $_POST['lastname'],
'email1' => $_POST['mail'],
'address' => $_POST['street'],
'zip' => $_POST['zip'],
'city' => $_POST['city'],
'langugage' => $_POST['language'],
'country' => $countrycode
);
if ($subcd == "y") {
$signupdata['wants_info'] = '1';
}
if ($subnl == "y") {
$signupdata['wants_newsletter_info'] = '1';
}
mail_signup($signupdata);
$signupdata = array(
'name' => $_POST['firstname'] . " " . $_POST['lastname'],
'email1' => $_POST['mail'],
'address' => $_POST['street'],
'zip' => $_POST['zip'],
'city' => $_POST['city'],
'langugage' => $_POST['language'],
'country' => $countrycode
);
if ($subcd == "y") {
$signupdata['wants_info'] = '1';
}
if ($subnl == "y") {
$signupdata['wants_newsletter_info'] = '1';
}
mail_signup($signupdata);
}
$data = [
@@ -291,8 +293,8 @@ curl_close($curl);
* Only process donations starting from 10 euro.
*/
if (isset($_POST['donate']) && ((int) $_POST['donate']) >= 5) {
relay_donation($_POST['donationID']);
relay_donation($_POST['donationID']);
} else {
// DEBUG: Comment out next line to be able to see errors and printed info
header("Location: https://fsfe.org/contribute/spreadtheword-orderthanks.$lang.html");
// DEBUG: Comment out next line to be able to see errors and printed info
header("Location: https://fsfe.org/contribute/spreadtheword-orderthanks.$lang.html");
}

View File

@@ -1,4 +1,5 @@
<?php
/* Copyright (C) 2012, Tobias Bengfort <tobias.bengfort@gmx.net> & Marius Jammes for FSFE e.V.
This program is free software: you can redistribute it and/or modify
@@ -215,7 +216,7 @@ function calculate_information($data)
empty(
array_filter(
$decoded_response,
fn($file) => $file["name"] === $filename
fn ($file) => $file["name"] === $filename
)
)
) {
@@ -257,7 +258,7 @@ function calculate_information($data)
empty(
array_filter(
$decoded_response,
fn($branch) => $branch["name"] === $branchname
fn ($branch) => $branch["name"] === $branchname
)
)
) {

View File

@@ -40,83 +40,91 @@ $who = explode('||', $who)[1];
// FUNCTIONS
function errexit($msg) {
exit("Error: " . $msg . "<br/><br/>To avoid losing your data, press the back button in your browser");
function errexit($msg)
{
exit("Error: " . $msg . "<br/><br/>To avoid losing your data, press the back button in your browser");
}
function replace_page($temp, $content){
$vars = array(':RESULT:'=>$content);
function replace_page($temp, $content)
{
$vars = array(':RESULT:' => $content);
return str_replace(array_keys($vars), $vars, $temp);
}
/* Snippet Begin:
* SPDX-SnippetLicenseConcluded: CC-BY-SA-4.0
* SPDX-SnippetCopyrightText: mgutt <https://stackoverflow.com/users/318765/mgutt>
*/
function filter_filename($filename, $beautify=true) {
// sanitize filename
$filename = preg_replace(
'~
function filter_filename($filename, $beautify = true)
{
// sanitize filename
$filename = preg_replace(
'~
[<>:"/\\|?*]| # file system reserved https://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
[\x00-\x1F]| # control characters http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx
[\x7F\xA0\xAD]| # non-printing characters DEL, NO-BREAK SPACE, SOFT HYPHEN
[#\[\]@!$&\'()+,;=]| # URI reserved https://tools.ietf.org/html/rfc3986#section-2.2
[{}^\~`] # URL unsafe characters https://www.ietf.org/rfc/rfc1738.txt
~x',
'-', $filename);
// avoids ".", ".." or ".hiddenFiles"
$filename = ltrim($filename, '.-');
// optional beautification
if ($beautify) $filename = beautify_filename($filename);
// maximize filename length to 255 bytes http://serverfault.com/a/9548/44086
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$filename = mb_strcut(pathinfo($filename, PATHINFO_FILENAME), 0, 255 - ($ext ? strlen($ext) + 1 : 0), mb_detect_encoding($filename)) . ($ext ? '.' . $ext : '');
return $filename;
'-',
$filename
);
// avoids ".", ".." or ".hiddenFiles"
$filename = ltrim($filename, '.-');
// optional beautification
if ($beautify) {
$filename = beautify_filename($filename);
}
// maximize filename length to 255 bytes http://serverfault.com/a/9548/44086
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$filename = mb_strcut(pathinfo($filename, PATHINFO_FILENAME), 0, 255 - ($ext ? strlen($ext) + 1 : 0), mb_detect_encoding($filename)) . ($ext ? '.' . $ext : '');
return $filename;
}
function beautify_filename($filename) {
// reduce consecutive characters
$filename = preg_replace(array(
// "file name.zip" becomes "file-name.zip"
'/ +/',
// "file___name.zip" becomes "file-name.zip"
'/_+/',
// "file---name.zip" becomes "file-name.zip"
'/-+/'
), '-', $filename);
$filename = preg_replace(array(
// "file--.--.-.--name.zip" becomes "file.name.zip"
'/-*\.-*/',
// "file...name..zip" becomes "file.name.zip"
'/\.{2,}/'
), '.', $filename);
// lowercase for windows/unix interoperability http://support.microsoft.com/kb/100625
$filename = mb_strtolower($filename, mb_detect_encoding($filename));
// ".file-name.-" becomes "file-name"
$filename = trim($filename, '.-');
return $filename;
function beautify_filename($filename)
{
// reduce consecutive characters
$filename = preg_replace(array(
// "file name.zip" becomes "file-name.zip"
'/ +/',
// "file___name.zip" becomes "file-name.zip"
'/_+/',
// "file---name.zip" becomes "file-name.zip"
'/-+/'
), '-', $filename);
$filename = preg_replace(array(
// "file--.--.-.--name.zip" becomes "file.name.zip"
'/-*\.-*/',
// "file...name..zip" becomes "file.name.zip"
'/\.{2,}/'
), '.', $filename);
// lowercase for windows/unix interoperability http://support.microsoft.com/kb/100625
$filename = mb_strtolower($filename, mb_detect_encoding($filename));
// ".file-name.-" becomes "file-name"
$filename = trim($filename, '.-');
return $filename;
}
/* Snippet End */
// Sanity checks for parameters, and setting variables depending on type
if ($type == "rc") {
if ( ! $rc_month || ! $rc_year ) {
errexit("You must provide month and year of the RC");
}
$type_verbose = "Reimbursement Claim";
$type_date = "$rc_year-$rc_month";
} else if ($type == "cc") {
if ( ! $cc_month || ! $cc_year ) {
errexit("You must provide quarter and year of the CC statement");
}
$type_verbose = "Credit Card Statement";
$type_date = "$cc_year-$cc_month";
if (! $rc_month || ! $rc_year) {
errexit("You must provide month and year of the RC");
}
$type_verbose = "Reimbursement Claim";
$type_date = "$rc_year-$rc_month";
} elseif ($type == "cc") {
if (! $cc_month || ! $cc_year) {
errexit("You must provide quarter and year of the CC statement");
}
$type_verbose = "Credit Card Statement";
$type_date = "$cc_year-$cc_month";
} else {
errexit("You must provide a reimbursement type");
errexit("You must provide a reimbursement type");
}
// Prepare output table
if ($mailopt === "onlyme") {
$html .= "<p><strong>ATTENTION: The email has only been sent to you, not to the financial team!</strong></p>";
} else if ($mailopt === "none") {
$html .= "<p><strong>ATTENTION: You have configured to not send any email!</strong></p>";
$html .= "<p><strong>ATTENTION: The email has only been sent to you, not to the financial team!</strong></p>";
} elseif ($mailopt === "none") {
$html .= "<p><strong>ATTENTION: You have configured to not send any email!</strong></p>";
}
$html .= "<p>This <strong>$type_verbose</strong> is made by <strong>$who_verbose</strong>.</p>
<table class='table table-striped'>
@@ -151,65 +159,65 @@ $email->SetFrom($who . "@fsfe.org", $who_verbose);
$email->CharSet = "UTF-8";
$email->Subject = "=?UTF-8?B?" . base64_encode("$type_verbose for $type_date by $who_verbose") . "?=";
if ($mailopt === "normal") {
$email->addAddress("finance@lists.fsfe.org");
$email->addAddress("finance@lists.fsfe.org");
}
$email->addAddress($who . "@fsfe.org");
foreach ($entry as $key => $date) { // run over each row
// Get basic variable for each row
/* For receipts, following variables are set:
* tmp: the temporary path of the uploaded file
* error: any errors with the file
* name: the original name of the file
* size: file size
* rename: the format we want each file to have
* dest: the temporary but known location of the file
*/
$receipt_tmp = $_FILES["receipt"]["tmp_name"][$key];
$receipt_error = $_FILES["receipt"]["error"][$key];
$receipt_name = basename($_FILES["receipt"]["name"][$key]);
$receipt_size = $_FILES["receipt"]["size"][$key];
$key1 = $key + 1;
$receipt_no = sprintf('%02d', $key1);
$activity_tag[$key] = explode("||", $activity[$key])[0];
$activity_text[$key] = explode("||", $activity[$key])[1];
$category_id[$key] = explode(":", $category[$key])[0];
$category_text[$key] = explode(":", $category[$key])[1];
$event[$key] = $event[$key];
// Get basic variable for each row
/* For receipts, following variables are set:
* tmp: the temporary path of the uploaded file
* error: any errors with the file
* name: the original name of the file
* size: file size
* rename: the format we want each file to have
* dest: the temporary but known location of the file
*/
$receipt_tmp = $_FILES["receipt"]["tmp_name"][$key];
$receipt_error = $_FILES["receipt"]["error"][$key];
$receipt_name = basename($_FILES["receipt"]["name"][$key]);
$receipt_size = $_FILES["receipt"]["size"][$key];
$key1 = $key + 1;
$receipt_no = sprintf('%02d', $key1);
$activity_tag[$key] = explode("||", $activity[$key])[0];
$activity_text[$key] = explode("||", $activity[$key])[1];
$category_id[$key] = explode(":", $category[$key])[0];
$category_text[$key] = explode(":", $category[$key])[1];
$event[$key] = $event[$key];
// Sanity checks for receipt: upload, size, mime type
if (! $receipt_tmp) {
errexit("Something with $receipt_name went wrong, it has not been uploaded.");
}
if ($receipt_size > 2097152) {
errexit("File size of $receipt_name must not be larger than 2MB");
}
$receipt_mime = mime_content_type($receipt_tmp);
if(! in_array($receipt_mime, array('image/jpeg', 'image/png', 'application/pdf'))) {
errexit("Only PDF, JPG and PNG allowed. $receipt_name has $receipt_mime");
}
// Set name and temporary destination for attached receipt
$receipt_ext = pathinfo($receipt_name)['extension'];
$receipt_rename = filter_filename($type_date ."-". $type ."-". $who ."-receipt-". $receipt_no ."-". $activity_tag[$key] .".". "$receipt_ext");
$receipt_dest[$key] = "/tmp/" . $receipt_rename;
// Try to move file to temporary destination
if ($receipt_error == UPLOAD_ERR_OK) {
if ( ! move_uploaded_file($receipt_tmp, $receipt_dest[$key]) ) {
errexit("Could not move uploaded file '".$receipt_tmp."' to '".$receipt_dest."'<br/>\n");
// Sanity checks for receipt: upload, size, mime type
if (! $receipt_tmp) {
errexit("Something with $receipt_name went wrong, it has not been uploaded.");
}
if ($receipt_size > 2097152) {
errexit("File size of $receipt_name must not be larger than 2MB");
}
$receipt_mime = mime_content_type($receipt_tmp);
if (! in_array($receipt_mime, array('image/jpeg', 'image/png', 'application/pdf'))) {
errexit("Only PDF, JPG and PNG allowed. $receipt_name has $receipt_mime");
}
} else {
errexit("Upload error. [".$receipt_error."] on file '".$receipt_name."'<br/>\n");
}
// Remove "-" when remark empty
if ($description[$key] === "-") {
$description[$key] = "";
}
// Set name and temporary destination for attached receipt
$receipt_ext = pathinfo($receipt_name)['extension'];
$receipt_rename = filter_filename($type_date ."-". $type ."-". $who ."-receipt-". $receipt_no ."-". $activity_tag[$key] .".". "$receipt_ext");
$receipt_dest[$key] = "/tmp/" . $receipt_rename;
// HTML output for this receipt
$html .= "
// Try to move file to temporary destination
if ($receipt_error == UPLOAD_ERR_OK) {
if (! move_uploaded_file($receipt_tmp, $receipt_dest[$key])) {
errexit("Could not move uploaded file '".$receipt_tmp."' to '".$receipt_dest."'<br/>\n");
}
} else {
errexit("Upload error. [".$receipt_error."] on file '".$receipt_name."'<br/>\n");
}
// Remove "-" when remark empty
if ($description[$key] === "-") {
$description[$key] = "";
}
// HTML output for this receipt
$html .= "
<tr>
<td>$date</td>
<td>$amount[$key]</td>
@@ -224,16 +232,16 @@ foreach ($entry as $key => $date) { // run over each row
<td></td>
</tr>";
// CSV for this receipt
$csv[$receipt_no] = array($who_empnumber, $who_verbose, $date, $amount[$key], $recipient[$key], $activity_tag[$key], $activity_text[$key], $category_id[$key], $category_text[$key], $event[$key], $description[$key], $receipt_no);
// CSV for this receipt
$csv[$receipt_no] = array($who_empnumber, $who_verbose, $date, $amount[$key], $recipient[$key], $activity_tag[$key], $activity_text[$key], $category_id[$key], $category_text[$key], $event[$key], $description[$key], $receipt_no);
// Add receipt as email attachment
$email->addAttachment($receipt_dest[$key], basename($receipt_dest[$key]));
// Add receipt as email attachment
$email->addAttachment($receipt_dest[$key], basename($receipt_dest[$key]));
} // foreach
// Write and attach temporary CSV file
foreach ($csv as $fields) {
fputcsv($csvfile, $fields, ';', '"', '"');
fputcsv($csvfile, $fields, ';', '"', '"');
}
$email->addAttachment($csvfile_path, filter_filename($type_date ."-". $type ."-". $who . ".csv"));
@@ -248,9 +256,9 @@ Please find the expenses and their receipts attached.";
// Finalise output table
$html .= "</table>";
if ($extra) {
$html .= "<p>Extra remarks: <br />$extra</p>";
$html .= "<p>Extra remarks: <br />$extra</p>";
$email_body .= "
$email_body .= "
The sender added the following comment:
@@ -260,11 +268,11 @@ $extra";
// Send email, and delete attachments
$email->Body = $email_body;
if ($mailopt === "normal" || $mailopt === "onlyme") {
$email->send();
$html .= $email->ErrorInfo;
$email->send();
$html .= $email->ErrorInfo;
}
foreach ($receipt_dest as $receipt) {
unlink($receipt);
unlink($receipt);
}
fclose($csvfile);
@@ -273,5 +281,3 @@ fclose($csvfile);
$template = file_get_contents('../internal/rc-result.en.html', true);
echo replace_page($template, $html);
?>

View File

@@ -1,4 +1,5 @@
<?php
/*
SPDX-License-Identifier: CC0-1.0
SPDX-FileCopyrightText: 2019 Free Software Foundation Europe e.V. <https://fsfe.org>
@@ -11,6 +12,4 @@ $config = [
'flattruser' => 'fsfe',
'supporturl' => 'https://my.fsfe.org/donate?referrer=share',
'sharepic' => 'https://sharepic.fsfe.org'
]
?>
];

View File

@@ -1,4 +1,5 @@
<?php
/*
* SPDX-FileCopyrightText: 2019 Free Software Foundation Europe e.V. <https://fsfe.org>
* SPDX-FileCopyrightText: 2018 Daniel Martin Gomez
@@ -23,130 +24,132 @@ $title = isset($_GET['title']) ? $_GET['title'] : false;
$ref = isset($_GET['ref']) ? $_GET['ref'] : false;
$fediversepod = isset($_GET['fediversepod']) ? $_GET['fediversepod'] : false;
if(empty($service) || empty($url)) {
echo 'At least one required variable is empty. You have to define at least service and url';
if (empty($service) || empty($url)) {
echo 'At least one required variable is empty. You have to define at least service and url';
} else {
$service = htmlspecialchars($service);
$fediversepod = htmlspecialchars($fediversepod);
$url = urlencode($url);
$title = urlencode($title);
$service = htmlspecialchars($service);
$fediversepod = htmlspecialchars($fediversepod);
$url = urlencode($url);
$title = urlencode($title);
/* Special referrers for FSFE campaigns */
if($ref == "pmpc-side" || $ref == "pmpc-spread") {
$via_fed = "";
$via_tw = "";
$via_dia = "";
$sharepic = "https://sharepic.fsfe.org/pmpc";
$supporturl = "https://my.fsfe.org/donate?referrer=pmpc";
} else {
$via_fed = " via " . $fediverseuser;
$via_tw = "&via=" . $twitteruser;
$via_dia = " via " . $diasporauser;
}
if ($service === "fediverse") {
$fediversepod = validateurl($fediversepod);
$fediverse = which_fediverse($fediversepod);
if($fediverse === "mastodon") {
// Mastodon
header("Location: " . $fediversepod . "/share?text=" . $title . " " . $url . $via_fed);
} elseif($fediverse === "diaspora") {
// Diaspora
header("Location: " . $fediversepod . "/bookmarklet?url=" . $url . "&title=" . $title . $via_dia);
} elseif($fediverse === "gnusocial") {
// GNU Social
header("Location: " . $fediversepod . "/notice/new?status_textarea=" . $title . " " . $url . $via_fed);
/* Special referrers for FSFE campaigns */
if ($ref == "pmpc-side" || $ref == "pmpc-spread") {
$via_fed = "";
$via_tw = "";
$via_dia = "";
$sharepic = "https://sharepic.fsfe.org/pmpc";
$supporturl = "https://my.fsfe.org/donate?referrer=pmpc";
} else {
echo 'Your Fediverse instance is unknown. We cannot find out which service it belongs to, sorry.';
$via_fed = " via " . $fediverseuser;
$via_tw = "&via=" . $twitteruser;
$via_dia = " via " . $diasporauser;
}
if ($service === "fediverse") {
$fediversepod = validateurl($fediversepod);
$fediverse = which_fediverse($fediversepod);
if ($fediverse === "mastodon") {
// Mastodon
header("Location: " . $fediversepod . "/share?text=" . $title . " " . $url . $via_fed);
} elseif ($fediverse === "diaspora") {
// Diaspora
header("Location: " . $fediversepod . "/bookmarklet?url=" . $url . "&title=" . $title . $via_dia);
} elseif ($fediverse === "gnusocial") {
// GNU Social
header("Location: " . $fediversepod . "/notice/new?status_textarea=" . $title . " " . $url . $via_fed);
} else {
echo 'Your Fediverse instance is unknown. We cannot find out which service it belongs to, sorry.';
}
die();
} elseif ($service === "reddit") {
header("Location: https://reddit.com/submit?url=" . $url . "&title=" . $title);
die();
} elseif ($service === "flattr") {
header("Location: https://flattr.com/submit/auto?user_id=" . $flattruser . "&url=" . $url . "&title=" . $title);
die();
} elseif ($service === "hnews") {
header("Location: https://news.ycombinator.com/submitlink?u=" . $url . "&t=" . $title);
die();
} elseif ($service === "twitter") {
header("Location: https://twitter.com/share?url=" . $url . "&text=" . $title . $via_tw);
die();
} elseif ($service === "facebook") {
header("Location: https://www.facebook.com/sharer/sharer.php?u=" . $url);
die();
} elseif ($service === "gplus") {
header("Location: https://plus.google.com/share?url=" . $url);
die();
} elseif ($service === "sharepic") {
header("Location: " . $sharepic);
die();
} elseif ($service === "support") {
header("Location: " . $supporturl);
die();
} else {
echo 'Social network unknown.';
}
die();
} elseif($service === "reddit") {
header("Location: https://reddit.com/submit?url=" . $url . "&title=" . $title);
die();
} elseif($service === "flattr") {
header("Location: https://flattr.com/submit/auto?user_id=" . $flattruser . "&url=" . $url . "&title=" . $title);
die();
} elseif($service === "hnews") {
header("Location: https://news.ycombinator.com/submitlink?u=" . $url . "&t=" . $title);
die();
} elseif($service === "twitter") {
header("Location: https://twitter.com/share?url=" . $url . "&text=" . $title . $via_tw);
die();
} elseif($service === "facebook") {
header("Location: https://www.facebook.com/sharer/sharer.php?u=" . $url);
die();
} elseif($service === "gplus") {
header("Location: https://plus.google.com/share?url=" . $url);
die();
} elseif($service === "sharepic") {
header("Location: " . $sharepic);
die();
} elseif($service === "support") {
header("Location: " . $supporturl);
die();
} else {
echo 'Social network unknown.';
}
}
// Sanitise URLs
function validateurl($url) {
// If Fediverse pod has been typed without http(s):// prefix, add it
if (preg_match('#^https?://#i', $url) === 0) {
$url = 'https://' . $url;
}
// remove trailing spaces and slashes
$url = trim($url, " /");
function validateurl($url)
{
// If Fediverse pod has been typed without http(s):// prefix, add it
if (preg_match('#^https?://#i', $url) === 0) {
$url = 'https://' . $url;
}
// remove trailing spaces and slashes
$url = trim($url, " /");
return $url;
return $url;
}
// Is $pod a Mastodon instance or a GNU Social server?
function getFediverseNetwork($pod) {
$curl = curl_init($pod . "/api/statusnet/version.xml");
curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($code == 200) {
// GNU social server
return 0;
} else {
// Mastodon server
return 1;
}
function getFediverseNetwork($pod)
{
$curl = curl_init($pod . "/api/statusnet/version.xml");
curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($code == 200) {
// GNU social server
return 0;
} else {
// Mastodon server
return 1;
}
}
function which_fediverse($pod) {
if (check_httpstatus($pod . "/api/v1/instance")) {
// Mastodon
return "mastodon";
} elseif (check_httpstatus($pod . "/api/statusnet/version.xml")) {
// GNU social
return "gnusocial";
} elseif (check_httpstatus($pod . "/users/sign_in")) {
// Diaspora
return "diaspora";
} else {
return "none";
}
function which_fediverse($pod)
{
if (check_httpstatus($pod . "/api/v1/instance")) {
// Mastodon
return "mastodon";
} elseif (check_httpstatus($pod . "/api/statusnet/version.xml")) {
// GNU social
return "gnusocial";
} elseif (check_httpstatus($pod . "/users/sign_in")) {
// Diaspora
return "diaspora";
} else {
return "none";
}
}
function check_httpstatus($url) {
$headers = get_headers($url, 1);
// check up to 2 redirections
if (array_key_exists('2', $headers)) {
$httpstatus = $headers[2];
} elseif (array_key_exists('1', $headers)) {
$httpstatus = $headers[1];
} else {
$httpstatus = $headers[0];
}
// check if HTTP status is 200
if (strpos($httpstatus, '200 OK') !== false) {
return true;
} else {
return false;
}
function check_httpstatus($url)
{
$headers = get_headers($url, 1);
// check up to 2 redirections
if (array_key_exists('2', $headers)) {
$httpstatus = $headers[2];
} elseif (array_key_exists('1', $headers)) {
$httpstatus = $headers[1];
} else {
$httpstatus = $headers[0];
}
// check if HTTP status is 200
if (strpos($httpstatus, '200 OK') !== false) {
return true;
} else {
return false;
}
}
?>

View File

@@ -9,8 +9,8 @@
tracking number.
</p>
<?php
if ( !empty($donationID) ) {
?>
if (!empty($donationID)) {
?>
<p>If you have yet to make your donation, you may now do so by following
this link: <a href=https://fsfe.org/order/payonline.<?=$lang?>/<?=$donationID?>>
https://fsfe.org/order/payonline.<?=$lang?>/<?=$donationID?></a>. Once the donation is

View File

@@ -19,6 +19,12 @@ pre-commit:
pyright:
glob: "*.py"
run: pyright {staged_files}
php-cs-fixer:
glob: "*.php"
exclude:
- "fsfe.org/cgi-bin/PHPMailer/*.php"
run: for file in {staged_files}; do php-cs-fixer fix "$file"; done
stage_fixed: true
pytest:
glob:
- "*.py"

View File

@@ -4,6 +4,7 @@ COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
# Install deps
RUN apt-get update && apt-get install --yes --no-install-recommends \
composer \
coreutils \
curl \
file \
@@ -16,12 +17,17 @@ libxslt1.1 \
mediainfo \
npm \
perl-base \
php-zip \
rsync \
sed \
shfmt
# Install prettier
RUN npm install -g prettier
# Install php cs fixer
RUN composer global require friendsofphp/php-cs-fixer
# Add composer to path
ENV PATH="/root/.composer/vendor/bin:$PATH"
# Set uv project env, to persist stuff moving dirs
ENV UV_PROJECT_ENVIRONMENT=/root/.cache/uv/venv
# Add vent to path

View File

@@ -35,6 +35,7 @@ in
file
shfmt
prettier
php84Packages.php-cs-fixer
]);
# Installed for every architecture: only install the lib outputs
multiPkgs =