Skip to:
Content
Pages
Categories
Search
Top
Bottom

“My Threads” – User Specific Views

  • I’d like to be able to offer two views for the users, which would work similarly to the “Threads with no tags” views at the bottom of the screen.

    1) Threads I’ve started

    2) Threads I’ve commented on

    Are there already plugins for these views, or do I need to make my own?

Viewing 25 replies - 1 through 25 (of 27 total)

  • _ck_
    Participant

    @_ck_

    I haven’t seen them (doesn’t mean it doesnt exist) but I’ve figured out the framework on how to build and attach a view if you’d like to copy my homework :D

    This is the code I whipped up for “most-views” and “least-views” (which requires the view count plugin to be installed (and inserting the views column in view.php)

    function most_views_views( $views ) {
    global $views;
    $views['most-views'] = 'Topics with the most views';
    return $views;
    }
    add_filter('bb_views', 'most_views_views');

    function least_views_views( $views ) {
    global $views;
    $views['least-views'] = 'Topics with the least views';
    return $views;
    }
    add_filter('bb_views', 'least_views_views');

    function most_views( $view ) {
    global $bbdb, $topics, $view_count;
    if ($view=='most-views') {$sort="DESC";}
    if ($view=='least-views') {$sort="ASC";}
    if ($view=='least-views' || $view=='most-views') {
    $limit = bb_get_option('page_topics');
    $where = apply_filters('get_latest_topics_where','');
    $most_views = $bbdb->get_results("SELECT topic_id FROM $bbdb->topicmeta WHERE meta_key='views' ORDER BY cast(meta_value as UNSIGNED) $sort LIMIT $limit");
    foreach (array_keys($most_views) as $i) {$trans[$most_views[$i]->topic_id] =& $most_views[$i];} $ids = join(',', array_keys($trans));
    $topics ="SELECT * FROM $bbdb->topics WHERE topic_status=0 AND topic_id IN ($ids) $where ORDER BY FIELD(topic_id, $ids)";
    $topics = $bbdb->get_results($topics);
    $view_count = count($topics);
    $topics = bb_append_meta( $topics, 'topic' );
    }
    else {do_action( 'bb_custom_view', $view );}
    }
    add_action( 'bb_custom_view', 'most_views' );

    As you can see a new view requires both 1. an action 2. a filter

    Easy once you’ve seen it, but try figuring it out from scratch!

    This bit adds the title to view pages (missing by default in bbpress)

    function bb_get_view_title($title) {
    if (is_view()) {$title = get_view_name(). ' « ' . bb_get_option( 'name' ); }
    return $title;
    }
    add_filter( 'bb_get_title', 'bb_get_view_title' );


    _ck_
    Participant

    @_ck_

    will have this working within an hour


    _ck_
    Participant

    @_ck_

    Wow I was making it too complicated! Try this…

    I managed to use internal functions but there’s a catch with get_recent_user_replies in that all topic data is not attached properly so I have to run through get_topic to pull all the cache data out again (the only proper way to do it without peeking in the cache directly)

    <?php
    /*
    Plugin Name: my views
    Description: views for a user's topics started and other participated topics
    Plugin URI:
    Author:
    Version: 0.01
    */

    function my_views_filter( $views ) {
    global $views;
    $views['my-topics'] = "Topics I've Started";
    $views['my-posts'] = "Topics I've Participated In";
    return $views;
    }
    add_filter('bb_views', 'my_views_filter');

    function my_views_action( $view ) {
    global $bbdb, $topics, $view_count; $user_id=bb_get_current_user_info( 'id' );
    if ($view=='my-topics') {$topics=get_recent_user_threads($user_id); $view_count = count($topics);}
    if ($view=='my-posts') {
    $posts=get_recent_user_replies($user_id); $topics="";
    foreach ($posts as $post) {$topics[]=get_topic($post->topic_id );}
    $topics=bb_append_meta( $topics, 'topic' );
    $view_count = count($topics);}
    }
    add_action( 'bb_custom_view', 'my_views_action' );

    if (!function_exists(bb_get_view_title)) {
    function bb_get_view_title($title) {
    if (is_view()) {$title = get_view_name(). ' &laquo; ' . bb_get_option( 'name' ); }
    return $title;
    }
    add_filter( 'bb_get_title', 'bb_get_view_title' );
    }

    ?>


    Sam Bauers
    Participant

    @sambauers

    You should be aware that views are registered differently in the latest versions in trunk. Views are now constructed using the BB_Query class.

    See the latest Support Forum plugin for a way to use both the new and old, although it is wrapped in a Class in there so the basic idea is:

    if (is_callable('bb_register_view')) { // Build 876+
    $query = <SOME ARRAY ACCEPTABLE TO BB_QUERY>;
    bb_register_view('myview', __('My view name'), $query);
    } else { // Build 214-875
    add_filter('bb_views', 'my_addView');
    add_action('bb_custom_view', 'my_processView');
    }


    _ck_
    Participant

    @_ck_

    Ugh. So that breaks a view things I’ve done.

    I’m waiting for an addition to the plugin svn and I’ll just update there at this point. I also missed checking if the user is logged in, now fixed.

    I don’t run the newest trunk so I don’t have a way to test. Looks like I’ll have to setup a test account and install it again.

    and I just put the finishes on a nice dropdown view box too… :-(

    function views_dropdown() {
    $views_dropdown='<form name="views_dropdown" id="views_dropdown">
    <select size=1 name="views_dropdown_select" onchange="if (this.selectedIndex != 0) {location=this.options[this.selectedIndex].value;}}">
    <option value="#">SHOW ME
    > </option>';
    $views=get_views(); foreach ($views as $view => $title ) {
    $views_dropdown.='<option value="'.get_view_link($view).'">'.$views[$view].'</option>';
    }
    $views_dropdown.='</select></form>'; echo $views_dropdown;
    }


    _ck_
    Participant

    @_ck_

    Sam, is there a method way to delete a view

    or do I have to just hack and unset the $views directly?


    Sam Bauers
    Participant

    @sambauers

    > is there a method way to delete a view

    In current trunk…

    bb_deregister_view( $view )


    _ck_
    Participant

    @_ck_

    Forgive my ignorance but how long realistically would it be before the current trunk become the stable/released? Are we talking a few weeks or more like several months?

    Looking at the milestone history, it was five months between 0.8.1 and 0.8.2 but only a month between previous releases. Is that “XML-RPC” coding going to hold everything back until it’s done? (I’d seriously love to read why a ping mechanism is believed to be so important and the working model envisioned).

    I just noticed you said something about cache? Is the cache working in the current bbPress release?

    I activated this plugin, but when I click on the link for “topics i’ve started”, all I get is a white page… looking at a sql trace, it doesn’t appear to be running the code at all.

    Any idea what I could be doing wrong here?


    Sam Bauers
    Participant

    @sambauers

    mdawaffe has committed to try and bring the point releases closer together. I believe there are no hard targets set, but it should be better than last time. I would estimate that 0.8.3 will be out within a month, but that is just an estimate. mdawaffe gets pulled from bbPress all the time to do other things.

    I can’t talk with authority about the XML-RPC features being added, but they will potentially open up a whole heap of options for people wanting to connect their forums with other forums and blogs. You should enquire about the development priorities and directions on the bbPress dev list though, you may get more joy there.


    Sam Bauers
    Participant

    @sambauers

    > Any idea what I could be doing wrong here?

    Are you using the latest trunk or the standard 0.8.2.1 release?

    Latest trunk won’t work with the above code.

    Using standard 0.8.2.1 release… wasn’t sure how stable the trunk is.

    Never had a problem. There’s occasionally a bug in it but I’ve never noticed it and it was invariably fixed within a day or two. It’s fine running it.


    Sam Bauers
    Participant

    @sambauers

    I usually fix the bugs I find and then the trunk catches up with me a day or two later after I submit a patch…. ; )


    _ck_
    Participant

    @_ck_

    Sigh, I guess I’ll tempt fate and install the latest trunk. Though I know it’s going to instantly break half a dozen plugins or more, so I need to do that when I have a full night to dedicate to it.

    I really like “views” and keep thinking of more helpful ones I can create that drill down through the data.

    You should enquire about the development priorities and directions on the bbPress dev list though, you may get more joy there.

    I find it somewhat hilarious that a *forum* development team uses a mailing list for group communications. The year 2000 called – it wants it’s static email posts back!


    _ck_
    Participant

    @_ck_

    Er, wait a minute. This new view registation method takes away massive potential from views.

    For example you can’t manipulate the data before and/or after the BB_QUERY.

    Here’s how I find “most viewed” and “least viewed” topics and create new views for them. How the heck is this even remotely possible with the new method? The new method also takes away all natural mysql query methods, making things much more complicated and easier to make mistakes on query configuration.

    function most_views( $view ) {
    global $bbdb, $topics, $view_count;
    if ($view=='most-views') {$sort="DESC";}
    if ($view=='least-views') {$sort="ASC";}
    if ($view=='least-views' || $view=='most-views') {
    $limit = bb_get_option('page_topics');
    $where = apply_filters('get_latest_topics_where','');
    $most_views = $bbdb->get_results("SELECT topic_id FROM $bbdb->topicmeta WHERE meta_key='views' ORDER BY cast(meta_value as UNSIGNED) $sort LIMIT $limit");
    foreach (array_keys($most_views) as $i) {$trans[$most_views[$i]->topic_id] =& $most_views[$i];} $ids = join(',', array_keys($trans));
    $topics ="SELECT * FROM $bbdb->topics WHERE topic_status=0 AND topic_id IN ($ids) $where ORDER BY FIELD(topic_id, $ids)";
    $topics = $bbdb->get_results($topics);
    $view_count = count($topics);
    $topics = bb_append_meta( $topics, 'topic' );
    }}

    .

    Absolutely no way to do that purely though BB_QUERY, at least to my limited knowledge. You’d have to hook BB_QUERY and check for what it’s doing on every call and that’s nasty.


    _ck_
    Participant

    @_ck_

    For anyone running 0.8.2.x I bundled this as a proper plugin with some of my other “views” tricks:

    bbPress plugin: My Views

    optional: install bb-topic-views for the other extra views

    Sweet, the plugin works for me!

    Thanks a ton!

    Just thought I’d throw this out there… if you want to put the two new views first in the list, you can first unset the existing view, and then re-set it below where you add the new views.

    unset($views);

    if (bb_is_user_logged_in()) {

    $views = "Topics I've Started";

    $views = "Topics I've Participated In";

    }

    $views = "Topics with no replies";

    You can also rename the view that way if you want.

    great job


    _ck_
    Participant

    @_ck_

    Good point HowToGeek. The array keys could also be manipulated without having to put back in the topic descriptions too. I could extend the plugin to let the user determine views order.

    Sigh, unfortunately all this will be useless in a month or so. I still don’t have the vaguest clue how to convert my routines to the trunk’s new methods.

    I might end up helping you with that… I’d like to upgrade but a bunch of the plugins I’m using don’t support the trunk.


    _ck_
    Participant

    @_ck_

    Just out of concerned curiosity, what other plugins have you found that don’t support the trunk?

    I suppose I am going to have to break down and setup a testing account with the trunk this weekend or so.

    We need a developer plugin that injects a bunch of fake new users and fake messages for testing.

    I haven’t tried the trunk yet either… I just opened my forum a week ago and I’m trying to keep up with all the traffic and add the most important missing features.

    The one thing that is very frustrating is that administration and moderation in bbPress is not only virtually non-existent, but it’s not even all in one place. If I want to delete a user, I can’t do it from the admin panel, I have to go to their profile instead… annoying.

    I want a plugin that lets me take a reply post and turn it into a new topic. That’s a sorely lacking feature. Your move-it plugin almost fits the bill, but I have to create a new topic first, and then move the post, and then delete my original post in the new topic, or just make it say “look below, moving post into topic”.

Viewing 25 replies - 1 through 25 (of 27 total)
  • You must be logged in to reply to this topic.
Skip to toolbar