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 . 'board-content-wrap' : "
", + // Individual items or parts of a single table cell. 'board-datum-lang' : "", 'board-datum-uri' : "", 'board-datum-sfw' : "", 'board-datum-nsfw' : "", - 'board-datum-tags' : "" + 'board-datum-tags' : "", + + + // Tag list. + 'tag-list' : "", + 'tag-item' : "
  • ", + 'tag-link' : "" } }, @@ -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", diff --git a/stylesheets/style.css b/stylesheets/style.css index 022cc319..62559dd4 100644 --- a/stylesheets/style.css +++ b/stylesheets/style.css @@ -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; diff --git a/templates/8chan/boards-search.html b/templates/8chan/boards-search.html index 41ef5cbd..d8bbbeb3 100644 --- a/templates/8chan/boards-search.html +++ b/templates/8chan/boards-search.html @@ -91,14 +91,14 @@ - Displaying results {{search.page + 1}} through {{ boards|count + search.page}} out of {{ boards|count + boards_omitted }}. Click to load more. + Displaying results {{search.page + 1}} through {{ boards|count + search.page}} out of {{ boards|count + boards_omitted }}. Click to load more. {% if boards_omitted > 0 %} {% endif %}