cvs: pearweb /public_html search.php

From: Date: Sun, 22 Mar 2009 17:11:34 +0000
Subject: cvs: pearweb /public_html search.php
Groups: php.pear.cvs php.pear.core 
Request: Send a blank email to pear-core+get-8276@lists.php.net to get a copy of this message
dufuz Sun Mar 22 17:11:34 2009 UTC Modified files: /pearweb/public_html search.php Log: Bug #15915 Search for developers - invalid pagination combo values [patch by amir] http://cvs.php.net/viewvc.cgi/pearweb/public_html/search.php?r1=1.21&r2=1.22&diff_format=u Index: pearweb/public_html/search.php diff -u pearweb/public_html/search.php:1.21 pearweb/public_html/search.php:1.22 --- pearweb/public_html/search.php:1.21 Fri Jan 25 00:44:59 2008 +++ pearweb/public_html/search.php Sun Mar 22 17:11:34 2009 @@ -1,74 +1,74 @@ -<?php -/* - +----------------------------------------------------------------------+ - | PEAR Web site version 1.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 2001-2005 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Martin Jansen <mj@php.net> | - +----------------------------------------------------------------------+ - $Id: search.php,v 1.21 2008/01/25 00:44:59 dufuz Exp $ -*/ - -require_once 'Damblan/Search.php'; - -$term = (isset($_GET['q']) ? trim(htmlspecialchars(strip_tags(urldecode($_GET['q'])))) : ''); -$in = (isset($_GET['in']) ? htmlspecialchars(strip_tags($_GET['in'])) : 'packages'); -$perP = (isset($_GET['setPerPage'])) ? (int)$_GET['setPerPage'] : 10; - -$search = Damblan_Search::factory($in, $dbh); -$search->setPerPage($perP); -$search->search($term); -$pager =& $search->getPager(); - -response_header('Search: ' . $term); - -echo "<h1>Search</h1>\n"; -echo "<h2>" . $search->getTitle() . "</h2>\n"; - -echo "<form method=\"get\" name=\"search\" action=\"search.php\">\n"; -echo "<input type=\"text\" name=\"q\" value=\"" . $term . "\" size=\"30\" /> in "; - -echo "<select name=\"in\" size=\"1\">\n"; -foreach (array("packages" => "Packages", "site" => "This Site (using Yahoo!)", "users" => "Developers") as $key => $value) { - $selected = ($key == $in) ? " selected=\"yes\" " : ""; - echo "<option value=\"" . $key . "\" " . $selected . ">" . $value . "</option>\n"; -} -echo "</select>\n"; -if (is_object($pager)) { - echo $pager->getPerPageSelectBox(10, 90, 10, false, array('optionText' => '%d packages', 'attributes' => 'id="perPage"', 'checkMaxLimit' => true)); -} -echo "<input type=\"submit\" value=\"Search\" />\n"; -echo "<script language=\"JavaScript\" type=\"text/javascript\">document.forms.search.q.focus();</script>\n"; -echo "</form>\n"; - -$total = $search->getTotal(); - -if ($total > 0) { - $start = (($pager->getCurrentPageID() - 1) * $search->getPerPage()) + 1; - $end = ($start + $search->getPerPage() - 1 < $total ? $start + $search->getPerPage() - 1 : $total); - - echo "<p>Results <strong>" . $start . " - " . $end . "</strong> of <strong>" . $search->getTotal() . "</strong>:</p>\n"; - - echo "<ol start=\"" . $start . "\">\n"; - foreach ($search->getResults() as $result) { - echo "<li>\n"; - echo $result['html']; - echo "</li>\n"; - } - echo "</ol>\n"; - - echo $pager->links; -} else if (!empty($term)) { - echo "<p><div class=\"explain\">Sorry, but we didn't find anything that matches &quot;" . $term . "&quot;.</div></p>\n"; -} - +<?php +/* + +----------------------------------------------------------------------+ + | PEAR Web site version 1.0 | + +----------------------------------------------------------------------+ + | Copyright (c) 2001-2005 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 2.02 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | http://www.php.net/license/2_02.txt. | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Martin Jansen <mj@php.net> | + +----------------------------------------------------------------------+ + $Id: search.php,v 1.22 2009/03/22 17:11:34 dufuz Exp $ +*/ + +require_once 'Damblan/Search.php'; + +$term = (isset($_GET['q']) ? trim(htmlspecialchars(strip_tags(urldecode($_GET['q'])))) : ''); +$in = (isset($_GET['in']) ? htmlspecialchars(strip_tags($_GET['in'])) : 'packages'); +$perP = (isset($_GET['setPerPage'])) ? (int)$_GET['setPerPage'] : 10; + +$search = Damblan_Search::factory($in, $dbh); +$search->setPerPage($perP); +$search->search($term); +$pager =& $search->getPager(); + +response_header('Search: ' . $term); + +echo "<h1>Search</h1>\n"; +echo "<h2>" . $search->getTitle() . "</h2>\n"; + +echo "<form method=\"get\" name=\"search\" action=\"search.php\">\n"; +echo "<input type=\"text\" name=\"q\" value=\"" . $term . "\" size=\"30\" /> in "; + +echo "<select name=\"in\" size=\"1\">\n"; +foreach (array("packages" => "Packages", "site" => "This Site (using Yahoo!)", "users" => "Developers") as $key => $value) { + $selected = ($key == $in) ? " selected=\"yes\" " : ""; + echo "<option value=\"" . $key . "\" " . $selected . ">" . $value . "</option>\n"; +} +echo "</select>\n"; +if ($search->getTotal() > $perP) { + echo $pager->getPerPageSelectBox(10, 90, 10, false, array('optionText' => '%d items', 'attributes' => 'id="perPage"', 'checkMaxLimit' => true)); +} +echo "<input type=\"submit\" value=\"Search\" />\n"; +echo "<script language=\"JavaScript\" type=\"text/javascript\">document.forms.search.q.focus();</script>\n"; +echo "</form>\n"; + +$total = $search->getTotal(); + +if ($total > 0) { + $start = (($pager->getCurrentPageID() - 1) * $search->getPerPage()) + 1; + $end = ($start + $search->getPerPage() - 1 < $total ? $start + $search->getPerPage() - 1 : $total); + + echo "<p>Results <strong>" . $start . " - " . $end . "</strong> of <strong>" . $search->getTotal() . "</strong>:</p>\n"; + + echo "<ol start=\"" . $start . "\">\n"; + foreach ($search->getResults() as $result) { + echo "<li>\n"; + echo $result['html']; + echo "</li>\n"; + } + echo "</ol>\n"; + + echo $pager->links; +} else if (!empty($term)) { + echo "<p><div class=\"explain\">Sorry, but we didn't find anything that matches &quot;" . $term . "&quot;.</div></p>\n"; +} + response_footer(); \ No newline at end of file

« previous php.pear.core (#8276) next »