Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Topic started by: Nathaniel on August 26, 2008, 07:52:41 PM

Title: Topic Summary
Post by: Nathaniel on August 26, 2008, 07:52:41 PM
Link to Mod (http://custom.simplemachines.org/mods/index.php?mod=1350)

Topic Summary Mod 1.3.1 by Nathaniel
Overview
This mod adds a "Topic Summary" column to the MessageIndex. The page where you view a list of topics for a particular board. It allows your users to get a better idea of what the topic is about before they view the actual topic itself. It basically takes the first x characters from the last or first post of a topic, strips any HTML, whitespace, newlines or BBC, and then displays it.

Settings are found in the Admin panel:
For SMF 1.1.x: "Features and Options" -> "Layout and Options".
For SMF 2: "Configuration" -> "Features and Options" -> "Layout".

Setting Explanations:
SMF Version Support
This mod is officially supported for SMF 2.0 and above only. Below is a list of available versions of this mod and the previous versions of SMF that they supported. Use them at your own risk. The mod author will not be supporting or upgrading this mod in any way for versions of SMF below 2.0.

Version 1.02:  SMF 1.1.x and SMF 2 RC2 or below.
Version 1.3.1: SMF 2 RC4 and above.

Donate
If this mod has helped you, then feel free to support the developer by Donating (https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=VCFQ7MJNVXLLA&lc=AU&item_name=Donation&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted). Any amount of money is welcome.

Themes/Templates
This mod only edits a single template file - MessageIndex.template.php - which is only used in a few Custom Themes. If your custom theme doesn't contain this file then it should work automatically. Otherwise you can use the 'Manual Install Instructions for SMF' function above to get a list of edits that you will need to make to your custom themes 'MessageIndex.template.php' for your relevant SMF version.

If you need any help with edits for custom themes, then you can ask for it in the support topic for this mod (http://www.simplemachines.org/community/index.php?topic=257942), remember that you will have to post the 'MessageIndex.template.php' file from your custom theme, otherwise I will not be able to perform the edits.

Version Changes
v1.3 - 5 November 2010
Updated for SMF 2 RC4.

v1.02 - 20 November 2009
Updated for SMF 2 RC2.

v1.01 - 15 September 2008
Updated for SMF 1.1.6 and SMF 2 Beta.

v1.0 - 24 August 2008
Original Mod release.
Title: Re: Topic Summary
Post by: K3TK3TK3T on August 26, 2008, 08:27:51 PM
screenie/demo please?
Title: Re: Topic Summary
Post by: Nathaniel on August 26, 2008, 08:34:37 PM
Download page is now updated to include a screenshot.

I will try to add a little tutorial that shows you how to do the template edits for custom themes, sometime today. ;)
Title: Re: Topic Summary
Post by: jossanaijr on August 27, 2008, 11:56:49 AM
Great idea.
Title: Re: Topic Summary
Post by: SA™ on August 28, 2008, 01:19:32 AM
yes grat mod thank you just what im looking for
Title: Re: Topic Summary
Post by: Nathaniel on August 28, 2008, 04:39:29 AM
I am glad that you guys like it. :D

Actually it was ccbtimewiz's idea, I just made it. ;)

I have updated the Mod download page so that it includes instructions for manual edits to custom themes. ;)
Title: Re: Topic Summary
Post by: Nathaniel on September 15, 2008, 03:01:25 AM
Version 1.01:
Updated for SMF 1.1.6 and SMF 2 Beta.
Title: Re: Topic Summary
Post by: Hoochie Coochie Man on October 16, 2008, 08:14:32 AM
Thanks for this beautiful mod.

I want to show only first post's summary, not reply's summary.

Can you do that please?

another question:
Can you make this code with work in index.template.php too

