diff --git a/upload/ajax/edit_user_profile.php b/upload/ajax/edit_user_profile.php index c60dc3cee..ed15289dd 100644 --- a/upload/ajax/edit_user_profile.php +++ b/upload/ajax/edit_user_profile.php @@ -39,11 +39,58 @@ switch ($field) break; case 'user_website': - if ($value == '' || preg_match('#^https?://[a-z0-9_:;?&=/.%~\-]+$#i', $value)) + if ($value == '' || preg_match('#^https?://[\w\#!$%&~/.\-;:=,?@а-яА-Я\[\]+]+$#iu', $value)) { $this->response['new_value'] = htmlCHR($value); } - else $this->ajax_die(' "" http:// '); + else $this->ajax_die('Поле "Сайт" может содержать только http:// ссылку'); + break; + + case 'user_gender': + if (!isset($lang['GENDER_SELECT'][$value])) + { + $this->ajax_die('error'); + } + else + { $this->response['new_value'] = $lang['GENDER_SELECT'][$value]; } + break; + + case 'user_birthday': + if(!$bb_cfg['birthday']['enabled']) $this->ajax_die('off'); + $data = explode('-', $value); + $b_day = (isset($data[2])) ? (int) $data[2] : 0; + $b_md = (isset($data[1])) ? (int) $data[1] : 0; + $b_year = (isset($data[0])) ? (int) $data[0] : 0; + + if($b_day || $b_md || $b_year) + { + if((bb_date(TIMENOW, 'Y') - $b_year) > $bb_cfg['birthday']['max_user_age']) + { $this->ajax_die(sprintf($lang['BIRTHDAY_TO_HIGH'], $bb_cfg['birthday']['max_user_age'])); } + else if((bb_date(TIMENOW, 'Y') - $b_year) < $bb_cfg['birthday']['min_user_age']) + { + $this->ajax_die(sprintf($lang['BIRTHDAY_TO_LOW'], $bb_cfg['birthday']['min_user_age'])); + } + if (!checkdate($b_md, $b_day, $b_year)) + { + $this->ajax_die($lang['WRONG_BIRTHDAY_FORMAT']); + } + else + { + $value = mkrealdate($b_day, $b_md, $b_year); + $next_birthday_greeting = (date('md') < $b_md . (($b_day <= 9) ? '0' : '') . $b_day) ? date('Y') : date('Y')+1; + } } + else + { + $next_birthday_greeting = 0; } + DB()->query("UPDATE $table SET user_next_birthday_greeting = $next_birthday_greeting WHERE user_id = $user_id LIMIT 1"); + + $this->response['new_value'] = $this->request['value']; + break; + + case 'user_from': + case 'user_occ': + $value = htmlCHR($value); + $this->response['new_value'] = $value; break; case 'user_regdate': diff --git a/upload/config_mods.php b/upload/config_mods.php index 233853c38..9cc3e7f3e 100644 --- a/upload/config_mods.php +++ b/upload/config_mods.php @@ -9,7 +9,7 @@ - Magnet links - No avatar */ - + if (!defined('BB_ROOT')) die(basename(__FILE__)); // Advanced Report Hack @@ -29,4 +29,9 @@ $bb_cfg['auto_delete_posted_pics'] = true; // Delete pictures while delete post? $bb_cfg['magnet_links_enabled'] = true; // No avatar -$bb_cfg['no_avatar'] = 'images/avatars/gallery/noavatar.png'; \ No newline at end of file +$bb_cfg['no_avatar'] = 'images/avatars/gallery/noavatar.png'; + +// Birthday +$bb_cfg['birthday']['enabled'] = true; +$bb_cfg['birthday']['max_user_age'] = 100; +$bb_cfg['birthday']['min_user_age'] = 10; \ No newline at end of file diff --git a/upload/includes/functions.php b/upload/includes/functions.php index 2c8fb28a7..88c90480d 100644 --- a/upload/includes/functions.php +++ b/upload/includes/functions.php @@ -1982,6 +1982,85 @@ function bb_date ($gmepoch, $format = false, $tz = null) return ($bb_cfg['translate_dates']) ? strtr(strtoupper($date), $lang['DATETIME']) : $date; } +// Birthday +// Add function mkrealdate for Birthday MOD +// the originate php "mktime()", does not work proberly on all OS, especially when going back in time +// before year 1970 (year 0), this function "mkrealtime()", has a mutch larger valid date range, +// from 1901 - 2099. it returns a "like" UNIX timestamp divided by 86400, so +// calculation from the originate php date and mktime is easy. +// mkrealdate, returns the number of day (with sign) from 1.1.1970. + +function mkrealdate($day, $month, $birth_year) +{ + // define epoch + $epoch = 0; + // range check months + if ($month < 1 || $month > 12) return "error"; + // range check days + switch ($month) + { + case 1: if ($day > 31) return "error"; break; + case 2: if ($day > 29) return "error"; + $epoch = $epoch+31; break; + case 3: if ($day > 31) return "error"; + $epoch = $epoch+59; break; + case 4: if ($day > 30) return "error" ; + $epoch = $epoch+90; break; + case 5: if ($day > 31) return "error"; + $epoch = $epoch+120; break; + case 6: if ($day > 30) return "error"; + $epoch = $epoch+151; break; + case 7: if ($day > 31) return "error"; + $epoch = $epoch+181; break; + case 8: if ($day > 31) return "error"; + $epoch = $epoch+212; break; + case 9: if ($day > 30) return "error"; + $epoch = $epoch+243; break; + case 10: if ($day > 31) return "error"; + $epoch = $epoch+273; break; + case 11: if ($day > 30) return "error"; + $epoch = $epoch+304; break; + case 12: if ($day > 31) return "error"; + $epoch = $epoch+334; break; + } + $epoch = $epoch+$day; + $epoch_Y = sqrt(($birth_year-1970)*($birth_year-1970)); + $leapyear = round((($epoch_Y+2) / 4)-.5); + if (($epoch_Y+2)%4 == 0) + {// curent year is leapyear + $leapyear--; + if ($birth_year > 1970 && $month >= 3) $epoch = $epoch+1; + if ($birth_year < 1970 && $month < 3) $epoch = $epoch-1; + } + else if ($month == 2 && $day > 28) return "error";//only 28 days in feb. + //year + if ($birth_year > 1970) + { + $epoch = $epoch + $epoch_Y*365-1 + $leapyear; + } + else + { + $epoch = $epoch - $epoch_Y*365-1 - $leapyear; + } + return $epoch; +} + +// Add function realdate for Birthday MOD +// the originate php "date()", does not work proberly on all OS, especially when going back in time +// before year 1970 (year 0), this function "realdate()", has a mutch larger valid date range, +// from 1901 - 2099. it returns a "like" UNIX date format (only date, related letters may be used, due to the fact that +// the given date value should already be divided by 86400 - leaving no time information left) +// a input like a UNIX timestamp divided by 86400 is expected, so +// calculation from the originate php date and mktime is easy. +// e.g. realdate ("m d Y", 3) returns the string "1 3 1970" + +// UNIX users should replace this function with the below code, since this should be faster +// + +function realdate($date, $format = "Ymd") +{ + return bb_date($date*86400+1, $format, 0); +} // // Pagination routine, generates // page number sequence @@ -2875,7 +2954,7 @@ function clean_text_match ($text, $ltrim_star = true, $remove_stopwords = false, if (!$text_match_sql && $die_if_empty) { - bb_die($lang['No_search_match']); + bb_die($lang['NO_SEARCH_MATCH']); } return $text_match_sql; } diff --git a/upload/includes/ucp/usercp_register.php b/upload/includes/ucp/usercp_register.php index bfa2acf72..d635e4caf 100644 --- a/upload/includes/ucp/usercp_register.php +++ b/upload/includes/ucp/usercp_register.php @@ -107,6 +107,7 @@ switch ($mode) 'user_email' => true, // должен быть после user_password 'user_lang' => true, 'user_gender' => true, + 'user_birthday' => true, 'user_timezone' => true, 'user_opt' => true, 'user_icq' => true, @@ -321,7 +322,7 @@ foreach ($profile_fields as $field => $can_edit) break; /** - * Язык (edit, reg) + * Пол (edit, reg) */ case 'user_gender': $gender = isset($_POST['user_gender']) ? (int) $_POST['user_gender'] : $pr_data['user_gender']; @@ -330,7 +331,42 @@ foreach ($profile_fields as $field => $can_edit) $pr_data['user_gender'] = $gender; $db_data['user_gender'] = $gender; } - $tp_data['USER_GENDER'] = build_select('user_gender', $lang['GENDER_SELECT'], $pr_data['user_gender']); + $tp_data['USER_GENDER'] = build_select('user_gender', array_flip($lang['GENDER_SELECT']), $pr_data['user_gender']); + break; + + /** + * Возраст (edit, reg) + */ + case 'user_birthday': + if($birthday = $pr_data['user_birthday']) + { + $b_day = (isset($_POST['b_day'])) ? (int) $_POST['b_day'] : realdate($pr_data['user_birthday'], 'j'); + $b_md = (isset($_POST['b_md'])) ? (int) $_POST['b_md'] : realdate($pr_data['user_birthday'], 'n'); + $b_year = (isset($_POST['b_year'])) ? (int) $_POST['b_year'] : realdate($pr_data['user_birthday'], 'Y'); + if ($b_day || $b_md || $b_year) + { + if (!checkdate($b_md, $b_day, $b_year)) + { + $errors[] = $lang['WRONG_BIRTHDAY_FORMAT']; + } + else + { + $birthday = mkrealdate($b_day, $b_md, $b_year); + $next_birthday_greeting = (date('md') < $b_md . (($b_day <= 9) ? '0' : '') . $b_day) ? date('Y') : date('Y')+1; + } + } + else + { + $birthday = 0; + $next_birthday_greeting = 0; + } + } + if ($submit && $birthday != $pr_data['user_birthday']) + { + $pr_data['user_birthday'] = $birthday; + $db_data['user_birthday'] = (int) $birthday; + $db_data['user_next_birthday_greeting'] = $next_birthday_greeting; + } break; /** @@ -662,6 +698,33 @@ foreach ($profile_fields as $field => $can_edit) } } +if($bb_cfg['birthday']['enabled'] && $mode != 'register') +{ + $days = array($lang['DELTA_TIME']['INTERVALS']['mon'][0] => 0); + for($i=1; $i<=31; $i++) + { + $days[$i] = $i; + } + $s_birthday = build_select('b_day', $days, $b_day); + + $months = array($lang['DELTA_TIME']['INTERVALS']['mon'][0] => 0); + for($i=1; $i<=12; $i++) + { + $month = bb_date(mktime(0, 0, 0, ($i+1), 0, 0), 'F'); + $months[$month] = $i; + } + $s_birthday .= build_select('b_md', $months, $b_md); + + $year = bb_date(TIMENOW, 'Y'); + $years = array($lang['DELTA_TIME']['INTERVALS']['year'][0] => 0); + for($i=$year-$bb_cfg['birthday']['max_user_age']; $i<=$year-$bb_cfg['birthday']['min_user_age']; $i++) + { + $years[$i] = $i; + } + $s_birthday .= build_select('b_year', $years, $b_year); + $tp_data['BIRTHDAY'] = $s_birthday; +} + // submit if ($submit && !$errors) { diff --git a/upload/includes/ucp/usercp_viewprofile.php b/upload/includes/ucp/usercp_viewprofile.php index 51c97c167..65ddd774a 100644 --- a/upload/includes/ucp/usercp_viewprofile.php +++ b/upload/includes/ucp/usercp_viewprofile.php @@ -198,6 +198,9 @@ $template->assign_vars(array( 'OCCUPATION' => ( $profiledata['user_occ'] ) ? $profiledata['user_occ'] : '', 'INTERESTS' => ( $profiledata['user_interests'] ) ? $profiledata['user_interests'] : '', + 'GENDER' => ( $profiledata['user_gender'] ) ? $lang['GENDER_SELECT'][$profiledata['user_gender']] : '', + 'BIRTHDAY' => ( $profiledata['user_birthday'] ) ? realdate($profiledata['user_birthday'], 'Y-m-d') : '', + 'AGE' => ( $profiledata['user_birthday'] ) ? bb_date(TIMENOW, 'Y') - realdate($profiledata['user_birthday'], 'Y') : '', 'AVATAR_IMG' => $avatar_img, 'L_VIEWING_PROFILE' => sprintf($lang['VIEWING_USER_PROFILE'], $profiledata['username']), diff --git a/upload/language/lang_english/lang_main.php b/upload/language/lang_english/lang_main.php index ab6d3232a..8900fd6f2 100644 --- a/upload/language/lang_english/lang_main.php +++ b/upload/language/lang_english/lang_main.php @@ -559,10 +559,15 @@ $lang['BOARD_STYLE'] = 'Board Style'; $lang['BOARD_LANG'] = 'Board Language'; $lang['GENDER'] = ''; $lang['GENDER_SELECT'] = array( - 'Unselect' => 0, - 'Male' => 1, - 'Female' => 2 + 0 => 'Unselect', + 1 => 'Male', + 2 => 'Female' ); +$lang['BIRTHDAY'] = 'Birthday'; +$lang['WRONG_BIRTHDAY_FORMAT'] = 'The birthday format was entered incorrectly.'; +$lang['AGE'] = 'Age'; +$lang['BIRTHDAY_TO_HIGH'] = 'Sorry, this site, does not accept user older than %d years old'; +$lang['BIRTHDAY_TO_LOW'] = 'Sorry, this site, does not accept user yonger than %d years old'; $lang['NO_THEMES'] = 'No Themes In database'; $lang['TIMEZONE'] = 'Timezone'; $lang['DATE_FORMAT_PROFILE'] = 'Date format'; diff --git a/upload/language/lang_russian/lang_main.php b/upload/language/lang_russian/lang_main.php index 2da54f5a1..edfb175c9 100644 --- a/upload/language/lang_russian/lang_main.php +++ b/upload/language/lang_russian/lang_main.php @@ -564,10 +564,15 @@ $lang['BOARD_STYLE'] = 'Внешний вид форумов'; $lang['BOARD_LANG'] = 'Язык'; $lang['GENDER'] = 'Пол'; $lang['GENDER_SELECT'] = array( - 'Не определилось' => 0, - 'Мужской' => 1, - 'Женский' => 2 + 0 => 'Не определилось', + 1 => 'Мужской', + 2 => 'Женский' ); +$lang['BIRTHDAY'] = 'День рождения'; +$lang['WRONG_BIRTHDAY_FORMAT'] = 'Дата рождения указан не верно.'; +$lang['AGE'] = 'Возраст'; +$lang['BIRTHDAY_TO_HIGH'] = 'Извините, сайт запрещено посещать людям старше %d лет'; +$lang['BIRTHDAY_TO_LOW'] = 'Извините, сайт запрещено посещать детям младше %d лет'; $lang['NO_THEMES'] = 'В базе нет цветовых схем'; $lang['TIMEZONE'] = 'Часовой пояс'; $lang['DATE_FORMAT_PROFILE'] = 'Формат даты'; diff --git a/upload/search.php b/upload/search.php index 683f2d7d9..c2e696618 100644 --- a/upload/search.php +++ b/upload/search.php @@ -337,6 +337,7 @@ if (!$items_found) } // Forum + $forum_selected = ''; if ($var =& $_REQUEST[$forum_key]) { $forum_selected = get_id_ary($var); diff --git a/upload/templates/default/page_header.tpl b/upload/templates/default/page_header.tpl index 1b28fa170..68d35d404 100644 --- a/upload/templates/default/page_header.tpl +++ b/upload/templates/default/page_header.tpl @@ -254,6 +254,15 @@ function OpenInEditor ($file, $line) +
Loading...
diff --git a/upload/templates/default/usercp_register.tpl b/upload/templates/default/usercp_register.tpl index b50a9884e..540283618 100644 --- a/upload/templates/default/usercp_register.tpl +++ b/upload/templates/default/usercp_register.tpl @@ -89,6 +89,12 @@ ajax.callback.gen_passkey = function(data){ {L_GENDER}: {USER_GENDER} + + + {L_BIRTHDAY}: + {BIRTHDAY} + + ICQ: diff --git a/upload/templates/default/usercp_viewprofile.tpl b/upload/templates/default/usercp_viewprofile.tpl index 4d6ffbc15..9ef114943 100644 --- a/upload/templates/default/usercp_viewprofile.tpl +++ b/upload/templates/default/usercp_viewprofile.tpl @@ -74,6 +74,13 @@ $(document).ready(function(){ {action: "edit_user_profile", id: "username"} {action: "edit_user_profile", id: "user_regdate"} {action: "edit_user_profile", id: "user_lastvisit"} +{action: "edit_user_profile", id: "user_from"} +{action: "edit_user_profile", id: "user_website"} +{action: "edit_user_profile", id: "user_occ"} +{action: "edit_user_profile", id: "user_interests"} +{action: "edit_user_profile", id: "user_gender", editableType: "yesno-gender"} +{action: "edit_user_profile", id: "user_birthday"} + {action: "edit_user_profile", id: "ignore_srv_load", editableType: "yesno-radio"} @@ -206,25 +213,37 @@ $(document).ready(function(){ {L_LOCATION}: - {LOCATION} + {LOCATION} {L_WEBSITE}: - {WWW} + {WWW} {L_OCCUPATION}: - {OCCUPATION} + {OCCUPATION} {L_INTERESTS}: - {INTERESTS} + {INTERESTS} + + + + + {L_GENDER}: + {GENDER} + + + + + {L_BIRTHDAY}: + {BIRTHDAY} @@ -239,7 +258,7 @@ $(document).ready(function(){ {L_ACCESS}: - {L_ACCESS_SRV_LOAD}: {IGNORE_SRV_LOAD} + {L_ACCESS_SRV_LOAD}: {IGNORE_SRV_LOAD}