<?php 

// pppBlog
// ------------------------------
// Based on Simple PHP blog and TFT gallery
// Joerg Tiedemann, jorgen <at> gmx.net
//	
// pppBlog is released under the GNU Public License.
//
	


function read_themes(&$themes){
  $dir = 'themes/';

  //  clearstatcache();
  if ( is_dir($dir) ) {
    $dhandle = opendir($dir);
    if ( $dhandle ) {
      while ($sub_dir = readdir( $dhandle )){
	if ( is_dir( $dir . $sub_dir . '/' ) == true && 
	     $sub_dir != '.' && $sub_dir != '..' ) {
	  $lang_dir = $sub_dir;
	  $lang_name = sb_read_file( $dir . $sub_dir . '/id.txt' );
	  if ( $lang_name ) {
	    $themes[$lang_name] = $sub_dir;
	  }
	}
      }
    }
    closedir( $dhandle );
  }
}

	
	
	function menu_display_links () {
		// Returns the Links menu as HTML.
		//
		// Example:
		// --------
		// Links
		// Home
		// Static
		// [ + link ]
		//
		global $lang_string, $logged_in, $blog_config;
		
		$str = '';
		//$str = '<a href="index.php">' . $lang_string[ 'menu_home' ] . '</a><br />';
		//if ( !empty( $blog_config[ 'blog_email' ] ) ) {
		//	$str = $str . '<a href="contact.php">' . $lang_string[ 'menu_contact' ] . '</a><br />';
		//}
		//$str = $str . '<a href="stats.php">' . $lang_string[ 'menu_stats' ] . '</a><br />';
		
		$str = $str . read_links( $logged_in );
		
		//$str = $str . "<br />" . menu_display_login();
		
		$result = array();
		$result[ 'title' ] = $lang_string[ 'menu_links' ];
		$result[ 'content' ] = $str;
		
		return ( $result );
	}

	function menu_bar_display_links () {
		// Returns the Links menu as HTML.
		//
		// Example:
		// --------
		// Links
		// Home
		// Static
		// [ + link ]
		//
		global $lang_string, $logged_in, $blog_config;
		global $signed_in,$blog_permissions;
		
		$str = '<TD width="20%" class="menu_body"><a href="index.php">' . $lang_string[ 'menu_home' ] . '</a><br /></TD>';
		if ( !empty( $blog_config[ 'blog_email' ] ) ) {
			$str .= '<TD width="20%" class="menu_body"><a href="contact.php">' . $lang_string[ 'menu_contact' ] . '</a><br /></TD>';
		} else {
			$str .= '<TD width="20%" class="menu_body"><a href="#" onclick="return false;" DISABLED>' . $lang_string[ 'menu_contact' ] . '</a><br /></TD>';
		}

		$str .= '<TD width="20%" class="menu_body"><a href="stats.php">' . $lang_string[ 'menu_stats' ] . '</a><br /></TD>';

		if ($signed_in && $blog_permissions['setup']) {
			$str .= '<TD width="20%" class="menu_body"><a href="set_login.php">' . $lang_string[ 'menu_change_login' ] . '</a></TD>';
			$str .= '<TD width="20%" class="menu_body"><a href="logout.php">' . $lang_string[ 'menu_logout' ] . '</a></TD>';
		} else {
			$str .= '<TD width="20%" class="menu_body"><a href="login.php">' . $lang_string[ 'menu_login' ] . '</a></TD>';
			$str .= '<TD width="20%" class="menu_body">&nbsp;</TD>';
		}

		return ( $str );
	}
	
	function menu_display_blognav () {
		// Returns the blog entry navigation calendar as HTML.
		global $month, $year, $day, $lang_string;

		$str = read_menus_calendar( $month, $year, $day );

		$result = array();
		$result[ 'title' ] = $lang_string[ 'menu_archive' ];
		$result[ 'content' ] = $str;
		
		return ( $result );
	}
	
	function menu_display_blognav_tree () {
		// Returns the blog entry navigation menu as HTML.
		//
		// Example:
		// --------
		// 2004
		// May (2)
		//   5/27/04 (2)
		//
		global $month, $year, $day, $lang_string;

		$str = read_menus_tree ( $month, $year, $day );

		$result = array();
		$result[ 'title' ] = $lang_string[ 'menu_archive' ];
		$result[ 'content' ] = $str;
		
		return ( $result );
	}
	
function menu_display_login () {
  // Returns login / logout link as HTML.
  //
  // Example:
  // --------
  // Login
  //
  global $lang_string, $logged_in;
  global $signed_in, $blog_permissions;
  $str = '';

  if ($signed_in && $blog_permissions['setup']) {
    $str .= '<a href="set_login.php">' . $lang_string[ 'menu_change_login' ] . '</a><br />';
    $str .= '<a href="logout.php">' . $lang_string[ 'menu_logout' ] . '</a>';
  }
  elseif ($signed_in === true) {
    $str .= '<a href="logout.php">' . $lang_string[ 'menu_logout' ] . '</a>';
  } else {
    $str .= '<a href="login.php">' . $lang_string[ 'menu_login' ] . '</a>';
  }
  
  return ( $str );
}

	
function menu_display_user () {
  // Returns login / logout link as HTML.
  //
  // Example:
  // --------
  // Menu
  // Add Entry
  // Add Static Page
  // Upload Image
  //
  global $lang_string, $logged_in, $user_colors;
  global $signed_in;
		
  $str = '';
  if ($signed_in === true) {
    global $blog_permissions;
    if ($blog_permissions['add']==1 ){ 
	$str .= '<a href="add.php">' . $lang_string[ 'menu_add' ] . '</a><br />';
	$str .= '<a href="add_static.php">' . $lang_string[ 'menu_add_static' ] . '</a><br />';
    }
    if ($signed_in && $blog_permissions['setup']){
	$str .= '<a href="upload_img.php">' . $lang_string[ 'menu_upload' ] . '</a>';
    }
  }
		
  $result = array();
  $result[ 'title' ] = $lang_string[ 'menu_menu' ];
  $result[ 'content' ] = $str;
		
  return ( $result );
}
	
   function menu_display_categories () {
		// Returns categories HTML.
		//
		// Example:
		// --------
		// Menu
		// Add Entry
		// Add Static Page
		// Upload Image
		//
		global $lang_string;
		global $day, $month, $year, $category;
		
		$base_date = '';
		if ( isset( $day ) ) {
			$base_date .= '?d=' . $day;
		}
		if ( isset( $month ) ) {
			if ( $base_date == '' ) {
				$base_date .= '?';
			} else {
				$base_date .= '&amp;';
			}
			$base_date .= 'm=' . $month;
		}
		if ( isset( $year ) ) {
			if ( $base_date == '' ) {
				$base_date .= '?';
			} else {
				$base_date .= '&amp;';
			}
			$base_date .= 'y=' . $year;
		}
		if ( $base_date == '' ) {
			$base_date .= '?';
		} else {
			$base_date .= '&amp;';
		}
		$base_date .= 'category=';
		
		
		$str = '';
		$catArray = get_category_array();
		if ( count($catArray) > 0) {
			for ( $i = 0; $i < count( $catArray ); $i++ ) {
				$id_number = $catArray[$i][0];
				$name_str = $catArray[$i][1];
				$space_count = $catArray[$i][2];
				for ( $j = 0; $j < $space_count; $j++ ) {
					$str = $str . '&nbsp;';
				}
				if ( $category == $id_number ) {
					$str = $str . $name_str;
				} else {
					$str = $str . "<a href=\"index.php" . $base_date . $id_number . "\">" . $name_str . "</a>";
				}
				if ( $i == count( $catArray ) - 1 ) {
					$str = $str . "\n";
				} else {
					$str = $str . "<br />\n";
				}
			}
		}
		
		$result = array();
		$result[ 'title' ] = $lang_string[ 'menu_categories' ];
		$result[ 'content' ] = $str;
		
		return ( $result );
	}
	
	function menu_display_setup () {
		// Returns login / logout link as HTML.
		//
		// Example:
		// --------
		// Setup
		// Setup
		// Options
		// Colors
		// Themes
		// Change Login
		//
		global $lang_string, $logged_in, $user_colors;
		global $signed_in,$blog_permissions;
		
		$str = '';
		if ($signed_in && $blog_permissions['setup']) {
			$str = $str . '<a href="categories.php">' . $lang_string[ 'menu_categories' ] . '</a><br />';
			$str = $str . '<a href="add_block.php">' . $lang_string[ 'menu_add_block' ] . '</a><br />';
			$str = $str . '<a href="setup.php">' . $lang_string[ 'menu_setup' ] . '</a><br />';
			$str = $str . '<a href="themes.php">' . $lang_string[ 'menu_themes' ] . '</a><br />';
			$str = $str . '<a href="emoticons.php">' . $lang_string[ 'menu_emoticons' ] . '</a><br />';
			$str = $str . '<a href="colors.php">' . $lang_string[ 'menu_colors' ] . '</a><br />';
			$str = $str . '<a href="options.php">' . $lang_string[ 'menu_options' ] . '</a><br />';
			$str = $str . '<a href="info.php">' . $lang_string[ 'menu_info' ] . '</a><br />';
		}
		
		$result = array();
		$result[ 'title' ] = $lang_string[ 'menu_setup' ];
		$result[ 'content' ] = $str;
		
		return ( $result );
	}
	
	function menu_most_recent_comments () {
		global $lang_string;
		
		$str = get_most_recent();
		
		$result = array();
		$result[ 'title' ] = $lang_string[ 'menu_most_recent' ];
		$result[ 'content' ] = $str;
		
		return ( $result );
	}
	
	function menu_most_recent_trackbacks () {
		global $lang_string, $blog_config;
		
		$result = array();
		
		if( $blog_config[ 'blog_trackback_enabled' ] ) {
			$str = get_most_recent_trackback();
			$result[ 'title' ] = $lang_string[ 'menu_most_recent_trackback' ];
			$result[ 'content' ] = $str;
		} else {
   			$result[ 'title' ] = '';
			$result[ 'content' ] = '';
		}
		return ( $result );
	}
	
	function menu_search_field () {
		// Returns the search field text box.
		//
		// Example:
		// --------
		// Search
		// --------- [go]
		//
		global $lang_string;
		
		$str = "<form accept-charset=\"" . $lang_string[ 'html_charset' ] . ",iso-8859-1,utf-8\" method=\"get\" action=\"search.php\">";
		$str = $str . "<input type=\"text\" size=\"14\" name=\"q\" />&nbsp;";
		$str = $str . "<input type=\"submit\" value=\"" . $lang_string[ 'search_go' ] . "\" />";
		$str = $str . "</form>";
		
		$result = array();
		$result[ 'title' ] = $lang_string[ 'search_title' ];
		$result[ 'content' ] = $str;
		
		return ( $result );
	}
	
	function page_generated_in () {
		// Returns "Page Generated x.xxxx in seconds"
		global $lang_string, $page_timestamp;
		
		$str = str_replace ( '%s', round( getmicrotime() - $page_timestamp, 4 ), $lang_string[ 'page_generated_in' ] );

		return ( $str );
	}
	
