<?php
/**
  Photo Nexus Theme
 * 
 */
if ( function_exists('register_sidebar') )
	register_sidebar(array(
		'before_widget' => '<div class="sidebarbox">',
		'after_widget' => '</div>',
		'before_title' => '<div class="sidebartitle">',
		'after_title' => '</div>',
	));

//***************Category Exluding script - 
//Enter categories to exclude seperated by commas. $query->set('cat', '-7, -1 , -2');
function exclude_category($query) {
	if ( $query->is_home ) {
		$query->set('cat', '');
	}
return $query;
}

add_filter('pre_get_posts', 'exclude_category');

function override_jquery() {
     if ( is_admin() ) // using a newer version of jQuery will break stuff in WP admin
          return;
     wp_deregister_script('jquery');
     wp_register_script('jquery', '/path/to/your/version/of/jquery.js'); // Keep as it is if there are no problems
}

add_action('init', 'override_jquery'); // Override Jquery to the version loaded by Header



/*Start of Theme Options*/
 
$themename = "Photo Nexus";
$shortname = "phonx";
$options = array (

array(  "name" => "Photo Nexus Options",
	"type" => "title"),

array(  "type" => "open"),

array(  "name" => "Photo Nexus theme",
	"desc" => "Choose either the Dark or Bright theme for Photo Nexus.",
	"id" => $shortname."_theme",
	"type" => "select",
	"std" => "Bright theme",
	"options" => array("Bright theme", "Dark theme")),
	
array(  "name" => "Top of page spacing (height in pixels)",
	"desc" => "Enter in Pixels height of space between top of page and header",
	"id" => $shortname."_topspace",
	"std" => "0",
	"type" => "text"),

array(  "name" => "How would you like the Menu",
	"desc" => "Do you want Expanded Menus or Subcategory Collapsed Menus",
	"id" => $shortname."_menu",
	"type" => "select",
	"std" => "Collapsed",
	"options" => array("Expanded", "Collapsed")),

array(  "name" => "Featured Slide Effect",
	"desc" => "Do you want Slide or Fade in/out featured slideshow",
	"id" => $shortname."_featured_slide",
	"type" => "select",
	"std" => "slide",
	"options" => array("fade", "slide")),

array(  "name" => "Featured Slideshow Type",
	"desc" => "How do you want the Slideshow",
	"id" => $shortname."_featured_slideshow",
	"type" => "select",
	"std" => "sequence",
	"options" => array("sequence", "random")),

array(  "name" => "Gallery Slideshow Autoplay",
	"desc" => "Do you want your slideshow to autoplay",
	"id" => $shortname."_autoplay_gallery",
	"type" => "select",
	"std" => "On",
	"options" => array("On", "Off")),

array(  "name" => "Image Quality",
	"desc" => "High Quality or Maximum Quality (NOTE: Maximum will give Best Quality with Big file size)",
	"id" => $shortname."_image_quality",
	"type" => "select",
	"std" => "High Quality",
	"options" => array("High Quality", "Maximum Quality")),

array(  "name" => "Gallery thumbnail size",
	"desc" => "Width",
	"id" => $shortname."_width_thumbnail",
	"std" => "30",
	"type" => "text"),

array(  "name" => "",
	"desc" => "Height",
	"id" => $shortname."_height_thumbnail",
	"std" => "30",
	"type" => "text"),

array(  "name" => "Slideshow Button Texts",
	"desc" => "Play",
	"id" => $shortname."_play_button",
	"std" => "Play",
	"type" => "text"),

array(  "name" => "",
	"desc" => "Stop",
	"id" => $shortname."_stop_button",
	"std" => "Stop",
	"type" => "text"),

array(  "name" => "",
	"desc" => "Prev",
	"id" => $shortname."_prev_button",
	"std" => "Prev",
	"type" => "text"),

array(  "name" => "",
	"desc" => "Next",
	"id" => $shortname."_next_button",
	"std" => "Next",
	"type" => "text"),

array(  "name" => "About Page ID",
	"desc" => "Enter About page ID. Usually this is always 2, unless you want another page there",
	"id" => $shortname."_about_id",
	"std" => "2",
	"type" => "text"),

array(  "name" => "Contact Page ID",
	"desc" => "Enter Contact page ID",
	"id" => $shortname."_contact_id",
	"std" => "",
	"type" => "text"),

array(  "name" => "Exclude Categories",
	"desc" => "Exclude Categories From List. Enter ID's (separate by ',') e.g. 2,4,8",
	"id" => $shortname."_exclude_cat",
	"std" => "",
	"type" => "text"),

array(  "name" => "Maximum no. of Photos to display",
	"desc" => "Enter the maximum noumber of photos to display",
	"id" => $shortname."_max_photos",
	"std" => "50",
	"type" => "text"),

array( "type" => "close")
 
);

add_action('admin_menu', 'mytheme_add_admin');



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><?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:200px;" 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 '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_option($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;
 
}
}
?>
 
<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');


?>
