Advertisement:

Author Topic: Ignored users: hiding posts on Recent.template.php  (Read 718 times)

Offline Antechinus

  • SMF Friend
  • SMF Master
  • *
  • Posts: 25,109
  • Master of BBC Abuse
Ignored users: hiding posts on Recent.template.php
« on: September 16, 2019, 09:27:40 PM »
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:

Code: [Select]
// 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?

Offline Sesquipedalian

  • The Mad Doctor
  • Lead Developer
  • Sophist Member
  • *
  • Posts: 1,091
  • Gender: Male
  • It works! ... in theory.
    • Sesquipedalian on GitHub
Re: Ignored users: hiding posts on Recent.template.php
« Reply #1 on: September 18, 2019, 10:20:21 AM »
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.
I promise you nothing.

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

Offline Suki

  • Carthago delenda est
  • Developer
  • SMF Super Hero
  • *
  • Posts: 15,679
  • Oh, wouldn't it be great if I *was* crazy?
    • MissAllSunday on GitHub
    • SMF mods
Re: Ignored users: hiding posts on Recent.template.php
« Reply #2 on: September 18, 2019, 10:32:54 AM »
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.

Look at them. They're just asking for it. Maybe the human race deserves to be wiped out.

Offline Antechinus

  • SMF Friend
  • SMF Master
  • *
  • Posts: 25,109
  • Master of BBC Abuse
Re: Ignored users: hiding posts on Recent.template.php
« Reply #3 on: September 18, 2019, 04:39:46 PM »
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.

Offline Antechinus

  • SMF Friend
  • SMF Master
  • *
  • Posts: 25,109
  • Master of BBC Abuse
Re: Ignored users: hiding posts on Recent.template.php
« Reply #4 on: February 08, 2020, 05:37:03 PM »
Just got around to trying this. Same code works in 2.0.x. I ended up doing the template like this:

Code: [Select]
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.

Offline Antechinus

  • SMF Friend
  • SMF Master
  • *
  • Posts: 25,109
  • Master of BBC Abuse
Re: Ignored users: hiding posts on Recent.template.php
« Reply #5 on: February 12, 2020, 04:37:18 PM »
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.