forked from leftypol/leftypol
Reimplement overboard
This commit is contained in:
parent
2efd67ef85
commit
ea99ddc6f6
|
@ -763,14 +763,19 @@ function mod_view_catalog($boardName) {
|
|||
$settings['title'] = 'Catalog';
|
||||
$settings['use_tooltipster'] = true;
|
||||
$catalog = new Catalog($settings);
|
||||
echo $catalog->build($boardName, true);
|
||||
|
||||
if (openBoard($boardName)) {
|
||||
echo $catalog->build($boardName, true);
|
||||
} else {
|
||||
error("The overboard(s) mod catalog hasn't been implemented yet");
|
||||
}
|
||||
}
|
||||
|
||||
function mod_view_board($boardName, $page_no = 1) {
|
||||
global $config, $mod;
|
||||
|
||||
if (!openBoard($boardName)){
|
||||
if (in_array($boardName,array_keys($config['overboards']))){
|
||||
if (in_array($boardName, array_keys($config['overboards']))){
|
||||
$type = $config['overboards'][$boardName]['type'];
|
||||
require_once("templates/themes/$type/theme.php");
|
||||
global $mod;
|
||||
|
|
|
@ -7,6 +7,11 @@
|
|||
$b = new Catalog($settings);
|
||||
$boards = explode(' ', $settings['boards']);
|
||||
|
||||
if (isset($settings['has_overboard']) && $settings['has_overboard']) {
|
||||
// Include overboard settings so that we can find them all and process exclusions
|
||||
require "templates/themes/overboards/overboards.php";
|
||||
}
|
||||
|
||||
// Possible values for $action:
|
||||
// - all (rebuild everything, initialization)
|
||||
// - news (news has been updated)
|
||||
|
@ -24,7 +29,21 @@
|
|||
$b->build($board);
|
||||
}
|
||||
}
|
||||
} elseif ($action == 'post-thread' || ($settings['update_on_posts'] && $action == 'post') || ($settings['update_on_posts'] && $action == 'post-delete') && in_array($board, $boards)) {
|
||||
if (isset($settings['has_overboard']) && $settings['has_overboard']) {
|
||||
foreach ($overboards_config as &$overboard) {
|
||||
$included_boards = array_diff(listBoards(true), $overboard['exclude']);
|
||||
$action = generation_strategy("sb_catalog", array($overboard));
|
||||
if ($action == 'delete') {
|
||||
file_unlink($config['dir']['home'] . $overboard . '/catalog.html');
|
||||
file_unlink($config['dir']['home'] . $overboard . '/index.rss');
|
||||
}
|
||||
elseif ($action == 'rebuild') {
|
||||
$b->buildOverboard($overboard['uri'], $settings, $included_boards);
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif ($action == 'post-thread' || ($settings['update_on_posts'] && $action == 'post') || ($settings['update_on_posts'] && $action == 'post-delete')
|
||||
|| $action == 'sticky' || ($action == 'lock' && in_array($board, $boards))) {
|
||||
$b = new Catalog($settings);
|
||||
|
||||
$action = generation_strategy("sb_catalog", array($board));
|
||||
|
@ -34,6 +53,13 @@
|
|||
}
|
||||
elseif ($action == 'rebuild') {
|
||||
$b->build($board);
|
||||
|
||||
if (isset($settings['has_overboard']) && $settings['has_overboard']) {
|
||||
foreach ($overboards_config as &$overboard) {
|
||||
$included_boards = array_diff(listBoards(true), $overboard['exclude']);
|
||||
$b->buildOverboard($overboard['uri'], $settings, $included_boards);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,7 +139,7 @@
|
|||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build and save the HTML of the catalog for the Rand theme
|
||||
*/
|
||||
|
@ -162,12 +188,76 @@
|
|||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the overboard.
|
||||
*
|
||||
* @param string $board_name The name of the overboard.
|
||||
* @param array $settings The settings array.
|
||||
* @param array $boards The array with all the board to generate the catalog from. Will use all the boards if null.
|
||||
* @param bool $mod If the board is to be generate for mod view.
|
||||
* @return mixed Viewable html.
|
||||
*/
|
||||
public function buildOverboard($board_name, $settings, $boards, $mod = false) {
|
||||
global $config;
|
||||
|
||||
if (array_key_exists($board_name, $this->threadsCache)) {
|
||||
$threads = $this->threadsCache[$board_name];
|
||||
} else {
|
||||
$sql = '';
|
||||
foreach ($boards as $board) {
|
||||
$sql .= '('. $this->buildThreadsQuery($board) . ')';
|
||||
$sql .= " UNION ALL ";
|
||||
}
|
||||
$sql = preg_replace('/UNION ALL $/', 'ORDER BY `bump` DESC LIMIT :limit', $sql);
|
||||
$query = prepare($sql);
|
||||
$query->bindValue(':limit', $settings['overboard_limit'], PDO::PARAM_INT);
|
||||
$query->execute() or error(db_error($query));
|
||||
|
||||
$threads = $query->fetchAll(PDO::FETCH_ASSOC);
|
||||
// Save for posterity
|
||||
$this->threadsCache[$board_name] = $threads;
|
||||
}
|
||||
// Generate data for the template
|
||||
$recent_posts = $this->generateRecentPosts($threads);
|
||||
|
||||
$ret = $this->saveForBoard($board_name, $recent_posts, '/' . $board_name, $mod, true);
|
||||
|
||||
// Build the overboard JSON outputs
|
||||
if ($config['api']['enabled']) {
|
||||
$api = new Api();
|
||||
|
||||
// Separate the threads into pages
|
||||
$pages = array(array());
|
||||
$totalThreads = count($recent_posts);
|
||||
$page = 0;
|
||||
for ($i = 1; $i <= $totalThreads; $i++) {
|
||||
$pages[$page][] = new Thread($recent_posts[$i-1]);
|
||||
|
||||
// If we have not yet visited all threads,
|
||||
// and we hit the limit on the current page,
|
||||
// skip to the next page
|
||||
if ($i < $totalThreads && ($i % $config['threads_per_page'] == 0)) {
|
||||
$page++;
|
||||
$pages[$page] = array();
|
||||
}
|
||||
}
|
||||
|
||||
$json = json_encode($api->translateCatalog($pages));
|
||||
file_write($config['dir']['home'] . $board_name . '/catalog.json', $json);
|
||||
|
||||
$json = json_encode($api->translateCatalog($pages, true));
|
||||
file_write($config['dir']['home'] . $board_name . '/threads.json', $json);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build and save the HTML of the catalog for the given board
|
||||
*/
|
||||
public function build($board_name, $mod = false) {
|
||||
if (!openBoard($board_name)) {
|
||||
error(sprintf(_("Board %s doesn't exist"), $post['board']));
|
||||
error(sprintf(_("Board %s doesn't exist"), $board_name));
|
||||
}
|
||||
|
||||
if (array_key_exists($board_name, $this->threadsCache)) {
|
||||
|
@ -267,7 +357,7 @@
|
|||
return $posts;
|
||||
}
|
||||
|
||||
private function saveForBoard($board_name, $recent_posts, $board_link = null, $mod = false) {
|
||||
private function saveForBoard($board_name, $recent_posts, $board_link = null, $mod = false, $is_overboard = false) {
|
||||
global $board, $config;
|
||||
|
||||
$required_scripts = array('js/jquery.min.js', 'js/jquery.mixitup.min.js',
|
||||
|
@ -286,7 +376,7 @@
|
|||
$board_link = ($mod) ? $config['root'] . $config['file_mod'] . '?/' . $board['dir'] : $config['root'] . $board['dir'];
|
||||
}
|
||||
|
||||
$element = Element('themes/catalog/catalog.html', Array(
|
||||
$template_config = Array(
|
||||
'settings' => $this->settings,
|
||||
'config' => $config,
|
||||
'boardlist' => createBoardlist($mod),
|
||||
|
@ -295,10 +385,26 @@
|
|||
'stats' => array(),
|
||||
'board_name' => $board_name,
|
||||
'board' => $board,
|
||||
'is_overboard' => $is_overboard,
|
||||
'antibot' => $antibot,
|
||||
'link' => $board_link,
|
||||
'mod' => $mod
|
||||
));
|
||||
);
|
||||
|
||||
// Fake board, I vomit and patch the template configuration.
|
||||
if ($is_overboard) {
|
||||
// Redefine 'board' and disable posting.
|
||||
$template_config['board'] = Array(
|
||||
'uri' => $board_name,
|
||||
'title' => $board_name,
|
||||
'name' => $board_name,
|
||||
'dir' => $board_name . '/',
|
||||
'url' => '/' . $board_name . '/'
|
||||
);
|
||||
$template_config['no_post_form'] = true;
|
||||
}
|
||||
|
||||
$element = Element('themes/catalog/catalog.html', $template_config);
|
||||
|
||||
if ($mod) {
|
||||
return $element;
|
||||
|
|
Loading…
Reference in New Issue
Block a user