Files
gallery3/modules/search/controllers/search.php
T
Tim Almdal a246b6fe45 Initial commit of a patch for Ticket #1764. as discussed here: https://github.com/gallery/gallery3/pull/58/files#r72949.
Create a Breadcrumb library which has two static methods for_item (which takes a an item and builds the entire
breadcrumb for the item) or build (which takes a variable number of Breadcrumb elements and creates a breadcrumb
based on the specified elements).

Used tag->url() to build the tag album url. Escaped the query string for the search. Tightened up the breadcrumb code
 in page.html.php.

When adding the show query parameter, we can't blindly concatenate using the ? separator.  We have to check that we
use a & if a query parameter already exists.
2011-08-11 22:04:02 -07:00

56 lines
2.2 KiB
PHP

<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2011 Bharat Mediratta
*
* 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
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* 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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Search_Controller extends Controller {
public function index() {
$page_size = module::get_var("gallery", "page_size", 9);
$q = Input::instance()->get("q");
$page = Input::instance()->get("page", 1);
// Make sure that the page references a valid offset
if ($page < 1) {
$page = 1;
}
$offset = ($page - 1) * $page_size;
$q_with_more_terms = search::add_query_terms($q);
list ($count, $result) = search::search($q_with_more_terms, $page_size, $offset);
$max_pages = max(ceil($count / $page_size), 1);
$template = new Theme_View("page.html", "collection", "search");
$root = item::root();
$search_url = url::abs_site("search?q=" . urlencode($q));
$template->set_global(array("page" => $page,
"max_pages" => $max_pages,
"page_size" => $page_size,
"breadcrumbs" => Breadcrumb::build_from_list(
new Breadcrumb(item::root()->title, "/", item::root()->id),
new Breadcrumb($q, $search_url)),
"children_count" => $count));
$template->content = new View("search.html");
$template->content->items = $result;
$template->content->q = $q;
print $template;
}
}