Search by username? Search by username?
 

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

Search by username?

Started by Streamer, August 27, 2010, 07:20:22 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Streamer

Any possibility to add search by username. There was such an option at 1.4 but now its removed (why?). I didnt find any plug-in etc about that.

papukaija



Αndré

What/where do you want to search by username? The meta albums lastupby and lastcomby still exists in cpg1.5.x and I cannot remember that we had other possibilities in cpg1.4.x.

phill104

In search.php Andre. In 1.4.x there was an "ownername" check box (take a look at the demo) but we dropped that in 1.5.x for some reason which I am not sure of.
It is a mistake to think you can solve any major problems just with potatoes.

Αndré

We dropped the column 'owner_name' some time ago. I think that was the reason. A simple JOIN can solve that in standalone versions.

Streamer


Αndré

This seems to work:

1. Open search.php, find
$customs
$ip

and above, add
                                        <tr>
                                                <td><input type="checkbox" name="owner_name" id="owner_name" class="checkbox" /><label for="owner_name" class="clickable_option">Owner name</label></td>
                                                <td>&nbsp;</td>
                                        </tr>



2. Open thumbnails.php, find
$allowed = array('title', 'caption', 'keywords', 'filename', 'pic_raw_ip', 'pic_hdr_ip', 'user1', 'user2', 'user3', 'user4', 'type');
and replace with
$allowed = array('title', 'caption', 'keywords', 'filename', 'pic_raw_ip', 'pic_hdr_ip', 'user1', 'user2', 'user3', 'user4', 'type', 'owner_name');


3. Open include/search.inc.php, find
$allowed = array('title', 'caption', 'keywords', 'filename', 'pic_raw_ip', 'pic_hdr_ip', 'user1', 'user2', 'user3', 'user4');
and below, add
// Use actual column name for search by user name
if ($USER['search']['params']['owner_name']) {
    global $cpg_udb;
    $USER['search']['params'][$cpg_udb->field['username']] = 'on';
    $allowed[] = $cpg_udb->field['username'];
}


find
            $query = "SELECT COUNT(*) FROM {$CONFIG['TABLE_PICTURES']} AS p
                WHERE $sql
                AND ($sort_order)";

and replace with
            $query = "SELECT COUNT(*) FROM {$CONFIG['TABLE_PICTURES']} AS p
                INNER JOIN {$cpg_udb->usertable} AS u ON p.owner_id = u.{$cpg_udb->field['user_id']}
                WHERE $sql
                AND ($sort_order)";


find
            $query = "SELECT * FROM {$CONFIG['TABLE_PICTURES']} AS p WHERE " . $sql;
and replace with
            $query = "SELECT p.*, u.{$cpg_udb->field['username']} AS owner_name FROM {$CONFIG['TABLE_PICTURES']} AS p
            INNER JOIN {$cpg_udb->usertable} AS u ON p.owner_id = u.{$cpg_udb->field['user_id']}
            WHERE " . $sql;

Αndré

Any reports / confirmation that it works in other galleries (in unbridged and bridged ones) are welcome, so that feature can be added back to Coppermine.

phill104

Seems to work well for me Andre.
It is a mistake to think you can solve any major problems just with potatoes.

Αndré

I assume you tested it in your Joomla bridged gallery?

phill104

Yes, but in my offline copy. I try not to fiddle with the live one except when I have the time to fix it after I break it. ;)
It is a mistake to think you can solve any major problems just with potatoes.

lurkalot

Quote from: Αndré on March 07, 2012, 11:46:42 AM
Any reports / confirmation that it works in other galleries (in unbridged and bridged ones) are welcome, so that feature can be added back to Coppermine.

Works for me Andre, on my testsite SMF 2.0.2 bridged with Coppermine 1.5.18.  Thanks for doing this, I was hoping you'd add it back in.  ;)
Running SMF 2.1.4  / Tinyportal 3.0.1, bridged with Coppermine 1.6.25, plus cpmfetch 2.0.0

heavensportal

thank you for this code, will give it a try later tonight.

Αndré

Unfortunately the language string has also been removed. I just compared the available language files for cpg1.4.x and cpg1.5.x. I think we can add that feature back to cpg1.5.x as well, as 31 of 33 available languages in cpg1.5.x also exist in cpg1.4.x.

heavensportal

Quote from: Αndré on March 08, 2012, 09:22:06 AM
Unfortunately the language string has also been removed. I just compared the available language files for cpg1.4.x and cpg1.5.x. I think we can add that feature back to cpg1.5.x as well, as 31 of 33 available languages in cpg1.5.x also exist in cpg1.4.x.

do you mean for the galleries that do not use english default or something else that I should add once I get the code edited into the files

Αndré

Just add the code as described. The language string is hard-coded in that example.


My last post was a reply to lurkalot's:
Quote from: lurkalot on March 07, 2012, 11:22:03 PM
I was hoping you'd add it back in

Sorry for the confusion.

heavensportal

ok and don't worry I confuse easy

Αndré

The current code change produces an error when "owner name" isn't selected. Additionally, the search result file count is wrong. Will post updated code for include/search.inc.php soon.

Αndré

Step 1 and 2 stay the same.


3. Open include/search.inc.php, find
$allowed = array('title', 'caption', 'keywords', 'filename', 'pic_raw_ip', 'pic_hdr_ip', 'user1', 'user2', 'user3', 'user4');
and below, add
global $cpg_udb;
// Use actual column name for search by owner name
if ($USER['search']['params']['owner_name']) {
    $USER['search']['params'][$cpg_udb->field['username']] = true;
    $allowed[] = $cpg_udb->field['username'];
}


find
            $query = "SELECT COUNT(*) FROM {$CONFIG['TABLE_PICTURES']} AS p
                WHERE $sql
                AND ($sort_order)";

and replace with
            $query = "SELECT COUNT(*) FROM {$CONFIG['TABLE_PICTURES']} AS p
                LEFT JOIN {$cpg_udb->usertable} AS u ON p.owner_id = u.{$cpg_udb->field['user_id']}
                WHERE $sql
                AND ($sort_order)";


find
            $query = "SELECT * FROM {$CONFIG['TABLE_PICTURES']} AS p WHERE " . $sql;

            $temp = str_replace('SELECT *', 'SELECT COUNT(*)', $query);

and replace with
            $query = "SELECT p.*, u.{$cpg_udb->field['username']} AS owner_name FROM {$CONFIG['TABLE_PICTURES']} AS p
            LEFT JOIN {$cpg_udb->usertable} AS u ON p.owner_id = u.{$cpg_udb->field['user_id']}
            WHERE " . $sql;

            $temp = str_replace("SELECT p.*, u.{$cpg_udb->field['username']} AS owner_name", 'SELECT COUNT(*)', $query);