Code: [Select]
', $topic[!empty($modSettings['TopicSummary_message']) ? $modSettings['TopicSummary_message'] : 'last_post']['summary'], '
Thanks.
Title: Re: Topic Summary
Post by: Hoochie Coochie Man on October 17, 2008, 08:41:43 AM
Bump This is important.
Please..  :-[
Title: Re: Topic Summary
Post by: Nathaniel on October 17, 2008, 09:08:37 AM
Ah, sorry I didn't notice this *erhan. ;)

1) You should already be able to choose if the last or first post is used for the summary, there is a setting for it. The setting locations are in the first post of this topic.
2) That should be possible, are you referring to the 'Last post' part for each board?
Title: Re: Topic Summary
Post by: Hoochie Coochie Man on October 17, 2008, 09:12:35 AM
Ah, sorry I didn't notice this *erhan. ;)

1) You should already be able to choose if the last or first post is used for the summary, there is a setting for it. The setting locations are in the first post of this topic.

Ohh sorry, I will look.

2) That should be possible, are you referring to the 'Last post' part for each board?

nope, first post of the topic, as I said above.

and thanks for your reply.
Title: Re: Topic Summary
Post by: Nathaniel on October 17, 2008, 09:15:08 AM
2) That should be possible, are you referring to the 'Last post' part for each board?

nope, first post of the topic, as I said above.

and thanks for your reply.

So which topics/posts do you want to be summarized? And in which exact areas?
Title: Re: Topic Summary
Post by: Hoochie Coochie Man on October 17, 2008, 09:25:36 AM
LHVWB

Actually, I was trying something.

Your mod is awesome, but I'm trying to put that topics' descriptions to meta area

I mean this area:

<meta name="description" content="THIS AREA" />

So, Topics descriptions will looks great on google or yahoo search results.

What do you think?  :-\
Title: Re: Topic Summary
Post by: Nathaniel on October 17, 2008, 08:45:44 PM
@*erhan,
Hmm, I'm not sure about that. I haven't really worked with meta description tags at all, which page are you referring to? The MessageIndex or Topic Display pages?
Title: Re: Topic Summary
Post by: Hoochie Coochie Man on October 18, 2008, 04:21:44 AM
Topic Display pages  :-\
Title: Re: Topic Summary
Post by: Nathaniel on October 18, 2008, 05:36:19 AM
It should be fairly easy to do, you will have to add a database query to the Display.php file to get the body of the first post, and then you can run it through the 'generate_summary' function which is added by this mod. I have make up some code for that, although I can't really do the database query unless I know which version of SMF you have.
Title: Re: Topic Summary
Post by: Hoochie Coochie Man on October 18, 2008, 05:39:30 AM
I'm using 1.1.6

This is very cool and important for SMF I think.
If you make this as a mod, I know a lot of people love it.
Title: Re: Topic Summary
Post by: Nathaniel on October 18, 2008, 05:48:22 AM
I'm using 1.1.6

This is very cool and important for SMF I think.
If you make this as a mod, I know a lot of people love it.

I could make it into a mod (and it would have to be a separate mod), although the mod below sort of already does this by showing a description for the 'Message Display'.
http://custom.simplemachines.org/mods/index.php?mod=1138

You might prefer an option that is more specific to producing good meta data. ;)

I can still create that code if you want, although I probably won't make it into a mod, because the mod above already does this.
Title: Re: Topic Summary
Post by: Hoochie Coochie Man on October 18, 2008, 06:57:15 AM
I can still create that code if you want, although I probably won't make it into a mod, because the mod above already does this.

Wow, that's right :D
But it's Compatible With: 2.0 Beta 3 Public  :(  :'(

Edit: ohh wait, I think i found
http://www.simplemachines.org/community/index.php?topic=230321.msg1557714#msg1557714

Edit2: Thank you very much dude :D I installed it, and works great. Thank you :)
Title: Re: Topic Summary
Post by: zaarin on October 22, 2008, 07:02:04 AM
Disclaimer: I'm new to both SMF and PHP in general.  O:)

This seems like exactly what I want to achieve as an SSI as part of SSI.php. Can this mod be used in this manner?

Basically, I've got a static, not part of SMF,  index page (site homepage), that uses various SSI calls to display the latest posts, newest member and so on.