function menu_most_recent_entries ($max_entries=10) {
  global $lang_string, $blog_config;

  if (!$max_entries){$max_entries=10;}
		
  $entry_file_array = blog_entry_listing();
		
  // Grab the next X number of entries
  $file_array = array();
  //for ( $i = 0; $i < min( $max_entries<<1,count($entry_file_array) ); $i++ ) {
  for ( $i = 0; $i < min( $max_entries , count($entry_file_array) ); $i++ ) {
    array_push( $file_array, $entry_file_array[ $i ] );
  }
		
		// Read entry files
  $contents = array();
  for ( $i = 0; $i < count( $file_array ); $i++ ) {
    list( $entry_filename, $year_dir, $month_dir ) = explode( '|', $file_array[ $i ] );
    array_push( $contents, array( 'path' => ( 'content/' . $year_dir . '/' . $month_dir . '/' . $entry_filename ),
				  'entry' => $entry_filename,
				  'year' => $year_dir,
				  'month' => $month_dir ) );
  }
		
  $str = '';
  if ( $contents ) {
    if ( ( dirname($_SERVER[ 'PHP_SELF' ]) == '\\' || dirname($_SERVER[ 'PHP_SELF' ]) == '/' ) ) {
      // Hosted at root.
      $base_permalink_url = 'http://'.$_SERVER[ 'HTTP_HOST' ].'/';
    } else {
      // Hosted in sub-directory.
      $base_permalink_url = 'http://'.$_SERVER[ 'HTTP_HOST' ].dirname($_SERVER[ 'PHP_SELF' ]).'/';
    }
			
    for ( $i = 0; $i <= count( $contents ) - 1; $i++ ) {
      $blog_entry_data = blog_entry_to_array( $contents[$i][ 'path' ] );
				
      $entry_array = array();
      $entry_array[ 'subject' ] = blog_to_html( $blog_entry_data[ 'SUBJECT' ], false, false );
				
      $entry = sb_strip_extension( $contents[$i][ 'entry' ] );
				
      $entry_array[ 'permalink' ][ 'url' ] = $base_permalink_url . 'index.php?entry=' . $entry;
				
      $str = $str . '<a href="' . $entry_array[ 'permalink' ][ 'url' ] . '">' . $entry_array[ 'subject' ] . '</a><br />';
    }
  }
		
  $result = array();
  $result[ 'title' ] = $lang_string[ 'menu_most_recent_entries' ];
  $result[ 'content' ] = $str;
		
  return ( $result );
}






