Unknown Coward Unknown Coward
 

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

Unknown Coward

Started by klewless, June 19, 2016, 09:22:23 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

klewless

I have just done an upgrade  to the latest CPG version, bridged it to my forum (SMF 2.011 with TP installed).

I had a certain number of albums left behind by former users of the gallery and forum (which is bridged to it). Their images are still there but they bear the label "unknown coward" as album owner. Their albums do not appear on the albums list. What shall I do to remove the "coward" label. The folks in question are actually nice people who have moved onto other things, but were kind enough not to delete their pictures, which we have enjoyed for a long time.

Also the images are "turning up" at random in some other members' galleries.

Thanks in advance!


Αndré

To change the "coward", have a look at the language file(s) in the "lang" directory and search for:
$lang_common['username_if_blank']

To fix the reason why this happens, we need more information. I assume the users who uploaded those pictures in the past have deleted their account in your board? From which Coppermine version did you upgraded from? A link to your gallery may also help.

klewless

Andre,

Good morning!

My gallery is in maintenance mode right now, sorry. Thanks for the help though; I will at least remove the insulting title.

I honestly do not think this is a version specific problem, because it was the same on 1410, our old version. On that version, the missing member would be called Mr. X, not "unknown coward"

You are correct about what is happening: the gallery member list was fine before I bridged it, but once bridged, if the member no longer has an account on the forum, the pictures seem to have nowhere to go.

I looked in the database..... it goes by member number (10106, 10109, etc) there and the user info is still all there. But because the member names and accounts are coming from SMF, if it does not find a match, it calls the person Unknown Coward. I can fix that now but what to do with the albums.... hmmm.....

I wonder if I should create new accounts on SMF for those people, create new albums in the gallery,  and move the pictures to the new albums? Would I lose all the peripheral info (stats, hits,comments etc.)? Should I transfer the info in the database to the new row for the new album? Who would own the new account?

Αndré

I think I'd adjust the user ID in the pictures table to the user ID which corresponds to "guest" (i.e. "0") and then either move all affected files to one album or, if you want/need to keep the files in their albums, adjust the album permissions (or whatever is currently wrong).

