Ignored users: hiding posts on Recent.template.php

Started by Antechinus, September 16, 2019, 09:27:40 PM

Previous topic - Next topic

Antechinus

Just wondering how difficult it would be to transfer the logic/conditionals from Display.template.php to Recent.template.php, so that posts by really irritating mongrels that you are trying to ignore would have their content hidden on both templates. I'm thinking of action=recent, not the unread and/or new replies functions.

I know I can swap the javascript over and add the required id's to whatever post elements on Recent. That should be straightforward. I'm just wondering if Recent can access the ignored logic that Display uses:

// Are we ignoring this message?
if (!empty($message['is_ignored']))
{
$ignoring = true;
$ignoredMsgs[] = $message['id'];
}


Can this be done just in the template? Or is it going to need a Sources hack as well?
Sources code: making easy front end changes difficult since 1873 :P

Mods & Themes | Revamped theme for this site | Dark theme for this site | GitHub for n00bz

Sesquipedalian

I'm on my phone at the moment, so I can't verify, but I'm sure you would need to make changes to the query in Sources if you want that to work out properly.
Slava Ukraini!
Heroiam slava!

I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

Suki

For 2.1?

$context['posts'] holds the following user info:

Code (php) Select

'first_poster' => array(
'id' => $row['id_first_member'],
'name' => $row['first_poster_name'],
'href' => empty($row['id_first_member']) ? '' : $scripturl . '?action=profile;u=' . $row['id_first_member'],
'link' => empty($row['id_first_member']) ? $row['first_poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_first_member'] . '">' . $row['first_poster_name'] . '</a>'
),
'poster' => array(
'id' => $row['id_member'],
'name' => $row['poster_name'],
'href' => empty($row['id_member']) ? '' : $scripturl . '?action=profile;u=' . $row['id_member'],
'link' => empty($row['id_member']) ? $row['poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>'
),


When that var gets iterated you can use an in_array on $user_info['ignoreusers'] to skip printing that message.

Code (php) Select
if (in_array($post['poster']['id'], $user_info['ignoreusers']))
continue;


Should be pretty similar for 2.0.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Making tough decisions, so you don't have to.

Antechinus

Cool. I'll mess around with it once I knock off a few other things. I was thinking of 2.0.x, but as you say it shouldn't be much different. Might be a good mod for both versions.
Sources code: making easy front end changes difficult since 1873 :P

Mods & Themes | Revamped theme for this site | Dark theme for this site | GitHub for n00bz

Antechinus

Just got around to trying this. Same code works in 2.0.x. I ended up doing the template like this:

function template_main()
{
global $context, $settings, $options, $txt, $scripturl, $modSettings, $user_info;

echo '
<div id="recent" class="main_section">
<a id="top"></a>
<div class="pagelinks">', $context['page_index'], '</div>
<div class="cat_bar">
<h3 class="catbg">
<img src="', $settings['images_url'], '/post/xx.gif" alt="" class="icon" />',$txt['recent_posts'],'
</h3>
</div>';

foreach ($context['posts'] as $post)
{
echo '
<div class="', $post['alternate'] == 0 ? 'windowbg' : 'windowbg2', ' core_posts">
<span class="topslice"></span>
<div class="content">
<div class="counter">', $post['counter'], '</div>
<div class="topic_details">
<h5>', $post['board']['link'], ' / ', $post['link'], '</h5>';

if (in_array($post['poster']['id'], $user_info['ignoreusers']))
{
echo '
<span class="smalltext">&#171; ', $txt['ignoring_user'], ' &#187;</span>
</div>
</div>';
}
else
{
echo '
<span class="smalltext">&#171;&nbsp;', $txt['last_post'], ' ', $txt['by'], ' <strong>', $post['poster']['link'], ' </strong> ', $txt['on'], '<em> ', $post['time'], '</em>&nbsp;&#187;</span>


After which it's just the standard 2.0.x code. It's quite tidy. I don't think it needs anything else (js bits to show posts, etc). The link to the post is still available, if anyone really wants to torture themselves and start a flame war with someone they can't stand.
Sources code: making easy front end changes difficult since 1873 :P

Mods & Themes | Revamped theme for this site | Dark theme for this site | GitHub for n00bz

Antechinus

Y'know I just thought of something: this could be a cool little mod package. Minimal code, and shouldn't conflict with other mods as I doubt any will touch this area (ran a search, and haven't found any that do).

It could conceivably run into problems with custom theme markup, but again that would be rather rare. It's not a function that theme authors tend to edit, because it never really needs it.
Sources code: making easy front end changes difficult since 1873 :P

Mods & Themes | Revamped theme for this site | Dark theme for this site | GitHub for n00bz

Advertisement: