<?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 add_menu_block_form($side='left'){
  //echo("<div class=\"menu_block\">");
  //echo( "<div class=\"menu_body\">\n" );
  echo('<div align="center">');
  echo('<form name="formBlock" id="formBlock" method="get" action="">');
  if ($side == 'top'){
    echo('  <select name="addtblock" onChange="submit();">');
  }
  elseif ($side == 'right'){
    echo('  <select name="addrblock" onChange="submit();">');
  }
  else{
    echo('  <select name="addlblock" onChange="submit();">');
  }
  echo('    <option>-- Add a block --</option>');
  $blocks = available_menu_blocks();
  foreach ($blocks as $block){
    $name = str_replace('_menu_block','',$block);
    echo('<option label="'.$block.'" value="'.$block.'"');
    echo('>'.$name.'</option>');
  }
  echo('  </select>');
  echo('</form>');
  echo '</div>';
  //echo( "</div></div><br />\n" );
}





function get_menu_blocks($side='left'){
  $file = 'config/'.$side.'blocks.txt';
  if (file_exists($file)){
    $blocks = file($file);
    $blocks = array_map('rtrim',$blocks);
    return $blocks;
  }
  return default_menu_blocks($side);
}

function get_right_menu_blocks(){return get_menu_blocks('right');}
function get_left_menu_blocks(){return get_menu_blocks('left');}


function default_menu_blocks($side=''){
  if ($side == 'left'){
    $blocks = array('calendar_menu_block',
		    'menu_menu_block',
		    'setup_menu_block',
		    'upcoming_menu_block',
		    'themes_menu_block');
    for ($i=1;$i<=nr_user_blocks();$i++){
      $blocks[] = 'user_menu_block:'.$i;
    }
    $blocks[] = 'trackback_menu_block';
  }
  elseif($side == 'right'){
    $blocks = array('categories_menu_block',
		    'album_menu_block',
		    'recent_entries_menu_block',
		    'recent_comments_menu_block',
		    'web_gadget_menu_block');
  }
  elseif($side == 'top'){
    $blocks = array('image_menu_block');
  }
  else{
    $blocks = array('links_login_menu_block',
		    'menu_menu_block',
		    'setup_menu_block');
    for ($i=1;$i<=nr_user_blocks();$i++){
      $blocks[] = 'user_menu_block:'.$i;
    }
    $block[] = 'calendar_menu_block';
    $block[] = 'categories_menu_block';
    $block[] = 'search_menu_block';
    $block[] = 'recent_entries_menu_block';
    $block[] = 'recent_comments_menu_block';
    $block[] = 'trackback_menu_block';
    $block[] = 'web_gadget_menu_block';
  }
  return $blocks;
}


function save_menu_blocks($blocks,$side='left'){
  $file = 'config/'.$side.'blocks.txt';
  if (is_array($blocks)){
    if ($fh = fopen($file,'w')){
      foreach ($blocks as $block){
	fwrite($fh,$block."\n");
      }
      fclose($fh);
    }
  }
}





function set_menublock_params($side,$pos,$params){

  if (!is_array($params)){return false;}

  $file = 'config/'.$side.'blocks.txt';
/*
  $fct = 'get_'.$side.'_menu_blocks';
  if (!function_exists($fct)){return false;}
  $blocks = $fct();
*/
  $blocks = get_menu_blocks($side);

  if ($fh = @fopen($file,'w+')){
    @flock( $fh, LOCK_EX );

    if (is_array($blocks)){
      if (isset($blocks[$pos-1])){
	list($fct,$par)=explode('|',$blocks[$pos-1]);
	$blocks[$pos-1]=$fct.'|'.implode('|',$params);
      }
    }

    foreach ($blocks as $block){
      @fwrite($fh,$block."\n");
    }
    $lock = @flock( $fh, LOCK_UN );
    @fclose($fh);
  }
  return true;

}



function nr_user_blocks(){

  $array = read_blocks ( false );
  if (count($array)){
    return floor((count($array)+1)/2);
  }
  return 0;
}


function remove_user_block($idx){
  $blocks = get_menu_blocks('left');
  for ($i=0;$i<count($blocks);$i++){
    list($fct,$pos)=explode(':',$blocks[$i]);
    if ($fct == 'user_menu_block'){
      if ($pos == $idx){
	array_splice($blocks,$i,1);
	$i--;
      }
      elseif ($pos>$idx){
	$pos=$pos-1;
	$blocks[$i]='user_menu_block:'.$pos;
      }
    }
  }
  save_menu_blocks($blocks,'left');

  $blocks = get_menu_blocks('right');
  for ($i=0;$i<count($blocks);$i++){
    list($fct,$pos)=explode(':',$blocks[$i]);
    if ($fct == 'user_menu_block'){
      if ($pos == $idx){
	array_splice($blocks,$i,1);
	$i--;
      }
      elseif ($pos>$idx){
	$pos=$pos-1;
	$blocks[$i]='user_menu_block:'.$pos;
      }
    }
  }
  save_menu_blocks($blocks,'right');
}

function available_menu_blocks(){
  $blocks = array('logo_menu_block',
		  'welcome_menu_block',
		  'calendar_menu_block',
		  'photo_calendar_menu_block',
		  'archive_menu_block',
		  'categories_menu_block',
		  'menu_menu_block',
		  'setup_menu_block',
		  'links_menu_block',
		  'login_menu_block',
		  'links_login_menu_block',
		  'search_menu_block',
		  'upcoming_menu_block',
		  'themes_menu_block',
		  'language_menu_block',
  //		  'user_menu_blocks',
		  'trackback_menu_block',
		  'album_menu_block',
		  'recent_entries_menu_block',
		  'recent_comments_menu_block',
		  'web_gadget_menu_block',
		  'rssfeed_menu_block',
		  'poll_menu_block',
		  'image_menu_block',
		  'exif_menu_block');
  for ($i=1;$i<=nr_user_blocks();$i++){
    $blocks[] = 'user_menu_block:'.$i;
  }
  sort($blocks);
  return $blocks;
}



function menu_blocks($side='left'){
  global $signed_in,$blog_permissions;
  if ($signed_in && $blog_permissions['setup']){
    add_menu_block_form($side);
  }
  $blocks = get_menu_blocks($side);
  if (is_array($blocks)){
    $pos=0;
    $nr_blocks = count($blocks);

    foreach ($blocks as $block){
	$arr=explode('|',$block);
	$block=array_shift($arr);
      $pos++;
      if (function_exists($block)){
	$links = block_admin_links($pos,$side,$nr_blocks,$block);
	$block($links,$side,$pos,$arr);
      }
      else{
	list($fct,$idx)=explode(':',$block);
	if ($fct == 'user_menu_block'){
	  $links = block_admin_links($pos,$side,$nr_blocks,$block);
	  user_menu_block($idx,$links,$side,$pos,$arr);
	}
      }
    }
  }
}

function left_menu_blocks(){return menu_blocks('left');}
function right_menu_blocks(){return menu_blocks('right');}



function top_menu_blocks(){
  global $signed_in,$blog_permissions;
  if ($signed_in && $blog_permissions['setup']){
    add_menu_block_form('top');
  }
  $blocks = get_menu_blocks('top');
  if (is_array($blocks)){
    $pos=0;
    $nr_blocks = count($blocks);

    foreach ($blocks as $block){
	$arr=explode('|',$block);
	$block=array_shift($arr);
      $pos++;
      echo '<div class="left">';
      if (function_exists($block)){
	$links = block_admin_links($pos,'top',$nr_blocks,$block);
	$block($links,'top',$pos,$arr);
      }
      else{
	list($fct,$idx)=explode(':',$block);
	if ($fct == 'user_menu_block'){
	  $links = block_admin_links($pos,'top',$nr_blocks,$block);
	  user_menu_block($idx,$links,'top',$pos,$arr);
	}
      }
      echo '</div>';
    }
  }
}





function block_admin_links($pos,$side,$nr_blocks,$block){

  $name = str_replace('_menu_block','',$block);
  $links = '';

  global $signed_in,$blog_permissions;
  if ($signed_in && $blog_permissions['setup']){
    // $links .= '<div align="center">';
    if ($side!='top' || $pos>1){
      $links.='<a href="?action=up&amp;block='.$pos.'&amp;side='.$side.'">';
      if ($side=='top'){$links .= '&larr;</a> ';}
      else{$links .= '&uarr;</a> ';}
    }
    if ($pos<$nr_blocks){
      $links.= '<a href="?action=down&amp;block='.$pos.'&amp;side='.$side.'">';
      if ($side=='top'){$links .= '&rarr;</a> ';}
      else{$links.= '&darr;</a> ';}
    }
    if ($side=='left'){
      $links.='<a href="?action=right&amp;block='.$pos.'&amp;side='.$side.'">';
      $links.='&rarr;</a> ';
    }
    if ($side=='right'){
      $links.='<a href="?action=left&amp;block='.$pos.'&amp;side='.$side.'">';
      $links.='&larr;</a> ';
    }
    $links.='<a href="?action=disable&amp;block='.$pos.'&amp;side='.$side.'">';
    // $links .= '&otimes;</a> ('.$name.')<br>';
    $links .= '&times;</a>';
  }
  return $links;
}

function block_admin(){
  global $signed_in,$blog_permissions;
  if ($signed_in && $blog_permissions['setup']){
    if (isset($_REQUEST['addlblock'])){
      $newblock=$_REQUEST['addlblock'];
      $blocks = get_menu_blocks('left');
      array_unshift($blocks,$newblock);
      save_menu_blocks($blocks,'left');
    }
    if (isset($_REQUEST['addrblock'])){
      $newblock=$_REQUEST['addrblock'];
      $blocks = get_menu_blocks('right');
      array_unshift($blocks,$newblock);
      save_menu_blocks($blocks,'right');
    }
    if (isset($_REQUEST['addtblock'])){
      $newblock=$_REQUEST['addtblock'];
      $blocks = get_menu_blocks('top');
      array_unshift($blocks,$newblock);
      save_menu_blocks($blocks,'top');
    }
    if (isset($_REQUEST['block'])){
      if (isset($_REQUEST['action'])){
	if (isset($_REQUEST['side'])){
	  $pos=$_REQUEST['block'];
	  $act=$_REQUEST['action'];
	  $side=$_REQUEST['side'];
	  $blocks = get_menu_blocks($side);
	  if (!is_array($blocks)){return false;}
	  if (isset($blocks[$pos-1])){
	    if ($act == 'up' && $pos>1){
	      $tmp=$blocks[$pos-2];
	      $blocks[$pos-2]=$blocks[$pos-1];
	      $blocks[$pos-1]=$tmp;
	    }
	    elseif ($act == 'up' && $pos==1 && $side!='top'){
	      $blocks2 = get_menu_blocks('top');
	      $blocks2[] = $blocks[$pos-1];
	      save_menu_blocks($blocks2,'top');
	      array_splice($blocks,$pos-1,1);
	    }
	    elseif ($act == 'down' && $pos<count($blocks)){
	      $tmp=$blocks[$pos];
	      $blocks[$pos]=$blocks[$pos-1];
	      $blocks[$pos-1]=$tmp;
	    }
	    elseif ($act == 'disable'){
	      array_splice($blocks,$pos-1,1);
	    }
	    elseif ($act == 'left' && $side == 'right'){
	      $blocks2 = get_menu_blocks('left');
	      $blocks2[] = $blocks[$pos-1];
	      save_menu_blocks($blocks2,'left');
	      array_splice($blocks,$pos-1,1);
	    }
	    elseif ($act == 'right' && $side == 'left'){
	      $blocks2 = get_menu_blocks('right');
	      $blocks2[] = $blocks[$pos-1];
	      save_menu_blocks($blocks2,'right');
	      array_splice($blocks,$pos-1,1);
	    }
	    
	    if ($side == 'left'){
	      save_menu_blocks($blocks,'left');
	    }
	    if ($side == 'right'){
	      save_menu_blocks($blocks,'right');
	    }
	    if ($side == 'top'){
	      save_menu_blocks($blocks,'top');
	    }
	  }
	}
      }
    }
  }
}


/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////


function rssfeed_menu_block($links,$side,$pos,$params){
    global $lang_string;
    global $logged_in,$signed_in,$blog_permissions;


  $src = 'http://jorg.jo.funpic.org/pppblog/rss.php';
  $chan = 'y';    // view channel name
  $desc = 50;    // number of characters to display (text)
  $date = 'y';    // display date (yes/no)
  $num  = 5;      // number of entries to show
  if (is_array($params)){
    if (isset($params[0])){
      $src = $params[0];
    }
    if (isset($params[1])){
      $chan = $params[1];
    }
    if (isset($params[2])){
      $desc = $params[2];
    }
    if (isset($params[3])){
      $date = $params[3];
    }
    if (isset($params[4])){
      $num = $params[4];
    }
  }

  echo('<div class="menu_'.$side.'">');
  echo("<div class=\"menu_block\">");
  if ($links != ''){
    echo('<div class="right">');

    // this block has a setup function -> display a link to activate it
    if ($_REQUEST['blocksetup'] != $side.$pos){
      echo '<a href="?blocksetup='.$side.$pos.'">setup</a> ';
    }
    echo ($links.'</div>');
  }
  echo( "<div class=\"menu_body\">\n" );

  if ($signed_in && $blog_permissions['setup']){
    // display a form for setup
    if ($_POST['setupblock'] == 'submit'){
      if ($_POST['blockside'].$_POST['blockpos'] == $side.$pos){
	$params=array($_POST['src'],
		      $_POST['chan'],
		      $_POST['desc'],
		      $_POST['date'],
		      $_POST['num']);
	if (set_menublock_params($side,$pos,$params)){
	  $src = $params[0];
	  $chan = $params[1];
	  $desc = $params[2];
	  $date = $params[3];
	  $num = $params[4];
	}
      }
    }
    if ($_REQUEST['blocksetup'] == $side.$pos){
      echo('<form name="setupblock" method="post" action="'.$_SERVER['PHP_SELF'].'">');
      echo('<input name="blockside" value="'.$side.'" type="hidden" />');
      echo('<input name="blockpos" value="'.$pos.'" type="hidden" />');
      echo('source URL<br /><input name="src" value="'.$src.'" size="20" type="text" /><br />');
      echo('show max <input name="num" value="'.$num.'" size="2" type="text" /> entries<br />');
      echo('show max <input name="desc" value="'.$desc.'" size="2" type="text" /> characters<br />');
      echo('<input name="chan" value="y" type="checkbox"');
      if ($chan == 'y'){echo 'checked="checked"';}
      echo('/> show channel<br />');
      echo('<input name="date" value="y" type="checkbox"');
      if ($date == 'y'){echo 'checked="checked"';}
      echo('/> show dates<br />');
      echo('<br /><input type="submit" name="setupblock" value="submit" />');
      echo('</form>');
    }
  }

  // feed2php uses local variables src, chan, desc, num, date
  // and makes the php string saved in variable $str
  require('scripts/feed2php.inc');
  echo $str;

  //  echo( "</div></div><br />\n" );
  echo( "</div></div></div>\n" );
}




