Adds a list of all available image keywords to the search_form.html template where the user can select 1 or more and include those words in their search criteria.See the screen shot at the bottom.
NOTE: There is some confusion circulating around what keywords really are in 4images. Let's see if I can help clear it up.
The default template search_form.html, with the english language pack, uses search_keywords and lang_search_keywords in the form field that actually accepts "words to search for". Search words can be anything from the image description, name, and even keywords. Keywords are words you explicitly assign to an image.
From a dictionary:
key·word also key word -
A word used as a reference point for finding other information.
It's very common for digital asset management software to not only let you categorize files, but to also let you assign keywords. Keywords are descriptive words, not phrases, that you can assign to your cataloged files in order to categorize and classify them. If you had an image of a tropical beach at sunset, you might assign it keywords such as Sand, Beach, Ocean, Sunset, Tropical, Vacation, Recreation, Outdoor, and so on. You might have chosen to place this image in a "Beaches" category. Suppose you also had an image of a city building taken at sunset when the color had changed and you placed it in a "Buildings" category. The keyword "sunset" could be used to group these images as having something in common. ("Tropical Sunset" is actually two keywords.)
Summary DescriptionThe database table 4images_images is read and a sorted, unique list of keywords is generated. This array is then used to add list of all image keywords found to the search_form.html template. This is a standard HTML <select> form control that allows multiple items to be selected. Example is shown below:
Summary of files affected[change] search.php
[change] includes/functions.php
[change] lang/english/main.php
[change] templates/default/search_form.html
Open search.php, locate this code near the top:
$org_search_keywords = $search_keywords;
if (isset($HTTP_POST_VARS['search_user']) || isset($HTTP_GET_VARS['search_user'])) {
Change it to the new lines as shown:
$org_search_keywords = $search_keywords;
// [Mod] Add a list of image keywords to the search form BEGIN
if (isset($HTTP_POST_VARS['search_keyword_list'])) {
$search_keyword_list = implode(" ", $HTTP_POST_VARS['search_keyword_list']);
$show_result = 1;
}
else {
$search_keyword_list = "";
}
$org_search_keywords .= trim(" ".$search_keyword_list);
$search_keywords = $org_search_keywords;
// [Mod] Add a list of image keywords to the search form END
if (isset($HTTP_POST_VARS['search_user']) || isset($HTTP_GET_VARS['search_user'])) {
Locate this code near the bottom:
"category_dropdown" => get_category_dropdown($cat_id)
));
Change it to the new lines as shown:
"category_dropdown" => get_category_dropdown($cat_id),
"lang_image_keyword_list" => $lang['image_keyword_list'], // [Mod] Add a list of image keywords to the search form
"image_keyword_list" => get_keyword_list() // [Mod] Add a list of image keywords to the search form
));
Open includes/functions.php, locate this code at the very bottom:
?>
Change it to the following:
// [Mod] Add a list of image keywords to the search form BEGIN
function get_keyword_list()
{
global $lang, $site_sess, $site_db;
$keyword_dropdown = "";
$keyword_dropdown .= "<select name=\"search_keyword_list[]\" multiple=\"multiple\" size=\"10\" class=\"setperpageselect\">\n";
$sql = "SELECT `image_keywords` FROM ".IMAGES_TABLE." WHERE 1 order by `image_keywords` DESC";
$result = $site_db->query($sql);
$array = array();
while(list($Name) = mysql_fetch_row($result)) {
// Commented out until enforcement of user/category/image permissions is developed
// if (!check_permission("auth_viewimage", $image_row['cat_id']) || !check_permission("auth_viewcat", $image_row['cat_id'])) {
if(!empty($Name)) {
$explode_array = explode(" ",$Name);
for($ctr=0; $ctr < count($explode_array); $ctr++){
$temp = $explode_array[$ctr];
$array[] = $temp;
}
}
}
$site_db->free_result();
$array1 = array_unique($array); // Remove duplicate values from the array
if (!empty($array1)) {
sort($array1,SORT_REGULAR); // Sort the array
foreach($array1 as $val) {
$keyword_dropdown .= "<option value=\"".$val."\">".$val."</option>\n";
}
}
$keyword_dropdown .= "</select>\n";
return $keyword_dropdown;
}
// [Mod] Add a list of image keywords to the search form END
?>
Now let's correct some misleading text in the english language pack and add our new language phrases for this mod.
Open lang/english/main.php and locate:
$lang['search_by_keyword'] = "Search by Keyword:<br /><span class=\"smalltext\">Use terms such as AND, OR and NOT to control your search in more detail. Use asterisks (*) as a wildcard for partial matches.</span>";
$lang['search_terms'] = "Search term:";
Change those lines to:
$lang['search_by_keyword'] = "Search Words:<br /><span class=\"smalltext\">Use terms such as AND, OR and NOT to control your search in more detail.<br />Use asterisks (*) as a wildcard for partial matches.</span>";
$lang['search_terms'] = "Any or All search words?";
After this line
$lang['or'] = "OR";
Add this new line
$lang['image_keyword_list'] = "Select Image Keywords:<br /><span class=\"smalltext\">Use CTRL-click or SHIFT-click to select multiple keywords.<br><br>You can use the '".$lang['keywords_only']."' field above to limit your search.</span>"; // [Mod] Add a list of image keywords to the search form
Open templates/default/search_form.html and locate:
<tr>
<td class="row1"> </td>
<td class="row1"><input type="submit" value="{lang_search}" class="button" /></td>
</tr>
Replace with this:
<tr class="row2">
<td valign="top"><b>{lang_image_keyword_list}</b></td>
<td>{image_keyword_list}</td>
</tr>
<tr>
<td class="row2"> </td>
<td class="row2"><input type="submit" value="{lang_search}" class="button" /></td>
</tr>
Revisions:
- Jan 28, 2005 - Version 2.0 - Major rewrite
Eliminated the need for a new template
Eliminated the single keyword jump menu and keyword links
Introduced a multi-item selectable list of image keywords providing more functionality than version 1.0
Consolidated and reduced code
TODO: Find a way to return only keywords for images the user has permission to view. Currently this mod returns ALL image keywords. - Removed extraneous show_error_page() from new code block for functions.php - Thanks to v@no for spotting it
- Fixed location of {keyword_dropdown_form} in search_form.html
Previous location had it embedded in the search form and caused a javascript error. - Added an example of {keyword_links} in search_form.html to the picture.