Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Topic started by: Avalanche91 on December 05, 2013, 09:09:24 AM

Title: Best Answer
Post by: Avalanche91 on December 05, 2013, 09:09:24 AM
Please use the latest version of this modification.

Link to Mod (http://custom.simplemachines.org/mods/index.php?mod=3803)

Mod in action (http://www.nau4ime.ava7.eu/index.php?topic=4)

Description:
Best Answer mod gives you the ability to mark a reply in a topic as Best Answer/Solution. The marked answer will be lit in green, showing the other users what exactly is the solution to the topic.
The permission to mark an answer as such has the person who started the topic, or if for any reason he has forgotten to mark anything, moderators and administrators can do this as well.

License
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License (http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode)

Languages:
- English
- English UTF8
- British English
- British English UTF8
- Bulgarian
- Bulgarian UTF8
- Turkish
- Turkish UTF8
- Italian
- Italian UTF8
- Brazilian Portuguese
- Brazilian Portuguese UTF8




(https://www.simplemachines.org/community/proxy.php?request=http%3A%2F%2Fwww.ava7.eu%2Fuploads%2Fimg%2FBAp1.jpg&hash=91cb9ef957f6d47e3496b9de5f793be619e9a53a)
(https://www.simplemachines.org/community/proxy.php?request=http%3A%2F%2Fwww.ava7.eu%2Fuploads%2Fimg%2FBAp2.jpg&hash=d93ead6950341b428dd9cff8c910cd40e0d4158c)
Title: Re: Best Answer
Post by: littlenicki on December 05, 2013, 12:38:30 PM
Hello, this is an excellent mod! Could you please do a SMF 1.1 verson of it? Thanks so much!
Title: Re: Best Answer
Post by: Arantor on December 05, 2013, 12:40:59 PM
It would require a total rewrite for 1.1.x.

You should also know that sometime in 2014 we will be discontinuing official support (including security patches) for 1.1.x; once 2.1 goes stable, 1.1 will be end of life.
Title: Re: Best Answer
Post by: 4Kstore on December 05, 2013, 12:50:29 PM
I just installed this on a test forum and when I go into a topic this error appears:

Parse error: syntax error, unexpected '[' in C:\xampp\htdocs\ssrs\Sources\Display.php on line 1247

In that line:

$context['ba_jump_to_msg'] = $smcFunc['db_fetch_row']($result)[0];


Title: Re: Best Answer
Post by: margarett on December 05, 2013, 01:10:43 PM
I can't see that happening.

That line does exist but produces no error in my test forum.
Title: Re: Best Answer
Post by: Kindred on December 05, 2013, 01:19:09 PM
I suspect that the line BEFORE that has an issue with a missing bracket
Title: Re: Best Answer
Post by: Adrek on December 05, 2013, 02:35:10 PM
Nice mod :)

I have the same error as 4Kstore :|
Title: Re: Best Answer
Post by: Kindred on December 05, 2013, 02:37:20 PM
Quote from: Kindred on December 05, 2013, 01:19:09 PM
I suspect that the line BEFORE that has an issue with a missing bracket

so please include your code for several lines BEFORE the affected line?
Title: Re: Best Answer
Post by: Adrek on December 05, 2013, 02:38:56 PM
it's code that this mod adds in Display.php file...



// Let's see if any Answer is marked as Best solution and if True, select all information needed to display
$result = $smcFunc['db_query']('',
'SELECT `ba`.`id`,`ba`.`id_msg`,`ba`.`id_topic`,`ba`.`id_member`,DATE(`ba`.`time_marked`) AS `day`,TIME(`ba`.`time_marked`) AS `time`,`m`.`member_name`
FROM {db_prefix}best_answer AS `ba`
INNER JOIN {db_prefix}members AS `m`
ON `ba`.`id_member`=`m`.`id_member`
WHERE `id_msg`={int:id_msg}',
array('id_msg' => $message['id_msg'])
);
$context['best_answer'] = $smcFunc['db_fetch_assoc']($result);

// Let's create the "jump to" link if we have a Best Answer
if ($context['topic_first_message'] == $output['id']) {
$result = $smcFunc['db_query']('',
'SELECT `id_msg` FROM {db_prefix}best_answer WHERE `id_topic`={int:id_topic}',
array('id_topic' => $output['id'])
);
// Contains the id of the post that was marked as Best Answer
$context['ba_jump_to_msg'] = $smcFunc['db_fetch_row']($result)[0];
}
Title: Re: Best Answer
Post by: Arantor on December 05, 2013, 02:42:24 PM
I knew I should have reviewed the code of this one.

Try replacing the affected line with:
list($context['ba_jump_to_msg']) = $smcFunc['db_fetch_row']($answer);
Title: Re: Best Answer
Post by: littlenicki on December 05, 2013, 02:43:33 PM
Quote from: Arantor Beeblebrox the First on December 05, 2013, 12:40:59 PM
It would require a total rewrite for 1.1.x.

You should also know that sometime in 2014 we will be discontinuing official support (including security patches) for 1.1.x; once 2.1 goes stable, 1.1 will be end of life.

Yes but many users will coninue using the old vesion. As I will do, too, I would really admire it if there was a 1.1 version of this mod available.
Title: Re: Best Answer
Post by: Arantor on December 05, 2013, 02:47:42 PM
QuoteYes but many users will coninue using the old vesion. As I will do, too,

So when SMF stops working because PHP has moved on, and/or there are security holes found in the software, these will NOT be fixed. Only a couple of months ago were we advised of holes found in 1.1.x, for example.
Title: Re: Best Answer
Post by: Avalanche91 on December 05, 2013, 02:48:08 PM
I apologize for the inconvenience folks. It's because of the "odd" syntax and I am using in this line:
Code (php) Select
$context['ba_jump_to_msg'] = $smcFunc['db_fetch_row']($result)[0];
Apparently PHP 5.4 (or may be v5.3 I am not sure) gives me the flexibility to use the first returned row from the query directly by using this syntax
  • [/b] at the end. So I assume that you guys are using lower version of PHP. Sorry, I just haven't noticed that. I will work out a quick fix for this problem.
Title: Re: Best Answer
Post by: Adrek on December 05, 2013, 02:50:38 PM
Arantor, error is gone, but now in logs  I have two another errors:

/index.php?/topic,16431.msg101063.html
2: mysql_fetch_row(): supplied argument is not a valid MySQL result resource
File: /Sources/Display.php
Line: 1259


and Undefined index:

/index.php?/topic,16431.msg101063.html
8: Undefined variable: answer
File: /Sources/Display.php
Line: 1259


Line 1259:
list($context['ba_jump_to_msg']) = $smcFunc['db_fetch_row']($answer);
Title: Re: Best Answer
Post by: Arantor on December 05, 2013, 02:52:22 PM
You really should not be doing that. The semantics of doing so are questionable when you're dealing with variable functions.

list($context['ba_jump_to_msg']) = $smcFunc['db_fetch_row']($result);

is what should have been used - sorry phantomm. Was doing it in a hurry while cooking my dinner.


Also, also please note that links should never be just referenced with ?action or ?topic, they should always be using $scripturl, partly due to subdomain specific conflicts and partly to ensure users who use Pretty URLs or some of the colourising mods won't find it broken.
Title: Re: Best Answer
Post by: Avalanche91 on December 05, 2013, 02:54:01 PM
Quote from: phantomm on December 05, 2013, 02:50:38 PM
Arantor, error is gone, but now in logs  I have two another errors:

/index.php?/topic,16431.msg101063.html
2: mysql_fetch_row(): supplied argument is not a valid MySQL result resource
File: /Sources/Display.php
Line: 1259


and Undefined index:

/index.php?/topic,16431.msg101063.html
8: Undefined variable: answer
File: /Sources/Display.php
Line: 1259


Line 1259:
list($context['ba_jump_to_msg']) = $smcFunc['db_fetch_row']($answer);

Could you please try like this:
Code (php) Select
// Contains the id of the post that was marked as Best
$data = $smcFunc['db_fetch_row']($result);
$context['ba_jump_to_msg'] = $data['0'];
Title: Re: Best Answer
Post by: Kindred on December 05, 2013, 02:56:10 PM
why not use the code that Arantor suggested?
Title: Re: Best Answer
Post by: Adrek on December 05, 2013, 02:56:41 PM
Arantor - now it works fine :)

Avalanche91, your fix also works just fine ;) (PHP 5.2.17)
Title: Re: Best Answer
Post by: Arantor on December 05, 2013, 02:57:58 PM
Do please note that your second line there only works on a technicality because PHP considers numbers and strings-that-contain-numbers to be the same thing in the hash table it uses for arrays. $data[0] is more proper though works the same way. Using the list construct is the proper way to do it in this situation.
Title: Re: Best Answer
Post by: Avalanche91 on December 05, 2013, 02:59:54 PM
Quote from: phantomm on December 05, 2013, 02:56:41 PM
Arantor - now it works fine :)

Avalanche91, your fix also works just fine ;) (PHP 5.2.17)
Thank you very much phantomm. PHP added this quite some time ago along with the new syntax for arrays
Code (php) Select
$myArray = ['value', 'value2'];

Quote from: Arantor Beeblebrox the First on December 05, 2013, 02:57:58 PM
Do please note that your second line there only works on a technicality because PHP considers numbers and strings-that-contain-numbers to be the same thing in the hash table it uses for arrays. $data[0] is more proper though works the same way. Using the list construct is the proper way to do it in this situation.

Oops, you are absolutely correct!

I am going to quickly upload a new version.
Title: Re: Best Answer
Post by: Arantor on December 05, 2013, 03:04:23 PM
QuotePHP added this quite some time ago along with the new syntax for arrays

That's PHP 5.4, however in this case that's not what the issue is. Using numbers to pull array indices has been standard forever, and interesting recently they changed how array handling worked under the hood so that you could access strings with array notation, e.g. $string[0] would return the first character of a string even though $string was not an array.

As part of the changes in 5.4, they also brought in the ability to access the result of a function via an array directly, which is what you're doing here. But there are some interesting quirks around using variable functions (which is what $smcFunc is) and array syntax and that's why it's much better to use list rather than trying to directly address it.

There has been, AFAIK, one vulnerability in PHP itself since 5.4 because of this.

Also please note that SMF 2.0 technically still supports the later 4.x releases of PHP, with reduced functionality in some places, and 2.1 is currently requiring 5.1 minimum, so 5.4+ syntax is not recommended.

/me will have to see about renewing his Zend certification in the new year, depending on whether they've updated for 5.4 or 5.5, currently only actually certified for 5.3
Title: Re: Best Answer
Post by: Avalanche91 on December 05, 2013, 03:12:23 PM
Quote from: littlenicki on December 05, 2013, 12:38:30 PM
Hello, this is an excellent mod! Could you please do a SMF 1.1 verson of it? Thanks so much!
Thanks for the support.

