diff --git a/include/functions_search.inc.php b/include/functions_search.inc.php index a03e2e572..f70fab46e 100644 --- a/include/functions_search.inc.php +++ b/include/functions_search.inc.php @@ -67,14 +67,6 @@ function get_search_array($search_id) { bad_request('this search identifier does not exist'); } - else - { - if (!empty($search['created_by']) and $search['created_by'] != $user['user_id']) - { - // we need to fork this search - save_search_and_redirect(unserialize($search['rules']), $search['id']); - } - } return unserialize($search['rules']); } @@ -1726,7 +1718,7 @@ SELECT } } -function save_search_and_redirect($rules, $forked_from=null) +function save_search($rules, $forked_from=null) { global $user; @@ -1745,14 +1737,14 @@ function save_search_and_redirect($rules, $forked_from=null) ) ); - redirect( - make_index_url( - array( - 'section' => 'search', - 'search' => $search_uuid, - ) + $url = make_index_url( + array( + 'section' => 'search', + 'search' => $search_uuid, ) ); + + return array($search_uuid, $url); } ?> diff --git a/include/ws_functions/pwg.images.php b/include/ws_functions/pwg.images.php index c90764196..cb71da75b 100644 --- a/include/ws_functions/pwg.images.php +++ b/include/ws_functions/pwg.images.php @@ -690,34 +690,29 @@ SELECT * /** * API method - * Returns a list of elements corresponding to a query search + * Registers a new search * @param mixed[] $params * @option string query - * @option int per_page - * @option int page - * @option string order (optional) */ -function ws_images_filteredSearch_update($params, $service) +function ws_images_filteredSearch_create($params, $service) { global $user; include_once(PHPWG_ROOT_PATH.'include/functions_search.inc.php'); // * check the search exists - if (empty(get_search_id_pattern($params['search_id']))) + if (isset($params['search_id'])) { - return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid search_id input parameter.'); - } + if (empty(get_search_id_pattern($params['search_id']))) + { + return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid search_id input parameter.'); + } - $search_info = get_search_info($params['search_id']); - if (empty($search_info)) - { - return new PwgError(WS_ERR_INVALID_PARAM, 'This search does not exist.'); - } - - if (!empty($search_info['created_by']) and $search_info['created_by'] != $user['user_id']) - { - return new PwgError(WS_ERR_INVALID_PARAM, 'This search was created by another user.'); + $search_info = get_search_info($params['search_id']); + if (empty($search_info)) + { + return new PwgError(WS_ERR_INVALID_PARAM, 'This search does not exist.'); + } } $search = array('mode' => 'AND'); @@ -846,15 +841,12 @@ function ws_images_filteredSearch_update($params, $service) $search['fields']['date_posted'] = $params['date_posted']; } - // register search rules in database, then they will be available on - // thumbnails page and picture page. - $query =' -UPDATE '.SEARCH_TABLE.' - SET rules = \''.pwg_db_real_escape_string(serialize($search)).'\' - , last_seen = NOW() - WHERE id = '.$search_info['id'].' -;'; - pwg_query($query); + list($search_uuid, $search_url) = save_search($search, $search_info['id'] ?? null); + + return array( + 'search_id' => $search_uuid, + 'search_url' => $search_url, + ); } /** diff --git a/search.php b/search.php index 42ba61321..83e8311f2 100644 --- a/search.php +++ b/search.php @@ -92,5 +92,6 @@ if (count($first_author) > 0) ); } -save_search_and_redirect($search); +list($search_uuid, $search_url) = save_search($search); +redirect($search_url); ?> diff --git a/themes/default/js/mcs.js b/themes/default/js/mcs.js index 1ec844e4c..26deeb127 100644 --- a/themes/default/js/mcs.js +++ b/themes/default/js/mcs.js @@ -700,13 +700,13 @@ $(document).ready(function () { function performSearch(params, reload = false) { $.ajax({ - url: "ws.php?format=json&method=pwg.images.filteredSearch.update", + url: "ws.php?format=json&method=pwg.images.filteredSearch.create", type:"POST", dataType: "json", data: params, success:function(data) { - if (reload) { - reloadPage(); + if (reload && typeof data.result.search_url !== 'undefined') { + reloadPage(data.result.search_url); } }, error:function(e) { @@ -842,6 +842,6 @@ function updateFilters(filterName, mode) { } } -function reloadPage(){ - location.reload(true); +function reloadPage(url){ + window.location.href = url; } \ No newline at end of file diff --git a/ws.php b/ws.php index 45857e027..c205c84a3 100644 --- a/ws.php +++ b/ws.php @@ -1369,10 +1369,13 @@ enabled_high, registration_date, registration_date_string, registration_date_sin ); $service->addMethod( - 'pwg.images.filteredSearch.update', - 'ws_images_filteredSearch_update', + 'pwg.images.filteredSearch.create', + 'ws_images_filteredSearch_create', array( - 'search_id' => array(), + 'search_id' => array( + 'flags' => WS_PARAM_OPTIONAL, + 'info' => 'prior search_id (or search_key), if any', + ), 'allwords' => array( 'flags' => WS_PARAM_OPTIONAL, 'info' => 'query to search by words',