404 Tech Support

Open All Unread in One Click – a phpBB3 Mod

It’s a rare and exciting opportunity when I get to introduce something I’ve developed. I’m an administrator for a small phpBB forum and I’ve regularly installed mods to tweak the behavior of phpBB to match my user’s needs. I did some looking around but couldn’t find anything to match a direct request I had: Open all the unread posts in one click instead of having to click each link and have it open in a new tab or window.

After scouring the phpBB Mods database and other phpBB hack sites and not finding anything, I set out to develop this myself. In the end, it seems to work perfectly but it’s nothing too complex. It was a great one to start off with because of its simplicity, but still had enough issues to generate a feeling of accomplishment.

If you’re unfamiliar with installing phpBB mods, check out my quick guide or the phpBB guide. One of the best mods I’ve installed on my forum is the View or mark unread posts mod and I highly recommend it. It makes the ‘Unread posts’ feature of phpBB more accurate and more useful. It also perfectly complements the Open All Unread in One Click mod I’ve made.

Summary:

Follow the ‘View Unread Posts‘ link at the top of the Index page of your phpBB3 forum. When you’re on that page, you’ll see a little line that says how many posts are unread in the top-right corner. I have made this line into a link. If you left-click on it, it will open all the unread posts in new windows. If you have Firefox or IE* configured as such, it will open them as new tabs and not new windows.

Title: Open All Unread in One Click

Version: 1.0.2

Category: Add-Ons

Complexity: Template Changes

Time: ~2 Minutes

phpBB version: 3.0.4

Files affected:

Open: stylesprosilvertemplatesearch_results.html

Find (around line 41, 42):

<div class="rightside pagination">
{SEARCH_MATCHES}

Replace with:

<div class="rightside pagination">
<!-- IF searchresults --><a href='#' onclick='open_all()'>{SEARCH_MATCHES}</a><!-- ELSE -->{SEARCH_MATCHES}<!-- ENDIF -->

Open: stylesprosilvertemplateoverall_header.html

Find (around line 100):

</head>

Add before:

<script language="Javascript">
function open_all()
{
<!-- BEGIN searchresults -->
var url1 = "{searchresults.U_VIEW_TOPIC}"
var url2 = url1.replace(/&amp;/g,'&')
<!-- IF searchresults.S_ROW_COUNT > 0  -->
window.open(url2);
<!-- ELSE -->
window.location.href = url2;
<!-- ENDIF -->
<!-- END searchresults -->
}
</script>

Purge the cache in your ACP and refresh the Unread Posts page.

Author’s Notes:

In overall_header.html, {searchresults.U_VIEW_TOPIC} is used. This will take the individual to the topic which makes this function also work for searches. If you want to take the user to the latest post, replace {searchresults.U_VIEW_TOPIC} with {searchresults.U_NEWEST_POST}. This will not work with searches. Instead, I’d recommend using the U_VIEW_TOPIC and making one further modification. From the View or mark unread posts mod author’s notes:

OPEN
search.php

FIND:
‘U_VIEW_TOPIC’ => $view_topic_url,

REPLACE WITH:
‘U_VIEW_TOPIC’ => ($search_id == ‘unread’) ? $view_topic_url . ‘&amp;view=unread#unread’ : $view_topic_url,

This will serve the function of when looking at the unread Posts page, you don’t have to click on the little orange square to get to the unread posts, instead you can click on the (bigger) topic title link and that will take you to the unread posts and not just the thread. It also makes this mod work seamlessly with searches so you can open all results on that page into new windows/tabs with one click.

I have successfully tested in IE8 and Firefox 3. If users don’t like this, it’s simple: nothing has changed with the interface. If they like this, just left-click (not middle click) the link and all the unread posts will be opened in new windows/tabs.

I actually ran into a little bit of a problem thanks to the javascript I have to use. IE8 handled it easily, but Firefox had problems with it. If you’ve looked at the URLs for an unread post, there are at least 2 ampersands (&) in it. phpBB generates the URLs as …&amp;f=4&amp;t=1300…
When either browser gets these URIs from a link, it converts the &amp; into &. When Firefox (Opera & Chrome too, based on what I read when searching for a solution) gets this URI from javascript, however, it leaves the &amp; as it is and thus the link doesn’t work. IE8 still converted it just fine.
Throwing in two more lines of code solved the problem:

var url1 = "{searchresults.U_NEWEST_POST}"
var url2 = url1.replace(/&amp;/g,'&')

*To make these pop-ups open in tabs instead of new windows in IE:

Tools, Internet Options
Under the General tab, click the Settings button in the Tabs section.
Change “When a pop-up is encountered” to:
Always open pop-ups in a new tab
Hit Ok.

The same setting can be found in Firefox 3 here:

Tools, Options
Tabs
Change “Open links that open in a new window in:” to:
New tab
Hit Ok.

Update: I changed the code in the overall_header.html file to open the first link in the current window and the rest of the links in new windows. This overwrites the View Unread Posts page, but you can easily get to it by hitting the back button.

Let me hear any feedback, questions, or problems in the comments!