I love to make things compatible and accessible for everyone and everything. I am sure that a version for SMF 1.x would be very helpful but it is very discouraging to hear that the official support for 1.x version will soon be cancelled. I guess that I would rather work on translations and fixing already existing problems than going from the scratch again.
Title: Re: Best Answer
Post by: Kindred on December 05, 2013, 03:15:47 PM
Why is that discouraging?  1.1.x has reached the end of its lifecycle....   2.0 is out and has been stable for years, and 2.1 will soon be out.
Title: Re: Best Answer
Post by: Avalanche91 on December 05, 2013, 03:27:04 PM
Quote from: Kindred on December 05, 2013, 03:15:47 PM
Why is that discouraging?  1.1.x has reached the end of its lifecycle....   2.0 is out and has been stable for years, and 2.1 will soon be out.
I am sorry, I absolutely approve what you stated. For example, I am using integrated hooks for my MOD, which are only supported in v2.x, and if I want to make my MOD compatible with SMF 1.x I will have to use some other way of constructing my MOD which eventually may lead to changes in the entire structure of the MOD. But if I were to make changes for SMF 2.1 or even SMF 3, I would love to do it because I know that this will be the feature of the platform. That's why it is so discouraging.
Title: Re: Best Answer
Post by: Arantor on December 05, 2013, 03:33:28 PM
And this is why 1.1.x is being EOL'd. It has been superseded by 2.0 and 2.1. 3.0 will likely be very different under the hood in any case.
Title: Re: Best Answer
Post by: Adrek on December 05, 2013, 04:25:31 PM
One more thing - notification in first message is not showing up. When I replaced this (in Display.template.php):
if ($context['topic_first_message'] == $message['id'] && $context['ba_jump_to_msg'] && ($context['total_visible_posts'] > 4))
to
if ($context['topic_first_message'] == $message['id'] && ($context['total_visible_posts'] > 4))

notification is visible, but it contains wrong message ID
Title: Re: Best Answer
Post by: Avalanche91 on December 05, 2013, 05:22:16 PM
Quote from: phantomm on December 05, 2013, 04:25:31 PM
One more thing - notification in first message is not showing up. When I replaced this (in Display.template.php):
if ($context['topic_first_message'] == $message['id'] && $context['ba_jump_to_msg'] && ($context['total_visible_posts'] > 4))
to
if ($context['topic_first_message'] == $message['id'] && ($context['total_visible_posts'] > 4))

notification is visible, but it contains wrong message ID
I just love you man, I owe you a beer... at least! The problem was coming from Display.php where I, assuming that it contains the id of the topic, was passing $output['id'] to the query that was supposed to find which answer is marked as best. As strange as it seems, it was working at some places and obviously it didn't at ohers, that's why I haven't noticed it. I have added a separate query that finds the real id of the topic and now the links are being built correctly. The job of the piece of code ($context['total_visible_posts'] > 4) is to prevent displaying the link to the best answer if it actually is one of the first four replies.

I have added the fix to the previous version (BestAnswer-v1.1.zip).
Title: Re: Best Answer
Post by: Adrek on December 05, 2013, 05:32:21 PM
Thanks for quick fix, but please test is on clean forum :)

URL in notification is still wrong, for example:
now it is: /index.php?topic=100973.msg104379#msg104379
and it should be: /index.php?topic=16431.msg104379#msg104379

in this example - 100973 is ID of my first message in topic
16431 is real topic ID
and Best answer ID is 104379, so basically you need to fix topic ID in URL :)
Title: Re: Best Answer
Post by: Avalanche91 on December 05, 2013, 05:43:08 PM
Quote from: phantomm on December 05, 2013, 05:32:21 PM
Thanks for quick fix, but please test is on clean forum :)

URL in notification is still wrong, for example:
now it is: /index.php?topic=100973.msg104379#msg104379
and it should be: /index.php?topic=16431.msg104379#msg104379

in this example - 100973 is ID of my first message in topic
16431 is real topic ID
and Best answer ID is 104379, so basically you need to fix topic ID in URL :)
With pleasure, I just had to replace the variable in Display.template.php. I fixed so many bugs this evening that I decided to drop the first version and leave the most recent one containing least bugs. Thank you guys!
Title: Re: Best Answer
Post by: Dzonny on December 05, 2013, 06:14:19 PM
Nice and handy mod, useful to have, thanks! ;)
Title: Re: Best Answer
Post by: Biology Forums on December 05, 2013, 11:07:43 PM
Quote from: littlenicki on December 05, 2013, 12:38:30 PM
Hello, this is an excellent mod! Could you please do a SMF 1.1 verson of it? Thanks so much!

There is an excellent one already for 1.x
Title: Re: Best Answer
Post by: Avalanche91 on December 06, 2013, 09:02:10 AM
Quote from: Liam_michael on December 05, 2013, 11:07:43 PM
There is an excellent one already for 1.x
The reason I decided to create this MOD was due to the fact that I couldn't find such kind of a MOD. May be you should share a link?


Also, I've made another update. Cheers!
QuoteNotification message below the question now shows only if the best answer is third or greater post.
Title: Re: Best Answer
Post by: Kindred on December 06, 2013, 09:58:36 AM
Nice job, Avalanche91.

It is good to see a responsive mod author :)
Title: Re: Best Answer
Post by: 4Kstore on December 06, 2013, 01:04:34 PM
now work great but I don't like that the mod add 2 query for each reply on the topic:

(https://www.simplemachines.org/community/proxy.php?request=http%3A%2F%2Fi.imgur.com%2F3mOXnqP.png&hash=3d35eddf9392eda11239b19bcb413ab30e182310)

If the topic have 6 replies
Without the mod the topic load with 13 querys
With the mod the topic load with 29 querys.

If the topic have 7 replies
Without the mod the topic load with 13 querys
With the mod the topic load with 32 querys.
Title: Re: Best Answer
Post by: Avalanche91 on December 06, 2013, 02:12:42 PM
Hello 4Kstore and many thanks for your interest. I feel so embarrassed, I was in such a rush to finish the MOD that I totally forgot to put some if statements to lower the database usage. Could you please tell me what kind of tool are you using to track the forum performance, that picture looks very useful?

I am using 4 queries;
- the first one is to figure out which topic I am going to deal with (id_topic from DB);
- the second one is to find if this topic contains a post marked as best answer;
- the third one I added this morning to help me prevent from the displaying the notification message below the first post (the question);
- the fourth one contains... I was about to describe what was the fourth query doing when I took a more precise look on it and I saw that I can actually combine it with my second query.

I think that there should be only 3 queries in total that the MOD will be using now. Could you please test the version that I published as BestAnswer-v1.1.zip or at least give me a tip how to manually track the queries that are being executed.
Title: Re: Best Answer
Post by: Arantor on December 06, 2013, 02:15:39 PM
QuoteCould you please tell me what kind of tool are you using to track the forum performance, that picture looks very useful?

Add $db_show_debug = true; to your Settings.php file. This will give you the entire debug output.

OK, I'm going to have to look at what you're doing but it sounds like you're putting it in prepareDisplayContext, which is run once per post.

Quote- the first one is to figure out which topic I am going to deal with (id_topic from DB);

Use the global $topic for that.
Title: Re: Best Answer
Post by: Avalanche91 on December 06, 2013, 02:41:41 PM
Quote from: Arantor Beeblebrox the First on December 06, 2013, 02:15:39 PM
Use the global $topic for that.
Thanks, this is exactly what I needed to drop one more query.  :) So now the MOD is using only two queries in total.
Btw $topic doesn't seem to work in Display.template.php but at least I am able to assign it to a variable in Display.php.
Title: Re: Best Answer
Post by: Arantor on December 06, 2013, 02:43:58 PM
You're not supposed to do anything other than purely presentation stuff in the templates. All main logic should already have been done in the main Display.php.

Don't forget that earlier in Display.php, there's a list built of all the messages going to be displayed to the user, look before the point where $messages_request is declared, you'll see an array (off hand I think it's actually called $messages) which contains all the ids to be loaded.
Title: Re: Best Answer
Post by: Avalanche91 on December 06, 2013, 03:10:17 PM
Quote from: Arantor Beeblebrox the First on December 06, 2013, 02:43:58 PM
You're not supposed to do anything other than purely presentation stuff in the templates. All main logic should already have been done in the main Display.php.

Don't forget that earlier in Display.php, there's a list built of all the messages going to be displayed to the user, look before the point where $messages_request is declared, you'll see an array (off hand I think it's actually called $messages) which contains all the ids to be loaded.
Yep, indeed. This is the very idea of MVC.

The array is actually called $message, and it contains the information about the posts. Unfortunately it doesn't hold anything such as id_topic. But it's not a problem, I already have the id of the topic stored in the database (the table that I am using to store the best answers).  :)
Title: Re: Best Answer
Post by: Arantor on December 06, 2013, 03:18:20 PM
Thanks for ignoring what I was trying to tell you.

1. I am not referring to $message which is a per-post item created during the depths of prepareDisplayContext. This is why you are generating queries per post.

2. I mentioned $messages, not $message, as an array of the message ids that will be fetched for the current post. I only didn't tell you where to look because I was in the middle of something else. Look at Display.php, line 814 onwards.


Using this information, let's be *really* clever and avoid extra queries.

The query on line 180 fetches the topic data. Fetch the msg id as the 'best answer' in that query, no extra queries required. This will be pushed into $topicinfo which is global.

Then by the time you get to the messages query stuff at line 814, you'll already know whether or not you have the best answer. But even if you didn't worry about that, you will have the topic's 'best answer' id available in $topicinfo, which means by the time you get to prepareDisplayContext, you don't have to do any queries but simple comparisons.
Title: Re: Best Answer
Post by: Avalanche91 on December 06, 2013, 03:46:03 PM
Quote from: Arantor Beeblebrox the First on December 06, 2013, 03:18:20 PM
Thanks for ignoring what I was trying to tell you.

1. I am not referring to $message which is a per-post item created during the depths of prepareDisplayContext. This is why you are generating queries per post.

2. I mentioned $messages, not $message, as an array of the message ids that will be fetched for the current post. I only didn't tell you where to look because I was in the middle of something else. Look at Display.php, line 814 onwards.


Using this information, let's be *really* clever and avoid extra queries.

The query on line 180 fetches the topic data. Fetch the msg id as the 'best answer' in that query, no extra queries required. This will be pushed into $topicinfo which is global.

Then by the time you get to the messages query stuff at line 814, you'll already know whether or not you have the best answer. But even if you didn't worry about that, you will have the topic's 'best answer' id available in $topicinfo, which means by the time you get to prepareDisplayContext, you don't have to do any queries but simple comparisons.
Now I understand you, sir. Thanks for the suggestion but at this point of development I will take the liberty to go on with a separate query. I am already joining one more table on my query and I will have to make some more replacements in the view. I will consider it again tomorrow, but I think I had enough of it for today; I would like to consult with my pillow firstly :)
Title: Re: Best Answer
Post by: Avalanche91 on December 09, 2013, 03:12:24 PM
Hey, @Arantor Beeblebrox the First , I spent some time trying to work out your suggestion. So I would like to hear your opinion now, here's what I managed to figure out. As you well noted, I can merge my code into the query at line 180 where we normally have:
Code (mysql) Select
SELECT
t.num_replies, t.num_views, t.locked, ms.subject, t.is_sticky, t.id_poll,
t.id_member_started, t.id_first_msg, t.id_last_msg, t.approved, t.unapproved_posts,
' . ($user_info['is_guest'] ? 't.id_last_msg + 1' : 'IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1') . ' AS new_from
' . (!empty($modSettings['recycle_board']) && $modSettings['recycle_board'] == $board ? ', id_previous_board, id_previous_topic' : '') . '
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)' . ($user_info['is_guest'] ? '' : '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = {int:current_topic} AND lt.id_member = {int:current_member})
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = {int:current_board} AND lmr.id_member = {int:current_member})') . '
WHERE t.id_topic = {int:current_topic}
LIMIT 1