function blogentry_rdf ( $entry_array ) {
  global $blog_config;
		
    $blog_content = "";
		
    // New 0.3.8
    // You must have this if you are using the trackback feature.
    if ( $blog_config[ "blog_trackback_enabled" ] ) {
	$blog_content .= "<!--\n";
	$blog_content .= '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"' . "\n";
	$blog_content .= '         xmlns:dc="http://purl.org/dc/elements/1.1/"' . "\n";
	$blog_content .= '         xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">' . "\n";
	$blog_content .= '<rdf:Description' . "\n";
	$blog_content .= '    rdf:about="' . $entry_array['permalink']['url'] . '"' . "\n";
	$blog_content .= '    dc:identifier="' . $entry_array['permalink']['url'] . '"' . "\n";
	$blog_content .= '    dc:title="' . $entry_array['subject'] . '"' . "\n";
	$blog_content .= '    trackback:ping="' . $entry_array['trackback']['ping_url'] . '" />' . "\n";
	$blog_content .= '</rdf:RDF>' . "\n";
	$blog_content .= '-->' . "\n";
    }

    return $blog_content;
}

function blogentry_categories( $entry_array ){

  $blog_content = "";
    // Display CATEGORIES
    // This is an array. There can be multiple categories per entry.
    if ( array_key_exists( "categories", $entry_array ) ) {
      $blog_content .= '<div class="blog_categories">';
      for ( $i = 0; $i < count( $entry_array["categories"] ); $i++ ) {
	$blog_content .= $entry_array["categories"][$i];
	if ( $i < count( $entry_array["categories"] ) - 1 ) {
	  $blog_content .= ", ";
	}
      }
      $blog_content .= '</div>';
    }
    return $blog_content;
}


function blogentry_author( $entry_array ){

  global $lang_string;
  $blog_content = "";
    // Display CATEGORIES
    // This is an array. There can be multiple categories per entry.
    if ( array_key_exists( "author", $entry_array ) ) {
      $blog_content .= '<div class="blog_author">';
      $str = str_replace('%s',$entry_array["author"],
			 $lang_string['written_by']);
      $blog_content .= $str;
      if ( array_key_exists( "translator", $entry_array ) ) {
	if ($entry_array["translator"] !== $entry_array["author"]){
	  $str = str_replace('%s',$entry_array["translator"],
			     $lang_string['translated_by']);
	  $blog_content .= ', '.$str;
	}
      }
      $blog_content .= '</div>';
    }
    return $blog_content;
}



function blogentry_buttons( $entry_array ){		
  global $blog_theme;

  // Default image path.
  $img_path = "themes/" . $blog_theme . "/images/";

  $blog_content = "";
    // Display EDIT and DELETE buttons if the user is logged in.
    if (isset($entry_array["logged_in"]) && $entry_array["logged_in"] == true){
      $blog_content .= '<span class="blog_title_buttons">';
			
      // Show "edit" and "delete" buttons if the user is logged-in...
      if ( isset( $entry_array["edit"]["url"] ) ) {
	$blog_content .= '<a href="' . $entry_array["edit"]["url"] . '"><img src="' . $img_path . 'box_right.png" alt="' . $entry_array["edit"]["name"] . '" width="14" height="14" /> </a>';
      }
      if ( isset( $entry_array["delete"]["url"] ) ) {
	$blog_content .= '<a href="' . $entry_array["delete"]["url"] . '"><img src="' . $img_path . 'box_cancel.png" alt="' . $entry_array["delete"]["name"] . '" width="14" height="14" /> </a>';
      }
      $blog_content .= "</span>";
    }
    return $blog_content;
}


