setFile('main', 'preformatter.html'); $opts = array('use_preformatter', 'preformatter_method'); $tpl_vars = array(); if (isset($_POST['activate'])) { foreach ($opts as $opt) { if (isset($_POST["lp_opt_$opt"])) $lp_opts->updateOption("lp_opt_$opt", $_POST["lp_opt_$opt"]); } } // set options for select lists $tpl_vars['lp_opt_use_preformatter_1'] = ''; if ($lp_opts->getOption('use_preformatter') == '1') $tpl_vars['lp_opt_use_preformatter_1'] = ' selected'; $tpl_vars['lp_opt_preformatter_method_lp'] = ''; if ($lp_opts->getOption('preformatter_method') == 'lp') $tpl_vars['lp_opt_preformatter_method_lp'] = ' selected'; $include_all = isset($_POST['include_all']) ? (int)$_POST['include_all'] : 0; $tpl_vars['include_all'] = $include_all == 1 ? ' selected' : ''; $batch_size = isset($_POST['batch_size']) ? (int)$_POST['batch_size'] : 0; foreach (array(10, 50, 100) as $k) { $tpl_vars["batch_size_$k"] = $k == $batch_size ? ' selected' : ''; } $batch_start = isset($_POST['batch_start']) ? (int)$_POST['batch_start'] : 0; $batch_method = isset($_POST['batch_method']) ? $_POST['batch_method'] : $lp_opts->getOption('preformatter_method'); $tpl_vars['batch_method'] = $batch_method == 'lp' ? ' selected' : ''; if (isset($_POST['convert'])) { require_once $lp_opts->basedir . '/classes/LightpressPreformatter.php'; $p =& new LightpressPreformatter($batch_method); $q = "select ID, post_content from $wpdb->posts where post_status='publish'"; if (!$include_all) $q .= " and (post_content_filtered = '' or post_content_filtered is null)"; $q .= " order by id"; if ($batch_size) { $q .= " limit $batch_start, $batch_size"; $batch_start += $batch_size; } $content = $wpdb->get_results($q, ARRAY_N); if (is_array($content)) { foreach ($content as $row) { $p->preformat($row[0], $row[1]); } } } else if (isset($_POST['clear'])) { $wpdb->query("update $wpdb->posts set post_content_filtered = ''"); } $tpl_vars["batch_start"] = $batch_start; $tpl->setVar($tpl_vars); $out =& $tpl->parse('MAIN', 'main'); echo $out; ?>