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->getHistory();
// Assign template variables.
$tpl->assign(
array( 'addon' => $addon,
@ -24,3 +25,4 @@ $tpl->assign(
'content' => 'history.tpl',
'sidebar' => 'inc/addon-sidebar.tpl')
);
?>

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

@ -84,9 +84,4 @@ $tpl = new AMO_Smarty();
// Global DB object.
$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;
// Categories.
var $Cats;
var $AddonCats;
// History of releases
var $History;
@ -79,7 +79,7 @@ class AddOn extends AMO_Object
function getAddOn()
{
$this->getCats();
$this->getAddonCats();
$this->getComments();
$this->getCurrentVersion();
$this->getMainPreview();
@ -245,11 +245,12 @@ class AddOn extends AMO_Object
$this->setVar('Comments',$this->db->record);
}
function getCats()
function getAddonCats()
{
// Gather addon categories.
$this->db->query("
SELECT DISTINCT
categories.CatID,
categories.CatName
FROM
categoryxref
@ -261,7 +262,7 @@ class AddOn extends AMO_Object
categories.CatName
", SQL_ALL, SQL_ASSOC);
$this->Cats = $this->db->record;
$this->AddonCats = $this->db->record;
}
}
?>

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

@ -4,7 +4,9 @@
*/
class AMO_Object
{
var $wrapper;
var $cats;
var $apps;
var $platforms;
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();
// Category.
if (isset($_GET['cat'])&&ctype_alpha($_GET['cat'])) {
$clean['cat'] = $_GET['cat'];
if (isset($_GET['cat'])&&ctype_digit($_GET['cat'])) {
$clean['cat'] = intval($_GET['cat']);
}
// Type.
@ -28,13 +28,13 @@ if (isset($_GET['type'])) {
}
// Platform.
if (isset($_GET['platform'])&&ctype_alpha($_GET['platform'])) {
$clean['platform'] = $_GET['platform'];
if (isset($_GET['platform'])&&ctype_digit($_GET['platform'])) {
$clean['platform'] = intval($_GET['platform']);
}
// Date.
if (isset($_GET['date'])&&ctype_alnum($_GET['date'])) {
$clean['date'] = strtotime($_GET['date']);
if (isset($_GET['date'])&&ctype_alpha($_GET['date'])) {
$clean['date'] = $_GET['date'];
}
// Application.
@ -43,33 +43,62 @@ if (isset($_GET['app'])&&ctype_alpha($_GET['app'])) {
}
// Sort.
if (isset($_GET['sort'])&&ctype_alpha($_GET['sort'])) {
if (isset($_GET['sort'])&&ctype_digit($_GET['sort'])) {
$clean['sort'] = $_GET['sort'];
}
// 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'];
}
// Sort.
if (isset($_GET['sort'])&&ctype_alpha($_GET['sort'])) {
$clean['sort'] = $_GET['sort'];
}
// Prepared verified inputs for their destinations.
foreach ($clean as $key=>$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(
array(
'clean' => $clean,
'cats' => $amo->Cats,
'platforms' => $amo->Platforms,
'apps' => $apps,
'dates' => $dates,
'sort' => $sort,
'content' => 'search.tpl',
'title' => 'Search',
)
);
$wrapper = 'inc/wrappers/nonav.tpl';
echo '<pre>';
print_r($clean);
echo '</pre>';
?>

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

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

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

@ -36,17 +36,8 @@
<div id="key-menu" class="earth">
<form id="search" method="get" action="{$config.webpath}/search.php" title="Search Mozilla Update">
<div>
<label for="q" title="Search Mozilla Update">Search for</label>
<input type="text" id="q" name="q" accesskey="s" size="10">
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">
<input type="text" id="q" name="q" accesskey="s" size="10" value="{$clean.q}">
<input type="submit" id="submit" value="Search">
</div>
</form>
<div class="ie-clear-menu">&nbsp;</div>

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

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