web: add "Share on Facebook" and "Share on Twitter" buttons to certificates.

Thanks to Delizald on github.
This commit is contained in:
David Anderson 2023-07-16 14:58:42 -07:00
parent 6a7c4a6202
commit ecb8067816
4 changed files with 80 additions and 28 deletions

View File

@ -52,6 +52,7 @@ function credit_string($credit, $bolden) {
}
// show button to download certificate as PNG
//
function show_download_button() {
echo '
<p>
@ -79,4 +80,30 @@ function show_download_button() {
</script>
';
}
// show buttons to share certificate on facebook and twitter
// Note: the cert pages don't use bootstrap, so we can't use show_button()
//
function show_share_buttons() {
echo '<p>';
$current_url = (empty($_SERVER['HTTPS']) ? 'http' : 'https') . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$cert_url = urlencode($current_url);
// Share on Facebook
$fb_url = 'https://www.facebook.com/sharer/sharer.php?u='.$cert_url;
echo sprintf(
'<button onclick="window.location.href=\'%s\';">%s</button>',
$fb_url,
tra('Share on Facebook')
);
echo '<p>';
// Share on Twitter
$twitter_text = urlencode("Check out my computation certificate from BOINC!");
$tw_url = 'https://twitter.com/intent/tweet?url='.$cert_url.'&text='.$twitter_text;
echo sprintf('<button onclick="window.location.href=\'%s\';">%s</button>',
$tw_url,
tra('Share on Twitter')
);
}
?>

View File

@ -23,21 +23,28 @@
require_once("../inc/util.inc");
require_once("../inc/cert.inc");
check_get_args(array("border"));
$user = get_logged_in_user();
$join = gmdate('j F Y', $user->create_time);
$today = gmdate('j F Y', time());
$border = get_str("border", true);
if ($border=="no") {
$border = 0;
$border=0;
} else {
$border=8;
}
// Make sure user_id is in the URL so that share functions work
//
$user_id = get_int('user_id', true);
if (!$user_id) {
$user = get_logged_in_user();
Header(sprintf('Location: %s/cert1.php?user_id=%d%s',
url_base(), $user->id, $border==0?'&border=no':''
));
exit;
}
$user = BoincUser::lookup_id($user_id);
$join = gmdate('j F Y', $user->create_time);
$today = gmdate('j F Y', time());
$credit = credit_string($user->total_credit, false);
$font = "\"Optima,Lucida Bright,Times New Roman\"";
@ -100,4 +107,5 @@ echo "
</td><tr></table></table>
";
show_download_button();
show_share_buttons();
?>

View File

@ -24,21 +24,28 @@ require_once("../inc/util.inc");
require_once("../inc/cert.inc");
require_once("../inc/user.inc");
check_get_args(array("border"));
$user = get_logged_in_user();
$join = gmdate('j F Y', $user->create_time);
$today = gmdate('j F Y', time());
$border = get_str("border", true);
if ($border=="no") {
$border = 0;
$border=0;
} else {
$border=8;
}
// Make sure user_id is in the URL so that share functions work
//
$user_id = get_int('user_id', true);
if (!$user_id) {
$user = get_logged_in_user();
Header(sprintf('Location: %s/cert_all.php?user_id=%d%s',
url_base(), $user->id, $border==0?'&border=no':''
));
exit;
}
$user = BoincUser::lookup_id($user_id);
$join = gmdate('j F Y', $user->create_time);
$today = gmdate('j F Y', time());
$font = "\"Optima,Lucida Bright,Times New Roman\"";
$user = get_other_projects($user);
@ -99,4 +106,5 @@ echo "
</td><tr></table></table>
";
show_download_button();
show_share_buttons();
?>

View File

@ -26,9 +26,25 @@ require_once("../inc/cert.inc");
if (DISABLE_TEAMS) error_page("Teams are disabled");
check_get_args(array("border"));
$border = get_str("border", true);
if ($border=="no") {
$border=0;
} else {
$border=8;
}
$user = get_logged_in_user();
// Make sure user_id is in the URL so that share functions work
//
$user_id = get_int('user_id', true);
if (!$user_id) {
$user = get_logged_in_user();
Header(sprintf('Location: %s/cert_team.php?user_id=%d%s',
url_base(), $user->id, $border==0?'&border=no':''
));
exit;
}
$user = BoincUser::lookup_id($user_id);
$team = BoincTeam::lookup_id($user->teamid);
if (!$team) error_page("no team");
@ -37,14 +53,6 @@ $today = gmdate('j F Y', time());
credit_to_ops($team->total_credit, $ops, $unit);
$border = get_str("border", true);
if ($border=="no") {
$border = 0;
} else {
$border=8;
}
$credit = credit_string($team->total_credit, false);
$font = "\"Optima,Lucida Bright,Times New Roman\"";
@ -107,4 +115,5 @@ echo "
</td><tr></table></table>
";
show_download_button();
show_share_buttons();
?>