function logo_menu_block($links,$side,$pos,$params){
  // display logo
  global $blog_theme,$signed_in, $blog_permissions;

  $logo = "themes/" . $blog_theme . "/images/logo.gif";
  if (is_array($params)){
    if (isset($params[0])){
      $logo = $params[0];
    }
  }

  if (file_exists($logo) || ($links != '')){
    echo( "<div class=\"menu_logo\">\n" );

    if ($links != ''){
      echo('<div class="menu_block"><div class="right">');

      // this block has a setup function -> display a link to activate it
      if ($_REQUEST['blocksetup'] != $side.$pos){
	echo '<a href="?blocksetup='.$side.$pos.'">setup</a> ';
      }
      echo ($links.'</div></div>');
    }

    if ($signed_in && $blog_permissions['setup']){
      // display a form for setup
      if ($_POST['setupblock'] == 'submit'){
	if ($_POST['blockside'].$_POST['blockpos'] == $side.$pos){
	  $params=array($_POST['logo']);
	  if (set_menublock_params($side,$pos,$params)){
	    $logo = $params[0];
	  }
	}
      }
      if ($_REQUEST['blocksetup'] == $side.$pos){
	echo('<div align="left">');
	echo('<form name="setupblock" method="post" action="'.$_SERVER['PHP_SELF'].'">');
	echo('<input name="blockside" value="'.$side.'" type="hidden" />');
	echo('<input name="blockpos" value="'.$pos.'" type="hidden" />');
	echo('image URL<br /><input name="logo" value="'.$logo.'" size="20" type="text" /><br />');
	echo('<br /><input type="submit" name="setupblock" value="submit" />');
	echo('</form>');
	echo('</div>');
      }
    }

    if (file_exists($logo)){
	echo ("<img src=\"$logo\" alt=\"logo\">");
    }
    //    echo( "</div><br />\n" );
    echo( "</div>\n" );
  }
}





function image_menu_block($links,$side,$pos,$params){
  // display logo
  global $blog_theme,$signed_in, $blog_permissions;

  $logo = "themes/" . $blog_theme . "/images/header.jpg";
  if (is_array($params)){
    if (isset($params[0])){
      $logo = $params[0];
    }
  }

  if (file_exists($logo) || ($links != '')){

    if ($links != ''){
      echo('<div class="menu_block"><div class="right">');

      // this block has a setup function -> display a link to activate it
      if ($_REQUEST['blocksetup'] != $side.$pos){
	echo '<a href="?blocksetup='.$side.$pos.'">setup</a> ';
      }
      echo ($links.'</div></div>');
    }

    if ($signed_in && $blog_permissions['setup']){
      // display a form for setup
      if ($_POST['setupblock'] == 'submit'){
	if ($_POST['blockside'].$_POST['blockpos'] == $side.$pos){
	  $params=array($_POST['logo']);
	  if (set_menublock_params($side,$pos,$params)){
	    $logo = $params[0];
	  }
	}
      }
      if ($_REQUEST['blocksetup'] == $side.$pos){
	echo('<div align="left">');
	echo('<form name="setupblock" method="post" action="'.$_SERVER['PHP_SELF'].'">');
	echo('<input name="blockside" value="'.$side.'" type="hidden" />');
	echo('<input name="blockpos" value="'.$pos.'" type="hidden" />');
	echo('image URL<br /><input name="logo" value="'.$logo.'" size="20" type="text" /><br />');
	echo('<br /><input type="submit" name="setupblock" value="submit" />');
	echo('</form>');
	echo('</div>');
      }
    }

    if (file_exists($logo)){
	echo ("<img src=\"$logo\" alt=\"logo\">");
    }
  }
}





function welcome_menu_block($links,$side,$pos,$params){
  global $blog_theme,$signed_in, $blog_permissions;

  $welcometext = 'Welcome <b>%s</b>!';
  if (is_array($params)){
    if (isset($params[0])){
      $welcometext = $params[0];
    }
  }

  if ($signed_in){
      echo( "<div class=\"menu_logo\">\n" );

      if ($links != ''){
	  echo('<div class="menu_block"><div class="right">');

	  // this block has a setup function -> display a link to activate it
	  if ($_REQUEST['blocksetup'] != $side.$pos){
	      echo '<a href="?blocksetup='.$side.$pos.'">setup</a> ';
	  }
	  echo ($links.'</div></div>');
      }

      if ($signed_in && $blog_permissions['setup']){
	  // display a form for setup
	  if ($_POST['setupblock'] == 'submit'){
	      if ($_POST['blockside'].$_POST['blockpos'] == $side.$pos){
		  $params=array($_POST['welcometext']);
		  if (set_menublock_params($side,$pos,$params)){
		      $welcometext = $params[0];
		  }
	      }
	  }
	  if ($_REQUEST['blocksetup'] == $side.$pos){
	      echo('<div align="left">');
	      echo('<form name="setupblock" method="post" action="'.$_SERVER['PHP_SELF'].'">');
	      echo('<input name="blockside" value="'.$side.'" type="hidden" />');
	      echo('<input name="blockpos" value="'.$pos.'" type="hidden" />');
	      echo('image URL<br /><input name="welcometext" value="'.$welcometext.'" size="20" type="text" /><br />');
	      echo('<br /><input type="submit" name="setupblock" value="submit" />');
	      echo('</form>');
	      echo('</div>');
	  }
      }

      $welcometext = str_replace('%s',$_SESSION['user'],$welcometext);
      echo $welcometext;
      echo( "</div><br />\n" );
  }
}





