Well, it looks like the admin over at macaddict (GUI?) is using a rewrite in combination with a few custom .php tweaks to get pretty URLs.

I wonder how involved the php hacking was...

27

(35 replies, posted in Feature requests)

Connorhd wrote:

...the mod ShawnBrown made mark topics read it can only mark them unread if your login times out while the session is still open in the browser (i think)...

The script only makes changes if the array info differs from the markup that the php has generated. So yes, it only bothers to mark unread posts as unread after they've timed out ... since they are already properly marked as unread before the timeout.

Here are the possible states and what the script does about them...

- unread & not timed-out: topic id tracked, DOM not altered
- unread & timed-out: topic id tracked, indicator turned-on
- read & not timed-out: topic and last-post id tracked, indicator turned-off
- read & timed-out: record pruned from array/cookie, DOM not altered

(using the multidimensional array structure... array[forum-id][topic-id]=x ...where x=0 if unread, or x=last_post_id if read)

Connorhd wrote:

...if you went on the site clicked on one topic and closed the browser, then came back 30min later the topics you didn't read would be marked read...

Yes. Though it is possible to extend the persistent cookie expiration time but I've recommended in the install that it be set to mirror the forum's "Visit Timeout" (default: 600 seconds). And I'd be reluctant to suggest turning the expiration time up too much right now as the script treats a larger-than-4k cookie like a buffer over-flow and clears it. But as things stand (with the short time out), the cookie can track at least 250 posts (but probably more like 350+). To exceed the 4k limit, you'd need a forum with several hundred new posts at a time, so this isn't much of a problem with the short timeout and the current pruning.

