Jump to the post that solved this thread.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Solved: 8 Months, 1 Week, 2 Days ago Require comments when giving negative reputation to posts
#1
Solved: 8 Months, 1 Week, 2 Days ago Question 
Hello mybb friends:

Is there any way to require users to add comments when giving negative reputation to posts? There are some forum users registering to my prod forum not posting at all but would rather rate posts negatively. I know I could disable to rate negatively, but to make it fair, a forum user should be able to add positive and negative reputation to posts. However, to make it even fair to the user getting a negative repu, the user adding it should add a comment explaining why.
Reply
#2
Solved: 8 Months, 1 Week, 2 Days ago
There is a way but it will force them to write a comment.
Could try this. Smile
https://community.mybb.com/thread-150751.html
Do NOT PM me for support unless I ask you on your support thread.
Reply
#3
Solved: 8 Months, 1 Week, 2 Days ago
(10-16-2018, 11:06 AM)Livewire Wrote: There is a way but it will force them to write a comment.
Could try this. Smile
https://community.mybb.com/thread-150751.html

Yes, that's the solution I'm looking for. However, that reputation.php version is not compatible with 1.8.18 (what I'm running), mine looks like this one:

	$mybb->input['comments'] = trim($mybb->get_input('comments')); // Trim whitespace to check for length
	if(my_strlen($mybb->input['comments']) < $mybb->settings['minreplength'] && $mybb->get_input('pid', MyBB::INPUT_INT) == 0)
	{
		$message = $lang->sprintf($lang->add_no_comment, $mybb->settings['minreplength']);
		if($mybb->input['nomodal'])
		{
			eval("\$error = \"".$templates->get("reputation_add_error_nomodal", 1, 0)."\";");
		}
		else
		{
			eval("\$error = \"".$templates->get("reputation_add_error", 1, 0)."\";");
		}
		echo $error;
		exit;

The base condition is not even there, so I'm still stuck. I would appreciate if you show me what needs to be tweaked.
Reply
#4
Solved: 8 Months, 1 Week, 2 Days ago
BUMP

Hello comrades. I'm bumping this thread to see if somebody can give me a hand with this issue.

Thanks for all your support.
Reply
#5
Solved: 8 Months, 1 Week, 2 Days ago
Well, the earlier guide posted by me which you have followed was for MyBB v1.6 and incompatible with v1.8.

You can validate the input right in frontend, by modifying 'submitReputation' method. Open 'general.js' and locate this code near line 365:
	submitReputation: function (uid, pid, del) {
		// Get form, serialize it and send it
		var datastring = $(".reputation_" + uid + "_" + pid).serialize();
		if (del == 1)
			datastring = datastring + '&delete=1';

		$.ajax({
			type: "POST",
			url: "reputation.php?modal=1",
			data: datastring,
			dataType: "html",
			success: function (data) {
				// Replace modal HTML (we have to access by class because the modals are appended to the end of the body, and when we get by class we get the last element of that class - which is what we want)
				$(".modal_" + uid + "_" + pid).fadeOut('slow', function () {
					$(".modal_" + uid + "_" + pid).html(data);
					$(".modal_" + uid + "_" + pid).fadeIn('slow');
					$(".modal").fadeIn('slow');
				});
			},
			error: function () {
				alert(lang.unknown_error);
			}
		});

		return false;
	},

Change it to:
	submitReputation: function (uid, pid, del) {
		if ($.trim($(".reputation_" + uid + "_" + pid + " input[name=comments]").val()) === '') {
			$.jGrowl('Please input Comment.', { theme: 'jgrowl_error' });
		} else {
			// Get form, serialize it and send it
			var datastring = $(".reputation_" + uid + "_" + pid).serialize();
			if (del == 1)
				datastring = datastring + '&delete=1';

			$.ajax({
				type: "POST",
				url: "reputation.php?modal=1",
				data: datastring,
				dataType: "html",
				success: function (data) {
					// Replace modal HTML (we have to access by class because the modals are appended to the end of the body, and when we get by class we get the last element of that class - which is what we want)
					$(".modal_" + uid + "_" + pid).fadeOut('slow', function () {
						$(".modal_" + uid + "_" + pid).html(data);
						$(".modal_" + uid + "_" + pid).fadeIn('slow');
						$(".modal").fadeIn('slow');
					});
				},
				error: function () {
					alert(lang.unknown_error);
				}
			});

		}

		return false;
	},

Now user will always be forced to add comment while giving reputation.

Note, that you need to validate in backend PHP as well, because disabling javascript will still allow users to add reputation without comments. And with v.1.8 its easy now, just omit the post reputation bypass condition from validation:

Open reputation.php and locate this line near line number 286:
if(my_strlen($mybb->input['comments']) < $mybb->settings['minreplength'] && $mybb->get_input('pid', MyBB::INPUT_INT) == 0)

and change it to:
if(my_strlen($mybb->input['comments']) < $mybb->settings['minreplength'])// && $mybb->get_input('pid', MyBB::INPUT_INT) == 0)

or simply remove the last part, if you are sure:
if(my_strlen($mybb->input['comments']) < $mybb->settings['minreplength'])

Save the file.
[Image: logo.svg.svg]
Reply
Jump to the post that solved this thread.


Forum Jump:


Users browsing this thread: 1 Guest(s)