function blogentry_permalink( $entry_array,$string ){
  if ( isset( $entry_array['permalink']['url'] ) ) {
    return '<a href="'.$entry_array['permalink']['url'].'">'.$string.'</a>';
  }
  else{
    return $string;
  }
}


function blogentry_comment( $entry_array ){
  if ( isset( $entry_array["comment"]["name"] ) ) {
    global $blog_theme;
    // Default image path.
    $img_path = "themes/" . $blog_theme . "/images/";
    if ( isset( $entry_array["comment"]["url"] ) ) {
      // Show "add comment" button if set...
      return '<a href="' . $entry_array["comment"]["url"] . '"><img src="' . $img_path . 'comment.gif" alt="' . $entry_array["comment"]["name"] . '" align="top" /> ' . $entry_array["comment"]["name"] . ' </a>';
    }
    else{
      return '<img src="' . $img_path . 'comment.gif" alt="' . $entry_array["comment"]["name"] . '" align="top" /> ' . $entry_array["comment"]["name"];
    }
  }
  return "";
}

function blogentry_views( $entry_array ){
  if ( isset( $entry_array["comment"]["count"] ) ) {
    // Show "( x views )" string...
    return " ( " . $entry_array["comment"]["count"] . " )";
  }
  return "";
}


function blogentry_trackback( $entry_array ){
  if ( isset( $entry_array['trackback']['url'] ) ) {
    // Show 'trackback' string...
    return '<a href="' . $entry_array['trackback']['url'] . '">[ ' . $entry_array['trackback']['name'] . ' ]</a>';
  }
  return "";
}


function blogentry_stars( $entry_array ){
  if ( isset( $entry_array['stars'] ) ) {
    // Show 'rating' stars...
    return $entry_array['stars'];
  }
  return "";
}


function blogentry_date( $entry_array ){
  // Display DATE
  return  "<div class=\"blog_date\">" . $entry_array["date"] . "</div>\n";
}


// Function:
// default_blogentry( $entry_array )
//
// Default Theme for Blog Entries
// -------------------------------
// All data is stored the $entry_array associative array and
// passed to the function. Keep in mind that multiple languages
// are used. So, try not to hard-code "english" strings. If
// you are creating graphics for buttons, try to use icons
// instead of words.
//

function default_blogentry ( $entry_array ) {
  global $user_colors, $blog_theme, $blog_config;


  // Display RDF header
  $blog_content = blogentry_rdf( $entry_array );

  $blog_content .= '<div class="blog_entry">' ;

  // Display SUBJECT Line
  $blog_content .= '<div class="blog_title">' ;
  $blog_content .= blogentry_categories( $entry_array );
  $blog_content .= blogentry_permalink( $entry_array,$entry_array["subject"] );
  $blog_content .= blogentry_buttons( $entry_array );		
  $blog_content .= "</div>\n";


  // Display BODY TEXT
  $blog_content .= '<div class="blog_body">';
  $blog_content .= blogentry_author( $entry_array );
  $blog_content .= $entry_array["entry"];
  $blog_content .= "</div>";


  // Display blogentry DATE
  $blog_content .= blogentry_date($entry_array);		


  // Display ADD COMMENT, COUNT, TRACKBACK, and RATING

  $comment_area = blogentry_comment($entry_array);
  $comment_area .= blogentry_views($entry_array);

  $trackback = blogentry_trackback($entry_array);
  if ($trackback != ""){
    if ($comment_area != ""){
      $comment_area .= '&nbsp;&nbsp;|&nbsp;&nbsp;';
    }
    $comment_area .= $trackback;
  }

  $stars = blogentry_stars($entry_array);
  if ($stars != ""){
    if ($comment_area != ""){
      $comment_area .= '&nbsp;&nbsp;|&nbsp;&nbsp;';
    }
    $comment_area .= $stars;
  }

  if ( $comment_area != "" ) {
    $blog_content .= "<div class=\"blog_comment\">".$comment_area."</div>\n";
  }


  $blog_content .= "</div><br />\n";
  return $blog_content;
}







function default_trackbackentry ( $entry_array ) {
    global $blog_config, $blog_theme, $user_colors;

    $img_path = 'themes/' . $blog_theme . '/images/';

    $blog_content = "\n" . '<!-- BLOG ENTRY BEGIN -->' . "\n";

    // SUBJECT
    $blog_content .= '<div class="blog_title">' . $entry_array['title'] . "\n";
		
    if ( isset( $entry_array['logged_in'] ) && $entry_array['logged_in'] == true ) {
	$blog_content .= "\t" . '<span class="blog_title_buttons">' . "\n";

	// Show 'delete' button if the user is logged-in...
	if ( isset( $entry_array['delete']['url'] ) ) {
	    $blog_content .= "\t\t" . '<a href="' . $entry_array['delete']['url'] . '"><img src="' . $img_path . 'box_cancel.png" alt="' . $entry_array['delete']['name'] . '" width="14" height="14" /> </a>' . "\n";
	}
			
	$blog_content .= "\t" . '</span>' . "\n";
    }

    $blog_content .= '</div>' . "\n";
		
    $blog_content .= '<div class="blog_body">' . "\n\t";
    $blog_content .= '<div class="blog_date">' . $entry_array['date'] . '</div>' . "\n\t\t";

    // Blog content body...
    $blog_content .= $entry_array['excerpt'] . "<p>\n";
		
    if ( (isset( $entry_array['blog_name'] ) ) && ($entry_array['blog_name'] != "") ) {
	$blog_content .= '<a href="'.$entry_array["url"].'" target="_blank">[ ' . $entry_array["blog_name"] . " ]</a><p>\n";
    } else {
	$blog_content .= '<a href="'.$entry_array["url"].'" target="_blank">[ ' . $entry_array["url"] . " ]</a><p>\n";
    }
		
    $blog_content .= "\n\t" . '</div>';
    $blog_content .= "<br />";
    $blog_content .= "\n" . '<!-- BLOG ENTRY END -->' . "\n";
		
    return $blog_content;
}



// Function:
// default_pagelayout( )
//
// Page Layout Container/Wrapper
// -----------------------------
// This function controls all HTML output to the browser.
//
// Invoking the page_content() fuction inserts the actual
// contents of the page.
//

function default_pagelayout () {
    global $user_colors, $blog_config, $theme_vars, $blog_theme, 
	$logged_in, $lang_string, $sb_info, $signed_in;
		
    $left_blocks = get_menu_blocks('left');
    $right_blocks = get_menu_blocks('right');
    $top_blocks = get_menu_blocks('top');

?>
<body>
  <div class="page">

      <?php if (count($top_blocks) && 
		function_exists('theme_menu_top')){ ?>

<!-- ........... HEADER MENU ................ -->

        <?php theme_menu_top(); ?>
      <br clear="all" />

      <?php } ?>

<?php   if (!$blog_config['blog_hide_header']){ ?>

    <div class="header">

<?php   if ($blog_config['show_searchbox_in_header'] && 
	    (! $blog_config['blog_hide_header_searchbox'] == 'on')){ ?>
      <div class="search_box">
        <br />
        <?php
        $result = menu_search_field();
        echo( $result["content"] );
        ?>
      </div>
<?php }
      if (!$blog_config['blog_hide_title']){ ?>
      <div class="title">
	<a href="index.php">
        <?php echo($blog_config[ 'blog_title' ]); ?>
        </a>
      </div>
<?php }
      if ($blog_config['show_links_in_header'] && 
	  (! $blog_config['blog_hide_header_links'] == 'on')){
	  echo '<span class="links">';
	  $parts = explode('.',$sb_info[ 'version' ]);
	  if ($parts['1'] > 3){
	    if ($parts['2'] > 3){
	      $newspb = true;
	    }
	  }

	  $links = link_array( $logged_in );
	  for ( $i = 0; $i < count( $links ); $i = $i + 2 ) {
	    if ($i){echo ' / ';}
	    if ( $links[$i+1] == '' ) {
	      echo $links[$i];
	    } else {
	      echo '<a href="' . $links[$i+1] . '">' . $links[$i] . '</a>';
	    }
	  }

	  echo '</span>';
	    }
	  ?>
    </div>

<?php } ?>

    <div class="main">
      <?php if (count($left_blocks) && function_exists('theme_menu_left')){ ?>

<!-- ........... LEFT SIDE MENU ................ -->

      <div class="left">
        <div class="sidebar">

        <?php theme_menu_left(); ?>

        </div>
      </div>

      <?php } ?>
      <?php if (count($right_blocks) && function_exists('theme_menu_right')){ ?>


<!-- ........... RIGHT SIDE MENU ............... -->

      <div class="right">
        <div class="sidebar">

          <?php theme_menu_right(); ?>

        </div>
      </div>

      <?php } ?>

<!-- ........... BLOG ENTRIES START HERE ....... -->

      <div class="centercontent">
	<?php page_content(); ?>
      </div>
    </div>

<!-- ........... FOOTER STARTS HERE ............ -->

    <div class="footer">
     <?php echo($blog_config[ 'blog_footer' ]); ?> - 
     <?php echo( page_generated_in() ); ?>
    </div>
  </div>
<?php 
		// End Page Layout HTML
}




