diff --git a/board-search.php b/board-search.php index c156fffb..8aaa7245 100644 --- a/board-search.php +++ b/board-search.php @@ -28,6 +28,8 @@ $search = array( 'tags' => false, 'time' => ( (int)( time() / 3600 ) * 3600 ) - 3600, 'title' => false, + + 'index' => count( $_GET ) == 0, ); // Include NSFW boards? @@ -169,12 +171,18 @@ array_multisort( $response['boards'] ); +$boardLimit = $search['index'] ? 50 : 100; + +$response['omitted'] = $search['index'] ? 0 : count( $response['boards'] ) - $boardLimit; +$response['boards'] = array_splice( $response['boards'], 0, $boardLimit ); +$response['order'] = array_keys( $response['boards'] ); + // Get the top most popular tags. if (count($response['tags']) > 0) { // Sort by most active tags. arsort( $response['tags'] ); // Get the first n most active tags. - $response['tags'] = array_splice( $response['tags'], 0, 200 ); + $response['tags'] = array_splice( $response['tags'], 0, 100 ); // $tagLightest = end( array_keys( $response['tag'] ) ); } diff --git a/boards.php b/boards.php index 40a9e841..4234aefd 100644 --- a/boards.php +++ b/boards.php @@ -28,12 +28,13 @@ $boardQuery = prepare("SELECT COUNT(1) AS 'boards_total', SUM(indexed) AS 'board $boardQuery->execute() or error(db_error($tagQuery)); $boardResult = $boardQuery->fetchAll(PDO::FETCH_ASSOC)[0]; -$boards_total = number_format( $boardResult['boards_total'], 0 ); -$boards_public = number_format( $boardResult['boards_public'], 0 ); -$boards_hidden = number_format( $boardResult['boards_total'] - $boardResult['boards_public'], 0 ); +$boards_total = number_format( $boardResult['boards_total'], 0 ); +$boards_public = number_format( $boardResult['boards_public'], 0 ); +$boards_hidden = number_format( $boardResult['boards_total'] - $boardResult['boards_public'], 0 ); +$boards_omitted = (int) $searchJson['omitted']; -$posts_hour = number_format( fetchBoardActivity(), 0 ); -$posts_total = number_format( $boardResult['posts_total'], 0 ); +$posts_hour = number_format( fetchBoardActivity(), 0 ); +$posts_total = number_format( $boardResult['posts_total'], 0 ); /* Create and distribute page */ $config['additional_javascript'] = array( @@ -54,21 +55,22 @@ $tagsHTML = Element("8chan/boards-tags.html", array( ); $searchHTML = Element("8chan/boards-search.html", array( - "config" => $config, + "config" => $config, - "boards_total" => $boards_total, - "boards_public" => $boards_public, - "boards_hidden" => $boards_hidden, + "boards_total" => $boards_total, + "boards_public" => $boards_public, + "boards_hidden" => $boards_hidden, + "boards_omitted" => $boards_omitted, - "posts_hour" => $posts_hour, - "posts_total" => $posts_total, + "posts_hour" => $posts_hour, + "posts_total" => $posts_total, - "founding_date" => $founding_date, - "page_updated" => date('r'), - "uptime" => shell_exec('uptime -p'), + "founding_date" => $founding_date, + "page_updated" => date('r'), + "uptime" => shell_exec('uptime -p'), - "html_boards" => $boardsHTML, - "html_tags" => $tagsHTML + "html_boards" => $boardsHTML, + "html_tags" => $tagsHTML ) ); diff --git a/js/board-directory.js b/js/board-directory.js index d9858150..6fe7edee 100644 --- a/js/board-directory.js +++ b/js/board-directory.js @@ -34,17 +34,19 @@ 'board-cell-uri' : "", 'board-cell-title' : "", 'board-cell-pph' : "", - 'board-cell-max' : "", - 'board-cell-unique' : "", + 'board-cell-posts_total' : "", + 'board-cell-active' : "", 'board-cell-tags' : "", // Content wrapper // Used to help constrain contents to their . 'board-content-wrap' : "
", - - // Tagging - 'board-datum-tags' : "" + 'board-datum-lang' : "", + 'board-datum-uri' : "", + 'board-datum-sfw' : "", + 'board-datum-nsfw' : "", + 'board-datum-tags' : "" } }, @@ -73,59 +75,101 @@ if ($search.length > 0) { // Bind form events. $search.on( 'submit', searchForms, boardlist.events.searchSubmit ); - $searchSubmit.on( 'click', searchForms, boardlist.events.searchSubmit ); + $searchSubmit.prop( 'disabled', false ).on( 'click', searchForms, boardlist.events.searchSubmit ); } } }, build : { boardlist : function(data) { - boardlist.build.boards(data['boards']); + boardlist.build.boards(data['boards'], data['order']); boardlist.build.tags(data['tags']); }, - boards : function(data) { + boards : function(data, order) { // Find our head, columns, and body. var $head = $( boardlist.options.selector['board-head'], boardlist.$boardlist ), $cols = $("[data-column]", $head ), $body = $( boardlist.options.selector['board-body'], boardlist.$boardlist ); - $.each( data, function( index, row ) { - var $row = $( boardlist.options.template['board-row'] ); + $.each( order, function( index, uri ) { + var row = data[uri]; + $row = $( boardlist.options.template['board-row'] ); $cols.each( function( index, col ) { - var $col = $(col), - column = $col.attr('data-column'), - value = row[column] - $cell = $( boardlist.options.template['board-cell-' + column] ), - $wrap = $( boardlist.options.template['board-content-wrap'] ); - - if (value instanceof Array) { - if (typeof boardlist.options.template['board-datum-' + column] !== "undefined") { - $.each( value, function( index, singleValue ) { - $( boardlist.options.template['board-datum-' + column] ) - .text( singleValue ) - .appendTo( $wrap ); - } ); - } - else { - $wrap.text( value.join(" ") ); - } - } - else { - $wrap.text( value ); - } - - $wrap.appendTo( $cell ); - $cell.appendTo( $row ); + boardlist.build.board( row, col ).appendTo( $row ); } ); - - if( index >= 100 ) return false; + + if( index >= 100 ) return false; $row.appendTo( $body ); } ); + }, + board : function( row, col ) { + var $col = $(col), + column = $col.attr('data-column'), + value = row[column] + $cell = $( boardlist.options.template['board-cell-' + column] ), + $wrap = $( boardlist.options.template['board-content-wrap'] ); + if (typeof boardlist.build.boardcell[column] === "undefined") { + if (value instanceof Array) { + if (typeof boardlist.options.template['board-datum-' + column] !== "undefined") { + $.each( value, function( index, singleValue ) { + $( boardlist.options.template['board-datum-' + column] ) + .text( singleValue ) + .appendTo( $wrap ); + } ); + } + else { + $wrap.text( value.join(" ") ); + } + } + else { + $wrap.text( value ); + } + } + else { + var $content = boardlist.build.boardcell[column]( row, value ); + + if ($content instanceof jQuery) { + // We use .append() instead of .appendTo() as we do elsewhere + // because $content can be multiple elements. + $wrap.append( $content ); + } + else if (typeof $content === "string") { + $wrap.html( $content ); + } + else { + console.log("Special cell constructor returned a " + (typeof $content) + " that board-directory.js cannot interpret."); + } + } + + $wrap.appendTo( $cell ); + return $cell; + }, + boardcell : { + 'meta' : function( row, value ) { + return $( boardlist.options.template['board-datum-lang'] ).text( row['locale'] ); + }, + 'uri' : function( row, value ) { + var $link = $( boardlist.options.template['board-datum-uri'] ), + $sfw = $( boardlist.options.template['board-datum-' + (row['sfw'] == 1 ? "sfw" : "nsfw")] ); + + $link + .attr( 'href', "/"+row['uri']+"/" ) + .text( "/"+row['uri']+"/" ); + + // I decided against NSFW icons because it clutters the index. + // Blue briefcase = SFW. No briefcase = NSFW. Seems better. + if (row['sfw'] == 1) { + return $link[0].outerHTML + $sfw[0].outerHTML; + } + else { + return $link[0].outerHTML; + } + } }, tags : function(data) { @@ -168,10 +212,13 @@ target = boardlist.options.selector.boardlist; } - var $target = $(target); + var $boardlist = $(target); - if ($target.length > 0 ) { - boardlist.$boardlist = $target; + if ($boardlist.length > 0 ) { + $( boardlist.options.selector['board-loading'], $boardlist ).hide(); + + + boardlist.$boardlist = $boardlist; boardlist.bind.form(); } } diff --git a/static/infinity-small.gif b/static/infinity-small.gif new file mode 100644 index 00000000..c7a2978e Binary files /dev/null and b/static/infinity-small.gif differ diff --git a/templates/8chan/boards-search.html b/templates/8chan/boards-search.html index 934403d9..39c3f4c2 100644 --- a/templates/8chan/boards-search.html +++ b/templates/8chan/boards-search.html @@ -39,6 +39,16 @@
+ +
@@ -65,14 +75,22 @@ {% trans %}Board{% endtrans %} {% trans %}Title{% endtrans %} {% trans %}PPH{% endtrans %} - {% trans %}Total posts{% endtrans %} - {% trans %}Active users{% endtrans %} + {% trans %}Total posts{% endtrans %} + {% trans %}Active users{% endtrans %} {% trans %}Tags{% endtrans %} {{html_boards}} + {% if boards_omitted > 0 %} + + + {{boards_omitted}} board{% if boards_omitted != 1 %}s were{% else %} was{% endif %} omitted. + + + {% endif %} + diff --git a/templates/8chan/boards-table.html b/templates/8chan/boards-table.html index f3451ae1..40f823bb 100644 --- a/templates/8chan/boards-table.html +++ b/templates/8chan/boards-table.html @@ -1,7 +1,10 @@ {% for board in boards %} - {{ board.img|raw }} {% if board['sfw'] %}{% else %}{% endif %} -
/{{board['uri']}}/{{lock|raw}}
+ {{ board.locale }} +
+ /{{board['uri']}}/ + {% if board['sfw'] %}{% endif %} +
{{ board['title'] }}
{{board['pph']}}
{{board['posts_total']}}