Skip to content

Commit

Permalink
feature 3091: search.php (advanced search), display a list of known a…
Browse files Browse the repository at this point in the history
…uthors instead of a text field.

git-svn-id: http://piwigo.org/svn/trunk@28707 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
plegall committed Jun 16, 2014
1 parent aacdb5a commit 0511ed2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
37 changes: 32 additions & 5 deletions search.php
Expand Up @@ -83,13 +83,17 @@
);
}

if ($_POST['search_author'])
if (isset($_POST['authors']) and is_array($_POST['authors']) and count($_POST['authors']) > 0)
{
$authors = array();

foreach ($_POST['authors'] as $author)
{
$authors[] = strip_tags($author);
}

$search['fields']['author'] = array(
'words' => preg_split(
'/\s+/',
strip_tags($_POST['search_author'])
),
'words' => $authors,
'mode' => 'OR',
);
}
Expand Down Expand Up @@ -210,6 +214,29 @@
);
}

// authors
$query = '
SELECT
author,
COUNT(*) AS counter
FROM '.IMAGES_TABLE.' AS i
JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.image_id = i.id
'.get_sql_condition_FandF(
array(
'forbidden_categories' => 'category_id',
'visible_categories' => 'category_id',
'visible_images' => 'ic.image_id'
),
' WHERE '
).'
AND author IS NOT NULL
GROUP BY author
ORDER BY author
;';
$authors = query2array($query);

$template->assign('AUTHORS', $authors);

//------------------------------------------------------------- categories form
$query = '
SELECT id,name,global_rank,uppercats
Expand Down
17 changes: 16 additions & 1 deletion themes/default/template/search.tpl
Expand Up @@ -3,6 +3,17 @@
{include file='include/resize.inc.tpl'}
*}

{combine_script id='jquery.selectize' load='footer' path='themes/default/js/plugins/selectize.min.js'}
{combine_css id='jquery.selectize' path="themes/default/js/plugins/selectize.dark.css"}

{footer_script}
jQuery(document).ready(function() {
jQuery("#authors").selectize({
plugins: ['remove_button']
});
});
{/footer_script}

{if isset($MENUBAR)}{$MENUBAR}{/if}
<div id="content" class="content{if isset($MENUBAR)} contentWithMenu{/if}">

Expand Down Expand Up @@ -33,7 +44,11 @@
</label></li>
</ul>
<label>{'Search for Author'|@translate}
<input type="text" name="search_author" size="35">
<select id="authors" placeholder="{'Type in a search term'|translate}" name="authors[]" multiple style="width:500px;">
{foreach from=$AUTHORS item=author}
<option value="{$author.author|strip_tags:false|escape:html}">{$author.author|strip_tags:false} ({'%d photos'|translate:$author.counter})</option>
{/foreach}
</select>
</label>
</fieldset>

Expand Down
1 change: 0 additions & 1 deletion themes/default/theme.css
Expand Up @@ -507,7 +507,6 @@ SELECT.categoryList {
FIELDSET {
padding: 1em;
margin: 1em;
overflow: hidden; /* <- makes Opera happy */
}

.filter UL,
Expand Down

0 comments on commit 0511ed2

Please sign in to comment.