1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-24 07:30:10 +01:00

- board-search.php Improved result limiting.

- boards.php Passes omit information
- js/board-directory.js Improved code organization.
- js/board-directory.js Added NSFW icon.
- js/board-directory.js Added basic locale handling.
- js/board-directory.js Disabled submit button until JS is bound.

Signed-off-by: 8n-tech <8n-tech@users.noreply.github.com>
This commit is contained in:
8n-tech 2015-04-15 22:02:11 +10:00
parent f09def2712
commit 0347bf772d
6 changed files with 138 additions and 60 deletions

View File

@ -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'] ) );
}

View File

@ -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
)
);

View File

@ -34,17 +34,19 @@
'board-cell-uri' : "<td class=\"board-uri\"></td>",
'board-cell-title' : "<td class=\"board-title\"></td>",
'board-cell-pph' : "<td class=\"board-pph\"></td>",
'board-cell-max' : "<td class=\"board-max\"></td>",
'board-cell-unique' : "<td class=\"board-unique\"></td>",
'board-cell-posts_total' : "<td class=\"board-max\"></td>",
'board-cell-active' : "<td class=\"board-unique\"></td>",
'board-cell-tags' : "<td class=\"board-tags\"></td>",
// Content wrapper
// Used to help constrain contents to their <td>.
'board-content-wrap' : "<div class=\"board-cell\"></div>",
// Tagging
'board-datum-tags' : "<a class=\"tag-link\" href=\"#\"></a>"
'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>"
}
},
@ -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();
}
}

BIN
static/infinity-small.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

View File

@ -39,6 +39,16 @@
<div class="search-item search-submit">
<button id="search-submit">Search</button>
<span id="search-loading" class="loading-small board-list-loading" style="display: none;"></span>
<script type="text/javascript">
/* Cheeky hack.
DOM Mutation is now depreceated, but board-directory.js fires before this button is added.
Since .ready() only fires after the entire page loads, we have this here to disable it as soon
as we pass it in the DOM structure.
We don't just disable="disable" it because then it would be broken for all non-JS browsers. */
document.getElementById( 'search-submit' ).disabled = "disabled";
document.getElementById( 'search-loading' ).style.display = "inline-block";
</script>
</div>
</div>
@ -65,14 +75,22 @@
<th class="board-uri" data-column="uri">{% trans %}Board{% endtrans %}</th>
<th class="board-title" data-column="title">{% trans %}Title{% endtrans %}</th>
<th class="board-pph" data-column="pph" title="Posts per hour">{% trans %}PPH{% endtrans %}</th>
<th class="board-max" data-column="max">{% trans %}Total posts{% endtrans %}</th>
<th class="board-unique" data-column="unique" title="Unique IPs to post in the last 72 hours">{% trans %}Active users{% endtrans %}</th>
<th class="board-max" data-column="posts_total">{% trans %}Total posts{% endtrans %}</th>
<th class="board-unique" data-column="active" title="Unique IPs to post in the last 72 hours">{% trans %}Active users{% endtrans %}</th>
<th class="board-tags" data-column="tags">{% trans %}Tags{% endtrans %}</th>
</tr>
</thead>
<tbody class="board-list-tbody">{{html_boards}}</tbody>
{% if boards_omitted > 0 %}
<tbody class="board-list-omitted" data-omitted="{{boards_omitted}}">
<tr>
<td colspan="7">{{boards_omitted}} board{% if boards_omitted != 1 %}s were{% else %} was{% endif %} omitted.</td>
</tr>
</tbody>
{% endif %}
<tfoot class="board-list-loading">
<tr>
<td colspan="7" class="loading"></td>

View File

@ -1,7 +1,10 @@
{% for board in boards %}
<tr>
<td class="board-meta">{{ board.img|raw }} {% if board['sfw'] %}<img src="/static/sfw.png" title="Safe for work">{% else %}<img src="/static/nsfw.png" title="Not safe for work">{% endif %}</td>
<td class="board-uri"><div class="board-list-wrapper uri"><a href='/{{board['uri']}}/'>/{{board['uri']}}/</a>{{lock|raw}}</div></td>
<td class="board-meta">{{ board.locale }}</td>
<td class="board-uri"><div class="board-cell">
<a href='/{{board['uri']}}/'>/{{board['uri']}}/</a>
{% if board['sfw'] %}<i class="fa fa-briefcase board-sfw" title="SFW"></i>{% endif %}
</div></td>
<td class="board-title"><div class="board-cell" title="Created {{board['time']}} ({{board['ago']}} ago)">{{ board['title'] }}</div></td>
<td class="board-pph"><div class="board-cell">{{board['pph']}}</td>
<td class="board-max"><div class="board-cell">{{board['posts_total']}}</td>