Topic: Missing argument 2... for 'generate_avatar_markup'

I'm using an extension called 'ajax rating' that is generating this error in PunBB 1.4.1 ...

Warning: Missing argument 2 for generate_avatar_markup(), called in /home/.../toprated.php on line 140 and defined in /home/.../include/functions.php on line 500 
Warning: Missing argument 3 for generate_avatar_markup(), called in /home/.../toprated.php on line 140 and defined in /home/.../include/functions.php on line 500 
Warning: Missing argument 4 for generate_avatar_markup(), called in /home/.../toprated.php on line 140 and defined in /home/.../include/functions.php on line 500

This is the toprated.php code section that seems to be causing trouble;

    // Generate author identification
                    if ($cur_post['poster_id'] > 1)
                    {
                        if ($forum_config['o_avatars'] == '1' && $forum_user['show_avatars'] != '0')
                        {
                            $forum_page['avatar_markup'] = generate_avatar_markup($cur_post['poster_id']);

                            if (!empty($forum_page['avatar_markup']))
                                $forum_page['author_ident']['avatar'] = '<li class="useravatar">'.$forum_page['avatar_markup'].'</li>';
                        }

Anyone know what problem could be?
functions.php

// Outputs markup to display a user's avatar
function generate_avatar_markup($user_id, $avatar_type, $avatar_width, $avatar_height, $username = NULL, $drop_cache = FALSE)
{
    global $forum_config, $base_url;

    $avatar_markup = $avatar_filename = '';

    $return = ($hook = get_hook('fn_generate_avatar_markup_start')) ? eval($hook) : null;
    if ($return != null)
        return $return;

^new 1.4.1

old 1.3.6

// Outputs markup to display a user's avatar
function generate_avatar_markup($user_id)
{
    global $forum_config, $base_url;

    $filetypes = array('jpg', 'gif', 'png');
    $avatar_markup = '';

    $return = ($hook = get_hook('fn_generate_avatar_markup_start')) ? eval($hook) : null;
    if ($return != null)
        return $return;

    foreach ($filetypes as $cur_type)
    {
        $path = $forum_config['o_avatars_dir'].'/'.$user_id.'.'.$cur_type;

        if (file_exists(FORUM_ROOT.$path) && $img_size = @getimagesize(FORUM_ROOT.$path))
        {
            $avatar_markup = '<img src="'.$base_url.'/'.$path.'" '.$img_size[3].' alt="" />';
            break;
        }
    }

    ($hook = get_hook('fn_generate_avatar_markup_end')) ? eval($hook) : null;

    return $avatar_markup;
}

Re: Missing argument 2... for 'generate_avatar_markup'

PHP expects 6 arguments. You gave the first one and the last 2 are automatically filled in. You can give the function a default width, but you can also specify the parameters yourself. I recommend having a default width, that would be something like this:

// Outputs markup to display a user's avatar
function generate_avatar_markup($user_id = '', $avatar_type = '', $avatar_width = '100px', $avatar_height = '100px', $username = NULL, $drop_cache = FALSE)
{

I don't really understand the function though, it calls $img_size[3], but I don't really see it defined anywhere. But please try this first, perhaps there are other errors and we'll see. smile

Re: Missing argument 2... for 'generate_avatar_markup'

Nice, solved my problem, so this must be bug of 1.4.1 ? (as that file is original functions.php )

4 (edited by Grez 2011-12-28 15:57)

Re: Missing argument 2... for 'generate_avatar_markup'

@Dr. Deejay: $img_size was defined in the if statement (it's not really common, but you can do that).

@KeyDog: It isn't bug, but little incompatibility of this extension with 1.4.1. smile Information about avatars width / height are now stored in database, instead of counting each time when rendering.

//If I'll have some time to spare in the evening I might fix that, but you may try as well tongue You can find variables you need in punbb_users table wink

Eraversum - scifi browser-based online webgame

Re: Missing argument 2... for 'generate_avatar_markup'

Would be great, here the manifest.xml

and the fns.php

6 (edited by Grez 2011-12-29 01:17)

Re: Missing argument 2... for 'generate_avatar_markup'

Ok, so if I haven't done any typo then

changing this (line 187)

    \'SELECT\'    => \'a.rate, t.subject as topicsubj, p.topic_id, u.email, u.title, u.url, u.location, u.signature, u.email_setting, u.num_posts, u.registered, u.admin_note, p.id, p.poster AS username, p.poster_id, p.poster_ip, p.poster_email, p.message, p.hide_smilies, p.posted, p.edited, p.edited_by, g.g_id, g.g_user_title, o.user_id AS is_online\',

to this

    \'SELECT\'    => \'a.rate, t.subject as topicsubj, p.topic_id, u.email, u.title, u.url, u.location, u.signature, u.email_setting, u.num_posts, u.registered, u.admin_note, u.avatar, u.avatar_width, u.avatar_height, p.id, p.poster AS username, p.poster_id, p.poster_ip, p.poster_email, p.message, p.hide_smilies, p.posted, p.edited, p.edited_by, g.g_id, g.g_user_title, o.user_id AS is_online\',

and this (line 278)

                            $forum_page[\'avatar_markup\'] = generate_avatar_markup($cur_post[\'poster_id\']);

to this

                            $forum_page[\'avatar_markup\'] = generate_avatar_markup($cur_post[\'poster_id\'], $cur_post[\'avatar\'], $cur_post[\'avatar_width\'], $cur_post[\'avatar_height\'], $cur_post[\'poster\']);

in manifest.xml should do the trick smile

BTW this will make the extension crash on 1.3. so I suggest re-release it after these changes wink
BTW2 for this code to work you have to completely reinstall the extension, since it does create new file wink I haven't checked the code, but if it stores anything in db you'll have to backup that, or do manually changes in file ./toprated.php

Eraversum - scifi browser-based online webgame

Re: Missing argument 2... for 'generate_avatar_markup'

Thanks, pasted your code changes here:
http://pastebin.com/5YfA2ihT

I'm thinking it could be good to add the disabling negative responses (like in pun_karma  code)  lines 85 etc...

If anyone wants to add that and re-release - I'd be happy big_smile

Here's the current version, tested and working on 1.4.1 - Thanks Grez!
https://rapidshare.com/files/4161757740/ajax_rating.zip  or
http://www.mediafire.com/?tmxitruo2ibpl4e