function photo_pagelayout(){
    global $user_colors, $blog_config, $theme_vars, $blog_theme, 
	$logged_in, $lang_string, $sb_info, $signed_in;
		
    $left_blocks = get_menu_blocks('left');
    $right_blocks = get_menu_blocks('right');
    $top_blocks = get_menu_blocks('top');

?>
<body>
  <div class="page">
      <?php if (count($top_blocks) && 
		function_exists('theme_menu_top')){ ?>
        <?php theme_menu_top(); ?>
      <br clear="all" />
      <?php } ?>


      <?php if (count($left_blocks) && function_exists('theme_menu_left')){ ?>
<!-- ........... LEFT SIDE MENU ................ -->
      <div class="left">
        <div class="sidebar">
        <?php theme_menu_left(); ?>
        </div>
      </div>
      <?php } ?>


     <?php if (count($right_blocks) && function_exists('theme_menu_right')){ ?>
<!-- ........... RIGHT SIDE MENU ............... -->
      <div class="right">
        <div class="sidebar">
          <?php theme_menu_right(); ?>
        </div>
      </div>
      <?php } ?>


    <div class="main">
<!-- ........... HEADER MENU ................ -->
<?php   if (!$blog_config['blog_hide_header']){ ?>
    <div class="header">
<?php   if ($blog_config['show_searchbox_in_header'] && 
	    (! $blog_config['blog_hide_header_searchbox'] == 'on')){ ?>
      <div class="search_box">
        <br />
        <?php
        $result = menu_search_field();
        echo( $result["content"] );
        ?>
      </div>
<?php }
      if (!$blog_config['blog_hide_title']){ ?>
      <div class="title">
	<a href="index.php">
        <?php echo($blog_config[ 'blog_title' ]); ?>
        </a>
      </div>
<?php }
      if ($blog_config['show_links_in_header'] && 
	  (! $blog_config['blog_hide_header_links'] == 'on')){
	  echo '<span class="links">';
	  $parts = explode('.',$sb_info[ 'version' ]);
	  if ($parts['1'] > 3){
	    if ($parts['2'] > 3){
	      $newspb = true;
	    }
	  }

	  $links = link_array( $logged_in );
	  for ( $i = 0; $i < count( $links ); $i = $i + 2 ) {
	    if ($i){echo ' / ';}
	    if ( $links[$i+1] == '' ) {
	      echo $links[$i];
	    } else {
	      echo '<a href="' . $links[$i+1] . '">' . $links[$i] . '</a>';
	    }
	  }

	  echo '</span>';
	    }
	  ?>
    </div>

<?php } ?>

<!-- ........... BLOG ENTRIES START HERE ....... -->
      <div class="centercontent">
	<?php page_content(); ?>
      </div>
    </div>
    <br clear="all">
  </div>
<script language="JavaScript">
<!--
setStyleByClass("div","centercontent","height",innerHeight()-165+"px");
//-->
</script>
<?php 
      // End Page Layout HTML
}





 function photo_commententry ( $entry_array ) {
  global $user_colors, $blog_theme, $blog_config;


  // Display RDF header
  $blog_content = blogentry_rdf( $entry_array );

  $blog_content .= '<div class="comment_entry">' ;

  // Display SUBJECT Line
  $blog_content .= '<div class="comment_title">' ;
  $blog_content .= blogentry_categories( $entry_array );
  $blog_content .= blogentry_permalink( $entry_array,$entry_array["subject"] );
  $blog_content .= blogentry_buttons( $entry_array );		
  $blog_content .= "</div>\n";


  // Display BODY TEXT
  $blog_content .= '<div class="comment_body">';
  $blog_content .= $entry_array["entry"];
  $blog_content .= "</div>";


  // Display blogentry DATE
  $blog_content .= blogentry_author( $entry_array );
  $blog_content .= blogentry_date($entry_array);


  // Display ADD COMMENT, COUNT, TRACKBACK, and RATING

  $comment_area = blogentry_comment($entry_array);
  $comment_area .= blogentry_views($entry_array);

  $trackback = blogentry_trackback($entry_array);
  if ($trackback != ""){
    if ($comment_area != ""){
      $comment_area .= '&nbsp;&nbsp;|&nbsp;&nbsp;';
    }
    $comment_area .= $trackback;
  }

  $stars = blogentry_stars($entry_array);
  if ($stars != ""){
    if ($comment_area != ""){
      $comment_area .= '&nbsp;&nbsp;|&nbsp;&nbsp;';
    }
    $comment_area .= $stars;
  }

  if ( $comment_area != "" ) {
    $blog_content .= "<div class=\"blog_comment\">".$comment_area."</div>\n";
  }


  $blog_content .= "</div><br />\n";
  return $blog_content;
}



 function photo_blogentry ( $entry_array ) {
  global $user_colors, $blog_theme, $blog_config;


  // Display RDF header
  $blog_content = blogentry_rdf( $entry_array );

  $blog_content .= '<div class="blog_entry">' ;

  // Display SUBJECT Line
  $blog_content .= '<div class="blog_title">' ;
  $blog_content .= blogentry_categories( $entry_array );
  $blog_content .= blogentry_permalink( $entry_array,$entry_array["subject"] );
  $blog_content .= blogentry_buttons( $entry_array );		
  $blog_content .= "</div>\n";


  // Display BODY TEXT
  $blog_content .= '<div class="blog_body">';
  $blog_content .= $entry_array["entry"];
  $blog_content .= "</div>";


  // Display blogentry DATE
  $blog_content .= blogentry_author( $entry_array );
  $blog_content .= blogentry_date($entry_array);


  // Display ADD COMMENT, COUNT, TRACKBACK, and RATING

  $comment_area = blogentry_comment($entry_array);
  $comment_area .= blogentry_views($entry_array);

  $trackback = blogentry_trackback($entry_array);
  if ($trackback != ""){
    if ($comment_area != ""){
      $comment_area .= '&nbsp;&nbsp;|&nbsp;&nbsp;';
    }
    $comment_area .= $trackback;
  }

  $stars = blogentry_stars($entry_array);
  if ($stars != ""){
    if ($comment_area != ""){
      $comment_area .= '&nbsp;&nbsp;|&nbsp;&nbsp;';
    }
    $comment_area .= $stars;
  }

  if ( $comment_area != "" ) {
    $blog_content .= "<div class=\"blog_comment\">".$comment_area."</div>\n";
  }


  $blog_content .= "</div><br />\n";
  return $blog_content;
}




