Search options are now populated. Next up is query forumlation and pagination along with displaying results.

This commit is contained in:
mike.morgan%oregonstate.edu 2005-07-24 11:34:05 +00:00
Родитель 9328a8c8e2
Коммит 0fd28e841e
8 изменённых файлов: 129 добавлений и 60 удалений

Просмотреть файл

@ -17,6 +17,7 @@ $sql['ID'] =& $clean['ID'];
$addon = new AddOn($sql['ID']); $addon = new AddOn($sql['ID']);
$addon->getHistory(); $addon->getHistory();
// Assign template variables. // Assign template variables.
$tpl->assign( $tpl->assign(
array( 'addon' => $addon, array( 'addon' => $addon,
@ -24,3 +25,4 @@ $tpl->assign(
'content' => 'history.tpl', 'content' => 'history.tpl',
'sidebar' => 'inc/addon-sidebar.tpl') 'sidebar' => 'inc/addon-sidebar.tpl')
); );
?>

Просмотреть файл

@ -84,9 +84,4 @@ $tpl = new AMO_Smarty();
// Global DB object. // Global DB object.
$db = new AMO_SQL(); $db = new AMO_SQL();
// Global categories array.
$db->query("SELECT DISTINCT CatName FROM categories ORDER BY CatName", SQL_ALL, SQL_ASSOC);
$cats = $db->record;
$tpl->assign('cats',$cats);
?> ?>

Просмотреть файл

@ -51,7 +51,7 @@ class AddOn extends AMO_Object
var $Comments; var $Comments;
// Categories. // Categories.
var $Cats; var $AddonCats;
// History of releases // History of releases
var $History; var $History;
@ -79,7 +79,7 @@ class AddOn extends AMO_Object
function getAddOn() function getAddOn()
{ {
$this->getCats(); $this->getAddonCats();
$this->getComments(); $this->getComments();
$this->getCurrentVersion(); $this->getCurrentVersion();
$this->getMainPreview(); $this->getMainPreview();
@ -245,11 +245,12 @@ class AddOn extends AMO_Object
$this->setVar('Comments',$this->db->record); $this->setVar('Comments',$this->db->record);
} }
function getCats() function getAddonCats()
{ {
// Gather addon categories. // Gather addon categories.
$this->db->query(" $this->db->query("
SELECT DISTINCT SELECT DISTINCT
categories.CatID,
categories.CatName categories.CatName
FROM FROM
categoryxref categoryxref
@ -261,7 +262,7 @@ class AddOn extends AMO_Object
categories.CatName categories.CatName
", SQL_ALL, SQL_ASSOC); ", SQL_ALL, SQL_ASSOC);
$this->Cats = $this->db->record; $this->AddonCats = $this->db->record;
} }
} }
?> ?>

Просмотреть файл