function poll_menu_block($links,$side,$pos,$params){
  // display logo
  global $blog_theme,$logged_in;
  global $signed_in,$blog_permissions;
  global $lang_string;
  require_once('scripts/sb_polls.php');

  if (isset($_POST['vote'])){
    add_vote($_POST['poll_answer']);
  }
  if ($signed_in && $blog_permissions['setup']){
    if (isset($_POST['setup_poll'])){
      $question = $_POST['poll_question'];
      $nr=1;
      $answers=array();
      while (isset($_POST['poll_answer'.$nr])){
	if ($_POST['poll_answer'.$nr] != ''){
	  array_push($answers,$_POST['poll_answer'.$nr]);
	}
	$nr++;
      }
      create_poll($question,$answers);
    }
  }


  if (poll_result($poll) || $logged_in){
    echo('<div class="menu_'.$side.'">');
    echo("<div class=\"menu_block\">");
    echo("<div class=\"menu_title\">");
    if ($links != ''){
      echo('<div class="right">');
      // this block has a setup function -> display a link to activate it
      if ($_REQUEST['blocksetup'] != $side.$pos){
	  echo '<a href="?blocksetup='.$side.$pos.'">setup</a> ';
      }
      echo($links.'</div>');
    }

    if (is_array($poll)){
	echo '<a href="polls.php">';
	echo array_shift($poll);
	echo '</a>';
    }

    echo( "</div><div class=\"menu_body\">\n" );

    if ($signed_in && $blog_permissions['setup']){
	if ($_REQUEST['blocksetup'] == $side.$pos){
	    echo '<br />'.$lang_string['create_poll'].'<br /><br />';
	    echo('<form name="setuppoll" method="post" action="'.$_SERVER['PHP_SELF'].'">');
	    echo('Question :<input name="poll_question" size="10" type="text" /><br/>');
	    echo('Answer 1:<input name="poll_answer1" size="10" type="text"/><br />');
	    echo('Answer 2:<input name="poll_answer2" size="10" type="text"/><br />');
	    echo('Answer 3:<input name="poll_answer3" size="10" type="text"/><br />');
	    echo('Answer 4:<input name="poll_answer4" size="10" type="text"/><br />');
	    echo('Answer 5:<input name="poll_answer5" size="10" type="text"/><br />');
	    echo('<br /><input type="submit" name="setup_poll" value="create" />');
	    echo('</form>');
	}
    }

    if (is_array($poll)){
      $nr_votes=rtrim(array_shift($poll));
      echo('<form name="vote" method="post" action="'.$_SERVER['PHP_SELF'].'">');

      for ($i=0;$i<count($poll);$i++){
	$a = $poll[$i];
	echo '<input type="radio" name="poll_answer" value='.$i.' />';
	echo $a.'<br />';
      }
      echo '<br />'.$lang_string['number_of_votes'].$nr_votes;
      echo('<br /><br /><input type="submit" name="vote" value="vote" />');
      echo '</form>';
    }
    //    echo( "</div></div><br />");
    echo( "</div></div></div>");
  }
}





function calendar_menu_block($links,$side){
  global $logged_in;
  global $signed_in, $blog_permissions;

  // show calendar to add events if logged_in
  // (and the event scripts exist)

  if ($signed_in && $blog_permissions['add'] && file_exists('scripts/sb_events.php')){
    if (!function_exists('menu_display_blognav_events')){
      include_once ('scripts/sb_events.php');
    }
    $result = menu_display_blognav_events();
    echo('<div class="menu_'.$side.'">');
    echo("<div class=\"menu_block\">");
    if ($links != ''){
      echo("<div class=\"menu_title\">");
      echo('<div class="right">'.$links.'</div></div>');
    }
    echo( "<div class=\"menu_body\">\n" );
    echo( $result["content"] . "\n" );
    // echo( "</div></div><br />\n" );
    echo( "</div></div></div>\n" );
  }
  else{

    // Retained from 0.3.7c
    //
    // However, this function now displays a calendar
    // rather then the "tree view"....
    $result = menu_display_blognav();
    echo('<div class="menu_'.$side.'">');
    echo("<div class=\"menu_block\">");
    if ($links != ''){
      echo("<div class=\"menu_title\">");
      echo('<div class="right">'.$links.'</div></div>');
    }
    //echo("<div class=\"menu_title\">");
    //echo($result["title"] . "</div>\n" );
    echo( "<div class=\"menu_body\">\n" );
    echo( $result["content"] . "\n" );
    // echo( "</div></div><br />\n" );
    echo( "</div></div></div>\n" );
  }
}


//function photo_calendar_menu_block($links){
function photo_calendar_menu_block($links,$side,$pos,$params){
  global $lang_string;
  global $logged_in,$signed_in,$blog_permissions;

  if (isset($_REQUEST['y'])){
    $year = $_REQUEST['y'];
  }
  if (isset($_REQUEST['m'])){
    $month = $_REQUEST['m'];
  }
  elseif (isset($_REQUEST['album'])){
    list($yy,$mm) = explode('/',$_REQUEST['album']);
    if (strlen($yy)==4){
      if (is_numeric($yy)){
	if ($yy>1900 && $yy<3000){
	  $year=substr($yy,3,2);
	}
      }
    }
    if (strlen($mm)==2){
      if (is_numeric($mm)){
	if ($mm>0 && $mm<13){
	  $month=$mm;
	}
      }
    }
  }

  if (!isset($month)){
    $month = date( 'm' );
  }
  if (!isset($year)){
    $year = date( 'y' );
  }

  if (isset($_REQUEST['d'])){
    $day = $_REQUEST['d'];
  }

  $before = $params[0];
  $after = $params[1];
  $hide_title = $params[2];
  $reverse = true;


  if ($signed_in && $blog_permissions['setup']){
    // display a form for setup
    if ($_POST['setupblock'] == 'submit'){
      if ($_POST['blockside'].$_POST['blockpos'] == $side.$pos){
	$params=array($_POST['before'],$_POST['after'],$_POST['hidetitle']);
	if (set_menublock_params($side,$pos,$params)){
	  $before = $params[0];
	  $after = $params[1];
	  $hide_title = $params[2];
	}
      }
    }
  }

  echo('<div class="menu_'.$side.'">');
  echo("<div class=\"menu_block\">");
  if ($links != '' || !$hide_title){
    echo("<div class=\"menu_title\">");
  }
  if ($links != ''){
    echo('<div class="right">');
    // this block has a setup function -> display a link to activate it
    if ($_REQUEST['blocksetup'] != $side.$pos){
      echo '<a href="?blocksetup='.$side.$pos.'">setup</a> ';
    }
    echo($links.'</div>');
  }
  if (!$hide_title){
    echo($lang_string['menu_photo_archive']);
  }
  if ($links != '' || !$hide_title){
    echo("</div>\n" );
  }

  echo( "<div class=\"menu_body\">\n" );


  if ($signed_in && $blog_permissions['setup']){
    if ($_REQUEST['blocksetup'] == $side.$pos){
      echo('<form name="setupblock" method="post" action="'.$_SERVER['PHP_SELF'].'">');
      echo('<input name="blockside" value="'.$side.'" type="hidden" />');
      echo('<input name="blockpos" value="'.$pos.'" type="hidden" />');
      echo('month before <input name="before" value="'.$params[0].'" size="3" type="text" /><br />');
      echo('month after <input name="after" value="'.$params[1].'" size="3" type="text" /><br />');
      echo('<input name="hidetitle" value="y" type="checkbox"');
      if ($hide_title == 'y'){echo 'checked="checked"';}
      echo('/> hide title<br />');
      echo('<br /><br /><input type="submit" name="setupblock" value="submit" />');
      echo('</form>');
    }
  }

  if ($reverse){
    for ($i=$month+$after;$i>=$month-$before;$i--){
      if ($i<$month+$after){ echo '<br />'; }
      $m=$i;
      $y=$year;
      while ($m<1){$m+=12;$y--;}
      while ($m>12){$m-=12;$y++;}
      if ($m<10){$m='0'.$m;}
      echo photo_calendar($m,$y,$day,false,$m==$month);
    }
  }
  else{
    for ($i=$month-$before;$i<=$month+$after;$i++){
      if ($i>$month-$before){ echo '<br />'; }
      $m=$i;
      $y=$year;
      while ($m<1){$m+=12;$y--;}
      while ($m>12){$m-=12;$y++;}
      if ($m<10){$m='0'.$m;}
      echo photo_calendar($m,$y,$day,false,$m==$month);
    }
  }
  echo( "</div></div></div>\n" );
}



