From 95e92c40a8aae8861ff2d7e64d9fdf042bab64e4 Mon Sep 17 00:00:00 2001 From: 8n-tech <8n-tech@users.noreply.github.com> Date: Thu, 16 Apr 2015 19:41:52 +1000 Subject: [PATCH] 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> --- board-search.php | 2 +- inc/functions.php | 16 +++++++--- js/board-directory.js | 49 ++++++++++++++++++++++++------ stylesheets/style.css | 9 ++++++ templates/8chan/boards-search.html | 4 +-- 5 files changed, 63 insertions(+), 17 deletions(-) diff --git a/board-search.php b/board-search.php index 931a0d53..74272b35 100644 --- a/board-search.php +++ b/board-search.php @@ -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; } } } diff --git a/inc/functions.php b/inc/functions.php index 98f07377..a6677d3a 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -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); diff --git a/js/board-directory.js b/js/board-directory.js index 1b3ad830..b278fbde 100644 --- a/js/board-directory.js +++ b/js/board-directory.js @@ -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