зеркало из https://github.com/mozilla/pjs.git
Bug 247810 Mozilla Update (update.mozilla.org) needs a Search Feature
Patch by Ted Mielczarek <ted.mielczarek@gmail.com>, r=alanjstr
This commit is contained in:
Родитель
a76d14bdc8
Коммит
26fc39ec35
|
@ -68,14 +68,19 @@
|
|||
<li><a href="/about/" title="Learn More About Mozilla Updates">about</a></li>
|
||||
<li><a href="/developers/" title="Find Tools and Information for Developers">developers</a></li>
|
||||
<li>
|
||||
<form id="search" method="get" action="http://www.google.com/custom" title="Mozilla.org Search">
|
||||
<form id="search" method="get" action="/quicksearch.php" title="Search Mozilla Update">
|
||||
<div>
|
||||
<label for="q" title="Search mozilla.org"s sites">search:</label>
|
||||
<input type="hidden" name="cof" value="">
|
||||
<input type="hidden" name="domains" value="update.mozilla.org">
|
||||
<input type="hidden" name="sitesearch" value="update.mozilla.org">
|
||||
<label for="q" title="Search Mozilla Update">search:</label>
|
||||
<input type="text" id="q" name="q" accesskey="s" size="10">
|
||||
<select name="section" id="sectionsearch"><option value="1">Entire Site</option><option value="2">Extensions</option><option value="">Themes</option><!--<option value="3">Plugins</option><option value="4">Search Engines</option>--></select>
|
||||
<select name="section" id="sectionsearch">
|
||||
<option value="A">Entire Site</option>
|
||||
<option value="E">Extensions</option>
|
||||
<option value="T">Themes</option>
|
||||
<!--
|
||||
<option value="P">Plugins</option>
|
||||
<option value="S">Search Engines</option>
|
||||
-->
|
||||
</select>
|
||||
<input type="submit" id="submit" value="Go">
|
||||
</div>
|
||||
</form>
|
||||
|
|
|
@ -0,0 +1,235 @@
|
|||
<?php
|
||||
// ***** BEGIN LICENSE BLOCK *****
|
||||
// Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
//
|
||||
// The contents of this file are subject to the Mozilla Public License Version
|
||||
// 1.1 (the "License"); you may not use this file except in compliance with
|
||||
// the License. You may obtain a copy of the License at
|
||||
// http://www.mozilla.org/MPL/
|
||||
//
|
||||
// Software distributed under the License is distributed on an "AS IS" basis,
|
||||
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
// for the specific language governing rights and limitations under the
|
||||
// License.
|
||||
//
|
||||
// The Original Code is Mozilla Update.
|
||||
//
|
||||
// The Initial Developer of the Original Code is
|
||||
// Chris "Wolf" Crews.
|
||||
// Portions created by the Initial Developer are Copyright (C) 2004
|
||||
// the Initial Developer. All Rights Reserved.
|
||||
//
|
||||
// Contributor(s):
|
||||
// Chris "Wolf" Crews <psychoticwolf@carolina.rr.com>
|
||||
// Chris "CTho" Thomas <cst@andrew.cmu.edu>
|
||||
// Alan "alanjstr" Starr <bugzilla-alanjstrBugs@sneakemail.com>
|
||||
// Ted "luser" Mielczarek <ted.mielczarek@gmail.com>
|
||||
//
|
||||
// Alternatively, the contents of this file may be used under the terms of
|
||||
// either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
// the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
// in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
// of those above. If you wish to allow use of your version of this file only
|
||||
// under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
// use your version of this file under the terms of the MPL, indicate your
|
||||
// decision by deleting the provisions above and replace them with the notice
|
||||
// and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
// the provisions above, a recipient may use your version of this file under
|
||||
// the terms of any one of the MPL, the GPL or the LGPL.
|
||||
//
|
||||
// ***** END LICENSE BLOCK *****
|
||||
?>
|
||||
<?php
|
||||
require"core/config.php";
|
||||
?>
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html lang="en">
|
||||
<head>
|
||||
|
||||
<?php
|
||||
// Prints which items are being displayed and what page is being displayed
|
||||
// i.e. "X - Y of Z | Page M of N"
|
||||
function print_page_list($startitem, $enditem, $totalresults, $num_pages, $pageid)
|
||||
{
|
||||
global $searchStr, $section;
|
||||
|
||||
echo"<h3>Results</h3>\n";
|
||||
|
||||
echo "$startitem - $enditem of $totalresults | ";
|
||||
|
||||
$previd=$pageid-1;
|
||||
if ($previd >"0") {
|
||||
echo"<a href=\"?q=$searchStr§ion=$section&pageid=$previd\">« Previous</a> • ";
|
||||
}
|
||||
echo "Page $pageid of $num_pages";
|
||||
|
||||
$nextid=$pageid+1;
|
||||
if ($pageid <$num_pages) {
|
||||
echo" • <a href=\"?q=$searchStr§ion=$section&pageid=$nextid\">Next »</a>";
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------
|
||||
//Global General $_GET variables
|
||||
//----------------------------
|
||||
//Detection Override
|
||||
$didSearch = 0;
|
||||
if ($_GET["q"] || $_GET["pageid"]) $didSearch = 1;
|
||||
|
||||
$items_per_page="10"; //Default Num per Page is 10
|
||||
|
||||
//Default PageID is 1
|
||||
if (!$_GET["pageid"]) {$pageid="1"; } else { $pageid = $_GET["pageid"]; }
|
||||
|
||||
// grab query string
|
||||
if ($_GET["q"]) {
|
||||
$searchStr = escape_string($_GET["q"]);
|
||||
$section = escape_string($_GET["section"]);
|
||||
}
|
||||
|
||||
?>
|
||||
<title>Mozilla Update :: Search<?php if ($didSearch) {echo " - Results - Page $pageid"; } ?></title>
|
||||
<?php
|
||||
include"$page_header";
|
||||
|
||||
// -----------------------------------------------
|
||||
// Begin Content of the Page Here
|
||||
// -----------------------------------------------
|
||||
|
||||
if ($didSearch) {
|
||||
// build our query
|
||||
$sql = "FROM `main` TM
|
||||
INNER JOIN version TV ON TM.ID = TV.ID
|
||||
INNER JOIN os TOS ON TV.OSID = TOS.OSID
|
||||
INNER JOIN applications TA ON TV.AppID = TA.AppID
|
||||
WHERE (TM.name LIKE '%$searchStr%' OR TM.Description LIKE '%$searchStr%') AND (TOS.OSName = '$OS' OR TOS.OSName = 'ALL') AND TA.AppName = '$application'";
|
||||
|
||||
// search extensions/themes/etc
|
||||
if($section !== "A") {
|
||||
$sql .= " AND TM.Type = '$section'";
|
||||
}
|
||||
|
||||
// get the number of items first.
|
||||
// this is so that we can figure out what page we're on
|
||||
// and only pull $items_per_page results in the real query
|
||||
$resultsquery = "SELECT COUNT(*) " . $sql;
|
||||
|
||||
// Get Total Results from Result Query & Populate Page Control Vars.
|
||||
$sql_result = mysql_query($resultsquery, $connection) or trigger_error("MySQL Error ".mysql_errno().": ".mysql_error()."", E_USER_NOTICE);
|
||||
$row = mysql_fetch_array($sql_result);
|
||||
$totalresults = $row[0];
|
||||
unset($row);
|
||||
|
||||
// Total # of Pages
|
||||
$num_pages = ceil($totalresults/$items_per_page);
|
||||
$num_pages = max($num_pages,1);
|
||||
|
||||
// Check PageId for Validity
|
||||
$pageid = max($num_pages, min(1, $pageid));
|
||||
// Determine startitem,startpoint, enditem
|
||||
$startpoint = ($pageid-1) * $items_per_page;
|
||||
$startitem = $startpoint + 1;
|
||||
$enditem = $startpoint + $items_per_page;
|
||||
if ($totalresults == "0") { $startitem = "0"; }
|
||||
|
||||
// Verify EndItem
|
||||
if ($enditem > $totalresults) { $enditem = $totalresults; }
|
||||
|
||||
// now build the query to get the item details
|
||||
// only $items_per_page number results,
|
||||
// starting at $startpoint
|
||||
$resultsquery = "SELECT TM.ID, TM.Name, TM.Description, TM.Type, TV.Version
|
||||
" . $sql ."
|
||||
GROUP BY TM.Name
|
||||
ORDER BY TM.Name
|
||||
LIMIT $startpoint , $items_per_page";
|
||||
|
||||
print_page_list($startitem, $enditem, $totalresults, $num_pages, $pageid);
|
||||
echo"<br><br>\n";
|
||||
|
||||
//---------------------------------
|
||||
// Begin List
|
||||
//---------------------------------
|
||||
// Query for items (if there are any)
|
||||
if($totalresults > 0) {
|
||||
$sql_result = mysql_query($resultsquery, $connection) or trigger_error("MySQL Error ".mysql_errno().": ".mysql_error()."", E_USER_NOTICE);
|
||||
while ($row = mysql_fetch_array($sql_result)) {
|
||||
$id = $row["ID"];
|
||||
$name = $row["Name"];
|
||||
$description = $row["Description"];
|
||||
$itemtype = $row["Type"];
|
||||
$version = $row["Version"];
|
||||
|
||||
echo "<div class=\"searchresult\">\n";
|
||||
//XXX this absolutely sucks. can't we have a function
|
||||
// to get the info URL for an item given its id?
|
||||
$typedirs = array("E"=>"extensions","T"=>"themes","U"=>"update");
|
||||
$typedir = $typedirs[$itemtype];
|
||||
echo "<h5 class=\"title\"><a href=\"$typedir/moreinfo.php?id=$id\">$name $version</a>";
|
||||
echo "</h5>";
|
||||
|
||||
// Description
|
||||
echo substr($description,0,250);
|
||||
echo"</div>\n";
|
||||
|
||||
} //End While Loop
|
||||
}
|
||||
else {
|
||||
|
||||
?>
|
||||
<div id="item" class="noitems">
|
||||
No items found matching "<?=$searchStr?>".
|
||||
</div>
|
||||
<?php
|
||||
|
||||
}
|
||||
}
|
||||
else { // no search, display a form
|
||||
?>
|
||||
<form action="quicksearch.php" method="GET">
|
||||
<div class="key-point">
|
||||
Search For: <input type="text" name="q">
|
||||
<select name="section" id="sectionsearch"><option value="A">Entire Site</option><option value="E">Extensions</option><option value="T">Themes</option><!--<option value="P">Plugins</option><option value="S">Search Engines</option>--></select>
|
||||
<input type="submit" value="search">
|
||||
</div>
|
||||
</form>
|
||||
<?
|
||||
}
|
||||
|
||||
// Footer page # display
|
||||
if ($didSearch) {
|
||||
print_page_list($startitem, $enditem, $totalresults, $num_pages, $pageid);
|
||||
echo"<br>\n";
|
||||
|
||||
// Skip to Page...
|
||||
if ($pageid <= $num_pages && $num_pages > 1) {
|
||||
echo "Jump to Page: ";
|
||||
$pagesperpage = 9; // Plus 1 by default..
|
||||
$i = 01;
|
||||
//Dynamic Starting Point
|
||||
if ($pageid > 11) {
|
||||
$nextpage = $pageid - 10;
|
||||
}
|
||||
$i = $nextpage;
|
||||
|
||||
// Dynamic Ending Point
|
||||
$maxpagesonpage = $pageid + $pagesperpage;
|
||||
// Page #s
|
||||
while ($i <= $maxpagesonpage && $i <= $num_pages) {
|
||||
if ($i==$pageid) {
|
||||
echo"<span style=\"color: #FF0000\">$i</span> ";
|
||||
} else {
|
||||
echo"<a href=\"?q=$searchStr§ion=$section&pageid=$i\">$i</a> ";
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
<?php
|
||||
include"$page_footer";
|
||||
?>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче