<?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 editor_addstatic(){
    global $lang_string;
    ?>
    <h2><?php echo( $lang_string[ 'title' ] ); ?></h2>
    <?php echo( $lang_string[ 'instructions' ] ); ?><p />

  <form accept-charset="<?php echo( $lang_string[ 'html_charset' ] ); ?>,iso-8859-1,utf-8" method="post" name="editor" id="editor" onsubmit="return validate(this)">

  <input type="hidden" name="entry" value="<?php global $entry; echo( $entry ); ?>" />

  <label for="blog_subject"><?php echo( $lang_string[ 'label_subject' ] ); ?></label><br />
  <input type="text" name="blog_subject" value="<?php global $temp_subject; echo( $temp_subject ); ?>" size="40" /><br /><br />
<?php

      blog_editor();

?>
<br /><br />
<label for="file_name"><?php echo( $lang_string[ 'file_name' ] ); ?></label><br/>
<input type="text" name="file_name" size="40" value="static<?php echo date('ymd-His'); ?>" /><br /><br />
<input type="submit" name="preview" value="<?php echo( $lang_string[ 'btn_preview' ] ); ?>" onclick="this.form.action='preview_static_cgi.php'" />
<input type="submit" name="submit" value="<?php echo( $lang_string[ 'btn_post' ] ); ?>" />
</form>
<?php

}


function editor_updatestatic(){
    global $lang_string;
    global $temp_file_name;

    editor_previewstatic();

    ?>
    <p />
    <h2><?php echo( $lang_string[ 'title_update' ] ); ?></h2>
    <?php echo( $lang_string[ 'instructions_update' ] ); ?><p />
   <div class="hr"><hr /></div>
  <form accept-charset="<?php echo( $lang_string[ 'html_charset' ] ); ?>,iso-8859-1,utf-8" action='add_static.php' method="post" name="editor" id="editor" onsubmit="return validate(this)">

  <input type="hidden" name="entry" value="<?php global $entry; echo( $entry ); ?>" />

  <table border="0" width="100%"><tr><td>
  <label for="blog_subject"><?php echo( $lang_string[ 'label_subject' ] ); ?></label><br />
  <input type="text" name="blog_subject" value="<?php global $temp_subject; echo( $temp_subject ); ?>" size="40" /><br /><br />
  </td><td>
<?php

    editor_languages();
    echo '</td></tr></table>';

    blog_editor();


?>
<br /><br />
<label for="file_name"><?php echo( $lang_string[ 'file_name' ] ); ?></label><br/>
<input type="text" name="file_name" autocomplete="OFF" value="<?php echo( $temp_file_name ); ?>" size="40"><br /><br />
<input type="submit" name="preview" value="<?php echo( $lang_string[ 'btn_preview' ] ); ?>" onclick="this.form.action='preview_static_cgi.php'" />
<input type="submit" name="submit" value="<?php echo( $lang_string[ 'btn_post' ] ); ?>" />
</form>
<?php

}




function editor_add(){
    global $lang_string;
    ?>
    <h2><?php echo( $lang_string[ 'title' ] ); ?></h2>
    <?php echo( $lang_string[ 'instructions' ] ); ?><p />

  <form accept-charset="<?php echo( $lang_string[ 'html_charset' ] ); ?>,iso-8859-1,utf-8" method="post" name="editor" id="editor" onsubmit="return validate(this)">

  <input type="hidden" name="entry" value="<?php global $entry; echo( $entry ); ?>" />

  <label for="blog_subject"><?php echo( $lang_string[ 'label_subject' ] ); ?></label><br />
  <input type="text" name="blog_subject" value="<?php global $temp_subject; echo( $temp_subject ); ?>" size="40" /><br /><br />
<?php

      blog_editor();
      echo( category_selection_box() );

?>
<br /><br />
<input type="submit" name="preview" value="<?php echo( $lang_string[ 'btn_preview' ] ); ?>" onclick="this.form.action='preview_cgi.php'" />
<input type="submit" name="submit" value="<?php echo( $lang_string[ 'btn_post' ] ); ?>" />
</form>
<?php

}


