function Element($templateFile, array $options) { global $config, $debug, $twig; if (!$twig) { load_twig(); } if (function_exists('create_pm_header') && (isset($options['mod']) && $options['mod'] || isset($options['__mod']))) { $options['pm'] = create_pm_header(); } if (isset($options['body']) && $config['debug']) { if (isset($debug['start'])) { $debug['time'] = '~' . round((microtime(true) - $debug['start']) * 1000, 2) . 'ms'; unset($debug['start']); } $debug['included'] = get_included_files(); $debug['memory'] = round(memory_get_usage(true) / (1024 * 1024), 2) . ' MiB'; $options['body'] .= '<h3>Debug</h3><pre style="white-space: pre-wrap;font-size: 10px;">' . str_replace("\n", '<br/>', utf8tohtml(print_r($debug, true))) . '</pre>'; } // Read the template file if (@file_get_contents("{$config['dir']['template']}/{$templateFile}")) { $body = $twig->render($templateFile, $options); if ($config['minify_html'] && preg_match('/\\.html$/', $templateFile)) { $body = trim(preg_replace("/[\t\r\n]/", '', $body)); } return $body; } else { throw new Exception("Template file '{$templateFile}' does not exist or is empty in '{$config['dir']['template']}'!"); } }
$start = microtime(true); // parse command line $opts = getopt('qfb:', array('board:', 'quick', 'full', 'quiet')); $options = array(); $global_locale = $config['locale']; $options['board'] = isset($opts['board']) ? $opts['board'] : (isset($opts['b']) ? $opts['b'] : false); $options['quiet'] = isset($opts['q']) || isset($opts['quiet']); $options['quick'] = isset($opts['quick']); $options['full'] = isset($opts['full']) || isset($opts['f']); if (!$options['quiet']) { echo "== Tinyboard + vichan {$config['version']} ==\n"; } if (!$options['quiet']) { echo "Clearing template cache...\n"; } load_twig(); $twig->clearCacheFiles(); if (!$options['quiet']) { echo "Regenerating theme files...\n"; } rebuildThemes('all'); if (!$options['quiet']) { echo "Generating Javascript file...\n"; } buildJavascript(); $main_js = $config['file_script']; $boards = listBoards(); foreach ($boards as &$board) { if ($options['board'] && $board['uri'] != $options['board']) { continue; }
function mod_rebuild() { global $config, $twig; if (!hasPermission($config['mod']['rebuild'])) { error($config['error']['noaccess']); } if (isset($_POST['rebuild'])) { @set_time_limit($config['mod']['rebuild_timelimit']); $log = array(); $boards = listBoards(); $rebuilt_scripts = array(); if (isset($_POST['rebuild_cache'])) { if ($config['cache']['enabled']) { $log[] = 'Flushing cache'; Cache::flush(); } $log[] = 'Clearing template cache'; load_twig(); $twig->clearCacheFiles(); } if (isset($_POST['rebuild_themes'])) { $log[] = 'Regenerating theme files'; rebuildThemes('all'); } if (isset($_POST['rebuild_javascript'])) { $log[] = 'Rebuilding <strong>' . $config['file_script'] . '</strong>'; buildJavascript(); $rebuilt_scripts[] = $config['file_script']; } foreach ($boards as $board) { if (!(isset($_POST['boards_all']) || isset($_POST['board_' . $board['uri']]))) { continue; } openBoard($board['uri']); $config['try_smarter'] = false; if (isset($_POST['rebuild_index'])) { buildIndex(); $log[] = '<strong>' . sprintf($config['board_abbreviation'], $board['uri']) . '</strong>: Creating index pages'; } if (isset($_POST['rebuild_javascript']) && !in_array($config['file_script'], $rebuilt_scripts)) { $log[] = '<strong>' . sprintf($config['board_abbreviation'], $board['uri']) . '</strong>: Rebuilding <strong>' . $config['file_script'] . '</strong>'; buildJavascript(); $rebuilt_scripts[] = $config['file_script']; } if (isset($_POST['rebuild_thread'])) { $query = query(sprintf("SELECT `id` FROM ``posts_%s`` WHERE `thread` IS NULL", $board['uri'])) or error(db_error()); while ($post = $query->fetch(PDO::FETCH_ASSOC)) { $log[] = '<strong>' . sprintf($config['board_abbreviation'], $board['uri']) . '</strong>: Rebuilding thread #' . $post['id']; buildThread($post['id']); } } } mod_page(_('Rebuild'), 'mod/rebuilt.html', array('logs' => $log)); return; } mod_page(_('Rebuild'), 'mod/rebuild.html', array('boards' => listBoards(), 'token' => make_secure_link_token('rebuild'))); }