function exif_menu_block($links,$side){

  if ((isset($_REQUEST['album']) && isset($_REQUEST['pic']) && 
       ereg("(\.jpg|\.JPG)$",$_REQUEST['pic'])) || $links!=''){
    global $lang_string;
    echo('<div class="menu_'.$side.'">');
    echo("<div class=\"menu_block\">");
    echo("<div class=\"menu_title\">");
    if ($links != ''){
      echo('<div class="right">'.$links.'</div>EXIF: ');
    }
    echo($_REQUEST['pic']."</div>\n" );
    echo( "<div class=\"menu_body\">\n" );

    if (isset($_REQUEST['album']) && isset($_REQUEST['pic'])){
      global $album_directory;
      
      $img = $album_directory.'/'.$_REQUEST['album'].'/'.$_REQUEST['pic'];
      if (!file_exists($img)){
	//echo "strange ... cannot find image $img<br />";
	return false;
      }

      $exif = @exif_read_data($img, 0, true);
      if (isset($exif['EXIF'])){
	if (isset($exif['EXIF']['DateTimeOriginal'])){
	  echo '<b>';
	  echo $exif['EXIF']['DateTimeOriginal'] . '</b><br />';
	}
      }
      if (isset($exif['COMPUTED'])){
	if (isset($exif['COMPUTED']['Width']) && 
	    isset($exif['COMPUTED']['Height'])){
	  echo '<b>';
	  echo $exif['COMPUTED']['Width'] . 'x';
	  echo $exif['COMPUTED']['Height'] . '</b>';
	  if (isset($exif['FILE'])){
	    if (isset($exif['FILE']['FileSize'])){
	      echo ' - ';
	      if ($exif['FILE']['FileSize']<1024*1024){
		printf("%5.1fKB",$exif['FILE']['FileSize']/1024);
		
	      }
	      else{
		printf("%5.1fMB",$exif['FILE']['FileSize']/1024/1024);
	      }
	    }
	  }
	  echo '<br /><br />';
	}
      }
      if (isset($exif['IFD0'])){
	/*
	if (isset($exif['IFD0']['Make'])){
	  echo 'Camera: <b>'.$exif['IFD0']['Make'].'</b><br />';
	}
	*/
	if (isset($exif['IFD0']['Model'])){
	  echo '<b>'.$exif['IFD0']['Model'].'</b><br />';
	  // echo 'Model: <b>'.$exif['IFD0']['Model'].'</b><br />';
	}
      }
      if (isset($exif['EXIF'])){
	if (isset($exif['EXIF']['ExposureTime'])){
	  echo 'Exposure: <b>'.$exif['EXIF']['ExposureTime'];
	  if (isset($exif['EXIF']['Flash'])){
	    if ($exif['EXIF']['Flash'] == 1){
	      echo ' (flash)';
	    }
	  }
	  echo '</b><br />';
	}
      }
      if (isset($exif['COMPUTED'])){
	if (isset($exif['COMPUTED']['ApertureFNumber'])){
	  echo 'Aperture: <b>'.$exif['COMPUTED']['ApertureFNumber'];
	  echo '</b><br />';
	}
	if (isset($exif['COMPUTED']['FocusDistance'])){
	  echo 'Focus Distance: <b>'.$exif['COMPUTED']['FocusDistance'];
	  echo '</b><br />';
	}
      }


// 10/7/06
// 683×1024 pixels %Gâ%@ 87KB
// Filename: IMG_5675.JPG
// Camera: Canon
// Model: Canon EOS 350D DIGITAL
// ISO: 100
// Exposure: 1/640 sec
// Aperture: f/5.0
// Focal Length: 40mm

/*
      foreach ($exif as $key => $section) {
	foreach ($section as $name => $val) {
	  echo "$key.$name: $val<br />\n";
	}
      }
*/

    }
    echo( "</div></div></div>\n" );
  }
}




function archive_menu_block($links,$side){
    global $lang_string;
    // Retained from 0.3.7c
    $result = menu_display_blognav_tree();
    echo('<div class="menu_'.$side.'">');
    echo("<div class=\"menu_block\">");
    echo("<div class=\"menu_title\">");
    if ($links != ''){
      echo('<div class="right">'.$links.'</div>');
    }
    echo($result["title"] . "</div>\n" );
    echo( "<div class=\"menu_body\">\n" );
    echo( $result["content"] . "\n" );
    //echo( "</div></div><br />\n" );
    echo( "</div></div></div>\n" );
}


function menu_menu_block($links,$side){
  global $logged_in, $lang_string, $signed_in, $blog_permissions;

  // Retained from 0.3.7c
  $result = menu_display_user();
  if ($signed_in && file_exists('events.php')){
      if ($blog_permissions['move']==1 ){ 
	  $result['content'] .= '<br /><a href="events.php">';
	  $result['content'] .= $lang_string['menu_move_entries'];
	  $result['content'] .= '</a>';
      }
  }
  if ($signed_in && file_exists('upload_photo.php')){
      if ($blog_permissions['upload']==1 ){ 
	  $result['content'] .= '<br /><a href="upload_photo.php">';
	  $result['content'] .= $lang_string['menu_upload_photo'];
	  $result['content'] .='</a>';
      }
  }
  if ($signed_in && $blog_permissions['setup'] && file_exists('upload_file.php')){
      $result['content'] .= '<br /><a href="upload_file.php">';
      $result['content'] .= $lang_string['menu_upload_file'];
      $result['content'] .= '</a>';
  }
  if ( $result["content"] != "" ) {
      $result['content'] .= '<br />';
  }
    /*
    if ($signed_in && $blog_permissions['setup'] && file_exists('signup.php')){
      echo ('<br /><a href="signup.php">');
      echo($lang_string[ 'menu_signup' ]);
      echo('</a>');
    }
    */
  if ($logged_in && file_exists('user_admin.php')){
      $result['content'] .= '<br /><a href="user_admin.php">';
      $result['content'] .= $lang_string[ 'menu_user_admin' ];
      $result['content'] .= '</a>';
  }
  if ($signed_in && $blog_permissions['setup'] && file_exists('filemanager.php')){
      $result['content'] .= '<br /><a href="filemanager.php">';
      $result['content'] .= $lang_string[ 'menu_filemanager' ];
      $result['content'] .= '</a>';
  }
  if ($signed_in && $blog_permissions['setup'] && file_exists('cacheadmin.php')){
      $result['content'] .= '<br /><a href="cacheadmin.php">';
      $result['content'] .= $lang_string[ 'menu_admin_cache' ];
      $result['content'] .= '</a>';
  }
  if ($signed_in && $blog_permissions['setup'] && file_exists('admin_backup.php')){
      $result['content'] .= '<br /><a href="admin_backup.php">';
      $result['content'] .= $lang_string[ 'menu_admin_backup' ];
      $result['content'] .= '</a>';
  }


  if ( $result["content"] != "" ) {
    echo('<div class="menu_'.$side.'">');
    echo("<div class=\"menu_block\"><div class=\"menu_title\">");
    if ($links != ''){
      echo('<div class="right">'.$links.'</div>');
    }
    echo($result["title"] . "</div>\n" );
    echo( "<div class=\"menu_body\">\n" );
    echo( $result["content"] . "\n" );
    echo('</div></div></div>');
  }
  elseif ($links != ''){
    echo('<div class="menu_'.$side.'">');
    echo('<div class="menu_block"><div class="menu_title">');
    echo('<div class="right">'.$links.'</div>');
    global $lang_string;
    echo $lang_string[ 'menu_menu' ];
    echo('</div></div></div>');
  }
}


