function user_format_local_time(&$user_prefs_array) { if (isset($user_prefs_array['TIMEZONE']) && is_numeric($user_prefs_array['TIMEZONE'])) { $timezone_id = $user_prefs_array['TIMEZONE']; } else { $timezone_id = forum_get_setting('forum_timezone', null, 27); } if (isset($user_prefs_array['GMT_OFFSET']) && is_numeric($user_prefs_array['GMT_OFFSET'])) { $gmt_offset = $user_prefs_array['GMT_OFFSET']; } else { $gmt_offset = forum_get_setting('forum_gmt_offset', null, 0); } if (isset($user_prefs_array['DST_OFFSET']) && is_numeric($user_prefs_array['DST_OFFSET'])) { $dst_offset = $user_prefs_array['DST_OFFSET']; } else { $dst_offset = forum_get_setting('forum_dst_offset', null, 0); } if (isset($user_prefs_array['DL_SAVING']) && user_check_pref('DL_SAVING', $user_prefs_array['DL_SAVING'])) { $dl_saving = $user_prefs_array['DL_SAVING']; } else { $dl_saving = forum_get_setting('forum_dl_saving', null, 'N'); } if ($dl_saving == "Y" && timestamp_is_dst($timezone_id, $gmt_offset)) { $local_time = time() + $gmt_offset * HOUR_IN_SECONDS + $dst_offset * HOUR_IN_SECONDS; } else { $local_time = time() + $gmt_offset * HOUR_IN_SECONDS; } $date_string = gmdate("i G j M Y", $local_time); list($min, $hour, $day, $month, $year) = explode(" ", $date_string); return sprintf(gettext("%s %s %s %s:%s"), $day, $month, $year, $hour, $min); // j M Y H:i }
function user_format_local_time(&$user_prefs_array) { if (isset($user_prefs_array['TIMEZONE']) && is_numeric($user_prefs_array['TIMEZONE'])) { $timezone_id = $user_prefs_array['TIMEZONE']; } else { $timezone_id = forum_get_setting('forum_timezone', null, 27); } if (isset($user_prefs_array['GMT_OFFSET']) && is_numeric($user_prefs_array['GMT_OFFSET'])) { $gmt_offset = $user_prefs_array['GMT_OFFSET']; } else { $gmt_offset = forum_get_setting('forum_gmt_offset', null, 0); } if (isset($user_prefs_array['DST_OFFSET']) && is_numeric($user_prefs_array['DST_OFFSET'])) { $dst_offset = $user_prefs_array['DST_OFFSET']; } else { $dst_offset = forum_get_setting('forum_dst_offset', null, 0); } if (isset($user_prefs_array['DL_SAVING']) && user_check_pref('DL_SAVING', $user_prefs_array['DL_SAVING'])) { $dl_saving = $user_prefs_array['DL_SAVING']; } else { $dl_saving = forum_get_setting('forum_dl_saving', null, 'N'); } if ($dl_saving == "Y" && timestamp_is_dst($timezone_id, $gmt_offset)) { $local_time = time() + $gmt_offset * HOUR_IN_SECONDS + $dst_offset * HOUR_IN_SECONDS; } else { $local_time = time() + $gmt_offset * HOUR_IN_SECONDS; } return strftime('%#d %b %Y %H:%M', $local_time); }
function user_update_prefs($uid, array $prefs, array $prefs_global = array()) { if (!($db = db::get())) { return false; } if (!is_numeric($uid)) { return false; } if (!is_array($prefs)) { return false; } // Check that $prefs_global_setting_array is an array if (!is_array($prefs_global)) { $prefs_global = array(); } // Arrays to hold preferences $global_prefs_array = array(); $forum_prefs_array = array(); // names of preferences that can be set globally $global_pref_names = array('FIRSTNAME', 'LASTNAME', 'DOB', 'HOMEPAGE_URL', 'PIC_URL', 'EMAIL_NOTIFY', 'TIMEZONE', 'DL_SAVING', 'MARK_AS_OF_INT', 'POSTS_PER_PAGE', 'FONT_SIZE', 'STYLE', 'EMOTICONS', 'VIEW_SIGS', 'START_PAGE', 'LANGUAGE', 'PM_NOTIFY', 'PM_NOTIFY_EMAIL', 'PM_SAVE_SENT_ITEM', 'PM_INCLUDE_REPLY', 'PM_AUTO_PRUNE', 'PM_EXPORT_TYPE', 'PM_EXPORT_FILE', 'PM_EXPORT_ATTACHMENTS', 'PM_EXPORT_WORDFILTER', 'DOB_DISPLAY', 'ANON_LOGON', 'SHOW_STATS', 'IMAGES_TO_LINKS', 'USE_WORD_FILTER', 'USE_ADMIN_FILTER', 'ALLOW_EMAIL', 'USE_EMAIL_ADDR', 'ALLOW_PM', 'POST_PAGE', 'SHOW_THUMBS', 'ENABLE_WIKI_WORDS', 'ENABLE_WIKI_QUICK_LINKS', 'ENABLE_TAGS', 'AUTO_SCROLL_MESSAGES', 'USE_MOVER_SPOILER', 'USE_LIGHT_MODE_SPOILER', 'USE_OVERFLOW_RESIZE', 'PIC_AID', 'AVATAR_URL', 'AVATAR_AID', 'REPLY_QUICK', 'THREADS_BY_FOLDER', 'THREAD_LAST_PAGE', 'LEFT_FRAME_WIDTH', 'SHOW_AVATARS', 'SHOW_SHARE_LINKS'); // names of preferences that can be set on a per-forum basis $forum_pref_names = array('HOMEPAGE_URL', 'PIC_URL', 'EMAIL_NOTIFY', 'MARK_AS_OF_INT', 'POSTS_PER_PAGE', 'FONT_SIZE', 'STYLE', 'EMOTICONS', 'VIEW_SIGS', 'START_PAGE', 'LANGUAGE', 'SHOW_STATS', 'IMAGES_TO_LINKS', 'USE_WORD_FILTER', 'USE_ADMIN_FILTER', 'SHOW_THUMBS', 'ENABLE_WIKI_WORDS', 'ENABLE_WIKI_QUICK_LINKS', 'ENABLE_TAGS', 'AUTO_SCROLL_MESSAGES', 'USE_MOVER_SPOILER', 'USE_LIGHT_MODE_SPOILER', 'USE_OVERFLOW_RESIZE', 'PIC_AID', 'AVATAR_URL', 'AVATAR_AID', 'REPLY_QUICK', 'THREADS_BY_FOLDER', 'THREAD_LAST_PAGE', 'LEFT_FRAME_WIDTH', 'SHOW_AVATARS', 'SHOW_SHARE_LINKS'); // Loop through the passed preference names and check they're valid // and whether the value needs to go in the global or forum USER_PREFS // table. If the preference is a global only preference it goes into // global USER_PREFS table regardless, otherwise the preference will // be checked against to see if the user wants it setting globally // or only on the current forum. foreach ($prefs as $pref_name => $pref_setting) { if (!user_check_pref($pref_name, $pref_setting)) { continue; } if (in_array($pref_name, $global_pref_names) && !in_array($pref_name, $forum_pref_names)) { $global_prefs_array[$pref_name] = $pref_setting; } else { if (in_array($pref_name, $global_pref_names) && isset($prefs_global[$pref_name]) && $prefs_global[$pref_name] == true) { $global_prefs_array[$pref_name] = $pref_setting; } else { if (in_array($pref_name, $forum_pref_names)) { $forum_prefs_array[$pref_name] = $pref_setting; } } } } // Check to see we have some preferences to set globally. if (sizeof($global_prefs_array) > 0) { // Concat the column names together, escaping them and enclosing them in backticks. $column_names = implode("`, `", array_map(array($db, 'escape'), array_keys($global_prefs_array))); // Concat the values together, escaping them and enclosing them in quotes. $column_insert_values = implode("', '", array_map(array($db, 'escape'), array_values($global_prefs_array))); // Concat the column names together, pass them through user_update_prefs_callback // which constructs a valid ON DUPLICATE KEY UPDATE statement for the INSERT. $column_update_values = implode(", ", array_map('user_update_prefs_callback_insert', array_keys($global_prefs_array))); // Construct the query and run it. $sql = "INSERT INTO USER_PREFS (`UID`, `{$column_names}`) VALUES('{$uid}', '{$column_insert_values}') "; $sql .= "ON DUPLICATE KEY UPDATE {$column_update_values} "; if (!$db->query($sql)) { return false; } // If a pref is set globally, we need to remove it from all the // per-forum USER_PREFS tables. We use array_intersect to find // out which columns we need to update. $update_prefs_array = array_intersect($forum_pref_names, array_keys($global_prefs_array)); // Only proceed if we have something to process. if (sizeof($update_prefs_array) > 0) { if (!($forum_prefix_array = forum_get_all_prefixes())) { return false; } foreach ($forum_prefix_array as $forum_prefix) { $update_prefs_sql = implode(", ", array_map('user_update_prefs_callback_update', $update_prefs_array)); $sql = "UPDATE LOW_PRIORITY `{$forum_prefix}USER_PREFS` SET {$update_prefs_sql} WHERE UID = '{$uid}'"; if (!$db->query($sql)) { return false; } } } } if (sizeof($forum_prefs_array) > 0 && ($table_prefix = get_table_prefix())) { // Concat the column names together, escaping them and enclosing them in backticks. $column_names = implode("`, `", array_map(array($db, 'escape'), array_keys($forum_prefs_array))); // Concat the values together, escaping them and enclosing them in quotes. $column_insert_values = implode("', '", array_map(array($db, 'escape'), array_values($forum_prefs_array))); // Concat the column names together, pass them through user_update_prefs_callback // which constructs a valid ON DUPLICATE KEY UPDATE statement for the INSERT. $column_update_values = implode(", ", array_map('user_update_prefs_callback_insert', array_keys($forum_prefs_array))); // Construct the query and run it. $sql = "INSERT INTO `{$table_prefix}USER_PREFS` (`UID`, `{$column_names}`) "; $sql .= "VALUES('{$uid}', '{$column_insert_values}') ON DUPLICATE KEY UPDATE {$column_update_values} "; if (!$db->query($sql)) { return false; } } return true; }
$error_msg_array[] = gettext("Unsupported image attachment. You can only use jpg, gif and png image attachments for your profile picture."); $valid = false; } if ($image_info[0] > 95 || $image_info[1] > 95) { $error_msg_array[] = gettext("Selected attachment is too large for profile picture. Maximum dimensions are 95x95px"); $valid = false; } } } else { $user_prefs['PIC_AID'] = null; } } if (isset($_POST['avatar_url'])) { $user_prefs['AVATAR_URL'] = trim($_POST['avatar_url']); $user_prefs_global['AVATAR_URL'] = isset($_POST['avatar_url_global']) ? $_POST['avatar_url_global'] == "Y" : false; if (strlen(trim($user_prefs['AVATAR_URL'])) > 0 && !user_check_pref('AVATAR_URL', $user_prefs['AVATAR_URL'])) { $error_msg_array[] = sprintf(gettext("%s is not a valid URL!"), gettext("Avatar URL")); $valid = false; } } if (isset($_POST['avatar_aid'])) { $user_prefs_global['AVATAR_AID'] = isset($_POST['avatar_url_global']) ? $_POST['avatar_url_global'] == "Y" : false; if (is_numeric($_POST['avatar_aid'])) { $user_prefs['AVATAR_AID'] = $_POST['avatar_aid']; if (isset($user_prefs['AVATAR_URL']) && strlen(trim($user_prefs['AVATAR_URL'])) > 0) { $error_msg_array[] = gettext("To use an attachment for your profile picture the Picture URL field must be blank."); $valid = false; } else { if (!($attachment_dir = attachments_check_dir())) { $error_msg_array[] = gettext("Attachments have been disabled by the forum owner."); $valid = false;
$error_msg_array[] = gettext("Attachments have been disabled by the forum owner."); $valid = false; } } } } } if (isset($_POST['avatar_url'])) { $user_prefs['AVATAR_URL'] = trim($_POST['avatar_url']); $user_prefs_global['AVATAR_URL'] = isset($_POST['avatar_url_global']) ? $_POST['avatar_url_global'] == "Y" : true; if (strlen(trim($user_prefs['AVATAR_URL'])) > 0) { if (preg_match('/^http:\\/\\//u', $user_prefs['AVATAR_URL']) < 1) { $error_msg_array[] = gettext("Avatar URL must include http:// schema."); $valid = false; } else { if (!user_check_pref('AVATAR_URL', $user_prefs['AVATAR_URL'])) { $error_msg_array[] = sprintf(gettext("%s contains invalid characters!"), gettext("Avatar URL")); $valid = false; } } } } if (isset($_POST['avatar_aid'])) { $user_prefs['AVATAR_AID'] = $_POST['avatar_aid']; $user_prefs_global['AVATAR_AID'] = isset($_POST['avatar_url_global']) ? $_POST['avatar_url_global'] == "Y" : true; if (strlen(trim($user_prefs['AVATAR_AID'])) > 0) { if (!is_md5($user_prefs['AVATAR_AID'])) { $error_msg_array[] = gettext("Invalid Attachment. Check that is hasn't been deleted."); $valid = false; } else { if (isset($user_prefs['AVATAR_URL']) && strlen(trim($user_prefs['AVATAR_URL'])) > 0) {