Avoid double slashes in notification email body

Refactor some of the URI generation code to avoid double slashes in
absolute URIs.

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
This commit is contained in:
Lukas Fleischer 2014-12-13 15:28:05 +01:00
parent aa2724bbfe
commit 5ebf534ba7
6 changed files with 26 additions and 20 deletions

View file

@ -48,7 +48,7 @@ html_header('AUR ' . __("Login"));
<?php else: ?> <?php else: ?>
<p> <p>
<?php printf(__("HTTP login is disabled. Please %sswitch to HTTPs%s if you want to login."), <?php printf(__("HTTP login is disabled. Please %sswitch to HTTPs%s if you want to login."),
'<a href="' . aur_location() . get_uri('/login') . '">', '</a>'); ?> '<a href="' . get_uri('/login', true) . '">', '</a>'); ?>
</p> </p>
<?php endif; ?> <?php endif; ?>
</div> </div>

View file

@ -660,7 +660,7 @@ function send_resetkey($email, $subject, $body) {
/* Send e-mail with confirmation link. */ /* Send e-mail with confirmation link. */
$body = wordwrap($body, 70); $body = wordwrap($body, 70);
$body .= "\n\n". aur_location() . get_uri('/passreset/') . $body .= "\n\n". get_uri('/passreset/', true) .
"?resetkey={$resetkey}"; "?resetkey={$resetkey}";
$headers = "MIME-Version: 1.0\r\n" . $headers = "MIME-Version: 1.0\r\n" .
"Content-type: text/plain; charset=UTF-8\r\n" . "Content-type: text/plain; charset=UTF-8\r\n" .

View file

@ -131,8 +131,7 @@ function pkgbase_add_comment($base_id, $uid, $comment) {
* work, users would be getting emails in the language that the * work, users would be getting emails in the language that the
* user who posted the comment was in. * user who posted the comment was in.
*/ */
$body = $body = 'from ' . get_pkgbase_uri($row['Name'], true) . "\n"
'from ' . aur_location() . get_pkgbase_uri($row['Name']) . "\n"
. username_from_sid($_COOKIE['AURSID']) . " wrote:\n\n" . username_from_sid($_COOKIE['AURSID']) . " wrote:\n\n"
. $comment . $comment
. "\n\n---\nIf you no longer wish to receive notifications about this package, please go the the above package page and click the UnNotify button."; . "\n\n---\nIf you no longer wish to receive notifications about this package, please go the the above package page and click the UnNotify button.";
@ -380,7 +379,7 @@ function pkgbase_flag($base_ids) {
$result = $dbh->query($q); $result = $dbh->query($q);
if ($result) { if ($result) {
while ($row = $result->fetch(PDO::FETCH_ASSOC)) { while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$body = "Your package " . $row['Name'] . " has been flagged out of date by " . $f_name . " [1]. You may view your package at:\n" . aur_location() . get_pkgbase_uri($row['Name']) . "\n\n[1] - " . aur_location() . get_user_uri($f_name); $body = "Your package " . $row['Name'] . " has been flagged out of date by " . $f_name . " [1]. You may view your package at:\n" . get_pkgbase_uri($row['Name'], true) . "\n\n[1] - " . get_user_uri($f_name, true);
$body = wordwrap($body, 70); $body = wordwrap($body, 70);
$headers = "MIME-Version: 1.0\r\n" . $headers = "MIME-Version: 1.0\r\n" .
"Content-type: text/plain; charset=UTF-8\r\n" . "Content-type: text/plain; charset=UTF-8\r\n" .

View file

@ -160,15 +160,15 @@ function pkgreq_file($ids, $type, $merge_into, $comments) {
$username . " [1] filed a request to merge " . $username . " [1] filed a request to merge " .
$row['Name'] . " [2] into " . $merge_into . $row['Name'] . " [2] into " . $merge_into .
" [3]:\n\n" . $comments . "\n\n" . " [3]:\n\n" . $comments . "\n\n" .
"[1] " . aur_location() . get_user_uri($username) . "\n" . "[1] " . get_user_uri($username, true) . "\n" .
"[2] " . aur_location() . get_pkgbase_uri($row['Name']) . "\n" . "[2] " . get_pkgbase_uri($row['Name'], true) . "\n" .
"[3] " . aur_location() . get_pkgbase_uri($merge_into) . "\n"; "[3] " . get_pkgbase_uri($merge_into, true) . "\n";
} else { } else {
$body = $body =
$username . " [1] filed a " . $type . " request for " . $username . " [1] filed a " . $type . " request for " .
$row['Name'] . " [2]:\n\n" . $comments . "\n\n" . $row['Name'] . " [2]:\n\n" . $comments . "\n\n" .
"[1] " . aur_location() . get_user_uri($username) . "\n" . "[1] " . get_user_uri($username, true) . "\n" .
"[2] " . aur_location() . get_pkgbase_uri($row['Name']) . "\n"; "[2] " . get_pkgbase_uri($row['Name'], true) . "\n";
} }
$body = wordwrap($body, 70); $body = wordwrap($body, 70);
$cc = array_unique($cc); $cc = array_unique($cc);
@ -278,7 +278,7 @@ function pkgreq_close($id, $reason, $comments, $auto_close=false) {
} }
if (!$auto_close) { if (!$auto_close) {
$body .= "\n"; $body .= "\n";
$body .= "[1] " . aur_location() . get_user_uri($username); $body .= "[1] " . get_user_uri($username, true);
$body .= "\n"; $body .= "\n";
} }
$body = wordwrap($body, 70); $body = wordwrap($body, 70);

View file

@ -37,9 +37,13 @@ function get_route($path) {
} }
} }
function get_uri($path) { function get_uri($path, $absolute=false) {
if ($absolute) {
return rtrim(aur_location(), '/') . $path;
} else {
return $path; return $path;
} }
}
function get_pkg_route() { function get_pkg_route() {
global $PKG_PATH; global $PKG_PATH;
@ -56,14 +60,16 @@ function get_pkgreq_route() {
return $PKGREQ_PATH; return $PKGREQ_PATH;
} }
function get_pkg_uri($pkgname) { function get_pkg_uri($pkgname, $absolute=false) {
global $PKG_PATH; global $PKG_PATH;
return $PKG_PATH . '/' . urlencode($pkgname) . '/'; $path = $PKG_PATH . '/' . urlencode($pkgname) . '/';
return get_uri($path, $absolute);
} }
function get_pkgbase_uri($pkgbase_name) { function get_pkgbase_uri($pkgbase_name, $absolute=false) {
global $PKGBASE_PATH; global $PKGBASE_PATH;
return $PKGBASE_PATH . '/' . urlencode($pkgbase_name) . '/'; $path = $PKGBASE_PATH . '/' . urlencode($pkgbase_name) . '/';
return get_uri($path, $absolute);
} }
function get_user_route() { function get_user_route() {
@ -71,7 +77,8 @@ function get_user_route() {
return $USER_PATH; return $USER_PATH;
} }
function get_user_uri($username) { function get_user_uri($username, $absolute=false) {
global $USER_PATH; global $USER_PATH;
return $USER_PATH . '/' . urlencode($username) . '/'; $path = $USER_PATH . '/' . urlencode($username) . '/';
return get_uri($path, $absolute);
} }

View file

@ -70,7 +70,7 @@
<?php else: ?> <?php else: ?>
<li><a href="<?= get_uri('/register/'); ?>"><?= __("Register"); ?></a></li> <li><a href="<?= get_uri('/register/'); ?>"><?= __("Register"); ?></a></li>
<?php if (config_get_bool('options', 'disable_http_login') && empty($_SERVER['HTTPS'])): ?> <?php if (config_get_bool('options', 'disable_http_login') && empty($_SERVER['HTTPS'])): ?>
<li><a href="<?= aur_location() . get_uri('/login/'); ?>"><?= __("Login"); ?></a></li> <li><a href="<?= get_uri('/login/', true); ?>"><?= __("Login"); ?></a></li>
<?php else: ?> <?php else: ?>
<li><a href="<?= get_uri('/login/'); ?>"><?= __("Login"); ?></a></li> <li><a href="<?= get_uri('/login/'); ?>"><?= __("Login"); ?></a></li>
<?php endif; ?> <?php endif; ?>