Browse Source

+ Signature preview non-js based

emanuele 13 years ago
parent
commit
c2a1f14ae0

+ 25 - 3
Sources/Profile-Modify.php

@@ -796,7 +796,7 @@ function saveProfileFields()
 	// Cycle through the profile fields working out what to do!
 	foreach ($profile_fields as $key => $field)
 	{
-		if (!isset($_POST[$key]) || !empty($field['is_dummy']))
+		if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview']) && $key == 'signature'))
 			continue;
 
 		// What gets updated?
@@ -1581,6 +1581,7 @@ function forumProfile($memID)
 
 	$context['sub_template'] = 'edit_options';
 	$context['page_desc'] = $txt['forumProfile_info'];
+	$context['show_preview_button'] = true;
 
 	setupProfileContext(
 		array(
@@ -2381,7 +2382,7 @@ function profileLoadGroups()
  */
 function profileLoadSignatureData()
 {
-	global $modSettings, $context, $txt, $cur_profile, $smcFunc;
+	global $modSettings, $context, $txt, $cur_profile, $smcFunc, $memberContext;
 
 	// Signature limits.
 	list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']);
@@ -2409,7 +2410,28 @@ function profileLoadSignatureData()
 
 	$context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && function_exists('pspell_new');
 
-	$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br />', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
+	if (empty($context['do_preview']))
+		$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br />', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
+	else
+	{
+		$signature = !empty($_POST['signature']) ? $_POST['signature'] : '';
+		$validation = profileValidateSignature($signature);
+		if (empty($context['post_errors']))
+		{
+			loadLanguage('Errors');
+			$context['post_errors'] = array();
+		}
+		$context['post_errors'][] = 'signature_not_yet_saved';
+		if ($validation !== true && $validation !== false)
+			$context['post_errors'][] = $validation;
+
+		censorText($context['member']['signature']);
+		$context['member']['current_signature'] = $context['member']['signature'];
+		censorText($signature);
+		$context['member']['signature_preview'] = parse_bbc($signature, true, 'sig' . $memberContext[$context['id_member']]);
+		$context['member']['signature'] = $_POST['signature'];
+		
+	}
 
 	return true;
 }

+ 4 - 2
Sources/Profile.php

@@ -394,6 +394,8 @@ function ModifyProfile($post_errors = array())
 
 	// Before we go any further, let's work on the area we've said is valid. Note this is done here just in case we ever compromise the menu function in error!
 	$context['completed_save'] = false;
+	$context['do_preview'] = isset($_REQUEST['preview']);
+
 	$security_checks = array();
 	$found_area = false;
 	foreach ($profile_areas as $section_id => $section)
@@ -409,7 +411,7 @@ function ModifyProfile($post_errors = array())
 					fatal_lang_error('no_access', false);
 
 				// Are we saving data in a valid area?
-				if (isset($area['sc']) && isset($_REQUEST['save']))
+				if (isset($area['sc']) && isset($_REQUEST['save']) || $context['do_preview'])
 				{
 					$security_checks['session'] = $area['sc'];
 					$context['completed_save'] = true;
@@ -645,7 +647,7 @@ function ModifyProfile($post_errors = array())
 			$context['modify_error'][$error_type] = true;
 	}
 	// If it's you then we should redirect upon save.
-	elseif (!empty($profile_vars) && $context['user']['is_owner'])
+	elseif (!empty($profile_vars) && $context['user']['is_owner'] && !$context['do_preview'])
 		redirectexit('action=profile;area=' . $current_area . ';updated');
 	elseif (!empty($force_redirect))
 		redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=' . $current_area);

+ 22 - 3
Themes/default/Profile.template.php

@@ -1146,7 +1146,7 @@ function template_edit_options()
 
 	// The main header!
 	echo '
-		<form action="', (!empty($context['profile_custom_submit_url']) ? $context['profile_custom_submit_url'] : $scripturl . '?action=profile;area=' . $context['menu_item_selected'] . ';u=' . $context['id_member'] . ';save'), '" method="post" accept-charset="', $context['character_set'], '" name="creator" id="creator" enctype="multipart/form-data" onsubmit="return checkProfileSubmit();">
+		<form action="', (!empty($context['profile_custom_submit_url']) ? $context['profile_custom_submit_url'] : $scripturl . '?action=profile;area=' . $context['menu_item_selected'] . ';u=' . $context['id_member']), '" method="post" accept-charset="', $context['character_set'], '" name="creator" id="creator" enctype="multipart/form-data" onsubmit="return checkProfileSubmit();">
 			<div class="cat_bar">
 				<h3 class="catbg">
 					<span class="ie6_header floatleft"><img src="', $settings['images_url'], '/icons/profile_sm.gif" alt="" class="icon" />';
@@ -1330,13 +1330,17 @@ function template_edit_options()
 	echo '
 					<div class="righttext">';
 
+	if (!empty($context['show_preview_button']))
+		echo '
+						<input type="submit" name="preview" value="', $txt['preview_signature'], '" class="button_submit" />';
+
 	// The button shouldn't say "Change profile" unless we're changing the profile...
 	if (!empty($context['submit_button_text']))
 		echo '
-						<input type="submit" value="', $context['submit_button_text'], '" class="button_submit" />';
+						<input type="submit" name="save" value="', $context['submit_button_text'], '" class="button_submit" />';
 	else
 		echo '
-						<input type="submit" value="', $txt['change_profile'], '" class="button_submit" />';
+						<input type="submit" name="save" value="', $txt['change_profile'], '" class="button_submit" />';
 
 	if (!empty($context['token_check']))
 		echo '
@@ -2542,6 +2546,21 @@ function template_profile_signature_modify()
 {
 	global $txt, $context, $settings;
 
+	echo '
+							<dt id="current_signature"', !isset($context['member']['current_signature']) ? ' style="display:none"' : '', '>
+								<strong>', $txt['current_signature'], ':</strong>
+							</dt>
+							<dd id="current_signature_display"', !isset($context['member']['current_signature']) ? ' style="display:none"' : '', '>
+								', isset($context['member']['current_signature']) ? $context['member']['current_signature'] : '', '<hr />
+							</dd>';
+	echo '
+							<dt id="signature_preview"', !isset($context['member']['signature_preview']) ? ' style="display:none"' : '', '>
+								<strong>', $txt['signature_preview'], ':</strong>
+							</dt>
+							<dd id="signature_preview_display"', !isset($context['member']['signature_preview']) ? ' style="display:none"' : '', '>
+								', isset($context['member']['signature_preview']) ? $context['member']['signature_preview'] : '', '<hr />
+							</dd>';
+
 	echo '
 							<dt>
 								<strong>', $txt['signature'], ':</strong><br />

+ 1 - 0
Themes/default/languages/Errors.english.php

@@ -321,6 +321,7 @@ $txt['profile_error_password_restricted_words'] = 'Your password must not contai
 $txt['profile_error_password_chars'] = 'Your password must contain a mix of upper and lower case letters, as well as digits.';
 $txt['profile_error_already_requested_group'] = 'You already have an outstanding request for this group!';
 $txt['profile_error_openid_in_use'] = 'Another user is already using that OpenID authentication URL';
+$txt['profile_error_signature_not_yet_saved'] = 'The signature is not yet saved!';
 
 $txt['mysql_error_space'] = ' - check database storage space or contact the server administrator.';
 

+ 3 - 0
Themes/default/languages/Profile.english.php

@@ -9,6 +9,9 @@ $txt['website_url'] = 'Website URL';
 $txt['signature'] = 'Signature';
 $txt['profile_posts'] = 'Posts';
 $txt['change_profile'] = 'Change profile';
+$txt['preview_signature'] = 'Preview signature';
+$txt['current_signature'] = 'Current signature';
+$txt['signature_preview'] = 'Signature preview';
 $txt['delete_user'] = 'Delete user';
 $txt['current_status'] = 'Current Status:';
 $txt['personal_text'] = 'Personal Text';