<?php
if (function_exists('register_sidebars'))
register_sidebar( array ('name'=>'Sidebar380px', 'id'=>'sidebar380px', 'before_title'=>"<h3>", 
'after_title'=>" </h3>\n", 'before_widget' => '<li class="blogroll widget">', ' after_widget' => "</li>"  ));

function new_excerpt_length($length) {
	return 60;
}
add_filter('excerpt_length', 'new_excerpt_length');

$themename = "MT Dark";
$shortname = "dark";

$options = array (

	array(	"name" => "About",
			"type" => "title"),
			
	array(	"type" => "open"),
			
	array(	"name" => "Image",
			"desc" => "Paste the url to the image(80x90px).",
			"id" => $shortname."_img",
			"std" => "",
			"type" => "text"),
			
	array(	"name" => "About",
			"desc" => "Text to display as welcome message.",
            "id" => $shortname."_message",
            "type" => "textarea"),
	
	array(  "name" => "Disable \"About\" ",
			"desc" => "Check this box if you would like to DISABLE the \"About\".",
            "id" => $shortname."_disable",
            "type" => "checkbox",
            "std" => "false"),
	
	array(	"type" => "close"),
			
    array(	"name" => "Social media",
			"type" => "title"),			
				
	array(	"type" => "open"),
			
	array(  "name" => "Twitter",
			"desc" => "\"Twitter\"- username.",
            "id" => $shortname."_twett",
            "type" => "text"),
			
	array(  "name" => "Facebook",
			"desc" => "\"Facebook\"- username.",
            "id" => $shortname."_facebook",
            "type" => "text"),
			
	array(  "name" => "Flickr",
			"desc" => "\"Flickr\"- username.",
            "id" => $shortname."_flickr",
            "type" => "text"),
			
	array(  "name" => "YouTube",
			"desc" => "\"YouTube\"- username.",
            "id" => $shortname."_youtube",
            "type" => "text"),
			
	array(  "name" => "Blogger",
			"desc" => "\"Blogger\"- full url (http://name.blogspot.com/).",
            "id" => $shortname."_blogger",
            "type" => "text"),
			
	array(  "name" => "Last FM",
			"desc" => "\"Last FM\"- username.",
            "id" => $shortname."_last",
            "type" => "text"),
			
	array(  "name" => "Delicious ",
			"desc" => "\"Delicious\"- username.",
            "id" => $shortname."_del",
            "type" => "text"),			
			
	array(	"type" => "close"),
			
    array(	"name" => "Other",
			"type" => "title"),			
				
	array(	"type" => "open"),

	array(	"name" => "Header image",
			"desc" => "Paste the url to the image.(80x80)",
			"id" => $shortname."_headerimg",
			"std" => "",
			"type" => "text"),
						
    array(  "name" => "Disable the footer",
			"desc" => "Check this box if you would like to DISABLE the footer.",
            "id" => $shortname."_disable_footer",
            "type" => "checkbox",
            "std" => "false"),
			
	//array(  "name" => "Analytics code",
	//		"desc" => "Paste your Google Analytics  code in the box below.",
    //        "id" => $shortname."_analitics",
    //        "type" => "code"),
			
	array(	"type" => "close")
	
);

function mytheme_add_admin() {

    global $themename, $shortname, $options;

    if ( $_GET['page'] == basename(__FILE__) ) {
    
        if ( 'save' == $_REQUEST['action'] ) {

                foreach ($options as $value) {
                    update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }

                foreach ($options as $value) {
                    if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); } 
					else { delete_option( $value['id'] ); } }

                header("Location: themes.php?page=functions.php&saved=true");
                die;

        } else if( 'reset' == $_REQUEST['action'] ) {

            foreach ($options as $value) {
                delete_option( $value['id'] ); }

            header("Location: themes.php?page=functions.php&reset=true");
            die;

        }
    }

    add_theme_page($themename." Options", "".$themename." Options", 'edit_themes', basename(__FILE__), 'mytheme_admin');

}

function mytheme_admin() {

    global $themename, $shortname, $options;

    if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
    if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>';
    
?>
<div class="wrap">
<h2><?php echo $themename; ?> settings</h2>

<form method="post">

<?php foreach ($options as $value) { 
    
	switch ( $value['type'] ) {
	
		case "open": ?>
        <table width="100%" border="0" style="background-color:#eef5fb; padding:10px;">
<?php break; case "close": ?>
		
        </table><br />
<?php break; case "title": ?>
<table width="100%" border="0" style="background-color:#dceefc; padding:5px 10px;"><tr>
<td colspan="2"><h3 style="font-family:Georgia,'Times New Roman',Times,serif;"><?php echo $value['name']; ?></h3></td>
</tr>
     	<?php break; case 'text': ?>
        
        <tr>
            <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
<td width="80%"><input style="width:400px;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>"
 value="<?php if ( get_settings( $value['id'] ) != "") { echo get_settings( $value['id'] ); } else { echo $value['std']; } ?>" /></td>
        </tr>

        <tr>
            <td><small><?php echo $value['desc']; ?></small></td>
        </tr>
<tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>

		<?php  break; case 'textarea': ?>
        
        <tr>
            <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
<td width="80%"><textarea name="<?php echo $value['id']; ?>" style="width:400px; height:200px;" type="<?php echo $value['type']; ?>" 
cols="" rows=""><?php if ( get_settings( $value['id'] ) != "") { echo get_settings( $value['id'] ); } else { echo $value['std']; } ?></textarea></td>
            
        </tr>

        <tr>
            <td><small><?php echo $value['desc']; ?></small></td>
 </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>

		<?php  break; case 'code': ?>
        
        <tr>
            <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
<td width="80%"><textarea name="<?php echo $value['id']; ?>" style="width:400px; height:200px;" type="<?php echo $value['type']; ?>" 
cols="" rows="">< pr> <?php if ( get_settings( $value['id'] ) != "") { echo get_settings( $value['id'] ); } else { echo $value['std']; } ?>area></td>
            
        </tr>

        <tr>
            <td><small><?php echo $value['desc']; ?></small></td>
 </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>


		<?php  break; case 'select': ?>
        <tr>
            <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
            <td width="80%"><select style="width:240px;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>">
<?php foreach ($value['options'] as $option) { ?><option<?php if ( get_settings( $value['id'] ) == $option) { echo ' selected="selected"'; } 
elseif ($option == $value['std']) { echo ' selected="selected"'; } ?>><?php echo $option; ?></option><?php } ?></select></td>
       </tr>
                
       <tr>
            <td><small><?php echo $value['desc']; ?></small></td>
       </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>

		<?php  break; case "checkbox": ?>
            <tr>
            <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
                <td width="80%"><? if(get_settings($value['id'])){ $checked = "checked=\"checked\""; }else{ $checked = ""; } ?>
                        <input type="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="true" 
			<?php echo $checked; ?> />
                        </td>
            </tr>
                        
            <tr>
                <td><small><?php echo $value['desc']; ?></small></td>
           </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>
 <?php 		break;
} 
}
?>

<!--</table>-->

<p class="submit">
<input name="save" type="submit" value="<?php _e('Save changes'); ?>" />    
<input type="hidden" name="action" value="<?php _e('save'); ?>" />
</p>
</form>
<form method="post">
<p class="submit">
<input name="reset" type="submit" value="Reset" />
<input type="hidden" name="action" value="reset" />
</p>
</form>

<?php
}

add_action('admin_menu', 'mytheme_add_admin'); 

?>