From 840d01dbf308bb2522982c20c2122d8d8396a29b Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 24 Jan 2018 14:28:32 -0800 Subject: [PATCH 1/2] web: properly factor project-specific donation code user.inc had some code to show icons for users who have donated. This wasn't properly factored - e.g. it made assumptions about how donations are represented. The right way to do this is to use project-defined functions that are called if they're defined (e.g. in project.inc). In this case we needed two such functions: project_user_summary_public() adds a row to a user page, and project_user_links() appends items to the user info shown e.g. in forums This functions can show donation info, or anything else the project wants. AFAIK this affects only SETI@home. --- html/inc/user.inc | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/html/inc/user.inc b/html/inc/user.inc index 6c45758aa63..fbace5140a1 100644 --- a/html/inc/user.inc +++ b/html/inc/user.inc @@ -310,13 +310,8 @@ function friend_links($user) { $x .= ' '.$alt.'
'; } $x .= " id."\">".$user->name.""; - if ($user->donated == 1) { - require_once("../project/donations.inc"); - $x .= DONATION_LINK; - } - if ($user->donated == 2) { - require_once("../project/donations.inc"); - $x .= DONATION_LINK_TWO; + if (function_exists("project_user_links")) { + $x .= project_user_links($user); } $x .= "\n"; return $x; @@ -336,20 +331,12 @@ function user_links($user, $badge_height=0) { $x .= ' Profile'; } $x .= " id."\">".$user->name.""; - if ($user->donated == 1) { - require_once("../project/donations.inc"); - $x .= DONATION_LINK; - } - if ($user->donated == 2) { - require_once("../project/donations.inc"); - $x .= DONATION_LINK_TWO; + if (function_exists("project_user_links")){ + $x .= project_user_links($user); } if ($badge_height) { $x .= badges_string(true, $user, $badge_height); } - if (function_exists("project_user_links")){ - $x .= project_user_links($user); - } return $x; } @@ -457,17 +444,8 @@ function show_user_summary_public($user) { row2(tra("Computers"), tra("hidden")); } } - if ($user->donated == 1) { - if (file_exists("../project/donations.inc")) { - require_once("../project/donations.inc"); - row2(tra("Donor"), DONATION_LINK); - } - } - if ($user->donated == 2) { - if (file_exists("../project/donations.inc")) { - require_once("../project/donations.inc"); - row2(tra("Donor"), DONATION_LINK_TWO); - } + if (function_exists("project_user_summary_public")) { + project_user_summary_public($user); } } From ed66386add398f39ab4fd524df877e69ecc8303d Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 24 Jan 2018 15:54:38 -0800 Subject: [PATCH 2/2] web: more fixes to factoring of project-specific content - don't refer to project/donations.inc. Projects can put functions wherever they want, generally in project.inc - check for existence of project_user_page_private() before calling it --- html/inc/user.inc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/html/inc/user.inc b/html/inc/user.inc index fbace5140a1..ba5f55ab8a5 100644 --- a/html/inc/user.inc +++ b/html/inc/user.inc @@ -525,17 +525,16 @@ function show_account_private($user) { show_preference_links(); show_user_stats_private($user); - if (file_exists("../project/donations.inc")) { - require_once("../project/donations.inc"); - if (function_exists('show_user_donations_private')) { - show_user_donations_private($user); - } + if (function_exists('show_user_donations_private')) { + show_user_donations_private($user); } end_table(); if (!NO_COMPUTING) { show_other_projects($user, true); } - project_user_page_private($user); + if (function_exists("project_user_page_private")) { + project_user_page_private($user); + } //echo "Delete account\n"; }, function() use ($user) {