1
LiliVG
Hack to show users avatars in CBB blocks?
  • 2006/11/13 4:55

  • LiliVG

  • Just popping in

  • Posts: 65

  • Since: 2005/12/25


Can someone please show me how to do this? It would be very much appreciated! Thank you!

2
LiliVG
Re: Hack to show users avatars in CBB blocks?
  • 2006/11/16 7:50

  • LiliVG

  • Just popping in

  • Posts: 65

  • Since: 2005/12/25


Ok, I got the user avatars to show up on the CBB Recent Topics, and Recent Topic Replies blocks (CBB 3.07). I could probably add it to the recent posts one too, I just don't use that block on my site, so I didn't bother. But here's the hacks for those two if anyone's interested:

In newbb/blocks/newbb_block.php:
function b_newbb_show($options) (this is the function for the block that shows recently replied topics) Add the lines in red (there are 3):
function b_newbb_show($options)
{
    global 
$xoopsConfig;
    global 
$access_forums;

    
$db =& Database::getInstance();
    
$myts =& MyTextSanitizer::getInstance();
    
$block = array();
    
$i 0;
    
$order "";
    
$extra_criteria "";
    if(!empty(
$options[2])) {
        
$time_criteria time() - newbb_getSinceTime($options[2]);
        
$extra_criteria " AND p.post_time>".$time_criteria;
    }
    
$time_criteria null;
    switch (
$options[0]) {
        case 
'time':
        default:
            
$order 'p.post_time';
            
$extra_criteria .= " AND p.approved=1";
            break;
    }
    
$newbbConfig getConfigForBlock();
                
    if(!isset(
$access_forums)){
        
$forum_handler =& xoops_getmodulehandler('forum''newbb');
        if(!
$access_obj =& $forum_handler->getForums(0'access', array('forum_id''cat_id''forum_type')) ){
            return 
null;
        }
        
$access_forums array_keys$access_obj ); // get all accessible forums
        
unset($access_obj );
    }
    if (!empty(
$options[6])) {
        
$allowedforums array_filter(array_slice($options6), "b_newbb_array_filter"); // get allowed forums
        
$allowed_forums array_intersect($allowedforums$access_forums);
    }else{
        
$allowed_forums $access_forums;
    }

    
$forum_criteria ' AND t.forum_id IN (' implode(','$allowed_forums) . ')';
    
$approve_criteria ' AND t.approved = 1';

    
$query 'SELECT'.
            
'    DISTINCT t.topic_id, t.topic_replies, t.forum_id, t.topic_title, t.topic_views, t.topic_subject,'.
            
'    f.forum_name, f.allow_subject_prefix,'.

[
color=FF0000]
            
'    u.user_avatar,'.
[/
color]

            
'    p.post_id, p.post_time, p.icon, p.uid, p.poster_name'.
            
'    FROM ' $db->prefix('bb_posts') . ' AS p '.
            
'    LEFT JOIN ' $db->prefix('bb_topics') . ' AS t ON t.topic_last_post_id=p.post_id'.
            
'    LEFT JOIN ' $db->prefix('bb_forums') . ' AS f ON f.forum_id=t.forum_id'.

[
color=FF0000]
                
'    LEFT JOIN ' $db->prefix('users') . ' AS u ON u.uid=p.uid'.
[/
color]

            
'    WHERE 1=1 ' .
                
$forum_criteria .
                
$approve_criteria .
                
$extra_criteria .
                
' ORDER BY ' $order ' DESC';


    
$result $db->query($query$options[1], 0);
    if (!
$result) {
        
newbb_message("newbb block query error: ".$query);
        return 
false;
    }
    
$block['disp_mode'] = $options[3]; // 0 - full view; 1 - compact view; 2 - lite view;
    
$rows = array();
    
$author = array();
    while (
$row $db->fetchArray($result)) {
        
$rows[] = $row;
        
$author[$row["uid"]] = 1;
    }
    if (
count($rows) < 1) return false;
    
$author_name newbb_getUnameFromIds(array_keys($author), $newbbConfig['show_realname'], true);

    foreach (
$rows as $arr) {
        
$topic_page_jump '';
        if (
$arr['allow_subject_prefix']) {
            
$subjectpres explode(','$newbbConfig['subject_prefix']);
            if (
count($subjectpres) > 1) {
                foreach(
$subjectpres as $subjectpre) {
                    
$subject_array[] = $subjectpre;
                }
                   
$subject_array[0] = null;
            }
            
$topic['topic_subject'] = $subject_array[$arr['topic_subject']];
        } else {
            
$topic['topic_subject'] = "";
        }
        
$topic['post_id'] = $arr['post_id'];
        
$topic['forum_id'] = $arr['forum_id'];
        
$topic['forum_name'] = $myts->htmlSpecialChars($arr['forum_name']);
        
$topic['id'] = $arr['topic_id'];

[
color=FF0000]
        
$topic['poster_avatar'] = $arr['user_avatar'];
[/
color]

        
$title $myts->htmlSpecialChars($arr['topic_title']);
        if(!empty(
$options[5])){
            
$title xoops_substr($title0$options[5]);
        }
        
$topic['title'] = $title;
        
$topic['replies'] = $arr['topic_replies'];
        
$topic['views'] = $arr['topic_views'];
        
$topic['time'] = newbb_formatTimestamp($arr['post_time']);
        if (!empty(
$author_name[$arr['uid']])) {
            
$topic_poster $author_name[$arr['uid']];
        } else {
            
$topic_poster $myts->htmlSpecialChars( ($arr['poster_name'])?$arr['poster_name']:$GLOBALS["xoopsConfig"]["anonymous"] );
        }

        
$topic['topic_poster'] = $topic_poster;
        
$topic['topic_page_jump'] = $topic_page_jump;
        
$block['topics'][] = $topic;
        unset(
$topic);

    }
    
$block['indexNav'] = intval($options[4]);


    return 
$block;
}




And for function b_newbb_topic_show($options) (shows the most recently created topics) within the same file (also 3 lines, very similar to the first 3):
function b_newbb_topic_show($options)
{
    global 
$xoopsConfig;
    global 
$access_forums;

    
$db = &Database::getInstance();
    
$myts = &MyTextSanitizer::getInstance();
    
$block = array();
    
$i 0;
    
$order "";
    
$extra_criteria "";
    
$time_criteria null;
    if(!empty(
$options[2])) {
        
$time_criteria time() - newbb_getSinceTime($options[2]);
        
$extra_criteria " AND t.topic_time>".$time_criteria;
    }
    switch (
$options[0]) {
        case 
'views':
            
$order 't.topic_views';
            break;
        case 
'replies':
            
$order 't.topic_replies';
            break;
        case 
'digest':
            
$order 't.digest_time';
            
$extra_criteria " AND t.topic_digest=1";
            if(
$time_criteria)
            
$extra_criteria .= " AND t.digest_time>".$time_criteria;
            break;
        case 
'sticky':
            
$order 't.topic_time';
            
$extra_criteria .= " AND t.topic_sticky=1";
            break;
        case 
'time':
        default:
            
$order 't.topic_time';
            break;
    }
    
$newbbConfig getConfigForBlock();

    if(!isset(
$access_forums)){
        
$forum_handler =& xoops_getmodulehandler('forum''newbb');
        if(!
$access_obj =& $forum_handler->getForums(0'access', array('forum_id''cat_id''forum_type')) ){
            return 
null;
        }
        
$access_forums array_keys$access_obj ); // get all accessible forums
        
unset($access_obj );
    }

    if (!empty(
$options[6])) {
        
$allowedforums array_filter(array_slice($options6), "b_newbb_array_filter"); // get allowed forums
        
$allowed_forums array_intersect($allowedforums$access_forums);
    }else{
        
$allowed_forums $access_forums;
    }

    
$forum_criteria ' AND t.forum_id IN (' implode(','$allowed_forums) . ')';
    
$approve_criteria ' AND t.approved = 1';

    
$query 'SELECT'.
            
'    t.topic_id, t.topic_replies, t.forum_id, t.topic_title, t.topic_views, t.topic_subject, t.topic_time, t.topic_poster, t.poster_name,'.

[
color=FF0000]
            
'    u.user_avatar,'.
[/
color]

            
'    f.forum_name, f.allow_subject_prefix'.
            
'    FROM ' $db->prefix('bb_topics') . ' AS t '.
            
'    LEFT JOIN ' $db->prefix('bb_forums') . ' AS f ON f.forum_id=t.forum_id'.

[
color=FF0000]
                
'    LEFT JOIN ' $db->prefix('users') . ' AS u ON u.uid=t.topic_poster'.
[/
color]

            
'    WHERE 1=1 ' .
                
$forum_criteria .
                
$approve_criteria .
                
$extra_criteria .
                
' ORDER BY ' $order ' DESC';

    
$result $db->query($query$options[1], 0);
    if (!
$result) {
        
newbb_message("newbb block query error: ".$query);
        return 
false;
    }
    
$block['disp_mode'] = $options[3]; // 0 - full view; 1 - compact view; 2 - lite view;
    
$rows = array();
    
$author = array();
    while (
$row $db->fetchArray($result)) {
        
$rows[] = $row;
        
$author[$row["topic_poster"]] = 1;
    }
    if (
count($rows) < 1) return false;
    
$author_name newbb_getUnameFromIds(array_keys($author), $newbbConfig['show_realname'], true);

    foreach (
$rows as $arr) {
        
$topic_page_jump '';
        if (
$arr['allow_subject_prefix']) {
            
$subjectpres explode(','$newbbConfig['subject_prefix']);
            if (
count($subjectpres) > 1) {
                foreach(
$subjectpres as $subjectpre) {
                    
$subject_array[] = $subjectpre;
                }
                   
$subject_array[0] = null;
            }
            
$topic['topic_subject'] = $subject_array[$arr['topic_subject']];
        } else {
            
$topic['topic_subject'] = "";
        }
        
$topic['forum_id'] = $arr['forum_id'];
        
$topic['forum_name'] = $myts->htmlSpecialChars($arr['forum_name']);
        
$topic['id'] = $arr['topic_id'];

[
color=FF0000]
        
$topic['poster_avatar'] = $arr['user_avatar'];
[/
color]

        
$title $myts->htmlSpecialChars($arr['topic_title']);
        if(!empty(
$options[5])){
            
$title xoops_substr($title0$options[5]);
        }
        
$topic['title'] = $title;
        
$topic['replies'] = $arr['topic_replies'];
        
$topic['views'] = $arr['topic_views'];
        
$topic['time'] = newbb_formatTimestamp($arr['topic_time']);
        if (!empty(
$author_name[$arr['topic_poster']])) {
            
$topic_poster $author_name[$arr['topic_poster']];
        } else {
            
$topic_poster $myts->htmlSpecialChars( ($arr['poster_name'])?$arr['poster_name']:$GLOBALS["xoopsConfig"]["anonymous"] );
        }
        
$topic['topic_poster'] = $topic_poster;
        
$topic['topic_page_jump'] = $topic_page_jump;
        
$block['topics'][] = $topic;
        unset(
$topic);
    }
    
$block['indexNav'] = intval($options[4]);

    return 
$block;
}



Then, you will be able to add this code to newbb/templates/blocks/newbb_block.html and newbb/templates/blocks/newbb_block_topic.html wherever you want the posters' avatars to appear in the template:

<img src="<{xoops_url}>/uploads/<{topic.poster_avatar}>" width="50px" alt="" />


And you're done!

3
alittlemisfi
Re: Hack to show users avatars in CBB blocks?

speaking of template in forum.. how to show the last post title on the forum main page? i'm a newbie here... using newbb 2
Thanks!


Resized Image

4
alittlemisfi
Re: Hack to show users avatars in CBB blocks?

anyone? help? please?

5
Cozzie
Re: Hack to show users avatars in CBB blocks?
  • 2008/6/23 4:03

  • Cozzie

  • Not too shy to talk

  • Posts: 133

  • Since: 2007/7/13


Great stuff and thanks for posting this - saved me loads of time

Just to say the final code is missing the necessary smarty '$' signs and should be:



thanks again!

Login

Who's Online

388 user(s) are online (271 user(s) are browsing Support Forums)


Members: 0


Guests: 388


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits