forum.coppermine-gallery.net
Support => cpg1.5.x Support => cpg1.5 miscellaneous => Topic started by: clemphoto on April 01, 2010, 02:06:36 am
-
My gallery application, http://clemsonphotos.org/coppermine (version 1.5 RC, guest access allowed), was developed using a fixed set of keywords available for each photograph. When searching, it would be convenient to display a fixed set of keywords (a controlled vocabulary) that users could combine when searching. Is this something that can reasonably be done by modifying code? If so, how should I proceed?
Del
-
Please read the documentation before asking questions: Documentation → Configuration → General settings → Enable clickable keywords in search (http://documentation.coppermine-gallery.net/en/configuration.htm#admin_general_keywords_start)
-
I read the documentation, including enabling clickable keywords. I have an existing set of keywords, already applied to the files before uploading. I do not want to be able to search for a single keyword (which is what clickable keywords does, among other things). I want to display a set of keywords that are constructed not by extracting them from uploaded file keywords, but from a fixed, static list. Users could then enter these keywords, in combinations and to combine with other text, in the search dialog. Searching for a single keyword is not helpful with my application, as it will return too many hits.
-
You can use this (http://documentation.coppermine-gallery.net/en/dev_plugin_hooks.htm#plugin_hooks_search_form) plugin hook to modify the search page.
-
Thanks, Andre. I am very new to this software, and to php, so I will think long and hard before trying this approach. At first glance, it looks like I could replace the search page with this, and that might turn out to be what I need. But, simpler approaches first.
I do appreciate the pointer to where I might productively add code. That is one of the challenges for me, knowing where I need to look.
Del
-
You can do a string replace (str_replace) to include your stuff. In your case I would add some tags (e.g. a list), that appends the selected word to the search fields. That's very simple and all you needs is just some very basic skills in php and javascript.
-
I am having a little trouble understanding this. Do you mean string replace to modify the set of search terms for a specific search, or string replace to replace segments of the search page as displayed to the user?
-
Neither. The common way is to search for a specific string and add your content before/after that string. Of course you simply can add it to the start/end of the search form. That's your choice.
-
Can you direct me to a place where I could see an example of this approach?
Del
-
Example of what? I don't know your skills. What exactly do you want to know?
-
An example of using string replace to add content to a page using the API hook for Search. My skills are ahead of my knowledge in this kind of programming. Quite a bit of experience, some with Perl, but very little with PHP.
Del
-
Have a look at search.php. Everything in the variable $text can be accessed and modified with the plugin hook 'search_form'. Now it's your choice. Either you want to place your list somewhere in the search form box. Then you have to use str_replace (http://www.php.net/manual/en/function.str-replace.php). If you want to display that list at the place where the actual keywords are listed, your plugin code have to look like this:
<?php
$thisplugin->add_filter('search_form', 'custom_search_form');
function custom_search_form($text) {
// here comes your html and js stuff
$keyword_list = '<span onclick="foo">bar</span>';
// then you append your list to the search form
$text .= $keyword_list;
return $text;
}
?>
-
Got it! Thanks very much, Andre.