Explorar o código

! Convert a use of fopen/fwrite/fclose to file_put_contents (Mantis 4913) and also have it report whether something was saved properly or not (another for #802)

Signed-off-by: Peter Spicer <[email protected]>
Peter Spicer %!s(int64=11) %!d(string=hai) anos
pai
achega
5f6cc7cf99

+ 7 - 3
Sources/ManageRegistration.php

@@ -205,11 +205,15 @@ function EditAgreement()
 		validateToken('admin-rega');
 
 		// Off it goes to the agreement file.
-		$fp = fopen($boarddir . '/agreement' . $context['current_agreement'] . '.txt', 'w');
-		fwrite($fp, str_replace("\r", '', $_POST['agreement']));
-		fclose($fp);
+		$to_write = str_replace("\r", '', $_POST['agreement']);
+		$bytes = file_put_contents($boarddir . '/agreement' . $context['current_agreement'] . '.txt', $to_write, LOCK_EX);
 
 		updateSettings(array('requireAgreement' => !empty($_POST['requireAgreement'])));
+
+		if ($bytes == strlen($to_write))
+			$context['saved_successful'] = true;
+		else
+			$context['could_not_save'] = true;
 	}
 
 	$context['agreement'] = file_exists($boarddir . '/agreement' . $context['current_agreement'] . '.txt') ? $smcFunc['htmlspecialchars'](file_get_contents($boarddir . '/agreement' . $context['current_agreement'] . '.txt')) : '';

+ 7 - 0
Themes/default/Register.template.php

@@ -597,6 +597,13 @@ function template_edit_agreement()
 {
 	global $context, $settings, $options, $scripturl, $txt;
 
+	if (!empty($context['saved_successful']))
+		echo '
+					<div class="infobox">', $txt['settings_saved'], '</div>';
+	elseif (!empty($context['could_not_save']))
+		echo '
+					<div class="errorbox">', $txt['admin_agreement_not_saved'], '</div>';
+
 	// Just a big box to edit the text file ;).
 	echo '
 		<form id="admin_form_wrapper" action="', $scripturl, '?action=admin;area=regcenter" method="post" accept-charset="', $context['character_set'], '">

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

@@ -45,6 +45,7 @@ $txt['admin_agreement'] = 'Show and require agreement letter when registering';
 $txt['admin_agreement_default'] = 'Default';
 $txt['admin_agreement_select_language'] = 'Language to edit';
 $txt['admin_agreement_select_language_change'] = 'Change';
+$txt['admin_agreement_not_saved'] = 'The agreement changes have not been saved. Perhaps the file permissions on the file were not set correctly.';
 $txt['admin_delete_members'] = 'Delete Selected Members';
 $txt['admin_repair'] = 'Repair All boards and topics';
 $txt['admin_main_welcome'] = 'This is your &quot;%1$s&quot;.  From here, you can edit settings, maintain your forum, view logs, install packages, manage themes, and many other things.<br /><br />If you have any trouble, please look at the &quot;Support &amp; Credits&quot; page.  If the information there doesn\'t help you, feel free to <a href="http://www.simplemachines.org/community/index.php" target="_blank" class="new_win">look to us for help</a> with the problem.<br />You may also find answers to your questions or problems by clicking the <img src="' . $settings['images_url'] . '/helptopics.png" alt="%2$s" title="%3$s" /> symbols for more information on the related functions.';