Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions html/inc/cert.inc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function credit_string($credit, $bolden) {
}

// show button to download certificate as PNG
//
function show_download_button() {
echo '
<p>
Expand Down Expand Up @@ -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')
);
}
?>
26 changes: 17 additions & 9 deletions html/user/cert1.php
Original file line number Diff line number Diff line change
Expand Up @@ -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\"";
Expand Down Expand Up @@ -100,4 +107,5 @@
</td><tr></table></table>
";
show_download_button();
show_share_buttons();
?>
26 changes: 17 additions & 9 deletions html/user/cert_all.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,28 @@
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);
Expand Down Expand Up @@ -99,4 +106,5 @@ function show_proj($p) {
</td><tr></table></table>
";
show_download_button();
show_share_buttons();
?>
29 changes: 19 additions & 10 deletions html/user/cert_team.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,25 @@

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;
}

// 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 = get_logged_in_user();
$user = BoincUser::lookup_id($user_id);
$team = BoincTeam::lookup_id($user->teamid);
if (!$team) error_page("no team");

Expand All @@ -37,14 +53,6 @@

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\"";
Expand Down Expand Up @@ -107,4 +115,5 @@
</td><tr></table></table>
";
show_download_button();
show_share_buttons();
?>
Loading