function setup_menu_block($links,$side){
  $result = menu_display_setup();
  if ( $result["content"] != "" ) {
    echo('<div class="menu_'.$side.'">');
    echo('<div class="menu_block"><div class="menu_title">');
    if ($links != ''){
      echo('<div class="right">'.$links.'</div>');
    }
    echo($result["title"] . "</div>\n" );
    echo( "<div class=\"menu_body\">\n" );
    echo( $result["content"] . "\n" );
    echo('</div></div></div>');
  }
  elseif ($links != ''){
    echo('<div class="menu_'.$side.'">');
    echo('<div class="menu_block"><div class="menu_title">');
    echo('<div class="right">'.$links.'</div>');
    global $lang_string;
    echo $lang_string[ 'menu_setup' ];
    //echo('</div></div><br>');
    echo('</div></div></div>');
  }
}



function upcoming_menu_block($links,$side,$pos,$params){
    global $lang_string;
    global $logged_in,$signed_in,$blog_permissions;

  // upcoming events
  if (function_exists('menu_upcoming_events')){
      $result = menu_upcoming_events($params[0]);
    if ( $result["content"] != "" ) {
      echo('<div class="menu_'.$side.'">');
      echo("<div class=\"menu_block\"><div class=\"menu_title\">");
      if ($links != ''){
	  echo('<div class="right">');

	  // this block has a setup function -> display a link to activate it
	  if ($_REQUEST['blocksetup'] != $side.$pos){
	      echo '<a href="?blocksetup='.$side.$pos.'">setup</a> ';
	  }
	  echo($links.'</div>');
      }
      echo($result["title"] . "</div>\n" );
      echo( "<div class=\"menu_body\">\n" );
      if ($links != ''){

	if ($signed_in && $blog_permissions['setup']){
	  // display a form for setup
	  if ($_POST['setupblock'] == 'submit'){
	    if ($_POST['blockside'].$_POST['blockpos'] == $side.$pos){
	      $params=array($_POST['max']);
	      if (set_menublock_params($side,$pos,$params)){
		$result = menu_upcoming_events($params[0]);
	      }
	    }
	  }
	  if ($_REQUEST['blocksetup'] == $side.$pos){
	    echo('<form name="setupblock" method="post" action="'.$_SERVER['PHP_SELF'].'">');
	    echo('<input name="blockside" value="'.$side.'" type="hidden" />');
	    echo('<input name="blockpos" value="'.$pos.'" type="hidden" />');
	    echo('show max <input name="max" value="'.$params[0].'" size="3" type="text" /> entries');
	    echo('<br /><br /><input type="submit" name="setupblock" value="submit" />');
	    echo('</form>');
	  }
	}
      }

      echo( $result["content"] . "\n" );
      echo( "</div></div></div>\n" );
    }
    elseif ($links != ''){
      echo('<div class="menu_'.$side.'">');
      echo('<div class="menu_block"><div class="menu_title">');
      echo('<div class="right">'.$links.'</div>');
      echo ($lang_string[ 'menu_upcoming' ]);
      echo( "</div></div></div>\n" );
    }
  }
  elseif ($links != ''){
    echo('<div class="menu_'.$side.'">');
    echo('<div class="menu_block"><div class="menu_title">');
    echo('<div class="right">'.$links.'</div>');
    echo('Upcoming</div></div></div>');
  }
}



function themes_menu_block($links,$side){
  global $blog_theme;
  echo('<div class="menu_'.$side.'">');
  echo("<div class=\"menu_block\">");
  echo("<div class=\"menu_title\">");
  if ($links != ''){
    echo('<div class="right">'.$links.'</div>');
  }  
  global $lang_string;
  echo( $lang_string[ 'menu_themes' ] );
  // echo( $lang_string[ 'choose_theme' ] );
  echo("</div>");
  echo( "<div class=\"menu_body\">\n" );
  echo('<form name="formTheme" method="get" action="">');
  echo('  <select name="theme" onchange="submit();">');
  //  echo('    <option>-- Choose a theme --</option>');
  $themes = array();
  read_themes($themes);
  foreach ($themes as $name => $dir){
    echo('<option label="'.$name.'" value="'.$dir.'"');
    if ( $blog_theme == $dir ) {
      echo(' selected="selected"');
    }
    echo('>'.$name.'</option>');
  }
  echo('  </select>');
  echo('</form>');
  echo( "</div></div></div>\n" );
}


function language_menu_block($links,$side){
  echo('<div class="menu_'.$side.'">');
  echo("<div class=\"menu_block\">");
  echo("<div class=\"menu_title\">");
  if ($links != ''){
    echo('<div class="right">'.$links.'</div>');
  }  
  global $lang_string;
  global $blog_config;
  // sb_language('setup');
  // echo( $lang_string[ 'blog_choose_language' ] );
  echo( $lang_string[ 'menu_languages' ] );
  echo("</div>");
  echo( "<div class=\"menu_body\">\n" );
  echo('<form name="formLang" method="get" action="">');
  echo('  <select name="lang" onchange="submit();">');
  //  echo('    <option>-- ');
  //  echo( $lang_string[ 'blog_choose_language' ] );
  //  echo (' --</option>');

  $langs = get_available_languages();
  foreach ($langs as $lang => $dir){
    echo('<option label="'.$lang.'" value="'.$dir.'"');
    if ( $blog_config[ 'blog_language' ] == $dir ) {
      echo(' selected="selected"');
    }
    echo('>'.$lang.'</option>');
  }
  echo('  </select>');
  echo('</form>');
  echo( "</div></div></div>\n" );
}



function user_menu_blocks($links,$side){
  global $logged_in,$signed_in,$blog_permissions;
  // New 0.3.8
  //
  // The ADD BLOCKS page lets you insert your own
  // content "blocks" into the menu area.
  $array = read_blocks($logged_in);
  for($i=0 ; $i<count($array) ; $i+=2) {
    if ($array[$i+1] != ''){
      echo('<div class="menu_'.$side.'">');
      echo('<div class="menu_block">');
      if ($array[$i] != ''){
	echo( '<div class="menu_title">');
	if ($links != ''){
	  echo('<div class="right">'.$links.'</div>');
	}
	echo($array[$i] . '</div>' );
      }
      elseif ($links != ''){
	echo('<div class="right">'.$links.'</div>');
      }
      echo( '<div class="menu_body">' );
      echo( $array[$i+1] );
      echo( '</div></div></div>' );
    }
  }
}

// new 13/09/2005 - show one of the user defined blocks

function user_menu_block($idx,$links,$side){
  global $logged_in,$signed_in,$blog_permissions;
  // New 0.3.8
  //
  // The ADD BLOCKS page lets you insert your own
  // content "blocks" into the menu area.
  $array = read_blocks($logged_in);
  $i=2*($idx-1);
  if ($array[$i+1] != ''){
    echo('<div class="menu_'.$side.'">');
    echo('<div class="menu_block">');
    if ($array[$i] != ''){
      echo( '<div class="menu_title">');
      if ($links != ''){
	echo('<div class="right">'.$links.'</div>');
      }
      echo($array[$i] . '</div>' );
    }
    elseif ($links != ''){
      echo('<div class="right">'.$links.'</div>');
    }
    echo( '<div class="menu_body">' );
    echo( $array[$i+1] );
    echo( '</div></div></div>' );
  }
  elseif ($links != ''){
    echo('<div class="menu_'.$side.'">');
    echo('<div class="menu_block"><div class="menu_title">');
    echo('<div class="right">'.$links.'</div>');
    echo('user menu block');
    echo('</div></div></div>');
  }
}




