[aur-dev] [PATCH] Refactor TU voters list
* Change voters_list() to return an array of voters instead of generating HTML code in the library call. * Change the template to generate HTML code for the list of voters instead of displaying the library's return value. * Use HTML lists. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- web/lib/acctfuncs.inc.php | 6 +++--- web/template/tu_details.php | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php index bce00f8..3fd23ae 100644 --- a/web/lib/acctfuncs.inc.php +++ b/web/lib/acctfuncs.inc.php @@ -969,14 +969,14 @@ function vote_details($voteid, $dbh=NULL) { * @param string $voteid The ID of the Trusted User proposal * @param \PDO $dbh An already established database connection * - * @return array All users (and HTML links) who voted for a specific proposal + * @return array All users who voted for a specific proposal */ function voter_list($voteid, $dbh=NULL) { if (!$dbh) { $dbh = db_connect(); } - $whovoted = ''; + $whovoted = array(); $q = "SELECT tv.UserID,U.Username "; $q.= "FROM TU_Votes tv, Users U "; @@ -987,7 +987,7 @@ function voter_list($voteid, $dbh=NULL) { $result = $dbh->query($q); if ($result) { while ($row = $result->fetch(PDO::FETCH_ASSOC)) { - $whovoted.= '<a href="' . get_user_uri($row['Username']) . '">'.$row['Username'].'</a> '; + $whovoted[] = $row['Username']; } } return $whovoted; diff --git a/web/template/tu_details.php b/web/template/tu_details.php index b53797f..89a7667 100644 --- a/web/template/tu_details.php +++ b/web/template/tu_details.php @@ -54,7 +54,11 @@ <?php if (!$isrunning): ?> <div class="box"> <h2><?= __("Voters"); ?></h2> - <?= $whovoted; ?> + <ul> + <?php foreach($whovoted => $voter): ?> + <li><a href="<?= get_user_uri($voter) ?>"><?= htmlspecialchars($voter) ?></a></li> + <?php endforeach; ?> + </ul> </div> <?php endif; ?> -- 1.7.12.2
* Change voters_list() to return an array of voters instead of generating HTML code in the library call. * Change the template to generate HTML code for the list of voters instead of displaying the library's return value. * Use HTML lists. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- Syntax fix. web/lib/acctfuncs.inc.php | 6 +++--- web/template/tu_details.php | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php index bce00f8..3fd23ae 100644 --- a/web/lib/acctfuncs.inc.php +++ b/web/lib/acctfuncs.inc.php @@ -969,14 +969,14 @@ function vote_details($voteid, $dbh=NULL) { * @param string $voteid The ID of the Trusted User proposal * @param \PDO $dbh An already established database connection * - * @return array All users (and HTML links) who voted for a specific proposal + * @return array All users who voted for a specific proposal */ function voter_list($voteid, $dbh=NULL) { if (!$dbh) { $dbh = db_connect(); } - $whovoted = ''; + $whovoted = array(); $q = "SELECT tv.UserID,U.Username "; $q.= "FROM TU_Votes tv, Users U "; @@ -987,7 +987,7 @@ function voter_list($voteid, $dbh=NULL) { $result = $dbh->query($q); if ($result) { while ($row = $result->fetch(PDO::FETCH_ASSOC)) { - $whovoted.= '<a href="' . get_user_uri($row['Username']) . '">'.$row['Username'].'</a> '; + $whovoted[] = $row['Username']; } } return $whovoted; diff --git a/web/template/tu_details.php b/web/template/tu_details.php index b53797f..be816ce 100644 --- a/web/template/tu_details.php +++ b/web/template/tu_details.php @@ -54,7 +54,11 @@ <?php if (!$isrunning): ?> <div class="box"> <h2><?= __("Voters"); ?></h2> - <?= $whovoted; ?> + <ul> + <?php foreach($whovoted as $voter): ?> + <li><a href="<?= get_user_uri($voter) ?>"><?= htmlspecialchars($voter) ?></a></li> + <?php endforeach; ?> + </ul> </div> <?php endif; ?> -- 1.7.12.2
participants (1)
-
Lukas Fleischer