2003-05-09 14:42:42 +02:00
|
|
|
<?php
|
2004-02-07 20:36:44 +01:00
|
|
|
// +-----------------------------------------------------------------------+
|
2011-01-18 01:02:52 +01:00
|
|
|
// | Piwigo - a PHP based photo gallery |
|
2008-04-05 00:57:23 +02:00
|
|
|
// +-----------------------------------------------------------------------+
|
2014-01-05 01:19:25 +01:00
|
|
|
// | Copyright(C) 2008-2014 Piwigo Team http://piwigo.org |
|
2008-04-05 00:57:23 +02:00
|
|
|
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
|
|
|
|
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | This program is free software; you can redistribute it and/or modify |
|
|
|
|
// | it under the terms of the GNU General Public License as published by |
|
2004-02-07 20:36:44 +01:00
|
|
|
// | the Free Software Foundation |
|
|
|
|
// | |
|
|
|
|
// | This program is distributed in the hope that it will be useful, but |
|
|
|
|
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
|
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
|
|
|
// | General Public License for more details. |
|
|
|
|
// | |
|
|
|
|
// | You should have received a copy of the GNU General Public License |
|
|
|
|
// | along with this program; if not, write to the Free Software |
|
|
|
|
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
|
|
|
|
// | USA. |
|
|
|
|
// +-----------------------------------------------------------------------+
|
2003-05-09 14:42:42 +02:00
|
|
|
|
2004-07-26 22:43:46 +02:00
|
|
|
//--------------------------------------------------------------------- include
|
2004-02-19 01:31:09 +01:00
|
|
|
define('PHPWG_ROOT_PATH','./');
|
|
|
|
include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
|
2006-03-09 23:46:28 +01:00
|
|
|
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | Check Access and exit when user status is not ok |
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
check_status(ACCESS_GUEST);
|
|
|
|
|
2014-06-02 09:55:46 +02:00
|
|
|
trigger_notify('loc_begin_search');
|
2012-09-20 14:16:45 +02:00
|
|
|
|
2004-07-26 22:43:46 +02:00
|
|
|
//------------------------------------------------------------------ form check
|
|
|
|
$search = array();
|
|
|
|
if (isset($_POST['submit']))
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
2010-01-26 10:20:10 +01:00
|
|
|
foreach ($_POST as $post_key => $post_value)
|
|
|
|
{
|
|
|
|
if (!is_array($post_value))
|
|
|
|
{
|
2010-06-10 23:07:22 +02:00
|
|
|
$_POST[$post_key] = pwg_db_real_escape_string($post_value);
|
2010-01-26 10:20:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-05 12:47:40 +01:00
|
|
|
if (isset($_POST['search_allwords'])
|
|
|
|
and !preg_match('/^\s*$/', $_POST['search_allwords']))
|
2006-02-28 05:28:06 +01:00
|
|
|
{
|
2014-01-17 13:50:14 +01:00
|
|
|
check_input_parameter('mode', $_POST, false, '/^(OR|AND)$/');
|
2014-06-17 13:11:44 +02:00
|
|
|
|
|
|
|
$fields = array_intersect($_POST['fields'], array('name', 'comment', 'file'));
|
2014-01-17 13:50:14 +01:00
|
|
|
|
2004-12-05 12:47:40 +01:00
|
|
|
$drop_char_match = array(
|
|
|
|
'-','^','$',';','#','&','(',')','<','>','`','\'','"','|',',','@','_',
|
|
|
|
'?','%','~','.','[',']','{','}',':','\\','/','=','\'','!','*');
|
|
|
|
$drop_char_replace = array(
|
|
|
|
' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','','',' ',' ',' ',' ','',' ',
|
|
|
|
' ',' ',' ',' ',' ',' ',' ',' ','' ,' ',' ',' ',' ',' ');
|
2006-02-28 05:28:06 +01:00
|
|
|
|
2004-12-05 12:47:40 +01:00
|
|
|
// Split words
|
2006-01-20 15:34:37 +01:00
|
|
|
$search['fields']['allwords'] = array(
|
|
|
|
'words' => array_unique(
|
|
|
|
preg_split(
|
|
|
|
'/\s+/',
|
|
|
|
str_replace(
|
|
|
|
$drop_char_match,
|
|
|
|
$drop_char_replace,
|
|
|
|
$_POST['search_allwords']
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'mode' => $_POST['mode'],
|
2014-06-17 13:11:44 +02:00
|
|
|
'fields' => $fields,
|
2006-01-20 15:34:37 +01:00
|
|
|
);
|
2004-07-26 22:43:46 +02:00
|
|
|
}
|
2006-02-28 05:28:06 +01:00
|
|
|
|
2006-04-03 00:26:19 +02:00
|
|
|
if (isset($_POST['tags']))
|
|
|
|
{
|
2010-03-19 23:25:39 +01:00
|
|
|
check_input_parameter('tags', $_POST, true, PATTERN_ID);
|
2014-01-17 13:50:14 +01:00
|
|
|
check_input_parameter('tag_mode', $_POST, false, '/^(OR|AND)$/');
|
2010-01-26 10:20:10 +01:00
|
|
|
|
2006-04-03 00:26:19 +02:00
|
|
|
$search['fields']['tags'] = array(
|
|
|
|
'words' => $_POST['tags'],
|
|
|
|
'mode' => $_POST['tag_mode'],
|
|
|
|
);
|
|
|
|
}
|
2006-04-05 04:01:36 +02:00
|
|
|
|
2014-06-16 15:53:16 +02:00
|
|
|
if (isset($_POST['authors']) and is_array($_POST['authors']) and count($_POST['authors']) > 0)
|
2004-07-26 22:43:46 +02:00
|
|
|
{
|
2014-06-16 15:53:16 +02:00
|
|
|
$authors = array();
|
|
|
|
|
|
|
|
foreach ($_POST['authors'] as $author)
|
|
|
|
{
|
|
|
|
$authors[] = strip_tags($author);
|
|
|
|
}
|
|
|
|
|
2006-01-20 15:34:37 +01:00
|
|
|
$search['fields']['author'] = array(
|
2014-06-16 15:53:16 +02:00
|
|
|
'words' => $authors,
|
2006-01-27 23:40:51 +01:00
|
|
|
'mode' => 'OR',
|
2006-01-20 15:34:37 +01:00
|
|
|
);
|
2003-05-25 10:31:39 +02:00
|
|
|
}
|
2006-02-28 05:28:06 +01:00
|
|
|
|
2004-11-25 15:12:33 +01:00
|
|
|
if (isset($_POST['cat']))
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
2010-03-19 23:25:39 +01:00
|
|
|
check_input_parameter('cat', $_POST, true, PATTERN_ID);
|
2010-01-26 10:20:10 +01:00
|
|
|
|
2006-01-20 15:34:37 +01:00
|
|
|
$search['fields']['cat'] = array(
|
|
|
|
'words' => $_POST['cat'],
|
|
|
|
'sub_inc' => ($_POST['subcats-included'] == 1) ? true : false,
|
|
|
|
);
|
2003-05-09 14:42:42 +02:00
|
|
|
}
|
2004-12-05 12:47:40 +01:00
|
|
|
|
|
|
|
// dates
|
|
|
|
$type_date = $_POST['date_type'];
|
2006-02-28 05:28:06 +01:00
|
|
|
|
2004-11-25 15:12:33 +01:00
|
|
|
if (!empty($_POST['start_year']))
|
2004-12-05 12:47:40 +01:00
|
|
|
{
|
2006-01-20 15:34:37 +01:00
|
|
|
$search['fields'][$type_date.'-after'] = array(
|
2010-06-10 23:07:22 +02:00
|
|
|
'date' => sprintf(
|
2013-10-19 13:04:11 +02:00
|
|
|
'%d-%02d-%02d',
|
|
|
|
$_POST['start_year'],
|
|
|
|
$_POST['start_month'] != 0 ? $_POST['start_month'] : '01',
|
|
|
|
$_POST['start_day'] != 0 ? $_POST['start_day'] : '01'
|
2006-01-20 15:34:37 +01:00
|
|
|
),
|
|
|
|
'inc' => true,
|
|
|
|
);
|
2004-12-05 12:47:40 +01:00
|
|
|
}
|
2004-11-25 15:12:33 +01:00
|
|
|
|
2004-12-05 12:47:40 +01:00
|
|
|
if (!empty($_POST['end_year']))
|
2004-11-25 15:12:33 +01:00
|
|
|
{
|
2006-01-20 15:34:37 +01:00
|
|
|
$search['fields'][$type_date.'-before'] = array(
|
2010-06-10 23:07:22 +02:00
|
|
|
'date' => sprintf(
|
2013-10-19 13:04:11 +02:00
|
|
|
'%d-%02d-%02d',
|
|
|
|
$_POST['end_year'],
|
|
|
|
$_POST['end_month'] != 0 ? $_POST['end_month'] : '12',
|
|
|
|
$_POST['end_day'] != 0 ? $_POST['end_day'] : '31'
|
2010-06-10 23:07:22 +02:00
|
|
|
),
|
2006-01-20 15:34:37 +01:00
|
|
|
'inc' => true,
|
|
|
|
);
|
2004-11-25 15:12:33 +01:00
|
|
|
}
|
2006-02-28 05:28:06 +01:00
|
|
|
|
2004-11-25 15:12:33 +01:00
|
|
|
if (!empty($search))
|
|
|
|
{
|
2006-01-20 15:34:37 +01:00
|
|
|
// default search mode : each clause must be respected
|
|
|
|
$search['mode'] = 'AND';
|
|
|
|
|
|
|
|
// register search rules in database, then they will be available on
|
|
|
|
// thumbnails page and picture page.
|
|
|
|
$query ='
|
|
|
|
INSERT INTO '.SEARCH_TABLE.'
|
2007-02-14 06:45:20 +01:00
|
|
|
(rules, last_seen)
|
2006-01-20 15:34:37 +01:00
|
|
|
VALUES
|
2007-02-14 06:45:20 +01:00
|
|
|
(\''.serialize($search).'\', NOW())
|
2006-01-20 15:34:37 +01:00
|
|
|
;';
|
|
|
|
pwg_query($query);
|
|
|
|
|
2010-02-15 20:49:04 +01:00
|
|
|
$search_id = pwg_db_insert_id(SEARCH_TABLE);
|
2004-11-25 15:12:33 +01:00
|
|
|
}
|
|
|
|
else
|
2004-07-26 22:43:46 +02:00
|
|
|
{
|
2013-10-19 19:43:04 +02:00
|
|
|
$page['errors'][] = l10n('Empty query. No criteria has been entered.');
|
2004-07-26 22:43:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//----------------------------------------------------------------- redirection
|
2011-12-18 22:46:24 +01:00
|
|
|
if (isset($_POST['submit']) and count($page['errors']) == 0)
|
2004-07-26 22:43:46 +02:00
|
|
|
{
|
2006-03-15 23:44:35 +01:00
|
|
|
redirect(
|
|
|
|
make_index_url(
|
|
|
|
array(
|
|
|
|
'section' => 'search',
|
|
|
|
'search' => $search_id,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2003-05-09 14:42:42 +02:00
|
|
|
}
|
|
|
|
//----------------------------------------------------- template initialization
|
2004-11-25 15:12:33 +01:00
|
|
|
|
2004-02-02 01:55:18 +01:00
|
|
|
//
|
|
|
|
// Start output of page
|
|
|
|
//
|
2010-03-02 15:54:22 +01:00
|
|
|
$title= l10n('Search');
|
- new : HTML BODY identifier to let CSS stylesheets manage specific
behaviour.
- deletion : admin/search useless
- improvement : in admin/user_list, special behaviour for true/false fields
(expand, show_comments)
- new : gallery_title and gallery_description are displayed at the top of
each page.
- improvement : simplification in HTML for categories menu.
- improvement : standardization of presentation in all public pages
(identification, registration, search, profile, notification, comments,
etc.)
(not in ChangeLog, below this line)
- add forgotten notification.php (should have been added in a previous
commit)
- [template cclear] deletion of useless class .bouton
- [template cclear] for test purpose, new presentation of register page
(using FORM.filter)
- [template cclear] adaptation of admin/group_list from template default
- [template cclear] deletion of obsolete admin/infos_images
- [template cclear] deletion of obsolete admin/search_username
- [template cclear] new icon register.png
git-svn-id: http://piwigo.org/svn/trunk@850 68402e56-0260-453c-a942-63ccdbb3a9ee
2005-08-26 00:43:47 +02:00
|
|
|
$page['body_id'] = 'theSearchPage';
|
2004-02-02 01:55:18 +01:00
|
|
|
|
2008-02-28 03:41:48 +01:00
|
|
|
$template->set_filename('search' ,'search.tpl' );
|
|
|
|
|
|
|
|
$month_list = $lang['month'];
|
|
|
|
$month_list[0]='------------';
|
|
|
|
ksort($month_list);
|
2006-02-28 05:28:06 +01:00
|
|
|
|
2008-02-28 03:41:48 +01:00
|
|
|
$template->assign(
|
2006-05-16 00:21:08 +02:00
|
|
|
array(
|
2008-02-28 03:41:48 +01:00
|
|
|
'F_SEARCH_ACTION' => 'search.php',
|
2006-05-16 00:21:08 +02:00
|
|
|
'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=search',
|
2008-05-01 03:12:34 +02:00
|
|
|
|
2008-02-28 03:41:48 +01:00
|
|
|
'month_list' => $month_list,
|
|
|
|
'START_DAY_SELECTED' => @$_POST['start_day'],
|
|
|
|
'START_MONTH_SELECTED' => @$_POST['start_month'],
|
|
|
|
'END_DAY_SELECTED' => @$_POST['end_day'],
|
|
|
|
'END_MONTH_SELECTED' => @$_POST['end_month'],
|
2006-05-16 00:21:08 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2006-12-21 22:38:20 +01:00
|
|
|
$available_tags = get_available_tags();
|
2006-05-16 00:21:08 +02:00
|
|
|
|
|
|
|
if (count($available_tags) > 0)
|
|
|
|
{
|
2008-07-01 04:09:21 +02:00
|
|
|
usort( $available_tags, 'tag_alpha_compare');
|
2006-05-16 00:21:08 +02:00
|
|
|
|
2014-06-16 16:17:53 +02:00
|
|
|
$template->assign('TAGS', $available_tags);
|
2006-05-16 00:21:08 +02:00
|
|
|
}
|
2004-02-08 02:28:18 +01:00
|
|
|
|
2014-06-16 15:53:16 +02:00
|
|
|
// 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',
|
2014-06-19 22:39:12 +02:00
|
|
|
'visible_images' => 'id'
|
2014-06-16 15:53:16 +02:00
|
|
|
),
|
|
|
|
' WHERE '
|
|
|
|
).'
|
|
|
|
AND author IS NOT NULL
|
|
|
|
GROUP BY author
|
|
|
|
ORDER BY author
|
|
|
|
;';
|
|
|
|
$authors = query2array($query);
|
|
|
|
|
|
|
|
$template->assign('AUTHORS', $authors);
|
|
|
|
|
2004-07-26 22:43:46 +02:00
|
|
|
//------------------------------------------------------------- categories form
|
2004-11-23 23:31:24 +01:00
|
|
|
$query = '
|
2008-05-01 03:12:34 +02:00
|
|
|
SELECT id,name,global_rank,uppercats
|
2006-12-21 22:38:20 +01:00
|
|
|
FROM '.CATEGORIES_TABLE.'
|
|
|
|
'.get_sql_condition_FandF
|
|
|
|
(
|
|
|
|
array
|
|
|
|
(
|
|
|
|
'forbidden_categories' => 'id',
|
|
|
|
'visible_categories' => 'id'
|
|
|
|
),
|
|
|
|
'WHERE'
|
|
|
|
).'
|
2004-11-23 23:31:24 +01:00
|
|
|
;';
|
2014-06-17 13:17:34 +02:00
|
|
|
display_select_cat_wrapper($query, array(), 'category_options', true);
|
2011-05-07 17:55:10 +02:00
|
|
|
|
|
|
|
// include menubar
|
|
|
|
$themeconf = $template->get_template_vars('themeconf');
|
2011-05-09 17:04:15 +02:00
|
|
|
if (!isset($themeconf['hide_menu_on']) OR !in_array('theSearchPage', $themeconf['hide_menu_on']))
|
2011-05-07 17:55:10 +02:00
|
|
|
{
|
|
|
|
include( PHPWG_ROOT_PATH.'include/menubar.inc.php');
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------ html code display
|
2006-12-02 17:46:15 +01:00
|
|
|
include(PHPWG_ROOT_PATH.'include/page_header.php');
|
2014-06-02 09:55:46 +02:00
|
|
|
trigger_notify('loc_end_search');
|
2013-02-07 22:17:08 +01:00
|
|
|
flush_page_messages();
|
2008-02-28 03:41:48 +01:00
|
|
|
$template->pparse('search');
|
2004-02-22 03:43:13 +01:00
|
|
|
include(PHPWG_ROOT_PATH.'include/page_tail.php');
|
2004-02-12 00:20:38 +01:00
|
|
|
?>
|