Changeset 1290

Show
Ignore:
Timestamp:
08/16/08 15:30:44 (4 months ago)
Author:
_ck_
Message:

0.0.3 fix for deleted topics failing in join query

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • forum-last-poster/trunk/forum-last-poster.php

    r1204 r1290  
    22/* 
    33Plugin Name: Forum Last Poster 
    4 Description:  Adds forum_last_poster, forum_time() and other functions to bbPress to mimic the topic tables' freshness columns. Requires simple template edits. 
     4Description:  Adds `forum_last_poster()`, `forum_time()`, `forum_last_post_link()` and other functions to bbPress to mimic the topic tables' FRESHNESS column. Requires simple template edits. 
    55Plugin URI:  http://bbpress.org/plugins/topic/123 
    66Author: _ck_ 
    77Author URI: http://bbShowcase.org 
    8 Version: 0.0.2 
     8Version: 0.0.3 
    99*/ 
    1010 
     
    2222 
    2323function forum_last_topic_id($id = 0) { 
    24 global $forums_last_topic_id, $forum, $bbdb;  
     24global $forums_last_topic_id, $forum, $bbdb, $bb_topic_cache;  
    2525if (!$id) {$id=$forum->forum_id;} 
    26 if (!isset($forums_last_topic_id)) { 
    27 $last_topics = $bbdb->get_results("SELECT t1.forum_id as forum_id, t1.topic_id as topic_id FROM $bbdb->topics AS t1 LEFT JOIN $bbdb->topics AS t2 ON t1.forum_id=t2.forum_id AND t1.topic_time < t2.topic_time WHERE t1.topic_status=0 AND t2.forum_id IS NULL;"); 
    28 foreach ($last_topics as $forum_last_topic_id) {if ($temp=$forum_last_topic_id->forum_id) {$forums_last_topic_id[$temp]=$forum_last_topic_id->topic_id;}} 
    29 if (function_exists("post_count_plus")) {bb_cache_last_posts($forums_last_topic_id);}   // cache last poster name for links to last post 
     26if (!isset($forums_last_topic_id)) {    // unfortunately the join method does not handle deleted topics correctly and returns no results for that forum :-( 
     27// $last_topics = $bbdb->get_results("SELECT t1.forum_id as forum_id, t1.topic_id as topic_id FROM $bbdb->topics AS t1 LEFT JOIN $bbdb->topics AS t2 ON t1.forum_id=t2.forum_id AND t1.topic_time < t2.topic_time WHERE t1.topic_status=0 AND t2.forum_id IS NULL;"); 
     28$last_topics = $bbdb->get_results("SELECT forum_id, topic_id FROM $bbdb->topics WHERE topic_last_post_id IN (SELECT MAX(topic_last_post_id) FROM $bbdb->topics WHERE topic_status=0 GROUP BY forum_id)");  
     29foreach ($last_topics as $forum_last_topic_id) { 
     30        if ($temp=$forum_last_topic_id->forum_id) { 
     31                $forums_last_topic_id[$temp]=$forum_last_topic_id->topic_id; 
     32                if (!isset($bb_topic_cache[$forum_last_topic_id->topic_id])) {$add_cache[]->topic_id=$forum_last_topic_id->topic_id;} 
     33        } 
     34} if (!empty($add_cache)) {bb_cache_post_topics($add_cache);}   // cache topics not already in cache 
    3035} return $forums_last_topic_id[$id]; 
    3136} 
  • forum-last-poster/trunk/readme.txt

    r1204 r1290  
    77Donate link: http://amazon.com/paypage/P2FBORKDEFQIVM 
    88 
    9 Adds `forum_last_poster()` `forum_time()` and other functions to bbPress to mimic the topic tables' FRESHNESS column. Requires simple template edits. 
     9Adds `forum_last_poster()`, `forum_time()`, `forum_last_post_link()` and other functions to bbPress to mimic the topic tables' FRESHNESS column. Requires simple template edits. 
    1010 
    1111== Description == 
    1212 
    13 Adds `forum_last_poster()` `forum_time()` and other functions to bbPress to mimic the topic tables' FRESHNESS column. Requires simple template edits. 
     13Adds `forum_last_poster()`, `forum_time()`, `forum_last_post_link()` and other functions to bbPress to mimic the topic tables' FRESHNESS column. Requires simple template edits. 
    1414 
    15 High performance: requires only a single extra query regardless of the number of forums listed (when topics are on same page). 
     15High performance: uses only a single extra query regardless of the number of forums listed (when topics are on same page). 
    1616 
    1717== Installation == 
     
    3131<?php while ( bb_forum() ) : ?> 
    3232<tr<?php bb_forum_class(); ?>> 
    33         <td><?php bb_forum_pad( '<div class="nest">' ); ?><a href="<?php forum_link(); ?>"><?php forum_name(); ?></a><small><?php forum_description(); ?></small><?php bb_forum_pad( '</div>' ); ?></td> 
     33        <td class="num"><?php bb_forum_pad( '<div class="nest">' ); ?><a href="<?php forum_link(); ?>"><?php forum_name(); ?></a><small><?php forum_description(); ?></small><?php bb_forum_pad( '</div>' ); ?></td> 
    3434        <td class="num"><?php forum_time(); ?></td> 
    3535        <td class="num"><?php forum_topics(); ?></td> 
     
    7373* first public alpha release 
    7474 
     75= Version 0.0.3 (2008-08-16) = 
     76 
     77* unfortunately the join query does not handle deleted topics correctly and returns no results for that forum, so have to use subquery :-( 
     78 
    7579== To Do == 
    7680