(I do intend to add large-cookie-friendly pruning in a future version though--to support a more-or-less permanent persistent cookie. But this won't be the default setup.)

ShawnBrown wrote:

When I was making the script I was concerned about execution time but it doesn't seem to be an issue.

Gary13579 wrote:

...It seems to slow down the page a bit .... but Im sure most of the problems are because im on a slow connection right now

When the script runs, the indicators are quickly flicked on or off--this used to cause a flicker especially in IE. To prevent this, the script immediately sets the visibility of the first column to hidden. Only after the browser receives the </body> tag, does the script run--updating the indicators and setting the first column's visibility back to visible.

I think the slow down you're seeing is caused by slow the connection (waiting to receive the </body> tag) rather than the script chugging away. I've been keeping the execution speed in mind from the beginning and have tried to make it as quick as possible.

Just in case this becomes an issue, I think I'll include different flavors of the script in the distribution package:
- small, packed version (default install)
- speedier copy (unpacked, comments & white space stripped)
- fully commented version (for modifications)

Smartys wrote:

...For some reason, the thread updates but not the forum (there are no unread threads but the forum is still marked as unread)
Is that normal?

No, that's not normal... but I know it can happen if you remove an unread post via the moderate forum link (moderate.php). Doing this leaves an unread mark in the array which turns the indicator on when you view index.php.

If that's not what happened, email me and I'll take a look at it.

ShawnBrown wrote:

I forgot about the middot... this could be tripping up the tclcon rebuild.

Rickard wrote:

Ah, OK. But that won't be a problem to update once 1.2.1 is out, right?

It looks like the missing middot support alone was causing this. The non-breaking spaces I saw were those generated when the middot is turned on (i.e., the "User has posted earlier" option).

For an updated version with added middot support you can download the working update.

Rickard: Can you try this on the latest source and see if it works?

Mart wrote:

One quick request: 26Kb is a bit heavy, so off I went to http://dean.edwards.name/packer/ to pack it up. Sure enough, it packed to 6Kb. Unfortunately it didn't work, because Packer needs everything terminated properly. Would it be possible for you to go through the code and terminate as per the requirements for the packer, so we can have a much lighter-weight (and very cool) addon? smile

That's a good idea. When I was making the script I was concerned about execution time but it doesn't seem to be an issue. I'll use the packer you listed and another one then put the smallest result in the distribution (along with an uncompressed copy).

Rickard wrote:

...when I return to the forum, the whole subject cell is empty. It doesn't show anything. Any idea what might be causing this ShawnBrown?

I should note that I tested this on the latest source, but viewforum.php hardly contains any changes worth mentioning.

The script should handle minor changes to most of the table cells robustly--but the first cell is more picky. A complete rebuild of the tclcon DIV takes place and the script needs to know what to look for in this DIV.

On this forum, viewforum.php is adding two non-breaking spaces that weren't there in my installed version of 1.2.0. The additional code between <div class="tclcon">
and the link alters the node tree for the content there. One thing I also noticed is that I forgot about the middot... this could be tripping up the tclcon rebuild.

##
##
##        Mod title:  PunJS New Posts
##
##      Mod version:  1.0
##   Works on PunBB:  1.2
##     Release date:  2005-01-22
##           Author:  Shawn Brown ( http://shawnbrown.com/contact )
##
##      Description:  Turns off new post indicators as messages are read.
##                    Also prevents unread messages from timing out.
##
##   Affected files:  include/template/main.tpl
##
##       Affects DB:  No
##
##            Notes:  This script tracks read/unread forums, topics and
##                    post id numbers. These numbers are derived from PunBB's
##                    HTML output and the web browser's environment variables.
##                    The information is managed in a multidimensional array
##                    which is serialized for storage in a cookie file. The
##                    read/unread indicators are manipulated using W3C DOM
##                    node references and methods. These are strictly
##                    client-side methods that require no extra work from
##                    the server once the script itself is downloaded.
##
##                    This is less of a traditional mod and more of a
##                    JavaScript add-on. The new_posts.js file is just
##                    under 26kb. A modern browser will cache this file so
##                    it is only retrieved once. As is, the script should
##                    lay seamlessly over an "out-of-the-box" install of
##                    PunBB 1.2.
##
##                    Note - If a members's ability to post replies in
##                    a forum is disabled, the script can not reliably
##                    turn off new post indicators for that forum.
##
##       DISCLAIMER:  Please note that "mods" are not officially supported by
##                    PunBB. Installation of this modification is done at your
##                    own risk. Backup your forum database and any and all
##                    applicable files before proceeding.
##

PunJS New Posts (for PunBB 1.2)

    Screenshot here

    Download v1.0 here (please use new_posts.js 1.0.1dev with this package instead of the included file)

    Working update: new_posts.js 1.0.1dev
        - New post tracking on index page implemented
        - "Sticky" topic handling implemented
        - Added support for "User has posted earlier" admin option--the "·" in front of the topics
        - For instalation instructions, download the 1.0 distribution

Rickard, Connorhd: Thanks for the info. I'll be posting this as a packaged mod in a few minutes.

Updated version...

http://shawnbrown.com/new_posts4.png
The new version is available at the same location as before (new_posts.js).

Here are some of the new changes:

- Last-post tracking has been added for posts that haven't timed out. All new posts are now accurately tracked and marked as such.

- A persistent cookie is used to prevent marked-as-read posts from coming back between short multiple visits.

-  To keep things visually consistent, the script generates a [Last post] link using action=last. I wanted to add a genuine [New posts] link for unread-but-timed-out messages but doing this reliably with the given markup just isn't possible.

- The script now also suppresses the update flicker that was sometimes apparent (especially in IE). The style sheet method used to do this should work in all common browsers except Opera. If you have Opera, you may still see a slight flicker as the script re-writes the new post indicators.

Question: One of the last things I need to add is detection for the punbb_cookie. The script needs to determine if the browser is logged in as a user or as a guest. Can anyone tell me what I should be looking for to determine this? I've looked at the unescaped cookie data but I can't readily see what I need to be testing for.

This detection is necessary to prevent odd behavior for users that have turned off the "Save username and password between visits" option.

After this user/guest detection is implemented, I believe the script is pretty much done. If I don't hear of any errors or strangeness, I'll package it up as a proper mod in a week or so.

36

(16 replies, posted in General discussion)

notnamed wrote:

...Microsoft's official support for Windows 98 ended almost exactly a year ago. That means they're not going to make any more security patches for it... meaning your computer is now wide open. ...

This isn't entirely accurate.

Full support for Win98 and Win98se was discontinued June 30, 2003 but Microsoft has continued to release updates and security patches. In fact I just installed MS05-001 on Win98se the other day--that patch was released on January 11, 2005.

Publicly released critical update support (for 98 & 98se) is currently scheduled through June 30, 2006. The non-critical issue support, however, has been dropped.

Question for Rickard:

I'm getting ready to add a [ New posts ] link for timed-out messages but I have a question: the normal [ New posts ] link uses the href: viewtopic.php?id=TOPICID&action=new.

Now when I append &action=new to an old post (e.g. 1.0 Preview) I'm taken to the last message in that topic.

So I see that this works... but can I use this as a reliable way to reach a topic's last post? Or should I use a different method (like building a proper pid=POSTNUM#pPOSTNUM link) instead?

Next Revision Will Include...
- [ New posts ] link for unread-but-timed-out messages
- last-post tracking for messages that aren't timed-out

I have an updated--and much improved--version of the script online now (new_posts.js). I decided to scrap the "STRONG-style copying" idea and do a proper rebuild of the "tclcon" DIV in the node tree. So instead of looking like a <strong> tag, it actually is a <strong> tag. Also, the <strong> is removed for messages marked as read.

[Edit: image removed, see the new screenshot instead]

Additionally, the "There are new posts" text in the "nosize" DIV is added/removed as appropriate. All of this DOM-node manipulation can be confirmed in Firefox by choosing: View > Page Style > No Style. And persistent cookies are currently turned off until the script supports reply-number tracking for marked-as-read posts.

i was thinking along the lines of this being in 1.2.1 wink...

I'd be happy if it were someday part of the core but I'm content with it being simply an add-on as well.

Yes, it's more of a patch over the current method as opposed to cleaner rewrite...

ShawnBrown wrote:

To change the URLs, you'd just alter that one $by_post_url= declaration.

Actually, this method would require a small handful of templates... by-post, by-forum, by-topic, etc.

Rickard wrote:

...Your suggestion requires that people edit all the scripts...

I was thinking that...
   $by_post_url = 'viewtopic.php?pid=$1#p$1';
      ...could be declared in a single file (like config.php or something).

And the...
   $the_link = variable_rewrite($by_post_url, $pid);
      ...line would be hard coded into each file.

To change the URLs, you'd just alter that one $by_post_url= declaration. I favor the viewtopic.php?pid=$1#p$1 format--with it's dollar-sign symbols--so that it's similar to Apache's rewrite format ... but this is just a matter of taste.

I think we're thinking the same thing basically ... I'm just not familiar enough with PunBBs internal structure to suggest a format consistent with the coding style you've already used.

The PHP code I'm using for the variable_rewrite() is...

function variable_rewrite($string, $one, $two='', $three='', $four='', $five='') {
    if ($string && $one) {
        $string = str_replace('$1', $one, $string);
        if ($two) {
            $string = str_replace('$2', $two, $string);
            if($three){
                $string = str_replace('$3', $three, $string);
                if($four){
                    $string = str_replace('$4', $four, $string);
                    if ($five) {
                        $string = str_replace('$5', $five, $string);
                    }
                }
            }
        }
    } else if (!$string)
        return null;
    return $string;
}

I just made a slight change to the script (it's still available at the same location - new_posts.js).

The script was assigning a punhover class to rows so they'd change color on mouseover...

[Edit: image removed from server]

...but I don't think it's appropriate for a new-indicator-management script to assign unrelated onmouseover/onmouseout events. (This should be a completely separate add-on.)

DIFFERENT TOPIC: In the screenshot above, I've declared STRONG { font-weight : normal }. But instead of this, I'm going to have the script alter the assigned font-weight of the timed-out-but-unread messages so they mirror the default or CSS-declared STRONG style.

Connorhd wrote:

one thing that would be cool is if instead of just making them as old topics it marked them in a new colour so you could see what was new even if you've read it...

This is certainly possible. Right now it assigns inormal to the DIVs as the messages are read... but a 3rd class could be assigned just-as-easily. Maybe something like ioff. If this is done, the array pruning will need to be modified to make the display operate intuitively... not really a problem though.

I could add an option for this after I'm sure the script works well in its current state. If it is added, the use of a 3rd class will not be the default behavior--I'd like the script to lay seamlessly over an out-of-the-box install of PunBB.

XuMiX wrote:

a small question then, how does this script determine that topic is new? i mean does it mark topic read immediately after entering it ?

When a page loads, the script looks at the first cell in each row--if it sees an inew class DIV, it adds that topic's id to the cookie along with an unread mark. If the topic gets timed-out, the cookie still has a record of the topic and its status. The cookie also stays small--only recording what it needs to. If a topic has been read and has timed-out, its entry is removed from the cookie.

Since this is currently a "session" cookie, all of this is cleared when the browser window closes. I'm thinking about changing its behavior slightly though.

Here's a screenshot...

[Edit: image removed, see the new screenshot instead]

During an earlier discussion about new post indicator tracking, I decided to make a JavaScript-only new post manager.

I have a working version of this now--I'm calling it PunJS New Posts. If anyone's feeling brave--and would like new post indicator management--you can install it on your forum but be warned that it's only been tested with a single account on an untrafficked test forum. That said, I don't expect it to behave too badly and since it's client-side script it can't cause any real harm.

To install it, copy new_posts.js into your forum directory (PunBB 1.2 only please!) and add a simple script tag in main.tpl to load it as an external file...

<script type="text/javascript" src="http://yoursite.com/forum/new_posts.js"></script>

If anyone installs this, let me know how it works out--and if you have problems with it.

Note: This isn't the final version but I don't have enough traffic on my own forum to give it any more of a test than I already have.

Issues:
- If you've modded your install of PunBB and added extra tables inside the punwrap DIV, you may encounter problems (but maybe not).
- If user-posting is disabled in a forum, the script might not be able to mark that forum's new posts as having been read.

47

(6 replies, posted in Programming)

They're very similar but child selectors are more specific. If we're working with the following markup...

<p>This is a <em>test</em>.</p>
<p>This is <i>a <em>test</em></i>.</p>

...a descendant selector like p em { color:red } would make both instances of the word "test" appear red.

But if we use a child selector like p > em { color:red }, only the first "test" would be red. This is because the first <em> is a direct child of the <p> and the second <em> is a descendant but not a direct child (it's the <p>'s child's child).

Although Google does index the pages without problem, it would be very convenient if PunBB had some type of URL template variables.

I've done this before using a simple variable-rewrite function. The default PHP code might read something like this...

$by_post_url = 'viewtopic.php?pid=$1#p$1'; // <-- this variable is our template
$the_link = variable_rewrite($by_post_url, $pid);

It would output what happens now -
  http://punbb.org/forums/viewtopic.php?pid=29006#p29006.

But if we wanted to modify the URL, we could change the $by_post_url variable...

//$by_post_url = 'viewtopic.php?pid=$1#p$1';
$by_post_url = 'by-post-id/$1';
$the_link = variable_rewrite($by_post_url, $pid);

...and add the following line in our Apache setup...

RewriteRule ^by-post-id/[0-9]+$ viewtopic.php?pid=$1#p$1

Then in the forum, our link would look like this -
  http://punbb.org/forums/by-post-id/29006

49

(13 replies, posted in PunBB 1.2 discussion)

a "whois" query wrote:

...Registered through: DNForum
   Domain Name: PUNBB.COM
      Created on: 24-Aug-04
      Expires on: 24-Aug-05
      Last Updated on: 24-Aug-04

   Administrative Contact:
      Admin, Domain  admin@commerceguard.com
      Commerce Garden
      291 Glen Dr
      Grants Pass, Oregon 97526
      United States
      5414721954      Fax -- 5414728078...

50

(15 replies, posted in General discussion)

Saw this one in my site's referrer list - http://www.googlr.com.