mirror of
https://github.com/vichan-devel/vichan.git
synced 2025-01-19 09:27:24 +01:00
Merge pull request #464 from 8n-tech/master
#456 - boards.php no longer generates a cache file or forbids direct acc...
This commit is contained in:
commit
9179290c2a
@ -125,7 +125,6 @@ foreach ($boards as $board) {
|
||||
|
||||
unset( $boards );
|
||||
|
||||
|
||||
/* Tag Fetching */
|
||||
// (We have do this even if we're not filtering by tags so that we know what each board's tags are)
|
||||
|
||||
@ -137,6 +136,7 @@ foreach ($response['boards'] as $boardUri => &$board) {
|
||||
// If we are filtering by tag and there is no match, remove from the response.
|
||||
if ( $search['tags'] !== false && ( !isset( $boardTags[ $boardUri ] ) || count(array_intersect($search['tags'], $boardTags[ $boardUri ])) !== count($search['tags']) ) ) {
|
||||
unset( $response['boards'][$boardUri] );
|
||||
continue;
|
||||
}
|
||||
// If we aren't filtering / there is a match AND we have tags, set the tags.
|
||||
else if ( isset( $boardTags[ $boardUri ] ) && $boardTags[ $boardUri ] ) {
|
||||
@ -146,6 +146,9 @@ foreach ($response['boards'] as $boardUri => &$board) {
|
||||
else {
|
||||
$board['tags'] = array();
|
||||
}
|
||||
|
||||
// Legacy support for API readers.
|
||||
$board['max'] = &$board['posts_total'];
|
||||
}
|
||||
|
||||
unset( $boardTags );
|
||||
@ -159,6 +162,7 @@ $boardActivity = fetchBoardActivity( array_keys( $response['boards'] ), $search[
|
||||
foreach ($response['boards'] as $boardUri => &$board) {
|
||||
$board['active'] = 0;
|
||||
$board['pph'] = 0;
|
||||
$board['ppd'] = 0;
|
||||
|
||||
if (isset($boardActivity['active'][ $boardUri ])) {
|
||||
$board['active'] = (int) $boardActivity['active'][ $boardUri ];
|
||||
@ -171,6 +175,7 @@ foreach ($response['boards'] as $boardUri => &$board) {
|
||||
}
|
||||
|
||||
$board['pph'] = round( $boardActivity['average'][ $boardUri ], 2 );
|
||||
$board['ppd'] = round( $boardActivity['today'][ $boardUri ], 2 );
|
||||
|
||||
unset( $precision );
|
||||
}
|
||||
@ -194,11 +199,17 @@ array_multisort(
|
||||
$response['boards']
|
||||
);
|
||||
|
||||
$boardLimit = $search['index'] ? 50 : 100;
|
||||
if (php_sapi_name() == 'cli') {
|
||||
$boardLimit = $search['index'] ? 50 : 100;
|
||||
|
||||
$response['omitted'] = count( $response['boards'] ) - $boardLimit;
|
||||
$response['omitted'] = $response['omitted'] < 0 ? 0 : $response['omitted'];
|
||||
$response['boards'] = array_splice( $response['boards'], $search['page'], $boardLimit );
|
||||
}
|
||||
else {
|
||||
$response['omitted'] = 0;
|
||||
}
|
||||
|
||||
$response['omitted'] = count( $response['boards'] ) - $boardLimit;
|
||||
$response['omitted'] = $response['omitted'] < 0 ? 0 : $response['omitted'];
|
||||
$response['boards'] = array_splice( $response['boards'], $search['page'], $boardLimit );
|
||||
$response['order'] = array_keys( $response['boards'] );
|
||||
|
||||
|
||||
|
14
boards.php
14
boards.php
@ -5,7 +5,7 @@ include "inc/functions.php";
|
||||
$admin = isset($mod["type"]) && $mod["type"]<=30;
|
||||
$founding_date = "October 23, 2013";
|
||||
|
||||
if (php_sapi_name() == 'fpm-fcgi' && !$admin) {
|
||||
if (php_sapi_name() == 'fpm-fcgi' && !$admin && count($_GET) == 0) {
|
||||
error('Cannot be run directly.');
|
||||
}
|
||||
|
||||
@ -92,5 +92,15 @@ $pageHTML = Element("page.html", array(
|
||||
)
|
||||
);
|
||||
|
||||
file_write("boards.html", $pageHTML);
|
||||
// We only want to cache if this is not a dynamic form request.
|
||||
// Otherwise, our information will be skewed by the search criteria.
|
||||
if (count($_GET) == 0) {
|
||||
// Preserves the JSON output format of [{board},{board}].
|
||||
$nonAssociativeBoardList = array_values($boards);
|
||||
|
||||
file_write("boards.html", $pageHTML);
|
||||
file_write("boards.json", json_encode($nonAssociativeBoardList));
|
||||
file_write("boards-top20.json", json_encode(array_splice($nonAssociativeBoardList, 0, 48)));
|
||||
}
|
||||
|
||||
echo $pageHTML;
|
@ -795,10 +795,11 @@ function listBoards($just_uri = false, $indexed_only = false) {
|
||||
``boards``.`indexed` indexed,
|
||||
``boards``.`sfw` sfw,
|
||||
``boards``.`posts_total` posts_total
|
||||
FROM ``boards``" . ( $indexed_only ? " WHERE `indexed` = 1 " : "" ) .
|
||||
"LEFT JOIN ``board_create``
|
||||
ON ``boards``.`uri` = ``board_create``.`uri`
|
||||
ORDER BY ``boards``.`uri`") or error(db_error());
|
||||
FROM ``boards``
|
||||
LEFT JOIN ``board_create``
|
||||
ON ``boards``.`uri` = ``board_create``.`uri`" .
|
||||
( $indexed_only ? " WHERE `indexed` = 1 " : "" ) .
|
||||
"ORDER BY ``boards``.`uri`") or error(db_error());
|
||||
|
||||
$boards = $query->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
@ -840,12 +841,17 @@ function fetchBoardActivity( array $uris = array(), $forTime = false, $detailed
|
||||
if (!is_integer($forTime)) {
|
||||
$forTime = time();
|
||||
}
|
||||
|
||||
// Get the last hour for this timestamp.
|
||||
$nowHour = ( (int)( time() / 3600 ) * 3600 );
|
||||
// Get the hour before. This is what we actually use for pulling data.
|
||||
$forHour = ( (int)( $forTime / 3600 ) * 3600 ) - 3600;
|
||||
// Get the hour from yesterday to calculate posts per day.
|
||||
$yesterHour = $forHour - ( 3600 * 23 );
|
||||
|
||||
$boardActivity = array(
|
||||
'active' => array(),
|
||||
'today' => array(),
|
||||
'average' => array(),
|
||||
);
|
||||
|
||||
@ -867,10 +873,21 @@ function fetchBoardActivity( array $uris = array(), $forTime = false, $detailed
|
||||
|
||||
// Format the results.
|
||||
foreach ($bsResult as $bsRow) {
|
||||
// Do we need to define the arrays for this URI?
|
||||
if (!isset($boardActivity['active'][$bsRow['stat_uri']])) {
|
||||
if ($bsRow['stat_hour'] == $forHour) {
|
||||
$boardActivity['active'][$bsRow['stat_uri']] = unserialize( $bsRow['author_ip_array'] );
|
||||
}
|
||||
else {
|
||||
$boardActivity['active'][$bsRow['stat_uri']] = array();
|
||||
}
|
||||
|
||||
if ($bsRow['stat_hour'] <= $forHour && $bsRow['stat_hour'] >= $yesterHour) {
|
||||
$boardActivity['today'][$bsRow['stat_uri']] = $bsRow['post_count'];
|
||||
}
|
||||
else {
|
||||
$boardActivity['today'][$bsRow['stat_uri']] = 0;
|
||||
}
|
||||
|
||||
$boardActivity['average'][$bsRow['stat_uri']] = $bsRow['post_count'];
|
||||
}
|
||||
@ -879,7 +896,11 @@ function fetchBoardActivity( array $uris = array(), $forTime = false, $detailed
|
||||
$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'];
|
||||
if ($bsRow['stat_hour'] <= $forHour && $bsRow['stat_hour'] >= $yesterHour) {
|
||||
$boardActivity['today'][$bsRow['stat_uri']] += $bsRow['post_count'];
|
||||
}
|
||||
|
||||
$boardActivity['average'][$bsRow['stat_uri']] += $bsRow['post_count'];
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user