Tweaks to user URL/country flags

- Put flags in config.xml instead of project.inc
- Make them positive instead of negative
- make db_dump respect them.
This commit is contained in:
David Anderson 2018-12-14 20:20:24 -08:00
parent b45e89e9af
commit ff91f05aa6
14 changed files with 43 additions and 29 deletions

View File

@ -102,7 +102,7 @@ function create_account_form($teamid, $next_url) {
),
"passwd", "", "password",'id="passwd"',passwd_visible_checkbox("passwd")
);
if (!NO_USER_COUNTRY) {
if (USER_COUNTRY) {
form_select(
sprintf('<span title="%s">%s</span>',
tra("Select the country you want to represent, if any."),

View File

@ -628,7 +628,7 @@ function show_post(
// - put the .png's in html/user/flags/
// - put define("COUNTRY_FLAGS", 1); in your html/project/project.inc
//
if (!NO_USER_COUNTRY && defined("COUNTRY_FLAGS")) {
if (USER_COUNTRY && defined("COUNTRY_FLAGS")) {
if (array_key_exists($user->country, $country_to_iso3166_2)) {
$code = $country_to_iso3166_2[$user->country];
echo "<img class=flag alt=\"$user->country\" title=\"$user->country\" src=flags/$code.png>\n";

View File

@ -243,13 +243,13 @@ function show_user_info_private($user) {
}
row2(tra("Email address"), $email_text);
}
if (!NO_USER_URL) {
if (USER_URL) {
if (strlen($user->url)) {
$u = normalize_user_url($user->url);
row2(tra("URL"), sprintf('<a href="%s">%s</a>', $u, $u));
}
}
if (!NO_USER_COUNTRY) {
if (USER_COUNTRY) {
row2(tra("Country"), $user->country);
}
if (POSTAL_CODE) {
@ -437,10 +437,10 @@ function show_user_summary_public($user) {
global $g_logged_in_user;
row2(tra("User ID"), $user->id);
row2(tra("%1 member since", PROJECT), date_str($user->create_time));
if (!NO_USER_COUNTRY) {
if (USER_COUNTRY) {
row2(tra("Country"), $user->country);
}
if (!NO_USER_URL) {
if (USER_URL) {
// don't show URL if user has no recent credit (spam suppression)
//
if (strlen($user->url)) {

View File

@ -260,7 +260,7 @@ function validate_post_make_user() {
$passwd_hash = md5($passwd.$new_email_addr);
$country = "";
if (!NO_USER_COUNTRY) {
if (USER_COUNTRY) {
$country = post_str("country", true);
if ($country && !is_valid_country($country)) {
error_page("bad country");

View File

@ -34,7 +34,7 @@ require_once("../inc/translation.inc");
require_once("../inc/profile.inc");
require_once("../inc/bootstrap.inc");
// parse some stuff from config (do it here for efficiency)
// parse some stuff from config.xml (do it here for efficiency)
//
$config = get_config();
global $master_url;
@ -42,8 +42,16 @@ $master_url = parse_config($config , "<master_url>");
$recaptcha_public_key = parse_config($config, "<recaptcha_public_key>");
$recaptcha_private_key = parse_config($config, "<recaptcha_private_key>");
// don't allow /... at the end of URL
// the following default to on
//
$x = parse_config($config, "<user_country>");
define('USER_COUNTRY', ($x===null)?1:(int)$x);
$x = parse_config($config, "<user_url>");
define('USER_URL', ($x===null)?1:(int)$x);
// don't allow /... at the end of URL
//
if (array_key_exists("PATH_INFO", $_SERVER)) {
die("bad URL");
}
@ -101,12 +109,6 @@ if (!defined('USER_HOME')) {
if (!defined('POST_MAX_LINKS')) {
define('POST_MAX_LINKS', 0);
}
if (!defined('NO_USER_COUNTRY')) {
define('NO_USER_COUNTRY', 0);
}
if (!defined('NO_USER_URL')) {
define('NO_USER_URL', 0);
}
// sleep this long on any login failure
// (slow the rate of hacker attacks)

View File

@ -95,7 +95,6 @@ function get_config() {
// If it's a single-tag element, and it's present, just return the tag
//
function parse_element($xml, $tag) {
$element = null;
$closetag = "</" . substr($tag,1);
$x = strstr($xml, $tag);
if ($x) {
@ -104,9 +103,10 @@ function parse_element($xml, $tag) {
$n = strpos($y, $closetag);
if ($n) {
$element = substr($y, 0, $n);
return trim($element);
}
}
return trim($element);
return null;
}
function parse_next_element($xml, $tag, &$cursor) {

View File

@ -113,10 +113,10 @@ function show_user_xml($user, $show_hosts) {
show_host_xml($host);
}
}
if (!NO_USER_COUNTRY) {
if (USER_COUNTRY) {
echo " <country>$user->country</country>\n";
}
if (!NO_USER_URL) {
if (USER_URL) {
$url = normalize_user_url($user->url);
echo " <url>".htmlspecialchars($url)."</url>\n";
}
@ -138,10 +138,10 @@ function show_team_member($user, $creditonly = false) {
<expavg_time>$user->expavg_time</expavg_time>
<has_profile>$user->has_profile</has_profile>
";
if (!NO_USER_COUNTRY) {
if (USER_COUNTRY) {
echo " <country>$user->country</country>\n";
}
if (!NO_USER_URL) {
if (USER_URL) {
$url = normalize_user_url($user->url);
echo " <url>".htmlspecialchars($url)."</url>\n";
}

View File

@ -100,7 +100,7 @@ if (!$user) {
}
$name = BoincDb::escape_string($name);
if (NO_USER_COUNTRY) {
if (!USER_COUNTRY) {
$country = "";
}
if (!is_valid_country($country)) {
@ -121,7 +121,7 @@ if (stripos($project_prefs, "<project_specific>") === false) {
$project_prefs = str_ireplace("<project_preferences>", "<project_preferences>\n".$orig_project_specific, $project_prefs);
}
if (NO_USER_URL) {
if (!USER_URL) {
$url = "";
}
$url = BoincDb::escape_string($url);

View File

@ -38,12 +38,12 @@ $name = BoincDb::escape_string($name);
$url = "";
$country = "";
$postal_code = "";
if (!NO_USER_URL) {
if (USER_URL) {
$url = post_str("url", true);
$url = sanitize_tags($url);
$url = BoincDb::escape_string($url);
}
if (!NO_USER_COUNTRY) {
if (USER_COUNTRY) {
$country = post_str("country");
if (!is_valid_country($country)) {
error_page("bad country");

View File

@ -35,7 +35,7 @@ form_input_text(
$user->name
);
if (!NO_USER_URL) {
if (USER_URL) {
form_input_text(
tra("URL %1 of your personal web page; optional%2", "<br><p class=\"small\">", "</p>"),
'url',
@ -43,7 +43,7 @@ if (!NO_USER_URL) {
);
}
if (!NO_USER_COUNTRY) {
if (USER_COUNTRY) {
form_select(
tra("Country"),
'country',

View File

@ -484,6 +484,7 @@ int run_program(
FCGI::perror("execvp");
#else
perror("execvp");
fprintf(stderr, "couldn't exec %s: %d\n", file, errno);
#endif
exit(errno);
}

View File

@ -582,7 +582,6 @@ void write_user(USER& user, ZFILE* f, bool /*detail*/) {
"<user>\n"
" <id>%lu</id>\n"
" <name>%s</name>\n"
" <country>%s</country>\n"
" <create_time>%d</create_time>\n"
" <total_credit>%f</total_credit>\n"
" <expavg_credit>%f</expavg_credit>\n"
@ -597,7 +596,13 @@ void write_user(USER& user, ZFILE* f, bool /*detail*/) {
user.expavg_time,
cpid
);
if (strlen(user.url)) {
if (config.user_country && strlen(user.country)) {
f->write(
" <country>%s</country>\n",
user.country
);
}
if (config.user_url && strlen(user.url)) {
f->write(
" <url>%s</url>\n",
url

View File

@ -95,6 +95,8 @@ int SCHED_CONFIG::parse(FILE* f) {
scheduler_log_buffer = 32768;
version_select_random_factor = 1.;
maintenance_delay = 3600;
user_url = true;
user_country = true;
if (!xp.parse_start("boinc")) return ERR_XML_PARSE;
if (!xp.parse_start("config")) return ERR_XML_PARSE;
@ -194,6 +196,8 @@ int SCHED_CONFIG::parse(FILE* f) {
if (xp.parse_bool("job_size_matching", job_size_matching)) continue;
if (xp.parse_bool("dont_send_jobs", dont_send_jobs)) continue;
if (xp.parse_bool("estimate_flops_from_hav_pfc", estimate_flops_from_hav_pfc)) continue;
if (xp.parse_bool("user_url", user_url)) continue;
if (xp.parse_bool("user_country", user_country)) continue;
//////////// STUFF RELEVANT ONLY TO SCHEDULER STARTS HERE ///////

View File

@ -101,6 +101,8 @@ struct SCHED_CONFIG {
bool enable_assignment_multi;
bool job_size_matching;
bool dont_send_jobs;
bool user_url; // whether to export user.url in db dump
bool user_country;
//////////// STUFF RELEVANT ONLY TO SCHEDULER FOLLOWS ///////////