2013-01-02 18:40:30 +01:00
< ? php
require 'info.php' ;
function ukko_build ( $action , $settings ) {
$ukko = new ukko ();
$ukko -> settings = $settings ;
2014-04-30 17:24:11 +02:00
file_write ( $settings [ 'uri' ] . '/index.html' , $ukko -> build ());
file_write ( $settings [ 'uri' ] . '/ukko.js' , Element ( 'themes/ukko/ukko.js' , array ()));
2013-01-02 18:40:30 +01:00
}
class ukko {
public $settings ;
public function build ( $mod = false ) {
2014-04-19 22:02:15 +02:00
global $config , $board ;
2013-01-02 18:40:30 +01:00
$boards = listBoards ();
$body = '' ;
$overflow = array ();
$board = array (
'url' => $this -> settings [ 'uri' ],
'name' => $this -> settings [ 'title' ],
'title' => sprintf ( $this -> settings [ 'subtitle' ], $this -> settings [ 'thread_limit' ])
);
$query = '' ;
foreach ( $boards as & $_board ) {
if ( in_array ( $_board [ 'uri' ], explode ( ' ' , $this -> settings [ 'exclude' ])))
continue ;
2013-08-01 07:16:20 +02:00
$query .= sprintf ( " SELECT *, '%s' AS `board` FROM ``posts_%s`` WHERE `thread` IS NULL UNION ALL " , $_board [ 'uri' ], $_board [ 'uri' ]);
2013-01-02 18:40:30 +01:00
}
$query = preg_replace ( '/UNION ALL $/' , 'ORDER BY `bump` DESC' , $query );
$query = query ( $query ) or error ( db_error ());
$count = 0 ;
$threads = array ();
while ( $post = $query -> fetch ()) {
if ( ! isset ( $threads [ $post [ 'board' ]])) {
$threads [ $post [ 'board' ]] = 1 ;
} else {
$threads [ $post [ 'board' ]] += 1 ;
}
if ( $count < $this -> settings [ 'thread_limit' ]) {
2014-04-19 22:02:15 +02:00
$config [ 'uri_thumb' ] = '/' . $post [ 'board' ] . '/thumb/' ;
$config [ 'uri_img' ] = '/' . $post [ 'board' ] . '/src/' ;
$board [ 'dir' ] = $post [ 'board' ] . '/' ;
2013-08-16 16:13:06 +02:00
$thread = new Thread ( $post , $mod ? '?/' : $config [ 'root' ], $mod );
2013-01-02 18:40:30 +01:00
2013-08-01 07:16:20 +02:00
$posts = prepare ( sprintf ( " SELECT * FROM ``posts_%s`` WHERE `thread` = :id ORDER BY `id` DESC LIMIT :limit " , $post [ 'board' ]));
2013-01-02 18:40:30 +01:00
$posts -> bindValue ( ':id' , $post [ 'id' ]);
$posts -> bindValue ( ':limit' , ( $post [ 'sticky' ] ? $config [ 'threads_preview_sticky' ] : $config [ 'threads_preview' ]), PDO :: PARAM_INT );
$posts -> execute () or error ( db_error ( $posts ));
$num_images = 0 ;
while ( $po = $posts -> fetch ()) {
2014-04-19 22:02:15 +02:00
$config [ 'uri_thumb' ] = '/' . $post [ 'board' ] . '/thumb/' ;
$config [ 'uri_img' ] = '/' . $post [ 'board' ] . '/src/' ;
2013-01-02 18:40:30 +01:00
if ( $po [ 'file' ])
$num_images ++ ;
2013-08-16 16:13:06 +02:00
$thread -> add ( new Post ( $po , $mod ? '?/' : $config [ 'root' ], $mod ));
2013-01-02 18:40:30 +01:00
}
if ( $posts -> rowCount () == ( $post [ 'sticky' ] ? $config [ 'threads_preview_sticky' ] : $config [ 'threads_preview' ])) {
2013-12-22 20:18:10 +01:00
$ct = prepare ( sprintf ( " SELECT COUNT(`id`) as `num` FROM ``posts_%s`` WHERE `thread` = :thread UNION ALL SELECT COUNT(`id`) FROM ``posts_%s`` WHERE `file` IS NOT NULL AND `thread` = :thread " , $post [ 'board' ], $post [ 'board' ]));
2013-01-02 18:40:30 +01:00
$ct -> bindValue ( ':thread' , $post [ 'id' ], PDO :: PARAM_INT );
$ct -> execute () or error ( db_error ( $count ));
$c = $ct -> fetch ();
$thread -> omitted = $c [ 'num' ] - ( $post [ 'sticky' ] ? $config [ 'threads_preview_sticky' ] : $config [ 'threads_preview' ]);
$c = $ct -> fetch ();
$thread -> omitted_images = $c [ 'num' ] - $num_images ;
}
$thread -> posts = array_reverse ( $thread -> posts );
$body .= '<h2><a href="' . $config [ 'root' ] . $post [ 'board' ] . '">/' . $post [ 'board' ] . '/</a></h2>' ;
$body .= $thread -> build ( true );
} else {
$page = 'index' ;
if ( floor ( $threads [ $post [ 'board' ]] / $config [ 'threads_per_page' ]) > 0 ) {
$page = floor ( $threads [ $post [ 'board' ]] / $config [ 'threads_per_page' ]) + 1 ;
}
$overflow [] = array ( 'id' => $post [ 'id' ], 'board' => $post [ 'board' ], 'page' => $page . '.html' );
}
$count += 1 ;
}
$body .= '<script> var overflow = ' . json_encode ( $overflow ) . '</script>' ;
2014-04-30 17:24:11 +02:00
$body .= '<script type="text/javascript" src="/' . $this -> settings [ 'uri' ] . '/ukko.js"></script>' ;
2013-01-02 18:40:30 +01:00
2014-04-19 22:02:15 +02:00
$config [ 'default_stylesheet' ] = array ( 'Yotsuba B' , $config [ 'stylesheets' ][ 'Yotsuba B' ]);
2014-05-05 17:04:41 +02:00
2014-04-30 17:24:11 +02:00
return Element ( 'index.html' , array (
2013-01-02 18:40:30 +01:00
'config' => $config ,
'board' => $board ,
'no_post_form' => true ,
'body' => $body ,
2014-04-30 17:24:11 +02:00
'mod' => $mod ,
'boardlist' => createBoardlist ( $mod ),
));
2013-01-02 18:40:30 +01:00
}
};
?>