[aur-dev] [PATCH 1/2] Refactor code for printing account links
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- web/lib/aur.inc.php | 13 +++++++++++-- web/template/pkg_details.php | 18 ------------------ web/template/pkgbase_details.php | 18 ------------------ web/template/tu_last_votes_list.php | 2 +- 4 files changed, 12 insertions(+), 39 deletions(-) diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php index c4a1705..2d06fc8 100644 --- a/web/lib/aur.inc.php +++ b/web/lib/aur.inc.php @@ -181,10 +181,19 @@ function username_from_sid($sid="") { * * @param string $username The user name to format * - * @return void + * @return string The generated HTML code for the account link */ function html_format_username($username) { - return $username ? htmlspecialchars($username) : __("None"); + $username_fmt = $username ? htmlspecialchars($username, ENT_QUOTES) : __("None"); + + if ($username && $_COOKIE["AURSID"]) { + $link = '<a href="' . get_uri('/account/') . $username_fmt; + $link .= '" title="' . __('View account information for %s', $username_fmt); + $link .= '">' . $username_fmt . '</a>'; + return $link; + } else { + return $username_fmt; + } } /** diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index cc2f055..7b75210 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -289,33 +289,15 @@ if (has_credential(CRED_PKGBASE_SET_KEYWORDS, array($row["MaintainerUID"]))): <?php endif; ?> <tr> <th><?= __('Submitter') .': ' ?></th> - <?php if ($row["SubmitterUID"] && $SID): ?> - <td><a href="<?= get_uri('/account/') . html_format_username($submitter, ENT_QUOTES) ?>" title="<?= __('View account information for %s', html_format_username($submitter)) ?>"><?= html_format_username($submitter) ?></a></td> - <?php elseif ($row["SubmitterUID"] && !$SID): ?> <td><?= html_format_username($submitter) ?></td> - <?php else: ?> - <td><?= __('None') ?></td> - <?php endif; ?> </tr> <tr> <th><?= __('Maintainer') .': ' ?></th> - <?php if ($row["MaintainerUID"] && $SID): ?> - <td><a href="<?= get_uri('/account/') . html_format_username($maintainer) ?>" title="<?= __('View account information for %s', html_format_username($maintainer)) ?>"><?= html_format_username($maintainer) ?></a></td> - <?php elseif ($row["MaintainerUID"] && !$SID): ?> <td><?= html_format_username($maintainer) ?></td> - <?php else: ?> - <td><?= __('None') ?></td> - <?php endif; ?> </tr> <tr> <th><?= __('Last Packager') .': ' ?></th> - <?php if ($row["PackagerUID"] && $SID): ?> - <td><a href="<?= get_uri('/account/') . html_format_username($packager) ?>" title="<?= __('View account information for %s', html_format_username($packager)) ?>"><?= html_format_username($packager) ?></a></td> - <?php elseif ($row["PackagerUID"] && !$SID): ?> <td><?= html_format_username($packager) ?></td> - <?php else: ?> - <td><?= __('None') ?></td> - <?php endif; ?> </tr> <tr> <th><?= __('Votes') . ': ' ?></th> diff --git a/web/template/pkgbase_details.php b/web/template/pkgbase_details.php index 2522f34..2ceb35f 100644 --- a/web/template/pkgbase_details.php +++ b/web/template/pkgbase_details.php @@ -148,33 +148,15 @@ if (has_credential(CRED_PKGBASE_SET_KEYWORDS, array($row["MaintainerUID"]))): <?php endif; ?> <tr> <th><?= __('Submitter') .': ' ?></th> - <?php if ($row["SubmitterUID"] && $SID): ?> - <td><a href="<?= get_uri('/account/') . html_format_username($submitter, ENT_QUOTES) ?>" title="<?= __('View account information for %s', html_format_username($submitter)) ?>"><?= html_format_username($submitter) ?></a></td> - <?php elseif ($row["SubmitterUID"] && !$SID): ?> <td><?= html_format_username($submitter) ?></td> - <?php else: ?> - <td><?= __('None') ?></td> - <?php endif; ?> </tr> <tr> <th><?= __('Maintainer') .': ' ?></th> - <?php if ($row["MaintainerUID"] && $SID): ?> - <td><a href="<?= get_uri('/account/') . html_format_username($maintainer) ?>" title="<?= __('View account information for %s', html_format_username($maintainer)) ?>"><?= html_format_username($maintainer) ?></a></td> - <?php elseif ($row["MaintainerUID"] && !$SID): ?> <td><?= html_format_username($maintainer) ?></td> - <?php else: ?> - <td><?= __('None') ?></td> - <?php endif; ?> </tr> <tr> <th><?= __('Last Packager') .': ' ?></th> - <?php if ($row["PackagerUID"] && $SID): ?> - <td><a href="<?= get_uri('/account/') . html_format_username($packager) ?>" title="<?= __('View account information for %s', html_format_username($packager)) ?>"><?= html_format_username($packager) ?></a></td> - <?php elseif ($row["PackagerUID"] && !$SID): ?> <td><?= html_format_username($packager) ?></td> - <?php else: ?> - <td><?= __('None') ?></td> - <?php endif; ?> </tr> <tr> <th><?= __('Votes') . ': ' ?></th> diff --git a/web/template/tu_last_votes_list.php b/web/template/tu_last_votes_list.php index f7b07bc..5cff248 100644 --- a/web/template/tu_last_votes_list.php +++ b/web/template/tu_last_votes_list.php @@ -21,7 +21,7 @@ ?> <tr class="<?= $c ?>"> <td> - <a href="<?= get_uri('/account/') . html_format_username($username) ?>" title="<?= __('View account information for %s', html_format_username($username)) ?>"><?= html_format_username($username) ?></a> + <?= html_format_username($username) ?> </td> <td> <a href="<?= get_uri('/tu/'); ?>?id=<?= $row['LastVote'] ?>"><?= intval($row["LastVote"]) ?></a> -- 2.4.3
Implements FS#45313. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- web/lib/aur.inc.php | 25 +++++++++++++++++++++++++ web/template/pkg_details.php | 3 ++- web/template/pkgbase_details.php | 3 ++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php index 2d06fc8..a45c9b6 100644 --- a/web/lib/aur.inc.php +++ b/web/lib/aur.inc.php @@ -197,6 +197,31 @@ function html_format_username($username) { } /** + * Format the maintainer and co-maintainers for inclusion in HTML data + * + * @param string $maintainer The user name of the maintainer + * @param array $comaintainers The list of co-maintainer user names + * + * @return string The generated HTML code for the account links + */ +function html_format_maintainers($maintainer, $comaintainers) { + $code = html_format_username($maintainer); + + if (count($comaintainers) > 0) { + $code .= ' ('; + foreach ($comaintainers as $comaintainer) { + $code .= html_format_username($comaintainer); + if ($comaintainer !== end($comaintainers)) { + $code .= ', '; + } + } + $code .= ')'; + } + + return $code; +} + +/** * Determine the user's e-mail address in the database using a session ID * * @param string $sid User's session ID diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index 7b75210..ae49e24 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -15,6 +15,7 @@ $keywords = pkgbase_get_keywords($base_id); $submitter = username_from_id($row["SubmitterUID"]); $maintainer = username_from_id($row["MaintainerUID"]); +$comaintainers = pkgbase_get_comaintainers($base_id); $packager = username_from_id($row["PackagerUID"]); $votes = $row['NumVotes']; @@ -293,7 +294,7 @@ if (has_credential(CRED_PKGBASE_SET_KEYWORDS, array($row["MaintainerUID"]))): </tr> <tr> <th><?= __('Maintainer') .': ' ?></th> - <td><?= html_format_username($maintainer) ?></td> + <td><?= html_format_maintainers($maintainer, $comaintainers) ?></td> </tr> <tr> <th><?= __('Last Packager') .': ' ?></th> diff --git a/web/template/pkgbase_details.php b/web/template/pkgbase_details.php index 2ceb35f..fa24e12 100644 --- a/web/template/pkgbase_details.php +++ b/web/template/pkgbase_details.php @@ -14,6 +14,7 @@ $keywords = pkgbase_get_keywords($base_id); $submitter = username_from_id($row["SubmitterUID"]); $maintainer = username_from_id($row["MaintainerUID"]); +$comaintainers = pkgbase_get_comaintainers($base_id); $packager = username_from_id($row["PackagerUID"]); $votes = $row['NumVotes']; @@ -152,7 +153,7 @@ if (has_credential(CRED_PKGBASE_SET_KEYWORDS, array($row["MaintainerUID"]))): </tr> <tr> <th><?= __('Maintainer') .': ' ?></th> - <td><?= html_format_username($maintainer) ?></td> + <td><?= html_format_maintainers($maintainer, $comaintainers) ?></td> </tr> <tr> <th><?= __('Last Packager') .': ' ?></th> -- 2.4.3
participants (1)
-
Lukas Fleischer