@ -4,7 +4,9 @@
*/ */
class AMO_Object class AMO_Object
{ {
var $wrapper; var $cats;
var $apps;
var $platforms;
function AMO_Object() function AMO_Object()
{ {
@ -49,5 +51,63 @@ class AMO_Object
} }
} }
function getCats()
{
// Gather categories.
$this->db->query("
SELECT
CategoryID,
CatName
FROM
categories
GROUP BY
CatName
ORDER BY
CatName
", SQL_INIT, SQL_ASSOC);
do {
$this->Cats[$this->db->record['CategoryID']] = $this->db->record['CatName'];
} while ($this->db->next(SQL_ASSOC));
}
function getPlatforms()
{
// Gather platforms..
$this->db->query("
SELECT
OSID,
OSName
FROM
os
ORDER BY
OSName
", SQL_INIT, SQL_ASSOC);
do {
$this->Platforms[$this->db->record['OSID']] = $this->db->record['OSName'];
} while ($this->db->next(SQL_ASSOC));
}
function getApps()
{
// Gather aapplications.
$this->db->query("
SELECT DISTINCT
AppID,
AppName
FROM
applications
WHERE
public_ver = 'YES'
GROUP BY
AppName
", SQL_INIT, SQL_ASSOC);
do {
$this->Apps[$this->db->record['AppID']] = $this->db->record['AppName'];
} while ($this->db->next(SQL_ASSOC));
}
} }
?> ?>

Просмотреть файл

@ -11,8 +11,8 @@ $clean = array();
$sql = array(); $sql = array();
// Category. // Category.
if (isset($_GET['cat'])&&ctype_alpha($_GET['cat'])) { if (isset($_GET['cat'])&&ctype_digit($_GET['cat'])) {
$clean['cat'] = $_GET['cat']; $clean['cat'] = intval($_GET['cat']);
} }
// Type. // Type.
@ -28,13 +28,13 @@ if (isset($_GET['type'])) {
} }
// Platform. // Platform.
if (isset($_GET['platform'])&&ctype_alpha($_GET['platform'])) { if (isset($_GET['platform'])&&ctype_digit($_GET['platform'])) {
$clean['platform'] = $_GET['platform']; $clean['platform'] = intval($_GET['platform']);
} }
// Date. // Date.
if (isset($_GET['date'])&&ctype_alnum($_GET['date'])) { if (isset($_GET['date'])&&ctype_alpha($_GET['date'])) {
$clean['date'] = strtotime($_GET['date']); $clean['date'] = $_GET['date'];
} }
// Application. // Application.
@ -43,33 +43,62 @@ if (isset($_GET['app'])&&ctype_alpha($_GET['app'])) {
} }
// Sort. // Sort.
if (isset($_GET['sort'])&&ctype_alpha($_GET['sort'])) { if (isset($_GET['sort'])&&ctype_digit($_GET['sort'])) {
$clean['sort'] = $_GET['sort']; $clean['sort'] = $_GET['sort'];
} }
// Query. // Query.
if (isset($_GET['q'])&&preg_match("/[a-zA-Z0-9'\.-]*/",$_GET['q'])) { if (isset($_GET['q'])&&preg_match("/^[a-zA-Z0-9'\.-]*$/",$_GET['q'])) {
$clean['q'] = $_GET['q']; $clean['q'] = $_GET['q'];
} }
// Sort.
if (isset($_GET['sort'])&&ctype_alpha($_GET['sort'])) {
$clean['sort'] = $_GET['sort'];
}
// Prepared verified inputs for their destinations. // Prepared verified inputs for their destinations.
foreach ($clean as $key=>$val) { foreach ($clean as $key=>$val) {
$sql[$key] = mysql_real_escape_string($val); $sql[$key] = mysql_real_escape_string($val);
} }
// Format inputs for
$amo = new AMO_Object();
$amo->getCats();
$amo->getPlatforms();
$dates = array(
'day' => 'Today',
'week' => 'This Week',
'month'=> 'This Month',
'year' => 'This Year'
);
$sort = array(
'name' => 'Name',
'rating' => 'Rating',
'downloads' => 'Popularity',
);
$apps = array(
'Firefox' => 'Firefox',
'Thunderbird' => 'Thunderbird',
'Mozilla' => 'Mozilla'
);
$tpl->assign( $tpl->assign(
array( array(
'clean' => $clean, 'clean' => $clean,
'cats' => $amo->Cats,
'platforms' => $amo->Platforms,
'apps' => $apps,
'dates' => $dates,
'sort' => $sort,
'content' => 'search.tpl', 'content' => 'search.tpl',
'title' => 'Search', 'title' => 'Search',
) )
); );
$wrapper = 'inc/wrappers/nonav.tpl'; $wrapper = 'inc/wrappers/nonav.tpl';
echo '<pre>';
print_r($clean);
echo '</pre>';
?> ?>

Просмотреть файл

@ -17,8 +17,8 @@
</ul> </ul>
<li><span>Find similar Addons...</span> <li><span>Find similar Addons...</span>
<ul> <ul>
{section name=cats loop=$addon->Cats} {section name=cats loop=$addon->AddonCats}
<li><a href="./search.php?cat={$addon->Cats[cats].CatName}" title="See other Addons in this category.">{$addon->Cats[cats].CatName}</a></li> <li><a href="./search.php?cat={$addon->AddonCats[cats].CatName}" title="See other Addons in this category.">{$addon->AddonCats[cats].CatName}</a></li>
{/section} {/section}
<li><a href="./search.php?app={$addon->AppName}">Other {$addon->AppName} Addons</a></li> <li><a href="./search.php?app={$addon->AppName}">Other {$addon->AppName} Addons</a></li>
</ul> </ul>

