Avatar in comments w/o modpack Avatar in comments w/o modpack
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

Avatar in comments w/o modpack

Started by mahdi1234, September 23, 2009, 10:33:25 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

mahdi1234

Hi there,

I wanted to include avatar in comments on my site, but wasn't happy about installing whole modpack nor using customprofile built-in coppermine. Reasons for this are complexity for former and not-much-flexibility for latter.

So I decided to come up with something on my own, yet simple. Here you go:

First create any folder in your coppermine install or anywhere else on your website with write access to store avatars. Then edit avatar.php for

$target_dir - path where your avatars would reside
if ($mime != 'image/jpeg') - filetype you would allow
elseif ($temp_file_size > 10240) - maximum filesize
elseif ($imagewidth != '50' || $width != '50') - dimensions of image

Once done you can copy over to root of your cpp and access at cpp.tld/avatar.php - should everything go well you can now upload avatars. All uploaded files are automatically renamed to user ID of current user.

Now let's integrate avatars into comments editing theme.php

Find function theme_html_comments($pid) (if not present copy over from sample theme)

replace
       
$params = array('{MSG_AUTHOR}' => stripslashes($row['msg_author']),
            '{MSG_ID}' => $row['msg_id'],
            '{MSG_AUTHOR_ID}' => $row['author_id'],
            '{PID}' => $row['pid'],
            '{EDIT_TITLE}' => &$lang_display_comments['edit_title'],
            '{CONFIRM_DELETE}' => &$lang_display_comments['confirm_delete'],
            '{MSG_DATE}' => localised_date($row['msg_date'], $comment_date_fmt),
            '{MSG_BODY}' => bb_decode($comment_body),
            '{MSG_BODY_RAW}' => $row['msg_body'],
            '{OK}' => &$lang_display_comments['OK'],
            '{SMILIES}' => $smilies,
            '{IP}' => $ip,
            '{REPORT_COMMENT_TITLE}' => &$lang_display_comments['report_comment_title'],
            '{WIDTH}' => $CONFIG['picture_table_width'],
            );

with

        $params = array('{MSG_AUTHOR}' => stripslashes($row['msg_author']),
            '{MSG_ID}' => $row['msg_id'],
            '{MSG_AUTHOR_ID}' => $row['author_id'],
            '{PID}' => $row['pid'],
            '{EDIT_TITLE}' => &$lang_display_comments['edit_title'],
            '{CONFIRM_DELETE}' => &$lang_display_comments['confirm_delete'],
            '{MSG_DATE}' => localised_date($row['msg_date'], $comment_date_fmt),
            '{MSG_BODY}' => bb_decode($comment_body),
            '{MSG_BODY_RAW}' => $row['msg_body'],
            '{OK}' => &$lang_display_comments['OK'],
            '{SMILIES}' => $smilies,
            '{IP}' => $ip,
            '{REPORT_COMMENT_TITLE}' => &$lang_display_comments['report_comment_title'],
            '{WIDTH}' => $CONFIG['picture_table_width'],
            '{AVATAR}' => $row['author_id'].'.jpg'
            );


Find $template_image_comments = <<<EOT

and based on your theme put where it fits

<img src="avatar/{AVATAR}">


Now avatar shall display in comments. You can see this in action here - http://fotoluzr.net/displayimage.php?pos=-1508 - note not all members uploaded theirs yet, so those who didn't have empty space next to left (I did not want to force some default avatar here, but you can).

I've also modified user profile, to have direct access from their profile to change avatar - though keep in mind this is modification of core file. It's up to you whether you include in menu or wherever. Here's my mod to profile.php -

Find function get_post_var($var)

replace

        echo <<<EOT

    <tr>
        <td colspan="2" align="center" class="tablef">
            <input type="submit" name="change_profile" value="{$lang_register_php['apply_modif']}" class="button" />
            <img src="images/spacer.gif" width="20" height="1" border="0" alt="" />
            <input type="submit" name="change_pass" value="{$lang_register_php['change_pass']}" class="button" />
        </td>
    </tr>


with

global $USER_DATA;
$current_user = $USER_DATA['user_id'];
$avatar = 'avatar/' . $current_user . '.jpg';

if (! file_exists($avatar)) {
$avatar = 'avatar/unset.jpg';
}

        echo <<<EOT

    <tr>
        <td colspan="2" align="center" class="tablef" valign="center">
<a href="avatar.php"><img src="$avatar" border="0"></a>
        </td>
    </tr>
    <tr>
        <td colspan="2" align="center" class="tablef">
            <input type="submit" name="change_profile" value="{$lang_register_php['apply_modif']}" class="button" />
            <img src="images/spacer.gif" width="20" height="1" border="0" alt="" />
            <input type="submit" name="change_pass" value="{$lang_register_php['change_pass']}" class="button" />
        </td>
    </tr>


This will display user avatars in profile and for those with unset avatar show up unset.jpg - clicking on this will bring them to page to upload avatar - see attached profile.jpg.

Hope this helps to someone.

PS - Since I'm no php coder nor coder at all, I would appreciate someone more experienced having look into those changes whether it's secure enough.

cheers,
mahdi