Search Album Title & Description Search Album Title & Description
 

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 Album Title & Description

Started by Paver, January 15, 2006, 09:43:32 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Paver

Note: This first post mentions some features that have been modified in later releases of this plugin.  Please read the whole thread for the history and for what features are present in the current release.

This plugin adds "Album Title" and "Album Description" to the list of fields you can search.  The results are returned in a separate box showing the albums that match your search criteria; this box appears above the regular search box.  The only configuration option is on installation: whether to show an empty box when no albums match your criteria or not. 

This was an interesting task due to the placement and number of the current plugin hooks.  As Donnoman noted on CPG-Contrib, modifying album contents using the thumb_caption plugin filters is problematic since the albums depend on a count variable which is not accessible to the plugin.  But in this case, since I'm returning albums and not images to browse in a meta album, the count isn't used.  Here's the thread for those interested: http://cpg-contrib.org/board/index.php?topic=52.0.  Also, the search page doesn't have a plugin hook.  This plugin uses a copied version of search.php and adds the new fields.  For the search results page, I use the 'lastalb' meta album and "hijack" it by replacing its title with my title and $rowset with my search results.

It works, but I don't know if I would consider it ideal or not.  I'm sure the plugin system will improve, but for the current state, I'm not sure if there's anything different (better) I could have done.  If anyone has any comments, please let me know.  It seems to me that adding this feature to the search core scripts would be useful; I'm willing to contribute to such an update for a future version.

Note that this plugin replaces the search link on your SUB_MENU.  If you have the search link someplace else (and especially if you don't use the sub menu), you might think this plugin is not working.  Ideally you shouldn't manually add a link to the plugin search form in your theme because then uninstalling the plugin would require an extra step.  Please let me know where else this plugin should look for search links and I can add them. 

v1.01 includes a bugfix (hard-coded config table) and a better check in _addresults
v1.02 improves the method of replacing the search link so it works with all themes
v1.03 adds the category name to the thumbnail caption for both search album results & 'lastalb' (Last Updated Albums)
v1.04 adds config option for category name display, fixes processing so original search form works, replaces search.php everywhere on page, added README.txt to describe theme custom search boxes, and a few other behind-the-scenes improvements
v1.05 adds a config panel, adds album stats, adds option to search albums only (no pictures) - more details
v1.06 uses a new stats template and date format, replaces thumbnail captions completely for albums - more details
v1.07 changes nothing except the default value of 'files' and 'views' in english.php, which is commented out by default - more details
v1.08 includes two important bug fixes regarding restricted & empty albums - more details - known issues

FYI: It's easier to read the thread manually than to use the "more details" links in the changelog.

Prisoner_24601

Downloaded.  Installed.

Two problems:

1.  The plugin initially wouldn't install.  I turned on CPG's debug and found that there was a problem where the plugin couldn't find a table.  This is in CODEBASE.PHP, line 39:

cpg_db_query("DELETE FROM cpg_config WHERE name REGEXP '^plugin_searchalbum_'");

Changed it to cpg_db_query("DELETE FROM cpg143_config WHERE name REGEXP '^plugin_searchalbum_'");

... In other words, I changed the name of the table prefix in the code.  On my CPG install the table prefixes are "cpg143", not "cpg".  I didn't install CPG myself, my webhost did, so I dunno if "cpg" or "cpg143" is the default table prefix.

2.  Doing the above correction allowed me to install the plugin, but when I searched, it didn't find anything.  For gee whiz, I also created a new album, uploaded some pics and then added a description.  Search still didn't find anything.

There was a notice in DEBUG:

Quote\plugins\search_album\codebase.php

* Notice line 162: Undefined index: REQUEST_URI

(This index also appears in line 62.)

I don't know how to resolve that.  Please assist! 

Here's the full DEBUG info (I've got all of 6 pictures in my DB; I don't mind reinstalling stuff to make this work).  It's a plain vanilla install of CPG 1.43 on a Windows 2003 server, running PHP 5.1.1 and MySQL 5:

USER:
------------------
Array
(
    [ID] => 11d4f5a45178d211db13b5858a7add36
    [am] => 1
    [lang] => english
    [liv] => Array
        (
            [0] => 5
        )

    [search] => Array
        (
            [search] => 1958
            [album] => search
            [title] => on
            [newer_than] =>
            [caption] => on
            [older_than] =>
            [keywords] => on
            [type] => OR
            [album_title] => on
            [album_description] => on
            [params] => Array
                (
                    [title] => on
                    [caption] => on
                    [keywords] => on
                )

        )

)

==========================
USER DATA:
------------------
Array
(
    [user_id] => 1
    [user_name] => saxpics
    [groups] => Array
        (
            [0] => 1
        )

    [disk_max] => 0
    [disk_min] => 0
    [can_rate_pictures] => 1
    [can_send_ecards] => 1
    [ufc_max] => 3
    [ufc_min] => 3
    [custom_user_upload] => 0
    [num_file_upload] => 5
    [num_URI_upload] => 3
    [can_post_comments] => 1
    [can_upload_pictures] => 1
    [can_create_albums] => 1
    [has_admin_access] => 1
    [pub_upl_need_approval] => 0
    [priv_upl_need_approval] => 0
    [group_name] => Administrators
    [upload_form_config] => 3
    [group_quota] => 0
    [can_see_all_albums] => 1
    [group_id] => 1
)

==========================
Queries:
------------------
Array
(
    [0] => SELECT extension, mime, content, player FROM cpg143_filetypes; (0.002s)
    [1] => select * from cpg143_plugins order by priority asc; (0.001s)
    [2] => delete from `test`.cpg143_sessions where time<1137358357 and remember=0; (0.001s)
    [3] => delete from `test`.cpg143_sessions where time<1136152357; (0.001s)
    [4] => select user_id from `test`.cpg143_sessions where session_id=md5("d7b002f7bde6566522de95281119c8f086230dde26c1ff66700314c65d7b330d"); (0.001s)
    [5] => select user_id as id, user_password as password from `test`.cpg143_users where user_id=1 (0.001s)
    [6] => SELECT u.user_id AS id, u.user_name AS username, u.user_password AS password, u.user_group+100 AS group_id FROM `test`.cpg143_users AS u INNER JOIN `test`.cpg143_usergroups AS g ON u.user_group=g.group_id WHERE u.user_id='1' (0.001s)
    [7] => SELECT user_group_list FROM `test`.cpg143_users AS u WHERE user_id='1' and user_group_list <> ''; (0.001s)
    [8] => SELECT MAX(group_quota) as disk_max, MIN(group_quota) as disk_min, MAX(can_rate_pictures) as can_rate_pictures, MAX(can_send_ecards) as can_send_ecards, MAX(upload_form_config) as ufc_max, MIN(upload_form_config) as ufc_min, MAX(custom_user_upload) as custom_user_upload, MAX(num_file_upload) as num_file_upload, MAX(num_URI_upload) as num_URI_upload, MAX(can_post_comments) as can_post_comments, MAX(can_upload_pictures) as can_upload_pictures, MAX(can_create_albums) as can_create_albums, MAX(has_admin_access) as has_admin_access, MIN(pub_upl_need_approval) as pub_upl_need_approval, MIN( priv_upl_need_approval) as  priv_upl_need_approval FROM cpg143_usergroups WHERE group_id in (1) (0.001s)
    [9] => SELECT group_name FROM  cpg143_usergroups WHERE group_id= 1 (0.001s)
    [10] => update `test`.cpg143_sessions set time='1137361957' where session_id=md5('d7b002f7bde6566522de95281119c8f086230dde26c1ff66700314c65d7b330d'); (0.001s)
    [11] => SELECT user_favpics FROM cpg143_favpics WHERE user_id = 1 (0.001s)
    [12] => DELETE FROM cpg143_banned WHERE expiry < '2006-01-15 21:52:37' (0.001s)
    [13] => SELECT * FROM cpg143_banned WHERE (ip_addr='68.104.158.246' OR ip_addr='68.104.158.246' OR user_id=1) AND brute_force=0 (0.001s)
    [14] => SELECT COUNT(*) FROM cpg143_pictures WHERE approved = 'NO' (0.001s)
    [15] => SELECT COUNT(*) FROM cpg143_pictures WHERE (title LIKE '%1958%' OR caption LIKE '%1958%' OR keywords LIKE '%1958%')  (0.001s)
    [16] => SELECT * FROM cpg143_pictures WHERE (title LIKE '%1958%' OR caption LIKE '%1958%' OR keywords LIKE '%1958%')  ORDER BY filename ASC  LIMIT 0 ,12 (0.001s)
)

==========================
GET :
------------------
Array
(
)

==========================
POST :
------------------
Array
(
    [search] => 1958
    [album] => search
    [title] => on
    [newer_than] =>
    [caption] => on
    [older_than] =>
    [keywords] => on
    [type] => OR
    [album_title] => on
    [album_description] => on
    [params] => Array
        (
            [title] => on
            [caption] => on
            [keywords] => on
        )

    [params_plugin] => Array
        (
            [album_title] => on
            [album_description] => on
        )

)

==========================
VERSION INFO :
------------------
PHP version: 5.1.1 - OK
------------------
mySQL version: 5.0.18-nt
------------------
Coppermine version: 1.4.3(stable)
==========================
Module: GD
------------------
GD Version: bundled (2.0.28 compatible)
FreeType Support: 1
FreeType Linkage: with freetype
T1Lib Support: 1
GIF Read Support: 1
GIF Create Support: 1
JPG Support: 1
PNG Support: 1
WBMP Support: 1
XPM Support:
XBM Support: 1
JIS-mapped Japanese Font Support:

==========================
Module: mysql
------------------
MySQL Supportenabled
Active Persistent Links 0
Active Links 1
Client API version 4.1.7
==========================
Module: zlib
------------------
ZLib Support enabled
Stream Wrapper support compress.zlib://
Stream Filter support zlib.inflate, zlib.deflate
Compiled Version 1.2.3
Linked Version 1.2.3
==========================
Server restrictions (safe mode)?
------------------
Directive | Local Value | Master Value
safe_mode | Off | Off
safe_mode_exec_dir | no value | no value
safe_mode_gid | Off | Off
safe_mode_include_dir | no value | no value
safe_mode_exec_dir | no value | no value
sql.safe_mode | Off | Off
disable_functions | no value | no value
file_uploads | On | On
include_path | .;C:\php5\pear | .;C:\php5\pear
open_basedir | no value | no value
==========================
email
------------------
Directive | Local Value | Master Value
sendmail_from <Edited out by Prisoner_24601>
sendmail_path | no value | no value
SMTP | localhost | localhost
smtp_port | 25 | 25
==========================
Size and Time
------------------
Directive | Local Value | Master Value
max_execution_time | 30 | 30
max_input_time | 60 | 60
upload_max_filesize | 2M | 2M
post_max_size | 8M | 8M
==========================
Page generated in 0.234 seconds - 17 queries in 0.018 seconds - Album set : ; Meta set: ;

Paver

#2
Darn.  This is the second time I've done this.  I'm 2 for 2 in the same bug in plugins!  I need to make a list of things to check before I release, and be more careful.  I fixed it and attached version 1.01 in the first post.  As for your search problem, are you sure your search link uses my new search page?  You should see 2 new checkboxes for Album Title and Album Description if you are using my new page.  If you don't see those, your search link was not replaced by my plugin.  My plugin only looks in the default place for the search link which is in the gallery SUB_MENU.  Never mind that.  I looked more carefully at your debug info.  I see you are using my form.

I thought at first that the notice you posted is just a warning.  I could avoid it by checking whether REQUEST_URI exists before doing a string compare, but it shouldn't cause errors.  But now I'm not so sure.  I looked more carefully at my check in function _addresults and changed it to avoid using the REQUEST_URI value.  Please see if this new version works for you.  This check is used since there is a search meta-album that is used for the search results for photos.  My plugin was adding album search results to this meta album.  I tried using REQUEST_URI to determine whether the referring file was thumbnails.php or displayimage.php.  It worked in my case so I'm not sure if this is your problem or not.  In any case, I replaced this check with one that should work more simply.

Prisoner_24601

It works!  I'm very happy.

Just a comment -- and this may be because I've not read the documentation in enough depth: this only works on the "default" theme ("classic", I think it's called).  In my case, at least, when I switched to a different theme, I got a variety of different PHP and SQL errors.  I tried three different themes and got three different pages of errors.  I did the expedient thing and turned off the ability to select different themes.

I am going to search and see if I can get the Album Description to show up on the Film Strip page.  That, this plugin that you've written, and the directory-to-album import mod will make CPG essentially PERFECT for my needs (although I'm gonna have to do descriptions for something like 50,000+ albums of pictures).

Thanks very much!

Paver

Huh.  I'm using a modified classic theme so I haven't tried any other themes yet.  I'm not sure why the theme would matter ... unless it has to do with the SUB_MENU search link being replaced.  I'll check it out.

I'm also working on a way to mass apply keywords to photos but that's not related to what you want to do.  You actually have to type in something different for each album I assume.  And yes, that batch add script is a beautiful way to add new photos - I use it routinely.  That's why I'm working on the mass-keyword plugin/add-on.

Prisoner_24601

Quoteunless it has to do with the SUB_MENU search link being replaced.
I think that may be it.  The most common error I get when I use a different theme is:

QuoteTemplate error
Failed to find block 'search'(#(<!-- BEGIN search -->)(.*?)(<!-- END search -->)#s)

I'm not a coder, nor do I play one on TV, so I'm not sure.

QuoteYou actually have to type in something different for each album I assume.
Yes, sir. 

I have a very large picture website and I recently got SQL and PHP for my server and I know that CPG will make my life and browsing my gallery easier.  Everything is in the form of:

<root>\make\model\configuration\finish\album

... and I have between 1 and a zillion pictures per album

Paver

I just added version 1.02 above.  I improved the method of replacing the search link and now it works for all themes, at least all the ones included in the core package.

Do you plan to put the category tree into the album description so that the albums are searchable by their inheritance?  If so, I would do that programatically using PHP & MySQL.  You could even modify the Batch Add script to do this during the process of adding the photos (and creating the albums & categories).

Prisoner_24601

Yup.  Works as advertised: search returns the Albums and it works with all the "included by default" themes.  Thanks much.


QuoteDo you plan to put the category tree into the album description so that the albums are searchable by their inheritance?  If so, I would do that programatically using PHP & MySQL.  You could even modify the Batch Add script to do this during the process of adding the photos (and creating the albums & categories).

I can see the benefits of doing this, but I hadn't even thought of it, because I had been putting in rather enthusiastic Album descriptions and didn't think I could make it automagic.

I know how to add tables and info into them in MySQL through phpMyAdmin, but I don't know how to do what you mention.  If you can give me some ideas, I'd appreciate it.  While I'm not a coder, I am a computer tech so playing with stuff doesn't bother me.


Paver

You're welcome.  If you notice any other themes where there's a problem, let me know on this thread.

If you are all set with enthusiastic descriptions, that's definitely better in the long run and nicer to read.  If you would like to discuss the automagic code, please start another thread somewhere (I'm not sure offhand which board is best).  Let's stick to one question per thread.  If you do, please post a link on this thread or I might not see it.

andrewshu329

Specific searches turn up database errors on my site:
-xinjiang
-x
-y
etc..

Any clues as to why?
heres my site:
www.sasphotos.net

CPG 1.4.2
Apache 2.0.54
PHP 5.0.5
MySql 4.1

Paver

#10
Huh.  You're right.  I assume you mean the "Template error: Failed to find block 'admin_approval'" error.  That's what I see for most searches on your site.  That's almost always a theme error.  Yes, my plugin produced a similar error noted in a previous post, but that's because I was modifying the theme's search link.  My plugin doesn't touch the $template_gallery_admin_menu variable which is where the admin_approval block is to be found.  Check the sample theme's theme.php to see.

I tried your original search.php and got the same errors.  But one thing is weird.  If I search for 'photos' on the plugin search form, I get results fine.  If I search for 'photos' on the original search form, I get the admin_approval error.  I don't know why my search form would avoid the error compared to the original search form.

The bottom line is that this "Failed to find block" error is easily fixed by modifying your theme.php file.  Look to see if your theme.php has a $template_gallery_admin_menu definition in it.  If it does, add the admin_approval block as shown in the sample theme.php.  If it doesn't add the whole definition from the sample theme.php, including the admin_approval block.

My guess is that you have photos to approve now and maybe coincidentally had those photos uploaded when you installed my plugin.  I don't think the error & my plugin are related, but I'm not sure.  For now, I don't think there's a reason to troubleshoot the problem further until you fix the theme error.

edit: If for some reason you don't want the admin_approval link on your admin menu, then just add the BEGIN & END comments and leave the space in between blank.

Prisoner_24601

Paver's quicker than me.  :)

I just wanted to mention that I don't have that problem.

andrewshu329, you've got several more search options than I do.  It could also be that you've got some conflict with another search plugin or hack, too.

Paver

I wanted to add the category name to search album results so I did and released version 1.03 (attached to the first post as usual).  I left 1.02 on there in case people don't want this added feature.  There's no config. option in 1.03; it just adds the category name.  And oh yeah, it adds the category name to the 'lastalb' meta-album ("Last Updated Albums) as well, since I think it's an analogous feature, and I like it.

If people would like this feature but want a config. option, go ahead and request it.  I'll probably do it anyways before the next release whenever it is, but I didn't have time now to do it, and I think it's a useful feature, so here it is.

Prisoner_24601

Thank you.  I will test further when I have a chance.

I have to ask it: is it possible to include a search for a) "star" ratings for albums and/or b) user comment fields?  As it stands, this plugin (1.02) is wonderful, but I'd love to have these features, too.

Thanks for putting up with my requests!

Paver

No problem with the requests.  I'm willing to consider anything; I just cannot promise anything either.

I assume you mean star ratings & comments for pictures, not albums, right?  Please give more details of exactly what would be searched and how the search results would be returned.

Paver

I added version 1.04 in the first post above, with changes as noted (and as noted in CHANGELOG in the plugin package).

I removed the previous versions because this release takes care of the previous releases' differences.

Prisoner_24601

Quote from: Paver
No problem with the requests.  I'm willing to consider anything; I just cannot promise anything either.
I'm sorry to say that I don't know enough about CPG to be that effective to help other folks on this forum -- although I try to share what I do know -- and I ask for a lot of stuff, so thanks for being gracious with your time.

Quote from: PaverI assume you mean star ratings & comments for pictures, not albums, right?  Please give more details of exactly what would be searched and how the search results would be returned.
Yes.

As far as the star ratings are concerned, I'm assuming that picture X has rating Y saved in some table someplace, and that table has numbers assigned to it (I could be completely wrong, of course).  It'd be nice to check the Gallery every now and then and perhaps remove all the photos with one star or put the five-star ones on display on my main website, using one or more of the other hacks/plugins that do this.

However, more important to me would be a search on comments.  Because CPG is so similar to phpBB (and is built on that technology, if I read the documentation right), it'd be like searching for a post.  I'm hoping to start getting comments from folks that may know more than I about the items in my gallery and I'd like to be able to search under their names and whatever comments they give, as the comments will relate to standardized equipment, etc.

As I said, the search feature does this well in phpBB, so I'd love to see that functionality integrated into CPG -- without having to use some sort of phpBB to CPG bridge, as I have no need for a full-featured Forum, nor do I wish to have to moderate/administrate one.

============

I installed 1.0.3 today and I really like the improvement.  Thanks for anticipating that feature request.

Joachim Müller

searching comments would really be a nice feature. Searching for particular ratings shouldn't go into this plugin imo, as it actually doesn't involve the search engine, but running a rather simple query, so I suggest writing a separate mod/plugin to accomplish this.

lordprodigy

when I do the search, it finds the the relevant albums and displays them. Underneath in a separate window is says "No image to display ". I guess it didnt find any images with the keyword I was looking for so has nothing to display... How can I get rid of that block as I am only interested in people searching by album and not by image... and the only results I want is Albums.

thanks.

Paver

@lordprodigy: Ok, I figured out one way to do what you want.  It's related to my plugin so I'll add it in to the next release.  But I assume you want the search form to have only the "Album Title" and the "Album Description" checkboxes and *nothing* else?  Otherwise it doesn't make sense to have checkboxes but then not to return matches using those checkboxes.