<?php
global $wp_version;

// Get the page number
if ( ! function_exists( 'dmm_get_page_number' ) ) {
  function dmm_get_page_number() {
      if ( get_query_var( 'paged' ) ) {
        print ' | ' . __( 'Page ' , 'desk-mess-mirrored' ) . get_query_var( 'paged' );
      }
    }
}
// end get_page_number

// Start Register Widgets
register_sidebars( 3, array(
                           'description' => '',
                           'before_widget' => '<li id="%1$s" class="widget %2$s">',
                           'after_widget' => "</li>\n",
                           'before_title' => '<h2 class="widgettitle">',
                           'after_title' => "</h2>\n",
                           ) );
// End Register Widgets

// Start Dynamic Copyright
if ( ! function_exists( 'bns_dynamic_copyright' ) ) {
  function bns_dynamic_copyright() {
      /* Get all posts */
      $all_posts = get_posts( 'post_status=publish&order=ASC' );
      /* Get first post */
      $first_post = $all_posts[0];
      /* Get date of first post */
      $first_date = $first_post->post_date_gmt;
      $first_year = substr( $first_date, 0, 4 );
      if ( $first_year == '' ) {
        $first_year = date( Y );
      }

      /* Display common footer copyright notice */
      _e( '<span id="bns-dynamic-copyright">Copyright &copy; ', 'desk-mess-mirrored' );
      /* Display first post year and current year */
      if ( $first_year == date( 'Y' ) ) {
      /* Only display current year if no posts in previous years */
        echo date( 'Y' );
      } else {
        echo $first_year . "-" . date( 'Y' );
      }
      /* Display blog name from 'General Settings' page and link to site home page */
      echo ' <a href="' . home_url( '/' ) . '" title="' . esc_attr( get_bloginfo( 'name', 'display' ) ) . '" rel="home">' . get_bloginfo( 'name', 'display' ) .'</a>  ';
      _e( 'All rights reserved.</span><!-- #bns-dynamic-copyright -->', 'desk-mess-mirrored' );
  }
}
// End Dynamic Copyright

// Start Theme Version
if ( ! function_exists( 'bns_theme_version' ) ) {
  function bns_theme_version () {
      $theme_version = ''; /* Clear variable */
      /* Get details of the theme / child theme */
      $blog_css_url = get_stylesheet_directory() . '/style.css';
      $my_theme_data = get_theme_data( $blog_css_url );
      $parent_blog_css_url = get_template_directory() . '/style.css';
      $parent_theme_data = get_theme_data( $parent_blog_css_url );
      /* Create and append to string to be displayed */
      $theme_version .= '<br /><span id="bns-theme-version">' . $my_theme_data['Name'] . ' v' . $my_theme_data['Version'];
      if ( $blog_css_url != $parent_blog_css_url ) {
        $theme_version .= __( ' a child of the ', 'desk-mess-mirrored' ) . $parent_theme_data['Name'] . ' v' . $parent_theme_data['Version'];
      }
      $theme_version .= __( ' theme from ', 'desk-mess-mirrored') . '<a href="http://buynowshop.com/" title="BuyNowShop.com">BuyNowShop.com</a>.';
      /* Display string */
      echo $theme_version . '</span><!-- #bns-theme-version -->';
    }
}
// End Theme Version

// Tell WordPress to run desk_mess_mirrored_setup() when the 'after_setup_theme' hook is run. */
add_action( 'after_setup_theme', 'desk_mess_mirrored_setup' );

if ( ! function_exists( 'desk_mess_mirrored_setup' ) ):
  function desk_mess_mirrored_setup(){
    
    // This theme uses post thumbnails
    add_theme_support( 'post-thumbnails', array( 'post', 'page' ) );
    
    // Add default posts and comments RSS feed links to head
    add_theme_support( 'automatic-feed-links' );
    
    // Add theme support for editor-style
    add_editor_style();
    
    // This theme allows users to set a custom background
    add_custom_background();
    
    // Add wp_nav_menu() custom menu support
    function dmm_nav_menu() {
      if ( function_exists( 'wp_nav_menu' ) )
        wp_nav_menu( array(
                           'theme_location' => 'top-menu',
                           'fallback_cb' => 'dmm_list_pages'
                           ) );
      else
        dmm_list_pages();      
    }
    
    function dmm_list_pages() {
      if ( is_home() || is_front_page() ) {
        wp_list_pages( 'title_li=' );
      } else { ?>
        <li><a href="<?php echo home_url( '/' ); ?>"><?php _e( 'Home', 'desk-mess-mirrored' ) ?></a></li>
        <?php wp_list_pages( 'title_li=' );
      }
    }
    
    add_action( 'init', 'register_dmm_menu' );
    function register_dmm_menu() {
      register_nav_menu( 'top-menu', __( 'Top Menu' ) );
    }
    // wp_nav_menu() end
    
    // Make theme available for translation
    // Translations can be filed in the /languages/ directory
    load_theme_textdomain( 'desk-mess-mirrored', TEMPLATEPATH . '/languages' );
    $locale = get_locale();
    $locale_file = TEMPLATEPATH . "/languages/$locale.php";
    if ( is_readable( $locale_file ) )
      require_once( $locale_file );
}
endif;

// Start BNS Modified Post - requires WordPress version 3.0 or greater
if ( ! function_exists( 'bns_modified_post' ) ) {
  function bns_modified_post(){
    /* If the post date and the last modified date are different display modified date */
    if ( get_the_date() <> get_the_modified_date() ) {
      echo '<div class="bns-modified-post">'; /* CSS wrapper for modified date details */
      echo 'Last modified by ' . get_the_modified_author() . ' on ' . get_the_modified_date();
      echo '</div><!-- .bns-modified-post -->';
    }
  }
}
// End BNS Modified Post

// Set the content width based on the theme's design and stylesheet, see #main-blog element in style.css
if ( ! isset( $content_width ) ) $content_width = 580;
?>
<?php /* Last Revised Jun 7, 2011 v1.8.5 */ ?>