зеркало из https://github.com/mozilla/pjs.git
Search optimization, comments pagination. Fixed unnecessary result rows in search.php and used the same method in comments. Fixed issues with comments pagination.
This commit is contained in:
Родитель
d9c9a2d9c1
Коммит
57ce266dac
|
@ -4,23 +4,63 @@
|
|||
*
|
||||
* @package amo
|
||||
* @subpackage docs
|
||||
* @TODO Disallow comments for addon authors (authors should not be allowed to comment on their own addon).
|
||||
* @TODO Throttle comment entry.
|
||||
*/
|
||||
|
||||
// Get our addon ID.
|
||||
$clean['ID'] = intval($_GET['id']);
|
||||
$sql['ID'] =& $clean['ID'];
|
||||
// Get our addon id.
|
||||
$clean['id'] = intval($_GET['id']);
|
||||
$sql['id'] =& $clean['id'];
|
||||
|
||||
startProcessing('comments.tpl',$clean['ID'],$compileId);
|
||||
// Sort.
|
||||
if (isset($_GET['sort'])&&ctype_alpha($_GET['sort'])) {
|
||||
$clean['sort'] = $_GET['sort'];
|
||||
}
|
||||
|
||||
// Starting point.
|
||||
$page['left'] = (isset($_GET['left'])) ? intval($_GET['left']) : 0;
|
||||
|
||||
// Ending point.
|
||||
$page['right'] = $page['left'] + 10;
|
||||
|
||||
// Order by.
|
||||
$orderby = (!empty($_GET['orderby'])&&ctype_alpha($_GET['orderby'])) ? $_GET['orderby'] : "";
|
||||
|
||||
startProcessing('comments.tpl',$clean['id'],$compileId);
|
||||
require_once('includes.php');
|
||||
|
||||
$addon = new AddOn($sql['ID']);
|
||||
$addon->getComments();
|
||||
$addon = new AddOn($sql['id']);
|
||||
$addon->getComments($page['left'],$page['right'],$orderby);
|
||||
|
||||
// Get our result count.
|
||||
$db->query("SELECT FOUND_ROWS()", SQL_INIT);
|
||||
$resultCount = !empty($db->record) ? $db->record[0] : $page['right'];
|
||||
if ($resultCount<$page['right']) {
|
||||
$page['right'] = $resultCount;
|
||||
}
|
||||
|
||||
// Do we even have a next or previous page?
|
||||
$page['previous'] = ($page['left'] >= 10) ? $page['left']-10 : null;
|
||||
$page['next'] = ($page['left']+10 < $resultCount) ? $page['left']+10 : null;
|
||||
$page['resultCount'] = $resultCount;
|
||||
$page['leftDisplay'] = $page['left']+1;
|
||||
|
||||
// Build the URL based on passed arguments.
|
||||
foreach ($clean as $key=>$val) {
|
||||
if (!empty($val)) {
|
||||
$buf[] = $key.'='.$val;
|
||||
}
|
||||
}
|
||||
$page['url'] = implode('&',$buf);
|
||||
unset($buf);
|
||||
|
||||
// Assign template variables.
|
||||
$tpl->assign(
|
||||
array( 'addon' => $addon,
|
||||
'title' => $addon->Name.' Comments',
|
||||
'content' => 'comments.tpl',
|
||||
'sidebar' => 'inc/addon-sidebar.tpl')
|
||||
'sidebar' => 'inc/addon-sidebar.tpl',
|
||||
'page' => $page,
|
||||
'orderby' => $orderby)
|
||||
);
|
||||
?>
|
||||
|
|
|
@ -436,3 +436,7 @@
|
|||
padding: .5em;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
#comments-sort {
|
||||
float: right;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
*
|
||||
* @package amo
|
||||
* @subpackage docs
|
||||
* @TODO Disallow comment rating by poster -- users should not be able to rate their own comments.
|
||||
* @TODO Throttle for comment ratings.
|
||||
*/
|
||||
|
||||
startProcessing('ratecomment.tpl', null, null);
|
||||
|
|
|
@ -45,12 +45,6 @@ switch (strtolower($rsslist)) {
|
|||
break;
|
||||
}
|
||||
|
||||
unset($rssapp);
|
||||
unset($rsstype);
|
||||
unset($rsslist);
|
||||
|
||||
|
||||
|
||||
// If we get here, we're going to have to pull DB contents.
|
||||
require_once('includes.php');
|
||||
|
||||
|
@ -81,6 +75,8 @@ $_rssSql = "
|
|||
v.approved = 'yes' AND
|
||||
a.appname = '{$sql['app']}' AND
|
||||
m.type = '{$sql['type']}'
|
||||
GROUP by
|
||||
m.id
|
||||
ORDER BY
|
||||
{$rssOrderBy}
|
||||
LIMIT 0,10
|
||||
|
@ -89,5 +85,11 @@ $_rssSql = "
|
|||
// Get data, then set the results.
|
||||
$db->query($_rssSql,SQL_ALL,SQL_ASSOC);
|
||||
$_rssData = $db->record;
|
||||
$tpl->assign('data',$_rssData);
|
||||
$tpl->assign(
|
||||
array(
|
||||
'data'=>$_rssData,
|
||||
'list'=>ucfirst($rsslist)
|
||||
)
|
||||
|
||||
);
|
||||
?>
|
||||
|
|
|
@ -4,11 +4,6 @@
|
|||
*
|
||||
* @package amo
|
||||
* @subpackage docs
|
||||
*
|
||||
* @todo figure out why some addon listings have incorrect applications.
|
||||
* @todo add page links ( 1 2 3 4 5 ..... n ) for big result sets? is this necessary?
|
||||
* @todo take pagination and throw it into a class so we can reuse the methodology.
|
||||
* @todo check validation - the form has some errors in it.
|
||||
*/
|
||||
|
||||
// Get our cache_id based on what we have in our query string.
|
||||
|
@ -115,14 +110,17 @@ $perpage = array(
|
|||
|
||||
// Now we need to build our query. Our query starts with four parts:
|
||||
|
||||
// Select and joins.
|
||||
$select = "
|
||||
SELECT DISTINCT
|
||||
// Select top.
|
||||
$selectTop = "
|
||||
SELECT DISTINCT SQL_CALC_FOUND_ROWS
|
||||
main.ID
|
||||
FROM
|
||||
main
|
||||
";
|
||||
|
||||
// Select joins.
|
||||
$select = "";
|
||||
|
||||
// Where clause.
|
||||
$where = "
|
||||
WHERE
|
||||
|
@ -204,24 +202,33 @@ if (!empty($sql['sort'])) {
|
|||
|
||||
$where .= ' 1 ';
|
||||
|
||||
$query = $select.$where.$orderby;
|
||||
$limit = " LIMIT {$page['left']}, {$page['right']} ";
|
||||
|
||||
$query = $selectTop.$select.$where.$orderby.$limit;
|
||||
|
||||
$results = array();
|
||||
$rawResults = array();
|
||||
|
||||
// Get results.
|
||||
$db->query($query, SQL_ALL);
|
||||
|
||||
unset($select);
|
||||
unset($where);
|
||||
unset($orderby);
|
||||
unset($query);
|
||||
|
||||
if (is_array($db->record)) {
|
||||
foreach ($db->record as $row) {
|
||||
$rawResults[] = $row[0];
|
||||
}
|
||||
}
|
||||
|
||||
// Get our result count.
|
||||
$db->query("SELECT FOUND_ROWS()", SQL_INIT);
|
||||
if (!empty($db->record)) {
|
||||
$resultCount = $db->record[0];
|
||||
}
|
||||
if ($resultCount<$page['right']) {
|
||||
$page['right'] = $resultCount;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// If we have only one result, redirect to the addon page.
|
||||
if ( count($rawResults) == 1) {
|
||||
header('Location: https://'.$_SERVER['HTTP_HOST'].WEB_PATH.'/addon.php?id='.$rawResults[0]);
|
||||
|
@ -234,11 +241,6 @@ if ( count($rawResults) == 1) {
|
|||
}
|
||||
}
|
||||
|
||||
$resultCount = count($rawResults);
|
||||
if ($resultCount<$page['right']) {
|
||||
$page['right'] = $resultCount;
|
||||
}
|
||||
|
||||
// Do we even have a next or previous page?
|
||||
$page['previous'] = ($page['left'] >= $clean['perpage']) ? $page['left']-$clean['perpage'] : null;
|
||||
$page['next'] = ($page['left']+$clean['perpage'] < $resultCount) ? $page['left']+$clean['perpage'] : null;
|
||||
|
|
|
@ -6,6 +6,47 @@ by <a href="{$config.webpath}/{$app}/{$addon->UserID}/author/">{$addon->UserName
|
|||
released on {$addon->VersionDateAdded|date_format}
|
||||
</p>
|
||||
|
||||
{if $addon->Comments}
|
||||
<p class="first">Showing comments <b>{$page.leftDisplay}-{$page.right}</b> out of <b>{$page.resultCount}</b>. </p>
|
||||
|
||||
<div id="comments-sort">
|
||||
<form action="{$config.webpath}/comments.php" method="get">
|
||||
<div>
|
||||
<input type="hidden" name="app" value="{$app}"/>
|
||||
<input type="hidden" name="id" value="{$addon->ID}"/>
|
||||
|
||||
<label>Sort by</label>
|
||||
<select id="orderby" name="orderby">
|
||||
<option value="mosthelpful"{if $orderby eq "mosthelpful" or !$orderby} selected="selected"{/if}>Most Helpful</option>
|
||||
<option value="ratinghigh"{if $orderby eq "ratinghigh"} selected="selected"{/if}>Highest Rated</option>
|
||||
<option value="datenewest"{if $orderby eq "datenewest"} selected="selected"{/if}>Newest</option>
|
||||
<option value="dateoldest"{if $orderby eq "dateoldest"} selected="selected"{/if}>Oldest</option>
|
||||
<option value="ratinglow"{if $orderby eq "ratinglow"} selected="selected"{/if}>Lowest Rated</option>
|
||||
<option value="leasthelpful"{if $orderby eq "leasthelpful"} selected="selected"{/if}>Least Helpful</option>
|
||||
</select>
|
||||
<input class="amo-submit" type="submit" value="Go"/></div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="pages">
|
||||
<div class="prev">
|
||||
{if $page.left}
|
||||
<a href="{$config.webpath}/comments.php?{$page.url}&left={$page.previous}">« Previous Page</a>
|
||||
{else}
|
||||
« Previous Page
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="next">
|
||||
{if $page.next}
|
||||
<a href="{$config.webpath}/comments.php?{$page.url}&left={$page.next}">Next Page »</a>
|
||||
{else}
|
||||
Next Page »
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<ul id="opinions">
|
||||
{section name=comments loop=$addon->Comments}
|
||||
<li>
|
||||
|
@ -18,4 +59,7 @@ Was this comment helpful? <a href="{$config.webpath}/ratecomment.php?aid={$addon
|
|||
</li>
|
||||
{/section}
|
||||
</ul>
|
||||
{else}
|
||||
<p>There are no comments yet for this addon. <a href="{$config.webpath}/addcomment.php?aid={$addon->ID}&app={$app}"></a></p>
|
||||
{/if}
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
<div id="mBody">
|
||||
|
||||
<h2>{$addon->Name} » Rate Comment</h2>
|
||||
<p class="first">
|
||||
<strong><a href="{$config.webpath}/{$app}/{$addon->ID}/">{$addon->Name} {$addon->Version}</a></strong>,
|
||||
|
@ -17,5 +15,3 @@ released on {$addon->VersionDateAdded|date_format}
|
|||
</div>
|
||||
|
||||
<p>« <a href="./addon.php?id={$addon->ID}">Return to information about{$addon->Name}</a></p>
|
||||
|
||||
</div>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<rss version="2.0">
|
||||
<channel>
|
||||
<title>{$listname|escape:html:"UTF-8"} :: Mozilla Addons</title>
|
||||
<title>{$list|escape:html:"UTF-8"} Mozilla Addons</title>
|
||||
<link>{$config.host|escape:html:"UTF-8"}{$config.webpath|escape:html:"UTF-8"}</link>
|
||||
<description>Mozilla Addons is the place to get extensions and themes for your Mozilla applications.</description>
|
||||
<language>en-US</language>
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
<form action="{$smarty.server.PHP_SELF}" method="get" class="amo-form">
|
||||
|
||||
<div>
|
||||
<input type="text" name="q" value="{$clean.q}" maxlength="32"/>
|
||||
<div id="show-search-options"><input class="amo-submit" type="submit" value="Search"/> <a href="javascript:toggle('hide-search-options','show-search-options','inline');show('search-options','inline');">Show Options</a></div>
|
||||
<input type="text" name="q" value="{$clean.q}" maxlength="32"/><input class="amo-submit" type="submit" value="Search"/>
|
||||
<div id="show-search-options"><a href="javascript:toggle('hide-search-options','show-search-options','inline');show('search-options','inline');">Show Options</a></div>
|
||||
<div id="hide-search-options"><a href="javascript:toggle('show-search-options','hide-search-options','inline');hide('search-options');">Hide Options</a></div>
|
||||
</div>
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче