forum.coppermine-gallery.net

Support => cpg1.5.x Support => cpg1.5 miscellaneous => Topic started by: Streamer on August 27, 2010, 07:20:22 pm

Title: Search by username?
Post by: Streamer on August 27, 2010, 07:20:22 pm
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.
Title: Re: Search by username?
Post by: papukaija on August 28, 2010, 04:55:27 pm
Please post a link to your gallery (http://forum.coppermine-gallery.net/index.php/topic,55415.msg270616.html#msg270616) as requested by board rules.
Title: Re: Search by username?
Post by: Streamer on August 30, 2010, 08:32:59 am
Sorry, forgot that. http://www.perhokalastajat.net/kuvagalleria/

Title: Re: Search by username?
Post by: Αndré on September 02, 2010, 12:44:18 pm
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.
Title: Re: Search by username?
Post by: Phill Luckhurst on September 02, 2010, 01:41:52 pm
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.
Title: Re: Search by username?
Post by: Αndré on September 02, 2010, 02:22:13 pm
We dropped the column 'owner_name' some time ago. I think that was the reason. A simple JOIN can solve that in standalone versions.
Title: Re: Search by username?
Post by: Streamer on September 02, 2010, 08:01:38 pm
Ok, thanks for the answer.
Title: Re: Search by username?
Post by: Αndré on March 07, 2012, 11:43:36 am
This seems to work:

1. Open search.php, find
Code: [Select]
$customs
$ip
and above, add
Code: [Select]
                                        <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
Code: [Select]
$allowed = array('title', 'caption', 'keywords', 'filename', 'pic_raw_ip', 'pic_hdr_ip', 'user1', 'user2', 'user3', 'user4', 'type');and replace with
Code: [Select]
$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
Code: [Select]
$allowed = array('title', 'caption', 'keywords', 'filename', 'pic_raw_ip', 'pic_hdr_ip', 'user1', 'user2', 'user3', 'user4');and below, add
Code: [Select]
// 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
Code: [Select]
            $query = "SELECT COUNT(*) FROM {$CONFIG['TABLE_PICTURES']} AS p
                WHERE $sql
                AND ($sort_order)";
and replace with
Code: [Select]
            $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
Code: [Select]
            $query = "SELECT * FROM {$CONFIG['TABLE_PICTURES']} AS p WHERE " . $sql;and replace with
Code: [Select]
            $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;
Title: Re: Search by username?
Post by: Α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.
Title: Re: Search by username?
Post by: Phill Luckhurst on March 07, 2012, 03:45:59 pm
Seems to work well for me Andre.
Title: Re: Search by username?
Post by: Αndré on March 07, 2012, 03:49:32 pm
I assume you tested it in your Joomla bridged gallery?
Title: Re: Search by username?
Post by: Phill Luckhurst on March 07, 2012, 10:39:07 pm
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. ;)
Title: Re: Re: Search by username?
Post by: lurkalot on March 07, 2012, 11:22:03 pm
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.  ;)
Title: Re: Search by username?
Post by: heavensportal on March 08, 2012, 12:20:54 am
thank you for this code, will give it a try later tonight.
Title: Re: Search by username?
Post by: Α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.
Title: Re: Re: Search by username?
Post by: heavensportal on March 08, 2012, 09:43:25 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
Title: Re: Search by username?
Post by: Αndré on March 08, 2012, 09:50:35 am
Just add the code as described. The language string is hard-coded in that example.


My last post was a reply to lurkalot's:
I was hoping you'd add it back in

Sorry for the confusion.
Title: Re: Search by username?
Post by: heavensportal on March 08, 2012, 10:00:06 am
ok and don't worry I confuse easy
Title: Re: Search by username?
Post by: Αndré on March 08, 2012, 11:05:34 am
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.
Title: Re: Search by username?
Post by: Αndré on March 08, 2012, 11:13:03 am
Step 1 and 2 stay the same (http://forum.coppermine-gallery.net/index.php/topic,66818.msg358834.html#msg358834).


3. Open include/search.inc.php, find
Code: [Select]
$allowed = array('title', 'caption', 'keywords', 'filename', 'pic_raw_ip', 'pic_hdr_ip', 'user1', 'user2', 'user3', 'user4');and below, add
Code: [Select]
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
Code: [Select]
            $query = "SELECT COUNT(*) FROM {$CONFIG['TABLE_PICTURES']} AS p
                WHERE $sql
                AND ($sort_order)";
and replace with
Code: [Select]
            $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
Code: [Select]
            $query = "SELECT * FROM {$CONFIG['TABLE_PICTURES']} AS p WHERE " . $sql;

            $temp = str_replace('SELECT *', 'SELECT COUNT(*)', $query);
and replace with
Code: [Select]
            $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);
Title: Re: Search by username?
Post by: heavensportal on March 08, 2012, 11:43:56 am
ok thanks
Title: Re: Search by username?
Post by: Αndré on March 08, 2012, 02:21:28 pm
After some thorough testing I think the modification is mature enough to go back to even the cpg1.5.x branch. Committed code changes and corresponding language strings in SVN revision 8321.

Please report any unexpected behavior as detailed as possible (using a bridged or unbridged gallery, which options have you checked, what have you searched for, ...).
Title: Re: Search by username?
Post by: heavensportal on March 08, 2012, 11:15:55 pm
after your fine edit instructions I went into search> entered name of artist > unchecked all  and checked username then clicked search and yippeeee I got all his images like before

thank you so very much

no problems what so ever
Title: Re: Search by username?
Post by: Streamer on April 14, 2012, 12:33:39 pm
Thanks a lot for adding search by user to 1.5.20!

Works nice but I don't know if it's necessary to be case sensitive?
Title: Re: Search by username?
Post by: Αndré on April 16, 2012, 03:04:02 pm
The search isn't case sensitive for me. It may be case sensitive for you, depending on which collations you used for your tables.
Title: Re: Search by username?
Post by: Αndré on May 02, 2012, 02:25:49 pm
Unfortunately a user in the German support board reported (http://forum.coppermine-gallery.net/index.php/topic,74857.0.html) that the search is broken in his bridged gallery, because the Coppermine DB user has no access to query the phpBB database.
Title: Re: Re: Search by username?
Post by: Αndré on May 04, 2012, 10:04:05 am
Unfortunately a user in the German support board reported (http://forum.coppermine-gallery.net/index.php/topic,74857.0.html) that the search is broken in his bridged gallery, because the Coppermine DB user has no access to query the phpBB database.
Added check in SVN revision 8391 (http://coppermine.svn.sourceforge.net/viewvc/coppermine?view=revision&revision=8391). It fixes the above issue, but also disables the search by user name if there are no sufficient MySQL permissions.