I assume the affected albums/pictures were created in the "user galleries" category (ID "1)? If so, I need to have a look at the code what exactly Coppermine does if the user doesn't exist anymore.

klewless

Hi Andre,

Good.

I like the idea of doing this with php better than renaming etc. There has to be something. Some sort of "if userID exists / else"? After all it does something with the pictures i.e. doies not ignore them altogether.  Unf ortunately I am at  but I will have a look during lunch break or when I am home.

Thanks again


Αndré

If you need more detailed help, I need to have a look at your gallery and your MySQL database. Let me know.

klewless

Sorry, how can I PM or contact you please?



Αndré


klewless

People who are reading this out of curiosity might be reminded here that you can delete an account (user) on the SMF board but it does not delete their gallery. I think part of the reason I have this problem is my own fault. I have not kept on top of the users in Coppermine like I do on SMF, somehow, I thought that both accounts would be deleted. Not so.

Over the weekend I decided to clean up the albums/userpics file and data base. I found there were dozens of empty albums in userpics, which I  deleted, along with the matching albums in the albums database, if they were still there. In most cases, the empty albums were no longer in the database, but there were a few empties belonging to people who were members (I think in those cases they were people who decided to open an album for themselves but had some trouble with it). I also looked over albums/userpics and made a list of the userpics folders that did not correspond to an album in the database. There were around a dozen that still have pictures in them, that we want to keep.

Doing this pruning seems to have eliminated one of the empty pages at the end of the ember albums search. That means my theory that the "empty" pages were for member pics that did not match up with current users, is correct.

Thanks in advance.

Αndré

I just created 2 test users and created an album for each of them in their personal gallery. Then, I deleted 1 user directly in the MySQL database to simulate a deleted user in your board. When I now open the orphaned picture, Coppermine displays this category/album path:
QuoteHome > User galleries > Unknown coward > album of test2

You said the picture is moved to the album of another user when you update something. And here's the reason: on the "Edit file" page there's a dropdown menu where you can select the album which the pictures is assigned to. If the current album doesn't exist, your browser automatically selects the first available item. So when you now submit the form, Coppermine moves the picture to another album.

Actually, the album of the former user still exists, but Coppermine doesn't add it to the album dropdown, if the user doesn't exist. I'll have a closer look at the code how to fix this.

klewless

Awesome. About the picture showing up in another album... suspected as much.

I am at work now with limited access.

thanks soooo much.

Αndré

To include the albums of former users in the album dropdown, please try the following. Open include/functions.inc.php, find
            foreach ($users as $user) {
                if (!empty($albums[$user['user_id'] + FIRST_USER_CAT])) {
                    $options .= '<optgroup label="&nbsp;&nbsp;&nbsp;&nbsp;' . $user['user_name'] . '">' . $LINEBREAK;
                    foreach ($albums[$user['user_id'] + FIRST_USER_CAT] as $aid => $title) {
                        $options .= sprintf('<option value="%d"%s>%s</option>' . $LINEBREAK, $aid, $aid == $selected ? ' selected="selected"' : '', '&nbsp;&nbsp;&nbsp;&nbsp;'.$title);
                    }
                    $options .= '</optgroup>';
                }
            }

and replace with
            $user_categories = array();
            foreach ($users as $user) {
                $user_categories[] = $user['user_id'] + FIRST_USER_CAT;
                if (!empty($albums[$user['user_id'] + FIRST_USER_CAT])) {
                    $options .= '<optgroup label="&nbsp;&nbsp;&nbsp;&nbsp;' . $user['user_name'] . '">' . $LINEBREAK;
                    foreach ($albums[$user['user_id'] + FIRST_USER_CAT] as $aid => $title) {
                        $options .= sprintf('<option value="%d"%s>%s</option>' . $LINEBREAK, $aid, $aid == $selected ? ' selected="selected"' : '', '&nbsp;&nbsp;&nbsp;&nbsp;'.$title);
                    }
                    $options .= '</optgroup>';
                }
            }

            // search for albums of non-existing members
            foreach ($albums as $key => $value) {
                if ($key > FIRST_USER_CAT) {
                    if (!in_array($key, $user_categories)) {
                        $options .= '<optgroup label="&nbsp;&nbsp;&nbsp;&nbsp;' . $lang_common['username_if_blank'] . ' ' . ($key - FIRST_USER_CAT) . '">' . $LINEBREAK;
                        foreach ($albums[$key] as $aid => $title) {
                            $options .= sprintf('<option value="%d"%s>%s</option>' . $LINEBREAK, $aid, $aid == $selected ? ' selected="selected"' : '', '&nbsp;&nbsp;&nbsp;&nbsp;'.$title);
                        }
                        $options .= '</optgroup>';
                    }
                }
            }


I initially thought to add all orphaned albums in one group, but then used the "unknown coward" string and added their user ID to it. However, there are 3 possibilities to add the albums to the album dropdown:
1. Put all orphaned albums in one group, after the existing users
2. Put all orphaned albums of each former user after the existing users (that's how it currently works)
3. Put all orphaned albums of each former user along with the existing users and sort them by user ID

I need to think some time about this, but I currently (again) tend to option 1 :D

klewless

How will the orphaned albums appear when someone waants to view the albums list?

L.

klewless

Hi Andre,

I added the code as suggested and it seems to work. (and thank you for telling me what file this is located in, I would never have found it).

At the end of the drop-down menu, there is now a very long list, not in numerical order, of Former Members, with their albums listed below.

On the gallery the pictures are visible, but not the albums' cover thumbnails, if you are looking at the Member Albums list. There are now four or five blank pages at the end of Member Galleries..

The funny thing is I went through and deleted the empty albums, and checked the data base for the user account if I deleted the user's empty folder from albums/userpix. Perhaps there is more member info in one of the other tables in the database, that I have to delete as well as what I did so far.

:) :)



I would like to see the album

klewless

Just as an aside, we had lots of misplaced pictures, about 40 of them, which happened while I was adding key words to them, and they were reassigned to the wrong album, as described in the above posts. Andre's code, above, will fix future problems but the misplaced pictures will remain where they are, unless you intervene . I didn't want to unbridgle my gallery cos we have a custom menu installation being worked on right now, so I had to do the following:

So when a picture is accidentally assigned to the wrong album you must go to the CPG database and look at the Users table, locate its owner, (the userID is shown) Locate the column called "aid" for the user's album ID number) . You will also need the album number of the place where the pictures wound up (the user is visible on the breadcrumbs above a open album too).

Open up the Pictures database next, and search for the album number where the misplaced pictures are currently located. You now need only to change the number in the AID column to the number of the correct album.

If you open up your backup copy of the albumx/userpics folder, you can confirm that user X owns the picture, in cases where, like me, I had to guess a lot because people love to give their albums imaginative names like "MY Pictures" and "New" and so on.  There is also a picture number displayed in the URL bar on your browser when you open an image, but the picture list is kind of long so better to search by user/album.

It's a little tedious to do this when you have a lot of orphans, but better than using the scroll bar to move them if it's a long one, like I have.

Hope this helps :)

Αndré

Quote from: klewless on July 12, 2016, 06:10:05 PM
How will the orphaned albums appear when someone waants to view the albums list?

We need to add a similar approach to the function list_users() in index.php as we just did in include/functions.inc.php. Will have a closer look now.

klewless

Still here, Andre. Thanks.

; - )

Αndré

The following change needs some improvement, e.g. there currently no data about album and file number for each former user. But it's a start and should work.

Open index.php, find
    if (!$rowset) {
        msg_box($lang_list_users['user_list'], $lang_list_users['no_user_gal'], '', '', 'info');
        return;
    }

and below, add
    if ($user_count > count($rowset)) {
        $sql  = "SELECT category "
                . "FROM {$CONFIG['TABLE_ALBUMS']} AS p "
                . " INNER JOIN {$CONFIG['TABLE_PICTURES']} AS pics ON pics.aid = p.aid "
                . "WHERE ( category > " . FIRST_USER_CAT . " $FORBIDDEN_SET) ";
        $result = cpg_db_query($sql);
        while ($row = cpg_db_fetch_assoc($result)) {
            $user_categories[$row['category'] - FIRST_USER_CAT] = 1;
        }
        cpg_db_free_result($result);

        foreach ($rowset as $user) {
            unset($user_categories[$user['user_id']]);
        }
        foreach ($user_categories as $user_id => $tmp) {
            $rowset[] = array(
                'user_id' => $user_id,
                'user_name' => 'Former user '.$user_id,
            );
        }
    }

klewless

Great, will get to work on it tonight.

I have found the picture owners'  IDs are in the path for the picture but I still have to go to the DB to find the AID number.

L.

Αndré

Updated code with album and picture counters (just tested on a very small test data, so I need your feedback if everything works as expected).

Open index.php, find
    if (!$rowset) {
        msg_box($lang_list_users['user_list'], $lang_list_users['no_user_gal'], '', '', 'info');
        return;
    }

and below, add
    if ($user_count > count($rowset)) {
        $sql  = "SELECT category "
                . "FROM {$CONFIG['TABLE_ALBUMS']} AS p "
                . " INNER JOIN {$CONFIG['TABLE_PICTURES']} AS pics ON pics.aid = p.aid "
                . "WHERE ( category > " . FIRST_USER_CAT . " $FORBIDDEN_SET) ";
        $result = cpg_db_query($sql);
        while ($row = cpg_db_fetch_assoc($result)) {
            $user_ids[$row['category'] - FIRST_USER_CAT] = 1;
        }
        cpg_db_free_result($result);

        foreach ($rowset as $user) {
            unset($user_ids[$user['user_id']]);
        }
        foreach ($user_ids as $user_id => $tmp) {
            $user_categories[] = $user_id + FIRST_USER_CAT;
        }
        $result = cpg_db_query("
            SELECT p.owner_id, p.aid, COUNT(*) AS pic_count FROM {$CONFIG['TABLE_PICTURES']} AS p
            INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a
            ON a.aid = p.aid
            WHERE a.category IN (".implode(',', $user_categories).")
            GROUP BY p.aid
        ");
        while ($row = cpg_db_fetch_assoc($result)) {
            $user_category_data[$row['owner_id']]['alb_count']++;
            $user_category_data[$row['owner_id']]['pic_count'] += $row['pic_count'];
        }
        foreach ($user_ids as $user_id => $tmp) {
            $rowset[] = array(
                'user_id' => $user_id,
                'user_name' => 'Former user '.$user_id,
                'alb_count' => $user_category_data[$user_id]['alb_count'],
                'pic_count' => $user_category_data[$user_id]['pic_count'],
            );
        }
    }