News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Topic Rating Bar

Started by Bugo, January 05, 2012, 11:13:27 PM

Previous topic - Next topic

vkot

I am using the default theme. I can can do changes myself if I need to, but a hint from you will be very useful. A piece of code, or just some words on where I should start.

Also... has anyone hacked this so that members can change their rating at a later time? (because of a mistake, or because the topic changed quality significantly)
For specialized SMF installation/customization, Web Development, Linux Server Administration, click here.
Για εξειδικευμένες υπηρεσίες στα παραπάνω, πατήστε εδώ.

Simple Site Designs

Quote from: vkot on April 08, 2013, 01:45:58 PM
I am using the default theme. I can can do changes myself if I need to, but a hint from you will be very useful. A piece of code, or just some words on where I should start.

Hi vkot,

part of the changes I made are in the source file MessageIndex.php

I had to replace this:

// We only know these.
if (isset($_REQUEST['sort']) && !in_array($_REQUEST['sort'], array('subject', 'starter', 'last_poster', 'replies', 'views', 'first_post')))
$_REQUEST['sort'] = 'last_post';


With this (to make rating an accepted sort field):

// We only know these.
if (isset($_REQUEST['sort']) && !in_array($_REQUEST['sort'], array('subject', 'starter', 'last_poster', 'replies', 'views', 'first_post', 'last_post', 'rating')))
$_REQUEST['sort'] = 'last_post';


I also had to edit the actual query to include a sort by rating.

Find this:

// Sequential pages are often not optimized, so we add an additional query.
$pre_query = $start > 0;
if ($pre_query && $maxindex > 0)
{

$request = $smcFunc['db_query']('', '
SELECT t.id_topic
FROM {db_prefix}topics AS t' . ($context['sort_by'] === 'last_poster' ? '
INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)' : (in_array($context['sort_by'], array('starter', 'subject')) ? '
INNER JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg)' : '')) . ($context['sort_by'] === 'starter' ? '
LEFT JOIN {db_prefix}members AS memf ON (memf.id_member = mf.id_member)' : '') . ($context['sort_by'] === 'last_poster' ? '
LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member)' : '') . '
WHERE t.id_board = {int:current_board}' . (!$modSettings['postmod_active'] || $context['can_approve_posts'] ? '' : '
AND (t.approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR t.id_member_started = {int:current_member}') . ')') . '
ORDER BY ' . (!empty($modSettings['enableStickyTopics']) ? 'is_sticky' . ($fake_ascending ? '' : ' DESC') . ', ' : '') . $_REQUEST['sort'] . ($ascending ? '' : ' DESC') . '
LIMIT {int:start}, {int:maxindex}',
array(
'current_board' => $board,
'current_member' => $user_info['id'],
'is_approved' => 1,
'id_member_guest' => 0,
'start' => $start,
'maxindex' => $maxindex,
)
);
$topic_ids = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$topic_ids[] = $row['id_topic'];
}



And replace with this:

// Sequential pages are often not optimized, so we add an additional query.
$pre_query = $start > 0;
if ($pre_query && $maxindex > 0)
{

$request = $smcFunc['db_query']('', '
SELECT t.id_topic
FROM {db_prefix}topics AS t' . ($context['sort_by'] === 'last_poster' ? '
INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)' : (in_array($context['sort_by'], array('starter', 'subject')) ? '
INNER JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg)' : '')) . ($context['sort_by'] === 'starter' ? '
LEFT JOIN {db_prefix}members AS memf ON (memf.id_member = mf.id_member)' : '') . ($context['sort_by'] === 'last_poster' ? '
LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member)' : '') . ($context['sort_by'] === 'rating' ? '
LEFT JOIN {db_prefix}topic_ratings AS r ON (r.id = t.id_topic)' : '') . '
WHERE t.id_board = {int:current_board}' . (!$modSettings['postmod_active'] || $context['can_approve_posts'] ? '' : '
AND (t.approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR t.id_member_started = {int:current_member}') . ')') . '
ORDER BY ' . (!empty($modSettings['enableStickyTopics']) ? 'is_sticky' . ($fake_ascending ? '' : ' DESC') . ', ' : '') . $_REQUEST['sort'] . ($ascending ? '' : ' DESC') . '
LIMIT {int:start}, {int:maxindex}',
array(
'current_board' => $board,
'current_member' => $user_info['id'],
'is_approved' => 1,
'id_member_guest' => 0,
'start' => $start,
'maxindex' => $maxindex,
)
);
$topic_ids = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$topic_ids[] = $row['id_topic'];
}


