register.php.t
来自「eGroupWare is a multi-user, web-based gr」· T 代码 · 共 617 行 · 第 1/2 页
T
617 行
<?php/**************************************************************************** copyright : (C) 2001-2003 Advanced Internet Designs Inc.* email : forum@prohost.org* $Id: register.php.t,v 1.6 2003/12/18 18:22:09 iliaa Exp $** This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or * (at your option) any later version.***************************************************************************//*{PRE_HTML_PHP}*//* Create a list of avaliable themes */function create_theme_select($name, $def=null){ $theme_select_values = ''; $r = uq("SELECT id, name FROM {SQL_TABLE_PREFIX}themes WHERE theme_opt>=1 AND (theme_opt & 1) > 0 ORDER BY ((theme_opt & 2) > 0) DESC"); while ($t = db_rowarr($r)) { $selected = $t[0] == $def ? ' selected' : ''; $theme_select_values .= '{TEMPLATE: theme_select_value}'; } return '{TEMPLATE: theme_select}';}if (!function_exists('array_fill')) {function array_fill($s, $e, $t){ ++$e; do { $arr[$s] = $t; } while (++$s < $e); return $arr;}}function fetch_img($url, $user_id){ $ext = array(1=>'gif', 2=>'jpg', 3=>'png', 4=>'swf'); list($max_w, $max_y) = explode('x', $GLOBALS['CUSTOM_AVATAR_MAX_DIM']); if (!($img_info = @getimagesize($url)) || $img_info[0] > $max_w || $img_info[1] > $max_y || $img_info[2] > ($GLOBALS['FUD_OPT_1'] & 64 ? 4 : 3)) { return; } if (!($img_data = file_get_contents($url))) { return; } $name = $user_id . '.' . $ext[$img_info[2]]. '_'; while (($fp = fopen(($path = tempnam($GLOBALS['TMP'], $name)), 'ab'))) { if (!ftell($fp)) { /* make sure that the temporary file picked, did not exist before, yes, this is paranoid. */ break; } } fwrite($fp, $img_data); fclose($fp); return $path;} /* intialize error status */ $GLOBALS['error'] = 0;function check_passwd($id, $passwd){ return q_singleval("SELECT login FROM {SQL_TABLE_PREFIX}users WHERE id=".$id." AND passwd='".md5($passwd)."'");}function sanitize_url($url){ if (!$url) { return ''; } if (strncasecmp($url, 'http://', strlen('http://')) && strncasecmp($url, 'https://', strlen('https://')) && strncasecmp($url, 'ftp://', strlen('ftp://'))) { if (stristr($url, 'javascript:')) { return ''; } else { return 'http://' . $url; } } return $url;}function sanitize_login($login){ for ($i = 0; $i < 32; $i++) $list[] = chr($i); for ($i = 127; $i < 160; $i++) $list[] = chr($i); return str_replace($list, array_fill(0, count($list), ''), $login);}function register_form_check($user_id){ $_POST['reg_home_page'] = sanitize_url(trim($_POST['reg_home_page'])); $_POST['reg_user_image'] = !empty($_POST['reg_user_image']) ? sanitize_url(trim($_POST['reg_user_image'])) : ''; if (!empty($_POST['reg_icq']) && !(int)$_POST['reg_icq']) { /* ICQ # can only be an integer */ $_POST['reg_icq'] = ''; } /* Image count check */ if ($GLOBALS['FORUM_IMG_CNT_SIG'] && $GLOBALS['FORUM_IMG_CNT_SIG'] < substr_count(strtolower($_POST['reg_sig']), '[img]') ) { set_err('reg_sig', '{TEMPLATE: register_err_toomanyimages}'); } /* Url Avatar check */ if (!empty($_POST['reg_avatar_loc']) && !($GLOBALS['reg_avatar_loc_file'] = fetch_img($_POST['reg_avatar_loc'], $user_id))) { set_err('avatar', '{TEMPLATE: register_err_not_valid_img}'); } /* Alias Check */ if ($GLOBALS['FUD_OPT_2'] & 128 && isset($_POST['reg_alias'])) { if (($_POST['reg_alias'] = trim(sanitize_login($_POST['reg_alias'])))) { if (strlen($_POST['reg_alias']) > $GLOBALS['MAX_LOGIN_SHOW']) { $_POST['reg_alias'] = substr($_POST['reg_alias'], 0, $GLOBALS['MAX_LOGIN_SHOW']); } if (q_singleval("SELECT id FROM {SQL_TABLE_PREFIX}users WHERE alias='".addslashes(htmlspecialchars($_POST['reg_alias']))."' AND id!=".$user_id)) { set_err('reg_alias', '{TEMPLATE: register_err_taken_alias}'); } } } if ($GLOBALS['FORUM_SIG_ML'] && strlen($_POST['reg_sig']) > $GLOBALS['FORUM_SIG_ML']) { set_err('reg_sig', '{TEMPLATE: register_err_sig_too_long}'); } return $GLOBALS['error'];}function fmt_year($val){ if (!($val = (int)$val)) { return; } if ($val > 1000) { return $val; } else if ($val < 100 && $val > 10) { return (1900 + $val); } else if ($val < 10) { return (2000 + $val); }}function set_err($err_name, $err_msg){ $GLOBALS['error'] = 1; if (isset($GLOBALS['err_msg'])) { array_push($GLOBALS['err_msg'], array($err_name => $err_msg)); } else { $GLOBALS['err_msg'] = array($err_name => $err_msg); }}function draw_err($err_name){ if (!isset($GLOBALS['err_msg'][$err_name])) { return; } return '{TEMPLATE: register_error}';}function make_avatar_loc($path, $disk, $web){ $img_info = @getimagesize($disk . $path); if ($img_info[2] < 4 && $img_info[2] > 0) { return '<img src="'.$web . $path.'" '.$img_info[3].' />'; } else if ($img_info[2] == 4) { return '<embed src="'.$web . $path.'" '.$img_info[3].' />'; } else { return ''; }}function remove_old_avatar($avatar_str){ if (preg_match('!images/custom_avatars/(([0-9]+)\.([A-Za-z]+))" width=!', $avatar_str, $tmp)) { @unlink($GLOBALS['WWW_ROOT_DISK'] . 'images/custom_avatars/' . basename($tmp[1])); }}function decode_uent(&$uent){ reverse_fmt($uent->home_page); reverse_fmt($uent->bio); reverse_fmt($uent->interests); reverse_fmt($uent->occupation); reverse_fmt($uent->location); reverse_fmt($uent->user_image); $uent->aim = urldecode($uent->aim); $uent->yahoo = urldecode($uent->yahoo); $uent->msnm = urldecode($uent->msnm); $uent->jabber = urldecode($uent->jabber); $uent->affero = urldecode($uent->affero);} if (isset($_GET['mod_id'])) { $mod_id = (int)$_GET['mod_id']; } else if (isset($_POST['mod_id'])) { $mod_id = (int)$_POST['mod_id']; } else { $mod_id = ''; } /* allow the root to modify settings other lusers */ if (_uid && $usr->users_opt & 1048576 && $mod_id) { if (!($uent =& usr_reg_get_full($mod_id))) { exit('Invalid User Id'); } decode_uent($uent); } else { $uent =& usr_reg_get_full($usr->id); decode_uent($uent); } /* this is a hack, it essentially disables uploading of avatars when file_uploads are off */ if (ini_get("file_uploads") != 1 || !($FUD_OPT_1 & 8)) { $register_enctype = ''; $FUD_OPT_1 = $FUD_OPT_1 &~ 8; } else { $register_enctype = '{TEMPLATE: register_enctype}'; } $avatar_tmp = $avatar_arr = null; /* deal with avatars, only done for regged users */ if (!empty($_POST['avatar_tmp'])) { list($avatar_arr['file'], $avatar_arr['del'], $avatar_arr['leave']) = explode("\n", base64_decode($_POST['avatar_tmp'])); } if (isset($_POST['btn_detach']) && isset($avatar_arr)) { $avatar_arr['del'] = 1; } if (!($FUD_OPT_1 & 8) && (!@file_exists($avatar_arr['file']) || empty($avatar_arr['leave']))) { /* hack attempt for URL avatar */ $avatar_arr = null; } else if (($FUD_OPT_1 & 8) && isset($_FILES['avatar_upload']) && $_FILES['avatar_upload']['size'] > 0) { /* new upload */ if ($_FILES['avatar_upload']['size'] >= $CUSTOM_AVATAR_MAX_SIZE) { set_err('avatar', '{TEMPLATE: register_err_avatartobig}'); } else { /* [user_id].[file_extension]_'random data' */ $file_name = $uent->id . strrchr($_FILES['avatar_upload']['name'], '.') . '_'; $tmp_name = safe_tmp_copy($_FILES['avatar_upload']['tmp_name'], 0, $file_name); if (!($img_info = @getimagesize($TMP . $tmp_name))) { set_err('avatar', '{TEMPLATE: register_err_not_valid_img}'); unlink($TMP . $tmp_name); } list($max_w, $max_y) = explode('x', $CUSTOM_AVATAR_MAX_DIM); if ($img_info[2] > ($FUD_OPT_1 & 64 ? 4 : 3)) { set_err('avatar', '{TEMPLATE: register_err_avatarnotallowed}'); unlink($TMP . $tmp_name); } else if ($img_info[0] >$max_w || $img_info[1] >$max_y) { set_err('avatar', '{TEMPLATE: register_err_avatardimtobig}'); unlink($TMP . $tmp_name); } else { /* remove old uploaded file, if one exists & is not in DB */ if (empty($avatar_arr['leave']) && @file_exists($avatar_arr['file'])) { @unlink($TMP . $avatar_arr['file']); } $avatar_arr['file'] = $tmp_name; $avatar_arr['del'] = 0; $avatar_arr['leave'] = 0; } } } if (count($_POST)) { $new_users_opt = 0; foreach (array('display_email', 'notify', 'notify_method', 'ignore_admin', 'email_messages', 'pm_messages', 'pm_notify', 'default_view', 'gender', 'append_sig', 'show_sigs', 'show_avatars', 'show_im', 'invisible_mode') as $v) { if (!empty($_POST['reg_'.$v])) { $new_users_opt |= (int) $_POST['reg_'.$v]; } } /* security check, prevent haxors from passing values that shouldn't */ if (!($new_users_opt & (131072|65536|262144|524288|1048576|2097152|4194304|8388608|16777216))) { $uent->users_opt = ($uent->users_opt & (131072|65536|262144|524288|1048576|2097152|4194304|8388608|16777216)) | $new_users_opt; } } /* SUBMITTION CODE */ if (isset($_POST['fud_submit']) && !isset($_POST['btn_detach']) && !isset($_POST['btn_upload']) && !register_form_check($uent->id)) { $old_email = $uent->email; $old_avatar_loc = $uent->avatar_loc; $old_avatar = $uent->avatar; /* import data from _POST into $uent object */ $vars = array_keys(get_object_vars($uent)); foreach ($vars as $v) { if (isset($_POST['reg_'.$v])) { $uent->{$v} = $_POST['reg_'.$v]; } } $uent->bday = fmt_year($_POST['b_year']) . str_pad((int)$_POST['b_month'], 2, '0', STR_PAD_LEFT) . str_pad((int)$_POST['b_day'], 2, '0', STR_PAD_LEFT); $uent->sig = apply_custom_replace($uent->sig); if ($FUD_OPT_1 & 131072) { $uent->sig = tags_to_html($uent->sig, $FUD_OPT_1 & 524288); } else if ($FUD_OPT_1 & 65536) { $uent->sig = nl2br(htmlspecialchars($uent->sig)); } if ($FUD_OPT_1 & 196608) { char_fix($uent->sig); } if ($FUD_OPT_1 & 262144) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?