From ecb80678161d0fa54b4bc2df4348864fc90518d0 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 16 Jul 2023 14:58:42 -0700 Subject: [PATCH] web: add "Share on Facebook" and "Share on Twitter" buttons to certificates. Thanks to Delizald on github. --- html/inc/cert.inc | 27 +++++++++++++++++++++++++++ html/user/cert1.php | 26 +++++++++++++++++--------- html/user/cert_all.php | 26 +++++++++++++++++--------- html/user/cert_team.php | 29 +++++++++++++++++++---------- 4 files changed, 80 insertions(+), 28 deletions(-) diff --git a/html/inc/cert.inc b/html/inc/cert.inc index ec807a782a..76d7328f8b 100644 --- a/html/inc/cert.inc +++ b/html/inc/cert.inc @@ -52,6 +52,7 @@ function credit_string($credit, $bolden) { } // show button to download certificate as PNG +// function show_download_button() { echo '

@@ -79,4 +80,30 @@ function show_download_button() { '; } + +// 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 '

'; + $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( + '', + $fb_url, + tra('Share on Facebook') + ); + echo '

'; + + // 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('', + $tw_url, + tra('Share on Twitter') + ); +} ?> diff --git a/html/user/cert1.php b/html/user/cert1.php index 7f63cfa3c6..df73f1832b 100644 --- a/html/user/cert1.php +++ b/html/user/cert1.php @@ -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 " "; show_download_button(); +show_share_buttons(); ?> diff --git a/html/user/cert_all.php b/html/user/cert_all.php index dc9374d1af..5d70a8eac6 100644 --- a/html/user/cert_all.php +++ b/html/user/cert_all.php @@ -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 " "; show_download_button(); +show_share_buttons(); ?> diff --git a/html/user/cert_team.php b/html/user/cert_team.php index b20ce57a5a..e22ef3d323 100644 --- a/html/user/cert_team.php +++ b/html/user/cert_team.php @@ -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 " "; show_download_button(); +show_share_buttons(); ?>