You just need to somehow add the sort to the column then, and that change will need to be in your default theme MessageIndex.template.php file.

Cheers,
Josh

Edit: You will also need to alter the second query (just below the comment "// For search engine effectiveness we'll link guests differently." to include the rating table for sorting. But I reckon you can work it out, it's basically the same change as above.

deadhero

#122
I get this error on error logs:

http://etkinforum.com/index.php?/index.php?action=seo4smf;u=aHR0cDovL2ZyZWFrc2hhcmUuY29tL2ZpbGVzL2xzNHIzdnd1L1RVUDIwMTIuMTIuMC4zNTAwLjE0LkZOTC5yYXIuaHRtbA==8: Undefined index: num_repliesDosya: /home/etkinforum.com/httpdocs/Themes/default/TopicRating.template.php (main sub template - eval?)


http://etkinforum.com/index.php?http://etkinforum.com/8: Undefined index: num_repliesDosya: /home/etkinforum.com/httpdocs/Themes/default/TopicRating.template.php (main sub template - eval?)
Satır: 433


http://etkinforum.com/index.php?8: Undefined index: num_repliesDosya: /home/etkinforum.com/httpdocs/Themes/default/TopicRating.template.php (main sub template - eval?)
Satır: 433


http://etkinforum.com/index.php?8: Undefined index: viewer_textDosya: /home/etkinforum.com/httpdocs/Themes/default/TopicRating.template.php (main sub template - eval?)
Satır: 170

JerryGraf

I installed  http://custom.simplemachines.org/mods/index.php?mod=3236 (which I believe is still state of the art). I'm running 2.0.4, and can see no sign of the mod, either on the board itself or in the admin console. The instructions I used to install are these:

Move the included directory "default/css" to "./Themes/default".
Move the included directory "default/images" to "./Themes/default".
Move the included directory "default/languages" to "./Themes/default".
Move the included directory "default/scripts" to "./Themes/default".
Move the included file "default/TopicRating.template.php" to "./Themes/default".
Move the included file "core/Subs-TopicRating.php" to "./Sources".


Did I miss something?

Thanks,

George

Arantor

Yes you did.

As per http://custom.simplemachines.org/mods/index.php?action=parse;mod=3236;attach=209740;smf_version=2.0.4 you need to execute both database.php and hooks.php to do post-install configuration for the mod. Which is generally why mods should be unpacked from the package manager wherever possible because it will do that for you.

Also please note that there are two security patches since 2.0.4 to be installed.

JerryGraf

Thanks so much for the reply. Can you advise what's required to "execute" these files? Many thanks!

Arantor

I don't see why you need to be doing any of this manually when the SMF Package Manager (more: Package Manager) will do it for you in the first place...

Failing that, unpack the files from the zip archive, upload them to your forum where SSI.php is then visit them in your browser.

JerryGraf

Many thanks. I just started with this and was not aware of the package manager.

Thanks again for the quick replies.

Alpay

Quote from: Simple Site Designs on April 16, 2013, 01:52:11 AM
Quote from: vkot on April 08, 2013, 01:45:58 PM
I am using the default theme. I can can do changes myself if I need to, but a hint from you will be very useful. A piece of code, or just some words on where I should start.

Hi vkot,

part of the changes I made are in the source file MessageIndex.php

I had to replace this:

// We only know these.
if (isset($_REQUEST['sort']) && !in_array($_REQUEST['sort'], array('subject', 'starter', 'last_poster', 'replies', 'views', 'first_post')))
$_REQUEST['sort'] = 'last_post';


With this (to make rating an accepted sort field):

// We only know these.
if (isset($_REQUEST['sort']) && !in_array($_REQUEST['sort'], array('subject', 'starter', 'last_poster', 'replies', 'views', 'first_post', 'last_post', 'rating')))
$_REQUEST['sort'] = 'last_post';


I also had to edit the actual query to include a sort by rating.

Find this:

// Sequential pages are often not optimized, so we add an additional query.
$pre_query = $start > 0;
if ($pre_query && $maxindex > 0)
{

$request = $smcFunc['db_query']('', '
SELECT t.id_topic
FROM {db_prefix}topics AS t' . ($context['sort_by'] === 'last_poster' ? '
INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)' : (in_array($context['sort_by'], array('starter', 'subject')) ? '
INNER JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg)' : '')) . ($context['sort_by'] === 'starter' ? '
LEFT JOIN {db_prefix}members AS memf ON (memf.id_member = mf.id_member)' : '') . ($context['sort_by'] === 'last_poster' ? '
LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member)' : '') . '
WHERE t.id_board = {int:current_board}' . (!$modSettings['postmod_active'] || $context['can_approve_posts'] ? '' : '
AND (t.approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR t.id_member_started = {int:current_member}') . ')') . '
ORDER BY ' . (!empty($modSettings['enableStickyTopics']) ? 'is_sticky' . ($fake_ascending ? '' : ' DESC') . ', ' : '') . $_REQUEST['sort'] . ($ascending ? '' : ' DESC') . '
LIMIT {int:start}, {int:maxindex}',
array(
'current_board' => $board,
'current_member' => $user_info['id'],
'is_approved' => 1,
'id_member_guest' => 0,
'start' => $start,
'maxindex' => $maxindex,
)
);
$topic_ids = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$topic_ids[] = $row['id_topic'];
}