function trackback_menu_block($links,$side){
  // New 0.3.8
  if( $blog_config[ 'blog_trackback_enabled' ] ) {
    $result = menu_most_recent_trackbacks();
    if ( $result["content"] != "" ) {
      echo('<div class="menu_'.$side.'">');
      echo("<div class=\"menu_block\"><div class=\"menu_title\">");
      if ($links != ''){
	echo('<div class="right">'.$links.'</div>');
      }
      echo($result["title"] . "</div>\n" );
      echo( "<div class=\"menu_body\">\n" );
      echo( $result["content"] . "\n" );
      echo( "</div></div></div>\n" );
    }
    elseif ($links != ''){
      echo('<div class="menu_'.$side.'">');
      echo('<div class="menu_block"><div class="menu_title">');
      echo('<div class="right">'.$links.'</div>');
      global $lang_string;
      echo $lang_string[ 'menu_most_recent_trackback' ];
      echo('</div></div></div>');
    }
  }
  elseif ($links != ''){
    echo('<div class="menu_block"><div class="menu_title">');
    echo('<div class="right">'.$links.'</div>');
    global $lang_string;
    echo $lang_string[ 'menu_most_recent_trackback' ];
    echo('</div></div><br>');
  }
}


function categories_menu_block($links,$side){
  // New 0.3.8
  $result = menu_display_categories();
  if ( $result["content"] != "" ) {
    echo('<div class="menu_'.$side.'">');
    echo("<div class=\"menu_block\"><div class=\"menu_title\">");
    if ($links != ''){
      echo('<div class="right">'.$links.'</div>');
    }
    echo($result["title"] . "</div>\n" );
    echo( "<div class=\"menu_body\">\n" );
    echo( $result["content"] . "\n" );
    echo( "</div></div></div>\n" );
  }
  elseif ($links != ''){
    echo('<div class="menu_'.$side.'">');
    echo('<div class="menu_block"><div class="menu_title">');
    echo('<div class="right">'.$links.'</div>');
    global $lang_string;
    echo $lang_string[ 'menu_categories' ];
    echo('</div></div></div>');
  }
}

function album_menu_block($links,$side,$pos,$params){
  global $lang_string;
  global $logged_in,$signed_in,$blog_permissions;

  $maxdepth = 1;
  $reverse = false;
  if (is_array($params)){
    if (isset($params[0])){
      $maxdepth = $params[0];
    }
    if (isset($params[1])){
      $reverse = $params[1];
    }
  }

  if (is_file('scripts/sb_gallery_config.php')){
    global $album_directory;
    include_once('scripts/sb_gallery_config.php');
  }
  if (is_dir($album_directory) || $links !== ''){
    echo('<div class="menu_'.$side.'">');
    echo("<div class=\"menu_block\"><div class=\"menu_title\">");
    if ($links != ''){
      echo('<div class="right">');
      if ($_REQUEST['blocksetup'] != $side.$pos){
	echo '<a href="?blocksetup='.$side.$pos.'">setup</a> ';
      }
      echo($links.'</div>');
    }
    echo '<a href="gallery.php">';
    echo ($lang_string[ 'menu_gallery' ]);
    echo("</a></div>\n" );
    echo( "<div class=\"menu_body\">\n" );


    /////////////////////////////////////////////////////////////////////
    // this is for setup
    if ($signed_in && $blog_permissions['setup']){
      if ($_POST['setupblock'] == 'submit'){
	if ($_POST['blockside'].$_POST['blockpos'] == $side.$pos){
	  $params=array($_POST['maxdepth'],$_POST['reverse']);
	  if (set_menublock_params($side,$pos,$params)){
	    $maxdepth = $params[0];
	    $reverse = $params[1];
	  }
	}
      }
      if ($_REQUEST['blocksetup'] == $side.$pos){
	echo('<form name="setupblock" method="post" action="'.$_SERVER['PHP_SELF'].'">');
	echo('<input name="blockside" value="'.$side.'" type="hidden" />');
	echo('<input name="blockpos" value="'.$pos.'" type="hidden" />');
	echo('max subdir depth <input name="maxdepth" value="'.$params[0].'" size="3" type="text" /><br />');
	echo('<input name="reverse" value="y" type="checkbox"');
	if ($reverse == 'y'){echo 'checked="checked"';}
	echo('/> reverse order<br />');
	echo('<br /><input type="submit" name="setupblock" value="submit" />');
	echo('</form><br />');
      }
    }
    /////////////////////////////////////////////////////////////////////

    if (is_dir($album_directory)){
      include_once "scripts/sb_gallery.php";
      echo listdir($album_directory,
		   'gallery.php?page=1&amp;album=',
		   $maxdepth,
		   $reverse);
    }
    echo( "</div></div></div>\n" );
  }
}

function album_menu_block_old($links,$side){
    global $lang_string;
  if (is_file('scripts/sb_gallery_config.php')){
    global $album_directory;
    include_once('scripts/sb_gallery_config.php');
    if (is_dir($album_directory)){
      echo('<div class="menu_'.$side.'">');
      echo("<div class=\"menu_block\"><div class=\"menu_title\">");
      if ($links != ''){
	echo('<div class="right">'.$links.'</div>');
      }
      echo ($lang_string[ 'menu_gallery' ]);
      echo("</div>\n" );
      echo( "<div class=\"menu_body\">\n" );
      include_once "scripts/sb_gallery.php";
      echo listdir($album_directory,'gallery.php?page=1&amp;album=',1);
      echo( "</div></div></div>\n" );
    }
    elseif ($links != ''){
      echo('<div class="menu_'.$side.'">');
      echo('<div class="menu_block"><div class="menu_title">');
      echo('<div class="right">'.$links.'</div>album</div></div></div>');
    }
  }
  elseif ($links != ''){
    echo('<div class="menu_'.$side.'">');
    echo('<div class="menu_block"><div class="menu_title">');
    echo('<div class="right">'.$links.'</div>');
    echo 'Photo album';
    echo('</div></div></div>');
  }
}


