forked from GithubBackups/vichan
#456 - boards.php no longer generates a cache file or forbids direct access if a $_GET is specified.
#456 - boards.php now generates a boards.json and boards-top20.json when accessed directly. #456 - Added API compatibility to board-search.php ('max' and 'ppd') #456 - Fixed an issue with listBoards() that caused an SQL error if you only asked for indexed. fuck I hope this works Signed-off-by: 8n-tech <8n-tech@users.noreply.github.com>
This commit is contained in:
parent
32061668a3
commit
5f5dbbd163
@ -125,7 +125,6 @@ foreach ($boards as $board) {
|
|||||||
|
|
||||||
unset( $boards );
|
unset( $boards );
|
||||||
|
|
||||||
|
|
||||||
/* Tag Fetching */
|
/* Tag Fetching */
|
||||||
// (We have do this even if we're not filtering by tags so that we know what each board's tags are)
|
// (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 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']) ) ) {
|
if ( $search['tags'] !== false && ( !isset( $boardTags[ $boardUri ] ) || count(array_intersect($search['tags'], $boardTags[ $boardUri ])) !== count($search['tags']) ) ) {
|
||||||
unset( $response['boards'][$boardUri] );
|
unset( $response['boards'][$boardUri] );
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
// If we aren't filtering / there is a match AND we have tags, set the tags.
|
// If we aren't filtering / there is a match AND we have tags, set the tags.
|
||||||
else if ( isset( $boardTags[ $boardUri ] ) && $boardTags[ $boardUri ] ) {
|
else if ( isset( $boardTags[ $boardUri ] ) && $boardTags[ $boardUri ] ) {
|
||||||
@ -146,6 +146,9 @@ foreach ($response['boards'] as $boardUri => &$board) {
|
|||||||
else {
|
else {
|
||||||
$board['tags'] = array();
|
$board['tags'] = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Legacy support for API readers.
|
||||||
|
$board['max'] = &$board['posts_total'];
|
||||||
}
|
}
|
||||||
|
|
||||||
unset( $boardTags );
|
unset( $boardTags );
|
||||||
@ -159,6 +162,7 @@ $boardActivity = fetchBoardActivity( array_keys( $response['boards'] ), $search[
|
|||||||
foreach ($response['boards'] as $boardUri => &$board) {
|
foreach ($response['boards'] as $boardUri => &$board) {
|
||||||
$board['active'] = 0;
|
$board['active'] = 0;
|
||||||
$board['pph'] = 0;
|
$board['pph'] = 0;
|
||||||
|
$board['ppd'] = 0;
|
||||||
|
|
||||||
if (isset($boardActivity['active'][ $boardUri ])) {
|
if (isset($boardActivity['active'][ $boardUri ])) {
|
||||||
$board['active'] = (int) $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['pph'] = round( $boardActivity['average'][ $boardUri ], 2 );
|
||||||
|
$board['ppd'] = round( $boardActivity['today'][ $boardUri ], 2 );
|
||||||
|
|
||||||
unset( $precision );
|
unset( $precision );
|
||||||
}
|
}
|
||||||
@ -194,11 +199,17 @@ array_multisort(
|
|||||||
$response['boards']
|
$response['boards']
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (php_sapi_name() == 'cli') {
|
||||||
$boardLimit = $search['index'] ? 50 : 100;
|
$boardLimit = $search['index'] ? 50 : 100;
|
||||||
|
|
||||||
$response['omitted'] = count( $response['boards'] ) - $boardLimit;
|
$response['omitted'] = count( $response['boards'] ) - $boardLimit;
|
||||||
$response['omitted'] = $response['omitted'] < 0 ? 0 : $response['omitted'];
|
$response['omitted'] = $response['omitted'] < 0 ? 0 : $response['omitted'];
|
||||||
$response['boards'] = array_splice( $response['boards'], $search['page'], $boardLimit );
|
$response['boards'] = array_splice( $response['boards'], $search['page'], $boardLimit );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$response['omitted'] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
$response['order'] = array_keys( $response['boards'] );
|
$response['order'] = array_keys( $response['boards'] );
|
||||||
|
|
||||||
|
|
||||||
|
12
boards.php
12
boards.php
@ -5,7 +5,7 @@ include "inc/functions.php";
|
|||||||
$admin = isset($mod["type"]) && $mod["type"]<=30;
|
$admin = isset($mod["type"]) && $mod["type"]<=30;
|
||||||
$founding_date = "October 23, 2013";
|
$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.');
|
error('Cannot be run directly.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,5 +92,15 @@ $pageHTML = Element("page.html", array(
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 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.html", $pageHTML);
|
||||||
|
file_write("boards.json", json_encode($nonAssociativeBoardList));
|
||||||
|
file_write("boards-top20.json", json_encode(array_splice($nonAssociativeBoardList, 0, 48)));
|
||||||
|
}
|
||||||
|
|
||||||
echo $pageHTML;
|
echo $pageHTML;
|
@ -795,10 +795,11 @@ function listBoards($just_uri = false, $indexed_only = false) {
|
|||||||
``boards``.`indexed` indexed,
|
``boards``.`indexed` indexed,
|
||||||
``boards``.`sfw` sfw,
|
``boards``.`sfw` sfw,
|
||||||
``boards``.`posts_total` posts_total
|
``boards``.`posts_total` posts_total
|
||||||
FROM ``boards``" . ( $indexed_only ? " WHERE `indexed` = 1 " : "" ) .
|
FROM ``boards``
|
||||||
"LEFT JOIN ``board_create``
|
LEFT JOIN ``board_create``
|
||||||
ON ``boards``.`uri` = ``board_create``.`uri`
|
ON ``boards``.`uri` = ``board_create``.`uri`" .
|
||||||
ORDER BY ``boards``.`uri`") or error(db_error());
|
( $indexed_only ? " WHERE `indexed` = 1 " : "" ) .
|
||||||
|
"ORDER BY ``boards``.`uri`") or error(db_error());
|
||||||
|
|
||||||
$boards = $query->fetchAll(PDO::FETCH_ASSOC);
|
$boards = $query->fetchAll(PDO::FETCH_ASSOC);
|
||||||
}
|
}
|
||||||
@ -840,12 +841,17 @@ function fetchBoardActivity( array $uris = array(), $forTime = false, $detailed
|
|||||||
if (!is_integer($forTime)) {
|
if (!is_integer($forTime)) {
|
||||||
$forTime = time();
|
$forTime = time();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the last hour for this timestamp.
|
// Get the last hour for this timestamp.
|
||||||
$nowHour = ( (int)( time() / 3600 ) * 3600 );
|
$nowHour = ( (int)( time() / 3600 ) * 3600 );
|
||||||
|
// Get the hour before. This is what we actually use for pulling data.
|
||||||
$forHour = ( (int)( $forTime / 3600 ) * 3600 ) - 3600;
|
$forHour = ( (int)( $forTime / 3600 ) * 3600 ) - 3600;
|
||||||
|
// Get the hour from yesterday to calculate posts per day.
|
||||||
|
$yesterHour = $forHour - ( 3600 * 23 );
|
||||||
|
|
||||||
$boardActivity = array(
|
$boardActivity = array(
|
||||||
'active' => array(),
|
'active' => array(),
|
||||||
|
'today' => array(),
|
||||||
'average' => array(),
|
'average' => array(),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -867,10 +873,21 @@ function fetchBoardActivity( array $uris = array(), $forTime = false, $detailed
|
|||||||
|
|
||||||
// Format the results.
|
// Format the results.
|
||||||
foreach ($bsResult as $bsRow) {
|
foreach ($bsResult as $bsRow) {
|
||||||
|
// Do we need to define the arrays for this URI?
|
||||||
if (!isset($boardActivity['active'][$bsRow['stat_uri']])) {
|
if (!isset($boardActivity['active'][$bsRow['stat_uri']])) {
|
||||||
if ($bsRow['stat_hour'] == $forHour) {
|
if ($bsRow['stat_hour'] == $forHour) {
|
||||||
$boardActivity['active'][$bsRow['stat_uri']] = unserialize( $bsRow['author_ip_array'] );
|
$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'];
|
$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['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