1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2025-01-31 12:23:48 +01:00

Bug fixes.

- board-search.php Fixed an issue with tag weight where all tags have an equal prominance
- inc/functions.php Fixed an issue where board stats were incorrectly assuming all recent activity was in the last hour.
- js/board-directory.js JS will now repopulate the tag list.
- Improved handling of the load more button.

Signed-off-by: 8n-tech <8n-tech@users.noreply.github.com>
This commit is contained in:
8n-tech 2015-04-16 19:41:52 +10:00
parent 9eb8452793
commit 95e92c40a8
5 changed files with 63 additions and 17 deletions

View File

@ -261,7 +261,7 @@ if (count($response['tags']) > 0) {
$response['tagWeight'][$tagName] = 75 + round( 100 * ( $weightDeparture / $weightDepartureFurthest ), 0);
}
else {
$response['tagWeight'][$tagName] = 0;
$response['tagWeight'][$tagName] = 100;
}
}
}

View File

@ -841,6 +841,7 @@ function fetchBoardActivity( array $uris = array(), $forTime = false, $detailed
$forTime = time();
}
// Get the last hour for this timestamp.
$nowHour = ( (int)( time() / 3600 ) * 3600 );
$forHour = ( (int)( $forTime / 3600 ) * 3600 ) - 3600;
$boardActivity = array(
@ -857,7 +858,7 @@ function fetchBoardActivity( array $uris = array(), $forTime = false, $detailed
}
if ($detailed === true) {
$bsQuery = prepare("SELECT `stat_uri`, `post_count`, `author_ip_array` FROM ``board_stats`` WHERE {$uriSearch} ( `stat_hour` <= :hour AND `stat_hour` >= :hoursago )");
$bsQuery = prepare("SELECT `stat_uri`, `stat_hour`, `post_count`, `author_ip_array` FROM ``board_stats`` WHERE {$uriSearch} ( `stat_hour` <= :hour AND `stat_hour` >= :hoursago )");
$bsQuery->bindValue(':hour', $forHour, PDO::PARAM_INT);
$bsQuery->bindValue(':hoursago', $forHour - ( 3600 * 72 ), PDO::PARAM_INT);
$bsQuery->execute() or error(db_error($bsQuery));
@ -867,11 +868,17 @@ function fetchBoardActivity( array $uris = array(), $forTime = false, $detailed
// Format the results.
foreach ($bsResult as $bsRow) {
if (!isset($boardActivity['active'][$bsRow['stat_uri']])) {
$boardActivity['active'][$bsRow['stat_uri']] = unserialize( $bsRow['author_ip_array'] );
if ($bsRow['stat_hour'] == $forHour) {
$boardActivity['active'][$bsRow['stat_uri']] = unserialize( $bsRow['author_ip_array'] );
}
$boardActivity['average'][$bsRow['stat_uri']] = $bsRow['post_count'];
}
else {
$boardActivity['active'][$bsRow['stat_uri']] = array_merge( $boardActivity['active'][$bsRow['stat_uri']], unserialize( $bsRow['author_ip_array'] ) );
if ($bsRow['stat_hour'] == $forHour) {
$boardActivity['active'][$bsRow['stat_uri']] = array_merge( $boardActivity['active'][$bsRow['stat_uri']], unserialize( $bsRow['author_ip_array'] ) );
}
$boardActivity['average'][$bsRow['stat_uri']] = $bsRow['post_count'];
}
}
@ -885,9 +892,8 @@ function fetchBoardActivity( array $uris = array(), $forTime = false, $detailed
}
// Simple return.
else {
$bsQuery = prepare("SELECT SUM(`post_count`) AS `post_count` FROM ``board_stats`` WHERE {$uriSearch} ( `stat_hour` <= :hour AND `stat_hour` >= :hoursago )");
$bsQuery = prepare("SELECT SUM(`post_count`) AS `post_count` FROM ``board_stats`` WHERE {$uriSearch} ( `stat_hour` = :hour )");
$bsQuery->bindValue(':hour', $forHour, PDO::PARAM_INT);
$bsQuery->bindValue(':hoursago', $forHour - ( 3600 * 72 ), PDO::PARAM_INT);
$bsQuery->execute() or error(db_error($bsQuery));
$bsResult = $bsQuery->fetchAll(PDO::FETCH_ASSOC);

View File

@ -24,12 +24,13 @@
'search-title' : "#search-title-input",
'search-submit' : "#search-submit",
'tag-list' : ".tag-list",
'tag-link' : ".tag-link",
'footer-page' : ".board-page-num",
'footer-count' : ".board-page-count",
'footer-total' : ".board-page-total",
'footer-more' : ".board-page-loadmore"
'footer-more' : "#board-list-more"
},
// HTML Templates for dynamic construction
@ -50,11 +51,18 @@
// Used to help constrain contents to their <td>.
'board-content-wrap' : "<div class=\"board-cell\"></div>",
// Individual items or parts of a single table cell.
'board-datum-lang' : "<span class=\"board-lang\"></span>",
'board-datum-uri' : "<a class=\"board-link\"></a>",
'board-datum-sfw' : "<i class=\"fa fa-briefcase board-sfw\" title=\"SFW\"></i>",
'board-datum-nsfw' : "<i class=\"fa fa-briefcase board-nsfw\" title=\"NSFW\"></i>",
'board-datum-tags' : "<a class=\"tag-link\" href=\"#\"></a>"
'board-datum-tags' : "<a class=\"tag-link\" href=\"#\"></a>",
// Tag list.
'tag-list' : "<ul class=\"tag-list\"></ul>",
'tag-item' : "<li class=\"tag-item\"></li>",
'tag-link' : "<a class=\"tag-link\" href=\"#\"></a>"
}
},
@ -103,7 +111,7 @@
boardlist.build.boards(data['boards'], data['order']);
boardlist.build.lastSearch(data['search']);
boardlist.build.footer(data);
boardlist.build.tags(data['tags']);
boardlist.build.tags(data['tagWeight']);
},
@ -207,7 +215,8 @@
$page = $( selector['footer-page'], boardlist.$boardlist ),
$count = $( selector['footer-count'], boardlist.$boardlist ),
$total = $( selector['footer-total'], boardlist.$boardlist ),
$more = $( selector['footer-more'], boardlist.$boardlist );
$more = $( selector['footer-more'], boardlist.$boardlist ),
$omitted = $( selector['board-omitted'], boardlist.$boardlist );
var boards = Object.keys(data['boards']).length,
omitted = data['omitted'] - data['search']['page'];
@ -221,10 +230,29 @@
//$page.text( data['search']['page'] );
$count.text( data['search']['page'] + boards );
$total.text( total );
$more.toggle( omitted != 0 );
$more.toggleClass( "board-list-hasmore", omitted != 0 );
$omitted.toggle( boards + omitted > 0 );
},
tags : function(data) {
tags : function(tags) {
var selector = boardlist.options.selector,
template = boardlist.options.template,
$list = $( selector['tag-list'], boardlist.$boardlist );
if ($list.length) {
$.each( tags, function(tag, weight) {
var $item = $( template['tag-item'] ),
$link = $( template['tag-link'] );
$link
.css( 'font-size', weight+"%" )
.text( tag )
.appendTo( $item );
$item.appendTo( $list );
} );
}
}
},
@ -240,6 +268,7 @@
searchSubmit : function(event) {
event.preventDefault();
$( boardlist.options.selector['tag-list'], boardlist.$boardlist ).html("");
$( boardlist.options.selector['board-body'], boardlist.$boardlist ).html("");
boardlist.submit( {
@ -268,12 +297,14 @@
},
submit : function( parameters ) {
var $boardlist = boardlist.$boardlist,
$boardload = $( boardlist.options.selector['board-loading'], $boardlist ),
$searchSubmit = $( boardlist.options.selector['search-submit'] );
var $boardlist = boardlist.$boardlist,
$boardload = $( boardlist.options.selector['board-loading'], $boardlist ),
$searchSubmit = $( boardlist.options.selector['search-submit'], $boardlist ),
$footerMore = $( boardlist.options.selector['board-omitted'], $boardlist );
$searchSubmit.prop( 'disabled', true );
$boardload.show();
$footerMore.hide();
return $.get(
"/board-search.php",

View File

@ -1419,9 +1419,18 @@ tbody.board-list-omitted td {
font-size: 125%;
text-align: center;
}
tbody.board-list-omitted #board-list-more {
cursor: default;
}
tbody.board-list-omitted #board-list-more.board-list-hasmore {
cursor: pointer;
}
tbody.board-list-omitted .board-page-loadmore {
display: none;
}
tbody.board-list-omitted .board-list-hasmore .board-page-loadmore {
display: inline;
}
aside.search-container {
margin-bottom: 12px;

View File

@ -91,14 +91,14 @@
<tbody class="board-list-omitted" data-omitted="{{boards_omitted}}">
<tr>
<td colspan="7">Displaying results <span class="board-page-num">{{search.page + 1}}</span> through <span class="board-page-count">{{ boards|count + search.page}}</span> out of <span class="board-page-total">{{ boards|count + boards_omitted }}</span>. <span class="board-page-loadmore">Click to load more.</span></td>
<td colspan="7" id="board-list-more">Displaying results <span class="board-page-num">{{search.page + 1}}</span> through <span class="board-page-count">{{ boards|count + search.page}}</span> out of <span class="board-page-total">{{ boards|count + boards_omitted }}</span>. <span class="board-page-loadmore">Click to load more.</span></td>
{% if boards_omitted > 0 %}
<script type="text/javascript">
/* Cheeky hack redux.
We want to show the loadmore for JS users when we have omitted boards.
However, the board-directory.js isn't designed to manipulate the page index on immediate load. */
document.getElementsByClassName("board-page-loadmore")[0].style.display = "inline";
document.getElementById("board-list-more").className = "board-list-hasmore";
</script>
{% endif %}
</tr>