Split out code to generate action links

Add (and use) two new helper functions html_account_link() and
html_account_form() to generate the links in the package actions box.

Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
This commit is contained in:
Lukas Fleischer 2015-06-26 12:06:21 +02:00
parent 3dbaee80b4
commit 4bc990f9c0
3 changed files with 86 additions and 107 deletions

View file

@ -221,6 +221,43 @@ function html_format_maintainers($maintainer, $comaintainers) {
return $code; return $code;
} }
/**
* Format a link in the package actions box
*
* @param string $uri The link target
* @param string $desc The link label
*
* @return string The generated HTML code for the action link
*/
function html_action_link($uri, $desc) {
$code = '<a href="' . htmlspecialchars($uri, ENT_QUOTES) . '">';
$code .= htmlspecialchars($desc) . '</a>';
return $code;
}
/**
* Format a form in the package actions box
*
* @param string $uri The link target
* @param string $action The action name (passed as HTTP POST parameter)
* @param string $desc The link label
*
* @return string The generated HTML code for the action link
*/
function html_action_form($uri, $action, $desc) {
$code = '<form action="' . htmlspecialchars($uri, ENT_QUOTES) . '" ';
$code .= 'method="post">';
$code .= '<input type="hidden" name="token" value="';
$code .= htmlspecialchars($_COOKIE['AURSID'], ENT_QUOTES) . '" />';
$code .= '<input type="submit" class="button text-button" name="';
$code .= htmlspecialchars($action, ENT_QUOTES) . '" ';
$code .= 'value="' . htmlspecialchars($desc, ENT_QUOTES) . '" />';
$code .= '</form>';
return $code;
}
/** /**
* Determine the user's e-mail address in the database using a session ID * Determine the user's e-mail address in the database using a session ID
* *

View file

@ -83,6 +83,9 @@ foreach ($rels as $rel) {
# $sources[0] = 'src'; # $sources[0] = 'src';
$sources = pkg_sources($row["ID"]); $sources = pkg_sources($row["ID"]);
$base_uri = get_pkgbase_uri($row['BaseName']);
?> ?>
<div id="pkgdetails" class="box"> <div id="pkgdetails" class="box">
<h2><?= __('Package Details') . ': ' . htmlspecialchars($row['Name']) . ' ' . htmlspecialchars($row['Version']) ?></h2> <h2><?= __('Package Details') . ': ' . htmlspecialchars($row['Name']) . ' ' . htmlspecialchars($row['Version']) ?></h2>
@ -99,75 +102,40 @@ $sources = pkg_sources($row["ID"]);
<li><span class="flagged"><?php if ($row["OutOfDateTS"] !== NULL) { echo __('Flagged out-of-date')." (${out_of_date_time})"; } ?></span></li> <li><span class="flagged"><?php if ($row["OutOfDateTS"] !== NULL) { echo __('Flagged out-of-date')." (${out_of_date_time})"; } ?></span></li>
<?php if ($uid): ?> <?php if ($uid): ?>
<?php if ($row["OutOfDateTS"] === NULL): ?> <?php if ($row["OutOfDateTS"] === NULL): ?>
<li> <li><?= html_action_form($base_uri . 'flag/', "do_Flag", __('Flag package out-of-date')) ?></li>
<form action="<?= get_pkgbase_uri($row['BaseName']) . 'flag/'; ?>" method="post">
<input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
<input type="submit" class="button text-button" name="do_Flag" value="<?= __('Flag package out-of-date') ?>" />
</form>
</li>
<?php elseif (($row["OutOfDateTS"] !== NULL) && has_credential(CRED_PKGBASE_UNFLAG, $maintainers)): ?> <?php elseif (($row["OutOfDateTS"] !== NULL) && has_credential(CRED_PKGBASE_UNFLAG, $maintainers)): ?>
<li> <li><?= html_action_form($base_uri . 'unflag/', "do_UnFlag", __('Unflag package')) ?></li>
<form action="<?= get_pkgbase_uri($row['BaseName']) . 'unflag/'; ?>" method="post">
<input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
<input type="submit" class="button text-button" name="do_UnFlag" value="<?= __('Unflag package') ?>" />
</form>
</li>
<?php endif; ?> <?php endif; ?>
<?php if (pkgbase_user_voted($uid, $base_id)): ?> <?php if (pkgbase_user_voted($uid, $base_id)): ?>
<li> <li><?= html_action_form($base_uri . 'unvote/', "do_UnVote", __('Remove vote')) ?></li>
<form action="<?= get_pkgbase_uri($row['BaseName']) . 'unvote/'; ?>" method="post">
<input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
<input type="submit" class="button text-button" name="do_UnVote" value="<?= __('Remove vote') ?>" />
</form>
</li>
<?php else: ?> <?php else: ?>
<li> <li><?= html_action_form($base_uri . 'vote/', "do_Vote", __('Vote for this package')) ?></li>
<form action="<?= get_pkgbase_uri($row['BaseName']) . 'vote/'; ?>" method="post">
<input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
<input type="submit" class="button text-button" name="do_Vote" value="<?= __('Vote for this package') ?>" />
</form>
</li>
<?php endif; ?> <?php endif; ?>
<?php if (pkgbase_user_notify($uid, $base_id)): ?> <?php if (pkgbase_user_notify($uid, $base_id)): ?>
<li> <li><?= html_action_form($base_uri . 'unnotify/', "do_UnNotify", __('Disable notifications')) ?></li>
<form action="<?= get_pkgbase_uri($row['BaseName']) . 'unnotify/'; ?>" method="post">
<input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
<input type="submit" class="button text-button" name="do_UnNotify" value="<?= __('Disable notifications') ?>" />
</form>
</li>
<?php else: ?> <?php else: ?>
<li> <li><?= html_action_form($base_uri . 'notify/', "do_Notify", __('Notify of new comments')) ?></li>
<form action="<?= get_pkgbase_uri($row['BaseName']) . 'notify/'; ?>" method="post">
<input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
<input type="submit" class="button text-button" name="do_Notify" value="<?= __('Notify of new comments') ?>" />
</form>
</li>
<?php endif; ?> <?php endif; ?>
<?php if (has_credential(CRED_PKGBASE_EDIT_COMAINTAINERS, array($row["MaintainerUID"]))): ?> <?php if (has_credential(CRED_PKGBASE_EDIT_COMAINTAINERS, array($row["MaintainerUID"]))): ?>
<li><a href="<?= get_pkgbase_uri($row['BaseName']) . 'comaintainers/'; ?>"><?= __('Manage Co-Maintainers'); ?></a></li> <li><?= html_action_link($base_uri . 'comaintainers/', __('Manage Co-Maintainers')) ?></a></li>
<?php endif; ?> <?php endif; ?>
<li><span class="flagged"><?php if ($row["RequestCount"] > 0) { echo _n('%d pending request', '%d pending requests', $row["RequestCount"]); } ?></span></li> <li><span class="flagged"><?php if ($row["RequestCount"] > 0) { echo _n('%d pending request', '%d pending requests', $row["RequestCount"]); } ?></span></li>
<li><a href="<?= get_pkgbase_uri($row['BaseName']) . 'request/'; ?>"><?= __('File Request'); ?></a></li> <li><?= html_action_link($base_uri . 'request/', __('File Request')) ?></a></li>
<?php if (has_credential(CRED_PKGBASE_DELETE)): ?> <?php if (has_credential(CRED_PKGBASE_DELETE)): ?>
<li><a href="<?= get_pkgbase_uri($row['BaseName']) . 'delete/'; ?>"><?= __('Delete Package'); ?></a></li> <li><?= html_action_link($base_uri . 'delete/', __('Delete Package')) ?></a></li>
<li><a href="<?= get_pkgbase_uri($row['BaseName']) . 'merge/'; ?>"><?= __('Merge Package'); ?></a></li> <li><?= html_action_link($base_uri . 'merge/', __('Merge Package')) ?></a></li>
<?php endif; ?>
<?php endif; ?> <?php endif; ?>
<?php if ($uid && $row["MaintainerUID"] === NULL): ?> <?php if ($uid && $row["MaintainerUID"] === NULL): ?>
<li> <li><?= html_action_form($base_uri . 'adopt/', "do_Adopt", __('Adopt Package')) ?></li>
<form action="<?= get_pkgbase_uri($row['BaseName']) . 'adopt/'; ?>" method="post">
<input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
<input type="submit" class="button text-button" name="do_Adopt" value="<?= __('Adopt Package') ?>" />
</form>
</li>
<?php elseif (has_credential(CRED_PKGBASE_DISOWN, array($row["MaintainerUID"]))): ?> <?php elseif (has_credential(CRED_PKGBASE_DISOWN, array($row["MaintainerUID"]))): ?>
<li> <li><?= html_action_form($base_uri . 'disown/', "do_Disown", __('Disown Package')) ?></li>
<form action="<?= get_pkgbase_uri($row['BaseName']) . 'disown/'; ?>" method="post"> <?php endif; ?>
<input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
<input type="submit" class="button text-button" name="do_Disown" value="<?= __('Disown Package') ?>" />
</form>
</li>
<?php endif; ?> <?php endif; ?>
</ul> </ul>
</div> </div>

View file

@ -17,6 +17,12 @@ $maintainer = username_from_id($row["MaintainerUID"]);
$comaintainers = pkgbase_get_comaintainers($base_id); $comaintainers = pkgbase_get_comaintainers($base_id);
$packager = username_from_id($row["PackagerUID"]); $packager = username_from_id($row["PackagerUID"]);
if ($row["MaintainerUID"] !== NULL) {
$maintainers = array_merge(array($row["MaintainerUID"]), pkgbase_get_comaintainer_uids(array($base_id)));
} else {
$maintainers = NULL;
}
$votes = $row['NumVotes']; $votes = $row['NumVotes'];
# In case of wanting to put a custom message # In case of wanting to put a custom message
@ -28,6 +34,9 @@ $submitted_time = ($row["SubmittedTS"] == 0) ? $msg : gmdate("Y-m-d H:i", intval
$out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : gmdate("Y-m-d", intval($row["OutOfDateTS"])); $out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : gmdate("Y-m-d", intval($row["OutOfDateTS"]));
$pkgs = pkgbase_get_pkgnames($base_id); $pkgs = pkgbase_get_pkgnames($base_id);
$base_uri = get_pkgbase_uri($row['Name']);
?> ?>
<div id="pkgdetails" class="box"> <div id="pkgdetails" class="box">
<h2><?= __('Package Base Details') . ': ' . htmlspecialchars($row['Name']) ?></h2> <h2><?= __('Package Base Details') . ': ' . htmlspecialchars($row['Name']) ?></h2>
@ -44,75 +53,40 @@ $pkgs = pkgbase_get_pkgnames($base_id);
<li><span class="flagged"><?php if ($row["OutOfDateTS"] !== NULL) { echo __('Flagged out-of-date')." (${out_of_date_time})"; } ?></span></li> <li><span class="flagged"><?php if ($row["OutOfDateTS"] !== NULL) { echo __('Flagged out-of-date')." (${out_of_date_time})"; } ?></span></li>
<?php if ($uid): ?> <?php if ($uid): ?>
<?php if ($row["OutOfDateTS"] === NULL): ?> <?php if ($row["OutOfDateTS"] === NULL): ?>
<li> <li><?= html_action_form($base_uri . 'flag/', "do_Flag", __('Flag package out-of-date')) ?></li>
<form action="<?= get_pkgbase_uri($row['Name']) . 'flag/'; ?>" method="post"> <?php elseif (($row["OutOfDateTS"] !== NULL) && has_credential(CRED_PKGBASE_UNFLAG, $maintainers)): ?>
<input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" /> <li><?= html_action_form($base_uri . 'unflag/', "do_UnFlag", __('Unflag package')) ?></li>
<input type="submit" class="button text-button" name="do_Flag" value="<?= __('Flag package out-of-date') ?>" />
</form>
</li>
<?php elseif (($row["OutOfDateTS"] !== NULL) && has_credential(CRED_PKGBASE_UNFLAG, array($row["MaintainerUID"]))): ?>
<li>
<form action="<?= get_pkgbase_uri($row['Name']) . 'unflag/'; ?>" method="post">
<input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
<input type="submit" class="button text-button" name="do_UnFlag" value="<?= __('Unflag package') ?>" />
</form>
</li>
<?php endif; ?> <?php endif; ?>
<?php if (pkgbase_user_voted($uid, $base_id)): ?> <?php if (pkgbase_user_voted($uid, $base_id)): ?>
<li> <li><?= html_action_form($base_uri . 'unvote/', "do_UnVote", __('Remove vote')) ?></li>
<form action="<?= get_pkgbase_uri($row['Name']) . 'unvote/'; ?>" method="post">
<input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
<input type="submit" class="button text-button" name="do_UnVote" value="<?= __('Remove vote') ?>" />
</form>
</li>
<?php else: ?> <?php else: ?>
<li> <li><?= html_action_form($base_uri . 'vote/', "do_Vote", __('Vote for this package')) ?></li>
<form action="<?= get_pkgbase_uri($row['Name']) . 'vote/'; ?>" method="post">
<input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
<input type="submit" class="button text-button" name="do_Vote" value="<?= __('Vote for this package') ?>" />
</form>
</li>
<?php endif; ?> <?php endif; ?>
<?php if (pkgbase_user_notify($uid, $base_id)): ?> <?php if (pkgbase_user_notify($uid, $base_id)): ?>
<li> <li><?= html_action_form($base_uri . 'unnotify/', "do_UnNotify", __('Disable notifications')) ?></li>
<form action="<?= get_pkgbase_uri($row['Name']) . 'unnotify/'; ?>" method="post">
<input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
<input type="submit" class="button text-button" name="do_UnNotify" value="<?= __('Disable notifications') ?>" />
</form>
</li>
<?php else: ?> <?php else: ?>
<li> <li><?= html_action_form($base_uri . 'notify/', "do_Notify", __('Notify of new comments')) ?></li>
<form action="<?= get_pkgbase_uri($row['Name']) . 'notify/'; ?>" method="post">
<input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
<input type="submit" class="button text-button" name="do_Notify" value="<?= __('Notify of new comments') ?>" />
</form>
</li>
<?php endif; ?> <?php endif; ?>
<?php if (has_credential(CRED_PKGBASE_EDIT_COMAINTAINERS, array($row["MaintainerUID"]))): ?> <?php if (has_credential(CRED_PKGBASE_EDIT_COMAINTAINERS, array($row["MaintainerUID"]))): ?>
<li><a href="<?= get_pkgbase_uri($row['Name']) . 'comaintainers/'; ?>"><?= __('Manage Co-Maintainers'); ?></a></li> <li><?= html_action_link($base_uri . 'comaintainers/', __('Manage Co-Maintainers')) ?></a></li>
<?php endif; ?> <?php endif; ?>
<li><span class="flagged"><?php if ($row["RequestCount"] > 0) { echo _n('%d pending request', '%d pending requests', $row["RequestCount"]); } ?></span></li> <li><span class="flagged"><?php if ($row["RequestCount"] > 0) { echo _n('%d pending request', '%d pending requests', $row["RequestCount"]); } ?></span></li>
<li><a href="<?= get_pkgbase_uri($row['Name']) . 'request/'; ?>"><?= __('File Request'); ?></a></li> <li><?= html_action_link($base_uri . 'request/', __('File Request')) ?></a></li>
<?php if (has_credential(CRED_PKGBASE_DELETE)): ?> <?php if (has_credential(CRED_PKGBASE_DELETE)): ?>
<li><a href="<?= get_pkgbase_uri($row['Name']) . 'delete/'; ?>"><?= __('Delete Package'); ?></a></li> <li><?= html_action_link($base_uri . 'delete/', __('Delete Package')) ?></a></li>
<li><a href="<?= get_pkgbase_uri($row['Name']) . 'merge/'; ?>"><?= __('Merge Package'); ?></a></li> <li><?= html_action_link($base_uri . 'merge/', __('Merge Package')) ?></a></li>
<?php endif; ?>
<?php endif; ?> <?php endif; ?>
<?php if ($uid && $row["MaintainerUID"] === NULL): ?> <?php if ($uid && $row["MaintainerUID"] === NULL): ?>
<li> <li><?= html_action_form($base_uri . 'adopt/', "do_Adopt", __('Adopt Package')) ?></li>
<form action="<?= get_pkgbase_uri($row['Name']) . 'adopt/'; ?>" method="post">
<input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
<input type="submit" class="button text-button" name="do_Adopt" value="<?= __('Adopt Package') ?>" />
</form>
</li>
<?php elseif (has_credential(CRED_PKGBASE_DISOWN, array($row["MaintainerUID"]))): ?> <?php elseif (has_credential(CRED_PKGBASE_DISOWN, array($row["MaintainerUID"]))): ?>
<li> <li><?= html_action_form($base_uri . 'disown/', "do_Disown", __('Disown Package')) ?></li>
<form action="<?= get_pkgbase_uri($row['Name']) . 'disown/'; ?>" method="post"> <?php endif; ?>
<input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
<input type="submit" class="button text-button" name="do_Disown" value="<?= __('Disown Package') ?>" />
</form>
</li>
<?php endif; ?> <?php endif; ?>
</ul> </ul>
</div> </div>