Просмотреть файл

@ -36,17 +36,8 @@
<div id="key-menu" class="earth"> <div id="key-menu" class="earth">
<form id="search" method="get" action="{$config.webpath}/search.php" title="Search Mozilla Update"> <form id="search" method="get" action="{$config.webpath}/search.php" title="Search Mozilla Update">
<div> <div>
<label for="q" title="Search Mozilla Update">Search for</label> <input type="text" id="q" name="q" accesskey="s" size="10" value="{$clean.q}">
<input type="text" id="q" name="q" accesskey="s" size="10"> <input type="submit" id="submit" value="Search">
in
<select name="cat" id="cat">
<option value="">All Categories</option>
{section name="inc_cats" loop=$cats}
<option value="{$cats[inc_cats].CatName}">{$cats[inc_cats].CatName}</option>
{/section}
</select>
<input type="submit" id="submit" value="Go">
</div> </div>
</form> </form>
<div class="ie-clear-menu">&nbsp;</div> <div class="ie-clear-menu">&nbsp;</div>

Просмотреть файл

@ -6,7 +6,7 @@
<form id="search-side" action="{$smarty.server.PHP_SELF}" method="get"> <form id="search-side" action="{$smarty.server.PHP_SELF}" method="get">
<input type="text" name="q" value="{$clean[q]}"> <input type="text" name="q" value="{$clean.q}" maxlength="32">
<input type="submit" value="Search"><br><br> <input type="submit" value="Search"><br><br>
<fieldset> <fieldset>
@ -15,17 +15,17 @@
<div class="search-option"> <div class="search-option">
<label for="cat">Category:</label> <label for="cat">Category:</label>
<select name="cat" id="cat"> <select name="cat" id="cat">
<option>Any</option> <option value="null">Any</option>
<option>Foo</option> {html_options options=$cats selected=$clean.cat}
</select> </select>
</div> </div>
<div class="search-option"> <div class="search-option">
<label for="type">Type:</label> <label for="type">Type:</label>
<select id="type" name="type"> <select id="type" name="type">
<option>Any</option> <option value="null">Any</option>
<option>Extensions</option> <option value="E"{if $clean.type eq 'E'} selected="selected"{/if}>Extensions</option>
<option>Themes</option> <option value="T"{if $clean.type eq 'T'} selected="selected"{/if}>Themes</option>
</select> </select>
</div> </div>
@ -33,43 +33,34 @@
<label for="app">App:</label> <label for="app">App:</label>
<select id="app" name="app"> <select id="app" name="app">
<option>Any</option> <option>Any</option>
<option>Firefox</option> {html_options options=$apps selected=$clean.app}
<option>Thunderbird</option>
<option>Mozilla</option>
</select> </select>
</div> </div>
<div class="search-option"> <div class="search-option">
<label for="os">Platform:</label> <label for="platform">Platform:</label>
<select id="os" name="os"> <select id="platform" name="platform">
<option>Windows</option> <option value="null">Any</option>
<option>Linux</option> {html_options options=$platforms selected=$clean.platform}
<option>OSX</option>
</select> </select>
</div> </div>
<div class="search-option"> <div class="search-option">
<label for="date">Date:</label> <label for="date">Date:</label>
<select id="date" name="date"> <select id="date" name="date">
<option>Any</option> <option value="null">Any</option>
<option>Today</option> {html_options options=$dates selected=$clean.date}
<option>This Week</option>
<option>This Month</option>
<option>This Year</option>
</select> </select>
</div> </div>
<div class="search-option"> <div class="search-option">
<label for="sort">Sort by:</label> <label for="sort">Sort by:</label>
<select id="sort" name="sort"> <select id="sort" name="sort">
<option>Name</option> {html_options options=$sort selected=$clean.sort}
<option>Date</option>
<option>Rating</option>
<option>Popularity</option>
</select> </select>
</div> </div>
</fieldset> </fieldset>
<input type="submit" value="Search"><br><br> <input type="submit" value="Search"><br><br>