setFile('main', 'themes.html'); if (isset($_POST['theme'])) { $lp_opts->updateOption('lp_opt_template', $_POST['theme']); } else { $tpl->setBlock('main', 'message', 'MESSAGE'); } $themes_dir = $lp_opts->basedir . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR; $current_theme = get_option('lp_opt_template'); $current_theme_preview = $themes_dir . $current_theme . DIRECTORY_SEPARATOR . 'preview.jpg'; $tpl_vars = array( 'url' => get_option('siteurl'), 'current_theme' => $current_theme, 'current_theme_preview' => is_file($current_theme_preview) && is_readable($current_theme_preview) ? "$current_theme/preview.jpg" : 'preview.jpg', 'current_theme_readme' => '', 'MESSAGE' => '' ); $theme_readme = $themes_dir . get_option('lp_opt_template') . DIRECTORY_SEPARATOR . 'readme.txt'; if (is_file($theme_readme) && is_readable($theme_readme)) $tpl_vars['current_theme_readme'] = implode('', file($theme_readme)); // detect valid themes $lang = explode('_', get_option('lp_opt_lang')); $lang = $lang[0]; $charset = get_option('lp_opt_charset'); $theme_subdir = "${lang}.$charset"; $themes = array(); if (is_dir($themes_dir)) { $themes_dirp = opendir($themes_dir); while (($theme_dir = readdir($themes_dirp)) !== false) { if ($theme_dir[0] == '.') continue; if ($theme_dir == $current_theme) continue; $theme_path = $themes_dir . $theme_dir . DIRECTORY_SEPARATOR; if (!is_dir($theme_path . $theme_subdir)) continue; $themes[] = array( 'theme'=>$theme_dir, 'theme_preview'=>file_exists($theme_path . 'preview.jpg') ? "$theme_dir/preview.jpg" : 'preview.jpg', 'theme_readme'=>file_exists($theme_path . 'readme.txt') && is_readable($theme_path . 'readme.txt') ? implode('', file($theme_path . 'readme.txt')) : ''); } } $tpl->setBlock('main', 'theme', 'THEME'); foreach ($themes as $t) { $tpl->setVar($t); $tpl->parse('THEME', 'theme', true); } $tpl->setVar($tpl_vars); $out =& $tpl->parse('MAIN', 'main'); echo $out; ?>