<?php
/*
Plugin Name: WP-Unattended Export
Plugin URI: http://technosailor.com
Description: This plugin is meant to work in conjunction with a WordPress unattended install. It exports the blog settings in a generic way to wp-unattended.ini
Author: Aaron Brazell
Version: 1.0
Author URI: http://technosailor.com
*/ 

if(!function_exists('export_tab')) 
{
        function 
export_tab() 
        {
                if (
function_exists('add_management_page')) 
                        
add_management_page('Export INI''Export INI'8__FILE__'export_ini_page');                
        }
}

if(!
function_exists('export_ini_page'))
{
        function 
export_ini_page()
        {
                echo
'<div class="wrap">';
                if(isset(
$_POST['submit']))
                {
                        echo
'<h2>Copy wp-unattended.ini</h2>';
                        echo
'<p>Please copy the contents of this textbox to a blank file called <code>wp-unattended.ini</code> and upload it to the folder where the new WordPress has been uploaded.</p>';
                        
$ini wp_unattended_export();
                        echo
'<textarea rows="20" cols="80" >'.$ini.'</textarea>';
                }
                else 
                {
                        echo
'<h2>Export wp-unattended.ini</h2>';
                        echo
'<p>This will export this blogs settings to a .ini file for use with the WordPress unatteded install developed by <a href="Aaron">http://www.technosailor.com/">Aaron Brazell</a>.</p>';
                        echo
'<form method="post">';
                        echo
'<input type="submit" name="submit" value="Get wp-unattended.ini File" class="submit" />';
                        echo
'</form>';
                        echo
'</div>';
                }
        }
}

if(!
function_exists('wp_unattended_export'))
{
        function 
wp_unattended_export()
        {
                global 
$wpdb$table_prefix;

                
$ini_out '';
                
                
// Jesus Christ -- We should be able to do this better. IS there someplace where we
                // Can find the default options installed in a vanilla WP install?
                
$include = array('blogdescription''users_can_register''admin_email'
                
'start_of_week''use_balanceTags''use_smilies''require_name_email',
                
'comments_notify''posts_per_rss''rss_excerpt_length''rss_use_excerpt',
                
'mailserver_url''mailserver_login''mailserver_pass''mailserver_port',
                
'default_category''default_comment_status''default_ping_status'
                
'default_pingback_flag''default_post_edit_rows''posts_per_page',
                
'what_to_show''date_format''time_format''links_updated_date_format',
                
'links_recently_updated_prepend''links_recently_updated_append',
                
'links_recently_updated_time''comment_moderation''moderation_notify',
                
'gzipcompression''hack_file''blog_charset''moderation_keys'
                
'category_base''ping_sites''advanced_edit''comment_max_links',
                
'gmt_offset''default_email_category''recently_edited''use_linksupdate',
                
'template''stylesheet''comment_whitelist''blacklist_keys',
                
'comment_registration''open_proxy_check''rss_language''html_type',
                
'use_trackback''default_role''rich_editing''uploads_use_yearmonth_folders',
                
'upload_path');
                
                
$opts $wpdb->get_results("SELECT * FROM ".$table_prefix."options");
                foreach(
$opts as $opt)
                {
                        
// Eliminate the stuff we don't want in the ini file
                        
if( !in_array$opt->option_name$include ))
                                continue;
                        
$val maybe_unserialize($opt->option_value);
                        
$inival = (is_array($val)) ? implode(', '$val) : $val;
                        
                        
$ini_out .= "[$opt->option_name]\n";
                        
$ini_out .= "blog_id=\"0\"\n";
                        
$ini_out .= "option_name=\"$opt->option_name\"\n";
                        
$ini_out .= "option_can_override=\"$opt->option_can_override\"\n";
                        
$ini_out .= "option_type=\"$opt->option_type\"\n";
                        
$ini_out .= "option_value=\"$inival\"\n";
                        
$ini_out .= "option_width=\"$opt->option_width\"\n";
                        
$ini_out .= "option_height=\"$opt->option_height\"\n";
                        
$ini_out .= "option_description=\"$opt->option_description\"\n";
                        
$ini_out .= "option_admin_level=\"$opt->option_admin_level\"\n";
                        
$ini_out .= "autoload=\"$opt->autoload\"\n\n";
                }
                return 
$ini_out;
                        
        }
}

/* Actions */
add_action('admin_menu''export_tab');
?>