// Function:
// theme_popuplayout( )
//
// Popup Layout Container/Wrapper
// -----------------------------
// This function controls all HTML output to the browser.
//
// Same as above, but for the pop-up comment window and 
// the image list pop-up.
//

function default_popuplayout () {
    global $user_colors, $blog_config, $theme_vars;
		
    // New 0.3.8
    //
    // You can change the width of the CONTENT area by editing
    // this variable in the "theme_init()" function at the top of
    // this file.
    $popup_width = $theme_vars['popup_window']['content_width']; 
		
    // Begin Popup Layout HTML
?>
<body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0">
<br />
<table border="0" width="<?php echo( $popup_width ); ?>" cellspacing="0" cellpadding="0" align="center" style="border: 1px solid #<?php echo( $user_colors['border_color'] ); ?>; border-top: 8px solid #<?php echo( $user_colors['border_color'] ); ?>;">
  <tr align="left" valign="top">
    <td width="<?php echo( $popup_width ); ?>" bgcolor="#<?php echo( $user_colors['header_bg_color'] ); ?>">
      <div class="header">
	<?php echo($blog_config[ 'blog_title' ]); ?><br />
      </div>
    </td>
  </tr>
  <tr align="left" valign="top">
    <td width="<?php echo( $popup_width ); ?>" bgcolor="#<?php echo( $user_colors['main_bg_color'] ); ?>">
      <div class="main">
	<?php page_content(); ?>
      </div>
    </td>
  </tr>
  <tr align="left" valign="top">
    <td width="<?php echo( $popup_width ); ?>">
      <div class="footer"><?php echo($blog_config[ 'blog_footer' ]); ?> - <?php echo( page_generated_in() ); ?></div>
    </td>
  </tr>
</table>
<br />
<?php 
		// End Popup Layout HTML
}



?>