So after adding more fields to the select clause and joining two more tables, I ended up with this.
Code (mysql) Select
SELECT
t.num_replies, t.num_views, t.locked, ms.subject, t.is_sticky, t.id_poll,
t.id_member_started, t.id_first_msg, t.id_last_msg, t.approved, t.unapproved_posts,
' . ($user_info['is_guest'] ? 't.id_last_msg + 1' : 'IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1') . ' AS new_from
' . (!empty($modSettings['recycle_board']) && $modSettings['recycle_board'] == $board ? ', id_previous_board, id_previous_topic' : '') . '
/* LINE ADDED */ ,`ba`.`id`,`ba`.`id_msg`,`ba`.`id_topic`,`ba`.`id_member`,DATE(`ba`.`time_marked`) AS `day`,TIME(`ba`.`time_marked`) AS `time`,`m`.`member_name`
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)' . ($user_info['is_guest'] ? '' : '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = {int:current_topic} AND lt.id_member = {int:current_member})
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = {int:current_board} AND lmr.id_member = {int:current_member})') . '
/* LINE ADDED */ LEFT JOIN {db_prefix}best_answer AS `ba` ON `ms`.`id_msg` = `ba`.`id_msg`
/* LINE ADDED */ LEFT JOIN {db_prefix}members AS `m` ON `ba`.`id_member` = `m`.`id_member`
WHERE t.id_topic = {int:current_topic}
LIMIT 1


So far so good! Now I only need to *somehow* place the second query here, which, by purpose, needs to tell me if the post marked as best answer is among the first 3 answers to the topic. Here comes the thing that troubles me. I have been thinking for hours and I did find a solution but, honestly, I don't really like for two reasons.
- One, it's actually a subquery and I have to disable query check to allow the subquery to work;
- Two, I am using concatenation that may take a lot of resources although I am not absolutely sure here.
This is the line of code:
Code (mysql) Select
(SELECT SUBSTRING_INDEX(GROUP_CONCAT(`id_msg` SEPARATOR "|"), "|", 4) FROM {db_prefix}messages WHERE `id_topic` = {int:id_topic}) AS `ba_jump_in_arr`
-- returns something like:  ["ba_jump_in_arr"]=> string(5) "2|3|4"


So, have you got any suggestions whether my concerns are reasonable or this way of building the query will cause no problems?
Title: Re: Best Answer
Post by: Arantor on December 09, 2013, 03:26:54 PM
I'm curious: why you have a table for best answer joined to *message*? Surely there's only one best answer for a topic? I assumed, slightly naively, that you had added it to the topics table based on the fact that's what I'd do if I were doing it...

Why also do you need the best answer being in the first three replies? There is really no good way to do that.
Title: Re: Best Answer
Post by: Avalanche91 on December 09, 2013, 04:04:55 PM
Quote from: Arantor Beeblebrox the First on December 09, 2013, 03:26:54 PM
I'm curious: why you have a table for best answer joined to *message*? Surely there's only one best answer for a topic? I assumed, slightly naively, that you had added it to the topics table based on the fact that's what I'd do if I were doing it...

Why also do you need the best answer being in the first three replies? There is really no good way to do that.
Everything is because one link that I am displaying below the question post. This link is supposed to take you to that post which is marked as best answer. It comes very handy when you have several pages of posts and you are just looking for the solution of the problem. So, there is no need of displaying this link when there are just few posts (3)... you can clearly see where the answer is.

To be honest, the original idea was to make it as if in Stackoverflow, with that best answer at very top. But unfortunately I found it impossible to mess with the order of the posts. On the other hand, now that you have personally explained to me what does $messages do in Display.php, I might actually be able to work that order out.
Title: Re: Best Answer
Post by: Arantor on December 09, 2013, 04:14:06 PM
Well... store the msg id of the best answer in the topics table.

You can always generate the link to a specific message from the topic id and message id - index.php?topic=123.msg456#msg456 will always take you to message 456 if message 456 is in topic 123. SMF will figure out which page to go to etc.

Reinjecting the message id into $messages won't work very well; the query that fetches the post data explicitly orders those posts by way of id_msg. You may have to do a separate query to fetch the best answer if the best answer is not currently listed in $messages, but that's also problematic.
Title: Re: Best Answer
Post by: Avalanche91 on December 09, 2013, 04:40:18 PM
Quote from: Arantor Beeblebrox the First on December 09, 2013, 04:14:06 PM
Well... store the msg id of the best answer in the topics table.
It is not going to help me. I store additional information regarding time and user; I don't want to drop it.

Maybe I should reconsider my logic, so many efforts for such a simple task. Or I could just delete that piece of code and work with the CSS to make it look less silly when I have only one answer. Or take the laziest way, to leave it just like this...
Title: Re: Best Answer
Post by: CHAOS-THEORY on December 10, 2013, 09:25:37 AM
Theres only one bug that u didn't notice; when u delete the choosen best answer's reply in the topi... the Best answer tip stays there all the time and can't be removed.

'This topic contains a post which is marked as Best Answer. Press here if you would like to see it.'

