<?php

// STD Page Generation System[tm] v0.2
// Copyright (C) 2004-2005, Cockos Incorporated
// License: public domain

// to use this code to make new pages, do:
//   include("std.php");
//   standardheaders("MyAppName"); // the parameter can be "" for the main page
//   displayfile("index.txt");
//   standardfooters();
//
//   index.txt is the content, and if the line begins with ^ it is centered.
//   by default the minimum page size is 80x25. you can tweak below, too.

//   Cockos STD homepage, http://cockos.com/std/

//   v0.2: autowrap support for long lines. specify your width/min height here.
//         (inspired by John Caruso's version)
//   v0.1: first version

$company_name "Cockos Incorporated";
$width=80;
$minheight=25;






function 
padoutstring($x$indent$outlen)
{
  
$buf="|";
  
$mylen=strlen(strip_tags($x));
  if (
$indent 0$indent=(($outlen-$mylen)/2)|0;

  for (
$pos 0$pos $indent$pos ++) $buf.=" ";
  
$buf .= $x;
  for (
$pos $indent $mylen$pos $outlen$pos++) $buf.=" ";
  
$buf .= " |\n";
  return 
$buf;
}

function 
displayfile($filename)
{
  global 
$width;
  global 
$minheight;
  
  
$xdim=$width;
  
$ydim=0;
  echo 
"/";
  for (
$x 1$x $xdim+3-1$x++) echo "-";
  echo 
"\\\n";

  
$fp fopen($filename,"r");
  if (
$fp)
  {
    while ((
$x=fgets($fp,1024)))
    {
      
$x=rtrim($x);
      if (
substr($x,0,1) == "^") { $indents[$ydim]=-1$x=substr($x,1); }
      
$l=strlen(strip_tags($x));
      
$lines[$ydim++]=$x;
    }
    
fclose($fp);
  }

  
$ypos=0;
  
$yspos=0;
  while (
$yspos $ydim)
  {
    if (
$indents[$yspos] == ''$ind=1;
    else 
$ind=$indents[$yspos];

    
$sl=$lines[$yspos++];

    do 
    {
      if (
strlen(strip_tags($sl)) >= $xdim)
      {
        
$newl=strlen($sl);
        do
        {
          
$newsub=substr($sl,0,--$newl);
        }
        while (
strlen(strip_tags($newsub)) >= $xdim);
 
        do
        {
          
$tmp=substr($sl,--$newl,1);
        }
        while (
$newl && $tmp != "\t" && $tmp != " ");
          
        echo 
padoutstring(substr($sl,0,$newl),$ind,$xdim);
        do
        {
          
$tmp=substr($sl,++$newl,1);
        }
        while (
$tmp == "\t" || $tmp == " ");

        
$sl=substr($sl,$newl);
      }
      else
      {
        echo 
padoutstring($sl,$ind,$xdim);
        
$sl="";
      }
      
$ypos++;
    } while (
$sl != "");
  }
  while (
$ypos $minheight
  {
    echo 
padoutstring("",1,$xdim);
    
$ypos++;
  }

  echo 
"\\";
  for (
$x 1$x $xdim+3-1$x++) echo "-";
  echo 
"/\n";
}

function 
standardheaders($title)
{
  global 
$company_name;
  echo 
"<HTML><HEAD><TITLE>";
  if (
$title != "") echo "$title | ";
  echo 
"$company_name</TITLE>";
  echo 
"</HEAD><BODY BGCOLOR=\"#000000\" TEXT=\"#8f8f8f\" LINK=\"#8f8f8f\" VLINK=\"#8f8f8f\" ALINK=\"#8f8f8f\">";
  echo 
"<TABLE width=100% height=100% valign=center><TR><TD align=center><CENTER>";
  echo 
"<PRE>";
}

function 
standardfooters()
{
  echo 
"</pre></TD></TR></TABLE></BODY></HTML>";
}

?>