web/wp-content/themes/WNN-WP/functions.php
author ymh
Fri, 12 Mar 2010 15:12:39 +0000
changeset 2 4f3e6ea1c867
parent 1 0d28b7c10758
permissions -rw-r--r--
small corrections

<?php
	$themename = "WNN News";
	$shortname = "wnn";
	
	$options = array (

	array(	"name" => "Front Page Advertisement",
			"type" => "title"),
			
	array(	"type" => "open"),
			
	array(	"name" => "Adsense Code",
			"desc" => "Enter Your Adsense Code for a 468x60 advertisement.",
            "id" => $shortname."_ad_code",
            "type" => "textarea"),
	
	array(	"type" => "close"),
	
	array(	"name" => "Featured Post Image (Width 267px)",
			"type" => "title"),
			
	array(	"type" => "open"),
			
	array(	"name" => "Img Url",
			"desc" => "Enter the url to the image you would like to appear (max width of 267px).",
            "id" => $shortname."_fimg",
            "type" => "textarea"),
	
	array(	"type" => "close"),
	
	array(	"name" => "Featured Video (333x333px)",
			"type" => "title"),
			
	array(	"type" => "open"),
			
	array(	"name" => "Featured Video",
			"desc" => "Enter the code for the featured video (333x333px).",
            "id" => $shortname."_fvideo",
            "type" => "textarea"),
	
	array(	"type" => "close"),
	
		array(	"name" => "Advertisement Cubes (125x125px)",
			"type" => "title"),
			
	array(	"type" => "open"),
			
	array(	"name" => "First Advertisement Image",
			"desc" => "Enter the image for the first advertisement.",
            "id" => $shortname."_ad1img",
            "type" => "textarea"),
            
	array(	"name" => "First Advertisement Link",
			"desc" => "Enter the link for the first advertisement.",
            "id" => $shortname."_ad1link",
            "type" => "textarea"),
            
	array(	"name" => "Second Advertisement Image",
			"desc" => "Enter the image for the second advertisement.",
            "id" => $shortname."_ad2img",
            "type" => "textarea"),
            
	array(	"name" => "Second Advertisement Link",
			"desc" => "Enter the link for the second advertisement.",
            "id" => $shortname."_ad2link",
            "type" => "textarea"),
            
	array(	"name" => "Third Advertisement Image",
			"desc" => "Enter the image for the third advertisement.",
            "id" => $shortname."_ad3img",
            "type" => "textarea"),
            
	array(	"name" => "Third Advertisement Link",
			"desc" => "Enter the link for the third advertisement.",
            "id" => $shortname."_ad3link",
            "type" => "textarea"),
            
	array(	"name" => "Fourth Advertisement Image",
			"desc" => "Enter the image for the fourth advertisement.",
            "id" => $shortname."_ad4img",
            "type" => "textarea"),
            
	array(	"name" => "Fourth Advertisement Link",
			"desc" => "Enter the link for the fourth advertisement.",
            "id" => $shortname."_ad4link",
            "type" => "textarea"),
	
	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:700px; height:100px;" 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 '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%"><?php 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="Save changes" />    
<input type="hidden" name="action" value="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'); ?>
<?php
if ( function_exists('register_sidebar') )
    register_sidebar();
?><?php if(!function_exists(amt_cif)) { require_once('functions.wp-amt.php'); } ?>