And replace with this:

// Sequential pages are often not optimized, so we add an additional query.
$pre_query = $start > 0;
if ($pre_query && $maxindex > 0)
{

$request = $smcFunc['db_query']('', '
SELECT t.id_topic
FROM {db_prefix}topics AS t' . ($context['sort_by'] === 'last_poster' ? '
INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)' : (in_array($context['sort_by'], array('starter', 'subject')) ? '
INNER JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg)' : '')) . ($context['sort_by'] === 'starter' ? '
LEFT JOIN {db_prefix}members AS memf ON (memf.id_member = mf.id_member)' : '') . ($context['sort_by'] === 'last_poster' ? '
LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member)' : '') . ($context['sort_by'] === 'rating' ? '
LEFT JOIN {db_prefix}topic_ratings AS r ON (r.id = t.id_topic)' : '') . '
WHERE t.id_board = {int:current_board}' . (!$modSettings['postmod_active'] || $context['can_approve_posts'] ? '' : '
AND (t.approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR t.id_member_started = {int:current_member}') . ')') . '
ORDER BY ' . (!empty($modSettings['enableStickyTopics']) ? 'is_sticky' . ($fake_ascending ? '' : ' DESC') . ', ' : '') . $_REQUEST['sort'] . ($ascending ? '' : ' DESC') . '
LIMIT {int:start}, {int:maxindex}',
array(
'current_board' => $board,
'current_member' => $user_info['id'],
'is_approved' => 1,
'id_member_guest' => 0,
'start' => $start,
'maxindex' => $maxindex,
)
);
$topic_ids = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$topic_ids[] = $row['id_topic'];
}


You just need to somehow add the sort to the column then, and that change will need to be in your default theme MessageIndex.template.php file.

Cheers,
Josh

