patch: CPG and SMF avatars... patch: CPG and SMF avatars...
 

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

patch: CPG and SMF avatars...

Started by blackRock, April 19, 2007, 06:53:33 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

blackRock

With CPG 1.4.10 (with modpack) and SMF 1.1.2 bridged, only the avatars that are in the avatars folder of the forum are displayed in CPG's comments page.
The avatars that the users have uploaded are not.

I tried to solved it and I made a solution. When the users uploads a file for avatar, two things happen:
1. The 'avatar' column in 'smf_members' table is empty
2. A row is added in 'smf_attachments' with the id_member of the user recorded in the column 'id_member'. Only when the file is for the user's avatar there is a value greater than zero in this column!

The goal is to get this id_attach and use the link: ../forum/index.php?action=dlattach;type=avatar;id=id_attach as image source in the $avatar_url variable of the theme.inc.php file.

Here is the code I used:


if ($row['avatar_url'] == "") {
  $sql = "SELECT id_attach FROM smf_attachments WHERE id_member=".$row['author_id'];
  $attach_row = mysql_fetch_array(cpg_db_query($sql));
  $avatar_url= " <img src='../forum/index.php?action=dlattach;type=avatar;id=".$attach_row['id_attach']."' class='image' style='float: left; margin-right: 5px;' alt='' />";
}


I added this code after the closing tag of: if($cpg_udb->can_join()){
The code starts with:

if($cpg_udb->can_join()){
  if ($CONFIG['enable_avatar']){


Make sure that you put the correct path for the forum's index.php in the img tag.
I would consider the solution better if I could make the sql parametric in order not to have the table 'smf_attachment' fixed with the smf_ prefix. Let someone help please!

I hope this help you.

Stramm


blackRock

There are four cases for avatar in the SMF:

Open the file themes.inc.php in the include folder and find line 2429. Replace the code shown here:

//check joins
if($cpg_udb->can_join()){
if ($CONFIG['enable_avatar']){
        ($row['avatar_url'] != "") ? $avatar_url= "<img src='".AVATAR_PATH.$row["avatar_url"]."' class='image' style='float: left; margin-right: 5px;' alt='' />" : $avatar_url = '';
}
else $avatar_url="";
} else { // only used when tables can't be joined... then we need to query for the avatar URL -> function get_avatar
if ($CONFIG['enable_avatar']){
$result2 = $cpg_udb->get_avatar($row['author_id']);
$avatar_url= preg_replace('/\/\//','/',AVATAR_PATH.$result2["avatar_url"]);
        ($result2['avatar_url'] != "") ? $avatar_url= "<img src='".$avatar_url."' class='image' style='float: left; margin-right: 5px;' alt='' />" : $avatar_url = '';
}
else $avatar_url="";
}


with this code:

//check joins
if($cpg_udb->can_join()){
if ($CONFIG['enable_avatar']){
if ($row['avatar_url'] != "") {
// See if the avatar is a url
if (stristr($row['avatar_url'], 'http://')) {
$avatar_url= "<img src='".$row["avatar_url"]."' class='image' style='float: left; margin-right: 5px;' alt='' />";
}
else {
// it is in the avatars folder
$avatar_url= "<img src='".AVATAR_PATH.$row["avatar_url"]."' class='image' style='float: left; margin-right: 5px;' alt='' />";
} // end if - stristr($row['avatar_url'], 'http://')
} // end if - $row['avatar_url'] != ""
}
else {
$avatar_url=""; // no avatar info in the smf_members table
} // end if - $CONFIG['enable_avatar'
}
else { // only used when tables can't be joined... then we need to query for the avatar URL -> function get_avatar
if ($CONFIG['enable_avatar']){
$result2 = $cpg_udb->get_avatar($row['author_id']);
if ($result2['avatar_url'] != "") {
// See if the avatar is a url
if (stristr($row['avatar_url'], 'http://')) {
$avatar_url= "<img src='".$result2["avatar_url"]."' class='image' style='float: left; margin-right: 5px;' alt='' />";
}
else {
// it is in the avatars folder
$avatar_url= preg_replace('/\/\//','/',AVATAR_PATH.$result2["avatar_url"]);
$avatar_url= "<img src='".$avatar_url."' class='image' style='float: left; margin-right: 5px;' alt='' />";
} // end if - stristr($row['avatar_url'], 'http://')
}
else {
$avatar_url = "";
} // end if - $result2['avatar_url'] != ""
} // end if - $CONFIG['enable_avatar'
else $avatar_url="";
} // end if - $cpg_udb->can_join()

// If the $avatar_url is still empty, maybe the user has upload one
if ($row['avatar_url'] == "") {
$sql = "SELECT id_attach FROM smf_attachments WHERE id_member=".$row['author_id'];
$attach_row = mysql_fetch_array(cpg_db_query($sql));
if ($attach_row['id_attach'] != "") {
$avatar_url= $id_attach." <img src='../forum/index.php?action=dlattach;type=avatar;id=".$attach_row['id_attach']."' class='image' style='float: left; margin-right: 5px;' alt='' />";
}
else $avatar_url = "";
}


This code will show avatar (if there is one) for all the cases I've metioned before.

Riox

Thanks for your efforts. Unfortunately I already use SMF 1.1.4 and CPG 1.4.13 modpack v2

As soon as there are comments for a picture I get a "Critical error - There was an error while processing a database query".
It doesn’t matter if the users have an avatar or not so I guess they made some changes to the DB structure. Sadly I don’t have access to the SQL-error-logs :/

caiboy

I would consider the solution better if I could make the sql parametric in order not to have the table 'smf_attachment' fixed with the smf_ prefix. Let someone help please!
wow geld|wow gold|world of warcraft geld|wow geld kauf|wow geld kaufen|billig wow gold

Joachim Müller

Stop the board spam - nobody asked for multiple links to your page >:(