diff options
Diffstat (limited to 'modules/search')
| -rw-r--r-- | modules/search/controllers/search.php | 5 | ||||
| -rw-r--r-- | modules/search/helpers/search.php | 23 | ||||
| -rw-r--r-- | modules/search/views/search.html.php | 16 | ||||
| -rw-r--r-- | modules/search/views/search_link.html.php | 6 |
4 files changed, 25 insertions, 25 deletions
diff --git a/modules/search/controllers/search.php b/modules/search/controllers/search.php index 08128ae8..cf9e271f 100644 --- a/modules/search/controllers/search.php +++ b/modules/search/controllers/search.php @@ -30,7 +30,12 @@ class Search_Controller extends Controller { } list ($count, $result) = search::search($q, $page_size, $offset); + + $max_pages = max(ceil($count / $page_size), 1); + $template = new Theme_View("page.html", "search"); + $template->set_global("page", $page); + $template->set_global("max_pages", $max_pages); $template->set_global("page_size", $page_size); $template->set_global("children_count", $count); diff --git a/modules/search/helpers/search.php b/modules/search/helpers/search.php index 0080b4ce..8c3bd3ab 100644 --- a/modules/search/helpers/search.php +++ b/modules/search/helpers/search.php @@ -22,30 +22,25 @@ class search_Core { $db = Database::instance(); $q = $db->escape_str($q); - if (!user::active()->admin) { - foreach (user::group_ids() as $id) { + if (!identity::active_user()->admin) { + foreach (identity::group_ids_for_active_user() as $id) { $fields[] = "`view_$id` = TRUE"; // access::ALLOW } - $access_sql = "AND (" . join(" AND ", $fields) . ")"; + $access_sql = "AND (" . join(" OR ", $fields) . ")"; } else { $access_sql = ""; } - // Count the total number of rows. We can't do this with our regular query because of the - // limit statement. It's possible that if we get rid of the limit (but keep the offset) on - // the 2nd query and combine the two, it might be faster than making 2 separate queries. - $count_query = "SELECT COUNT(*) AS c " . - "FROM {items} JOIN {search_records} ON ({items}.`id` = {search_records}.`item_id`) " . - "WHERE MATCH({search_records}.`data`) AGAINST ('$q' IN BOOLEAN MODE) " . - $access_sql; - $count = $db->query($count_query)->current()->c; - - $query = "SELECT {items}.*, MATCH({search_records}.`data`) AGAINST ('$q') AS `score` " . + $query = + "SELECT SQL_CALC_FOUND_ROWS {items}.*, " . + " MATCH({search_records}.`data`) AGAINST ('$q') AS `score` " . "FROM {items} JOIN {search_records} ON ({items}.`id` = {search_records}.`item_id`) " . "WHERE MATCH({search_records}.`data`) AGAINST ('$q' IN BOOLEAN MODE) " . $access_sql . "ORDER BY `score` DESC " . "LIMIT $limit OFFSET $offset"; + $data = $db->query($query); + $count = $db->query("SELECT FOUND_ROWS() as c")->current()->c; return array($count, new ORM_Iterator(ORM::factory("item"), $db->query($query))); } @@ -57,7 +52,7 @@ class search_Core { list ($remaining) = search::stats(); if ($remaining) { site_status::warning( - t('Your search index needs to be updated. <a href="%url" class="gDialogLink">Fix this now</a>', + t('Your search index needs to be updated. <a href="%url" class="g-dialog-link">Fix this now</a>', array("url" => html::mark_clean(url::site("admin/maintenance/start/search_task::update_index?csrf=__CSRF__")))), "search_index_out_of_date"); } diff --git a/modules/search/views/search.html.php b/modules/search/views/search.html.php index 91d9eec8..fdf22a9e 100644 --- a/modules/search/views/search.html.php +++ b/modules/search/views/search.html.php @@ -1,6 +1,6 @@ <?php defined("SYSPATH") or die("No direct script access.") ?> <? // @todo Set hover on AlbumGrid list items ?> -<form action="<?= url::site("/search") ?>" id="gSearchForm"> +<form action="<?= url::site("/search") ?>" id="g-search-form" class="g-short-form"> <fieldset> <legend> <?= t("Search") ?> @@ -17,17 +17,17 @@ </fieldset> </form> -<div id="gSearchResults"> - <h1><?= t("Search Results") ?></h1> +<div id="g-search-results"> + <h1><?= t("Search results") ?></h1> <? if (count($items)): ?> - <ul id="gAlbumGrid"> + <ul id="g-album-grid" class="ui-helper-clearfix"> <? foreach ($items as $item): ?> - <? $item_class = "gPhoto"; ?> + <? $item_class = "g-photo"; ?> <? if ($item->is_album()): ?> - <? $item_class = "gAlbum"; ?> + <? $item_class = "g-album"; ?> <? endif ?> - <li class="gItem <?= $item_class ?>"> + <li class="g-item <?= $item_class ?>"> <a href="<?= $item->url() ?>"> <?= $item->thumb_img() ?> <p> @@ -40,7 +40,7 @@ </li> <? endforeach ?> </ul> - <?= $theme->pager() ?> + <?= $theme->paginator() ?> <? else: ?> <p> diff --git a/modules/search/views/search_link.html.php b/modules/search/views/search_link.html.php index 51bb4e14..481d0c82 100644 --- a/modules/search/views/search_link.html.php +++ b/modules/search/views/search_link.html.php @@ -1,9 +1,9 @@ <?php defined("SYSPATH") or die("No direct script access.") ?> -<form action="<?= url::site("search") ?>" id="gQuickSearchForm"> +<form action="<?= url::site("search") ?>" id="g-quick-search-form" class="g-short-form"> <ul> <li> - <label for="gSearch"><?= t("Search the gallery") ?></label> - <input type="text" name="q" id="gSearch"/> + <label for="g-search"><?= t("Search the gallery") ?></label> + <input type="text" name="q" id="g-search"/> </li> <li> <input type="submit" value="<?= t("Go")->for_html_attr() ?>" /> |
