Skip to:
Content
Pages
Categories
Search
Top
Bottom

New Code: show forum posts since last visit

  • Avatar of 3sixty
    3sixty
    Participant

    @3sixty

    I wrote up some code that highlights forum threads that have been updated since the user’s last visit. I believe it may be more sophisticated than some other approaches I’ve seen because it checks each specific thread the user has previously visited. Here’s how it works:

    1. when the user visits a thread page, a serialized ‘last visits’ cookie is updated with the server timestamp.

    2. When you visit the group forum index, little post icon will light up if current time is > stored server time of last post for each thread

    3. The cookie is only stored for pages that trigger the forum loop (think it’s called has_forum_topics)

    I tested it and it seems fairly predictable, but I am seeking testers. Let me know if interested. It will require you to update code in your theme’s forum index, header, and forum single page. It is not a plugin (though I wouldn’t mind it being included in one).

Viewing 20 replies - 1 through 20 (of 20 total)
  • Avatar of stwc
    stwc
    Participant

    @stwc

    I am very interested in building up functionality in the bbPress Forums component of BP — weak forum functionality will be the dealbreaker in a new deployment I’m working on for an existing community. The fact that the bbPress community is quite moribund (and the tendency in discussing it here tends to be to direct people there, despite the fact that there’s an even greater paucity of documentation and resources ‘there’), and we need to rewrite or create new extensions for stuff within BP anyway makes things a little difficult for dilettante coders like myself!

    Not a complaint or a derail — just saying that I’m happy to see other people thinking about beefing up bbPress within BP. I figured what the heck, and created a group, here: http://buddypress.org/groups/extending-bbpress-within-buddypress

    Please, do share, and join the group if you’re interested!

    Avatar of 3sixty
    3sixty
    Participant

    @3sixty

    I’m a little worried that a bbpress usergroup will marginalize/’ghettoize’ the discussions? Wouldn’t it be better to keep development front and center?

    Avatar of stwc
    stwc
    Participant

    @stwc

    Heh. It is funny and very germane, the idea that using groups rather than the forum would marginalize. I totally agree with you though — it’s testament to the importance of the forum model that that’s where the good stuff happens, even here.

    Absolutely — keep stuff happening here. The group just might be useful for people to see who else is interested in working on extending bbPress, not for discussion per se.

    Avatar of 3sixty
    3sixty
    Participant

    @3sixty

    Yeah, in this particular community, there’s still a pretty good signal-to-noise ratio in the main forum, so I’d advocate that we keep threads on forum stuff out in the open… that said, I’ll definitely join the group and hope some extra awesomeness comes out of it. Thanks for setting it up, stwc.

    Avatar of 3sixty
    3sixty
    Participant

    @3sixty

    heh… well, turns out the groups as set up here on buddypress.org don’t actually have forum or activity stream options… pretty much all you can do right now is join, so that renders all this hand-wringing a moot point. :)

    In terms of the “new posts since last visit” code I need to find a way to expire each serialized cookie at 60 days, and then it’s pretty much ready to go.

    Avatar of stwc
    stwc
    Participant

    @stwc

    Excellent — looking forward to messing with it, when you’re ready to share! Another piece of the puzzle. ;-)

    Avatar of 3sixty
    3sixty
    Participant

    @3sixty

    I managed to condense this to about 20 lines of code. Try this (4 steps):

    header.php

    1. At very top of file, add:

    <?php ob_start(); ?>

    2. After <?php wp_head() ?>, add:

    <?php

    if ( bp_has_forum_topic_posts() ) {

    global $forum_template; $timestamp=time();

    if (isset($_COOKIE["bp_forum_visits"])) {

    $unserialized_cookies = unserialize($_COOKIE["bp_forum_visits"]);

    $unserialized_cookies[$forum_template->topic->topic_id] = $timestamp;

    foreach ($unserialized_cookies as $topic_id => $timestamp) {

    //keep cookie but unset any serialized data older than 60 days

    if( time() > $timestamp+60*60*24*30*2 ) { unset($unserialized_cookies[$topic_id]); }

    }

    //NEED HELP HERE: unset cookies for any deleted topics. How to do this?

    } else {

    $unserialized_cookies = array($forum_template->topic->topic_id => $timestamp);

    }

    $serialized_cookies = serialize($unserialized_cookies);

    //set the cookie. the whole thing expires in 60 days if there are no forum visits

    setcookie(“bp_forum_visits”, $serialized_cookies, $timestamp+60*60*24*30*2, “/”);

    } ?>

    <?ob_end_flush(); ?>

    forums/forums-loop.php

    3. After <td class=”td-title”>, add:

    <div style=”float:left; margin-right:5px”>

    <?php global $forum_template;

    if ($user_topic_visits[$forum_template->topic->topic_id]) {

    if ($forum_template->topic->topic_time > date(‘Y-m-d H:i:s’, $user_topic_visits[$forum_template->topic->topic_id])) {

    echo ‘<img alt=”new posts since last visit” src=”http://img.photobucket.com/albums/v502/Vidster/newposts.jpg”>’;

    } else {

    echo ‘<img style=”width:20px;height:20px” alt=”no new posts since last visit” src=”http://img.photobucket.com/albums/v502/Vidster/nonewposts.jpg”>’;

    }

    } else {

    echo ‘<img style=”width:20px;height:20px” alt=”no new posts since last visit” src=”http://img.photobucket.com/albums/v502/Vidster/newposts.jpg”>’;

    }

    ?>

    4. Download the icons and upload them to your own server; edit the src= to point to your own server copy of the icons

    Avatar of r-a-y
    r-a-y
    Moderator

    @r-a-y

    1) hook into the get_header action

    eg. add_action('get_header','your_ob_start_call_in_a_function');

    2) hook into the wp_head action with a high priority

    eg. add_action('wp_head','your_code_in_a_function',999);

    3) is the only edit you have to make to the template

    Avatar of stwc
    stwc
    Participant

    @stwc

    I have to admit that I’m utterly mystified, still, by actions and hooking stuff into other stuff.

    Thanks, though, 3sixty and r-a-y.

    Avatar of andrew_s1
    andrew_s1
    Participant

    @andrew_s1

    3sixty, I’d strongly recommend not doing it that way. ISTM that it’s far better if you store this info server-side, not client-side: it’s information that’s specific to the logged-in user, not to the browser they’re logged in from. I wouldn’t want to see posts marked as new, that I’d already read, just because I was using a different browser or a different machine. Big cookies harm browser-side performance, too.

    Yes, I’m interested in working on extending buddypress’s forum capabilities. Here’s my work in progress: http://andrewsinlondon.wordpress.com/

    Avatar of andrew_s1
    andrew_s1
    Participant

    @andrew_s1

    Think about scalability too – does it make sense to store a marker for every topic, given that it will grow with every new user and every new topic?

    Another way to do it would be to store a “high tide mark” for every user on each forum, recording the highest post number that a user has read. That way, when they come back to the forum, you can do an easy SELECT on topics which have a post higher than the high tide mark, and flag those as having unread posts.

    Avatar of Mike Pratt
    Mike Pratt
    Participant

    @mikepratt

    1. Andy is about to put everything into Groups on this site (where I think they belong) I know everyone wants to stick with the old forum b-board model but think of it this way: While you point out that everything is “front and center” here…that’s exactly the problem. You have to wade through tons of stuff you don’t care about just to track what you want. Now, you might say, well….just categorize within forums. That’s exactly what Groups are. They are contextual groupings. But a category is 1 dimensional. A group is extensible to make the Group so much more than slapping a category on a topic. To each his own, but to me, a forum is just one part of a much bigger concept.

    2. Just curious (seriously) What is all this extending people want to do with forums (is bbPress) I am having trouble wrapping my head around what was deemed “weak forum functionality” What is it supposed to do that it already isn’t? There are a few plugins underway to integrate a few things into the activity stream (media, etc) (which, therefore, integrates them into the forums) and maybe I can see some tweaking to the forum listing page) I’m all for adding capabilities, but everywhere Iv’e seen them implemented, the forums (in Groups) do an awesome job of being the discussion framework.

    PS Awesome idea on “posts since last visit” btw

    Avatar of 3sixty
    3sixty
    Participant

    @3sixty

    I was hoping someone would take the “why are you using cookies” bait. :) Yes, we are aware it’s suboptimal because it’s only specific to the current browser. Here’s the big concern, though:

    3sixty, I’d strongly recommend not doing it that way [using cookies to store "last post visited" info]. ISTM that it’s far better if you store this info server-side, not client-side:

    In terms of being scalable, isn’t a cookie less overhead than a database query?? BP is so dynamic that I would assume it probably already generates an amazing amount of database queries… would I want to tax the server that much more by storing “last visit” info in a data table?

    I’m hoping someone will tell me not to worry about it, but having been “shut down” multiple times in the past for excessive mySQL queries, I’m treading as lightly as I can. BP gurus, please weigh in here.

    Avatar of 3sixty
    3sixty
    Participant

    @3sixty

    What is all this extending people want to do with forums (is bbPress) I am having trouble wrapping my head around what was deemed “weak forum functionality”

    It’s not “weak” functionality, as the core forum code (bbPress) is very elegant and versatile. However, there is a long list of moderator/user features that are missing from BP Forums, but we are trying to add them in (hence my “last visit” code here). The Forum Extras plugin is a laundry list of essential forum features that have been added in just the past few weeks: http://buddypress.org/forums/topic/new-plugin-buddypress-group-forum-extras

    Excellent little treat this one, I use it all the time on traditional forums. The ((bbpress)buddypress)) discussion is important, I’ll have my say.

    Avatar of andrew_s1
    andrew_s1
    Participant

    @andrew_s1

    In terms of being scalable, isn’t a cookie less overhead than a database query?

    In this case: no, no it’s not. Your cookie will grow and grow with each new forum topic read. It is doomed.

    i would just store a last_activity (every 5 minutes – like the standard last_activity) for each group a user is a member of then run the compare on the topic->topic_time (maybe to make it cleaner – store the last_activity for each group in the bb_meta table – and restrict it down to is_forum and is_forum_topic )

    (WP and BP use a lot of cookies as it is – you run the danger of some of the being purged out when the limit is hit)

    Avatar of 3sixty
    3sixty
    Participant

    @3sixty

    how would I trigger storing the last_activity?

    Avatar of stwc
    stwc
    Participant

    @stwc

    What is all this extending people want to do with forums (is bbPress) I am having trouble wrapping my head around what was deemed “weak forum functionality” What is it supposed to do that it already isn’t?

    From my perspective only: I’m working on migrating a busy community of about 1000 users from Vanilla. Now Vanilla itself is just that — basic, but nice and solid forum structure. Unfortunately, Mark, the guy behind it, fractured the vibrant development community around extensions when he jumped the gun on the 2.0 release, reworked the extension repository, badly, in my opinion, and now things are in disarray, sadly, and the 2.0 version, nice as it looks, just isn’t coming very fast, while the 1.x versions, still apparently being maintained and moved forward, have a floundering and disjointed developer community kind of wondering what’s going on. It’s a bit sad to see, as it’s a great little app. It’s just that I think there was a big mistake made in the way that the community website around it (like this one here) was changed, and lost focus on users. It’s gotten better since, the developer site, but I think momentum might have been lost.

    So, anyway. My users have come to expect some basic functionality from a forum, most of which ihas been added through extensions to Vanilla. Things like:

    • Attaching inline images to posts
    • Easy quoting of posts in replies
    • Minor, standard forum structural stuff like new comments since last visit, links to last reply/replier and so on
    • Inline PMs (which, in my case, will be moved to BP private messages when I do the jump)
    • Individual hread pagination/navigation in the forum view
    • Ways to thank (ie vote up, ‘like’, whatever) posts
    • Buttons on textareas for basic tinyMCE-like functionality

    And lots of other little niceties like that. I am determined to make the transition from Vanilla to BP as smooth and seamless as possible for my users (many of whom are developers and sophisticated web users, many of whom aren’t), and so the little things have been much on my mind. I want to provide them with a core forum experience that replicates as closely as possible what they’ve been used to for the past few years, but with all the other BP goodness and blog hosting with WPMU and all the rest extending it.

    Pretty much all of that is now covered by plugins (or even core BP stuff) from etiviti (rich!) and Boone and others, thank goodness. But until literally the last couple of weeks, a lot of the plugin functionality to fill in those gaps, available on standalone bbPress installs through plugins written for bbPress, wasn’t available in Buddypress’s integrated version. So I am deeply thankful to folks working on that stuff and porting it to work natively in BP.

    So, for me, it’s not that there’s anything intrinsically wrong with BP’s forum functionality as provided by bbPress, but there are just a whole bunch of nice little things that people don’t think about much until they’re no longer there that I want to make sure my userbase doesn’t miss if we make the move.

    Again — that’s just my own personal story with the site I’m currently working on. And yes, I am well aware that Buddypress isn’t about replicating or extending the kind of bog-standard forum style we’re all used to, it’s kneedeep in the MyFace-y Spacebook-y Twitteriffic social networking hoohah that is so au courant these days. All good.

    In my case, it’s not a matter of everything looking like a nail because I have a hammer in my hand, honestly. If all my work with BP to tweak it towards something that will please my users doesn’t pan out, I won’t end up using it for this particular project I’m working on right now — but I’m so close I can taste it. ;-) Learning BP is an end in itself, as well.

    Avatar of 3sixty
    3sixty
    Participant

    @3sixty

    I am working on a database version of this.

Viewing 20 replies - 1 through 20 (of 20 total)

You must be logged in to reply to this topic.