<?php


global $supported_charsets;
$supported_charsets = supported_charsets();


// print the HTML header
// extra_header ----> string with extra info witin the <head> tags
// editor ----------> include java scripts for editor (true/false)


function html_header($extra_header='', $editor=false){

  global $lang_string, $blog_config, $pppb_info, $blog_theme;

  // send header with language specific charater set!

  header('Content-Type: text/html; charset='.$lang_string[ 'html_charset' ]);
  echo '<?xml version="1.0" encoding="'.$lang_string[ 'html_charset' ].'"?>';

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <!--[if lt IE 7.]>
<script defer type="text/javascript" src="scripts/pngfix.js"></script>
<![endif]--> <meta http-equiv="Content-Type" content="text/html; charset=<?php echo( $lang_string[ 'html_charset' ] ); ?>" />
 
  <!-- Meta Data -->
  <meta name="generator" content="pppBLOG <?php echo( $pppb_info[ 'version' ] );?>" />
  <link rel="alternate" type="application/rss+xml" title="Get RSS 2.0 Feed" href="rss.php" />
  <link rel="alternate" type="application/rdf+xml" title="Get RDF 1.0 Feed" href="rdf.php" />
  <link rel="alternate" type="application/atom+xml" title="Get Atom 0.3 Feed" href="atom.php" />

  <!-- Meta Data -->
  <!-- http://dublincore.org/documents/dces/ -->
  <meta name="dc.title"       content="<?php echo( $blog_config[ 'blog_title' ] ); ?>" />
  <meta name="author"         content="<?php echo( $blog_config[ 'blog_author' ] ); ?>" />
  <meta name="dc.creator"     content="<?php echo( $blog_config[ 'blog_author' ] ); ?>" />
  <meta name="dc.subject"     content="<?php echo( $blog_config[ 'info_keywords' ] ); ?>" />
  <meta name="keywords"       content="<?php echo( $blog_config[ 'info_keywords' ] ); ?>" />
  <meta name="dc.description" content="<?php echo( $blog_config[ 'info_description' ] ); ?>" />
  <meta name="description"    content="<?php echo( $blog_config[ 'info_description' ] ); ?>" />
  <meta name="dc.type"        content="weblog" />
  <meta name="dc.type"        content="blog" />
  <meta name="resource-type"  content="document" />
  <meta name="dc.format"      scheme="IMT" content="text/html" />
  <meta name="dc.source"      scheme="URI" content="<?php if ( ( dirname($_SERVER[ 'PHP_SELF' ]) == '\\' || dirname($_SERVER[ 'PHP_SELF' ]) == '/' ) ) { echo( 'http://'.$_SERVER[ 'HTTP_HOST' ].'/index.php' ); } else { echo( 'http://'.$_SERVER[ 'HTTP_HOST' ].dirname($_SERVER[ 'PHP_SELF' ]).'/index.php' ); } ?>" />
  <meta name="dc.language"    scheme="RFC1766" content="<?php echo( str_replace('_', '-', $lang_string[ 'locale' ]) ); ?>" />
  <meta name="dc.coverage"    content="global" />
  <meta name="distribution"   content="GLOBAL" /> 
  <meta name="dc.rights"      content="<?php echo( $blog_config[ 'info_copyright' ] ); ?>" />
  <meta name="copyright"      content="<?php echo( $blog_config[ 'info_copyright' ] ); ?>" />

  <!-- Robots -->
  <meta name="robots" content="INDEX,NOFOLLOW" />
  <meta name="revisit-after" content="7 days" />

  <!-- Fav Icon -->
  <link rel="shortcut icon" href="interface/favicon.ico" />

  <link rel="stylesheet" type="text/css" href="themes/<?php echo( $blog_theme ); ?>/style.css" />
  <?php 
   if (file_exists('themes/general.css')){
    echo '<link rel="stylesheet" type="text/css" href="themes/general.css" />';
   }
   require_once('themes/' . $blog_theme . '/user_style.php'); 
  ?>
  <script language="javascript" src="scripts/sb_javascript.js" type="text/javascript"></script>
  <title><?php echo($blog_config[ 'blog_title' ]); ?></title>
  <?php echo $extra_header ?>
  <?php if ($editor){require_once('scripts/sb_editor.php');} ?>
</head>
<?php 
}



function html_footer($extra_footer = ''){
  global $pppb_info;
?>
    <div class="blog_date" align="right">
      <br />
       powered by <a href="http://pppblog.sourceforge.net/">pppBLOG v
       <?php echo $pppb_info['version']; ?>
       </a>&nbsp;
    </div>
  </body>
</html>
<?php
}


function ppp_htmlentities($string,$ent,$charset){

    global $supported_charsets;

    if (is_int(array_search(strtolower($charset),$supported_charsets))){
	$string = htmlspecialchars($string,ENT_COMPAT,$charset);
    }
    else{
      $string = str_replace ( array ( '&', '"', '<', '>' ), array ( '&amp;' , '&quot;', '&lt;' , '&gt;' ), $string );
    }

    // new 2005-11-22: don't convert html/xml entities
    // (convert &amp; back to &)
    return preg_replace("/&amp;([A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/","&$1",$string);
}


// from http://nl3.php.net/htmlentities

function xmlentities($string, $quote_style=ENT_QUOTES)
{
   static $trans;
   if (!isset($trans)) {
       $trans = get_html_translation_table(HTML_ENTITIES, $quote_style);
       foreach ($trans as $key => $value)
           $trans[$key] = '&#'.ord($key).';';
       // dont translate the '&' in case it is part of &xxx;
       $trans[chr(38)] = '&';
   }
   // after the initial translation, _do_ map standalone '&' into '&#38;'

   return preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/","&#38;" , strtr($string, $trans));
}


?>