function editor_update(){
    global $lang_string;

    editor_preview();

    ?>
    <p />
    <h2><?php echo( $lang_string[ 'title_update' ] ); ?></h2>
    <?php echo( $lang_string[ 'instructions_update' ] ); ?><p />
   <div class="hr"><hr /></div>
  <form accept-charset="<?php echo( $lang_string[ 'html_charset' ] ); ?>,iso-8859-1,utf-8" action='add.php' method="post" name="editor" id="editor" onsubmit="return validate(this)">

  <input type="hidden" name="entry" value="<?php global $entry; echo( $entry ); ?>" />

  <table border="0" width="100%"><tr><td>
  <label for="blog_subject"><?php echo( $lang_string[ 'label_subject' ] ); ?></label><br />
  <input type="text" name="blog_subject" value="<?php global $temp_subject; echo( $temp_subject ); ?>" size="40" /><br /><br />
  </td><td>
<?php

    editor_languages();
    echo '</td></tr></table>';

    blog_editor();
    echo( category_selection_box() );
?>
<br /><br />
<input type="submit" name="preview" value="<?php echo( $lang_string[ 'btn_preview' ] ); ?>" onclick="this.form.action='preview_cgi.php'" />
<input type="submit" name="submit" value="<?php echo( $lang_string[ 'btn_post' ] ); ?>" />
</form>
<?php

}




function editor_description($album){
    global $lang_string;
    ?>
  <form accept-charset="<?php echo( $lang_string[ 'html_charset' ] ); ?>,iso-8859-1,utf-8" method="post" name="editor" id="editor" onsubmit="return validate(this)">
  <input type="hidden" name="album" value="<?php echo( $album ); ?>" />
<?php blog_editor(); ?>
<br /><br />
<input type="submit" name="edit description" value="<?php echo( $lang_string[ 'btn_post' ] ); ?>" />
</form>
<?php

}





function blog_editor(){
  global $blog_config;
  global $entry_format;

  $editor = 'default';
  if (isset($_REQUEST['blog_editor'])){
    $editor=$_REQUEST['blog_editor'];
    global $temp_text;
    if ($editor != 'fck'){
      if (isset($temp_text) && $entry_format=='fck'){
	$temp_text = '[html]'.$temp_text.'[/html]';
      }
    }
  }
  elseif(isset($entry_format)){
    $editor=$entry_format;
  }
  elseif($blog_config['blog_fckeditor']){
    $editor = 'fck';
  }

  if ($editor=='fck'){
    echo '<a href="?blog_editor=default';
    if (isset($_REQUEST['y'])){echo '&amp;y='.$_REQUEST['y'];}
    if (isset($_REQUEST['m'])){echo '&amp;m='.$_REQUEST['m'];}
    if (isset($_REQUEST['entry'])){
      $parts=explode('/',$_REQUEST['entry']);
      echo '&amp;entry='.$parts[count($parts)-1];
      if (count($parts)==4){
	echo '&amp;y='.$parts[1];
	echo '&amp;m='.$parts[2];
      }
    }
    echo '">default editor</a><br /><br />';
    return FCK_editor();
  }
  if (file_exists("FCKeditor/fckeditor.php")){
    echo '<a href="?blog_editor=fck';
    if (isset($_REQUEST['y'])){echo '&amp;y='.$_REQUEST['y'];}
    if (isset($_REQUEST['m'])){echo '&amp;m='.$_REQUEST['m'];}
    if (isset($_REQUEST['entry'])){
      //echo '&amp;entry='.$_REQUEST['entry'];
      $parts=explode('/',$_REQUEST['entry']);
      echo '&amp;entry='.$parts[count($parts)-1];
      if (count($parts)==4){
	echo '&amp;y='.$parts[1];
	echo '&amp;m='.$parts[2];
      }
    }
    echo '">WYSIWYG editor</a><br /><br />';
  }
  return default_editor();
}





function FCK_editor(){

    if (file_exists("FCKeditor/fckeditor.php")){
        include("FCKeditor/fckeditor.php") ;

        echo '<input type="hidden" name="blog_editor" value="fck" />';
        $oFCKeditor = new FCKeditor('blog_text') ;
        $oFCKeditor->BasePath = 'FCKeditor/' ;

        global $temp_text;
	$temp_text = blog_to_html($temp_text,false,false,false,false,'edit');

        $oFCKeditor->Height             = 400;
	// $oFCKeditor->ToolbarSet         = 'Basic';
        $oFCKeditor->Value              = $temp_text;

	// use files will be stored in 'data'
	// create 'data' if necessary
	// create symbolic links to albums, images
	// create symbolic links to other diretories that FCK created before
	// Note: symlink only works on *nix!!!


	if (!file_exists('data')){
	    my_mkdir('data',0755);
	}
	if (file_exists('data')){
	    if (!file_exists('data/Image')){
		my_mkdir('data/Image',0755);
	    }
	    //$path = realpath( './' );
	    if (file_exists('data/Image')){
		if (file_exists('data/Image')){
		    if (!file_exists('data/Image/images')){
		      if (function_exists('symlink')){
			//@symlink($path.'/images',$path.'/data/Image/images');
			@symlink('../../images','data/Image/images');
		      }
		    }
		    if (file_exists('albums') && 
			(!file_exists('data/Image/albums'))){
		      if (function_exists('symlink')){
			//@symlink($path.'/albums',$path.'/data/Image/albums');
			@symlink('../../albums','data/Image/albums');
		      }
		    }
		}
	    }
	    if (file_exists('Image') && (!file_exists('data/Image'))){
	      if (function_exists('symlink')){
		//@symlink($path.'/Image',$path.'/data/Image/Image');
		@symlink('../../Image','data/Image/Image');
	      }
	    }
	    if (file_exists('Flash') && (!file_exists('data/Flash'))){
	      //@symlink($path.'/Flash',$path.'/data/Flash');
		@symlink('../Flash','data/Flash');
	    }
	    if (file_exists('Media') && (!file_exists('data/Media'))){
	      if (function_exists('symlink')){
		//@symlink($path.'/Media',$path.'/data/Media');
		@symlink('../Media','data/Media');
	      }
	    }
	}

	/*
	$sBasePath = $_SERVER['PHP_SELF'] ;
	$sSelfPath = substr( $sSelfPath, 0, strrpos( $sSelfPath, '/' ) ) ;
	$oFCKeditor->Config['SkinPath'] = $sBasePath . 'editor/skins/silver';
	*/

	//	$PathParts = explode('/',$_SERVER['PHP_SELF']);
	//	for ($i=0;$i<8;$i++){array_pop($PathParts);}
	//	array_pop($PathParts);
	//	$oFCKeditor->Config['UserFilesPath'] = implode('/',$PathParts);
	// $oFCKeditor->Config['UserFilesAbsolutePath'] = realpath('.');

        $oFCKeditor->Create() ;
        echo '<br />';
    }
    else{
        return default_editor();
    }
}




function default_editor(){
    global $lang_string,$blog_config;

    editor_style_buttons();
    editor_style_dropdown();
    echo '<br />';
    editor_table_buttons();
    editor_more_button();
    echo '<br /><br />';
    emoticons_show();
    editor_image_dropdown();
    echo '<br /><br />';

?>			
<label for="blog_text"><?php echo( $lang_string[ 'label_entry' ] ); ?></label>
<br />
<textarea style="width: <?php global $theme_vars; echo( $theme_vars[ 'max_image_width' ] ); ?>px;" id="text" name="blog_text" rows="20" cols="50"><?php global $temp_text; echo( $temp_text ); ?></textarea><br /><br />

<?php if ( $blog_config[ 'blog_trackback_enabled' ] ) { ?>
<label for="tb_ping"><?php echo( $lang_string[ 'label_tb_ping' ] ); ?></label>
<br />
<input type="text" id="tb_ping" name="tb_ping" 
<?php 
     global $temp_tb_ping; 
      if( $blog_config[ 'blog_trackback_auto_discovery' ] ) { 
	  echo ' value="' . $temp_tb_ping . '" '; } 
?>
style="width: <?php global $theme_vars; echo( $theme_vars[ 'max_image_width' ] ); ?>px;" /><br /><br />
<?php 


    }
}



function editor_comments(){
    global $lang_string, $user_colors, $logged_in;

    ?>
    <p />
    <h2><?php echo( $lang_string[ 'header' ] ); ?></h2>
    <p><?php echo( $lang_string[ 'instructions' ] ); ?></p>
<form action="comments.php" accept-charset="<?php echo( $lang_string[ 'html_charset' ] ); ?>,iso-8859-1,utf-8" method="post" name="vbform" onsubmit="return validate_comment(this)">
<input type="hidden" name="y" value="<?php echo( $_GET[ 'y' ] ); ?>" />
<input type="hidden" name="m" value="<?php echo( $_GET[ 'm' ] ); ?>" />
<input type="hidden" name="entry" value="<?php echo( $_GET[ 'entry' ] ); ?>" />


<?php comment_editor(); ?>


<input type="submit" name="submit" value="<?php echo( $lang_string[ 'post_btn' ] ); ?>" />
</form>
<?php

}







function comment_editor(){
    global $lang_string, $user_colors, $logged_in;

?>
<label for="comment_name"><?php echo( $lang_string[ 'comment_name' ] ); ?></label><br />
<input type="text" name="comment_name" value="<?php echo $_COOKIE[ 'comment_name' ]; ?>" /><br />
<label for="comment_email"><?php echo( $lang_string[ 'comment_email' ] ); ?></label><br />
<input type="text" name="comment_email" value="<?php echo $_COOKIE[ 'comment_email' ]; ?>" /><br />
<label for="comment_url"><?php echo( $lang_string[ 'comment_url' ] ); ?></label><br />
<input type="text" name="comment_url" value="<?php echo $_COOKIE[ 'comment_url' ]; ?>" /><br />

<label for="comment_remember"><?php echo( $lang_string[ 'comment_remember' ] ); ?><input type="checkbox" name="comment_remember" value="1" <?php if (!empty($_COOKIE[ 'comment_name' ])) echo 'checked'; ?> /></label><br /><br />

<!-- NEW -->

<?php echo( $lang_string[ 'label_insert' ] ); ?><br />
<?php

 global $blog_config;

 if ( in_array( 'b', $blog_config[ 'comment_tags_allowed' ] ) ) {
    ?><input type="button" class="bginput" value="<?php echo( $lang_string[ 'btn_bold' ] ); ?>" onclick="ins_styles(this.form.blog_text,'b','');" /><?php
 }
 if ( in_array( 'i', $blog_config[ 'comment_tags_allowed' ] ) ) {
    ?><input type="button" class="bginput" value="<?php echo( $lang_string[ 'btn_italic' ] ); ?>" onclick="ins_styles(this.form.blog_text,'i','');" /><?php
 }
 if ( in_array( 'url', $blog_config[ 'comment_tags_allowed' ] ) ) {
    ?><input type="button" class="bginput" value="<?php echo( $lang_string[ 'btn_url' ] ); ?>" onclick="ins_url_no_options(this.form.blog_text);" /><?php
 }
 if ( in_array( 'img', $blog_config[ 'comment_tags_allowed' ] ) ) {
    ?><input type="button" class="bginput" value="<?php echo( $lang_string[ 'btn_image' ] ); ?>" onclick="ins_image_v2(this.form.blog_text);"/><?php
 }
 if ( in_array( 'html', $blog_config[ 'comment_tags_allowed' ] ) ) {
    ?><input type="button" class="bginput" value="LaTeX" onclick="ins_latex(this.form.blog_text);"/><?php
 }
?>
			
<select name="style_dropdown" onchange="ins_style_dropdown(this.form.blog_text,this.form.style_dropdown.value);">
<option label="--" value="--">--</option>
<?php
     if ( in_array( 'blockquote', $blog_config[ 'comment_tags_allowed' ] ) ) {
	 ?><option label="[blockquote]xxx[/blockquote]" value="blockquote">[blockquote]xxx[/blockquote]</option><?php
     }
     if ( in_array( 'pre', $blog_config[ 'comment_tags_allowed' ] ) ) {
         ?><option label="[pre]xxx[/pre]" value="pre">[pre]xxx[/pre]</option><?php
     }
     if ( in_array( 'code', $blog_config[ 'comment_tags_allowed' ] ) ) {
         ?><option label="[code]xxx[/code]" value="code">[code]xxx[/code]</option><?php
     }
     if ( in_array( 'strong', $blog_config[ 'comment_tags_allowed' ] ) ) {
         ?><option label="[strong]xxx[/strong]" value="strong">[strong]xxx[/strong]</option><?php
     }
     if ( in_array( 'b', $blog_config[ 'comment_tags_allowed' ] ) ) {
         ?><option label="[b]xxx[/b]" value="b">[b]xxx[/b]</option><?php
     }
     if ( in_array( 'em', $blog_config[ 'comment_tags_allowed' ] ) ) {
         ?><option label="[em]xxx[/em]" value="em">[em]xxx[/em]</option><?php
     }
     if ( in_array( 'i', $blog_config[ 'comment_tags_allowed' ] ) ) {
         ?><option label="[i]xxx[/i]" value="i">[i]xxx[/i]</option><?php
     }
     if ( in_array( 'hN', $blog_config[ 'comment_tags_allowed' ] ) ) {
         ?><option label="[hN]xxx[/hN] (N=1-6)" value="hN">[hN]xxx[/hN] (?=1-6)</option><?php
     }
     if ( in_array( 'html', $blog_config[ 'comment_tags_allowed' ] ) ) {
    ?><option label="[html]xxx[/html]" value="html">[html]xxx[/html]</option><?php
	   }
     if ( in_array( 'del', $blog_config[ 'comment_tags_allowed' ] ) ) {
    ?><option label="[del]xxx[/del]" value="del">[del]xxx[/del]</option><?php
	   }
     if ( in_array( 'ins', $blog_config[ 'comment_tags_allowed' ] ) ) {
    ?><option label="[ins]xxx[/ins]" value="ins">[ins]xxx[/ins]</option><?php
	   }
     if ( in_array( 'strike', $blog_config[ 'comment_tags_allowed' ] ) ) {
    ?><option label="[strike]xxx[/strike]" value="strike">[strike]xxx[/strike]</option><?php
	   }

?>
</select>
<input type="button" class="bginput" value="ok" onclick="ins_style_dropdown(this.form.blog_text,this.form.style_dropdown.value);"/><br /><br />
<?php emoticons_show(); ?>
<?php
      if ( in_array( 'img', $blog_config[ 'comment_tags_allowed' ] ) ) {
	  global $theme_vars;

?>
<a href="javascript:openpopup('image_list.php',<?php echo( $theme_vars[ 'popup_window' ][ 'width' ] ); ?>,<?php echo( $theme_vars[ 'popup_window' ][ 'height' ] ); ?>,true);"><?php echo( $lang_string[ 'view_images' ] ); ?></a><br />
<?php echo image_dropdown(); ?><br /><br />
<?php
      }
    ?>

<label for="blog_text"><?php echo( $lang_string[ 'comment_text' ] ); ?></label><br />
<textarea style="width: <?php global $theme_vars; echo( $theme_vars[ 'max_image_width' ] ); ?>px;" id="text" name="blog_text" rows="20" cols="50"></textarea><br /><br />

<?php 
     global $blog_config;
     if (!$blog_config['disable_comment_capcha']){
?>
<label for="comment_capcha"><?php 
       if ( function_exists('imagecreate') ) {
	   printf( $lang_string[ 'comment_capcha' ], '<br /><img src="capcha.php?entry=' . $_REQUEST[ 'entry' ]. '" alt="capcha" />' );
       }
       else {
	   printf( $lang_string[ 'comment_capcha' ], sb_str_to_ascii( $_SESSION[ 'capcha_' . $_REQUEST[ 'entry' ] ] ) ); 
       }
?></label>
<br />
<input type="text" name="comment_capcha" value="" maxlength="6" /><br /><br />
<?php 
      }


}





function editor_preview(){
    global $lang_string, $user_colors, $blog_config, $theme_vars;
    global $blog_subject, $blog_text, $temp_subject, $temp_text, $entry, $temp_tb_ping, $temp_categories;
	
    ?>
    <h2><?php echo( $lang_string[ 'title_preview' ] ); ?></h2>
    <?php echo( $lang_string[ 'instructions_preview' ] ); ?><p />
    <div class="hr"><hr /></div>
    <p><?php
		
   if ( isset( $_GET[ 'entry' ] ) ) {
       $entry = 'content/'.$_GET['y'].'/'.$_GET['m'].'/'.$_GET['entry'];
       $entry_dir = 'content/'.$_GET['y'].'/'.$_GET['m'];
       $entry_base = $_GET['entry'];

       ///////////////////////////////////////////////////////////////
       // check if there is another version for the chosen language!
       ///////////////////////////////////////////////////////////////

       if (@is_dir($entry)){
	   if (@is_dir($entry.'/trans')){
	       $lang = $blog_config['blog_language'];
	       $dir = $entry.'/trans';
	       
	       if ( $blog_config[ 'blog_enable_gzip_txt' ] ) {
		   if (file_exists($dir.'/'.$lang.'.txt.gz')){
		       $entry .= '/trans/'.$lang;
		       $entry_base .= '/trans/'.$lang;
		   }
	       }
	       elseif (file_exists($dir.'/'.$lang.'.txt')){
		   $entry .= '/trans/'.$lang;
		   $entry_base .= '/trans/'.$lang;
	       }
	   }
       }
       ///////////////////////////////////////////////////////////////

       if ( file_exists( $entry . ".txt" ) ) {
	   $filename = $entry . ".txt";
       } elseif ( file_exists( $entry . ".txt.gz" ) ) {
	   $filename = $entry . ".txt.gz";
       }

       if (isset($_GET['time'])){
	   $old_entry = history_entry($entry,$_GET['time']);
	   $blog_content = read_entry_from_file( $old_entry );
	   $old_entry_file = history_file($entry,$_GET['time']);
	   $blog_entry_data = blog_entry_to_array( $old_entry_file );
       }
       else{
	   $blog_content = read_entry_from_file( $entry );
	   $blog_entry_data = blog_entry_to_array( $filename );
       }
				
       $temp_subject = $blog_entry_data[ 'SUBJECT' ];
       $temp_text = $blog_entry_data[ 'CONTENT' ];
       $temp_tb_ping = $blog_entry_data[ 'TB_PING' ];

       if ( array_key_exists( "CATEGORIES", $blog_entry_data ) ) {
	   $temp_categories = $blog_entry_data[ 'CATEGORIES' ];
       }

       $blog_history = 
	   blog_entry_history($entry_dir,$entry_base);
       //blog_entry_history('content/'.$_GET['y'].'/'.$_GET['m'],
       //			   $_GET['entry']);

       if (count($blog_history)){
	   echo '<div class="right">';
	   // echo '<div class="right">entry history: ';
	   foreach ($blog_history as $time => $file){
	       $time_str = date('m/d H:i',$time);
	       echo '[<a href="';
	       echo '?entry='.$_GET['entry'];
	       echo '&amp;y='.$_GET['y'];
	       echo '&amp;m='.$_GET['m'];
	       echo '&amp;time='.$time;
	       echo '">'.$time_str.'</a>]';
	   }		echo '</div>';
       }
       
       echo( $blog_content );

       // set entry back to original one
       $entry = 'content/'.$_GET['y'].'/'.$_GET['m'].'/'.$_GET['entry'];

   } else {
       $entry = NULL;
       if ( isset( $_POST[ 'entry' ] ) ) {
	   $entry = $_POST[ 'entry' ];
       }
	      
       global $entry_format;
       $entry_format = $_POST['blog_editor'];
       $temp_text = sb_stripslashes( $_POST[ 'blog_text' ] );

       $temp_subject = sb_stripslashes( $_POST[ 'blog_subject' ] );
       $temp_tb_ping = sb_stripslashes( $_POST[ 'tb_ping' ] );       
       $blog_content = preview_entry($temp_subject,$temp_text,$temp_tb_ping);
	      
       echo( $blog_content );
   }
}




function editor_previewstatic(){
    global $lang_string, $user_colors, $theme_vars;
	    ?>
    <h2><?php echo( $lang_string[ 'title_preview' ] ); ?></h2>
	<?php echo( $lang_string[ 'instructions_preview' ] ); ?><p />
	<div class="hr"><hr /></div>
    <?php
   global $blog_subject, $blog_text, $temp_subject, $temp_text;
    global $entry, $temp_file_name;
    if ( isset( $_GET[ 'entry' ] ) ) {
	$entry = $_GET[ 'entry' ];
	      
	if ( file_exists( 'content/static/' . $entry . '.txt' ) ) {
	    $filename = 'content/static/' . $entry . '.txt';
	} elseif (file_exists( 'content/static/' . $entry . '.txt.gz')){
	    $filename = 'content/static/' . $entry . '.txt.gz';
	}

	if (isset($_GET['time'])){
	    $old_entry = history_static('content/static',
					$entry,
					$_GET['time']);
	    
	    $blog_content = get_static_entry_by_file( $old_entry );
	    $old_entry_file = history_file('content/static/'.$entry,
					   $_GET['time']);
	    $blog_entry_data = static_entry_to_array( $old_entry_file );
	}
	else{
	    $blog_entry_data = static_entry_to_array( $filename );
	    $blog_content = get_static_entry_by_file( $entry );
	}

	$temp_subject = $blog_entry_data[ 'SUBJECT' ];
	$temp_text = $blog_entry_data[ 'CONTENT' ];
	$temp_file_name = $entry;

	$blog_history = 
	    blog_entry_history('content/static',$_GET['entry']);

	if (count($blog_history)){
	    echo '<div class="right">';
	    // echo '<div class="right">entry history: ';
	    foreach ($blog_history as $time => $file){
		$time_str = date('m/d H:i',$time);
		echo '[<a href="';
		echo '?entry='.$_GET['entry'];
		echo '&amp;time='.$time;
		echo '">'.$time_str.'</a>]';
	    }		echo '</div>';
	}


	echo( $blog_content );
    } else {
	$entry = NULL;
	if ( isset( $_POST[ 'entry' ] ) ) {
	    $entry = $_POST[ 'entry' ];
	}

	global $entry_format;
	$entry_format = $_POST['blog_editor'];
				
	$temp_subject = sb_stripslashes( $_POST[ 'blog_subject' ] );
	$temp_text = sb_stripslashes( $_POST[ 'blog_text' ] );
	$blog_content = preview_static_entry( $temp_subject, $temp_text );
	$temp_file_name = sb_stripslashes( $_POST[ 'file_name' ] );
	echo( $blog_content );
    }
}





function editor_addevent(){

    global $lang_string, $user_colors, $blog_config, $theme_vars, $logged_in;
    global $signed_in,$blog_permissions;
?>

<!--	<h2><?php echo( $lang_string['title'] ); ?></h2>-->
<h2>Add Event for <?php echo $_GET['m'].'/'.$_GET['d'].'/'.$_GET['y']; ?></h2>
<!--	<?php echo( $lang_string['instructions'] ); ?><p /> -->

<hr noshade size="1" color=#<?php echo( $user_colors['inner_border_color'] ); ?>>
<form method="post" name="vbform" onsubmit="return validate_comment(this)">

<input type="hidden" name="y" value="<?php echo( $_GET['y'] ); ?>">
<input type="hidden" name="m" value="<?php echo( $_GET['m'] ); ?>">
<input type="hidden" name="d" value="<?php echo( $_GET['d'] ); ?>">

<label for="blog_subject"><?php echo( $lang_string['label_subject'] ); ?></label><br />
<input type="text" name="blog_subject" autocomplete=OFF value="" size="40">

time:
<input value="18" type="text" name="H" autocomplete="OFF" size="2" maxlength="2">
<input value="00" type="text" name="i" autocomplete="OFF" size="2" maxlength="2">
repeat
<select name="repeat">
<option label="--" value="--">--</option>
<option label="every year" value="1:0">every year</option>
<option label="every month" value="0:1">every month</option>
</select>
<br /><br />
<?php

    blog_editor();
    echo( category_selection_box() );

?>
<br /><br />			
<input type="submit" name="submit" value="<?php echo( $lang_string['btn_post'] ); ?>" /><br /><br />
</form>
		
<?php 
     }




function category_selection_box () {
  // Returns categories HTML.
  global $lang_string, $theme_vars, $temp_categories;
		
  if ( array_key_exists( 'catlist', $_POST ) ) {
    $blog_categories = $_POST[ 'catlist' ];
  } else {
    if ( isset( $temp_categories ) ) {			
      $blog_categories = explode( ',', $temp_categories );
    }
  }
		
  $catArray = get_category_array();
  if ( count($catArray) > 0) {
    $str = '<select name="catlist[]" size="'. min( 8, count($catArray) ) ."\" multiple>\n";
    for ( $i = 0; $i < count( $catArray ); $i++ ) {
      $id_number = $catArray[$i][0];
      $name_str = $catArray[$i][1];
      $space_count = $catArray[$i][2];
				
      $label = '';
      for ( $j = 0; $j < $space_count; $j++ ) {
	$label = $label . '&nbsp;';
      }
      $label = $label . $name_str;
				
      $selected = false;
      for ( $j=0; $j < count( $blog_categories ); $j++) {
	if ( $blog_categories[$j] == $id_number ) {
	  $selected = true;
	  break;
	}
      }
				
      if ( $selected == true ) {
	$str = $str . '<option label="' . $label . '" value="' . $id_number . '" selected="selected">' . $label . "</option>\n";
      } else {
	$str = $str . '<option label="' . $label . '" value="' . $id_number . '">' . $label . "</option>\n";
      }
				
    }
    $str = $str . "</select>\n";
  }
  
  return ( $str );
}


function editor_style_buttons(){
    global $lang_string;
echo( $lang_string[ 'label_insert' ] ); ?><br />
<input type="button" class="bginput" value="<?php echo( $lang_string[ 'btn_bold' ] ); ?>" onclick="ins_styles(this.form.blog_text,'b','');" />
<input type="button" class="bginput" value="<?php echo( $lang_string[ 'btn_italic' ] ); ?>" onclick="ins_styles(this.form.blog_text,'i','');" />
<input type="button" class="bginput" value="<?php echo( $lang_string[ 'btn_url' ] ); ?>" onclick="ins_url(this.form.blog_text);" />
<input type="button" class="bginput" value="<?php echo( $lang_string[ 'btn_image' ] ); ?>" onclick="ins_image_v2(this.form.blog_text);"/>
<input type="button" class="bginput" value="RSS feed" onclick="ins_rssfeed(this.form.blog_text);"/>
<input type="button" class="bginput" value="LaTeX" onclick="ins_latex(this.form.blog_text);"/> 
<?php
}

function editor_table_buttons(){
    global $lang_string;
?>
<input type="button" class="bginput" value="[table]" onclick="ins_table(this.form.blog_text);" />
<input type="button" class="bginput" value="[td]" onclick="ins_string(this.form.blog_text,'||');" />
<input type="button" class="bginput" value="[tr]" onclick="ins_string(this.form.blog_text,'\\\\');" />
<input type="button" class="bginput" value="[/table]" onclick="ins_string(this.form.blog_text,'[/table]');" />

<?php
}

function editor_more_button(){
    global $lang_string;
?>
<input type="button" class="bginput" value="more" onclick="ins_string(this.form.blog_text,'[more]');"/> 
<?php
}


function editor_style_dropdown(){
?>			
			<select name="style_dropdown" onchange="ins_style_dropdown(this.form.blog_text,this.form.style_dropdown.value);">
				<option label="--" value="--">--</option>
				<option label="[blockquote]xxx[/blockquote]" value="blockquote">[blockquote]xxx[/blockquote]</option>
				<option label="[pre]xxx[/pre]" value="pre">[pre]xxx[/pre]</option>
				<option label="[code]xxx[/code]" value="code">[code]xxx[/code]</option>
				<option label="[strong]xxx[/strong]" value="strong">[strong]xxx[/strong]</option>
				<option label="[b]xxx[/b]" value="b">[b]xxx[/b]</option>
				<option label="[em]xxx[/em]" value="em">[em]xxx[/em]</option>
				<option label="[i]xxx[/i]" value="i">[i]xxx[/i]</option>
				<option label="[h?]xxx[/h?] (?=1-6)" value="h?">[h?]xxx[/h?] (?=1-6)</option>
				<option label="[html]xxx[/html]" value="html">[html]xxx[/html]</option>
				<option label="[del]xxx[/del]" value="del">[del]xxx[/del]</option>
				<option label="[ins]xxx[/ins]" value="ins">[ins]xxx[/ins]</option>
				<option label="[strike]xxx[/strike]" value="strike">[strike]xxx[/strike]</option>
			</select>
			<input type="button" class="bginput" value="ok" onclick="ins_style_dropdown(this.form.blog_text,this.form.style_dropdown.value);"/>
<?php 
			     }


function editor_image_dropdown(){
    global $lang_string, $theme_vars;


    echo "<a href=\"javascript:openpopup('image_list.php',";
    echo $theme_vars[ 'popup_window' ][ 'width' ].',';
    echo $theme_vars[ 'popup_window' ][ 'height' ].',true)">';
    echo $lang_string[ 'view_images' ].'</a>';
    if (file_exists('albums')){
      echo "&nbsp;|&nbsp;<a href=\"javascript:openpopup('photo_list.php',";
      echo $theme_vars[ 'popup_window' ][ 'width' ].',';
      echo $theme_vars[ 'popup_window' ][ 'height' ].',true)">';
      echo $lang_string[ 'menu_gallery' ].'</a>';
    }
    echo '<br />';
    echo image_dropdown();
}


function editor_languages(){
    global $lang_string,$blog_config;

  echo( $lang_string[ 'menu_languages' ] );
  echo '<br />';
  echo('  <select name="entry_language">');
  $langs = iso639();
  $lang_found = 0;
#  $langs = get_available_languages();
  foreach ($langs as $id => $lang){
    echo('<option label="'.$lang.'" value="'.$id.'"');
    if (isset($_POST['entry_language'])){
	if ($_POST['entry_language'] == $id){
	    echo(' selected="selected"');
	    $lang_found = 1;
	}
    }
    elseif ( strtolower($blog_config[ 'blog_language' ]) == 
	     strtolower($lang) ) {
	$lang_found = 1;
	echo(' selected="selected"');
    }
    echo('>'.$lang.'</option>');
  }
  if (!$lang_found){
    echo '<option label="'.$blog_config[ 'blog_language' ].'" value="';
    echo $blog_config[ 'blog_language' ].'" selected="selected">';
    echo($blog_config[ 'blog_language' ].'</option>');
  }
  echo('  </select><br /><br />');
}

?>