function recent_entries_menu_block($links,$side,$pos,$params){
    global $lang_string;
    global $logged_in,$signed_in,$blog_permissions;

  // New 0.3.8
  $result = menu_most_recent_entries($params[0]);
  if ( $result["content"] != "" ) {
    echo('<div class="menu_'.$side.'">');
    echo("<div class=\"menu_block\"><div class=\"menu_title\">");
    if ($links != ''){
      echo('<div class="right">');

      // this block has a setup function -> display a link to activate it
      if ($_REQUEST['blocksetup'] != $side.$pos){
	echo '<a href="?blocksetup='.$side.$pos.'">setup</a> ';
      }
      echo($links.'</div>');
    }
    echo($result["title"] . "</div>\n" );
    echo( "<div class=\"menu_body\">\n" );

    if ($signed_in && $blog_permissions['setup']){
      // display a form for setup
      if ($_POST['setupblock'] == 'submit'){
	if ($_POST['blockside'].$_POST['blockpos'] == $side.$pos){
	  $params=array($_POST['max']);
	  if (set_menublock_params($side,$pos,$params)){
	    $result = menu_most_recent_entries($params[0]);
	  }
	}
      }
      if ($_REQUEST['blocksetup'] == $side.$pos){
	echo('<form name="setupblock" method="post" action="'.$_SERVER['PHP_SELF'].'">');
	echo('<input name="blockside" value="'.$side.'" type="hidden" />');
	echo('<input name="blockpos" value="'.$pos.'" type="hidden" />');
	echo('show max <input name="max" value="'.$params[0].'" size="3" type="text" /> entries');
	echo('<br /><br /><input type="submit" name="setupblock" value="submit" />');
	echo('</form>');
      }
    }

    echo( $result["content"] . "\n" );
    echo( "</div></div></div>\n" );
  }
  elseif ($links != ''){
    echo('<div class="menu_'.$side.'">');
    echo('<div class="menu_block"><div class="menu_title">');
    echo('<div class="right">'.$links.'</div>');
    global $lang_string;
    echo $lang_string[ 'menu_most_recent_entries' ];
    echo('</div></div></div>');
  }
}



function recent_comments_menu_block($links,$side){

  // Retained from 0.3.7c
  $result = menu_most_recent_comments();
  if ( $result["content"] != "" ) {
    echo('<div class="menu_'.$side.'">');
    echo("<div class=\"menu_block\"><div class=\"menu_title\">");
    if ($links != ''){
	  echo('<div class="right">');
	  echo($links.'</div>');
    }
    echo($result["title"] . "</div>\n" );
    echo( "<div class=\"menu_body\">\n" );
    echo( $result["content"] . "\n" );
    echo( "</div></div></div>\n" );
  }
  elseif ($links != ''){
    echo('<div class="menu_'.$side.'">');
    echo('<div class="menu_block"><div class="menu_title">');
    echo('<div class="right">'.$links.'</div>');
    global $lang_string;
    echo $lang_string[ 'menu_most_recent' ];
    echo('</div></div></div>');
  }
}

function search_menu_block($links,$side){
  // Retained from 0.3.7c
  $result = menu_search_field();
  echo('<div class="menu_'.$side.'">');
  echo('<div class="menu_block">');
  echo('<div class="menu_title">');
  if ($links != ''){
      echo('<div class="right">'.$links.'</div>');
  }
  echo($result["title"] . "</div>\n" );
  echo( "<div class=\"menu_body\">\n" );
  echo( $result["content"] . "\n" );
  echo( "</div></div></div>\n" );
}

function links_login_menu_block($links,$side){
  // Retained from 0.3.7c
  global $lang_string;
  global $blog_config;
  $result = menu_display_links();
  echo('<div class="menu_'.$side.'">');
  echo('<div class="menu_block"><div class="menu_title">');
  if ($links != ''){
      echo('<div class="right">'.$links.'</div>');
  }
  echo ($result["title"] . "</div>\n" );
  echo( "<div class=\"menu_body\">\n" );

  echo '<a href="index.php">'.$lang_string['menu_home'] .'</a><br>';
  echo( $result["content"] . "\n" );
  if ( !empty( $blog_config[ 'blog_email' ])){
    echo '<a href="contact.php">';
    echo $lang_string['menu_contact'].'</a><br>';
  }
  echo '<a href="stats.php">'.$lang_string['menu_stats'].'</a><br>';

  echo( "<br />" . menu_display_login() . "\n" );
  echo( "</div></div></div>\n" );
}

function links_menu_block($links,$side){
  // Retained from 0.3.7c
  global $lang_string;
  global $blog_config;
  $result = menu_display_links();
  echo('<div class="menu_'.$side.'">');
  echo('<div class="menu_block"><div class="menu_title">');
  if ($links != ''){
      echo('<div class="right">'.$links.'</div>');
  }
  echo ($result["title"] . "</div>\n" );
  echo( "<div class=\"menu_body\">\n" );
  echo '<a href="index.php">'.$lang_string['menu_home'] .'</a><br>';
  echo( $result["content"] . "\n" );
  if ( !empty( $blog_config[ 'blog_email' ])){
    echo '<a href="contact.php">';
    echo $lang_string['menu_contact'].'</a><br>';
  }
  echo '<a href="stats.php">'.$lang_string['menu_stats'].'</a><br>';
  echo( "</div></div></div>\n" );
}

function login_menu_block($links,$side){
  // Retained from 0.3.7c
  $result = menu_display_login();
  echo('<div class="menu_'.$side.'">');
  echo('<div class="menu_block">');
  if ($links != ''){
    echo("<div class=\"menu_title\">");
    echo('<div class="right">'.$links.'</div>');
    echo ("</div>\n" );
  }
  echo( "<div class=\"menu_body\">\n" );
  echo( $result. "\n" );
  echo( "</div></div></div>\n" );
}


function web_gadget_menu_block($links,$side){
  // Web Badges - Updated for 0.3.8
    global $pppb_info;
  if ($links != ''){
    echo('<div class="menu_'.$side.'">');
    echo("<div class=\"menu_block\"><div class=\"menu_title\">");
    echo('<div align="right">'.$links.'</div>');
    echo('</div>');
  }
  echo( '<div align="center">' );
echo( '<a href="http://pppblog.sourceforge.net/"><img style="margin-bottom: 5px;" src="interface/button_pppblog.png" alt="Powered by pppBlog ' .  $sb_info[ 'version' ] . '" title="Powered by pppBlog ' .  $pppb_info[ 'version' ] . '" border="0" /></a><br />' );
  echo( '<a href="http://sourceforge.net/projects/sphpblog/"><img style="margin-bottom: 5px;" src="interface/button_sphpblog.png" alt="Based on Simple PHP Blog ' .  $sb_info[ 'version' ] . '" title="Based on Simple PHP Blog ' .  $sb_info[ 'version' ] . '" border="0" /></a><br />' );
  echo( '<a href="rss.php"><img style="margin-bottom: 5px;" src="interface/button_rss20.png" alt="Get RSS 2.0 Feed" title="Get RSS 2.0 Feed" border="0" /></a><br />' );
  echo( '<a href="atom.php"><img style="margin-bottom: 5px;" src="interface/button_atom03.png" alt="Get Atom 0.3 Feed" title="Get Atom 0.3 Feed" border="0" /></a><br />' );
  echo( '<a href="rdf.php"><img style="margin-bottom: 5px;" src="interface/button_rdf10.png" alt="Get RDF 1.0 Feed" title="Get RDF 1.0 Feed" border="0" /></a><br />' );
  echo( '<a href="http://php.net/"><img style="margin-bottom: 5px;" src="interface/button_php.png" alt="Powered by PHP ' . phpversion() . '" title="Powered by PHP ' . phpversion() . '" border="0" /></a><br />' );
  echo( '<a href="http://jade.mcli.dist.maricopa.edu/feed/index.php"><img style="margin-bottom: 5px;" src="interface/feed2js_badge.gif" alt="feed2js" title="Feed2JS" border="0" /></a><br />' );
  //  echo( '<img style="margin-bottom: 5px;" src="interface/button_txt.png" alt="Powered by Plain text files" title="Powered by Plain text files" border="0" /><br />' );
  echo( '</div>' );
  if ($links != ''){
    echo( '</div></div>' );
  }

}



?>