ir's stuck/bugged; i can't remove it, due that the reply choosed as best answer is removed. give me a fix as quick as u can. thanks for ur cooperation
Title: Re: Best Answer
Post by: Shambles on December 10, 2013, 09:26:55 AM
Maybe Avalanche91 could consider moving the mod to the Customization Development (http://www.simplemachines.org/community/index.php?board=195.0) board with [WIP][MOD] in the title, just to remind other members that it's still under development/fix...?
Title: Re: Best Answer
Post by: Avalanche91 on December 11, 2013, 10:34:27 AM
Quote from: Shambles on December 10, 2013, 09:26:55 AM
Maybe Avalanche91 could consider moving the mod to the Customization Development (http://www.simplemachines.org/community/index.php?board=195.0) board with [WIP][MOD] in the title, just to remind other members that it's still under development/fix...?
Thank you very much, I wanted to warn the users somehow but I actually had no idea how to do it.

@CHAOS-THEORY
Thank you for the report, this bug has been fixed.

Although it looks like a small update I actually did some serious changes including the suggestion of @Arantor Beeblebrox the First. I managed to catch most of the bugs that were caused by the new changes, but I am still afraid that there might be more that I am not aware of.
Title: Re: [WIP][MOD]Best Answer
Post by: Alex_Ita on December 11, 2013, 02:48:22 PM
Hi. Congratulation for this mod, very helpfully.

I 've just downloaded newest version and it works better then older.

I've occurred a probably bug: if I merge two threads, and in those trhreads there are two best answer, in new merged topic there's some problem:
in the first post I can read there is a best answer, but the best answer has lost highlight, and the buttons "best answer" and "undo best answer" are disappared.

Would be great if I can assigne privilege to mark best answer at a particular group (not only section moderators).

My best regards.


Alex
Title: Re: [WIP][MOD]Best Answer
Post by: Skaty on December 12, 2013, 07:48:39 AM
It would be great feature to use this mod in specific boards.

-Which code should i move to fix that issue ? (display php attached).
(https://www.simplemachines.org/community/proxy.php?request=http%3A%2F%2Fi.imgur.com%2FBc5T0Qi.jpg&hash=aa1ed6fa73fdb705062e28afd1f6a63950660436)

-I think there is no permissions for mod right now ?

thank your for the mod it is usefull.

Title: Re: [WIP][MOD]Best Answer
Post by: Avalanche91 on December 12, 2013, 12:57:04 PM
Quote from: Skaty on December 12, 2013, 07:48:39 AM
It would be great feature to use this mod in specific boards.

-Which code should i move to fix that issue ? (display php attached).
(https://www.simplemachines.org/community/proxy.php?request=http%3A%2F%2Fi.imgur.com%2FBc5T0Qi.jpg&hash=aa1ed6fa73fdb705062e28afd1f6a63950660436)

-I think there is no permissions for mod right now ?

thank your for the mod it is usefull.
It looks like there is a conflict between the two mods. I will have to install Thank-o-Matic and change the CSS a bit.

@Alex_Ita Thank you very much. The fix for the bug with the merged topics is ready but I will upload it once I make a fix for in case of using the option to split topics. Things are slightly different when we speak of topic splitting, there are several possible occasions and a single solution might not be the best option here. I want to make the MOD as useful as possible but I have the feeling that eventually the solution would simply be to unset the post marked as best answer, and the person doing the topic splitting would have to manually mark the desired post again.
Quote from: Alex_Ita on December 11, 2013, 02:48:22 PMWould be great if I can assigne privilege to mark best answer at a particular group (not only section moderators).
Originally I wanted to make things simple, if I go for such extras I will have to create a new view (template) for the MOD and I will have to add all the things that I have in my mind (custom colours, rating system, etc :D). I could eventually think of adding such things in version two of my modification, but I don't think that I will have the time (and the patience) any time soon. This is my first mod and it looks like I have underrated the complexity of the SMF platform.

Hopefully I will be ready with the fix for Skaty's problem and the rest of the things that were already reported by the end of tomorrow. Thank you very much guys, great community!
Title: Re: [WIP][MOD]Best Answer
Post by: Alex_Ita on December 13, 2013, 05:48:00 AM
Quote from: Avalanche91 on December 12, 2013, 12:57:04 PM
Hopefully I will be ready with the fix for Skaty's problem and the rest of the things that were already reported by the end of tomorrow. Thank you very much guys, great community!

Thanks for your job and you patience. Great mod!

I waiting for your update  :)
Title: Re: [WIP][MOD]Best Answer
Post by: Skaty on December 13, 2013, 12:17:55 PM
Turkish Translate



// Best Answer
$txt['bestanswer'] = 'En İyi Cevap';
$txt['rv_bestanswer'] = 'En İyi Cevap (Geri Al)';
$txt['bestanswer_marked'] = 'Bu mesaj En İyi Cevap olarak işaretlendi. İşaretleyen: ';
$txt['bestanswer_jumpto_1'] = 'Bu konu En İyi Cevap olarak işaretlenmiş bir mesaj içeriyor.';
$txt['bestanswer_jumpto_2'] = 'Görmek için tıklayınız.';
// End of Best Answer
Title: Re: [WIP][MOD]Best Answer
Post by: Avalanche91 on December 13, 2013, 05:36:54 PM
According to GooGle Translate the Turkish translation quite makes sense. I don't speak Turkish and I have no idea if the translation is correct so if anyone has to say something about Skaty's strings, let it be. Other than that I can only say thanks.


Quote* Notes
   - Topic managing:
      -- In case of merging topics each of containing posts marked as best answers, these posts will no longer be marked as such and you will have to choose a new best answer manually, otherwise the best answer will be merged along with the rest of the posts;
      -- In case of splitting a topic containing a post marked as best answer, the best answer will be moved along with the rest of the posts or unset as best answer if it is the only post going to be split.
It was easier than I thought, once you figure out how the topic splitting/merging works you can make the life of the user a little easier... at least.


One more thing, I haven't fixed the problem with the Thank-o-matic MOD. I hope I am mistaken, but GooGle brought me to this page (http://custom.simplemachines.org/mods/index.php?mod=710) when I searched for the MOD and apparently the MOD is no longer there. That's why I couldn't download it and make any tests.
Title: Re: [WIP][MOD]Best Answer
Post by: margarett on December 13, 2013, 07:05:18 PM
ADK-Team removed all their MODs from our modsite, that's why you don't find it in there
http://www.smfpersonal.net/ModsSmfp.html;sa=topic;id=3284
Title: Re: [WIP][MOD]Best Answer
Post by: Alex_Ita on December 14, 2013, 01:27:27 PM
Thank you so much Avalanche91

here you are an Italian language:

// Best Answer
$txt['bestanswer'] = 'Miglior risposta';
$txt['rv_bestanswer'] = 'Annulla Miglior risposta';
$txt['bestanswer_marked'] = 'Marcato come miglior risposta da';
$txt['bestanswer_jumpto_1'] = 'Questo topic contiene un post marcato come Miglior Risposta.';
$txt['bestanswer_jumpto_2'] = 'Clicca qui se vuoi prenderne visione.';
// End of Best Answer


UTF8
// Best Answer
$txt['bestanswer'] = 'Miglior risposta';
$txt['rv_bestanswer'] = 'Annulla miglior risposta';
$txt['bestanswer_marked'] = 'Marcato come miglior risposta da';
$txt['bestanswer_jumpto_1'] = 'Questo topic contiene un post marcato come Miglior Risposta.';
$txt['bestanswer_jumpto_2'] = 'Clicca qui se vuoi prenderne visione.';
// End of Best Answer
Title: Re: [WIP][MOD]Best Answer
Post by: Avalanche91 on December 14, 2013, 02:38:57 PM
Quote from: margarett on December 13, 2013, 07:05:18 PM
ADK-Team removed all their MODs from our modsite, that's why you don't find it in there
http://www.smfpersonal.net/ModsSmfp.html;sa=topic;id=3284
Thank you very much, margarett. I just spent about two hours trying to figure out some way to go through this problem and I didn't find a good enough solution. The trouble comes a little below the lines where the code producing user signatures comes:
Code (php) Select
echo '
</div>
</div>
<span class="botslice"><span></span></span>
</div>
<hr class="post_separator" />';


For some reason the guys working on Thank-o-meter have decided to place their code within the echo. In matter of fact, that hr tag has display property set to none so basically it is not even visible. It would have been so painless if they have placed their div tag containing thank counts after the hr. The only way I could sort things out is to put my code within the echo as well, searching for the whole piece of code before the hr tag. Which I don't really want to do because it may cause more conflicts with other modifications. Plus that, to make things even worse Thank-o-meter is looking for tabulations too:
Code (xml) Select
<search position="after"><![CDATA[ <hr class="post_separator" />';]]></search>These white-spaces cause more code conflict and in the end if you are to uninstall one of these two mods from your forum - you will have to firstly uninstall the mod that you have installed second.

I will contact the Thank-o-meter team to ask them for a consensus about this precedent. If nothing comes out of that I will publish the changes and I will have my fingers crossed for no other code conflicts with any other modifications. And yes, the Italian version will also be included, thank you Alex_Ita.
Title: Re: [WIP][MOD]Best Answer
Post by: Arantor on December 14, 2013, 02:40:48 PM
Except they don't want to put it there because they want it 'inside the post' and thus inside the div.

As for consensus, don't expect great things. They removed all their mods from here because they didn't like how we do things.
Title: Re: [WIP][MOD]Best Answer
Post by: Avalanche91 on December 14, 2013, 02:58:15 PM
Quote from: Arantor Beeblebrox the First on December 14, 2013, 02:40:48 PM
Except they don't want to put it there because they want it 'inside the post' and thus inside the div.

As for consensus, don't expect great things. They removed all their mods from here because they didn't like how we do things.
Yes, I agree with you. If I were to make their mod I'd probably want to make it *attached* to the post. But honestly, it looks like it is outside of the post, as if it is a new tiny post. There I lose the point.

I changed my mind, there is no point of contacting them. Even if they make any changes there would still be many people using older versions of their MOD. I will look for another solution.
Title: Re: [WIP][MOD]Best Answer
Post by: Avalanche91 on December 14, 2013, 04:24:21 PM
Well if you can't fix it, make use of it. Soooo, I moved everything at the top and to be honest it might even look better :)
QuoteChangelog
v1.2.2
Added support for Italian language. Translation by Alex_Ita;
Moved information area about the Best Answer from the bottom to the top of the post;
Best answers are now properly displayed along with Thank-o-matic thanks.tic thanks.
Title: Re: [WIP][MOD]Best Answer
Post by: Skaty on December 14, 2013, 06:17:06 PM
Avalanche91, thank you so much for your effor to make things better.
Title: Re: [WIP][MOD]Best Answer
Post by: Gargoyle on December 14, 2013, 08:14:39 PM
This looks promising!

Thanks for the work!
Title: Re: [WIP][MOD]Best Answer
Post by: margarett on December 14, 2013, 11:15:41 PM
Just for clarification, you are *not* forced, in any way, to guarantee compatibility with other mods. You should stick your mods to a clean install. If you find a way to make it compatible with other mods, that should be IMHO, posted in this topic as a trick (if you want to call it that way).

If not, then why don't you make it compatible with Likes or ... or ...

Anyway, great work in supporting your mod ;)
Title: Re: [WIP][MOD]Best Answer
Post by: Arantor on December 14, 2013, 11:20:22 PM
Though it'll be easier in 2.1 which has support for likes built in :)
Title: Re: [WIP][MOD]Best Answer
Post by: margarett on December 14, 2013, 11:26:48 PM
:P It was just an example. But you know that ;)
Title: Re: [WIP][MOD]Best Answer
Post by: Skaty on December 15, 2013, 06:31:35 AM
I installed the updated version. It is like this now:
(https://www.simplemachines.org/community/proxy.php?request=http%3A%2F%2Fi.imgur.com%2Fpe9POJu.png&hash=4b7b98537ff90fec5e36aba641b8b1f012aa4339)


Or i can just remove that green frame :)  which code is that ?
Title: Re: [WIP][MOD]Best Answer
Post by: akbora on December 15, 2013, 06:33:53 AM
The last version is perfect. I want to say that 3 points:

1. Warning label must be at the bottom of last message or with above first message. Because nobody can not see the first message of big topic ( Or how can I change it?)
2. Warning icon there must be message index and bords in main page
3. Permission must be selectable any group from admin...


Edit to add: 4. The User who its message remarked must take an info PM or email or with both of them and profile commnet

Thanks a lot
Title: Re: [WIP][MOD]Best Answer
Post by: Avalanche91 on December 15, 2013, 11:50:51 AM
Quote from: Skaty on December 15, 2013, 06:31:35 AM
I installed the updated version. It is like this now:
(https://www.simplemachines.org/community/proxy.php?request=http%3A%2F%2Fi.imgur.com%2Fpe9POJu.png&hash=4b7b98537ff90fec5e36aba641b8b1f012aa4339)


Or i can just remove that green frame :)  which code is that ?
This is a very strange problem that you are showing me here. I may even claim that it is impossible to happen. Your forum is using exactly the same structure as the default theme, the very one that I have been using to test everything at so far. I don't see any reason why it should look like this. As dumb as it sounds, I'd rather ask if you have cleared your browser's cache. I fear that if you try to remove the border it would become unclear which exactly is the post marked as best answer. But still, it's the first operation for Display.template.php in modification.xml. I am just adding a class to the div tag that is holding the whole post.

@akbora I don't really understand what you are asking me in the first two points, could you please try explaining again? For point number 3 I already spoke of a few posts before, I know it would be amazing but for now I will keep things simple, I may add such functionality in future. About number 4, I don't really think it is such a big deal when somebody changes the best answer. I mean, this *somebody* will always be either an admin or a moderator - a person who is trustful enough.
Title: Re: [WIP][MOD]Best Answer
Post by: Adrek on December 15, 2013, 12:57:22 PM
I have one "feature request" :) Can you use timestamp and format it with timeformat(); for best answers? This way date will be formatted as any other date on forum.
Title: Re: [WIP][MOD]Best Answer
Post by: akbora on December 15, 2013, 01:46:55 PM
Thank you for your reply. I am sorry my english isn't good.

I try to explain.

1. I want that Best Answer warning message is not only the first message it must be bottom of the last message. Fisrt message can not be seen in the big topic that contains hundreds messages.

2. Everyone can see the best answer icon on the homepage and message index. Like rss icons.

Thanks
Title: Re: [WIP][MOD]Best Answer
Post by: CHAOS-THEORY on December 15, 2013, 02:51:26 PM
Alright, let's get some bugz. thanks for the info/fix.
_________________________________________
Needs 2 more things,

1- Permission to choose specific Boards/Topics to ignor having a bestanswer.
2- http:// w w w(.)w3schools(.)com/css/css3_gradients(.)asp (cross browsers)

a wish i can help u man, buh am busy all the day.. pc technology ******, u know Game servers, Ruling communities, programing...
so if any free time comes up; ill be here to Bug u cause am startin to get interested in providing help lel. Peace yo
Title: Re: [WIP][MOD]Best Answer
Post by: Avalanche91 on December 15, 2013, 05:44:20 PM
Quote from: phantomm on December 15, 2013, 12:57:22 PM
I have one "feature request" :) Can you use timestamp and format it with timeformat(); for best answers? This way date will be formatted as any other date on forum.
Of course I can! I didn't know of this function's existence otherwise I'd have stored the date in the database as UNIX timestamp. Much appreciated, I already played with the function and changed the look of the date/time in the notification bar. It will be published in the next release.


Quote from: akbora on December 15, 2013, 01:46:55 PM
Thank you for your reply. I am sorry my english isn't good.

I try to explain.

1. I want that Best Answer warning message is not only the first message it must be bottom of the last message. Fisrt message can not be seen in the big topic that contains hundreds messages.

2. Everyone can see the best answer icon on the homepage and message index. Like rss icons.

Thanks
Now I understand what you are trying to tell me. I could maybe add an icon to directly go to the best answer, as if you are clicking on that icon to go to the latest post when browsing topics. I like this suggestion of yours. But I disagree with the other suggestion to add the link to the best answer at the bottom of the page. Honestly I find it quite useless. Let's say that we have a huge topic, about 100 pages. The first place where I'd search for solution to my problem is the first post, I wouldn't even bother scrolling somewhere else in such big topic. This is my opinion, please do tell if I miss something but I think it would not be much useful.


Quote from: CHAOS-THEORY on December 15, 2013, 02:51:26 PM
Alright, let's get some bugz. thanks for the info/fix.
_________________________________________
Needs 2 more things,

1- Permission to choose specific Boards/Topics to ignor having a bestanswer.
2- http:// w w w(.)w3schools(.)com/css/css3_gradients(.)asp (cross browsers)

a wish i can help u man, buh am busy all the day.. pc technology ******, u know Game servers, Ruling communities, programing...
so if any free time comes up; ill be here to Bug u cause am startin to get interested in providing help lel. Peace yo
Ah, I know pretty well, I also have exams. Programming used to my job but now is just a hobby. So due to the lack of time I will leave the ability to add permissions to choose specific boards/topics to ignore having a best answer for future second version of my MOD. I am sorry.
Title: Re: [WIP][MOD]Best Answer
Post by: drfun on December 15, 2013, 06:00:51 PM
Nice mod, i just install the mod but cant find any place to enable it. please i will be glad if am pointed to it. this has not been included in the mod download description
QuoteBest Answer mod gives you the ability to mark a reply in a topic as Best Answer/Solution. The marked answer will be lit in green, showing the other users what exactly is the solution to the topic.

The permission to mark an answer as such has the person who started the topic, or if for any reason he has forgotten to mark anything, moderators and administrators can do this as well.
And after installation i was not redirected to any page to enable it.
Title: Re: [WIP][MOD]Best Answer
Post by: Avalanche91 on December 15, 2013, 06:21:57 PM
Quote from: drfun on December 15, 2013, 06:00:51 PM
Nice mod, i just install the mod but cant find any place to enable it. please i will be glad if am pointed to it. this has not been included in the mod download description
QuoteBest Answer mod gives you the ability to mark a reply in a topic as Best Answer/Solution. The marked answer will be lit in green, showing the other users what exactly is the solution to the topic.

The permission to mark an answer as such has the person who started the topic, or if for any reason he has forgotten to mark anything, moderators and administrators can do this as well.
And after installation i was not redirected to any page to enable it.
The MOD doesn't need to be enabled. It becomes available to use in any topic within your forum once you install it. Just head to any of your topics and you should see a green tick button labeled Best Answer at the top right corner of the posts, next to quoting, modifying, removing, etc.
Title: Re: [WIP][MOD]Best Answer
Post by: drfun on December 15, 2013, 06:33:16 PM
Quoteyou should see a green tick button labeled Best Answer at the top right corner of the posts, next to quoting, modifying, removing, etc.
Thank you for the quick response, however i have not seen anything like that on the topic.
Title: Re: [WIP][MOD]Best Answer
Post by: DSystem on December 15, 2013, 06:35:05 PM
Congratulations!!! Great mod. Will be a hit ...:D

Brazil Portuguese translation:

Title: Re: [WIP][MOD]Best Answer
Post by: Avalanche91 on December 15, 2013, 06:42:21 PM
Quote from: drfun on December 15, 2013, 06:33:16 PM
Quoteyou should see a green tick button labeled Best Answer at the top right corner of the posts, next to quoting, modifying, removing, etc.
Thank you for the quick response, however i have not seen anything like that on the topic.
Were there any problems during the installation? You may want to take a look at the screenshots in the first post of this topic.
Title: Re: [WIP][MOD]Best Answer
Post by: drfun on December 15, 2013, 07:04:53 PM
There were no problem during the installation, it went smoothly. i am using the theme Flagrantly by, Crip. i also install it my second forum and its still the same thing.
Title: Re: [WIP][MOD]Best Answer
Post by: DSystem on December 15, 2013, 07:09:43 PM
Do a reload of the page in the browser it should work. Already installed in two tests here and it worked perfectly. I'm only expected over the development to put on my forum. So far I didn't find any bug.
Title: Re: [WIP][MOD]Best Answer
Post by: drfun on December 15, 2013, 07:17:36 PM
I have refresh and reloaded the page in the browser but still nothing is coming up. i also open the forum on a different browser, open a different topic and the only thing coming up there is Quote, Modify and Remove

   
   

Title: Re: [WIP][MOD]Best Answer
Post by: Dzonny on December 16, 2013, 05:20:36 AM
Did you check your custom theme install while installing mod? Maybe the code is not placed inside your Display.template.php or the button image is not there?
Check if changes is made on your files following this page:
http://custom.simplemachines.org/mods/index.php?action=parse;mod=3803;attach=227026;smf_version=2.0.6
Title: Re: [WIP][MOD]Best Answer
Post by: Avalanche91 on December 16, 2013, 07:14:33 AM
No, it's not about the browser cache, I already said it was a dumb suggestion but I had no other idea what it could be. Anyways, you can fix that by ticking the checkbox for your theme at the bottom of the installation page where the "Install in Other Themes" section is. The thing that bothers me is related to the picture, it seems that it is not being copied in the same directory as the custom theme, in our case Flagrantly. Even the images for Thank-o-matic are not available for Flagrantly, have you guys got any suggestions about the image?
Title: Re: [WIP][MOD]Best Answer
Post by: drfun on December 16, 2013, 08:45:56 AM
Quote from: Dzonny on December 16, 2013, 05:20:36 AM
Did you check your custom theme install while installing mod? Maybe the code is not placed inside your Display.template.php or the button image is not there?
Check if changes is made on your files following this page:
http://custom.simplemachines.org/mods/index.php?action=parse;mod=3803;attach=227026;smf_version=2.0.6

Thanks i went through all the file one after the other, and everything is in place, and it is working now. The only problem now is the image which is not displaying. however it sitting in the right folder it should be, that is "./Themes/default/images/buttons"
"
Any idea on how to get this image to display? i notice all the images in the "/Themes/default/images/buttons" ends with the extension .gif while the best_answer ends in .png
Title: Re: [WIP][MOD]Best Answer
Post by: Avalanche91 on December 16, 2013, 10:10:49 AM
Nah, don't worry about the file extension, it reads the css file so you just have to copy the image Themes/default/images/buttons/best_answer.png to Themes/flagrantly202/images/buttons/best_answer.png.
Title: Re: [WIP][MOD]Best Answer
Post by: drfun on December 16, 2013, 02:16:56 PM
Quote from: Avalanche91 on December 16, 2013, 10:10:49 AM
Nah, don't worry about the file extension, it reads the css file so you just have to copy the image Themes/default/images/buttons/best_answer.png to Themes/flagrantly202/images/buttons/best_answer.png.
Thanks, everything is working perfectly now. Thanks a lot to you all, for putting me through.
Title: Re: [WIP][MOD]Best Answer
Post by: Avalanche91 on December 17, 2013, 10:24:57 AM
Quotev1.3
Added an icon shortcut to the best answer while browsing topics.

Since there haven't been any kind of bugs reported lately I think that this will be the final version and I will remove [WIP][MOD] from the title. Now I will work on making the mod available for SMF v1 since I was kindly asked to do so and even offered a bounty.

Thanks again to everyone who helped me repair and expand this modification. Cheers!  :)
Title: Re: Best Answer
Post by: akbora on December 17, 2013, 02:12:42 PM
Thanks Avalanche91, I want to change warning place last message intead of first message. How can I do? Can you help me about this.