Edit: You will also need to alter the second query (just below the comment "// For search engine effectiveness we'll link guests differently." to include the rating table for sorting. But I reckon you can work it out, it's basically the same change as above.

Hello ;

messages.index.template ;

add ?

<th class="t"><a href="', $scripturl, '?board=', $context['current_board'], '.', $context['start'], ';sort=rating', $context['sort_by'] == 'rating' && $context['sort_direction'] == 'up' ? ';desc' : '', '">', $txt['rating'], $context['sort_by'] == 'rating' ? ' <img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.gif" alt="" />' : '', '</a></th>


did not ?

MaccabeeY

Bugo,

Very nice mod!!! Good work.

Have I have identified bugs that generate Log Errors.  If seems to be centered around "permissions".

The main error generated is:

--
http://forum.myplace.com/index.php?/topic,4.0.html [nofollow]
8: Undefined index: message
File: /home/.../forum/Themes/default/TopicRating.template.php (main sub template - eval?)
Line: 82
--

The bug is "serious" in the sense that it seems to generates Log Errors under at least two conditions:
1) EVERY time any ADMINISTATOR reads ANY post, this "floods" the error log
and
2) EVERY time the author of a post reads his own post

These errors appear to be generated regardless of how permissions are configured.  I investigated for a bit and it looks like the bug may be centered around the use or testing of the "$context['proper_user']" value.

To avoid flooding the Error Log, for now I will turn off "Top Ratings Bar".  I look forward to the solution.
Thx,
Edward

cwl

Quote from: Ascot on February 04, 2012, 01:18:08 PM
Hi there, i've install this mod... but nothing seems to happen D:
i mean, there isn't stars at topics, neither inside them.
Is there something i forgot to do?

I have the same issue. androiderrors com - latest version of smf. after installing topic rating bar, nothing happens. Installation was successful. The description column was blank on the install screen. Any ideas?

Shadight

Quote from: pixeleyes on March 28, 2012, 11:53:50 AM
User can do rating.

But mini stars doesn't show on post category during logged-in session.

Only appears when log out.

Any idea how to fix this problem?

Hello, as pixeleys, i have this same problem.

I work on local forum. At first, i was believe that maybe this mod has some conflict with other mod.
I have started a new clean installation and i have the same problem. The mini-stars doesn't show on post category during logged-in session.

For information, i use this theme (in defauts theme no problem to see mini stars but when i'm logged in with fumes, i can't see them).

http://custom.simplemachines.org/themes/index.php?lemma=2697

(sorry for my english)

Thank you for any help

Ian Mc

I know this is a very old thread, but I wondered if anyone found or made the code to put the most popular topics into a Simple Portal box?

This mod is exactly what I need but I need that bit of code!! I saw a few people asking for it earlier in the thread so I'm hoping someone sorted it !!

OCJ

You should ask over at simple portal. Some people there will do it as custom coding... they might ask for a fee if its a personal customization request.

Ian Mc

Quote from: igirisjin on April 07, 2016, 01:07:03 PM
You should ask over at simple portal. Some people there will do it as custom coding... they might ask for a fee if its a personal customization request.
That's a very good suggestion. I'll give them a try.

Biology Forums

On this line:

if (!empty($context['current_topic']) && empty($context['current_action']) && empty($board_info['error']) && empty(strpos($_SERVER['REQUEST_URI'], ';')))

I'm getting the error:

PHP Fatal error:  Can't use function return value in write context in /home/***/public_html/Sources/Class-TopicRating.php on line 117

Presumably because of this part: empty(strpos($_SERVER['REQUEST_URI'], ';'))

because when I remove it, it works. What's wrong?


Arantor

Well, you're stuck on PHP below 5.5 where this syntax became legal.

I guess you could probably rewrite it as:
if (!empty($context['current_topic']) && empty($context['current_action']) && empty($board_info['error']) && strpos($_SERVER['REQUEST_URI'], ';') === false)

but I wouldn't want to encourage you to stay on a version of PHP with known vulnerabilities.

Biology Forums

I didn't know this was designed for >5.5.

I decided to uninstall it since it doesn't have built-in guest voting. I do realize guest voting potentially leads to spam, but it does engage a larger population of visitors. Has guest posting been implemented by anyone anyway?

Arantor

I wouldn't say "designed for > 5.5" but a by product of the author's level of PHP knowledge at the time it was written.

SMF can do guest posting out of the box but it leads to spam and no one has really nailed a good way to deal with that (2.0 let's you expose all the CAPTCHA stuff including plugins to guest posting, but almost everyone I know pushes for registration instead)

Biology Forums

I was referring to the rating permission for this mod, there isn't the option to allow guest rating :(

Advertisement: