1
3lr0n
Re: How to put avatars in forum blocks
  • 2010/9/10 22:54

  • 3lr0n

  • Not too shy to talk

  • Posts: 167

  • Since: 2004/3/13


Done!

For all of you that want to have this feature I explain the steps.

1- Include in /include/functions.php the getAvatarFromIds, cloned from getUnameFromIds.
function getAvatarFromIds($uid$usereal false)
    {
        if (!
is_array($uid)) {
            
$uid = array($uid);
        }
        
$userid array_map('intval'array_filter($uid));

        
$myts =& MyTextSanitizer::getInstance();
        
$avatars = array();
        if (
count($userid) > 0) {
            
$xoopsDB =& XoopsDatabaseFactory::getDatabaseConnection();
            
$sql 'SELECT uid, user_avatar FROM ' $xoopsDB->prefix('users') . ' WHERE level > 0 AND uid IN(' implode(','array_unique($userid)) . ')';
            if (!
$result $xoopsDB->query($sql)) {
                return 
$avatars;
            }
            while (
$row $xoopsDB->fetchArray($result)) {
                
$uid $row['uid'];
                
$avatars[$uid] = $myts->htmlSpecialChars($row['user_avatar']);

                }

           }

        return 
$avatars;
    }


2-Open /modules/newbb/blocks/newbb_block.php. There are 3 functions, one called b_newbb_show for recent answered topic, b_newbb_topic_show for last topics and b_newbb_post_show for last posts. All works the same in this modification, but you have to modify each function in order to have the hack running in all the three blocks.

Find in each
$author_name newbb_getUnameFromIds(array_keys($author), $newbbConfig['show_realname'], true);


After add

$author_avatar getAvatarFromIds(array_keys($author));


And now for b_newbb_show and b_newbb_post_show find

$topic['topic_poster'] = $topic_poster;


and after add
if (!empty($author_avatar[$arr['uid']])) {
            
$topic_avatar $author_avatar[$arr['uid']];
        } else {
            
$topic_avatar '';
        }
        
$topic['topic_avatar'] = $topic_avatar;


for b_newbb_topic_show find

$topic['topic_poster'] = $topic_poster;


and after add

if (!empty($author_avatar[$arr['topic_poster']])) {
            
$topic_avatar $author_avatar[$arr['topic_poster']];
        } else {
            
$topic_avatar '';
        }
        
$topic['topic_avatar'] = $topic_avatar;


3-Finally add to your templates located in /modules/newbb/templates/blocks/ this code to show the new smarty variable.

<img src="<{$xoops_url}>/uploads/<{$topic.topic_avatar}>" alt="avatar" />


To have all the avatars same size and shape I use smart resizer.

Hope you find this useful.

Demo here, the red block in the bottom of the page.

PS: Thks guia for the help




Spanish Overclocking Community xoops based site : www.overclocking.es



2
3lr0n
How to put avatars in forum blocks
  • 2010/9/10 13:36

  • 3lr0n

  • Not too shy to talk

  • Posts: 167

  • Since: 2004/3/13


Hello, I need some help to display the author avatar in last posts and last topics newbb blocks.

The things I did.

1. create a new function on /include/functions.php to get avatar from a given Id.

function getAvatarFromId($userid$usereal 0)
    {
        
$userid intval($userid);
        
$usereal intval($usereal);
        if (
$userid 0) {
            
$member_handler = & xoops_gethandler('member');
            
$user =& $member_handler->getUser($userid);
            if (
is_object($user)) {
                
$ts =& MyTextSanitizer::getInstance();
                if (
$usereal) {
                    
$avatar $user->getVar('user_avatar');
                    if (
$avatar != '') {
                        return 
$ts->htmlSpecialChars($avatar);
                    } else {
                        return 
$ts->htmlSpecialChars($user->getVar('user_avatar'));
                    }
                } else {
                    return 
$ts->htmlSpecialChars($user->getVar('user_avatar'));
                }
            }
        }
       
    }


Cloned from getunamefromid with some modifications.

2. in newbb/blocks/newbb_block.php in the function b_newbb_topic_show in this section

$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,'.
            
'    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'.
            
'    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);


include this line just after the getunamefromids array

$author_avatar getAvatarFromId(array_keys($author));


so i have an array of the avatars for each id

But i cant pass it to smarty wit this

$topic['avatar'] = $author_avatar[$arr['topic_subject']];


I suppose it is because the $arr is an array created from $rows and this inherit the number of colums created in the $query and $result variables.

Bus as I am not a programmer dont know how to pass it to smarty so I can have a variable like this: <{$topic.avatar}> or what ever..

Any help

Thks

Spanish Overclocking Community xoops based site : www.overclocking.es



3
3lr0n
Re: forum block users avatar
  • 2010/6/21 14:51

  • 3lr0n

  • Not too shy to talk

  • Posts: 167

  • Since: 2004/3/13


I mean,

the problem is in the code of the blocks only are checking the newbb tables, there is no user object to access atributes, like avatar.

I think a function to retrieve the user avatar if you have the user uid should be easy for a programmer, but Iam not and Iam a bit lost. Is there a fuction allready present in the xoops core for do this..

I only need the name of the file

regards
Spanish Overclocking Community xoops based site : www.overclocking.es



4
3lr0n
Re: forum block users avatar
  • 2010/6/21 5:12

  • 3lr0n

  • Not too shy to talk

  • Posts: 167

  • Since: 2004/3/13


In index.php? where?

I was checking newbb_block.php to see where the poster avatar was generated, but i didnt find it.

Spanish Overclocking Community xoops based site : www.overclocking.es



5
3lr0n
forum block users avatar
  • 2010/6/20 21:46

  • 3lr0n

  • Not too shy to talk

  • Posts: 167

  • Since: 2004/3/13


Hi,

I want to show the avatar of the user who made the post in the newbb last post block..

Is there a way to have it?

Thks
Spanish Overclocking Community xoops based site : www.overclocking.es



6
3lr0n
Re: quality resized avatars and top users
  • 2010/6/20 21:04

  • 3lr0n

  • Not too shy to talk

  • Posts: 167

  • Since: 2004/3/13


After looking for it I cant find where the post/comments variable is set in the code.

I mean, cant find where is the code that check how many forum post and how many comments does a user have.

Im planning to replace it with a code to check the points of a certain user in mypoints module.

Any help?

thks
Spanish Overclocking Community xoops based site : www.overclocking.es



7
3lr0n
Re: quality resized avatars and top users
  • 2010/6/20 12:14

  • 3lr0n

  • Not too shy to talk

  • Posts: 167

  • Since: 2004/3/13


This solution is good, but with the script is enough for my needs and is croosmodule usable.

The second point.. Iam going to try to swap the way the system calculate all the messages in forums and comments sent by users and bypass this data with the one present in mypoints module. So the new data will be the users points.

With this i can set any points for any message or contribution, for example 5 points for every piece of news, 100 points fors every comment.. etc..

I will check the code to find where the messages send is calculated, but if someone can help me would be great.

Regards
3lr0n
Spanish Overclocking Community xoops based site : www.overclocking.es



8
3lr0n
Re: quality resized avatars and top users
  • 2010/6/20 10:45

  • 3lr0n

  • Not too shy to talk

  • Posts: 167

  • Since: 2004/3/13


Point one solved..

using this amazing code

http://shiftingpixel.com/2008/03/03/smart-image-resizer/
Spanish Overclocking Community xoops based site : www.overclocking.es



9
3lr0n
quality resized avatars and top users
  • 2010/6/19 22:30

  • 3lr0n

  • Not too shy to talk

  • Posts: 167

  • Since: 2004/3/13


Hi,

I have a 2 questions:

1. Have xoops any way to resize images with php. I mean, I plan to use the top users block of the system module, but the avatar resized setting the width and height look really poor in quality. So I thought if xoops can dinamically resize the avatars to show them with a certain width and height.

2. The top users show only the forum posts. How can I set this to count the sent news and other colaborations?

Ta in advance.
3lr0n
Spanish Overclocking Community xoops based site : www.overclocking.es



10
3lr0n
Re: problem with img tag and caricafoto
  • 2010/5/16 22:06

  • 3lr0n

  • Not too shy to talk

  • Posts: 167

  • Since: 2004/3/13


solved

I check the code and find in module.textsanitizer this line that i have added in the old instalation to allow IMG tag in caps.

$patterns[] = "/[IMG]([^"()?&'<>]*)[/IMG]/sU";


As in 2.4.4 the image replacements are made in another file this was causing the problem.

Thks for all

Hope soon you can see the version 2.0 of my site ;)
Spanish Overclocking Community xoops based site : www.overclocking.es




TopTop
(1) 2 3 4 ... 15 »



Login

Who's Online

241 user(s) are online (178 user(s) are browsing Support Forums)


Members: 0


Guests: 241


more...

Donat-O-Meter

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

Latest GitHub Commits