What I would like is for the "ssi_recentTopics" and "ssi_topTopicsViews" functions to be able to display a summary of the topic in addition to the title.

If this is possible, could I please get some instructions, suitable for a beginner, on how to implement it?

Thank you very much.
Title: Re: Topic Summary
Post by: Nathaniel on October 22, 2008, 04:26:31 PM
That should be fairly easy. The main thing that you need to do, is to use the 'generate_summary($text)' function that is provided by this mod, to generate a summary of some text when you need to.

The edits below are to your 'SSI.php' file.

For the 'ssi_recentTopics' function. Find the code below:
Code: [Select]
      $row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']), array('<br />' => '')));
      if ($func['strlen']($row['body']) > 128)
         $row['body'] = $func['substr']($row['body'], 0, 128) . '...';

Replace with this code:
Code: [Select]
    $row['body'] = generate_summary($row['body']);
Then at the end of that SSI.php function, there is some html code. You will have to add the '$post['time']' php variable into that code. I can help you with that if you specify exactly where you want it.

Getting the 'ssi_topTopicsViews' to work will be harder, because it uses another SSI.php function and it doesn't load the body of the topic, I can still have a go at that if you want?
Title: Re: Topic Summary
Post by: zaarin on October 28, 2008, 03:55:15 AM
Hi LHVWB,

Thanks for your help with this. Sorry for the late reply, my wife just had a baby earlier in the week.

I've replaced the 3 lines, with the new line you said.

With regard to the $post['time'] php variable. It outputs the time the post was made. Do I need to modify something else, or call a different variable, to get the summary?

My HTML output (topic_summary, doesn't appear to output anything):
Code: [Select]
if ($output_method != 'echo' || empty($posts))
return $posts;

echo '
<ul>';
foreach ($posts as $post)
echo '
<li>
<h3><a href="', $post['href'], '">', $post['subject'], '</a></h3>
<p>', $post['topic_summary'], $post['time'], '</p>
</li>';
echo '
</ul>';
}

Thanks again for your help.

Edit: Oh, and yes, if you have the time, I would love to get ssi_topTopicsViews working as well. Thanks.
Title: Re: Topic Summary
Post by: Nathaniel on October 28, 2008, 06:24:16 AM
Congratulations on the new child. :)

I apologise, I made a mistake when I wrote that post. You need to use the '$post['preview']' variable instead. ;)

For editing the 'ssi_topTopicsReplies' function. That function is based off the 'ssi_topTopics' function, so you will have to perform edits to the 'ssi_topTopics' function and then those changes will happen for the output from the 'ssi_topTopicsReplies' function as well.

Find this code (from that function):
Code: [Select]
SELECT m.subject, m.id_topic, t.num_views, t.num_repliesReplace with this code:
Code: [Select]
SELECT m.subject, m.id_topic, m.body, t.num_views, t.num_replies
Find this code:
Code: [Select]
        $topics[] = array(
            'id' => $row['id_topic'],
Replace with this code:
Code: [Select]
        $row['body'] = generate_summary($row['body']);
   
        $topics[] = array(
            'id' => $row['id_topic'],
            'preview' => $row['body'],

Find this code:
Code: [Select]
                <td align="right">', $topic['num_views'], '</td>
                <td align="right">', $topic['num_replies'], '</td>
Replace with this code:
Code: [Select]
                <td align="right">', $topic['num_views'], '</td>
                <td align="right">', $topic['num_replies'], '</td>
                <td align="right">', $topic['preview'], '</td>

As with the 'ssi_recentTopics' function, the last edit may be different depending on how you want the HTML output to look. :)
Title: Re: Topic Summary
Post by: zaarin on October 29, 2008, 06:56:31 AM
Perfect. Thanks very much for your help.
Title: Re: Topic Summary
Post by: Nathaniel on December 21, 2008, 03:13:00 AM
Tested Compatibility with SMF 1.1.7, the mod page has been updated accordingly.
Title: Re: Topic Summary
Post by: cleanfiles on December 21, 2008, 08:47:31 PM
Hey great mod, and works for me on 1.1.7 default theme.

I am using this mod "Look But No Read" (http://custom.simplemachines.org/mods/index.php?mod=1332) So guests can see the boards and posts but not read the posts
I was wondering if it would be possible to turn the summery off for guests as it can giv to much of the post away lol?
Title: Re: Topic Summary
Post by: Nathaniel on December 22, 2008, 03:39:58 AM
@cleanfiles,
The edits below (to your 'MessageIndex.template.php' file) assume that the mod has been installed normally.

Find this code:
Code: [Select]
<td class="windowbg2" valign="middle" ', (!empty($modSettings['TopicSummary_column_width']) ? 'width="'.$modSettings['TopicSummary_column_width'].'"' : ''), '>
', $topic[!empty($modSettings['TopicSummary_message']) ? $modSettings['TopicSummary_message'] : 'last_post']['summary'], '
</td>
<td class="windowbg2" valign="middle" width="14%">
', $topic['first_post']['member']['link'], '
</td>

Replace with this code:
Code: [Select]
', !empty($context['user']['is_guest']) ? '' : '<td class="windowbg2" valign="middle" ' . (!empty($modSettings['TopicSummary_column_width']) ? 'width="'.$modSettings['TopicSummary_column_width'].'"' : '') . '>
', $topic[!empty($modSettings['TopicSummary_message']) ? $modSettings['TopicSummary_message'] : 'last_post']['summary'], '
</td>', '
<td class="windowbg2" valign="middle" width="14%">
', $topic['first_post']['member']['link'], '
</td>

Find this code:
Code: [Select]
<td class="catbg3"><a href="', $scripturl, '?board=', $context['current_board'], '.', $context['start'], ';sort=subject', $context['sort_by'] == 'subject' && $context['sort_direction'] == 'up' ? ';desc' : '', '">', $txt[70], $context['sort_by'] == 'subject' ? ' <img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.gif" alt="" />' : '', '</a></td>

<td class="catbg3" ', (!empty($modSettings['TopicSummary_column_width']) ? 'width="'.$modSettings['TopicSummary_column_width'].'"' : ''), '>', $txt[468], '</td>

Replace with this code:
Code: [Select]
<td class="catbg3"><a href="', $scripturl, '?board=', $context['current_board'], '.', $context['start'], ';sort=subject', $context['sort_by'] == 'subject' && $context['sort_direction'] == 'up' ? ';desc' : '', '">', $txt[70], $context['sort_by'] == 'subject' ? ' <img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.gif" alt="" />' : '', '</a></td>

', !empty($context['user']['is_guest']) ? '' : '<td class="catbg3" ' . (!empty($modSettings['TopicSummary_column_width']) ? 'width="'.$modSettings['TopicSummary_column_width'].'"' : '') . '>' . $txt[468] . '</td>', '
Title: Re: Topic Summary
Post by: cleanfiles on December 22, 2008, 04:42:54 AM
I will give that a go, thanks :)
Title: Re: Topic Summary
Post by: Uhura! on April 20, 2009, 03:06:55 PM
This mod is AWESOME!
Title: Re: Topic Summary
Post by: Nathaniel on November 19, 2009, 06:01:44 PM
v1.02 - 20 November 2009
Updated for SMF 2 RC2.
Title: Re: Topic Summary
Post by: Tiribulus on November 20, 2009, 03:42:33 PM
This is pretty spiffy dude. I don't know how I missed this one. Had to do the editing for the MessageIndex.template.php for my theme and one for the modsettings file, but works great
Title: Re: Topic Summary
Post by: jack3d on January 13, 2010, 02:39:16 AM
For some reason, I'm having trouble uninstalling this? I personally love it but a few people complained about how it posted spoilers and majority opted for it to be removed lol.

When I view my packages summary, it is not there. When I view my installed packages, it is there but when I click uninstall, it says that it cannot locate the package file.

Any help would be rockin'.

ETA: Internet cut out haha. The 'installed' version, with the missing file, is 1.01.
Title: Re: Topic Summary
Post by: jack3d on January 18, 2010, 12:31:54 AM
I understand that it's very rude for me to ask... and ask again... but any help would be greatly appreciated.  :)
Title: Re: Topic Summary
Post by: GoldieFR on April 22, 2010, 01:02:48 PM
great mod, thanks !  8)
Title: Re: Topic Summary
Post by: Nathaniel on November 06, 2010, 08:43:56 AM
v1.3 - 5 November 2010
Updated for SMF 2 RC4.
Title: Re: Topic Summary
Post by: Joomlamz on November 07, 2010, 02:04:26 AM
Portuguese Update

Title: Re: Topic Summary
Post by: helike13 on April 15, 2011, 03:24:53 PM
It would be better idea to add a description under the topic name to make them look like child forums.
Title: Re: Topic Summary
Post by: danialasghar on June 06, 2011, 08:39:43 PM
Can i use this mod in Smf 2.0 RC5?
Title: Re: Topic Summary
Post by: live627 on June 06, 2011, 09:32:49 PM
You can certainly give it a try.
Title: Re: Topic Summary
Post by: Nathaniel on June 16, 2011, 02:11:43 AM
Updated to include the portuguese translation. Thanks Joomlamz, apologies I didn't notice it ages ago, lol. :/

Can i use this mod in Smf 2.0 RC5?

I believe so, it certainly works in SMF 2.0 final.
Title: Re: Topic Summary
Post by: Lolafish on October 06, 2011, 08:00:37 PM
I've had this installed for a while now and I love it!  The only things is, I've been unable to adjust the column width. I've tried everything.  Is there an exact wording that it's looking for here?

Features & Options/Column Width (Must Be in Pixels 'px' or Percent '%')

For example, if I want to use 20 pixels, how exactly do I write that so that it's understood? 
Title: Re: Topic Summary
Post by: Lolafish on October 06, 2011, 08:05:39 PM
I've had this installed for a while now and I love it!  The only things is, I've been unable to adjust the column width. I've tried everything.  Is there an exact wording that it's looking for here?

Features & Options/Column Width (Must Be in Pixels 'px' or Percent '%')

For example, if I want to use 20 pixels, how exactly do I write that so that it's understood? 

I can get the percent to work, just not the pixels.
Title: Re: Topic Summary
Post by: RGMears on June 28, 2020, 08:41:01 AM
I realize this is an old thread, however, I am having trouble with a bit of code from this modification in the Subs.php file after upgrading to SMF 2.0.17.
In the error log I keep getting this:

preg_replace_callback(): Requires argument 2, 'preg_replace_callback('/(.{20})/u', '\$1< >', '$1')', to be a valid callback ... Line: 5027

Code: [Select]
if ($smcFunc['strlen']($message) > $modSettings['TopicSummary_maxwordlength'])
{
// This is done in a roundabout way because $breaker has "long words" :P.
$message = strtr($message, array($breaker => '< >', '&nbsp;' => $context['utf8'] ? "\xC2\xA0" : "\xA0"));
$message = preg_replace_callback('~(?<=[>;:!? ' . $non_breaking_space . '\]()]|^)([\w' . ($context['utf8'] ? '\pL' : '') . '\.]{' . ($modSettings['TopicSummary_maxwordlength'] + 1) . ',})~e' . ($context['utf8'] ? 'u' : ''),
'preg_replace_callback(\'/(.{' . ($modSettings['TopicSummary_maxwordlength']) . '})/' . ($context['utf8'] ? 'u' : '') . '\', \'\\$1< >\', \'$1\')', $message);
$message = strtr($message, array('< >' => $breaker, $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
}

The line in question is this one:
Code: [Select]
'preg_replace_callback(\'/(.{' . ($modSettings['TopicSummary_maxwordlength']) . '})/' . ($context['utf8'] ? 'u' : '') . '\', \'\\$1< >\', \'$1\')', $message);
Any help is appreciated.