Also let me add my asking list, best answer top10, top5 two way users applying best answer, and users that having best message

Edit: WARNİNG: Your file ext name is .RAR it must be .zip We can not install it.
Title: Re: Best Answer
Post by: Avalanche91 on December 17, 2013, 07:01:26 PM
Quote from: akbora on December 17, 2013, 02:12:42 PM
Edit: WARNİNG: Your file ext name is .RAR it must be .zip We can not install it.
I knew I had done something wrong.

Look for this piece of code in Display.template.php:
Code (php) Select
// If this is the question post; If we have a Best Answers; If the Best Answer is within the first 3 posts
if ($context['topic_first_message'] == $message['id'] && $context['ba']['id_msg'] && ($context['ba_display_link'] == false)) {
echo '<div id="best_answer_goto" class="centertext is_best_answer">' . $txt['bestanswer_jumpto_1'] . ' <a href="?topic=' . $context['ba']['id_topic'] . '.msg' . $context['ba']['id_msg'] . '#msg' . $context['ba']['id_msg'] . '">' . $txt['bestanswer_jumpto_2'] . '</a></div>';
}


Change $context['topic_first_message'] to $context['topic_last_message']. It will be displayed above the last message. In order to place it after the last post, you will have to move the entire piece of code to the end of the while loop but still inside of it.
Code (php) Select
while ($message = $context['get_message']())
{
/*
All the code and displaying the posts
*/

<-- Place the code here
}


Your asking list will be added to my to-do list. Just please try to explain better, I didn't understand most of the things you tried to say. I don't blame you for your English, I know the feeling I am not a native English speaker as well and I often make mistakes. I respect your efforts to express yourself. Please be more specific, what do you mean by top 10? I don't promise you anything for now, I just got other things to do.
Title: Re: Best Answer
Post by: akbora on December 17, 2013, 10:54:11 PM
I've changed first message to last message like your words but it gives error: Notice: Undefined index: ba_display_link in /home/xxxxxxx/public_html/Themes/default/Display.template.php on line 291 and no change still warning above first message.

İn fact I want it after last post that is bottom last post.

for Top10: You know there are two groups of user about BA.
1. Topic starter remarks BA,
2. User of takes BA.

Top 10 that is find out these counters of BA
Title: Re: Best Answer
Post by: Avalanche91 on December 18, 2013, 05:47:27 AM
Quote from: akbora on December 17, 2013, 10:54:11 PM
I've changed first message to last message like your words but it gives error: Notice: Undefined index: ba_display_link in /home/xxxxxxx/public_html/Themes/default/Display.template.php on line 291 and no change still warning above first message.

İn fact I want it after last post that is bottom last post.

for Top10: You know there are two groups of user about BA.
1. Topic starter remarks BA,
2. User of takes BA.

Top 10 that is find out these counters of BA
The purpose of this variable is to prevent the notification message from showing if the the best answer is within the first 3 answers. You can simply delete it. Just be careful, eventually you may not be able to uninstall the MOD. You are doing these changes at your own risk.
Title: Re: Best Answer
Post by: Avalanche91 on December 18, 2013, 12:35:15 PM
Quotev1.4
Added support for 1.1.x versions (tested on 1.1.19, default theme);
Fixed: images not being copied to custom themes.
Title: Re: Best Answer
Post by: akbora on December 18, 2013, 10:06:13 PM
Avalanche91 I don't understand you.

I insisted I want to get to the bottom of the last message of warning, I would be glad if you could help on this issue.

What about BA top10? must see to whom it has given a best message remark this is very important. or you would not know it fade. Thank you
Title: Re: Best Answer
Post by: Arantor on December 18, 2013, 10:12:45 PM
I think what Avalanche is saying is that just because you want something doesn't mean that anyone is obligated to provide it for you. It is working as the mod author intended, and the author is not bound by anyone to actually change it to suit you.
Title: Re: Best Answer
Post by: akbora on December 19, 2013, 03:55:24 PM
I've asked the author only. He gave me the code did not work but has failed. I've reported it. It was not a compulsion or otherwise harass or.

I may uninstall this mod. Most of my contribution was made for example message index icon. The aim here is to be a better mode.

Anyway: something like this would be very nice 'all best message button' How good is not it.Thank you
Title: Re: Best Answer
Post by: Avalanche91 on December 19, 2013, 04:30:09 PM
Quote from: akbora on December 19, 2013, 03:55:24 PM
I've asked the author only. He gave me the code did not work but has failed. I've reported it. It was not a compulsion or otherwise harass or.

I may uninstall this mod. Most of my contribution was made for example message index icon. The aim here is to be a better mode.

Anyway: something like this would be very nice 'all best message button' How good is not it.Thank you
Thank you, Arantor Beeblebrox the First, I have no idea how you manage to watch every single thread at these forums, your 50k posts here are impressive indeed, you have my respect.

Akbora, I do appreciate your opinion and your suggestions, I am pretty sure they would be very useful to the entire community but as I previously stated I don't have the time to make everything happen so this is the reason why I want to keep my mod as simple and clean as possible.

To be honest, I believe that I already told you how to achieve your desire to place the notification message at the bottom of the last post. It looks like I will have to repeat myself. $context['ba_display_link'] is there to prevent that notification from displaying if the post marked as best answer is within the first 3 posts. Getting that notice for undefined index means that there is already something broken. You may simply delete that variable (the line would look like this: if ($context['topic_last_message'] == $message['id'] && $context['ba']['id_msg']) { ), I don't recommend it but you do insist for things to go your way so this is how you can do it.

Cheers!
Title: Re: Best Answer
Post by: akbora on December 19, 2013, 05:22:12 PM
Very thanks Avalanche91 for your reply.

I am assertive will be very nice If you do that 'all BA message button' board and board also sub-board on the homepage. How?

Edit:

(https://www.simplemachines.org/community/proxy.php?request=http%3A%2F%2Fwww.anindatepki.com%2Fuploads%2F1387588270.jpg&hash=8b27540f330a626f09b74a1089e1492322cdacf9)

(https://www.simplemachines.org/community/proxy.php?request=http%3A%2F%2Fwww.anindatepki.com%2Fuploads%2F1387534815.jpg&hash=56d0fb125601ece7fe91b597fd5640d8410bfcb6)

For board  all message button

Thsi place is better than the old place I think.
Title: Re: Best Answer
Post by: jmpenasse on December 26, 2013, 09:13:17 AM
Hi Avalanche,

Thanks for this very usefull mod !

Here is my small contribution : French translation.

HTH

Best wishes and Happy New Year !
Title: Re: Best Answer
Post by: diegolyanky on January 10, 2014, 11:11:01 AM
Hi:

Nice MOD, I installed and worked fine.

Now, I need to give permissions to another groups...

How can I do that ?

I looked into:


/* - If being veiwed by topic starter, or may be an admin, or may be a mod;
- If this is not the first message;
- If somebody has not already marked any reply from the topic as Best Answer  */
if (($context['topic_starter_id'] == $context['user']['id'] || $context['user']['is_mod'] || $context['user']['is_admin']) && $message['id'] != $context['topic_first_message'] && $context['isMarkedBest'] == 0) {
echo '<a class="best_answer_button" href="' . $scripturl . '?action=bestanswer;do=mark;msg=' , $message['id'] , '"><img src="' . $settings['images_url'] . '/buttons/best_answer.gif" alt="' . $txt['bestanswer'] . '" title="' . $txt['bestanswer'] . '" align="middle" /><b>' . $txt['bestanswer'] . '</b></a>';
}
// Allows TopicStarter/Admin/Mod to unset a reply as Best Answer
if ($context['ba']['id_msg'] != 0 && $context['ba']['id_msg'] == $message['id'] && ($context['topic_starter_id'] == $context['user']['id'] || $context['user']['is_mod'] || $context['user']['is_admin']) && $message['id'] != $context['topic_first_message'] && $context['isMarkedBest'] == 1) {
echo '<a class="remove_best_answer_button" href="' . $scripturl . '?action=bestanswer;do=unmark;msg=' , $message['id'] , '"><img src="' . $settings['images_url'] . '/buttons/best_answer_remove.gif" alt="' . $txt['rv_bestanswer'] . '" title="' . $txt['rv_bestanswer'] . '" align="middle"  /><b>' . $txt['rv_bestanswer'] . '</b></a>';
}




What must I modify in these lines ?

Thanks a lot for helping me :)
Title: Re: Best Answer
Post by: Avalanche91 on January 10, 2014, 12:10:56 PM
Erhm, it's not going to be that simple.
$context['topic_starter_id'] == $context['user']['id'] - checks whether the topic starter is behind the monitor
$context['user']['is_mod'] || $context['user']['is_admin'] - check whether an admin or a mod is behind the monitor
So I don't know if the members of your desired groups are placed in the same array. Even if they are you will have to edit more files, for example $sourcedir/BestAnswer.php. There are quite the similar checks except that I have placed one more (I have absolutely no idea why lol). Look for the array $adminOrModerator, it represents IDs from the database (1 is admin, 2 is global mod, 3 is just mod), I think it should be the table {{$db_prefix}}membergroups. Basically you just have to add more numbers that correspond to these groups of yours.
Title: Re: Best Answer
Post by: margarett on January 10, 2014, 12:19:59 PM
In order to do that you must create such a permission (not terribly difficult) and use allowedTo('your_new_permission_here'). But you should do that in Sources, not in template (if you do it in Sources, you can easily pass it to template via $context)

edit: fixed typo
Title: Re: Best Answer
Post by: diegolyanky on January 10, 2014, 12:31:03 PM
Avalancha:

Gracias por responder ( THANKS FOR YOUR REPLY )

Yes, but the question is:

What sintax must I use ?....

I tried with:  $context ['group_id'] == '5' ... BUT DON'T WORK...

if (($context['topic_starter_id'] == $context['user']['id'] || $context['user']['is_mod'] || $context ['group_id'] == '5' || $context['user']['is_admin']) && $message['id'] !=


I need the sintax for using that strings.

Some idea ?

Margarett:

Thanks for your reply...

But, I don't know where and what code is... lol
Title: Re: Best Answer
Post by: Avalanche91 on January 10, 2014, 02:55:16 PM
Margarett's solution seems legit and is probably how it should be done. But unfortunately I still haven't read and don't know how to do it like that.

This is how the membergroups usually look like:

mysql> SELECT id_group,group_name FROM smf_membergroups;
+----------+------------------+
| id_group | group_name       |
+----------+------------------+
|        1 | Administrator    |
|        2 | Global Moderator |
|        3 | Moderator        |
|        4 | Newbie           |
|        5 | Jr. Member       |
|        6 | Full Member      |
|        7 | Sr. Member       |
|        8 | Hero Member      |
+----------+------------------+

So what you can do is to hardcode the ID of the group. Something that I do not really recommend. I will be glad if someone helps you do the thing that margarett suggested.
Title: Re: Best Answer
Post by: Arantor on January 10, 2014, 03:01:25 PM
*whistle* http://www.simplemachines.org/community/index.php?topic=345127.0
Title: Re: Best Answer
Post by: diegolyanky on January 10, 2014, 03:05:09 PM
Quote from: Sir Cumber-Patcher on January 10, 2014, 03:01:25 PM
*whistle* http://www.simplemachines.org/community/index.php?topic=345127.0

I have 1.1.19 --- That's for 2.0

Thanks !!

Avalanche91:

I don't know how...

If I find the solution, I'll post it here.

Thanks !!!

Title: Re: Best Answer
Post by: telles0808 on January 17, 2014, 06:07:12 AM
Any chance of get the best answer post and show it on the first position?

Also, would be nice to make a BIG "Best Answer" button on the topic description, like IPB did.

BTW, thank you, this is an amazing mod!
Title: Re: Best Answer
Post by: ScrumpyJack on February 06, 2014, 05:19:37 AM
I was using this mod but it seems to have recently broken.

I've uninstalled it via package manager but it is still leaving the 'Best Answer' button on each topic.

Is there anyway to remove this so that people don't click on it?

I've uninstalling and reinstalling the mod a couple of times but it causes a error in one of the sources files.

The mod itself reports everything as successful when it is installing.

I managed to get rid of that error but now the button takes people through to the Fatal Error screen.

Thanks

Lee
:)
Title: Re: Best Answer
Post by: Avalanche91 on February 06, 2014, 06:38:53 AM
Hello Lee,

I am very sorry to hear that you have some problems with my mod. By the looks of it, there is most probably some sort of conflict between my mod and another one that is already installed. So what has happened is that you have partially removed the mod; the presentation files still contain unnecessary code.

I assume that you are using version 2.X; please note if I am mistaken. In other to fix that you will have to manually modify some of the files. You can find all the changes the mod is performing to your forum in YourSmfFolder/Packages/BestAnswer-v1.4/modification-2.0.xml. The file responsible for displaying the posts is located in YourSmfFolder/Themes/YourCurrentTheme/Display.template.php, so open up both this file and modification-2.0.xml. In the second named file, scroll down to line number 92, and copy the code between the CDATA tags (<![CDATA[COPYME]]>). Then head back to the other file, start searching in the file (CTRL + F in most text redactors) and paste the code. Then look back to the modification file, and check if the code on the next line (that one in the add tags) can still be found in your Display.template.php file. If so, please remove it. Continue the same procedure until the code is all clear.

Should you have any other problems and/or questions, please make sure you tell me. And also, I would like to know what other mod packages you are using, thank you.
Title: Re: Best Answer
Post by: ScrumpyJack on February 06, 2014, 07:32:31 AM
Hi Avalanche,

Thanks...I'll give this a go later this afternoon.

There was an issue with my forum which meant I had to copy over all of the source files from my back-up location.

This is what I think broke the mode.

When I tried to re-install it, I think the error was on line 413, when clicking into a post...so you couldn't actually get to the post if that makes sense.

Due to the copying over of files...I think some of my mods are installed...but the package manager doesn't actually show them as being installed if that makes sense, so it's hard to be sure which ones are all definately installed ok.

The mod mentioned something about a database error...so perhaps it isn't creating the table in MyPHPAdmin correctly?

Is there a way to recreate that?

Thanks

Lee
:)
Title: Re: Best Answer
Post by: Kindred on February 06, 2014, 07:33:52 AM
http://wiki.simplemachines.org/smf/Manually_setting_a_package_installed_or_uninstalled
Title: Re: Best Answer
Post by: Paffman on March 21, 2014, 08:40:46 AM
Hi all,

First off great mod :D

I have just installed it, but when you use it and list the topic, the icon/picture (go_to_best_answer.gif) on the RHS is broken. Have I overlooked something? Where can I find the .gif to put where it should be?

[Edit] I have found where the go_to_best_answer.gif should go and have copied it there, all OK now. Wonder why it didn't install there?

Thanks again.
Title: Re: Best Answer
Post by: littlenicki on April 18, 2014, 07:38:04 PM
Hello, I installed this fine looking mod on my SMF 1.1.19 but it gives me a blank screen when going to messageindex.template.php

Any hints? Thank you!
Title: Re: Best Answer
Post by: margarett on April 19, 2014, 12:14:34 PM
Check your PHP error log (not SMF log) for the cause of this white screen
Title: Re: Best Answer
Post by: Impsat-1 on April 27, 2014, 12:14:14 AM
Ufff!!!... great MOD Avalanche91, Thanks.... I have a SMF 2.0.7 and work fine on default template, thanks again.... :)

Thanks & Regards
Have a Great Time 8).-
Title: Re: Best Answer
Post by: Biology Forums on May 13, 2014, 09:38:19 AM
Is there any way of connecting this mod to the topic solved mod, so that when a post is picked as the best answer, it automatically converts the topic as solved?
Title: Re: Best Answer
Post by: Alex_Ita on May 30, 2014, 10:26:18 AM
I report a little bug:

Every account can be in one group (primary) or two/more groups (secondary)
mod works well on primary group , but the mod doesn't work on the secondary group.

Any suggest?

Best regards
Title: Re: Best Answer
Post by: Skaty on May 31, 2014, 03:18:17 AM
it can be great to show members in simple portal block. best anwerers :)
Title: Re: Best Answer
Post by: user86 on July 21, 2014, 03:06:19 AM
Hello,

thank you for this very good mod! I'm using it on SMF 1.1.19 but expirience a database error. When restoring deleted post from the recycle bin I get this error message:

Quote
Unknown column 'Array' in 'where clause'
File: /var/www/clients/client0/web1/web/smf/Sources/SplitTopics.php
Line: 991

Here is my code from splittopics.php. I have marked the line causing the error in bold.

// We're off to insert the new topic!  Use 0 for now to avoid UNIQUE errors.
db_query("
INSERT INTO {$db_prefix}topics
(ID_BOARD, ID_MEMBER_STARTED, ID_MEMBER_UPDATED, ID_FIRST_MSG, ID_LAST_MSG, numReplies, isSticky)
VALUES ($ID_BOARD, $split2_firstMem, $split2_lastMem, 0, 0, $split2_replies, $isSticky)", __FILE__, __LINE__);
$split2_ID_TOPIC = db_insert_id();
if ($split2_ID_TOPIC <= 0)
fatal_lang_error('smf273');


// If the best answer was amongst these posts that were moved, we have to move the best best answer as well
$query = db_query("SELECT id, id_msg FROM {$db_prefix}best_answer WHERE id_msg IN ($splitMessages)",
__FILE__, __LINE__);
if (mysql_num_rows($query) == 1) {
$data = mysql_fetch_row($query);
if ($data[1] == $splitMessages[0]) {
// The question cannot be an answer!
db_query(
"DELETE FROM {$db_prefix}best_answer WHERE `id`=$data[0]",
__FILE__, __LINE__
);
} else {
// Now that we are moving stuff, it's time for the best answer to be moved
db_query(
"UPDATE {$db_prefix}best_answer SET ID_TOPIC = $split2_ID_TOPIC WHERE id = $data[0]",
__FILE__, __LINE__
);
}
}
mysql_free_result($query);
$data = null;

// Move the messages over to the other topic.
$new_subject = $func['htmlspecialchars']($new_subject);
db_query("
UPDATE {$db_prefix}messages
SET
ID_TOPIC = $split2_ID_TOPIC,
subject = '$new_subject'
WHERE ID_MSG IN ($postList)
LIMIT " . ($split2_replies + 1), __FILE__, __LINE__);



It's this line of code:

$query = db_query("SELECT id, id_msg FROM {$db_prefix}best_answer WHERE id_msg IN ($splitMessages)",
      __FILE__, __LINE__);


The message get restored. But the error pops up.

Can you please suggest what I should change in order to make it work again? Thank you!
Title: Re: Best Answer
Post by: user86 on July 23, 2014, 05:53:06 PM
Bump
Title: Re: Best Answer
Post by: user86 on August 05, 2014, 08:37:00 AM
Also Split Topics is now no longer working ... please kindly help. Thank you!
Title: Re: Best Answer
Post by: user86 on August 08, 2014, 08:40:35 AM
bump
Title: Re: Best Answer
Post by: user86 on August 12, 2014, 02:26:07 PM
bump
Title: Re: Best Answer
Post by: SilverKnight on August 22, 2014, 06:40:23 PM
Great idea for a mod however i believe it needs to have the following support:

Subforums mod
Enable\disable it by forum

This way you can have question\answer forums and it will have multiple forum support.
Title: Re: Best Answer
Post by: user86 on October 11, 2014, 05:14:41 AM
Quote from: user86 on July 21, 2014, 03:06:19 AM
Hello,

thank you for this very good mod! I'm using it on SMF 1.1.19 but expirience a database error. When restoring deleted post from the recycle bin I get this error message:

Quote
Unknown column 'Array' in 'where clause'
File: /var/www/clients/client0/web1/web/smf/Sources/SplitTopics.php
Line: 991

Here is my code from splittopics.php. I have marked the line causing the error in bold.

// We're off to insert the new topic!  Use 0 for now to avoid UNIQUE errors.
db_query("
INSERT INTO {$db_prefix}topics
(ID_BOARD, ID_MEMBER_STARTED, ID_MEMBER_UPDATED, ID_FIRST_MSG, ID_LAST_MSG, numReplies, isSticky)
VALUES ($ID_BOARD, $split2_firstMem, $split2_lastMem, 0, 0, $split2_replies, $isSticky)", __FILE__, __LINE__);
$split2_ID_TOPIC = db_insert_id();
if ($split2_ID_TOPIC <= 0)
fatal_lang_error('smf273');


// If the best answer was amongst these posts that were moved, we have to move the best best answer as well
$query = db_query("SELECT id, id_msg FROM {$db_prefix}best_answer WHERE id_msg IN ($splitMessages)",
__FILE__, __LINE__);
if (mysql_num_rows($query) == 1) {
$data = mysql_fetch_row($query);
if ($data[1] == $splitMessages[0]) {
// The question cannot be an answer!
db_query(
"DELETE FROM {$db_prefix}best_answer WHERE `id`=$data[0]",
__FILE__, __LINE__
);
} else {
// Now that we are moving stuff, it's time for the best answer to be moved
db_query(
"UPDATE {$db_prefix}best_answer SET ID_TOPIC = $split2_ID_TOPIC WHERE id = $data[0]",
__FILE__, __LINE__
);
}
}
mysql_free_result($query);
$data = null;

// Move the messages over to the other topic.
$new_subject = $func['htmlspecialchars']($new_subject);
db_query("
UPDATE {$db_prefix}messages
SET
ID_TOPIC = $split2_ID_TOPIC,
subject = '$new_subject'
WHERE ID_MSG IN ($postList)
LIMIT " . ($split2_replies + 1), __FILE__, __LINE__);



It's this line of code:

$query = db_query("SELECT id, id_msg FROM {$db_prefix}best_answer WHERE id_msg IN ($splitMessages)",
      __FILE__, __LINE__);


The message get restored. But the error pops up.

Can you please suggest what I should change in order to make it work again? Thank you!

Bump Bump Bump
Title: Re: [WIP][MOD]Best Answer
Post by: Rain Forest on October 14, 2014, 10:40:06 AM
Quote from: CHAOS-THEORY on December 15, 2013, 02:51:26 PM
1- Permission to choose specific Boards/Topics to ignor having a bestanswer.

+1
Title: Re: Best Answer
Post by: Mr. Jinx on January 20, 2016, 03:38:52 PM
Thanks for this very nice mod. I just installed it on my forum without problems.
Title: Re: Best Answer
Post by: Mr. Jinx on January 22, 2016, 04:49:36 AM
Question: If a topic is marked as best answer, it shows the users login name instead of the users display name.
Would it be possible to change this?
Title: Re: Best Answer
Post by: Mr. Jinx on February 05, 2016, 04:10:43 AM
Two hotfixes for this fine mod:

Fix 1: Show user's display name instead of login name

$sourcedir/Display.php
Find:
,`ba`.`id`,`ba`.`id_msg`,`ba`.`id_topic`,`ba`.`id_member`,UNIX_TIMESTAMP(`ba`.`time_marked`) AS `time`,`m`.`member_name`
Replace with:
,`ba`.`id`,`ba`.`id_msg`,`ba`.`id_topic`,`ba`.`id_member`,UNIX_TIMESTAMP(`ba`.`time_marked`) AS `time`,`m`.`real_name`

Find:
$context['ba']['member_name'] = $topicinfo['member_name'];
Replace with:
$context['ba']['member_name'] = $topicinfo['real_name'];

Fix 2: Allow Admins,Mods AND GlobalMods to select Best Answer (GlobalMod was not working)

$sourcedir/BestAnswer.php
Find:
if ($context['user']['id'] == $msgInfo['id_member_started'] || ($context['user']['is_mod'] || $context['user']['is_admin'])) {
Replace with:
if ($context['user']['id'] == $msgInfo['id_member_started'] || in_array($user_info['groups'][0], $adminOrModerator)) {

$themedir/Display.template.php
Find:
global $context, $settings, $options, $txt, $scripturl, $modSettings;
Replace with:
global $context, $settings, $options, $txt, $scripturl, $modSettings, $user_info;
$adminOrModerator = array(1, 2, 3); //BestAnswer mod 1=>Admin, 2=>Global Mod, 3=>Mod;


Find:
if (($context['topic_starter_id'] == $context['user']['id'] || $context['user']['is_mod'] || $context['user']['is_admin']) && $message['id'] != $context['topic_first_message'] && $context['isMarkedBest'] == 0) {
Replace with:
if (($context['topic_starter_id'] == $context['user']['id'] || in_array($user_info['groups'][0], $adminOrModerator)) && $message['id'] != $context['topic_first_message'] && $context['isMarkedBest'] == 0) {

Find:
if ($context['ba']['id_msg'] != 0 && $context['ba']['id_msg'] == $message['id'] && ($context['topic_starter_id'] == $context['user']['id'] || $context['user']['is_mod'] || $context['user']['is_admin']) && $message['id'] != $context['topic_first_message'] && $context['isMarkedBest'] == 1) {
Replace with:
if ($context['ba']['id_msg'] != 0 && $context['ba']['id_msg'] == $message['id'] && ($context['topic_starter_id'] == $context['user']['id'] || in_array($user_info['groups'][0], $adminOrModerator)) && $message['id'] != $context['topic_first_message'] && $context['isMarkedBest'] == 1) {
Title: Re: Best Answer
Post by: PLAYBOY on March 02, 2016, 01:41:58 PM
I use Mineral Multicolor theme and I dont have any part of this in my index.template.php


<a href="', $topic['last_post']['href'], '"><img src="', $settings['images_url'], '/icons/last_post.gif" alt="', $txt['last_post'], '" title="', $txt['last_post'], '" /></a>


where should I make the change? Can someone help please?
Title: Re: Best Answer
Post by: PLAYBOY on March 03, 2016, 10:31:53 AM
Can someone please help me on this? I know it hasnt been 24 hours to bump it but it`ll be 24hrs in about 3 hrs :)

I just really need help on this
Title: Re: Best Answer
Post by: margarett on March 03, 2016, 10:45:45 AM
Default theme doesn't have it too. Try MessageIndex.template.php
:P
Title: Re: Best Answer
Post by: PLAYBOY on March 03, 2016, 10:56:26 AM
Got it thank you very much
Title: Re: Best Answer
Post by: PLAYBOY on March 03, 2016, 11:43:11 AM
This mod doesnt show in Mineral_Multicolor theme. I tried everything but it doesnt show the button nor the writings.

It shows in default theme tho
Title: Re: Best Answer
Post by: Kindred on March 03, 2016, 12:10:05 PM
If you didn't do the full theme install, did you remember to copy over all of the images needed for this mod into your custom theme?
Title: Re: Best Answer
Post by: PLAYBOY on March 03, 2016, 12:17:39 PM
Yes, I copied all images and even checked the files for manual modifications. There is one weird problem tho.

Mod is trying to make a code change in messageindex.template.php but the code it`s looking for is actually in display.template.php for my theme. I tried to add the code in both files an still cant see the button or the writing for it.

Also I should mention that it shows fine in Default theme and my forum is in Turkish so there is no language problem there.
If you need I can give any files or codes here

PS: some turkish characters are wrong but I can help on that once I get the mod working for me

Title: Re: Best Answer
Post by: PLAYBOY on March 09, 2016, 08:33:44 PM
This mod desperately needs an update. Spend literally 3 day on this and below is the result

- Icons didnt show
- Turkish characters were in wrong encoding
- When you`re installing it shows that it`s still 1.3 version while it shows 1.4 in the mod list
- None of the moderators could participate (this should be added in the permissions for each group so the person could choose who can participate who cant)
- Didnt create a green bar around the best answer while it gives the best answer notice there
- The edit in index.template.php is actually in  MessageIndex.template.php in my theme

Anyways, I really wish this mod could get a good update/upgrade. I`m willing to help with the Turkish part of it.
It`s sad seeing a great idea being wasted like this
Uninstalled


Is there a similar mod I can use?
Title: Re: Best Answer
Post by: Mr. Jinx on March 12, 2016, 04:35:14 AM
Quote from: PLAYBOY on March 09, 2016, 08:33:44 PM
- None of the moderators could participate (this should be added in the permissions for each group so the person could choose who can participate who cant)

Did you see my comment (Fix 2) (http://www.simplemachines.org/community/index.php?topic=515339.msg3859194#msg3859194)? There was a problem with global mods.

Quote- The edit in index.template.php is actually in  MessageIndex.template.php in my theme
That is weird. You are using SMF 2?
I checked the mod, but doesn't modify index.template.php at all. Maybe you downloaded an old version?

Except the two fixes I mentioned, this mod works great for me.
Title: Re: Best Answer
Post by: PLAYBOY on March 13, 2016, 06:56:26 AM
QuoteDid you see my comment (Fix 2)? There was a problem with global mods.

Yes. I applied it manually but that didn`t fix my problem.

Quoteyou are using SMF 2?

Yes. 2.0.11

QuoteI checked the mod, but doesn't modify index.template.php at all.  Maybe you downloaded an old version?

You`re right. I looked at the manual install for 1.3.

It`d be the best if install Mineral Multicolor theme and check it. Cause I`m pretty sure my issues are valid except the index.template.php thing
Title: Re: Best Answer
Post by: Mr. Jinx on August 21, 2016, 03:20:06 PM
Update: Added extra security to prevent guests from changing answered/unanswered status. If someone started a topic and that member is deleted, all guests could modify the status of that post.

ps: I can't edit my previous post (?) so I'll have to post this modification again completely instead of editting the previous post.

Two hotfixes for this fine mod:

Fix 1:
Show user's display name instead of login name.

$sourcedir/Display.php
Find:
,`ba`.`id`,`ba`.`id_msg`,`ba`.`id_topic`,`ba`.`id_member`,UNIX_TIMESTAMP(`ba`.`time_marked`) AS `time`,`m`.`member_name`
Replace with:
,`ba`.`id`,`ba`.`id_msg`,`ba`.`id_topic`,`ba`.`id_member`,UNIX_TIMESTAMP(`ba`.`time_marked`) AS `time`,`m`.`real_name`

Find:
$context['ba']['member_name'] = $topicinfo['member_name'];
Replace with:
$context['ba']['member_name'] = $topicinfo['real_name'];

Fix 2:
Allow Admins,Mods AND GlobalMods to select Best Answer (GlobalMod was not working).
Disallow guests from changing best answer!

$sourcedir/BestAnswer.php
Find:
if ($context['user']['id'] == $msgInfo['id_member_started'] || ($context['user']['is_mod'] || $context['user']['is_admin'])) {
Replace with:
if ($context['user']['id'] != 0 && ($context['user']['id'] == $msgInfo['id_member_started'] || in_array($user_info['groups'][0], $adminOrModerator))) {

Find:
if (($msgInfo['id_member_started'] == $context['user']['id']) || in_array($user_info['groups'][0], $adminOrModerator)) {
Replace with:
if ($context['user']['id'] != 0 && ($context['user']['id'] == $msgInfo['id_member_started'] || in_array($user_info['groups'][0], $adminOrModerator))) {


$themedir/Display.template.php
Find:
global $context, $settings, $options, $txt, $scripturl, $modSettings;
Replace with:
global $context, $settings, $options, $txt, $scripturl, $modSettings, $user_info;
$adminOrModerator = array(1, 2, 3); //BestAnswer mod 1=>Admin, 2=>Global Mod, 3=>Mod;


Find:
if (($context['topic_starter_id'] == $context['user']['id'] || $context['user']['is_mod'] || $context['user']['is_admin']) && $message['id'] != $context['topic_first_message'] && $context['isMarkedBest'] == 0) {
Replace with:
if (($context['topic_starter_id'] == $context['user']['id'] || in_array($user_info['groups'][0], $adminOrModerator)) && $message['id'] != $context['topic_first_message'] && $context['isMarkedBest'] == 0 && $context['user']['id'] != 0) {

Find:
if ($context['ba']['id_msg'] != 0 && $context['ba']['id_msg'] == $message['id'] && ($context['topic_starter_id'] == $context['user']['id'] || $context['user']['is_mod'] || $context['user']['is_admin']) && $message['id'] != $context['topic_first_message'] && $context['isMarkedBest'] == 1) {
Replace with:
if ($context['ba']['id_msg'] != 0 && $context['ba']['id_msg'] == $message['id'] && ($context['topic_starter_id'] == $context['user']['id'] || in_array($user_info['groups'][0], $adminOrModerator)) && $message['id'] != $context['topic_first_message'] && $context['isMarkedBest'] == 1 && $context['user']['id'] != 0) {
Title: Re: Best Answer
Post by: Adrek on August 21, 2016, 03:58:12 PM

$adminOrModerator = array(1, 2, 3);



in_array($user_info['groups'][0], $adminOrModerator)


is it always going to return false or I'm reading it wrong?
Title: Re: Best Answer
Post by: Arantor on August 21, 2016, 04:29:55 PM
No, not necessarily. It just mandates that the primary group of the current user must be admin, global moderator or board moderator for that to work. Except the last part will never work because group 3 isn't a real group and only gets that setting under very specific circumstances.

Better solution, convert it to an allowedTo() call, maybe allowedTo moderate_board or admin_forum. Or a permission if the mod has one.
Title: Re: Best Answer
Post by: Mr. Jinx on August 22, 2016, 03:18:20 AM
@phantomm: You probably wonder about the (0) part in $user_info['groups'][0]? That would return the primary group number of the member. I'm pretty sure it works nicely.

@Arantor: You are totally right, but this was just a quick change to fix something that wasn't working, without changing the code to much. The correct way would be to add a permission.
Title: Re: Best Answer
Post by: Arantor on August 22, 2016, 08:01:17 AM
Except it might not because the primary group holding 3 for board moderator won't be as correct as often as thought.

Switching it out for moderate_board and admin_forum checks would be more reliable as other groups beyond 1, 2 and sometimes 3 could have relevant permissions.
Title: Re: Best Answer
Post by: slashdc on August 27, 2016, 08:06:31 AM
Hello,

can someone help me to port this great mod to 2.0 RC3. thank you
obviously, I already failed to install it manually (table creation issue, I create the table myself, SSI hook not installed properly, ba.id fields not found, syntax error with character `, part of the code outside the scope of the function after return $output;.... etc.). ;)

Thanks for your time.

Title: Re: Best Answer
Post by: slashdc on August 27, 2016, 12:08:49 PM
I think after a complete manual reinstallation that version 2.0 RC3 doesn't have the necessary function to install the hook...


add_integration_function('integrate_pre_include', '$sourcedir/Subs-BestAnswer.php');
add_integration_function('integrate_actions', 'bestanswer_add_hook');



How to install them with 2.0 RC3?

thanks


Quote from: slashdc on August 27, 2016, 08:06:31 AM
Hello,

can someone help me to port this great mod to 2.0 RC3. thank you
obviously, I already failed to install it manually (table creation issue, I create the table myself, SSI hook not installed properly, ba.id fields not found, syntax error with character `, part of the code outside the scope of the function after return $output;.... etc.). ;)

Thanks for your time.


Title: Re: Best Answer
Post by: slashdc on August 27, 2016, 12:28:57 PM
okay I found how to workaround the hook function installation of Sub-BestAnswer.php by copy all functions into BestAnswer.php...
So if I resume the change:

edit the modifitcation files and remove all  character `, copy all sub functions into BestAnswer.php, install the MOD.
That's it!
Title: Re: Best Answer
Post by: Kindred on August 30, 2016, 08:31:35 AM
you need to UPGRADE ASAP!! !!

Seriously, you are 15 revisions behind.
RC3 has known security issues which have been patched
RC3 has known functional issues which have been patched

Upgrade to 2.0.11 as soon as humanly possible
Title: Re: Best Answer
Post by: slashdc on August 30, 2016, 08:52:21 AM
Quoteyou need to UPGRADE ASAP!! !!

I hesitate reply because it is totally off topic but okay. SO my short reply is:

THANK YOU! but Who cares!

Do you really know if this forum needs to be secure, if it's worth the updates, if the new features of current SMF is needed, no! So this forum contains more needed functionalities than the current SMF final version as it has been heavily modded, all security patches have been evaluated before applied manually to not break the compatibility of current features but YES! its version is still 2.0 RC3. So that's it and sorry for this totally OFF TOPIC notes.
Title: Re: Best Answer
Post by: FredT on May 04, 2022, 03:16:53 AM
Not working in v2.1.1

When I mark an answer as "best answer" it posts an new answers below.
Title: Re: Best Answer
Post by: shadav on May 04, 2022, 03:58:35 AM
Quote from: FredT on May 04, 2022, 03:16:53 AMNot working in v2.1.1

When I mark an answer as "best answer" it posts an new answers below.
Um, this mod isn't made to work with smf 2.1.x
QuoteCOMPATIBLE WITH 1.1.19, 2.0.6
I'm surprised you even got it to install
Title: Re: Best Answer
Post by: FredT on May 06, 2022, 09:07:22 AM
Installation did work as far I remember (deinstalled it again). But it would be so cool to have
Title: Re: Best Answer
Post by: shadav on May 06, 2022, 09:52:34 AM
unless you edited the mod or are not actually using smf 2.1.x it shouldn't have installed or uninstalled per the package-info.xml
Quote<install for="2.0-2.0.99">
Quote<uninstall for="2.0-2.0.99">

it would be nice to see this updated (well rewritten) for smf 2.1.x
but seeing as how the mod author hasn't even been active since 2015 I wouldn't hold my breath
Title: Re: Best Answer
Post by: Doug Heffernan on May 06, 2022, 10:24:27 AM
There is a Best Answer mod compatible with Smf 2.1.x.

https://custom.simplemachines.org/index.php?mod=4274
Title: Re: Best Answer
Post by: shadav on May 06, 2022, 10:31:40 AM
Quote from: Doug Heffernan on May 06, 2022, 10:24:27 AMThere is a Best Answer mod compatible with Smf 2.1.x.

https://custom.simplemachines.org/index.php?mod=4274
oh, well there ya go  :laugh:
I swear I had looked and didn't see one